/* The print stylesheet — Kierie's own decision about how PDFs get made.
 *
 * His words: *"option to print/PDF send would be usefull"*, *"print stocktake
 * pdf"*. The brief records that he chose print-ready pages plus the browser's
 * own PDF export over server-side generation, knowingly: no new dependency,
 * works offline on a plant PC, and emailing one means saving it first. That
 * trade is his and this file is the consequence of it.
 *
 * Linked with `media="print"` so **none of it is live on screen**. A print
 * stylesheet behind `@media print` inside `app.css` would be parsed and
 * cascaded on every page load for rules that can never match; worse, a
 * mistake in one of them is invisible until somebody prints. Separate file,
 * separate concern, and `print-preview` in the browser is how it gets
 * checked.
 *
 * ---- It must be legible on a MONO laser ----
 *
 * A plant prints on a monochrome laser, so every rule below assumes colour
 * is absent rather than merely optional:
 *
 *   - Every status that is a colour on screen prints as a **word with a
 *     border**. That is already true of `.wh-pill` on screen (AGENTS.md §2
 *     rule 4: status always carries a word), so printing only has to stop the
 *     tint from becoming an illegible grey fill behind dark text.
 *   - Text is forced to black and backgrounds to white. `--brand-ink` is
 *     #23305E, which a laser renders as a muddy halftone; and a reader who
 *     printed from dark mode would otherwise get white text on white paper,
 *     which is the one failure that wastes a whole toner cartridge before
 *     anybody notices.
 *   - `print-color-adjust: exact` is deliberately NOT used. It tells the
 *     printer to honour backgrounds, which is the opposite of what is wanted
 *     here.
 */

@page {
  size: A4 portrait;
  /* 14 mm, not the browser default of about 12.7 mm: a plant printer with a
   * duplex unit loses a few millimetres at the gripper edge, and a table
   * that reaches the edge of the paper comes back with its last column
   * clipped. */
  margin: 14mm;
}

/* Nothing that is navigation, a control or a transient overlay goes on
 * paper. Listed rather than inverted (`.wh-main *` visible, everything else
 * hidden), because an inverted rule hides the next thing somebody adds —
 * and the thing most likely to be added to a print page is content. */
.wh-header,
.wh-nav,
.wh-footer,
.wh-banner,
.wh-toast,
.wh-skip,
.wh-actions,
.wh-editor,
form,
button,
select,
input,
[data-no-print] { display: none !important; }

/* The print document itself is opted IN, so a screen the operator happened to
 * be on does not print as a half-page of chrome. */
.wh-print { display: block !important; }
.wh-print form,
.wh-print button { display: none !important; }

html, body {
  background: #fff !important;
  color: #000 !important;
  font-size: 10.5pt;
}

body * {
  /* Backgrounds off, text black. See the header: a tinted note block prints
   * as a grey band, and in dark mode it prints as white-on-white. */
  background: transparent !important;
  color: #000 !important;
  box-shadow: none !important;
}

.wh-app { display: block !important; min-height: 0 !important; }
.wh-main { padding: 0 !important; max-width: none !important; }

.wh-card {
  border: 0 !important;
  border-radius: 0 !important;
  padding: 0 !important;
  margin: 0 0 6mm !important;
  /* A card is a logical block — a GRN's lines, a count's variances — and
   * splitting one across a page boundary is what makes a printed document
   * hard to read. `avoid` is a request, not a guarantee, and a table longer
   * than a page will still break; `thead` repeating below is what makes that
   * survivable. */
  break-inside: avoid;
}

h1 { font-size: 16pt; margin: 0 0 2mm; }
h2 { font-size: 12pt; margin: 4mm 0 2mm; break-after: avoid; }
h3 { font-size: 10.5pt; margin: 3mm 0 1mm; break-after: avoid; }

/* ------------------------------------------------------------- the masthead
 *
 * AGENTS.md §2 rule 2: the KPJ credit is on every footer, About, login and
 * firmware page — and a printed document that leaves a building is exactly
 * the place it matters most. It is rendered from `BRAND.credit`, never typed
 * (see `screens.js`'s print screens), so a rename costs one file. */
.wh-print-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8mm;
  border-bottom: 0.4mm solid #000;
  padding-bottom: 3mm; margin-bottom: 5mm;
}
.wh-print-head img { height: 12mm; width: auto; }
.wh-print-meta { text-align: right; font-size: 9pt; line-height: 1.4; }
.wh-print-credit {
  margin-top: 6mm; padding-top: 2mm;
  border-top: 0.2mm solid #000;
  font-size: 8.5pt;
}

/* ----------------------------------------------------------------- tables */

.wh-table-wrap { overflow: visible !important; }

table.wh-table {
  width: 100% !important;
  border-collapse: collapse;
  font-size: 9.5pt;
}
table.wh-table th,
table.wh-table td {
  border: 0.2mm solid #000 !important;
  padding: 1.2mm 1.6mm !important;
  text-align: left;
}
table.wh-table th {
  /* Not a tint — a laser turns a light grey into a dotted halftone behind
   * 9.5 pt text. A rule under the header does the same job in black. */
  font-weight: 700;
  border-bottom-width: 0.4mm !important;
}
table.wh-table .wh-num, table.wh-table th.wh-num { text-align: right; }

/* The one thing that makes a long table printable: the header repeats on
 * every page. Without it, page 2 of a stock count is a grid of numbers with
 * no column names. */
table.wh-table thead { display: table-header-group; }
table.wh-table tfoot { display: table-footer-group; }
table.wh-table tr { break-inside: avoid; }

/* ------------------------------------------------------- status, in words */

/* On screen a pill is a tint plus a word. On paper the tint is gone, so the
 * word needs an outline to still read as a state rather than as stray text.
 * Coral never appears here, on screen or on paper. */
.wh-pill, .wh-flag {
  border: 0.2mm solid #000 !important;
  border-radius: 1mm !important;
  padding: 0.2mm 1.2mm !important;
  font-size: 8.5pt !important;
  font-weight: 600;
}
/* An alarm state gets weight rather than colour — the one visual difference
 * a mono laser can actually carry. */
.wh-pill-alarm { border-width: 0.5mm !important; }

.wh-note {
  border: 0 !important;
  border-left: 0.5mm solid #000 !important;
  padding: 1mm 0 1mm 2.5mm !important;
  margin: 2mm 0 !important;
  font-size: 9pt;
  break-inside: avoid;
}
.wh-muted, .wh-small { color: #000 !important; }
.wh-stat-row { display: flex !important; gap: 6mm !important; flex-wrap: wrap; }
.wh-stat-label { font-size: 8pt !important; font-weight: 700; }
.wh-stat-value { font-size: 12pt !important; }
.wh-empty { font-style: italic; }

/* ------------------------------------------------------------ the labels
 *
 * ---- Only the PAGE and the ink live here. The geometry is in app.css ----
 *
 * The label's size, padding, type scale and flex layout are in `app.css`,
 * under `media="all"`, and that is deliberate rather than untidy.
 *
 * A label is the one thing in this product whose on-screen rendering is
 * supposed to BE the artefact — somebody looks at the preview and decides
 * whether the sizing is right before putting label stock in a printer. Two
 * copies of the geometry, one for the screen and one for paper, is exactly how
 * the preview comes to disagree with the print, and this whole task exists
 * because a label looked fine and printed wrong. So there is one copy, it is
 * live on screen, and what is left in this file is only what paper adds:
 * the `@page` box, and black ink on white.
 *
 * ---- What was wrong, measured in the browser on 16 Nov ----
 *
 * Kierie printed the old labels: *"the stock labels are a bit of a mess. The
 * sizing is all out."* On the 50 x 25 mm size, with this stylesheet switched
 * to `media="all"` and read with `getBoundingClientRect` — COMPUTED figures,
 * not figures off paper:
 *
 *   - The label element was sized to the PAPER (`width:50mm;height:25mm`
 *     inline) while `@page` subtracts its own margin. A 50 x 25 page with a
 *     2 mm margin prints into 46 x 21 mm, so the label was 4 mm too wide and
 *     4 mm too tall for its own page, at every size.
 *   - `grid-template-rows: auto 1fr` put no cap on the fields row. It took its
 *     natural 24.61 mm inside a 20.6 mm box and pushed the barcode row down to
 *     **y = 33.16 mm on a 25 mm label**. `overflow: hidden` then hid the
 *     evidence: the small label printed with NO BARCODE AT ALL.
 *   - At 100 x 50 the same fault cropped the barcode to 6.19 mm of its 14. That
 *     still scans — Code 128 carries its data in the WIDTH and needs height
 *     only to sweep — which is exactly how he could say the barcodes read fine
 *     and the labels were a mess in the same breath.
 *
 * `@page` cannot be scoped to a class, so the size is switched by a body-level
 * data attribute the label screen sets. The page name goes on the BODY rather
 * than on `.wh-label`: a named page on a descendant forces a break where the
 * name changes, which can emit a leading blank sheet of the default A4 page.
 * At the root the whole document is label pages and there is no name change to
 * break on. */

@page wh-100x50  { size: 100mm 50mm;  margin: 3mm; }
@page wh-150x75  { size: 150mm 75mm;  margin: 3mm; }
@page wh-200x100 { size: 200mm 100mm; margin: 3mm; }

body[data-print="label-100x50"]  { page: wh-100x50; }
body[data-print="label-150x75"]  { page: wh-150x75; }
body[data-print="label-200x100"] { page: wh-200x100; }

/* The screen's scroll container must be INERT on paper. `overflow: auto`
 * establishes a scroll container, and a paginated child inside one does not
 * reliably honour `break-after: page` — so a sheet of thirty rack labels
 * could come out as one clipped page. Not a hypothetical: this wrapper only
 * exists because a 200 mm label is 756 px on a 375 px phone, and the fix for
 * the screen must not cost the print. */
.wh-label-sheet {
  display: block !important;
  overflow: visible !important;
  padding: 0 !important;
}

/* One label per page. The LAST one does not force a break after it, or every
 * job ends with a blank label — one wasted sticker is invisible on a sheet of
 * one and obvious on a sheet of thirty. */
.wh-label {
  break-after: page;
  break-inside: avoid;
  /* On paper the die-cut edge of the label stock IS the border, and a printed
   * rule inside it just looks like a mistake. On screen the border is what
   * shows you where the sticker ends, which is the whole point of a preview. */
  border: 0 !important;
  margin: 0 !important;
}
.wh-label:last-child { break-after: auto; }

/* The field captions are at 75% opacity on screen, which reads as a soft grey.
 * A mono laser renders that as a halftone dot screen, and at 2.2 mm it turns
 * to mush. Full black on paper — this is the same decision as `.wh-table th`
 * above, for the same reason. */
.wh-label-fields dt { opacity: 1 !important; }

/* ---------------------------------------- the customer's own branding
 *
 * AGENTS.md §2's rule 5: "Customer branding wins. Where a product shows the
 * customer's own logo and site name, keep it. wozansi is the product; the
 * customer is the site." Stage 5's printables shipped with the wozansi
 * lockup as the masthead and nothing of the customer's on the page at all;
 * this is the correction. See `docs/brand-corrections.md`.
 *
 * Sizes are in mm because this stylesheet is for paper. 16 mm of height is
 * about what a letterhead logo occupies on an A4 page and is small enough
 * that a tall, narrow logo does not push the document title off the first
 * line. `max-width` as well as `max-height`, because a wide wordmark
 * constrained only by height would run into the meta block on the right. */
.wh-print-site { max-width: 110mm; }

/* `.wh-print-head .wh-print-logo`, not `.wh-print-logo` alone: the existing
 * `.wh-print-head img { height: 12mm }` above is specificity (0,1,1) and
 * would beat a bare class at (0,1,0), so a one-class rule here would have
 * had the customer's logo forced to 12 mm with its aspect ratio ignored —
 * `height: auto` losing to the earlier `height`. Two classes is (0,2,0) and
 * wins. Caught by reading the file rather than in the browser, which is
 * where it would otherwise have shown up as a logo that looked wrong only
 * when it was not square. */
.wh-print-head .wh-print-logo {
  max-height: 16mm;
  max-width: 70mm;
  width: auto;
  height: auto;
  display: block;
  margin-bottom: 2mm;
}
.wh-print-company {
  font-size: 12pt;
  font-weight: 600;
  margin-bottom: 1mm;
}

/* The small wozansi mark, beside the KPJ credit at the foot — Kierie's
 * "smaller wozansi logo located somewhere else". It is the SOFTWARE's mark,
 * so it belongs with the software's credit rather than at the head of the
 * customer's document. Rule 2 is untouched: the credit text is still there
 * and a customer logo never displaces it. */
.wh-print-credit { display: flex; align-items: center; gap: 2mm; }
.wh-print-mark {
  height: 4.5mm;
  width: auto;
  /* The mark must survive a mono printer. A flat grey keeps it legible as a
   * shape rather than relying on the brand colours reproducing. */
  filter: grayscale(100%);
}
