/* P02 and F4 section 4: the printed page.

   FOUR SURFACES PRINT A SHEET, AND ONLY WHILE THEY CARRY THE MARKER. The register, the class list,
   the class-scoped learner record and the attendance report put `ic-print-root` on their own
   section exactly while a sheet exists. The print block below holds four kinds of rule:
     - one rule for every page, withdrawing the skip link and nothing else (its reason is beside it);
     - the page boxes: A4 and its margins for every page, and a page number that prints only while
       the document holds a marked page; they are not selectors and match no element;
     - rules reached through the marker: the landscape page choice, the page number's exposure, the
       ground, the chrome, the frame's flattened grid, the body and the sheet;
     - rules for the sheet's own `ic-print__` elements, which only a marked page draws.
   So a page without the marker prints as the ordinary screen on A4, with nothing withdrawn but a
   link nobody can see on screen, and nothing recoloured. A print control that yields the screen's chrome
   on paper is worse than none, and so is a stylesheet that quietly strips every other page to make
   these four look right.

   THIS FILE IS LINKED LAST, after every riwaq sheet, so a print rule here that ties a screen rule
   on specificity wins it on order. There is no important flag anywhere in it.

   SCREEN RULES FIRST, THEN ONE PRINT BLOCK THAT RUNS TO THE END OF THE FILE. The guards read the
   block as everything from its opening to the last byte, so a screen rule placed after it would be
   read as print, and a second print block would be read as part of the first. */

/* The sheet is a parallel document beside the page body and is never shown on screen. Its one
   home is here: it used to sit in the shell sheet while the only thing that shows it lived nowhere
   at all. */
.ic-print-sheet { display: none; }

@media print {
    /* THE PAPER. A4 everywhere, because the guard pins it and the market is Danish. The report is
       the one sheet that lies landscape, and it reaches that page only through its own modifier,
       so no other surface can land on it by accident. Symmetric margins, so no side is named: a
       page margin is physical and does not mirror for a printed Arabic or Urdu register.

       A PAGE NUMBER, "PAGE 3 OF 7", IN THE FOOT MARGIN OF EVERY PAGE OF A MARKED SHEET. The engine
       counts the pages, so the number cannot be wrong, and a loose sheet of a forty-learner register
       says where it belongs. The words are the reader's: a stylesheet cannot reach the localiser,
       so PrintFrame hands the translated sentence, with the two counters in the translation's own
       order, to the root element as a custom property, and the margin box reads it from there
       (a page box inherits from the root and from nothing below it). The property is exposed only
       while the document holds a marked page, so an unmarked page, or a label left behind by the
       last sheet, prints no number. The counters are decimal, the digits every other figure on the
       sheet prints in. An engine without page margin boxes prints no number, which is not a wrong
       one. Measured in Chromium 151's PDF, whose named landscape page inherits the box. */
    @page {
        size: A4;
        margin: 14mm 12mm;
        @bottom-center {
            content: var(--ic-print-page, none);
            font-family: var(--rw-font-body);
            font-size: 8.5pt;
            color: #000;
        }
    }
    @page ic-report-landscape { size: A4 landscape; margin: 12mm 12mm; }
    .ic-print-root--landscape { page: ic-report-landscape; }
    html:has(.ic-print-root) { --ic-print-page: var(--ic-print-page-label, none); }

    /* PAPER IS NOT A THEME. White ground and black ink are the only colours this sheet names, and
       they are the recorded exception to token-only colour: the limestone ground costs a masjid
       its toner and the night palette costs it a black page. Scoped to a document that holds a
       marked page, through the has pseudo-class, so a page without the marker keeps whatever it
       prints with today.

       THE HAS PSEUDO-CLASS IS WHAT THIS BLOCK RELIES ON: Chromium 105, Safari 15.4, Firefox 121
       and later. An engine older than those drops every rule below that uses it, and prints the
       sheet in place of the page body (those two rules need nothing new) inside the shell's
       chrome and on the theme's ground. */
    html:has(.ic-print-root),
    html:has(.ic-print-root) body {
        color-scheme: light;
        background: #fff;
        background-image: none;
        color: #000;
    }

    /* THE SKIP LINK, ON EVERY PAGE, AND IT IS THE ONLY RULE HERE THAT REACHES AN UNMARKED ONE. It is
       moved off the screen until it has focus, so a reader never sees it there; on paper it printed
       over the content of every page outside the four (the Task 7 rig's PDFs of the Reports pages
       showed "Skip to content" across a card). Withdrawing it is what makes "an unmarked page prints
       as it is" true. It is not a licence for a wider strip: PrintStylesheetTests allows this one
       selector unscoped, by name, and nothing else. */
    .ic-skip { display: none; }

    /* THE SHELL'S CHROME, WITHDRAWN ONLY BESIDE A MARKED PAGE. The marker is on the page's own
       section, inside the main landmark. The pinned chrome (the support bar, the platform notice
       bands, the header and the offline line, which the layout wraps as one piece), the rail and
       the workspace strip are all drawn by the layout outside that section, so no selector
       descending from the marker can reach them and the document is asked whether it holds one.
       With them go the pieces that sit over or beside a page rather than in it: the menu scrim,
       which is fixed, the development account switcher, the route-loading caption, and the
       unhandled-error bar, which is fixed to the foot of the viewport. The skip link is withdrawn on
       every page, by the rule above. */
    html:has(.ic-print-root) :is(
        .ic-shell__chrome,
        .ic-scrim,
        .ic-side,
        .ic-localnav,
        .ic-devswitch,
        #blazor-error-ui) {
        display: none;
    }

    /* The frame's grid, height floors and gutters, flattened so the sheet starts at the page's own
       margin. The row is a two-column grid on screen, and with the rail withdrawn its first track
       would still hold the page body at the rail's width. A viewport-tall floor in print is a
       blank second page. */
    html:has(.ic-print-root) :is(#app, .ic-shell, .ic-shell__row, .ic-shell__body, .ic-main) {
        display: block;
        min-block-size: 0;
        max-inline-size: none;
        margin: 0;
        padding: 0;
        border: 0;
        background: none;
    }

    /* THE PAGE BODY IS WITHDRAWN AND THE SHEET STANDS IN FOR IT, under the marker and never bare.
       An unscoped reset here would break the screen of every other page to fix the paper for
       one. */
    .ic-print-root .ic-org__inner { display: none; }
    .ic-print-root .ic-print-sheet {
        display: block;
        color: #000;
        background: #fff;
        font-family: var(--rw-font-body);
        font-size: 10.5pt;
        line-height: 1.4;
    }

    /* THE MASTHEAD IS THE FRAME'S. What this paper is, where and when it was true, and the one
       end-side fact beside it. A rule under it, in ink. */
    .ic-print__masthead {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-end;
        justify-content: space-between;
        gap: 2mm 8mm;
        padding-block-end: 2.5mm;
        margin-block-end: 2.5mm;
        border-block-end: 0.6pt solid #000;
    }
    .ic-print__title { margin: 0; font-size: 15pt; font-weight: 700; line-height: 1.25; }
    .ic-print__subline { margin: 0; font-size: 9.5pt; }
    .ic-print__aside { margin: 0; font-size: 10.5pt; font-weight: 700; white-space: nowrap; }

    /* The register's state strip: not yet taken, or taken by whom, and who printed it. Boxed,
       because it is the sentence that keeps a sheet from being read as more than it is. */
    .ic-print__strip {
        margin: 0 0 3mm;
        padding: 2mm 3mm;
        border: 0.6pt solid #000;
        font-size: 9.5pt;
    }

    /* The report's calculation and its caveats, printed with the figures they define. */
    .ic-print__definition { margin: 0 0 2mm; font-size: 9.5pt; max-inline-size: 60rem; }

    /* THE TABLE. Its head is a header group and its foot a footer group, so a sheet longer than a
       page carries its column names and its data-protection line on every page, and the foot sits
       under the last row of each page rather than over it. A row is never cut in half. */
    .ic-print__table {
        inline-size: 100%;
        border-collapse: collapse;
        margin-block: 0 3mm;
        font-variant-numeric: tabular-nums;
    }
    .ic-print__table thead { display: table-header-group; }
    .ic-print__table tbody { display: table-row-group; }
    .ic-print__foot { display: table-footer-group; }
    .ic-print__table tr { break-inside: avoid; }
    /* Toner, not theme: no tint behind a heading cell. Its own rule, ahead of the shared one,
       because PrintStylesheetTests reads the first rule that names a heading cell. */
    .ic-print__table th { background: none; color: #000; font-weight: 700; }
    .ic-print__table th,
    .ic-print__table td {
        padding: 1.8mm 2mm;
        border-block-end: 0.4pt solid #000;
        text-align: start;
        vertical-align: middle;
    }
    .ic-print__table thead th { border-block-end-width: 0.8pt; }

    /* The row number, in its own narrow column. */
    .ic-print__num { inline-size: 8mm; text-align: end; white-space: nowrap; }

    /* A tick box a pen can use: a square in ink, the mark centred in it when the register was
       taken. */
    .ic-print__box { inline-size: 16mm; text-align: center; }
    .ic-print__tick {
        display: inline-block;
        inline-size: 5mm;
        block-size: 5mm;
        border: 0.6pt solid #000;
        line-height: 5mm;
        text-align: center;
        font-size: 9pt;
    }

    /* AN UNMARKED LEARNER PRINTS AS UNMARKED, NEVER AS ABSENT, across the three boxes, in words. */
    .ic-print__unmarked { text-align: center; font-style: italic; }

    /* The note column is the widest on the register, because it is the one a pen fills. */
    .ic-print__note { inline-size: 35%; }

    /* The foot's one cell: the product's name and the data-protection sentence. */
    .ic-print__foot td { border-block-end: 0; border-block-start: 0.6pt solid #000; padding-block: 2mm 0; }
    .ic-print__footer {
        display: flex;
        flex-wrap: wrap;
        justify-content: space-between;
        gap: 1mm 6mm;
        font-size: 8.5pt;
    }
}
