/* 30_plan.css - KP Equipment plan screen (slice 1, Fable). Uses 01_tokens.css tokens only for the chrome.
 * The plan's own drawing colours are scoped to .plan-root (not global tokens): they copy how v1.0 draws
 * equipment (#dbeafe / #2563eb), areas (#fef3c7 / #d97706 at .38) and decor (#ED7D31), with a dark pass.
 * Layouts (D61): phone <= 700 px wide (or <= 500 tall and <= 960 wide), tablet to 1299, PC from 1300.
 * Breakpoints are `screen` scoped so paper never inherits them. */

.plan-root {
  --eq-fill: #dbeafe; --eq-line: #2563eb;
  --eq-fill-retired: #f1f5f9; --eq-line-retired: #94a3b8;
  --eq-unmatched: #64748b;
  --area-fill: #fef3c7; --area-line: #d97706;
  --decor-fill: #ED7D31; --decor-line: #94a3b8;
  --stage-bg: #ffffff; --stage-grid: #eef2f7;
  --label-ink: #1e293b;
  --drawer-w: 360px;
}
[data-theme="dark"] .plan-root {
  --eq-fill: #1d3b63; --eq-line: #93c5fd;
  --eq-fill-retired: #1e293b; --eq-line-retired: #64748b;
  --stage-bg: #0f172a; --stage-grid: #1e293b;
  --label-ink: #e2e8f0;
}

html, body { height: 100%; }
body.plan-root {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  height: 100dvh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

.visually-hidden { position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.skip { position: absolute; left: var(--sp-3); top: -48px; z-index: 50; padding: var(--sp-2) var(--sp-3); background: var(--surface); color: var(--ink); border-radius: var(--r-sm); box-shadow: var(--shadow); }
.skip:focus { top: var(--sp-3); }

/* ---- house bar ---- */
.kp-bar { position: relative; z-index: 5; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: var(--sp-2); min-height: 44px; }
.kp-mark { display: block; flex: none; width: 28px; height: 28px; filter: drop-shadow(0 2px 4px rgba(15, 23, 42, .35)); } /* the EQU tool mark (favicon.svg), as KP CIC / KP Hygiene show theirs */
.kp-bar-title { font-size: 17px; letter-spacing: .01em; white-space: nowrap; }

.site-switch { display: inline-flex; padding: 3px; border-radius: var(--r-pill); background: var(--kp-bar-tint); border: 1px solid var(--kp-bar-line); }
.site-btn { min-height: 44px; min-width: 44px; padding: 0 var(--sp-4); border: 0; border-radius: var(--r-pill); background: transparent; color: var(--kp-bar-ink); font: inherit; font-weight: 500; cursor: pointer; }
.site-btn[aria-pressed="true"] { background: var(--kp-bar-on); color: var(--navy); font-weight: 600; }
[data-theme="dark"] .site-btn[aria-pressed="true"] { color: var(--on-brand); }
.site-btn:focus-visible { box-shadow: 0 0 0 2px var(--kp-bar-ring); }

.search { position: relative; flex: 1 1 220px; max-width: 480px; }
.search-input { width: 100%; min-height: 44px; padding: 0 var(--sp-4) 0 40px; border: 1px solid var(--kp-bar-line); border-radius: var(--r-pill); background: var(--kp-bar-tint); color: var(--kp-bar-ink); font: inherit; font-size: 15px; }
.search-input::placeholder { color: var(--kp-bar-ink-2); }
.search-input:focus { outline: none; box-shadow: 0 0 0 2px var(--kp-bar-ring); background: rgba(255,255,255,.16); }
[data-theme="dark"] .search-input:focus { background: var(--surface-alt); }
.search-icon { position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); fill: none; stroke: var(--kp-bar-ink-2); stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.search-results { position: absolute; left: 0; right: 0; top: calc(100% + 6px); margin: 0; padding: var(--sp-1); list-style: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-lg); max-height: min(60vh, 420px); overflow: auto; z-index: 40; }
.search-results[hidden] { display: none; }
.result { display: grid; grid-template-columns: auto 1fr; gap: 2px var(--sp-3); align-items: center; min-height: 48px; padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm); cursor: pointer; }
.result-id { font-family: var(--mono); font-weight: 600; font-size: 14px; color: var(--ink); }
.result-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-sub { grid-column: 1 / -1; font-size: 13px; color: var(--ink-muted); }
.result[aria-selected="true"], .result:hover { background: var(--brand-soft); }
.result-empty { padding: var(--sp-3); color: var(--ink-muted); }

.bar-btn { min-height: 44px; min-width: 44px; padding: 0 var(--sp-3); border: 1px solid var(--kp-bar-line); border-radius: var(--r-pill); background: var(--kp-bar-tint); color: var(--kp-bar-ink); font: inherit; font-size: 14px; cursor: pointer; }
.bar-btn:focus-visible { box-shadow: 0 0 0 2px var(--kp-bar-ring); }
.sample-badge { padding: 4px 10px; border-radius: var(--r-pill); background: var(--warning-bg); color: var(--warning-fg); font-size: 12px; font-weight: 600; letter-spacing: .02em; }
.sample-badge[hidden] { display: none; }
.kp-spacer { flex: 1 1 0; }

/* ---- toolbar ---- */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-4); padding: var(--sp-2) var(--sp-4); background: var(--surface); border-bottom: 1px solid var(--line); }
.field { display: inline-flex; align-items: center; gap: var(--sp-2); min-height: 44px; }
.field-label { font-size: 13px; color: var(--ink-muted); font-weight: 500; }
.select { min-height: 40px; max-width: 260px; padding: 0 36px 0 var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'><path d='M4 6l4 4 4-4' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round'/></svg>") no-repeat right 10px center; color: var(--ink); font: inherit; font-size: 15px; appearance: none; -webkit-appearance: none; }
.check { display: inline-flex; align-items: center; gap: var(--sp-2); min-height: 44px; cursor: pointer; font-size: 15px; }
.check input { width: 20px; height: 20px; margin: 0; accent-color: var(--brand); }
.counts { margin: 0; font-size: 13px; color: var(--ink-muted); }
.zoom { display: inline-flex; gap: var(--sp-1); margin-left: auto; }
.tool-btn { min-width: 44px; min-height: 44px; padding: 0 var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); font: inherit; font-size: 15px; font-weight: 500; cursor: pointer; }
.tool-btn:hover { background: var(--surface-alt); }
.tool-btn:active { background: var(--brand-soft); }

/* ---- main: stage + drawer ---- */
.plan-main { position: relative; display: flex; min-height: 0; }
.stage { position: relative; flex: 1 1 auto; min-width: 0; min-height: 0; overflow: hidden; background: var(--stage-bg); outline: none; }
.stage:focus-visible { box-shadow: inset 0 0 0 2px var(--brand); }
.plan-svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; background-color: var(--stage-bg); background-image: linear-gradient(var(--stage-grid) 1px, transparent 1px), linear-gradient(90deg, var(--stage-grid) 1px, transparent 1px); background-size: 48px 48px; }
.plan-svg.is-panning { cursor: grabbing; }
.plan-svg[hidden] { display: none; }

/* drawing: strokes stay 1 screen px at any zoom */
.area-shape { fill: var(--area-fill); fill-opacity: .38; stroke: var(--area-line); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.area-label { fill: var(--label-ink); opacity: .62; font-family: var(--font); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; pointer-events: none; }
.decor-shape { fill: var(--decor-fill); fill-opacity: .5; stroke: var(--decor-line); stroke-width: 1; vector-effect: non-scaling-stroke; pointer-events: none; }
.decor-label { fill: var(--label-ink); opacity: .7; font-family: var(--font); font-weight: 600; pointer-events: none; }
.machine { cursor: pointer; outline: none; }
.machine .shp { fill: var(--eq-fill); stroke: var(--eq-line); stroke-width: 1.25; vector-effect: non-scaling-stroke; transition: stroke-width var(--dur-fast); }
.machine .band-edge { fill: none; stroke: var(--eq-line); stroke-linejoin: round; stroke-linecap: butt; }
.machine .band-fill { fill: none; stroke: var(--eq-fill); stroke-linejoin: round; stroke-linecap: butt; }
.machine .hit { fill: transparent; stroke: none; }
.machine:hover .shp, .machine:focus-visible .shp { stroke-width: 2; }
.machine.is-selected .shp { stroke: var(--brand); stroke-width: 2.5; }
.machine.is-selected .band-edge { stroke: var(--brand); }
.machine.is-retired .shp { fill: var(--eq-fill-retired); stroke: var(--eq-line-retired); stroke-dasharray: 4 3; }
.machine.is-retired .band-edge { stroke: var(--eq-line-retired); }
.machine.is-retired .band-fill { stroke: var(--eq-fill-retired); }
.machine.is-retired:not(.show-all *) { }
.plan-root:not(.show-retired) .machine.is-retired { display: none; }
.plan-root:not(.show-retired) .mlabel.is-retired { display: none; }
.unmatched .shp { fill: var(--eq-unmatched); fill-opacity: .14; stroke: var(--eq-unmatched); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; pointer-events: none; }
.unmatched .band-edge { fill: none; stroke: var(--eq-unmatched); stroke-opacity: .6; pointer-events: none; }
.unmatched .band-fill { fill: none; stroke: var(--eq-unmatched); stroke-opacity: .14; pointer-events: none; }
.mlabel { fill: var(--label-ink); font-family: var(--font); font-weight: 600; text-anchor: middle; dominant-baseline: central; pointer-events: none; paint-order: stroke; stroke: var(--stage-bg); stroke-width: .12; stroke-linejoin: round; }
.is-dim { opacity: .10; pointer-events: none !important; }
.sel-ring { fill: none; stroke: var(--brand); stroke-width: 1.5; stroke-dasharray: 6 4; vector-effect: non-scaling-stroke; pointer-events: none; }
.sel-ring.is-pulse { animation: ring-pulse 1.2s var(--ease) 2; }
@keyframes ring-pulse { 0% { stroke-opacity: 1; stroke-width: 1.5; } 50% { stroke-opacity: .35; stroke-width: 6; } 100% { stroke-opacity: 1; stroke-width: 1.5; } }
@media (prefers-reduced-motion: reduce) { .sel-ring.is-pulse { animation: none; } }

.scale { position: absolute; left: var(--sp-4); bottom: var(--sp-3); display: inline-flex; align-items: center; gap: var(--sp-2); margin: 0; padding: 4px 10px; border-radius: var(--r-sm); background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--ink-soft); font-size: 12px; pointer-events: none; }
.scale-svg path { stroke: currentColor; stroke-width: 1.5; fill: none; }
.scale { white-space: nowrap; } .scale-svg { flex: none; } /* D7-fix: "50 m" stays on one line at 320 px */
.clean-note { margin: -4px 0 var(--sp-2); font-size: 12px; color: var(--ink-muted); } /* D7-fix: under the Cleaning heading */
.clean-note[hidden] { display: none; }
.hint { position: absolute; right: var(--sp-4); bottom: var(--sp-3); margin: 0; padding: 4px 10px; border-radius: var(--r-sm); background: color-mix(in srgb, var(--surface) 85%, transparent); color: var(--ink-muted); font-size: 12px; pointer-events: none; }
.hint[hidden], .scale[hidden] { display: none; }
.scale.is-unmeasured .scale-svg { display: none; }

/* O2b: v1.0 part markings (52_marks.js). Overlay strokes stay 1.2 screen px at every zoom, as in v1.0. */
.ov-host, .ov-host * { pointer-events: none; }
.ov-host *, .legend-row .ov * { vector-effect: non-scaling-stroke; }
.marks { display: flex; gap: var(--sp-2); }
.legend-panel { position: absolute; top: var(--sp-3); right: var(--sp-3); z-index: 6; width: min(340px, calc(100% - 24px)); max-height: calc(100% - 24px); overflow: auto; padding: 10px 12px 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); box-shadow: 0 8px 24px rgba(15, 23, 42, .18); }
.legend-panel[hidden] { display: none; }
.legend-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); }
.legend-head h3 { margin: 0; font-size: 15px; }
.legend-panel h4 { margin: 12px 0 6px; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-muted); }
.legend-modes { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.legend-modes button { flex: 1 0 30%; min-height: 40px; padding: 2px 6px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface-alt); color: var(--ink); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
.legend-modes button[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); color: #1e40af; }
.legend-note { margin: 4px 0; font-size: 12px; line-height: 1.5; color: var(--ink-soft); }
.tcat { margin: 10px 0 4px; font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .7px; color: var(--ink-muted); }
.legend-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; border-bottom: 1px solid var(--line-soft); font-size: 12.5px; }
.legend-row svg { width: 80px; height: 48px; flex: none; background: var(--surface-alt); border-radius: 6px; } /* F9a: 80 x 48 (was 60 x 36), the same 5:3 box - Key symbols draw a third larger */
.legend-ab { color: var(--ink-muted); font-size: 11px; font-family: ui-monospace, Consolas, monospace; }

/* Balmalcolm: no drawing yet, list by area */
.listwrap { position: absolute; inset: 0; overflow: auto; padding: var(--sp-4); background: var(--bg); }
.listwrap[hidden] { display: none; }
.empty { max-width: 720px; margin: 0 auto var(--sp-4); padding: var(--sp-4) var(--sp-5); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--r); }
.empty h2 { margin: 0 0 var(--sp-1); font-size: 18px; }
.empty p { margin: 0; color: var(--ink-soft); font-size: 15px; }
.group { max-width: 720px; margin: 0 auto var(--sp-3); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; }
.group-head { display: flex; justify-content: space-between; align-items: baseline; margin: 0; padding: var(--sp-3) var(--sp-4); font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); background: var(--surface-alt); border-bottom: 1px solid var(--line); }
.group-head span { font-weight: 500; letter-spacing: 0; text-transform: none; color: var(--ink-muted); }
.row { display: grid; grid-template-columns: auto 1fr auto; gap: var(--sp-3); align-items: center; width: 100%; min-height: 52px; padding: var(--sp-2) var(--sp-4); border: 0; border-top: 1px solid var(--line-soft); background: transparent; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.row:first-of-type { border-top: 0; }
.row:hover { background: var(--surface-alt); }
.row.is-selected { background: var(--brand-soft); }
.row-id { font-family: var(--mono); font-weight: 600; font-size: 14px; }
.row-name { font-weight: 500; }
.plan-root:not(.show-retired) .row.is-retired { display: none; }

.badge { display: inline-block; padding: 2px 8px; border-radius: var(--r-pill); font-size: 12px; font-weight: 600; letter-spacing: .02em; }
.badge-active { background: var(--success-bg); color: var(--success-fg); }
.badge-retired { background: var(--surface-alt); color: var(--ink-muted); border: 1px solid var(--line); }
.badge-undrawn { background: var(--info-bg); color: var(--info); }

/* ---- drawer ---- */
.drawer { flex: 0 0 var(--drawer-w); width: var(--drawer-w); display: flex; flex-direction: column; min-height: 0; background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow); }
.drawer[hidden] { display: none; }
.drawer-head { display: flex; align-items: flex-start; gap: var(--sp-3); padding: var(--sp-4) var(--sp-4) var(--sp-3); border-bottom: 1px solid var(--line); }
.drawer-head > div { flex: 1 1 auto; min-width: 0; }
.drawer-id { margin: 0; font-family: var(--mono); font-size: 24px; font-weight: 700; letter-spacing: .01em; color: var(--ink); }
.drawer-name { margin: 2px 0 0; font-size: 18px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.drawer-sub { margin: 4px 0 0; font-size: 13px; color: var(--ink-muted); overflow-wrap: anywhere; }
.icon-btn { flex: 0 0 auto; width: 44px; height: 44px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); font-size: 22px; line-height: 1; cursor: pointer; }
.icon-btn:hover { background: var(--surface-alt); }
.drawer-body { flex: 1 1 auto; min-height: 0; overflow: auto; padding: var(--sp-3) var(--sp-4) var(--sp-5); }
.drawer h3 { margin: var(--sp-4) 0 var(--sp-2); font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-muted); }
.facts { display: grid; grid-template-columns: 1fr auto; gap: 0; margin: 0; }
.facts > div { display: contents; }
.facts dt, .facts dd { padding: 10px 0; border-bottom: 1px solid var(--line-soft); margin: 0; }
.facts dt { color: var(--ink-soft); font-size: 15px; }
.facts dd { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.facts dd.is-blank { color: var(--ink-muted); font-weight: 500; }
.drawer-actions:empty { display: none; }
.drawer .muted { margin: 0; color: var(--ink-muted); font-size: 15px; }
.drawer-handle { display: none; }

/* ---- footer ---- */
.foot { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--sp-1) var(--sp-4); padding: var(--sp-2) var(--sp-4); background: var(--surface); border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-muted); }
.foot p { margin: 0; }
.foot b { color: var(--ink-soft); font-weight: 600; }

/* ---- layouts ---- */
@media screen and (min-width: 1300px) {
  .plan-root { --drawer-w: 400px; }
  .kp-bar { padding: var(--sp-2) var(--sp-5); }
  .toolbar { padding: var(--sp-2) var(--sp-5); }
  .kp-bar-title { font-size: 18px; }
}
@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  .kp-bar { padding: var(--sp-2) var(--sp-3); gap: var(--sp-2); }
  .kp-bar-title { font-size: 16px; }
  .kp-spacer { order: 9; flex-basis: 100%; }
  .search { order: 10; flex: 1 1 200px; max-width: none; }
  .sample-badge { order: 11; }
  .bar-btn { order: 12; padding: 0 var(--sp-3); font-size: 14px; }
  .site-btn { padding: 0 var(--sp-3); }
  .toolbar { padding: var(--sp-2) var(--sp-3); gap: var(--sp-2) var(--sp-3); }
  .select { max-width: 170px; }
  .check { font-size: 14px; }
  .counts { flex: 1 1 auto; order: 20; }
  .zoom { order: 21; margin-left: auto; }
  #zoom-in, #zoom-out { display: none; }
  .hint { display: none; }
  .listwrap { padding: var(--sp-3); }
  .drawer { position: fixed; left: 0; right: 0; bottom: 0; width: auto; max-height: 62dvh; border-left: 0; border-top: 1px solid var(--line); border-radius: var(--r) var(--r) 0 0; box-shadow: var(--shadow-lg); z-index: 30; padding-bottom: env(safe-area-inset-bottom); }
  .drawer-handle { display: block; width: 40px; height: 4px; margin: 8px auto 0; border-radius: 2px; background: var(--line); }
  .drawer-head { padding-top: var(--sp-2); }
  .drawer-id { font-size: 21px; }
  .foot { font-size: 12px; }
}
/* O2c: the key never clips. Rows wrap their text; on a phone the key is a bottom sheet in the drawer's style. */
.legend-row > span { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.legend-modes button { min-width: 0; white-space: normal; overflow-wrap: anywhere; }
@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  .legend-panel { position: fixed; top: auto; left: 0; right: 0; bottom: 0; width: auto; max-width: none; max-height: 62dvh; border: 0; border-top: 1px solid var(--line); border-radius: var(--r) var(--r) 0 0; box-shadow: var(--shadow-lg); z-index: 31; padding: 10px var(--sp-4) calc(12px + env(safe-area-inset-bottom)); box-sizing: border-box; overflow-x: hidden; }
}


/* ==== A6a: header + toolbar pass for phone, tablet and PC. KP CIC language: pill controls on the navy bar,
   bottom sheets on a phone. Selectors carry .kp-bar / .toolbar so they also win over 60_changes / 65_editor. ==== */

/* Segmented switches (site, 2D/3D): the whole 44 px is the touch target, the thumb is drawn 3 px inside it. */
.kp-bar .site-switch, .kp-bar .view-switch { padding: 0; border: 0; box-shadow: inset 0 0 0 1px var(--kp-bar-line); }
.kp-bar .site-btn, .kp-bar .view-btn { position: relative; z-index: 0; min-height: 44px; min-width: 48px; background: transparent; }
.kp-bar .view-btn { padding: 0 var(--sp-3); }
.kp-bar .site-btn[aria-pressed="true"], .kp-bar .view-btn[aria-pressed="true"] { background: transparent; }
.kp-bar .site-btn[aria-pressed="true"]::before, .kp-bar .view-btn[aria-pressed="true"]::before { content: ""; position: absolute; inset: 3px; z-index: -1; border-radius: var(--r-pill); background: var(--kp-bar-on); }
.select { min-height: 44px; }

/* "More" (phone only): Dark and Edit plan live in a popover. On tablet and PC the wrapper is transparent to layout. */
.more-menu { display: contents; }
.more-title, .kp-bar .more-btn, .kp-bar .more-close { display: none; }
.kp-bar .more-btn { width: 44px; padding: 0; }
.kp-bar .more-ic { stroke-width: 3.2; }

/* Small tablets (701-900): the name gives way to its mark so the bar stays on one row. */
@media screen and (min-width: 701px) and (max-width: 900px) {
  .kp-bar { gap: var(--sp-2); }
  .kp-bar .kp-bar-title { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .kp-bar .search { flex-basis: 140px; }
}

@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  /* one 52 px bar: mark, site, [space], 2D/3D, search, more */
  .kp-bar { gap: 4px; min-height: 52px; padding: 4px 8px; }
  .kp-bar .kp-bar-title { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .kp-bar .brand { margin-right: 2px; }
  .kp-bar .site-btn { min-width: 44px; padding: 0 8px; font-size: 14px; }
  .kp-bar .view-btn { min-width: 44px; padding: 0 8px; font-size: 14px; }
  .kp-bar .kp-spacer { order: 1; flex: 1 1 0; min-width: 0; }
  .kp-bar .sample-badge { order: 1; }
  .kp-bar .view-switch { order: 2; }
  .kp-bar .bar-btn { order: 5; }

  /* search: a round button that opens across the bar while it is in use */
  .kp-bar .search { order: 3; flex: 0 0 44px; width: 44px; max-width: none; }
  .kp-bar .search-icon { left: 13px; stroke: var(--kp-bar-ink); }
  .kp-bar .search-input { width: 44px; padding: 0; font-size: 16px; color: transparent; caret-color: transparent; cursor: pointer; }
  .kp-bar .search-input::placeholder { color: transparent; }
  .kp-bar .search:not(:focus-within) .search-input::-webkit-search-cancel-button { display: none; }
  .kp-bar .search:has(.search-input:not(:placeholder-shown)):not(:focus-within) .search-input { background: var(--kp-bar-on); border-color: var(--kp-bar-on); }
  .kp-bar .search:has(.search-input:not(:placeholder-shown)):not(:focus-within) .search-icon { stroke: var(--navy); }
  [data-theme="dark"] .kp-bar .search:has(.search-input:not(:placeholder-shown)):not(:focus-within) .search-icon { stroke: var(--on-brand); }
  .kp-bar .search:focus-within { position: absolute; left: 8px; right: 8px; top: 4px; z-index: 3; width: auto; }
  .kp-bar .search:focus-within .search-input { width: 100%; padding: 0 var(--sp-3) 0 42px; color: var(--kp-bar-ink); caret-color: auto; cursor: text; background: var(--navy-hover); box-shadow: 0 0 0 2px var(--kp-bar-ring); }
  [data-theme="dark"] .kp-bar .search:focus-within .search-input { background: var(--surface-alt); }
  .kp-bar .search:focus-within .search-input::placeholder { color: var(--kp-bar-ink-2); }
  .kp-bar .search-results { position: fixed; left: 8px; right: 8px; top: 58px; max-height: min(60dvh, 420px); }

  /* toolbar: one row of chips that scrolls sideways; a soft fade marks the edge */
  .toolbar { flex-wrap: nowrap; gap: var(--sp-2); padding: 4px 8px; overflow-x: auto; overflow-y: hidden; overscroll-behavior-x: contain; scrollbar-width: none; }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar > * { flex: 0 0 auto; }
  .toolbar::after { content: ""; order: 99; position: sticky; right: 0; flex: 0 0 28px; align-self: stretch; background: linear-gradient(to right, transparent, var(--surface) 75%); pointer-events: none; }
  .toolbar .field-label { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .toolbar .select { max-width: 150px; }
  .toolbar .tool-btn { white-space: nowrap; }
  .toolbar .marks { order: 2; }
  .toolbar .changes { order: 3; }
  .toolbar .zoom { order: 4; margin-left: 0; }
  .toolbar .check { order: 6; padding: 0 var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-sm); white-space: nowrap; }
  .toolbar .counts { order: 7; flex: 0 0 auto; white-space: nowrap; }
  /* Changes opens as a bottom sheet (a dropdown would be clipped by the scrolling row) */
  .toolbar .changes-menu { position: fixed; left: 0; right: 0; top: auto; bottom: 0; z-index: 46; width: auto; padding: var(--sp-3) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom, 0px)); border: 0; border-top: 1px solid var(--line); border-radius: var(--r) var(--r) 0 0; box-shadow: var(--shadow-lg); }

  .foot { gap: 0 var(--sp-3); padding: 4px var(--sp-3) calc(4px + env(safe-area-inset-bottom, 0px)); font-size: 11.5px; line-height: 1.4; }

  @supports selector(:popover-open) {
    .kp-bar .more-btn { display: inline-flex; order: 4; }
    body.is-editing .kp-bar .more-btn { display: none; }
    .kp-bar .more-menu { display: none; }
    .kp-bar .more-menu:popover-open { display: flex; flex-direction: column; gap: var(--sp-2); position: fixed; inset: auto 0 0 0; width: auto; height: auto; max-width: none; max-height: 70dvh; margin: 0; padding: var(--sp-3) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom, 0px)); border: 0; border-top: 1px solid var(--line); border-radius: var(--r) var(--r) 0 0; background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); overflow: auto; }
    .kp-bar .more-menu::backdrop { background: rgba(15, 23, 42, .5); }
    /* A6c: the sheet is solid from its first frame (it slides up, it never fades); dark gets a deeper dim */
    [data-theme="dark"] .kp-bar .more-menu::backdrop { background: rgba(2, 6, 23, .68); }
    .kp-bar .more-menu:popover-open { opacity: 1; background-color: var(--surface); }
    .kp-bar .more-menu:popover-open .more-title { display: block; margin: 0 0 var(--sp-1); font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-muted); }
    .kp-bar .more-menu:popover-open .bar-btn { display: flex; justify-content: flex-start; gap: 10px; width: 100%; min-height: 52px; padding: 0 var(--sp-4); border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); font-size: 16px; font-weight: 500; box-shadow: none; }
    .kp-bar .more-menu:popover-open .bar-btn:active { background: var(--brand-soft); }
    .kp-bar .more-menu:popover-open .bar-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
    .kp-bar .more-menu:popover-open .more-close { justify-content: center; margin-top: var(--sp-1); background: var(--surface-alt); color: var(--ink-soft); }
    .kp-bar .more-menu:popover-open #theme-btn { gap: 0; text-transform: lowercase; }
    .kp-bar .more-menu:popover-open #theme-btn::before { content: "Switch to "; white-space: pre; text-transform: none; }
    .kp-bar .more-menu:popover-open #theme-btn::after { content: " theme"; white-space: pre; text-transform: none; }
  }
}
@media screen and (max-width: 379px) { .kp-bar .brand { display: none; } }
@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  .toolbar::after { right: -8px; }                      /* the fade sits flush with the screen edge, past the row's padding */
  .foot { display: block; } .foot p { display: inline; } /* the two notes run on as one short paragraph */
}
/* Tablet and narrow PC windows (901-1299): the toolbar stays on one row; the machine count shortens first. */
@media screen and (min-width: 901px) and (max-width: 1299px) and (min-height: 501px) {
  .toolbar { flex-wrap: nowrap; gap: var(--sp-3); }
  .toolbar > * { flex: 0 0 auto; }
  .toolbar .field-label { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .toolbar .tool-btn, .toolbar .check { white-space: nowrap; }
  .toolbar .counts { flex: 0 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media screen and (min-width: 901px) and (max-width: 1299px) and (min-height: 501px) and (pointer: coarse) {
  .toolbar #zoom-in, .toolbar #zoom-out { display: none; }  /* touch: pinch zooms, Fit stays (as on a phone) */
}
@media (prefers-reduced-motion: no-preference) {
  .kp-bar .more-menu:popover-open { transition: transform var(--dur) var(--ease-out); }
  @starting-style { .kp-bar .more-menu:popover-open { transform: translateY(24px); } }
}

/* ==== A6b (Fable, 09/11/2026): layout defects found on the live test site ====
 * 1. The page never scrolls sideways. The body grid had an auto column, so the one-row toolbar (901-1299) pushed the whole
 *    page out to its own min-content width (1052 px): from 901 to 1050 the header grew with it and Edit plan and Changes sat
 *    off screen. The column is now minmax(0, 1fr): the page is as wide as the screen, and the machine count gives way first
 *    (it already shortens with an ellipsis). 901-960: the name gives way to its mark, as on small tablets, so the header
 *    stays on one row.
 * 2. Phone toolbar: Area, Changes and Fit are always in view; the less-used controls follow in the same sideways row, and a
 *    chevron on the fade says there is more (it fades out at the end of the row). 380-389: the mark steps aside so the
 *    header keeps to one row. */
body.plan-root { grid-template-columns: minmax(0, 1fr); }
@media screen and (min-width: 901px) and (max-width: 960px) and (min-height: 501px) {
  .kp-bar .kp-bar-title { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
}
@media screen and (max-width: 389px) { .kp-bar .brand { display: none; } }
@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  .toolbar .changes { order: 1; }
  .toolbar .zoom { order: 2; }
  .toolbar .marks { order: 3; }
  .toolbar::after { flex-basis: 44px; background: linear-gradient(to right, transparent, var(--surface) 55%); }
  @supports (animation-timeline: scroll()) {
    .toolbar::after { content: "›"; display: flex; align-items: center; justify-content: flex-end; box-sizing: border-box; padding: 0 10px 3px 0; font-size: 24px; font-weight: 600; line-height: 1; color: var(--ink-soft); opacity: 0; animation: kp-more-cue linear both; animation-timeline: scroll(nearest inline); animation-range: calc(100% - 48px) 100%; }
  }
}
@keyframes kp-more-cue { from { opacity: 1; } to { opacity: 0; } }

/* ==== C2a (Fable, 10/11/2026): edit mode in the machine record (50_plan.js) ====
 * Header: Edit sits beside Close, the status badge under them, so the number and the name keep their width at 360 px.
 * Edit mode: the record body gives way to a form (.rec-edit) with a sticky Save bar. A changed value is marked with
 * words ("Changed on this device"), never with a tint. Phone: the sheet grows to 92dvh, and while the on-screen
 * keyboard is up a spacer (.kb-pad) holds the form and its Save bar above it.
 * The two message colours are scoped here, with a dark pass, so both stay above 4.5:1 on the record's surface. */
.drawer { --rec-bad: #b91c1c; --rec-good: #15803d; }
[data-theme="dark"] .drawer { --rec-bad: #fca5a5; --rec-good: #86efac; }

.drawer-head { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; grid-template-areas: "text edit close" "text badge badge"; align-items: start; gap: var(--sp-2); }
.drawer-head > div { grid-area: text; min-width: 0; }
.drawer-head > .badge { grid-area: badge; justify-self: end; }
.drawer-head > .drawer-edit { grid-area: edit; min-width: 56px; font-weight: 600; }
.drawer-head > .icon-btn { grid-area: close; }

.fact-tag { display: block; margin-top: 2px; font-size: 12px; font-weight: 600; letter-spacing: .01em; color: var(--ink-soft); }
.fact-tag[hidden] { display: none; }
.drawer-name-tag { margin: 4px 0 0; }

.drawer.is-rec-edit .drawer-body > :not(.rec-edit) { display: none; }
.drawer.is-rec-edit .drawer-body { scroll-padding-bottom: 128px; }
.drawer.is-rec-edit .drawer-head .drawer-sub, .drawer.is-rec-edit .drawer-head .drawer-area, .drawer.is-rec-edit .drawer-head .drawer-name-tag { display: none; }
.kb-pad { display: none; flex: 0 0 auto; }

.rec-edit { display: flex; flex-direction: column; }
.rec-edit > h3:first-child { margin-top: var(--sp-1); }
.rec-field { display: flex; flex-direction: column; min-width: 0; margin: 0 0 var(--sp-3); }
.rec-label { margin: 0 0 4px; font-size: 14px; font-weight: 600; line-height: 1.3; color: var(--ink-soft); }
.rec-input { width: 100%; min-width: 0; min-height: 44px; padding: 0 var(--sp-3); border: 1px solid var(--ink-muted); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; font-variant-numeric: tabular-nums; }
.rec-input:read-only { color: var(--ink-soft); }
.rec-input[aria-invalid="true"] { border-color: var(--rec-bad); box-shadow: inset 0 0 0 1px var(--rec-bad); }
.rec-notes { min-width: 0; }
.rec-hint, .rec-msg { margin: 4px 0 0; font-size: 13px; line-height: 1.35; overflow-wrap: anywhere; }
.rec-hint { color: var(--ink-muted); }
.rec-msg { font-weight: 600; }
.rec-msg.is-error { color: var(--rec-bad); }
.rec-msg.is-saved { color: var(--rec-good); }

.rec-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: var(--sp-3); }
.rec-grid .is-wide { grid-column: 1 / -1; }
.rec-grid .rec-field.is-refused { grid-column: 1 / -1; } /* C2a-2: a refused value's reason spans the form */
@supports (grid-template-rows: subgrid) {
  /* label, field and message share rows across a pair, so two fields line up even when one label wraps */
  .rec-grid .rec-field { display: grid; grid-template-rows: subgrid; grid-row: span 3; row-gap: 0; }
  .rec-grid .rec-label { align-self: end; }
}

.rec-locked { margin: 0 0 var(--sp-3); padding: 10px var(--sp-3); border: 1px dashed var(--line); border-radius: var(--r-sm); background: var(--surface-alt); }
.rec-locked .rec-label { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); margin: 0; }
.rec-lock { padding: 1px 8px; border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface); font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.rec-static { margin: 2px 0 0; font-size: 16px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.rec-static.is-blank { color: var(--ink-muted); font-weight: 500; }
.rec-locked .rec-hint { color: var(--ink-soft); }

.rec-bar { position: sticky; bottom: calc(-1 * var(--sp-5)); /* sticky is measured inside the body padding: -24px puts the bar on the true bottom edge */ z-index: 1; display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2) var(--sp-3); margin: var(--sp-2) calc(-1 * var(--sp-4)) calc(-1 * var(--sp-5)); padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--line); background: var(--surface); box-shadow: 0 -8px 12px -10px rgba(15, 23, 42, .28); }
.rec-status { grid-column: 1 / -1; min-height: 20px; margin: 0; font-size: 14px; line-height: 1.4; color: var(--ink-soft); }
.rec-bar .tool-btn { min-height: 48px; font-size: 16px; }
.rec-status.is-warn { color: var(--rec-bad); font-weight: 600; }
.rec-bar .tool-btn:disabled { opacity: .5; cursor: default; }

@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  .drawer.is-rec-edit, .drawer.is-rec-edit.is-peek { max-height: 92dvh; }
  .drawer.is-rec-edit.is-peek .drawer-body { display: block; }
  .drawer.is-rec-edit.is-peek .drawer-head { border-bottom: 1px solid var(--line); padding-bottom: var(--sp-3); }
  .drawer.is-rec-edit .drawer-handle { visibility: hidden; }
  .drawer.is-rec-edit.has-kb { max-height: 100dvh; border-radius: 0; }
  .drawer.has-kb .kb-pad { display: block; }
}

/* ==== C2b-2a (Fable, 10/11/2026): the Redundant shelf in the machine record (50_plan.js) and the backup note ====
 * The amber --shelf-* colours are scoped here, with a dark pass, and are shared with 56_shelf.css. Text on them stays
 * above 4.5:1. At rest the record shows one quiet button; the confirm step and the Redundant status are cards. */
.plan-root { --shelf-ink: #92400e; --shelf-bg: #fef3c7; --shelf-soft: #fffbeb; --shelf-edge: #d97706; --shelf-line: #fcd34d; }
[data-theme="dark"] .plan-root { --shelf-ink: #fcd34d; --shelf-bg: rgba(217, 119, 6, .24); --shelf-soft: rgba(217, 119, 6, .10); --shelf-edge: #f59e0b; --shelf-line: rgba(245, 158, 11, .45); }
.badge-redundant { background: var(--shelf-bg); color: var(--shelf-ink); }

.rec-shelf { display: flex; flex-direction: column; gap: var(--sp-2); margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--line); }
.rec-shelf[hidden] { display: none; }
.rec-shelf p { margin: 0; }
.rec-shelf-btn { align-self: flex-start; }
.rec-shelf-note { color: var(--ink-muted); font-size: 14px; line-height: 1.4; }
.rec-shelf-msg { font-size: 14px; line-height: 1.4; color: var(--ink-soft); overflow-wrap: anywhere; }
.rec-shelf-msg[hidden] { display: none; }
.rec-shelf-msg.is-error { color: var(--rec-bad); font-weight: 600; }
.rec-shelf.is-asking, .rec-shelf.is-shelved { padding: var(--sp-3); border: 1px solid var(--shelf-line); border-left: 4px solid var(--shelf-edge); border-radius: var(--r); background: var(--shelf-soft); }
.rec-shelf.is-shelved { margin: 0 0 var(--sp-2); }
.rec-shelf-q, .rec-shelf-status { font-size: 16px; font-weight: 600; line-height: 1.3; color: var(--ink); }
.rec-shelf-text { font-size: 14px; line-height: 1.45; color: var(--ink-soft); }
.rec-shelf-row { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--sp-2) var(--sp-3); margin-top: var(--sp-1); }
.rec-shelf-row .tool-btn, .rec-shelf.is-shelved .rec-shelf-btn { min-height: 48px; font-size: 16px; }
.rec-shelf-row .tool-btn { padding: 0 var(--sp-4); }
.rec-shelf.is-shelved .rec-shelf-btn { align-self: stretch; margin-top: var(--sp-1); }
.rec-shelf-flash { margin: 0 0 var(--sp-2); padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm); background: var(--success-bg); color: var(--rec-good); font-size: 14px; font-weight: 600; line-height: 1.4; }
.rec-shelf-flash[hidden] { display: none; }

/* Changes menu: what the backup file holds (D23) */
.menu-note { margin: 0 var(--sp-3) var(--sp-2); font-size: 12.5px; line-height: 1.4; color: var(--ink-muted); }

/* ==== C2b-2c (Fable, 10/11/2026): a button that is off, in the record panel or on the Redundant shelf ====
 * It reads as off, not as a faded primary: a flat grey surface, a muted label, no shadow, full opacity.
 * Label contrast 6.1:1 light (--ink-soft on --line), 7.0:1 dark (--ink-muted on --surface-alt). One rule for both homes. */
.drawer, .shelf { --off-bg: var(--line); --off-ink: var(--ink-soft); --off-line: var(--line); }
[data-theme="dark"] .drawer, [data-theme="dark"] .shelf { --off-bg: var(--surface-alt); --off-ink: var(--ink-muted); --off-line: var(--line); }
.drawer .tool-btn:disabled, .drawer .tool-btn:disabled:hover, .shelf .tool-btn:disabled, .shelf .tool-btn:disabled:hover { opacity: 1; background: var(--off-bg); border-color: var(--off-line); color: var(--off-ink); box-shadow: none; cursor: default; }

/* ==== D-b1 (Fable, 10/11/2026): 2D chrome polish for the tablet (design punch list P2-6, 7, 8, 11, 15) ====
 * 1. Header: every control on the navy bar is 15 px (was 16 px switches beside 14 px buttons). Tablet and PC only;
 *    the phone bar keeps its own sizes.
 * 2. Search: the clear button is drawn by us (a white cross on a soft disc, 28 px) so it shows on navy in both themes;
 *    the second line of the highlighted result steps up to --ink-soft (6:1 light, 9:1 dark on the highlight).
 * 3. Key: colour modes sit in an even grid (Plain across the top, then pairs), 44 px high, one line each; the rows,
 *    category heads and abbreviations are 12 px or larger. The chosen mode reads in both themes.
 * 4. Record head: one flex row "id  status ...... Edit  Close". Edit and Close are pinned top right and the status
 *    keeps their room free; if a long status and a wide id cannot share the row, the status drops under the id
 *    (it never slides under a button). The name now has the full width of the panel.
 * 5. Stage: the hint is the same card as the 3D hint, bottom left; the scale bar is its twin, bottom right. */

@media screen and (min-width: 701px) and (min-height: 501px), screen and (min-width: 961px) {
  .kp-bar .site-btn, .kp-bar .view-btn, .kp-bar .bar-btn { font-size: 15px; }
  .legend-panel { width: min(360px, calc(100% - 24px)); padding: 12px 14px 14px; }
  .drawer-id { font-size: 22px; }
}
@media screen and (min-width: 1300px) { .drawer-id { font-size: 24px; } }

.search-input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; flex: none; width: 28px; height: 28px; margin: 0 -6px 0 6px; border-radius: 50%; background: rgba(255, 255, 255, .18) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 2l8 8M10 2l-8 8' fill='none' stroke='white' stroke-width='1.8' stroke-linecap='round'/></svg>") no-repeat center; opacity: 1; cursor: pointer; }
.result[aria-selected="true"] .result-sub, .result:hover .result-sub { color: var(--ink-soft); }

.legend-head h3 { font-size: 16px; }
.legend-modes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2); margin: 0 0 var(--sp-2); }
.legend-modes button { min-height: 44px; padding: 4px 10px; font-size: 14px; line-height: 1.2; }
.legend-modes button:first-child:nth-last-child(odd) { grid-column: 1 / -1; }
.legend-modes button[aria-pressed="true"] { color: var(--brand-hover); box-shadow: inset 0 0 0 1px var(--brand); }
.legend-modes button:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.legend-note { font-size: 13px; }
.tcat { margin: 14px 0 4px; font-size: 12px; letter-spacing: .06em; }
.legend-row { padding: 6px 0; font-size: 14px; line-height: 1.3; }
.legend-ab { font-size: 12.5px; }

.drawer-head { --dh-top: var(--sp-4); --dh-btns: 116px; /* Edit 56 + 8 + Close 44 + 8 */ position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 0 var(--sp-2); padding-top: var(--dh-top); }
.drawer-head > div { display: contents; }
.drawer-head > div > * { order: 3; flex: 0 0 100%; min-width: 0; }
.drawer-head > div > .drawer-id { order: 1; flex: 0 1 auto; display: inline-flex; align-items: center; min-height: 44px; }
.drawer-head > .badge { order: 2; flex: 0 0 auto; margin-right: var(--dh-btns); }
.drawer-head > .drawer-edit, .drawer-head > .icon-btn { position: absolute; top: var(--dh-top); }
.drawer-head > .icon-btn { right: var(--sp-4); }
.drawer-head > .drawer-edit { right: calc(var(--sp-4) + 44px + var(--sp-2)); }
@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  .drawer-head { --dh-top: var(--sp-2); }
}

.hint, .scale { bottom: var(--sp-3); padding: 7px 12px; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); background: color-mix(in srgb, var(--surface) 96%, transparent); font-weight: 500; line-height: 1.4; box-shadow: var(--shadow-sm); }
.hint { left: var(--sp-3); right: auto; max-width: calc(100% - 200px); color: var(--ink); font-size: 13px; }
.scale { left: auto; right: var(--sp-3); color: var(--ink-soft); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.stage.has-shelf .hint, .stage.has-shelf .scale { padding-top: 3px; padding-bottom: 3px; } /* the Redundant pill sits 46 px up: keep 8 px under it */
#layer-names .area-name.is-culled { visibility: hidden; } /* FIX names 10/11: 50_plan.js declutter hides a name that would overlap a higher-priority name or cross the stage edge */

/* D3 (14/11/2026) - machine labels: 50_plan.js labelDeclutter() hides a machine label that would print over a
   higher-priority one and cannot be moved clear along its own machine. */
.mlabel.is-culled { visibility: hidden; }

/* D3 (14/11/2026) - phone peek card of a machine that has a close-up: the "Higher resolution" button (83_hires.js puts it
   first in the record body) shows in the peek card, under the name, so the close-up is one tap away. The rest of the
   record still waits for the card to be pulled up, and a machine with no close-up keeps the short card. The note under
   the button (the file size) stays in the full record; the loading card says the size and has Cancel. */
@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  .drawer.is-peek:not(.is-rec-edit):has(.drawer-body > .hr-entry:not([hidden])) { max-height: max(calc(28dvh + 60px), 272px); }
  .drawer.is-peek:not(.is-rec-edit):has(.drawer-body > .hr-entry:not([hidden])) .drawer-body { display: block; flex: 0 0 auto; overflow: hidden; padding: 0 var(--sp-4) var(--sp-3); }
  .drawer.is-peek:not(.is-rec-edit):has(.drawer-body > .hr-entry:not([hidden])) .drawer-body > :not(.hr-entry) { display: none; }
  .drawer.is-peek:not(.is-rec-edit) .drawer-body > .hr-entry { margin: 0; padding: 0; border: 0; }
  .drawer.is-peek:not(.is-rec-edit) .drawer-body > .hr-entry .hr-entry-note { display: none; }
}
/* a phone on its side has little height: the card keeps to the id, the name and the button, so some plan still shows */
@media screen and (max-height: 500px) and (max-width: 960px) {
  .drawer.is-peek:not(.is-rec-edit):has(.drawer-body > .hr-entry:not([hidden])) { max-height: max(28dvh, 208px); }
  .drawer.is-peek:not(.is-rec-edit):has(.drawer-body > .hr-entry:not([hidden])) .drawer-sub,
  .drawer.is-peek:not(.is-rec-edit):has(.drawer-body > .hr-entry:not([hidden])) .drawer-area { display: none; }
}

/* ==== F9a (Fable, 15/11/2026): view-fix looks - search extras, the greyed 3D button, the record's hidden helpers ====
 * 1. Search. .result-also is the line that says which other name matched ("Also called ..." / "Formerly ...", from
 *    53_names_ui.js matchWords). It takes the full row width and wraps. .result-more ("Showing 8 of 23 - type more to
 *    narrow") cannot be picked: muted, no pointer hand, no highlight. Eight results are taller than the list, so the
 *    row is pinned to the list's bottom edge and is in view without scrolling; the scroll padding keeps a result that
 *    is scrolled into view clear of it.
 * 2. The 3D button on a site with no 3D model (75_sheet.js sets aria-disabled, a title and #view-3d-why): the estate's
 *    held-back look (dashed edge, quieter label, a dot) drawn for the navy bar. A press still says why, so the pointer
 *    hand stays. The reason shows as a small card under the switch while the button has focus or is being pressed
 *    (touch has no hover title and the keyboard never saw one); a builder can also show it with .is-shown.
 * 3. The record body is the frame for its own hidden helpers. 84_photos.js keeps a status line and two file inputs in
 *    it as .visually-hidden (position: absolute). With no positioned box before .plan-main they escaped the body's
 *    scroll box and made the PAGE taller than the screen in Edit (856 px at 1280 x 800, more with a longer record),
 *    so scrolling a control into view moved the whole app. */
.result-also { grid-column: 1 / -1; font-size: 13px; line-height: 1.35; color: var(--ink-soft); overflow-wrap: anywhere; }
.result[aria-selected="true"] .result-also, .result:hover .result-also { color: var(--ink-soft); }
.search-results { min-width: min(360px, calc(100vw - 32px)); } /* never narrower than its words: the search box is 256 px wide at 1280 and 190 px on a small tablet */
.result-more { position: sticky; bottom: calc(-1 * var(--sp-1)); /* sticky is measured inside the list padding, as for .rec-bar */ margin: var(--sp-1) calc(-1 * var(--sp-1)) calc(-1 * var(--sp-1)); padding: var(--sp-2) calc(var(--sp-3) + var(--sp-1)); border-top: 1px solid var(--line-soft); background: var(--surface); color: var(--ink-muted); font-size: 13px; line-height: 1.35; cursor: default; }
.search-results:has(> .result-more) { scroll-padding-bottom: 56px; }

.kp-bar .view-switch { position: relative; }
.kp-bar .view-btn[aria-disabled="true"] { color: var(--kp-bar-ink-2); cursor: pointer; }
.kp-bar .view-btn[aria-disabled="true"]::before { content: ""; position: absolute; inset: 3px; z-index: -1; border: 1px dashed var(--kp-bar-ink-2); border-radius: var(--r-pill); }
.kp-bar .view-btn[aria-disabled="true"]::after { content: ""; position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; background: var(--kp-bar-ink); }
.kp-bar .view-btn[aria-disabled="true"]:focus ~ #view-3d-why, .kp-bar .view-btn[aria-disabled="true"]:active ~ #view-3d-why, .kp-bar #view-3d-why.is-shown { top: calc(100% + var(--sp-2)); right: 0; z-index: 41; width: max-content; max-width: min(240px, calc(100vw - 32px)); height: auto; margin: 0; padding: 6px 10px; overflow: visible; clip: auto; white-space: normal; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); font-size: 13px; font-weight: 500; line-height: 1.35; text-align: left; pointer-events: none; }

.drawer-body { position: relative; }

/* ==== F11 (Fable, 15/11/2026): the kind of the search line, and the record's saved / not saved words (hooks from VF-A3) ====
 * 1. Search. .result-also.is-also is a name people use today: full ink, the weight of the row's own name.
 *    .result-also.is-old ("Formerly ...") is history, so it steps back: regular weight, muted ink. The first word of
 *    each line says which it is; weight and ink only support it. A picked or hovered row keeps both readable.
 * 2. The record. .fact-tag.is-saved / .is-pending wear the Sheet's two marks (75_sheet.css .sheet-dot and its legend):
 *    saved for everyone = a small filled dot, not saved yet = a larger open ring. Shape, weight and the words tell
 *    them apart; colour only supports it. The saved dot is a filled border, so it stays filled where the system
 *    forces its own colours. The tag stays display: block, so .fact-tag[hidden] further up still hides it. */
.result-also.is-also { color: var(--ink); font-weight: 500; }
.result-also.is-old { color: var(--ink-muted); font-weight: 400; }
.result[aria-selected="true"] .result-also.is-also, .result:hover .result-also.is-also { color: var(--ink); }
.result[aria-selected="true"] .result-also.is-old, .result:hover .result-also.is-old { color: var(--ink-soft); }

/* The mark is part of the line of words, straight before the first one, so it stays with its words on whichever side
 * they sit: on the right under a changed value, on the left under the name. Both marks take the same 15 px, and a
 * second line of words hangs under the first word, not under the mark. */
.fact-tag.is-saved, .fact-tag.is-pending { padding-left: 15px; text-indent: -15px; line-height: 1.35; overflow-wrap: anywhere; }
.fact-tag.is-saved::before, .fact-tag.is-pending::before { content: ""; display: inline-block; box-sizing: border-box; border-radius: 50%; vertical-align: middle; }
.fact-tag.is-saved { color: var(--ink-soft); font-weight: 500; }
.fact-tag.is-saved::before { width: 7px; height: 7px; margin: 0 7px 2px 1px; border: 3px solid var(--success-fg); background: var(--success-fg); }
.fact-tag.is-pending { color: var(--ink); font-weight: 600; }
.fact-tag.is-pending::before { width: 9px; height: 9px; margin: 0 6px 2px 0; border: 2px solid var(--info); background: transparent; }

/* ==== N1-7 (Fable, 16/11/2026): the phone footer note is easier to read ====
 * The source note under the save line was 11 px in the lighter grey (5.5:1). It is now 12 px in the stronger grey:
 * 7.6:1 on the light footer and 9.9:1 on the dark one (AA asks for 4.5:1). The date in it steps up to the full ink
 * colour so it still stands out. The footer grows by about 3 px. Phone, view mode only. */
html[data-device="phone"] body.plan-root:not(.is-editing) .foot #foot-source { font-size: 12px; line-height: 1.25; color: var(--ink-soft); }
html[data-device="phone"] body.plan-root:not(.is-editing) .foot #foot-source b { color: var(--ink); }
/* ==== end N1-7 ==== */

/* ==== N1-6b (Fable, 16/11/2026): the area filter - one button and a list of check boxes (50_plan.js, D344/D345/D348) ====
 * The closed button carries the class select, so it already has the height, edge, type and chevron of the other toolbar
 * lists. Here it only learns to sit still: a steady width (each screen size's own max-width still caps it, and the
 * phone row keeps the width 65_editor.css gives it) and one line of text that shortens with three dots.
 * The open list drops under the button. Tablet and PC: 320 px wide. Phone: pinned to the screen 8 px in from both
 * edges, because the toolbar row scrolls sideways and would cut it off; it scrolls inside itself.
 * Every row is one press target of 44 px or more. A chosen row has a ticked box and heavier type, never colour alone.
 * The rows touch each other on purpose: the whole control sits inside the toolbar's Area label, and a press on a gap
 * between rows would count as a press on that label (it would close the list). The heading ("Areas to show", the
 * legend) is kept for screen readers and is not drawn, for the same reason: a press on it closed the list in the proof.
 * SCOPE: no rule here may name the bare class area-pick - the record drawer's Change-area label has it too (60_changes.css). */
#area-select { position: relative; }
.area-pick-btn { display: block; width: 260px; overflow: hidden; text-align: left; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.area-pick-btn[aria-expanded="true"] { border-color: var(--brand); }
.area-pick-list { position: absolute; left: 0; top: calc(100% + 6px); z-index: 46; width: 320px; min-width: 0; max-width: calc(100vw - 32px); max-height: calc(100vh - 190px); max-height: calc(100dvh - 190px); margin: 0; padding: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); font-size: 15px; font-weight: 400; line-height: 1.3; white-space: normal; cursor: default; }
.area-pick-list[hidden] { display: none; }
.area-pick-legend { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.area-pick-opt { display: flex; align-items: center; gap: var(--sp-3); min-height: 44px; padding: var(--sp-1) var(--sp-3); cursor: pointer; -webkit-tap-highlight-color: transparent; }
.area-pick-opt:active, .area-pick-opt:has(.area-pick-box:focus-visible) { background: var(--surface-alt); }
.area-pick-all { border-bottom: 1px solid var(--line); }
.area-pick-box { flex: 0 0 auto; width: 22px; height: 22px; margin: 0; accent-color: var(--brand); cursor: pointer; }
.area-pick-name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.area-pick-count { flex: 0 0 auto; color: var(--ink-muted); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.area-pick-opt:has(.area-pick-box:checked) .area-pick-name { font-weight: 600; }
@media (hover: hover) { .area-pick-opt:hover { background: var(--surface-alt); } }
@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  .area-pick-list { position: fixed; left: 8px; right: 8px; top: auto; width: auto; max-width: 420px; max-height: min(56vh, 440px); max-height: min(56dvh, 440px); margin-top: 6px; }
}
/* ==== end N1-6b ==== */

/* ==== H-B (Fable, 16/11/2026): on a phone the footer and the scale take less of the screen ====
 * Footer: it was three lines (61 px) because the save status and the snapshot note ran on as one paragraph. Each now
 * has its own line: the save status first, the snapshot note under it in smaller type. No words are changed and
 * nothing is hidden; a long note wraps.
 * Scale: no card, and a shorter bar (50_plan.js updateScale picks the length: on a phone it now aims for 38 px and up,
 * so the bar is 38 to 95 px, not 110 to 275). A pale edge round the figures keeps them readable over the drawing. */
/* H-C: this block sits above the VF-D block on purpose. From the VF-D marker to the end of this file the harness
   (view-fix, VF-D AC6) allows working rules only: no colours, type, edges or shade. Add new styling above the marker. */
/* View only: while editing, the footer is already one line inside the edit dock, and it is left exactly as it was. */
html[data-device="phone"] body:not(.is-editing) .foot { display: flex; flex-direction: column; flex-wrap: nowrap; justify-content: flex-start; gap: 0; padding: 3px var(--sp-3) calc(3px + env(safe-area-inset-bottom, 0px)); font-size: 12px; line-height: 1.3; }
html[data-device="phone"] body:not(.is-editing) .foot p { display: block; min-width: 0; }
html[data-device="phone"] body:not(.is-editing) .foot #foot-source { font-size: 11px; line-height: 1.25; }
html[data-device="phone"] body:not(.is-editing) .foot #foot-source:empty { display: none; }
html[data-device="phone"] .stage .scale { gap: 6px; padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; -webkit-backdrop-filter: none; backdrop-filter: none; color: var(--ink); font-size: 12px; text-shadow: 0 0 2px var(--stage-bg), 0 0 2px var(--stage-bg), 0 0 3px var(--stage-bg), 0 0 3px var(--stage-bg); }
html[data-device="phone"] .stage .scale .scale-svg { overflow: visible; filter: drop-shadow(0 0 1px var(--stage-bg)) drop-shadow(0 0 1.5px var(--stage-bg)); }
/* ==== end H-B ==== */

/* VF-D (F34, 15/11/2026) - the phone record drawer has three states, set by 50_plan.js setDrawerState(): is-peek (the card,
   heights in 65_editor.css), is-half (the record, the 62dvh above) and is-full (the whole screen). Functional rules only:
   the handle and the Expand button are styled by the designer. Wide screens: the side panel, no states, no Expand. */
.drawer-expand { display: none; }
@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  .drawer.is-full { height: 100dvh; max-height: 100dvh; padding-top: env(safe-area-inset-top); }
  body.is-editing .drawer.is-full { height: calc(100dvh - var(--eb-h)); max-height: calc(100dvh - var(--eb-h)); } /* Edit: full = all the height above the edit bar (65_editor.css bottom: var(--eb-h)); beats its 54dvh cap */
  .drawer-expand:not([hidden]) { display: block; }
  .drawer.is-rec-edit .drawer-expand { display: none; }
}

/* ==== F12c begin (Fable, 15/11/2026): the record head in Edit ====
 * In Edit the head carries the "Change details" button (about 126 px wide; the reserve above was made for a 56 px
 * "Edit"), so the status badge beside the number ended up under it and read "Act". In Edit only: the number takes
 * the first row to itself, with the buttons at its right end as before, and the badge moves to the right end of the
 * name row. Nothing is cut at any drawer width and the head is no taller. View is untouched. */
body.is-editing .drawer-head > div > .drawer-id { flex: 0 0 100%; }
body.is-editing .drawer-head > div > .drawer-name { order: 2; flex: 1 1 0; }
body.is-editing .drawer-head > .badge { order: 2; align-self: flex-start; margin: 2px 0 0; }
/* F12c end ==== */
