:root {
  --bg: #0b0d12;
  --panel: #12151c;
  --panel-2: #191d26;
  --line: #232833;
  --text: #e7eaf0;
  --muted: #8b94a6;
  --accent: #7462f2;
  --accent-2: #a093ff;
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --info: #38bdf8;
  --r: 14px;
  --sidebar: 236px;
}

/* The toggle stamps data-theme on <html>; it must beat the media query. */
:root[data-theme="dark"] {
  --bg: #0b0d12; --panel: #12151c; --panel-2: #191d26; --line: #232833;
  --text: #e7eaf0; --muted: #8b94a6; --accent: #7462f2; --accent-2: #a093ff;
}
:root[data-theme="light"] {
  --bg: #f4f6fa; --panel: #ffffff; --panel-2: #f0f3f8; --line: #e2e7f0;
  --text: #131722; --muted: #5d6880; --accent: #5a44e4; --accent-2: #5a44e4;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg: #f4f6fa;
    --panel: #ffffff;
    --panel-2: #f0f3f8;
    --line: #e2e7f0;
    --text: #131722;
    --muted: #5d6880;
    --accent: #5a44e4;
    --accent-2: #5a44e4;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 "Instrument Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-feature-settings: "tnum" 1;
  overflow-x: hidden;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1rem; }
a { color: var(--accent-2); text-decoration: none; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85em; }

.shell { display: flex; min-height: 100vh; }

/* ── sidebar ───────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 14px calc(18px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 11px; padding: 0 6px; }
.brand strong { display: block; font-size: 0.98rem; }
.brand span { display: block; font-size: 0.72rem; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 11px;
  border-radius: 9px;
  color: var(--muted);
  font-weight: 550;
  font-size: 0.9rem;
}
.nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { background: var(--accent); color: #fff; }
.nav .ico { width: 16px; text-align: center; opacity: 0.9; }

.sys-status {
  margin-top: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 12px;
}
.sys-status h4 {
  font-size: 0.67rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--muted);
  margin-bottom: 9px;
}
.sys-row { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; font-size: 0.8rem; }
.sys-row span:last-child { color: var(--muted); }

/* ── main ──────────────────────────────────────────────────── */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: calc(18px + env(safe-area-inset-top));
}
.page-title { flex: 1; min-width: 0; }
.page-title p { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }

.views { padding: 20px 24px 60px; }
.view { display: flex; flex-direction: column; gap: 16px; }
/* `display` on a class beats the browser's own `[hidden] { display: none }`,
   so setting `.hidden = true` in JS did nothing and every view rendered at
   once — seven sections stacked, which is why clicking a tab looked like it
   did nothing and the page read as an unusable mess. */
.view[hidden] { display: none; }

/* ── buttons ───────────────────────────────────────────────── */

button { font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid transparent; }
button.primary {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  padding: 9px 16px;
  white-space: nowrap;
}
button.primary:hover { background: var(--accent-2); }
button.primary.wide { width: 100%; padding: 12px; margin-top: 14px; }
button.primary:disabled { opacity: 0.55; cursor: progress; }
button.ghost {
  background: var(--panel-2);
  border-color: var(--line);
  color: var(--text);
  padding: 6px 12px;
  font-size: 0.85rem;
}
.icon-btn {
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  width: 38px;
  height: 38px;
  font-size: 1.1rem;
}
.only-mobile { display: none; }

/* ── cards ─────────────────────────────────────────────────── */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px 18px;
}
.card.narrow { max-width: 620px; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.stack { display: flex; flex-direction: column; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1.55fr 1fr; gap: 16px; align-items: start; }

/* ── KPIs ──────────────────────────────────────────────────── */

/* As many columns as there are figures: five fixed columns left a gap. */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
/* Label, figure, note — stacked. Inline, the figure sat between the words
   ("Topics analysed 82 0 in the last 7 days"). */
.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 15px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.kpi-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.kpi-dot {
  width: 32px; height: 32px; border-radius: 9px;
  display: grid; place-items: center;
  font-size: 0.95rem;
}
.kpi-label { font-size: 0.78rem; color: var(--muted); font-weight: 550; }
.kpi-value { font-size: 2.1rem; letter-spacing: -0.02em; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-sub { font-size: 0.74rem; color: var(--muted); margin-top: 3px; }

/* ── tables ────────────────────────────────────────────────── */

table { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
th {
  text-align: left;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
  padding: 0 10px 9px;
  white-space: nowrap;
}
td { padding: 11px 10px; border-top: 1px solid var(--line); vertical-align: middle; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.num { text-align: right; }

/* Destructive actions look destructive, and never sit under the cursor by
   accident — the delete button only appears when its row is hovered. */
.head-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.head-tools input[type="search"] { min-width: 180px; }

.ghost.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.ghost.danger:hover:not(:disabled) { background: color-mix(in srgb, var(--bad) 12%, transparent); }
.ghost.danger:disabled { opacity: 0.45; cursor: not-allowed; }

.row-del {
  border: 1px solid transparent;
  background: none;
  color: var(--muted);
  border-radius: 7px;
  padding: 3px 8px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, color 0.12s ease;
}
tr:hover .row-del, .row-del:focus-visible { opacity: 1; }
.row-del:hover { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
.row-del:disabled { opacity: 0.4; cursor: wait; }
@media (hover: none) { .row-del { opacity: 1; } }

/* A pane that is fetching must not look like a pane that is broken. */
.loading {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 18px 2px;
}
.loading::after {
  content: "";
  display: inline-block;
  width: 0.9em;
  animation: ellipsis 1.2s steps(4, end) infinite;
}
@keyframes ellipsis { 0% { content: ""; } 25% { content: "."; }
  50% { content: ".."; } 75% { content: "..."; } }
@media (prefers-reduced-motion: reduce) {
  .loading::after { animation: none; content: "…"; }
}
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }
.topic-cell strong { display: block; font-weight: 600; }
.topic-cell span { font-size: 0.75rem; color: var(--muted); }

/* ── score ring ────────────────────────────────────────────── */

.ring { position: relative; width: 44px; height: 44px; }
.ring svg { transform: rotate(-90deg); display: block; }
.ring b {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 0.8rem; font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* ── badges & bars ─────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  border: 1px solid;
  white-space: nowrap;
}
.badge[data-b="SCALE"], .badge[data-b="STRONG_TEST"] { color: var(--good); border-color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent); }
.badge[data-b="TEST"] { color: var(--info); border-color: var(--info); background: color-mix(in srgb, var(--info) 12%, transparent); }
.badge[data-b="WATCHLIST"] { color: var(--warn); border-color: var(--warn); background: color-mix(in srgb, var(--warn) 12%, transparent); }
.badge[data-b="REJECTED"] { color: var(--bad); border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, transparent); }

.mini-bar { height: 5px; background: var(--panel-2); border-radius: 999px; overflow: hidden; min-width: 60px; }
.mini-bar > span { display: block; height: 100%; background: var(--accent); }

.spark { display: block; }

/* ── status rows ───────────────────────────────────────────── */

.status-row {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-top: 1px solid var(--line);
}
.status-row:first-child { border-top: 0; }
.status-row .name { flex: 1; font-weight: 550; font-size: 0.88rem; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.on { background: var(--good); box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent); }
.dot.off { background: var(--muted); }
.dot.err { background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 22%, transparent); }
.status-row .state { font-size: 0.78rem; color: var(--muted); }

/* ── pipeline ──────────────────────────────────────────────── */

.pipeline { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.stage { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--muted); }
.stage i {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--line);
  display: grid; place-items: center; font-style: normal; font-size: 0.7rem;
}
.stage.done i { border-color: var(--good); color: var(--good); }
.stage.done { color: var(--text); }
.stage.active i { border-color: var(--accent); color: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.stage.active { color: var(--text); }
.stage-arrow { color: var(--line); }
@keyframes pulse { 50% { opacity: 0.45; } }

.progress { margin: 0; padding-left: 18px; font-size: 0.82rem; color: var(--muted); max-height: 220px; overflow-y: auto; }
.progress li { margin-bottom: 3px; }
.progress b { color: var(--text); }

/* ── forms ─────────────────────────────────────────────────── */

label { display: block; font-weight: 600; margin: 14px 0 7px; font-size: 0.88rem; }
input[type="text"] {
  width: 100%; padding: 12px 14px; font-size: 16px;
  color: var(--text); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 10px;
}
input[type="text"]:focus-visible, button:focus-visible, .nav a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.check { display: flex; align-items: center; gap: 9px; font-weight: 500; font-size: 0.86rem; cursor: pointer; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); margin: 0; }

/* ── category sweep results ─────────────────────────────────── */

.cat-group { margin-top: 16px; }
.cat-group:first-child { margin-top: 4px; }
.cat-group h3 {
  margin: 0 0 6px;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.cand-row {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 10px 0; border-top: 1px solid var(--line);
}
.cand-signal {
  min-width: 44px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent-2);
}
.cand-headline { font-weight: 600; line-height: 1.4; }

/* Complaint vs question: the difference between a problem and a shopper. */
.kind {
  display: inline-block;
  padding: 1px 7px; margin-right: 6px;
  border-radius: 999px;
  font-size: 0.66rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em;
  border: 1px solid;
}
.kind.complaint {
  color: var(--good); border-color: var(--good);
  background: color-mix(in srgb, var(--good) 12%, transparent);
}
.kind.question {
  color: var(--muted); border-color: var(--line);
  background: var(--panel-2);
}

/* Mode switch on Opportunities: flat list vs top 10 grouped by family. */
.modes { display: flex; gap: 6px; }

/* A family header spans the table so its rows read as one group. */
.family-head > td {
  padding-top: 16px;
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--line);
}
.family-head b { color: var(--text); }
tbody tr.family-head:first-child > td { padding-top: 4px; }

/* Sits beside the confidence figure, never folded into the score. */
.thin {
  display: inline-block;
  margin-left: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--warn);
  cursor: help;
}

.filters { display: flex; gap: 6px; flex-wrap: wrap; }
/* Same trap as `.view[hidden]` above: this `display` beats the browser's own
   `[hidden]` rule, so hiding the band chips in grouped mode did nothing and
   they sat there filtering a list that no longer honoured them. */
.filters[hidden] { display: none; }
.chip {
  padding: 5px 12px; border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── detail view ───────────────────────────────────────────── */

.factor { padding: 12px 0; border-top: 1px solid var(--line); }
.factor:first-child { border-top: 0; }
.factor-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.factor-name { font-weight: 600; font-size: 0.9rem; }
.factor-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.factor-score.unscored { color: var(--muted); font-weight: 500; font-size: 0.82rem; }
.factor-why { font-size: 0.8rem; color: var(--muted); margin: 7px 0 0; }
.tag {
  font-size: 0.64rem; letter-spacing: 0.04em; padding: 2px 6px;
  border-radius: 4px; background: var(--panel-2); color: var(--muted); font-weight: 600;
}
.tag[data-claim="ESTIMATED"] { color: var(--warn); }
.tag[data-claim="CALCULATED"], .tag[data-claim="OBSERVED"] { color: var(--good); }

.evidence {
  padding: 10px 12px; margin: 8px 0;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
}
.evidence-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; margin-bottom: 5px; }
.evidence code { font-size: 0.7rem; color: var(--muted); }
.evidence p { margin: 0 0 6px; font-size: 0.84rem; overflow-wrap: anywhere; }

.objection {
  padding: 12px 14px; margin-bottom: 11px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-left: 3px solid var(--muted); border-radius: 9px;
}
.objection[data-sev="CRITICAL"] { border-left-color: var(--bad); }
.objection[data-sev="HIGH"] { border-left-color: var(--warn); }
.objection[data-sev="MEDIUM"] { border-left-color: var(--info); }
.objection h3 { font-size: 0.92rem; margin: 4px 0 6px; }
.objection p { margin: 0 0 7px; font-size: 0.85rem; }

.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; padding: 7px 14px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line);
  color: var(--muted); font-size: 0.85rem; font-weight: 600;
}
.tab[aria-selected="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.warn-box { border-color: var(--warn); }
.warn-box.critical { border-color: var(--bad); border-width: 2px; }
.warn-box ul { margin: 0; padding-left: 20px; font-size: 0.84rem; color: var(--muted); }
.warn-box li.loud { color: var(--bad); font-weight: 550; font-size: 0.92rem; }

pre {
  margin: 0; font-size: 0.76rem; line-height: 1.5; white-space: pre;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.muted, .fineprint { color: var(--muted); }
.fineprint { font-size: 0.78rem; }
.small { font-size: 0.78rem; }
.error { color: var(--bad); font-size: 0.86rem; }
.link { font-size: 0.82rem; font-weight: 600; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.empty { color: var(--muted); font-size: 0.88rem; padding: 18px 0; text-align: center; }

.backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 40;
}

/* ── top bar controls ──────────────────────────────────────── */

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.select {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 8px 10px; font: inherit; font-size: 0.84rem;
}
.icon-btn.bell { position: relative; }
.icon-btn.bell b {
  position: absolute; top: -5px; right: -5px;
  min-width: 17px; height: 17px; padding: 0 4px;
  border-radius: 999px; background: var(--bad); color: #fff;
  font-size: 0.62rem; font-weight: 700;
  display: grid; place-items: center;
}

/* ── thumbnails ────────────────────────────────────────────── */

.thumb {
  width: 56px; height: 38px; border-radius: 7px; object-fit: cover;
  display: block; background: var(--panel-2); border: 1px solid var(--line);
}
.thumb-empty {
  display: grid; place-items: center;
  color: var(--muted); font-size: 0.9rem;
}

/* ── charts ────────────────────────────────────────────────── */

.legend-row {
  display: flex; align-items: center; gap: 14px;
  margin-top: 8px; flex-wrap: wrap;
}
.legend { display: inline-flex; align-items: center; gap: 6px; font-size: 0.76rem; color: var(--muted); }
.legend i { width: 9px; height: 9px; border-radius: 2px; display: inline-block; }

/* ── alerts ────────────────────────────────────────────────── */

.alert-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 9px 0; border-top: 1px solid var(--line);
}
.alert-row:first-child { border-top: 0; }
.alert-ico {
  width: 24px; height: 24px; border-radius: 7px; flex: none;
  display: grid; place-items: center; font-size: 0.78rem; font-weight: 700;
}
.alert-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.alert-body b { font-size: 0.86rem; font-weight: 600; }
.alert-body span { font-size: 0.76rem; color: var(--muted); }

/* ── activity flow ─────────────────────────────────────────── */

.flow {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  padding-bottom: 12px; margin-bottom: 6px; border-bottom: 1px solid var(--line);
}
.flow-step { display: flex; align-items: center; gap: 7px; font-size: 0.76rem; color: var(--muted); }
.flow-step i {
  width: 26px; height: 26px; border-radius: 8px; font-style: normal;
  background: var(--panel-2); border: 1px solid var(--line);
  display: grid; place-items: center; color: var(--accent-2); font-size: 0.8rem;
}
.flow-arrow { color: var(--line); }

/* ── outcome band ──────────────────────────────────────────── */

.outcome-band {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r); padding: 16px 18px;
}
.outcome-band b { display: block; font-size: 0.88rem; margin-bottom: 3px; }
.outcome-band span { font-size: 0.76rem; color: var(--muted); }

/* ── discover ──────────────────────────────────────────────── */

.seedbar label:first-child { margin-top: 0; }
.seedbar-row { display: flex; gap: 8px; align-items: stretch; }
.seedbar-row input[type="text"] { flex: 1; min-width: 0; }
.seedbar-row button { white-space: nowrap; padding: 0 16px; }
.seedbar .fineprint { margin: 10px 0 0; }

.disc-section { display: flex; flex-direction: column; gap: 12px; }
.disc-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }

.occards { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 14px; }
.occards > .empty, .occards > .error, .occards > .locked { grid-column: 1 / -1; }

.occard {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--r);
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.occard.clickable { cursor: pointer; }
.occard.clickable:hover { border-color: var(--accent); }
.occard-head { display: flex; align-items: flex-start; gap: 12px; }
.occard-title { flex: 1; min-width: 0; }
.occard-title h3 { font-size: 0.95rem; overflow-wrap: anywhere; }
.occard-title span { display: block; margin-top: 2px; }

.occard-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.occard-metrics div {
  background: var(--panel-2); border-radius: 10px; padding: 8px 6px; text-align: center;
}
.occard-metrics b { display: block; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.occard-metrics span { font-size: 0.7rem; color: var(--muted); }

.occard-quotes { margin: 0; padding-left: 16px; font-size: 0.8rem; color: var(--muted); }
.occard-quotes li { margin-bottom: 5px; overflow-wrap: anywhere; }
.occard-note { margin: 0; }
.occard-trend { display: flex; justify-content: flex-end; }

.occard-actions { display: flex; gap: 8px; margin-top: auto; }
button.sm { padding: 7px 12px; font-size: 0.8rem; }
.occard-actions .primary { flex: 1; }

.tag[data-status="promoted"] { color: var(--good); }
.tag[data-status="rejected"] { color: var(--bad); }
.tag[data-status="investigating"] { color: var(--info); }

/* The AI section is empty on purpose until a real call has been made. */
.locked {
  border: 1px dashed var(--line); border-radius: var(--r);
  padding: 18px; background: var(--panel);
}
.locked b { font-size: 0.92rem; }
.locked p { margin: 8px 0 0; font-size: 0.84rem; color: var(--muted); }

/* ── factor blocks ─────────────────────────────────────────── */

.blocks { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.block {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--r);
  padding: 15px; display: flex; flex-direction: column; gap: 10px;
}
.block-head { display: flex; align-items: center; gap: 12px; }
.block-title { flex: 1; min-width: 0; }
.block-title h3 { font-size: 0.98rem; }
.block-note { margin: 0; font-size: 0.78rem; color: var(--muted); }
.block-why { margin: 0; font-size: 0.84rem; overflow-wrap: anywhere; }

.block-gap { margin: 0; font-size: 0.76rem; color: var(--warn); }
.block-gap.loud {
  color: var(--bad); font-weight: 550;
  border-left: 2px solid var(--bad); padding-left: 9px;
}

.block-rows { display: flex; flex-direction: column; margin-top: auto; }
.block-row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 10px;
  padding: 6px 0; border-top: 1px solid var(--line); font-size: 0.84rem;
}
.block-row-name { font-weight: 550; }
.block-row-name .fineprint { font-weight: 400; margin-left: 5px; }
.block-row-score { font-weight: 700; font-variant-numeric: tabular-nums; }
.block-row-score.unscored { color: var(--muted); font-weight: 500; font-size: 0.78rem; }

.block summary, .all-factors summary {
  cursor: pointer; font-size: 0.78rem; color: var(--muted);
}
.all-factors { margin-top: 16px; border-top: 1px solid var(--line); padding-top: 12px; }
.all-factors summary { font-weight: 600; }

/* ── responsive ────────────────────────────────────────────── */

@media (max-width: 1080px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 1080px) {
  .outcome-band { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 780px) {
  .only-mobile { display: grid; place-items: center; }
  .topbar-actions .select { display: none; }
  .outcome-band { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 40px rgba(0,0,0,0.4);
  }
  .sidebar.open { transform: none; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding: 14px 16px; padding-top: calc(14px + env(safe-area-inset-top)); }
  .views { padding: 16px 16px 70px; }
  h1 { font-size: 1.22rem; }
  .page-title p { display: none; }
  button.primary { padding: 9px 12px; font-size: 0.85rem; }
  /* Three controls will not fit one phone row; stack instead of scrolling. */
  .seedbar-row { flex-direction: column; }
  .seedbar-row button { padding: 11px 16px; }
  .occards { grid-template-columns: 1fr; }
  .blocks { grid-template-columns: 1fr; }
}

@media (max-width: 420px) {
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-value { font-size: 1.5rem; }
}

/* ── Read-only demo (data-demo="1", see export_demo.py) ─────────────────
   Every control that writes is hidden rather than left to fail. */
[data-demo="1"] #new-research-btn,
[data-demo="1"] .seedbar,
[data-demo="1"] .card:has(#sweep-btn),
[data-demo="1"] #clear-runs-btn,
[data-demo="1"] #probe-btn,
[data-demo="1"] .row-del,
[data-demo="1"] [data-cand] [data-act] { display: none !important; }
.demo-note {
  margin: 0 0 16px; padding: 10px 14px; border-radius: 10px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  font-size: 0.88rem; line-height: 1.45;
}


/* Grid and flex children may shrink below their content, so a wide table
   scrolls inside its .scroll-x box instead of widening the whole page: the
   dashboard's top-opportunities table pushed phones to 613px. */
.main, .grid-2 > *, .blocks > *, .kpis > *, .occards > *, .stack > *, .card { min-width: 0; }

/* ── The evidence map ─────────────────────────────────────────────────
   Behind the pages: observations as dots, gathered into clusters and linked
   to each cluster's centre, the best-backed clusters ringed — what the engine
   does, drawn faintly. Two mask tiles (evidence-map.svg, evidence-rings.svg)
   so each theme colours them: dots and links in the text colour, rings in
   the accent. Cards stay opaque on top; it shows only in the gaps. */
.main { position: relative; isolation: isolate; }
.main::before,
.main::after {
  content: "";
  position: fixed;
  inset: 0 0 0 var(--sidebar);
  z-index: -1;
  pointer-events: none;
  -webkit-mask: url(evidence-map.svg) 0 0 / 1200px 1200px repeat;
  mask: url(evidence-map.svg) 0 0 / 1200px 1200px repeat;
  background: var(--text);
  opacity: 0.075;
}
.main::after {
  -webkit-mask-image: url(evidence-rings.svg);
  mask-image: url(evidence-rings.svg);
  background: var(--accent);
  opacity: 0.32;
}
:root[data-theme="light"] .main::before { opacity: 0.09; }
:root[data-theme="light"] .main::after { opacity: 0.28; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .main::before { opacity: 0.09; }
  :root:not([data-theme]) .main::after { opacity: 0.28; }
}
@media (max-width: 780px) {
  .main::before, .main::after { left: 0; }
}

/* Touch screens: the small controls get a fingertip-sized target (chips
   were 31px, "View all" 20px, a report's source links 15px). */
@media (pointer: coarse) {
  .chip { min-height: 40px; }
  .link { display: inline-flex; align-items: center; min-height: 40px; }
  a.fineprint { display: inline-flex; align-items: center; min-height: 36px; }
}

