/* ============================================================
   State of Ministry — Research Explorer
   Design: warm-neutral editorial (Notion-derived palette),
   whisper borders, data-dense but calm.
   ============================================================ */

:root {
  --bg:            #ffffff;
  --bg-warm:       #f7f6f4;
  --bg-warm-2:     #f1efec;
  --surface:       #ffffff;
  --ink:           rgba(0,0,0,0.95);
  --ink-2:         #5f5b56;
  --ink-3:         #8f8a84;
  --ink-4:         #b3ada6;
  --line:          rgba(0,0,0,0.10);
  --line-2:        rgba(0,0,0,0.06);

  /* Accent: deep ministry teal + warm clay for contrast series */
  --accent:        #0f7268;
  --accent-2:      #0b5a52;
  --accent-soft:   #e8f3f1;
  --accent-ink:    #0a5049;
  --clay:          #c2603a;
  --clay-soft:     #fbeee8;
  --gold:          #b8892b;
  --violet:        #6b4ea8;
  --blue:          #2f6fb5;

  --pos:           #1f8a4c;
  --neg:           #c0392b;

  --radius-sm: 5px;
  --radius:    9px;
  --radius-lg: 14px;
  --pill:      9999px;

  --shadow-card:
    rgba(0,0,0,0.04) 0 4px 18px,
    rgba(0,0,0,0.027) 0 2px 7.8px,
    rgba(0,0,0,0.02) 0 .8px 2.9px,
    rgba(0,0,0,0.01) 0 .17px 1px;
  --shadow-pop:
    rgba(0,0,0,0.01) 0 1px 3px,
    rgba(0,0,0,0.02) 0 3px 7px,
    rgba(0,0,0,0.02) 0 7px 15px,
    rgba(0,0,0,0.04) 0 14px 28px,
    rgba(0,0,0,0.05) 0 23px 52px;

  --sidebar-w: 292px;
  --header-h: 61px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg-warm);
  color: var(--ink);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "lnum" 1;
}

button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ---------- Header ------------------------------------------------ */
.masthead {
  position: sticky; top: 0; z-index: 60;
  height: var(--header-h);
  display: flex; align-items: center; gap: 18px;
  padding: 0 20px;
  background: rgba(255,255,255,0.88);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; flex: none;
  background: linear-gradient(145deg, var(--accent) 0%, #14867a 55%, #1a9d7f 100%);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 13px; letter-spacing: -0.3px;
}
.brand-text { min-width: 0; }
.brand-title {
  font-size: 15px; font-weight: 700; letter-spacing: -0.28px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand-sub {
  font-size: 11.5px; font-weight: 500; color: var(--ink-3);
  letter-spacing: 0.12px; margin-top: -2px;
}

.tabs { display: flex; gap: 2px; margin-left: 6px; background: var(--bg-warm-2); padding: 3px; border-radius: var(--radius); }
.tab {
  padding: 6px 13px; border-radius: 6px; font-size: 13.5px; font-weight: 600;
  color: var(--ink-2); white-space: nowrap; transition: background .12s, color .12s;
}
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.07); }

.masthead-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.n-badge {
  display: inline-flex; align-items: baseline; gap: 6px;
  background: var(--accent-soft); color: var(--accent-ink);
  border-radius: var(--pill); padding: 5px 12px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.n-badge b { font-size: 14px; font-variant-numeric: tabular-nums; }
.n-badge.filtered { background: var(--clay-soft); color: #8e401f; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px; border-radius: 6px; font-size: 13.5px; font-weight: 600;
  background: rgba(0,0,0,0.045); color: var(--ink);
  transition: background .12s, transform .08s;
  white-space: nowrap;
}
.btn:hover { background: rgba(0,0,0,0.075); }
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn-ghost:hover { background: rgba(0,0,0,0.04); }
.btn-sm { padding: 4px 9px; font-size: 12.5px; }
.btn[disabled] { opacity: .45; pointer-events: none; }

/* ---------- Shell -------------------------------------------------- */
.shell { display: flex; align-items: flex-start; }

.sidebar {
  width: var(--sidebar-w); flex: none;
  position: sticky; top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto; overscroll-behavior: contain;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 16px 14px 60px;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 4px; padding: 0 4px;
}
.sidebar-title {
  font-size: 11px; font-weight: 700; letter-spacing: 0.7px;
  text-transform: uppercase; color: var(--ink-3);
}
.link-btn {
  font-size: 12px; font-weight: 600; color: var(--accent);
}
.link-btn:hover { text-decoration: underline; }
.link-btn[disabled] { color: var(--ink-4); pointer-events: none; }

.active-filters { padding: 6px 4px 10px; display: flex; flex-wrap: wrap; gap: 5px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--accent-soft); color: var(--accent-ink);
  border-radius: var(--pill); padding: 3px 8px 3px 10px;
  font-size: 11.5px; font-weight: 600; line-height: 1.5;
  max-width: 100%;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button {
  color: inherit; opacity: .6; font-size: 14px; line-height: 1;
  padding: 0 1px; border-radius: 3px;
}
.chip button:hover { opacity: 1; }

.facet { border-top: 1px solid var(--line-2); }
.facet:first-of-type { border-top: none; }
.facet-toggle {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 9px 6px; text-align: left;
  font-size: 13px; font-weight: 600; color: var(--ink);
  border-radius: var(--radius-sm);
}
.facet-toggle:hover { background: rgba(0,0,0,0.03); }
.facet-toggle .caret {
  font-size: 9px; color: var(--ink-4); transition: transform .15s; flex: none;
  transform: rotate(-90deg);
}
.facet[open] .facet-toggle .caret { transform: rotate(0deg); }
.facet-count {
  margin-left: auto; font-size: 10.5px; font-weight: 700;
  background: var(--accent); color: #fff;
  border-radius: var(--pill); padding: 1px 6px;
}
.facet-body { padding: 2px 4px 10px; }

.opt {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 7px; border-radius: var(--radius-sm);
  font-size: 13px; color: var(--ink-2); cursor: pointer;
  transition: background .1s;
}
.opt:hover { background: rgba(0,0,0,0.035); color: var(--ink); }
.opt input { accent-color: var(--accent); margin: 0; width: 14px; height: 14px; flex: none; }
.opt-label { flex: 1; min-width: 0; }
.opt-n {
  font-size: 11px; color: var(--ink-4); font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.opt input:checked + .opt-label { color: var(--ink); font-weight: 600; }
.opt.zero { opacity: .42; }

/* ---------- Main --------------------------------------------------- */
.main { flex: 1; min-width: 0; padding: 26px 30px 90px; max-width: 1220px; }

.page-head { margin-bottom: 22px; }
.page-title {
  font-size: 27px; font-weight: 700; letter-spacing: -0.85px; line-height: 1.15;
}
.page-sub { color: var(--ink-2); font-size: 14.5px; margin-top: 5px; max-width: 68ch; }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 11px 14px; margin-bottom: 20px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow-card);
  position: sticky; top: calc(var(--header-h) + 10px); z-index: 40;
}
.toolbar-label {
  font-size: 11px; font-weight: 700; letter-spacing: .6px;
  text-transform: uppercase; color: var(--ink-3);
}
.field {
  display: flex; align-items: center; gap: 7px;
}
select.control, input.control {
  border: 1px solid var(--line); background: var(--surface);
  border-radius: 6px; padding: 6px 9px; font-size: 13.5px; font-weight: 500;
  max-width: 260px;
}
select.control:hover { border-color: rgba(0,0,0,0.2); }
input.control::placeholder { color: var(--ink-4); }
.toolbar .spacer { flex: 1; }

/* ---------- Cards -------------------------------------------------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
  padding: 20px 22px; margin-bottom: 16px;
}
.card-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.card-title { font-size: 16.5px; font-weight: 700; letter-spacing: -0.3px; line-height: 1.32; }
.card-meta { font-size: 12px; color: var(--ink-3); margin-top: 3px; font-weight: 500; }
.card-actions { margin-left: auto; display: flex; gap: 6px; flex: none; }

.qnum {
  flex: none; width: 30px; height: 24px; border-radius: 6px;
  background: var(--bg-warm-2); color: var(--ink-3);
  display: grid; place-items: center;
  font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums;
  margin-top: 1px;
}

.tag {
  display: inline-block; font-size: 10.5px; font-weight: 700;
  letter-spacing: .4px; text-transform: uppercase;
  padding: 2px 7px; border-radius: var(--pill);
  background: var(--bg-warm-2); color: var(--ink-2);
}
.tag.theme { background: var(--accent-soft); color: var(--accent-ink); }
.tag.pain  { background: var(--clay-soft); color: #8e401f; }
.tag.multi { background: #eef2fa; color: #2f5c96; }

/* ---------- Bars --------------------------------------------------- */
.bars { display: flex; flex-direction: column; gap: 3px; }
.bar-row {
  display: grid; grid-template-columns: minmax(150px, 34%) 1fr 62px;
  align-items: center; gap: 12px;
  padding: 4px 6px; border-radius: var(--radius-sm);
}
.bar-row:hover { background: rgba(0,0,0,0.025); }
.bar-label {
  font-size: 13.2px; color: var(--ink); line-height: 1.35;
  overflow-wrap: anywhere;
}
.bar-track {
  height: 22px; background: var(--bg-warm-2);
  border-radius: 4px; overflow: hidden; position: relative;
}
.bar-fill {
  height: 100%; border-radius: 4px;
  background: var(--accent);
  transition: width .35s cubic-bezier(.22,.7,.3,1);
}
.bar-row.top .bar-fill { background: linear-gradient(90deg, var(--accent) 0%, #17907f 100%); }
.bar-row.low .bar-fill { background: #b9c4c2; }
.bar-val {
  text-align: right; font-size: 13px; font-weight: 700;
  font-variant-numeric: tabular-nums; color: var(--ink);
}
.bar-val small { display: block; font-size: 10.5px; font-weight: 500; color: var(--ink-4); margin-top: -3px; }

/* Grouped / cross-tab bars */
.xtab-legend {
  display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 14px;
  padding-bottom: 12px; border-bottom: 1px solid var(--line-2);
}
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--ink-2); font-weight: 500; }
.swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.legend-n { color: var(--ink-4); font-variant-numeric: tabular-nums; }

.xtab-row { padding: 8px 6px; border-radius: var(--radius-sm); }
.xtab-row:hover { background: rgba(0,0,0,0.02); }
.xtab-row + .xtab-row { border-top: 1px solid var(--line-2); }
.xtab-label {
  font-size: 13.2px; font-weight: 600; margin-bottom: 6px;
  display: flex; align-items: baseline; gap: 8px;
}
.xtab-label .overall {
  margin-left: auto; font-size: 11.5px; font-weight: 600; color: var(--ink-4);
  font-variant-numeric: tabular-nums;
}
.xtab-series { display: flex; flex-direction: column; gap: 3px; }
.xtab-line {
  display: grid; grid-template-columns: minmax(96px, 20%) 1fr 92px;
  align-items: center; gap: 10px;
}
.xtab-name { font-size: 12px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xtab-track { height: 15px; background: var(--bg-warm-2); border-radius: 3px; overflow: hidden; }
.xtab-fill { height: 100%; border-radius: 3px; transition: width .35s cubic-bezier(.22,.7,.3,1); }
.xtab-num {
  text-align: right; font-size: 12px; font-weight: 700;
  font-variant-numeric: tabular-nums; display: flex; gap: 6px; justify-content: flex-end;
}
.idx {
  font-size: 10.5px; font-weight: 700; padding: 1px 5px; border-radius: var(--pill);
  min-width: 38px; text-align: center;
}
.idx.up   { background: #e5f4ea; color: var(--pos); }
.idx.down { background: #fbeceb; color: var(--neg); }
.idx.flat { background: var(--bg-warm-2); color: var(--ink-4); }
.idx.na   { background: transparent; color: var(--ink-4); }

/* ---------- Stat grid ---------------------------------------------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
  gap: 12px; margin-bottom: 18px;
}
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 15px 17px; box-shadow: var(--shadow-card);
}
.stat-k {
  font-size: 11px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
  color: var(--ink-3);
}
.stat-v {
  font-size: 30px; font-weight: 700; letter-spacing: -1.1px; line-height: 1.15;
  margin-top: 6px; font-variant-numeric: tabular-nums;
}
.stat-d { font-size: 12.5px; color: var(--ink-2); margin-top: 3px; line-height: 1.4; }
.stat.accent .stat-v { color: var(--accent); }
.stat.clay .stat-v { color: var(--clay); }

/* ---------- Insight list ------------------------------------------- */
.insight {
  display: flex; gap: 13px; padding: 13px 0;
  border-top: 1px solid var(--line-2);
}
.insight:first-child { border-top: none; padding-top: 2px; }
.insight-badge {
  flex: none; width: 46px; height: 30px; border-radius: 6px;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums;
}
.insight-badge.up { background: #e5f4ea; color: var(--pos); }
.insight-badge.down { background: #fbeceb; color: var(--neg); }
.insight-body { min-width: 0; }
.insight-t { font-size: 13.8px; font-weight: 600; line-height: 1.45; }
.insight-s { font-size: 12.2px; color: var(--ink-3); margin-top: 2px; }
.insight-s b { color: var(--ink-2); font-variant-numeric: tabular-nums; }

/* ---------- Theme nav ---------------------------------------------- */
.theme-nav {
  display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 18px;
}
.theme-pill {
  padding: 6px 13px; border-radius: var(--pill);
  border: 1px solid var(--line); background: var(--surface);
  font-size: 13px; font-weight: 600; color: var(--ink-2);
  transition: all .12s;
}
.theme-pill:hover { border-color: var(--accent); color: var(--accent-ink); }
.theme-pill[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.theme-pill .cnt { opacity: .6; font-weight: 500; margin-left: 4px; }

.section-rule {
  display: flex; align-items: center; gap: 12px;
  margin: 30px 0 14px;
}
.section-rule:first-child { margin-top: 4px; }
.section-rule h2 {
  font-size: 12px; font-weight: 800; letter-spacing: 1.1px; text-transform: uppercase;
  color: var(--ink-3); margin: 0; white-space: nowrap;
}
.section-rule::after { content: ""; flex: 1; height: 1px; background: var(--line); }

/* ---------- Report builder ----------------------------------------- */
.builder-grid { display: grid; grid-template-columns: 1fr 330px; gap: 18px; align-items: start; }
@media (max-width: 1080px) { .builder-grid { grid-template-columns: 1fr; } }

.picker { max-height: 560px; overflow-y: auto; padding-right: 4px; }
.pick-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer;
}
.pick-row:hover { background: rgba(0,0,0,0.03); }
.pick-row input { accent-color: var(--accent); margin-top: 3px; flex: none; width: 15px; height: 15px; }
.pick-t { font-size: 13.4px; line-height: 1.4; }
.pick-m { font-size: 11.5px; color: var(--ink-4); margin-top: 1px; }

.summary-panel { position: sticky; top: calc(var(--header-h) + 76px); }
.sum-line { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; font-size: 13.2px; border-top: 1px solid var(--line-2); }
.sum-line:first-of-type { border-top: none; }
.sum-line .k { color: var(--ink-2); }
.sum-line .v { font-weight: 600; text-align: right; }

.empty {
  text-align: center; padding: 52px 20px; color: var(--ink-3);
  border: 1px dashed var(--line); border-radius: var(--radius-lg);
  background: var(--surface);
}
.empty-t { font-size: 15px; font-weight: 600; color: var(--ink-2); }
.empty-s { font-size: 13.5px; margin-top: 5px; }

.note {
  font-size: 12.4px; color: var(--ink-3); line-height: 1.55;
  background: var(--bg-warm-2); border-radius: var(--radius);
  padding: 11px 14px; margin-bottom: 18px;
  border-left: 3px solid var(--ink-4);
}
.note.warn { background: #fdf6e9; border-left-color: var(--gold); color: #6f5312; }
.note b { font-weight: 700; }

.small-n {
  display: inline-block; font-size: 10.5px; font-weight: 700;
  color: var(--gold); background: #fdf6e9; padding: 1px 6px;
  border-radius: var(--pill); margin-left: 6px;
}

/* ---------- Print --------------------------------------------------- */
@media print {
  :root { --header-h: 0px; }
  .masthead, .sidebar, .toolbar, .card-actions, .theme-nav, .no-print { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  .main { padding: 0; max-width: none; }
  .card {
    box-shadow: none; border: 1px solid #ddd; break-inside: avoid;
    page-break-inside: avoid; margin-bottom: 12px; padding: 14px 16px;
  }
  .print-head { display: block !important; margin-bottom: 18px; }
  .bar-fill, .xtab-fill { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}
.print-head { display: none; }
.print-head h1 { font-size: 20pt; margin: 0 0 4px; letter-spacing: -0.5px; }
.print-head .ph-sub { color: #555; font-size: 10pt; }
.print-head .ph-filters { margin-top: 8px; font-size: 9.5pt; color: #333; }

/* ---------- Responsive ---------------------------------------------- */
.mobile-filter-btn { display: none; }

@media (max-width: 900px) {
  .shell { display: block; }
  .sidebar {
    position: fixed; left: 0; top: var(--header-h); z-index: 70;
    width: min(320px, 88vw); height: calc(100vh - var(--header-h));
    transform: translateX(-102%); transition: transform .22s ease;
    box-shadow: var(--shadow-pop);
  }
  body.filters-open .sidebar { transform: translateX(0); }
  body.filters-open .scrim { display: block; }
  .scrim {
    display: none; position: fixed; inset: var(--header-h) 0 0 0;
    background: rgba(0,0,0,.28); z-index: 65;
  }
  .main { padding: 20px 16px 80px; }
  .mobile-filter-btn { display: inline-flex; }
  .tabs { margin-left: 0; }
  .brand-sub { display: none; }
  .bar-row { grid-template-columns: 1fr; gap: 3px; }
  .bar-row .bar-val { text-align: left; display: flex; gap: 8px; align-items: baseline; }
  .bar-val small { margin-top: 0; }
  .xtab-line { grid-template-columns: 84px 1fr 84px; }
  .page-title { font-size: 22px; }
  .toolbar { position: static; }
}
@media (max-width: 620px) {
  .masthead { gap: 10px; padding: 0 12px; }
  .brand-title { font-size: 13.5px; }
  .tab { padding: 6px 10px; font-size: 12.5px; }
  .n-badge { display: none; }
}
