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

:root {
  --bg: #14141b;
  --panel: #1b1b25;
  --panel-2: #21212e;
  --border: #2c2c3a;
  --text: #e8e8f0;
  --muted: #9a9ab0;
  --faint: #6c6c82;
  --accent: #e0584f;
  --accent-2: #f0a04b;
  --ongoing: #f0a04b;
  --state: #7c93e8;
  --coalition: #5ec8c0;
  --nonstate: #c98be0;
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Space Grotesk', system-ui, sans-serif;
}

.page {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 0.9rem;
  padding: 0.9rem 1.1rem 0.8rem;
}

/* ---- topbar ---- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.7rem;
}
.topbar-left { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; }
.topbar-icon { font-size: 1.5rem; }
.topbar-title { font-size: 1.3rem; font-weight: 700; letter-spacing: 0.2px; }
.topbar-sub { color: var(--muted); font-size: 0.85rem; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.data-vintage {
  font-family: 'Space Mono', monospace;
  font-size: 0.72rem;
  color: var(--faint);
  border: 1px solid var(--border);
  padding: 0.18rem 0.5rem;
  border-radius: 5px;
}
.back-link { color: var(--muted); text-decoration: none; font-size: 0.85rem; }
.back-link:hover { color: var(--text); }

/* ---- KPIs ---- */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.7rem;
}
.metric-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.7rem 0.9rem;
}
.metric-card.alert { border-color: rgba(224, 88, 79, 0.55); background: linear-gradient(180deg, rgba(224,88,79,0.08), var(--panel)); }
.metric-val { font-family: 'Space Mono', monospace; font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.metric-card.alert .metric-val { color: var(--accent); }
.metric-label { font-size: 0.82rem; margin-top: 0.15rem; }
.metric-note { font-size: 0.72rem; color: var(--muted); margin-top: 0.2rem; }

/* ---- main grid ---- */
.main {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(320px, 1.2fr);
  gap: 0.9rem;
  min-height: 0;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 11px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ---- controls ---- */
.controls { padding: 0.7rem 0.8rem; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.6rem; }
.view-toggle { display: flex; background: var(--panel-2); border: 1px solid var(--border); border-radius: 7px; padding: 0.2rem; gap: 0.2rem; }
.vt-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.5rem;
  border-radius: 5px;
  cursor: pointer;
}
.vt-btn.active { background: var(--accent); color: #fff; }
.control-row { display: flex; gap: 0.5rem; }
#search, #region-filter {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
}
#search { flex: 1; min-width: 0; }
#region-filter { cursor: pointer; }
#search:focus, #region-filter:focus { outline: none; border-color: var(--accent); }

/* ---- scroll lists ---- */
.list-scroll { overflow-y: auto; padding: 0.6rem 0.8rem; flex: 1; }
.right-panel { padding: 1rem 1.1rem; overflow-y: auto; }

/* ---- bar rows ---- */
.bar-row { padding: 0.5rem 0.55rem; border-radius: 8px; margin-bottom: 0.35rem; cursor: pointer; border: 1px solid transparent; transition: background 0.12s, border-color 0.12s; }
.list-scroll .bar-row:hover { background: var(--panel-2); }
.bar-row.selected { background: var(--panel-2); border-color: rgba(224,88,79,0.5); }
.detail-bars .bar-row { cursor: default; }
.detail-bars .bar-row[onclick] { cursor: pointer; }
.detail-bars .bar-row[onclick]:hover { background: var(--panel-2); }
.bar-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; margin-bottom: 0.3rem; }
.bar-name { font-size: 0.86rem; font-weight: 500; }
.bar-val { font-family: 'Space Mono', monospace; font-size: 0.8rem; color: var(--accent-2); white-space: nowrap; }
.bar-track { height: 7px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.detail-bars .bar-track, .list-scroll .bar-row:not(.selected) .bar-track { background: #16161f; }
.bar-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.bar-sub { font-size: 0.72rem; color: var(--muted); margin-top: 0.28rem; }

/* ---- kind tags ---- */
.kind { font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.4px; padding: 0.08rem 0.36rem; border-radius: 4px; margin-left: 0.4rem; vertical-align: middle; }
.kind-state { background: rgba(124,147,232,0.18); color: var(--state); }
.kind-coalition { background: rgba(94,200,192,0.18); color: var(--coalition); }
.kind-nonstate { background: rgba(201,139,224,0.18); color: var(--nonstate); }
.ongoing { color: var(--ongoing); font-weight: 600; }

/* ---- detail panel ---- */
.detail-back {
  display: none;
  align-items: center;
  gap: 0.35rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.4rem 0.7rem;
  border-radius: 7px;
  cursor: pointer;
  margin-bottom: 0.8rem;
}
.detail-back:hover { border-color: var(--accent); }
.detail-empty { color: var(--faint); font-size: 0.9rem; padding: 1.2rem 0.4rem; text-align: center; }
.detail-head { border-bottom: 1px solid var(--border); padding-bottom: 0.7rem; margin-bottom: 0.9rem; }
.detail-head h2 { font-size: 1.25rem; font-weight: 700; }
.detail-meta { display: flex; gap: 0.45rem; color: var(--muted); font-size: 0.82rem; margin-top: 0.3rem; align-items: center; }
.detail-total { font-family: 'Space Mono', monospace; font-size: 1.05rem; color: var(--accent); margin-top: 0.5rem; font-weight: 700; }
.detail-note { background: var(--panel-2); border-left: 3px solid var(--accent-2); padding: 0.55rem 0.7rem; border-radius: 0 6px 6px 0; font-size: 0.8rem; color: var(--muted); margin-top: 0.6rem; line-height: 1.45; }
.detail-source { font-size: 0.72rem; color: var(--faint); margin-top: 0.8rem; font-family: 'Space Mono', monospace; }

/* ---- footer ---- */
.sources { font-size: 0.72rem; color: var(--faint); line-height: 1.5; border-top: 1px solid var(--border); padding-top: 0.6rem; }
.sources strong { color: var(--muted); }
.sources em { color: var(--muted); font-style: italic; }

/* ---- scrollbars ---- */
.list-scroll::-webkit-scrollbar, .right-panel::-webkit-scrollbar { width: 8px; }
.list-scroll::-webkit-scrollbar-thumb, .right-panel::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ---- responsive ---- */
@media (max-width: 760px) {
  .page { gap: 0.6rem; padding: 0.7rem 0.7rem 0.6rem; }
  .kpis { grid-template-columns: repeat(2, 1fr); gap: 0.5rem; }
  .topbar-sub { display: none; }

  /* single-panel master/detail: list fills the area, detail swaps in on select */
  .main { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  .right-panel { display: none; }
  body.detail-open .left-panel { display: none; }
  body.detail-open .right-panel { display: flex; }

  .detail-back { display: inline-flex; }

  /* keep attribution from eating the viewport */
  .sources { max-height: 4.5rem; overflow-y: auto; font-size: 0.66rem; padding-top: 0.5rem; }
}
