@import './tokens.css';

/* Global Reset & Box Sizing */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family-sans);
  background-color: var(--color-neutral-100);
  color: var(--color-neutral-900);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  overflow-x: hidden;
}

/* App Header */
.app-header {
  height: 64px;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--color-neutral-1000);
  letter-spacing: -0.2px;
}

.brand-tag {
  font-size: 11px;
  font-weight: 600;
  background: rgba(0, 204, 170, 0.15);
  color: var(--color-primary-500);
  padding: 3px 8px;
  border-radius: 12px;
  border: 1px solid rgba(0, 204, 170, 0.3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Layout Container */
.app-container {
  display: flex;
  flex: 1;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
  padding: 24px;
  gap: 24px;
}

/* Control Sidebar */
.controls-sidebar {
  width: 380px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--color-neutral-200);
  border: 1px solid var(--color-neutral-300);
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  transition: border-color 0.2s ease;
}

.card:hover {
  border-color: var(--color-neutral-400);
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--color-neutral-1000);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-title svg {
  color: var(--color-primary-500);
}

/* Dropzone Upload */
.upload-dropzone {
  border: 2px dashed var(--color-neutral-400);
  border-radius: 12px;
  padding: 28px 16px;
  text-align: center;
  background: rgba(17, 19, 23, 0.4);
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  position: relative;
}

.upload-dropzone:hover,
.upload-dropzone.dragover {
  border-color: var(--color-primary-500);
  background: rgba(0, 204, 170, 0.05);
}

.upload-icon {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--color-neutral-300);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-primary-500);
  transition: transform 0.2s ease;
}

.upload-dropzone:hover .upload-icon {
  transform: translateY(-2px);
  background: var(--color-primary-500);
  color: var(--color-neutral-100);
}

.upload-prompt {
  font-size: 13px;
  color: var(--color-neutral-700);
}

.btn-select-file {
  background: var(--color-neutral-300);
  color: var(--color-neutral-1000);
  border: 1px solid var(--color-neutral-400);
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;

}

.btn-select-file:hover {
  background: var(--color-neutral-400);
  border-color: var(--color-neutral-500);
}

.file-input {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.file-badge {
  margin-top: 12px;
  padding: 10px 14px;
  overflow-wrap: anywhere;
  border: 1px solid rgba(0, 204, 170, 0.3);
  border-radius: 8px;
  background: rgba(0, 204, 170, 0.1);
  color: var(--color-primary-500);
  font-size: 12px;
  font-weight: 500;
}

.file-badge[hidden] {
  display: none;
}

/* Control Options */
.control-group {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}

.toggle-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--color-neutral-800);
}

/* Animated Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--color-neutral-400);
  transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

input:checked+.slider {
  background-color: var(--color-primary-500);
}

input:checked+.slider:before {
  transform: translateX(20px);
}

/* Input Fields */
.input-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-neutral-600);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.input-field {
  background: var(--color-neutral-100);
  border: 1px solid var(--color-neutral-300);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  color: var(--color-neutral-1000);
  outline: none;
  transition: border-color 0.2s ease;

}

.input-field:focus {
  border-color: var(--color-primary-500);
  box-shadow: 0 0 0 2px rgba(0, 204, 170, 0.2);
}

/* Buttons */
.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, var(--color-primary-500) 0%, #00b395 100%);
  color: var(--color-neutral-100);
  border: none;
  padding: 14px 20px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  box-shadow: 0 4px 16px rgba(0, 204, 170, 0.3);
  transition: all 0.2s ease;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 204, 170, 0.4);
}

.btn-primary:active {
  transform: translateY(0);
}

/* Main Workspace Preview */
.workspace-preview {
  flex: 1;
  min-width: 0;
  /* Prevents flex items from overflowing or compressing preview viewport */
  display: flex;
  flex-direction: column;
  background: var(--color-neutral-200);
  border: 1px solid var(--color-neutral-300);
  border-radius: 16px;
  overflow: hidden;
}

.preview-toolbar {
  height: 52px;
  background: var(--color-neutral-100);
  border-bottom: 1px solid var(--color-neutral-300);
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--color-neutral-600);
}

.preview-title {
  font-weight: 600;
  color: var(--color-neutral-900);
  display: flex;
  align-items: center;
  gap: 8px;
}

.preview-viewport {
  flex: 1;
  padding: 40px;
  overflow: auto;
  /* Enables both horizontal & vertical scrolling so A4 format never deforms */
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: #181B20;
}

/* Fixed DIN A4 Sheet Format (210mm x 297mm @ 96 DPI: 794px x 1123px) */
.a4-page {
  width: 794px !important;
  min-width: 794px !important;
  max-width: 794px !important;
  height: 1123px !important;
  min-height: 1123px !important;
  max-height: 1123px !important;
  flex-shrink: 0 !important;
  background: #FFFFFF;
  color: #111317;
  padding: 48px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  border-radius: 2px;
  box-sizing: border-box !important;
  font-family: var(--font-family-sans);
  position: relative;
  overflow: hidden;
}

/* DIN Lang Overlay Image */
.din-overlay-img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
  opacity: 0.65;
  z-index: 99;
}

/* Exact Reference PDF Layout Styles matching 2607_amasol_time-entries-after.pdf */

.pdf-header {
  margin-bottom: 24px;
}

.pdf-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.pdf-logo {
  height: 28px;
  width: auto;
  object-fit: contain;
  margin-top: 4px;
}

.pdf-title {
  font-size: 32px;
  font-weight: 800;
  color: #111317;
  line-height: 1.1;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.pdf-subtitle {
  font-size: 15px;
  font-weight: 600;
  color: #697388;
  letter-spacing: 0.2px;
}

/* Address Details Block (DIN 5008 Alignment for Envelope Window) */
.pdf-address-block {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 98px;
  /* Shifted down so CLIENT header & lines sit 100% inside green area */
  margin-bottom: 0px;
  padding: 0;
  max-width: 620px;
  margin-left: auto;
  margin-right: auto;
}

.address-col {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 14.67px;
  /* 11pt equivalent at 96 DPI CSS / 300 DPI print scale */
  color: #111317;
  line-height: 1.4;
}

.client-col {
  text-align: left;
  max-width: 300px;
}

.provider-col {
  text-align: right;
  max-width: 300px;
}

.address-header {
  font-size: 13.33px;
  /* 10pt equivalent */
  font-weight: 700;
  color: #697388;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
}

.provider-name,
.client-name {
  font-weight: 700;
  font-size: 14.67px;
  color: #111317;
}

.address-line {
  font-size: 14.67px;
  color: #21242C;
}

/* Disabled State for Inputs */
.input-field:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  background-color: var(--color-neutral-300);
  border-color: rgba(255, 255, 255, 0.05);
}

/* Summary Card Box (Positioned completely below the green window box) */
.pdf-summary-card {
  border: 1px solid #D5D9E0;
  border-radius: 12px;
  padding: 20px 24px;
  margin-top: 60px;
  /* Clears bottom edge of green window box (y = 378px) when address block is shown */
  margin-bottom: 28px;
  background: #FFFFFF;
  display: flex;
  align-items: flex-start;
}

/* Reduced margin when address block is hidden */
#pdf-address-block[style*="display: none"]~.pdf-summary-card {
  margin-top: 24px;
}

.summary-col {
  display: flex;
  flex-direction: column;
}

.summary-label {
  font-size: 15px;
  font-weight: 600;
  color: #697388;
  margin-bottom: 4px;
}

.summary-value {
  font-size: 26px;
  font-weight: 800;
  color: #111317;
  letter-spacing: -0.5px;
  line-height: 1.2;
}

/* Report Table */
.pdf-table-container {
  border: 1px solid #D5D9E0;
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 40px;
}

.pdf-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  text-align: left;
}

.pdf-table th {
  padding: 12px 14px;
  font-weight: 700;
  color: #111317;
  border-bottom: 1px solid #D5D9E0;
  background: #FFFFFF;
  font-size: 13px;
}

.pdf-table td {
  padding: 12px 14px;
  color: #111317;
  border-bottom: 1px solid #E5E7EB;
  vertical-align: top;
  line-height: 1.4;
}

.pdf-table tr:last-child td {
  border-bottom: none;
}

.pdf-table tr {
  break-inside: avoid;
  page-break-inside: avoid;
}

.entry-desc {
  font-weight: 500;
  color: #111317;
  margin-bottom: 2px;
}

.entry-meta {
  font-size: 12px;
  color: #111317;
  line-height: 1.3;
}

.entry-meta strong {
  font-weight: 700;
  color: #111317;
}

/* Footer */
.pdf-footer {
  position: absolute;
  left: 48px;
  right: 48px;
  bottom: 48px;
  font-size: 13px;
  color: #697388;
  font-weight: 500;
}

.legal-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--color-neutral-600);
  font-size: 13px;
}

.legal-card a {
  color: var(--color-neutral-700);
  text-underline-offset: 4px;
  transition: color 0.2s ease;
}

.legal-card a:hover { color: var(--color-primary-500); }

.legal-card a:focus-visible {
  border-radius: 2px;
  outline: 2px solid var(--color-primary-500);
  outline-offset: 4px;
}

.continuation-page .pdf-table-container {
  margin-bottom: 0;
}

/* Print & PDF Page Setup */
@page {
  size: A4 portrait;
  margin: 0;
}

@media print {

  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    width: 210mm !important;
    height: auto !important;
    background: #FFFFFF !important;
    color: #111317 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .app-header,
  .controls-sidebar,
  .preview-toolbar,
  .din-overlay-img {
    display: none !important;
  }

  .app-container,
  .workspace-preview,
  .preview-viewport {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
    width: 210mm !important;
    max-width: 210mm !important;
    height: auto !important;
    min-height: 0 !important;
    background: #FFFFFF !important;
    border: none !important;
    overflow: visible !important;
  }

  #pages-container {
    display: block !important;
    width: 210mm !important;
    gap: 0 !important;
  }

  .a4-page {
    width: 210mm !important;
    min-width: 210mm !important;
    max-width: 210mm !important;
    /* A tiny tolerance prevents browser rounding from creating an overflow
       fragment (and therefore an empty final print page). */
    height: 296.8mm !important;
    min-height: 296.8mm !important;
    max-height: 296.8mm !important;
    box-shadow: none !important;
    padding: 48px !important;
    margin: 0 !important;
    overflow: hidden !important;
    page-break-inside: avoid !important;
    break-inside: avoid-page !important;
    page-break-after: auto !important;
    break-after: auto !important;
  }

  .a4-page:not(:last-child) {
    page-break-after: always !important;
    break-after: page !important;
  }
}
