/* Loading-lane sticker print stylesheet (S0L, design note D1b L2).

   The repo's FIRST print stylesheet, loaded AFTER portal-overrides.css
   (App.razor). Scope discipline (view-layer rule): every selector here
   either names the sticker page's OWN classes - label-sheets, labels-chrome,
   sheet-*, sticker-* - which NO other stylesheet styles, or hides the app
   chrome for printing via body:has(.label-sheets), so the print output of
   every other portal page is untouched. :has() is supported by every
   browser the office runs.

   Geometry facts this file encodes (D1b L2):
   - A4 sticker sheets, 105 x 48 mm grid: 2 columns x 6 rows = 12 cells,
     210 mm wide, 6 x 48 = 288 mm + 2 x 4.5 mm page margin = 297 mm.
   - Thermal: ONE label per page via named @page sizes, one class per
     preset from the page's fixed list; only the non-refused preset ever
     renders (the narrow-stock refusal happens server-side, before any
     sticker markup exists).
   - The barcode SVG carries its own explicit mm width/height attributes
     (Code128Svg); nothing here may scale it, or the X-dimension math the
     scannability rests on would be silently undone. */

/* ── screen preview: minimal sheet borders only ───────────────────── */

.label-sheets {
    margin-top: 1rem;
}

/* The subset controls (D1b L2's "any subset" promise): screen chrome
   inside .labels-chrome, hidden at print with the rest of it. Another of
   the page's OWN class names, styled only here (scope discipline above). */
.labels-subset {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
    border: 1px solid #9996;
    padding: 0.5rem;
}

.sheet-a4 {
    display: grid;
    grid-template-columns: 105mm 105mm;
    grid-auto-rows: 48mm;
    width: 210mm;
    page: a4labels;
}

.sticker,
.sticker-blank {
    box-sizing: border-box;
    padding: 3mm;
    overflow: hidden;
    break-inside: avoid;
    /* A sticker is white stock with black ink wherever it renders: the
       portal's dark theme would otherwise swallow the black bars in the
       on-screen preview, and print gets the exact contrast the scanner
       math assumes. */
    background: #fff;
    color: #000;
}

/* Height discipline (cross-slice repair 2026-08-21): the cell is FIXED and
   overflow: hidden clips at its edge, so a Mode A line with a source lot
   plus several declared dates used to push the LAST rows - the ordinal and
   the revision stamp, the stale-tray defence - silently off the printed
   sticker. The sticker is a flex column whose only shrinkable region is
   the facts block: when content exceeds the cell, FACTS clip (and the
   page's screen-only height warning names the affected lines), while the
   head, product, barcode, code and meta rows always print. */
.sticker {
    display: flex;
    flex-direction: column;
}

.sticker-head,
.sticker-product,
.sticker-code,
.sticker-meta {
    flex-shrink: 0;
}

/* The barcode keeps its exact mm geometry: never shrunk (X-dimension math)
   and never stretched across the flex cross axis. */
.sticker > svg {
    flex-shrink: 0;
    align-self: flex-start;
}

.sticker-facts-block {
    flex-shrink: 1;
    min-height: 0;
    overflow: hidden;
}

@media screen {
    .sticker {
        outline: 1px dashed #999;
    }
    .sticker-blank {
        outline: 1px dotted #ccc;
    }
}

/* The heavy divider opening each line's run - the bench discipline that
   prevents cross-line mis-stickering at the source (pick line 7's boxes,
   sticker from the line-7 run, move on). */
.sticker-first {
    border-top: 1.2mm solid #000;
}

.sticker-head {
    margin: 0 0 1mm;
    font-size: 14pt;
    font-weight: 700;
    line-height: 1.1;
}

.sticker-product {
    margin: 0 0 1mm;
    font-size: 11pt;
    line-height: 1.15;
}

.sticker-facts {
    margin: 0;
    font-size: 9pt;
    line-height: 1.2;
}

.sticker-code {
    margin: 0.5mm 0 0;
    font-size: 8pt;
    font-family: ui-monospace, Consolas, monospace;
}

/* A5 (2026-08-23): the §7.4 manual code moved INTO the sticker-head (the
   unit sticker's top line is "Kod: 7012" now) - the extra .sticker-manual
   row is gone and the height stack matches the pre-§7.4 arithmetic. */

.sticker-meta {
    margin: 0.5mm 0 0;
    font-size: 9pt;
    display: flex;
    justify-content: space-between;
    gap: 2mm;
}

.sticker-stamp {
    font-size: 8pt;
}

/* ── thermal: one label per page, per-preset named pages ──────────── */

.sheet-thermal .sticker {
    break-after: page;
}

.sheet-thermal-100x50 {
    page: thermal100x50;
}
.sheet-thermal-100x50 .sticker {
    width: 100mm;
    height: 50mm;
}
@page thermal100x50 {
    size: 100mm 50mm;
    margin: 0;
}

/* 100x150 courier stock cut into three 100x50 stickers: the page breaks
   after every THIRD sticker (owner request at the client, 2026-08-26).
   border-box keeps the run divider's border-top inside the 50 mm, so
   3 x 50 fills the 150 mm page exactly. */
.sheet-thermal-100x150 {
    page: thermal100x150;
}
.sheet-thermal-100x150 .sticker {
    width: 100mm;
    height: 50mm;
    break-after: auto;
}
.sheet-thermal-100x150 .sticker:nth-child(3n) {
    break-after: page;
}
@page thermal100x150 {
    size: 100mm 150mm;
    margin: 0;
}

.sheet-thermal-80x50 {
    page: thermal80x50;
}
.sheet-thermal-80x50 .sticker {
    width: 80mm;
    height: 50mm;
}
@page thermal80x50 {
    size: 80mm 50mm;
    margin: 0;
}

/* The two narrow presets exist so the REFUSAL is real and testable
   (D11): Code 128 at the camera-safe X-dimension does not fit them, and
   the page refuses server-side before any sticker renders. The rules
   stay for the day a payload short enough arrives. */
.sheet-thermal-58x40 {
    page: thermal58x40;
}
.sheet-thermal-58x40 .sticker {
    width: 58mm;
    height: 40mm;
}
@page thermal58x40 {
    size: 58mm 40mm;
    margin: 0;
}

.sheet-thermal-57x32 {
    page: thermal57x32;
}
.sheet-thermal-57x32 .sticker {
    width: 57mm;
    height: 32mm;
}
@page thermal57x32 {
    size: 57mm 32mm;
    margin: 0;
}

@page a4labels {
    size: A4;
    margin: 4.5mm 0;
}

/* ── print: only the stickers, nothing else ───────────────────────── */

@media print {
    /* Hide the app shell ONLY while a label-sheets page prints; other
       pages' printing is untouched because :has() misses them.
       .side-panel is the layout's WRAPPER around .side-nav (cross-slice
       repair 2026-08-21): hiding only the nav left the wrapper's 1px
       app.css border printable on the default page, and the named-page
       sheets (page: a4labels / thermalNNxNN) forced a page break after
       it - a leading junk page on every job, one wasted sheet of label
       stock. */
    body:has(.label-sheets) .app-bar,
    body:has(.label-sheets) .side-panel,
    body:has(.label-sheets) .side-nav,
    body:has(.label-sheets) .labels-chrome {
        display: none;
    }

    /* The shell's layout paddings would shift the mm grid off the label
       stock; flatten them for the sticker page only. */
    body:has(.label-sheets) .app-main,
    body:has(.label-sheets) .page-shell,
    body:has(.label-sheets) .card {
        margin: 0;
        padding: 0;
        border: none;
        box-shadow: none;
    }

    .label-sheets {
        margin: 0;
    }

    .sticker {
        outline: none;
    }
}
