/* Where Does the Money Go? — household budgets from the BLS CE survey.
 * Shared Money-app tokens; spending families get their own muted colors,
 * and compare mode uses green (this group) against copper (the other).
 */
:root {
  --paper: #f4f1e8; --card: #fbf9f3; --ink: #1d2420; --ink-2: #4c5650;
  --ink-3: #87908a; --rule: rgba(29,36,32,.18); --rule-soft: rgba(29,36,32,.09);
  --accent: #2f5d46;
  --accent-2: #b0662a;
  --serif: "Fraunces", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --side-w: 330px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-padding-top: calc(var(--appnav-h, 0px) + 20px); }
body {
  background: var(--paper); color: var(--ink);
  font-family: var(--sans); font-size: 15.5px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---- layout ---- */
.layout {
  display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr);
  min-height: calc(100vh - var(--appnav-h, 0px));
}
.side {
  border-right: 1px solid var(--rule); background: var(--paper);
  position: sticky; top: var(--appnav-h, 0px);
  height: calc(100vh - var(--appnav-h, 0px)); overflow-y: auto;
}
.side-inner { padding: 22px 22px 20px; }
.chart-main { padding: 20px 26px 24px 26px; min-width: 0; }

.kicker {
  font-family: var(--mono); font-size: 11px; letter-spacing: .12em;
  text-transform: uppercase; color: var(--ink-3); margin-bottom: 6px;
}
.title {
  font-family: var(--serif); font-weight: 600; font-size: 34px; line-height: 1.05;
  letter-spacing: -.01em; margin-bottom: 10px;
}
.title em, h2 em { font-style: italic; color: var(--accent); }
.lede { color: var(--ink-2); margin-bottom: 14px; }

.side-h {
  font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-3); margin: 0 0 6px;
}
fieldset { border: 0; border-top: 1px solid var(--rule); padding-top: 10px; margin-bottom: 12px; }
legend.side-h { padding-right: 8px; }

.seg { display: flex; border: 1px solid var(--rule); border-radius: 6px; overflow: hidden; }
.seg button {
  flex: 1; font-family: var(--mono); font-size: 12px; padding: 6px 4px; cursor: pointer;
  background: transparent; color: var(--ink-2); border: 0; border-right: 1px solid var(--rule);
}
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed=true] { background: var(--ink); color: var(--paper); }
.seg button:hover:not([aria-pressed=true]) { background: var(--card); color: var(--ink); }

.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0; font-size: 14.5px; }
.field.stack { flex-direction: column; align-items: stretch; gap: 3px; }
.field > span:first-child { color: var(--ink-2); display: flex; align-items: center; gap: 7px; }
select {
  font-family: var(--sans); font-size: 14.5px; color: var(--ink); width: 100%;
  background: var(--card); border: 1px solid var(--rule); border-radius: 4px; padding: 5px 6px;
}
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13.5px; color: var(--ink-2); margin-top: 8px; cursor: pointer; }
.check input { margin-top: 3px; accent-color: var(--accent); }
.check.off { opacity: .45; cursor: default; }

.sw { display: inline-block; width: 12px; height: 12px; border-radius: 2px; background: currentColor; flex: none; }
.sw-a { color: var(--accent); }
.sw-b { color: var(--accent-2); }

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin: 8px 0 4px; }
.chips button {
  font-family: var(--mono); font-size: 11.5px; color: var(--ink-2);
  background: transparent; border: 1px solid var(--rule); border-radius: 999px;
  padding: 3px 9px; cursor: pointer;
}
.chips button[aria-pressed=true] { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chips button:hover { border-color: var(--ink-2); color: var(--ink); }
.hint { font-size: 13px; line-height: 1.45; color: var(--ink-3); margin: 4px 0 6px; }

.own { border-top: 1px solid var(--rule); padding-top: 10px; margin-bottom: 12px; }
.own summary { cursor: pointer; list-style: revert; }
.own-f { align-items: flex-start; }
.own-f > span:first-child { flex-wrap: wrap; font-size: 14px; }
.own-f small { display: block; width: 100%; font-size: 12px; line-height: 1.3; color: var(--ink-3); padding-left: 19px; }
.own-f .sw { width: 12px; height: 12px; }
.money { display: inline-flex; align-items: center; gap: 3px; font-family: var(--mono); font-size: 13px; color: var(--ink-3); flex: none; }
.money b { font-weight: 400; }
.money input {
  width: 78px; font-family: var(--mono); font-size: 14px; color: var(--ink);
  background: var(--card); border: 1px solid var(--rule); border-radius: 4px; padding: 3px 5px; text-align: right;
}

.readout { border-top: 1px solid var(--rule); padding-top: 10px; }
.ro { border-collapse: collapse; width: 100%; font-size: 13.5px; }
.ro th { font-family: var(--mono); font-size: 11px; font-weight: 500; color: var(--ink-2); text-align: right; padding: 0 0 4px 8px; vertical-align: bottom; }
.ro th .sw { width: 9px; height: 9px; margin-right: 4px; }
.ro td { padding: 3px 0; border-bottom: 1px solid var(--rule-soft); color: var(--ink-2); }
.ro td.v { font-family: var(--mono); color: var(--ink); text-align: right; padding-left: 8px; white-space: nowrap; }
.side-foot { margin-top: 14px; font-size: 13.5px; color: var(--ink-3); }

/* ---- chart ---- */
.chart { position: relative; max-width: 1100px; }
.chart-head h2 { font-family: var(--serif); font-weight: 600; font-size: 26px; line-height: 1.15; }
.chart-head .ca { color: var(--accent); }
.chart-head .cb { color: var(--accent-2); }
.chart-head .vs { font-style: italic; font-weight: 400; color: var(--ink-3); font-size: .8em; }
.chart-head p { font-family: var(--mono); font-size: 12.5px; color: var(--ink-2); margin: 2px 0 14px; }

.strips { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.strip-row { display: flex; flex-direction: column; gap: 3px; }
.strip-lab { font-family: var(--mono); font-size: 12px; color: var(--ink-2); display: flex; gap: 6px; align-items: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strip { display: flex; height: 46px; border-radius: 4px; overflow: hidden; background: var(--rule-soft); }
.strip.blank { align-items: center; padding: 0 12px; font-size: 13px; color: var(--ink-3); background: var(--card); border: 1px dashed var(--rule); }
.seg-part {
  flex: 0 0 auto; min-width: 0; display: flex; align-items: center; justify-content: center;
  border-right: 1px solid rgba(251,249,243,.7); overflow: hidden; cursor: default;
}
.seg-part:last-child { border-right: 0; }
.seg-part span { font-family: var(--mono); font-size: 11px; white-space: nowrap; }
.seg-part:hover { filter: brightness(1.08); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--ink-2); margin: 4px 0 16px; }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; }

.rows { border-top: 1px solid var(--rule); }
.row-h, .row {
  display: grid; grid-template-columns: minmax(150px, 230px) minmax(0, 1fr) 118px;
  gap: 12px; align-items: center;
}
.row-h { font-family: var(--mono); font-size: 10.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); padding: 6px 4px; }
.row-h span:last-child { text-align: right; }
.row {
  width: 100%; text-align: left; font: inherit; color: inherit; background: transparent;
  border: 0; border-bottom: 1px solid var(--rule-soft); padding: 5px 4px; cursor: pointer;
}
.row:hover, .row:focus-visible { background: var(--card); }
.row:focus-visible { outline-offset: -2px; }
.row-l { font-size: 14.5px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.row.sub .row-l { padding-left: 18px; font-size: 13.5px; color: var(--ink-2); }
.row.parent .row-l { font-weight: 600; }
.row.ref .row-l { font-style: italic; color: var(--ink-2); }
.bars { position: relative; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.bar-line { display: flex; align-items: center; gap: 6px; min-width: 0; }
.bar { height: 14px; border-radius: 2px; min-width: 2px; flex: none; transition: width .25s ease; }
.rows.two .bar { height: 10px; }
.row.sub .bar { height: 9px; opacity: .85; }
.bar.caution, .seg-part.caution {
  background-image: repeating-linear-gradient(135deg, rgba(251,249,243,.55) 0 3px, transparent 3px 7px) !important;
}
.bar-v { font-family: var(--mono); font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.rows.two .bar-v { font-size: 11px; }
.row-r { text-align: right; font-family: var(--mono); font-size: 13px; display: flex; flex-direction: column; line-height: 1.25; }
.row-r small { font-size: 11px; color: var(--ink-3); }
.row-r .d.up { color: var(--accent-2); }
.row-r .d.down { color: var(--accent); }
.refline { position: absolute; top: -5px; bottom: -5px; width: 0; border-left: 1px dashed var(--ink-3); pointer-events: none; }
.rows.across .row { padding: 8px 4px; }
.rows.across .bar { height: 18px; }
.cap { font-size: 12.5px; color: var(--ink-3); margin-top: 10px; max-width: 760px; }

.tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--card); border: 1px solid var(--rule); border-radius: 6px;
  box-shadow: 0 4px 16px rgba(29,36,32,.12);
  padding: 8px 10px; font-size: 13px; min-width: 220px; max-width: 300px;
}
.tip h4 { font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin-bottom: 4px; }
.tip table { border-collapse: collapse; width: 100%; }
.tip td { padding: 1px 0; color: var(--ink-2); }
.tip td.g { color: var(--ink); font-weight: 600; padding-top: 4px; }
.tip td.g .sw { width: 9px; height: 9px; margin-right: 5px; }
.tip td.v { font-family: var(--mono); text-align: right; padding-left: 12px; color: var(--ink); white-space: nowrap; }
.tip td.warn { font-size: 12px; color: var(--accent-2); }
.tip tr.gap td { border-top: 1px solid var(--rule-soft); padding-top: 4px; }

/* ---- panels below ---- */
.panel { max-width: 980px; margin: 0 auto; padding: 40px 24px 8px; }
.panel h2 { font-family: var(--serif); font-weight: 600; font-size: 28px; line-height: 1.15; margin-bottom: 12px; }
#counts { border-top: 1px solid var(--rule); max-width: none; padding-left: max(24px, calc((100% - 932px) / 2)); padding-right: max(24px, calc((100% - 932px) / 2)); }
.reading p { max-width: 720px; margin-bottom: 12px; }
.facts { max-width: 760px; padding-left: 18px; }
.facts li { margin-bottom: 10px; }
.src-list { padding-left: 18px; max-width: 820px; }
.src-list li { margin-bottom: 10px; }
.sources p { max-width: 820px; margin: 10px 0; }
.changelog { padding-bottom: 60px; }
.changelog ul { list-style: none; }
.changelog li { font-size: 14px; color: var(--ink-2); }
.changelog time { font-family: var(--mono); font-size: 12px; color: var(--ink-3); margin-right: 10px; }

/* ---- narrow ---- */
@media (max-width: 860px) {
  .layout { display: block; }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--rule); }
  .side-inner { padding: 18px 16px; }
  .chart-main { padding: 16px 16px 20px; }
  .title { font-size: 30px; }
  .panel { padding: 30px 16px 6px; }
  #counts { padding-left: 16px; padding-right: 16px; }
}
@media (max-width: 560px) {
  .row-h, .row { grid-template-columns: minmax(0, 1fr) 92px; gap: 2px 10px; }
  .row-h span:nth-child(2) { display: none; }
  .row-l { grid-column: 1; grid-row: 1; }
  .row-r { grid-column: 2; grid-row: 1 / span 2; }
  .bars { grid-column: 1; grid-row: 2; }
  .chart-head h2 { font-size: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}
