/* angthong-pmc — shared styles (design tokens + base copied from kpi-health, then the components this site needs).
   Colour: cool teal-biased neutrals, one teal accent. Group colours come from assets/config/schemes.js and are applied inline
   as the CSS variable --gc. Dark mode = :root[data-theme='dark'] (toggle in the header, saved in localStorage). */
:root {
  color-scheme: light;
  --font-body: 'Sarabun', 'Noto Sans Thai', 'Leelawadee UI', Tahoma, sans-serif;

  --bg: #f2f6f6;
  --surface: #ffffff;
  --surface-2: #e9f0f0;
  --ink: #102a2e;
  --ink-2: #3f5558;
  --muted: #5a6d70;
  --line: #d5e0e0;
  --grid: #e3eaea;
  --axis: #b9c8c9;
  --accent: #0b6e75;
  --accent-ink-text: #0b6e75;
  --accent-soft: #dcefef;
  --on-accent: #ffffff;
  --logo-plate: transparent;

  --ok-ink: #0a6a0a;
  --warn: #fab219;
  --warn-ink: #7a5000;
  --bad-ink: #a82323;
  --ok-bg: #e2f3df;
  --warn-bg: #fdf0cc;
  --bad-bg: #fbe1df;
  --na-bg: #eef2f2;

  --cal-weekend: #eef2f2;
  --cal-nodata: transparent;
  --overlay: rgba(242, 246, 246, 0.96);

  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 42, 46, 0.06), 0 2px 10px rgba(16, 42, 46, 0.05);
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #0d1618;
  --surface: #152124;
  --surface-2: #1c2b2e;
  --ink: #edf5f5;
  --ink-2: #bccbcd;
  --muted: #97a9ab;
  --line: #2a3b3e;
  --grid: #223134;
  --axis: #3a4c4f;
  --accent: #52c2c8;
  --accent-ink-text: #6fd3d8;
  --accent-soft: #173a3d;
  --on-accent: #062426;
  --logo-plate: #ffffff;

  --ok-ink: #6bdc6b;
  --warn: #fab219;
  --warn-ink: #f5c451;
  --bad-ink: #ff8f86;
  --ok-bg: #16361b;
  --warn-bg: #3a2f12;
  --bad-bg: #43201f;
  --na-bg: #1b2729;

  --cal-weekend: #182427;
  --overlay: rgba(13, 22, 24, 0.96);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
img { max-width: 100%; height: auto; }
a { color: var(--accent-ink-text); }
a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { text-wrap: balance; margin: 0; }
.num, table { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

.wrap { max-width: 1400px; margin-inline: auto; padding-inline: 16px; }
@media (min-width: 700px) { .wrap { padding-inline: 24px; } }

/* ── Header ─────────────────────────────────────────── */
.site-header { background: var(--surface); border-bottom: 1px solid var(--line); z-index: 20; }
.hdr-row {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px 24px; padding-block: 10px;
}
.brand { display: flex; align-items: center; gap: 14px; text-decoration: none; color: inherit; min-width: 0; }
.brand-plate { background: var(--logo-plate); border-radius: 8px; padding: 2px 6px; display: inline-flex; flex: none; }
.brand-logo { height: 44px; width: auto; display: block; }
.brand-text { display: flex; flex-direction: column; gap: 1px; line-height: 1.25; min-width: 0; }
.brand-text strong { font-size: 1.1rem; font-weight: 700; color: var(--ink); }
.brand-sub { color: var(--muted); font-size: 0.9rem; }
.hdr-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.hdr-link { font-weight: 600; font-size: 0.95rem; text-decoration: none; }
.hdr-link:hover { text-decoration: underline; }
.theme-btn, .btn {
  font: inherit; font-size: 0.95rem; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: transparent; color: var(--ink-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 14px; cursor: pointer;
}
.theme-btn:hover, .btn:hover { color: var(--ink); border-color: var(--axis); }

/* ── Main scaffolding ──────────────────────────────── */
.main { padding-block: 16px 32px; display: flex; flex-direction: column; gap: 18px; outline: none; min-width: 0; }
.main > * { min-width: 0; }
.loading, .muted { color: var(--muted); }
.small { font-size: 0.88rem; }
.crumbs { margin: 0; font-size: 0.98rem; }
.crumbs a { text-decoration: none; font-weight: 500; }
.crumbs a:hover { text-decoration: underline; }
.page-title { font-size: clamp(1.5rem, 3.2vw, 2.1rem); font-weight: 800; line-height: 1.2; }
.page-title .swatch { display: inline-block; width: 0.55em; height: 0.55em; border-radius: 3px; background: var(--gc, var(--accent)); margin-right: 0.3em; }
.footer { border-top: 1px solid var(--line); color: var(--muted); font-size: 0.9rem; padding-block: 16px; text-align: center; }

/* ── Controls ──────────────────────────────────────── */
.controls { display: flex; flex-wrap: wrap; align-items: end; gap: 10px 16px; }
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.field > span, .field-label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
select, input[type='text'], input[type='password'], input[type='tel'], input[type='email'], textarea {
  font: inherit; font-size: 1rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--axis); border-radius: 8px; padding: 6px 10px; min-width: 0; max-width: 100%;
}
select { padding-right: 6px; }
.asof { color: var(--ink-2); font-size: 0.92rem; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 14px; }
.asof-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); margin-right: 6px; }
.flags { display: flex; flex-wrap: wrap; gap: 6px; }
.flag {
  display: inline-block; font-size: 0.82rem; font-weight: 600; line-height: 1.5; padding: 1px 10px;
  border-radius: 999px; background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn);
}

/* segmented toggle (metric switch) */
.seg { display: inline-flex; flex-wrap: wrap; background: var(--surface-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  font: inherit; font-size: 0.95rem; font-weight: 600; cursor: pointer; border: 0; background: transparent;
  color: var(--ink-2); padding: 4px 16px; border-radius: 999px;
}
.seg button:hover { color: var(--ink); background: var(--surface); }
.seg button[aria-pressed='true'] { background: var(--accent); color: var(--on-accent); }

/* ── Panels / cards ────────────────────────────────── */
.panel {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; display: flex; flex-direction: column; gap: 10px;
}
.panel-hd { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 20px; }
.panel-hd h2 { font-size: 1.2rem; font-weight: 700; }
.panel-sub { margin: 0; color: var(--muted); font-size: 0.92rem; }

.cards { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
.cards.c5s { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 1100px) { .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 720px) { .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 440px) { .cards { grid-template-columns: minmax(0, 1fr); } }
.gcard {
  display: flex; flex-direction: column; gap: 4px; min-width: 0;
  background: var(--surface); border: 1px solid var(--line); border-top: 6px solid var(--gc, var(--accent));
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px 12px;
  color: var(--ink); text-decoration: none;
}
a.gcard:hover { border-color: var(--gc, var(--accent)); box-shadow: 0 2px 14px rgba(16, 42, 46, 0.14); }
.gcard-name { font-weight: 700; display: flex; align-items: center; gap: 6px; }
.gcard-name::after { content: '›'; margin-left: auto; color: var(--muted); font-weight: 400; }
div.gcard .gcard-name::after { content: none; }
.gcard-baht { font-size: clamp(1.4rem, 2.1vw, 1.9rem); font-weight: 800; line-height: 1.15; }
.gcard-baht small { font-size: 0.55em; font-weight: 600; color: var(--muted); margin-left: 3px; }
.gcard dl { margin: 4px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 1px 12px; font-size: 0.93rem; }
.gcard dt { color: var(--muted); }
.gcard dd { margin: 0; text-align: right; font-weight: 600; }
.gcard-extra { margin: 6px 0 0; font-size: 0.82rem; color: var(--muted); line-height: 1.4; }
.dash { cursor: help; border-bottom: 1px dotted var(--muted); }

.strip {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 22px;
  background: var(--surface); border: 1px solid var(--line); border-left: 6px solid var(--ink-2);
  border-radius: var(--radius); padding: 10px 16px;
}
.strip b { font-size: 1.05rem; }
.strip .lbl { color: var(--muted); font-size: 0.88rem; margin-right: 4px; }
.strip .note { flex-basis: 100%; color: var(--muted); font-size: 0.85rem; }

/* ── Chart ─────────────────────────────────────────── */
.chart-box { position: relative; height: 340px; width: 100%; }
@media (max-width: 600px) { .chart-box { height: 280px; } }

/* ── Data tables ───────────────────────────────────── */
.table-scroll { overflow-x: auto; overscroll-behavior-x: contain; max-width: 100%; border: 1px solid var(--line); border-radius: 8px; }
table.dt { border-collapse: collapse; width: 100%; font-size: 0.93rem; }
.dt th, .dt td { padding: 6px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
.dt th { background: var(--surface-2); font-weight: 600; color: var(--ink-2); position: sticky; top: 0; }
.dt th:first-child, .dt td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); z-index: 1; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.dt th:first-child { background: var(--surface-2); z-index: 2; }
.dt tr.sub td { color: var(--ink-2); font-size: 0.88rem; }
.dt tr.sub td:first-child { padding-left: 28px; }
.dt tr.tot td { font-weight: 700; border-top: 2px solid var(--axis); }
.dt tr.hl td { background: var(--warn-bg); }
.dt td.l, .dt th.l { text-align: left; }
.dt tr.hl td:first-child { background: var(--warn-bg); }
.expander {
  font: inherit; font-weight: 600; background: transparent; border: 0; color: inherit; cursor: pointer;
  padding: 0; display: inline-flex; align-items: center; gap: 6px; text-align: left;
}
.expander::before { content: '▸'; color: var(--muted); display: inline-block; width: 1em; transition: transform 0.12s; }
.expander[aria-expanded='true']::before { transform: rotate(90deg); }
.sw { display: inline-block; width: 11px; height: 11px; border-radius: 3px; background: var(--gc); flex: none; }
.lt5 { color: var(--muted); font-style: italic; }

/* ── Calendar heat strip ───────────────────────────── */
.cal-month { display: grid; grid-template-columns: 70px 1fr; align-items: start; gap: 4px 10px; padding-block: 3px; }
.cal-label { font-weight: 600; font-size: 0.92rem; padding-top: 2px; }
.cal-days { display: flex; flex-wrap: wrap; gap: 2px; }
.cal-day {
  width: 24px; height: 24px; border-radius: 4px; font-size: 0.68rem; line-height: 24px; text-align: center;
  background: var(--surface-2); color: var(--ink-2); cursor: default; flex: none;
}
@media (max-width: 600px) { .cal-day { width: 19px; height: 22px; line-height: 22px; font-size: 0.62rem; } .cal-month { grid-template-columns: 56px 1fr; } }
.cal-day.has { background: color-mix(in srgb, var(--accent) calc(var(--lv) * 1%), var(--surface-2)); color: var(--ink); font-weight: 600; }
.cal-day.has.dk { color: #fff; }
:root[data-theme='dark'] .cal-day.has.dk { color: #062426; }
.cal-day.zero-wd { background: var(--warn); color: #3a2800; font-weight: 700; }
.cal-day.wknd { background: var(--cal-weekend); color: var(--muted); opacity: 0.75; }
.cal-day.nodata { background: transparent; border: 1px dashed var(--axis); color: var(--muted); opacity: 0.6; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.85rem; color: var(--muted); align-items: center; }
.legend .cal-day { width: 18px; height: 18px; line-height: 18px; display: inline-block; vertical-align: middle; margin-right: 4px; }

/* ── Paired bars (sex / age) ───────────────────────── */
.pairs { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px 22px; }
.pair-metric h3 { font-size: 0.95rem; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.pair-row { display: grid; grid-template-columns: 70px 1fr; align-items: center; gap: 8px; margin-block: 3px; }
.pair-lbl { font-size: 0.9rem; color: var(--ink-2); }
.pair-bar { display: block; background: var(--surface-2); border-radius: 5px; height: 26px; position: relative; overflow: hidden; }
.pair-fill { display: block; height: 100%; background: var(--gc, var(--accent)); border-radius: 5px; }
.pair-row:nth-of-type(2) .pair-fill { opacity: 0.6; }
.pair-val { position: absolute; left: 8px; top: 0; line-height: 26px; font-size: 0.85rem; font-weight: 700; color: var(--ink); text-shadow: 0 0 3px var(--surface); }

/* ── Notes ─────────────────────────────────────────── */
.notes ul { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 4px; font-size: 0.92rem; color: var(--ink-2); }
.warn-box { background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn); border-radius: 8px; padding: 8px 12px; font-size: 0.92rem; }
.ok-box { background: var(--ok-bg); color: var(--ok-ink); border-radius: 8px; padding: 8px 12px; }
.err-box { background: var(--bad-bg); color: var(--bad-ink); border-radius: 8px; padding: 8px 12px; }

/* ── PIN gate overlay ──────────────────────────────── */
.gate {
  position: fixed; inset: 0; z-index: 100; background: var(--overlay); backdrop-filter: blur(6px);
  display: grid; place-items: center; padding: 16px;
}
.gate-box {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 22px 22px 20px; width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; text-align: center;
}
.gate-box h2 { font-size: 1.25rem; }
.pin-input { font-size: 1.8rem; letter-spacing: 0.5em; text-align: center; padding: 8px 10px 8px 0.5em; width: 100%; }
.btn-primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); padding: 8px 20px; font-size: 1rem; }
.btn-primary:hover { background: var(--accent); color: var(--on-accent); filter: brightness(1.08); }
.btn-primary:disabled { opacity: 0.5; cursor: wait; }
.btn-danger { color: var(--bad-ink); border-color: var(--bad-ink); }
.btn-danger:hover { background: var(--bad-bg); color: var(--bad-ink); }
.btn-sm { padding: 2px 12px; font-size: 0.88rem; }
.msg { min-height: 1.4em; font-size: 0.93rem; margin: 0; }
.msg.err { color: var(--bad-ink); }
.msg.ok { color: var(--ok-ink); }

/* ── Menu (home) ───────────────────────────────────── */
.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.menu-card {
  display: flex; flex-direction: column; gap: 6px; padding: 20px 22px; text-decoration: none; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-top: 6px solid var(--accent);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
a.menu-card:hover { border-color: var(--accent); box-shadow: 0 2px 14px rgba(16, 42, 46, 0.14); }
.menu-card h2 { font-size: 1.35rem; font-weight: 800; }
.menu-card p { margin: 0; color: var(--ink-2); font-size: 0.97rem; }
.menu-card.soon { border-top-color: var(--axis); opacity: 0.6; }
.menu-card.soon h2 { color: var(--muted); }

/* ── Admin ─────────────────────────────────────────── */
.adm-section { scroll-margin-top: 12px; }
.adm-row { display: flex; flex-wrap: wrap; align-items: end; gap: 10px 14px; }
.dropzone {
  display: block; border: 2px dashed var(--axis); border-radius: var(--radius); padding: 22px 16px; text-align: center;
  background: var(--surface-2); color: var(--ink-2); cursor: pointer;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone input { display: none; }
.progress { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; width: 40%; background: var(--accent); border-radius: 999px; animation: slide 1s ease-in-out infinite; }
@keyframes slide { 0% { margin-left: -40%; } 100% { margin-left: 100%; } }
@media (prefers-reduced-motion: reduce) { .progress > i { animation: none; width: 100%; } }
.sheet-list { display: flex; flex-direction: column; gap: 6px; }
.sheet-list label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.switch { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.badge { display: inline-block; font-size: 0.78rem; font-weight: 700; padding: 0 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-ink-text); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.chip-list { display: flex; flex-wrap: wrap; gap: 4px 6px; margin: 0; padding: 0; list-style: none; }
.chip-list li { background: var(--surface-2); border-radius: 6px; padding: 0 8px; font-size: 0.85rem; }
.table-scroll.tall { max-height: 440px; overflow-y: auto; }
