/* Remoboko figures: shared design system.
   Plain editorial charts at Datawrapper's craft level: white ground, one
   workhorse sans, hairline grid, restrained colour, strong title and source
   line. Every figure is its own page (embedded in an iframe or opened
   standalone), so the figure IS the page: no site chrome. */

:root {
  color-scheme: light;

  /* Surfaces and ink */
  --rb-surface: #ffffff;
  --rb-surface-2: #f4f4f2;
  --rb-ink: #1b1b1b;
  --rb-ink-2: #4a4a4a;
  --rb-ink-3: #6f6f6f;       /* 5.3:1 on white: axis labels, sources */
  --rb-grid: #e6e6e3;
  --rb-axis: #bdbdb8;
  --rb-hairline: rgba(27, 27, 27, 0.14);
  --rb-hover: rgba(27, 27, 27, 0.06);
  --rb-link: #0b5fad;
  --rb-selection: #cfe3fb;

  /* Country identity (pinned; shared with viz_common.py) */
  --rb-benin: #3388ff;
  --rb-togo: #2ecc71;
  --rb-west-africa: #e67e22;

  /* Categorical palette, fixed order, validated for adjacent CVD separation */
  --rb-cat-1: #2a78d6;
  --rb-cat-2: #eb6834;
  --rb-cat-3: #1baf7a;
  --rb-cat-4: #eda100;
  --rb-cat-5: #e87ba4;
  --rb-cat-6: #008300;
  --rb-cat-7: #4a3aa7;
  --rb-cat-8: #e34948;
  --rb-other: #9c9c98;
  --rb-seq: #2a78d6;

  /* Type */
  --rb-font: "Source Sans 3", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --rb-fs-title: 1.375rem;   /* 22px */
  --rb-fs-body: 0.9375rem;   /* 15px */
  --rb-fs-label: 0.8125rem;  /* 13px */
  --rb-fs-small: 0.75rem;    /* 12px */

  /* Rhythm */
  --rb-space-1: 4px;
  --rb-space-2: 8px;
  --rb-space-3: 12px;
  --rb-space-4: 16px;
  --rb-space-5: 24px;
  --rb-space-6: 32px;
  --rb-radius: 4px;
  --rb-shadow: 0 1px 2px rgba(27, 27, 27, 0.08), 0 6px 16px rgba(27, 27, 27, 0.10);
  --rb-ease: cubic-bezier(0.16, 1, 0.3, 1);
}

/* --- Base ---------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

/* A background on html keeps body's own background on the body box, so a fullscreened body is not painted over the black backdrop. */
html { height: 100%; background: var(--rb-surface); -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--rb-surface);
  color: var(--rb-ink);
  font-family: var(--rb-font);
  font-size: var(--rb-fs-body);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--rb-selection); color: var(--rb-ink); }

a { color: var(--rb-link); text-decoration: underline; text-underline-offset: 0.15em; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--rb-ink); outline-offset: 2px; border-radius: 2px; }

button { font: inherit; color: inherit; }

svg text { font-family: var(--rb-font); }

/* Scrollbars, where they appear (table view, long lists) */
* { scrollbar-width: thin; scrollbar-color: var(--rb-axis) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-thumb { background: var(--rb-axis); border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* --- Figure page ------------------------------------------------------------ */

.rb-figure {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--rb-space-5) var(--rb-space-6) var(--rb-space-4);
  gap: var(--rb-space-4);
}

.rb-head { display: flex; flex-direction: column; gap: var(--rb-space-1); max-width: 72ch; }

.rb-title {
  margin: 0;
  font-size: var(--rb-fs-title);
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.rb-desc { margin: 0; color: var(--rb-ink-2); font-size: var(--rb-fs-body); text-wrap: pretty; }

/* Controls row: legend and toggles share one line above the plot */
.rb-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--rb-space-2) var(--rb-space-5);
}
.rb-controls > * { min-width: 0; max-width: 100%; }

.rb-plot {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}
.rb-plot > svg { display: block; width: 100%; height: 100%; overflow: visible; }

.rb-foot {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--rb-space-2) var(--rb-space-5);
  padding-top: var(--rb-space-3);
  border-top: 1px solid var(--rb-grid);
  color: var(--rb-ink-3);
  font-size: var(--rb-fs-small);
}
.rb-foot p { margin: 0; }
.rb-notes { color: var(--rb-ink-3); }

.rb-actions { display: flex; flex-wrap: wrap; gap: var(--rb-space-1) var(--rb-space-4); }
.rb-actions button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--rb-ink-3);
  font-size: var(--rb-fs-small);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.15em;
  text-decoration-color: transparent;
  transition: color 0.15s var(--rb-ease), text-decoration-color 0.15s var(--rb-ease);
}
.rb-actions button:hover { color: var(--rb-ink); text-decoration-color: currentColor; }
.rb-actions button[aria-pressed="true"] { color: var(--rb-ink); font-weight: 600; }
.rb-actions button:disabled { opacity: 0.65; cursor: progress; }
.rb-action-status { flex-basis: 100%; font-size: var(--rb-fs-small); }
.rb-action-status:empty { display: none; }
.rb-actions svg { width: 12px; height: 12px; fill: currentColor; }

@media (max-width: 640px) {
  .rb-figure { padding: var(--rb-space-4) var(--rb-space-4) var(--rb-space-3); gap: var(--rb-space-3); }
  :root { --rb-fs-title: 1.1875rem; }
}

/* --- Legend ---------------------------------------------------------------- */

.rb-legend { display: flex; flex-wrap: wrap; gap: var(--rb-space-1) var(--rb-space-4); margin: 0; padding: 0; list-style: none; }
.rb-legend li { display: flex; }
.rb-key {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 2px 4px 2px 0;
  border: 0;
  background: none;
  color: var(--rb-ink-2);
  font-size: var(--rb-fs-label);
  line-height: 1.3;
  cursor: default;
  border-radius: 2px;
}
button.rb-key { cursor: pointer; transition: color 0.15s var(--rb-ease); }
button.rb-key:hover { color: var(--rb-ink); }
.rb-swatch {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: var(--swatch, var(--rb-ink-3));
  transition: opacity 0.15s var(--rb-ease);
}
.rb-swatch--dot { border-radius: 50%; }
.rb-swatch--line { height: 3px; width: 16px; border-radius: 2px; }
.rb-key[aria-pressed="false"] { color: var(--rb-ink-3); text-decoration: line-through; text-decoration-thickness: 1px; }
.rb-key[aria-pressed="false"] .rb-swatch { opacity: 0.25; }
.rb-key .rb-count { color: var(--rb-ink-3); font-variant-numeric: tabular-nums; }

/* --- Segmented control (basemap switch, granularity) ---------------------- */

.rb-seg { display: inline-flex; flex-wrap: wrap; max-width: 100%; padding: 2px; border: 1px solid var(--rb-hairline); border-radius: 6px; background: var(--rb-surface); }
.rb-seg button {
  padding: 3px 10px;
  border: 0;
  border-radius: 4px;
  background: none;
  color: var(--rb-ink-2);
  font-size: var(--rb-fs-label);
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.15s var(--rb-ease), color 0.15s var(--rb-ease);
}
.rb-seg button:hover { color: var(--rb-ink); background: var(--rb-hover); }
.rb-seg button[aria-pressed="true"] { background: var(--rb-ink); color: var(--rb-surface); }
.rb-seg-label { margin-right: var(--rb-space-2); color: var(--rb-ink-3); font-size: var(--rb-fs-label); }

/* --- Tooltip ---------------------------------------------------------------- */

.rb-tooltip {
  position: fixed;
  z-index: 50;
  max-width: 300px;
  padding: 8px 10px;
  border: 1px solid var(--rb-hairline);
  border-radius: var(--rb-radius);
  background: var(--rb-surface);
  color: var(--rb-ink);
  box-shadow: var(--rb-shadow);
  font-size: var(--rb-fs-label);
  line-height: 1.35;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s var(--rb-ease);
}
.rb-tooltip[data-open="true"] { opacity: 1; }
.rb-tooltip-title { font-weight: 600; margin: 0 0 2px; }
.rb-tooltip-sub { color: var(--rb-ink-3); margin: 0 0 4px; font-size: var(--rb-fs-small); }
.rb-tooltip-rows { display: grid; grid-template-columns: auto 1fr auto; column-gap: 8px; row-gap: 2px; align-items: center; margin: 0; }
.rb-tooltip-rows .rb-swatch--line { width: 12px; }
.rb-tooltip-rows .v { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }
.rb-tooltip-rows .k { color: var(--rb-ink-2); }
.rb-tooltip-rows .muted { color: var(--rb-ink-3); }
.rb-tooltip ul { margin: 4px 0 0; padding-left: 1.1em; }
.rb-tooltip li { margin: 0; }

/* --- Table view -------------------------------------------------------------- */

.rb-table-wrap { position: absolute; inset: 0; overflow: auto; }
.rb-table { border-collapse: collapse; width: 100%; font-size: var(--rb-fs-label); font-variant-numeric: tabular-nums; }
.rb-table caption { text-align: left; caption-side: top; padding: 0 0 6px; color: var(--rb-ink-3); font-size: var(--rb-fs-small); }
.rb-table th, .rb-table td { padding: 5px 10px 5px 0; border-bottom: 1px solid var(--rb-grid); text-align: left; vertical-align: top; }
.rb-table th { color: var(--rb-ink-3); font-weight: 600; font-size: var(--rb-fs-small); text-transform: uppercase; letter-spacing: 0.04em; position: sticky; top: 0; background: var(--rb-surface); }
.rb-table th.num, .rb-table td.num { text-align: right; }
.rb-table tbody tr:hover { background: var(--rb-hover); }

/* --- Chart marks (shared SVG classes) ---------------------------------------- */

.rb-axis text { fill: var(--rb-ink-3); font-size: var(--rb-fs-small); font-variant-numeric: tabular-nums; }
.rb-axis line, .rb-axis path { stroke: var(--rb-axis); shape-rendering: crispEdges; }
.rb-grid line { stroke: var(--rb-grid); shape-rendering: crispEdges; }
.rb-cat-label { fill: var(--rb-ink); font-size: var(--rb-fs-label); }
.rb-value { fill: var(--rb-ink); font-size: var(--rb-fs-small); font-weight: 600; font-variant-numeric: tabular-nums; }
.rb-value--muted { fill: var(--rb-ink-3); font-weight: 400; }
.rb-annotation { fill: var(--rb-ink); font-size: var(--rb-fs-small); }
.rb-annotation-line { stroke: var(--rb-ink-3); stroke-width: 1; }
.rb-hit { fill: transparent; }
.rb-hit:hover { fill: var(--rb-hover); }
.rb-mark { transition: opacity 0.15s var(--rb-ease); }
.rb-mark.is-dim { opacity: 0.35; }
.rb-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--rb-ink-3); font-size: var(--rb-fs-label); text-align: center; padding: var(--rb-space-4); }

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

.rb-map-page { position: fixed; inset: 0; display: flex; flex-direction: column; overflow: hidden; }
.rb-map-head { flex: none; display: flex; flex-direction: column; gap: 2px; padding: 12px 16px 10px; border-bottom: 1px solid var(--rb-grid); max-width: none; background: var(--rb-surface); }
.rb-map-head .rb-title { font-size: 1.0625rem; }
.rb-map-head .rb-desc { font-size: var(--rb-fs-label); max-width: 80ch; }
.rb-map-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 16px; font-size: var(--rb-fs-small); }
.rb-map-actions button, .rb-map-link, .rb-map-reset { padding: 4px 0; border: 0; background: none; color: var(--rb-link); font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 0.15em; }
.rb-map-actions button:disabled, .rb-map-link:disabled { color: var(--rb-ink-3); cursor: default; text-decoration: none; }
.rb-map-actions p { margin: 0; color: var(--rb-ink-3); }
.rb-map-reset { background: var(--rb-surface); border-radius: var(--rb-radius); padding: 6px 10px; box-shadow: var(--rb-shadow); }
.rb-map-body { position: relative; flex: 1 1 auto; min-height: 0; }
.rb-map-data { position: absolute; inset: 0; overflow: auto; padding: 12px 16px; background: var(--rb-surface); }
.rb-map-data-visible #map, .rb-map-data-visible .rb-map-body > .rb-card { visibility: hidden; }
.rb-map-data .rb-table { min-width: 560px; }
.rb-map-data .rb-table td { vertical-align: top; }
.rb-map-source { margin: 12px 0 0; color: var(--rb-ink-3); font-size: var(--rb-fs-small); }
.rb-people-list { margin: 0; padding: 0; list-style: none; }
.rb-people-list li + li { margin-top: 4px; }
#map { position: absolute; inset: 0; }
.maplibregl-map { font-family: var(--rb-font); }
.maplibregl-ctrl-group { box-shadow: var(--rb-shadow) !important; border-radius: var(--rb-radius) !important; }
.maplibregl-ctrl-attrib { font-family: var(--rb-font); font-size: 11px; }
.maplibregl-popup-content {
  font-family: var(--rb-font);
  font-size: var(--rb-fs-label);
  line-height: 1.35;
  color: var(--rb-ink);
  padding: 10px 14px 10px 12px;
  border-radius: var(--rb-radius);
  box-shadow: var(--rb-shadow);
  max-height: min(60dvh, 420px);
  overflow: auto;
}
.maplibregl-popup-close-button { font-size: 18px; line-height: 1; padding: 4px 6px; color: var(--rb-ink-3); border-radius: 2px; }
.maplibregl-popup-close-button:hover { color: var(--rb-ink); background: var(--rb-hover); }
.rb-popup-title { margin: 0 14px 2px 0; font-weight: 600; font-size: var(--rb-fs-body); line-height: 1.25; }
.rb-popup-sub { margin: 0; color: var(--rb-ink-3); font-size: var(--rb-fs-small); }
.rb-popup ul { margin: 6px 0 0; padding: 0; list-style: none; }
.rb-popup li { padding: 2px 0; }
.rb-popup img { display: block; width: 56px; height: 56px; object-fit: cover; border-radius: var(--rb-radius); margin-bottom: 8px; }

/* Cards floating over the map */
.rb-card {
  position: absolute;
  z-index: 5;
  padding: 10px 12px;
  border-radius: var(--rb-radius);
  background: var(--rb-surface);
  box-shadow: var(--rb-shadow);
  font-size: var(--rb-fs-label);
  max-width: min(92vw, 360px);
}
.rb-card--legend { bottom: 12px; left: 12px; max-height: calc(100% - 24px); overflow: auto; }
.rb-card-toggle { display: none; padding: 2px 0 6px; border: 0; background: none; color: var(--rb-link); font-size: var(--rb-fs-label); cursor: pointer; text-decoration: underline; text-underline-offset: 0.15em; }
@media (max-width: 640px) {
  .rb-card-toggle { display: inline-block; }
  .rb-card--legend[data-open="false"] { padding: 6px 12px; }
  .rb-card--legend[data-open="false"] .rb-card-toggle { padding-bottom: 2px; }
  .rb-card--legend[data-open="false"] > :not(.rb-card-toggle) { display: none; }
}
.rb-card--legend h2 { margin: 0 0 6px; font-size: var(--rb-fs-small); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--rb-ink-3); }
.rb-card--legend h2 + h2, .rb-card--legend .rb-legend + h2, .rb-card--legend .rb-type-key + h2, .rb-card--legend .rb-size-key + h2 { margin-top: 10px; }
.rb-card--legend .rb-legend { flex-direction: column; gap: 2px; }
.rb-card--tools { top: 12px; right: 12px; display: flex; flex-direction: column; gap: 8px; padding: 0; background: none; box-shadow: none; align-items: flex-end; }
.rb-card--tools .rb-seg { box-shadow: var(--rb-shadow); }
.rb-type-key { display: flex; flex-direction: column; gap: 3px; margin: 0; padding: 0; list-style: none; color: var(--rb-ink-2); font-size: var(--rb-fs-label); }
.rb-type-key li { display: grid; grid-template-columns: 16px 1fr; column-gap: 8px; align-items: center; }
.rb-type-key svg { width: 14px; height: 14px; fill: var(--rb-ink-2); justify-self: center; }
.rb-size-key { display: flex; flex-direction: column; gap: 4px; margin: 0; padding: 0; list-style: none; color: var(--rb-ink-2); font-size: var(--rb-fs-label); }
.rb-size-key li { display: flex; align-items: center; gap: 8px; }
.rb-size-key span:first-child { display: inline-block; flex: none; box-sizing: content-box; border-radius: 50%; background: var(--rb-seq); opacity: 0.8; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--rb-hairline); }

/* Map markers */
.rb-pin { width: 30px; height: 38px; border: 0; padding: 0; background: none; cursor: pointer; filter: drop-shadow(0 1px 1px rgba(0,0,0,0.25)); }
.rb-pin:hover svg, .rb-pin:focus-visible svg { transform: scale(1.12); }
.rb-pin svg { display: block; width: 100%; height: 100%; overflow: visible; transition: transform 0.15s var(--rb-ease); transform-origin: 50% 100%; }
.rb-pin .pin-body { fill: var(--pin, var(--rb-ink-3)); }
.rb-pin .pin-icon { fill: #fff; }
.rb-logo-marker { width: 48px; height: 48px; border: 0; padding: 0; background: none; cursor: pointer; }
.rb-logo-image { display: block; width: 100%; height: 100%; border-radius: 8px; overflow: hidden; background: #fff; box-shadow: var(--rb-shadow); border: 2px solid #fff; transition: transform 0.15s var(--rb-ease); }
.rb-logo-marker:hover .rb-logo-image, .rb-logo-marker:focus-visible .rb-logo-image { transform: scale(1.08); }
.rb-logo-marker img { display: block; width: 100%; height: 100%; object-fit: contain; }

/* Search */
.rb-search { position: relative; width: min(92vw, 300px); }
.rb-search input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  border: 1px solid var(--rb-hairline);
  border-radius: var(--rb-radius);
  background: var(--rb-surface);
  box-shadow: var(--rb-shadow);
  font: inherit;
  font-size: var(--rb-fs-label);
  color: var(--rb-ink);
}
.rb-search input::placeholder { color: var(--rb-ink-3); }
.rb-search > svg { position: absolute; left: 11px; top: 50%; width: 14px; height: 14px; transform: translateY(-50%); fill: var(--rb-ink-3); pointer-events: none; }
.rb-search ul { position: absolute; top: calc(100% + 4px); left: 0; right: 0; max-height: min(260px, 42dvh); overflow: auto; margin: 0; padding: 4px 0; list-style: none; background: var(--rb-surface); border-radius: var(--rb-radius); box-shadow: var(--rb-shadow); }
.rb-search ul[hidden] { display: none; }
.rb-search li { display: flex; justify-content: space-between; gap: 8px; padding: 6px 12px; cursor: pointer; font-size: var(--rb-fs-label); }
.rb-search li:hover, .rb-search li[aria-selected="true"] { background: var(--rb-hover); }
.rb-search li .muted { color: var(--rb-ink-3); font-size: var(--rb-fs-small); white-space: nowrap; }
.rb-search li.rb-search-empty { color: var(--rb-ink-3); cursor: default; }

@media (max-width: 640px) {
  .rb-map-head { padding: 10px 12px 8px; }
  .rb-card--legend { max-height: 42%; max-width: 60vw; }
  .rb-search { width: min(60vw, 260px); }
  .rb-map-actions button, .rb-map-link, .rb-map-reset, .rb-card--legend .rb-key, .rb-uni-list button, .rb-search li { min-height: 42px; }
}

@media (prefers-reduced-motion: reduce) {
  .rb-pin svg, .rb-logo-image { transition: none; }
}

.rb-sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
