/* ═══════════════════════════════════════════════════════════════
   GST Invoice Generator — Print / PDF Preview Styles
   Applied via @media print and when printing from the browser
   ═══════════════════════════════════════════════════════════════ */

@page {
  size: A4 portrait;
  margin: 10mm 10mm 16mm;

  @bottom-left {
    content: "Page " counter(page) " of " counter(pages);
    color: #9ca3af;
    font-size: 7.5pt;
    font-family: "Segoe UI", Arial, sans-serif;
    margin-left: 0mm;
  }
  @bottom-center {
    content: "";
  }
  @bottom-right {
    content: "";
  }
}

@media print {
  /* ── Hide all screen chrome and the invoice form ────────── */
  /* NOTE: .modal is intentionally NOT here — #modal-preview must print */
  #app-screen,
  #login-screen,
  #app-header,
  #app-main,
  #tab-invoice,
  #tab-bar,
  #totals-sidebar,
  #mobile-totals-trigger,
  #mobile-totals-drawer,
  #loading-overlay,
  #notification-bar,
  #invoice-form-area,
  #tab-history,
  #tab-inventory,
  .btn-add-row,
  .btn-remove-row,
  .totals-actions,
  .history-filters,
  [data-no-print],
  #modal-create-customer,
  #modal-confirm-clear,
  #modal-history,
  #modal-return {
    display: none !important;
  }

  body {
    font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    font-size: 9.5pt;
    color: #1f2937;
    background: #ffffff;
    margin: 0;
    padding: 0;
  }

  /* ── Render the invoice preview modal as full-page document ─ */
  #modal-preview {
    position: static !important;
    inset: auto !important;
    background: transparent !important;
    padding: 0 !important;
    display: block !important;
    overflow: visible !important;
    z-index: auto !important;
  }

  .modal-dialog {
    box-shadow: none !important;
    max-width: 100% !important;
    border-radius: 0 !important;
    margin: 0 !important;
    animation: none !important;
  }

  .modal-header { display: none !important; }

  #preview-content {
    max-height: none !important;
    overflow: visible !important;
    padding: 0 !important;
    background: #fff !important;
  }

  /* ── Force print colours ────────────────────────────────── */
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

  /* ── Page breaks ────────────────────────────────────────── */
  .invoice-item-row  { break-inside: avoid; page-break-inside: avoid; }
  .preview-bottom    { break-inside: avoid; }
  .preview-terms     { break-inside: avoid; }
  .preview-footer    { break-inside: avoid; }

  /* ── Table repeating header ─────────────────────────────── */
  table.invoice-items thead { display: table-header-group; }
  table.invoice-items tfoot { display: table-footer-group; }

  table.invoice-items thead tr {
    background: linear-gradient(90deg, #1e40af 0%, #2563eb 100%) !important;
    -webkit-print-color-adjust: exact !important;
  }

  table.invoice-items th { color: #ffffff !important; }

  table.invoice-items tbody tr:nth-child(even) td {
    background: #f8faff !important;
  }

  .row-total { color: #1e40af !important; }

  table.invoice-items tfoot td {
    background: #eff6ff !important;
    color: #1e40af !important;
    border-top: 2px solid #1e40af !important;
  }

  /* ── Preview-specific colours ───────────────────────────── */
  .preview-top-bar {
    background: linear-gradient(135deg, #1e40af 0%, #1d4ed8 60%, #2563eb 100%) !important;
    height: 7pt;
    display: block !important;
  }

  .preview-grand-total { background: #1e40af !important; color: #ffffff !important; }
  .preview-words-text  { border-left: 3pt solid #1e40af !important; }
  .preview-box-header  { background: #1e40af !important; color: #ffffff !important; }
  .preview-terms-header { background: #f3f4f6 !important; }
  .preview-sum-header   { background: #f3f4f6 !important; }

  .preview-gstin-badge {
    background: #eff6ff !important;
    border: 1pt solid #bfdbfe !important;
    color: #1e40af !important;
  }

  /* ── Watermark ──────────────────────────────────────────── */
  .print-watermark {
    position: fixed;
    top: 46%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-28deg);
    font-size: 80pt;
    font-weight: 900;
    letter-spacing: 6pt;
    color: rgba(22, 163, 74, 0.12);   /* PAID — green */
    pointer-events: none;
    z-index: 0;
  }

  .print-watermark-unpaid  { color: rgba(220, 38,  38,  0.10); }  /* UNPAID — red */
  .print-watermark-partial { color: rgba(217, 119, 6,   0.10); }  /* PARTIAL — amber */
}

/* ── Standalone print preview panel ────────────────────────── */
.print-preview-frame {
  background: #fff;
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  padding: 0;
  box-shadow: 0 0 20px rgba(0,0,0,0.15);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  font-size: 9.5pt;
  color: #1f2937;
  position: relative;
}

/* Print preview — top bar accent */
.print-preview-frame .top-bar {
  background: linear-gradient(135deg, #1e40af 0%, #1d4ed8 60%, #2563eb 100%);
  height: 7px;
  width: 100%;
  display: block;
}

/* Items table within print frame */
.print-preview-frame .items {
  width: calc(100% - 28px);
  margin: 0 14px;
  border-collapse: collapse;
}

.print-preview-frame .items thead tr {
  background: linear-gradient(90deg, #1e40af 0%, #2563eb 100%);
}

.print-preview-frame .items th {
  color: #ffffff;
  padding: 5px 4px;
  font-size: 7.5pt;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border-right: 1px solid rgba(255,255,255,0.15);
}

.print-preview-frame .items th:last-child { border-right: none; }

.print-preview-frame .items td {
  padding: 4px 5px;
  font-size: 8.5pt;
  line-height: 1.35;
  vertical-align: top;
  border-bottom: 1px solid #f3f4f6;
}

.print-preview-frame .items tbody tr:nth-child(even) td {
  background: #f8faff;
}

.print-preview-frame .items tfoot td {
  padding: 5px 5px;
  font-size: 8.5pt;
  font-weight: 700;
  background: #eff6ff;
  border-top: 2px solid #1e40af;
  color: #1e40af;
}

/* Column alignments */
.print-preview-frame .right  { text-align: right !important; }
.print-preview-frame .center { text-align: center !important; }
.print-preview-frame .total-cell { font-weight: 700; color: #1e40af; }
.print-preview-frame .item-name  { font-weight: 600; color: #111827; }

/* Summary grand total */
.print-preview-frame .grand-total-row {
  background: #1e40af !important;
  color: #ffffff !important;
  padding: 7px 10px;
  font-size: 11pt;
  font-weight: 800;
}

.print-preview-frame .grand-total-row .s-label {
  color: rgba(255,255,255,0.8) !important;
}

/* Amount in words */
.print-preview-frame .amount-words-text {
  border-left: 3px solid #1e40af;
}

/* Disclaimer */
.print-preview-frame .disclaimer {
  text-align: center;
  font-size: 7pt;
  color: #d1d5db;
  margin-top: 6px;
  padding: 0 14px 10px;
}

/* ── Responsive print preview (screen) ─────────────────────── */
@media screen {
  .print-preview-frame {
    max-width: 100%;
    overflow-x: auto;
  }
}

/* ── Select elements in invoice rows print as plain text ────── */
@media print {
  table.invoice-items select {
    -webkit-appearance: none;
    appearance: none;
    border: none;
    background: transparent;
    padding: 0;
    font-size: inherit;
    font-family: inherit;
    color: inherit;
  }
}
