/* IBM Plex Sans Thai (เก็บไว้ในเว็บ ไม่พึ่ง Google Fonts) */
@font-face { font-family: 'Plex Thai'; font-weight: 400; font-display: swap; src: url(fonts/plex-thai-400.woff2) format('woff2'); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Plex Thai'; font-weight: 500; font-display: swap; src: url(fonts/plex-thai-500.woff2) format('woff2'); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Plex Thai'; font-weight: 600; font-display: swap; src: url(fonts/plex-thai-600.woff2) format('woff2'); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Plex Thai'; font-weight: 700; font-display: swap; src: url(fonts/plex-thai-700.woff2) format('woff2'); unicode-range: U+02D7, U+0303, U+0331, U+0E01-0E5B, U+200C-200D, U+25CC; }
@font-face { font-family: 'Plex Thai'; font-weight: 400; font-display: swap; src: url(fonts/plex-latin-400.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Plex Thai'; font-weight: 500; font-display: swap; src: url(fonts/plex-latin-500.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Plex Thai'; font-weight: 600; font-display: swap; src: url(fonts/plex-latin-600.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Plex Thai'; font-weight: 700; font-display: swap; src: url(fonts/plex-latin-700.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ---------- tokens ---------- */
:root {
  color-scheme: light;
  --font: 'Plex Thai', 'IBM Plex Sans Thai', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2f6;
  --line: #e4e8ee;
  --line-strong: #cdd5df;
  --text: #0f172a;
  --text-2: #475467;
  --text-3: #6b7685;

  --side: #0b4428;
  --side-2: rgba(255, 255, 255, .10);
  --side-text: #cfe3d6;
  --side-line: rgba(255, 255, 255, .12);
  --brand-900: #062f1b;
  --brand-800: #0b4428;
  --brand-700: #116034;
  --brand-600: #1a7a44;
  --brand-500: #24935a;
  --brand-soft: #e6f3ea;
  --brand-ink: #0f5a31;

  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #e8f1fc;
  --accent-line: #b7d3f6;

  --series-this: #2a78d6;        /* ปีนี้ */
  --series-last: #eb6834;        /* ปีที่แล้ว */
  --series-median: #344054;      /* ค่ามัธยฐาน (เส้นประ) */
  --series-old: #a3adba;         /* ปีเก่า */
  --band-iqr: rgba(52, 64, 84, .13);
  --band-range: rgba(52, 64, 84, .055);
  --grid: #edf0f4;
  --axis: #6b7685;
  --incomplete: rgba(250, 178, 25, .13);
  --range: rgba(42, 120, 214, .06);

  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-ink: #b42318;
  --critical-soft: #fdecec;
  --good-ink: #067647;
  --good-soft: #e7f6ec;
  --warn-soft: #fff6e0;
  --neutral-soft: #eef1f5;

  --map-zero: #eef1f5;
  --map-stroke: #ffffff;
  --map-sel: #0f172a;

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .04);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, .07);
  --shadow-lg: 0 16px 48px rgba(16, 24, 40, .18);
  --gutter: 28px;
  --side-w: 244px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b0f16; --surface: #131923; --surface-2: #171e29; --surface-3: #1e2733;
    --line: #232c39; --line-strong: #334052;
    --text: #edf1f7; --text-2: #b4bfcd; --text-3: #8c98a8;
    --side: #08301c; --side-2: rgba(255, 255, 255, .08); --side-text: #b9d4c2;
    --brand-soft: #14281c; --brand-ink: #7fd6a0;
    --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #15253b; --accent-line: #1f4673;
    --series-this: #3987e5; --series-last: #d95926; --series-median: #d0d7e1; --series-old: #5d6878;
    --band-iqr: rgba(208, 215, 225, .14); --band-range: rgba(208, 215, 225, .06);
    --grid: #1d2532; --axis: #8c98a8; --incomplete: rgba(250, 178, 25, .11); --range: rgba(57, 135, 229, .09);
    --critical-ink: #ff9b93; --critical-soft: #3a1d1f; --good-ink: #6fd39a; --good-soft: #13301f; --warn-soft: #3a3014; --neutral-soft: #1e2733;
    --map-zero: #1e2733; --map-stroke: #131923; --map-sel: #ffffff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-md: 0 4px 16px rgba(0, 0, 0, .35); --shadow-lg: 0 16px 48px rgba(0, 0, 0, .6);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f16; --surface: #131923; --surface-2: #171e29; --surface-3: #1e2733;
  --line: #232c39; --line-strong: #334052;
  --text: #edf1f7; --text-2: #b4bfcd; --text-3: #8c98a8;
  --side: #08301c; --side-2: rgba(255, 255, 255, .08); --side-text: #b9d4c2;
  --brand-soft: #14281c; --brand-ink: #7fd6a0;
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-soft: #15253b; --accent-line: #1f4673;
  --series-this: #3987e5; --series-last: #d95926; --series-median: #d0d7e1; --series-old: #5d6878;
  --band-iqr: rgba(208, 215, 225, .14); --band-range: rgba(208, 215, 225, .06);
  --grid: #1d2532; --axis: #8c98a8; --incomplete: rgba(250, 178, 25, .11); --range: rgba(57, 135, 229, .09);
  --critical-ink: #ff9b93; --critical-soft: #3a1d1f; --good-ink: #6fd39a; --good-soft: #13301f; --warn-soft: #3a3014; --neutral-soft: #1e2733;
  --map-zero: #1e2733; --map-stroke: #131923; --map-sel: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4); --shadow-md: 0 4px 16px rgba(0, 0, 0, .35); --shadow-lg: 0 16px 48px rgba(0, 0, 0, .6);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 400 15px/1.55 var(--font); min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent-ink); }
.ic { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.num { font-variant-numeric: tabular-nums; }
.skip { position: absolute; left: -999px; top: 0; }
.skip:focus { left: 8px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- app bar + tabs ---------- */
.appbar {
  position: sticky; top: 0; z-index: 40; color: var(--side-text); box-shadow: 0 4px 18px rgba(4, 40, 22, .28);
  background:
    radial-gradient(1200px 120px at 85% -40px, rgba(120, 220, 160, .22), transparent 70%),
    linear-gradient(100deg, var(--brand-900) 0%, var(--brand-800) 45%, var(--brand-700) 100%);
}
.appbar::before { content: ''; position: absolute; inset: 0; pointer-events: none; opacity: .09;
  background-image: radial-gradient(#fff 1px, transparent 1.4px); background-size: 16px 16px;
  -webkit-mask-image: linear-gradient(90deg, transparent 10%, #000 70%); mask-image: linear-gradient(90deg, transparent 10%, #000 70%); }
.appbar > * { position: relative; z-index: 1; }
.appbar-in, .tabs-in { max-width: 1640px; margin: 0 auto; padding: 0 var(--gutter); display: flex; align-items: center; gap: 16px; }
.appbar-in { min-height: 78px; padding-top: max(0px, env(safe-area-inset-top)); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark {
  width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; flex: none; overflow: hidden;
  background: linear-gradient(140deg, #34b26c, #116034); color: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.brand-mark img + .ic { display: none; }
.brand-mark .ic { width: 22px; height: 22px; stroke-width: 2.2; }
.brand-title { color: #fff; font-weight: 700; font-size: 22px; line-height: 1.2; white-space: nowrap; letter-spacing: .2px; text-shadow: 0 1px 2px rgba(0, 0, 0, .25); }
.brand-sub { font-size: 13.5px; opacity: .82; white-space: nowrap; }
.appbar-tools { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.updated { font-size: 12.5px; text-align: right; line-height: 1.35; white-space: nowrap; margin-right: 6px; }
.updated b { color: #fff; font-weight: 600; }
.updated .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #3fcf8e; margin-right: 6px; vertical-align: 1px; box-shadow: 0 0 0 3px rgba(63, 207, 142, .18); }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--side-line); display: grid; place-items: center; background: transparent; color: var(--side-text); }
.icon-btn:hover { background: var(--side-2); color: #fff; }
.help-btn { display: flex; align-items: center; gap: 7px; border: 0; border-radius: 10px; padding: 8px 14px; background: #fff; color: var(--brand-800); font-weight: 600; white-space: nowrap; box-shadow: 0 2px 8px rgba(0, 0, 0, .18); }
.help-btn .ic { width: 19px; height: 19px; color: #eda100; }
.tabs { border-top: 1px solid rgba(255, 255, 255, .14); background: rgba(0, 0, 0, .22); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .05); }
.tabs-in { padding-top: 7px; padding-bottom: 7px; gap: 6px; }
.tabs-in { gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs-in::-webkit-scrollbar { display: none; }
.tabs a {
  position: relative; display: flex; align-items: center; gap: 8px; padding: 9px 16px; color: #e3f2e8; border-radius: 11px;
  text-decoration: none; font-weight: 600; font-size: 15px; white-space: nowrap; transition: background .15s, color .15s;
  border: 1px solid transparent;
}
.tabs a .ic { width: 18px; height: 18px; opacity: .85; }
.tabs a:hover { color: #fff; background: rgba(255, 255, 255, .10); border-color: rgba(255, 255, 255, .14); }
.tabs a.active { color: #fff; }
.tabs a.active { background: #fff; color: var(--brand-800); box-shadow: 0 4px 14px rgba(0, 0, 0, .22); }
.tabs a.active .ic { color: var(--brand-600); opacity: 1; }
.tabs a.active .new { background: #eda100; }
.tabs .new { font-style: normal; font-size: 10.5px; font-weight: 600; background: #eda100; color: #1a1300; border-radius: 99px; padding: 0 6px; line-height: 16px; }

/* ---------- shell ---------- */
.shell { min-height: calc(100vh - 110px); display: flex; flex-direction: column; }
.wrap { width: 100%; max-width: 1640px; margin: 0 auto; padding: 0 var(--gutter); flex: 1; display: flex; flex-direction: column; }
.sample-banner {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  background: var(--warn-soft); color: #7a4f00; padding: 8px var(--gutter); font-size: 13.5px; border-bottom: 1px solid #f3dd9b;
}
:root[data-theme="dark"] .sample-banner { color: #f3dc9a; border-color: #4d3f17; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .sample-banner { color: #f3dc9a; border-color: #4d3f17; } }

/* ---------- page head ---------- */
.page-top { padding: 22px 0 14px; display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; }
.page-top:empty { padding: 12px 0 0; }
.crumb { font-size: 13px; color: var(--text-3); display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-weight: 500; }
.crumb .ic { width: 15px; height: 15px; color: var(--accent); }
.page-top h1 { margin: 0; font-size: 26px; font-weight: 600; line-height: 1.25; letter-spacing: -.2px; }
.page-top h1 .dzname { color: var(--brand-ink); }
.page-top .sub { color: var(--text-2); font-size: 14px; margin-top: 4px; }
.page-top .tools { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- filter bar ---------- */
.filterbar {
  position: sticky; top: 144px; z-index: 30; margin-bottom: 18px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-md);
  padding: 10px 12px;
}
.fb-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; }
.fb-field {
  display: flex; flex-direction: column; gap: 1px; min-width: 0;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 6px 12px 7px; transition: border-color .15s;
}
.fb-field:hover { border-color: var(--line-strong); }
.fb-label { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--text-3); font-weight: 500; letter-spacing: .1px; white-space: nowrap; }
.fb-label .ic { width: 13px; height: 13px; }
.fb-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 0; background: none; padding: 0; text-align: left; font-weight: 600; min-height: 24px; font-size: 14.5px;
}
.fb-btn .val { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 280px; }
.fb-btn .ic { width: 15px; height: 15px; color: var(--text-3); }
.fb-select {
  border: 0; background: transparent; padding: 0 20px 0 0; font-weight: 600; font-size: 14.5px; min-height: 24px; max-width: 210px;
  appearance: none; -webkit-appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7685' stroke-width='2.4' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right center; background-size: 14px;
}
.fb-select:disabled { opacity: .45; cursor: default; }
.fb-select option { color: #0f172a; background: #fff; }
.fb-area { flex-direction: row; gap: 0; padding: 0; }
.fb-area > div { display: flex; flex-direction: column; gap: 1px; padding: 6px 12px 7px; }
.fb-area > div + div { border-left: 1px solid var(--line); }
.fb-week { min-width: 240px; }
.fb-spacer { flex: 1; }
.seg { display: inline-flex; background: var(--surface-3); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: none; padding: 3px 11px; border-radius: 7px; font-size: 13.5px; font-weight: 500; color: var(--text-2);
  white-space: nowrap; min-height: 26px;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface); color: var(--accent-ink); box-shadow: 0 1px 3px rgba(16, 24, 40, .14); font-weight: 600; }
.fb-field .seg { margin-top: 2px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; border-radius: var(--radius-sm); padding: 8px 14px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 500; white-space: nowrap; font-size: 14px;
}
.btn:hover { border-color: var(--line-strong); background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-3); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn .badge {
  background: var(--accent); color: #fff; border-radius: 99px; font-size: 11.5px; min-width: 19px; height: 19px;
  display: inline-grid; place-items: center; padding: 0 5px;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--line); }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; border-radius: 99px; padding: 2px 6px 2px 11px; font-size: 13px; font-weight: 500;
  background: var(--accent-soft); color: var(--accent-ink); border: 1px solid var(--accent-line);
}
.chip button { border: 0; background: none; padding: 2px; display: grid; place-items: center; color: inherit; border-radius: 50%; }
.chip button:hover { background: rgba(0, 0, 0, .08); }
.chip .ic { width: 13px; height: 13px; }

/* week range */
.wr { display: flex; align-items: center; gap: 10px; }
.wr-nums { font-weight: 600; white-space: nowrap; font-size: 14.5px; }
.wr-track { position: relative; flex: 1; height: 24px; min-width: 110px; }
.wr-track input[type=range] {
  position: absolute; inset: 0; width: 100%; margin: 0; background: none; pointer-events: none;
  -webkit-appearance: none; appearance: none; height: 24px;
}
.wr-track input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; pointer-events: auto; width: 20px; height: 20px; border-radius: 50%;
  background: var(--surface); border: 2.5px solid var(--accent); box-shadow: 0 1px 4px rgba(0,0,0,.2); cursor: grab;
}
.wr-track input[type=range]::-moz-range-thumb {
  pointer-events: auto; width: 15px; height: 15px; border-radius: 50%; background: var(--surface); border: 2.5px solid var(--accent); cursor: grab;
}
.wr-rail { position: absolute; left: 0; right: 0; top: 10px; height: 4px; border-radius: 4px; background: var(--surface-3); }
.wr-fill { position: absolute; top: 10px; height: 4px; border-radius: 4px; background: var(--accent); }

/* ---------- layout ---------- */
main { flex: 1; padding-bottom: 28px; outline: none; }
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 18px; }
.grid + .grid, .kpis + .grid, .grid + .section-title, .section-title + .grid { margin-top: 18px; }
.s3 { grid-column: span 3; } .s4 { grid-column: span 4; } .s5 { grid-column: span 5; } .s6 { grid-column: span 6; }
.s7 { grid-column: span 7; } .s8 { grid-column: span 8; } .s12 { grid-column: span 12; }
.section-title { font-size: 13px; font-weight: 600; color: var(--text-3); letter-spacing: .3px; display: flex; align-items: center; gap: 8px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 20px 20px; min-width: 0; position: relative; display: flex; flex-direction: column;
}
.card-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 14px; min-height: 30px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 10px; line-height: 1.35; }
.card-head h2 .ic {
  width: 30px; height: 30px; padding: 6px; border-radius: 9px; background: var(--brand-soft); color: var(--brand-ink); stroke-width: 2;
}
.card-head .hint { color: var(--text-3); font-size: 12.5px; width: 100%; margin-top: -6px; padding-left: 40px; }
.card-head .acts { margin-left: auto; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.mini-btn {
  width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text-3);
  display: grid; place-items: center;
}
.mini-btn:hover { background: var(--surface-2); border-color: var(--line-strong); color: var(--text); }
.note { font-size: 12.5px; color: var(--text-3); margin-top: 10px; display: flex; gap: 6px; align-items: flex-start; }
.note .ic { width: 14px; height: 14px; margin-top: 3px; }
.note:empty { display: none; }
.empty { display: grid; place-items: center; text-align: center; color: var(--text-3); padding: 40px 10px; gap: 8px; }
.empty .ic { width: 34px; height: 34px; opacity: .55; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 18px; }
.kpis.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpis.five .k-val { font-size: 27px; }
.kpi {
  border-radius: var(--radius); padding: 16px 18px 16px; position: relative; overflow: hidden; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow); display: flex; flex-direction: column;
}
.kpi .k-top { display: flex; align-items: center; gap: 10px; font-size: 13.5px; font-weight: 500; color: var(--text-2); }
.kpi .k-icon {
  width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex: none;
  background: var(--brand-soft); color: var(--brand-ink);
}
.kpi .k-icon .ic { width: 18px; height: 18px; }
.kpi .k-val { font-size: 30px; font-weight: 600; line-height: 1.15; margin-top: 12px; letter-spacing: -.6px; display: flex; align-items: baseline; gap: 6px; flex-wrap: wrap; }
.kpi .k-unit { font-size: 14px; font-weight: 500; color: var(--text-3); letter-spacing: 0; }
.kpi .k-sub { font-size: 13px; color: var(--text-2); margin-top: 6px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.kpi .k-sub b { font-weight: 600; color: var(--text); }
.kpi .k-spark { position: absolute; right: 14px; top: 14px; width: 96px; height: 34px; }
.kpi.k-death .k-icon { background: var(--critical-soft); color: var(--critical-ink); }
.kpi.k-hero {
  color: #fff; border: 0;
  background:
    radial-gradient(160px 120px at 100% 0%, rgba(255, 255, 255, .22), transparent 70%),
    linear-gradient(140deg, var(--brand-500), var(--brand-700) 60%, var(--brand-800));
  box-shadow: 0 10px 24px -8px rgba(17, 96, 52, .55), inset 0 1px 0 rgba(255, 255, 255, .18);
}
.kpi.k-hero::before { content: ''; position: absolute; right: -30px; bottom: -40px; width: 140px; height: 140px; border-radius: 50%;
  border: 18px solid rgba(255, 255, 255, .07); }
.kpi.k-hero .k-top, .kpi.k-hero .k-sub, .kpi.k-hero .k-unit { color: rgba(255, 255, 255, .86); }
.kpi.k-hero .k-sub b { color: #fff; }
.kpi.k-hero .k-icon { background: rgba(255, 255, 255, .18); color: #fff; }
.kpi.k-hero .k-spark path[stroke-dasharray] { stroke: rgba(255, 255, 255, .7); }
.kpi.k-hero .k-spark path:not([stroke-dasharray]):not([fill^="var"]) { stroke: #fff; }
.kpi.k-hero .k-spark path[fill^="var"] { fill: rgba(255, 255, 255, .18); }
.kpi.k-death-hero { background: linear-gradient(140deg, #2b2f36, #121418); color: #fff; border: 0; box-shadow: 0 10px 24px -10px rgba(0, 0, 0, .55); }
.kpi.k-death-hero .k-top, .kpi.k-death-hero .k-sub, .kpi.k-death-hero .k-unit { color: rgba(255, 255, 255, .8); }
.kpi.k-death-hero .k-sub b { color: #fff; }
.kpi.k-death-hero .k-icon { background: rgba(255, 255, 255, .12); color: #ff9b93; }
.kpi.k-alert { border-color: color-mix(in srgb, var(--critical) 35%, var(--line)); }
.kpi.k-alert::after { content: ''; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--critical); }
.kpi.k-alert .k-icon { background: var(--critical-soft); color: var(--critical-ink); }
.kpi.k-ok .k-icon { background: var(--good-soft); color: var(--good-ink); }
.kpi .k-val .delta { font-size: inherit; }
.status { display: inline-flex; align-items: center; gap: 5px; border-radius: 99px; padding: 2px 10px 2px 7px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.status .ic { width: 14px; height: 14px; }
.status.hi { background: var(--critical-soft); color: var(--critical-ink); }
.status.lo { background: var(--good-soft); color: var(--good-ink); }
.status.eq { background: var(--neutral-soft); color: var(--text-2); }

/* ---------- charts ---------- */
.chart-box { position: relative; width: 100%; height: 300px; }
.chart-box.tall { height: 290px; }
.chart-box.short { height: 230px; }
.card > .chart-box { flex: 1; min-height: 230px; }
.card > .chart-box.tall { min-height: 290px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12.5px; color: var(--text-2); margin: -4px 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 16px; height: 3px; border-radius: 2px; background: currentColor; }
.legend i.dash { background: repeating-linear-gradient(90deg, var(--series-median) 0 5px, transparent 5px 8px); height: 2px; }
.legend i.iqr { height: 10px; background: var(--band-iqr); border-radius: 3px; }
.legend i.rng { height: 10px; background: var(--band-range); border: 1px solid var(--line); border-radius: 3px; }
.legend i.inc { height: 10px; background: var(--incomplete); border: 1px dashed #d6a21c; border-radius: 3px; }
.legend i.box { width: 11px; height: 11px; border-radius: 3px; }

/* ---------- map ---------- */
.map-wrap { position: relative; flex: 1; min-height: 280px; display: flex; flex-direction: column; }
.map-svg { width: 100%; flex: 1; min-height: 260px; max-height: 420px; touch-action: manipulation; }
.map-svg path { stroke: var(--map-stroke); stroke-width: .6; vector-effect: non-scaling-stroke; transition: fill .2s, opacity .2s; cursor: pointer; }
.map-svg path:hover { stroke: var(--map-sel); stroke-width: 1.4; }
.map-svg path.sel { stroke: var(--map-sel); stroke-width: 2.2; }
.map-svg path.dim { opacity: .25; }
.map-svg .outline { fill: none; stroke: var(--text-3); stroke-width: .7; pointer-events: none; opacity: .6; }
.map-legend { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-2); margin-top: 10px; flex-wrap: wrap; }
.map-legend .steps { display: flex; gap: 2px; flex-wrap: wrap; }
.map-legend .steps span { display: flex; flex-direction: column; align-items: center; gap: 3px; }
.map-legend .steps i { width: 42px; height: 8px; border-radius: 2px; display: block; }
.map-legend .steps em { font-style: normal; font-size: 10.5px; color: var(--text-3); white-space: nowrap; }

/* ---------- tables ---------- */
.tbl-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); max-height: 540px; -webkit-overflow-scrolling: touch; }
table.tbl { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; }
.tbl th, .tbl td { padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl thead th {
  position: sticky; top: 0; z-index: 2; background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: 12.5px;
  text-align: right; cursor: pointer; user-select: none; border-bottom: 1px solid var(--line-strong); line-height: 1.3;
}
.tbl thead th:hover { color: var(--text); }
.tbl thead th:first-child, .tbl thead th.l { text-align: left; }
.tbl thead th .ic { width: 12px; height: 12px; opacity: .45; vertical-align: -1px; }
.tbl thead th.sorted { color: var(--accent-ink); }
.tbl thead th.sorted .ic { opacity: 1; }
.tbl td { text-align: right; font-variant-numeric: tabular-nums; }
.tbl td.l { text-align: left; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl tr.zone td { font-weight: 600; }
.tbl tr.zone td.l { color: var(--text); }
.tbl tr.child td.l:first-child { padding-left: 34px; }
.tbl tr.child td { color: var(--text-2); }
.tbl tr.grand td { font-weight: 600; background: var(--surface-3); position: sticky; bottom: 0; z-index: 1; border-top: 1px solid var(--line-strong); }
.tbl tr.sel td { background: var(--accent-soft); }
.tbl tr.click { cursor: pointer; }
.tbl .tog { display: inline-flex; align-items: center; gap: 6px; border: 0; background: none; padding: 0; font-weight: inherit; text-align: left; }
.tbl .tog .ic { width: 15px; height: 15px; transition: transform .15s; color: var(--text-3); }
.tbl .tog.open .ic { transform: rotate(90deg); }
.tbl .link { border: 0; background: none; padding: 0; color: inherit; font-weight: inherit; text-align: left; }
.tbl .link:hover { color: var(--accent-ink); text-decoration: underline; text-underline-offset: 3px; }
.tbl .bar { position: relative; }
.tbl .bar::before {
  content: ''; position: absolute; right: 6px; top: 7px; bottom: 7px; width: calc(var(--w, 0%) * .9);
  background: color-mix(in srgb, var(--series-this) 14%, transparent); border-radius: 4px;
}
.tbl .bar span { position: relative; }
.dz-cell { display: flex; flex-direction: column; line-height: 1.3; }
.dz-cell small { color: var(--text-3); font-size: 12px; }
.grp-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.delta { font-size: 13px; display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }
.delta .ic { width: 14px; height: 14px; }
.delta.up { color: var(--critical-ink); }
.delta.down { color: var(--good-ink); }
.spark { width: 120px; height: 30px; display: block; margin-left: auto; }

/* heat table */
.heat td.c { min-width: 44px; padding: 7px 6px; font-size: 12.5px; text-align: right; border-left: 1px solid color-mix(in srgb, var(--surface) 60%, transparent); position: relative; }
.heat td.c.over::after {
  content: ''; position: absolute; top: 3px; right: 3px; width: 6px; height: 6px; border-radius: 50%;
  background: #1b1f24; box-shadow: 0 0 0 1.5px #fff;
}
.heat td.c.inc { background-image: repeating-linear-gradient(135deg, transparent 0 5px, rgba(214, 162, 28, .28) 5px 7px); }
.heat th.c { min-width: 44px; text-align: center; padding: 8px 4px; }
.heat .stick { position: sticky; left: 0; z-index: 1; background: var(--surface); }
.heat .stick2 { position: sticky; z-index: 1; background: var(--surface); }
.heat thead .stick, .heat thead .stick2 { z-index: 3; background: var(--surface-2); }
.heat tr:hover td.stick, .heat tr:hover td.stick2 { background: var(--surface-2); }
.tbh .stick { min-width: 170px; max-width: 170px; overflow: hidden; text-overflow: ellipsis; }

/* ---------- composition bars ---------- */
.comp { display: flex; flex-direction: column; gap: 18px; }
.comp-title { font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }
.comp-title .ic { width: 15px; height: 15px; color: var(--text-3); }
.comp-bar { display: flex; height: 14px; border-radius: 7px; overflow: hidden; gap: 2px; background: var(--surface-3); }
.comp-bar span { height: 100%; min-width: 3px; cursor: pointer; transition: opacity .15s; }
.comp-bar span:hover { opacity: .8; }
.comp-rows { display: grid; grid-template-columns: auto 1fr auto auto; gap: 6px 12px; margin-top: 10px; font-size: 13.5px; align-items: center; }
.comp-rows .sw { width: 10px; height: 10px; border-radius: 3px; }
.comp-rows .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.comp-rows .p { text-align: right; color: var(--text-3); font-variant-numeric: tabular-nums; min-width: 52px; }
.comp-rows button { border: 0; background: none; padding: 0; text-align: left; color: var(--text); }
.comp-rows button:hover { color: var(--accent-ink); }
.comp-rows .off { opacity: .4; }

/* ---------- compare panels ---------- */
.panel { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 20px; }
.panel-side { display: flex; flex-direction: column; gap: 10px; }
.panel-ctl { display: flex; flex-direction: column; gap: 8px; }
.stat { border-radius: var(--radius-sm); padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--line); }
.stat .t { font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 6px; font-weight: 500; }
.stat .t .ic { width: 14px; height: 14px; color: var(--accent); }
.stat .v { font-size: 21px; font-weight: 600; line-height: 1.25; letter-spacing: -.3px; }
.stat.dark .t .ic { color: var(--critical); }
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.map-cols { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.map-col .stat-row { margin-bottom: 10px; }
.panel-title { font-weight: 600; font-size: 15.5px; line-height: 1.35; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.panel-title .en { color: var(--text-3); font-weight: 400; font-size: 13px; }
.panel-num {
  width: 24px; height: 24px; border-radius: 7px; background: var(--accent); color: #fff; display: inline-grid;
  place-items: center; font-weight: 600; font-size: 13px; flex: none;
}

/* ---------- picker / popover ---------- */
.pop {
  position: fixed; z-index: 60; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); padding: 14px; width: min(440px, calc(100vw - 24px)); max-height: min(72vh, 640px);
  display: flex; flex-direction: column; gap: 12px;
}
.pop-head { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15.5px; }
.pop-head .ic { color: var(--accent); }
.pop-head .mini-btn { margin-left: auto; border-color: transparent; }
.search { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 8px 11px; background: var(--surface); }
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search input { border: 0; background: none; outline: none; flex: 1; min-width: 0; }
.search .ic { color: var(--text-3); }
.pick-groups { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.pick-groups button { border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 3px 12px; font-size: 13px; white-space: nowrap; }
.pick-groups button.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.pick-list { overflow: auto; flex: 1; margin: 0 -6px; padding: 0 6px; }
.pick-item { display: flex; align-items: center; gap: 10px; padding: 8px 8px; border-radius: 9px; cursor: pointer; min-height: 46px; }
.pick-item:hover { background: var(--surface-2); }
.pick-item input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }
.pick-item .nm { flex: 1; min-width: 0; font-weight: 500; }
.pick-item .nm small { display: block; color: var(--text-3); font-size: 12px; line-height: 1.25; font-weight: 400; }
.pick-item .ct { color: var(--text-3); font-size: 13px; font-variant-numeric: tabular-nums; }
.pick-foot { display: flex; gap: 8px; justify-content: flex-end; align-items: center; padding-top: 4px; border-top: 1px solid var(--line); }
.pick-foot .info { margin-right: auto; font-size: 12.5px; color: var(--text-3); }
.opt-group { display: flex; flex-direction: column; gap: 7px; }
.opt-group > .fb-label { font-size: 12.5px; }
.toggles { display: flex; flex-wrap: wrap; gap: 6px; }
.toggles button { border: 1px solid var(--line-strong); background: var(--surface); border-radius: 9px; padding: 5px 12px; font-size: 13.5px; min-height: 36px; }
.toggles button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.scrim { position: fixed; inset: 0; z-index: 55; background: rgba(15, 23, 42, .12); }

/* ---------- tooltip / toast / modal ---------- */
.tooltip {
  position: fixed; z-index: 80; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 11px; box-shadow: var(--shadow-lg); padding: 9px 12px; font-size: 13px; max-width: 290px;
}
.tooltip .tt-t { font-weight: 600; margin-bottom: 4px; }
.tooltip .tt-r { display: flex; justify-content: space-between; gap: 16px; color: var(--text-2); }
.tooltip .tt-r span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 90;
  background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: 12px; font-size: 14px; box-shadow: var(--shadow-lg);
}
.modal {
  border: 0; border-radius: 20px; padding: 0; width: min(780px, calc(100vw - 24px)); max-height: 86vh;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
}
.modal::backdrop { background: rgba(10, 17, 28, .5); }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--surface); }
.modal-head h2 { margin: 0; font-size: 19px; display: flex; align-items: center; gap: 10px; }
.modal-head h2 .ic { color: var(--accent); }
.modal-head .mini-btn { margin-left: auto; border-color: transparent; }
.modal-body { padding: 8px 22px 22px; }
.modal-body h3 { font-size: 15.5px; margin: 18px 0 6px; display: flex; align-items: center; gap: 8px; }
.modal-body h3 .ic { color: var(--accent); }
.modal-body p, .modal-body li { color: var(--text-2); font-size: 14.5px; }
.modal-body ul { padding-left: 20px; margin: 4px 0; }

.loading { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 80px 0; color: var(--text-3); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.busy { position: absolute; inset: 0; background: color-mix(in srgb, var(--surface) 55%, transparent); display: grid; place-items: center; border-radius: inherit; z-index: 5; }

.footer {
  display: flex; flex-wrap: wrap; gap: 6px 18px; justify-content: space-between; padding: 16px 0 22px;
  color: var(--text-3); font-size: 12.5px; border-top: 1px solid var(--line);
}

/* ---------- responsive ---------- */
@media (max-width: 1440px) { .tabs a { padding: 9px 12px; font-size: 14.5px; } }
@media (max-width: 1180px) { .brand-sub { display: none; } }
@media (max-width: 1279px) {          /* แท็บเล็ตแนวนอน */
  :root { --gutter: 20px; }
  .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .kpis.five { gap: 12px; }
  .kpis.five .kpi { padding: 14px 14px; }
  .kpis.five .k-val { font-size: 24px; }
  .kpis.five .k-spark { width: 64px; }
  .panel { grid-template-columns: 230px minmax(0, 1fr); }
  .fb-week { min-width: 190px; }
  .fb-select { max-width: 170px; }
  .fb-btn .val { max-width: 190px; }
  .tabs a { font-size: 14px; }
}
@media (max-width: 1023px) {
  .kpis.five { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis > .kpi:last-child:nth-child(odd) { grid-column: span 2; }
  .m-s12 { grid-column: span 12; } .m-s6 { grid-column: span 6; }
  .updated { display: none; }
  .tabs a:not(.active) span { display: none; }
  .tabs a { padding: 9px 13px; }
}
@media (max-width: 899px) {           /* แท็บเล็ตแนวตั้ง */
  :root { --gutter: 16px; }
  .filterbar { position: static; }
  .grid > * { grid-column: span 12; }
  .t-s6 { grid-column: span 6 !important; }
  .kpis, .kpis.five { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis > .kpi:last-child:nth-child(odd) { grid-column: span 2; }
  .panel { grid-template-columns: 1fr; }
  .panel-side { display: grid; grid-template-columns: 1fr 1fr; }
  .map-cols { grid-template-columns: 1fr; }
  .page-top h1 { font-size: 22px; }
  .help-btn span { display: none; }
  .summary ul { columns: 1; }
}
@media (max-width: 640px) {
  .kpis, .kpis.five { grid-template-columns: 1fr; }
  .kpis > .kpi:last-child:nth-child(odd) { grid-column: auto; }
  .t-s6 { grid-column: span 12 !important; }
  .panel-side { grid-template-columns: 1fr; }
  .fb-area { flex-wrap: wrap; }
  .brand-text { display: none; }
}

/* ---------- หมายเหตุ / วิธีอ่าน / สรุป / ข้อจำกัด ---------- */
.chart-note {
  margin: 12px 0 0; padding: 9px 12px; font-size: 13px; line-height: 1.6; color: #7a4b00;
  background: #fff8ec; border: 1px solid #f0dcb8; border-radius: var(--radius-sm); display: flex; gap: 8px; align-items: flex-start;
}
.chart-note .ic { width: 15px; height: 15px; margin-top: 3px; color: #b26a00; }
.chart-note:empty { display: none; }
:root[data-theme="dark"] .chart-note { background: #2b2414; border-color: #4d3f17; color: #f0d69a; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chart-note { background: #2b2414; border-color: #4d3f17; color: #f0d69a; } }
.info-btn { display: inline-flex; align-items: center; gap: 5px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--text-2); padding: 0 10px; font-size: 13px; font-weight: 500; }
.info-btn .ic { width: 15px; height: 15px; color: var(--accent); }
.info-btn:hover, .info-btn[aria-expanded="true"] { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-ink); }
.card-info {
  margin: -4px 0 14px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--accent-soft);
  border: 1px solid var(--accent-line); font-size: 13.5px; line-height: 1.65; color: var(--text-2);
}
.card-info b { color: var(--text); font-weight: 600; }
.card-info ul { margin: 4px 0 0; padding-left: 18px; }
.card-info li + li { margin-top: 2px; }
.summary { border-left: 4px solid var(--brand-600); }
.summary ul { margin: 0; padding-left: 20px; columns: 2; column-gap: 36px; font-size: 14.5px; line-height: 1.7; color: var(--text-2); }
.summary li { break-inside: avoid; margin-bottom: 4px; }
.summary li b { color: var(--text); font-weight: 600; }
.summary .hi { color: var(--critical-ink); font-weight: 600; }
.summary .lo { color: var(--good-ink); font-weight: 600; }
.limits { margin-top: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.limits summary { cursor: pointer; padding: 14px 20px; font-weight: 600; display: flex; align-items: center; gap: 10px; list-style: none; }
.limits summary::-webkit-details-marker { display: none; }
.limits summary .ic { width: 20px; height: 20px; color: #b26a00; }
.limits summary .chev { margin-left: auto; color: var(--text-3); transition: transform .15s; }
.limits[open] summary .chev { transform: rotate(180deg); }
.limits .lim-body { padding: 0 20px 18px 50px; color: var(--text-2); font-size: 14px; line-height: 1.7; }
.limits .lim-body ul { margin: 0; padding-left: 18px; }
.limits .lim-body li + li { margin-top: 4px; }

@media print {
  .appbar .tabs, .appbar-tools, .info-btn, .filterbar .btn, .mini-btn, .sample-banner { display: none !important; }
  .appbar { position: static; }
  .filterbar { position: static; box-shadow: none; }
  body { background: #fff; }
  .card, .kpi { break-inside: avoid; box-shadow: none; }
  .tbl-wrap { max-height: none; overflow: visible; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.summary .card-head { align-items: center; }
.summary .card-head .hint { width: auto; margin: 0; padding: 0; }
@media (max-width: 899px) { .summary ul { columns: 1; } }

/* สเกลสีกำหนดเอง */
.info-btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-ink); }
.scale-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.scale-grid > div { grid-column: span 2; display: flex; flex-direction: column; gap: 4px; }
.scale-grid label { display: flex; flex-direction: column; gap: 4px; }
.num-in { border: 1px solid var(--line-strong); border-radius: var(--radius-sm); padding: 8px 10px; background: var(--surface); font-weight: 600; font-variant-numeric: tabular-nums; min-width: 0; }
.num-in:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.scale-preview { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; color: var(--text-2); }
.scale-preview b { background: var(--surface-3); border-radius: 6px; padding: 1px 8px; font-weight: 600; font-variant-numeric: tabular-nums; }
.scale-tag { font-size: 11px; color: var(--text-3); border: 1px solid var(--line); border-radius: 99px; padding: 0 8px; }
.scale-tag.on { color: var(--accent-ink); border-color: var(--accent-line); background: var(--accent-soft); }

/* ---------- ส่วนใหม่ ---------- */
.pyr-legend span i { width: 11px; height: 11px; border-radius: 3px; }
.access { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.access .stat .v { font-size: 22px; }
.access .stat .d { font-size: 12px; color: var(--text-3); }
.hbars { display: grid; grid-template-columns: minmax(90px, auto) 1fr auto; gap: 6px 10px; align-items: center; font-size: 13px; }
.hbars .bar-t { height: 12px; border-radius: 0 4px 4px 0; background: var(--series-this); min-width: 2px; }
.hbars .bar-t.alt { background: var(--brand-500); }
.hbars .lbl { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 210px; }
.hbars .val { font-variant-numeric: tabular-nums; color: var(--text-2); text-align: right; white-space: nowrap; }
.sub-title { font-size: 13.5px; font-weight: 600; color: var(--text-2); margin: 14px 0 8px; display: flex; align-items: center; gap: 6px; }
.sub-title .ic { width: 15px; height: 15px; color: var(--text-3); }
.cal td.c { min-width: 40px; text-align: center; font-size: 12px; }
.cal th.now, .cal td.now { box-shadow: inset 2px 0 0 var(--brand-600), inset -2px 0 0 var(--brand-600); }
.cal th.now { color: var(--brand-ink); }
.cal td.next { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--brand-600) 40%, transparent); }
.fc-text { font-size: 14.5px; color: var(--text-2); line-height: 1.7; margin-bottom: 8px; }
.fc-text b { color: var(--text); }
.section-head { display: flex; align-items: center; gap: 10px; margin: 26px 0 12px; }
.section-head h2 { margin: 0; font-size: 19px; font-weight: 600; display: flex; align-items: center; gap: 10px; }
.section-head h2 .ic { width: 32px; height: 32px; padding: 6px; border-radius: 10px; background: var(--brand-700); color: #fff; }
.section-head .sub { color: var(--text-3); font-size: 13.5px; }
.week-pick { display: flex; align-items: center; gap: 6px; }
.week-pick select { border: 1px solid var(--line-strong); border-radius: 8px; padding: 4px 8px; background: var(--surface); font-weight: 600; }
:root { --male: #8cc3ee; --female: #f4a9c8; --fc-band: rgba(42, 120, 214, .14); }
:root[data-theme="dark"] { --male: #5fa3db; --female: #db7fa6; --fc-band: rgba(57, 135, 229, .18); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --male: #5fa3db; --female: #db7fa6; --fc-band: rgba(57, 135, 229, .18); } }
/* ลักษณะทางระบาดวิทยา */
.epi-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px; }
.epi-col { min-width: 0; }
.epi-head { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; padding-bottom: 8px; margin-bottom: 6px; border-bottom: 2px solid var(--brand-soft); color: var(--brand-ink); }
.epi-head .ic { width: 18px; height: 18px; }
.epi-col .sub-title { margin-top: 12px; }
.epi-col .stat .d { font-size: 12px; color: var(--text-3); }
.ratio-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 4px 0 2px; }
.ratio-line .d { font-size: 12.5px; color: var(--text-3); }
.ratio-badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 12px 3px 9px; border-radius: 99px; font-size: 13.5px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--male) 30%, var(--surface)), color-mix(in srgb, var(--female) 30%, var(--surface)));
  border: 1px solid color-mix(in srgb, var(--male) 45%, var(--line)); color: var(--text); }
.ratio-badge b { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.ratio-badge .ic { width: 15px; height: 15px; }
@media (max-width: 1023px) { .epi-grid { grid-template-columns: 1fr 1fr; } .epi-grid > :last-child { grid-column: span 2; } }
@media (max-width: 640px) { .epi-grid { grid-template-columns: 1fr; } .epi-grid > :last-child { grid-column: auto; } }
/* การ์ดย่อยของลักษณะทางระบาดวิทยา */
.mc-grid { display: grid; gap: 14px; margin-bottom: 14px; }
.mc-grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.mc-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.mini-card { background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px 14px; min-width: 0; display: flex; flex-direction: column; }
.mc-title { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 14px; color: var(--text); margin-bottom: 8px; }
.mc-title .ic { width: 16px; height: 16px; color: var(--brand-ink); }
.donut-wrap { display: flex; align-items: center; gap: 12px; flex: 1; }
.donut-box { position: relative; width: 132px; height: 132px; flex: none; }
.donut-legend { display: flex; flex-direction: column; gap: 5px; min-width: 0; flex: 1; font-size: 13px; }
.dl-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 7px; align-items: center; border: 0; background: none; padding: 2px 0; text-align: left; color: var(--text-2); }
button.dl-row { cursor: pointer; }
button.dl-row:hover .dl-t { color: var(--accent-ink); }
.dl-row.off { opacity: .45; }
.dl-row i { width: 10px; height: 10px; border-radius: 3px; }
.dl-t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-v { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.mini-card .ratio-line { margin-top: 10px; justify-content: center; }
.mc-stat { padding: 8px 0; border-top: 1px dashed var(--line); }
.mc-title + .mc-stat { border-top: 0; padding-top: 0; }
.mc-stat .t { font-size: 12.5px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.mc-stat .t .ic { width: 14px; height: 14px; color: var(--brand-ink); }
.mc-stat .v { font-size: 22px; font-weight: 600; line-height: 1.2; }
.mc-stat .d { font-size: 12px; color: var(--text-3); }
.mc-stat.death .t .ic { color: var(--critical-ink); }
.mini-card .btn.sm { align-self: flex-start; margin-top: 4px; }
@media (max-width: 1279px) { .mc-grid.four { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 899px) { .mc-grid.two { grid-template-columns: 1fr; } }
@media (max-width: 640px) { .mc-grid.four { grid-template-columns: 1fr; } }
