/* Pre-inspection API console. Tokens first; light by default, dark when the system asks or the
   toggle says so. Severity and status colours mean the same thing everywhere. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #17202b;
  --muted: #5d6877;
  --border: #dde2e8;
  --accent: #0f6e78;
  --accent-ink: #ffffff;
  --accent-soft: #e2f1f2;
  --ok: #1d7a43;
  --ok-bg: #e4f4ea;
  --warn: #8a5a00;
  --warn-bg: #fdf0d5;
  --bad: #b3261e;
  --bad-bg: #fbe6e4;
  --info: #3b5b8c;
  --info-bg: #e7edf7;
  --neutral-bg: #eceff3;
  --code-bg: #0f1720;
  --code-ink: #dde6ef;
  --code-key: #8fd3dd;
  --code-str: #b9e08f;
  --code-num: #f2c27b;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1319; --surface: #151c24; --surface-2: #1b2430; --text: #e6ebf1; --muted: #98a4b3;
    --border: #2a3542; --accent: #4fb3bd; --accent-ink: #06181a; --accent-soft: #13323a;
    --ok: #6fd39a; --ok-bg: #143022; --warn: #f0c060; --warn-bg: #352a10; --bad: #ff8a80; --bad-bg: #3a1716;
    --info: #9cb8e6; --info-bg: #1a2638; --neutral-bg: #222c38; --code-bg: #0a0f14;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1319; --surface: #151c24; --surface-2: #1b2430; --text: #e6ebf1; --muted: #98a4b3;
  --border: #2a3542; --accent: #4fb3bd; --accent-ink: #06181a; --accent-soft: #13323a;
  --ok: #6fd39a; --ok-bg: #143022; --warn: #f0c060; --warn-bg: #352a10; --bad: #ff8a80; --bad-bg: #3a1716;
  --info: #9cb8e6; --info-bg: #1a2638; --neutral-bg: #222c38; --code-bg: #0a0f14;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); }
h1, h2, h3, h4 { line-height: 1.25; text-wrap: balance; margin: 0; }
h2 { font-size: 1rem; margin: 18px 0 8px; }
h3 { font-size: 0.95rem; margin: 0 0 8px; }
p { margin: 0 0 10px; }
a { color: var(--accent); }
code, kbd, pre, .mono { font-family: var(--mono); font-size: 0.88em; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

/* Header */
.top {
  position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center;
  justify-content: space-between; background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 12px max(16px, env(safe-area-inset-right, 0px)) 12px max(16px, env(safe-area-inset-left, 0px));
}
.brand { display: flex; gap: 12px; align-items: center; min-width: 0; }
.logo { width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-weight: 700; letter-spacing: 0.04em; flex: none; }
.brand h1 { font-size: 1.05rem; }
.ver { font-size: 0.75rem; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 1px 7px; border-radius: 99px; vertical-align: 2px; }
.sub { margin: 0; font-size: 0.82rem; color: var(--muted); }
.status { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.keyform { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.keyform input[type="password"], .keyform input[type="text"] { width: 230px; max-width: 60vw; font-family: var(--mono); font-size: 0.85rem; }
.remember { font-size: 0.8rem; color: var(--muted); display: flex; gap: 4px; align-items: center; }

/* Tabs */
.tabs { display: flex; gap: 2px; overflow-x: auto; background: var(--surface); border-bottom: 1px solid var(--border); padding: 0 max(16px, env(safe-area-inset-right, 0px)) 0 max(16px, env(safe-area-inset-left, 0px)); }
.tabs button { background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); padding: 11px 14px; font-weight: 600; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
main { max-width: 1320px; margin: 0 auto; padding: 18px max(16px, env(safe-area-inset-right, 0px)) 48px max(16px, env(safe-area-inset-left, 0px)); }
.intro { max-width: 70ch; color: var(--muted); margin-bottom: 14px; }

/* Controls */
input, select, textarea, button { font: inherit; color: inherit; }
input[type="text"], input[type="password"], input:not([type]), select, textarea {
  background: var(--surface); border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px; min-width: 0;
}
textarea { width: 100%; font-family: var(--mono); font-size: 0.85rem; min-height: 110px; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button { cursor: pointer; border: 1px solid var(--border); background: var(--surface); border-radius: 7px; padding: 7px 12px; font-weight: 600; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); }
button.big { width: 100%; padding: 11px; font-size: 1rem; }
button.ghost { background: none; border-color: transparent; color: var(--muted); padding: 6px 8px; }
button:disabled { opacity: 0.55; cursor: progress; }
.field { display: grid; gap: 4px; margin-bottom: 10px; }
.field label { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.field input, .field select { width: 100%; }
.check { display: flex; gap: 8px; align-items: center; font-size: 0.9rem; margin: 6px 0 12px; }
.hint { font-size: 0.82rem; color: var(--muted); margin-bottom: 8px; }
.filebtn { display: inline-flex; gap: 6px; align-items: center; border: 1px dashed var(--border); border-radius: 7px; padding: 7px 12px; cursor: pointer; font-weight: 600; font-size: 0.9rem; margin-top: 8px; }
.filebtn input { display: none; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.row input.wide { flex: 1 1 100%; min-width: 0; }
.pair { display: inline-flex; gap: 8px; }

/* Cards and layout */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.try { display: grid; grid-template-columns: minmax(300px, 410px) minmax(0, 1fr); gap: 16px; align-items: start; }
.inputs h2:first-child { margin-top: 0; }
.output { display: grid; gap: 16px; min-width: 0; }
@media (max-width: 920px) { .try { grid-template-columns: minmax(0, 1fr); } }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.stack { display: grid; gap: 16px; }
/* Grid children may shrink below their content; wide tables and code scroll inside their own box. */
.try > *, .output > *, .stack > *, .grid2 > *, .findings > *, .samples > * { min-width: 0; }
.mono, .ev, .path, .by { overflow-wrap: anywhere; }

/* Samples */
.samples { display: grid; gap: 8px; margin-bottom: 14px; }
.sample { text-align: left; display: grid; gap: 2px; padding: 9px 11px; font-weight: 400; }
.sample strong { font-size: 0.92rem; }
.sample .muted { font-size: 0.8rem; }
.sample[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); }

/* Thumbnails */
.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.thumb { position: relative; border-radius: 8px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); }
.thumb img, .thumb .ph { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; cursor: zoom-in; }
.thumb .ph { display: grid; place-items: center; font-size: 0.72rem; color: var(--muted); cursor: default; }
.thumb .cap { font: 600 0.7rem/1.3 var(--mono); padding: 3px 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thumb .x { position: absolute; top: 3px; right: 3px; padding: 0 6px; font-size: 0.8rem; line-height: 1.4; background: rgba(0, 0, 0, 0.55); color: #fff; border: 0; border-radius: 99px; }
.mini { width: 54px; height: 40px; object-fit: cover; border-radius: 5px; border: 1px solid var(--border); cursor: zoom-in; vertical-align: middle; }
.minis { display: flex; flex-wrap: wrap; gap: 4px; }

/* Conditions */
.conditions { display: grid; gap: 6px; }
.cond { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; font-size: 0.85rem; }
.cond .when { color: var(--muted); font-size: 0.78rem; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 4px 8px; font-size: 0.75rem; font-weight: 600; background: var(--surface); color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* Pills and chips */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--neutral-bg); color: var(--muted); white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.chip { display: inline-block; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em; padding: 1px 7px; border-radius: 5px; background: var(--neutral-bg); color: var(--muted); white-space: nowrap; }
.sev-block, .st-missing, .d-not_ready { background: var(--bad-bg); color: var(--bad); }
.sev-retake, .st-present_unverified, .d-needs_review { background: var(--warn-bg); color: var(--warn); }
.sev-info, .st-unchecked { background: var(--info-bg); color: var(--info); }
.st-present, .d-ready { background: var(--ok-bg); color: var(--ok); }
.st-not_needed, .d-not_checked { background: var(--neutral-bg); color: var(--muted); }
.by { font: 600 0.7rem var(--mono); color: var(--muted); }

/* Result */
.empty { text-align: center; padding: 34px 20px; color: var(--muted); }
.decision { display: grid; gap: 6px; border-left: 5px solid var(--border); }
.decision.d-ready { border-left-color: var(--ok); }
.decision.d-not_ready { border-left-color: var(--bad); }
.decision.d-needs_review { border-left-color: var(--warn); }
.decision.d-not_checked { border-left-color: var(--muted); }
.decision, .decision.d-ready, .decision.d-not_ready, .decision.d-needs_review, .decision.d-not_checked { background: var(--surface); color: var(--text); }
.decision .label { font-size: 1.45rem; font-weight: 750; }
.decision .what { color: var(--muted); font-size: 0.9rem; }
.decision ul { margin: 4px 0 0; padding-left: 20px; }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; }
.metric { background: var(--surface-2); border-radius: 8px; padding: 9px 11px; min-width: 0; }
.metric .v { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric .k { font-size: 0.74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.metric .n { font-size: 0.72rem; color: var(--muted); }
.stages { display: flex; height: 12px; border-radius: 99px; overflow: hidden; background: var(--surface-2); margin: 12px 0 4px; }
.stages span { display: block; height: 100%; }
.s-photos { background: var(--info); }
.s-model { background: var(--accent); }
.s-other { background: var(--border); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 0.78rem; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }
.subtabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.subtabs button { padding: 5px 10px; font-size: 0.85rem; }
.subtabs button[aria-selected="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

/* Tables */
.tablewrap { overflow-x: auto; }
.tablewrap > table { min-width: 520px; }
table { border-collapse: collapse; width: 100%; font-size: 0.86rem; }
th { text-align: left; font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 700; border-bottom: 1px solid var(--border); padding: 7px 8px; white-space: nowrap; }
td { border-bottom: 1px solid var(--border); padding: 8px; vertical-align: top; }
#fr td:first-child, #nfr td:first-child { white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }

/* Findings */
.findings { display: grid; gap: 8px; }
.finding { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
.finding .t { font-weight: 650; }
.finding .r { font-size: 0.88rem; }
.finding .ev { font: 0.75rem/1.4 var(--mono); color: var(--muted); }
.finding .fb { display: flex; gap: 4px; }
.finding .fb button { padding: 3px 8px; font-size: 0.75rem; }
.finding .fb button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
@media (max-width: 640px) {
  .finding { grid-template-columns: auto minmax(0, 1fr); }
  .finding .fb { grid-column: 1 / -1; justify-content: flex-end; }
}
.group-title { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 6px 0 2px; }

/* Photo cards */
.photocards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.pcard { border: 1px solid var(--border); border-radius: 9px; overflow: hidden; background: var(--surface); }
.pcard img, .pcard .ph { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; cursor: zoom-in; background: var(--surface-2); }
.pcard .ph { display: grid; place-items: center; color: var(--muted); font-size: 0.8rem; cursor: default; }
.pcard .body { padding: 8px 10px; display: grid; gap: 5px; font-size: 0.82rem; }
.pcard .id { font: 700 0.78rem var(--mono); }
.tags { display: flex; flex-wrap: wrap; gap: 4px; }

/* Code */
pre.code { background: var(--code-bg); color: var(--code-ink); border-radius: 8px; padding: 12px 14px; overflow: auto; max-height: 520px; margin: 0; white-space: pre; font-size: 0.8rem; line-height: 1.45; }
pre.code .k { color: var(--code-key); }
pre.code .s { color: var(--code-str); }
pre.code .n { color: var(--code-num); }
.copy { float: right; margin: -4px 0 6px 8px; padding: 3px 9px; font-size: 0.75rem; }

/* Endpoints */
.ep { display: grid; gap: 10px; align-content: start; }
.ep-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.method { font: 700 0.75rem var(--mono); padding: 2px 7px; border-radius: 5px; background: var(--info-bg); color: var(--info); }
.method.post { background: var(--ok-bg); color: var(--ok); }
.path { font: 600 0.92rem var(--mono); word-break: break-all; }
.resp-head { display: flex; gap: 8px; align-items: center; font-size: 0.82rem; color: var(--muted); }
.code-chip { font: 700 0.78rem var(--mono); padding: 1px 7px; border-radius: 5px; }
.code-2 { background: var(--ok-bg); color: var(--ok); }
.code-4, .code-5 { background: var(--bad-bg); color: var(--bad); }
.errors { display: grid; gap: 8px; }
.err { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: center; border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; }
.err .out { grid-column: 1 / -1; font: 0.78rem/1.4 var(--mono); color: var(--muted); word-break: break-word; }

/* Docs */
.doc { max-width: 980px; }
.doc p, .doc li { max-width: 75ch; }
.doc ul { padding-left: 20px; }
.pipeline { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; margin: 6px 0 14px; }
.stage { flex: 1 1 140px; background: var(--surface-2); border-radius: 9px; padding: 10px 12px; border-top: 3px solid var(--accent); min-width: 0; }
.stage b { display: block; font-size: 0.92rem; }
.stage span { font-size: 0.8rem; color: var(--muted); }
.callout { border-left: 4px solid var(--accent); background: var(--accent-soft); padding: 10px 14px; border-radius: 0 8px 8px 0; margin: 10px 0 14px; }

/* Overlays */
dialog#lightbox { border: 0; padding: 0; border-radius: 12px; max-width: min(1100px, 94vw); background: var(--surface); color: var(--text); }
dialog#lightbox::backdrop { background: rgba(5, 10, 15, 0.72); }
dialog#lightbox img { display: block; max-width: 100%; max-height: 78vh; margin: 0 auto; }
dialog#lightbox .lb-foot { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 10px 14px; font-size: 0.85rem; }
#toast { position: fixed; bottom: max(18px, env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 9px 16px; border-radius: 99px; font-size: 0.88rem; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity 0.2s; z-index: 50; max-width: calc(100vw - 32px); }
#toast.on { opacity: 1; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } #toast { transition: none; } }
