/* Map page (map.html): the globe / flat map figure, its legend, timeline, country panel and tables.
   Loaded after site.css. The six --map-* steps are the site's documented blue ramp (200→700), a magnitude ramp;
   dark mode reverses lightness, so the copy never describes colours as "darker". */

:root {
  --map-1: #9ec5f4;
  --map-2: #6da7ec;
  --map-3: #3987e5;
  --map-4: #256abf;
  --map-5: #184f95;
  --map-6: #0d366b;
  --map-ocean: var(--surface-2);
  --map-graticule: var(--grid);
  --map-edge: var(--axis);
  --map-border: rgba(11, 11, 11, 0.5);
  --map-hatch: #a3a199;
  --map-zero: #dddcd5;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --map-1: #184f95;
    --map-2: #256abf;
    --map-3: #3987e5;
    --map-4: #6da7ec;
    --map-5: #9ec5f4;
    --map-6: #cde2fb;
    --map-ocean: var(--surface-2);
    --map-border: rgba(13, 13, 13, 0.6); /* a dark gap: a light line vanishes between the light top steps */
    --map-hatch: #6f6e69;
    --map-zero: #34342f;
  }
}

:root[data-theme="dark"] {
  --map-1: #184f95;
  --map-2: #256abf;
  --map-3: #3987e5;
  --map-4: #6da7ec;
  --map-5: #9ec5f4;
  --map-6: #cde2fb;
  --map-ocean: var(--surface-2);
  --map-border: rgba(13, 13, 13, 0.6); /* a dark gap: a light line vanishes between the light top steps */
  --map-hatch: #6f6e69;
  --map-zero: #34342f;
}

/* ---------- Map ---------- */
.map-headline { font-size: 1.15rem; color: var(--ink); max-width: 62ch; margin: 0 0 18px; line-height: 1.45; }
.map-headline-note { max-width: 84ch; margin: -12px 0 18px; } /* about the headline's width at its smaller size */
.map-controls .controls { padding-top: 12px; }
.map-controls .chips:empty { display: none; }
.map-controls .chart-note { margin: 4px 0 6px; }
#map-callouts .callout { margin: 0 0 12px; }
#map-callouts .callout .btn-link { margin-left: 2px; }
.map-excluded { margin: -4px 0 14px; }
.map-excluded:empty { display: none; }

#fig-map .figure-title { font-family: var(--font-sans); font-size: 1.15rem; font-weight: 650; letter-spacing: 0; }
.figure-annot { font-weight: 600; color: var(--muted); white-space: nowrap; }

/* Toolbar: view switch, Zoom to…, zoom buttons */
.map-toolbar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; padding: 10px 0 10px; }
.map-search { flex: 1 1 200px; max-width: 320px; min-width: 0; }
.map-search input { width: 100%; }
/* A long query with no spaces wraps instead of widening the page (P28). */
.map-search-hint { margin: 4px 0 0; font-size: 0.8rem; color: var(--ink-2); overflow-wrap: anywhere; }
.map-zoom { display: flex; gap: 4px; }
.map-zoom .btn { min-width: 34px; justify-content: center; padding: 5px 10px; }
/* At a zoom limit the button stays focusable (P24): it only looks, and is announced as, unavailable. */
.map-zoom .btn[aria-disabled="true"] { opacity: 0.45; cursor: default; }

/* Stage and the side (or docked) country panel */
.map-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px 18px; align-items: start; }
.map-grid.wide { grid-template-columns: minmax(0, 1fr) 300px; }
.map-main { min-width: 0; }
.stage-wrap { position: relative; min-width: 0; }
.map-stage {
  position: relative; width: 100%; height: 420px; overflow: hidden; border-radius: 6px;
  touch-action: none; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent;
  cursor: grab;
}
.map-stage[data-view="flat"] { touch-action: pan-y; cursor: default; }
.map-stage.dragging { cursor: grabbing; }
.map-stage:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
/* Keyboard users get a reticle: Enter reads the country under it. */
.map-stage[data-view="globe"]:focus-visible::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px; z-index: 2;
  border: 2px solid var(--focus); border-radius: 50%; box-shadow: 0 0 0 2px var(--surface); pointer-events: none;
}
.map-stage > canvas { position: absolute; inset: 0; display: block; }
.stage-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 0.9rem; text-align: center; padding: 16px; }
.map-flash {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 3; pointer-events: none;
  background: var(--ink); color: var(--surface); padding: 8px 12px; border-radius: 8px; font-size: 0.88rem;
  opacity: 0; transition: opacity 0.2s; max-width: calc(100% - 24px); text-align: center;
}
.map-flash.show { opacity: 0.88; }
.map-hint { margin: 6px 0 0; }
.map-hint .btn-link { font-size: inherit; }

/* ---------- Binned legend (binlegend.js) ---------- */
.binlegend { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 6px 18px; margin: 10px 0 4px; font-size: 0.8rem; color: var(--ink-2); }
.bl-title { font-size: 0.82rem; color: var(--ink-2); font-weight: 600; padding-bottom: 1px; flex: 0 1 auto; }
.bl-row { display: flex; align-items: flex-end; gap: 8px 14px; flex: 1 1 340px; min-width: 0; flex-wrap: wrap; }
.bl-extras { display: flex; gap: 4px 12px; flex-wrap: wrap; }
.bl-extra {
  display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; color: var(--ink-2);
  padding: 2px 0; cursor: pointer; font: inherit; font-size: 0.8rem; border-radius: 3px;
}
.bl-sw { width: 18px; height: 12px; border-radius: 2px; box-shadow: inset 0 0 0 1px var(--border-strong); flex: none; }
.bl-empty { margin: 0; color: var(--muted); font-size: 0.8rem; }
.bl-scale { position: relative; flex: 1 1 260px; min-width: 0; max-width: 460px; padding-top: 18px; }
.bl-scale.two-rows { padding-top: 32px; }
.bl-strip { display: grid; gap: 2px; }
.bl-bin { height: 12px; border: 0; padding: 0; cursor: pointer; border-radius: 0; min-width: 0; }
.bl-bin.bl-first { clip-path: polygon(6px 0, 100% 0, 100% 100%, 6px 100%, 0 50%); }
.bl-bin.bl-last { clip-path: polygon(0 0, calc(100% - 6px) 0, 100% 50%, calc(100% - 6px) 100%, 0 100%); }
.bl-bin:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; clip-path: none; }
.bl-ticks { position: absolute; left: 0; right: 0; top: 0; height: 0; }
.bl-tick {
  position: absolute; top: 2px; transform: translateX(-50%); white-space: nowrap; font-size: 0.76rem; color: var(--axis-ink);
  font-variant-numeric: tabular-nums; line-height: 1.2;
}
.bl-tick::after { content: ""; position: absolute; left: 50%; top: 100%; width: 1px; height: 3px; background: var(--axis); }
.bl-scale.two-rows .bl-tick { top: 16px; }
.bl-scale.two-rows .bl-tick.raised { top: 1px; }
.bl-scale.two-rows .bl-tick.raised::after { height: 17px; }
.binlegend.has-pin .bl-bin[aria-pressed="false"], .binlegend.has-pin .bl-extra[aria-pressed="false"] { opacity: 0.35; }
.bl-bin[aria-pressed="true"] { box-shadow: inset 0 -3px 0 var(--ink); }
.bl-extra[aria-pressed="true"] { color: var(--ink); font-weight: 600; }

/* ---------- Timeline ---------- */
.timeline { display: flex; align-items: center; gap: 10px; margin: 12px 0 2px; min-width: 0; }
.tl-play {
  flex: none; width: 32px; height: 32px; border-radius: 50%; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--ink); cursor: pointer; display: grid; place-items: center; padding: 0;
}
.tl-play:hover { background: var(--surface-2); }
.tl-play svg { width: 12px; height: 12px; fill: currentColor; }
.tl-track { position: relative; flex: 1 1 auto; min-width: 0; padding-bottom: 16px; }
.tl-spark { position: absolute; left: 8px; right: 8px; top: -4px; height: 22px; width: calc(100% - 16px); pointer-events: none; overflow: visible; }
.tl-spark path { fill: none; stroke: var(--axis); stroke-width: 1.25; }
.tl-spark .tl-area { fill: var(--surface-2); stroke: none; }
.tl-track input[type="range"] { position: relative; width: 100%; margin: 0; accent-color: var(--ink-2); background: transparent; height: 22px; }
.tl-track input[type="range"]:disabled { opacity: 0.5; }
.tl-ticks { position: absolute; left: 8px; right: 8px; top: 22px; height: 14px; font-size: 0.72rem; color: var(--axis-ink); font-variant-numeric: tabular-nums; }
.tl-ticks span { position: absolute; transform: translateX(-50%); white-space: nowrap; }
.tl-year { flex: none; font-weight: 650; font-variant-numeric: tabular-nums; min-width: 3.2em; text-align: right; }
.tl-status { font-size: 0.8rem; color: var(--muted); margin: 0; }
.tl-status:empty { display: none; }

/* ---------- Country panel ---------- */
.country-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 14px;
  font-size: 0.88rem; min-width: 0;
}
.map-grid.wide .country-panel { max-height: 760px; overflow-y: auto; }
.cp-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.cp-name { font-size: 1.1rem; font-weight: 650; margin: 0; line-height: 1.25; }
.cp-sub { color: var(--muted); font-size: 0.82rem; margin: 2px 0 8px; }
.cp-actions { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.cp-actions .btn { font-size: 0.82rem; padding: 4px 9px; }
.cp-value { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.cp-unit { color: var(--ink-2); font-size: 0.85rem; }
.cp-iv { color: var(--ink-2); font-size: 0.82rem; margin-top: 2px; }
.cp-facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 3px 12px; margin: 10px 0 4px; font-size: 0.84rem; }
.cp-facts dt { color: var(--muted); }
.cp-facts dd { margin: 0; font-variant-numeric: tabular-nums; text-align: right; }
.country-panel h3 { font-size: 0.86rem; font-weight: 650; margin: 14px 0 6px; color: var(--ink); }
.cp-bars { display: grid; gap: 6px; }
.cp-bar-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; align-items: baseline; font-size: 0.82rem; }
/* Names wrap rather than lose their last letters to an ellipsis (RV-09). */
.cp-bar-row a, .cp-bar-row .cp-bar-name { color: var(--ink); overflow-wrap: break-word; }
.cp-bar-val { color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cp-bar-track { grid-column: 1 / -1; height: 6px; background: var(--surface-2); border-radius: 0 2px 2px 0; overflow: hidden; }
.cp-bar-fill { height: 100%; border-radius: 0 2px 2px 0; min-width: 1px; }
.cp-table { width: 100%; border-collapse: collapse; font-size: 0.76rem; table-layout: fixed; }
.cp-table col.c-group { width: 34%; }
.cp-table col.c-year { width: 15%; }
.cp-table td { overflow-wrap: anywhere; }
.cp-table th, .cp-table td { padding: 3px 4px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.cp-table th { color: var(--muted); font-weight: 600; }
.cp-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.cp-spark { display: block; width: 100%; max-width: 260px; height: auto; overflow: visible; }
.cp-spark path.line { fill: none; stroke: var(--ink-2); stroke-width: 1.5; }
.cp-spark .dot { fill: var(--ink); }
.cp-spark text { font-size: 10px; fill: var(--axis-ink); font-variant-numeric: tabular-nums; }
.cp-spark .base { stroke: var(--axis); stroke-width: 1; }
.cp-notes { margin: 0; padding-left: 18px; color: var(--ink-2); font-size: 0.8rem; display: grid; gap: 3px; }
.cp-sel { display: flex; flex-wrap: wrap; gap: 4px; margin: 0 0 10px; }
.cp-sel .chip { font-size: 0.78rem; padding: 2px 8px; color: var(--ink-2); }
.cp-sel .chip[aria-current="true"] { color: var(--ink); border-color: var(--ink); font-weight: 600; }
.cp-empty { color: var(--ink-2); }
.cp-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 5px; }
.cp-list button { all: unset; cursor: pointer; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 8px; width: 100%; font-size: 0.82rem; border-radius: 4px; }
.cp-list button:hover .cp-bar-name { text-decoration: underline; }
.cp-list button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.cp-muted { color: var(--muted); font-size: 0.8rem; }
.cp-left-out { margin: 8px 0 0; }
.proxy-mark { color: var(--muted); cursor: help; }

/* Tooltip extras (the tooltip itself is common.js's) */
.tt-subtitle { color: var(--muted); font-size: 0.8rem; margin: -2px 0 6px; }
.tt-main { display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.tt-main .tt-sw { width: 10px; height: 10px; border-radius: 2px; display: inline-block; flex: none; align-self: center; }
.tt-line { color: var(--ink-2); font-size: 0.82rem; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tt-spark { display: block; margin: 6px 0 2px; overflow: visible; }
.tt-spark path { fill: none; stroke: var(--ink-2); stroke-width: 1.25; }
.tt-spark circle { fill: var(--ink); }
.tt-notes { margin: 6px 0 0; padding: 6px 0 0; border-top: 1px solid var(--border); list-style: none; color: var(--muted); font-size: 0.76rem; display: grid; gap: 2px; }

/* ---------- Table, sources, download tabs ---------- */
.map-table-tools { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: flex-end; margin: 10px 0 8px; }
.map-table-tools input[type="search"] { width: 16rem; max-width: 100%; }
.map-regions { margin: 4px 0 14px; max-width: 520px; }
.map-regions td.bar { width: 40%; }
.map-regions .rbar { height: 8px; background: var(--ink-2); border-radius: 0 2px 2px 0; min-width: 1px; }
.map-regions td { white-space: nowrap; }
/* Phones: the bars give way and the names wrap, so the continent, its value and its share fit (RV-01). */
@media (max-width: 480px) {
  .map-regions .bar { display: none; }
  .map-regions td:first-child, table.data.map-regions th { white-space: normal; }
}
/* position: relative keeps the hidden screen-reader text of off-screen columns inside the box, not widening the page. */
#map-table-main { position: relative; max-height: min(640px, 75vh); overflow: auto; border: 1px solid var(--border); border-radius: 6px; }
/* Every column fits the 864px figure at 940px and wider (RV-01): the headings and "Largest part" wrap, and the
   continent sits under the country's name. */
#map-data-table th, #map-data-table td { padding: 7px 8px; }
#map-data-table th { white-space: normal; vertical-align: bottom; z-index: 2; }
#map-data-table td { white-space: nowrap; }
#map-data-table td.name { white-space: normal; min-width: 7em; }
#map-data-table td.small { white-space: normal; min-width: 7.5em; }
#map-table-main td .muted { font-size: 0.8rem; }
#map-table-main .ctry-region { display: block; }
/* Narrower: the country stays in view, with its value beside it, while the other columns scroll sideways. */
@media (max-width: 939px) {
  #map-data-table th:first-child, #map-data-table td:first-child {
    position: sticky; left: 0; z-index: 1; background: var(--surface); box-shadow: inset -1px 0 0 var(--border); max-width: 9.5em;
  }
  #map-data-table th:first-child { z-index: 3; }
  #map-data-table tbody tr:hover td:first-child { background: var(--surface-2); }
  #map-data-table td.small { white-space: nowrap; } /* it scrolls into view: one line keeps the rows even */
}
#map-table-main td.notes { white-space: nowrap; color: var(--ink-2); }
#map-table-main td.counted { white-space: normal; min-width: 9em; font-size: 0.8rem; color: var(--ink-2); } /* "Counted in Belgium-Luxembourg (until 1999)" (P48) */
#map-table-main .btn-link { font-size: 0.84rem; white-space: nowrap; }
.hc-note { margin: 4px 0 10px; }
.src-groups td { font-size: 0.8rem; }
/* Narrow enough that all eight columns fit the 1086px figure at 1280 (RV-10); phones scroll the table sideways. */
.src-groups td.basis { min-width: 170px; }
.src-groups td.caveat { min-width: 220px; color: var(--ink-2); }
/* Laptops and tablets on their side (about 940px and wider) fit all eight columns too, with room to spare: the
   headings may wrap ("Share / year") and the long columns narrow (P30). */
@media (min-width: 900px) {
  #map-sources table.src-groups th { white-space: normal; }
  .src-groups td.basis { min-width: 150px; }
  .src-groups td.caveat { min-width: 200px; }
}
.dl-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 14px; }
.map-download h3 { margin: 14px 0 6px; font-size: 0.95rem; }

/* ---------- Below the figure ---------- */
.map-caveats h2 { font-size: 1.25rem; margin: 0 0 8px; color: var(--ink); }
.map-caveats ol { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.map-caveats li { color: var(--ink-2); }
.map-below { margin-top: 8px; }
.map-below > h2 { font-size: 1.3rem; margin: 26px 0 8px; }
.map-below details.assumptions { margin: 18px 0 6px; }
.map-below .formula { margin: 8px 0; }

@media (max-width: 550px) {
  .map-toolbar .map-search { order: 3; flex: 1 1 100%; max-width: none; }
  .map-headline { font-size: 1.05rem; }
  .bl-scale { flex-basis: 100%; max-width: none; }
  .bl-row { flex-basis: 100%; }
  .map-table-tools input[type="search"] { width: 100%; }
  .tl-ticks span:nth-child(odd) { display: none; }
}

@media (forced-colors: active) {
  .bl-bin { forced-color-adjust: none; }
  .map-stage canvas { forced-color-adjust: none; }
  /* The map's own marks keep their fills (RC-07): the panel's bars, the key's swatches (the "No data" hatch) and the
     tooltip's swatch; the continent bars in the Table tab are drawn in the text colour. */
  .cp-bar-fill, .bl-sw, .tt-sw { forced-color-adjust: none; }
  .map-regions .rbar { forced-color-adjust: none; background: CanvasText; }
  .cp-bar-track { outline: 1px solid GrayText; outline-offset: -1px; }
}
@media (prefers-reduced-motion: reduce) {
  .map-flash { transition: none; }
}
