/* CareFindings design system. Tokens first, then layout, then components. */
@font-face {
  font-family: "Inter";
  src: url("../vendor/fonts/inter-latin-wght-normal.8e433c0592f7.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --bg: #f5f7f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;
  --accent: #0d9488;
  --accent-ink: #0f766e;
  --accent-soft: #f0fdfa;
  --accent-line: #99f6e4;
  --high: #0d9488;
  --high-ink: #0f766e;
  --high-soft: #e6f7f5;
  --good: #d97706;
  --good-ink: #92400e;
  --good-soft: #fef6e7;
  --watch: #475569;
  --watch-soft: #eef2f6;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --ok: #16a34a;
  --chart-high: #0d9488;
  --chart-good: #d97706;
  --focus: 0 0 0 3px rgba(13, 148, 136, .35);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --shadow-lg: 0 24px 60px -20px rgba(15, 23, 42, .35);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar: 232px;
  color-scheme: light;
}

/* Dark theme: data-theme is set before first paint from the saved choice or the OS setting. */
:root[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111a2e;
  --surface-2: #0f172a;
  --surface-3: #16213a;
  --line: #1f2b44;
  --line-strong: #2c3a57;
  --ink: #e6ebf3;
  --ink-2: #c3ccda;
  --muted: #8a97ad;
  --faint: #5f6c84;
  --accent: #2dd4bf;
  --accent-ink: #5eead4;
  --accent-soft: #0f2a2e;
  --accent-line: #134e4a;
  --high: #2dd4bf;
  --high-ink: #5eead4;
  --high-soft: #0f2a2e;
  --good: #fbbf24;
  --good-ink: #fcd34d;
  --good-soft: #2a2110;
  --watch: #94a3b8;
  --watch-soft: #1a2438;
  --danger: #f87171;
  --danger-soft: #2a1414;
  --ok: #4ade80;
  --chart-high: #0f9e90;
  --chart-good: #c97a0a;
  --focus: 0 0 0 3px rgba(45, 212, 191, .35);
  --shadow-sm: none;
  --shadow: 0 1px 0 rgba(255, 255, 255, .02), 0 10px 30px -18px rgba(0, 0, 0, .8);
  --shadow-lg: 0 30px 70px -20px rgba(0, 0, 0, .8);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  font-feature-settings: "cv11", "ss01", "tnum" 0;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent-ink); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
p { margin: 0; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.xsmall { font-size: 12px; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.stack > * + * { margin-top: var(--gap, 12px); }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
[hidden] { display: none !important; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
svg.i.sm { width: 15px; height: 15px; }

/* ---------------------------------------------------------------- shell */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
  padding: 18px 14px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; font-weight: 700; font-size: 16px; letter-spacing: -.02em; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(145deg, #0f172a, #134e4a); color: #5eead4;
}
:root[data-theme="dark"] .brand-mark { background: linear-gradient(145deg, #134e4a, #0f766e); color: #ccfbf1; }
.brand small { display: block; font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: 0; }
.nav-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); padding: 14px 10px 6px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 9px;
  color: var(--ink-2); font-weight: 500; font-size: 14px;
}
.nav a:hover { background: var(--surface-3); color: var(--ink); }
.nav a.active { background: var(--accent-soft); color: var(--accent-ink); }
.nav a .count { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--muted); }
.nav a.active .count { color: var(--accent-ink); }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 28px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar .search { flex: 1; max-width: 420px; position: relative; }
.topbar .search input { padding-left: 36px; background: var(--surface); }
.topbar .search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--faint); }
.content { padding: 26px 28px 60px; max-width: 1360px; width: 100%; margin: 0 auto; }
.content.bleed { padding: 0; max-width: none; flex: 1; display: flex; }

.page-head { display: flex; align-items: flex-end; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; font-weight: 700; }
.page-head p { color: var(--muted); margin-top: 4px; }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--accent-ink); }

.mobile-nav { display: none; }

/* ------------------------------------------------------------- controls */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: 9px;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); color: var(--ink); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.btn.primary:hover { background: var(--ink-2); border-color: var(--ink-2); color: var(--surface); }
:root[data-theme="dark"] .btn.primary { background: var(--accent); border-color: var(--accent); color: #042f2e; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 38px; padding: 0; }
.btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-ink); }

input[type="text"], input[type="search"], input[type="number"], input[type="email"], input[type="password"], select, textarea {
  width: 100%; height: 38px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: 9px;
  background: var(--surface); color: var(--ink);
  font: inherit; font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
label.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.check { display: flex; align-items: center; gap: 9px; font-size: 14px; color: var(--ink-2); cursor: pointer; padding: 3px 0; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.check .n { margin-left: auto; font-size: 12px; color: var(--faint); }

.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: 10px; border: 1px solid var(--line); }
.seg a, .seg button { border: 0; background: transparent; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); padding: 6px 12px; border-radius: 7px; cursor: pointer; }
.seg a.on, .seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---------------------------------------------------------------- cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-head h2, .card-head h3 { font-size: 15px; font-weight: 650; }
.card-body { padding: 18px 20px; }
.section-title { font-size: 13px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 10px; }

.grid { display: grid; gap: 16px; }
.grid.kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.two { grid-template-columns: minmax(0, 1.65fr) minmax(300px, 1fr); align-items: start; }
.grid.halves { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.kpi { padding: 18px 20px; display: grid; gap: 6px; position: relative; overflow: hidden; }
.kpi .label { font-size: 13px; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.kpi .value { font-size: 32px; font-weight: 700; letter-spacing: -.03em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 13px; color: var(--muted); }
.kpi .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.kpi.high .dot { background: var(--high); }
.kpi.good .dot { background: var(--good); }
.kpi.watch .dot { background: var(--watch); }

/* ---------------------------------------------------------------- chips */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--ink-2); border: 1px solid var(--line);
}
.chip svg.i { width: 13px; height: 13px; }
.tier { height: 26px; padding: 0 10px; border: 0; font-weight: 700; letter-spacing: .01em; }
.tier::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tier-high { background: var(--high-soft); color: var(--high-ink); }
.tier-good { background: var(--good-soft); color: var(--good-ink); }
.tier-watch { background: var(--watch-soft); color: var(--watch); }
.ind { background: transparent; }
.ind.on { background: var(--surface); border-color: var(--line-strong); color: var(--ink); }
.ind.off { color: var(--faint); border-style: dashed; }
.ind.primary.on { border-color: var(--accent-line); background: var(--accent-soft); color: var(--accent-ink); }

.status-pill { display: inline-flex; align-items: center; gap: 8px; height: 30px; padding: 0 12px; border-radius: 999px; font-size: 13px; font-weight: 500; color: var(--ink-2); background: var(--surface); border: 1px solid var(--line); }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(22, 163, 74, .5); animation: pulse 2.4s infinite; }
.pulse.warn { background: var(--good); animation: none; }
.pulse.err { background: var(--danger); animation: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(22,163,74,.45); } 70% { box-shadow: 0 0 0 8px rgba(22,163,74,0); } 100% { box-shadow: 0 0 0 0 rgba(22,163,74,0); } }
@media (prefers-reduced-motion: reduce) { .pulse { animation: none; } * { transition: none !important; } }

.bell { position: relative; }
.bell .badge {
  position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  display: grid; place-items: center; border: 2px solid var(--bg);
}

/* -------------------------------------------------------------- strength */
.strength { display: grid; gap: 5px; min-width: 96px; }
.strength .top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.strength .top b { color: var(--ink); font-size: 13px; font-variant-numeric: tabular-nums; }
.meter { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 999px; background: var(--good); }
.meter.high span { background: var(--high); }

/* ----------------------------------------------------------- leads page */
.leads-layout { display: grid; grid-template-columns: 272px minmax(0, 1fr); gap: 22px; align-items: start; }
.filters { position: sticky; top: 78px; max-height: calc(100vh - 96px); overflow: auto; padding: 18px; }
.filters .group { padding: 14px 0; border-top: 1px solid var(--line); }
.filters .group:first-of-type { border-top: 0; padding-top: 4px; }
.filters .group > .title { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); margin-bottom: 8px; }
.filters .range { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

.results-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.results-head .count { font-weight: 650; }
.results-head select { width: auto; min-width: 190px; }

.lead-list { display: grid; gap: 10px; container-type: inline-size; }
.lead-card {
  display: grid; grid-template-columns: minmax(0, 1fr) 150px; gap: 18px; align-items: center;
  padding: 16px 18px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  transition: border-color .15s, box-shadow .15s, transform .15s;
  position: relative;
}
.lead-card:hover { border-color: var(--line-strong); box-shadow: var(--shadow); color: inherit; }
.lead-card.high { box-shadow: inset 3px 0 0 var(--high); }
.lead-card.good { box-shadow: inset 3px 0 0 var(--good); }
.lead-card.watch { box-shadow: inset 3px 0 0 var(--watch); }
.lead-card.high:hover { box-shadow: inset 3px 0 0 var(--high), var(--shadow); }
.lead-card.good:hover { box-shadow: inset 3px 0 0 var(--good), var(--shadow); }
.lead-card h3 { font-size: 16px; font-weight: 650; }
.lead-card .meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); margin-top: 3px; }
.lead-card .meta span { display: inline-flex; align-items: center; gap: 5px; }
.lead-card .why { font-size: 14px; color: var(--ink-2); margin-top: 8px; }
.lead-card .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.lead-card .aside { display: grid; gap: 10px; justify-items: end; text-align: right; }
.lead-card .fresh { font-size: 12px; color: var(--muted); }
.lead-card .fresh b { color: var(--ink); font-weight: 600; }
.new-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; vertical-align: middle; }

@container (max-width: 560px) {
  .lead-card { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .lead-card .aside { justify-items: start; text-align: left; grid-auto-flow: column; justify-content: space-between; align-items: center; }
}
.pager { display: flex; justify-content: center; gap: 8px; margin-top: 18px; align-items: center; }

/* ------------------------------------------------------------- detail */
.detail-head { display: grid; gap: 14px; margin-bottom: 20px; }
.crumbs { font-size: 13px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.detail-title { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.detail-title h1 { font-size: 28px; font-weight: 750; letter-spacing: -.025em; }
.detail-title .sub { color: var(--muted); margin-top: 4px; }
.hero-why {
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
}
.hero-why.high { background: var(--high-soft); border-color: var(--accent-line); }
.hero-why.good { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 35%, transparent); }
.hero-why .text { font-size: 15px; font-weight: 600; flex: 1; min-width: 220px; }
.hero-why .facts { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.hero-why .facts b { display: block; font-size: 16px; color: var(--ink); font-variant-numeric: tabular-nums; }

.ai-card .card-head { background: linear-gradient(180deg, var(--accent-soft), transparent); }
.ai-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 650; color: var(--accent-ink); }
.ai-body { display: grid; gap: 20px; }
.ai-body .lede { font-size: 16px; line-height: 1.6; color: var(--ink); }
.visit-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.visit-list li { display: grid; grid-template-columns: 22px 1fr; gap: 8px; font-size: 14px; color: var(--ink-2); }
.visit-list li svg { color: var(--accent); margin-top: 2px; }

.low-list { display: grid; gap: 8px; }
.low-item { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: 12px; padding: 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); }
.score-box { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-weight: 750; font-size: 15px; background: var(--good-soft); color: var(--good-ink); }
.score-box.s1 { background: var(--danger-soft); color: var(--danger); }
.score-box.s0 { background: var(--surface-3); color: var(--muted); font-size: 11px; }
.low-item .name { font-weight: 600; font-size: 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.low-item .note { font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.crit-tag { font-size: 11px; font-weight: 650; padding: 1px 7px; border-radius: 6px; background: var(--surface-3); color: var(--muted); }
.crit-tag.laundry, .crit-tag.ipc, .crit-tag.staffing { background: var(--accent-soft); color: var(--accent-ink); }

.evidence-group { padding: 16px 20px; border-top: 1px solid var(--line); }
.evidence-group:first-child { border-top: 0; }
.evidence-group .gh { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.evidence-group .gh h3 { font-size: 14px; font-weight: 650; }
blockquote.q {
  margin: 8px 0 0; padding: 10px 14px; border-left: 3px solid var(--line-strong);
  background: var(--surface-2); border-radius: 0 9px 9px 0;
  font-size: 14px; line-height: 1.55; color: var(--ink-2);
}
blockquote.q.hit { border-left-color: var(--accent); }
blockquote.q cite { display: block; margin-top: 6px; font-size: 12px; font-style: normal; color: var(--muted); }
.empty-note { font-size: 14px; color: var(--muted); }

.facts-list { display: grid; gap: 0; margin: 0; }
.facts-list > div { display: grid; grid-template-columns: 118px minmax(0, 1fr); gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; }
.facts-list > div:first-child { border-top: 0; }
.facts-list dt { color: var(--muted); }
.facts-list dd { margin: 0; color: var(--ink); overflow-wrap: anywhere; }

.domain-bars { display: grid; gap: 10px; }
.domain-bar { display: grid; grid-template-columns: 80px minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: 13px; }
.domain-bar .track { height: 8px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.domain-bar .fill { height: 100%; border-radius: 999px; background: var(--faint); }
.domain-bar .fill.r-good, .domain-bar .fill.r-outstanding { background: var(--high); }
.domain-bar .fill.r-requires-improvement { background: var(--good); }
.domain-bar .fill.r-inadequate { background: var(--danger); }
.domain-bar .r { text-align: right; color: var(--muted); font-size: 12px; white-space: nowrap; }

.breakdown { display: grid; gap: 6px; font-size: 14px; }
.breakdown div { display: flex; justify-content: space-between; gap: 10px; }
.breakdown b { font-variant-numeric: tabular-nums; }
.breakdown .total { border-top: 1px solid var(--line); padding-top: 8px; margin-top: 2px; font-weight: 700; }

.callout { padding: 12px 14px; border-radius: 10px; font-size: 14px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-2); display: flex; gap: 10px; }
.callout.warn { background: var(--good-soft); border-color: color-mix(in srgb, var(--good) 30%, transparent); color: var(--good-ink); }
.callout.err { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); }

/* ------------------------------------------------------------ skeleton */
.skeleton { background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.4s infinite linear; border-radius: 8px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.htmx-request .results-body { opacity: .55; transition: opacity .2s; }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line-strong); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 48px 20px; }
.empty .art { width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 16px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent-ink); }
.empty h3 { font-size: 17px; }
.empty p { color: var(--muted); margin: 6px auto 16px; max-width: 460px; }

/* ----------------------------------------------------------------- feed */
.feed { display: grid; }
.feed a { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 12px 20px; border-top: 1px solid var(--line); }
.feed a:first-child { border-top: 0; }
.feed a:hover { background: var(--surface-2); color: inherit; }
.feed .t { font-weight: 600; font-size: 14px; }
.feed .s { font-size: 13px; color: var(--muted); }
.feed.unread a.unread { background: color-mix(in srgb, var(--accent-soft) 60%, transparent); }

/* ------------------------------------------------------------------ map */
.map-wrap { position: relative; flex: 1; min-height: calc(100vh - 63px); display: flex; }
#map { flex: 1; min-height: calc(100vh - 63px); background: var(--surface-3); z-index: 0; }
.map-panel {
  position: absolute; top: 16px; left: 16px; z-index: 500; width: 300px;
  max-height: calc(100% - 32px); overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 16px;
}
.map-toggle { display: none !important; }
.map-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.map-legend span { display: inline-flex; align-items: center; gap: 6px; }
.map-legend i { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--line-strong); }
.pin { width: 18px; height: 18px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 2px 6px rgba(15, 23, 42, .35); }
.pin.high { background: #0d9488; }
.pin.good { background: #d97706; }
.pin.watch { background: #64748b; }
.leaflet-popup-content-wrapper { border-radius: 12px; box-shadow: var(--shadow-lg); }
.leaflet-popup-content { margin: 14px 16px; font-family: var(--font); }
.popup h4 { font-size: 15px; margin: 6px 0 2px; }
.popup .s { font-size: 12px; color: #64748b; }
.popup .w { font-size: 13px; margin: 8px 0 10px; color: #334155; }
.popup a.btn { height: 32px; font-size: 13px; }
.marker-cluster { background: rgba(13, 148, 136, .2) !important; border-radius: 50%; }
.marker-cluster div { width: 30px; height: 30px; margin: 5px 0 0 5px; border-radius: 50%; text-align: center; background: #0f766e !important; color: #fff; font: 700 12px/30px var(--font) !important; box-shadow: 0 2px 6px rgba(15, 23, 42, .3); }
.marker-cluster span { line-height: 30px; }
/* The basemap is already muted (light and dark canvas), so pins carry the colour. */
.leaflet-container { background: #e5e5e3; }
:root[data-theme="dark"] .leaflet-container { background: #242424; }
.leaflet-container .leaflet-control-attribution { font-size: 10px; }
.marker-cluster.has-high div { background: #0d9488 !important; }
.marker-cluster.only-good { background: rgba(217, 119, 6, .2) !important; }
.marker-cluster.only-good div { background: #b45309 !important; }

/* ----------------------------------------------------------- data health */
.bars { display: grid; gap: 12px; }
.bar-row { display: grid; grid-template-columns: 200px minmax(0, 1fr) 56px; gap: 12px; align-items: center; font-size: 14px; }
.bar-row .track { height: 10px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.bar-row .fill { height: 100%; background: var(--accent); border-radius: 999px; }
.bar-row .v { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--line); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .seg-high { fill: var(--chart-high); }
.chart .seg-good { fill: var(--chart-good); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + g rect, .chart g.col:hover rect { opacity: .85; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5;
  padding: 8px 10px; border-radius: 8px; font-size: 12px;
  background: var(--ink); color: var(--surface); box-shadow: var(--shadow-lg);
  transform: translate(-50%, calc(-100% - 10px)); white-space: nowrap;
}
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }

table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 12px; font-weight: 650; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
table.data td { padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
.ok-text { color: var(--ok); font-weight: 600; }
.err-text { color: var(--danger); font-weight: 600; }

/* ---------------------------------------------------------------- auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1200px 600px at 10% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.auth .card { width: 100%; max-width: 400px; padding: 30px; box-shadow: var(--shadow-lg); }
.auth .brand { padding: 0 0 20px; }

/* ------------------------------------------------------------- messages */
.toast-stack { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 10px; z-index: 1000; }
.toast { padding: 12px 16px; border-radius: 10px; background: var(--ink); color: var(--surface); font-size: 14px; box-shadow: var(--shadow-lg); animation: rise .25s ease-out; max-width: 380px; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------ responsive */
.filter-toggle { display: none !important; }
.brand-mini { display: none !important; align-items: center; gap: 8px; font-weight: 700; }

@media (max-width: 1180px) {
  .grid.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.two { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
  .leads-layout { grid-template-columns: minmax(0, 1fr); }
  .filters { position: static; max-height: none; }
  .filters.collapsible:not(.open) .group { display: none; }
  .filter-toggle { display: inline-flex !important; }
}
@media (max-width: 860px) {
  .grid.halves { grid-template-columns: minmax(0, 1fr); }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { display: none; }
  .topbar { padding: 10px 16px; }
  .content { padding: 18px 16px 90px; }
  .mobile-nav {
    display: grid; grid-template-columns: repeat(5, 1fr);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 900;
    background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .mobile-nav a { display: grid; justify-items: center; gap: 2px; font-size: 11px; font-weight: 600; color: var(--muted); padding: 4px 0; }
  .mobile-nav a.active { color: var(--accent-ink); }
  .topbar .brand-mini { display: flex !important; }
  .map-panel { left: 10px; right: 10px; width: auto; top: 10px; max-height: 60%; padding: 12px 14px; }
  .map-panel:not(.open) .map-more { display: none; }
  .map-panel .map-toggle { display: inline-flex !important; }
  .content.bleed { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .map-wrap, #map { min-height: calc(100vh - 58px - 64px); }
  .lead-card { grid-template-columns: minmax(0, 1fr); }
  .lead-card .aside { justify-items: start; text-align: left; grid-auto-flow: column; justify-content: space-between; align-items: center; }
  .bar-row { grid-template-columns: 1fr 48px; }
  .bar-row .track { grid-column: 1 / -1; grid-row: 2; }
  .detail-title h1 { font-size: 22px; }
  .topbar .status-pill .label { display: none; }
}
@media (max-width: 520px) {
  .grid.kpis, .grid.halves { grid-template-columns: minmax(0, 1fr); }
  .facts-list > div { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .domain-bar { grid-template-columns: 70px minmax(0, 1fr) auto; }
}
