/* ==========================================================================
   Cane Agency — Specification document shell
   A4 print docs: running header w/ brand logo, screen-only nav, content kit.
   Consumes Cane Agency DS tokens (colors/typography/spacing must be linked).
   ========================================================================== */

/* Device reading-scale policy (MANDATED, project-wide) — SINGLE SOURCE:
   shared/reading-scale.css. Never restate a scale here or in a document. */
@import url("../../shared/reading-scale.css");

/* Body-container policy (MANDATED, project-wide) — SINGLE SOURCE:
   shared/layout.css. Never restate a container width here or in a document. */
@import url("../../shared/layout.css");

doc-page:not(:defined) { visibility: hidden; }

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--text);
  font-size: var(--fs-base);
  line-height: var(--lh-relaxed);
}

/* ---- Screen-only spec navigation ---------------------------------------- */
.spec-nav {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 12px;
  height: 40px;
  padding: 0 0 0 16px;
  background: var(--cane-900);
  border-bottom: 1px solid var(--cane-800);
}
/* No brand mark or wordmark here: the project bar (shared/site-nav.js) carries
   the branding for every surface. This row shows the SECTION only (A-104). */
.spec-nav__title {
  font-family: var(--font-display);
  font-weight: var(--fw-semibold);
  font-size: var(--fs-sm);
  letter-spacing: var(--ls-wide);
  color: var(--neutral-0);
  white-space: nowrap;
}
a.spec-nav__title { text-decoration: none; }
a.spec-nav__title:hover { color: var(--gold-200); }
.spec-nav__links { display: flex; align-self: stretch; align-items: stretch; margin-left: auto; }
.spec-nav__links a {
  display: flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  text-decoration: none;
  color: var(--cane-100);
  padding: 0 12px;
}
.spec-nav__links a:hover { background: var(--cane-800); color: var(--neutral-0); }
.spec-nav__links a.is-current {
  background: var(--gold-400);
  color: var(--cane-950);
  font-weight: var(--fw-bold);
}
.spec-nav__theme {
  display: flex;
  align-self: stretch;
  align-items: stretch;
  margin-left: -12px; /* cancel the nav's gap so the toggle sits flush right */
  border-left: 1px solid var(--cane-800);
}
.spec-nav__theme button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--cane-200);
  cursor: pointer;
}
.spec-nav__theme button:hover { background: var(--cane-800); color: var(--neutral-0); }
.spec-nav__theme button.is-active { background: var(--cane-800); color: var(--gold-300); }
.spec-nav__theme svg { width: 16px; height: 16px; display: block; }

doc-page h2 { scroll-margin-top: 56px; }
@media print { .spec-nav { display: none; } }

/* ---- Language switcher (EN | ไทย; injected by spec-lang.js) -------------- */
.spec-nav__lang {
  display: flex;
  align-self: stretch;
  align-items: stretch;
  margin-left: -12px; /* cancel the nav's gap so groups sit flush */
  border-left: 1px solid var(--cane-800);
}
.spec-nav__lang button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  padding: 0 10px;
  border: none;
  background: transparent;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  color: var(--cane-200);
  cursor: pointer;
}
.spec-nav__lang button:hover { background: var(--cane-800); color: var(--neutral-0); }
.spec-nav__lang button.is-active {
  background: var(--gold-400);
  color: var(--cane-950);
  font-weight: var(--fw-bold);
}

/* ---- Bilingual content (EN primary, TH translation) ----------------------
   Pair language-specific content as .l-en / .l-th siblings; anything
   unwrapped (IDs, numbers, Thai domain terms, code) is language-neutral.
   html[data-lang] is applied by shared/lang.js (default: en). */
html[data-lang="th"] .l-en { display: none !important; }
html:not([data-lang="th"]) .l-th { display: none !important; }

/* ---- Document-series docnav (e.g. PRD series; sits between nav & subnav) - */
.spec-docnav {
  position: sticky;
  top: 40px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px;
  height: 32px;
  padding: 0 16px;
  background: var(--cane-950);
  border-bottom: 1px solid var(--cane-800);
}
.spec-docnav__area {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps);
  color: var(--cane-300);
  white-space: nowrap;
}
.spec-docnav__links {
  display: flex;
  align-self: stretch;
  align-items: stretch;
  flex-wrap: wrap;
  scrollbar-width: none;
}
.spec-docnav__links::-webkit-scrollbar { display: none; }
.spec-docnav__links a {
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--cane-100);
  text-decoration: none;
  white-space: nowrap;
}
.spec-docnav__links a:hover { background: var(--cane-800); color: var(--neutral-0); }
.spec-docnav__links a.is-current {
  background: var(--gold-400);
  color: var(--cane-950);
  font-weight: var(--fw-bold);
}
/* Set-apart entry: platform infrastructure, not a capacity (e.g. FED).
   Design policy: set-apart docnav items are signalled by the divider (.spec-docnav__sep)
   + a subtle color shift ONLY — never a leading bullet/dot glyph. */
.spec-docnav__sep {
  flex: none;
  align-self: center;
  width: 1px;
  height: 15px;
  margin: 0 6px;
  background: var(--cane-700);
}
.spec-docnav__links a.is-infra { color: var(--cane-200); }
/* Code-only labels; full name revealed as a hover popover */
.spec-docnav__links a[data-tip] { position: relative; }
.spec-docnav__links a[data-tip]::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%) translateY(-2px);
  padding: 4px 9px;
  background: var(--cane-950);
  color: var(--neutral-0);
  border: 1px solid var(--cane-700);
  border-radius: 5px;
  font-family: var(--font-sans);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-medium);
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
  box-shadow: 0 4px 14px rgba(0,0,0,.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity .12s ease, transform .12s ease;
  z-index: 60;
}
.spec-docnav__links a[data-tip]:hover::after,
.spec-docnav__links a[data-tip]:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
body:has(.spec-docnav) doc-page h2 { scroll-margin-top: 88px; }
@media print { .spec-docnav { display: none; } }

/* ---- Running header / footer (repeat on every printed page) ------------- */
.spec-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  /* A qualified code ("PROP-050 · FIELD & CROP COST ACCOUNTING") is wider than
     the space left beside the lockup. Wrap the meta block onto its own line
     rather than let it collide with the rev line or push past the sheet —
     applies at every width, print included, so a printed header never clips. */
  flex-wrap: wrap;
  gap: 2px 16px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--cane-600);
  background: var(--surface);
}
.spec-head__logo { height: 30px; display: block; flex: 0 0 auto; }
/* Letterhead branding is for PAPER. On screen the project bar already carries the
   mark and wordmark, so the printed lockup is withheld and the header keeps its
   code + revision only (A-104: branding appears once per page). */
@media screen { .spec-head__logo { display: none; } }
.spec-head__meta { text-align: right; min-width: 0; margin-left: auto; }
.spec-head__code {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  color: var(--cane-700);
  /* Breaks at the · separators only; spec-fit.js pins single-token codes. */
  text-wrap: balance;
}
.spec-head__rev {
  display: block;
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--text-muted);
}
.spec-foot {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--text-muted);
  background: var(--surface);
}

/* ---- Title block --------------------------------------------------------- */
.spec-eyebrow {
  margin: 18px 0 0;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps);
  color: var(--gold-600);
}
h1 {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: var(--fw-bold);
  line-height: var(--lh-tight);
  letter-spacing: var(--ls-tight);
  color: var(--cane-900);
  margin: 6px 0 18px;
}
.spec-meta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  margin: 0 0 30px;
}
.spec-meta > div { background: var(--surface-2); padding: 7px 12px; min-width: 0; }
/* Metadata label colour: --text, not --text-muted. On the --surface-2 panel the
   muted step measured 4.26:1 in light at --fs-2xs, under the 4.5:1 WCAG AA floor
   for normal text (dark was already compliant at ~9:1). A semantic alias is used
   rather than a raw neutral step or a light-only override, because the aliases
   flip per theme and a raw step would fail dark; --text clears AA in BOTH themes
   with no theme-specific branching. The label stays distinct from its dd by
   FORM — mono family, --fs-2xs, uppercase, --ls-caps — and not by colour.
   Colour only: no size, weight, spacing, wording or structure is changed. */
.spec-meta dt {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps);
  color: var(--text);
  margin: 0 0 2px;
}
.spec-meta dd {
  margin: 0;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-strong);
  overflow-wrap: break-word;
}
/* A pill used as a meta value may carry a long status sentence — let it wrap
   instead of forcing its 1fr column wider than the sheet. */
.spec-meta dd .pill { white-space: normal; }

/* ---- Headings & body ------------------------------------------------------ */
h2 {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-snug);
  color: var(--cane-800);
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin: 34px 0 12px;
}
h3 {
  font-family: var(--font-display);
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
  margin: 22px 0 8px;
}
p { margin: 0 0 12px; }
ul, ol { margin: 0 0 14px; padding-left: 22px; }
li { margin-bottom: 4px; }
strong { font-weight: var(--fw-semibold); color: var(--text-strong); }

doc-page a { color: var(--primary); text-underline-offset: 2px; }

.mono {
  font-family: var(--font-mono);
  font-size: 0.92em;
  font-variant-numeric: tabular-nums lining-nums;
  color: var(--cane-700);
}

/* ---- Tables ---------------------------------------------------------------- */
table.spec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-sm);
  line-height: var(--lh-snug);
  margin: 0 0 18px;
}
.spec-table th {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps);
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  text-align: left;
  padding: 4px 14px 4px 0;
  border-bottom: 1.5px solid var(--border-strong);
}
.spec-table td {
  padding: 5px 14px 5px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.spec-table th:last-child,
.spec-table td:last-child { padding-right: 0; }
.spec-table td.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums lining-nums;
  text-align: right;
  white-space: nowrap;
}
.spec-table .id {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--cane-700);
  /* Wrap long labels (e.g. ERD relationship phrases) at spaces, but never
     break inside a token: rev numbers (1.0), dates and codes stay whole.
     Use .id--code to pin a multi-word code that must not wrap at all. */
  white-space: normal;
  overflow-wrap: normal;
  word-break: keep-all;
}
.spec-table .id--code { white-space: nowrap; }
.spec-table .nb { white-space: nowrap; }
.spec-table .id--wrap { white-space: normal; }
.spec-table td.date {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-variant-numeric: tabular-nums lining-nums;
  white-space: nowrap;
}

/* ---- Pills ------------------------------------------------------------------ */
.pill {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-wide);
  padding: 1px 7px;
  border-radius: 2px;
  white-space: nowrap;
}
.pill--p0     { background: var(--primary);         color: var(--on-primary); }
.pill--p1     { background: var(--chip-gold-bg);    color: var(--chip-gold-fg); }
.pill--p2     { background: var(--chip-neutral-bg); color: var(--chip-neutral-fg); }
.pill--ok     { background: var(--chip-success-bg); color: var(--chip-success-fg); }
.pill--warn   { background: var(--chip-warning-bg); color: var(--chip-warning-fg); }
.pill--danger { background: var(--chip-danger-bg);  color: var(--chip-danger-fg); }
.pill--info   { background: var(--chip-info-bg);    color: var(--chip-info-fg); }

/* ---- Callout ------------------------------------------------------------------ */
.callout {
  background: var(--primary-soft);
  border: 1px solid var(--primary-border);
  padding: 12px 16px;
  font-size: var(--fs-sm);
  margin: 0 0 18px;
}
.callout .callout__label {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  text-transform: uppercase;
  letter-spacing: var(--ls-caps);
  color: var(--cane-700);
  display: block;
  margin-bottom: 4px;
}

/* ---- Open questions (MANDATED shell — SINGLE SOURCE) ---------------------
   Every proposal renders its Open questions section as ONE CARD PER QUESTION,
   never as table rows. Shape (established by PROP-059, mandated project-wide
   by PROP-073):
     <div class="oq [oq--gating|oq--done]">
       <h4><span class="oqid">OQ-1</span>
           [<span class="gate">gating</span> | <span class="dec">answered</span>]
           <span class="l-en">…the question…</span><span class="l-th">…</span></h4>
       <p class="l-en">…why it is open…</p><p class="l-th">…</p>
       <p class="rec"><b><span class="l-en">Recommend:</span><span class="l-th">แนะนำ:</span></b> …</p>
       <p class="note">…a dated annotation on the question…</p>
       <p class="ans">…the decision, once it is taken…</p>
     </div>
   A proposal's own <style> must never restate these rules. */
.oq {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg, 3px);
  background: var(--surface);
  padding: 10px 13px 8px;
  margin: 9px 0;
  break-inside: avoid;
}
.oq h4 {
  margin: 0 0 4px;
  font-size: 12.5px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.oq h4 .oqid { font: 700 10.5px/1 var(--font-mono); color: var(--primary); }
.oq p { margin: 3px 0; font-size: 11.3px; line-height: 1.55; }
.oq .rec { color: var(--text-muted); font-size: 10.5px; line-height: 1.5; margin-top: 4px; }
.oq .rec b { font-weight: 600; color: var(--text); }
/* Annotation — a dated remark that narrows or cross-references the question
   ("Premise refreshed …", "Cross-reference …", "Rev 0.5 (DF-1) …"). It is neither
   the recommendation nor a decision, so it carries no lead-word contract and
   leaves the card open. */
.oq .note {
  color: var(--text-muted);
  font-size: 10.5px;
  line-height: 1.5;
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px dashed var(--border);
}
.oq .note b { font-weight: 600; color: var(--text); }
/* Gating — the question that blocks the change set until it is answered. */
.oq--gating { border-left: 4px solid var(--gold-400, #D9A323); }
.oq h4 .gate {
  font: 700 8.5px/1.5 var(--font-mono);
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 2px;
  background: var(--chip-gold-bg);
  color: var(--chip-gold-fg);
}
/* Closed — the answer is recorded in .ans and the question is kept above it. */
.oq--done { border-left: 4px solid var(--success); }
.oq h4 .dec {
  font: 700 8.5px/1.5 var(--font-mono);
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 2px;
  background: var(--success-soft);
  color: var(--success);
}
.oq .ans {
  background: var(--success-soft);
  border-radius: 2px;
  padding: 6px 9px;
  margin: 5px 0;
  font-size: 11.3px;
  line-height: 1.55;
}
.oq .ans b { font-weight: 600; }
/* Legacy decided variant (PROP-051) — kept so an existing document is not edited. */
.oq--decided { border-color: var(--success); background: var(--success-soft); }
.oq--decided .dec { color: var(--text); font-size: 11.3px; line-height: 1.55; margin-top: 5px; }
.oq--decided .dectag {
  font: 700 8.5px/1.35 var(--font-mono);
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--success);
  border: 1px solid var(--success);
  border-radius: var(--radius-md, 2px);
  padding: 2px 5px;
}

/* ---- Process flow strip --------------------------------------------------------- */
.flow {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 6px;
  margin: 0 0 18px;
}
.flow__step {
  flex: 1 1 90px;
  min-width: 90px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  padding: 8px 10px;
}
.flow__step--accent { background: var(--primary-soft); border-color: var(--primary-border); }
.flow__num {
  font-family: var(--font-mono);
  font-size: var(--fs-2xs);
  color: var(--gold-600);
  display: block;
}
.flow__title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-strong);
  display: block;
  line-height: var(--lh-snug);
}
.flow__sub {
  font-size: var(--fs-2xs);
  color: var(--text-muted);
  display: block;
  line-height: var(--lh-snug);
}
.flow__arrow {
  align-self: center;
  color: var(--neutral-400);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
}

/* ---- ERD figure ------------------------------------------------------------------ */
figure.spec-fig { margin: 0 0 18px; }
figure.spec-fig svg { width: 100%; height: auto; display: block; }
figure.spec-fig figcaption {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: 6px;
}

/* ---- IA tree ---------------------------------------------------------------------- */
pre.ia {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  line-height: 1.6;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 12px 16px;
  margin: 0 0 18px;
  white-space: pre;
  overflow-x: auto;
}

/* ---- Related-documents links -------------------------------------------------------- */
.spec-links {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin: 0 0 12px;
}
.spec-links a {
  display: block;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 9px 12px;
}
.spec-links a:hover { border-color: var(--primary); background: var(--primary-soft); }
.spec-links .code {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  color: var(--cane-700);
  display: block;
}
.spec-links .name {
  font-size: var(--fs-sm);
  color: var(--text);
  display: block;
  line-height: var(--lh-snug);
}
.spec-links .desc {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
  line-height: var(--lh-snug);
}

/* ---- Print pagination (A4 210mm × 297mm; doc-page owns page geometry) -----
   Keep breaks away from awkward places; use .break-before to force a new
   page ahead of a heavy section. */
p { orphans: 3; widows: 3; }
@media print {
  h1, h2, h3 { break-after: avoid; }
  .spec-eyebrow { break-after: avoid; }
  .spec-meta, .callout, .flow, figure.spec-fig, .spec-links a { break-inside: avoid; }
  .spec-table tr { break-inside: avoid; }
  .spec-table thead { display: table-header-group; }
  pre.ia { break-inside: avoid; }
  li { break-inside: avoid; }
  .break-before { break-before: page; }
}

/* ---- Theme switching (light / dark) --------------------------------------- */
doc-page { --doc-desk: #ECE8DD; --doc-sheet: #FFFFFF; }
[data-theme="dark"] doc-page { --doc-desk: #0C100D; --doc-sheet: var(--surface); }
[data-theme="dark"] h1 { color: var(--text-strong); }
[data-theme="dark"] h2 { color: var(--cane-200); }
[data-theme="dark"] .spec-eyebrow,
[data-theme="dark"] .flow__num { color: var(--gold-300); }
[data-theme="dark"] .mono,
[data-theme="dark"] .spec-table .id,
[data-theme="dark"] .spec-head__code,
[data-theme="dark"] .spec-links .code,
[data-theme="dark"] .callout .callout__label { color: var(--cane-300); }

/* ---- Media containment (all widths) --------------------------------------
   Figures, images and code blocks never define the sheet's width. */
doc-page img, doc-page svg, doc-page canvas, doc-page video { max-width: 100%; }
doc-page pre { max-width: 100%; overflow-x: auto; }

/* ---- Sheet containment (all widths) --------------------------------------
   Nothing may render wider than the sheet's text column. The one construct that
   still could is a table cell a page's own <style> re-declares `nowrap` on while
   it holds a long ·-separated attribute list — at A4 that pushes the table past
   the paper edge on screen and clips it in print. Cells therefore wrap at every
   width; the deliberate exceptions keep their nowrap: `.date` / `.num` / `.nb`
   columns, and single short codes pinned atom-wise by spec-fit.js ([data-nb]). */
doc-page table { max-width: 100%; }
doc-page .spec-table :is(th, td):not(.date):not(.num):not(.nb):not([data-nb]) { white-space: normal !important; }
doc-page .spec-table :is(th, td) { overflow-wrap: break-word; }

/* ---- ID codes never break mid-token (all widths) --------------------------
   FR-222, NFR-61/63, PROP-048, v0.25.0, 2026-07-25: an ID is one atom, and a
   hyphen is a break opportunity by default — `word-break: keep-all` removes it,
   so codes stay whole while wrapping still happens between them (at spaces and
   · separators). `overflow-wrap` is deliberately NOT set here: a page that asks
   for `anywhere` (long composite index strings) keeps its last-resort break,
   which only applies to a token too long to fit a line on its own.
   Thai runs are exempt — Thai wraps mid-run by dictionary and keep-all would
   make a Thai sentence unbreakable. */
doc-page :is(.id, .mono, .ref, .pill, .nb, .sect, .date, code, .spec-links .code, .spec-head__code, .oqid, .plab) {
  word-break: keep-all;
  hyphens: none;
}
/* Short document codes additionally give up the last-resort break, so a column
   a pixel or two too narrow lets the code sit proud of its cell instead of
   splitting it. `.mono` / `code` keep it — they carry long snake_case
   identifiers and composite index strings that must still be breakable. */
doc-page :is(.id, .ref, .pill, .nb, .sect, .date, .oqid, .plab, .spec-links .code, .spec-head__code) { overflow-wrap: normal; }
/* Single-token codes are pinned whole by spec-fit.js (data-nb) — CSS alone
   cannot suppress the break opportunity a hyphen creates, and pinning the whole
   cell would stop long attribute lists from wrapping at their separators. */
doc-page [data-nb][data-nb] { white-space: nowrap !important; overflow-wrap: normal !important; }
doc-page :is(.id, .mono, .ref, .pill, .nb, .sect, .date, code) :is(.l-th, [lang="th"]) { word-break: normal; }
/* English prose carries inline codes as bare text (PROP-047, NFR-61/63); keep-all
   stops the hyphen break there too. Scoped to prose blocks only \u2014 inside a narrow
   table cell keep-all would leave a long English word unable to break at all,
   and codes in table cells are already pinned atom-wise via [data-nb]. Thai runs
   (.l-th) never get keep-all: they wrap mid-run by dictionary. */
/* Codes in prose live in `.mono` / `.ref` spans, so [data-nb] pins them; the prose
   itself keeps normal line breaking — keep-all on English runs left long CamelCase
   words unable to break inside narrow table cells. */

/* ---- Device viewport policy (MANDATED — all spec docs & drafts) -----------
   Three device classes, one policy, applied by the shared shell only — a
   document's own <style> must never set the sheet width or a page-level
   font-size override that fights it:

     Phone            ≤600px            fluid sheet, base type
     Tablet portrait  touch, ≤1024px    fluid sheet, zoomed to a ~640px reading box
     Tablet landscape touch, ≤1400px    fluid or A4 sheet, ~860px reading box
     Desktop          fine pointer      A4 paper-width sheet on the desk, base type

   The SHEET WIDTH half of that policy is the fluid-device-class block below.
   The READING SCALE half lives in shared/reading-scale.css + reading-scale.js
   (the CSS is imported at the top of this file, the script is loaded in every
   page's <head>) — it is the project-wide single source of truth and covers
   doc-page documents (via `--doc-zoom`) and plain pages (via a body zoom)
   alike. Do not restate a scale here. */

/* ---- Mobile / tablet (fluid device class) --------------------------------------------
   The paper card goes full-bleed (see doc-page.js) and the navbar collapses
   behind a hamburger (see spec-nav.js). Here we keep flow content inside the
   viewport: single-column link cards, wrapping tables, and card strips that
   reflow instead of holding a fixed column count. Declarations are
   `!important` on purpose — a document's own <style> block loads AFTER this
   sheet and often re-asserts nowrap / repeat(N, 1fr) at higher specificity.
   The condition is the FLUID DEVICE CLASS — keep it identical in doc-page.js
   and spec-fit.js. */
@media screen and (max-width: 1024px),
       screen and (max-width: 1366px) and (pointer: coarse) {
  /* Document meta grid: 3 equal columns can't fit prose values on a narrow
     viewport — drop to 2, then 1 on phones. */
  .spec-meta { grid-template-columns: repeat(2, 1fr) !important; }
  .spec-meta > div { min-width: 0; }
  .spec-head { gap: 6px 12px; }
  .spec-head__logo { height: 26px; }
  .spec-foot { flex-wrap: wrap; gap: 2px 12px; }

  /* Related-doc link cards: one column on a phone (a 2-up `1fr` track can't
     shrink below a long SPEC-*-GOV-OCSB code and would push past the sheet). */
  .spec-links { grid-template-columns: 1fr !important; }

  /* Tables fit the viewport: auto layout + wrapping cells. With nowrap
     removed from pills/ids/nums below, auto layout sizes columns to their
     content (narrow rev/date/id columns, wide prose columns) and can no
     longer push the table wider than the sheet. */
  doc-page table { max-width: 100%; }
  .spec-table th,
  .spec-table td { overflow-wrap: break-word !important; word-break: normal; }
  .spec-table th:not(.date):not(.nb) { white-space: normal !important; }
  .spec-table td.num { white-space: normal !important; }
  .spec-table .pill,
  .spec-table .id,
  .spec-table .id--code,
  .spec-table .nb,
  .spec-table .mono,
  .spec-table .ref,
  .spec-table .sect { white-space: normal !important; }
  .spec-table td.date,
  .spec-table .date { white-space: nowrap !important; word-break: normal; overflow-wrap: normal !important; }
  /* …but a wrapping cell must still never break inside an ID code. */
  doc-page :is(.id, .mono, .ref, .pill, .nb, .sect, .date, code, .oqid, .plab) {
    word-break: keep-all !important;
    hyphens: none !important;
  }
  doc-page :is(.id, .ref, .pill, .nb, .sect, .date, .oqid, .plab) { overflow-wrap: normal !important; }
  doc-page :is(.id, .mono, .ref, .pill, .nb, .sect, .date, code) :is(.l-th, [lang="th"]) { word-break: normal !important; }

  /* Authored card strips across the doc series: hold the pattern, drop the
     fixed column count so they reflow into rows instead of overflowing. */
  doc-page :is(.flow, .tl, .cluster, .flow3, .aud-wrap, .aud__grid, .erd-stats,
    .erd-cards, .grid2, .sig, .semver, .who, .g-2, .g-3, .g-4)
    { grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)) !important; }
  doc-page .flow__step { min-width: 0; }

  /* Static (non-hamburger) spec navs wrap their link row instead of
     overflowing; pages that load spec-nav.js keep its burger behaviour. */
  .spec-nav:not(:has(.spec-nav__burger)) { flex-wrap: wrap; height: auto; min-height: 40px; padding-right: 0; }
  .spec-nav:not(:has(.spec-nav__burger)) .spec-nav__links {
    order: 3; flex: 1 1 100%; margin-left: 0;
    overflow-x: auto; scrollbar-width: none;
    border-top: 1px solid var(--cane-800);
  }
  .spec-nav:not(:has(.spec-nav__burger)) .spec-nav__links::-webkit-scrollbar { display: none; }
  .spec-nav:not(:has(.spec-nav__burger)) .spec-nav__links a { flex: none; padding: 9px 12px; }
  .spec-docnav { position: static; height: auto; flex-wrap: wrap; padding: 4px 12px; }
  .spec-docnav__links { flex-wrap: wrap; }

  /* ---- Runtime fits applied by spec-fit.js (measured overflow only) ------ */
  doc-page [data-fit="grid-auto"] { grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)) !important; }
  doc-page [data-fit="grid-one"] { grid-template-columns: 1fr !important; }
  doc-page [data-fit^="grid"] > * { min-width: 0 !important; overflow-wrap: break-word; }
  doc-page [data-fit="flex-wrap"] { flex-wrap: wrap !important; }
  doc-page table[data-fit="table"] { table-layout: fixed !important; width: 100% !important; }
  doc-page table[data-fit="table"] :is(th, td) { white-space: normal !important; overflow-wrap: break-word !important; }
  doc-page table[data-fit="table"] :is(th, td).date { white-space: nowrap !important; overflow-wrap: normal !important; }
  doc-page [data-fit="squeeze"] { min-width: 0 !important; white-space: normal !important; overflow-wrap: break-word !important; }
  doc-page [data-fit="squeeze"] > * { min-width: 0 !important; }
  doc-page [data-fit="scroll"] { max-width: 100% !important; overflow-x: auto !important; -webkit-overflow-scrolling: touch; }
  /* A `display: table` box does not become a scroll container — capping its width
     just makes the cells spill. Turn it into a block so the rows can be wider
     than the sheet and scroll inside it. */
  doc-page table[data-fit="scroll"] { display: block !important; width: 100% !important; }
  /* Pinned single-token codes outrank every wrapping rule above. */
  doc-page [data-nb][data-nb] { white-space: nowrap !important; overflow-wrap: normal !important; }
}
@media screen and (max-width: 430px) {
  /* Small phones: the app bar's brand + language + theme + burger cluster is
     8px wider than a 360px viewport at full padding \u2014 tighten the chrome and
     let the title truncate rather than push the page sideways. */
  .spec-nav { padding-left: 10px !important; gap: 6px !important; }
  .spec-nav__title { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
  .spec-nav__theme button { width: 28px !important; }
  .spec-nav__lang button { min-width: 32px !important; padding: 0 6px !important; }
}
@media screen and (max-width: 560px) {
  .spec-meta { grid-template-columns: 1fr !important; }
  /* ERD/flow diagrams: scaling a 800pt-wide diagram into a 350pt phone makes
     its labels unreadable, so let the figure pan instead of shrink. */
  figure.spec-fig { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  figure.spec-fig svg { min-width: 460px; }
  /* True-phone fallback: fixed layout guarantees the table never exceeds the
     viewport even when every column's min-content is wide. */
  table.spec-table { table-layout: fixed; }
  doc-page :is(.flow, .tl, .cluster, .flow3, .aud__grid, .erd-stats, .erd-cards,
    .grid2, .sig, .g-2, .g-3, .g-4)
    { grid-template-columns: repeat(auto-fit, minmax(min(100%, 118px), 1fr)) !important; }
  doc-page [data-fit="grid-auto"] { grid-template-columns: repeat(auto-fit, minmax(min(100%, 118px), 1fr)) !important; }
}
