:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3250;
  --accent: #4f8ef7;
  --accent2: #7c5cbf;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #f59e0b;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100vh;
  font-size: 14px;
}

/* ── Header ── */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
  margin-right: 8px;
}

.header input[type="text"],
.header input[type="date"] {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color .2s;
}
.header input:focus { border-color: var(--accent); }
.header input[type="text"] { width: 110px; }
.header input[type="date"] { width: 150px; }

.btn-run {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 7px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s;
  white-space: nowrap;
}
.btn-run:disabled { opacity: .45; cursor: not-allowed; }
.btn-run:not(:disabled):hover { opacity: .85; }

.analyst-select {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.analyst-chip {
  border: 1px solid var(--border);
  background: var(--surface2);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  user-select: none;
  transition: all .15s;
  color: var(--text-dim);
}
.analyst-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Layout ── */
.main {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 160px 1fr;
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 58px);
}

@media (max-width: 700px) {
  .main {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr;
    height: auto;
    min-height: calc(100vh - 58px);
  }
  .messages-panel { max-height: 160px; }
}

/* ── Progress panel ── */
.progress-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  overflow-y: auto;
  grid-row: span 2;
}

@media (max-width: 700px) {
  .progress-panel { grid-row: span 1; }
}

.panel-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 12px;
}

.team-block { margin-bottom: 14px; }
.team-name {
  font-size: 11px;
  color: var(--accent2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
}

.agent-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 6px;
  border-radius: 6px;
  font-size: 13px;
}
.agent-row:hover { background: var(--surface2); }

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--border);
  transition: background .3s;
}
.status-dot.pending  { background: var(--border); }
.status-dot.in_progress {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  animation: pulse 1s infinite;
}
.status-dot.completed { background: var(--green); }
.status-dot.error     { background: var(--red); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .4; }
}

/* ── Messages panel ── */
.messages-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  overflow-y: auto;
  height: 160px;
}

.msg-row {
  display: flex;
  gap: 8px;
  padding: 3px 0;
  font-size: 12px;
  border-bottom: 1px solid transparent;
}
.msg-role {
  flex-shrink: 0;
  width: 46px;
  color: var(--text-dim);
  text-align: right;
  font-weight: 600;
  font-size: 11px;
  padding-top: 1px;
}
.msg-role.agent  { color: var(--accent); }
.msg-role.tool   { color: var(--yellow); }
.msg-role.user   { color: var(--green); }
.msg-content {
  flex: 1;
  color: var(--text);
  word-break: break-word;
  white-space: pre-wrap;
  max-height: 60px;
  overflow: hidden;
}

/* ── Reports tabs ── */
.reports-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 300px;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 8px 10px 0;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}
.tab {
  padding: 6px 14px;
  border-radius: 6px 6px 0 0;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-dim);
  white-space: nowrap;
  border: 1px solid transparent;
  border-bottom: none;
  transition: all .15s;
  position: relative;
}
.tab:hover { color: var(--text); background: var(--surface2); }
.tab.active {
  color: var(--text);
  background: var(--surface2);
  border-color: var(--border);
}
.tab .dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  margin-left: 5px;
  vertical-align: middle;
  animation: pulse 1s infinite;
}

.tab-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
}

/* ── Decision card ── */
.decision-card {
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
  border-left: 4px solid var(--accent);
}
.decision-card.BUY  { border-color: var(--green); background: rgba(34,197,94,.07); }
.decision-card.SELL { border-color: var(--red);   background: rgba(239,68,68,.07); }
.decision-card.HOLD { border-color: var(--yellow); background: rgba(245,158,11,.07); }

.decision-badge {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: .05em;
  margin-bottom: 8px;
}
.decision-badge.BUY  { color: var(--green); }
.decision-badge.SELL { color: var(--red); }
.decision-badge.HOLD { color: var(--yellow); }

/* ── Markdown ── */
.md-body { line-height: 1.7; }
.md-body h1, .md-body h2, .md-body h3 {
  margin: 16px 0 8px;
  font-weight: 700;
  color: var(--text);
}
.md-body h1 { font-size: 18px; }
.md-body h2 { font-size: 16px; }
.md-body h3 { font-size: 14px; color: var(--accent); }
.md-body p  { margin: 6px 0; color: var(--text); }
.md-body ul, .md-body ol { padding-left: 20px; margin: 6px 0; }
.md-body li { margin: 3px 0; }
.md-body strong { color: #fff; }
.md-body hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.md-body code {
  background: var(--surface2);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
  color: var(--yellow);
}
.md-body table { border-collapse: collapse; width: 100%; margin: 8px 0; }
.md-body th, .md-body td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}
.md-body th { background: var(--surface2); font-weight: 600; }

/* ── Debate layout ── */
.debate-col { margin-bottom: 16px; }
.debate-col-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--accent2);
  margin-bottom: 8px;
  letter-spacing: .06em;
}

/* ── Empty state ── */
.empty {
  color: var(--text-dim);
  font-style: italic;
  text-align: center;
  padding: 40px 20px;
  font-size: 13px;
}

/* ── Error banner ── */
.error-banner {
  background: rgba(239,68,68,.15);
  border: 1px solid var(--red);
  border-radius: 6px;
  padding: 10px 14px;
  color: var(--red);
  font-size: 13px;
  margin: 10px 12px 0;
}

.btn-stop {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
}
.btn-stop:hover { border-color: var(--red); color: var(--red); }

/* ── Nav tabs (header) ── */
.nav-tabs {
  display: flex;
  gap: 2px;
  margin-right: 8px;
  background: var(--surface2);
  border-radius: 6px;
  padding: 3px;
}
.nav-tab {
  padding: 4px 14px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-dim);
  transition: all .15s;
  white-space: nowrap;
}
.nav-tab:hover { color: var(--text); }
.nav-tab.active { background: var(--surface); color: var(--text); }

/* ── History page ── */
.history-page {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 58px);
}

@media (max-width: 700px) {
  .history-page {
    grid-template-columns: 1fr;
    grid-template-rows: 220px 1fr;
    height: auto;
  }
}

.history-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-y: auto;
  padding: 10px 8px;
}

.history-item {
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .15s;
  border-bottom: 1px solid var(--border);
}
.history-item:last-child { border-bottom: none; }
.history-item:hover { background: var(--surface2); }
.history-item.active { background: var(--surface2); border-left: 3px solid var(--accent); }

.hi-ticker {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}
.hi-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}

.history-viewer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  overflow-y: auto;
}

.hv-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

/* ── Language selector ── */
.lang-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 7px 8px;
  font-size: 13px;
  outline: none;
}
