:root {
  --bg: #0a0d13;
  --bg-panel: #111620;
  --bg-panel-2: #161c28;
  --bg-elev: #1b2333;
  --border: #232c3d;
  --border-soft: #1a2130;
  --text: #e6ebf2;
  --text-dim: #93a0b4;
  --text-mute: #5f6b7e;
  --accent: #3dd6c4;
  --accent-dim: #1c7d73;
  --pass: #3fb950;
  --fail: #f85149;
  --review: #e3a008;
  --info: #58a6ff;
  --vision: #bc8cff;
  --text-model: #58a6ff;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: "SF Mono", "JetBrains Mono", "Fira Code", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.muted { color: var(--text-dim); }
.sep { color: var(--text-mute); margin: 0 8px; }

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 18px;
  height: 54px;
  background: linear-gradient(180deg, #121824, #0e131c);
  border-bottom: 1px solid var(--border);
  flex: none;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 22px; height: 22px; border-radius: 6px;
  background: conic-gradient(from 210deg, var(--accent), #6b8cff 55%, var(--vision));
  box-shadow: 0 0 16px -2px var(--accent-dim);
}
.brand-text strong { letter-spacing: 0.14em; font-weight: 700; }
.brand-text { font-size: 14px; }

.viewtabs { display: flex; gap: 4px; margin-left: 8px; }
.viewtabs button {
  background: transparent; border: 1px solid transparent; color: var(--text-dim);
  padding: 6px 14px; border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 500;
  transition: all 0.12s;
}
.viewtabs button:hover { color: var(--text); background: var(--bg-panel); }
.viewtabs button.active { color: var(--bg); background: var(--accent); border-color: var(--accent); }

.runstat { margin-left: auto; display: flex; align-items: center; gap: 18px; }
.counts { display: flex; gap: 8px; font-size: 12px; }
.counts .chip { padding: 3px 9px; border-radius: 20px; background: var(--bg-panel); border: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.counts .chip b { font-weight: 700; }
.counts .chip.pass b { color: var(--pass); }
.counts .chip.fail b { color: var(--fail); }
.counts .chip.review b { color: var(--review); }

.status { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-dim); }
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-mute); }
.status.running .dot { background: var(--accent); box-shadow: 0 0 0 0 var(--accent); animation: pulse 1.6s infinite; }
.status.done .dot { background: var(--pass); }
.status.error .dot { background: var(--fail); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(61, 214, 196, 0.5); }
  70% { box-shadow: 0 0 0 7px rgba(61, 214, 196, 0); }
  100% { box-shadow: 0 0 0 0 rgba(61, 214, 196, 0); }
}

.progressbar { height: 2px; background: var(--border-soft); flex: none; }
.progressbar-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-dim), var(--accent)); transition: width 0.4s; }

main { flex: 1; min-height: 0; position: relative; }
.view { position: absolute; inset: 0; display: none; flex-direction: column; }
.view.active { display: flex; }

/* ── Live view ── */
.ribbon {
  padding: 9px 18px; font-size: 12.5px; color: var(--text-dim);
  border-bottom: 1px solid var(--border-soft); background: var(--bg-panel);
  display: flex; align-items: center; gap: 12px; flex: none; min-height: 38px;
}
.ribbon .phase-tag {
  text-transform: uppercase; letter-spacing: 0.08em; font-size: 10.5px; font-weight: 700;
  color: var(--accent); background: rgba(61, 214, 196, 0.1); padding: 3px 8px; border-radius: 5px;
}
.ribbon .url { color: var(--text); font-family: var(--mono); font-size: 11.5px; }

.panes { flex: 1; min-height: 0; display: grid; grid-template-columns: 1.1fr 0.9fr 1fr; gap: 1px; background: var(--border-soft); }
.pane { background: var(--bg); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.pane-head {
  padding: 10px 14px; font-size: 12px; font-weight: 600; letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border-soft); color: var(--text-dim);
  display: flex; align-items: center; gap: 8px; flex: none;
}
.pane-ico { color: var(--accent); }
.pane-count { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--text-mute); background: var(--bg-panel); padding: 1px 8px; border-radius: 10px; font-size: 11px; }
.pane-body { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
/* Flex children in scrollable columns must keep their natural height (image-based items would
   otherwise be shrunk to fit instead of overflowing/scrolling once a column has many entries). */
.pane-body > *, .findings-list > * { flex-shrink: 0; }

/* Live-pane screenshot thumbnails: never overflow the column; full image via lightbox click. */
.thumb {
  max-width: 100%; display: block; max-height: 200px; object-fit: cover; object-position: top center;
  border-radius: 6px; border: 1px solid var(--border-soft); cursor: zoom-in; margin-top: 6px;
}

.entry {
  background: var(--bg-panel); border: 1px solid var(--border-soft); border-left: 2px solid var(--accent-dim);
  border-radius: 7px; padding: 8px 11px; font-size: 12.5px; animation: slidein 0.2s ease;
}
@keyframes slidein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.entry .meta { display: flex; align-items: center; gap: 7px; margin-bottom: 4px; font-size: 10.5px; color: var(--text-mute); }
.entry .body { color: var(--text); }
.entry.src-orchestrator { border-left-color: var(--accent); }
.entry.src-vision-model { border-left-color: var(--vision); }
.entry.src-text-model { border-left-color: var(--text-model); }
.src-badge { padding: 1px 6px; border-radius: 4px; font-weight: 600; letter-spacing: 0.03em; }
.src-badge.orchestrator { color: var(--accent); background: rgba(61,214,196,0.1); }
.src-badge.vision-model { color: var(--vision); background: rgba(188,140,255,0.12); }
.src-badge.text-model { color: var(--text-model); background: rgba(88,166,255,0.12); }

.crit-tag { font-family: var(--mono); font-size: 10px; font-weight: 700; color: var(--info); background: rgba(88,166,255,0.1); padding: 1px 5px; border-radius: 4px; }

.entry.act .body { font-family: var(--mono); font-size: 11.5px; }
.entry .coords { color: var(--text-mute); }

.evi-item { background: var(--bg-panel); border: 1px solid var(--border-soft); border-radius: 8px; overflow: hidden; animation: slidein 0.2s ease; }
.evi-item .evi-label { padding: 7px 10px; font-size: 11.5px; color: var(--text-dim); display: flex; gap: 7px; align-items: center; }
.evi-item .thumb { margin-top: 0; border-radius: 0; border: none; border-top: 1px solid var(--border-soft); max-height: 240px; background: #000; }

/* ── Results view ── */
.results-layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 380px 1fr; }
.findings-col { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--bg-panel); }
.filters { padding: 12px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--border-soft); flex: none; }
.filter-group { display: flex; gap: 5px; }
.filter-group button {
  flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--text-dim);
  padding: 5px 8px; border-radius: 6px; cursor: pointer; font-size: 11.5px; transition: all 0.1s;
}
.filter-group button:hover { color: var(--text); }
.filter-group button.active { background: var(--bg-elev); color: var(--text); border-color: var(--accent-dim); }

.findings-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.page-group-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-mute); padding: 10px 8px 4px; }
.finding-item {
  background: var(--bg); border: 1px solid var(--border-soft); border-radius: 8px; padding: 10px 11px;
  cursor: pointer; transition: all 0.1s; border-left: 3px solid var(--text-mute);
}
.finding-item:hover { border-color: var(--border); background: var(--bg-panel-2); }
.finding-item.selected { border-color: var(--accent); background: var(--bg-panel-2); }
.finding-item.v-pass { border-left-color: var(--pass); }
.finding-item.v-fail { border-left-color: var(--fail); }
.finding-item.v-needs_review { border-left-color: var(--review); }
.finding-item .fi-top { display: flex; align-items: center; gap: 8px; margin-bottom: 5px; }
.finding-item .fi-title { font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.finding-item .fi-bottom { display: flex; align-items: center; gap: 8px; }

.pill { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 2px 7px; border-radius: 5px; }
.pill.pass { color: var(--pass); background: rgba(63,185,80,0.12); }
.pill.fail { color: var(--fail); background: rgba(248,81,73,0.12); }
.pill.needs_review { color: var(--review); background: rgba(227,160,8,0.12); }
.sev { font-size: 10px; color: var(--text-mute); text-transform: uppercase; letter-spacing: 0.04em; }

.confbar { flex: 1; height: 5px; background: var(--bg-elev); border-radius: 3px; overflow: hidden; min-width: 40px; }
.confbar > span { display: block; height: 100%; background: var(--accent); }
.confval { font-size: 10.5px; color: var(--text-mute); font-variant-numeric: tabular-nums; min-width: 30px; text-align: right; }

/* ── Trace ── */
.trace-col { overflow-y: auto; padding: 22px 26px; min-height: 0; }
.empty, .empty-trace { color: var(--text-mute); padding: 40px 20px; text-align: center; font-size: 13px; }
.trace-header { border-bottom: 1px solid var(--border); padding-bottom: 18px; margin-bottom: 20px; }
.trace-header .th-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.trace-header h2 { margin: 4px 0 12px; font-size: 20px; font-weight: 600; }
.trace-meta { display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: 12px; color: var(--text-dim); }
.trace-meta b { color: var(--text); font-weight: 500; }
.trace-meta .mono { font-family: var(--mono); font-size: 11.5px; }

.score-row { display: flex; align-items: center; gap: 20px; margin: 16px 0; padding: 14px 16px; background: var(--bg-panel); border: 1px solid var(--border-soft); border-radius: 10px; }
.score-row .metric { display: flex; flex-direction: column; gap: 3px; }
.score-row .metric .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-mute); }
.score-row .metric .v { font-size: 16px; font-weight: 600; }
.big-conf { display: flex; flex-direction: column; gap: 5px; flex: 1; }
.big-conf .confbar { height: 8px; }

.layers-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-mute); margin: 22px 0 10px; }
.layer {
  background: var(--bg-panel); border: 1px solid var(--border-soft); border-radius: 9px;
  margin-bottom: 10px; overflow: hidden;
}
.layer-head { padding: 11px 14px; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.layer-head:hover { background: var(--bg-panel-2); }
.layer-kind { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 7px; border-radius: 4px; color: var(--bg); }
.layer-kind.metric { background: var(--accent); }
.layer-kind.vision { background: var(--vision); }
.layer-kind.text { background: var(--text-model); }
.layer-kind.action { background: #f0883e; }
.layer-kind.screenshot { background: var(--text-dim); }
.layer-kind.dom { background: #8b949e; }
.layer-label { font-weight: 600; font-size: 13px; }
.layer-summary { color: var(--text-dim); font-size: 12.5px; margin-left: auto; text-align: right; }
.layer-src { font-family: var(--mono); font-size: 10.5px; color: var(--text-mute); }
.layer-body { padding: 0 14px 14px; display: none; }
.layer.open .layer-body { display: block; }
.layer-body img { max-width: 100%; border-radius: 7px; border: 1px solid var(--border); cursor: zoom-in; margin-top: 6px; }
.layer-body pre {
  background: var(--bg); border: 1px solid var(--border-soft); border-radius: 7px; padding: 11px 13px;
  font-family: var(--mono); font-size: 11.5px; overflow-x: auto; color: var(--text-dim); margin: 8px 0 0;
  white-space: pre-wrap; word-break: break-word;
}
/* ── human-review gate ── */
.review-gate { margin: 16px 0 4px; padding: 14px 16px; background: rgba(227,160,8,0.06); border: 1px solid rgba(227,160,8,0.35); border-radius: 10px; }
.gate-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.gate-title { font-size: 13px; font-weight: 700; color: var(--review); letter-spacing: 0.02em; }
.gate-status { margin-left: auto; font-size: 11px; padding: 2px 9px; border-radius: 12px; background: var(--bg-elev); color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; }
.gate-status.agree { color: var(--review); }
.gate-status.override_pass { color: var(--pass); }
.gate-status.override_fail { color: var(--fail); }
.gate-note { font-size: 12px; color: var(--text-dim); margin-bottom: 11px; }
.gate-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.gate-btn { background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 7px 13px; border-radius: 7px; cursor: pointer; font-size: 12.5px; font-weight: 500; transition: all 0.1s; }
.gate-btn:hover { border-color: var(--text-mute); }
.gate-btn.agree.chosen { background: rgba(227,160,8,0.18); border-color: var(--review); color: var(--review); }
.gate-btn.pass.chosen { background: rgba(63,185,80,0.16); border-color: var(--pass); color: var(--pass); }
.gate-btn.fail.chosen { background: rgba(248,81,73,0.16); border-color: var(--fail); color: var(--fail); }
.gate-btn.reset { color: var(--text-mute); }

.gate-badge { font-size: 9.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; padding: 2px 6px; border-radius: 4px; margin-left: auto; }
.gate-badge.agree { color: var(--review); background: rgba(227,160,8,0.14); }
.gate-badge.override_pass { color: var(--pass); background: rgba(63,185,80,0.14); }
.gate-badge.override_fail { color: var(--fail); background: rgba(248,81,73,0.14); }

.remediation { margin-top: 18px; padding: 13px 15px; background: rgba(61,214,196,0.06); border: 1px solid var(--accent-dim); border-radius: 9px; font-size: 13px; }
.remediation .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--accent); margin-bottom: 5px; }

.chevron { color: var(--text-mute); transition: transform 0.15s; font-size: 11px; }
.layer.open .chevron { transform: rotate(90deg); }

/* ── Lightbox ── (hidden by default; shown only when .open is added.
   NOTE: must default to display:none — a `display` rule here overrides the [hidden] attribute
   at equal specificity, so relying on `hidden` alone leaves this overlay permanently covering
   the page and swallowing every click.) */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.88); display: none; align-items: center; justify-content: center; z-index: 100; cursor: zoom-out; padding: 30px; }
.lightbox.open { display: flex; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; box-shadow: 0 10px 60px rgba(0,0,0,0.6); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #2e3a4f; }
