/* ============================================================================
   mw-print.css — print styling + preview surface for MitWare.

   ONE ruleset, scoped under `.mw-print-surface`, drives three contexts:
     1. the on-screen print-preview <iframe> (DtPrintPreview)
     2. printing that iframe (preview == output)
     3. a direct Ctrl/Cmd+P on the live page — mw-print.ts adds `.mw-print-surface`
        (+ the default opt-* classes) to <body> on `beforeprint` and removes them on
        `afterprint` (see registerDirectPrintSurface).

   `.mw-print-surface` is the wrapper around the cloned page content in the iframe,
   and <body> during a direct print.

   Per-switch modifier classes (DtPrintPreview / PrintOptions toggle these on the
   surface root; presence = hide). Defaults (toolbars / pagination / floating
   buttons hidden) are applied as classes by the dialog and by mw-print.ts.

   Public utility classes (any markup):
     .mw-print-hide   — always omitted from the printout
     .mw-print-only   — hidden on screen, shown only on a print surface
     .mw-print-break  — force a page break before this element
   ============================================================================ */

/* Default margins for any print pass (paged media only — harmless on screen). */
@page {
    margin: 1.5cm;
}

/* Hidden on screen; revealed only on a print surface (rule further down). */
.mw-print-only {
    display: none;
}

/* --- The print surface ---------------------------------------------------- */
/* NOTE: The surface forces a LIGHT MudBlazor palette (scoped to the clone only, never
   the live app) so content prints as dark-on-white paper regardless of the user's
   dark/light mode — otherwise dark-mode light text would vanish on the white sheet. */
.mw-print-surface {
    color-scheme: light;
    color: #1a1a1a;
    --mud-palette-text-primary: #1a1a1a;
    --mud-palette-text-secondary: #555555;
    --mud-palette-text-disabled: #999999;
    --mud-palette-background: #ffffff;
    --mud-palette-surface: #ffffff;
    --mud-palette-divider: #dddddd;
    --mud-palette-lines-default: #dddddd;
}

/* Print true colors, drop screen-only depth cues. */
.mw-print-surface * {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    box-shadow: none !important;
}

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

.mw-print-surface .mw-print-break {
    break-before: page;
}

.mw-print-surface .mw-print-hide {
    display: none !important;
}

/* --- Always-hidden application chrome (no switch) ------------------------- */
/* Present only on the live-page direct-print path; the iframe clone holds page
   content only, so these selectors simply don't match there. */

.mw-print-surface .mud-appbar,
.mw-print-surface .mud-drawer,
.mw-print-surface .mud-drawer-overlay,
.mw-print-surface .mud-overlay,
.mw-print-surface .mud-popover,
.mw-print-surface .mud-snackbar,
.mw-print-surface .mud-scroll-to-top,
.mw-print-surface .background-logo,
.mw-print-surface .mw-window {
    display: none !important;
}

/* Let the page body own the full sheet on the direct-print path. */
.mw-print-surface .mud-layout,
.mw-print-surface .mud-main-content {
    margin: 0 !important;
    padding: 0 !important;
    height: auto !important;
    overflow: visible !important;
}

/* Un-clip internal scroll containers so every rendered row/cell is captured (paired with
   "render all" / disabled virtualization — otherwise a fixed-height overflow:auto box still
   shows only its viewport). */
.mw-print-surface .mw-dg-comp,
.mw-print-surface .mw-dg-container,
.mw-print-surface .mw-dg-compact,
.mw-print-surface .mud-table-container,
.mw-print-surface .mw-sc-scroll-container {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
}

/* Always-hidden non-content affordances. */
.mw-print-surface .mud-table-loading,
.mw-print-surface .mud-table-loading-progress,
.mw-print-surface .mw-dg-resize-handle {
    display: none !important;
}

/* --- Switch: hide toolbars ------------------------------------------------ */
.mw-print-surface.mw-print-opt-no-toolbars .mud-table-toolbar,
.mw-print-surface.mw-print-opt-no-toolbars .mw-dg-toolbar,
.mw-print-surface.mw-print-opt-no-toolbars .mw-dg-filter-panel,
.mw-print-surface.mw-print-opt-no-toolbars .mw-dg-filter-row {
    display: none !important;
}

/* --- Switch: hide pagination ---------------------------------------------- */
.mw-print-surface.mw-print-opt-no-pagination .mud-table-pagination,
.mw-print-surface.mw-print-opt-no-pagination .mud-pagination {
    display: none !important;
}

/* --- Switch: hide floating buttons ---------------------------------------- */
.mw-print-surface.mw-print-opt-no-fabs .mud-fab,
.mw-print-surface.mw-print-opt-no-fabs .mud-fab-menu-container {
    display: none !important;
}

/* --- Switch: hide grid / table headers ------------------------------------ */
.mw-print-surface.mw-print-opt-no-grid-headers .mw-dg-header-row,
.mw-print-surface.mw-print-opt-no-grid-headers .mud-table-head {
    display: none !important;
}

/* --- Switch: black & white ------------------------------------------------ */
.mw-print-surface.mw-print-opt-bw {
    filter: grayscale(1);
}

/* --- Switch: page-break markers ------------------------------------------- */
.mw-print-surface.mw-print-opt-show-breaks .mw-print-break {
    border-top: 2px dashed var(--mud-palette-text-secondary, #999);
}

/* ============================================================================
   Preview sheet — only present inside the DtPrintPreview iframe. mw-print.ts builds
   .mw-pp-iframe-body > .mw-pp-viewport > .mw-pp-sheet > .mw-print-surface > .mw-pp-scale,
   and injects the exact sheet dimensions, content scale, page-break guides, and @page
   rule. These rules are copied into the iframe with the rest of the document stylesheets;
   the @media print block strips the screen-only chrome so the printed iframe == the sheet.
   ============================================================================ */

.mw-pp-iframe-body {
    margin: 0;
    padding: 24px;
    background: #e9e9ee;
}

/* .mw-pp-viewport zoom (preview, view-only) is injected by mw-print.ts. */

.mw-pp-sheet {
    margin: 0 auto;
    background-color: #ffffff;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.28);
    /* width / min-height / page-break guides injected by mw-print.ts */
}

/* .mw-pp-scale zoom (content scale, affects print) is injected by mw-print.ts. */

@media print {
    /* The printed iframe shows only the sheet content — strip the preview chrome. */
    .mw-pp-iframe-body {
        padding: 0;
        background: #ffffff;
    }

    .mw-pp-viewport {
        zoom: 1 !important;
    }

    .mw-pp-sheet {
        margin: 0;
        box-shadow: none;
        background-image: none !important;
    }
}
