/* ================================================
   TALLY LEGACY — Classic Tally ERP 9 GST Invoice
   ================================================ */

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0; background: #fff;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 10px; color: #000;
}

/* ── OUTER WRAPPER fills A4 ── */
.tally-invoice {
    width: 100%;
    flex: 1;                /* fills #invoicePreview container on screen */
    min-height: 277mm;      /* A4 - 10mm top - 10mm bottom margins */
    display: flex;
    flex-direction: column;
    border: 1px solid #000;
}

/* ── TOP BAR: doc type + original copy ── */
.ti-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 3px 10px;
    border-bottom: 1px solid #000;
    background: #f0f0f0;
    font-size: 9px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── HEADER TABLE ── */
.ti-head-table {
    width: 100%; border-collapse: collapse;
    border-bottom: 1px solid #000;
}
.ti-head-table td { vertical-align: top; }
.ti-head-left {
    width: 60%;
    padding: 8px 10px;
    border-right: 1px solid #000;
}
.ti-head-right {
    width: 40%;
    padding: 0;
}
.ti-company-name { font-size: 16px; font-weight: 800; color: #000; margin-bottom: 3px; }
.ti-company-sub  { font-size: 11px; line-height: 1.65; color: #111; }
.ti-logo { width: 70px; height: 70px; object-fit: contain; flex-shrink: 0; }
.ti-head-company { display: flex; align-items: flex-start; gap: 10px; }

/* Invoice meta cells in a mini-table */
.ti-meta-table { width: 100%; border-collapse: collapse; height: 100%; }
.ti-meta-table td {
    padding: 6px 8px; vertical-align: top;
    border-bottom: 1px solid #ccc; border-left: 1px solid #ccc;
    font-size: 10px; line-height: 1.5;
}
.ti-meta-table tr:last-child td { border-bottom: none; }
.ti-meta-k { font-size: 9px; color: #555; margin-bottom: 1px; }
.ti-meta-v { font-weight: 700; font-size: 11px; }

/* ── PARTY SECTION ── */
.ti-party-table {
    width: 100%; border-collapse: collapse;
    border-bottom: 1px solid #000;
}
.ti-party-table td { vertical-align: top; padding: 7px 10px; font-size: 10px; line-height: 1.6; }
.ti-party-left  { width: 55%; border-right: 1px solid #000; }
.ti-party-right { width: 45%; }
.ti-party-section-label {
    font-size: 8.5px; font-weight: 700;
    text-transform: uppercase; color: #555;
    border-bottom: 1px solid #ddd; margin-bottom: 4px; padding-bottom: 2px;
}

/* ── ITEMS TABLE ── */
.ti-items {
    width: 100%; border-collapse: collapse;
    font-size: 9.5px;
}
.ti-items thead { display: table-header-group; }
.ti-items thead tr { background: #e8e8e8; }
.ti-items th {
    padding: 5px 3px; text-align: center;
    font-size: 8.5px; font-weight: 700;
    border: 1px solid #999;
    text-transform: uppercase;
}
.ti-items td {
    padding: 4px 3px; vertical-align: top;
    border-bottom: 1px solid #ccc;
    border-right: 1px solid #ccc;
}
.ti-items td:last-child { border-right: none; }
.ti-items tbody tr:nth-child(even) td { background: #f8f8f8; }
.ti-items tbody tr { page-break-inside: avoid; }

/* Filler rows to fill blank space in items table */
.ti-filler-row td { height: 18px; border-bottom: 1px solid #e0e0e0; border-right: 1px solid #ccc; }
.ti-filler-row td:last-child { border-right: none; }
.ti-filler-row:last-child td { border-bottom: none; }

/* ── TOTALS TABLE (separate from items) ── */
.ti-totals-table {
    width: 100%; border-collapse: collapse;
    border-top: 2px solid #000;
    border-bottom: 1px solid #000;
}
.ti-totals-table td { padding: 4px 6px; vertical-align: middle; }

/* Sub-total rows */
.ti-subtotal-row td {
    background: #f0f0f0;
    font-style: italic; font-size: 10px;
    border-bottom: 1px solid #ccc;
}
.ti-grand-row td {
    border-top: 2px solid #000;
    background: #000;
    color: #fff;
    font-weight: 700; font-size: 11px;
}

/* ── BOTTOM GROUP: pushed to end of page ── */
.ti-bottom { margin-top: auto; page-break-inside: avoid; break-inside: avoid; }

/* ── AMOUNT IN WORDS ── */
.ti-words {
    padding: 5px 10px; font-size: 9.5px;
    border-bottom: 1px solid #000;
    background: #fafafa;
    page-break-inside: avoid;
}

/* ── HSN SUMMARY ── */
.ti-hsn-section { border-bottom: 1px solid #000; page-break-inside: avoid; }
.ti-hsn-title { padding: 3px 10px; font-size: 8.5px; font-weight: 700; text-transform: uppercase; background: #ececec; border-bottom: 1px solid #ccc; }
.ti-hsn { width: 100%; border-collapse: collapse; font-size: 9px; }
.ti-hsn thead { display: table-header-group; }
.ti-hsn thead tr { background: #e0e0e0; }
.ti-hsn th { padding: 4px 5px; border: 1px solid #999; font-weight: 700; text-align: center; }
.ti-hsn td { padding: 3px 5px; border: 1px solid #ccc; }
.ti-hsn tfoot tr { background: #e0e0e0; font-weight: 700; }

/* ── BANK + QR + SIGN row ── */
.ti-footer-row {
    display: flex;
    border-bottom: 1px solid #000;
    page-break-inside: avoid;
}
.ti-bank-col {
    flex: 1; padding: 7px 10px;
    border-right: 1px solid #000;
    font-size: 9.5px; line-height: 1.65;
}
.ti-bank-entry { margin-top: 4px; padding-top: 4px; border-top: 1px dashed #bbb; }
.ti-bank-entry:first-child { border-top: none; padding-top: 0; margin-top: 3px; }
.ti-qr-col {
    width: 130px;
    border-right: 1px solid #000;
    padding: 7px 6px;
    text-align: center;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
}
#upiQR { margin: 0 auto 3px; }
.ti-qr-lbl { font-size: 8.5px; font-weight: 700; }
.ti-qr-amt { font-size: 9.5px; font-weight: 700; }
.ti-sign-col {
    width: 185px;
    padding: 7px 10px;
    display: flex; flex-direction: column;
    justify-content: space-between;
    font-size: 10px; text-align: right;
}
.ti-sign-space { flex: 1; min-height: 30px; }

/* ── DECLARATION ── */
.ti-decl {
    padding: 6px 10px; font-size: 9px;
    line-height: 1.5; border-bottom: 1px solid #000;
    background: #fafafa;
    page-break-inside: avoid;
}

/* ── HELPERS ── */
.r { text-align: right; }
.c { text-align: center; }

/* ── PRINT ── */
@media print {
    @page { size: A4 portrait; margin: 8mm; }
    html, body { margin: 0 !important; padding: 0 !important; background: #fff !important; }
    #invoicePreview { padding: 0 !important; }
    .tally-invoice { min-height: 277mm; border: 1px solid #000; }
    .ti-words, .ti-hsn-section, .ti-footer-row, .ti-decl { page-break-inside: avoid; }
}
