:root {
  --bg: #0e1117;
  --panel: #161b22;
  --panel-2: #1c2230;
  --border: #2a313c;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #3b82f6;
  --green: #26a269;
  --amber: #d9a441;
  --red: #d9534f;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo { color: var(--accent); font-size: 22px; }
.topbar h1 { font-size: 18px; margin: 0; }
.subtitle { margin: 0; color: var(--muted); font-size: 12px; }
.actions { display: flex; align-items: center; gap: 10px; }
.exp-badge { display: inline-block; font-size: 10px; font-weight: 700; letter-spacing: 0.02em; color: var(--amber); background: rgba(217,164,65,0.14); border: 1px solid rgba(217,164,65,0.4); padding: 2px 7px; border-radius: 999px; vertical-align: middle; margin-left: 8px; }
.menu-wrap { position: relative; display: inline-block; }
.menu { position: absolute; top: calc(100% + 4px); left: 0; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 6px; display: flex; flex-direction: column; gap: 6px; z-index: 20; box-shadow: var(--shadow); min-width: 150px; }
.menu .btn { width: 100%; text-align: left; }
.status { color: var(--muted); font-size: 12px; margin-right: 6px; }

.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.progress { display: flex; align-items: center; gap: 12px; padding: 8px 20px; background: var(--panel); }
.progress-bar { flex: 1; height: 6px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.3s; }

.controls {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
}
.input {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--border);
  padding: 7px 10px; border-radius: 8px; font-size: 13px;
}
.input[type='search'] { min-width: 220px; }
.range { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }

.backtest {
  margin: 12px 20px; padding: 14px 16px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px;
}
.backtest table { width: 100%; border-collapse: collapse; font-size: 13px; }
.backtest th, .backtest td { text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); }
.backtest .num { text-align: right; }
.backtest .note { color: var(--muted); font-size: 12px; margin-top: 8px; }

main { padding: 6px 20px 40px; }
.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.grid th { color: var(--muted); font-weight: 600; font-size: 12px; cursor: pointer; user-select: none; }
.grid th.num, .grid td.num { text-align: right; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: var(--panel); }
.grid .name { color: var(--muted); max-width: 240px; overflow: hidden; text-overflow: ellipsis; }

.scorecell { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.scorebar { width: 60px; height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.scorebar > div { height: 100%; }

.badge { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.undervalued { background: rgba(38,162,105,0.18); color: #4ade80; }
.badge.fair { background: rgba(217,164,65,0.18); color: #f0c674; }
.badge.rich { background: rgba(217,83,79,0.18); color: #f2837f; }
.badge.unknown { background: var(--panel-2); color: var(--muted); }

.flag { font-size: 10px; color: var(--amber); background: rgba(217,164,65,0.12); padding: 1px 6px; border-radius: 6px; margin-right: 4px; }
.flag.danger { color: var(--red); background: rgba(217,83,79,0.12); }

.empty { color: var(--muted); text-align: center; padding: 40px; }
.hidden { display: none !important; }

.disclaimer { color: var(--muted); font-size: 11px; padding: 16px 20px 30px; border-top: 1px solid var(--border); }

/* Drawer */
.drawer { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; justify-content: flex-end; z-index: 50; }
.drawer-inner { width: min(560px, 100%); height: 100%; background: var(--panel); border-left: 1px solid var(--border); box-shadow: var(--shadow); overflow-y: auto; padding: 20px 22px; position: relative; }
.close { position: absolute; top: 14px; right: 16px; background: none; border: none; color: var(--muted); font-size: 18px; cursor: pointer; }
.detail-head h2 { margin: 0; font-size: 22px; }
.detail-head .sub { color: var(--muted); font-size: 13px; margin: 2px 0 14px; }
.detail-metrics { margin: 6px 0 18px; }
.cat { margin-bottom: 14px; }
.cat-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 6px; }
.cat-head .w { color: var(--muted); font-weight: 400; font-size: 11px; }
.subrow { display: flex; justify-content: space-between; padding: 3px 0; font-size: 12px; color: var(--muted); }
.subrow .sname { color: var(--text); }
.mini { width: 90px; height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; display: inline-block; vertical-align: middle; margin-left: 8px; }
.mini > div { height: 100%; }
canvas { background: var(--panel-2); border-radius: 8px; padding: 6px; }

/* Signal thesis (Phase 2.5): descriptive "why interesting" panel in the drawer. */
.thesis { margin: 4px 0 16px; padding: 10px 12px; background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: 8px; }
.thesis.match { border-left-color: var(--green); }
.thesis-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.thesis-head .sub { color: var(--muted); font-size: 12px; }
.thesis-label { margin: 2px 0 6px; font-size: 14px; color: var(--text); }
.thesis .sub { font-size: 12px; margin: 4px 0; }
.thesis .muted { color: var(--muted); }
.thesis-chip { background: var(--green); color: #04120a; border-radius: 10px; padding: 1px 8px; font-size: 11px; font-weight: 700; }

/* ── Phase B: decision-first candidate view ─────────────────────────────── */
.ds-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.ds-row h2 { margin: 0; }
.price-line { margin: 2px 0 6px; font-size: 15px; }
.ds-pill { font-size: 13px; font-weight: 800; letter-spacing: .04em; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.ds-BUY      { background: rgba(38,162,105,.16);  color: #4ade80; border-color: #2b7a54; }
.ds-HOLD     { background: rgba(59,130,246,.16);   color: #7dacff; border-color: #2f5ca8; }
.ds-ELIGIBLE { background: rgba(217,164,65,.16);    color: #e5b95f; border-color: #8a6b28; }
.ds-REDUCE   { background: rgba(217,164,65,.16);    color: #e5b95f; border-color: #8a6b28; }
.ds-WATCH    { background: rgba(139,148,158,.14);   color: var(--muted); }
.ds-EXIT     { background: rgba(217,83,79,.16);     color: #f0928f; border-color: #8a3b38; }
.ds-headline { color: var(--text); font-size: 13px; margin: 4px 0 10px; opacity: .92; }
.ds-sect { margin: 12px 0; }
.ds-h { margin: 0 0 6px; font-size: 11px; font-weight: 700; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; }
.ds-list { list-style: none; margin: 0; padding: 0; }
.ds-list li { font-size: 12.5px; line-height: 1.5; margin: 2px 0; color: var(--text); }
.ds-list.good li { color: #cfe9db; }
.ds-list.bad li  { color: #f0b6b4; }
.ds-list.warn li { color: #e9d4a6; }
.ds-list.chg li  { color: #b9cdf0; }
.ev-grid { display: grid; grid-template-columns: 1fr; gap: 2px; }
.ev-row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.ev-row > span:first-child { color: var(--muted); }
.ev-strong  { color: #4ade80; font-weight: 700; }
.ev-neutral { color: var(--muted); }
.ev-weak    { color: #f0928f; font-weight: 700; }
.ds-sect.research { margin-top: 16px; padding-top: 10px; border-top: 1px dashed var(--border); opacity: .9; }
.ds-sect.research .unval { color: var(--amber); font-style: normal; font-size: 11px; font-weight: 600; }

/* ── Phase B: portfolio decision-chain (journal) timeline ───────────────── */
tr.clickrow { cursor: pointer; }
tr.clickrow:hover td { background: var(--panel-2); }
.tl-wrap { margin: 10px 0 4px; }
.tl-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin: 8px 0; background: var(--panel-2); }
.tl-head { display: flex; align-items: center; gap: 10px; }
.tl-date { font-weight: 700; color: var(--text); }
.tl-recon { font-size: 10px; color: var(--amber); border: 1px solid #8a6b28; border-radius: 6px; padding: 0 6px; }
.tl-then { margin-top: 8px; }
.tl-thenlbl, .tl-nowlbl { display: block; font-size: 10px; letter-spacing: .08em; color: var(--muted); text-transform: uppercase; margin-bottom: 3px; }
.tl-thesis { font-size: 12.5px; color: var(--text); line-height: 1.45; }
.tl-ev { font-size: 12px; margin-top: 4px; color: var(--muted); }
.tl-meta { font-size: 11.5px; margin-top: 3px; color: var(--muted); }
.tl-now { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--border); font-size: 12.5px; }

/* ── Phase B: attribution skeleton ──────────────────────────────────────── */
.attr-pending { color: var(--muted); font-style: italic; }

/* grid decision pill (compact) */
.ds-pill.ds-mini { font-size: 10px; font-weight: 700; padding: 1px 7px; letter-spacing: .03em; }

/* ── Data-legitimacy / research-integrity ledger ────────────────────────── */
.lg-grid { display: grid; gap: 10px; margin-top: 10px; }
.lg-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; background: var(--panel-2); }
.lg-head { display: flex; gap: 10px; align-items: baseline; }
.lg-statuses { display: flex; gap: 6px; flex-wrap: wrap; margin: 7px 0; }
.lg-chip { font-size: 11px; padding: 1px 8px; border-radius: 6px; border: 1px solid var(--border); color: var(--muted); }
.lg-chip.lg-good { color: #4ade80; border-color: #2b7a54; }
.lg-chip.lg-bad { color: #f0928f; border-color: #8a3b38; }
.lg-chip.lg-warn { color: var(--amber); border-color: #8a6b28; }
.lg-verdict { font-weight: 800; font-size: 12px; letter-spacing: .04em; }
.lg-v-muted { color: var(--muted); }
.lg-v-warn { color: var(--amber); }
.lg-v-good { color: #4ade80; }
.lg-v-info { color: #7dacff; }

/* ── Automation readiness (four-gate doctrine) ──────────────────────────── */
.ar-box { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; background: var(--panel-2); }
.ar-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ar-state { font-weight: 800; font-size: 12px; letter-spacing: .04em; padding: 2px 10px; border-radius: 999px; }
.ar-disarmed { background: rgba(217,83,79,.16); color: #f0928f; border: 1px solid #8a3b38; }
.ar-armed { background: rgba(38,162,105,.16); color: #4ade80; border: 1px solid #2b7a54; }

/* Left-rail navigation (replaces the top-bar dropdown buttons, 2026-09-09) */
.layout { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 18px; align-items: start; padding: 0 16px; }
.sidebar { position: sticky; top: 12px; display: flex; flex-direction: column; gap: 16px; }
.sidebar .nav-group { display: flex; flex-direction: column; gap: 4px; }
.sidebar h3 { margin: 0 0 2px; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted, #8a94a6); }
.sidebar .nav-item {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 7px;
  background: transparent; border: 1px solid transparent; color: var(--text, inherit);
  cursor: pointer; font-size: 13px; line-height: 1.2;
}
.sidebar .nav-item:hover { background: var(--panel, rgba(127,127,127,.10)); border-color: var(--border, #2a2f3a); }
.sidebar .nav-item.active { background: var(--panel, rgba(127,127,127,.14)); border-color: var(--border, #3a4150); font-weight: 600; }
.sidebar-note { margin: 4px 2px 0; font-size: 11px; color: var(--muted, #8a94a6); line-height: 1.35; }
.content { min-width: 0; }
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; gap: 10px; }
  .sidebar { position: static; flex-direction: row; flex-wrap: wrap; gap: 10px; }
  .sidebar .nav-group { flex-direction: row; flex-wrap: wrap; }
  .sidebar h3 { width: 100%; }
  .sidebar-note { display: none; }
}
