
/* ==========================================================================
   charts.css — chart styles for the Median Bank Balances page
   ==========================================================================
   The specialized half of this page's styling: the bar charts, the
   percentile spread, the aggregate total panel, and the trend chart.
   Everything generic (layout, type, cards, controls, tables, forms) lives
   in the shared stylesheet, assets/site.css.

   Link order in the page <head> matters — site.css first, then this file:

     <link rel="stylesheet" href="assets/site.css">
     <link rel="stylesheet" href="assets/charts.css">

   All colors come from the design tokens in site.css, so editing a token
   there restyles these charts too.
   ========================================================================== */

/* ---------- Category tabs (what's counted) ---------- */
.cat-tabs-wrap{margin:22px 0 0}
.cat-tabs{display:flex; width:100%; padding:4px; border-radius:12px; margin-top:7px}
.cat-tabs button{
  flex:1 1 0; padding:11px 8px;  border-radius:9px; text-align:center; line-height:1.25;
}
@media (max-width:560px){ .cat-tabs button{ padding:10px 5px} }
.cat-desc{ color:var(--ink-2); margin:9px 2px 0}

/* Negative-value color for this page's diverging bars (below-zero rungs) */
:root{--neg: var(--site-tertiary)}
@media (prefers-color-scheme: dark){ :root{--neg: var(--site-tertiary)} }

/* Legend swatch colors for this page's series */
.swatch.median{background:var(--accent)}
.swatch.mean{background:var(--mean)}
.swatch.marker{background:var(--marker)}
.swatch.negative{background:var(--neg)}

/* ---------- Bar charts ---------- */
.bars{display:flex; flex-direction:column; gap:6px}
.bar-row{display:grid; grid-template-columns:190px 1fr auto; grid-template-areas:"label tracks skew"; gap:6px 14px; padding:9px 0; border-bottom:1px dashed var(--line)}
.bar-row:last-child{border-bottom:0}
@media (max-width:640px){ .bar-row{grid-template-columns:1fr auto; grid-template-areas:"label skew" "tracks tracks"} }
.bar-label{grid-area:label; font-weight:600; font-size:15px; line-height:1.3; align-self:center}
.bar-label small{display:block; font-weight:400; color:var(--ink-3); font-size:12.5px; margin-top:2px}
.tracks{grid-area:tracks; display:flex; flex-direction:column; gap:5px; justify-content:center; min-width:0; overflow-x:clip}
/* Skew tag (breakdown chart, "Both" view only): the average ÷ median
   ratio for the row, sitting at the end of the bars in its own column
   so every tag lines up. On phones it moves up beside the row label
   while the bars take the full width below. */
.skew-cell{grid-area:skew; display:flex; align-items:center; justify-content:flex-end; min-width:52px}
@media (max-width:640px){ .skew-cell{min-width:0} }
.skew-tag{
  font-family:"IBM Plex Sans", system-ui, sans-serif; font-size:13.5px; font-weight:600;
  color:var(--ink); background:var(--mean-soft); border:1px solid var(--line);
  padding:4px 9px; border-radius:999px; white-space:nowrap; line-height:1.3;
}
.skew-tag.muted{background:transparent; border-color:transparent; color:var(--ink-3)}
.skew-legend{font-family:"IBM Plex Sans", system-ui, sans-serif;  color:var(--ink-3)}
.track{position:relative; height:26px; background:var(--surface-2); border-radius:6px}
.fill{
  position:absolute; top:0; bottom:0; border-radius:6px; min-width:3px;
  transition:width .55s cubic-bezier(.22,.8,.3,1), left .55s cubic-bezier(.22,.8,.3,1);
}
.fill.median{background:var(--accent)}
.fill.mean{background:var(--mean)}
/* Below-zero bars: red, stretching left from the zero point. The value label
   sits to the left of the bar when there is room (.label-left), inside the
   bar when it is long (.inside), otherwise just right of the bar's end. */
.fill.negative{background:var(--neg)}
.fill.negative:not(.inside) .val{color:var(--neg)}
.fill.label-left .val{left:auto; right:calc(100% + 9px)}
.fill.negative.inside .val{left:9px; right:auto}
.fill .val{
  position:absolute; left:calc(100% + 9px); top:50%; transform:translateY(-50%);
  font-family:"IBM Plex Sans", system-ui, sans-serif; font-size:14px; font-weight:600; white-space:nowrap; color:var(--ink);
}
.fill.inside .val{left:auto; right:9px; color:#fff}
@media (prefers-color-scheme: dark){ .fill.inside .val{color:#0d1512} }
.marker-line{
  position:absolute; top:-4px; bottom:-4px; width:2px; background:var(--marker); z-index:2;
  transition:left .55s cubic-bezier(.22,.8,.3,1);
}
.marker-line::after{
  content:""; position:absolute; top:-5px; left:50%; transform:translateX(-50%);
  border:5px solid transparent; border-top-color:var(--marker);
}
.axis-note{font-size:12px; color:var(--ink-3); margin:10px 0 0}

/* ---------- Full-spread range filter (dual-ended slider) ---------- */
.dist-filter{
  margin:0 0 16px; padding:14px 16px 12px;
  background:var(--surface-2); border:1px solid var(--line); border-radius:10px;
}
.dist-filter-head{display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:6px}
.dist-reset{
  appearance:none; border:1px solid var(--line); background:var(--surface); color:var(--accent-ink);
  font:inherit; font-size:13px; font-weight:600; padding:5px 11px; border-radius:999px; cursor:pointer;
}
.dist-reset:hover{border-color:var(--accent)}
.dist-reset:focus-visible{outline:2px solid var(--accent); outline-offset:2px}
.dual-range{position:relative; height:34px; margin:2px 2px 0}
.dual-track{
  position:absolute; left:0; right:0; top:50%; transform:translateY(-50%);
  height:6px; border-radius:999px; background:var(--line);
}
.dual-fill{
  position:absolute; top:0; bottom:0; border-radius:999px; background:var(--accent);
}
.dual-range input[type="range"]{
  position:absolute; inset:0; width:100%; margin:0; height:34px;
  -webkit-appearance:none; appearance:none; background:transparent; pointer-events:none;
}
.dual-range input[type="range"]:focus{outline:none}
.dual-range input[type="range"]:focus-visible::-webkit-slider-thumb{box-shadow:0 0 0 4px var(--accent-soft), 0 1px 4px rgba(23,33,28,.28)}
.dual-range input[type="range"]:focus-visible::-moz-range-thumb{box-shadow:0 0 0 4px var(--accent-soft), 0 1px 4px rgba(23,33,28,.28)}
.dual-range input[type="range"]::-webkit-slider-runnable-track{background:transparent; height:34px}
.dual-range input[type="range"]::-webkit-slider-thumb{
  -webkit-appearance:none; appearance:none; pointer-events:auto; cursor:grab;
  width:22px; height:22px; margin-top:6px; border-radius:50%;
  background:var(--surface); border:2.5px solid var(--accent);
  box-shadow:0 1px 4px rgba(23,33,28,.28);
}
.dual-range input[type="range"]::-moz-range-track{background:transparent; height:34px}
.dual-range input[type="range"]::-moz-range-thumb{
  pointer-events:auto; cursor:grab; width:17px; height:17px; border-radius:50%;
  background:var(--surface); border:2.5px solid var(--accent);
  box-shadow:0 1px 4px rgba(23,33,28,.28);
}
.dual-range input[type="range"]:active::-webkit-slider-thumb{cursor:grabbing; background:var(--accent-soft)}
.dual-range input[type="range"]:active::-moz-range-thumb{cursor:grabbing; background:var(--accent-soft)}
.dual-labels{
  display:flex; align-items:baseline; justify-content:space-between; gap:8px 14px; flex-wrap:wrap; margin-top:2px;
}
.dual-end{font-family:"IBM Plex Sans", system-ui, sans-serif; font-size:13px; font-weight:600; color:var(--ink); white-space:nowrap}
.dual-end-r{text-align:right}
.dual-summary{ color:var(--ink-2); text-align:center; flex:1 1 auto}
.dist-filter-note{ color:var(--ink-3); margin:7px 0 0}
@media (max-width:560px){
  .dual-summary{order:3; flex-basis:100%; text-align:left}
}

/* ---------- Aggregate total (full spread) ---------- */
.aggregate{
  margin-top:12px; border:1px solid var(--line); border-radius:10px;
  background:var(--surface-2); padding:16px;
}
.aggregate .k{font-size:12px; font-weight:600; letter-spacing:.07em; text-transform:uppercase; color:var(--ink-3); margin:0 0 4px}
.aggregate .v{font-family:"IBM Plex Sans", system-ui, sans-serif; font-size:clamp(28px,4.5vw,38px); font-weight:600; line-height:1.1; margin:0; color:var(--ink)}
.aggregate .n{ color:var(--ink-2); margin:7px 0 0}
.aggregate .n strong{color:var(--ink)}
.aggregate-math{
  display:grid; grid-template-columns:repeat(3,1fr); gap:10px; margin:14px 0 0;
}
@media (max-width:640px){ .aggregate-math{grid-template-columns:1fr} }
.aggregate-math div{background:var(--surface); border:1px solid var(--line); border-radius:8px; padding:10px 12px}
.aggregate-math .mk{font-size:12px; font-weight:600; letter-spacing:.05em; text-transform:uppercase; color:var(--ink-3); margin:0 0 3px}
.aggregate-math .mv{font-family:"IBM Plex Sans", system-ui, sans-serif; font-size:17px; font-weight:600; margin:0; color:var(--ink)}

/* ---------- Trend chart ---------- */
/* Start-year filter: one slider narrows the chart from the left. */
.trend-filter{
  margin:0 0 14px; padding:14px 16px 12px;
  background:var(--surface-2); border:1px solid var(--line); border-radius:10px;
}
.trend-wrap{overflow:hidden}
svg.trend{width:100%; height:auto; display:block}
.trend-legend{display:flex; flex-wrap:wrap; gap:8px 16px;  color:var(--ink-2); margin-top:8px}
.trend-legend span{display:inline-flex; align-items:center; gap:6px}
.dot{width:9px; height:9px; border-radius:50%; display:inline-block}

@media (prefers-reduced-motion: reduce){
  .fill, .marker-line{transition:none}
}

/* ---------- Collapsible sections (below the breakdown chart) ----------
   Each of these sections starts shrunk to just its header. The header
   title is a .sec-toggle button — chevron plus title, mirroring the
   footer's Source data toggle — and everything else sits in a
   .sec-body wrapper that stays hidden until the header is clicked;
   clicking again shrinks the section back. The compare card's
   verdict box is a grid sibling of its form, so it is hidden
   alongside the body instead of living inside it. */
.sec-toggle{
  appearance:none; background:none; border:0; padding:0; margin:0;
  font:inherit; color:inherit; text-align:left; cursor:pointer;
  display:inline-flex; align-items:center; gap:9px;
}
.sec-toggle .sec-arrow{width:15px; height:15px; flex:none; transition:transform .25s ease}
.sec-toggle[aria-expanded="true"] .sec-arrow{transform:rotate(90deg)}
.sec-toggle:hover{color:var(--accent-ink)}
@media (prefers-color-scheme: dark){ .sec-toggle:hover{color:var(--accent)} }
.sec-toggle:focus-visible{outline:2px solid var(--accent); outline-offset:2px; border-radius:4px}
@media (prefers-reduced-motion: reduce){ .sec-toggle .sec-arrow{transition:none} }
.sec-body[hidden]{display:none}
.verdict[hidden]{display:none}
/* A collapsed card shows only its title — the chart legend that shares
   the header row belongs to the hidden chart, so it hides too. */
.sec:not(.open) .card-head .legend{display:none}
@media (max-width:560px){ }
.settings-btn{
     
    
     
    
}
@media (prefers-color-scheme: dark){ }

/* Age-line color controls (trend chart): a dual-thumb start & end
   slider whose band can be dragged or scrolled to shift the run,
   a saturation slider whose track runs from gray
   to full color at the current start hue (the --sat-h variable, set
   from JS), and a live preview strip showing the six graduated
   colors, youngest to oldest. */
.spec-block{padding:12px 0 10px; border-bottom:1px dashed var(--line)}
.spec-sliders{margin-top:2px}
.spec-row{padding:8px 0 2px}
.hue-slider.rainbow::-webkit-slider-runnable-track{background:linear-gradient(90deg,hsl(0,85%,55%),hsl(60,85%,50%),hsl(120,70%,42%),hsl(180,85%,42%),hsl(240,85%,62%),hsl(300,85%,55%),hsl(360,85%,55%))}
.hue-slider.rainbow::-moz-range-track{background:linear-gradient(90deg,hsl(0,85%,55%),hsl(60,85%,50%),hsl(120,70%,42%),hsl(180,85%,42%),hsl(240,85%,62%),hsl(300,85%,55%),hsl(360,85%,55%))}
.hue-slider.sat::-webkit-slider-runnable-track{background:linear-gradient(90deg,hsl(var(--sat-h,0),0%,55%),hsl(var(--sat-h,0),100%,50%))}
.hue-slider.sat::-moz-range-track{background:linear-gradient(90deg,hsl(var(--sat-h,0),0%,55%),hsl(var(--sat-h,0),100%,50%))}
.spec-preview{height:12px; border-radius:999px; border:1px solid var(--line); margin:10px 0 0}
.spec-note{ color:var(--ink-3); margin:6px 0 0}

/* Start & end share one dual-thumb slider (reusing the .dual-range
   mechanics above): the track is the whole color wheel, the band
   between the two points shows the graduated run itself, and each
   thumb is filled with its own end's color — the --thumb-c custom
   property, set from JS as the colors change. The band doubles as
   the shift control: it takes the grab cursor, and dragging it (or
   scrolling on it) rotates the whole run — JS drives that, with
   touch-action off so a touch drag shifts instead of scrolling. */
.spec-dual{margin-top:6px}
.spec-dual .dual-track{background:linear-gradient(90deg,hsl(0,85%,55%),hsl(60,85%,50%),hsl(120,70%,42%),hsl(180,85%,42%),hsl(240,85%,62%),hsl(300,85%,55%),hsl(360,85%,55%)); touch-action:none; cursor:grab}
.spec-dual .dual-fill{top:-3px; bottom:-3px; box-shadow:0 0 0 1px var(--line); cursor:grab}
.spec-dual.band-dragging .dual-track, .spec-dual.band-dragging .dual-fill{cursor:grabbing}
.spec-dual input[type="range"]::-webkit-slider-thumb{
  background:var(--thumb-c, var(--surface)); border-color:var(--surface);
  box-shadow:0 0 0 1.5px var(--line), 0 1px 4px rgba(23,33,28,.3);
}
.spec-dual input[type="range"]::-moz-range-thumb{
  background:var(--thumb-c, var(--surface)); border-color:var(--surface);
  box-shadow:0 0 0 1.5px var(--line), 0 1px 4px rgba(23,33,28,.3);
}
.spec-dual input[type="range"]:active::-webkit-slider-thumb{background:var(--thumb-c, var(--surface))}
.spec-dual input[type="range"]:active::-moz-range-thumb{background:var(--thumb-c, var(--surface))}
.spec-ends{margin-top:4px}
.spec-end-label{display:inline-flex; align-items:center; gap:7px;  font-weight:600; color:var(--ink); white-space:nowrap}
.spec-end-label .hue-val{padding-top:0}

/* Independent comparison marker; advanced settings remain unavailable. */
:root {--marker:#FFF260}
#settingsOverlay [hidden] {display:none!important}
