:root {
  --bg: #0a0e14;
  --bg-surface: #0d1117;
  --fg: #33ff33;
  --fg-dim: #1a8c1a;
  --fg-bright: #66ff66;
  --amber: #ffb833;
  --red: #ff3333;
  --red-dim: #991a1a;
  --cyan: #33cccc;
  --purple: #bb88ff;
  --border: #1a8c1a;
  --border-bright: #33ff33;
  --font: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  --glow: 0 0 8px rgba(51, 255, 51, 0.15);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: clamp(0.7rem, 0.65rem + 0.3vw, 0.875rem);
  line-height: 1.5;
  overflow-x: hidden;
}

/* CRT container */
#crt {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  position: relative;
}

#crt::after {
  content: '';
  position: fixed;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 2px,
    rgba(0, 0, 0, 0.08) 2px,
    rgba(0, 0, 0, 0.08) 4px
  );
  pointer-events: none;
  z-index: 100;
}

/* ── Stats Bar ───────────────────────────── */
#stats-bar {
  border: 1px solid var(--border-bright);
  padding: 0.5rem 1rem;
  margin-bottom: 1rem;
  white-space: pre;
  text-shadow: var(--glow);
  background: var(--bg-surface);
}

.stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem 2rem;
}

.stats-row .label {
  color: var(--fg-dim);
}

.stats-title {
  font-weight: 700;
  font-size: 1.1em;
  color: var(--fg-bright);
  margin-bottom: 0.25rem;
  text-align: center;
}

/* ── Agent Cards ─────────────────────────── */
#agents {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.agent-card {
  border: 1px solid var(--border);
  padding: 0.75rem;
  background: var(--bg-surface);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  text-align: center;
  min-height: 7rem;
}

.agent-card:hover,
.agent-card:focus-visible {
  border-color: var(--border-bright);
  box-shadow: var(--glow);
  outline: 2px solid var(--border-bright);
  outline-offset: 2px;
}

.agent-card.active {
  border-color: var(--fg-bright);
  box-shadow: 0 0 12px rgba(51, 255, 51, 0.3);
}

.agent-name {
  font-weight: 700;
  font-size: 0.85em;
  letter-spacing: 0.1em;
  margin-bottom: 0.25rem;
}

.agent-face {
  font-size: 1.6em;
  line-height: 1.2;
  margin: 0.25rem 0;
}

.agent-status {
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.agent-time {
  font-size: 0.7em;
  color: var(--fg-dim);
  margin-top: 0.25rem;
}

.agent-card[data-agent="scout"] .agent-name { color: var(--cyan); }
.agent-card[data-agent="quant"] .agent-name { color: var(--fg-bright); }
.agent-card[data-agent="technician"] .agent-name { color: var(--amber); }
.agent-card[data-agent="cio"] .agent-name { color: var(--purple); }

/* ── Section Headers ─────────────────────── */
.section-header {
  color: var(--fg-dim);
  font-weight: 700;
  letter-spacing: 0.15em;
  font-size: 0.8em;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.25rem;
  margin-bottom: 0.5rem;
}

/* ── Portfolio Table ─────────────────────── */
#portfolio {
  margin-bottom: 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 0.75rem;
}

.ascii-table {
  width: 100%;
  overflow-x: auto;
  white-space: pre;
  font-size: 0.85em;
  line-height: 1.6;
}

.pnl-pos { color: var(--fg-bright); }
.pnl-neg { color: var(--red); }

/* ── Memo Feed ───────────────────────────── */
#memo-feed {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  padding: 0.75rem;
  margin-bottom: 1rem;
}

#memo-list {
  max-height: 35vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) var(--bg);
}

#memo-list::-webkit-scrollbar {
  width: 6px;
}

#memo-list::-webkit-scrollbar-track {
  background: var(--bg);
}

#memo-list::-webkit-scrollbar-thumb {
  background: var(--border);
}

.memo-entry {
  padding: 0.2rem 0;
  border-bottom: 1px solid rgba(51, 255, 51, 0.05);
  font-size: 0.82em;
}

.memo-time {
  color: var(--fg-dim);
}

.memo-agent {
  font-weight: 700;
  min-width: 4ch;
  display: inline-block;
}

.memo-agent.scout { color: var(--cyan); }
.memo-agent.quant { color: var(--fg-bright); }
.memo-agent.technician { color: var(--amber); }
.memo-agent.cio { color: var(--purple); }
.memo-agent.pipeline { color: var(--fg-dim); }

/* ── Pipeline Bar ────────────────────────── */
#pipeline-bar {
  border: 1px solid var(--border);
  padding: 0.4rem 1rem;
  background: var(--bg-surface);
  font-size: 0.8em;
  color: var(--fg-dim);
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.pipeline-stage {
  letter-spacing: 0.05em;
}

.stage-done { color: var(--fg); }
.stage-fail { color: var(--red); }
.stage-pending { color: var(--fg-dim); }

/* ── Detail Panel ────────────────────────── */
.panel {
  position: fixed;
  top: 0;
  right: 0;
  width: min(480px, 90vw);
  height: 100vh;
  background: var(--bg);
  border-left: 2px solid var(--border-bright);
  z-index: 200;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  transition: transform 0.2s ease;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.5);
}

.panel.hidden {
  transform: translateX(100%);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-bright);
  padding-bottom: 0.5rem;
  margin-bottom: 1rem;
  font-weight: 700;
  font-size: 1em;
}

.panel-header button {
  background: none;
  border: 1px solid var(--border);
  color: var(--fg);
  font-family: var(--font);
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  font-size: 0.85em;
}

.panel-header button:hover,
.panel-header button:focus-visible {
  border-color: var(--red);
  color: var(--red);
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

#detail-body {
  font-size: 0.85em;
  line-height: 1.6;
}

#detail-body .detail-section {
  margin-bottom: 1rem;
}

#detail-body .detail-label {
  color: var(--fg-dim);
  font-size: 0.8em;
  letter-spacing: 0.1em;
  margin-bottom: 0.25rem;
}

/* ── Status indicators ───────────────────── */
.status-idle { color: var(--fg-dim); }
.status-running { color: var(--amber); }
.status-error { color: var(--red); }

/* ── Theme toggle ────────────────────────── */
.theme-btn {
  font-size: 0.5em;
  cursor: pointer;
  padding: 0.15rem 0.5rem;
  border: 1px solid var(--border);
  margin-left: 0.75rem;
  letter-spacing: 0.1em;
  transition: border-color 0.15s, color 0.15s;
  user-select: none;
}
.theme-btn:hover {
  border-color: var(--border-bright);
  color: var(--fg-bright);
}

/* ── Pipeline stages ─────────────────────── */
.pipeline-stages {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}

/* ── Empty state ─────────────────────────── */
.empty-state {
  color: var(--fg-dim);
  font-style: italic;
  padding: 1rem 0;
  text-align: center;
}

/* ── Thesis panel ─────────────────────────── */
.thesis-chain {
  margin-bottom: 1rem;
}

.thesis-stage {
  border-left: 2px solid var(--border);
  padding: 0.5rem 0 0.5rem 1rem;
  margin-left: 0.25rem;
  position: relative;
}

.thesis-stage::before {
  content: '';
  position: absolute;
  left: -5px;
  top: 0.6rem;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg-dim);
}

.thesis-stage.scout-stage::before { background: var(--cyan); }
.thesis-stage.quant-stage::before { background: var(--fg-bright); }
.thesis-stage.tech-stage::before { background: var(--amber); }
.thesis-stage.cio-stage::before { background: var(--purple); }

.thesis-stage-label {
  font-weight: 700;
  font-size: 0.85em;
  letter-spacing: 0.1em;
  margin-bottom: 0.25rem;
}

.thesis-stage.scout-stage .thesis-stage-label { color: var(--cyan); }
.thesis-stage.quant-stage .thesis-stage-label { color: var(--fg-bright); }
.thesis-stage.tech-stage .thesis-stage-label { color: var(--amber); }
.thesis-stage.cio-stage .thesis-stage-label { color: var(--purple); }

.thesis-field {
  display: flex;
  gap: 0.5rem;
  font-size: 0.82em;
  line-height: 1.5;
}

.thesis-field .field-label {
  color: var(--fg-dim);
  min-width: 8ch;
  flex-shrink: 0;
}

.thesis-narrative {
  font-size: 0.82em;
  line-height: 1.5;
  color: var(--fg);
  margin-top: 0.15rem;
}

.thesis-red-flags {
  color: var(--red);
  font-size: 0.82em;
}

.thesis-pos-header {
  text-align: center;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.thesis-pos-header .ticker-name {
  font-size: 1.4em;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--fg-bright);
}

.thesis-pos-header .pnl-line {
  font-size: 0.9em;
  margin-top: 0.25rem;
}

.thesis-pos-header .meta-line {
  font-size: 0.8em;
  color: var(--fg-dim);
  margin-top: 0.15rem;
}

.ticker-link {
  cursor: pointer;
  text-decoration: underline;
  text-decoration-style: dotted;
  text-underline-offset: 3px;
  transition: color 0.15s;
}

.ticker-link:hover {
  color: var(--fg-bright);
  text-shadow: 0 0 6px currentColor;
}

/* ── Compliance bar ─────────────────────── */
.compliance-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  font-size: 0.8em;
  padding: 0.3rem 0;
  border-top: 1px solid var(--border);
  margin-top: 0.3rem;
  align-items: center;
}

.compliance-bar .label {
  color: var(--fg-dim);
  font-weight: bold;
}

.compliance-warnings {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.75em;
  padding: 0.2rem 0;
}

.compliance-warn {
  color: #ff6;
  background: rgba(255, 255, 102, 0.08);
  padding: 0.1rem 0.4rem;
  border-radius: 2px;
}

/* ── Research / review panels ───────────────── */
#research-ops,
#decision-review {
  border: 1px solid var(--border);
  background: var(--bg-surface);
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.review-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.review-card {
  border: 1px solid rgba(51, 255, 51, 0.2);
  padding: 0.65rem 0.75rem;
  background: rgba(10, 14, 20, 0.8);
}

.review-label {
  color: var(--fg-dim);
  font-size: 0.8em;
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.review-value {
  color: var(--fg-bright);
  font-weight: 700;
  font-size: 1.1em;
}

.review-subvalue {
  color: var(--cyan);
  font-size: 0.85em;
  margin-top: 0.15rem;
}

.review-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.review-toolbar .toolbar-btn {
  display: inline-block;
  border: 1px solid var(--border);
  color: var(--fg);
  text-decoration: none;
  background: transparent;
  padding: 0.35rem 0.55rem;
  font: inherit;
  cursor: pointer;
}

.review-toolbar .toolbar-btn:hover {
  border-color: var(--border-bright);
  color: var(--fg-bright);
}

.run-list,
.dissent-list {
  display: grid;
  gap: 0.6rem;
}

.run-item,
.dissent-item {
  border-left: 3px solid var(--border);
  padding-left: 0.65rem;
}

.run-item.failed,
.dissent-item.loss {
  border-left-color: var(--red);
}

.run-item.completed,
.dissent-item.win {
  border-left-color: var(--fg-bright);
}

.run-meta,
.dissent-meta {
  color: var(--fg-dim);
  font-size: 0.82em;
}

.report-markdown {
  white-space: pre-wrap;
  font-family: var(--font);
  color: var(--fg);
  line-height: 1.55;
}

/* ── Responsive ──────────────────────────── */
@media (max-width: 768px) {
  #agents {
    grid-template-columns: repeat(2, 1fr);
  }
  #crt {
    padding: 0.5rem;
  }
}

@media (max-width: 480px) {
  #agents {
    grid-template-columns: 1fr;
  }
}

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