/* ── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  --bg:           #0d0d0d;
  --surface:      #161616;
  --surface-hi:   #1a1a1a;
  --border:       #222;
  --border-hi:    #2a2a2a;
  --accent:       #00c8aa;
  --accent-dim:   rgba(0,200,170,.15);
  --text:         #ffffff;
  --text-muted:   #aaaaaa;
  --text-dim:     #666666;
  --selected-bg:  #1a2a28;
  --selected-bdr: rgba(0,200,170,.35);
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: system-ui, sans-serif; font-size: 14px; line-height: 1.5; }
a { color: var(--accent); text-decoration: none; }
ul { list-style: none; padding: 0; }
button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.top-bar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: #111; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.main-panels { display: flex; flex: 1; overflow: hidden; }

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.wordmark { color: var(--accent); font-size: 11px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; white-space: nowrap; }
.preset-badge { background: var(--accent-dim); color: var(--accent); font-size: 8px; padding: 2px 8px; border-radius: 10px; font-weight: 600; white-space: nowrap; }
.top-bar-spacer { flex: 1; }
.filter-select { background: var(--surface-hi); color: var(--text-muted); border: 1px solid var(--border-hi); border-radius: 4px; padding: 4px 8px; font-size: 11px; }
.fetch-btn { background: var(--accent); color: #000; border-radius: 4px; padding: 5px 14px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.fetch-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── News list (left panel) ──────────────────────────────────────────────── */
.news-list { width: 38%; min-width: 260px; border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.news-list-header { padding: 10px 12px 6px; font-size: 9px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 1px; flex-shrink: 0; }
.news-list-items { overflow-y: auto; flex: 1; padding: 6px 8px; }
.news-item { background: var(--surface); border: 1px solid var(--border); border-radius: 5px; padding: 10px; margin-bottom: 6px; cursor: pointer; text-align: left; width: 100%; transition: border-color .15s; }
.news-item:hover { border-color: #333; }
.news-item.is-selected { background: var(--selected-bg); border-color: var(--selected-bdr); }
.news-item-chips { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 5px; }
.news-item-title { font-size: 10px; font-weight: 600; color: var(--text); line-height: 1.35; margin-bottom: 4px; }
.news-item-meta { font-size: 8px; color: var(--text-dim); }

/* ── Analysis panel (right panel) ────────────────────────────────────────── */
.analysis-panel { flex: 1; overflow-y: auto; padding: 16px; }
.analysis-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.analysis-meta-region { font-size: 9px; color: var(--text-dim); }
.analysis-source-link { margin-left: auto; font-size: 9px; }
.analysis-title { font-size: 15px; font-weight: 700; line-height: 1.3; margin-bottom: 4px; }
.analysis-byline { font-size: 9px; color: var(--text-dim); margin-bottom: 16px; }
.analysis-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.analysis-box { background: var(--surface); border: 1px solid var(--border); border-radius: 5px; padding: 12px; }
.analysis-materials-checks { display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start; margin-bottom: 10px; }
.material-chips { display: flex; flex-direction: column; gap: 4px; }
.checks-list { padding-left: 14px; list-style: disc; }
.checks-list li { color: var(--text-muted); font-size: 10px; line-height: 1.8; }

/* ── Cross-checks ────────────────────────────────────────────────────────── */
.cross-checks { background: var(--surface-hi); border: 1px solid var(--border-hi); border-radius: 5px; padding: 12px; }
.cross-checks-header { font-size: 8px; color: var(--accent); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; }
.cross-checks-ts { color: var(--text-dim); font-size: 8px; text-transform: none; letter-spacing: 0; margin-left: 6px; }
.cross-check-row { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 7px; }
.cross-check-label { font-size: 8px; color: var(--text-dim); min-width: 60px; padding-top: 2px; }
.cross-check-text { font-size: 9px; color: var(--text-dim); line-height: 1.5; }
.badge { font-size: 8px; padding: 1px 7px; border-radius: 3px; border: 1px solid; white-space: nowrap; flex-shrink: 0; }
.badge-warn  { color: #ffa94d; border-color: rgba(200,130,0,.3); background: rgba(200,130,0,.1); }
.badge-ok    { color: #66cc88; border-color: rgba(0,150,60,.3);  background: rgba(0,150,60,.1);  }
.badge-info  { color: var(--accent); border-color: var(--accent-dim); background: var(--accent-dim); }
.badge-neutral { color: #888; border-color: var(--border-hi); background: transparent; }

/* ── Shared components ───────────────────────────────────────────────────── */
.eyebrow { font-size: 8px; color: var(--accent); text-transform: uppercase; letter-spacing: 1px; margin-bottom: 6px; }
.chip { font-size: 9px; padding: 2px 8px; border-radius: 10px; display: inline-block; }
.chip-material { background: var(--accent-dim); color: var(--accent); }
.chip-inferred { background: rgba(255,180,0,0.1); color: #b8860b; border: 1px dashed #b8860b; font-style: italic; cursor: help; }
.event-pill { font-size: 8px; padding: 1px 7px; border-radius: 10px; font-weight: 600; }

/* ── Event type colours ──────────────────────────────────────────────────── */
.et-export-restriction  { background: rgba(200,0,50,.15);  color: #ff6b6b; }
.et-import-tariff       { background: rgba(200,50,50,.15); color: #ff9090; }
.et-sanctions           { background: rgba(200,100,0,.15); color: #ffa94d; }
.et-supply-shortage     { background: rgba(200,180,0,.15); color: #ffd166; }
.et-mine-disruption     { background: rgba(0,50,200,.15);  color: #66aaff; }
.et-smelter-disruption  { background: rgba(0,80,200,.15);  color: #88ccff; }
.et-logistics           { background: rgba(120,0,200,.15); color: #cc88ff; }
.et-labour-unrest       { background: rgba(200,0,120,.15); color: #ff88cc; }
.et-geopolitical        { background: rgba(0,150,120,.15); color: #00c8aa; }
.et-natural-disaster    { background: rgba(100,100,100,.15); color: #aaaaaa; }
.et-regulatory          { background: rgba(200,200,0,.15); color: #ffe066; }
.et-company-update      { background: rgba(100,100,100,.1); color: #999999; }

/* ── Empty / loading states ──────────────────────────────────────────────── */
.empty-state, .loading-state, .error-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--text-dim); gap: 12px; text-align: center; padding: 32px;
}
.state-icon { font-size: 28px; }
.state-title { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.state-body { font-size: 11px; max-width: 320px; line-height: 1.6; }
.retry-btn { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 6px 14px; font-size: 11px; margin-top: 4px; }

/* ============================================================
   Intelligence mode
   ============================================================ */

.mode-toggle {
  display: flex;
  gap: 2px;
  background: #1a1a1a;
  border-radius: 6px;
  padding: 2px;
}

.mode-btn {
  padding: 4px 12px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: #888;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.mode-btn.is-active {
  background: #2a2a2a;
  color: #e2e8f0;
}

.intel-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.intel-panel {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
}

.intel-section {
  background: #141414;
  border: 1px solid #2a2a2a;
  border-radius: 8px;
  padding: 16px;
}

.intel-section-header {
  font-size: 11px;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Day tabs */
.day-tabs {
  display: flex;
  gap: 2px;
}

.day-tab {
  padding: 3px 10px;
  border: 1px solid #333;
  border-radius: 4px;
  background: transparent;
  color: #888;
  font-size: 11px;
  cursor: pointer;
}

.day-tab.is-active {
  background: #2a2a2a;
  color: #e2e8f0;
  border-color: #444;
}

/* Ranked table */
.intel-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.intel-table th {
  text-align: left;
  color: #666;
  font-weight: 500;
  font-size: 10px;
  padding: 4px 8px;
  border-bottom: 1px solid #2a2a2a;
}

.intel-table-row {
  cursor: pointer;
  transition: background 0.1s;
}

.intel-table-row:hover { background: #1e1e1e; }

.intel-table-row td {
  padding: 8px 8px;
  border-bottom: 1px solid #1e1e1e;
  color: #ccc;
  vertical-align: middle;
}

.intel-mat-name { font-weight: 500; color: #e2e8f0; text-transform: capitalize; }
.intel-count    { font-variant-numeric: tabular-nums; }
.intel-country  { color: #888; }

/* Trend chips */
.trend-up     { color: #ef4444; font-weight: 600; }
.trend-down   { color: #10b981; font-weight: 600; }
.trend-stable { color: #888; }

/* Charts */
.chart-container {
  position: relative;
  overflow: hidden; /* prevent responsive Chart.js ResizeObserver loop in scrollable parent */
}

.chart-container--timeline { height: 280px; }
.chart-container--bar      { height: 180px; }

/* Country list */
.country-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.country-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.country-name    { color: #e2e8f0; font-weight: 500; min-width: 100px; }
.country-count   { color: #888; min-width: 70px; }
.country-also    { color: #666; font-size: 10px; }
.country-materials { color: #666; font-size: 10px; }

/* Per-material header */
.intel-material-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid #2a2a2a;
  flex-wrap: wrap;
}

.back-btn {
  background: none;
  border: none;
  color: #6366f1;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}

.back-btn:hover { color: #818cf8; }

.intel-material-name {
  font-size: 16px;
  font-weight: 600;
  color: #e2e8f0;
  text-transform: capitalize;
}

.trend-chip {
  font-size: 11px;
  color: #888;
  margin-left: auto;
}

/* Narrative box */
.narrative-section {}

.narrative-box {
  background: #0f172a;
  border: 1px solid #1e3a5f;
  border-radius: 6px;
  padding: 16px;
}

.narrative-text {
  font-size: 13px;
  line-height: 1.7;
  color: #cbd5e1;
  margin: 0 0 12px 0;
}

.narrative-meta {
  font-size: 10px;
  color: #475569;
  margin: 0;
  font-style: italic;
}

/* Highlighted callout bullets inside narrative boxes */
.narrative-bullet {
  font-size: 13px;
  line-height: 1.7;
  color: #cbd5e1;
  margin: 0 0 6px 0;
}

.narrative-signal {
  background: rgba(251, 191, 36, 0.08);
  border-left: 3px solid #f59e0b;
  border-radius: 4px;
  padding: 10px 14px;
  margin: 12px 0 6px 0;
}
.signal-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #f59e0b;
  margin-bottom: 5px;
}
.signal-body {
  font-size: 13px;
  line-height: 1.65;
  color: #fde68a;
}

.narrative-action {
  background: rgba(59, 130, 246, 0.08);
  border-left: 3px solid #3b82f6;
  border-radius: 4px;
  padding: 10px 14px;
  margin: 12px 0 0 0;
}
.action-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #60a5fa;
  margin-bottom: 5px;
}
.action-body {
  font-size: 13px;
  line-height: 1.65;
  color: #93c5fd;
}

/* Charts row */
.intel-charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

@media (max-width: 900px) {
  .intel-charts-row { grid-template-columns: 1fr; }
}

.no-data {
  font-size: 11px;
  color: #555;
  margin: 0;
}

/* ── Risk History timeline ───────────────────────────────────────────────── */
.risk-history-section {}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-entry {
  border-radius: 5px;
  overflow: hidden;
}

.history-entry + .history-entry {
  border-top: 1px solid #1e1e1e;
}

/* Remove default <details> marker */
.history-entry > summary {
  list-style: none;
}
.history-entry > summary::-webkit-details-marker {
  display: none;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 5px;
  transition: background 0.12s;
  user-select: none;
}

.history-row:hover {
  background: #1a1a1a;
}

.history-entry[open] > .history-row {
  background: #111827;
  border-radius: 5px 5px 0 0;
}

/* Custom expand/collapse icon */
.history-toggle-icon {
  flex-shrink: 0;
  width: 14px;
  height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #555;
  font-size: 10px;
  transition: transform 0.15s;
}
.history-toggle-icon::before {
  content: "▶";
}
.history-entry[open] > .history-row .history-toggle-icon {
  transform: rotate(90deg);
}

.history-date {
  flex-shrink: 0;
  font-size: 11px;
  color: #888;
  font-variant-numeric: tabular-nums;
  min-width: 78px;
}

.history-count {
  flex-shrink: 0;
  font-size: 10px;
  color: #666;
  min-width: 52px;
  text-align: right;
}

.history-trend {
  flex-shrink: 0;
  font-size: 11px;
  min-width: 16px;
  text-align: center;
}

.history-preview {
  flex: 1;
  font-size: 11px;
  color: #9ca3af;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.history-entry[open] > .history-row .history-preview {
  display: none;
}

.history-full-narrative {
  background: #0f172a;
  border: 1px solid #1e3a5f;
  border-top: none;
  border-radius: 0 0 5px 5px;
  padding: 12px 14px;
}

.history-full-narrative p {
  font-size: 12px;
  line-height: 1.65;
  color: #94a3b8;
  margin: 0;
}
