:root {
  --canvas: #e8ebef;
  --surface: #ffffff;
  --surface-sunk: #f2f4f7;
  --ink: #16202b;
  --ink-soft: #5a6673;
  --ink-faint: #8a949f;
  --rule: #cfd6de;
  --brass: #a8791c;
  --brass-soft: #f0e2c4;
  --gain: #0f6b4f;
  --loss: #a32a21;
  --radius: 3px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--canvas);
  color: var(--ink);
  font-family: 'Archivo', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

h1, h2, h3 { letter-spacing: -0.018em; margin: 0; font-weight: 800; }
h2 { font-size: 1.22rem; }
h3 { font-size: 0.95rem; font-weight: 600; margin: 26px 0 10px; color: var(--ink-soft); }
p { margin: 0; }
.muted { color: var(--ink-soft); font-size: 0.86rem; }
.hidden { display: none !important; }
.num { font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; }

/* ---------- login ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-card {
  background: var(--surface); padding: 34px; width: 100%; max-width: 360px;
  border: 1px solid var(--rule); border-radius: var(--radius);
  display: flex; flex-direction: column; gap: 14px;
}
.login-card h1 { font-size: 1.5rem; }
.login-card p { color: var(--ink-soft); font-size: 0.9rem; margin-bottom: 6px; }

label { display: block; font-size: 0.82rem; color: var(--ink-soft); font-weight: 500; }
input, select, textarea {
  width: 100%; margin-top: 5px; padding: 9px 10px; font: inherit; font-size: 0.9rem;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule); border-radius: var(--radius);
}
input[type="number"] { font-family: 'IBM Plex Mono', monospace; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--brass); outline-offset: -1px; border-color: var(--brass);
}
textarea { font-family: 'IBM Plex Mono', monospace; font-size: 0.82rem; resize: vertical; }

.btn {
  font: inherit; font-size: 0.86rem; font-weight: 600; padding: 9px 15px; cursor: pointer;
  border-radius: var(--radius); border: 1px solid var(--rule);
  background: var(--surface); color: var(--ink);
}
.btn:hover { border-color: var(--ink-soft); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #24313f; }
.btn.quiet { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn.quiet:hover { color: var(--ink); background: var(--surface-sunk); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--brass); outline-offset: 2px; }
.error { color: var(--loss); font-size: 0.84rem; min-height: 18px; }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; gap: 26px; padding: 0 20px; height: 56px;
  background: var(--surface); border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; letter-spacing: -0.02em; }
.mark {
  width: 13px; height: 13px; background: var(--brass);
  clip-path: polygon(0 100%, 33% 45%, 66% 62%, 100% 0, 100% 100%);
}
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.tab {
  font: inherit; font-size: 0.88rem; font-weight: 500; padding: 7px 12px;
  background: none; border: 0; border-radius: var(--radius);
  color: var(--ink-soft); cursor: pointer; white-space: nowrap;
}
.tab:hover { background: var(--surface-sunk); color: var(--ink); }
.tab.active { background: var(--ink); color: #fff; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.run-state { font-size: 0.8rem; color: var(--ink-soft); }

.progress-strip {
  height: 26px; background: var(--brass-soft); display: flex; align-items: center;
  padding: 0 16px; font-size: 0.78rem; color: #6b4c0e; position: relative;
}
.progress-fill {
  position: absolute; left: 0; top: 0; bottom: 0; background: rgba(168,121,28,.28);
  transition: width .4s ease;
}
.progress-strip span { position: relative; }

/* ---------- views ---------- */
.view { display: none; }
.view.active { display: block; }
#view-shortlist.active { display: grid; grid-template-columns: minmax(320px, 400px) 1fr; }
.page { max-width: 940px; padding: 26px 24px 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 20px; }
.page-actions { display: flex; gap: 8px; }

/* ---------- candidate rail ---------- */
.rail {
  background: var(--surface); border-right: 1px solid var(--rule);
  min-height: calc(100vh - 56px);
}
.rail-head {
  padding: 18px 20px 12px; border-bottom: 1px solid var(--rule);
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
}
.rail-head .meta { font-size: 0.76rem; color: var(--ink-faint); }
.candidates { list-style: none; margin: 0; padding: 0; }
.candidate {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 12px; align-items: center;
  padding: 13px 20px; border-bottom: 1px solid var(--rule); cursor: pointer;
  border-left: 3px solid transparent;
}
.candidate:hover { background: var(--surface-sunk); }
.candidate.selected { background: var(--surface-sunk); border-left-color: var(--brass); }
.candidate.lead .ticker { color: var(--brass); }
.rank { font-family: 'IBM Plex Mono', monospace; font-size: 0.8rem; color: var(--ink-faint); }
.ticker { font-family: 'IBM Plex Mono', monospace; font-weight: 600; font-size: 0.9rem; }
.company { font-size: 0.8rem; color: var(--ink-soft); margin-top: 1px; }
.cand-right { display: flex; align-items: center; gap: 12px; }
.cand-score { font-family: 'IBM Plex Mono', monospace; font-weight: 600; font-size: 1.05rem; }

/* the signal signature: six bars whose shape you learn to recognise */
.sig { display: flex; align-items: flex-end; gap: 2px; height: 26px; }
.sig i { width: 4px; background: var(--rule); display: block; border-radius: 1px; }
.sig i.on { background: var(--ink); }
.candidate.lead .sig i.on { background: var(--brass); }

/* ---------- detail ---------- */
.detail { padding: 26px 30px 60px; max-width: 780px; }
.detail-head { border-bottom: 1px solid var(--rule); padding-bottom: 16px; margin-bottom: 20px; }
.detail-head h2 { font-size: 1.55rem; }
.detail-head .sym { font-family: 'IBM Plex Mono', monospace; color: var(--ink-soft); font-size: 0.9rem; }
.headline-score { display: flex; align-items: baseline; gap: 10px; margin-top: 12px; }
.headline-score b { font-family: 'IBM Plex Mono', monospace; font-size: 2.4rem; font-weight: 600; color: var(--brass); line-height: 1; }
.narrative { font-size: 1.02rem; margin: 14px 0 0; max-width: 62ch; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip {
  font-size: 0.74rem; padding: 3px 8px; border: 1px solid var(--rule);
  border-radius: 999px; color: var(--ink-soft); background: var(--surface);
}

.bars { display: grid; gap: 9px; margin-top: 6px; }
.bar-row { display: grid; grid-template-columns: 132px 1fr 42px; gap: 10px; align-items: center; font-size: 0.84rem; }
.bar-track { height: 7px; background: var(--surface-sunk); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--ink); border-radius: 999px; }
.bar-row.top .bar-fill { background: var(--brass); }
.bar-val { font-family: 'IBM Plex Mono', monospace; font-size: 0.82rem; text-align: right; }

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 1px; background: var(--rule); border: 1px solid var(--rule); }
.fact { background: var(--surface); padding: 11px 13px; }
.fact span { display: block; font-size: 0.74rem; color: var(--ink-soft); }
.fact b { font-family: 'IBM Plex Mono', monospace; font-size: 1.05rem; font-weight: 600; }
.fact b.up { color: var(--gain); }
.fact b.down { color: var(--loss); }

.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: 9px 0; border-bottom: 1px solid var(--rule); font-size: 0.87rem; }
.list-plain li:last-child { border-bottom: 0; }
.list-plain a { color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--rule); }
.list-plain a:hover { border-bottom-color: var(--brass); }
.src { color: var(--ink-faint); font-size: 0.76rem; }

.spark { display: block; margin-top: 8px; }

/* ---------- settings ---------- */
.group { background: var(--surface); border: 1px solid var(--rule); margin-bottom: 14px; }
.group > summary {
  padding: 13px 16px; cursor: pointer; font-weight: 600; font-size: 0.95rem;
  display: flex; justify-content: space-between; align-items: center;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::after { content: '+'; color: var(--ink-faint); font-weight: 400; }
.group[open] > summary::after { content: '\2013'; }
.group[open] > summary { border-bottom: 1px solid var(--rule); }
.group-body { padding: 16px; }
.group-desc { font-size: 0.83rem; color: var(--ink-soft); margin-bottom: 14px; max-width: 66ch; }
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(196px, 1fr)); gap: 13px; }
.kv-row { display: grid; grid-template-columns: 1fr 96px; gap: 8px; margin-bottom: 7px; align-items: center; }
.kv-row span { font-size: 0.84rem; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; margin: 0; }
.save-note { font-size: 0.84rem; color: var(--gain); margin-left: 10px; }
.save-note.bad { color: var(--loss); }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--rule); font-size: 0.86rem; }
.table th { text-align: left; font-weight: 600; font-size: 0.78rem; color: var(--ink-soft); padding: 9px 12px; border-bottom: 1px solid var(--rule); }
.table td { padding: 9px 12px; border-bottom: 1px solid var(--rule); }
.table tr:last-child td { border-bottom: 0; }
.table td.n { font-family: 'IBM Plex Mono', monospace; }
.pill { font-size: 0.74rem; padding: 2px 8px; border-radius: 999px; }
.pill.hit { background: #dff0e8; color: var(--gain); }
.pill.miss { background: #f6e2e0; color: var(--loss); }
.pill.wait { background: var(--surface-sunk); color: var(--ink-soft); }

.import-box { background: var(--surface); border: 1px solid var(--rule); padding: 16px; margin-bottom: 18px; }
.import-box .btn { margin-top: 12px; }
.model-status { background: var(--surface); border: 1px solid var(--rule); padding: 14px 16px; margin-bottom: 18px; font-size: 0.88rem; }
.logs { background: var(--surface); border: 1px solid var(--rule); max-height: 340px; overflow: auto; font-family: 'IBM Plex Mono', monospace; font-size: 0.78rem; }
.logs div { padding: 5px 12px; border-bottom: 1px solid var(--surface-sunk); }
.logs .error { color: var(--loss); }

.empty { padding: 40px 22px; color: var(--ink-soft); font-size: 0.9rem; max-width: 46ch; }
.empty p + p { margin-top: 8px; }
.disclaimer { padding: 18px 24px 30px; font-size: 0.76rem; color: var(--ink-faint); }

@media (max-width: 900px) {
  #view-shortlist.active { grid-template-columns: 1fr; }
  .rail { border-right: 0; border-bottom: 1px solid var(--rule); min-height: 0; }
  .topbar { height: auto; flex-wrap: wrap; padding: 10px 14px; gap: 12px; }
  .tabs { order: 3; width: 100%; }
  .detail { padding: 20px 16px 50px; }
  .bar-row { grid-template-columns: 104px 1fr 38px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
