/* ============================================================
   Church Tech Compensation Explorer
   Palette + tokens from the validated data-viz reference palette
   (light + dark are both selected, not an auto-invert).
   ============================================================ */
:root {
  color-scheme: light;
  --page:        #f9f9f7;
  --surface-1:   #fcfcfb;
  --surface-2:   #f2f1ec;
  --text-1:      #0b0b0b;
  --text-2:      #52514e;
  --muted:       #898781;
  --grid:        #e1e0d9;
  --baseline:    #c3c2b7;
  --border:      rgba(11,11,11,0.10);
  --s1:          #2a78d6;
  --good-text:   #006300;
  --critical:    #d03b3b;
  --warning:     #fab219;
  --shadow:      0 1px 2px rgba(0,0,0,0.04), 0 10px 30px rgba(0,0,0,0.06);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:        #0d0d0d;
  --surface-1:   #1a1a19;
  --surface-2:   #232321;
  --text-1:      #ffffff;
  --text-2:      #c3c2b7;
  --muted:       #898781;
  --grid:        #2c2c2a;
  --baseline:    #383835;
  --border:      rgba(255,255,255,0.10);
  --s1:          #3987e5;
  --good-text:   #0ca30c;
  --critical:    #d03b3b;
  --warning:     #fab219;
  --shadow:      0 1px 2px rgba(0,0,0,0.3), 0 12px 34px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text-1);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--s1); }

/* ---------- page shell ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 26px 22px 80px; }
.masthead { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.masthead h1 { font-size: 23px; margin: 0 0 4px; letter-spacing: -0.01em; }
.masthead p { margin: 0; color: var(--text-2); font-size: 14px; max-width: 680px; }
.theme-toggle {
  flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface-1);
  color: var(--text-2); border-radius: 9px; padding: 8px 12px; font: inherit;
  font-size: 13px; cursor: pointer;
}
.theme-toggle:hover { color: var(--text-1); }

/* ---------- explorer layout ---------- */
.explorer { display: grid; grid-template-columns: 264px 1fr; gap: 22px; align-items: start; }
.results { min-width: 0; display: flex; flex-direction: column; gap: 18px; }

/* ---------- filter rail ---------- */
.rail {
  position: sticky; top: 16px;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  padding: 16px; box-shadow: var(--shadow); max-height: calc(100vh - 32px); overflow: auto;
}
.rail-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.rail-head h2 { font-size: 14px; margin: 0; }
.rail-clear { border: 0; background: none; color: var(--s1); font: inherit; font-size: 12px; cursor: pointer; padding: 4px; }
.rail-clear:hover { text-decoration: underline; }
.rail section { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.rail section:first-of-type { border-top: 0; margin-top: 0; }
.rail h3 { font-size: 11px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin: 0 0 6px; }
.facet-dim { font-size: 12px; font-weight: 600; color: var(--text-2); margin: 10px 0 3px; }
.facet-group:first-child .facet-dim { margin-top: 0; }

.facet {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 5px 8px; border: 0; border-radius: 8px; background: none; cursor: pointer;
  font: inherit; font-size: 13px; color: var(--text-2); text-align: left;
}
.facet:hover { background: var(--surface-2); }
.facet.on { background: color-mix(in srgb, var(--s1) 14%, transparent); color: var(--text-1); font-weight: 500; }
.facet .lab { display: flex; align-items: center; min-width: 0; }
.facet .lab span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facet .n { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; padding-left: 8px; }
.facet .box {
  width: 15px; height: 15px; flex: 0 0 auto; margin-right: 8px; border-radius: 4px;
  border: 1.5px solid var(--baseline); position: relative;
}
.facet.on .box { background: var(--s1); border-color: var(--s1); }
.facet.on .box::after {
  content: ""; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px;
  border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg);
}
:root[data-theme="dark"] .facet.on .box::after { border-color: #0d0d0d; }

/* ---------- chips ---------- */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chip-lead { font-size: 13px; color: var(--text-2); font-weight: 600; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; border: 1px solid var(--border);
  background: var(--surface-1); border-radius: 999px; padding: 4px 10px 4px 11px;
  font: inherit; font-size: 12.5px; color: var(--text-1); cursor: pointer;
}
.chip:hover { border-color: var(--critical); }
.chip .x { color: var(--muted); font-size: 11px; }
.chip:hover .x { color: var(--critical); }

/* ---------- KPI tiles ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 14px 16px; box-shadow: var(--shadow);
}
.tile .k-lab { font-size: 12px; color: var(--text-2); }
.tile .k-val { font-size: 27px; font-weight: 600; letter-spacing: -0.01em; margin-top: 2px; }
.tile .k-val.small { font-size: 18px; padding-top: 5px; }
.tile .k-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.delta-up { color: var(--good-text); font-weight: 600; }
.delta-dn { color: var(--critical); font-weight: 600; }

/* ---------- cards / figures ---------- */
.card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; margin: 0; box-shadow: var(--shadow);
}
.card figcaption, .card .cap { font-size: 15px; font-weight: 600; }
.card .cap-sub { font-size: 12.5px; color: var(--text-2); margin: 2px 0 12px; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; margin: 6px 0 10px; font-size: 12.5px; color: var(--text-2); }
.legend .key { display: inline-flex; align-items: center; gap: 7px; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; flex: 0 0 auto; }
.legend .lk { width: 18px; height: 0; border-top: 2px solid var(--muted); }

.chart-box { position: relative; width: 100%; }
.chart-box canvas { max-width: 100%; }
.chart-box.h-dist { height: 300px; }
.chart-box.h-break { height: 260px; }
.chart-box.h-sent { height: 260px; }
.chart-box.h-drivers { height: 210px; }

/* ---------- breakdown selector ---------- */
.seg { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button {
  border: 0; background: none; font: inherit; font-size: 12px; color: var(--text-2);
  padding: 5px 10px; border-radius: 7px; cursor: pointer;
}
.seg button.on { background: var(--surface-1); color: var(--text-1); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.08); }

/* ---------- suppression ---------- */
.suppress {
  background: var(--surface-1); border: 1px dashed var(--baseline); border-radius: 14px;
  padding: 34px; text-align: center;
}
.suppress svg { width: 38px; height: 38px; color: var(--warning); margin-bottom: 8px; }
.suppress h3 { margin: 0 0 6px; font-size: 16px; }
.suppress p { margin: 0 auto; max-width: 440px; color: var(--text-2); font-size: 13.5px; }
.suppress .badge { display: inline-block; margin-top: 14px; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- table view ---------- */
.table-toggle { margin-top: 12px; }
.table-toggle summary { cursor: pointer; font-size: 12.5px; color: var(--s1); }
table.dist { border-collapse: collapse; width: 100%; font-size: 12.5px; margin-top: 10px; }
table.dist th, table.dist td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--border); }
table.dist th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }
table.dist td.num, table.dist th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.dist tr.hi { background: color-mix(in srgb, var(--s1) 9%, transparent); }
.note { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

/* ---------- two-up ---------- */
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

@media (max-width: 900px) {
  .explorer { grid-template-columns: 1fr; }
  .rail { position: static; max-height: none; }
  .two { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
}

/* Hold the previous render during a live refetch (no skeleton flash). */
[data-live-loading] { opacity: 0.55; transition: opacity .12s ease; }
