/* ========= ระบบสีและตัวอักษร: เอกสารราชการ เขียวสาธารณสุข + เส้นทองแบบหัวกระดาษราชการ ========= */
:root {
  --bg: #F3F6F4; --surface: #FFFFFF; --line: #D6DFDA; --line-soft: #E8EEEA; --head-row: #EEF3F0;
  --ink: #18261F; --ink-2: #33433B; --muted: #5A6A62;
  --brand: #0D5C46; --brand-ink: #08402F; --brand-deep: #062F23; --brand-soft: #E1EEE8; --brand-mid: #0F7A5C;
  --gold: #B38B3D; --gold-soft: #F4ECDA; --gold-ink: #7A5A1C;
  --good: #0ca30c; --good-ink: #136B22; --good-soft: #E1F2E1;
  --warn: #fab219; --warn-ink: #7A4B00; --warn-soft: #FBF0D6;
  --bad: #d03b3b; --bad-ink: #9A2525; --bad-soft: #F8E0DF;
  --series: #0F7A5C; --grid: #E3E9E5;
  --radius: 10px; --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(6, 47, 35, .06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: 'Sarabun', 'TH Sarabun New', sans-serif; font-size: 16px; line-height: 1.6; }
a { color: var(--brand); text-underline-offset: 3px; } a:hover { color: var(--brand-ink); }
h1 { font-size: 28px; margin: 0; line-height: 1.3; font-weight: 700; letter-spacing: -0.005em; }
h2 { font-size: 19px; margin: 0 0 6px; line-height: 1.4; font-weight: 700; }
h3 { font-size: 16px; margin: 0 0 4px; font-weight: 700; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 15px; }
.small { font-size: 14px; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ========= หัวกระดาษ (แถบบน) ========= */
.topbar { background: var(--brand-deep); color: #fff; border-bottom: 3px solid var(--gold); display: flex; align-items: center; gap: 14px; padding: 10px 24px; min-height: 68px; }
.emblem { flex: 0 0 auto; width: 46px; height: 46px; border-radius: 50%; border: 2px solid var(--gold); background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 16px; letter-spacing: .02em; overflow: hidden; }
.emblem img { width: 100%; height: 100%; object-fit: cover; }
.emblem:has(img) { background: #fff; }
.login-logo { display: block; width: min(260px, 70%); height: auto; margin: 0 auto 4px; }
.hero-mark { display: block; width: 88px; height: 88px; border-radius: 50%; border: 3px solid var(--gold); margin-bottom: 14px; background: #fff; }
@media (max-width: 560px) { .hero-mark { width: 68px; height: 68px; } }
.org { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.org span { font-size: 13px; color: #CFE3DA; }
.org b { font-size: 18px; font-weight: 700; }
.top-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.top-actions a, .top-actions button { color: #fff; }
.btn.on-dark { background: transparent; border-color: rgba(255, 255, 255, .45); color: #fff; }
.btn.on-dark:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.btn.gold { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn.gold:hover { background: var(--gold-ink); color: #fff; }

/* ========= โครงหน้าแอป ========= */
.shell { display: flex; flex-wrap: wrap; min-height: calc(100vh - 71px); }
.side { flex: 1 1 220px; max-width: 248px; background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; }
.side a.nav { display: flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 12px; border-radius: var(--radius-sm); color: var(--ink-2); text-decoration: none; font-size: 15.5px; border-left: 3px solid transparent; }
.side a.nav:hover { background: var(--bg); color: var(--ink); }
.side a.nav.on { background: var(--brand-soft); color: var(--brand-ink); font-weight: 700; border-left-color: var(--gold); border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.side .sep { margin: 14px 12px 4px; font-size: 13px; color: var(--muted); font-weight: 600; }
.side .me { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--line-soft); font-size: 13.5px; color: var(--muted); }
.side .me b { color: var(--ink); display: block; }
main { flex: 999 1 560px; min-width: 0; padding: 28px 36px 64px; display: flex; flex-direction: column; gap: 22px; max-width: 1400px; }
.demo-bar { background: var(--gold-soft); color: var(--gold-ink); padding: 8px 14px; border-radius: var(--radius-sm); font-size: 14.5px; border: 1px solid #E6D3A8; }

.head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.head h2 { margin: 0; }
section .head, .card .head { border-bottom: 0; padding-bottom: 0; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cols { display: flex; flex-wrap: wrap; gap: 20px; align-items: stretch; }
.cols > * { flex: 1 1 320px; min-width: 0; }
.cols > .wide { flex: 2 1 460px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); }
.card > h2:first-child { padding-bottom: 8px; margin-bottom: 10px; border-bottom: 1px solid var(--line-soft); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }

/* ตัวเลขสรุป */
.figs { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.fig { padding: 16px 20px; border-left: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: 2px; }
.fig:first-child { border-left: 0; }
.fig .k { font-size: 14px; color: var(--muted); }
.fig .v { font-size: 30px; font-weight: 700; line-height: 1.2; color: var(--brand-ink); font-variant-numeric: tabular-nums; }
.fig .v small { font-size: 16px; color: var(--muted); font-weight: 400; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-size: 28px; font-weight: 700; line-height: 1.2; color: var(--brand-ink); }

/* ปุ่ม */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px; padding: 0 16px; border-radius: var(--radius-sm); border: 1px solid #C3CEC8; background: var(--surface); color: var(--ink); font: inherit; font-size: 15px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--bg); color: var(--ink); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-ink); color: #fff; }
.btn.danger { color: var(--bad-ink); border-color: #E4B8B5; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 14px; }
.btn[disabled] { opacity: .5; cursor: default; }

/* ป้ายสถานะ: สี + คำเสมอ */
.tag { display: inline-block; padding: 1px 10px; border-radius: 999px; font-size: 13px; background: var(--line-soft); color: var(--ink-2); white-space: nowrap; }
.tag.good { background: var(--good-soft); color: var(--good-ink); }
.tag.warn { background: var(--warn-soft); color: var(--warn-ink); }
.tag.bad { background: var(--bad-soft); color: var(--bad-ink); }
.tag.brand { background: var(--brand-soft); color: var(--brand-ink); }

/* ตาราง */
.tbl-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 15px; }
th { text-align: left; font-weight: 700; color: var(--ink-2); padding: 9px 10px; background: var(--head-row); border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
tr.click { cursor: pointer; } tr.click:hover td { background: #F6F9F7; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.list > .item { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line-soft); }
.list > .item:first-child { border-top: 0; }

/* ฟอร์ม */
form.f { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px 20px; }
form.f .full { grid-column: 1 / -1; }
label.fl { display: flex; flex-direction: column; gap: 5px; font-size: 15px; font-weight: 600; color: var(--ink-2); }
label.fl .req { color: var(--bad-ink); }
input, select, textarea { font: inherit; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid #C3CEC8; border-radius: var(--radius-sm); padding: 9px 11px; min-height: 44px; width: 100%; }
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
input[disabled], select[disabled], textarea[disabled] { background: #F2F5F3; color: var(--muted); }
.hint { font-weight: 400; font-size: 13.5px; color: var(--muted); }

dl.kv { display: grid; grid-template-columns: minmax(160px, 260px) 1fr; gap: 0; margin: 0; }
dl.kv dt, dl.kv dd { padding: 8px 0; border-bottom: 1px solid var(--line-soft); margin: 0; }
dl.kv dt { color: var(--muted); font-size: 15px; padding-right: 16px; }
dl.kv dd { white-space: pre-wrap; }

.bar { height: 8px; border-radius: 999px; background: var(--line-soft); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--series); border-radius: 999px; }

.kanban { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 6px; }
.kanban .col { flex: 0 0 220px; display: flex; flex-direction: column; gap: 8px; background: #EAF0EC; border-radius: var(--radius); padding: 10px; }
.kanban .col > h3 { font-size: 14.5px; display: flex; justify-content: space-between; padding: 0 4px; margin: 0; }
.pc { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px; display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--ink); }
.pc:hover { border-color: var(--brand); color: var(--ink); }

.empty { color: var(--muted); padding: 14px 0; font-size: 15px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--brand-deep); color: #fff; padding: 10px 18px; border-radius: var(--radius-sm); z-index: 60; font-size: 15px; border-bottom: 2px solid var(--gold); max-width: calc(100vw - 32px); }
.login { max-width: 480px; margin: 8vh auto; display: flex; flex-direction: column; gap: 14px; text-align: center; }
.gate { max-width: 780px; margin: 5vh auto; padding: 0 16px 40px; display: flex; flex-direction: column; gap: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid #C3CEC8; background: #fff; font: inherit; font-size: 14.5px; cursor: pointer; color: var(--ink-2); }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.video-box { border: 1px solid var(--brand); background: var(--brand-soft); border-radius: var(--radius); padding: 16px 18px; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }

/* ========= กราฟ ========= */
.chart { width: 100%; height: auto; display: block; font-family: inherit; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 14px; }
.chart .lab { fill: var(--ink-2); font-size: 15px; }
.chart .val { fill: var(--ink); font-size: 15px; font-weight: 700; }
.chart .mark { fill: var(--series); }
.chart .mark.o0 { fill: #86b6ef; } .chart .mark.o1 { fill: #6da7ec; } .chart .mark.o2 { fill: #5598e7; } .chart .mark.o3 { fill: #3987e5; }
.chart .mark.o4 { fill: #2a78d6; } .chart .mark.o5 { fill: #256abf; } .chart .mark.o6 { fill: #1c5cab; }
.chart .line { fill: none; stroke: var(--series); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series); opacity: .1; }
.chart .dot { fill: var(--series); stroke: var(--surface); stroke-width: 2; }
.chart .target { stroke: var(--gold); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .hit { outline: none; }
.chart .hit:hover .mark, .chart .hit:focus .mark { fill: var(--brand-ink); }
.chart .hit:hover .dot, .chart .hit:focus .dot { r: 6; }
.chart-note { font-size: 13.5px; color: var(--muted); margin-top: 6px; }
details.tv { margin-top: 8px; font-size: 14px; }
details.tv summary { cursor: pointer; color: var(--brand); width: fit-content; }
details.tv table { margin-top: 8px; font-size: 14px; }

.split { display: flex; gap: 2px; height: 22px; border-radius: 4px; overflow: hidden; background: var(--line-soft); }
.split .seg { min-width: 4px; }
.seg.good, .sw.good { background: var(--good); } .seg.warn, .sw.warn { background: var(--warn); } .seg.bad, .sw.bad { background: var(--bad); } .seg.none, .sw.none { background: #B9C4BE; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 8px; font-size: 14.5px; color: var(--ink-2); }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* Scorecard ตัวชี้วัด */
.score { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 0 28px; }
.sc { padding: 12px 0 10px; border-bottom: 1px solid var(--line-soft); outline: none; }
.sc:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.sc-top { display: flex; gap: 10px; align-items: baseline; }
.sc-code { font-weight: 700; color: var(--brand-ink); font-size: 14px; flex: 0 0 34px; }
.sc-name { flex: 1; font-size: 15px; line-height: 1.4; color: var(--ink-2); }
.sc-val { font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.bullet { position: relative; height: 10px; margin: 8px 0 6px 44px; background: var(--line-soft); border-radius: 4px; }
.bullet .fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 0 4px 4px 0; background: var(--series); }
.bullet .fill.warn { background: var(--warn); } .bullet .fill.good { background: var(--good); } .bullet .fill.none { background: transparent; }
.bullet .tick { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--ink); margin-left: -1px; }
.sc-foot { display: flex; justify-content: space-between; margin-left: 44px; font-size: 13.5px; color: var(--muted); }
.st { display: inline-flex; gap: 5px; align-items: center; font-weight: 600; }
.st i { font-style: normal; display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; font-size: 11px; color: #fff; }
.st.good { color: var(--good-ink); } .st.good i { background: var(--good); }
.st.warn { color: var(--warn-ink); } .st.warn i { background: #C98500; }
.st.none i { background: #9AA6A0; }

.tooltip { position: fixed; z-index: 70; pointer-events: none; background: var(--brand-deep); color: #fff; font-size: 14px; padding: 6px 10px; border-radius: var(--radius-sm); max-width: 320px; line-height: 1.4; box-shadow: 0 4px 12px rgba(0, 0, 0, .15); }

/* ========= หน้าสาธารณะ ========= */
.pub { background: var(--bg); min-height: 100vh; }
.pub-nav { background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.pub-nav .in { max-width: 1160px; margin: 0 auto; padding: 0 24px; display: flex; gap: 4px; overflow-x: auto; }
.pub-nav button { background: none; border: 0; border-bottom: 3px solid transparent; font: inherit; font-size: 15.5px; padding: 12px 12px 9px; color: var(--ink-2); cursor: pointer; white-space: nowrap; }
.pub-nav button:hover { color: var(--brand); border-bottom-color: var(--gold); }
.pub-hero { background: var(--brand); color: #fff; }
.pub-hero .in { max-width: 1160px; margin: 0 auto; padding: 44px 24px 40px; display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 40px; align-items: end; }
.pub-hero h1 { font-size: 36px; line-height: 1.25; margin: 6px 0 14px; text-wrap: balance; }
.pub-hero p { color: #D7EAE1; font-size: 18px; max-width: 34em; }
.pub-hero .sub { color: #CFE3DA; font-size: 15px; }
.ledger { background: var(--brand-deep); border-top: 3px solid var(--gold); border-radius: 0 0 var(--radius) var(--radius); padding: 6px 20px 10px; }
.ledger .r { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 10px 0; border-bottom: 1px solid rgba(255, 255, 255, .12); }
.ledger .r:last-of-type { border-bottom: 0; }
.ledger .r span { color: #CFE3DA; font-size: 15.5px; }
.ledger .r b { font-size: 26px; font-variant-numeric: tabular-nums; }
.ledger .asof { font-size: 13px; color: #A9C7BA; padding-top: 6px; }
.pub-sec { scroll-margin-top: 52px; max-width: 1160px; margin: 0 auto; padding: 44px 24px 8px; }
.pub-sec > h2 { font-size: 26px; margin-bottom: 4px; }
.pub-sec > .lead { color: var(--muted); margin-bottom: 18px; max-width: 46em; }
.about { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; }
.about h3 { color: var(--brand-ink); border-bottom: 2px solid var(--gold); padding-bottom: 6px; margin-bottom: 8px; width: fit-content; }
.about ol { margin: 0; padding-left: 20px; }
.work { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; padding: 14px 0; border-top: 1px solid var(--line-soft); }
.work:first-child { border-top: 0; }
.work .t { font-weight: 700; font-size: 17px; }
.team-h { font-size: 18px; color: var(--brand-ink); border-bottom: 2px solid var(--gold); width: fit-content; padding-bottom: 4px; margin: 22px 0 12px; }
.team-h:first-of-type { margin-top: 4px; }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 16px; }
.person { background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--brand); border-radius: 10px; padding: 18px; display: grid; grid-template-columns: 96px 1fr; gap: 16px; align-items: start; }
.ph { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; border: 2px solid var(--gold); background: var(--brand); display: block; }
.ph.mono { display: grid; place-items: center; color: #fff; font-size: 38px; font-weight: 700; }
.ph.sm { width: 44px; height: 44px; font-size: 18px; }
.person .nm { font-weight: 700; font-size: 17.5px; line-height: 1.35; }
.person .pos { color: var(--muted); font-size: 15px; }
.person .role { color: var(--brand); font-weight: 600; font-size: 15px; margin-top: 4px; }
.person dl { margin: 10px 0 0; font-size: 15px; line-height: 1.5; }
.person dt { color: var(--muted); display: inline; }
.person dt::after { content: ' '; }
.person dd { margin: 0 0 2px; display: inline; overflow-wrap: anywhere; }
.person dd::after { content: ''; display: block; }
.team-admin { list-style: none; margin: 0; padding: 0; }
.team-admin li { display: grid; grid-template-columns: 44px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line-soft); }
@media (max-width: 560px) {
  .person { grid-template-columns: 72px 1fr; padding: 14px; gap: 12px; }
  .person .ph:not(.sm) { width: 72px; height: 72px; font-size: 28px; }
  .people { grid-template-columns: 1fr; }
  .team-admin li { grid-template-columns: 44px 1fr; }
  .team-admin li .row { grid-column: 1 / -1; }
}
.pub-foot { margin-top: 48px; background: var(--brand-deep); color: #D7EAE1; border-top: 3px solid var(--gold); }
.pub-foot .in { max-width: 1160px; margin: 0 auto; padding: 28px 24px; display: flex; flex-wrap: wrap; gap: 24px 48px; justify-content: space-between; }
.pub-foot b { color: #fff; }
.pub-foot a { color: #fff; }

@media (max-width: 860px) {
  .pub-hero .in { grid-template-columns: 1fr; padding-top: 32px; }
  .pub-hero h1 { font-size: 30px; }
}
@media (max-width: 760px) {
  .topbar { padding: 10px 16px; }
  .org b { font-size: 16px; }
  .top-actions .hide-sm { display: none; }
  .side { max-width: none; flex-basis: 100%; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; }
  .side .sep, .side .me { display: none; }
  .side a.nav { min-height: 38px; font-size: 14.5px; border-left: 0; }
  main { padding: 18px 16px 48px; }
  dl.kv { grid-template-columns: 1fr; }
  dl.kv dt { border-bottom: 0; padding-bottom: 0; }
  .fig { border-left: 0; border-top: 1px solid var(--line-soft); }
  .fig:first-child { border-top: 0; }
  .pub-sec { padding: 32px 16px 8px; }
}
@media print {
  .side, .topbar, .no-print, .demo-bar, .pub-nav { display: none !important; }
  main { padding: 0; }
  .card { border: 0; padding: 0; box-shadow: none; }
  body { background: #fff; }
}
