/* =====================================================================
   FATURIM.COM — invoice.css
   Production invoice rendering. Identical across:
     1. Browser preview
     2. Downloaded PDF (via Save as PDF)
     3. Printed paper

   Rules:
   - Uses `mm` for the printable canvas (A4 = 210 × 297mm, 12mm margins)
   - Uses `pt` for font sizes (1pt = 1/72 inch — pixel-perfect)
   - Uses `<table>` layout for ALL multi-column sections (parties, items, totals)
     because flex/grid render inconsistently across print engines.
   - All colored elements force `print-color-adjust: exact`.
   - All number cells use `font-variant-numeric: tabular-nums` so digits align.
   ===================================================================== */

/* ---------- Tokens ---------- */
:root {
    --inv-primary:   #1a5fa8;
    --inv-accent:    #e94560;
    --inv-text:      #1a1a2e;
    --inv-text-mut:  #5b6470;
    --inv-text-lt:   #8a929b;
    --inv-border:    #e1e4ea;
    --inv-bg-soft:   #f5f7fb;
    --inv-bg-notes:  #fff3f5;

    /* Fixed canvas: A4 printable area */
    --inv-canvas-width: 186mm;        /* 210mm − (12mm × 2) */

    /* Font sizes (pt for print stability) */
    --inv-fs-xxs: 7pt;
    --inv-fs-xs:  8pt;
    --inv-fs-sm:  9pt;
    --inv-fs-md:  10pt;
    --inv-fs-lg:  12pt;
    --inv-fs-xl:  16pt;
    --inv-fs-2xl: 22pt;

    --inv-font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --inv-font-num: 'Inter', 'SF Mono', 'Roboto Mono', Consolas, monospace;
}

/* ---------- Page setup (A4) ---------- */
@page {
    size: A4;
    margin: 12mm;
}

/* ---------- Canvas ---------- */
.inv {
    box-sizing: border-box;
    width: var(--inv-canvas-width);
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
    background: white;
    color: var(--inv-text);
    font-family: var(--inv-font);
    font-size: var(--inv-fs-md);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}

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

/* ---------- Header (table layout for stability) ---------- */
.inv-head {
    display: table;
    width: 100%;
    border-collapse: collapse;
    border-bottom: 1.5pt solid var(--inv-border);
    padding-bottom: 6mm;
    margin-bottom: 7mm;
}
.inv-head__brand,
.inv-head__meta {
    display: table-cell;
    vertical-align: top;
    width: 50%;
}
.inv-head__meta {
    text-align: right;
}

.inv-logo {
    display: inline-table;
    border-collapse: collapse;
}
.inv-logo__mark,
.inv-logo__text {
    display: table-cell;
    vertical-align: middle;
}
.inv-logo__mark {
    width: 12mm;
    height: 12mm;
    background: var(--inv-primary);
    color: white;
    text-align: center;
    font-size: var(--inv-fs-xl);
    font-weight: 800;
    border-radius: 2mm;
    line-height: 12mm;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.inv-logo__text {
    padding-left: 3mm;
}
.inv-logo__name {
    font-size: var(--inv-fs-lg);
    font-weight: 700;
    color: var(--inv-text);
    line-height: 1.1;
    letter-spacing: -0.01em;
}
.inv-logo__name span {
    color: var(--inv-primary);
}
.inv-logo__sub {
    font-size: var(--inv-fs-xs);
    color: var(--inv-text-lt);
    margin-top: 0.5mm;
}
.inv-logo__img {
    max-height: 18mm;
    max-width: 60mm;
    width: auto;
    height: auto;
    display: block;
    object-fit: contain;
}

.inv-head__badge {
    display: inline-block;
    background: var(--inv-accent);
    color: white;
    font-size: var(--inv-fs-xxs);
    font-weight: 700;
    letter-spacing: 0.15em;
    padding: 1mm 3mm;
    border-radius: 1mm;
    margin-bottom: 2mm;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.inv-head__no {
    font-size: var(--inv-fs-2xl);
    font-weight: 700;
    color: var(--inv-primary);
    letter-spacing: -0.02em;
    margin-bottom: 1.5mm;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}
.inv-head__dates {
    font-size: var(--inv-fs-sm);
    color: var(--inv-text-mut);
    line-height: 1.7;
}
.inv-head__dates b {
    color: var(--inv-text);
    font-weight: 600;
}
.inv-head__dates .inv-label {
    color: var(--inv-text-lt);
    font-weight: 400;
}

/* ---------- Parties (table layout — bulletproof across engines) ---------- */
.inv-parties {
    display: table;
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    background: var(--inv-bg-soft);
    border: 0.75pt solid var(--inv-border);
    border-radius: 2mm;
    margin-bottom: 7mm;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.inv-party {
    display: table-cell;
    width: 50%;
    vertical-align: top;
    padding: 5mm 6mm;
}
.inv-party + .inv-party {
    border-left: 0.5pt solid var(--inv-border);
    text-align: right;
}
.inv-party__label {
    font-size: var(--inv-fs-xxs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--inv-text-lt);
    margin-bottom: 2.5mm;
}
.inv-party__name {
    font-size: var(--inv-fs-lg);
    font-weight: 700;
    color: var(--inv-text);
    margin-bottom: 1.5mm;
    line-height: 1.3;
    word-wrap: break-word;
}
.inv-party__detail {
    font-size: var(--inv-fs-sm);
    color: var(--inv-text-mut);
    line-height: 1.7;
    word-wrap: break-word;
}
.inv-party__detail b {
    color: var(--inv-text);
    font-weight: 600;
}

/* ---------- Items table ---------- */
.inv-items {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    margin-bottom: 7mm;
    font-size: var(--inv-fs-sm);
}
.inv-items thead {
    display: table-header-group;  /* repeat on every page */
}
.inv-items tbody {
    display: table-row-group;
}
.inv-items thead tr {
    background: var(--inv-primary);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.inv-items th {
    padding: 3mm 3mm;
    font-size: var(--inv-fs-xxs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: white;
    text-align: left;
    vertical-align: middle;
}
.inv-items th.num,
.inv-items td.num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}
.inv-items th.cen,
.inv-items td.cen {
    text-align: center;
}
.inv-items tbody tr {
    page-break-inside: avoid;
    break-inside: avoid;
}
.inv-items tbody tr:nth-child(even) {
    background: #fafbfd;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.inv-items td {
    padding: 3mm 3mm;
    border-bottom: 0.5pt solid var(--inv-border);
    color: var(--inv-text-mut);
    vertical-align: top;
    word-wrap: break-word;
    overflow-wrap: break-word;
}
.inv-items td.desc {
    color: var(--inv-text);
    font-weight: 500;
}
.inv-items td.total {
    color: var(--inv-text);
    font-weight: 700;
}

/* Column widths — locked for A4 */
.inv-items col.c-desc  { width: 32%; }
.inv-items col.c-qty   { width: 9%;  }
.inv-items col.c-unit  { width: 9%;  }
.inv-items col.c-price { width: 13%; }
.inv-items col.c-vat   { width: 8%;  }
.inv-items col.c-vatv  { width: 13%; }
.inv-items col.c-total { width: 16%; }

/* ---------- Summary row (notes left + totals right) ---------- */
.inv-summary {
    display: table;
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    margin-bottom: 7mm;
    page-break-inside: avoid;
    break-inside: avoid;
}
.inv-notes-cell,
.inv-totals-cell {
    display: table-cell;
    vertical-align: top;
}
.inv-notes-cell { width: 55%; padding-right: 6mm; }
.inv-totals-cell { width: 45%; }

.inv-notes {
    border-left: 1mm solid var(--inv-accent);
    background: var(--inv-bg-notes);
    padding: 3mm 4mm;
    border-radius: 0 1.5mm 1.5mm 0;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.inv-notes__title {
    font-size: var(--inv-fs-xxs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--inv-accent);
    margin-bottom: 1.5mm;
}
.inv-notes__text {
    font-size: var(--inv-fs-sm);
    color: var(--inv-text-mut);
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.inv-totals {
    width: 100%;
    border-collapse: collapse;
}
.inv-totals td {
    padding: 2mm 3mm;
    font-size: var(--inv-fs-sm);
    border-bottom: 0.5pt solid var(--inv-border);
    font-variant-numeric: tabular-nums;
}
.inv-totals td.lbl {
    color: var(--inv-text-mut);
    text-align: left;
}
.inv-totals td.val {
    color: var(--inv-text);
    font-weight: 600;
    text-align: right;
}
.inv-totals tr.discount td.lbl,
.inv-totals tr.discount td.val {
    color: var(--inv-accent);
}
.inv-totals tr.grand {
    background: var(--inv-primary);
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.inv-totals tr.grand td {
    padding: 3.5mm 3mm;
    font-size: var(--inv-fs-lg);
    font-weight: 800;
    color: white;
    border-bottom: none;
    letter-spacing: 0.02em;
}

/* ---------- Footer ---------- */
.inv-foot {
    text-align: center;
    padding-top: 5mm;
    border-top: 0.5pt solid var(--inv-border);
    page-break-inside: avoid;
    break-inside: avoid;
}
.inv-foot__thank {
    font-size: var(--inv-fs-lg);
    font-weight: 600;
    color: var(--inv-primary);
    margin-bottom: 1mm;
}
.inv-foot__brand {
    font-size: var(--inv-fs-xs);
    color: var(--inv-text-lt);
}

/* =====================================================================
   PRINT MEDIA — final overrides (max specificity, most reliable)
   ===================================================================== */
@media print {
    html, body {
        background: white !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    .inv {
        width: var(--inv-canvas-width) !important;
        max-width: 100% !important;
        margin: 0 auto !important;
        padding: 0 !important;
        box-shadow: none !important;
        border-radius: 0 !important;
    }

    /* Force colored elements to print in color */
    .inv-logo__mark,
    .inv-head__badge,
    .inv-parties,
    .inv-items thead tr,
    .inv-items tbody tr:nth-child(even),
    .inv-notes,
    .inv-totals tr.grand {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Repeat table headers, prevent broken rows */
    .inv-items { page-break-inside: auto; }
    .inv-items thead { display: table-header-group; }
    .inv-items tr,
    .inv-summary,
    .inv-foot { page-break-inside: avoid; break-inside: avoid; }
}

/* =====================================================================
   SCREEN ONLY — preview chrome
   ===================================================================== */
@media screen {
    .inv-screen-wrap {
        background: #eef1f8;
        min-height: 100vh;
        padding: 6mm 4mm;
    }
    .inv {
        box-shadow: 0 4px 24px rgba(0,0,0,0.08);
        padding: 14mm;
        border-radius: 2mm;
    }
}
@media screen and (max-width: 800px) {
    .inv-screen-wrap { padding: 0; }
    .inv {
        width: 100%;
        padding: 6mm 4mm;
        border-radius: 0;
    }
    .inv-head__no { font-size: 18pt; }
}
