/* ==========================================================================
   SKALA Paramedics Invoice Generator - Style Guide & Theme
   Corporate Red: #ff3838
   Custom Font: Wix Madefor Text
   ========================================================================== */

/* Load Wix Madefor Text Variable Fonts locally */
@font-face {
  font-family: 'Wix Madefor Text';
  src: local('Wix Madefor Text'),
       local('Wix Madefor Text Regular'),
       local('Wix Madefor Text-Regular'),
       local('WixMadeforText-Regular'),
       local('WixMadeforText'),
       url('WixMadeforText-VariableFont_wght.ttf') format('truetype-variations'),
       url('WixMadeforText-VariableFont_wght.ttf') format('truetype');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Wix Madefor Text';
  src: local('Wix Madefor Text Italic'),
       local('Wix Madefor Text-Italic'),
       local('WixMadeforText-Italic'),
       local('WixMadeforTextItalic'),
       url('WixMadeforText-Italic-VariableFont_wght.ttf') format('truetype-variations'),
       url('WixMadeforText-Italic-VariableFont_wght.ttf') format('truetype');
  font-weight: 100 900;
  font-style: italic;
  font-display: swap;
}

/* Variables */
:root {
  --color-primary: #ff3838;
  --color-primary-hover: #e02424;
  --color-primary-light: rgba(255, 56, 56, 0.1);
  --color-bg-dark: #090b0e;
  --color-bg-sidebar: #12151a;
  --color-border-dark: #222a36;
  --color-text-light: #f3f4f6;
  --color-text-muted: #9ca3af;
  
  --color-bg-preview: #eef1f6;
  --color-sheet-bg: #ffffff;
  --color-sheet-text: #1f2937;
  --color-sheet-muted: #4b5563;
  --color-sheet-border: #e5e7eb;
  
  --font-logo: 'Wix Madefor Text', -apple-system, sans-serif;
  --font-ui: 'Wix Madefor Text', -apple-system, sans-serif;
  
  --transition-speed: 0.2s;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -1px rgba(0,0,0,0.04);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.04), 0 4px 6px -2px rgba(0,0,0,0.02);
  --shadow-sheet: 0 12px 40px rgba(0, 0, 0, 0.08);
}

/* Reset & Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-ui);
  background-color: var(--color-bg-preview);
  color: var(--color-sheet-text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Layout */
.app-container {
  display: flex;
  min-height: 100vh;
  width: 100vw;
  overflow-x: hidden;
}

/* ==========================================================================
   Sidebar Styles (Light Floating Dashboard Control Panel)
   ========================================================================== */
.sidebar {
  width: 450px;
  background-color: #f3f4f6;
  border-right: 1px solid #e5e7eb;
  color: #1f2937;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  z-index: 10;
}

.sidebar-header {
  padding: 2rem 1.5rem 1.5rem 1.5rem;
  border-bottom: 1px solid #e5e7eb;
}

.logo-container {
  display: flex;
  align-items: center;
  margin-bottom: 1rem;
}

.logo-img {
  max-height: 36px;
  width: auto;
  object-fit: contain;
}

.sidebar-title {
  font-family: var(--font-logo);
  font-size: 1.25rem;
  font-weight: 700;
  color: #1f2937;
}

.sidebar-subtitle {
  font-size: 0.8rem;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Form Styles */
.form-container {
  padding: 1.5rem;
  flex-grow: 1;
}

.form-section {
  background-color: #ffffff;
  border: 1px solid #e5e7eb;
  border-radius: 20px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.03);
}

.section-title {
  font-family: var(--font-logo);
  font-size: 0.95rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 1rem;
  color: #1f2937;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-bottom: 1px solid #f3f4f6;
  padding-bottom: 0.5rem;
}

.section-icon {
  width: 1.1rem;
  height: 1.1rem;
  color: var(--color-primary);
}

.input-group {
  margin-bottom: 1rem;
}

.input-group:last-child {
  margin-bottom: 0;
}

.input-row {
  display: flex;
  gap: 1rem;
}

.input-row .input-group {
  flex: 1;
}

label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  background-color: #ffffff;
  border: 1.5px solid #e5e7eb;
  border-radius: 8px;
  color: #1f2937;
  padding: 0.65rem 0.75rem;
  font-family: var(--font-ui);
  font-size: 0.9rem;
  transition: border-color var(--transition-speed), box-shadow var(--transition-speed);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(255, 56, 56, 0.15);
}

input::placeholder {
  color: #9ca3af;
}

/* Custom styles for select elements */
select {
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%234b5563' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3E%3C/svg%3E");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
  padding-right: 2.5rem;
}

/* Actions Section */
.sidebar-actions {
  padding: 1.5rem;
  border-top: 1px solid #e5e7eb;
  background-color: #f3f4f6;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.85rem 1.25rem;
  font-family: var(--font-logo);
  font-weight: 600;
  font-size: 0.95rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: all var(--transition-speed);
  text-decoration: none;
  text-align: center;
}

.btn-primary {
  background-color: var(--color-primary);
  color: white;
}

.btn-primary:hover {
  background-color: var(--color-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(255, 56, 56, 0.25);
}

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

.btn-outline {
  background-color: #ffffff;
  border: 1.5px solid #e5e7eb;
  color: #4b5563;
}

.btn-outline:hover {
  background-color: #f9fafb;
  border-color: #d1d5db;
  color: #1f2937;
}

.btn-icon {
  width: 1.1rem;
  height: 1.1rem;
}

.email-notice {
  font-size: 0.75rem;
  color: #4b5563;
  line-height: 1.4;
  margin-top: 0.25rem;
  padding: 0.65rem;
  background-color: rgba(255, 56, 56, 0.04);
  border-radius: 8px;
  border-left: 3px solid var(--color-primary);
}

/* ==========================================================================
   Preview Area (Light-grey backdrop, hosting A4 sheet simulation)
   ========================================================================== */
.preview-area {
  flex-grow: 1;
  padding: 3rem;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
  height: 100vh;
}

/* DIN A4 Sheet Simulation */
.a4-sheet {
  background-color: var(--color-sheet-bg);
  color: var(--color-sheet-text);
  width: 210mm;
  height: 297mm;
  max-height: 297mm;
  padding: 20mm 20mm 15mm 20mm;
  box-shadow: var(--shadow-sheet);
  display: flex;
  flex-direction: column;
  position: relative;
  font-size: 9.5pt;
  line-height: 1.5;
  box-sizing: border-box;
  overflow: hidden;
}

/* A4 Sheet Typography & Sections */
.sheet-header {
  margin-bottom: 15mm;
}

.sender-info-compact {
  font-size: 7.5pt;
  color: var(--color-sheet-muted);
  border-bottom: 0.5px solid var(--color-sheet-border);
  padding-bottom: 2mm;
  margin-bottom: 6mm;
  letter-spacing: 0.5px;
}

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

/* Left block: Window-envelope address layout */
.recipient-address-block {
  width: 85mm;
  height: 35mm;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
}

.sender-return-line {
  font-size: 7.5pt;
  color: var(--color-sheet-muted);
  text-decoration: underline;
  margin-bottom: 3mm;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.recipient-address {
  font-size: 10pt;
  line-height: 1.4;
}

/* Right block: Sender Contact details card & Logo */
.sender-side-container {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  max-width: 75mm;
}

.sheet-logo-container {
  margin-bottom: 4mm;
  display: flex;
  justify-content: flex-end;
}

.sheet-logo {
  max-height: 12mm;
  max-width: 55mm;
  width: auto;
  object-fit: contain;
}

.sender-contact-details {
  text-align: right;
  max-width: 70mm;
}

.sender-contact-details h3 {
  font-family: var(--font-logo);
  font-size: 12pt;
  font-weight: 700;
  margin-bottom: 2mm;
  color: var(--color-sheet-text);
}

.sender-contact-details p {
  font-size: 9.5pt;
  color: var(--color-sheet-muted);
  line-height: 1.45;
}

.sender-contact-details .contact-sub {
  margin-top: 3mm;
  font-size: 8.5pt;
  border-top: 1px solid var(--color-sheet-border);
  padding-top: 2mm;
}

/* Meta Info Block (Rechnungsdetails in columns) */
.invoice-meta-section {
  display: flex;
  border-top: 1px solid var(--color-sheet-text);
  border-bottom: 1px solid var(--color-sheet-text);
  padding: 3mm 0;
  margin-bottom: 6mm;
}

.meta-column {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.meta-column:not(:last-child) {
  border-right: 1px solid var(--color-sheet-border);
  padding-right: 2mm;
  margin-right: 4mm;
}

.meta-label {
  font-size: 7.5pt;
  text-transform: uppercase;
  color: var(--color-sheet-muted);
  letter-spacing: 0.5px;
  margin-bottom: 1mm;
}

.meta-value {
  font-size: 9.5pt;
  font-weight: 600;
  color: var(--color-sheet-text);
}

/* Subject line */
.document-title-section {
  margin-bottom: 3mm;
}

.document-title-section h2 {
  font-family: var(--font-logo);
  font-size: 20pt;
  font-weight: 800;
  color: var(--color-sheet-text);
  margin-bottom: 2mm;
}

.invoice-subject {
  font-size: 11pt;
  color: var(--color-sheet-text);
}

.invoice-intro {
  margin-bottom: 5mm;
  font-size: 10pt;
}

/* Items Table styling */
.invoice-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 5mm;
}

.invoice-items-table th {
  background-color: #f9fafb;
  border-bottom: 2px solid var(--color-sheet-text);
  font-weight: 700;
  font-size: 9pt;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--color-sheet-muted);
  padding: 3mm 4mm;
  text-align: left;
}

.invoice-items-table td {
  border-bottom: 1px solid var(--color-sheet-border);
  padding: 3mm 4mm;
  font-size: 9.5pt;
  vertical-align: top;
}

.col-pos { width: 8%; }
.col-desc { width: 52%; }
.col-qty { width: 12%; text-align: right; }
.col-price { width: 13%; text-align: right; }
.col-total { width: 15%; text-align: right; }

.text-right {
  text-align: right;
}

/* Calculation & Totals block */
.invoice-totals-wrapper {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 5mm;
}

.totals-table {
  width: 75mm;
  border-collapse: collapse;
}

.totals-table td {
  padding: 2mm 4mm;
  font-size: 9.5pt;
}

.totals-table td:last-child {
  text-align: right;
  width: 35mm;
}

.row-grand-total {
  border-top: 1.5px solid var(--color-sheet-text);
  border-bottom: 2px double var(--color-sheet-text);
  font-size: 11pt !important;
}

.row-grand-total td {
  padding: 3mm 4mm;
}

/* Tax Exemption Notice Text */
.tax-notice-container {
  font-size: 8.5pt;
  font-style: italic;
  color: var(--color-sheet-muted);
  margin-bottom: 6mm;
  line-height: 1.4;
}

/* Payment Terms */
.payment-terms-section {
  margin-bottom: 8mm;
  padding: 3mm 4mm;
  background-color: #f9fafb;
  border-left: 3px solid var(--color-sheet-text);
  font-size: 9.5pt;
}

/* Sheet Footer */
.sheet-footer {
  margin-top: auto;
  border-top: 1px solid var(--color-sheet-border);
  padding-top: 3mm;
}

.footer-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr;
  gap: 6mm;
}

.footer-col h4 {
  font-family: var(--font-logo);
  font-size: 7.5pt;
  text-transform: uppercase;
  color: var(--color-sheet-muted);
  margin-bottom: 2mm;
  letter-spacing: 0.5px;
}

.footer-col p {
  font-size: 8pt;
  color: var(--color-sheet-muted);
  line-height: 1.45;
}

.footer-thanks {
  text-align: center;
  font-family: var(--font-logo);
  font-size: 8.5pt;
  color: var(--color-sheet-muted);
  margin-top: 6mm;
  font-style: italic;
}

/* Helper Utilities */
.hidden {
  display: none !important;
}

/* ==========================================================================
   Responsive Adaptations
   ========================================================================== */
@media (max-width: 1280px) {
  .sidebar {
    width: 380px;
  }
}

@media (max-width: 1024px) {
  .app-container {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    border-right: none;
    border-bottom: 1px solid var(--color-border-dark);
  }
  .preview-area {
    height: auto;
    padding: 1.5rem;
    overflow-y: visible;
  }
  .a4-sheet {
    width: 100%;
    height: auto;
    min-height: 297mm;
    padding: 15mm 10mm;
  }
  
  /* Scale letterhead elements fluidly side-by-side on mobile screens */
  .header-main {
    display: flex !important;
    flex-direction: row !important;
    justify-content: space-between !important;
    align-items: flex-start !important;
  }
  
  .recipient-address-block {
    width: 55% !important;
    height: auto !important;
    margin-bottom: 0 !important;
  }
  
  .sender-contact-details {
    width: 42% !important;
    max-width: 42% !important;
    text-align: right !important;
  }

  /* Hide download button and make print button primary on mobile devices */
  #btn-download {
    display: none !important;
  }
  #btn-print {
    background-color: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
    color: white !important;
    box-shadow: 0 4px 12px rgba(255, 56, 56, 0.25) !important;
  }
  #btn-print:hover {
    background-color: var(--color-primary-hover) !important;
  }
}

/* ==========================================================================
   Print Stylesheet (Hard formatting to force exact A4 rendering)
   ========================================================================== */
@page {
  size: A4;
  margin: 0;
}

@media print {
  /* Hide all non-printable elements */
  .no-print, 
  .sidebar, 
  .sidebar-actions, 
  .email-notice {
    display: none !important;
  }

  /* Reset layout margins for browser printing */
  html, body {
    background-color: #ffffff !important;
    color: #000000 !important;
    width: 210mm !important;
    height: 100% !important; /* Allow fluid scaling */
    margin: 0 !important;
    padding: 0 !important;
    font-size: 9.5pt !important;
    overflow: hidden !important; /* Block overflow pages */
  }

  .app-container {
    display: block !important;
    width: 210mm !important;
    height: 100% !important; /* Allow fluid scaling */
    overflow: hidden !important; /* Block overflow pages */
    margin: 0 !important;
    padding: 0 !important;
  }

  .preview-area {
    display: block !important;
    width: 210mm !important;
    height: 100% !important; /* Allow fluid scaling */
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important; /* Block overflow pages */
    background-color: transparent !important;
  }

  /* Hard-format the sheet to standard A4 printing constraints with a minor safety buffer */
  .a4-sheet {
    box-shadow: none !important;
    border: none !important;
    width: 210mm !important;
    height: 268mm !important; /* Safe height to prevent 2nd blank page on default printer/browser margins and US Letter */
    max-height: 268mm !important;
    padding: 12mm 15mm 10mm 15mm !important; /* Slightly tighter padding for print safety */
    margin: 0 !important;
    position: relative !important;
    background-color: #ffffff !important;
    box-sizing: border-box !important;
    overflow: hidden !important; /* Guarantee no spillage */
    page-break-after: avoid !important;
    page-break-before: avoid !important;
    page-break-inside: avoid !important;
  }

  /* Compact print margins to prevent 2-page spill */
  .sheet-header {
    margin-bottom: 12mm !important;
  }
  
  .recipient-address-block {
    height: 35mm !important;
  }
  
  .sheet-logo-container {
    margin-bottom: 2mm !important;
  }

  .sheet-logo {
    max-height: 10mm !important;
  }

  .invoice-meta-section {
    padding: 3mm 0 !important;
    margin-bottom: 6mm !important;
  }

  .document-title-section {
    margin-bottom: 3mm !important;
  }

  .invoice-intro {
    margin-bottom: 5mm !important;
  }

  .invoice-items-table {
    margin-bottom: 5mm !important;
  }

  .invoice-items-table td {
    padding: 3mm !important;
  }

  .invoice-totals-wrapper {
    margin-bottom: 5mm !important;
  }

  .tax-notice-container {
    margin-bottom: 6mm !important;
  }

  .payment-terms-section {
    margin-bottom: 8mm !important;
    padding: 3mm !important;
  }

  /* Force table formatting inside PDF printer engines */
  .invoice-items-table th {
    background-color: #f3f4f6 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .payment-terms-section {
    background-color: #f3f4f6 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Force grid sizing on print engines that don't support full grids in print */
  .footer-grid {
    display: flex !important;
    justify-content: space-between !important;
    gap: 4mm !important;
  }
  
  .footer-col {
    width: 31% !important;
  }
  
  .sheet-footer {
    padding-top: 3mm !important;
  }

  .footer-thanks {
    margin-top: 4mm !important;
  }
}

/* ==========================================================================
   PDF Rendering Helper
   Forces desktop A4 dimensions during canvas capture on mobile screens
   ========================================================================== */
.a4-sheet.rendering-pdf {
  width: 210mm !important;
  height: 268mm !important; /* Shrunk print-safe height to prevent 2nd blank page in html2pdf */
  max-height: 268mm !important;
  padding: 12mm 15mm 10mm 15mm !important; /* Safe margins padding */
  font-size: 9.5pt !important;
  box-shadow: none !important;
  position: static !important;
  display: flex !important;
  flex-direction: column !important;
  overflow: hidden !important;
}

