/*!
 * Customer invoice (A4) — presentation layer for sale_pos/receipts/classic.
 *
 * Print-only and scoped to #receipt_section. The template itself is untouched:
 * every field, label and @if still renders exactly as before, this only
 * changes type, spacing, rules and colour. Remove the <link> to get the stock
 * invoice back.
 *
 * Printing constraint that shapes the whole design: Chrome omits background
 * colours unless the person ticks "Background graphics", and that box is off
 * by default. So nothing legible may depend on a fill. Headings, rules and the
 * totals panel are drawn with ink -- text colour and borders -- which always
 * print; the tints are enhancement only. The watermark is an <img> rather than
 * a CSS background for the same reason.
 *
 * Also deliberate: thead { display: table-header-group } repeats the column
 * headings on every page of a long invoice instead of only the first.
 *
 * Sizes and the muted colour are set for PAPER, not for a screen. The first
 * version of this file used 9-11px type and a #6B6484 grey, both of which
 * look right in a print preview on a backlit monitor and come out faint from
 * an actual printer -- worse again from a laser at draft quality, or once the
 * invoice has been photocopied. Nothing here is smaller than 10px and nothing
 * secondary is lighter than #3F3852.
 */

@media print {

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

    #receipt_section {
        --inv-ink:      #1B1230;   /* near-black, warmed toward the brand */

        /* Was #6B6484, which is a perfectly good muted grey on a screen and
           a faint one on paper. Everything secondary on this invoice is
           drawn with it -- the shop's address, the field labels, the
           payments, the notes -- so one screen-weight colour made most of
           the document print pale. Darkened until it reads as ink that
           happens to be quieter, rather than as grey. */
        --inv-muted:    #3F3852;

        /* Row and cell rules. Also lifted: at #E3DFEC they were visible on
           a backlit screen and all but absent on paper, which is what left
           the line items looking like floating text. */
        --inv-line:     #CFC8DE;
        --inv-rule:     #B4AAC9;
        --inv-accent:   #3B1063;   /* deep brand purple */
        --inv-soft:     #F5F2FB;

        font-family: 'DM Sans', 'Hind Siliguri', 'Nirmala UI', system-ui, sans-serif;
        font-size: 12px;
        line-height: 1.55;
        color: var(--inv-ink);

        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    #receipt_section *,
    #receipt_section p,
    #receipt_section td,
    #receipt_section th {
        /* The template hard-codes color:#000 inline on its wrappers */
        color: var(--inv-ink) !important;
    }

    /* ------------------------------------------------------------------
       Watermark
       ------------------------------------------------------------------
       position: fixed makes the mark repeat on every page of a long invoice
       rather than only the first. It is pinned behind the content and kept
       very light so figures stay legible over it; print-color-adjust on the
       section above is what allows it to print at all.
       ------------------------------------------------------------------ */
    #receipt_section img.invoice-watermark {
        position: fixed;
        /* inset + auto margins centre the mark inside the page box. The old
           top/left 50% with a translate put its origin at the page centre and
           pushed the lower half off the sheet, so only part of the logo showed.
           A definite box plus object-fit keeps the whole mark on the page
           whatever aspect ratio the logo happens to have. */
        inset: 0;
        margin: auto;
        width: 105mm;
        height: 105mm;
        max-height: none !important;
        object-fit: contain;
        opacity: .07;
        /* Deliberately 0, not -1: the theme paints an opaque colour on <body>,
           and a negative index would put the mark behind that and lose it
           entirely. The invoice rows are lifted to 1 instead. */
        z-index: 0;
        pointer-events: none;
    }

    #receipt_section > .row {
        position: relative;
        z-index: 1;
    }

    /* The skin gives <body> a grey canvas. Harmless while Chrome strips
       backgrounds, but it would flood the sheet the moment someone ticks
       "Background graphics", so pin it white for print. */
    body {
        background: #fff !important;
    }
    /* ------------------------------------------------------------------
       Masthead
       ------------------------------------------------------------------ */
    #receipt_section img.img-responsive {
        max-height: 74px !important;
        width: auto;
        margin: 0 auto 10px;
    }

    /* Business name */
    #receipt_section h2 {
        font-family: 'Days One', 'Hind Siliguri', 'Nirmala UI', system-ui, sans-serif;
        font-size: 21px;
        font-weight: 400;
        line-height: 1.2;
        letter-spacing: -.01em;
        margin: 0 0 4px;
    }

    /* Address, contact, tax lines */
    #receipt_section h2 + p,
    #receipt_section .col-xs-12.text-center > p {
        font-size: 11px;
        line-height: 1.5;
        color: var(--inv-muted) !important;
        margin: 0 0 2px;
    }
    #receipt_section .col-xs-12.text-center > p small {
        font-size: 11px;
    }

    /* "Invoice" — a label, not a headline, so it sits under the business
       name without competing with it. */
    #receipt_section h3 {
        font-family: 'DM Sans', system-ui, sans-serif;
        font-size: 19px;
        font-weight: 700;
        letter-spacing: .26em;
        text-transform: uppercase;
        color: var(--inv-accent) !important;
        margin: 16px 0 0;
        padding-top: 14px;
        border-top: 2px solid var(--inv-accent);
        display: block;
    }

    /* ------------------------------------------------------------------
       Invoice meta — invoice no / customer on the left, dates on the right
       ------------------------------------------------------------------ */
    /* The two blocks are float-based spans inside one <p>. Flex lays them out
       without relying on float clearing, and keeps them top-aligned. */
    #receipt_section .col-xs-12.text-center > p.word-wrap {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 24px;
        text-align: left;
        font-size: 12px;
        color: var(--inv-ink) !important;
        margin: 18px 0 0;
        padding-bottom: 16px;
        border-bottom: 1px solid var(--inv-line);
    }
    #receipt_section p.word-wrap > span.pull-left,
    #receipt_section p.word-wrap > span.pull-right {
        float: none !important;
        display: block;
    }
    #receipt_section p.word-wrap > span.pull-right {
        text-align: right;
        white-space: nowrap;
    }
    /* Field labels ("Invoice No.", "Customer", "Date") */
    #receipt_section p.word-wrap b,
    #receipt_section p.word-wrap strong {
        font-weight: 600;
        color: var(--inv-muted) !important;
    }

    /* ------------------------------------------------------------------
       Line items
       ------------------------------------------------------------------ */
    #receipt_section table {
        width: 100%;
        border-collapse: collapse;
        margin-bottom: 0;
    }

    /* Headings are drawn with type and a rule, not a filled band. Chrome only
       prints background colours when the user ticks "Background graphics", so
       a purple band with white text disappeared completely for anyone who did
       not -- headings and all. Ink prints in every configuration. */
    #receipt_section table.table-slim > thead > tr > th {
        background-color: transparent;
        color: var(--inv-accent) !important;
        font-size: 10px;
        font-weight: 700;
        letter-spacing: .1em;
        text-transform: uppercase;
        padding: 0 10px 7px;
        border: none;
        border-bottom: 1.5px solid var(--inv-accent);
        vertical-align: bottom;
    }

    /* Alternate rows carry a very light tint. It only appears when the person
       prints backgrounds; the row rules below do the work either way. */
    #receipt_section table.table-slim > tbody > tr:nth-child(even) > td {
        background-color: #FBFAFE;
    }

    #receipt_section table.table-slim > tbody > tr > td {
        padding: 11px 10px;
        border: none;
        border-bottom: 1px solid var(--inv-line);
        vertical-align: top;
    }

    /* Product name carries the weight; the serial/IMEI line below it is meta */
    #receipt_section table.table-slim > tbody > tr > td:first-child {
        font-weight: 500;
    }
    #receipt_section table.table-slim > tbody > tr > td small,
    #receipt_section table.table-slim > tbody > tr > td .text-muted {
        display: inline-block;
        margin-top: 2px;
        font-size: 10px;
        font-weight: 400;
        line-height: 1.4;
        color: var(--inv-muted) !important;
    }

    /* Money and quantities line up only with tabular figures */
    #receipt_section td.text-right,
    #receipt_section th.text-right {
        text-align: right;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
    }

    #receipt_section table.table-slim > tbody > tr:last-child > td {
        border-bottom: 1.5px solid var(--inv-rule);
    }

    /* ------------------------------------------------------------------
       Payments (left) and totals (right)
       ------------------------------------------------------------------ */
    /* The template separates these with a bare <hr>; the totals panel below
       does that job better. */
    #receipt_section .col-md-12 > hr {
        display: none;
    }

    #receipt_section .col-xs-6 {
        padding-top: 14px;
    }

    /* Payments: quiet, it is a record rather than the headline figure */
    #receipt_section .col-xs-6 > table.table-slim > tbody > tr > td,
    #receipt_section .col-xs-6 > table.table-slim > tr > td {
        padding: 4px 0;
        border: none;
        font-size: 11px;
        color: var(--inv-muted) !important;
    }
    #receipt_section .col-xs-6 > table.table-slim td:first-child {
        font-weight: 500;
    }

    /* Totals sit in a tinted panel so the eye lands on them first.
       This table is the one wrapped in .table-responsive. */
    #receipt_section .col-xs-6 > .table-responsive {
        /* The tint only appears when backgrounds print; the border is what
           actually delineates this panel on a default print. */
        background-color: var(--inv-soft);
        border: 1px solid var(--inv-rule);
        border-radius: 4px;
        padding: 4px 12px;
    }
    #receipt_section .col-xs-6 > .table-responsive table.table-slim th,
    #receipt_section .col-xs-6 > .table-responsive table.table-slim td {
        padding: 5px 0;
        border: none;
        border-bottom: 1px solid var(--inv-line);
        font-size: 11px;
        font-weight: 400;
        vertical-align: middle;
    }
    #receipt_section .col-xs-6 > .table-responsive table.table-slim th {
        color: var(--inv-muted) !important;
        text-align: left;
    }

    /* Grand total is the last row of that tbody */
    #receipt_section .col-xs-6 > .table-responsive table.table-slim > tbody > tr:last-child > th,
    #receipt_section .col-xs-6 > .table-responsive table.table-slim > tbody > tr:last-child > td {
        border-bottom: none;
        border-top: 1.5px solid var(--inv-accent);
        padding-top: 10px;
        font-size: 15px;
        font-weight: 700;
        color: var(--inv-accent) !important;
    }
    /* "Total in words" stays small underneath the figure */
    #receipt_section .col-xs-6 > .table-responsive table.table-slim > tbody > tr:last-child small {
        display: block;
        font-size: 10px;
        font-weight: 400;
        font-style: italic;
        white-space: normal;
        color: var(--inv-muted) !important;
    }

    /* ------------------------------------------------------------------
       Tax summary
       ------------------------------------------------------------------ */
    #receipt_section table.table-bordered {
        margin-top: 12px;
    }
    #receipt_section table.table-bordered th,
    #receipt_section table.table-bordered td {
        border: 1px solid var(--inv-line) !important;
        padding: 5px 8px;
        font-size: 10.5px;
    }
    #receipt_section table.table-bordered th {
        background-color: var(--inv-soft);
        font-weight: 600;
        color: var(--inv-muted) !important;
    }

    /* ------------------------------------------------------------------
       Notes, footer, barcode
       ------------------------------------------------------------------ */
    #receipt_section .row:last-child {
        margin-top: 22px;
        padding: 12px 14px;
        background-color: var(--inv-soft);
        border: 1px solid var(--inv-line);
        border-radius: 4px;
        font-size: 11px;
        line-height: 1.6;
        color: var(--inv-muted) !important;
    }
    #receipt_section .row:last-child p {
        color: var(--inv-muted) !important;
        margin: 0;
    }
    #receipt_section .row:last-child img {
        max-width: 100%;
        height: auto;
    }

    /* ------------------------------------------------------------------
       Signature and date
       ------------------------------------------------------------------ */
    /* Two ruled lines with a caption under each. Drawn with borders rather
       than underscores so the rule is the same length whatever the font
       does, and with ink so it survives a print without backgrounds.

       Kept off a page of its own: a signature line stranded alone on page
       two is worse than no signature line. */
    #receipt_section .invoice-signature {
        margin-top: 34px;
        break-inside: avoid;
        page-break-inside: avoid;
    }

    #receipt_section .invoice-signature__rule {
        border-bottom: 1px solid var(--inv-rule);
        /* Long enough to sign across, short enough that the two do not meet
           in the middle of the page. */
        max-width: 210px;
        margin-bottom: 5px;
    }

    #receipt_section .col-xs-6.text-right .invoice-signature__rule {
        margin-left: auto;
    }

    #receipt_section .invoice-signature__label {
        font-size: 10px;
        font-weight: 600;
        letter-spacing: .06em;
        text-transform: uppercase;
        color: var(--inv-muted);
    }

    /* The right-hand caption sits under its own rule, not under the page. */
    #receipt_section .col-xs-6.text-right .invoice-signature__label {
        max-width: 210px;
        margin-left: auto;
    }

    /* ------------------------------------------------------------------
       Pagination behaviour for long invoices
       ------------------------------------------------------------------ */
    #receipt_section thead {
        display: table-header-group;      /* repeat headings on every page */
    }
    #receipt_section tr,
    #receipt_section img {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    /* Never strand the totals panel on a page of its own */
    #receipt_section .col-xs-6 > .table-responsive {
        break-inside: avoid;
        page-break-inside: avoid;
    }
}
