/* ==========================================================================
   Print-only page styles. Loaded via PrintLayout.razor for routes such as
   /Cart/{QuoteNumber}/Print. Designed to look identical on screen and on
   paper — the on-screen view IS the preview. No app chrome.
   ========================================================================== */

html,
body {
    margin: 0;
    padding: 0;
}

/* Visual reset lives on .print-page (not html/body) so this stylesheet is safe to
   load app-wide — the inline cart-print view (CartPage "Save Quote and Print")
   pulls it in on the main app. The standalone PrintLayout page is unaffected: its
   content is inside .print-page. */
.print-page {
    max-width: 8.5in;
    margin: 0.5in auto;
    padding: 0 0.25in;
    background: #fff;
    color: #000;
    /* Pin to light so the quote always renders/prints black-on-white regardless of
       the app's dark/light theme (data-bs-theme). Without this, .print-page inherits
       color-scheme: dark in dark mode, which some browsers' print engines honor for
       default backgrounds/controls. */
    color-scheme: light;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 11pt;
    line-height: 1.35;
}

/* ----- Header ------------------------------------------------------------- */
.print-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid #000;
    padding-bottom: 0.5em;
    margin-bottom: 1em;
}

.print-header__brand img {
    height: 56px;
    width: auto;
}

.print-header__brand h1 {
    font-size: 14pt;
    margin: 0.25em 0 0;
    font-weight: 700;
}

.print-header__meta {
    text-align: right;
    font-size: 10pt;
}

.print-header__meta dt {
    font-weight: 700;
    display: inline-block;
    min-width: 8em;
    text-align: right;
    margin-right: 0.5em;
}

.print-header__meta dd {
    display: inline-block;
    margin: 0;
}

.print-header__meta div {
    margin-bottom: 0.15em;
}

/* ----- Account / ship-to block ------------------------------------------- */
.print-account {
    display: flex;
    justify-content: space-between;
    gap: 1em;
    margin-bottom: 1em;
    font-size: 10pt;
}

.print-account__block {
    flex: 1;
}

.print-account__block h2 {
    font-size: 10pt;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 0.25em;
    border-bottom: 1px solid #999;
    padding-bottom: 0.15em;
}

.print-account__block p {
    margin: 0;
    line-height: 1.3;
}

/* ----- Line items table -------------------------------------------------- */
.print-items {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1em;
    font-size: 10pt;
}

.print-items thead {
    /* Repeat header on every printed page */
    display: table-header-group;
}

.print-items th,
.print-items td {
    border: 1px solid #999;
    padding: 4px 6px;
    text-align: left;
    vertical-align: top;
}

.print-items th {
    background: #eee;
    font-weight: 700;
    font-size: 9.5pt;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.print-items td.numeric,
.print-items th.numeric {
    text-align: right;
    white-space: nowrap;
}

.print-line-item {
    page-break-inside: avoid;
    break-inside: avoid;
}

.print-line-item__details {
    background: #fafafa;
    font-size: 9pt;
}

.print-line-item__details dl {
    margin: 0;
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.15em 1em;
}

.print-line-item__details dt {
    font-weight: 700;
    color: #444;
}

.print-line-item__details dd {
    margin: 0;
}

.print-line-item__memo {
    font-style: italic;
    color: #444;
    font-size: 9pt;
}

/* ----- Totals ------------------------------------------------------------ */
.print-totals {
    width: 50%;
    margin-left: auto;
    border-collapse: collapse;
    font-size: 10pt;
}

.print-totals td {
    padding: 4px 6px;
    border-top: 1px solid #999;
}

.print-totals .grand-total td {
    border-top: 2px solid #000;
    font-weight: 700;
    font-size: 11pt;
}

.print-totals td.numeric {
    text-align: right;
}

/* ----- Footnotes --------------------------------------------------------- */
.print-footnotes {
    margin-top: 1.5em;
    font-size: 9pt;
    color: #444;
    border-top: 1px solid #ccc;
    padding-top: 0.5em;
}

.print-footnotes p {
    margin: 0.25em 0;
}

/* ----- On-screen-only fallback "Print" button ---------------------------- */
.print-actions {
    text-align: right;
    margin-bottom: 0.75em;
}

.print-actions button {
    padding: 6px 14px;
    border: 1px solid #333;
    background: #f5f5f5;
    cursor: pointer;
    font-size: 10pt;
}

/* ----- Error state (cart/quote mismatch) --------------------------------- */
.print-error {
    border: 1px solid #c33;
    background: #fdeceb;
    color: #6a1f1c;
    padding: 1em;
    margin: 1em 0;
}

/* ----- Blazor unhandled-error banner ------------------------------------- */
/* PrintLayout renders the #blazor-error-ui div but doesn't pull in the app's
   main stylesheet, so without this rule the placeholder shows permanently on
   every print page (even with no error). Hidden by default; Blazor sets an
   inline `display:block` when an actual unhandled exception occurs, which
   overrides this rule. */
#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: #000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* The print portal is a print-only clone of .print-page (created by printQuote()
   in custom.js) — never shown on screen. Declared BEFORE @media print so the
   print-time `display: block` override wins (media queries don't add specificity,
   so source order decides between equal-specificity #print-quote-portal rules). */
#print-quote-portal {
    display: none;
}

/* ==========================================================================
   Print-only adjustments (when actually printing)
   ========================================================================== */
@media print {
    /* Force background colors / borders to render */
    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .print-page {
        margin: 0;
        padding: 0;
        max-width: none;
    }

    .print-actions,
    .no-print,
    #blazor-error-ui {
        display: none !important;
    }

    /* Hyperlinks: drop the ":after content" pattern that some browsers add */
    a[href]:after {
        content: none !important;
    }

    /* Avoid widow/orphan splits on important blocks */
    .print-header,
    .print-account,
    .print-totals {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Inline cart-print view (CartPage "Save Quote and Print"): print ONLY the
       quote, not the app chrome (nav/footer/etc.). printQuote() (custom.js) clones
       .print-page into a body-level #print-quote-portal and adds body.printing-quote
       for the duration of window.print(). We hide every other direct child of body
       and show the portal — so the quote prints from the TOP of page 1 (no leading
       gap from the hidden-but-space-occupying app chrome) and multi-page content
       flows naturally. Gated on body.printing-quote so other pages are unaffected. */
    body.printing-quote > *:not(#print-quote-portal) {
        display: none !important;
    }

    #print-quote-portal {
        display: block !important;
    }

    #print-quote-portal .print-page {
        margin: 0;
        padding: 0;
        max-width: none;
    }
}
