/* ===========================================================================
   Quest Vision AOI — dark navy theme, aligned with Quest Admin / Web.

   One palette, one type scale, one set of radii and control heights. Every
   surface in this file is a token; there are no ad-hoc light backgrounds left,
   because a single `#fff` or `#f8fafc` on a dark page reads as a hole punched
   through the screen.

   Photographs are the exception on purpose: crops, thumbnails and reference
   images carry **no filter, no blend mode and no opacity**. Their backdrop is a
   dark neutral so a `contain`-fitted image does not sit in a glaring box, but
   the pixels themselves are shown exactly as captured — this is an inspection
   tool, and tinting the evidence would be a defect, not a style.
   =========================================================================== */

:root {
  /* Surfaces ------------------------------------------------------------- */
  --navy: #0d1b2a;        /* page */
  --surface: #1a2a3a;     /* cards, panels, table heads */
  --surface-2: #14222f;   /* recessed: inputs, code, image backdrop */
  --surface-3: #22364a;   /* raised: hover, badges */
  --border: #2a3a4a;

  /* Ink ------------------------------------------------------------------ */
  --text: #e0e0e0;
  --muted: #8892a0;

  /* Accent. `--accent` is for fills behind white text; `--link` is the text
     colour, because #1E6FD9 on #1A2A3A is only 3.0:1 and fails as text. */
  --accent: #1e6fd9;
  --accent-hover: #2a7fe8;
  --link: #6fa8f5;

  /* Status. Foreground carries the meaning; the tinted background is a hint,
     never the only signal. All four pass 4.5:1 on --surface. */
  --ok: #5cd08a;
  --ok-bg: rgba(92, 208, 138, .12);
  --ok-border: rgba(92, 208, 138, .38);
  --ng: #ff7a7a;
  --ng-bg: rgba(255, 122, 122, .12);
  --ng-border: rgba(255, 122, 122, .38);
  --warn: #f5a623;
  --warn-bg: rgba(245, 166, 35, .12);
  --warn-border: rgba(245, 166, 35, .38);
  --info-bg: rgba(30, 111, 217, .14);
  --info-border: rgba(30, 111, 217, .40);

  /* Shape and rhythm ----------------------------------------------------- */
  --radius-button: 8px;
  --radius-card: 16px;
  --radius-pill: 999px;
  --control: 44px;

  /* Type scale: body 14, heading 24, subheading 18, caption 12. No other
     sizes, so nothing drifts. */
  --text-body: 14px;
  --text-heading: 24px;
  --text-subheading: 18px;
  --text-caption: 12px;

  /* System stack only — nothing is downloaded. Simplified Chinese first so CJK
     never falls back to a Latin face with substituted glyphs. */
  --font: "Noto Sans SC", "Noto Sans", -apple-system, BlinkMacSystemFont,
          "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
          Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, "Noto Sans Mono", monospace;

  font-family: var(--font);
  color-scheme: dark;
}

/* Show inspection photos immediately; use two cards per row on wide screens. */
.positions.compact-positions { grid-template-columns: minmax(0, 1fr); gap: 10px; }
.compact-positions details.position { padding: 12px 16px; min-width: 0; }
.compact-positions details.position > summary { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; min-height: 44px; }
.compact-positions .position-name { flex: 1 1 180px; }
.compact-positions .crop-pair img { max-height: 390px; }
.compact-positions .when-closed { display: inline; }
.compact-positions .when-open { display: none; }
.compact-positions details[open] > summary .when-closed { display: none; }
.compact-positions details[open] > summary .when-open { display: inline; }
@media (min-width: 1100px) {
  .positions.compact-positions { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}
.group-header .header-facts { gap: 8px 16px; margin: 10px 0; }
.group-header .header-facts > div { padding: 4px 8px; }
.group-header .header-facts.simple-header-facts { grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); }
section.rerun-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 14px; }
.rerun-panel .reinspect { margin: 0; }
.rerun-panel [data-rerun-progress]:empty { display: none; }
.product-info, .operation-help, .remaining-details { margin: 8px 0; }
.product-info > summary, .operation-help > summary, .remaining-details > summary { min-height: 44px; display: flex; align-items: center; }

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--navy);
  color: var(--text);
  min-height: 100vh;
  font-family: var(--font);
  font-size: var(--text-body);
  line-height: 1.6;
}

/* Every control inherits the same face and size — a `select` that keeps the
   platform default is the thing that makes a form look assembled from parts. */
button, input, select, textarea, ::file-selector-button {
  font-family: var(--font);
  font-size: var(--text-body);
}
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--link); }
code, kbd, samp, pre { font-family: var(--font-mono); }
code { color: var(--text); background: var(--surface-2); border-radius: 4px; padding: 1px 5px; }

:focus-visible { outline: 3px solid var(--link); outline-offset: 2px; }

h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: var(--text-heading); font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: var(--text-subheading); font-weight: 700; }
h3 { font-size: var(--text-subheading); font-weight: 650; }
h4 { font-size: var(--text-body); font-weight: 700; margin: 0 0 6px; }

/* --- shell ---------------------------------------------------------------- */

.topbar {
  height: 68px; background: var(--surface); color: var(--text);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 max(24px, calc((100vw - 1120px) / 2));
}
.brand { display: flex; align-items: center; gap: 12px; font-size: var(--text-subheading); font-weight: 700; }
.brand-mark {
  width: 38px; height: 38px; border-radius: var(--radius-button);
  background: var(--accent); color: #fff;
  display: inline-grid; place-items: center; font-weight: 800;
}
.quiet {
  border: 1px solid var(--border); background: transparent; color: var(--text);
  border-radius: var(--radius-button); padding: 0 16px; min-height: var(--control); cursor: pointer;
}
.quiet:hover { background: var(--surface-3); border-color: var(--link); }

.tabs {
  min-height: 48px; display: flex; align-items: stretch; gap: 4px;
  padding: 0 max(24px, calc((100vw - 1120px) / 2));
  background: var(--navy); border-bottom: 1px solid var(--border); overflow-x: auto;
}
.tabs a {
  display: grid; place-items: center; padding: 0 16px; color: var(--muted);
  text-decoration: none; font-size: var(--text-body); font-weight: 650;
  white-space: nowrap; border-bottom: 3px solid transparent;
}
.tabs a:hover { color: var(--text); background: var(--surface); }
.tabs a.active { color: var(--link); border-bottom-color: var(--accent); }
.legacy-link { color: var(--muted); font-weight: 600; }

.page { width: min(1120px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0 64px; }
.intro { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; margin-bottom: 24px; }
.intro p { color: var(--muted); margin: 0; font-size: var(--text-body); line-height: 1.6; }
.intro.compact { margin-bottom: 20px; }
.scope {
  white-space: nowrap; color: var(--warn); background: var(--warn-bg);
  border: 1px solid var(--warn-border); border-radius: var(--radius-button);
  padding: 9px 12px; font-weight: 650; font-size: var(--text-caption);
}

/* --- testing guide ------------------------------------------------------- */

.guide-header, .guide-finish {
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
}
.guide-header { margin-bottom: 24px; }
.guide-header p, .guide-finish p { margin: 0; color: var(--muted); }
.primary-link {
  display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
  min-height: var(--control); padding: 0 18px; border-radius: var(--radius-button);
  color: #fff; background: var(--accent); text-decoration: none; font-weight: 700;
}
.primary-link:hover { color: #fff; background: var(--accent-hover); }
.guide-flow {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: 4px 24px; margin-bottom: 18px;
}
.guide-step { display: grid; grid-template-columns: 44px minmax(0, 1fr); gap: 18px; padding: 24px 0; }
.guide-step + .guide-step { border-top: 1px solid var(--border); }
.guide-number {
  display: grid; place-items: center; width: 40px; height: 40px; border-radius: var(--radius-pill);
  color: #fff; background: var(--accent); font-size: var(--text-subheading); font-weight: 800;
}
.guide-step h2 { margin: 4px 0 8px; }
.guide-step p { margin-bottom: 8px; }
.guide-note { color: var(--muted); }
.guide-choices { margin: 10px 0; padding-left: 20px; }
.guide-choices li + li { margin-top: 6px; }
.guide-help {
  margin-bottom: 18px; padding: 22px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card);
}
.guide-help h2 { margin-bottom: 14px; }
.guide-help dl { margin: 0; }
.guide-help dl > div { display: grid; grid-template-columns: 160px minmax(0, 1fr); gap: 18px; padding: 12px 0; }
.guide-help dl > div + div { border-top: 1px solid var(--border); }
.guide-help dt { font-weight: 700; color: var(--text); }
.guide-help dd { margin: 0; color: var(--muted); }
.guide-finish {
  padding: 18px 22px; background: var(--info-bg); border: 1px solid var(--info-border);
  border-radius: var(--radius-card);
}
.guide-question { margin-top: 18px; padding: 18px 22px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
.guide-question summary { min-height: 44px; display: flex; align-items: center; color: var(--link); font-weight: 700; cursor: pointer; }
.guide-question form { display: grid; gap: 10px; padding-top: 12px; }
.guide-question label { color: var(--muted); font-weight: 650; }
.guide-question textarea { min-height: 110px; resize: vertical; }
.guide-question button { justify-self: start; }

/* --- trial activity ------------------------------------------------------ */
.activity-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.activity-header p, .activity-list .section-heading p { margin: 0; color: var(--muted); }
.activity-note { margin: 0 0 18px; padding: 12px 14px; color: var(--muted); background: var(--info-bg); border: 1px solid var(--info-border); border-radius: var(--radius-button); }
.activity-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.activity-summary article { display: grid; gap: 4px; padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
.activity-summary span, .activity-summary small { color: var(--muted); }
.activity-summary strong { color: var(--text); font-size: 28px; }
.activity-table { width: 100%; border-collapse: collapse; }
.activity-table th, .activity-table td { padding: 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.activity-table th { color: var(--muted); font-size: var(--text-caption); }

/* --- cards and panels ----------------------------------------------------- */

.panel, .upload-form, .asset-panel, .identity-panel, .run, .shortcut-help,
.filters, .metric-summary > div, .bank-item, .empty-state, .login-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
}
.panel { margin-bottom: 18px; padding: 22px; }
.upload-form { padding: 26px; }
.section-heading { display: flex; justify-content: space-between; gap: 18px; align-items: end; margin-bottom: 18px; }
.section-heading h2 { margin-bottom: 4px; }
.section-heading p { margin: 0; color: var(--muted); font-size: var(--text-caption); }

/* --- forms and controls --------------------------------------------------- */

fieldset { border: 0; padding: 0; margin: 0 0 22px; }
legend, .file-field strong { font-size: var(--text-subheading); font-weight: 650; margin-bottom: 10px; }
label { color: var(--text); }

input, select, textarea { max-width: 100%; box-sizing: border-box; }
input[type="text"], input[type="date"], input[type="password"], input[type="search"],
select, textarea {
  min-height: var(--control); padding: 10px 12px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-button);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
input[type="text"]:focus, select:focus, textarea:focus { border-color: var(--link); }

input[type="file"] { color: var(--muted); width: 100%; padding: 8px 0; }
::file-selector-button {
  min-height: 40px; margin-right: 12px; padding: 0 14px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-button);
  background: var(--surface-3); color: var(--text); font-weight: 650;
}
::file-selector-button:hover { border-color: var(--link); }

/* Checkbox and radio: the box itself takes the accent, and the label beside it
   is a comfortable target without stretching the row. */
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); width: 18px; height: 18px; }
label:has(> input[type="checkbox"]), label:has(> input[type="radio"]) {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 36px; color: var(--text); font-size: var(--text-body);
}

button {
  min-height: var(--control); padding: 0 18px; cursor: pointer;
  border: 1px solid var(--border); border-radius: var(--radius-button);
  background: var(--surface-3); color: var(--text); font-weight: 650;
}
button:hover { border-color: var(--link); }
button[disabled] { opacity: .5; cursor: not-allowed; }
.saved-choice { color: var(--ok); font-size: var(--text-caption); font-weight: 700; }
.queue-view-switch { display: flex; justify-content: flex-end; margin: -30px 0 16px; }
.queue-actions-cell { min-width: 190px; vertical-align: middle; }
.queue-row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; white-space: nowrap; }
.record-action { display: inline-flex; margin: 0; }
.queue-primary-action,
.queue-secondary-action,
.queue-archive-action {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 38px; padding: 0 14px; border-radius: var(--radius-button);
  font-size: var(--text-body); font-weight: 700; text-decoration: none;
}
.queue-primary-action { color: #fff; background: var(--accent); border: 1px solid var(--accent); }
.queue-primary-action:hover { color: #fff; background: var(--accent-hover); border-color: var(--accent-hover); }
.queue-secondary-action { color: var(--text); background: transparent; border-color: var(--border); }
.queue-secondary-action:hover { background: var(--surface-3); border-color: var(--link); }
.queue-archive-action { min-height: 38px; color: var(--muted); background: transparent; border-color: transparent; padding-inline: 10px; }
.queue-archive-action:hover { color: var(--ng); background: var(--ng-bg); border-color: var(--ng-border); }
.queue-archive-time { display: block; margin-top: 6px; color: var(--muted); font-size: var(--text-caption); text-align: right; }
.quiet-danger { color: var(--muted); background: transparent; }
.quiet-danger:hover { color: var(--ng); border-color: var(--ng-border); }

/* Accent fill is scarce on purpose: one obvious action per form. The inline row
   actions in the photo table (assign view, attach, re-upload) stay neutral —
   they are secondary, and a screen of competing blue buttons tells an operator
   nothing about where to look. */
.primary,
.import > button[type="submit"],
.upload-form button[type="submit"],
.filters button[type="submit"],
.identity-form button[type="submit"],
.login-form button[type="submit"],
.completion-bar button[type="submit"] {
  border-color: var(--accent); background: var(--accent); color: #fff; font-weight: 700;
}
.primary:hover,
.import > button[type="submit"]:hover,
.upload-form button[type="submit"]:hover,
.filters button[type="submit"]:hover,
.identity-form button[type="submit"]:hover,
.login-form button[type="submit"]:hover,
.completion-bar button[type="submit"]:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

/* Two submits sit in the sticky bar. The "six normal, finish" action is the
   frequent one; "save" beside it stays quieter so they are distinguishable. */
.completion-bar #bulk-normal-button { border-color: var(--accent); background: var(--accent); color: #fff; }
.completion-bar button[type="submit"]:not(#bulk-normal-button) {
  background: transparent; border-color: var(--border); color: var(--text); font-weight: 650;
}
.completion-bar button[type="submit"]:not(#bulk-normal-button):hover { border-color: var(--link); background: var(--surface-3); }
.analyze { width: 100%; margin-top: 18px; font-size: var(--text-subheading); }

.sizes { display: flex; gap: 10px; }
.sizes label { cursor: pointer; }
.sizes input { position: absolute; opacity: 0; }
.sizes span {
  display: grid; place-items: center; width: 64px; height: var(--control);
  border: 1px solid var(--border); border-radius: var(--radius-button);
  font-weight: 650; background: var(--surface-2); color: var(--text);
}
.sizes input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.sizes input:focus-visible + span { outline: 3px solid var(--link); outline-offset: 2px; }

.file-fields { display: grid; grid-template-columns: 1fr; gap: 16px; }
.file-field {
  border: 1px solid var(--border); background: var(--surface-2);
  border-radius: var(--radius-card); padding: 18px;
  display: flex; flex-direction: column; gap: 8px;
}
.file-field span { color: var(--muted); font-size: var(--text-caption); }

.filters { display: flex; align-items: end; gap: 12px; padding: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.filters label { display: grid; gap: 6px; color: var(--muted); font-size: var(--text-caption); font-weight: 650; }
.filters select, .filters input { min-height: var(--control); }

.fixed-recipe {
  display: flex; justify-content: space-between; gap: 18px; margin: 0 0 22px;
  padding: 14px 16px; border-radius: var(--radius-button);
  background: var(--info-bg); border: 1px solid var(--info-border); color: var(--text);
}
.fixed-recipe span { color: var(--muted); text-align: right; }
.privacy { color: var(--muted); text-align: center; font-size: var(--text-caption); margin: 12px 0 0; }

/* --- messages and status -------------------------------------------------- */

.message { border-radius: var(--radius-button); padding: 12px 14px; margin-bottom: 16px; border: 1px solid var(--border); }
.message.error { color: var(--ng); background: var(--ng-bg); border-color: var(--ng-border); }
.message.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-border); }
.message.ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-border); }
.message strong, .message ul, .message li { color: var(--text); }
.warn-inline { color: var(--warn); font-weight: 650; }
.danger-text { color: var(--ng); }
.na { color: var(--muted); font-weight: 700; }

.status-label { display: inline-block; border-radius: 6px; padding: 5px 9px; font-size: var(--text-caption); font-weight: 700; margin-bottom: 12px; }
.ok_candidate .status-label { color: var(--ok); background: var(--ok-bg); }
.suspect .status-label { color: var(--ng); background: var(--ng-bg); }
.not_evaluable .status-label { color: var(--warn); background: var(--warn-bg); }

.badge {
  display: inline-block; font-size: var(--text-caption); font-weight: 650;
  padding: 3px 10px; border-radius: var(--radius-pill);
  background: var(--surface-3); color: var(--text); border: 1px solid var(--border);
}
.badge.current { background: var(--info-bg); color: var(--link); border-color: var(--info-border); }

/* --- legacy single-photo result screens ----------------------------------- */

.results { margin-top: 32px; }
.results-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.results-heading h2 { margin-bottom: 4px; }
.results-heading p { margin: 0; color: var(--muted); }
.results-heading a { color: var(--link); font-weight: 650; text-decoration: none; }
.overall-result {
  display: flex; justify-content: space-between; gap: 24px; margin-bottom: 14px; padding: 20px;
  border: 1px solid var(--border); border-left-width: 6px; border-radius: var(--radius-card);
  background: var(--surface);
}
.overall-result.ok_candidate { border-left-color: var(--ok); background: var(--ok-bg); }
.overall-result.suspect { border-left-color: var(--ng); background: var(--ng-bg); }
.overall-result.not_evaluable { border-left-color: var(--warn); background: var(--warn-bg); }
.overall-result > div:first-child > span { display: block; margin-bottom: 4px; color: var(--muted); font-size: var(--text-caption); font-weight: 650; }
.overall-result strong { display: block; font-size: var(--text-heading); }
.overall-result p { margin: 7px 0 0; color: var(--muted); line-height: 1.5; }
.overall-counts { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.overall-counts span { padding: 7px 9px; border-radius: 6px; background: var(--surface-2); font-size: var(--text-caption); font-weight: 650; }
.size-result {
  display: flex; justify-content: space-between; gap: 18px; margin-bottom: 14px; padding: 13px 15px;
  border: 1px solid var(--info-border); border-radius: var(--radius-button); background: var(--info-bg);
}
.size-result span { color: var(--muted); font-size: var(--text-caption); text-align: right; }
.trial-note { margin: 0 0 14px; padding: 11px 14px; border-radius: var(--radius-button); background: var(--surface-2); color: var(--muted); font-size: var(--text-caption); }
.result {
  display: grid; grid-template-columns: minmax(260px, .72fr) 1.5fr; gap: 24px;
  background: var(--surface); border: 1px solid var(--border); border-left-width: 6px;
  border-radius: var(--radius-card); padding: 22px; margin-bottom: 16px;
}
.result.ok_candidate { border-left-color: var(--ok); }
.result.suspect { border-left-color: var(--ng); }
.result.not_evaluable { border-left-color: var(--warn); }
.result h3 { margin-bottom: 9px; }
.summary { font-size: var(--text-body); line-height: 1.6; }
.human-review { margin: 16px 0 0; padding: 13px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-button); }
.human-review > span { display: block; margin-bottom: 8px; font-size: var(--text-caption); color: var(--muted); font-weight: 650; }
.human-review form { display: flex; gap: 8px; flex-wrap: wrap; }
.human-review button { min-height: 40px; padding: 0 12px; background: var(--surface-3); }
.human-review .review-ok { color: var(--ok); }
.human-review .review-ng { color: var(--ng); }
.human-review .review-ok.selected { color: var(--navy); background: var(--ok); border-color: var(--ok); }
.human-review .review-ng.selected { color: var(--navy); background: var(--ng); border-color: var(--ng); }
.human-review .review-clear { color: var(--muted); }
.human-review small { display: block; margin-top: 8px; color: var(--muted); line-height: 1.5; }
.decision-boundary { color: var(--muted); font-size: var(--text-caption); text-align: center; margin: 18px 0 0; }

/* --- definition lists and disclosures -------------------------------------- */

dl { margin: 16px 0 0; display: grid; gap: 6px; }
dl div { display: flex; justify-content: space-between; gap: 10px; border-bottom: 1px solid var(--border); padding: 6px 0; }
dt { color: var(--muted); font-size: var(--text-caption); }
dd { margin: 0; font-size: var(--text-body); font-weight: 650; }
.note { color: var(--muted); font-size: var(--text-caption); line-height: 1.6; margin: 14px 0 0; }

details { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; }
summary { color: var(--link); cursor: pointer; font-size: var(--text-body); font-weight: 650; }
details[open] summary { margin-bottom: 6px; }
.engineering-detail { margin-top: 10px; font-size: var(--text-body); }
.engineering-detail summary { color: var(--muted); font-weight: 650; }
.engineering-detail > summary { cursor: pointer; padding: 10px 0; min-height: var(--control); }
.evidence { margin: 14px 0; }
.evidence-block { border-left: 3px solid var(--accent); padding-left: 12px; margin: 12px 0; }

/* --- imagery ---------------------------------------------------------------
   Nothing below applies a filter, blend mode or opacity to a photograph. The
   backdrop is dark so a contained image is not framed in glare; the pixels are
   shown as captured. */

figure { margin: 0; min-width: 0; }
figure img {
  display: block; width: 100%; aspect-ratio: 1 / 1; object-fit: contain;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-button);
}
figcaption { text-align: center; color: var(--muted); font-size: var(--text-caption); margin-top: 6px; }
.comparisons { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }

.crop-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.crop-pair figure { margin: 0; }
.crop-pair figcaption { font-size: var(--text-caption); color: var(--muted); margin-bottom: 4px; }
.crop-pair img {
  width: 100%; height: auto; display: block;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
}
.crop-pair img:hover { border-color: var(--link); }
.crop-pair a:focus-visible img { outline: 3px solid var(--link); outline-offset: 2px; }

.asset-thumb {
  width: 96px; height: 72px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface-2);
}
.image-bank { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.golden-bank { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 10px; }
.golden-bank figcaption { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bank-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; margin-top: 12px; }
.bank-item { margin: 0; padding: 8px; min-width: 0; }
.bank-item img { width: 100%; height: 130px; object-fit: contain; background: var(--surface-2); border-radius: 6px; }
.bank-item figcaption { margin-top: 8px; font-size: var(--text-caption); line-height: 1.6; text-align: left; }
.bank-item strong { display: block; margin-top: 7px; font-size: var(--text-body); }
.bank-item span, .bank-item small { display: block; margin-top: 3px; color: var(--muted); font-size: var(--text-caption); }
.bank-item.label-ng { border-color: var(--ng-border); }
.bank-item.label-ok { border-color: var(--ok-border); }
.bank-item.reference { border-style: dashed; background: var(--surface-2); }
.empty-state { padding: 32px 18px; text-align: center; }
.empty-state strong { display: block; font-size: var(--text-subheading); }
.empty-state p { margin: 8px 0 0; color: var(--muted); font-size: var(--text-caption); }

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

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--text-body); }
th, td { padding: 11px 10px; border-bottom: 1px solid var(--border); text-align: left; }
thead th { color: var(--muted); background: var(--surface-2); font-size: var(--text-caption); font-weight: 650; white-space: nowrap; }
tbody th { font-size: var(--text-body); }
tbody tr:hover { background: var(--surface-3); }
.table-link, .metrics-table td a, .pager a { color: var(--link); font-weight: 650; text-decoration: none; }

.groups, .assets, .positions-table, .metrics-table { width: 100%; border-collapse: collapse; font-size: var(--text-body); }
.groups th, .groups td { border-bottom: 1px solid var(--border); padding: 10px 10px; text-align: left; }
.assets th, .assets td,
.positions-table th, .positions-table td,
.metrics-table th, .metrics-table td { border-bottom: 1px solid var(--border); padding: 9px 10px; text-align: left; vertical-align: top; }
.assets th, .positions-table th, .metrics-table th { background: var(--surface-2); color: var(--muted); font-size: var(--text-caption); white-space: nowrap; }
.engineering-row td { padding-top: 0; }
.pager { display: flex; align-items: center; gap: 14px; margin-top: 14px; font-size: var(--text-body); }
.timeline ol { font-size: var(--text-body); color: var(--text); }

/* --- metrics --------------------------------------------------------------- */

.metric-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.metric-summary > div { padding: 18px; }
.metric-summary span { display: block; color: var(--muted); font-size: var(--text-caption); font-weight: 650; }
.metric-summary strong { display: block; margin-top: 6px; font-size: var(--text-heading); }
.confusion-grid { display: grid; grid-template-columns: 100px repeat(2, minmax(110px, 180px)); gap: 8px; justify-content: center; align-items: stretch; }
.matrix-axis { display: grid; place-items: center; min-height: 36px; color: var(--muted); font-size: var(--text-caption); font-weight: 650; text-align: center; }
.matrix-cell { display: grid; place-items: center; min-height: 92px; border-radius: var(--radius-button); border: 1px solid var(--border); background: var(--surface-2); }
.matrix-cell strong { font-size: var(--text-heading); }
.matrix-cell span { font-size: var(--text-caption); font-weight: 700; }
.matrix-cell.tp, .matrix-cell.tn { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-border); }
.matrix-cell.fp, .matrix-cell.fn { color: var(--ng); background: var(--ng-bg); border-color: var(--ng-border); }
.data-note { margin: 16px 0 0; color: var(--muted); font-size: var(--text-caption); text-align: center; }

/* The headline 2×2. Colour is a hint; TP/FP/FN/TN are labelled in text, so the
   matrix is still readable without it. */
.confusion { display: flex; gap: 24px; flex-wrap: wrap; align-items: stretch; }
.confusion-matrix { flex: 1; min-width: 280px; border-collapse: separate; border-spacing: 6px; }
.confusion-matrix th { padding: 10px; text-align: center; background: transparent; color: var(--muted); }
.confusion-matrix .cell { padding: 18px; text-align: center; border-radius: var(--radius-button); border: 1px solid var(--border); }
.confusion-matrix .tp, .confusion-matrix .tn { background: var(--ok-bg); border-color: var(--ok-border); }
.confusion-matrix .fp, .confusion-matrix .fn { background: var(--ng-bg); border-color: var(--ng-border); }
.cell-name { display: block; font-size: var(--text-caption); font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.confusion-matrix .tp .cell-name, .confusion-matrix .tn .cell-name { color: var(--ok); }
.confusion-matrix .fp .cell-name, .confusion-matrix .fn .cell-name { color: var(--ng); }
.confusion-matrix .cell a { display: block; font-size: var(--text-heading); font-weight: 700; min-height: var(--control); color: var(--text); text-decoration: none; }
.confusion-matrix .cell a:hover { color: var(--link); }
.headline-ratios { min-width: 230px; margin: 0; }
.headline-ratios > div { display: flex; gap: 16px; justify-content: space-between; padding: 12px; border-bottom: 1px solid var(--border); }
.headline-ratios dt { font-size: var(--text-body); }
.headline-ratios dd { margin: 0; font-weight: 700; }

/* --- v3 group review -------------------------------------------------------- */

.group-header { margin-bottom: 18px; }
.group-header .header-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px 18px; margin: 0; }
.group-header .header-facts div { border-left: 3px solid var(--accent); border-bottom: 0; padding: 2px 0 2px 12px; display: block; }
.group-header dt { font-size: var(--text-caption); color: var(--muted); }
.group-header dd { margin: 3px 0 0; font-weight: 650; }
.side-heading { margin: 24px 0 10px; border-bottom: 1px solid var(--border); padding-bottom: 6px; color: var(--text); }

.positions { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }
.position { border: 1px solid var(--border); border-radius: var(--radius-card); padding: 14px; background: var(--surface); }
.position header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.position h3 { margin: 0; }
.position .badge { font-size: var(--text-caption); }
.position.status-ok_candidate .badge { background: var(--ok-bg); color: var(--ok); border-color: var(--ok-border); }
.position.status-ok_candidate .badge.manual-review,
.position .badge.manual-review { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.position.status-suspect .badge { background: var(--ng-bg); color: var(--ng); border-color: var(--ng-border); }
.position.status-not_evaluable .badge { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.position.status-missing_photo .badge, .position.status-unsupported .badge { background: var(--surface-3); color: var(--muted); }
.position fieldset { border: 1px solid var(--border); border-radius: var(--radius-button); margin: 10px 0 0; padding: 10px; }
.position legend { font-size: var(--text-caption); color: var(--muted); margin-bottom: 0; }
.position .reason { display: block; margin-top: 8px; font-size: var(--text-caption); color: var(--muted); }
.position .reason input { width: 100%; margin-top: 4px; }
.position .viewed { display: block; margin-top: 8px; font-size: var(--text-caption); }
.viewed-box { display: inline-flex; align-items: center; gap: 8px; font-size: var(--text-caption); }
.viewed-status { color: var(--muted); font-size: var(--text-caption); }
.manual-review-reason { margin: 10px 0 0; color: var(--warn); font-weight: 650; }
.unavailable {
  font-size: var(--text-caption); color: var(--warn); background: var(--warn-bg);
  border: 1px dashed var(--warn-border); border-radius: 6px; padding: 10px; margin: 0;
}

/* Sticky action bar. z-index keeps it above the position cards it slides over, and the
   safe-area inset stops the last button sitting under an iPhone's home indicator. */
.completion-bar { position: sticky; bottom: 0; z-index: 20; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; background: var(--surface); color: var(--text); border: 1px solid var(--border); padding: 12px 14px calc(12px + env(safe-area-inset-bottom, 0px)); border-radius: var(--radius-card); margin: 18px 0; box-shadow: 0 -8px 24px rgba(0, 0, 0, .35); }
.completion-bar button:focus-visible { outline: 3px solid var(--link); outline-offset: 2px; }
.review-page-nav { margin: 12px 0; }
.back-to-list { display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border: 1px solid var(--border); border-radius: var(--radius-button); text-decoration: none; }
.completion-bar.review-actions { position: static; box-shadow: none; padding: 18px; justify-content: space-between; gap: 16px; }
.review-progress { display: grid; gap: 4px; }
.review-progress strong { font-size: 24px; line-height: 1.3; }
.review-progress strong span { font-size: 16px; font-weight: 400; }
.progress-caption, .unsaved-count { font-size: 14px; color: var(--muted); }
.review-action-buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.review-action-buttons a { display: inline-flex; min-height: 44px; align-items: center; padding: 0 12px; }
.completion-bar.review-actions button.primary:not(#bulk-normal-button) { background: var(--accent); border-color: var(--accent); color: #fff; }
.completion-bar.review-actions button.primary:not(#bulk-normal-button):hover { background: var(--accent-hover); }
.review-action-note { flex-basis: 100%; margin: 0; color: var(--muted); font-size: 14px; }
.supporting-info { margin: 28px 0 18px; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface); overflow: hidden; }
.supporting-info > .supporting-summary { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 18px 20px; min-height: 64px; cursor: pointer; }
.supporting-summary strong { display: block; font-size: 18px; color: var(--text); }
.supporting-summary small { display: block; margin-top: 5px; font-size: 14px; color: var(--muted); }
.supporting-toggle { font-size: 14px; white-space: nowrap; color: var(--link); }
.supporting-content { padding: 0 20px 16px; border-top: 1px solid var(--border); }
.supporting-content > details { margin: 0; padding: 12px 0; }
.supporting-content > details > summary { min-height: 44px; display: flex; align-items: center; gap: 10px; }
.support-count { background: var(--surface-2); border: 1px solid var(--border); border-radius: 16px; padding: 2px 8px; font-size: 12px; color: var(--muted); }
.review-footer-nav, .review-footer-tools { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.review-footer-nav { justify-content: space-between; margin: 20px 0 32px; padding-top: 16px; border-top: 1px solid var(--border); }
.secondary-nav-button { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 16px; border: 1px solid var(--border); border-radius: var(--radius-button); color: var(--text); text-decoration: none; background: var(--surface); }
.secondary-nav-button:hover, .back-to-list:hover { border-color: var(--link); background: var(--surface-2); }
@media (max-width: 640px) {
  .review-action-buttons { flex-direction: column; align-items: stretch; width: 100%; }
  .review-action-buttons a { justify-content: center; }
}
.completion-bar button { padding: 0 16px; }
.completion-bar .acknowledge { font-size: var(--text-body); }

/* Four identifiers as four lines, and progress as one line per statement. Both are
   rendered inside table cells, so they wrap and shrink rather than widening the row. */
.identifiers { list-style: none; margin: 0; padding: 0; }
.identifiers li { display: block; margin: 0 0 4px; overflow-wrap: anywhere; word-break: break-word; }
.identifiers .id-label { color: var(--muted); font-size: var(--text-caption); margin-right: 6px; }
.identifiers .id-value { overflow-wrap: anywhere; word-break: break-word; }
.progress-line { display: block; overflow-wrap: anywhere; }
.rerun-panel { background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-card); padding: 14px; margin: 18px 0; }
.rerun-panel h2 { margin-bottom: 6px; }

/* Photos start open; collapsing is optional. Keep the header touch target generous. */
details.position > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  min-height: 44px; padding: 10px 12px; cursor: pointer; font-size: var(--text-body); }
details.position > summary .position-name { font-weight: 600; }
details.position > summary .look { margin-left: auto; color: var(--link); }
details.position[open] > summary { border-bottom: 1px solid var(--border); }
details.position fieldset label { min-height: 44px; display: inline-flex; align-items: center; }

/* Thumbnails first, corrections behind a disclosure. */
.photo-thumbs { display: flex; flex-wrap: wrap; gap: 18px; margin: 12px 0; }
.photo-thumb-group { min-width: 140px; }
.photo-thumb-group h3 { font-size: var(--text-body); margin-bottom: 6px; }
.photo-thumb-group figure { margin: 0 0 8px; }
.photo-thumb-group figure.superseded img { opacity: .55; }

.identity-panel { padding: 14px; margin: 18px 0; }
.identity-form label, .import label { display: block; margin: 8px 0; font-size: var(--text-body); }
.import .lead { font-size: var(--text-body); color: var(--text); margin-bottom: 10px; }

.asset-panel { padding: 14px; margin: 18px 0; }
.asset-panel .fields, .asset-actions { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; }
/* `position: relative` is the containing block for the `.sr-label` inside each of these
   forms. Without it those labels are `position: absolute` with no positioned ancestor, so
   they resolve against the *initial* containing block: their static position sits inside a
   1020px-wide table, and they were measured at left 965.5 on a 390px screen, holding
   `documentElement.scrollWidth` at 966 even though `body.scrollWidth` was 390. The table's
   own `overflow-x: auto` could not contain them, because they were never laid out relative
   to it. This adds no visual change — nothing here is offset — it only decides *what* the
   hidden label is positioned against. */
.asset-actions form.inline { position: relative; display: flex; flex-wrap: wrap; align-items: end; gap: 8px; }
.attach-form, .retake-form, .add-photos, .reinspect, .review-form { margin: 10px 0; }
.sr-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.run { padding: 14px; margin: 14px 0; }
.run.current-run { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(30, 111, 217, .18); }
.snapshot { max-height: 260px; overflow: auto; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); padding: 12px; border-radius: var(--radius-button); font-size: var(--text-caption); }

/* An anchored run or position must be visible on arrival, not merely scrolled to. */
.run:target { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(30, 111, 217, .28); }
.positions-table tr:target { background: var(--info-bg); outline: 2px solid var(--accent); }
.run, .positions-table tr { scroll-margin-top: 84px; }

/* --- login ------------------------------------------------------------------ */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; background: var(--navy); }
.login-panel { width: min(420px, 100%); padding: 34px; box-shadow: 0 24px 70px rgba(0, 0, 0, .45); }
.login-panel .brand-mark { margin-bottom: 20px; }
.login-panel h1 { margin-bottom: 6px; }
.login-panel > p { color: var(--muted); margin-bottom: 24px; }
.login-form { display: grid; gap: 10px; }
.login-form label { font-size: var(--text-caption); color: var(--muted); font-weight: 650; }
.login-form input { margin-bottom: 6px; }
.login-form button { margin-top: 8px; }

/* --- accessibility helpers --------------------------------------------------- */

/* A keyboard user should reach the work without tabbing the whole nav first. Visible only
   when focused, so it costs a mouse user nothing. */
.skip-link { position: absolute; left: -9999px; top: 0; background: var(--accent); color: #fff; padding: 10px 16px; border-radius: 0 0 6px 0; z-index: 50; }
.skip-link:focus { left: 0; }

/* R1.6 shortcut list. Collapsed by default; `?` opens it. */
.shortcut-help { margin: 0 0 16px; padding: 10px 14px; }
.shortcut-help summary { font-weight: 650; cursor: pointer; }
.shortcut-help kbd {
  display: inline-block; min-width: 20px; padding: 2px 6px;
  border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px;
  background: var(--surface-3); color: var(--text);
  font: 650 var(--text-caption)/1.4 var(--font-mono); text-align: center;
}

/* The card the shortcuts move to is programmatically focused, so it must show it. */
.position:focus-visible { outline: 3px solid var(--link); outline-offset: 3px; }
.position { scroll-margin-top: 84px; }
.bank-item a:focus-visible, .metrics-table a:focus-visible { outline: 3px solid var(--link); }

/* ---------------------------------------------------------------------------
   390px: let content shrink and wrap, never clip it.

   Measured in a real browser at 390×844: the queue was 390px wide and the review
   page was 966px. Three things were widening it, and none of them was the table —
   a table scrolling inside itself is fine.

   1. A grid or flex item defaults to `min-width: auto`, which is its *content*
      width. One 64-character path or SHA-256 inside a `minmax(300px, 1fr)` track
      therefore pushes the track past the viewport no matter how well the text
      could have wrapped. `min-width: 0` is what lets the wrapping below work.
   2. Hashes, ids, paths and filenames have no break opportunity. `overflow-wrap`
      is inherited, so one declaration on the page container covers every one of
      them without listing elements that will change.
   3. A file input and a `select` carry an intrinsic width of their own.

   What is deliberately *not* here: `overflow-x: hidden` on a page container. It
   would make the measurement look right while cutting evidence off the side of the
   screen, which is worse than the bug. --------------------------------------- */
.page { overflow-wrap: anywhere; }

.positions > *,
.header-facts > div,
.crop-pair > figure,
.asset-actions > form,
.position header > * { min-width: 0; }

/* A wide table scrolls inside its own container, at every viewport rather than only on a
   phone. The photo table's min-content width is real once its view/attach controls render
   — measured at 1424px inside a 1120px page — and containment that lived only in the
   `max-width: 430px` query let the desktop page grow to 1519.

   The container is a block, not the table: `overflow` is not reliably honoured on a
   `display: table` box. `min-width: 0` keeps it shrinkable if it is ever placed in a flex
   or grid parent, and the focus ring is visible because `tabindex="0"` makes this a real
   tab stop for keyboard scrolling. */
.table-scroll { overflow-x: auto; max-width: 100%; min-width: 0; }
.table-scroll:focus-visible { outline: 3px solid var(--link); outline-offset: 2px; }

@media (max-width: 760px) {
  .topbar { padding: 0 16px; }
  .tabs { padding: 0 8px; }
  .tabs a { padding: 0 12px; }
  .page { width: min(100% - 22px, 1120px); padding-top: 24px; }
  .intro { display: block; }
  .scope { display: inline-block; margin-top: 14px; }
  .upload-form { padding: 18px; }
  .file-fields, .result { grid-template-columns: 1fr; }
  .result { padding: 18px; }
  .results-heading { align-items: flex-start; }
  .size-result { display: grid; gap: 6px; }
  .size-result span { text-align: left; }
  .overall-result { display: grid; }
  .overall-counts { flex-wrap: wrap; }
  .metric-summary { grid-template-columns: 1fr 1fr; }
  .confusion-grid { grid-template-columns: 72px repeat(2, minmax(82px, 1fr)); }
  .matrix-cell { min-height: 76px; }
  .panel { padding: 16px; }
  .image-bank { grid-template-columns: 1fr 1fr; }
  .golden-bank { grid-template-columns: repeat(3, 1fr); }
  .guide-header, .guide-finish { align-items: stretch; flex-direction: column; }
  .guide-header .primary-link, .guide-finish .primary-link { width: 100%; }
  .guide-flow { padding: 2px 16px; }
  .guide-step { grid-template-columns: 36px minmax(0, 1fr); gap: 12px; padding: 20px 0; }
  .guide-number { width: 34px; height: 34px; }
  .guide-help dl > div { grid-template-columns: 1fr; gap: 3px; }
  .activity-summary { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 640px) {
  .crop-pair { grid-template-columns: 1fr; }
  .bank-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* Small screens: the review screen has to work on a 390px phone in the factory. */
@media (max-width: 430px) {
  /* Single column below the breakpoint: `auto-fit` with a 300px/210px floor keeps
     one column here anyway, but the floor itself is larger than the space once
     padding is taken off, and an explicit `1fr` removes the floor. */
  .positions { grid-template-columns: 1fr; }
  .group-header .header-facts { grid-template-columns: 1fr; }
  .page { width: calc(100% - 16px); padding: 20px 0 48px; }
  .topbar, .tabs { padding: 0 12px; }
  .queue-view-switch { margin: 0 0 16px; justify-content: flex-start; }
  .intro { flex-direction: column; gap: 12px; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters label, .filters select, .filters input, .filters button { width: 100%; }
  .crop-pair { grid-template-columns: 1fr; }
  .comparisons { grid-template-columns: 1fr; }
  .completion-bar { flex-direction: column; align-items: stretch; gap: 8px; }
  .completion-bar button { width: 100%; }
  /* Wide tables scroll rather than forcing the whole page sideways. */
  .groups, .assets, .positions-table, .metrics-table { display: block; overflow-x: auto; }
  .bank-grid { grid-template-columns: 1fr 1fr; }
  .asset-thumb { width: 72px; height: 54px; }
  .confusion { gap: 16px; }
  .metric-summary { grid-template-columns: 1fr; }
  .activity-header { align-items: stretch; flex-direction: column; }
  .activity-summary { grid-template-columns: 1fr 1fr; gap: 8px; }
}
