/* html2pdf (ledger + supplier statement exports) renders these templates
   via html2canvas in normal document flow, not the browser print engine —
   so this rule must live outside @media print. Combined with the
   `pagebreak: {mode:['css','avoid-all']}` option in export.js, this stops
   a table row from being sliced in half across a PDF page boundary. */
#pdf-ledger-content tr,
#pdf-supplier-content tr {
  page-break-inside: avoid;
}

/* Invoice Print Document styles */
.inv-doc {
  background: #fff; max-width: 480px; margin: 16px auto; padding: 0; border-radius: 10px;
  box-shadow: 0 4px 28px rgba(26,22,19,0.14); overflow: hidden; border: 1px solid var(--line);
}
.inv-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 22px 24px; background: linear-gradient(135deg, var(--ink) 0%, #2a231d 100%);
}
.inv-brand { display: flex; align-items: center; gap: 12px; }
.inv-logo { width: 52px; height: 52px; border-radius: 50%; object-fit: contain; background: #fff; border: 2px solid var(--gold); flex-shrink: 0; padding: 2px; }
.inv-brand-name { font-family: Georgia, serif; font-size: 19px; letter-spacing: 0.5px; color: var(--gold-light); font-weight: 700; }
.inv-brand-tag { font-size: 9px; color: #b8a888; letter-spacing: 0.8px; text-transform: uppercase; margin-top: 2px; }
.inv-doc-type { text-align: right; font-size: 10px; color: #b8a888; text-transform: uppercase; letter-spacing: 1.5px; }
.inv-doc-num { font-size: 17px; font-weight: 700; color: var(--gold-light); margin-top: 2px; }

.inv-body { padding: 22px 24px 6px; }

.inv-meta {
  display: flex; justify-content: space-between; gap: 14px; margin-bottom: 18px; font-size: 12.5px;
  background: var(--cream-2); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
}
.inv-meta-block div { margin-bottom: 4px; }
.inv-meta-block div:last-child { margin-bottom: 0; }
.inv-meta-lbl { color: var(--text-dim); font-size: 10px; text-transform: uppercase; letter-spacing: 0.4px; margin-right: 4px; }
.inv-meta-val { font-weight: 700; color: var(--ink); }

.inv-totals { margin-left: auto; width: 65%; font-size: 13px; border-top: 1.5px solid var(--line); padding-top: 8px; margin-bottom: 4px; }
.inv-totals-row { display: flex; justify-content: space-between; padding: 5px 2px; color: var(--text-dim); }
.inv-totals-row span:last-child { color: var(--ink); font-weight: 600; }
.inv-totals-row.grand {
  border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); margin-top: 6px;
  padding: 10px 8px; font-weight: 700; font-size: 15.5px; color: var(--ink); background: var(--gold-light);
  border-radius: 6px; margin-left: -8px; margin-right: -8px;
}
.inv-totals-row.grand span { color: var(--ink) !important; }
.inv-totals-row.balance-row { padding: 8px 2px 2px; }
.inv-totals-row.balance-row span:last-child { color: var(--red); font-weight: 700; font-size: 14.5px; }

.inv-foot { display: flex; justify-content: space-between; margin-top: 30px; padding: 18px 24px 4px; border-top: 1px dashed var(--line); font-size: 11px; }
.inv-sign-block { text-align: center; }
.inv-sign-name { font-weight: 700; font-size: 12.5px; color: var(--ink); border-bottom: 1.5px solid var(--ink); padding-bottom: 5px; margin-bottom: 4px; min-width: 120px; }
.inv-sign-label { color: var(--text-dim); font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.5px; }

.inv-shop-foot {
  margin-top: 6px; padding: 14px 24px 20px; background: var(--cream-2);
  font-size: 10px; color: var(--text-dim); text-align: center; line-height: 1.7; border-top: 1px solid var(--line);
}
.inv-thanks { text-align: center; font-family: Georgia, serif; color: var(--gold-dark); font-size: 13.5px; padding-top: 14px; letter-spacing: 0.6px; font-style: italic; }

.print-actions { display: flex; gap: 10px; padding: 16px; max-width: 480px; margin: 0 auto; }

/* Print-only footer strip: printed date/time. Hidden on screen, shown
   only inside @media print below. Populated by JS right before
   window.print() is called (see invoices.js). */
.inv-print-meta { display: none; }

/* ── Print: show ONLY the invoice document ───────────────────────
   Mobile Safari's print (via the share-sheet) renders the page as-is,
   so without this rule it prints the whole app underneath — topbar,
   dashboard content, bottom nav, other hidden panels/sheets.
   Approach: hide every top-level sibling except the invoice panel,
   using display:none (not visibility) so no leftover blank space or
   scroll-container artifacts show up in mobile print previews. */
@media print {
  /* Force background colors/gradients to actually print. Without this,
     Chrome/Firefox/Safari all strip background-color and background-image
     by default in print - the dark invoice header, gold totals highlight,
     and dark table header row would otherwise come out blank/white. */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  html, body { background: #fff !important; margin: 0 !important; padding: 0 !important; height: auto !important; }

  #pinScreen, .topbar, #main-content, .bottom-nav,
  .sheet, .sheet-overlay {
    display: none !important;
  }
  /* Hide every panel-overlay except the invoice print panel */
  .panel-overlay:not(#invoice-print-panel) {
    display: none !important;
  }
  #invoice-print-panel {
    display: block !important;
    position: static !important;
    inset: auto !important;
    background: #fff !important;
    overflow: visible !important;
    min-height: 0 !important;
  }
  #invoice-print-panel .panel-top,
  #invoice-print-panel .print-actions {
    display: none !important;
  }

  /* Reset the mobile-preview card (480px, rounded corners, shadow) so the
     invoice fills the printable A4 area edge-to-edge instead of printing
     as a small box in the corner of the page. */
  #pdf-content {
    position: static !important;
    box-shadow: none !important;
    border: none !important;
    border-radius: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    margin: 0 !important;
  }
  #invoice-print-panel .container { padding: 0 !important; margin: 0 !important; max-width: 100% !important; }

  /* Auto page-break protection: never let a table row, the totals block,
     or the signature footer split across two pages. */
  .inv-tbl { page-break-inside: auto; }
  .inv-tbl thead { display: table-header-group; }
  .inv-tbl tr { page-break-inside: avoid; page-break-after: auto; }
  .inv-totals, .inv-foot, .inv-shop-foot { page-break-inside: avoid; }

  .inv-print-meta {
    display: block !important;
    margin-top: 10px;
    padding: 6px 24px;
    font-size: 9px;
    color: #8a7f70;
    text-align: center;
    border-top: 1px dashed var(--line);
  }

  @page {
    size: A4;
    margin: 12mm;
  }
}
