/* hf-charts - shared chart chrome for the Transform 2030 Health Financing
   widgets (hf_gov, hf_house, hf_extrfin, hf_spend, hf_mstpart), rendered by
   js/hf-charts.js (window.HFCharts) and js/hf-popup.js (window.HFPopup).
   Loaded once per page alongside each widget's own css/<name>.css, same
   precedent as mnch/shared's download helper being loaded once alongside
   each MNCH widget's own css.

   Colors are literal hex values taken verbatim from the client-provided
   mockup's own effective (last-wins) `:root` palette - its CSS redeclares
   `:root` four times; whichever value a property gets in the LAST block
   (the "GFF Data Portal live palette" layer, near the end of the file) is
   what actually renders, which is what these tokens capture:
     --hf-ink        #2b3440   (mockup --ink)
     --hf-ink-2      #46515f   (mockup --ink-2)
     --hf-muted      #6b7786   (mockup --muted)
     --hf-line       #d9dfe8   (mockup --line)
     --hf-grid       #e6eaf0   (mockup --grid)
     --hf-surface-2  #edf0f4   (mockup --surface-2)
     --hf-brand      #1f4e80   (mockup --brand / --s1)
     --hf-brand-2    #2f6fb3   (mockup .ida-bar.up gradient's 2nd stop)
     --hf-coral      #ef6f6c   (mockup --s2)
     --hf-coral-2    #f39a97   (mockup .ida-bar.down gradient's 2nd stop)
     --hf-gold       #dcab22   (mockup --s3 / --gold)
     --hf-teal       #1fa39a   (mockup --teal)
     --hf-lime       #f5b324   (mockup --lime)
     --hf-lime-ink   #1c2634   (mockup --lime-ink)
     --hf-navy       #14304f   (mockup --navy)
     --hf-tint       #edf0f4   (mockup --tint, "live palette" layer - its own
                                 earlier theme layer sets --tint:#f3f7f6, but
                                 that layer is overridden by the final one)
     --hf-other      #c5ccd6   (mockup's literal "other private" stack color)
     --hf-radius     16px      (mockup --radius)
     --hf-shadow     0 6px 22px -14px rgba(20,48,79,.35)   (mockup --shadow) */
:root {
  --hf-ink: #2b3440;
  --hf-ink-2: #46515f;
  --hf-muted: #6b7786;
  --hf-line: #d9dfe8;
  --hf-grid: #e6eaf0;
  --hf-surface: #ffffff;
  --hf-surface-2: #edf0f4;
  --hf-brand: #1f4e80;
  --hf-brand-2: #2f6fb3;
  --hf-coral: #ef6f6c;
  --hf-coral-2: #f39a97;
  --hf-gold: #dcab22;
  --hf-teal: #1fa39a;
  --hf-lime: #f5b324;
  --hf-lime-ink: #1c2634;
  --hf-navy: #14304f;
  --hf-tint: #edf0f4;
  --hf-other: #c5ccd6;
  --hf-radius: 16px;
  --hf-shadow: 0 6px 22px -14px rgba(20, 48, 79, .35);
}

/* ---------- stat card (shared shape, reused across HF widgets) ----------
   Matched to cross-country-analytics' own .cx-st stat tiles
   (components/cross-country-analytics/explorer/css/explorer.css) -
   inset floating accent bar via ::after (top/bottom:16px, left:16px),
   not a flush border-left; radius alternates 0 16px 0 16px / 16px 0 16px
   0 on even children, same as .cx-st:nth-child(even). Only the
   structural shape lives here - background and the accent bar's color
   are left to each consumer via the --hf-stat-bg/--hf-stat-accent custom
   properties (defaults below), set on the same element alongside its own
   BEM class (e.g. class="hf-reform-progress__insight hf-stat-card"), so
   font-size/text color stay entirely in the consumer's own CSS. */
.hf-stat-card {
  --hf-stat-bg: var(--hf-surface-2);
  --hf-stat-accent: var(--hf-gold);
  position: relative;
  margin: 0;
  background: var(--hf-stat-bg);
  border-radius: 0 16px 0 16px;
  padding: 16px 16px 16px 34px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-sizing: border-box;
}

.hf-stat-card:nth-child(even) {
  border-radius: 16px 0 16px 0;
}

.hf-stat-card::after {
  content: "";
  position: absolute;
  top: 16px;
  bottom: 16px;
  left: 16px;
  border-left: 2.5pt solid var(--hf-stat-accent);
  pointer-events: none;
}

/* Value/label typography inside a .hf-stat-card - same 34px/15px pair
   budget-execution/external-financing/reform-progress all use. Colors
   are custom properties (not hardcoded) so each consumer can still set
   its own, e.g. --hf-stat-value-color: var(--hfrp-teal). */
.hf-stat-card__value {
  --hf-stat-value-color: var(--hf-ink);
  margin: 0;
  font-size: var(--fs-34, 34px);
  line-height: 1.05;
  font-weight: var(--fw-bold, 700);
  color: var(--hf-stat-value-color);
}

.hf-stat-card__text {
  --hf-stat-text-color: var(--hf-ink-2);
  margin: 0;
  font-size: var(--fs-15, 15px);
  line-height: 1.5;
  color: var(--hf-stat-text-color);
}

/* "What the data show" heading + the 3-card grid it introduces - the rest
   of a .hf-stat-card group (above). Color is a custom property like the
   rest of this group; vertical spacing before this block is each
   consumer's own concern (e.g. .hf-reform-progress__insights-title's own
   margin-top), not set here. */
.hf-stat-group-title {
  --hf-stat-group-title-color: var(--hf-ink);
  margin: 0;
  font-size: var(--fs-18, 18px);
  line-height: 1.35;
  font-weight: var(--fw-bold, 700);
  color: var(--hf-stat-group-title-color);
}

.hf-stat-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 767px) {
  .hf-stat-grid {
    grid-template-columns: 1fr;
  }
}

/* ---------- toolbar: dual Sort/Filter/View control ----------
   Segmented buttons (.hf-seg--radio) for wide layouts; a parallel teal
   pill <select> (.hf-seg--select) below the 720px container width AND
   unconditionally inside an Enlarge popup - same dual-control precedent
   as mnch/mortality, srhr/gender, shared-components/trend-panel,
   adolescent/indicators (see shared-components/common.css). */
.hf-tools {
  container-type: inline-size;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  /* No top margin by default - every current consumer's own card already
     carries its own gap between title-row/mount/source (e.g.
     budget-execution/external-financing's __card{gap:18px}), so a
     margin-top here would double up with that. A component whose own
     layout has no such gap (reform-progress's single full-width
     __card{gap:0}) adds its own scoped override instead of changing this
     shared default - see that component's own css. */
  margin: 0 0 8px;
}

.hf-seg {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

.hf-seg-label {
  font-size: var(--fs-14, 14px);
  font-weight: var(--fw-bold, 700);
  color: var(--hf-ink, #2b3440);
  white-space: nowrap;
}

.hf-seg--select {
  display: none;
}

/* Segmented buttons + pill <select> - same convention and literal values
   as the site's existing Sort by/Show controls (mnch/mortality,
   srhr/gender, shared-components/trend-panel, adolescent/indicators),
   verified against the live MNCH key-theme page. */
.hf-seg-group {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: #e3e3e3;
  border-radius: 999px;
}

.hf-seg-btn,
.hf-seg-btn:hover,
.hf-seg-btn:focus {
  white-space: nowrap;
  font: inherit;
  font-size: var(--fs-13, 13px);
  font-weight: var(--fw-semibold, 600);
  min-height: 34px;
  padding: 0 16px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--hf-ink, #2b3440);
  cursor: pointer;
}

.hf-seg-btn[aria-checked="false"]:hover {
  background: #fff;
}

.hf-seg-btn[aria-checked="true"] {
  background: var(--toggler-active-bg, #00413c);
  color: #fff;
  pointer-events: none;
}

.hf-select-wrap {
  position: relative;
  display: flex;
}

.hf-select {
  font: inherit;
  font-size: var(--fs-14, 14px);
  font-weight: var(--fw-bold, 700);
  min-height: 40px;
  padding: 0 42px 0 18px;
  border: 0;
  border-radius: 999px;
  background: var(--select-bg, #00413c);
  color: #fff;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.hf-select:hover {
  background: var(--select-hover-bg, #1fa29c);
}

.hf-select:focus-visible,
.hf-select.is-open {
  outline: none;
  background: var(--clr-teal-dark, #0a544f);
}

.hf-select option {
  color: var(--hf-ink, #2b3440);
  background: #fff;
}

.hf-select-chevron {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: #fff;
  pointer-events: none;
  transition: transform .15s ease;
}

.hf-select.is-open + .hf-select-chevron {
  transform: translateY(-50%) rotate(180deg);
}

/* 480px, not mortality/trend-panel's 720px: those establish the
   container query on a wider ancestor than their own controls row, so
   720px rarely triggers there at their own typical card widths. .hf-tools
   (above) is itself the queried container, and these 4 widgets' own
   cards run ~550-650px (the row/col split's main column) - at 720px the
   select variant would show unconditionally, even though 2-3 short
   Sort/View options fit the radio pills comfortably at that width. */
@container (max-width: 480px) {
  .hf-seg--radio {
    display: none;
  }
  .hf-seg--select {
    display: flex;
  }
}

/* Enlarge popup: always the select variant, regardless of its own
   (wide) container width - same rule as shared-components/common.css
   applies to every other component's own __seg--radio/__seg--select. */
.popup-component .hf-seg--radio {
  display: none;
}

.popup-component .hf-seg--select {
  display: flex;
}

/* js/hf-popup.js's open() moves .hf-tools (a block-level child everywhere
   else) into .popup-download-options, a flex ROW - as a flex item with no
   explicit width, its own `container-type: inline-size` (above) has
   nothing but its content to size from, which is exactly what inline-size
   containment blocks it from using: the item collapses to 0 width while
   its children still render past that boundary (Sort by's label sitting
   on its own line, Download appearing to float instead of sharing the
   row). The @container query above is moot in the popup anyway - the
   unconditional .hf-seg--select rule already forces the select variant
   regardless of width - so containment is simply switched off here. */
.popup-component .hf-tools {
  container-type: normal;
  margin-top: 0;
  margin-bottom: 0;
}

/* Enlarge popup's own Download row: js/hf-popup.js moves the chart's
   Sort/Filter/View tools in here on open (and back out on close) so they
   sit outside .popup-content's own scroll area - same precedent and same
   layout as mnch/mortality's .popup-download-options (controls on the
   left, Download pinned right via margin-left:auto, which still works
   when the tools are hidden on the Table tab and it's the only child). */
.popup-component .popup-download-options {
  display: flex;
  align-items: center;
  gap: 16px;
}

.popup-component .popup-download-options > ul {
  margin-left: auto;
}

@media (max-width: 767px) {
  .popup-component .hf-seg--select {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  .popup-component .hf-select-wrap,
  .popup-component .hf-select {
    width: 100%;
  }
}

.hf-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  font-size: 13px;
  color: var(--hf-ink-2);
  margin: 6px 0 4px;
}

.hf-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: -1px;
  background: var(--hf-muted);
}

.hf-legend i.hf-swatch--sq {
  border-radius: 2px;
}

.hf-legend i.hf-swatch--ring {
  background: transparent !important;
  border: 2px solid var(--hf-brand);
}

.hf-legend i.hf-swatch--up {
  background: var(--hf-brand);
}

.hf-legend i.hf-swatch--down {
  background: var(--hf-coral);
}

.hf-legend i.hf-swatch--line {
  width: 16px;
  height: 0;
  border-top: 2px dashed var(--hf-ink-2);
  border-radius: 0;
  vertical-align: 3px;
  background: none;
}

.hf-viz {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.hf-chart {
  position: relative;
  width: 100%;
  min-width: 0;
}

.hf-chart svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}

/* Below 767, per-row label/value columns (hf-charts.js's dumbbell/bars/
   stack all draw to box.clientWidth, dropping to a "narrow" column layout
   under 560px) still run out of room on a long country list - same fix/
   shape as t2030-trend-panel's own .chart/.chart-inner pair: float the
   chart at a readable minimum width and let its scrollable parent pan to
   it, instead of squeezing labels down further.

   The floor has to go on .hf-chart itself (not its svg) because
   box.clientWidth - what ../shared/js/hf-charts.js's register() measures
   and what dumbbell/bars/stack lay the chart out against - is .hf-chart's
   OWN layout width. Floor the svg instead (as a first pass here did) and
   .hf-chart stays at the real narrow width, so the chart still draws at
   e.g. 300px-worth of coordinates; the svg then gets stretched from that
   to 600px by `width:100%` + `min-width`, scaling every font-size/stroke
   up with it (reported, screenshot) instead of just revealing more chart.
   Floor .hf-chart so register() measures 600 and the chart draws at that
   width natively - no post-hoc stretch, nothing to scale. .hf-viz (its
   parent, flex-direction:column) becomes the actual scroll viewport,
   which also carries the legend row above the chart along for the
   horizontal scroll (hf-charts.js nests both in the same .hf-viz, unlike
   trend-panel/mortality's controls living outside their own scroll
   wrapper) - accepted trade-off, the chart itself no longer distorts. */
@media (max-width: 767px) {
  .hf-viz {
    max-height: 350px;
    overflow-x: auto;
    overflow-y: auto;
  }
  .hf-chart {
    min-width: 600px;
  }

  /* HFPopup moves vizEl (.hf-viz itself - see hf-charts.js's dumbbell/
     bars/stack, each setting `c.vizEl = viz`) into the Enlarge popup on
     open; the popup already lays its own chart out full-size there, so
     undo the scroll/floor above once .hf-viz is inside it - same "scoped
     so it doesn't follow into the popup" precedent as every other rule
     below keyed off .popup-component. */
  .popup-component .hf-viz {
    max-height: none;
    overflow: visible;
  }
  .popup-component .hf-chart {
    min-width: 0;
  }
}

.hf-chart text {
  fill: var(--hf-ink-2);
  font-family: var(--primary-ff, 'Poppins', sans-serif);
  font-size: 12px;
}

.hf-gridline {
  stroke: var(--hf-grid);
  stroke-width: 1;
}

.hf-lbl {
  fill: var(--hf-ink);
  font-size: 12.5px;
}

.hf-val {
  fill: var(--hf-ink-2);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

.hf-colhead {
  fill: var(--hf-ink);
  font-weight: 600;
  text-anchor: middle;
}

.hf-refline {
  stroke: var(--hf-ink-2);
  stroke-dasharray: 4 3;
  stroke-width: 1.2;
}

.hf-reftxt {
  fill: var(--hf-ink-2);
  font-size: 11px;
  font-weight: 600;
}

.hf-band {
  fill: var(--hf-surface-2);
}

.hf-bandtxt {
  fill: var(--hf-muted);
  font-size: 10.5px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

.hf-row:hover .hf-hit,
.hf-row.is-focus .hf-hit {
  fill: rgba(31, 78, 128, .08);
}

.hf-row.is-focus .hf-lbl {
  font-weight: 700;
}

.hf-dumbbell-track {
  stroke: var(--hf-brand);
  stroke-width: 2.5;
  stroke-linecap: round;
  opacity: .45;
}

.hf-dumbbell-start {
  fill: var(--hf-surface);
  stroke: var(--hf-brand);
  stroke-width: 2;
}

.hf-dumbbell-end {
  stroke: var(--hf-surface);
  stroke-width: 2;
}

.hf-dumbbell-end.is-better {
  fill: var(--hf-brand);
}

.hf-dumbbell-end.is-worse {
  fill: var(--hf-coral);
}

.hf-fcv-dot {
  fill: var(--hf-coral);
}

.hf-tag {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--hf-surface-2);
  color: var(--hf-ink-2);
  vertical-align: 1px;
}

.hf-tag--fcs {
  background: rgba(239, 111, 108, .2);
  color: var(--hf-ink);
}

/* ---------- tooltip (shared singleton element, appended once to <body>) ----------
   position:fixed on a <body>-level singleton means it competes against the
   Enlarge popup's own fixed-position stacking, instead of a local
   chart-scoped context (mortality/trend-panel's own __tooltip is
   position:absolute inside the chart itself, so it travels into the
   popup along with everything else and never needs to out-rank it at
   all). The site's real shared popup chrome - .popup-component, which
   every HF Enlarge popup uses (inner-pages/common/css/common.css on the
   live theme) - is z-index:10001, not the 55 a stale version of this
   comment assumed (that 55 belongs to mortality/trend-panel's own
   unrelated bespoke popup overlay, a different component entirely).
   1000 < 10001, so the tooltip rendered behind every open HF Enlarge
   popup and never showed on hover there (reported). */
.hf-tip {
  position: fixed;
  z-index: 10050;
  pointer-events: none;
  background: var(--hf-surface);
  color: var(--hf-ink);
  border: 1px solid var(--hf-line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .14);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
  line-height: 1.4;
  max-width: 260px;
  opacity: 0;
  transition: opacity .12s;
}

.hf-tip.is-on {
  opacity: 1;
}

.hf-tip b {
  font-family: var(--primary-ff, 'Poppins', sans-serif);
  font-size: 14px;
}

.hf-tip__row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-variant-numeric: tabular-nums;
  color: var(--hf-ink-2);
}

.hf-tip__row span:last-child {
  color: var(--hf-ink);
  font-weight: 600;
}

/* Title injected into the popup's chart-wrap/table-wrap just for the JPG
   download (js/hf-popup.js's beforeImage/afterImage) - the visible popup
   title lives in .popup-head, outside the area MnchDownload captures. */
.hf-download-title {
  margin: 0 0 12px;
  font-family: var(--primary-ff, 'Poppins', sans-serif);
  font-size: 18px;
  font-weight: 700;
  color: var(--hf-ink, #2b3440);
}

.hf-tip__unit,
.hf-tip__note {
  margin-top: 4px;
  color: var(--hf-muted);
  font-size: 12px;
}

/* The Enlarge popup's data table (js/hf-popup.js's renderTable) uses the
   shared `tbl-theme-default tbl-vr-brdr-none` utility classes (table_layout
   library, added to the popup's table-wrap in the HFPopup constructor)
   instead of its own CSS - same default look as mortality's own popup
   table, no bespoke table styling needed here. Text alignment is the one
   exception: `.tbl-theme-default th/td` (sub-modules/tables/table.css)
   doesn't set it, and every existing component's OWN `.<name>__table th,
   td{text-align:left}` + `.is-num{text-align:right}` (e.g. mortality.css)
   is what supplies it there - renderTable() rebuilds a fresh table each
   time with no such component class, so this one shared rule covers it
   for every HF widget's popup instead of each repeating it. */
.popup-component .tbl-theme-default th {
  text-align: left;
}

.popup-component .tbl-theme-default .is-num {
  text-align: right;
}

/* ---------- footnote refs + numbered footnote list (shared) ----------
   Generic across HF widgets with in-text footnote markers (first consumer:
   ida's stat-tile text, components/transform2030-page/health-financing/ida).
   A ref is a real <a href="#some-id"> inside <sup class="hf-footnote-sup">
   (not bare text), so it's keyboard-focusable and actually jumps to the
   matching <li id="some-id"> in the .hf-footnote-list below - a native
   `title` attribute can do neither, and its tooltip is slow to appear and
   unstyled, so the tooltip text instead lives in `data-tooltip` and is
   drawn by this CSS via ::before/::after (no JS positioning needed, unlike
   the singleton .hf-tip above, since the trigger itself is the positioning
   context). The footnote list numbers itself with a CSS counter rather
   than native <ol> numbering, so "1." / "2." survives even if something
   upstream (a page-wide `list-style` reset, a CMS body-field default)
   turns the numbers into plain bullets - counter-increment doesn't care
   what list-style is set to. */
.hf-footnote-sup {
  font-size: .72em;
  font-weight: 700;
  margin-left: 1px;
}

.hf-footnote-ref {
  position: relative;
  font-size: 14px;
  font-weight: 600;
  color: var(--hf-brand-2, #2f6fb3) !important;
  text-decoration: none;
  cursor: help;
}

.hf-footnote-ref:hover,
.hf-footnote-ref:focus-visible {
  text-decoration: underline;
}

.hf-footnote-ref::after {
  content: attr(data-tooltip);
  position: absolute;
  z-index: 20;
  bottom: calc(100% + 9px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  width: max-content;
  max-width: 260px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--hf-surface, #ffffff);
  color: var(--clr-gray-dark, #4d4d4d);
  border: 1px solid var(--hf-line, #d9dfe8);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.4;
  text-align: left;
  white-space: normal;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .18);
  opacity: 0;
  visibility: hidden;
  transition: opacity .12s ease, transform .12s ease;
}

.hf-footnote-ref::before {
  content: "";
  position: absolute;
  z-index: 20;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  border: 5px solid transparent;
  border-top-color: var(--hf-surface, #ffffff);
  opacity: 0;
  visibility: hidden;
  transition: opacity .12s ease;
}

.hf-footnote-ref:hover::after,
.hf-footnote-ref:focus-visible::after,
.hf-footnote-ref:hover::before,
.hf-footnote-ref:focus-visible::before {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.hf-footnote-list {
  list-style: none !important;
  margin: 0;
  padding: 0;
  counter-reset: hf-footnote;
}

.hf-footnote-list > li {
  position: relative;
  counter-increment: hf-footnote;
  padding-left: 20px;
}

.hf-footnote-list > li::before {
  content: counter(hf-footnote) ".";
  position: absolute;
  left: 0;
  top: 0;
  font-weight: 600;
}

.hf-footnote-list > li + li {
  margin-top: 4px;
}

@media (max-width: 560px) {
  .hf-tools {
    gap: 8px 12px;
  }
}
