/* Coldtrail. Dark-only: this is a monitoring surface, and the map's near-zero
   step is meant to recede into the surface rather than glow on a light page.
   Colour roles follow the data-viz reference palette's dark column. */

:root {
  color-scheme: dark;

  --plane:        #0d0d0d;  /* page */
  --surface:      #1a1a19;  /* cards, chart surface */
  --surface-2:    #232322;  /* insets, zero-value fill */
  --ink:          #ffffff;
  --ink-2:        #c3c2b7;
  --ink-muted:    #898781;
  --grid:         #2c2c2a;
  --axis:         #383835;
  --hairline:     rgba(255, 255, 255, 0.10);

  /* Categorical slots (dark steps). */
  --series-1:     #3987e5;  /* blue  */
  --series-8:     #e66767;  /* red   */

  /* Status. Fixed, never themed; always shipped with an icon + label. */
  --good:         #0ca30c;
  --critical:     #d03b3b;

  --radius:       10px;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--plane);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--series-1); text-decoration: none; }
a:hover { text-decoration: underline; }

[hidden] { display: none !important; }

/* --- Sign-in gate -------------------------------------------------------- */

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate-card {
  width: min(440px, 100%);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 36px 32px 28px;
  text-align: center;
}

.gate-mark { font-size: 30px; color: var(--series-1); line-height: 1; }
.gate-card h1 { margin: 12px 0 28px; font-size: 26px; letter-spacing: -0.02em; }
.gsi-button { display: flex; justify-content: center; min-height: 44px; }
.gate-foot { margin: 22px 0 0; color: var(--ink-muted); font-size: 12.5px; }

.gate-error {
  margin: 16px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: rgba(208, 59, 59, 0.14);
  border: 1px solid rgba(208, 59, 59, 0.4);
  color: #f0b4b4;
  font-size: 13px;
  text-align: left;
}

/* --- Shell --------------------------------------------------------------- */

#app { max-width: none; margin: 0; padding: 0 24px 64px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 20px 0 18px;
  border-bottom: 1px solid var(--hairline);
}

.brand { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.brand-mark { color: var(--series-1); font-size: 18px; }
.brand-name { font-size: 19px; font-weight: 650; letter-spacing: -0.01em; }
.brand-sub { color: var(--ink-muted); font-size: 13px; }

.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 13px; }
.freshness { color: var(--ink-muted); }
.who { color: var(--ink-2); }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--hairline);
  color: var(--ink-2);
  border-radius: 8px;
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  min-height: 34px;
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.05); color: var(--ink); }
.btn-ghost.wide { width: 100%; margin-top: 12px; }

/* --- Filter row ---------------------------------------------------------- */

.filters {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 16px 0;
}

.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; }
.field > span { color: var(--ink-muted); letter-spacing: 0.02em; }
.field.grow { flex: 1 1 220px; }

.field select, .field input {
  background: var(--surface);
  border: 1px solid var(--hairline);
  color: var(--ink);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13.5px;
  min-height: 36px;
}
.field select:focus-visible, .field input:focus-visible,
.btn-ghost:focus-visible, .segmented button:focus-visible, .tabs button:focus-visible {
  outline: 2px solid var(--series-1);
  outline-offset: 2px;
}

/* --- Stat tiles ---------------------------------------------------------- */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.tile .label { color: var(--ink-muted); font-size: 12px; letter-spacing: 0.02em; }
/* Proportional figures on display numbers; tabular-nums is for columns only. */
.tile .value { font-size: 27px; font-weight: 640; letter-spacing: -0.02em; margin: 6px 0 2px; }
.tile .note { color: var(--ink-2); font-size: 12.5px; }

/* --- News alerts --------------------------------------------------------- */

.news-list { list-style: none; margin: 0; padding: 0; }

.news-item { border-bottom: 1px solid var(--grid); }
.news-item:last-child { border-bottom: 0; }

/* Narrower than the old full-width row, so the tag and timestamp stack under
   the headline rather than squeezing it to two words a line. */
.news-item a {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  padding: 11px 4px 11px 0;
  color: inherit;
  text-decoration: none;
  /* Comfortably past the 24px minimum hit target. */
  min-height: 44px;
}
.news-item .news-tag { grid-row: 1; grid-column: 1; }
.news-item .news-when { grid-row: 1; grid-column: 2; }
.news-item .news-body { grid-row: 2; grid-column: 1 / -1; }
.news-item a:hover { background: rgba(255, 255, 255, 0.035); text-decoration: none; }
.news-item a:hover .news-title { color: var(--series-1); }
.news-item a:focus-visible { outline: 2px solid var(--series-1); outline-offset: -2px; }

.news-title { font-size: 13.5px; line-height: 1.45; }
.news-sum { display: block; color: var(--ink-muted); font-size: 12px; margin-top: 3px; }
.news-when { color: var(--ink-muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.news-src { color: var(--ink-2); }

.segmented-wrap { margin-bottom: 10px; }
.segmented-wrap button { flex: 1; border-radius: 0; }
.segmented-wrap button:first-child { border-radius: 8px 0 0 8px; }
.segmented-wrap button:last-child { border-radius: 0 8px 8px 0; }

/* --- Cards --------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 620; letter-spacing: -0.01em; }
.card-sub { margin: 4px 0 0; color: var(--ink-muted); font-size: 12.5px; max-width: 62ch; }

/* Country ranking, the year trend and the news feed sit as one row of three.
   Each body scrolls inside a shared height so the three cards stay aligned. */
/* minmax(0, …) rather than bare fr: the ranking table's min-content width is
   wider than its share, and a plain fr track refuses to shrink below that,
   which starved the other two columns. The table scrolls inside instead. */
.three-up {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 16px;
}
/* Each panel scrolls its own body, so three across stays usable well below the
   width a three-column layout would normally need. */
@media (max-width: 1100px) { .three-up { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
@media (max-width: 760px) { .three-up { grid-template-columns: minmax(0, 1fr); } }

.three-up .card { display: flex; flex-direction: column; }
.panel-body { max-height: 380px; overflow-y: auto; flex: 1; }

/* --- Segmented control & tabs -------------------------------------------- */

.head-controls { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.segmented, .tabs { display: flex; gap: 2px; flex-wrap: wrap; }

a.btn-ghost { display: inline-flex; align-items: center; text-decoration: none; }
a.btn-ghost:hover { text-decoration: none; }

.segmented button, .tabs button {
  background: var(--surface-2);
  border: 1px solid var(--hairline);
  color: var(--ink-2);
  font: inherit;
  font-size: 13px;
  padding: 8px 13px;
  cursor: pointer;
  min-height: 36px;
}
.segmented button:first-child, .tabs button:first-child { border-radius: 8px 0 0 8px; }
.segmented button:last-child, .tabs button:last-child { border-radius: 0 8px 8px 0; }
.segmented button.on, .tabs button.on {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #fff;
}
.segmented button:hover:not(.on), .tabs button:hover:not(.on) { color: var(--ink); }

/* --- Map ----------------------------------------------------------------- */

.map-card { padding-bottom: 14px; }
.map-wrap { position: relative; overflow: hidden; border-radius: 8px; }
#map { width: 100%; display: block; cursor: grab; touch-action: none; }
#map.dragging { cursor: grabbing; }

.zoom-controls {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  z-index: 4;
}
.zoom-level { font-size: 12px; color: var(--ink-2); margin-right: 4px; font-variant-numeric: tabular-nums; }

.zoom-btn {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 1px solid var(--hairline);
  background: rgba(26, 26, 25, 0.9);
  color: var(--ink-2);
  font: inherit;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.zoom-btn.wide { width: auto; padding: 0 10px; font-size: 12px; }
.zoom-btn:hover { background: var(--surface-2); color: var(--ink); }
.zoom-btn:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; }

.map-hint { margin: 10px 0 0; color: var(--ink-muted); font-size: 12px; }

/* The flow arcs animate every frame. Keeping them on their own layer means the
   176-country base map is painted once per data change, not 60 times a second. */
#flows {
  position: absolute;
  inset: 0;
  width: 100%;
  display: block;
  pointer-events: none;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  min-height: 36px;
  padding: 0 4px;
}
.toggle input { accent-color: var(--series-1); width: 15px; height: 15px; cursor: pointer; }

.chart-wrap { position: relative; }
#timeline { width: 100%; display: block; }

.tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: #0a0a0a;
  border: 1px solid var(--hairline);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 12.5px;
  line-height: 1.45;
  min-width: 150px;
  max-width: 280px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.55);
}
.tip .t-name { font-weight: 620; margin-bottom: 4px; }
.tip .t-row { display: flex; justify-content: space-between; gap: 14px; color: var(--ink-2); }
.tip .t-row b { color: var(--ink); font-weight: 560; font-variant-numeric: tabular-nums; }

/* --- Legends ------------------------------------------------------------- */

.legend {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
  color: var(--ink-muted);
  font-size: 12px;
}
.legend .swatches { display: flex; }
.legend .sw { width: 30px; height: 11px; }
.legend .sw:first-child { border-radius: 3px 0 0 3px; }
.legend .sw:last-child { border-radius: 0 3px 3px 0; }

.legend-inline { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 8px; font-size: 12.5px; color: var(--ink-2); }
.legend-inline span { display: inline-flex; align-items: center; gap: 6px; }
.legend-inline i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }

/* --- Tables -------------------------------------------------------------- */

.scroll-x { overflow-x: auto; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td {
  text-align: left;
  padding: 9px 12px 9px 0;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}
table.data th {
  color: var(--ink-muted);
  font-weight: 520;
  font-size: 11.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  background: var(--surface);
}
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tbody tr:hover { background: rgba(255, 255, 255, 0.035); }
table.data td.wrap { white-space: normal; min-width: 200px; }

.muted { color: var(--ink-muted); }
.mono { font-family: var(--mono); font-size: 12px; }

.pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  font-size: 11px;
  color: var(--ink-2);
}
.pill.dprk { border-color: rgba(230, 103, 103, 0.5); color: var(--series-8); }

.dir { display: inline-flex; align-items: center; gap: 5px; font-weight: 560; }
.dir.out { color: var(--critical); }
.dir.in { color: var(--good); }

.bar-cell { position: relative; min-width: 90px; }
.bar-cell .fill {
  position: absolute;
  inset: 3px auto 3px 0;
  background: rgba(57, 135, 229, 0.28);
  border-radius: 2px;
}
.bar-cell span { position: relative; }

/* --- About page ---------------------------------------------------------- */

.about { max-width: 1100px; margin: 0 auto; padding: 0 24px 72px; }

.prose { max-width: 74ch; margin: 32px 0 0; color: var(--ink-2); }
.prose h1 { font-size: 27px; letter-spacing: -0.02em; color: var(--ink); margin: 0 0 14px; }
.prose h2 {
  font-size: 16px;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 38px 0 10px;
  padding-top: 18px;
  border-top: 1px solid var(--hairline);
}
.prose p { margin: 0 0 14px; line-height: 1.65; }
.prose strong { color: var(--ink); font-weight: 600; }
.prose ul { margin: 0 0 14px; padding-left: 20px; line-height: 1.65; }
.prose li { margin-bottom: 9px; }

.prose dl { margin: 0 0 14px; }
.prose dt { color: var(--ink); font-weight: 600; margin-top: 14px; font-size: 14px; }
.prose dd { margin: 4px 0 0; line-height: 1.65; }

.about-table { margin: 0 0 18px; }
.about-table td { white-space: normal; vertical-align: top; padding-right: 18px; line-height: 1.55; }
.about-table td:first-child { color: var(--ink); white-space: nowrap; }
.about-table td:last-child { white-space: nowrap; color: var(--ink-muted); }

.about-foot { margin-top: 40px; padding-top: 18px; border-top: 1px solid var(--hairline); }

/* --- Footer -------------------------------------------------------------- */

.foot {
  margin-top: 26px;
  padding-top: 18px;
  border-top: 1px solid var(--hairline);
  color: var(--ink-muted);
  font-size: 12.5px;
  display: grid;
  gap: 12px;
}
.coverage { display: flex; gap: 18px; flex-wrap: wrap; color: var(--ink-2); }
.caveat { max-width: 90ch; }

/* Hold the previous render at reduced opacity on refetch; never a skeleton
   flash, never a layout jump. */
.stale { opacity: 0.55; transition: opacity 120ms ease; }
