/* Phantom Recon Lab — guide §7 visual tokens exactly as specified
   (cool-neutral palette, accent #0C5779) */
:root {
  --bg:            #EBF1F7;  /* page */
  --surface:       #FFFFFF;  /* panels, cards */
  --surface-2:     #F6F9FC;  /* inputs, table stripes, log well */
  --border:        #D7E1EC;
  --border-strong: #C4D2E0;  /* input borders, secondary buttons */
  --text:          #132433;
  --text-muted:    #566A7E;
  --text-faint:    #90A2B4;  /* placeholders and disabled only */
  --accent:        #0C5779;  /* primary button, selected tab, running pill */
  --accent-hover:  #0A4763;
  --accent-soft:   #E3ECF0;
  --on-accent:     #FFFFFF;
  --focus:         #0C5779;  /* 2px ring, 2px offset */
  --success:       #1E9E4A;
  --warning:       #B87708;
  --danger:        #D8382F;
  --neutral:       #566A7E;  /* idle, cancelled */
  --radius:        6px;      /* buttons, panels */
  --radius-sm:     4px;      /* inputs, pills, metric cards */
  --shadow-pop:    0 4px 16px rgba(19,36,51,.10);  /* menus, dialogs, toasts only */
  --font-sans:     'Geist', system-ui, sans-serif;
  --font-mono:     'Geist Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font-sans); font-size: 14px; color: var(--text);
  background: var(--bg); -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
input, select, textarea { font-family: inherit; font-size: 13px; }
main, nav, section { display: block; }
a { color: var(--text); }
.mono, .num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.small { font-size: 12px; }

/* ---------- layout (§6) ---------- */
#app { display: flex; flex-direction: column; height: 100vh; min-width: 640px; }
.topbar {
  display: flex; align-items: center; gap: 16px; height: 46px; flex: 0 0 46px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 0 16px; z-index: 20;
}
.topbar .appname { font-weight: 600; font-size: 14px; }
.topbar nav { display: flex; gap: 4px; height: 100%; }
.topbar nav a {
  display: flex; align-items: center; padding: 0 10px; font-size: 13px;
  color: var(--text-muted); text-decoration: none; border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.topbar nav a:hover { color: var(--text); }
.topbar nav a.active { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.topbar .spacer { flex: 1; }
.topbar .right { display: flex; align-items: center; gap: 10px; }

#main { display: flex; flex: 1; min-height: 0; }
.panel-left {
  width: 320px; flex: 0 0 320px; background: var(--surface);
  border-right: 1px solid var(--border); overflow-y: auto;
  display: flex; flex-direction: column;
}
.panel-left .controls { padding: 12px 16px; flex: 1; overflow-y: auto; }
.panel-left .actions {
  border-top: 1px solid var(--border); padding: 12px 16px; display: flex; gap: 8px;
  flex-wrap: wrap;
}
.viewport {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  background: var(--bg);
}
.panel-right {
  width: 300px; flex: 0 0 300px; background: var(--surface);
  border-left: 1px solid var(--border); overflow-y: auto; padding: 12px;
}
.logconsole {
  flex: 0 0 160px; border-top: 1px solid var(--border); background: var(--surface-2);
  display: flex; flex-direction: column; min-height: 60px;
}
.logconsole .bar {
  display: flex; align-items: center; gap: 8px; padding: 4px 12px;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.logconsole .well {
  flex: 1; overflow-y: auto; padding: 6px 12px; font-family: var(--font-mono);
  font-size: 12px; line-height: 1.55; color: var(--text);
}
.logconsole.collapsed { flex: 0 0 30px; }
.logconsole.collapsed .well { display: none; }
.log-line .ts { color: var(--text-faint); }
.log-line .lvl-INFO { color: var(--text-muted); }
.log-line .lvl-WARN { color: var(--warning); font-weight: 500; }
.log-line .lvl-ERROR { color: var(--danger); font-weight: 500; }

/* responsive: results panel under viewport below 1100px */
@media (max-width: 1100px) {
  #main { flex-direction: column; overflow-y: auto; }
  .panel-left { width: 100%; flex: none; border-right: none; border-bottom: 1px solid var(--border);
    max-height: 40vh; }
  .panel-right { width: 100%; flex: none; border-left: none; border-top: 1px solid var(--border); }
  .viewport { min-height: 60vh; }
}
/* single column below 640px */
@media (max-width: 640px) {
  #app { min-width: 0; }
  body { font-size: 13px; }
}

/* ---------- components (§9) ---------- */
.btn {
  height: 32px; padding: 0 12px; border-radius: var(--radius); font-size: 13px;
  font-weight: 500; cursor: pointer; border: 1px solid transparent; background: none;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.btn:disabled { color: var(--text-faint); cursor: not-allowed; }
.btn.primary:disabled, .btn.danger:disabled { opacity: .45; }
.btn.primary:disabled { color: var(--on-accent); }
.btn.danger:disabled { color: var(--danger); }
.btn.secondary[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.secondary { background: var(--surface); border-color: var(--border-strong); }
.btn.secondary:hover:not(:disabled) { background: var(--accent-soft); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: #FEF2F2; }
.btn.small { height: 26px; padding: 0 8px; font-size: 12px; }
.btn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border-radius: 999px; font-size: 12px; font-weight: 500;
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.idle, .pill.cancelled { color: var(--neutral); background: rgba(113,113,122,.12); }
.pill.queued { color: var(--warning); background: rgba(161,98,7,.12); }
.pill.running { color: var(--text); background: var(--accent-soft); }
.pill.succeeded { color: var(--success); background: rgba(21,128,61,.12); }
.pill.failed { color: var(--danger); background: rgba(220,38,38,.12); }

.badge { display: inline-flex; align-items: center; gap: 4px; height: 20px; padding: 0 6px;
  border-radius: var(--radius-sm); font-size: 11px; font-weight: 500; }
.badge.warning { color: var(--warning); background: rgba(161,98,7,.12); }
.badge.danger { color: var(--danger); background: rgba(220,38,38,.12); }
.badge.info { color: var(--text-muted); background: var(--surface-2); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 8px; }
.metric-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; min-width: 0;
}
.metric-card .label { font-size: 12px; color: var(--text-muted); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; }
.metric-card .value { font-size: 20px; font-family: var(--font-mono);
  font-variant-numeric: tabular-nums; margin-top: 2px; white-space: nowrap; }
.metric-card .value.text { white-space: normal; overflow-wrap: anywhere; font-size: 14px;
  line-height: 1.35; margin-top: 4px; }
.metric-card .value.wrap { white-space: normal; overflow-wrap: anywhere; font-size: 12px; line-height: 1.5; }
.metric-card .value .unit { font-size: 12px; color: var(--text-muted); }
.metric-card .delta { font-size: 12px; margin-top: 2px; }
.metric-card .delta.up { color: var(--success); }
.metric-card .delta.down { color: var(--danger); }

/* forms */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 500; margin-bottom: 4px; }
.field .hint { font-size: 11px; color: var(--text-muted); margin-top: 3px; }
.field .err { font-size: 11px; color: var(--danger); margin-top: 3px; }
.field input[type="text"], .field input[type="number"], .field select, .field input[type="url"] {
  width: 100%; height: 30px; padding: 0 8px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text);
}
.field input:focus-visible, .field select:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 1px; }
.field input.invalid { border-color: var(--danger); }
.checkline { display: flex; align-items: center; gap: 8px; font-size: 13px; margin-bottom: 12px; }
.checkline input { width: 14px; height: 14px; }
.checkline .hint { color: var(--text-muted); font-size: 11px; }
.section { margin-bottom: 8px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.section > summary {
  cursor: pointer; font-size: 12px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .04em; padding: 8px 0;
  list-style: none; display: flex; align-items: center; gap: 6px;
}
.section > summary::before { content: "▸"; transition: transform .12s; }
.section[open] > summary::before { transform: rotate(90deg); }
.section > .section-body { padding-bottom: 8px; }

/* tables (§9) */
.tablewrap { overflow: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); max-height: 100%; }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th {
  position: sticky; top: 0; background: var(--surface); text-align: left;
  font-size: 12px; font-weight: 600; color: var(--text-muted); padding: 8px 10px;
  border-bottom: 1px solid var(--border); cursor: pointer; user-select: none; white-space: nowrap;
  z-index: 2;
}
table.data td { padding: 6px 10px; border-bottom: 1px solid var(--border);
  white-space: nowrap; }
table.data tr:nth-child(even) td { background: var(--surface-2); }
table.data td.num, table.data th.num { text-align: right; font-family: var(--font-mono);
  font-variant-numeric: tabular-nums; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover td { background: var(--accent-soft); }
table.data tbody tr.selected td { background: var(--accent-soft); }

/* tabs inside the main viewport (§6a) */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border);
  background: var(--surface); padding: 0 8px; flex: 0 0 auto; }
.tabs button {
  height: 34px; padding: 0 12px; background: none; border: none; cursor: pointer;
  font-size: 13px; color: var(--text-muted); border-bottom: 2px solid transparent;
}
.tabs button:hover { color: var(--text); }
.tabs button.active { color: var(--text); font-weight: 600;
  border-bottom-color: var(--accent); }
.tabbody { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* stepper */
.stepper { display: flex; gap: 6px; padding: 8px 12px; overflow-x: auto;
  background: var(--surface); border-bottom: 1px solid var(--border); flex: 0 0 auto; }
.step {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px;
  border-radius: 999px; border: 1px solid var(--border); font-size: 12px; cursor: pointer;
  background: var(--surface); color: var(--text-muted); white-space: nowrap;
  font-family: var(--font-mono);
  max-width: 200px; overflow: hidden; text-overflow: ellipsis; flex: 0 0 auto;
}
.stepper:empty { display: none; }
.step .n { color: var(--text-faint); font-size: 11px; }
.step .k { font-weight: 600; }
.step:hover { border-color: var(--border-strong); color: var(--text); }
.step.active { background: var(--accent); border-color: var(--accent);
  color: var(--on-accent); }
.step.active .n { color: rgba(255,255,255,.6); }
.step.running { border-color: var(--text); color: var(--text); }
.step.failed { border-color: var(--danger); color: var(--danger); }

.progressbar { height: 3px; background: var(--surface-2); flex: 0 0 3px; }
.progressbar .fill { height: 100%; background: var(--accent); width: 0%;
  transition: width .4s; }

/* 3D viewer */
.viewer3d { position: relative; flex: 1; min-height: 200px; background: var(--surface); }
.viewer3d canvas { display: block; }
.viewer3d .overlay-ui {
  position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; flex-wrap: wrap;
  max-width: 70%;
}
.viewer3d .corner {
  position: absolute; left: 8px; bottom: 8px; font-family: var(--font-mono);
  font-size: 11px; color: var(--text-muted); background: rgba(255,255,255,.85);
  padding: 4px 8px; border-radius: var(--radius-sm); pointer-events: none;
}
.viewer3d .spinner {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: rgba(250,250,250,.7); color: var(--text-muted); font-size: 13px;
  flex-direction: column; gap: 8px;
  pointer-events: none; z-index: 0;
}
.viewer3d.loading .spinner { display: flex; }
.viewer3d .empty {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--text-faint); font-size: 13px; padding: 24px; text-align: center;
  pointer-events: none; z-index: 0;   /* never block the overlay buttons */
}
.viewer3d .overlay-ui { z-index: 3; }
.viewer3d .corner, .viewer3d .legend { z-index: 3; }
.viewer3d .legend {
  position: absolute; left: 8px; top: 8px; background: rgba(255,255,255,.9);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px 8px;
  font-size: 11px; display: none;
}
.viewer3d .legend .swatch { display: inline-block; width: 10px; height: 10px;
  border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* interactive error colorbar (hover = highlight band, click = pin) */
.errbar { min-width: 210px; }
.errbar-title { font-weight: 600; margin-bottom: 4px; }
.errbar-bar { display: flex; height: 14px; border-radius: 3px; overflow: hidden;
  border: 1px solid var(--border-strong); }
.errseg { flex: 1; border: 0; padding: 0; cursor: pointer; }
.errseg:hover { outline: 2px solid var(--text); outline-offset: -1px; }
.errseg.pin { outline: 2px solid var(--text); outline-offset: -1px;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.55); }
.errbar-scale { display: flex; justify-content: space-between; font-size: 10px;
  color: var(--text-muted); margin-top: 2px; }
.errbar-status { font-size: 10px; color: var(--text-muted); margin-top: 3px;
  min-height: 13px; font-variant-numeric: tabular-nums; }

/* compare side-by-side */
.comparegrid { display: grid; gap: 2px; background: var(--border); flex: 1; min-height: 0; }
.comparepane { position: relative; display: flex; flex-direction: column;
  min-height: 0; background: var(--surface); }
.comparepane .viewer3d { min-height: 160px; }
.comparepane .vizlabel { position: absolute; top: 8px; left: 8px; z-index: 4;
  background: rgba(255,255,255,.92); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 2px 8px; font-size: 11px;
  font-family: var(--font-mono); max-width: 55%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* narrow panes: buttons below the label row, legend clear of the label */
.comparepane .viewer3d .overlay-ui { top: 36px; max-width: 100%; }
.comparepane .viewer3d .legend { top: 36px; }

/* plots */
.plot { width: 100%; min-height: 260px; background: var(--surface); }
#plot-histogram { height: 300px; }
#plot-drift { height: 340px; }
.plothead { display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px 0 12px; }
.plothead .title { font-size: 13px; font-weight: 600; }
.plothead .sub { font-size: 11px; color: var(--text-muted); }

/* misc */
.page { display: none; flex: 1; min-height: 0; min-width: 0; }
.page.active { display: flex; }
.toastwrap { position: fixed; bottom: 16px; right: 16px; display: flex;
  flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-pop); padding: 10px 14px; font-size: 13px; max-width: 360px;
  animation: slidein .15s ease-out;
}
.toast.error { border-color: var(--danger); color: var(--danger); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } }
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; color: var(--text-muted); padding: 48px 24px; text-align: center; font-size: 14px;
}
.empty-state .big { font-size: 16px; color: var(--text); font-weight: 600; }
.skeleton { background: var(--surface-2); border-radius: var(--radius-sm);
  animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; } }
.dialog-backdrop { position: fixed; inset: 0; background: rgba(9,9,11,.3);
  display: flex; align-items: center; justify-content: center; z-index: 50; }
.dialog { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-pop);
  min-width: 420px; max-width: 720px; max-height: 80vh; overflow: auto; padding: 16px; }
.dialog h3 { margin: 0 0 12px 0; font-size: 15px; }
.imgstrip { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px; }
.imgstrip img { height: 110px; border-radius: var(--radius-sm); border: 1px solid var(--border);
  cursor: pointer; }
details.errorbox[open] .imgstrip img.bigfig { height: auto; max-width: 100%; max-height: 420px; }
.gallery-main { display: flex; gap: 8px; padding: 8px 12px; align-items: flex-start; }
.gallery-main img { max-height: 320px; border-radius: var(--radius);
  border: 1px solid var(--border); }
.kv { font-size: 12px; color: var(--text-muted); }
.kv b { color: var(--text); font-weight: 500; }
.split { display: flex; gap: 0; flex: 1; min-height: 0; }
.split > * { min-width: 0; }
.comparebar {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px;
  border-bottom: 1px solid var(--border); background: var(--surface); flex-wrap: wrap;
}
.uploadzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
  padding: 14px; text-align: center; color: var(--text-muted); font-size: 12px;
  cursor: pointer; margin-bottom: 12px;
}
.uploadzone.drag { border-color: var(--text); color: var(--text); background: var(--accent-soft); }
.trialpicker-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--border);
  border-radius: var(--radius-sm); background: var(--surface); }
.trialpicker-list .opt { padding: 6px 10px; font-size: 12px; cursor: pointer;
  display: flex; justify-content: space-between; gap: 8px; }
.trialpicker-list .opt > span:first-child { min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.trialpicker-list .opt > span + span { flex: 0 0 auto; }
.trialpicker-list .opt:hover, .trialpicker-list .opt.sel { background: var(--accent-soft); }
.trialpicker-list .opt.disabled { color: var(--text-faint); cursor: not-allowed; }
.trialpicker-list .opt.disabled:hover { background: none; }
input[type="range"] { width: 100%; }
.checkbox-row { display: flex; align-items: center; gap: 6px; }
details.errorbox summary { cursor: pointer; font-size: 12px; color: var(--danger); }
details.gallery summary { color: var(--text-muted); font-weight: 600; }
details.errorbox pre { background: var(--surface-2); padding: 8px; border-radius: 4px;
  font-size: 11px; overflow: auto; max-height: 200px; }

/* Explore: summary cards + full-width distribution plot */
#explore-cards .plotrow { grid-column: 1 / -1; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius-sm); }
#explore-cards .plotrow .plothead { padding: 8px 12px 0; }
/* History: runs table fills the page until Compare opens */
#page-history .viewport > .tablewrap { flex: 1 1 auto; min-height: 0; max-height: none; }
#page-history .viewport.comparing > .tablewrap { flex: 0 0 auto; max-height: 38%; }

/* ---- Explore & Run (merged page) ---- */
.labhead { display: flex; gap: 10px; align-items: center; padding: 6px 12px;
  border-bottom: 1px solid var(--border); background: var(--surface); }
.labhead .labtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; flex: 0 0 auto; }
.seg button { border: 0; background: var(--surface); color: var(--text-muted); padding: 4px 10px;
  font: inherit; font-size: 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.active { background: var(--accent-soft); color: var(--text); font-weight: 600; }

/* ---- metric sort menu (funnel icon, shopping-style) ---- */
.listhead { display: flex; align-items: center; gap: 8px; }
.listhead > label { flex: 1; margin-bottom: 0; }
.filtermenu { position: relative; flex: 0 0 auto; }
.iconbtn { position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; padding: 0; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text-muted);
  cursor: pointer; }
.iconbtn:hover { background: var(--accent-soft); color: var(--text); }
.filtermenu .pop { position: absolute; top: calc(100% + 6px); right: 0; min-width: 180px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(19,36,51,.14); padding: 6px; z-index: 40; }
.filtermenu .pop[hidden] { display: none; }
.menuhead { font-size: 11px; font-weight: 600; color: var(--text-muted); padding: 4px 8px 6px; }
.menuopt { display: flex; align-items: baseline; gap: 8px; padding: 6px 8px;
  border-radius: var(--radius-sm); font-size: 13px; cursor: pointer; }
.menuopt:hover { background: var(--accent-soft); }
.menuopt .tick { width: 12px; flex: 0 0 12px; color: var(--accent); font-weight: 700; }
.menuopt .name { flex: 1; }
.menuopt .unit { font-size: 11px; }
.menuopt.sel { color: var(--accent); font-weight: 600; }
.labinfo { flex: 0 0 auto; border-top: 1px solid var(--border); background: var(--surface);
  padding: 6px 12px; overflow-y: auto; max-height: 30%; min-width: 0; }
#page-explore .labsplit { flex-direction: column; }
#page-explore .labsplit > div:first-child { flex: 1 1 0 !important; min-height: 0; }
#page-explore .labsplit .viewer3d { min-height: 0; overflow: hidden; }
.paneltitle { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.lab-list { max-height: none; height: 46vh; }
.lab-list .opt .sub { display: block; color: var(--text-faint); font-size: 11px; }
#lab-right .controls { padding: 0; }
#lab-right .section > summary { font-size: 12px; }
.evaltable { width: 100%; font-size: 12px; margin-top: 8px; }

/* image-only stages: renders in place of the 3D viewer */
.stage-imgpanel { flex: 1; min-height: 200px; overflow: auto; padding: 12px; background: var(--surface); }
.stage-imgpanel figure { margin: 0; }
.stage-imgpanel img { cursor: zoom-in; display: block; border: 1px solid var(--border); background: #fff; }
.stage-imgpanel .imgrow { display: flex; gap: 12px; height: 100%; align-items: flex-start; }
.stage-imgpanel .imgrow figure { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.stage-imgpanel .imgrow img { width: 100%; height: auto; max-height: calc(100vh - 320px); object-fit: contain; }
.stage-imgpanel .imggrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.stage-imgpanel .imggrid img { width: 100%; height: 120px; object-fit: cover; }

/* stage info: a column in side panels, a compact wrapping strip under the lab viewer */
.stageinfo { display: flex; flex-direction: column; gap: 8px; }
.stageinfo .stagehead { font-weight: 600; font-size: 14px; color: var(--text); }
.labinfo .stageinfo { flex-direction: row; flex-wrap: wrap; align-items: baseline; gap: 2px 16px; }
.labinfo .stageinfo .stagehead { font-size: 13px; }
.stage-metric-cards { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
.labinfo .stageinfo > pre, .labinfo .stageinfo > table { flex-basis: 100%; margin: 4px 0; }

/* mesh stage with renders: small PNG viewer inset bottom-right of the 3D viewer */
.stage-inset { position: absolute; right: 8px; bottom: 8px; z-index: 4; width: min(30%, 280px);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: 0 2px 8px rgba(0,0,0,.12); display: flex; flex-direction: column; overflow: hidden; }
.stage-inset img { display: block; width: 100%; max-height: 220px; object-fit: contain;
  background: #fff; cursor: zoom-in; }
.stage-inset .bar { display: flex; align-items: center; gap: 2px; padding: 2px 4px;
  border-top: 1px solid var(--border); font-size: 11px; }
.stage-inset .cap { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; color: var(--text-muted); }
.stage-inset .ib { border: 0; background: none; cursor: pointer; color: var(--text-muted);
  font: inherit; font-size: 13px; padding: 0 5px; line-height: 20px; }
.stage-inset .ib:hover { color: var(--text); }
.stage-inset .pill { display: none; border: 0; background: none; cursor: pointer; font: inherit;
  font-size: 12px; padding: 4px 10px; color: var(--text); }
.stage-inset.min { width: auto; }
.stage-inset.min img, .stage-inset.min .bar { display: none; }
.stage-inset.min .pill { display: block; }
.stage-inset.big { left: 8px; top: 44px; width: auto; }
.stage-inset.big img { flex: 1; max-height: none; min-height: 0; cursor: zoom-out; }

/* busts: step toggles overlaid on the 3D viewer (bottom-center: the legend owns
   top-left and the view controls top-right) */
.viewer3d .overlay-toggles {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: row; gap: 6px; align-items: center;
  background: rgba(255,255,255,.92); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 6px 8px; z-index: 4;
}
.viewer3d .overlay-toggles .btn { white-space: nowrap; }
.viewer3d .overlay-toggles .btn.toggle.is-on.primary { background: var(--accent); color: var(--on-accent); }
.viewer3d .overlay-toggles .btn.toggle { min-width: unset; }

/* capture video above the sampled frames on the raw stage */
.stage-imgpanel .stage-video { margin: 0 0 12px; display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.stage-imgpanel .stage-video video { max-width: 100%; max-height: 55vh; background: #000; border-radius: var(--radius-sm); }

/* ---- sort-direction arrow beside the funnel icon ---- */
.sortgroup { display: inline-flex; gap: 4px; flex: 0 0 auto; align-items: center; }
#btn-sortdir[data-dir="asc"] .dir-down { display: none; }
#btn-sortdir[data-dir="desc"] .dir-up { display: none; }
#btn-sortdir[hidden] { display: none; }

/* ---- cached cleaning animation ---- */
.animation-controls { display: inline-flex; gap: 4px; align-items: center; }
.animation-controls select { height: 30px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); font-size: 12px; }
.animation-stage { flex: 1; min-height: 220px; position: relative; display: flex;
  align-items: center; justify-content: center; overflow: hidden;
  background: var(--surface); outline: none; }
.animation-stage img { width: 100%; height: 100%; object-fit: contain; }
.animation-stage .empty-state { margin: 20px; color: var(--text-muted); }
.animation-scrub { display: flex; align-items: center; gap: 12px; padding: 8px 12px;
  border-top: 1px solid var(--border); background: var(--surface); }
.animation-scrub input { flex: 1; min-width: 0; accent-color: var(--accent); }
.animation-scrub span { flex: 0 0 auto; font-variant-numeric: tabular-nums; }
