/* =============================================
   Global Print Stylesheet
   ---------------------------------------------
   Loaded site-wide (App.razor + index.html). Provides:
     1. Universal @page rules (size, margins) so all printed reports get
        consistent page geometry instead of browser defaults.
     2. Visibility utilities: .print-hide / .print-only.
     3. Page-break utilities: .print-break-before / .print-break-after / .print-break-avoid.
     4. Color preservation across browsers (background colors, gradients, badges).
     5. Sensible default of hiding navigation chrome (sidebar, topbar, toasts).

   Components opt-in by:
     - Wrapping output in <ReportLayout> (preferred), OR
     - Adding the utility classes (.print-hide, .print-break-avoid, etc.) directly.

   Per-page print styles (per-component .razor.css @media print blocks) are
   STILL supported and stack on top of these defaults — so existing reports
   keep working.
   ============================================= */

/* ─── @page geometry ──────────────────────────── */
@page {
    size: A4;
    margin: 1.5cm 1cm 1.5cm 1cm;

    /* Page numbering — visible on every printed page (audit trails, multi-page invoices). */
    @bottom-right {
        content: "Page " counter(page) " of " counter(pages);
        font-size: 9pt;
        color: #666;
    }
}

@page :first {
    /* On the first page leave a bit more room at the top for the brand header */
    margin-top: 1cm;
}

/* ─── Visibility utilities (also active on screen so authors can preview) ── */
.print-only {
    display: none;
}

@media print {
    /* Universal preserveables — keep brand colors/badges/gradients on paper */
    *,
    *::before,
    *::after {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }

    /* Visibility */
    .print-hide,
    .no-print {
        display: none !important;
    }

    .print-only {
        display: revert !important;
    }

    /* Page-break utilities */
    .print-break-before {
        break-before: page;
        page-break-before: always;
    }

    .print-break-after {
        break-after: page;
        page-break-after: always;
    }

    .print-break-avoid {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* Sensible defaults: keep table rows and headings together */
    tr,
    img,
    figure {
        break-inside: avoid;
        page-break-inside: avoid;
    }

    /* Long tables (invoices, ledgers, statements) repeat their thead/tfoot on each page. */
    table {
        border-collapse: collapse;
    }

    thead {
        display: table-header-group;
    }

    tfoot {
        display: table-footer-group;
    }

    h1, h2, h3, h4, h5, h6 {
        break-after: avoid-page;
        page-break-after: avoid;
    }

    /* Widow/orphan control for body text */
    p {
        orphans: 3;
        widows: 3;
    }

    /* Hide app chrome by default — pages can opt back in by removing these classes */
    .app-sidebar,
    .app-topbar,
    .app-footer,
    .global-toast-container,
    .fsh-toast-container,
    .navigation-bar,
    .breadcrumb-nav,
    .page-loading-bar,
    .help-toggle-button {
        display: none !important;
    }

    /* Ensure printed background is plain white regardless of theme */
    html,
    body {
        background: #fff !important;
        color: #000 !important;
    }

    /* Strip scoped scroll containers so content can flow across pages */
    .content-area,
    .table-container,
    main,
    .main-content {
        overflow: visible !important;
        max-height: none !important;
        height: auto !important;
    }

    /* Avoid action / interactive controls bleeding into the printed report */
    button,
    .fsh-btn,
    [role="button"]:not(.print-keep) {
        display: none !important;
    }

    /* Anchors: show URL after link for traceability on paper, except inside reports
       where it would clutter the layout */
    .fsh-report a[href]:not(.print-no-href)::after {
        content: "";
    }

    /* Form inputs print cleanly — preserve the user's value, drop the form chrome */
    input,
    select,
    textarea {
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
        appearance: none;
        -webkit-appearance: none;
    }

    input[type="checkbox"],
    input[type="radio"] {
        accent-color: #000;
    }
}

/* =============================================
   Reduced-motion respect (not strictly print, but a global a11y default)
   ============================================= */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}
