/* ============================================================
   Paper.

   What two printed documents have in common: the sheet format,
   the preview laid on a grey background, the action bar that
   does not print, and the @media print rule that strips the
   application all around.

   What a document says is its own and lives in its own
   stylesheet — order-form.css for the order form,
   news-sheet.css for the news. Nothing here speaks of any
   content: no product-range colour, no amount column.

   The file is written in millimetres and ignores the
   application theme: a document must come out identical from
   two browsers and two themes. That is also why it depends on
   no MudBlazor variable.
   ============================================================ */

/* --- The sheet ---

   An A4. What it carries inside — margins, body text, line
   spacing — belongs to the document: two sheets of the same
   size are not read at the same pace. */
.paper {
    box-sizing: border-box;
    margin: 0 auto;
    background: #ffffff;
    color: #14181d;
    font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}

/* --- Fitting to the page ---

   A sheet that runs a few millimetres past its A4 is scaled down as a whole, by the factor
   paper.fit() computes (js/print.js) — 1 everywhere else. The zoom shrinks everything,
   format included, so the format is divided by the same factor: the box stays an A4. */
.paper {
    --paper-fit: 1;

    width: calc(210mm / var(--paper-fit));
    min-height: calc(297mm / var(--paper-fit));
    zoom: var(--paper-fit);
}

.paper *,
.paper *::before,
.paper *::after {
    box-sizing: inherit;
}

/* --- On-screen preview: the sheet sits on a background, with a subtle shadow.
       None of this prints, the @media print rule takes it back. --- */
.paper-frame {
    background: #eceef1;
    padding: 20px;
    overflow: auto;
}

.paper-frame .paper {
    box-shadow: 0 1px 3px rgba(18, 22, 32, .12), 0 8px 24px rgba(18, 22, 32, .08);
    border: 1px solid #dfe3e8;
}

/* --- Scaled-down preview in an editor ---

   The scale, and nothing else. Shrinking sizes one by one would give a preview that lies about
   line breaks, hence about the page count — and that is precisely what one is looking at.

   "zoom" rather than "transform: scale()": the transform only shrinks the drawing, not the
   box. The sheet kept occupying its 210 mm in the layout, and the frame — 380 px wide —
   offered a horizontal scrollbar to go and look at empty space. Zoom shrinks the box itself:
   no more overflow, no more negative margin to compensate, and a two-page document stays
   correct (a fixed margin only compensated for one page).

   The factor is computed so an A4 fits in an editor column: 210 mm equal 793 px, reduced to
   357 px, which leaves room for the vertical scrollbar. */
.paper-compact {
    --paper-scale: .45;

    zoom: calc(var(--paper-scale) * var(--paper-fit));
}

/* Fallback for browsers without "zoom": back to the transform, but the origin moves to the
   top left and negative margins take back the room the box keeps. */
@supports not (zoom: 1) {
    .paper-compact {
        transform: scale(var(--paper-scale));
        transform-origin: top left;
        margin: 0 calc(-210mm * (1 - var(--paper-scale))) calc(-297mm * (1 - var(--paper-scale))) 0;
    }
}

/* ============================================================
   Printing. It is the intended output: the rest is only a
   preview.

   The portal does not produce PDFs server-side — it lays out
   a sheet, and lets the browser's print dialog render it:
   "Destination: Save as PDF". The resulting file is exactly
   what one has in front of one's eyes, which a second layout
   to maintain would not
   guarantee.
   ============================================================ */
@media print {
    @page {
        size: A4 portrait;
        /* Zero margin: the sheet's own margins make the margin, otherwise they add up to the
           browser's and the document spills over by one page. */
        margin: 0;
    }

    /* Everything that does not belong to the sheet disappears. The first two lines apply to
       the whole application: a top bar and a navigation menu never have any business on
       paper, and printing them was already wrong before these documents. */
    .mud-appbar,
    .mud-drawer,
    .no-print {
        display: none !important;
    }

    /* The content takes the whole page once the menu is removed: otherwise, the margin
       MudBlazor reserves for the drawer would shift the sheet to the right. */
    .mud-main-content {
        margin: 0 !important;
        padding: 0 !important;
    }

    body {
        background: #fff;
    }

    .print-page {
        margin: 0;
        padding: 0;
    }

    .paper-frame {
        background: none;
        padding: 0;
        overflow: visible;
    }

    /* The frame's own selector too: ".paper-frame .paper" outweighs ".paper", and its border
       and shadow printed around the sheet. */
    .paper,
    .paper-frame .paper {
        box-shadow: none;
        border: 0;
        width: auto;
        min-height: auto;
        margin: 0;

        /* Rules, badges and coloured headings are part of the document: without this rule,
           browsers strip them "to save ink" and the hierarchy
           collapses. */
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .paper-compact {
        zoom: var(--paper-fit);
        transform: none;
        margin: 0;
    }
}

/* ============================================================
   The action bar of a print page. It does not print: it
   carries no-print.
   ============================================================ */
/* Screen only: written after the @media print block, this rule used to win there too. On
   paper, 100vh is the page itself, and a document held at exactly one page height is one
   rounding away from a second, blank sheet. */
@media screen {
    .print-page {
        min-height: 100vh;
        background: #eceef1;
    }
}

.paper-bar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: #fff;
    border-bottom: 1px solid #dfe3e8;
    font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
    font-size: 13px;
}

.paper-bar-name {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-weight: 500;
    color: #14181d;
}

.paper-bar-name .numeric {
    font-family: "IBM Plex Mono", ui-monospace, Consolas, monospace;
    font-size: 11px;
    color: #5d646f;
}

/* A bar that carries choices — a range of versions, a language — and not only a name: it
   wraps rather than pushing the print button out of the window. */
.paper-bar-wrap {
    flex-wrap: wrap;
    row-gap: 6px;
}

.paper-bar-wrap .mud-select {
    flex: 0 0 auto;
}

/* What is not published, or not translated, must be visible before the sheet goes out to a
   customer. */
.paper-warning {
    padding: 2px 8px;
    border: 1px solid #d8a94b;
    border-radius: 3px;
    background: #fdf6e7;
    color: #8a5610;
    font-size: 11.5px;
    font-weight: 500;
}
