.invoice-preview-container {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  background: #ffffff;
  color: #111827;
  padding: 30px 36px;
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  font-family: 'DM Sans', 'Noto Sans Gujarati', sans-serif;
  box-sizing: border-box;
}

/* Explicitly mark unsaved/void documents even if printed with the browser shortcut. */
@media print {
  #modalInvoiceViewer[hidden] { display: none !important; }
  #invoiceRenderArea .draft-stamp { display: block !important; }
  .inv-table thead { display: table-header-group; }
  .inv-table tfoot { display: table-row-group; }
  .inv-table tr { break-inside: avoid; }
  .statement-style .inv-signatures { grid-template-columns: repeat(2, 1fr) !important; }
}

.invoice-sheet {
  width: 100%;
}

/* Letterhead Layout */
.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.inv-brand {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.brand-badge {
  width: 48px;
  height: 48px;
  background: #d97706;
  color: #ffffff;
  font-weight: 800;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  flex-shrink: 0;
}

.brand-title {
  font-size: 22px;
  font-weight: 800;
  color: #0f172a;
  line-height: 1.2;
}

.brand-tagline {
  font-size: 11.5px;
  color: #d97706;
  font-weight: 700;
  margin-top: 2px;
}

.brand-meta {
  font-size: 11px;
  color: #475569;
  margin-top: 3px;
}

.brand-gst {
  font-size: 11px;
  color: #0f172a;
  margin-top: 2px;
}

.inv-doc-tag {
  text-align: right;
}

.badge-doc-type {
  display: inline-block;
  background: #0f172a;
  color: #ffffff;
  font-size: 12px;
  font-weight: 800;
  padding: 5px 12px;
  border-radius: 6px;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.badge-doc-type.badge-tax-inv {
  background: #b45309;
}

.meta-row {
  font-size: 12px;
  color: #334155;
  margin-top: 2px;
}

.inv-divider {
  height: 2px;
  background: #e2e8f0;
  margin: 12px 0 16px;
}

.inv-info-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}

.info-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 14px;
}

.info-box .box-title {
  font-size: 10.5px;
  font-weight: 800;
  color: #64748b;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.party-name {
  font-size: 16px;
  font-weight: 800;
  color: #0f172a;
}

.party-site {
  font-size: 12px;
  color: #334155;
  margin-top: 3px;
}

.info-box p {
  font-size: 12px;
  color: #334155;
  margin: 3px 0;
}

.highlight-veh {
  background: #e2e8f0;
  font-family: var(--font-mono);
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
}

.party-bill-bar {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.billed-party .bar-label {
  font-size: 10px;
  font-weight: 700;
  color: #64748b;
  text-transform: uppercase;
}

.billed-party .party-title {
  font-size: 17px;
  font-weight: 800;
  color: #0f172a;
}

.bill-summary-stats {
  display: flex;
  align-items: center;
  gap: 20px;
}

.mini-stat {
  display: flex;
  flex-direction: column;
  text-align: right;
}

.mini-lbl {
  font-size: 10.5px;
  color: #64748b;
}

.mini-val {
  font-size: 15px;
  font-weight: 800;
  color: #0f172a;
}

/* Printable Table */
.inv-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 14px;
  font-size: 12.5px;
}

.inv-table th {
  background: #0f172a;
  color: #ffffff;
  font-size: 11.5px;
  font-weight: 700;
  padding: 8px 10px;
  text-align: left;
}

.inv-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #e2e8f0;
  font-size: 12.5px;
  color: #1e293b;
}

.inv-table tbody tr:nth-child(even) {
  background: #f8fafc;
}

.inv-table tfoot td {
  padding: 7px 10px;
  font-size: 12.5px;
}

.tfoot-total, .tfoot-final {
  background: #f1f5f9;
  border-top: 2px solid #0f172a;
}

.highlight-total {
  font-size: 15px;
  color: #b45309;
}

.sub-note {
  font-size: 11px;
  color: #64748b;
  margin-top: 2px;
}

.amount-words-box {
  background: #f8fafc;
  border: 1px dashed #cbd5e1;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  color: #0f172a;
  margin-bottom: 14px;
}

.inv-footer-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 14px;
  margin-bottom: 20px;
}

.footer-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 11.5px;
  color: #334155;
  line-height: 1.5;
}

.footer-box .box-title {
  font-weight: 800;
  color: #0f172a;
  margin-bottom: 4px;
  text-transform: uppercase;
  font-size: 10.5px;
}

.inv-signatures {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-top: 28px;
  padding-top: 6px;
}

.sign-block {
  text-align: center;
}

.sign-line {
  height: 1px;
  background: #94a3b8;
  margin-bottom: 6px;
}

.sign-block p {
  font-size: 11.5px;
  color: #475569;
  font-weight: 600;
}

.company-sign {
  color: #0f172a !important;
  font-weight: 800 !important;
}

.sub-sign {
  font-size: 10.5px;
  color: #64748b;
}

/* ==========================================================================
   ULTRA-COMPACT A4 PRINT ENGINE
   Guarantees Delivery Challan prints on exactly 1 single sheet of paper
   ========================================================================== */

@media print {
  @page {
    size: A4 portrait;
    margin: 8mm 10mm 8mm 10mm;
  }

  html, body {
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    color: #000000 !important;
    font-family: 'DM Sans', 'Noto Sans Gujarati', sans-serif !important;
    font-size: 11px !important;
    line-height: 1.3 !important;
    overflow: visible !important;
  }

  /* Completely HIDE all UI elements outside the invoice */
  body > *:not(#modalInvoiceViewer) {
    display: none !important;
  }

  .app-container,
  .app-sidebar,
  .app-main,
  .app-header,
  .page-container,
  #modalTripEntry,
  .modal-header,
  .modal-footer,
  .no-print,
  .filter-card,
  .btn,
  .btn-close-modal {
    display: none !important;
  }

  /* Unravel modal into direct printable document */
  #modalInvoiceViewer {
    display: block !important;
    position: static !important;
    background: transparent !important;
    backdrop-filter: none !important;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    box-shadow: none !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
  }

  #modalInvoiceViewer .modal-window {
    display: block !important;
    position: static !important;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: none !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    animation: none !important;
  }

  #modalInvoiceViewer .modal-body,
  .invoice-modal-body {
    display: block !important;
    position: static !important;
    background: transparent !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: visible !important;
    width: 100% !important;
  }

  .invoice-preview-container {
    display: block !important;
    position: static !important;
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    background: #ffffff !important;
    color: #000000 !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
  }

  .invoice-sheet {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    box-sizing: border-box !important;
  }

  .invoice-sheet.challan-style {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  /* Compact Print Header */
  .inv-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: flex-start !important;
    margin-bottom: 8px !important;
  }

  .brand-badge {
    width: 40px !important;
    height: 40px !important;
    font-size: 18px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .brand-title {
    font-size: 19px !important;
    line-height: 1.15 !important;
    color: #0f172a !important;
  }

  .brand-tagline {
    font-size: 10px !important;
    margin-top: 1px !important;
    color: #d97706 !important;
  }

  .brand-meta, .brand-gst {
    font-size: 9.5px !important;
    margin-top: 2px !important;
  }

  .badge-doc-type {
    font-size: 10.5px !important;
    padding: 3px 10px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .meta-row {
    font-size: 10.5px !important;
    margin-top: 2px !important;
  }

  .inv-divider {
    height: 1px !important;
    background: #cbd5e1 !important;
    margin: 6px 0 8px !important;
  }

  /* Info Grid */
  .inv-info-grid {
    display: grid !important;
    grid-template-columns: 1.1fr 1fr !important;
    gap: 10px !important;
    margin-bottom: 10px !important;
  }

  .info-box {
    padding: 6px 10px !important;
    border: 1px solid #cbd5e1 !important;
    border-radius: 6px !important;
    background: #f8fafc !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .info-box .box-title {
    font-size: 9px !important;
    margin-bottom: 2px !important;
  }

  .party-name {
    font-size: 14px !important;
  }

  .party-site, .info-box p {
    font-size: 10.5px !important;
    line-height: 1.35 !important;
    margin: 1px 0 !important;
  }

  .highlight-veh {
    background: #e2e8f0 !important;
    font-weight: 700 !important;
    padding: 1px 4px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Table */
  .inv-table {
    margin-bottom: 8px !important;
    font-size: 10.5px !important;
  }

  .inv-table th {
    background: #0f172a !important;
    color: #ffffff !important;
    padding: 5px 8px !important;
    font-size: 10px !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .inv-table td {
    padding: 5px 8px !important;
    font-size: 10.5px !important;
    border-bottom: 1px solid #e2e8f0 !important;
  }

  .inv-table tbody tr:nth-child(even) {
    background: #f8fafc !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .inv-table tfoot td {
    padding: 5px 8px !important;
    font-size: 11px !important;
  }

  .tfoot-total, .tfoot-final {
    background: #f1f5f9 !important;
    border-top: 2px solid #0f172a !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .highlight-total {
    font-size: 13px !important;
    color: #b45309 !important;
  }

  /* Amount in words */
  .amount-words-box {
    padding: 5px 8px !important;
    font-size: 10.5px !important;
    margin-bottom: 8px !important;
    border: 1px dashed #cbd5e1 !important;
    background: #f8fafc !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Bank & Terms */
  .inv-footer-grid {
    display: grid !important;
    grid-template-columns: 1.1fr 1fr !important;
    gap: 10px !important;
    margin-bottom: 12px !important;
  }

  .footer-box {
    padding: 6px 8px !important;
    font-size: 9.5px !important;
    line-height: 1.35 !important;
    border: 1px solid #cbd5e1 !important;
    background: #f8fafc !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .footer-box .box-title {
    font-size: 9px !important;
    margin-bottom: 2px !important;
  }

  /* Signatures */
  .inv-signatures {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 14px !important;
    margin-top: 18px !important;
    padding-top: 0 !important;
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }

  .sign-line {
    height: 1px !important;
    background: #000000 !important;
    margin-bottom: 4px !important;
  }

  .sign-block p {
    font-size: 10px !important;
  }

  .company-sign {
    font-size: 10.5px !important;
  }

  .sub-sign {
    font-size: 9px !important;
  }

  /* Consolidated statement specific */
  .party-bill-bar {
    padding: 6px 10px !important;
    margin-bottom: 8px !important;
  }

  .billed-party .party-title {
    font-size: 15px !important;
  }

  .mini-val {
    font-size: 13px !important;
  }
}
