/* โทนสาธารณสุข: เขียวน้ำทะเลเข้ม (หลัก) · แถบเมนูซ้ายสีเข้ม · ผลประเมินยังใช้ เขียว/เหลือง/แดง แยกจากสีหลัก */
:root {
  --bg: #f3f6f8; --card: #fff; --text: #1c2b33; --muted: #637582; --line: #dce4e9;
  --primary: #0e7490; --primary-dark: #0b5e75; --primary-ink: #fff; --primary-soft: #e8f4f7; --primary-line: #bcdfe8;
  --danger: #c62f3b; --ok: #1f8a43; --warn: #b7791f;
  --side-bg: #0f3b47; --side-ink: #cfe5eb; --side-muted: #86aab4; --accent: #5fd4c4;
  --head-h: 64px; --side-w: 252px;
  --radius: 10px; --shadow: 0 1px 3px rgba(16,42,52,.08);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: 'Sarabun', system-ui, sans-serif; font-size: 16px; background: var(--bg); color: var(--text); }
a { color: var(--primary); }
h2 { margin: 0; font-size: 1.35rem; } h3 { margin: 0 0 .3rem; font-size: 1.1rem; }

.top { display: flex; align-items: center; gap: .5rem 1rem; min-height: var(--head-h); padding: .45rem 20px; background: #fff;
  border-top: 3px solid var(--primary); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 900; }
.brand { display: inline-flex; align-items: center; gap: .6rem; font-weight: 600; text-decoration: none; color: #0f3b47; font-size: 1.1rem; line-height: 1.25; min-width: 0; }
.brand img { width: 40px; height: 40px; flex: none; }
.brand-text { display: flex; flex-direction: column; }
.brand .yr { color: var(--primary); }
.brand .org { font-weight: 400; font-size: .8rem; color: var(--muted); }
.login-head { display: flex; flex-direction: column; align-items: center; gap: .3rem; text-align: center; margin-bottom: .3rem; }
.login-head img { width: 96px; height: 96px; }
.login-head .org { color: var(--muted); font-size: .92rem; }
#nav { display: flex; align-items: center; margin-left: auto; }

/* ---- โครงหน้า: เมนูซ้าย + เนื้อหา ---- */
#side { display: none; }
.content { min-width: 0; }
@media (min-width: 769px) {
  body.has-side .shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); align-items: start; }
  body.has-side #side { display: flex; flex-direction: column; gap: 2px; position: sticky; top: var(--head-h); height: calc(100vh - var(--head-h));
    overflow-y: auto; background: var(--side-bg); color: var(--side-ink); padding: .6rem .75rem 1rem; }
  body.has-side main { max-width: 1180px; margin: 1.4rem auto; padding: 0 24px; }
}
.side-sec { font-size: .78rem; font-weight: 600; color: var(--side-muted); padding: 1rem .75rem .35rem; letter-spacing: .02em; }
.side-sec:first-child { padding-top: .6rem; }
.side-link { position: relative; display: flex; align-items: center; gap: .7rem; padding: .58rem .75rem; border-radius: 8px;
  color: var(--side-ink); text-decoration: none; font-size: .96rem; line-height: 1.3; }
.side-link svg { width: 20px; height: 20px; flex: none; opacity: .8; }
.side-link:hover { background: rgba(255,255,255,.07); color: #fff; }
.side-link:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.side-link.on { background: rgba(255,255,255,.13); color: #fff; font-weight: 600; }
.side-link.on svg { opacity: 1; color: var(--accent); }
.side-link.on::before { content: ''; position: absolute; left: -.75rem; top: 7px; bottom: 7px; width: 4px; border-radius: 0 4px 4px 0; background: var(--accent); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: .1rem; padding: .9rem .75rem 0; border-top: 1px solid rgba(255,255,255,.12);
  font-size: .8rem; color: var(--side-muted); }
.side-foot strong { color: #fff; font-size: .9rem; font-weight: 600; }

/* ---- เมนูผู้ใช้ บนขวา ---- */
.um { position: relative; }
.um-btn { display: flex; align-items: center; gap: .6rem; font: inherit; color: var(--text); background: none; border: 1px solid transparent;
  border-radius: 10px; padding: .3rem .55rem .3rem .3rem; cursor: pointer; max-width: 360px; }
.um-btn:hover, .um-btn[aria-expanded=true] { background: var(--primary-soft); border-color: var(--primary-line); }
.um-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.um-btn > svg { width: 18px; height: 18px; color: var(--muted); flex: none; transition: transform .15s; }
.um-btn[aria-expanded=true] > svg { transform: rotate(180deg); }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 600; flex: none; }
.avatar.lg { width: 44px; height: 44px; font-size: 1.15rem; }
.um-name { display: flex; flex-direction: column; text-align: left; line-height: 1.25; min-width: 0; }
.um-name strong, .um-name small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.um-name strong { font-size: .95rem; }
.um-name small { color: var(--muted); font-size: .78rem; }
.um-menu { position: absolute; right: 0; top: calc(100% + 8px); width: 290px; background: #fff; border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 14px 36px rgba(15,59,71,.18); padding: .4rem; z-index: 1000; }
.um-menu[hidden] { display: none; }
.um-head { display: flex; gap: .7rem; align-items: center; padding: .65rem .7rem .8rem; margin-bottom: .2rem; border-bottom: 1px solid var(--line); }
.um-head div { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.um-head small { color: var(--muted); font-size: .8rem; }
.um-sec { font-size: .76rem; font-weight: 600; color: var(--muted); padding: .55rem .75rem .2rem; }
.um-menu a, .um-menu button { display: flex; align-items: center; gap: .65rem; width: 100%; padding: .55rem .75rem; border-radius: 8px; color: var(--text);
  text-decoration: none; background: none; border: 0; font: inherit; font-size: .95rem; cursor: pointer; text-align: left; }
.um-menu a:hover, .um-menu button:hover, .um-menu a:focus-visible, .um-menu button:focus-visible { background: var(--primary-soft); outline: none; }
.um-menu a.on { color: var(--primary); font-weight: 600; }
.um-menu svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.um-menu a.on svg { color: var(--primary); }
.um-menu .danger-t, .um-menu .danger-t svg { color: var(--danger); }
.um-menu hr { border: 0; border-top: 1px solid var(--line); margin: .35rem 0; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1rem; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }
.banner { background: #fff3cd; padding: .6rem 16px; text-align: center; }
main { max-width: 1100px; margin: 1.2rem auto; padding: 0 16px; }
.foot { text-align: center; font-size: .85rem; padding: 1.5rem 16px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; }
.narrow { max-width: 440px; margin: 0 auto; }
.stack { display: flex; flex-direction: column; gap: .9rem; }
.row { display: flex; gap: .6rem; align-items: center; }
.row > label { flex: 1; }
.wrap { flex-wrap: wrap; } .between { justify-content: space-between; } .end { justify-content: flex-end; } .center { text-align: center; justify-content: center; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .9rem; }
.tile { text-decoration: none; color: inherit; } .tile:hover { border-color: var(--primary); }
.tile.disabled { opacity: .6; }
.muted { color: var(--muted); }
.err { color: var(--danger); margin: 0; }
.note { background: var(--primary-soft); border-color: var(--primary-line); padding: .7rem .9rem; border-radius: var(--radius); }

label { display: block; font-weight: 600; font-size: .95rem; }
label > input, label > select, label > textarea, label > .row { display: flex; margin-top: .3rem; }
label small { font-weight: 400; }
label.check { display: flex; flex-direction: row; align-items: center; gap: .4rem; font-weight: 400; }
label.check > input { margin-top: 0; }
input, select, textarea { font: inherit; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9fd3df; border-color: var(--primary); }
label.check input { width: auto; }
select#ag { max-width: 320px; }
select#fm, select#dist { width: auto; max-width: 220px; }
.row select#ag { width: auto; }

.btn { font: inherit; border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: .55rem 1rem; cursor: pointer; }
a.btn { text-decoration: none; color: inherit; display: inline-block; }
a.btn.primary { color: #fff; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 600; }
.btn.primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn:not(.primary):hover { border-color: var(--primary-line); }
.btn.danger { color: var(--danger); border-color: #f0c4c8; }
.btn.ghost { background: transparent; }
.btn.small { padding: .25rem .6rem; font-size: .9rem; }
.btn:disabled { opacity: .6; cursor: wait; }
button.link { background: none; border: 0; color: var(--primary); font: inherit; cursor: pointer; padding: 0; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; flex-wrap: wrap; }
.seg button { font: inherit; border: 0; background: #fff; padding: .35rem .8rem; cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--primary); color: #fff; }

.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #f8fafc; font-size: .9rem; white-space: nowrap; }
td.num, th.num { text-align: right; }
td.acts { white-space: nowrap; text-align: right; }
tr.suspended td { color: var(--muted); }
tr.pending td { background: #fffbea; }
.pill { display: inline-block; padding: .1rem .55rem; border-radius: 99px; font-size: .85rem; background: #eef1f4; }
.pill.active { background: #e3f4e8; color: var(--ok); } .pill.pending { background: #fff1c2; color: var(--warn); } .pill.suspended { background: #f3e1e3; color: var(--danger); }
.badge { display: inline-block; min-width: 1.6em; text-align: center; background: var(--danger); color: #fff; border-radius: 99px; padding: 0 .4em; }
code { background: #f1f3f5; padding: 0 .3em; border-radius: 4px; }

.dlg { border: 0; border-radius: var(--radius); padding: 1.2rem; width: min(460px, calc(100vw - 32px)); box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.dlg.wide { width: min(860px, calc(100vw - 32px)); }
.dlg form { max-height: calc(100vh - 80px); overflow-y: auto; }
.dlg textarea { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; min-height: 5.5rem; }
.dlg fieldset { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .8rem; margin: 0; }
.dlg fieldset legend { font-weight: 600; padding: 0 .3rem; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem .9rem; }
.optrows { width: 100%; border-collapse: collapse; }
.optrows td { padding: .2rem .25rem; border: 0; }
.optrows input[type=text], .optrows input:not([type]) { min-width: 0; }
.desc { font-size: .88rem; color: var(--primary-dark); background: var(--primary-soft); border-radius: 6px; padding: .3rem .5rem; }
.tabs { display: flex; flex-wrap: wrap; gap: .3rem; border-bottom: 1px solid var(--line); }
.tabs button { font: inherit; background: none; border: 0; padding: .5rem .9rem; cursor: pointer; border-bottom: 3px solid transparent; }
.tabs button.on { border-color: var(--primary); font-weight: 600; }
tr.inactive td { color: var(--muted); text-decoration: line-through; }
tr.inactive td.acts { text-decoration: none; }
.dlg::backdrop { background: rgba(0,0,0,.35); }
.cred { background: #f8fafc; border: 1px dashed var(--line); padding: .7rem; border-radius: 8px; font-size: 1.05rem; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); padding: .7rem 1.1rem; border-radius: 8px; color: #fff; background: var(--ok); z-index: 1000; max-width: calc(100vw - 32px); }
.toast-error { background: var(--danger); }

/* ---- บันทึกข้อมูล ---- */
.req { color: var(--danger); }
.big { font-size: 1.15rem; font-weight: 600; margin: .3rem 0; }
.houses { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .6rem; }
.house { display: flex; flex-direction: column; gap: .2rem; text-decoration: none; color: inherit; padding: .7rem; position: relative; }
.house strong { font-size: 1.1rem; }
.house .dot { position: absolute; top: .7rem; right: .7rem; width: 12px; height: 12px; border-radius: 50%; }
fieldset.q { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .4rem; }
fieldset.q legend, .qlabel { font-weight: 600; font-size: .95rem; padding: 0; margin-bottom: .3rem; }
.opts { display: flex; flex-wrap: wrap; gap: .4rem; }
/* ข้อย่อย: เยื้องตามชั้น อยู่ใต้ข้อหลักในการ์ดเดียวกัน */
.q-sub { margin-left: calc((var(--d, 1) - 1) * 1rem + .4rem); padding: .55rem 0 .55rem .85rem; border-left: 3px solid var(--primary-line); display: flex; flex-direction: column; gap: .4rem; }
.q-sub > .q, .q-sub > fieldset.q { margin: 0; }
/* รหัสผ่านชั่วคราวหลังรีเซ็ต */
.pw-box { display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: .6rem; border: 1.5px solid var(--primary-line); border-radius: 10px; padding: .8rem; background: var(--primary-soft); }
.pw-box > div { display: flex; flex-direction: column; gap: .2rem; }
.pw-box code { font-size: 1.15rem; padding: .3rem .5rem; background: #fff; border-radius: 6px; user-select: all; word-break: break-all; }
.pw-box code.pw { font-size: 1.35rem; letter-spacing: .08em; font-weight: 700; }
.pw-box + .pw-box { margin-top: .5rem; }
.pw-box .pw-who, .pw-box .pw-acts { grid-column: 1 / -1; }
.pw-box > .pw-acts { flex-direction: row; justify-content: flex-start; align-items: center; gap: .4rem; }
.rr-card { border-left: 4px solid var(--warn, #d97706); }
.rr-card .filters { padding: 0; }
.rr-bulk { border-top: 1px solid var(--line); padding-top: .6rem; }
.pill.role-admin { background: #fff4e5; color: #9a4b00; border: 1px solid #f3c98b; }
.pill.role-user { background: var(--primary-soft); color: var(--primary-dark); border: 1px solid var(--primary-line); }
.pill.role-superadmin { background: #f3e8ff; color: #6b21a8; border: 1px solid #d8b4fe; }
/* กรอบกลุ่มข้อ (ข้อหลัก + ข้อย่อย) */
.q-group { border: 1.5px solid var(--primary-line); border-left: 4px solid var(--primary); border-radius: 10px; padding: .8rem .9rem; background: #fbfdfe; display: flex; flex-direction: column; gap: .5rem; }
.q-group .q-sub { border-left-color: var(--primary-line); }
table tbody.fgroup.has-sub > tr > td { background: #f7fbfc; }
table tbody.fgroup.has-sub > tr:first-child > td { border-top: 2px solid var(--primary-line); }
table tbody.fgroup.has-sub > tr:last-child > td { border-bottom: 2px solid var(--primary-line); }
table tbody.fgroup.has-sub > tr > td:first-child { box-shadow: inset 4px 0 0 var(--primary); }
table tbody.fgroup.has-sub > tr > td:last-child { box-shadow: inset -2px 0 0 var(--primary-line); }
table tbody.fgroup.has-sub + tbody > tr:first-child > td { border-top: 0; }
/* ตารางฟิลด์: รายการข้อย่อยใต้ข้อหลัก */
.sub-list { list-style: none; margin: .45rem 0 0; padding: 0; display: flex; flex-direction: column; gap: .15rem; font-size: .85rem; }
.sub-list li { padding-left: calc((var(--d, 1) - 1) * 1.1rem); }
.sub-list li.off { opacity: .55; text-decoration: line-through; }
.pager { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; justify-content: center; margin-top: .75rem; }
.pager .btn[disabled] { opacity: .45; cursor: default; }
.pager .btn.primary[disabled] { opacity: 1; }
.btn.primary-soft { background: var(--primary-soft); border-color: var(--primary-line); color: var(--primary-dark); }
/* หน้าแก้ข้อ: ลำดับขั้นของกลุ่มข้อ */
.fstep-box { border: 1.5px solid var(--primary-line); border-left: 4px solid var(--primary); border-radius: 10px; padding: .7rem .8rem; background: #fbfdfe; display: flex; flex-direction: column; gap: .5rem; }
.fstep { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .3rem; }
.fstep-i { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; margin-left: calc(var(--d, 0) * 1.4rem); position: relative; }
.fstep-i[style*="--d:1"], .fstep-i[style*="--d:2"], .fstep-i[style*="--d:3"], .fstep-i[style*="--d:4"] { padding-left: .6rem; border-left: 2px solid var(--primary-line); }
.fstep-go { flex: 1 1 16rem; min-width: 0; display: flex; align-items: baseline; gap: .5rem; text-align: left; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: .4rem .6rem; cursor: pointer; font: inherit; color: inherit; }
.fstep-go:hover { border-color: var(--primary-line); }
.fstep-i.on > .fstep-go { border: 2px solid var(--primary); background: var(--primary-soft); cursor: default; }
.fstep-i.new > .fstep-go { border-style: dashed; }
.fstep-i.off > .fstep-go { opacity: .6; }
.fstep-l { display: flex; flex-direction: column; min-width: 0; }
.fstep-l small { color: var(--muted); }
.fstep-acts { display: flex; gap: .25rem; flex-wrap: wrap; }
.pv-list { list-style: none; padding-left: 0; }
.pv-list li { padding-top: .25rem; padding-bottom: .25rem; }
.pv-head, .pv-sub { background: #f7fbfc; border-left: 4px solid var(--primary); border-right: 1.5px solid var(--primary-line); }
.pv-head { border-top: 1.5px solid var(--primary-line); border-radius: 8px 8px 0 0; margin-top: .4rem; }
.pv-end { border-bottom: 1.5px solid var(--primary-line); border-radius: 0 0 8px 8px; margin-bottom: .4rem; }
.q-note { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; max-width: 28rem; }
.fnum { display: inline-block; min-width: 2.2rem; font-variant-numeric: tabular-nums; color: var(--muted); font-weight: 600; }
.ftree-sub td:nth-child(2) { padding-left: calc(var(--d, 1) * 1.1rem + .5rem); }
.ftree-sub td:nth-child(2)::before { content: '↳ '; color: var(--muted); }
.sub-of { display: inline-block; font-size: .78rem; color: var(--muted); }
.opt-spec { display: flex; flex-direction: column; gap: .15rem; font-size: .8rem; }
.opt { display: flex; flex-direction: row; align-items: center; gap: .4rem; font-weight: 400; border: 1px solid var(--line); border-radius: 8px; padding: .45rem .7rem; cursor: pointer; background: #fff; }
.opt:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.opt input { width: auto; margin: 0; }
.check { display: inline-flex; align-items: center; gap: .4rem; font-weight: 400; }
.check input { width: auto; }
.unit { color: var(--muted); white-space: nowrap; }
.computed { font-size: 1.05rem; padding: .3rem 0; }
.photo-pick label.btn { display: inline-flex; align-items: center; gap: .3rem; cursor: pointer; font-weight: 400; }
.photo, .photo-preview { max-width: 100%; max-height: 360px; border-radius: 8px; border: 1px solid var(--line); object-fit: contain; align-self: flex-start; }
.computed.bad { color: var(--danger); font-weight: 600; }
.birth > * { flex: 1; min-width: 0; }
.birth select { flex: 1.4; }
.summary > div { padding: .15rem 0; }
.score { border-left: 4px solid var(--primary); }
.sticky { position: sticky; bottom: 0; background: var(--bg); padding: .6rem 0; }
.pill.lv-pass { background: #e3f4e8; color: var(--ok); } .pill.lv-risk { background: #fff1c2; color: var(--warn); }
.pill.lv-fail { background: #f3e1e3; color: var(--danger); } .pill.lv-incomplete { background: #eef1f4; color: var(--muted); }

/* ---- dashboard ---- */
:root { --lv-pass: #28a745; --lv-risk: #ffc107; --lv-fail: #dc3545; --lv-none: #6c757d; --lv-incomplete: #ced4da; }
.small { font-size: .85rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .9rem; }
.kpi .big-num { font-size: 2.2rem; font-weight: 600; line-height: 1.2; }
.kpi-row { display: flex; flex-wrap: wrap; gap: .3rem 1.1rem; margin-top: .5rem; font-size: .95rem; }
.track { display: block; height: 8px; background: #e9ecef; border-radius: 4px; overflow: hidden; margin-top: .4rem; }
.track .fill { display: block; height: 100%; background: var(--primary); border-radius: 0 4px 4px 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: .9rem; }
/* สุขภาพจิต / ภาวะพึ่งพิง */
:root { --mh-high: #fd7e14; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: .9rem 1.4rem; }
.mh h4 { margin: .2rem 0 0; font-size: .98rem; }
.mh-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .6rem; margin: .5rem 0 1rem; }
.mh-tile { border: 1px solid var(--line); border-radius: 10px; padding: .55rem .75rem; }
.mh-num { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.mh-ok { background: var(--lv-pass); } .mh-warn { background: var(--lv-risk); } .mh-high { background: var(--mh-high); } .mh-bad { background: var(--lv-fail); }
.stack-bar .mh-warn { color: #1f2933; }
.legend { display: flex; flex-wrap: wrap; gap: .3rem 1rem; font-size: .9rem; margin: .4rem 0 .6rem; }
.legend span, .legend label { display: inline-flex; align-items: center; gap: .35rem; }
.sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.lv-pass { background: var(--lv-pass); } .lv-risk { background: var(--lv-risk); } .lv-fail { background: var(--lv-fail); }
.lv-none { background: var(--lv-none); } .lv-incomplete { background: var(--lv-incomplete); }
.sbars { display: flex; flex-direction: column; gap: .55rem; }
.srow { display: grid; grid-template-columns: 7.5rem 1fr 3.5rem; align-items: center; gap: .6rem; font-size: .92rem; }
.srow.strong { font-weight: 600; border-top: 1px solid var(--line); padding-top: .55rem; }
.srow .val, .hbar .val { text-align: right; font-variant-numeric: tabular-nums; }
.stack-bar { display: flex; gap: 2px; height: 22px; }
.stack-bar > span { display: flex; align-items: center; justify-content: center; color: #fff; font-size: .78rem; min-width: 3px; }
.stack-bar > span:first-child { border-radius: 4px 0 0 4px; } .stack-bar > span:last-child { border-radius: 0 4px 4px 0; }
.stack-bar > span:only-child { border-radius: 4px; }
.stack-bar .lv-risk, .stack-bar .lv-incomplete { color: #1f2933; }
.stack-bar .empty { color: var(--muted); background: #f1f3f5; flex: 1; border-radius: 4px; }
.hbars { display: flex; flex-direction: column; gap: .45rem; }
.hbar { display: grid; grid-template-columns: 7.5rem 1fr 5.5rem; align-items: center; gap: .6rem; font-size: .92rem; }
.hbar .track { margin: 0; height: 12px; }
.cov { display: inline-flex; align-items: center; gap: .35rem; white-space: nowrap; }
.cov i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.cov-good i { background: var(--lv-pass); } .cov-mid i { background: var(--lv-risk); } .cov-low i { background: var(--lv-fail); }
.map { height: min(70vh, 620px); border-radius: var(--radius); border: 1px solid var(--line); z-index: 0; }
.leaflet-popup-content a { color: var(--primary); }
/* กลุ่มจุดใช้สีกลาง ไม่ให้สับสนกับสีผลประเมิน (เขียว/เหลือง/แดง) */
.map .marker-cluster-small, .map .marker-cluster-medium, .map .marker-cluster-large { background: rgba(52, 73, 94, .25); }
.map .marker-cluster-small div, .map .marker-cluster-medium div, .map .marker-cluster-large div { background: #34495e; color: #fff; font-weight: 600; }

/* กล่องสรุปบ้านบนแผนที่ */
.hpop { display: flex; flex-direction: column; gap: .35rem; font-size: .88rem; }
.hpop-head { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.hpop-list { max-height: 220px; overflow-y: auto; border-top: 1px solid var(--line); }
.hpop-list table { width: 100%; border-collapse: collapse; }
.hpop-list td { padding: .3rem .2rem; border-bottom: 1px solid #f0f2f4; vertical-align: top; font-size: .85rem; }
.hpop-list td:last-child { text-align: right; white-space: nowrap; }
.gone summary { cursor: pointer; font-weight: 600; }
.gone ul { list-style: none; margin: .5rem 0 0; padding: 0; }
.gone li { padding: .4rem 0; border-top: 1px solid var(--line); gap: .5rem; }
.ok-t { color: var(--ok); } .risk-t { color: var(--warn); } .fail-t { color: var(--danger); }

/* ---- ประวัติการประเมิน ---- */
.carried { display: inline-block; font-size: .72rem; font-weight: 500; line-height: 1.3; padding: .05rem .4rem; border-radius: 999px;
  background: #fff4d6; color: #7a5300; border: 1px solid #f0d58a; vertical-align: middle; white-space: nowrap; }
.carry-note { margin-top: .6rem; }
.suggest { margin-top: .35rem; font-size: .88rem; background: #eef5ff; border: 1px solid #c9dcf5; border-radius: 8px; padding: .3rem .55rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .6rem; }
.suggest.warn { background: #fff1e6; border-color: #f2c39b; color: #7a3a00; }
.imp-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .6rem; }
.imp-kpis > div { border: 1px solid var(--line); border-radius: 10px; padding: .55rem .7rem; }
.imp-kpis b { display: block; font-size: 1.5rem; line-height: 1.2; }
.imp-kpis small { color: var(--muted, #667); }
table.imp td:first-child, table.imp-rows td:first-child { width: 2rem; }
table.imp input[type=checkbox], table.imp-rows input[type=checkbox] { width: 1.2rem; height: 1.2rem; }
.visit-bar { margin-top: .6rem; padding-top: .6rem; border-top: 1px solid var(--line); gap: .5rem; }
.history summary { cursor: pointer; }
.hist { margin: .6rem 0 .3rem; padding-left: 1.4rem; display: flex; flex-direction: column; gap: .45rem; }
.hist li { display: flex; flex-wrap: wrap; align-items: center; gap: .2rem .5rem; }
.hist-date { font-weight: 600; min-width: 7.5rem; }

/* ---- ผู้ใช้งาน: ตัวกรอง + สรุป ---- */
.filters { display: flex; flex-wrap: wrap; gap: .75rem 1rem; align-items: flex-end; padding: .9rem 1.1rem; }
.filters > label { flex: 1 1 170px; font-size: .88rem; }
.filters > label.f-search { flex: 2 1 280px; }
.filters select, .filters input { margin-top: .3rem; }
.filters select#dist, .filters select#ag { width: 100%; max-width: none; }
.f-status { display: flex; flex-direction: column; gap: .3rem; }
.f-label { font-weight: 600; font-size: .88rem; }
.u-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .75rem; }
.u-kpi { display: flex; flex-direction: column; gap: .15rem; border: 1px solid var(--line); border-radius: 10px; padding: .7rem .9rem; background: #fff; }
.u-kpi > span:first-child { color: var(--muted); font-size: .88rem; }
.u-kpi b { font-size: 1.8rem; line-height: 1.15; font-variant-numeric: tabular-nums; }
.u-kpi b small { font-size: 1rem; font-weight: 400; }
.u-kpi small { color: var(--muted); font-size: .82rem; }
.u-kpi.warn { border-color: #f0d58a; background: #fffbea; }
.u-kpi .track { margin: .25rem 0 .1rem; }
.u-dash h3 small { font-weight: 400; font-size: .8rem; }
table.u-sum td, table.u-sum th { padding: .45rem .65rem; font-variant-numeric: tabular-nums; }
table.u-sum tr.click { cursor: pointer; }
table.u-sum tr.click:hover td { background: var(--primary-soft); }
table.u-sum tr.u-none td:first-child { border-left: 3px solid var(--warn); }
.u-bar { display: flex; align-items: center; gap: .5rem; min-width: 140px; }
.u-bar .track { flex: 1; margin: 0; height: 8px; }
.u-bar b { min-width: 2.2rem; text-align: right; }
/* ปิดระบบชั่วคราว */
.banner.closing { background: #fdecee; color: #8a1f29; border-bottom: 1px solid #f3c6cb; font-weight: 500; }
.closed-page { max-width: 560px; margin: 3rem auto; text-align: center; align-items: center; padding: 2rem 1.5rem; }
.closed-ic { width: 72px; height: 72px; border-radius: 50%; background: #fdecee; color: var(--danger); display: grid; place-items: center; }
.closed-page h2 { margin: 0; }
.closed-msg { font-size: 1.08rem; background: var(--primary-soft); border-radius: 8px; padding: .7rem 1rem; margin: 0; white-space: pre-line; }
.row.center { justify-content: center; }
.closure-card.is-closed { border-left: 4px solid var(--danger); }
.closure-card h3 { margin: 0; }
.closure-who { margin: 0; padding-left: 1.1rem; display: flex; flex-direction: column; gap: .2rem; }
.card .filters { padding: 0; }
.closure-bulk { border-top: 1px solid var(--line); padding-top: .8rem; }
.btn.danger-fill { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-fill:hover { background: #a8252f; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
table.closure-list td:first-child, table.closure-list th:first-child { width: 2.2rem; }
table.closure-list input[type=checkbox] { width: 18px; height: 18px; }
/* แบบฟอร์ม: ภาพรวมคะแนน + เกณฑ์ */
.crit-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .75rem; }
.crit-card { gap: .55rem; }
.crit-max { color: var(--muted); font-size: .88rem; } .crit-max b { color: var(--text); font-size: 1.15rem; }
.cbar { position: relative; display: flex; gap: 2px; height: 12px; margin: .3rem 0 1.15rem; }
.cbar > span { display: block; height: 100%; border-radius: 3px; min-width: 2px; }
.cbar i { position: absolute; top: 14px; transform: translateX(-50%); font-style: normal; font-size: .75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.z-pass { background: var(--ok); } .z-risk { background: #e0a526; } .z-fail { background: var(--danger); }
.clegend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .2rem; font-size: .9rem; }
.clegend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .4rem; vertical-align: baseline; }
table.sc-matrix td.na { color: #b5c0c8; } table.sc-matrix td.off { color: var(--muted); font-size: .85rem; }
table.sc-matrix td.ov, .ov-key { font-weight: 700; color: var(--primary-dark); }
table.sc-matrix tfoot th { background: var(--primary-soft); border-top: 2px solid var(--primary-line); }
table.sc-matrix th:first-child, table.sc-matrix td:first-child { min-width: 200px; }
.sc-max { display: inline-block; background: var(--primary-soft); color: var(--primary-dark); border-radius: 99px; padding: 0 .5rem; font-weight: 600; }
/* หน้าต่างแก้ฟิลด์: คะแนน */
.sc-box { border-color: var(--primary-line) !important; background: #fbfdfe; }
.sc-toggle { font-size: 1rem; }
.sc-off .sc-col, .dlg [hidden] { display: none !important; }
.sc-overview { gap: .9rem; } .sc-overview h3 { margin: .6rem 0 0; }
.sc-step { display: flex; gap: .7rem; align-items: flex-start; padding-top: .55rem; border-top: 1px dashed var(--line); }
.sc-step > .stack { flex: 1; gap: .4rem; min-width: 0; }
.sc-n { flex: none; width: 1.6rem; height: 1.6rem; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: .85rem; font-weight: 600; }
label.inline { display: inline-flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
label.inline input { width: auto; }
.optrows.rng input { width: 100%; max-width: 8rem; }
.ov-list { display: flex; flex-direction: column; gap: .4rem; }
.ov-row { display: grid; grid-template-columns: minmax(7rem, 10rem) 1fr; gap: .4rem .6rem; align-items: center; }
.ov-row select { max-width: 20rem; }
.ov-row .ov-custom { grid-column: 2; background: var(--primary-soft); border-radius: 8px; padding: .4rem .6rem; }
.ov-row.off .ov-g { color: var(--muted); text-decoration: line-through; }
@media (max-width: 640px) { .ov-row { grid-template-columns: 1fr; } .ov-row .ov-custom { grid-column: 1; }
  table.sc-matrix th:first-child, table.sc-matrix td:first-child { min-width: 140px; } }
.u-ag summary { cursor: pointer; font-weight: 600; padding: .2rem 0 .5rem; }

/* ---- หน้าสาธารณะ ---- */
.pub-head { display: flex; align-items: center; gap: .9rem; }
.pub-head img { width: 64px; height: 64px; flex: none; }
.pub-head h1 { font-size: 1.35rem; margin: 0; }
.pub-head p { margin: .15rem 0 0; }
.pmap { height: min(60vh, 480px); }

/* ---- ประเมินสุขภาพตนเอง (ประชาชน) ---- */
.sc { max-width: 760px; margin: 0 auto; }
.narrow-l { max-width: 520px; width: 100%; margin: 0 auto; }
.sc-cta { display: flex; align-items: center; gap: .8rem; margin-top: 1rem; text-decoration: none; color: var(--text);
  border: 2px solid var(--primary); background: var(--primary-soft); }
.sc-cta:hover { background: #d9eef3; }
.sc-cta > span:nth-child(2) { flex: 1; display: flex; flex-direction: column; gap: .1rem; }
.sc-cta strong { color: var(--primary-dark); font-size: 1.1rem; }
.sc-cta small { color: var(--muted); }
.sc-cta-ic { flex: none; width: 48px; height: 48px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; }
.sc-cta-go { font-size: 1.8rem; color: var(--primary); line-height: 1; }
.sc-privacy { margin: 0; }
.sc-who { align-items: center; }
.sc-score { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.sc-score .big-num { font-size: 2.6rem; font-weight: 700; line-height: 1; }
.sc-score .pill { align-self: center; font-size: 1rem; padding: .2rem .8rem; }
.sc-gauge { position: relative; height: 14px; background: #e9ecef; border-radius: 7px; overflow: hidden; }
.sc-gauge .fill { display: block; height: 100%; border-radius: 7px; }
.sc-gauge i { position: absolute; top: 0; bottom: 0; width: 2px; background: #fff; }
.sc-result { border-top: 6px solid var(--lv-incomplete); }
.sc-result.lvb-pass { border-top-color: var(--lv-pass); } .sc-result.lvb-risk { border-top-color: var(--lv-risk); } .sc-result.lvb-fail { border-top-color: var(--lv-fail); }
.sc-lead { font-size: 1.05rem; margin: .2rem 0 0; }
.sc-topics { padding-left: 1.3rem; display: flex; flex-direction: column; gap: .7rem; margin: 0; }
.sc-topics ul { margin: .25rem 0 0; padding-left: 1.1rem; }
.sc-topics li li { margin: .15rem 0; }
.sc-pub { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }

/* ---- รายการรอตรวจสอบ ---- */
.chip { font: inherit; font-size: .9rem; border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: .25rem .75rem; cursor: pointer; }
.chip b { font-variant-numeric: tabular-nums; margin-left: .2rem; }
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip-group { margin-top: .7rem; display: flex; flex-direction: column; gap: .3rem; }
.flag { display: inline-block; font-size: .8rem; padding: .05rem .45rem; border-radius: 6px; background: #fff1c2; color: #7a5a00; margin: .1rem 0; }
.flag.k-person { background: #e8eefc; color: #2c4a8a; } .flag.k-answer { background: #fdeaea; color: #8a2c2c; }
.flag.k-house { background: #e9f5ee; color: #24603a; } .flag.k-info { background: #eef1f4; color: var(--muted); }
.flag.cur { outline: 2px solid currentColor; }
td.acts { white-space: nowrap; } td.acts .btn { margin: .1rem 0; }
.ok { color: var(--ok); font-weight: 600; }

/* ---- แถบเมนูล่าง + ปุ่มลอย (แสดงเฉพาะจอเล็ก) ---- */
#tabbar, .fab { display: none; }
.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.toolbar select, .toolbar input { width: auto; flex: 1 1 200px; }
.toolbar .seg { flex: 0 0 auto; }
input[type=search]::-webkit-search-cancel-button { cursor: pointer; }

@media (max-width: 768px) {
  /* หัวเว็บกะทัดรัด: เมนูย้ายไปแถบล่าง */
  body.has-tabbar #nav { display: none; }
  .top { padding: .4rem 12px; min-height: 0; }
  .brand img { width: 34px; height: 34px; }
  .brand { font-size: 1rem; }
  main { margin: .8rem auto; padding: 0 12px; }
  body.has-tabbar { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  body.has-tabbar .foot { padding-bottom: 1rem; }

  #tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 950; background: #fff; border-top: 1px solid var(--line);
    padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); box-shadow: 0 -2px 10px rgba(0,0,0,.06); }
  body:not(.has-tabbar) #tabbar { display: none; }
  #tabbar > a, #tabbar > button { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 54px; text-decoration: none; color: var(--muted); font: inherit; font-size: .75rem; background: none; border: 0; border-radius: 10px; cursor: pointer; }
  #tabbar > .on { color: var(--primary); font-weight: 600; }
  #tabbar > .on svg { stroke-width: 2.4; }
  /* "บันทึก" เด่นที่สุด */
  #tabbar > a.main { color: #fff; background: var(--primary); margin: 0 4px; font-weight: 600; }
  #tabbar > a.main:not(.on) { background: #2a8ca6; }
  .sheet { position: absolute; right: 8px; bottom: calc(100% + 8px); width: min(280px, calc(100vw - 16px)); background: #fff; border: 1px solid var(--line);
    border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: .4rem; display: flex; flex-direction: column; }
  .sheet[hidden] { display: none; }
  .sheet a, .sheet button { display: block; text-align: left; padding: .8rem .9rem; border-radius: 10px; text-decoration: none; color: var(--text); font: inherit; background: none; border: 0; cursor: pointer; min-height: 44px; }
  .sheet a.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
  .sheet .danger-t { color: var(--danger); border-top: 1px solid var(--line); border-radius: 0 0 10px 10px; }
  .sheet-who { display: flex; flex-direction: column; padding: .6rem .9rem .7rem; border-bottom: 1px solid var(--line); margin-bottom: .2rem; font-size: .9rem; }

  .hide-m { display: none !important; }
  .fab { display: inline-flex; align-items: center; gap: .35rem; position: fixed; right: 14px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 940;
    background: var(--primary); color: #fff; text-decoration: none; font-weight: 600; padding: .85rem 1.15rem; border-radius: 99px; box-shadow: 0 6px 16px rgba(14,116,144,.35); }
  .fab span { font-size: 1.2rem; line-height: 1; }

  /* รายการบ้าน: แถบค้นหาติดด้านบน · การ์ดบ้านใหญ่ กดง่าย */
  .survey .toolbar { position: sticky; top: 55px; z-index: 800; background: var(--bg); padding: .4rem 0; margin: -.4rem 0 0; }
  .toolbar select, .toolbar input { flex: 1 1 100%; }
  .toolbar .seg { display: flex; width: 100%; }
  .toolbar .seg button { flex: 1; padding: .55rem .3rem; font-size: .88rem; }
  .houses { grid-template-columns: repeat(3, 1fr); gap: .5rem; padding-bottom: 4.5rem; }
  .house { min-height: 72px; padding: .65rem; }

  /* ปุ่มและช่องกรอกใหญ่ขึ้น (≥ 44px) · ขนาดตัวอักษร 16px กัน iOS ซูม */
  .btn { min-height: 44px; }
  .btn.small { min-height: 38px; padding: .35rem .7rem; }
  input, select, textarea { min-height: 44px; font-size: 16px; }
  .opts { gap: .5rem; }
  .opt { min-height: 46px; flex: 1 1 calc(50% - .5rem); padding: .55rem .75rem; }
  .sticky { bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 850; padding: .5rem 0; }
  .sticky .btn { width: 100%; }

  /* ตารางสมาชิกในหน้าบ้าน → การ์ดรายคน */
  .mcards-wrap { background: none; border: 0; overflow: visible; }
  table.mcards thead { display: none; }
  table.mcards, table.mcards tbody { display: block; }
  table.mcards tr { display: block; background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
    padding: .75rem .85rem; margin-bottom: .6rem; box-shadow: var(--shadow); }
  table.mcards tr.todo { border-left: 4px solid var(--primary); }
  table.mcards td { display: flex; justify-content: space-between; align-items: center; gap: .7rem; border: 0; padding: .18rem 0; text-align: right; }
  table.mcards td.mc-title { display: block; font-weight: 600; font-size: 1.05rem; margin-bottom: .25rem; text-align: left; }
  table.mcards td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: .88rem; text-align: left; flex: none; }
  table.mcards td.acts { flex-wrap: wrap; justify-content: stretch; gap: .4rem; margin-top: .5rem; }
  table.mcards td.acts .btn { flex: 1 1 auto; text-align: center; }
  table.mcards td.center { display: block; text-align: center; }
}

@media (max-width: 640px) {
  td.acts { white-space: normal; }
  .grid2 { grid-template-columns: 1fr; }
  .srow, .hbar { grid-template-columns: 5.5rem 1fr 3rem; }
  th, td { padding: .45rem .5rem; }
}
