/* death - MNCH "Where and why children die" (causes section). Section
   header and the light (#EEF2F6) backdrop are rendered by the master twig.

   Design colors matched to tokens where exact: #4D4D4D --clr-gray-dark,
   #DBDBDB --clr-gray-light, #21568C --clr-blue, #1FA29C --clr-teal-500,
   #F8B323 --clr-yellow-orange. No token for the rest - scoped below. */
.death {
  --death-ink: var(--clr-gray-dark, #4d4d4d);
  --death-border: var(--clr-gray-light, #dbdbdb);
  --death-navy: var(--clr-blue, #21568c);
  --death-teal: var(--clr-teal-500, #1fa29c);
  --death-teal-ink: #1d5c55;
  --death-gold: var(--clr-yellow-orange, #f8b323);
  --death-other: #c4c4c4;
  --death-th-bg: #efefef;
  --death-seg-bg: #e3e3e3;
  --death-name-w: 148px;
  --death-fcv-w: 12px;
  --death-val-w: 56px;
  --death-cause-label-w: 150px;
  --death-cause-val-w: 40px;

  position: relative;
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  align-items: stretch;
  min-width: 0;
  font-family: var(--primary-ff, 'Poppins', sans-serif);
  color: var(--death-ink);
}

.death [hidden] {
  display: none !important;
}

/* ---------- columns ---------- */
.death {
  /* Download bar height above the main card; the side column starts this
     far down (+ the main column gap) so both columns' cards line up. */
  --death-toolbar-h: 33px;
  --death-main-gap: 6px;
}

.death__main {
  flex: 3 1 560px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--death-main-gap);
}

.death__side {
  flex: 2 1 380px;
  /* Matches mortality.css's own .mortality__aside max-width exactly.
     Without a cap here, .death__side kept growing in lockstep with
     .death__main (3:2 ratio) as the page widened, so .death__main/
     .death__viz never got past ~650-680px even on wide desktop -
     short of the 720px container-query threshold the Year/Sort by
     toggle swaps on, so it stayed stuck in dropdown mode on desktop too
     (not just at genuinely narrow widths, the actual bug reported).
     Capping the side column lets .death__main claim the rest of the
     row's width instead, same as mortality__chart-col already does. */
  max-width: 380px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding-top: calc(var(--death-toolbar-h) + var(--death-main-gap));
}

/* ---------- top download (light section backdrop) ---------- */
.death__toolbar-top {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  height: var(--death-toolbar-h);
}

/* Site visualisation.css positions every .share-download-options absolutely
   (align-top: top -40px, right 0), which drops the bar out of the column and
   breaks the side-column alignment on Drupal pages. Keep it in flow here. */
.death__toolbar-top .share-download-options {
  position: static;
  inset: auto;
  padding: 0;
}

.death .options-field {
  position: relative;
}

.death .icon--download {
  cursor: pointer;
}

/* Site download chrome is styled by the site; only the reveal is needed
   for it to function standalone. */
.death .options-field-list {
  display: none;
  /* Site chrome positions this flush against the download icon (top:100%,
     no gap) - adds visible space between them. */
  margin-top: var(--sp2, 8px);
}

.death .options-field:hover .options-field-list,
.death .options-field:focus-within .options-field-list {
  display: block;
}

/* ---------- card ---------- */
.death__card {
  flex: 1 1 auto;
  background: var(--clr-white, #fff);
  border-radius: 0 24px 0 24px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  box-sizing: border-box;
}

.death__card--cause {
  border-radius: 24px 0 24px 0;
}

.death__card-head {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
}

.death__card-titles {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.death__card-title {
  margin: 0;
  font-size: var(--fs-18, 18px);
  line-height: 1.35;
  font-weight: var(--fw-bold, 700);
  color: var(--death-teal);
}

.death__card-sub {
  margin: 0;
  font-size: var(--fs-14, 14px);
  line-height: 1.5;
  color: var(--death-ink);
}

.death__card-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: none;
}

/* Site visualisation.css (loaded on Drupal pages) positions every
   .visualization-actions-block absolutely (top/right of its card). Here the
   Enlarge button sits in the card-head flex row, so keep it in flow. */
.death__card-actions .visualization-actions-block {
  position: static;
  inset: auto;
}

.death__divider {
  width: 1px;
  height: 30px;
  background: var(--death-teal);
}

.death .maximize-popup {
  cursor: pointer;
}

.death__card-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
}

.death__viz {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-width: 0;
  /* Establishes the containment context the @container (max-width:
     720px) rule below needs to fire at all - matches mortality.css's
     own .mortality__chart-col. Without this, that query can never match
     (no ancestor ever provided an inline-size containment context), so
     the Year/Sort by controls were stuck showing the full pill-radio
     layout even at narrow widths where mortality already swaps to the
     compact dropdown. */
  container-type: inline-size;
}

/* ---------- toolbar (Year + Sort toggles side by side) ---------- */
.death__toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 32px;
}

/* ---------- Year / Sort toggles - pill-group style, matching
   mortality.css's own .mortality__seg/-label/-group/-btn Sort by/Show
   controls exactly (rounded grey track, teal filled active pill) - the
   toggle button style already established elsewhere in
   transform2030-page, not this component's own previous underline-tab
   look (that was .mortality__tab's pattern, a different control: the
   page's top-level section tabs, not a Sort-by/Show-style toggle). */
.death__seg {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
}

/* Dropdown counterpart of .death__seg--radio - same data/options, native
   <select> instead of pill buttons. Hidden by default; shown instead of
   the radio pills inside the enlarge popup (matches every other t2030
   card's Sort by/Show control - shared-components/common.css's generic
   `.popup-component [class$="__seg--select"]`/`[class$="__seg--radio"]`
   display swap already covers this by class suffix alone, no popup-
   specific rule needed here) and at narrow container widths below. */
.death__seg--select {
  display: none;
}

.death__select-wrap {
  position: relative;
  display: flex;
  /* Both selects auto-size to their own content (correct, same mechanism
     mortality.css's own .mortality__select-wrap uses - no bug there).
     Mortality's two option labels ("Highest 2024"/"All countries")
     happen to measure close in length, so both pills land near the same
     width already; death's genuinely don't ("2024" vs "Largest neonatal
     share"), so the short one needs a floor or it reads as cramped next
     to its much longer sibling. 140px matches mortality's own narrower
     pill ("All countries", 144px) - doesn't affect the longer select,
     which already exceeds this on its own content. */
  min-width: 140px;
}

.death__select {
  font: inherit;
  font-size: var(--fs-16, 16px);
  font-weight: var(--fw-bold, 700);
  width: 100%;
  min-height: 46px;
  padding: 0 52px 0 24px;
  border: 0;
  border-radius: 999px;
  background: var(--death-teal);
  color: var(--clr-white, #fff);
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}

.death__select option {
  color: var(--death-ink);
  background: var(--clr-white, #fff);
}

.death__select-chevron {
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--clr-white, #fff);
  pointer-events: none;
}

.death__select--sm {
  font-size: var(--fs-14, 14px);
  min-height: 40px;
  padding: 0 42px 0 18px;
}

.death__select--sm + .death__select-chevron {
  right: 14px;
}

@container (max-width: 720px) {
  .death__seg--radio {
    display: none;
  }

  .death__seg--select {
    display: flex;
  }
}

/* Vertical divider between the two Sort by/Year pill-dropdown pairs,
   popup-only (matches mortality__seg-divider's own reasoning exactly). */
.death__seg-divider {
  display: none;
}

.death__popup .death__seg-divider {
  display: block;
  flex: none;
  width: 1px;
  height: 30px;
  background: var(--death-teal);
}

/* death.js moves .death__toolbar (Year/Sort by) into the popup's own
   Download row on enlarge (and back on close), so it sits outside
   .popup-content's scroll area instead of scrolling away with the chart
   rows. Lay the two out as one row: controls on the left, the existing
   Download link on the right. Mirrors mortality.css's own identical
   .mortality__popup rules exactly (same reasoning, same values) - death
   was missing all four of these, which is what made its own popup
   toolbar/select sizing and layout come out wrong. */
.death__popup .popup-download-options {
  display: flex;
  align-items: center;
  gap: 16px;
}

/* justify-content:space-between (instead of this) only positions the
   Download link right when .death__toolbar is also present - on the
   Table tab, .death__toolbar gets hidden (see death.js's setView()),
   leaving it as the only flex child, which space-between would then
   place at flex-start (left) instead. margin-left:auto keeps it pinned
   right regardless. */
.death__popup .popup-download-options > ul {
  margin-left: auto;
}

.death__popup .death__toolbar {
  justify-content: flex-start;
  gap: 12px 20px;
}

.death__popup .death__select--sm {
  font-size: 13px;
  min-height: 34px;
}

.death__seg-label {
  font-size: var(--fs-14, 14px);
  font-weight: var(--fw-bold, 700);
}

.death__seg-group {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--death-seg-bg);
  border-radius: 999px;
}

/* The site's button.css sets `body button:hover, body button:focus` to
   teal bg + white text, which beats this one-class rule. Applying the
   base colours to :hover/:focus too keeps them; the state rules below
   (hover / checked / selected) still win. */
.death__seg-btn,
.death__seg-btn:hover,
.death__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(--death-ink);
  cursor: pointer;
}

.death__seg-btn[aria-checked="false"]:hover {
  background: var(--clr-white, #fff);
}

.death__seg-btn[aria-checked="true"] {
  background: var(--death-teal);
  color: var(--clr-white, #fff);
}

.death__seg-btn:focus-visible,
.death__row:focus-visible,
.death__cause:focus-visible {
  outline: 2px solid var(--death-navy);
  outline-offset: 2px;
}

/* ---------- legend ---------- */
.death__legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  font-size: var(--fs-13, 13px);
  color: var(--death-ink);
}

.death__legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.death__legend-swatch {
  flex: none;
  width: 12px;
  height: 12px;
  border-radius: 3px;
}

.death__legend-swatch--first,
.death__legend-swatch--birth {
  background: var(--death-navy);
}

.death__legend-swatch--after,
.death__legend-swatch--infection {
  background: var(--death-teal);
}

.death__legend-swatch--other {
  background: var(--death-other);
}

.death__legend-swatch--half {
  width: 16px;
  height: 0;
  border-radius: 0;
  border-top: 2px dashed var(--death-gold);
}

.death__legend-swatch--fcv {
  width: 6px;
  height: 6px;
  margin: 0 3px;
  border-radius: 0;
  background: var(--death-teal);
  transform: rotate(45deg);
}

/* ---------- neonatal share chart ---------- */
.death__chart {
  position: relative;
}

.death__refs {
  position: absolute;
  top: 0;
  bottom: 22px;
  left: calc(var(--death-name-w) + var(--death-fcv-w));
  right: var(--death-val-w);
  pointer-events: none;
}

.death__ref-line {
  position: absolute;
  top: -6px;
  bottom: 0;
  border-left: 2px dashed var(--death-gold);
}

.death__row {
  display: flex;
  align-items: center;
  height: 25px;
  border-radius: 4px;
  cursor: default;
}

.death__row:hover,
.death__row:focus {
  background: #edf5f5;
}

.death__row-name {
  flex: 0 0 var(--death-name-w);
  padding-right: 6px;
  box-sizing: border-box;
  text-align: right;
  font-size: var(--fs-12, 12px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.death__row-fcv-cell {
  flex: 0 0 var(--death-fcv-w);
  display: flex;
  justify-content: center;
}

.death__row-fcv {
  width: 6px;
  height: 6px;
  background: var(--death-teal);
  transform: rotate(45deg);
}

.death__row-track {
  position: relative;
  flex: 1 1 auto;
  height: 25px;
}

/* Two segments per row (neonatal + 1-59 months), always summing to
   100% of the track - replaces the old single-colour-threshold bar
   (.death__row-bar / .death__row--first) now that both shares are shown
   directly instead of just picking a colour above/below 51%. */
.death__row-seg {
  position: absolute;
  top: 4px;
  height: 17px;
}

.death__row-seg--neo {
  left: 0;
  border-radius: 4px 0 0 4px;
  background: var(--death-navy);
}

.death__row-seg--old {
  border-radius: 0 4px 4px 0;
  background: var(--death-teal);
}

.death__row-value {
  flex: 0 0 var(--death-val-w);
  text-align: right;
  font-size: var(--fs-12, 12px);
}

.death__ticks {
  display: flex;
  height: 22px;
  margin-top: 4px;
}

.death__ticks-spacer-left {
  flex: 0 0 calc(var(--death-name-w) + var(--death-fcv-w));
}

.death__ticks-spacer-right {
  flex: 0 0 var(--death-val-w);
}

.death__ticks-track {
  position: relative;
  flex: 1 1 auto;
  border-top: 1px solid var(--death-border);
}

.death__tick {
  position: absolute;
  top: 4px;
  transform: translateX(-50%);
  font-size: var(--fs-11, 11px);
  white-space: nowrap;
}

/* ---------- cause bars ---------- */
.death__causes {
  display: flex;
  flex-direction: column;
  /* 4px (was 8px): rows now carry 5px top/bottom padding of their own. */
  gap: 4px;
}

/* Padding so the hover/focus highlight doesn't sit flush against the
   label/value text - top/bottom and left/right (QC 452645). */
.death__cause {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 12px;
  box-sizing: border-box;
  border-radius: 4px;
  cursor: default;
}

.death__cause:hover,
.death__cause:focus {
  background: #edf5f5;
}

.death__cause-label {
  flex: 0 0 var(--death-cause-label-w);
  font-size: var(--fs-13, 13px);
  line-height: 1.3;
  text-align: right;
}

.death__cause-track {
  position: relative;
  flex: 1 1 auto;
  height: 16px;
}

.death__cause-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: 0 4px 4px 0;
  background: var(--death-teal);
}

.death__cause--birth .death__cause-bar {
  background: var(--death-navy);
}

.death__cause--other .death__cause-bar {
  background: var(--death-other);
}

.death__cause-value {
  flex: 0 0 var(--death-cause-val-w);
  font-size: var(--fs-13, 13px);
  font-weight: var(--fw-semibold, 600);
  text-align: right;
}

/* ---------- notes / sources ---------- */
.death__note {
  margin: 0;
  padding-left: 14px;
  border-left: 3px solid var(--death-teal);
  font-size: var(--fs-14, 14px);
  line-height: 1.65;
}

.death__card[data-accent="birth"] .death__note {
  border-left-color: var(--death-navy);
}

.death__note--cms p {
  margin: 0;
}

.death__note--cms p+p {
  margin-top: 0.6em;
}

.death__note--cms strong {
  font-weight: var(--fw-bold, 700);
}

.death__note-lead {
  font-weight: var(--fw-bold, 700);
}

.death__source {
  margin: 0;
  padding-top: 14px;
  border-top: 1px solid var(--death-border);
  font-size: var(--fs-13, 13px);
  line-height: 1.55;
}

/* ---------- tooltip ---------- */
/* Above the site's enlarge popup (.popup-component, z-index 10001 in
   common.css) - at 1000 the tooltip rendered behind the popup when
   hovering the enlarged chart (QC 452646). */
.death__tooltip {
  position: fixed;
  z-index: 10002;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 140px;
  max-width: 260px;
  padding: 8px 12px;
  background: var(--clr-white, #fff);
  border: 1px solid var(--death-border);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(30, 50, 80, 0.18);
  font-size: var(--fs-12, 12px);
  line-height: 1.45;
  color: var(--death-ink);
  pointer-events: none;
}

.death__tooltip-name {
  font-size: var(--fs-13, 13px);
}

.death__tooltip-cur {
  font-weight: var(--fw-semibold, 600);
  color: var(--death-teal-ink);
}

/* ---------- table ---------- */
.death__table-wrap {
  overflow: auto;
  /* border: 1px solid var(--death-border); */
  /* border-radius: 8px; */
}

.death__table {
  width: 100%;
  border-collapse: collapse;
}

.death__table th,
.death__table td {
  text-align: left;
}

.death__table thead th {
  position: sticky;
  top: 0;
}

.death__table .is-num {
  text-align: right;
}

/* ---------- enlarge popup (site chrome; only functional rules here) ---------- */
.death__popup {
  display: none;
}

.death__popup.is-active {
  display: flex;
}

.death__popup .popup-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 35, 0.55);
  z-index: 55;
}

.death__popup .popup-tab-content {
  display: none;
}

.death__popup .popup-tab-content.is-active {
  display: block;
}

.death__popup .custom-modal-close-field {
  cursor: pointer;
}

body.death-lock-scroll {
  overflow: hidden;
}

/* ---------- compact layout (set by js on narrow charts) ---------- */
.death__viz--ns.is-narrow {
  --death-name-w: 104px;
  --death-val-w: 44px;
}

/* Every other tick (leaves 0/50%, hides 25/75%) so labels don't collide. */
.death__viz--ns.is-narrow .death__tick:nth-child(even) {
  display: none;
}

.death__viz--ns.is-narrow .death__row-name {
  font-size: var(--fs-11, 11px);
}

.death__viz--cause.is-narrow {
  --death-cause-label-w: 112px;
  --death-cause-val-w: 34px;
}

.death__viz--cause.is-narrow .death__cause {
  gap: 8px;
  padding: 4px 8px;
}

.death__viz--cause.is-narrow .death__cause-label {
  font-size: var(--fs-12, 12px);
}

/* ---------- responsive ---------- */
/* Columns stack below ~1180px viewport: no offset needed for the side
   column then (it only aligns with the card below the main Download). */
@media (max-width: 1180px) {
  .death__side {
    padding-top: 0;
  }
}

/* The pipe between the popup's Year/Sort by pill dropdowns (shown
   unconditionally by .death__popup .death__seg-divider above) has no
   room to read as a divider once those dropdowns stack/wrap at this
   width - hide it. Same fix/threshold as mortality.css's own
   .mortality__popup .mortality__seg-divider. */
@media (max-width: 767px) {
  .death__popup .death__seg-divider {
    display: none;
  }

  .death__popup .death__toolbar {
    gap: 12px;
    width: 100%;
  }
}

@media (max-width: 600px) {
  .death__card {
    padding: 18px 14px;
  }

  .death__divider {
    display: none;
  }

  .death__seg-btn {
    padding: 0 12px;
  }
}
