/* ---------------------------------------------------------------------------
   Components. Import AFTER tokens.css.

   Everything here is domain-neutral: shell chrome, cards, stat tiles, tables,
   prose, forms, tooltips. Chart marks themselves are drawn in charts.js; the
   classes at the bottom (.axis-lbl, .bar-lbl) style their text.
--------------------------------------------------------------------------- */

#app { max-width: var(--content-max); margin: 0 auto; padding: 0 24px 40px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 28px; padding: 16px 0 14px; flex-wrap: wrap; }
.brand { display: inline-flex; align-items: center; gap: 9px; text-decoration: none; color: var(--ink); width: var(--sidebar-w); flex: none; }
.brand-mark { display: block; }
.brand-text { font-size: 17px; font-weight: 750; letter-spacing: -0.01em; }
.tabs { display: flex; gap: 2px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.tab {
  border: 0; background: none; color: var(--ink-2); font: inherit; font-size: 13.5px; font-weight: 550;
  padding: 6px 13px; border-radius: 8px; cursor: pointer; position: relative;
}
.tab:hover { color: var(--ink); }
.tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.tab-dot {
  position: absolute; top: 5px; right: 5px; width: 6px; height: 6px; border-radius: 50%;
  background: var(--warn); box-shadow: 0 0 0 2px var(--surface-2);
}
.tab-dot.run { background: var(--s1); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.topbar-right { position: relative; margin-left: auto; display: flex; align-items: center; gap: 10px; }
.popover {
  position: absolute; top: 40px; right: 0; z-index: 60; width: 320px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow); padding: 14px 16px; font-size: 13px; color: var(--ink-2); line-height: 1.55;
}
.popover h4 { color: var(--ink); font-size: 13px; margin-bottom: 6px; }
.popover p { margin: 6px 0; }
.popover code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 0 5px; font-size: 11.5px; }

/* identity / status pill */
.pill { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 550; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--border); padding: 3px 12px; border-radius: 99px; }
.pill.with-avatar { padding-left: 4px; }

/* circle-masked photo, initial-on-accent fallback */
.avatar { border-radius: 50%; object-fit: cover; display: inline-block; flex: none; border: 1px solid var(--border); }
.av-fallback { color: #fff; font-weight: 700; text-align: center; border: 0; }
.avatar-lg { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; border: 1px solid var(--border); }

/* ---------- buttons & inputs ---------- */
.icon-btn { border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); border-radius: 8px; width: 30px; height: 30px; cursor: pointer; font-size: 15px; }
.icon-btn:hover { color: var(--ink); }
.icon-btn.txt { width: auto; padding: 0 12px; font-size: 12.5px; font-weight: 550; font-family: inherit; }
a.icon-btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
/* accent-filled call to action — use sparingly, one per view */
a.icon-btn.accent, .icon-btn.accent { background: var(--s1); color: #fff; border: 0; font-weight: 650; }
a.icon-btn.accent:hover, .icon-btn.accent:hover { filter: brightness(1.1); color: #fff; }

.btn {
  font: inherit; font-size: 13px; font-weight: 600; color: #fff; background: var(--s1);
  border: 0; border-radius: 9px; padding: 8px 16px; cursor: pointer;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.subtle { background: var(--surface-2); color: var(--ink); border: 1px solid var(--border); }
button.linky { border: 0; background: none; color: var(--s1); cursor: pointer; font: inherit; font-size: 12.5px; padding: 0; }

input.text, input.search {
  font: inherit; font-size: 13px; color: var(--ink); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 9px; padding: 7px 11px; width: 260px;
}
input.search { font-size: 12.5px; padding: 6px 11px; width: 220px; }
input.search::placeholder { color: var(--muted); }
input.text:focus, input.search:focus { outline: none; border-color: var(--baseline); background: var(--surface); }
input.slider { width: 260px; accent-color: var(--s1); }
select.ctl {
  font: inherit; font-size: 12.5px; font-weight: 550; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px;
  padding: 7px 10px; max-width: 220px; cursor: pointer;
}
select.ctl:hover { background: var(--surface); }
.field { display: flex; align-items: center; gap: 10px; margin: 10px 0; flex-wrap: wrap; }
.field label { font-size: 12px; color: var(--muted); min-width: 90px; }

/* segmented control — the in-card metric switcher */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 2px; }
.seg button {
  border: 0; background: none; font: inherit; font-size: 12.5px; font-weight: 550; color: var(--ink-2);
  padding: 5px 11px; border-radius: 7px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.seg button:hover { color: var(--ink); }
.seg button.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg .dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink); background: var(--surface-2); border: 1px solid var(--border); border-radius: 7px; padding: 3px 8px; }
.chip button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 13px; padding: 0; line-height: 1; }
.chip button:hover { color: var(--ink); }
.tag { font-size: 10.5px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--border); padding: 2px 7px; border-radius: 6px; }
.badge { font-size: 9.5px; letter-spacing: .08em; color: var(--muted); border: 1px solid var(--border); padding: 1px 5px; border-radius: 5px; }
.copy-btn { border: 1px solid var(--border); background: var(--surface); color: var(--ink-2); font: inherit; font-size: 11.5px; padding: 3px 10px; border-radius: 7px; cursor: pointer; flex: none; }
.copy-btn:hover { color: var(--ink); }

/* ---------- shell: sidebar filters + content ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); gap: 28px; align-items: start; }
.shell.no-side { grid-template-columns: minmax(0, 1fr); }
.side { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 20px; }
.fgroup { display: flex; flex-direction: column; gap: 3px; }
.flabel { font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); margin-bottom: 5px; padding-left: 2px; }
.frow {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  border: 0; background: none; font: inherit; font-size: 13px; font-weight: 550; color: var(--ink-2);
  padding: 6px 10px; border-radius: 8px; cursor: pointer;
}
.frow:hover { color: var(--ink); background: var(--surface-2); }
.frow.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); border: 1px solid var(--border); padding: 5px 9px; }
.frow .dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.frow .badge { margin-left: auto; }
.side select.ctl { width: 100%; max-width: none; }
.main { min-width: 0; }
@media (max-width: 940px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; flex-direction: row; flex-wrap: wrap; gap: 16px; }
  .fgroup { min-width: 150px; }
  .brand { width: auto; }
}

/* ---------- layout ---------- */
.view { display: flex; flex-direction: column; gap: 14px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g23 { grid-template-columns: 2fr 1fr; }
.g32 { grid-template-columns: 2fr 1fr 1fr; }
@media (max-width: 980px) { .g2, .g3, .g23, .g32 { grid-template-columns: 1fr; } }
.filterbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filter-spacer { flex: 1; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); min-width: 0;
}
.card h3 { font-size: 13px; font-weight: 650; color: var(--ink-2); margin-bottom: 8px; letter-spacing: .01em; display: flex; align-items: center; gap: 7px; }
.card .sub { font-size: 12px; color: var(--muted); margin: -4px 0 10px; }
.card .chart { width: 100%; }
/* the ? affordance: explanation lives in a tooltip, not on the card surface */
.c-info {
  width: 16px; height: 16px; border-radius: 50%; flex: none;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  font-size: 10px; font-weight: 700; line-height: 1; cursor: help; padding: 0;
}
.c-info:hover { color: var(--ink); }

/* stat tiles — four across, two on narrow screens */
.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.tiles.t3 { grid-template-columns: repeat(3, 1fr); }
.tiles.t2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) { .tiles, .tiles.t3 { grid-template-columns: repeat(2, 1fr); } }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
  position: relative; overflow: hidden; display: flex; flex-direction: column; height: 132px;
}
.tile .t-label { font-size: 12px; color: var(--muted); }
.tile .t-value { font-size: 27px; font-weight: 650; letter-spacing: -0.01em; margin-top: 2px; }
.tile .t-value.hero { font-size: 34px; }
.tile .t-delta { font-size: 12px; color: var(--ink-2); margin-top: 2px; }
.tile .t-delta .up { color: var(--good); }
.tile .t-delta .down { color: var(--bad); }
/* pure numbers centre themselves, a size up */
.tile.t-center { justify-content: center; align-items: center; text-align: center; }
.tile.t-center .t-label { position: absolute; top: 14px; left: 16px; right: 16px; text-align: left; }
.tile.t-center .t-value { font-size: 32px; margin-top: 10px; }
/* sparkline pinned flush to the bottom edge; the value centres above it */
.tile.t-spark { padding-bottom: 46px; }
.tile .spark { position: absolute; left: 0; right: 0; bottom: 0; height: 44px; display: block; }
.t-info {
  position: absolute; top: 10px; right: 10px; width: 18px; height: 18px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--muted);
  font-size: 11px; font-weight: 700; line-height: 1; cursor: help; padding: 0;
}
.t-info:hover { color: var(--ink); }

/* ---------- data tables ---------- */
.dtable { width: 100%; border-collapse: collapse; font-size: 13px; }
.dtable th { text-align: right; font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 600; padding: 6px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
.dtable th:first-child { text-align: left; }
.dtable th.sortable { cursor: pointer; }
.dtable td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; }
.dtable td:first-child { text-align: left; }
.dtable tr:last-child td { border-bottom: 0; }
.dtable th.hl, .dtable td.hl { background: var(--surface-2); }
.dtable .u { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; color: var(--ink); }
.dtable .u .dot { width: 9px; height: 9px; border-radius: 50%; }
/* a bar drawn behind the number, so magnitude reads without a separate chart */
.dtable .bar-cell { position: relative; }
.dtable .mini-bar { position: absolute; left: 0; top: 20%; height: 60%; opacity: .14; border-radius: 3px; }
.dtable.rows-clickable tr { cursor: pointer; }
.dtable tr:hover td { background: var(--surface-2); }
/* compact variant for long lists */
.dtable.compact { font-size: 12.5px; }
.dtable.compact th { font-size: 10.5px; padding: 5px 8px; text-align: left; }
.dtable.compact td { padding: 6px 8px; text-align: left; max-width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dtable.compact th.num, .dtable.compact td.num { text-align: right; font-variant-numeric: tabular-nums; }
.dtable .t-dot { display: inline-block; width: 8px; height: 8px; border-radius: 2.5px; margin-right: 6px; }

/* ---------- text blocks ---------- */
/* readable measure, generous leading — for About/methodology pages */
.prose { max-width: 700px; font-size: 14.5px; color: var(--ink-2); line-height: 1.7; }
.prose h1, .prose h2, .prose h3 { color: var(--ink); margin: 28px 0 10px; line-height: 1.3; }
.prose h1 { font-size: 21px; } .prose h3 { font-size: 15px; }
.prose h2 { font-size: 17px; padding-bottom: 7px; border-bottom: 1px solid var(--grid); }
.prose > :first-child, .prose h2:first-child { margin-top: 4px; }
.prose p { margin: 12px 0; }
.prose b { color: var(--ink); font-weight: 650; }
.prose ul { margin: 10px 0; }
.prose li { margin: 7px 0 7px 20px; padding-left: 2px; }
.prose code { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; font-size: 12.5px; }
.prose blockquote { border-left: 3px solid var(--baseline); padding: 2px 0 2px 14px; color: var(--muted); margin: 14px 0; font-style: italic; }
.prose table { border-collapse: collapse; margin: 14px 0; font-size: 13.5px; line-height: 1.5; }
.prose th, .prose td { border: 1px solid var(--grid); padding: 9px 13px; text-align: left; vertical-align: top; }
.prose th { background: var(--surface-2); color: var(--ink); font-weight: 650; }
.prose td.num, .prose th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* monospace panel — code, logs, quoted payloads */
.mono {
  font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; line-height: 1.65;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px;
  white-space: pre-wrap; overflow-wrap: break-word; max-height: 480px; overflow-y: auto; color: var(--ink);
}
.mono.nowrap { white-space: pre; overflow-x: auto; }
.mono.sm { font-size: 11.5px; line-height: 1.6; padding: 10px 12px; max-height: 200px; color: var(--ink-2); }
.mono .cmt { color: var(--muted); }

/* insight rows — one-line findings with an accent mark */
.insights { display: flex; flex-direction: column; gap: 8px; }
.insight { display: flex; gap: 10px; font-size: 13px; color: var(--ink-2); }
.insight .i-mark { color: var(--s1); flex: none; }
.insight b { color: var(--ink); font-weight: 650; }

/* numbered steps — setup flows, pipelines, checklists */
.steps { display: flex; flex-direction: column; }
.step { display: grid; grid-template-columns: 30px 1fr; gap: 0 14px; padding: 16px 0; border-top: 1px solid var(--grid); }
.step:first-child { border-top: 0; padding-top: 4px; }
.step-num {
  width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); border: 1px solid var(--border);
  color: var(--ink-2); font-size: 12.5px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.step.done .step-num { background: var(--s1); border-color: var(--s1); color: #fff; }
.step-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.step-title { font-size: 14px; font-weight: 650; color: var(--ink); }
.step-status { font-size: 12.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.step-status b { color: var(--ink); }
.step-controls { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 9px; }
.step-note { font-size: 12px; color: var(--muted); line-height: 1.55; margin-top: 7px; max-width: 820px; }

/* ---------- feedback ---------- */
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink-2); margin-top: 8px; }
.legend .li { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; }
.legend .lk { width: 14px; height: 2px; border-radius: 1px; }

.tooltip {
  position: fixed; z-index: 99; pointer-events: none; max-width: 320px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 11px; font-size: 12.5px; box-shadow: var(--shadow);
}
.tooltip .tt-title { font-weight: 650; font-size: 12px; margin-bottom: 4px; color: var(--ink-2); }
.tooltip .tt-row { display: flex; align-items: center; gap: 7px; padding: 1px 0; }
.tooltip .tt-key { width: 12px; height: 2.5px; border-radius: 2px; flex: none; }
.tooltip .tt-val { font-weight: 650; margin-left: auto; padding-left: 14px; font-variant-numeric: tabular-nums; }
.tooltip .tt-lbl { color: var(--ink-2); }
.tooltip .tt-body { font-size: 12px; color: var(--ink-2); line-height: 1.5; max-width: 280px; }

.empty { text-align: center; color: var(--muted); padding: 60px 0; font-size: 14px; }
.empty code { background: var(--surface-2); padding: 2px 8px; border-radius: 6px; }
.hint { font-size: 11.5px; color: var(--muted); }
.foot { display: flex; justify-content: space-between; gap: 20px; flex-wrap: wrap; color: var(--muted); font-size: 11.5px; margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--grid); }
.foot em { font-style: normal; color: var(--ink-2); }

/* chart text */
svg text { font-family: inherit; }
.axis-lbl { font-size: 10.5px; fill: var(--muted); }
.bar-lbl { font-size: 11px; fill: var(--ink-2); font-weight: 600; }
