/* MSS dashboard — Health Office, Sankhuwasabha.
   Palette values come from the dataviz reference palette and are validated;
   see README before changing any --series/--seq/--status token. */

:root {
  color-scheme: light;

  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  /* Categorical — sections I / II / III (slots 1-3, all-pairs validated) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;

  /* Sequential blue, for score magnitude */
  --seq-100: #cde2fb;
  --seq-200: #9ec5f4;
  --seq-300: #6da7ec;
  --seq-400: #3987e5;
  --seq-450: #2a78d6;
  --seq-500: #256abf;
  --seq-600: #184f95;
  --seq-700: #0d366b;

  /* Status — fixed, never themed. Always paired with an icon + label. */
  --status-good: #0ca30c;
  --status-warning: #fab219;
  --status-critical: #d03b3b;

  --radius: 10px;
  --gap: 1rem;
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans Devanagari", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: 1180px; margin: 0 auto; padding: 0 1rem 4rem; }

/* ---------- header ---------- */

.masthead {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  padding: 1.1rem 0;
  margin-bottom: 1.5rem;
}
.masthead .wrap {
  display: flex; align-items: center; gap: 1rem;
  flex-wrap: wrap; padding-bottom: 0;
}
.brand { margin-right: auto; }
.brand h1 { margin: 0; font-size: 1.3rem; letter-spacing: -0.01em; }
.brand p { margin: 0.1rem 0 0; color: var(--text-secondary); font-size: 0.86rem; }

.controls { display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap; }

button, select, input[type="search"] {
  font: inherit;
  color: var(--text-primary);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
}
input[type="search"] { cursor: text; min-width: min(260px, 100%); }
button:hover, select:hover { border-color: var(--baseline); }
button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--series-1); outline-offset: 2px;
}

.toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.toggle button { border: 0; border-radius: 0; padding: 0.4rem 0.65rem; background: transparent; }
.toggle button[aria-pressed="true"] { background: var(--series-1); color: #fff; }

/* ---------- cards ---------- */

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  margin-bottom: var(--gap);
}
.card > h2 {
  margin: 0 0 0.15rem; font-size: 1rem; letter-spacing: -0.01em;
  text-wrap: balance;
}
.card > h2 + .hint { margin: 0 0 0.9rem; }
.hint { color: var(--text-muted); font-size: 0.82rem; margin: 0 0 0.8rem; }

/* ---------- KPI row ---------- */

.kpis {
  display: grid; gap: var(--gap); margin-bottom: var(--gap);
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
}
.kpi { background: var(--surface-1); border: 1px solid var(--border);
       border-radius: var(--radius); padding: 0.9rem 1.1rem; }
.kpi .label { color: var(--text-secondary); font-size: 0.8rem; }
.kpi .value { font-size: 2.1rem; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; }
.kpi .value.sm { font-size: 1.15rem; font-weight: 600; line-height: 1.35; padding-top: 0.35rem; }
.kpi .sub { color: var(--text-muted); font-size: 0.78rem; }

/* ---------- ranked bars ---------- */

.rank { display: flex; flex-direction: column; gap: 2px; }
.rank-row {
  display: grid; grid-template-columns: minmax(120px, 1.1fr) 1fr auto auto;
  gap: 0.75rem; align-items: center;
  padding: 0.3rem 0.4rem; border-radius: 6px;
  background: none; border: 0; width: 100%; text-align: left; cursor: pointer;
}
.rank-row:hover { background: color-mix(in srgb, var(--series-1) 8%, transparent); }
/* These rows drill into a facility, so say so rather than relying on hover. */
.rank-row .chev { color: var(--text-muted); font-size: 0.9rem; line-height: 1; }
.rank-row:hover .chev { color: var(--series-1); }
.rank-name { font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-name .muni { color: var(--text-muted); font-size: 0.76rem; }
.rank-track { background: var(--gridline); border-radius: 4px; height: 16px; position: relative; }
.rank-fill { height: 100%; border-radius: 4px; }
.rank-val { font-variant-numeric: tabular-nums; font-size: 0.86rem; min-width: 3.6em; text-align: right; }

/* ---------- section comparison ---------- */

.legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.8rem; }
.legend.bands { margin-bottom: 0; gap: 0.5rem 1.3rem; }
.legend.bands span { font-variant-numeric: tabular-nums; }

/* Band label beside the big facility score. */
.chip {
  display: inline-block; margin-top: 0.35rem;
  padding: 0.12rem 0.5rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--page);
  color: var(--text-secondary); font-size: 0.76rem;
}
/* "may not apply" marker — never carries meaning on its own, always beside text. */
.flag {
  display: inline-block; padding: 0.05rem 0.4rem; border-radius: 999px;
  border: 1px dashed var(--baseline); color: var(--text-muted);
  font-size: 0.7rem; white-space: nowrap;
}
.legend span { display: inline-flex; align-items: center; gap: 0.4rem;
               font-size: 0.82rem; color: var(--text-secondary); }
.swatch { width: 11px; height: 11px; border-radius: 3px; flex: none; }

.sect-row { margin-bottom: 0.7rem; }
.sect-row .rank-name { margin-bottom: 3px; }
/* Grouped bars, stacked vertically with the 2px surface gap between adjacent
   fills that the mark spec calls for. */
.sect-bars { display: flex; flex-direction: column; gap: 2px; }
.sect-bar {
  height: 15px; border-radius: 4px; display: flex; align-items: center;
  justify-content: flex-end; padding-right: 5px; min-width: 2.6rem;
  font-size: 0.71rem; color: #fff; font-variant-numeric: tabular-nums;
}

/* ---------- heatmap ---------- */

.heat-scroll { overflow-x: auto; padding-bottom: 0.3rem; }
.heat { border-collapse: separate; border-spacing: 2px; font-size: 0.78rem; }
.heat th { font-weight: 500; color: var(--text-secondary); text-align: left; padding: 0 0.4rem; }
.heat thead th { vertical-align: bottom; height: 8.5rem; padding: 0; }
.heat thead th span {
  display: block; writing-mode: vertical-rl; transform: rotate(180deg);
  white-space: nowrap; max-height: 8.2rem; overflow: hidden; font-size: 0.76rem;
}
.heat tbody th { white-space: nowrap; max-width: 15rem; overflow: hidden; text-overflow: ellipsis; }
.heat td {
  width: 34px; height: 26px; text-align: center; border-radius: 4px;
  font-variant-numeric: tabular-nums; font-size: 0.72rem;
}
.heat td.na { background: var(--gridline); color: var(--text-muted); }

/* ---------- standards list ---------- */

.area-block { border-top: 1px solid var(--border); padding-top: 0.8rem; margin-top: 0.8rem; }
.area-block:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.area-head { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.area-head h3 { margin: 0; font-size: 0.92rem; }
.area-head .pct { color: var(--text-secondary); font-size: 0.82rem; font-variant-numeric: tabular-nums; }

.meter { height: 6px; border-radius: 3px; background: var(--gridline); flex: 1 1 90px; min-width: 90px; }
.meter i { display: block; height: 100%; border-radius: 3px; background: var(--series-1); }

.std { display: grid; grid-template-columns: auto 4.6rem 1fr auto; gap: 0.6rem;
       padding: 0.35rem 0; border-top: 1px solid var(--gridline); align-items: start;
       font-size: 0.85rem; }
.std:first-child { border-top: 0; }
.std .icon { font-weight: 700; line-height: 1.5; }
.std .code { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 0.8rem; }
.std .pts { color: var(--text-secondary); font-variant-numeric: tabular-nums; font-size: 0.8rem; white-space: nowrap; }
.std.met .icon { color: var(--status-good); }
.std.partial .icon { color: var(--status-warning); }
.std.unmet .icon { color: var(--status-critical); }
.std.none .icon { color: var(--text-muted); }
.std .tag { color: var(--text-muted); font-size: 0.72rem; }

/* ---------- tables ---------- */

table.data { border-collapse: collapse; width: 100%; font-size: 0.84rem; }
table.data th, table.data td {
  text-align: left; padding: 0.45rem 0.6rem; border-bottom: 1px solid var(--gridline);
  vertical-align: top;
}
table.data th { color: var(--text-secondary); font-weight: 600; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

/* ---------- facility detail ---------- */

.crumb { display: inline-flex; align-items: center; gap: 0.35rem; margin-bottom: 0.8rem;
         color: var(--series-1); background: none; border: 0; padding: 0; font-size: 0.88rem; }
.crumb:hover { text-decoration: underline; }

.facts { display: flex; flex-wrap: wrap; gap: 0.4rem 1.6rem; margin: 0.5rem 0 0; padding: 0; list-style: none; }
.facts li { font-size: 0.84rem; color: var(--text-secondary); }
.facts b { color: var(--text-primary); font-weight: 600; }

.detail-head { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-start; }
.detail-head .score { margin-left: auto; text-align: right; }
.detail-head .score .value { font-size: 2.6rem; font-weight: 600; letter-spacing: -0.02em; line-height: 1; }
.detail-head .score .label { color: var(--text-secondary); font-size: 0.8rem; }

.filters { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; margin-bottom: 0.9rem; }
label.check { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; cursor: pointer; }

.empty { color: var(--text-muted); font-size: 0.88rem; padding: 0.6rem 0; }

footer.site { color: var(--text-muted); font-size: 0.79rem; text-align: center;
              padding: 1.5rem 1rem; border-top: 1px solid var(--border); margin-top: 1rem; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

@media (max-width: 640px) {
  .rank-row { grid-template-columns: 1fr auto; }
  .rank-row .rank-track { grid-column: 1 / -1; }
  .std { grid-template-columns: auto 1fr; }
  .std .code { grid-row: 1; }
  .std .pts { grid-column: 2; }
}

@media print {
  .controls, .filters, .crumb, button { display: none !important; }
  body { background: #fff; }
  .card { break-inside: avoid; border-color: #ccc; }
}
