/* =====================================================================
   app.css — NCDs Phrae Dashboard 2027
   ธีมขาว · 1 ตัวชี้วัด = 1 แถว (แผนที่ 5 / กราฟ 7) · มือถือซ้อน แผนที่→กราฟ
   ===================================================================== */

/* ---------- tokens ---------- */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #0f172a;
  --ink-2: #475569;
  --muted: #94a3b8;
  --line: #e5e9f0;
  --line-2: #eef1f5;

  --brand: #123f8a;
  --brand-2: #2a78d6;
  --dm: #2a78d6;
  --ht: #1baf7a;

  --good: #0ca30c;
  --warn: #d98a00;
  --bad: #d03b3b;
  --target: #b42318;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --shadow-hover: 0 2px 4px rgba(15, 23, 42, .05), 0 16px 32px -14px rgba(15, 23, 42, .18);

  --font-head: 'IBM Plex Sans Thai', 'Sarabun', Tahoma, sans-serif;
  --font-body: 'Sarabun', 'IBM Plex Sans Thai', Tahoma, sans-serif;

  --row-h: 420px;
  --gutter: 16px;
  --container: 1400px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); overflow-x: hidden;
  font-family: var(--font-body); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--font-head); margin: 0; font-weight: 600; letter-spacing: -.01em; }
a { color: var(--brand-2); }
code { font-family: ui-monospace, Consolas, monospace; font-size: .85em; color: var(--ink-2); }
button { font: inherit; }

.container { max-width: var(--container); margin: 0 auto; padding: 0 var(--gutter); }

/* ---------- header ---------- */
.site-header {
  background: var(--surface); border-bottom: 1px solid var(--line);
  position: relative;
}
.site-header::before { content: ''; display: block; height: 4px; background: linear-gradient(90deg, var(--brand), var(--brand-2) 50%, var(--ht)); }
.site-header .container { display: flex; align-items: center; gap: 16px; padding-top: 14px; padding-bottom: 14px; }
.site-logo { width: 56px; height: 56px; object-fit: contain; flex: none; }
.site-titles { flex: 1; min-width: 0; }
.site-title { font-size: clamp(17px, 2vw, 22px); line-height: 1.3; color: var(--ink); }
.site-subtitle { margin: 2px 0 0; color: var(--ink-2); font-size: 13px; }
.site-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; flex: none; }
.site-meta__line { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.site-meta__actions { display: flex; gap: 8px; }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill--online { background: #e6f7ea; color: #0b6b2b; }
.pill--online::before { animation: pulse 1.8s ease-in-out infinite; }
.pill--stale { background: #fff4e0; color: #9a5b00; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 10px; padding: 8px 14px; font-weight: 600; font-size: 13px; cursor: pointer; text-decoration: none; transition: background .15s, box-shadow .15s, transform .1s; min-height: 40px; }
.btn:hover { background: var(--surface-2); box-shadow: var(--shadow); }
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn--primary:hover { background: var(--brand); }
.btn--ghost { background: transparent; }
.btn--sm { padding: 5px 10px; min-height: 32px; font-size: 12px; border-radius: 8px; }
.btn--icon { padding: 8px 10px; }

/* ---------- home ---------- */
.site-logo-link { display: inline-flex; border-radius: 12px; flex: none; transition: transform .15s; }
.site-logo-link:hover { transform: scale(1.04); }
.site-logo-link:focus-visible { outline: 2px solid var(--brand-2); outline-offset: 3px; }
.btn--home { gap: 6px; padding: 8px 14px 8px 12px; }
.home-icon { font-size: 18px; line-height: 1; color: var(--brand-2); }
.btn--home:hover .home-icon { color: var(--brand); }

/* ---------- view toggle ---------- */
.btn--view { gap: 8px; }
.view-icon { font-size: 15px; line-height: 1; color: var(--brand-2); }
.btn--view[aria-pressed="true"] { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn--view[aria-pressed="true"] .view-icon { color: #fff; }
body.view-summary .mini-nav, body.view-summary .switch { display: none !important; }
.rows[hidden], .summary[hidden] { display: none !important; }   /* display:flex ของคลาสจะชนะ [hidden] ถ้าไม่บังคับ */

/* ---------- filter bar ---------- */
.filter-bar { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, .92); backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--line); }
.filter-bar .container { display: flex; align-items: center; gap: 16px; padding-top: 10px; padding-bottom: 10px; }
.filter-bar__year { display: flex; align-items: center; gap: 8px; }
.filter-bar__year label { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.select { appearance: none; border: 1px solid var(--line); background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23475569' stroke-width='1.8'/%3E%3C/svg%3E") no-repeat right 12px center; padding: 8px 34px 8px 12px; border-radius: 10px; font: 600 14px var(--font-body); color: var(--ink); min-height: 40px; cursor: pointer; }
.select:focus { outline: 2px solid var(--brand-2); outline-offset: 1px; }
.filter-bar__date { font-size: 13px; color: var(--ink-2); margin-left: auto; text-align: right; }
.filter-bar__date b { color: var(--ink); font-weight: 600; }

/* ---------- switch แสดงแผนที่ (มือถือเท่านั้น) ---------- */
.switch { display: none; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch__track { position: relative; width: 38px; height: 22px; border-radius: 999px; background: #cbd5e1; transition: background .2s; flex: none; }
.switch__track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked + .switch__track { background: var(--brand-2); }
.switch input:checked + .switch__track::after { transform: translateX(16px); }
.switch input:focus-visible + .switch__track { outline: 2px solid var(--brand-2); outline-offset: 2px; }

/* ---------- layout ---------- */
.main { padding: 22px 0 48px; }
.rows { display: flex; flex-direction: column; gap: 22px; }

/* mini-nav ซ้าย (PC เท่านั้น) */
.mini-nav { position: fixed; left: 10px; top: 50%; transform: translateY(-50%); display: none; flex-direction: column; gap: 6px; z-index: 15; }
.mini-nav a { display: flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: 10px; font-weight: 700; text-decoration: none; transition: all .15s; }
.mini-nav a:hover, .mini-nav a.active { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
@media (min-width: 1500px) { .mini-nav { display: flex; } }

/* ---------- KPI row ---------- */
.kpi-row { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); transition: box-shadow .2s; scroll-margin-top: 80px; }
.kpi-row:hover { box-shadow: var(--shadow-hover); }

.kpi-row__head { display: grid; grid-template-columns: auto 1fr auto; gap: 14px 16px; align-items: start; padding: 18px 20px 6px; }
.kpi-row__no { font-family: var(--font-head); font-size: 28px; font-weight: 700; color: var(--brand-2); line-height: 1; opacity: .9; padding-top: 2px; letter-spacing: -.03em; }
.kpi-row__title { font-size: 17px; line-height: 1.35; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.kpi-row__desc { margin: 4px 0 0; color: var(--ink-2); font-size: 13px; max-width: 70ch; }
.badge { display: inline-block; font: 700 11px var(--font-head); letter-spacing: .04em; padding: 2px 8px; border-radius: 6px; color: #fff; }
.badge--dm { background: var(--dm); }
.badge--ht { background: var(--ht); }

.kpi-row__headline { text-align: right; min-width: 200px; }
.headline__value { display: flex; align-items: baseline; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.headline__num { font-family: var(--font-head); font-size: 34px; font-weight: 700; letter-spacing: -.02em; line-height: 1; color: var(--ink); }
.headline__num small { font-size: 13px; font-weight: 600; color: var(--ink-2); letter-spacing: 0; }
.delta { font-weight: 700; font-size: 13px; padding: 2px 8px; border-radius: 6px; }
.delta--good { color: #0b6b2b; background: #e6f7ea; }
.delta--bad { color: #9f1d1d; background: #fdeaea; }
.delta--neutral { color: var(--ink-2); background: var(--surface-2); }
.delta__vs { font-size: 11px; color: var(--muted); margin-left: 6px; }
.headline__sub { font-size: 12px; color: var(--ink-2); margin-top: 6px; }
.headline__status { margin-top: 6px; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px 3px 6px; border-radius: 999px; }
.status i { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px; border-radius: 50%; font-style: normal; font-size: 10px; color: #fff; }
.status--pass { background: #e6f7ea; color: #0b6b2b; } .status--pass i { background: var(--good); }
.status--warn { background: #fff4e0; color: #8a5300; } .status--warn i { background: var(--warn); }
.status--fail { background: #fdeaea; color: #9f1d1d; } .status--fail i { background: var(--bad); }

.kpi-row__body { display: grid; grid-template-columns: 5fr 7fr; gap: 12px; padding: 6px 12px 8px; min-height: var(--row-h); }
.kpi-row__map, .kpi-row__chart { position: relative; background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px; min-height: var(--row-h); display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.map-host, .chart-host { position: relative; width: 100%; flex: 1 1 auto; min-height: 0; }
.chart-host { min-height: calc(var(--row-h) - 20px); }
.chart-host canvas { width: 100% !important; height: 100% !important; }

.kpi-row__foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 20px 14px; flex-wrap: wrap; }
.kpi-row__actions { display: flex; gap: 6px; flex-wrap: wrap; }
.kpi-row__source { font-size: 12px; color: var(--muted); }

.kpi-row--pending { opacity: .7; }
.kpi-row--pending .kpi-row__body { min-height: 0; padding: 0 20px 6px; }
.kpi-row--pending .kpi-row__body .pending { min-height: 44px; font-size: 12px; }
.kpi-row--pending .kpi-row__headline, .kpi-row--pending .kpi-row__foot, .kpi-row--pending .kpi-row__desc { display: none; }
.pending { display: grid; place-items: center; min-height: 160px; color: var(--muted); font-size: 14px; border: 1px dashed var(--line); border-radius: var(--radius-sm); }
.error { background: #fdeaea; color: #9f1d1d; padding: 16px; border-radius: var(--radius-sm); }

/* ---------- map ---------- */
.ncd-map { position: relative; width: 100%; height: 100%; min-height: 380px; display: flex; flex-direction: column; }
.ncd-map svg { flex: 1; width: 100%; height: calc(100% - 26px); min-height: 340px; display: block; touch-action: manipulation; }
.ncd-map .area { stroke: #ffffff; stroke-width: 2.5; stroke-linejoin: round; cursor: pointer; transition: fill .3s, opacity .2s, filter .2s; outline: none; }
.ncd-map .area:hover, .ncd-map .area.hover { filter: brightness(1.06) saturate(1.1); }
.ncd-map .area:focus-visible { stroke: var(--brand-2); stroke-width: 4; }
.ncd-map .area.selected { stroke: var(--ink); stroke-width: 4; filter: drop-shadow(0 4px 8px rgba(15, 23, 42, .25)); }
.ncd-map .area.dim { opacity: .35; }
.ncd-map .label { pointer-events: none; text-anchor: middle; font-family: var(--font-body); }
.ncd-map .label .name { font-size: 30px; font-weight: 600; }
.ncd-map .label .val { font-size: 34px; font-weight: 700; }
.ncd-map .label.small .name { font-size: 22px; }
.ncd-map .label.small .val { font-size: 25px; }
.ncd-map .label { paint-order: stroke fill; stroke: rgba(255,255,255,.55); stroke-width: 3px; stroke-linejoin: round; }
.ncd-map .label.on-dark { stroke: rgba(15,23,42,.35); }
.ncd-map .label.dim { opacity: .35; }
.ncd-map__legend { display: flex; align-items: center; gap: 3px; height: 26px; padding: 0 4px; font-size: 11px; color: var(--ink-2); }
.ncd-map__legend .sw { width: 22px; height: 10px; border-radius: 2px; }
.ncd-map__legend-title { margin: 0 6px; }
.ncd-map__tip { position: absolute; left: 0; top: 0; pointer-events: none; background: var(--ink); color: #fff; padding: 8px 12px; border-radius: 8px; font-size: 12px; line-height: 1.4; box-shadow: 0 8px 24px -8px rgba(0, 0, 0, .4); z-index: 5; white-space: nowrap; }
.ncd-map__tip b { display: block; font-size: 13px; }
.ncd-map__tip span { display: block; }
.ncd-map__tip strong { font-size: 14px; }
.ncd-map__tip small { display: block; color: #cbd5e1; margin-top: 2px; }
.ncd-map__tip[hidden] { display: none; }

/* ---------- modal ---------- */
dialog.modal { border: 0; border-radius: var(--radius); padding: 0; max-width: min(640px, calc(100vw - 32px)); width: 100%; box-shadow: 0 24px 64px -20px rgba(15, 23, 42, .45); }
dialog.modal::backdrop { background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 18px 20px 10px; border-bottom: 1px solid var(--line); }
.modal__head h3 { font-size: 17px; }
.modal__body { padding: 16px 20px 20px; font-size: 14px; color: var(--ink-2); max-height: 70vh; overflow: auto; }
.modal__name { color: var(--ink); font-weight: 600; }
.deflist { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; margin: 12px 0; }
.deflist dt { font-weight: 700; color: var(--ink); }
.deflist dd { margin: 0; }
.notice { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; margin-top: 12px; }
.notice pre { white-space: pre-wrap; font: inherit; margin: 6px 0 0; }
.modal__links { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }

/* ---------- toast ---------- */
.toasts { position: fixed; top: 16px; right: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 13px; box-shadow: 0 12px 32px -10px rgba(0, 0, 0, .4); opacity: 0; transform: translateY(-8px); transition: all .3s; max-width: min(360px, calc(100vw - 32px)); }
.toast.show { opacity: 1; transform: none; }
.toast--ok { background: #0b6b2b; }
.toast--warn { background: #9a5b00; }

/* ---------- footer ---------- */
.site-footer { border-top: 1px solid var(--line); padding: 18px 0 28px; color: var(--muted); font-size: 12px; }
.site-footer .container { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

/* ---------- tablet แนวนอน (900–1023) : ยัง 5:7 แต่ย่อ ---------- */
@media (max-width: 1023px) and (min-width: 900px) {
  :root { --row-h: 380px; }
  .kpi-row__head { grid-template-columns: auto 1fr; }
  .kpi-row__headline { grid-column: 1 / -1; text-align: left; }
  .headline__value { justify-content: flex-start; }
  .ncd-map .label .name { font-size: 34px; } .ncd-map .label .val { font-size: 38px; }
}

/* ---------- มือถือ / แท็บเล็ตแนวตั้ง (<900) : 1 คอลัมน์ แผนที่ก่อน → กราฟ ---------- */
@media (max-width: 899px) {
  :root { --row-h: 340px; --gutter: 12px; }
  body { font-size: 14px; }
  .site-header .container { gap: 10px; padding-top: 10px; padding-bottom: 10px; }
  .site-logo { width: 40px; height: 40px; }
  .site-title { font-size: 15px; }
  .site-subtitle { display: none; }
  .site-meta__line { display: none; }
  .site-meta__actions .btn { min-height: 36px; padding: 6px 9px; }
  .site-meta__actions .btn span { display: none; }
  .filter-bar .container { gap: 10px; flex-wrap: wrap; }
  .filter-bar__year label { display: none; }
  .btn--home span:last-child { display: none; }
  .btn--home { padding: 8px 10px; min-height: 40px; }
  .filter-bar__date { font-size: 11px; line-height: 1.3; }
  .kpi-row__head { grid-template-columns: auto 1fr; }
  .kpi-row__headline { grid-column: 1 / -1; min-width: 0; text-align: left; }
  .headline__value { justify-content: flex-start; }
  .switch { display: inline-flex; margin-left: auto; }
  .filter-bar__date { flex-basis: 100%; margin-left: 0; text-align: left; }
  body.no-map .kpi-row__map { display: none; }
  .kpi-row__head { padding: 14px 14px 4px; gap: 10px; }
  .kpi-row__no { font-size: 22px; }
  .kpi-row__title { font-size: 15px; }
  .headline__num { font-size: 28px; }
  .kpi-row__body { grid-template-columns: 1fr; gap: 10px; padding: 4px 8px 6px; min-height: 0; }
  .kpi-row__map { min-height: 0; }
  .ncd-map { min-height: 0; }
  .ncd-map svg { min-height: 0; height: auto; aspect-ratio: 1 / 0.95; max-height: 520px; }
  .kpi-row__chart { min-height: 0; }
  .chart-host { min-height: 380px; }
  .kpi-row__foot { padding: 4px 14px 12px; }
  .toasts { top: auto; bottom: 16px; left: 16px; right: 16px; }
}

/* ---------- print : 2 แถว/หน้า A4 ---------- */
@media print {
  @page { size: A4 portrait; margin: 10mm 10mm 12mm; }
  :root { --row-h: 250px; }
  html, body { background: #fff !important; font-size: 11px; }
  .filter-bar, .mini-nav, .toasts, .site-meta__actions, .kpi-row__actions, .switch, dialog, .site-footer { display: none !important; }
  .site-header::before { display: none; }
  .site-header { border: 0; }
  .site-header .container { padding: 0 0 6px; gap: 10px; }
  .site-logo { width: 34px; height: 34px; }
  .site-title { font-size: 15px; }
  .site-subtitle { display: block; font-size: 10px; margin: 0; }
  .site-meta__line { display: flex; font-size: 10px; }
  .pill { display: none; }
  .print-meta { display: block !important; font-size: 10px; color: var(--ink-2); margin: 2px 0 0; }
  .container { max-width: none; padding: 0; }
  .main { padding: 6px 0 0; }
  .rows { gap: 8px; }
  .kpi-row { break-inside: avoid; page-break-inside: avoid; box-shadow: none; border-color: #cfd6e0; border-radius: 8px; }
  .kpi-row:nth-child(2n) { break-after: page; page-break-after: always; }
  /* บังคับโครง PC แม้กระดาษแคบ */
  .kpi-row__head { grid-template-columns: auto 1fr auto; padding: 8px 12px 2px; gap: 6px 10px; }
  .kpi-row__headline { grid-column: auto; text-align: right; min-width: 150px; }
  .headline__value { justify-content: flex-end; }
  .headline__num { font-size: 22px; }
  .kpi-row__no { font-size: 18px; }
  .kpi-row__title { font-size: 12px; }
  .kpi-row__desc { font-size: 9.5px; margin-top: 2px; }
  .headline__sub, .status, .delta { font-size: 9.5px; }
  .kpi-row__body { grid-template-columns: 5fr 7fr; gap: 8px; padding: 4px 8px; min-height: var(--row-h); }
  .kpi-row__map, .kpi-row__chart { min-height: var(--row-h); padding: 6px; background: #fff; border: 1px solid #eef1f5; }
  .chart-host { min-height: calc(var(--row-h) - 14px); }
  .ncd-map svg { min-height: 0; }
  .ncd-map .label .name { font-size: 34px; } .ncd-map .label .val { font-size: 38px; }
  .kpi-row__foot { padding: 2px 12px 6px; }
  .kpi-row__source { font-size: 9px; }
  .kpi-row__table { padding: 0 8px 6px; }
  .table-wrap { overflow: visible; padding: 0; }
  .kpi-table { min-width: 0; font-size: 9px; }
  .kpi-table th, .kpi-table td { padding: 3px 6px; }
  canvas { max-width: 100% !important; }
}
.print-meta { display: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  html { scroll-behavior: auto; }
}

/* ---------- ตาราง (เฉพาะ DM Remission) ---------- */
.kpi-row__table { padding: 0 12px 10px; }
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); background: var(--surface-2); padding: 6px; }
.kpi-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 640px; }
.kpi-table caption { text-align: left; font-size: 12px; color: var(--ink-2); padding: 6px 8px 8px; caption-side: top; }
.kpi-table th, .kpi-table td { padding: 8px 10px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.kpi-table thead th { font-weight: 600; color: var(--ink-2); font-size: 12px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.kpi-table th[scope="row"], .kpi-table thead th:first-child { text-align: left; font-weight: 600; color: var(--ink); position: sticky; left: 0; background: var(--surface-2); }
.kpi-table tbody tr:nth-child(odd) td, .kpi-table tbody tr:nth-child(odd) th { background: var(--surface); }
.kpi-table tbody tr:hover td, .kpi-table tbody tr:hover th { background: #eef4ff; }
.kpi-table .row--total th, .kpi-table .row--total td { font-weight: 700; color: var(--ink); border-top: 2px solid var(--line); background: var(--surface-2) !important; }
.kpi-table td.cell--pass { color: #0b6b2b; font-weight: 700; background: #e6f7ea !important; }
.kpi-table td.cell--warn { color: #8a5300; font-weight: 700; background: #fff4e0 !important; }
.kpi-table td.cell--fail { color: #9f1d1d; font-weight: 700; background: #fdeaea !important; }
@media (max-width: 767px) { .kpi-table { font-size: 12px; } .kpi-table th, .kpi-table td { padding: 6px 8px; } }
@media print { .table-wrap { overflow: visible; } .kpi-table { min-width: 0; font-size: 10px; } }

/* ---------- มุมมองสรุป (ตาราง อำเภอ × ตัวชี้วัด) ---------- */
.summary { display: flex; flex-direction: column; gap: 22px; }
.sum-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px 16px; }
.sum-head h2 { font-size: 18px; }
.sum-head p { margin: 2px 0 12px; font-size: 13px; }
.sum-card h3 { font-size: 15px; margin-bottom: 10px; }
.sum-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-sm); }
.sum-table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
.sum-table th, .sum-table td { padding: 5px 4px; text-align: center; white-space: nowrap; border-bottom: 1px solid var(--line-2); }
.sum-table thead th { font-size: 12px; font-weight: 600; color: var(--ink-2); background: var(--surface-2); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.sum-table thead th small { display: block; font-weight: 400; font-size: 10px; color: var(--muted); }
.sum-table .sticky-col { position: sticky; left: 0; background: var(--surface); text-align: left; font-weight: 600; color: var(--ink); z-index: 1; padding-left: 8px; min-width: 96px; }
.sum-table thead .sticky-col { background: var(--surface-2); z-index: 3; }
.sum-table tbody tr:hover td, .sum-table tbody tr:hover th { background: #f5f8fd; }
.sum-table .row--total th, .sum-table .row--total td { border-top: 2px solid var(--line); background: var(--surface-2); font-weight: 700; }
.sum-table .sum-col { border-left: 2px solid var(--line); }
.kpi-head { border: 0; background: #e8f0fe; color: var(--brand); font: 700 12px var(--font-head); width: 30px; height: 26px; border-radius: 7px; cursor: pointer; }
.kpi-head:hover { background: var(--brand-2); color: #fff; }

.dot { display: inline-flex; align-items: center; justify-content: center; width: 42px; height: 42px; border-radius: 50%; font: 700 12px var(--font-body); letter-spacing: -.01em; color: #fff; border: 2px solid transparent; font-variant-numeric: tabular-nums; }
.dot--pass { background: var(--good); }
.dot--near { background: #f59e0b; }
.dot--far  { background: var(--bad); }
.dot--none { background: var(--surface); color: var(--ink); border-color: var(--line); }
.dot--na   { background: var(--surface-2); color: var(--muted); border-color: var(--line-2); }
.dot--sum  { width: 48px; border-radius: 12px; }
.dot--mini { width: 16px; height: 16px; border-width: 1px; vertical-align: -3px; margin-right: 4px; }
.dot .v-short { display: none; }

.sum-legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin-top: 12px; font-size: 12px; color: var(--ink-2); align-items: center; }
.sum-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 6px 20px; }
.sum-list li { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 0; border-bottom: 1px dashed var(--line-2); }
.sum-list__title { flex: 1; min-width: 0; }
.sum-list .kpi-head { flex: none; }

.sum-mobile { display: none; }
.vh { display: inline-block; writing-mode: vertical-rl; transform: rotate(180deg); font-size: 11px; line-height: 1; padding: 4px 0; }

@media (max-width: 899px) {
  .sum-pc { display: none; }
  .sum-mobile { display: table; }
  .sum-card { padding: 14px 10px 12px; }
  .sum-table th, .sum-table td { padding: 3px 1px; }
  .sum-table .sticky-col { min-width: 40px; padding-left: 3px; }
  .sum-table .kpi-head { width: 26px; height: 24px; font-size: 11px; }
  .dot { width: 29px; height: 29px; font-size: 10px; border-width: 1.5px; }
  .dot--sum { width: 32px; font-size: 9.5px; border-radius: 8px; }
  .sum-table thead th { font-size: 10px; }
  .vh { font-size: 10px; }
  /* จอแคบมาก: ซ่อนคอลัมน์จังหวัด (มีในสรุปหัวแถว/รายงานเต็มอยู่แล้ว) ให้ 8 อำเภอพอดีจอ */
  .sum-mobile .col-prov { display: none; }
  .sum-card { padding: 12px 6px 10px; }
}
@media (min-width: 480px) and (max-width: 899px) {
  .sum-mobile .col-prov { display: table-cell; }
  .dot .v-full { display: none; }
  .dot .v-short { display: inline; }
  .sum-list { grid-template-columns: 1fr; }
  .sum-legend { font-size: 11px; gap: 6px 12px; }
}
@media print {
  .btn--view { display: none !important; }
  .sum-wrap { overflow: visible; }
  .dot { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
