/* =============================================================================
   CGD figure house base — the LOOK, extracted from the shipped bilateral-
   remittances figures (e.g. 3-total-remittance-flows.html) so a new figure comes
   out matching the ones already published and signed off.

   Load order in every figure:
     <link rel="stylesheet" href="../shared/cgd-figure.css">      <!-- this: the look -->
     <link rel="stylesheet" href="../shared/cgd-responsive.css">  <!-- mobile behaviour -->
   and at end of <body>:
     <script src="../shared/cgd-embed.js"></script>               <!-- resize + analytics -->

   DENSITY-EXACT to house practice: body 12px, notes 10.8px, axis 10.5px,
   controls ~11.6px, fullscreen 30px. These sit BELOW the older written
   accessibility floors (≥12px / 44px) — a deliberate density decision; see
   SKILL.md §D "House type scale" for the documented trade-off.
   ============================================================================= */
:root {
  --cgd-teal:#0B4C5B; --cgd-light-teal:#006970; --cgd-gold:#FFB52C; --cgd-light-gold:#FEE8BF;
  --cgd-teal-gray:#85A5AD; --cgd-blue:#2D99B5; --cgd-light-blue:#BFDEE0; --cgd-light-gray:#DFE0E2;
  --cgd-dark-gray:#394649; --cgd-teal-black:#1A272A; --cgd-green:#00896C; --cgd-red:#D15553;
  --cgd-white:#FFFFFF; --cgd-offwhite:#F8FAFB; --border:#D9E1E4;
  --font-sans:"Sofia Pro","Inter","Helvetica Neue",Arial,sans-serif;
  --title-size-desktop:24px; --label-size:12px; --body-size:12px; --note-size:10.8px;
  --control-height:34px; --control-radius:9px; --panel-radius:12px;
}

*{box-sizing:border-box}
html,body{margin:0;padding:0;background:#fff;color:var(--cgd-teal-black);font-family:var(--font-sans)}
html{scrollbar-gutter:stable}
body{font-size:var(--body-size)}
img,svg,canvas{max-width:100%}

.viz-wrapper{width:100%;max-width:930px;margin:0 auto;padding:13px;background:#fff;position:relative;color:var(--cgd-teal-black);font-family:var(--font-sans)}

/* Header */
.header-row{display:flex;align-items:flex-start;justify-content:space-between;gap:10px;margin-bottom:8px}
.title-block{min-width:0}
.viz-wrapper h1{margin:0;color:var(--cgd-teal);font-size:var(--title-size-desktop);line-height:1.14;letter-spacing:-.012em;font-weight:700}
.viz-sub{margin:4px 0 0;color:var(--cgd-dark-gray);font-size:12.5px;line-height:1.3;max-width:70ch}

.fullscreen-btn{flex:0 0 auto;width:30px;height:30px;border:1px solid var(--border);background:#fff;color:var(--cgd-teal);border-radius:8px;cursor:pointer;display:inline-flex;align-items:center;justify-content:center}
.fullscreen-btn:hover,.fullscreen-btn:focus{border-color:var(--cgd-teal-gray);outline:none;box-shadow:0 0 0 3px rgba(11,76,91,.10)}
.fullscreen-btn .icon-compress{display:none}
.viz-wrapper:fullscreen .fullscreen-btn .icon-expand{display:none}
.viz-wrapper:fullscreen .fullscreen-btn .icon-compress{display:block}
.viz-wrapper:fullscreen{max-width:none;width:100%;min-height:100vh;min-height:100dvh;overflow-y:auto;padding:22px;background:#fff}
.viz-wrapper:fullscreen h1{font-size:30px}
.viz-wrapper:fullscreen .tooltip,.viz-wrapper:fullscreen .select-menu{position:fixed;z-index:2147483647}

/* Controls (paneled) */
.controls{display:flex;flex-wrap:nowrap;gap:8px;align-items:flex-start;padding:9px;border:1px solid var(--border);border-radius:12px;background:var(--cgd-offwhite);margin-bottom:8px;overflow:visible}
.control-group{min-width:0;position:relative}
.control-label,.control-group label{display:block;color:var(--cgd-teal);font-size:var(--label-size);line-height:1.05;font-weight:600;margin-bottom:4px}

.plain-select{width:100%;height:var(--control-height);border:1px solid var(--border);border-radius:var(--control-radius);background:#fff;color:var(--cgd-teal-black);font:inherit;font-size:11.6px;line-height:1;padding:7px 30px 7px 10px;outline:none;cursor:pointer}
.plain-select:hover,.plain-select:focus{border-color:var(--cgd-teal-gray);box-shadow:0 0 0 3px rgba(11,76,91,.08)}

/* Accessible search-select combobox (input + listbox), house-styled */
.search-select{position:relative;width:100%}
.search-select input{width:100%;height:var(--control-height);border:1px solid var(--border);border-radius:var(--control-radius);background:#fff;color:var(--cgd-teal-black);font:inherit;font-size:11.6px;line-height:1;padding:8px 32px 8px 11px;outline:none}
.search-select input:hover,.search-select input:focus{border-color:var(--cgd-teal-gray);box-shadow:0 0 0 3px rgba(11,76,91,.08)}
.search-select::after{content:"";position:absolute;right:12px;top:50%;width:7px;height:7px;border-right:1.6px solid var(--cgd-teal);border-bottom:1.6px solid var(--cgd-teal);transform:translateY(-65%) rotate(45deg);pointer-events:none}
.select-menu{display:none;position:absolute;z-index:30;top:calc(100% + 4px);left:0;right:0;max-height:238px;overflow-y:auto;border:1px solid var(--border);background:#fff;border-radius:10px;box-shadow:0 12px 26px rgba(26,39,42,.16);padding:4px}
.search-select.open .select-menu{display:block}
.select-option{width:100%;border:0;background:transparent;text-align:left;padding:7px 9px;border-radius:7px;cursor:pointer;color:var(--cgd-teal-black);font:inherit;font-size:11.6px}
.select-option:hover,.select-option:focus,.select-option.active{background:#EEF4F5;outline:none}
.select-empty{padding:8px 9px;color:var(--cgd-dark-gray);font-size:11.2px}

/* Segmented toggle (house), matches cgd-responsive.css hooks */
.segmented{display:inline-flex;border:1px solid var(--border);border-radius:10px;background:#fff;overflow:hidden}
.segmented button{border:0;background:transparent;color:var(--cgd-teal);font:inherit;font-size:13px;font-weight:600;padding:6px 9px;line-height:1.2;cursor:pointer}
.segmented button + button{border-left:1px solid var(--border)}
.segmented button[aria-pressed="true"],.segmented button.active{background:var(--cgd-teal);color:#fff}
.segmented button:focus-visible{outline:2px solid var(--cgd-teal);outline-offset:-2px}

/* Panel */
.panel{border:1px solid var(--border);border-radius:12px;background:#fff;overflow:hidden;margin-bottom:8px}
.panel-header{display:grid;grid-template-columns:auto minmax(0,1fr);gap:8px 12px;padding:8px 10px 6px;border-bottom:1px solid #EDF2F3;align-items:center}
.panel-title{margin:0;color:var(--cgd-teal);font-size:15px;line-height:1.18;font-weight:700;white-space:nowrap}
.chart-area{padding:8px 10px 10px}

/* Legend (interactive filter) */
.legend{display:flex;flex-wrap:wrap;gap:3px 5px;justify-content:flex-end;align-content:center}
.legend-item{display:inline-flex;align-items:center;gap:4px;border:0;background:transparent;color:var(--cgd-dark-gray);font:inherit;font-size:10.2px;white-space:nowrap;padding:1px 3px;border-radius:999px;cursor:pointer}
.legend-item:hover,.legend-item:focus{background:#EEF4F5;outline:none}
.legend-item.active{color:var(--cgd-teal);font-weight:700;background:#F2F7F8}
.legend-item.muted{opacity:.55}
.swatch{width:8.5px;height:8.5px;border-radius:999px;display:inline-block;background:var(--swatch);border:1px solid rgba(26,39,42,.1)}

/* Chart primitives */
svg{display:block;width:100%;height:100%}
.axis text,.small-text{fill:var(--cgd-dark-gray);font-size:10.5px}
.axis line,.axis path{stroke:#D9E1E4;stroke-width:1;vector-effect:non-scaling-stroke}
.grid-line{stroke:#EDF2F3;stroke-width:1;vector-effect:non-scaling-stroke}
.diag-line{stroke:var(--cgd-teal-gray);stroke-width:1.2;stroke-dasharray:4 4;vector-effect:non-scaling-stroke}
.axis-title{fill:var(--cgd-teal);font-size:11.2px;font-weight:700}
.point{cursor:pointer;stroke:#fff;stroke-width:1;opacity:.76}
.point:hover{opacity:.98;stroke:var(--cgd-teal-black);stroke-width:1.5}
.point.selected{stroke:var(--cgd-teal-black);stroke-width:2.2;opacity:1}
.point.muted{fill:var(--cgd-light-gray);opacity:.28}
/* Data-driven fill: set --bar-fill inline (element.style). A plain fill="…"
   presentation attribute would LOSE to this rule in the SVG cascade. */
.bar{fill:var(--bar-fill,var(--cgd-light-teal))}
.bar.muted{fill:var(--cgd-teal-gray);opacity:.55}
.bar-value{fill:var(--cgd-teal-black);font-size:10.5px;font-variant-numeric:tabular-nums}
.row-label{fill:var(--cgd-teal-black);font-size:11px}

/* Tooltip */
.tooltip{position:fixed;z-index:9999;max-width:305px;pointer-events:none;opacity:1;background:#fff;border:1px solid var(--border);border-radius:9px;box-shadow:0 10px 24px rgba(26,39,42,.14);padding:9px 10px;color:var(--cgd-teal-black);font-size:11.5px;line-height:1.38}
.tooltip[hidden]{display:none}
.tooltip strong{color:var(--cgd-teal)}
.tooltip-grid{display:grid;grid-template-columns:auto auto;gap:2px 10px;margin-top:5px}
.tooltip-grid span{color:var(--cgd-dark-gray)}
.tooltip-grid b{color:var(--cgd-teal);font-weight:700;text-align:right}

/* Notes: ONE paragraph opening "Source: …" (references/02 §2.8). Build it with a
   single function and replaceChildren, so it can neither duplicate nor grow. */
.notes{margin-top:9px;border-top:1px solid var(--border);padding-top:8px;color:var(--cgd-dark-gray);font-size:var(--note-size);line-height:1.38}
.notes strong{color:var(--cgd-teal)}

/* --- Review-round fixes (SKILL.md §C rows 16–32) ------------------------- */

/* SVG focus: outlines are drawn round an SVG element's BOUNDING BOX, so a
   clicked flow line or country flashes a rectangle across the chart. Remove the
   outline on every SVG element (not only [tabindex]: non-focusable features
   still get the default ring) and draw keyboard focus on the mark's own shape. */
.viz-wrapper svg:focus,.viz-wrapper svg :focus{outline:none}
.viz-wrapper svg [tabindex]:focus-visible{stroke:var(--cgd-gold);stroke-width:2;paint-order:stroke}

/* Native controls on-brand: no browser-default blue slider or checkbox. */
.viz-wrapper input[type="range"],.viz-wrapper input[type="checkbox"],.viz-wrapper input[type="radio"]{accent-color:var(--cgd-teal)}

/* Checkbox sized to its 12px text, INSIDE its label so the line carries the
   24px target and box and text share one centre line. */
.viz-wrapper .check-line label{display:inline-flex;align-items:center;gap:7px;min-height:24px;cursor:pointer;line-height:1.25}
.viz-wrapper .check-line input[type="checkbox"]{width:15px;height:15px;margin:0;flex:0 0 auto}

/* A legend key that is a button is a tap target: 24px, text stays 10.2px.
   Hidden series show a hollow swatch rather than vanishing. */
.viz-wrapper button.legend-item{min-height:24px}
.viz-wrapper .legend-item.muted .swatch{background:transparent;border-color:var(--cgd-teal-gray)}

/* Quick tip (dom.js): the house replacement for native `title` tooltips. */
.cgd-quicktip{position:fixed;z-index:2147483647;max-width:260px;padding:5px 8px;border-radius:5px;background:var(--cgd-teal-black);color:#fff;font-size:11px;line-height:1.35;pointer-events:none;box-shadow:0 2px 8px rgba(26,39,42,.22)}
.cgd-quicktip[hidden]{display:none}

/* Pager: under the chart, above the notes; never in the control bank. */
.pager-row{display:flex;justify-content:flex-end;align-items:center;gap:8px;margin-top:8px}
.pager-row output{color:var(--cgd-dark-gray);font-size:11.5px;font-variant-numeric:tabular-nums}
@media (max-width:520px){.pager-row{justify-content:space-between}}

[hidden]{display:none !important}
