/* ── Reset + base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #0d0d1a;
  --surface:      #15152a;
  --surface-2:    #1e1e38;
  --border:       #2a2a4a;
  --text:         #e2e2f0;
  --text-muted:   #8888aa;
  --accent:       #4d7cfe;
  --accent-dim:   #1e2f66;

  --land:         #2e7d32;
  --land-bg:      #0a2610;
  --bridge:       #1565c0;
  --bridge-bg:    #051226;
  --scale:        #6a1b9a;
  --scale-bg:     #1a0528;
  --anchor:       #b71c1c;
  --anchor-bg:    #270808;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 12px;
  --shadow: 0 4px 20px rgba(0,0,0,0.4);
}

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

/* ── Layout ─────────────────────────────────────────────────────────────────── */
.layout { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }

/* ── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 20px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.logo { display: flex; align-items: center; gap: 10px; }
.logo-icon { font-size: 1.6em; }
.logo-text { font-size: 1.1em; font-weight: 800; letter-spacing: -0.5px; color: var(--text); }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--text-muted); font-weight: 600; }
.optional { font-weight: 400; text-transform: none; letter-spacing: 0; }

.form-group input, .form-group select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  transition: border-color 0.15s;
  width: 100%;
}
.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--accent);
}
.form-group input::placeholder { color: var(--text-muted); }

.options-section { display: flex; flex-direction: column; gap: 8px; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); cursor: pointer; }
.checkbox-label input[type="checkbox"] { accent-color: var(--accent); }

.btn-primary {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
  transition: opacity 0.15s, transform 0.1s;
  font-family: var(--font);
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: border-color 0.15s;
}
.btn-secondary:hover { border-color: var(--accent); }

.sidebar-meta {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.meta-row { display: flex; justify-content: space-between; font-size: 12px; }
.meta-row span:first-child { color: var(--text-muted); }
.meta-row span:last-child { color: var(--text); font-weight: 600; }

/* ── Main ───────────────────────────────────────────────────────────────────── */
.main { padding: 32px; overflow-y: auto; max-width: 960px; }

/* ── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 60vh; text-align: center; gap: 16px;
}
.empty-icon { font-size: 3em; }
.empty-state h2 { font-size: 1.6em; font-weight: 800; color: var(--text); letter-spacing: -0.5px; }
.empty-state p { color: var(--text-muted); max-width: 400px; }
.empty-pipeline { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; justify-content: center; }
.pipe-arrow { color: var(--text-muted); }
.pipe-badge { padding: 4px 14px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.pipe-badge.land    { background: var(--land-bg);   color: #4caf50; }
.pipe-badge.bridge  { background: var(--bridge-bg); color: #42a5f5; }
.pipe-badge.scale   { background: var(--scale-bg);  color: #ce93d8; }
.pipe-badge.anchor  { background: var(--anchor-bg); color: #ef9a9a; }

/* ── Error state ────────────────────────────────────────────────────────────── */
.error-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 40vh; gap: 12px; text-align: center;
}
.error-icon { font-size: 2.5em; }
.error-state h3 { color: #ef9a9a; font-size: 1.2em; }
.error-state p { color: var(--text-muted); max-width: 400px; }

/* ── Cards ──────────────────────────────────────────────────────────────────── */
.cards-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.cards-row .card { margin-bottom: 0; }

.card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Stage card ─────────────────────────────────────────────────────────────── */
.stage-badge {
  font-size: 2em;
  font-weight: 900;
  letter-spacing: -1px;
  margin-bottom: 4px;
}
.stage-confidence { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.stage-desc { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

.card-stage[data-stage="LAND"]   { border-color: var(--land);   background: var(--land-bg); }
.card-stage[data-stage="BRIDGE"] { border-color: var(--bridge); background: var(--bridge-bg); }
.card-stage[data-stage="SCALE"]  { border-color: var(--scale);  background: var(--scale-bg); }
.card-stage[data-stage="ANCHOR"] { border-color: var(--anchor); background: var(--anchor-bg); }

.card-stage[data-stage="LAND"]   .stage-badge { color: #4caf50; }
.card-stage[data-stage="BRIDGE"] .stage-badge { color: #42a5f5; }
.card-stage[data-stage="SCALE"]  .stage-badge { color: #ce93d8; }
.card-stage[data-stage="ANCHOR"] .stage-badge { color: #ef9a9a; }

/* ── Score gauge ────────────────────────────────────────────────────────────── */
.score-meter { position: relative; display: flex; flex-direction: column; align-items: center; }
.gauge { width: 120px; }
.score-number { font-size: 2em; font-weight: 900; margin-top: -20px; }
.score-tier { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 12px; }

.category-scores { width: 100%; display: flex; flex-direction: column; gap: 6px; }
.cat-row { display: flex; align-items: center; gap: 8px; }
.cat-label { font-size: 11px; color: var(--text-muted); width: 90px; text-transform: capitalize; }
.cat-bar-bg { flex: 1; height: 4px; background: var(--surface-2); border-radius: 2px; }
.cat-bar-fill { height: 100%; border-radius: 2px; background: var(--accent); transition: width 0.6s ease; }
.cat-score-num { font-size: 11px; color: var(--text-muted); width: 28px; text-align: right; }

/* ── Positioning card ───────────────────────────────────────────────────────── */
.positioning-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.pos-item { display: flex; flex-direction: column; gap: 4px; }
.pos-wide { grid-column: 1 / -1; }
.pos-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.pos-value { font-size: 15px; font-weight: 700; color: var(--text); }
.pos-rationale { font-size: 13px; color: var(--text-muted); font-style: italic; line-height: 1.5; }

.expansion-path { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.exp-step {
  background: var(--accent-dim);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}
.exp-arrow { color: var(--text-muted); font-size: 12px; }

/* ── Talk tracks ────────────────────────────────────────────────────────────── */
.talk-track-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.talk-track-list li {
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: 0 8px 8px 0;
  font-size: 13px;
  color: var(--text);
  line-height: 1.5;
}

/* ── Reasoning card ─────────────────────────────────────────────────────────── */
.confidence-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}
.confidence-badge.high   { background: #0a2610; color: #4caf50; }
.confidence-badge.medium { background: #2a1500; color: #ff9800; }
.confidence-badge.low    { background: #270808; color: #ef5350; }

.reasoning-headline {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
  line-height: 1.4;
  border-left: 3px solid var(--accent);
  padding-left: 12px;
}
.reasoning-narrative {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.7;
  margin-bottom: 16px;
  white-space: pre-wrap;
}

.reasoning-facts, .reasoning-risks { margin-bottom: 12px; }
.reasoning-facts h4, .reasoning-risks h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.fact-item, .risk-item {
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  line-height: 1.5;
}
.fact-item:last-child, .risk-item:last-child { border-bottom: none; }
.risk-item { color: #ef9a9a; }

/* ── Evidence table ─────────────────────────────────────────────────────────── */
.evidence-count { background: var(--surface-2); padding: 2px 8px; border-radius: 10px; font-size: 10px; }
.table-wrapper { overflow-x: auto; }
.evidence-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.evidence-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.evidence-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.evidence-table tbody tr:hover { background: var(--surface-2); }
.evidence-table tbody tr:last-child td { border-bottom: none; }

.source-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
}
.source-pill.tech            { background: #0a2010; color: #66bb6a; }
.source-pill.hiring          { background: #0a1520; color: #42a5f5; }
.source-pill.gdelt           { background: #1a1000; color: #ffca28; }
.source-pill.opencorporates  { background: #18080a; color: #ef9a9a; }

.category-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}
.category-pill.activation   { background: var(--land-bg);   color: #4caf50; }
.category-pill.measurement  { background: var(--bridge-bg); color: #42a5f5; }
.category-pill.identity     { background: var(--scale-bg);  color: #ce93d8; }
.category-pill.data         { background: var(--anchor-bg); color: #ef9a9a; }

.cred-bar-bg { background: var(--surface-2); border-radius: 4px; height: 6px; min-width: 60px; }
.cred-bar-fill { height: 100%; border-radius: 4px; background: var(--accent); }
.cred-num { font-size: 11px; color: var(--text-muted); text-align: right; }

/* ── Debug panel ────────────────────────────────────────────────────────────── */
.card-debug summary { cursor: pointer; user-select: none; }
.json-block {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-family: "Fira Code", "Cascadia Code", monospace;
  font-size: 12px;
  color: var(--text-muted);
  overflow-x: auto;
  white-space: pre;
  margin-top: 12px;
  max-height: 400px;
  overflow-y: auto;
}

/* ── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; border-right: none; border-bottom: 1px solid var(--border); }
  .cards-row { grid-template-columns: 1fr; }
  .positioning-grid { grid-template-columns: 1fr; }
  .main { padding: 20px; }
}
