/*
 * Sudantam invoice / receipt / credit-note / statement sheet.
 * ONE stylesheet shared by: the in-app preview, the print window (Save as PDF) and the patient-portal PDF.
 *
 * Page-fit rules (why this file exists):
 *  - The sheet is exactly as tall as its content. It is NOT stretched to a page, centred, or padded to A4 -
 *    that made it taller than one page and produced a blank first page and a stray footer page.
 *  - Paper size/margins are decided by the printing context (print window: @page margin; PDF: html2pdf margin),
 *    so the same sheet fits A4 and US Letter.
 *  - Long invoices flow onto more pages cleanly: table headings repeat, rows never split, and the closing block
 *    (terms + signature + contact line) always travels together with the payments block.
 */
.invoice-preview-wrap{overflow:auto;background:#f3f5f7;padding:8px}
.billing-sheet{box-sizing:border-box;width:210mm;margin:0 auto;background:#fff;color:#111;padding:0;font-family:Arial,Helvetica,sans-serif;font-size:10.8px;line-height:1.25}
.invoice-paper{box-sizing:border-box;border:1px solid #173f78;background:#fff;position:relative}
.invoice-header{min-height:32mm;box-sizing:border-box;border-bottom:1px solid #173f78;display:flex;justify-content:space-between;align-items:center;gap:6mm;padding:3mm 5.5mm}
.invoice-brand{display:flex;align-items:center;min-width:0}
.invoice-brand-logo{width:78mm;height:27mm;object-fit:contain;object-position:left center}
.invoice-doctor{max-width:70mm;text-align:right;font-size:10.6px;line-height:1.5}.invoice-doctor strong{font-size:12px}
.invoice-title{min-height:9mm;border-bottom:1px solid #173f78;display:flex;align-items:center;justify-content:center;gap:2mm;font-size:18px;font-weight:700;letter-spacing:.2px;background:#e8f1fb;color:#173f78;box-sizing:border-box}
.invoice-body{padding:2mm 2mm 0;box-sizing:border-box}
.invoice-meta{margin:0 0 2.2mm;border:1px solid #9aa2aa;display:grid;grid-template-columns:1fr 1fr;grid-auto-rows:minmax(6.8mm,auto)}
.invoice-meta .cell{padding:1.4mm 2mm;border-bottom:1px solid #c9ced3;break-inside:avoid;overflow-wrap:anywhere}
.invoice-meta .cell:nth-child(odd){border-right:1px solid #c9ced3}.invoice-meta .cell:nth-last-child(-n+2){border-bottom:0}
.invoice-meta b{font-weight:700;margin-right:1.5mm}.invoice-status{text-align:right}
.invoice-status-badge{display:inline-block;margin-left:1mm;padding:.7mm 2mm;border-radius:2mm;background:#62c48a;color:#fff;font-weight:700;line-height:1.1}
.invoice-section-title{background:#e8eef5;border:1px solid #b7c0ca;border-bottom:0;padding:1.2mm 2mm;font-weight:700;font-size:10.5px;color:#173f78;break-after:avoid;page-break-after:avoid}

/* ---- tables: one column layout per table kind (the payments table no longer inherits the services widths) ---- */
.invoice-table{width:100%;border-collapse:collapse;table-layout:fixed;font-size:10px}
.invoice-table th,.invoice-table td{box-sizing:border-box;border:1px solid #9aa2aa;padding:1.8mm 1.5mm;vertical-align:middle;overflow-wrap:anywhere}
.invoice-table th{background:#173f78;color:#fff;font-weight:700;text-align:center}
.invoice-table thead{display:table-header-group}
.invoice-table tr{break-inside:avoid;page-break-inside:avoid}
/* services: # | service | tooth | qty | rate | amount */
.t-services th:nth-child(1){width:6%}.t-services th:nth-child(2){width:44%}.t-services th:nth-child(3){width:10%}.t-services th:nth-child(4){width:7%}.t-services th:nth-child(5){width:16%}.t-services th:nth-child(6){width:17%}
.t-services td:nth-child(1),.t-services td:nth-child(3),.t-services td:nth-child(4){text-align:center}.t-services td:nth-child(5),.t-services td:nth-child(6){text-align:right;white-space:nowrap}
/* services with GST: # | service | tooth | qty | rate | HSN/SAC | GST | amount */
.t-services-gst th:nth-child(1){width:5%}.t-services-gst th:nth-child(2){width:30%}.t-services-gst th:nth-child(3){width:9%}.t-services-gst th:nth-child(4){width:6%}.t-services-gst th:nth-child(5){width:15%}.t-services-gst th:nth-child(6){width:11%}.t-services-gst th:nth-child(7){width:7%}.t-services-gst th:nth-child(8){width:17%}
.t-services-gst td:nth-child(1),.t-services-gst td:nth-child(3),.t-services-gst td:nth-child(4),.t-services-gst td:nth-child(6),.t-services-gst td:nth-child(7){text-align:center}.t-services-gst td:nth-child(5),.t-services-gst td:nth-child(8){text-align:right;white-space:nowrap}
/* payments: receipt | date | mode | reference | amount */
.t-payments th:nth-child(1){width:27%}.t-payments th:nth-child(2){width:15%}.t-payments th:nth-child(3){width:19%}.t-payments th:nth-child(4){width:21%}.t-payments th:nth-child(5){width:18%}
.t-payments td:nth-child(2){text-align:center;white-space:nowrap}.t-payments td:nth-child(5){text-align:right;white-space:nowrap}
/* statement: date | type | ref | details | charges | credits | balance */
.t-statement th:nth-child(1){width:12%}.t-statement th:nth-child(2){width:14%}.t-statement th:nth-child(3){width:19%}.t-statement th:nth-child(4){width:25%}.t-statement th:nth-child(5),.t-statement th:nth-child(6),.t-statement th:nth-child(7){width:10%}
.t-statement td:nth-child(5),.t-statement td:nth-child(6),.t-statement td:nth-child(7){text-align:right;white-space:nowrap}

.invoice-financial{margin-top:2.2mm;border:1px solid #9aa2aa;display:grid;grid-template-columns:1fr 1.15fr;min-height:22mm;break-inside:avoid;page-break-inside:avoid}
.invoice-words{padding:2.5mm;border-right:1px solid #9aa2aa;align-self:center}.invoice-totals{padding:1mm 2mm}
.invoice-total-row{display:flex;justify-content:flex-end;gap:4mm;padding:1mm 0}.invoice-total-row span:first-child{min-width:32mm;text-align:right}.invoice-total-row strong{min-width:30mm;text-align:right}
.invoice-total-grand{font-size:12px;font-weight:700;border-top:1px solid #444;margin-top:1mm;padding-top:1.4mm;background:#173f78;color:#fff;margin-left:-2mm;margin-right:-2mm;padding-left:2mm;padding-right:2mm}
.pay-qr-print{display:flex;gap:12px;align-items:center;margin:2.5mm 0 0;font-size:11px;line-height:1.4;break-inside:avoid;page-break-inside:avoid}
.invoice-payment{margin-top:2.5mm;border:1px solid #9aa2aa;break-inside:avoid;page-break-inside:avoid;break-after:avoid;page-break-after:avoid}
.invoice-payment-head{display:grid;grid-template-columns:1fr 1fr;background:#e8eef5;border-bottom:1px solid #b7c0ca;font-weight:700;color:#173f78}
.invoice-payment-head div,.invoice-payment-grid div{padding:1.5mm 2mm}
.invoice-payment-grid{display:grid;grid-template-columns:1fr 1fr;grid-auto-rows:minmax(7.5mm,auto)}
.invoice-payment-grid>div:nth-child(odd){border-right:1px solid #c9ced3}.invoice-payment-grid>div:nth-child(-n+2){border-bottom:1px solid #c9ced3}.invoice-payment-grid b{font-weight:700;margin-right:1.5mm}.invoice-payment-grid .right{text-align:right}
.invoice-payment .invoice-table{border:0}

/* Closing block: terms + signature + contact line stay together and never end up alone on a page. */
.invoice-end{break-inside:avoid;page-break-inside:avoid}
.invoice-footer{margin-top:4mm;box-sizing:border-box;border-top:1px solid #9aa2aa;display:grid;grid-template-columns:1fr 1fr;background:#fff}
.invoice-footer>div{padding:2mm 2.5mm}.invoice-footer>div:first-child{border-right:1px solid #c9ced3}
.invoice-footer h4{margin:0 0 1.2mm;font-size:11px;color:#173f78}.invoice-footer ol{margin:0;padding-left:4.5mm}.invoice-footer li{margin:0 0 .75mm}
.signature{text-align:center}.signature-line{width:50mm;border-bottom:1px solid #555;margin:8mm auto 0}
.invoice-contact-footer{margin-top:3mm;box-sizing:border-box;border-top:1px solid #173f78;background:#fff;display:flex;flex-direction:column;justify-content:center;align-items:center;font-size:8.6px;line-height:1.35;color:#173f78;padding:1.5mm 2mm;text-align:center}
.invoice-contact-footer .address{font-weight:600}.invoice-contact-footer .contacts{font-weight:500}

/* Dense mode: automatically applied to invoices with many rows so that they still fit one page. */
.billing-sheet.dense{font-size:10px}
.dense .invoice-header{min-height:24mm;padding:2mm 5mm}.dense .invoice-brand-logo{width:62mm;height:20mm}
.dense .invoice-title{min-height:7.5mm;font-size:16px}
.dense .invoice-meta{grid-auto-rows:minmax(5.8mm,auto);margin-bottom:1.6mm}.dense .invoice-meta .cell{padding:1mm 2mm}
.dense .invoice-table{font-size:9.4px}.dense .invoice-table th,.dense .invoice-table td{padding:1mm 1.3mm}
.dense .invoice-financial{min-height:0;margin-top:1.6mm}.dense .invoice-total-row{padding:.6mm 0}
.dense .invoice-payment{margin-top:1.8mm}.dense .invoice-payment-grid{grid-auto-rows:minmax(6mm,auto)}
.dense .invoice-footer{margin-top:2.5mm}.dense .signature-line{margin-top:5mm}.dense .invoice-contact-footer{margin-top:2mm}
.dense .pay-qr-print{margin-top:1.6mm}


@media(max-width:800px){.invoice-preview-wrap{overflow:auto}}
