/* ============================================================================
   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-root,
.mw-print-surface .mw-sc-container,
.mw-print-surface .mw-sc-scroll-container {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
}

/* Sticky headers/labels exist for interactive scrolling. With the scroll containers above
   un-clipped, their sticky children re-anchor to the preview iframe's document scrollport and
   ride along while the user scrolls the preview — and the real print pass lays sticky out at
   scroll offset 0 anyway, so the preview would lie. Pin them to their natural flow position.
   `relative` + zeroed offsets (not `static`) so elements that are containing blocks for
   absolutely positioned children (e.g. the scheduler date cells) keep working. */
.mw-print-surface .mw-sc-resource-header,
.mw-print-surface .mw-sc-resource-row-header,
.mw-print-surface .mw-sc-resource-column-header,
.mw-print-surface .mw-sc-date-header,
.mw-print-surface .mw-sc-date-cell,
.mw-print-surface .mw-sc-date-cell-horizontal,
.mw-print-surface .mw-sc-time-header,
.mw-print-surface .mw-sc-time-slot,
.mw-print-surface .mw-sc-time-slot-horizontal,
.mw-print-surface .mw-sc-corner-header,
.mw-print-surface .mw-sc-group-header,
.mw-print-surface .mw-sc-group-header-horizontal,
.mw-print-surface .mw-sc-group-event-row-header,
.mw-print-surface .mw-sc-separator-content,
.mw-print-surface .mw-sc-events-header,
.mw-print-surface .mw-sc-header-resize-divider,
.mw-print-surface .mw-sc-viewport,
.mw-print-surface .mw-sc-cp-corner-header,
.mw-print-surface .mw-sc-cp-header,
.mw-print-surface .mw-sc-cp-separator-content,
.mw-print-surface .mw-sc-cp-header-horizontal,
.mw-print-surface .mw-sc-cp-resource-header-horizontal,
.mw-print-surface .mw-sc-ref-strip,
.mw-print-surface .mw-sc-ref-header,
.mw-print-surface .mw-dg-th,
.mw-print-surface .mw-dg-filter-cell,
.mw-print-surface .mw-gc-corner,
.mw-print-surface .mw-gc-tick,
.mw-print-surface .mw-gc-group-label,
.mw-print-surface .mw-gc-row-label {
    position: relative !important;
    top: 0 !important;
    left: 0 !important;
}

/* The scheduler date labels fake stickiness via JS-set inline top (vertical) / left (horizontal)
   offsets; the clone carries whatever offset the live page was scrolled to — reset to the day start. */
.mw-print-surface .mw-sc-date-cell-content {
    top: 0 !important;
}

.mw-print-surface .mw-sc-date-cell-content-horizontal {
    left: 0 !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 {
    position: relative;
    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 */
}

/* Red "off-page" curtain — covers content that extends past the right page edge (won't print).
   Width (--mw-pp-overflow-w) and the .mw-pp-overflowing toggle are set by markOverflow in mw-print.ts. */
.mw-pp-overflow-curtain {
    display: none;
    position: absolute;
    top: 0;
    left: 100%;
    height: 100%;
    width: var(--mw-pp-overflow-w, 0);
    background: rgba(220, 38, 38, 0.22);
    border-left: 2px dashed rgba(220, 38, 38, 0.8);
    pointer-events: none;
}

.mw-pp-sheet.mw-pp-overflowing .mw-pp-overflow-curtain {
    display: block;
}

/* Numbered page badges at each vertical page boundary (set by remeasure in mw-print.ts);
   makes the automatic downward multi-page pagination visible in the preview. */
.mw-pp-page-label {
    position: absolute;
    right: 6px;
    transform: translateY(6px);
    z-index: 3;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    color: #ffffff;
    background: rgba(70, 70, 85, 0.72);
    pointer-events: none;
}

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

/* Horizontal slicing (setSlicing in mw-print.ts): the content is rebuilt into stacked page-width
   strips, each clipping to one slot-aligned window of the content; the browser paginates the stack
   downward. The sheet-level content-scale zoom is pinned to 1 while sliced (the natural-size
   measurement needs unscaled content); the user scale is applied per strip via zoom on the
   .mw-pp-slice-inner clones instead. */
.mw-pp-scale.mw-pp-sliced {
    zoom: 1 !important;
}

/* The sheet's page-boundary guides assume one continuous flow; with forced breaks per strip the
   real page boundaries are at the strip tops (badged by remeasure) — hide the misleading lines. */
.mw-pp-sheet:has(.mw-pp-sliced) {
    background-image: none !important;
}

.mw-pp-slice {
    position: relative;
    overflow: clip;
}

/* NOTE: contain: strict on the clip boxes (all explicitly sized by mw-print.ts) is load-bearing:
   ANY stray absolutely-positioned element inside the clones that pokes past the page width makes
   Chromium rescale the WHOLE printout by a fixed ~2/3 ("shrink to fit"), and neither
   overflow: hidden/clip nor contain: paint alone stops that detection. */

/* Repeated leading label region (e.g. the scheduler's resource-header column) on strips after the
   first. Absolutely positioned + stretched so the in-flow window drives the strip's height. */
.mw-pp-slice-repeat {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    overflow: clip;
    contain: strict;
}

/* The strip's window onto the content (width + margin-left + height set by mw-print.ts). */
.mw-pp-slice-window {
    overflow: clip;
    contain: strict;
}

/* Rotation (setRotation in mw-print.ts): content-scale zoom is pinned to 1 (the natural-size
   measurement needs unscaled content). The mode is "rotate the paper, not the DOM": upright
   page-height windows of the content (.mw-pp-rot-view > .mw-pp-rot-strip, built like slices via
   per-strip zoom) print on the FLIPPED page orientation; only the on-screen preview rotates each
   strip, via the injected mw-pp-dynamic-rotation style. Chromium misplaces/rescales transformed
   layers in multi-page print output, so the print pass must stay transform-free. */
.mw-pp-scale.mw-pp-rotated {
    zoom: 1 !important;
}

/* .mw-pp-slice-inner width + margin-left (the window offset) are set 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;
        /* Chrome "shrink to fit" rescales the WHOLE printout when anything overflows the page
           horizontally — the preview would lie about the output size. Clip instead, matching the
           red curtain's contract: what hangs off the right page edge does not print. (Vertical
           growth is unaffected — the sheet auto-grows with its content, so downward multi-page
           pagination still works.) */
        overflow: clip;
    }

    /* Preview-only affordances — never print them. */
    .mw-pp-overflow-curtain,
    .mw-pp-page-label {
        display: none !important;
    }
}
