/* =============================================================================
   MNH QI Dashboard — styles
   ========================================================================== */
:root {
  --green: #1aab57;
  --green-bg: #e6f7ee;
  --yellow: #e0a106;
  --yellow-bg: #fdf4dc;
  --red: #e23b3b;
  --red-bg: #fce8e8;
  --ink: #1d2733;
  --muted: #66758a;
  --line: #e3e8ef;
  --panel: #ffffff;
  --bg: #f4f6fa;
  --brand: #15489e;
  --brand-2: #2f6fd0;
  --shadow: 0 1px 3px rgba(16, 38, 73, .08), 0 4px 16px rgba(16, 38, 73, .06);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
}
a { color: var(--brand-2); }

/* ---------- Header ---------- */
header.app {
  background: linear-gradient(120deg, var(--brand), var(--brand-2));
  color: #fff;
  padding: 16px 24px;
  box-shadow: var(--shadow);
}
header.app .row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
header.app h1 { font-size: 1.2rem; margin: 0; font-weight: 700; }
header.app .sub { font-size: .8rem; opacity: .85; margin-top: 2px; }
header.app .spacer { flex: 1; }
.status-line { font-size: .78rem; opacity: .9; }
button.refresh {
  background: rgba(255,255,255,.18); color: #fff; border: 1px solid rgba(255,255,255,.4);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: .82rem; font-weight: 600;
}
button.refresh:hover { background: rgba(255,255,255,.3); }

/* ---------- Tabs ---------- */
nav.tabs {
  display: flex; gap: 4px; background: var(--panel); padding: 0 16px;
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
  overflow-x: auto;
}
nav.tabs a {
  padding: 13px 16px; text-decoration: none; color: var(--muted);
  font-weight: 600; border-bottom: 3px solid transparent; white-space: nowrap;
}
nav.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
nav.tabs a:hover { color: var(--brand); }

/* ---------- Layout ---------- */
main { padding: 20px 24px 60px; max-width: 1280px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }
h2.section { font-size: 1.05rem; margin: 4px 0 14px; }
h3.sub { font-size: .92rem; margin: 22px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); margin-bottom: 18px;
}

/* ---------- Filters ---------- */
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { display: flex; flex-direction: column; gap: 4px; }
.filters label { font-size: .72rem; color: var(--muted); font-weight: 600; text-transform: uppercase; }
.filters select {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  font-size: .85rem; min-width: 150px;
}
.filters button.clear {
  padding: 8px 12px; border: 1px solid var(--line); background: #fff; border-radius: 8px;
  cursor: pointer; font-size: .82rem; color: var(--muted);
}

/* ---------- KPI cards ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi .val { font-size: 1.8rem; font-weight: 800; line-height: 1; }
.kpi .lbl { font-size: .76rem; color: var(--muted); margin-top: 6px; text-transform: uppercase; letter-spacing: .03em; }
.kpi.green .val { color: var(--green); }
.kpi.yellow .val { color: var(--yellow); }
.kpi.red .val { color: var(--red); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--brand); }
tbody tr:hover { background: #f8fafc; }
tr.clickable { cursor: pointer; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Status chips & traffic lights ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: .75rem; font-weight: 700; }
.chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; }
.chip.green { background: var(--green-bg); color: var(--green); }
.chip.green::before { background: var(--green); }
.chip.yellow { background: var(--yellow-bg); color: #9a6e04; }
.chip.yellow::before { background: var(--yellow); }
.chip.red { background: var(--red-bg); color: var(--red); }
.chip.red::before { background: var(--red); }
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot.green { background: var(--green); }
.dot.yellow { background: var(--yellow); }
.dot.red { background: var(--red); }

/* ---------- Two-column grids ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.grid-2 > .panel { margin-bottom: 0; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Map ---------- */
#map { height: 420px; border-radius: var(--radius); border: 1px solid var(--line); }

/* ---------- Scorecard ---------- */
.facility-head { display: flex; align-items: flex-start; gap: 20px; flex-wrap: wrap; }
.facility-head .meta { flex: 1; min-width: 240px; }
.facility-head h2 { margin: 0 0 4px; font-size: 1.3rem; }
.facility-head .meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 6px 18px; margin-top: 10px; font-size: .84rem; }
.facility-head .meta-grid b { color: var(--muted); font-weight: 600; }
.score-badge { text-align: center; padding: 14px 22px; border-radius: var(--radius); color: #fff; min-width: 150px; }
.score-badge .big { font-size: 2.2rem; font-weight: 800; line-height: 1; }
.score-badge .pct { font-size: .95rem; opacity: .95; }
.score-badge .lbl { font-size: .75rem; opacity: .9; margin-top: 4px; }
.score-badge.green { background: var(--green); }
.score-badge.yellow { background: var(--yellow); }
.score-badge.red { background: var(--red); }
.badge-stack { display: flex; gap: 12px; flex-wrap: wrap; }
.badge-cap { font-size: .68rem; text-transform: uppercase; letter-spacing: .04em; opacity: .9; margin-bottom: 4px; }
.part-score { font-weight: 700; font-size: .8rem; margin-left: 8px; vertical-align: middle; }
h2.section .chip { vertical-align: middle; }

/* Domain bar list */
.dombar { display: grid; grid-template-columns: 220px 1fr 56px 116px; align-items: center; gap: 10px; margin: 6px 0; padding: 5px 8px; border-radius: 8px; font-size: .82rem; border-left: 4px solid transparent; }
.dombar.green { background: var(--green-bg); border-left-color: var(--green); }
.dombar.yellow { background: var(--yellow-bg); border-left-color: var(--yellow); }
.dombar.red { background: var(--red-bg); border-left-color: var(--red); }
.dombar .track { background: rgba(255,255,255,.6); border-radius: 6px; height: 16px; overflow: hidden; }
.dombar .fill { height: 100%; border-radius: 6px; }
.dombar .fill.green { background: var(--green); }
.dombar .fill.yellow { background: var(--yellow); }
.dombar .fill.red { background: var(--red); }
.dombar .sc { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }
.dombar .chip { justify-self: start; }
@media (max-width: 640px){
  .dombar { grid-template-columns: 1fr 56px; }
  .dombar .track { grid-column: 1 / -1; order: 3; }
  .dombar .chip { grid-column: 2; order: 2; }
}

/* Signal functions */
.sf-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 10px; }
.sf-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.sf-card.green { background: var(--green-bg); border-color: #b9e6cc; }
.sf-card.red { background: var(--red-bg); border-color: #f2c2c2; }
.sf-card .name { font-weight: 700; font-size: .82rem; }
.sf-card .sc { font-size: 1.1rem; font-weight: 800; margin-top: 4px; }

/* Part C stat grid */
.statgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fbfcfe; }
.stat .v { font-size: 1.5rem; font-weight: 800; }
.stat .k { font-size: .74rem; color: var(--muted); margin-top: 2px; }

/* warning banner */
.warn { background: var(--red-bg); border: 1px solid #f2c2c2; color: #9c2020; padding: 12px 14px; border-radius: 10px; font-weight: 600; margin-top: 12px; }
.note-banner { background: var(--yellow-bg); border: 1px solid #f0dca0; color: #8a6403; padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: .85rem; }

/* gap list */
.gaplist { list-style: none; padding: 0; margin: 0; }
.gaplist li { display: flex; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .85rem; }
.gaplist .bar { flex: 1; background: #eef1f6; height: 14px; border-radius: 6px; overflow: hidden; }
.gaplist .bar > span { display: block; height: 100%; background: var(--red); }
.gaplist .cnt { width: 90px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.gaplist .qd { min-width: 56px; font-weight: 700; color: var(--brand); }

/* misc */
.muted { color: var(--muted); }
.center { text-align: center; }
.loading, .empty { text-align: center; padding: 60px 20px; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 4px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-box { background: var(--red-bg); border: 1px solid #f2c2c2; color: #9c2020; padding: 16px; border-radius: var(--radius); }
.picker { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.picker select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; min-width: 240px; font-size: .85rem; }
canvas { max-width: 100%; }
.chart-wrap { position: relative; height: 320px; }
.chart-wrap.tall { height: 420px; }
