/* CBO January-2020 Counterfactual Explorer — house look (Literata, chartbook palette).
   Bespoke SVG charts; one data.json drives gallery + table + detail so they can't drift. */

:root {
  --ink:      #262626;
  --muted:    #808080;
  --line:     #e8e8e8;
  --grid:     #d9d9d9;
  --bg:       #ffffff;
  --actual:   #4472c4;   /* blue  — actual (chartbook primary)  */
  --forecast: #ed7d31;   /* orange — CBO Jan-2020 (chartbook secondary) */
  --crimson:  #c00000;   /* Harvard crimson — active states / "below" */
  --above:    #2f7d4f;   /* restrained green — "above forecast" (directional only) */
  --below:    #c0504d;   /* restrained brick — "below forecast" */
  --chip-bg:  #f4f5f7;
  --font: "Literata", var(--mf-font, Georgia), serif;
}

* { box-sizing: border-box; }

body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font);
  -webkit-font-smoothing: antialiased; }

.cbo { max-width: 1180px; margin: 0 auto; padding: 28px 22px 64px; }
.cbo-loading { color: var(--muted); font-style: italic; padding: 40px 0; }

/* ── header band ─────────────────────────────────────────────────────────── */
.head { border-bottom: 1.5px solid var(--ink); padding-bottom: 14px; margin-bottom: 16px; }
.head .topline { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.head .back { font-size: 13px; color: var(--muted); text-decoration: none; }
.head .back:hover { color: var(--crimson); }
.head .brand { font-size: 13px; color: var(--muted); white-space: nowrap; }
.head h1 { font-size: 27px; font-weight: 700; margin: 8px 0 4px; line-height: 1.15; }
.head .sub { font-size: 15px; color: var(--ink); margin: 0 0 6px; }
.head .src { font-size: 12px; color: var(--muted); font-style: italic; margin: 0; }
.disclaimer { font-size: 12.5px; color: var(--crimson); background: #fdf3f2;
  border: 1px solid #f3d9d7; border-radius: 6px; padding: 7px 11px; margin: 12px 0 0; }

/* ── global legend (single source — never repeated on each card) ──────────── */
.legend { display: flex; gap: 22px; align-items: center; flex-wrap: wrap;
  font-size: 13.5px; margin: 14px 0 4px; }
.legend .key { display: inline-flex; align-items: center; gap: 8px; }
.legend svg { display: block; }

/* ── control bar (sticky) ────────────────────────────────────────────────── */
.controls { position: sticky; top: 0; z-index: 20; background: rgba(255,255,255,0.96);
  backdrop-filter: blur(3px); border-bottom: 1px solid var(--line);
  padding: 10px 0; margin-bottom: 18px; display: flex; flex-wrap: wrap; gap: 12px 18px;
  align-items: center; }
.controls .group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.controls .glabel { font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin-right: 2px; }

.seg { display: inline-flex; border: 1px solid var(--grid); border-radius: 7px; overflow: hidden; }
.seg button { font-family: var(--font); font-size: 13px; border: 0; background: #fff;
  color: var(--ink); padding: 5px 12px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--grid); }
.seg button.on { background: var(--crimson); color: #fff; }

.chip { font-family: var(--font); font-size: 12.5px; border: 1px solid var(--grid);
  background: #fff; color: var(--ink); padding: 4px 11px; border-radius: 999px; cursor: pointer; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }

.controls input[type=search] { font-family: var(--font); font-size: 13px; padding: 5px 10px;
  border: 1px solid var(--grid); border-radius: 7px; min-width: 180px; }
.toggle { font-family: var(--font); font-size: 12.5px; border: 1px solid var(--grid);
  background: #fff; color: var(--ink); padding: 5px 11px; border-radius: 7px; cursor: pointer; }
.toggle.on { background: var(--crimson); color: #fff; border-color: var(--crimson); }
.toggle[disabled] { opacity: .4; cursor: default; }

/* Selection bar: count · "Show selected only" toggle (lit while on) · "Add another" · clear.
   The two action buttons share one fixed width so they never resize with their labels. */
.selbar { font-size: 13px; color: var(--ink); display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.selbar .toggle { width: 150px; text-align: center; }
button.link { font-family: var(--font); font-size: 12.5px; padding: 0; margin: 0;
  background: none; border: 0; color: var(--crimson); cursor: pointer; text-decoration: underline; }
/* A ticked card stays in the grid beside the others and is outlined so the selection reads at a glance. */
.card.picked, .card.picked:hover { border-color: var(--crimson); box-shadow: inset 0 0 0 1px var(--crimson); }
.card.picked:hover { box-shadow: inset 0 0 0 1px var(--crimson), 0 3px 14px rgba(0,0,0,.07); }
/* Empty grid: a sentence across the full width, never a blank page. */
.gallery .empty { grid-column: 1 / -1; text-align: center; color: var(--muted); font-style: italic; padding: 34px 0; margin: 0; }
.gallery .empty button.link { margin-left: 8px; font-style: normal; }
table.master td.empty { text-align: center; color: var(--muted); font-style: italic; padding: 26px 10px; }
table.master td.empty button.link { margin-left: 8px; font-style: normal; }

/* ── gallery (small multiples) ───────────────────────────────────────────── */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(285px, 1fr)); gap: 16px; }
.card { border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px 8px; background: #fff;
  cursor: pointer; transition: box-shadow .12s, border-color .12s; }
.card:hover { box-shadow: 0 3px 14px rgba(0,0,0,.07); border-color: var(--grid); }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.card-head .cname { font-size: 14px; font-weight: 600; line-height: 1.2; }
.card-head .csec { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card-pick { flex: 0 0 auto; }
.card-pick input { cursor: pointer; }
.gap { font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.gap .word { font-weight: 400; color: var(--muted); }
.gap.above { color: var(--above); }
.gap.below { color: var(--below); }
.gap.inline { color: var(--muted); }
.card svg.chart { width: 100%; height: auto; display: block; }
.paired-toggle { display: inline-flex; gap: 4px; margin-top: 4px; }
.paired-toggle button { font-family: var(--font); font-size: 11px; padding: 2px 8px;
  border: 1px solid var(--grid); background: #fff; border-radius: 6px; cursor: pointer; color: var(--muted); }
.paired-toggle button.on { color: var(--ink); border-color: var(--ink); font-weight: 600; }

/* ── master table ────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table.master { border-collapse: collapse; width: 100%; font-size: 13px; }
table.master th, table.master td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.master th { font-weight: 600; cursor: pointer; user-select: none; white-space: nowrap;
  border-bottom: 1.5px solid var(--ink); background: #fff; }
table.master th .arr { color: var(--crimson); font-size: 11px; }
table.master td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.master tr.datarow:hover { background: #fafafa; cursor: pointer; }
table.master .vsec { color: var(--muted); font-size: 12px; }
.csvbtn { font-family: var(--font); font-size: 12.5px; border: 1px solid var(--grid); background: #fff;
  padding: 5px 11px; border-radius: 7px; cursor: pointer; margin: 0 0 12px; }

/* ── detail modal ────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; background: rgba(38,38,38,.5); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 24px; }
.modal[hidden] { display: none; }
.modal-inner { background: #fff; border-radius: 12px; max-width: 720px; width: 100%;
  padding: 22px 26px 18px; position: relative; max-height: 92vh; overflow: auto; }
.modal-inner h2 { font-size: 20px; margin: 0 0 2px; }
.modal-inner .msec { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.modal-close { position: absolute; top: 12px; right: 14px; border: 0; background: none;
  font-size: 24px; color: var(--muted); cursor: pointer; line-height: 1; }
.modal-close:hover { color: var(--crimson); }
.tooltip { position: fixed; pointer-events: none; background: var(--ink); color: #fff;
  font-size: 11.5px; padding: 6px 9px; border-radius: 6px; z-index: 60; white-space: nowrap; opacity: 0;
  transition: opacity .08s; }

/* ── Claude-written synthesis essay ──────────────────────────────────────── */
.discussion { max-width: 760px; margin: 42px 0 0; padding-top: 22px; border-top: 2px solid var(--ink); }
.discussion .dlabel { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--crimson); font-weight: 600; }
.discussion h2 { font-size: 22px; margin: 6px 0 14px; line-height: 1.18; }
.discussion h3 { font-size: 15.5px; margin: 20px 0 4px; }
.discussion p { font-size: 15.5px; line-height: 1.64; margin: 0 0 13px; color: var(--ink); }
.discussion em { font-style: italic; }
.discussion .dcaveat { font-size: 12px; color: var(--muted); font-style: italic; margin-top: 18px; }

/* ── footer ──────────────────────────────────────────────────────────────── */
.foot { margin-top: 34px; padding-top: 14px; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.foot b { color: var(--ink); font-weight: 600; }

@media (max-width: 560px) {
  .head h1 { font-size: 22px; }
  .gallery { grid-template-columns: 1fr; }
}

/* "Econvitals original" (assets/house.js) on the header line: this page keeps its own palette, so
   the tag is styled here from these variables. */
.head .mf-original-line { font-size: 13px; color: var(--muted); margin: -2px 0 8px; }
.head .mf-original-line a:not(.mf-original) { color: var(--muted); text-decoration: underline; }
.mf-original { display: inline-block; font-size: 10px; line-height: 16px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: var(--actual); border: 1px solid var(--actual); border-radius: 999px; padding: 0 8px;
  text-decoration: none; white-space: nowrap; vertical-align: middle; }
.mf-original:hover { background: var(--chip-bg); text-decoration: none; }
