:root {
  color-scheme: light;
  --surface-1:      #ffffff;
  --page-plane:     #eef1ee;
  --text-primary:   #182420;
  --text-secondary: #47524c;
  --text-muted:     #7c877f;
  --gridline:       #dde2db;
  --baseline:       #b7c3bc;
  --border:         rgba(24,36,32,0.14);

  --series-1: #2f5a72; /* ink blue */
  --series-2: #a1651f; /* ochre */
  --series-3: #3d7a6a; /* teal */
  --series-4: #b98a2e; /* gold */
  --series-5: #9c4a68; /* wine */
  --series-6: #3f6b3a; /* moss */
  --series-7: #5b4a8a; /* violet */
  --series-8: #a3402d; /* brick */

  --seq-250: #9dbdcb;
  --seq-350: #6f97a8;
  --seq-450: #2f5a72;
  --seq-550: #234456;
  --seq-650: #182f3a;

  --ma-accent:      #6b4a7d;
  --ma-accent-soft: #ece3ee;
  --wa-accent:      #2f6b78;
  --wa-accent-soft: #e2ebe9;
  --co-accent:      #96591c;
  --co-accent-soft: #f0e6d8;
  --ca-accent:      #8a3350;
  --ca-accent-soft: #f0e2e7;
  --states-accent:      #4a4570;
  --states-accent-soft: #e6e5ee;
  --fed-accent-soft: #dfe6e6;
  --compare-accent:      #3f6b3a;
  --compare-accent-soft: #e5ebe1;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --surface-1:      #1c211d;
    --page-plane:     #141815;
    --text-primary:   #f2f1ea;
    --text-secondary: #c7cec8;
    --text-muted:     #8b968f;
    --gridline:       #2b322c;
    --baseline:       #3c453e;
    --border:         rgba(242,241,234,0.12);

    --series-1: #6f9db3;
    --series-2: #c98a4a;
    --series-3: #5fa08d;
    --series-4: #d4a94e;
    --series-5: #c1718c;
    --series-6: #6f9b64;
    --series-7: #8779b8;
    --series-8: #c96f5c;

    --ma-accent:      #a889ba;
    --ma-accent-soft: #2c2430;
    --wa-accent:      #6fa8b3;
    --wa-accent-soft: #1c2b2c;
    --co-accent:      #c98a4a;
    --co-accent-soft: #332a1c;
    --ca-accent:      #c17e97;
    --ca-accent-soft: #2f2126;
    --states-accent:      #8d87b3;
    --states-accent-soft: #26243a;
    --fed-accent-soft: #1c262b;
    --compare-accent:      #6f9b64;
    --compare-accent-soft: #212b1e;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1:      #1c211d;
  --page-plane:     #141815;
  --text-primary:   #f2f1ea;
  --text-secondary: #c7cec8;
  --text-muted:     #8b968f;
  --gridline:       #2b322c;
  --baseline:       #3c453e;
  --border:         rgba(242,241,234,0.12);

  --series-1: #6f9db3;
  --series-2: #c98a4a;
  --series-3: #5fa08d;
  --series-4: #d4a94e;
  --series-5: #c1718c;
  --series-6: #6f9b64;
  --series-7: #8779b8;
  --series-8: #c96f5c;

  --ma-accent:      #a889ba;
  --ma-accent-soft: #2c2430;
  --wa-accent:      #6fa8b3;
  --wa-accent-soft: #1c2b2c;
  --co-accent:      #c98a4a;
  --co-accent-soft: #332a1c;
  --ca-accent:      #c17e97;
  --ca-accent-soft: #2f2126;
  --states-accent:      #8d87b3;
  --states-accent-soft: #26243a;
  --fed-accent-soft: #1c262b;
  --compare-accent:      #6f9b64;
  --compare-accent-soft: #212b1e;
}

* { box-sizing: border-box; }

body {
  background: var(--page-plane);
  color: var(--text-primary);
  font-family: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px 64px; }

header.site {
  padding: 40px 20px 28px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}
header.site h1 { font-family: "Source Serif 4", Georgia, serif; font-weight: 600; font-size: 1.8rem; margin: 0 0 8px; }
header.site p.subtitle { color: var(--text-secondary); max-width: 74ch; margin: 0 0 4px; }
header.site .meta-line { color: var(--text-muted); font-size: 0.85rem; margin-top: 12px; }

nav.toc {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 20px; padding: 6px; font-size: 0.86rem;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 2px;
}
nav.toc a {
  color: var(--text-secondary); text-decoration: none; font-weight: 500;
  padding: 7px 14px; border-radius: 2px; border: 1px solid transparent;
  transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}
nav.toc a:hover { color: var(--text-primary); background: var(--page-plane); border-color: var(--border); }
nav.toc a:active { background: var(--series-1); color: #fff; }

section.block { margin-bottom: 56px; }
section.block > h2 { font-family: "Source Serif 4", Georgia, serif; font-weight: 600; font-size: 1.35rem; margin: 0 0 6px; }
section.block > p.lede { color: var(--text-secondary); max-width: 80ch; margin: 0 0 20px; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 20px; }
.card-grid.single { grid-template-columns: 1fr; }

.card {
  /* A grid item's automatic minimum width is its content's intrinsic
     size unless overridden -- without this, a wide table/matrix inside
     an overflow-x:auto wrapper expands the grid track (and the page)
     instead of scrolling internally. */
  min-width: 0;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 18px 20px 14px;
}
.card h3 { font-family: "Source Serif 4", Georgia, serif; font-weight: 600; margin: 0 0 2px; font-size: 1.05rem; }
.card p.note { color: var(--text-muted); font-size: 0.82rem; margin: 0 0 12px; }
.card .chart-holder { position: relative; height: 300px; }
.card .chart-holder.tall { height: 380px; }

.card-toolbar { display: flex; justify-content: flex-end; margin: -4px 0 6px; }
.btn-table-toggle {
  font-size: 0.78rem; color: var(--text-secondary);
  background: transparent; border: 1px solid var(--border); border-radius: 2px;
  padding: 3px 9px; cursor: pointer;
}
.btn-table-toggle:hover { color: var(--text-primary); border-color: var(--baseline); }

table.data-table {
  width: 100%; border-collapse: collapse; font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
table.data-table th, table.data-table td {
  text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--gridline);
}
table.data-table th {
  color: var(--text-secondary); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.74rem;
  border-bottom: 2px solid var(--text-primary);
}
table.data-table td.num, table.data-table th.num { text-align: right; }
table.data-table td.num { font-family: "IBM Plex Mono", ui-monospace, monospace; }

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 28px; }
.stat-tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 2px;
  border-top: 3px solid var(--series-1);
  padding: 16px 18px;
}
.stat-tile .label { color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.03em; font-size: 0.72rem; margin-bottom: 6px; }
.stat-tile .value { font-family: "IBM Plex Mono", ui-monospace, monospace; font-size: 1.5rem; font-weight: 600; }
.stat-tile .sub { color: var(--text-muted); font-size: 0.78rem; margin-top: 4px; }

.callout {
  background: var(--surface-1); border: 1px solid var(--border); border-left: 3px solid var(--series-1);
  border-radius: 2px; padding: 14px 18px; margin-bottom: 24px; font-size: 0.92rem; color: var(--text-secondary);
}
.callout strong { color: var(--text-primary); }

ul.notes { color: var(--text-secondary); font-size: 0.88rem; padding-left: 20px; }
ul.notes li { margin-bottom: 8px; }

.legend-inline { display: flex; flex-wrap: wrap; gap: 12px 20px; font-size: 0.8rem; color: var(--text-secondary); margin: 4px 0 14px; }
.legend-inline .key { display: inline-flex; align-items: center; gap: 6px; }
.legend-inline .swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

footer.site {
  border-top: 1px solid var(--border); margin-top: 40px; padding-top: 20px;
  color: var(--text-muted); font-size: 0.82rem;
}
footer.site a { color: var(--text-secondary); }

.view-toggle { display: inline-flex; gap: 4px; margin-bottom: 18px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 2px; padding: 3px; }
.btn-view-mode {
  font-size: 0.82rem; color: var(--text-secondary); background: transparent; border: none; border-radius: 2px;
  padding: 5px 12px; cursor: pointer;
}
.btn-view-mode:hover { color: var(--text-primary); }
.btn-view-mode.is-active { background: var(--series-1); color: #fff; }

.filter-row { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 18px; align-items: flex-end; }
.filter-row label { display: flex; flex-direction: column; gap: 4px; font-size: 0.82rem; color: var(--text-secondary); }
.filter-row select {
  font-size: 0.88rem; color: var(--text-primary); background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 2px; padding: 6px 10px; min-width: 160px;
}

table.data-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
table.data-table th.sortable:hover { color: var(--text-primary); }
table.data-table th.sortable .sort-arrow { color: var(--text-muted); margin-left: 3px; }
table.data-table td a, table.data-table a.entity-link { color: var(--series-1); text-decoration: none; }
table.data-table td a:hover, table.data-table a.entity-link:hover { text-decoration: underline; }
table.data-table.scroll-wrap { display: block; overflow-x: auto; }
table.data-table th[title] { text-decoration: underline dotted; text-decoration-color: var(--text-muted); text-underline-offset: 3px; }
table.data-table th[title]:not(.sortable) { cursor: help; }

.matrix-wrap { overflow-x: auto; padding-bottom: 4px; }
table.matrix-table { border-collapse: collapse; font-size: 0.78rem; font-variant-numeric: tabular-nums; }
table.matrix-table th, table.matrix-table td { padding: 0; }
table.matrix-table th.matrix-row-label {
  text-align: right; padding: 0 10px 0 0; white-space: nowrap; font-weight: 500;
  color: var(--text-secondary); position: sticky; left: 0; background: var(--surface-1);
}
table.matrix-table th.matrix-corner { background: var(--surface-1); position: sticky; left: 0; }
table.matrix-table th.matrix-col-label { height: 108px; vertical-align: bottom; text-align: left; }
table.matrix-table th.matrix-col-label span {
  display: inline-block; transform: rotate(-45deg); transform-origin: left bottom;
  white-space: nowrap; font-weight: 500; color: var(--text-secondary); padding-bottom: 4px;
}
table.matrix-table td.matrix-cell {
  width: 46px; height: 34px; min-width: 46px; text-align: center;
  border: 2px solid var(--page-plane); cursor: default;
}
table.matrix-table td.matrix-cell.is-diagonal { background: var(--surface-1) !important; color: var(--text-muted); }

.chart-holder canvas { cursor: pointer; }

.detail-header { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-bottom: 4px; }
.detail-header h2 { font-family: "Source Serif 4", Georgia, serif; font-weight: 600; font-size: 1.4rem; margin: 0; }
.back-link { display: inline-block; margin-bottom: 18px; color: var(--text-secondary); font-size: 0.88rem; text-decoration: none; }
.back-link:hover { color: var(--text-primary); }
.detail-stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin: 18px 0 28px; }
.pill { display: inline-block; font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-1); border: 1px solid var(--border); color: var(--text-secondary); margin-left: 8px; }
.pill.pill-legacy { background: var(--series-4); border-color: var(--series-4); color: #1a1400; }
.pill.pill-medium-confidence { background: var(--series-2); border-color: var(--series-2); color: #fff; margin-left: 0; }
tr.row-medium-confidence { background: color-mix(in srgb, var(--series-2) 7%, transparent); }
.text-muted { color: var(--text-muted); }

.confidence-toggle-bar {
  display: flex; align-items: flex-start; gap: 12px;
  margin: 4px 0 20px; padding: 10px 14px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 2px;
  max-width: 74ch;
}
.confidence-toggle-label { font-size: 0.86rem; color: var(--text-primary); font-weight: 500; cursor: pointer; }
.confidence-toggle-sub { display: block; color: var(--text-muted); font-weight: 400; font-size: 0.78rem; margin-top: 3px; }

.legacy-toggle-bar {
  display: flex; align-items: flex-start; gap: 12px;
  margin-top: 16px; padding: 10px 14px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 2px;
  max-width: 74ch;
}
.toggle-switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; margin-top: 1px; }
.toggle-switch input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle-slider {
  position: absolute; inset: 0; background: var(--baseline); border-radius: 999px;
  transition: background 0.15s ease;
}
.toggle-slider::before {
  content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px;
  background: var(--surface-1); border-radius: 50%; transition: transform 0.15s ease;
}
.toggle-switch input:checked + .toggle-slider { background: var(--series-1); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(16px); }
.toggle-switch input:focus-visible + .toggle-slider { outline: 2px solid var(--series-1); outline-offset: 2px; }
.legacy-toggle-label { font-size: 0.86rem; color: var(--text-primary); font-weight: 500; cursor: pointer; }
.legacy-toggle-sub { display: block; color: var(--text-muted); font-weight: 400; font-size: 0.78rem; margin-top: 3px; }
.legacy-toggle-sub a { color: var(--text-secondary); }

.search-bar-wrap {
  position: sticky; top: 0; z-index: 30;
  background: var(--page-plane);
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}
.search-bar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 2px;
  padding: 8px 12px;
}
.search-icon { color: var(--text-muted); flex: none; }
.search-input {
  flex: 1 1 220px; min-width: 160px; border: none; background: transparent;
  color: var(--text-primary); font-size: 0.92rem; padding: 4px 0;
}
.search-input:focus { outline: none; }
.search-input::placeholder { color: var(--text-muted); }
.search-filter-chips { display: flex; gap: 4px; flex: none; }
.search-filter-chips .chip {
  font-size: 0.76rem; color: var(--text-secondary); background: var(--page-plane);
  border: 1px solid var(--border); border-radius: 999px; padding: 4px 10px; cursor: pointer;
}
.search-filter-chips .chip:hover { color: var(--text-primary); border-color: var(--baseline); }
.search-filter-chips .chip.is-active { background: var(--series-1); border-color: var(--series-1); color: #fff; }

.search-results {
  margin-top: 6px; max-height: 60vh; overflow-y: auto;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 2px;
  padding: 6px; box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
.search-group-label {
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); padding: 8px 10px 4px;
}
.search-result {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: 8px 10px; border-radius: 2px; text-decoration: none;
  color: var(--text-primary);
}
.search-result:hover, .search-result:focus { background: var(--page-plane); }
.search-result-label { font-weight: 500; }
.search-result-sub { color: var(--text-muted); font-size: 0.8rem; white-space: nowrap; }
.search-empty { color: var(--text-muted); font-size: 0.84rem; padding: 8px 10px; }

[hidden] { display: none !important; }

/* Dataset tabs: federal vs. Massachusetts are two entirely separate
   datasets (different disclosure regime, different scale, not merged) --
   this switcher is the primary way a visitor moves between them, and its
   own coloring carries into every card via .dataset-pill below. */
.dataset-tabs { display: inline-flex; gap: 4px; margin: 4px 0 18px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 2px; padding: 4px; }
.dataset-tab {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  background: transparent; border: none; border-radius: 2px; cursor: pointer;
  padding: 8px 16px; text-align: left; color: var(--text-secondary);
}
.dataset-tab:hover { background: var(--page-plane); color: var(--text-primary); }
.dataset-tab-title { font-weight: 700; font-size: 0.98rem; }
.dataset-tab-sub { font-size: 0.74rem; color: var(--text-muted); }
/* Every non-Federal tab (each state, plus Compare) sets its own --accent /
   --accent-soft custom properties inline (see docs/index.html) so one
   generic rule covers all of them -- adding a state tab needs a new
   --<id>-accent[-soft] pair above and a tab button with the matching
   inline style, not a new CSS selector here. */
.dataset-tab.is-active { background: var(--accent-soft, var(--fed-accent-soft)); }
.dataset-tab.is-active .dataset-tab-title { color: var(--accent, var(--series-1)); }

/* State dropdown: the four individual state tabs (Massachusetts,
   Washington, Colorado, California) nest under one "State" trigger rather
   than sitting as four separate top-level tabs -- keeps the bar to five
   entries (Federal / State / States / Compare, the last two full tabs of
   their own) as more states get added, rather than growing one slot per
   state. The trigger reuses .dataset-tab's own styling and the same
   --accent/--accent-soft convention (app.js sets it to whichever state is
   currently active, or clears it), so it needs no color rules of its own. */
.dataset-tab-dropdown { position: relative; }
.dropdown-caret { font-size: 0.7em; color: var(--text-muted); }
.dataset-tab-dropdown-menu {
  position: absolute; top: calc(100% + 6px); left: 0; z-index: 20;
  display: flex; flex-direction: column; gap: 2px; min-width: 210px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 2px;
  padding: 4px; box-shadow: 0 8px 24px rgba(0,0,0,0.14);
}
.dataset-tab-dropdown-menu .dataset-tab { width: 100%; }

/* Context pill: stamped on every card's title row so which dataset a given
   chart or table belongs to is never ambiguous, even mid-scroll. Federal
   cards get the dataset-pill-federal modifier (a static class, never
   rebuilt); every state's cards set --accent/--accent-soft inline instead
   (built fresh per state, see stateCardTitle() in app.js). */
.dataset-pill {
  display: inline-flex; align-items: center; gap: 5px; font-size: 0.68rem; font-weight: 700;
  letter-spacing: 0.02em; padding: 2px 9px; border-radius: 999px; margin-left: 10px;
  vertical-align: middle; white-space: nowrap;
  background: var(--accent-soft, var(--fed-accent-soft)); color: var(--accent, var(--series-1));
}
.dataset-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--accent, var(--series-1)); }
.dataset-pill-federal { background: var(--fed-accent-soft); color: var(--series-1); }
.dataset-pill-federal::before { background: var(--series-1); }

.state-banner {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  background: var(--accent-soft); border: 1px solid var(--accent);
  border-radius: 2px; padding: 12px 18px; margin-bottom: 28px; font-size: 0.9rem; color: var(--text-secondary);
}
.state-banner strong { color: var(--accent); }

.compare-banner {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  background: var(--compare-accent-soft); border: 1px solid var(--compare-accent);
  border-radius: 2px; padding: 12px 18px; margin-bottom: 28px; font-size: 0.9rem; color: var(--text-secondary);
}
.compare-banner strong { color: var(--compare-accent); }

/* Compare-tab vendor table: category tags, description column, and the
   momentum column's directional badge (recent-vs-earlier spending trend,
   blended across whichever of Federal/MA a vendor has data in). */
.tag-chip {
  display: inline-block; font: inherit; font-size: 0.7rem; line-height: 1.4; padding: 2px 7px; border-radius: 999px;
  background: var(--surface-1); border: 1px solid var(--border); color: var(--text-secondary); margin: 0 4px 2px 0;
  cursor: pointer;
}
.tag-chip:hover { border-color: var(--compare-accent); color: var(--compare-accent); }
.tag-chip.is-active { background: var(--compare-accent); border-color: var(--compare-accent); color: #fff; }
.desc-cell { max-width: 280px; white-space: normal; color: var(--text-secondary); }
.trend-up { color: var(--series-6); font-weight: 600; white-space: nowrap; }
.trend-down { color: var(--series-8); font-weight: 600; white-space: nowrap; }
.trend-flat { color: var(--text-muted); white-space: nowrap; }

.active-filter-bar {
  display: flex; align-items: center; gap: 8px; margin-bottom: 12px; font-size: 0.85rem; color: var(--text-secondary);
}
.filter-clear-btn {
  font: inherit; font-size: 0.78rem; color: var(--series-1); background: none; border: none; cursor: pointer;
  padding: 0; text-decoration: underline;
}
.filter-clear-btn:hover { color: var(--text-primary); }

@media (max-width: 640px) {
  .card-grid { grid-template-columns: 1fr; }
}
