/* Meter Vision tester page. Every value comes from the tokens below: one light and one dark set, the rest of the file only
   refers to them. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #15191f;
  --muted: #5a6472;
  --border: #d5dbe3;
  --primary: #1f5fd1;
  --primary-text: #ffffff;
  --focus: #1f5fd1;
  --ok-bg: #e3f4ea;
  --ok-fg: #13633a;
  --warn-bg: #fdf1dc;
  --warn-fg: #7a4a00;
  --bad-bg: #fde6e6;
  --bad-fg: #9b1c1c;
  --info-bg: #e5eefc;
  --info-fg: #1a4aa3;
  --display: #16a34a;
  --serial: #7c3aed;
  --barcode: #d97706;
  --option: #64748b;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.1);

  --s-0: 2px;
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-7: 28px;
  --s-8: 32px;
  --line: 1px;
  --line-2: 2px;
  --line-3: 3px;
  --line-4: 4px;
  --r-1: 2px;
  --r-2: 6px;
  --r-3: 8px;
  --r-4: 10px;
  --r-5: 12px;
  --r-pill: 999px;
  --fs-xs: 0.8125rem;
  --fs-s: 0.875rem;
  --fs-m: 0.9375rem;
  --fs-base: 1rem;
  --fs-l: 1.0625rem;
  --fs-xl: 1.125rem;
  --fs-2xl: 1.5rem;
  --fs-3xl: 1.75rem;
  --fw-m: 500;
  --fw-sb: 600;
  --fw-b: 650;
  --fw-xb: 700;
  --lh: 1.5;
  --lh-tight: 1.25;
  --tap: 48px;
  --tap-s: 40px;
  --tap-l: 52px;
  --mark: 22px;
  --check: 20px;
  --spinner: 40px;
  --sw-w: 14px;
  --sw-h: 10px;
  --frac-w: 96px;
  --side-min: 320px;
  --page: 1100px;
  --textarea-h: 64px;
  --track: 0.02em;
  --halo: rgba(0, 0, 0, 0.55);
  --dash: 8 6;
  --dash-s: 4 4;
  --spin: 0.9s;
  --hover: brightness(1.06);
  --disabled: 0.55;
  --z-top: 2;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f252d;
    --text: #e8ecf1;
    --muted: #a3adba;
    --border: #2d3540;
    --primary: #5b8ef0;
    --primary-text: #0b1220;
    --focus: #8fb3ff;
    --ok-bg: #12301f;
    --ok-fg: #7fe0a6;
    --warn-bg: #3a2a0c;
    --warn-fg: #f3c574;
    --bad-bg: #3b1515;
    --bad-fg: #ff9c9c;
    --info-bg: #15243f;
    --info-fg: #9dbcff;
    --display: #4ade80;
    --serial: #c4a1ff;
    --barcode: #fbbf24;
    --option: #94a3b8;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); line-height: var(--lh); font-size: var(--fs-base);
  font-family: var(--font);
  padding-bottom: env(safe-area-inset-bottom);
}
h1 { font-size: var(--fs-2xl); line-height: var(--lh-tight); margin: 0 0 var(--s-2); }
h2 { font-size: var(--fs-xl); margin: 0 0 var(--s-3); }
p { margin: 0 0 var(--s-3); }
.muted { color: var(--muted); }
.small { font-size: var(--fs-s); }
.lead { font-size: var(--fs-l); }
.visually-hidden { position: absolute; width: var(--line); height: var(--line); overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
/* the file inputs stay in the tab order (the label is not focusable); the focus ring is drawn on the label beside them */
.file-input { position: absolute; width: var(--line); height: var(--line); opacity: 0; }
.file-input:focus-visible + .btn { outline: var(--line-3) solid var(--focus); outline-offset: var(--s-0); }
:focus-visible { outline: var(--line-3) solid var(--focus); outline-offset: var(--s-0); }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  padding: var(--s-3) var(--s-4); background: var(--surface); border-bottom: var(--line) solid var(--border);
  position: sticky; top: 0; z-index: var(--z-top);
}
.brand { display: flex; align-items: center; gap: var(--s-2); font-weight: var(--fw-b); min-width: 0; }
.mark { width: var(--mark); height: var(--mark); border-radius: var(--r-2); background: var(--primary); flex: none; }
.tag { font-weight: var(--fw-m); font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; }
.who { font-size: var(--fs-xs); color: var(--muted); text-align: right; }

main { max-width: var(--page); margin: 0 auto; padding: var(--s-5) var(--s-4) var(--s-8); outline: none; }
section + section { margin-top: var(--s-7); }
.card { background: var(--surface); border: var(--line) solid var(--border); border-radius: var(--r-5); padding: var(--s-4); box-shadow: var(--shadow); }
.center { text-align: center; }

.tips { margin: 0 0 var(--s-4); padding-left: var(--s-5); color: var(--muted); }
.tips li { margin-bottom: var(--s-1); }
.actions { display: flex; flex-wrap: wrap; gap: var(--s-3); margin: var(--s-4) 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: var(--tap); padding: 0 var(--s-5);
  border-radius: var(--r-4); border: var(--line) solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: var(--fw-sb); cursor: pointer; text-decoration: none; user-select: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.primary:hover { filter: var(--hover); }
.btn[disabled] { opacity: var(--disabled); cursor: progress; }
.btn.wide { width: 100%; }
.actions .btn { flex: 1 1 auto; }

.error { color: var(--bad-fg); background: var(--bad-bg); border-radius: var(--r-3); padding: var(--s-3) var(--s-3); }

.spinner {
  width: var(--spinner); height: var(--spinner); margin: var(--s-2) auto var(--s-4); border-radius: 50%;
  border: var(--line-4) solid var(--surface-2); border-top-color: var(--primary); animation: spin var(--spin) linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

.result-grid { display: grid; gap: var(--s-5); grid-template-columns: minmax(0, 1fr); }
/* ds-allow-hardcode: a media query cannot read a custom property; 900px is the one layout breakpoint of this page */
@media (min-width: 900px) { .result-grid { grid-template-columns: minmax(0, 5fr) minmax(var(--side-min), 4fr); align-items: start; } }
.photo-wrap { margin: 0; }
.photo { position: relative; background: var(--surface-2); border-radius: var(--r-5); overflow: hidden; border: var(--line) solid var(--border); }
.photo img { display: block; width: 100%; height: auto; }
.photo svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.photo .r-display { fill: none; stroke: var(--display); }
.photo .r-serial { fill: none; stroke: var(--serial); }
.photo .r-barcode { fill: none; stroke: var(--barcode); stroke-dasharray: var(--dash); }
.photo .r-option { fill: none; stroke: var(--option); stroke-dasharray: var(--dash-s); }
.photo .r-halo { fill: none; stroke: var(--halo); }
.legend { display: flex; flex-wrap: wrap; gap: var(--s-1) var(--s-4); margin-top: var(--s-2); font-size: var(--fs-s); color: var(--muted); }
.sw { display: inline-block; width: var(--sw-w); height: var(--sw-h); border-radius: var(--r-1); margin-right: var(--s-1); vertical-align: middle; border: var(--line-2) solid; }
.sw-display { border-color: var(--display); }
.sw-serial { border-color: var(--serial); }
.sw-barcode { border-color: var(--barcode); border-style: dashed; }

.side { display: grid; gap: var(--s-3); }
.status { font-weight: var(--fw-sb); }
.value-card { background: var(--surface); border: var(--line) solid var(--border); border-radius: var(--r-5); padding: var(--s-3) var(--s-4); box-shadow: var(--shadow); }
#reading-card { border-left: var(--line-4) solid var(--display); }
#serial-card { border-left: var(--line-4) solid var(--serial); }
.vc-head { display: flex; justify-content: space-between; align-items: center; gap: var(--s-2); }
.vc-title { font-size: var(--fs-s); color: var(--muted); font-weight: var(--fw-sb); }
.vc-value { font-size: var(--fs-3xl); font-weight: var(--fw-xb); letter-spacing: var(--track); font-variant-numeric: tabular-nums; word-break: break-all; }
.vc-value.empty { font-size: var(--fs-base); font-weight: var(--fw-m); color: var(--muted); }
.vc-parts, .vc-note { font-size: var(--fs-s); color: var(--muted); }
#retake { margin-top: var(--s-2); align-self: flex-start; }
[hidden] { display: none !important; }
#main:focus { outline: none; } /* focus is moved here by script on every step change; it is not a control */
.badge { font-size: var(--fs-xs); font-weight: var(--fw-sb); padding: var(--s-0) var(--s-3); border-radius: var(--r-pill); white-space: nowrap; }
.t-ok { background: var(--ok-bg); color: var(--ok-fg); }
.t-warn { background: var(--warn-bg); color: var(--warn-fg); }
.t-bad { background: var(--bad-bg); color: var(--bad-fg); }
.t-info { background: var(--info-bg); color: var(--info-fg); }
.chips { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-2); }
.chip { min-height: var(--tap-s); padding: 0 var(--s-3); border-radius: var(--r-pill); border: var(--line) solid var(--border); background: var(--surface-2); color: var(--text); font: inherit; font-weight: var(--fw-sb); cursor: pointer; }
.chip[aria-pressed="true"] { border-color: var(--serial); outline: var(--line-2) solid var(--serial); }
.reasons { margin: 0; padding-left: var(--s-5); color: var(--muted); font-size: var(--fs-m); }
.reasons:empty { display: none; }

.form { display: grid; gap: var(--s-3); }
.row { display: flex; gap: var(--s-3); }
.field { display: grid; gap: var(--s-1); font-size: var(--fs-s); font-weight: var(--fw-sb); color: var(--muted); }
.field.grow { flex: 1 1 auto; }
.field.narrow { flex: 0 0 var(--frac-w); }
.field input, .field textarea {
  font: inherit; font-size: var(--fs-l); font-weight: var(--fw-m); color: var(--text); background: var(--surface);
  border: var(--line) solid var(--border); border-radius: var(--r-3); padding: var(--s-3) var(--s-3); min-height: var(--tap); width: 100%;
}
.field textarea { min-height: var(--textarea-h); resize: vertical; }
.field input:disabled { background: var(--surface-2); color: var(--muted); }
.check { display: flex; align-items: center; gap: var(--s-3); font-size: var(--fs-m); min-height: var(--tap-s); }
.check input { width: var(--check); height: var(--check); }
.saved h2 { color: var(--ok-fg); }

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s-2); }
.history button {
  width: 100%; display: flex; justify-content: space-between; align-items: center; gap: var(--s-3); text-align: left;
  background: var(--surface); color: var(--text); border: var(--line) solid var(--border); border-radius: var(--r-4); padding: var(--s-3) var(--s-4);
  font: inherit; cursor: pointer; min-height: var(--tap-l);
}
.history button:hover { background: var(--surface-2); }
.h-main { font-weight: var(--fw-sb); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.h-sub { font-size: var(--fs-xs); color: var(--muted); }
.foot { max-width: var(--page); margin: 0 auto; padding: 0 var(--s-4) var(--s-6); }

/* --- AI check, consent, admin --- */
.top-right { display: flex; align-items: center; gap: var(--s-4); min-width: 0; }
.admin-link { font-size: var(--fs-s); font-weight: var(--fw-sb); color: var(--primary); min-height: var(--tap-s); display: inline-flex; align-items: center; }
.ai-card { border-left: var(--line-4) solid var(--option); }
.ai-grid { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--s-1) var(--s-3); margin: var(--s-2) 0 0; font-size: var(--fs-m); }
.ai-grid dt { color: var(--muted); }
.ai-grid dd { margin: 0; font-weight: var(--fw-m); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.ai-grid:empty { display: none; }
.ai-reasons { margin-top: var(--s-2); }
.check.consent { align-items: flex-start; margin: var(--s-2) 0 var(--s-3); }
.check.consent input { margin-top: var(--s-0); flex: none; }
.btn.danger { color: var(--bad-fg); border-color: var(--bad-fg); }
.btn.danger:hover { background: var(--bad-bg); }
.ok-note { color: var(--ok-fg); background: var(--ok-bg); border-radius: var(--r-3); padding: var(--s-3); }
.tabs { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-bottom: var(--s-5); border-bottom: var(--line) solid var(--border); }
.tab { min-height: var(--tap); padding: 0 var(--s-4); background: none; border: 0; border-bottom: var(--line-3) solid transparent; color: var(--muted); font: inherit; font-weight: var(--fw-sb); cursor: pointer; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--primary); }
.tab:hover { color: var(--text); }
.pane-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: var(--s-3); }
.history button[aria-current="true"] { border-color: var(--primary); outline: var(--line-2) solid var(--primary); }
.history .log { display: grid; gap: var(--s-0); padding: var(--s-2) var(--s-3); border: var(--line) solid var(--border); border-radius: var(--r-4); background: var(--surface); }
.sub { margin-top: var(--s-6); }
.table-wrap { overflow-x: auto; border: var(--line) solid var(--border); border-radius: var(--r-4); background: var(--surface); }
table.data { border-collapse: collapse; width: 100%; font-size: var(--fs-s); font-variant-numeric: tabular-nums; }
table.data th, table.data td { padding: var(--s-2) var(--s-3); text-align: left; border-bottom: var(--line) solid var(--border); white-space: nowrap; }
table.data thead th { color: var(--muted); font-weight: var(--fw-sb); background: var(--surface-2); }
table.data tbody th { font-weight: var(--fw-sb); }
