:root {
    --bg: #f4f6f5;
    --surface: #ffffff;
    --ink: #1a2421;
    --muted: #5f6f6a;
    --line: #e2e8e5;
    --accent: #0f766e;      /* teal เข้ม */
    --accent-2: #0d5f58;
    --warn: #c2410c;
    --danger: #b91c1c;
    --ok: #15803d;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(16, 40, 34, .08), 0 4px 16px rgba(16, 40, 34, .05);
    font-family: "Sarabun", "Noto Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); line-height: 1.55; }
a { color: var(--accent); }

/* ---------- Auth ---------- */
.auth-body { display: grid; place-items: center; min-height: 100vh; padding: 20px;
    background: linear-gradient(135deg, #0f766e 0%, #134e48 100%); }
.auth-card { width: 100%; max-width: 380px; background: var(--surface);
    padding: 32px 28px; border-radius: 16px; box-shadow: var(--shadow); }
.auth-title { margin: 0 0 4px; font-size: 1.25rem; }
.auth-sub { margin: 0 0 20px; color: var(--muted); font-size: .9rem; }

/* ---------- Forms ---------- */
label { display: block; margin-bottom: 14px; font-size: .88rem; font-weight: 600; color: var(--muted); }
input, select, textarea { width: 100%; margin-top: 5px; padding: 10px 12px; font: inherit;
    border: 1px solid var(--line); border-radius: 9px; background: #fbfdfc; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }

.btn { display: inline-block; padding: 9px 16px; border: 0; border-radius: 9px; cursor: pointer;
    font: inherit; font-weight: 600; text-decoration: none; text-align: center; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4); }
.btn-sm { padding: 6px 12px; font-size: .85rem; }
.btn-block { width: 100%; }

.alert { padding: 10px 14px; border-radius: 9px; margin-bottom: 16px; font-size: .9rem; }
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.alert-ok { background: #f0fdf4; color: var(--ok); border: 1px solid #bbf7d0; }

/* ---------- App shell ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px;
    height: 56px; padding: 0 16px; background: var(--accent); color: #fff; }
.brand { font-weight: 700; font-size: .98rem; }
.spacer { flex: 1; }
.user-chip { font-size: .82rem; opacity: .95; }
.nav-toggle { display: none; background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }

.sidenav { position: fixed; top: 56px; left: 0; width: 210px; height: calc(100vh - 56px);
    background: var(--surface); border-right: 1px solid var(--line); padding: 14px 10px 28px;
    overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
    scrollbar-color: #cbd5d1 transparent; }
/* แถบเลื่อนบาง ๆ ให้เห็นว่ายังมีเมนูด้านล่าง */
.sidenav::-webkit-scrollbar { width: 8px; }
.sidenav::-webkit-scrollbar-track { background: transparent; }
.sidenav::-webkit-scrollbar-thumb { background: #cbd5d1; border-radius: 999px;
    border: 2px solid var(--surface); }
.sidenav::-webkit-scrollbar-thumb:hover { background: var(--muted); }
.sidenav a { display: block; padding: 10px 14px; margin-bottom: 4px; border-radius: 9px;
    color: var(--ink); text-decoration: none; font-weight: 600; font-size: .92rem; }
.sidenav a:hover { background: #eef4f2; }
.sidenav a.active { background: var(--accent); color: #fff; }

.content { margin-left: 210px; padding: 24px; max-width: 1100px; }

/* ---------- Cards / tables ---------- */
h1.page { margin: 0 0 18px; font-size: 1.35rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 16px 18px; box-shadow: var(--shadow); }
.card .num { font-size: 1.8rem; font-weight: 700; color: var(--accent); }
.card .lbl { color: var(--muted); font-size: .85rem; margin-top: 2px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line);
    border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { background: #f0f4f3; color: var(--muted); font-weight: 700; font-size: .82rem; }
tr:last-child td { border-bottom: 0; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; }
.tag-gap { background: #fff7ed; color: var(--warn); }
.tag-ok { background: #f0fdf4; color: var(--ok); }
.tag-none { background: #fef2f2; color: var(--danger); }

/* ---------- Home (role landing) ---------- */
.home-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.home-tile { display: flex; flex-direction: column; gap: 6px; padding: 22px 20px; text-decoration: none;
    background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
    box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s; }
.home-tile:hover { transform: translateY(-3px); box-shadow: 0 6px 22px rgba(16,40,34,.12); border-color: var(--accent); }
.home-ico { font-size: 2rem; }
.home-label { font-size: 1.15rem; font-weight: 700; color: var(--ink); }
.home-desc { font-size: .88rem; color: var(--muted); }
.home-section { margin: 24px 0 12px; font-size: 1rem; font-weight: 700; color: var(--ink); border-left: 3px solid var(--accent); padding-left: 10px; }
.home-section:first-of-type { margin-top: 6px; }
.sidenav .nav-group { font-size: .7rem; font-weight: 700; color: var(--muted); margin: 15px 14px 5px; opacity: .7; }

/* ---------- Breadcrumb / sections ---------- */
.breadcrumb { margin: 0 0 18px; font-size: .92rem; color: var(--muted); }
.breadcrumb a { text-decoration: none; }
.breadcrumb strong { color: var(--ink); }
h3.sec { margin: 6px 0 12px; font-size: 1.05rem; }
td a { color: var(--accent); font-weight: 600; text-decoration: none; }
td a:hover { text-decoration: underline; }

/* ---------- Map (map.php) ---------- */
.map-hint { color: var(--muted); font-size: .88rem; margin: 0 0 12px; }
.map-pending { margin: 0 0 12px; padding: 8px 12px; background: #fef2f2; color: var(--danger);
    border: 1px solid #fecaca; border-radius: 9px; font-size: .85rem; }
.map-pending a { font-weight: 700; }
/* Checklist งานที่ต้องทำ (admin_checklist.php) */
.ck-sum { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; padding: 12px 16px;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.ck-bar { flex: 1; height: 10px; background: #e8eeec; border-radius: 999px; overflow: hidden; }
.ck-bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; transition: width .25s; }
.ck-sum-text { font-size: .9rem; color: var(--muted); white-space: nowrap; }
.ck-sec { margin-bottom: 16px; }
.ck-head { margin: 0 0 4px; font-size: 1.02rem; display: flex; align-items: center; gap: 10px; }
.ck-count { font-size: .78rem; font-weight: 700; padding: 2px 10px; border-radius: 999px;
    background: #fff7ed; color: var(--warn); }
.ck-count.ok { background: #f0fdf4; color: var(--ok); }
.ck-note { color: var(--muted); font-size: .84rem; margin: 0 0 10px; }
.ck-item { padding: 7px 0; border-top: 1px solid var(--line); }
.ck-item.done .ck-label { color: var(--muted); text-decoration: line-through; }
.ck-line { display: flex; align-items: flex-start; gap: 9px; margin: 0; cursor: pointer; font-weight: 400; }
.ck-box { margin: 3px 0 0; width: 17px; height: 17px; flex: none; cursor: pointer; }
.ck-code { font-size: .72rem; font-weight: 700; color: var(--accent); background: #f0fdfa;
    padding: 1px 7px; border-radius: 999px; flex: none; margin-top: 2px; }
.ck-label { font-size: .92rem; color: var(--ink); line-height: 1.45; }
.ck-noteinput { margin: 5px 0 0 52px; width: calc(100% - 52px); padding: 4px 9px;
    font-size: .82rem; border: 1px dashed var(--line); border-radius: 7px; background: #fbfdfc; }
.ck-noteinput:focus { border-style: solid; }
.ck-who { font-size: .7rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; flex: none;
    margin-top: 2px; background: #f1f5f9; color: var(--muted); white-space: nowrap; }
.ck-who.me { background: #fff7ed; color: #b45309; }
.ck-who.sys { background: #eef2ff; color: #4338ca; }
.ck-filter { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.ck-filter button { padding: 5px 14px; font-size: .84rem; border: 1px solid var(--line);
    border-radius: 999px; background: var(--surface); color: var(--muted); cursor: pointer; }
.ck-filter button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.ck-item.hide, .ck-sec.hide { display: none; }

/* เลือก node รายตำบล (nodes.php) */
tr.nd-on td { background: #f0fdfa; }
tr.nd-on td strong { color: var(--accent); }
.nd-pull, .nd-undo { padding: 5px 12px; font-size: .82rem; }

/* ฟอร์มงานเชิงคุณภาพ (qual_form.php) */
.qf-row { padding: 9px 0; border-top: 1px solid var(--line); }
.qf-row:first-child { border-top: 0; }
.qf-label { display: block; font-size: .9rem; font-weight: 600; color: var(--ink); margin-bottom: 5px; line-height: 1.45; }
.qf-in { width: 100%; padding: 8px 11px; font: inherit; font-size: .92rem;
    border: 1px solid var(--line); border-radius: 8px; background: #fff; box-sizing: border-box; }
.qf-in:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea.qf-in { resize: vertical; }
.qf-checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.qf-chk { display: flex; align-items: center; gap: 6px; font-size: .89rem; font-weight: 400; cursor: pointer; }
.qf-files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 7px; }
.qf-file { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px;
    background: #f0fdfa; border: 1px solid var(--line); border-radius: 999px; font-size: .82rem; }
.qf-file small { color: var(--muted); }
.qf-del { border: 0; background: none; color: #b91c1c; cursor: pointer; font-weight: 700; padding: 0 2px; }
.qf-bar { position: sticky; bottom: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* แถบความคืบหน้าโมดูลวิจัย (cases.php) */
.mod-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px;
    padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.mod-title { font-weight: 700; color: var(--ink); font-size: .9rem; }
.mod-chip { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: .84rem;
    background: #f0fdfa; color: var(--accent); border: 1px solid #99f6e4; text-decoration: none; font-weight: 600; }
.mod-chip:hover { background: #ccfbf1; }
.mod-chip.ok { background: #f0fdf4; color: var(--ok); border-color: #bbf7d0; }
.mod-chip.warn { background: #fff7ed; color: var(--warn); border-color: #fed7aa; }
select.mod-set { padding: 3px 6px; font-size: .82rem; border-radius: 6px; min-width: 120px; margin: 0; }
.twin-btn { background: none; border: 1px dashed var(--accent); color: var(--accent); cursor: pointer;
    font: inherit; font-size: .74rem; font-weight: 600; padding: 1px 7px; border-radius: 999px; margin-top: 3px; }
.twin-btn:hover { background: #f0fdfa; }
.twin-tag { font-size: .74rem; color: var(--muted); margin-top: 3px; }
.ssn-note { background: #fff7ed; border: 1px solid #fed7aa; color: var(--warn); border-radius: 9px;
    padding: 8px 12px; margin-bottom: 12px; font-size: .88rem; }
.collector-box { background: #f0fdfa; border: 1px solid #99f6e4; border-radius: 9px;
    padding: 10px 14px; margin-bottom: 14px; font-size: .9rem; color: var(--ink); }
.collector-box a { font-weight: 600; }
.ent-map { height: 72vh; min-height: 460px; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; z-index: 1; margin-bottom: 4px; }
.ent-pinbar { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
textarea { width: 100%; box-sizing: border-box; padding: 11px 12px; font: inherit;
    border: 1px solid var(--line); border-radius: 9px; background: #fbfdfc; resize: vertical; }
.map-box { height: 68vh; min-height: 420px; border: 1px solid var(--line);
    border-radius: var(--radius); overflow: hidden; z-index: 1; }
/* เต็มจอ (toggle ด้วยปุ่ม ⛶) */
.map-fullscreen { position: fixed !important; inset: 0 !important;
    width: 100vw !important; height: 100vh !important; max-height: none !important;
    border-radius: 0 !important; z-index: 9999 !important; }
.leaflet-control-fs { width: 32px; height: 32px; line-height: 32px; text-align: center;
    background: #fff; font-size: 18px; color: var(--ink); cursor: pointer; display: block;
    border-radius: 6px; box-shadow: 0 1px 4px rgba(0,0,0,.3); text-decoration: none; }
.leaflet-control-fs:hover { background: #f4f6f5; }
.map-err { padding: 24px; color: var(--danger); font-weight: 600; }
.map-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
    margin-top: 12px; padding: 10px 14px; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius); font-size: .82rem; }
.map-legend .lg-title { font-weight: 700; color: var(--ink); margin-right: 4px; }
.map-legend .lg-item { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.map-legend .lg-item i { width: 16px; height: 16px; border-radius: 4px; display: inline-block;
    border: 1px solid rgba(0,0,0,.08); }
.map-legend .lg-noent { background: #fff; border: 2px dashed var(--danger); }
.map-pop { font-size: .9rem; margin-bottom: 6px; }
.pop-tbl { border-collapse: collapse; width: 100%; font-size: .85rem; }
.pop-tbl td { padding: 2px 8px 2px 0; }
.pop-warn { color: var(--danger); font-weight: 600; font-size: .82rem; margin-bottom: 6px; }
.pop-link { display: inline-block; margin-top: 8px; font-weight: 600; }
.map-tt { font-weight: 600; }
.ent-marker { display: flex; align-items: center; justify-content: center; font-size: 15px;
    background: #fff; border: 2px solid var(--accent); border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0,0,0,.3); line-height: 1; }

/* ---------- Survey form (survey_form.php) ---------- */
.round-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.round-tab { padding: 7px 14px; border: 1px solid var(--line); border-radius: 999px;
    background: var(--surface); color: var(--muted); font-size: .85rem; font-weight: 600; text-decoration: none; }
.round-tab:hover { border-color: var(--accent); }
.round-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.q-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-bottom: 8px; }
.q-item { display: flex; flex-direction: column; gap: 5px; margin-bottom: 0; }
.q-item > span { font-size: .85rem; font-weight: 600; color: var(--muted); }
.scale { display: flex; gap: 6px; }
.scale-op { display: inline-flex; align-items: center; gap: 3px; margin: 0; font-weight: 600; color: var(--ink);
    border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; cursor: pointer; }
.scale-op input { margin: 0; }
.net-line { margin: 16px 0; padding: 10px 14px; background: #f0fdfa; border: 1px solid var(--line);
    border-radius: 9px; font-weight: 600; }
.net-line strong { color: var(--accent); font-size: 1.1rem; }

/* ---------- Village pins (village_pins.php) ---------- */
.pin-wrap { display: grid; grid-template-columns: 300px 1fr; gap: 14px; align-items: start; }
.pin-list { max-height: 72vh; overflow-y: auto; display: flex; flex-direction: column; gap: 6px;
    border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; background: var(--surface); }
.pin-item { text-align: left; border: 1px solid var(--line); background: #fbfdfc; border-radius: 9px;
    padding: 8px 10px; cursor: pointer; display: flex; flex-direction: column; gap: 3px; }
.pin-item:hover { border-color: var(--accent); }
.pin-item.active { border-color: var(--accent); background: #f0fdfa; box-shadow: 0 0 0 2px var(--accent) inset; }
.pin-vname { font-weight: 700; color: var(--ink); font-size: .92rem; }
.pin-vmeta { color: var(--muted); font-size: .78rem; }
.pin-map-col { display: flex; flex-direction: column; gap: 10px; }
.pin-bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--surface);
    border: 1px solid var(--line); border-radius: var(--radius); flex-wrap: wrap; }
.pin-active { font-weight: 600; color: var(--ink); }
.pin-coord { color: var(--accent); font-family: monospace; font-size: .9rem; }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
    .nav-toggle { display: block; }
    .user-chip { display: none; }
    .sidenav { transform: translateX(-100%); transition: transform .2s; z-index: 30; box-shadow: var(--shadow); }
    body.nav-open .sidenav { transform: translateX(0); }
    .content { margin-left: 0; padding: 16px; }
    .map-box { height: 60vh; }
    .pin-wrap { grid-template-columns: 1fr; }
    .pin-list { max-height: 34vh; }
}

/* ---- ฟอร์มงานเชิงคุณภาพ: ตัวช่วยให้กรอกง่าย ---- */
.qf-nav { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; position: sticky; top: 0; z-index: 5;
          background: var(--bg); padding: 8px 0; }
.qf-nav a { font-size: .84rem; padding: 4px 11px; border: 1px solid var(--line); border-radius: 999px;
            color: var(--muted); text-decoration: none; background: var(--card); }
.qf-nav a:hover { color: var(--accent); border-color: var(--accent); }
.qf-auto { display: inline-block; margin-left: 6px; font-size: .74rem; font-weight: 500; padding: 1px 7px;
           border-radius: 999px; background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }
.qf-more { margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 6px; }
.qf-more > summary { cursor: pointer; font-size: .87rem; color: var(--muted); padding: 5px 0; user-select: none; }
.qf-more > summary:hover { color: var(--accent); }
.qf-more[open] > summary { font-weight: 600; color: var(--ink); }
.qf-count { margin-left: auto; font-size: .85rem; font-weight: 600; color: var(--accent); white-space: nowrap; }
.qf-restore { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; border-color: var(--accent); }
.qf-row[hidden] { display: none; }

/* ==================================================================
   จอเล็ก — มือถือ & แท็บเล็ต (ใช้กับทั้งแบบสอบถามและงานเชิงคุณภาพ)
   หลัก: กันซูมอัตโนมัติบน iOS · นิ้วกดโดนแน่ · ปุ่มบันทึกอยู่ติดมือเสมอ
   ================================================================== */

/* --- ≤1024px : แท็บเล็ตแนวตั้งขึ้นไป --- */
@media (max-width: 1024px) {
    /* คำถามเรียงคอลัมน์เดียว — ป้ายคำถามภาษาไทยยาว 2 คอลัมน์แล้วอ่านยาก */
    .q-grid { grid-template-columns: 1fr; gap: 16px; }

    /* iOS Safari ซูมหน้าจอเองถ้าตัวอักษรในช่องกรอก < 16px */
    input, select, textarea, .qf-in { font-size: 16px; }

    /* นิ้วกดโดน — WCAG แนะนำเป้ากด ≥ 44px */
    input:not([type=radio]):not([type=checkbox]):not([type=file]),
    select, .qf-in:not(textarea) { min-height: 46px; }
    .btn { min-height: 46px; padding: 12px 18px; display: inline-flex;
           align-items: center; justify-content: center; }
    .btn-sm { min-height: 40px; padding: 8px 14px; }

    /* มาตรวัด 1–5 เต็มความกว้าง กดทั้งช่องได้ ไม่ต้องจิ้มวงกลมเล็ก ๆ */
    .scale { gap: 8px; }
    .scale-op { flex: 1; justify-content: center; min-height: 48px; font-size: 1.05rem;
                background: #fbfdfc; }
    .scale-op:has(input:checked) { background: var(--accent); color: #fff; border-color: var(--accent); }
    .scale-op input { width: auto; min-height: 0; }

    /* ช่องติ๊กหลายข้อ — เพิ่มพื้นที่กดรอบข้อความ */
    .qf-checks { gap: 4px 10px; }
    .qf-chk { min-height: 44px; padding: 4px 10px; border: 1px solid var(--line);
              border-radius: 9px; background: #fbfdfc; font-size: .95rem; }
    .qf-chk input { width: auto; min-height: 0; transform: scale(1.25); }

    /* สารบัญหมวด: เลื่อนแนวนอนแถวเดียว ไม่ตัดบรรทัดกินพื้นที่ */
    .qf-nav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch;
              scrollbar-width: none; gap: 8px; }
    .qf-nav::-webkit-scrollbar { display: none; }
    .qf-nav a { white-space: nowrap; min-height: 40px; display: inline-flex; align-items: center; }

    /* หัวข้อย่อย "ช่องเสริม" กดง่ายขึ้น */
    .qf-more > summary { min-height: 46px; display: flex; align-items: center; font-size: .95rem; }

    /* แถบบันทึกลอยติดล่างจอ + เผื่อขอบจอ iPhone */
    .qf-bar, .sf-bar { position: sticky; bottom: 0; z-index: 8;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
        box-shadow: 0 -6px 18px rgba(0,0,0,.08); }
    .qf-count { margin-left: 0; width: 100%; order: 9; }

    /* ป้ายคำถามอ่านง่ายขึ้นบนจอเล็ก */
    .q-item > span, .qf-label { font-size: .95rem; color: var(--ink); }
}

/* --- ≤560px : มือถือ --- */
@media (max-width: 560px) {
    .content { padding: 12px 12px 0; }
    .card { padding: 14px 12px; }
    h1.page { font-size: 1.15rem; }
    h3.sec { font-size: 1rem; }
    .round-tabs { gap: 6px; }
    .round-tab { font-size: .82rem; padding: 6px 11px; }
    /* ปุ่มหลักเต็มความกว้าง กดพลาดยาก */
    .qf-bar .btn, .sf-bar .btn { flex: 1 1 44%; }
    .scale-op { padding: 6px 4px; font-size: 1rem; }
    /* ตารางกว้าง ๆ ให้เลื่อนในกรอบตัวเอง ไม่ดันทั้งหน้า */
    .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* --- แถบบันทึกของแบบสอบถามเชิงปริมาณ --- */
.sf-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
          background: var(--surface); border: 1px solid var(--line);
          border-radius: var(--radius); padding: 12px 14px; margin-top: 14px; }
.sf-net { margin: 0; font-weight: 600; }
.sf-net strong { color: var(--accent); font-size: 1.15rem; }
.sf-progress { margin-left: auto; font-size: .88rem; font-weight: 600; color: var(--accent); }

/* ---- ตารางสิทธิ์ในหน้าผู้ใช้ระบบ ---- */
.rm-legend { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; }
.rm-role { border-left: 3px solid var(--accent); padding-left: 10px; }
.rm-role strong { display: block; font-size: .95rem; }
.rm-role code { font-size: .74rem; color: var(--accent); background: #f0fdfa;
                padding: 1px 6px; border-radius: 5px; }
.rm-role span { display: block; font-size: .82rem; color: var(--muted); margin-top: 3px; }
.rm-role em { display: block; font-size: .78rem; color: var(--muted); margin-top: 2px; font-style: normal; opacity: .85; }
.rm-table th { text-align: center; font-size: .8rem; line-height: 1.3; vertical-align: bottom; }
.rm-table th:first-child { text-align: left; }
.rm-table th code, .rm-table td code { font-size: .7rem; color: var(--muted); font-weight: 400; }
.rm-group td { background: #f0fdfa; font-weight: 700; font-size: .85rem; color: var(--accent); }
.rm-cell { text-align: center; font-weight: 700; width: 74px; }
.rm-cell.yes { color: var(--accent); }
.rm-cell.no { color: #cbd5e1; }
.rm-note { font-size: .76rem; color: #b45309; margin-top: 3px; line-height: 1.4; }
.rm-extra { margin-top: 14px; }
.rm-ul { margin: 4px 0 14px; padding-left: 20px; font-size: .87rem; color: var(--muted); line-height: 1.7; }
@media (max-width: 1024px) {
    .rm-cell { width: 56px; font-size: 1.05rem; }
    .rm-table th { font-size: .74rem; }
}

/* ---- อนุมัติผู้ใช้ + กำหนดสิทธิ์ในแถวเดียว ---- */
.approve-form { display: flex; align-items: center; gap: 6px; margin: 0 0 4px; }
.approve-role { width: auto; min-width: 132px; margin: 0; padding: 5px 8px; font-size: .82rem; border-radius: 7px; }
.approve-btn { border: 0; background: var(--ok, #0f766e); color: #fff; cursor: pointer;
               font: inherit; font-weight: 700; font-size: .82rem; padding: 6px 11px; border-radius: 7px;
               white-space: nowrap; }
.approve-btn:hover { filter: brightness(1.1); }
@media (max-width: 1024px) {
    .approve-form { flex-wrap: wrap; }
    .approve-role { min-height: 40px; font-size: 16px; }
    .approve-btn { min-height: 40px; }
}

/* ---- หน้าสถิติ PPAOS ---- */
.st-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.st-card { text-align: center; padding: 16px 12px; }
.st-pct { display: inline-block; font-size: .74rem; font-weight: 700; color: var(--accent);
          background: #f0fdfa; border-radius: 999px; padding: 1px 7px; margin-left: 3px; }
.st-h2 { font-size: 1.1rem; margin: 26px 0 8px; }
.st-legend { display: flex; flex-wrap: wrap; gap: 8px 18px; margin: 0 0 10px; font-size: .87rem; }
.st-dot { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.st-dot i { width: 12px; height: 12px; border-radius: 50%; display: inline-block; border: 1px solid #fff;
            box-shadow: 0 0 0 1px rgba(0,0,0,.12); }
.st-dot strong { color: var(--ink); }
.st-bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.st-bar span { display: block; height: 100%; border-radius: 999px; }
@media (max-width: 1024px) {
    .st-cards { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
    .st-card .num { font-size: 1.5rem; }
}

/* ---- Dashboard เชิงกราฟ (ppaos_stats) ---- */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); gap: 14px; margin-bottom: 20px; }
.dash-wide { grid-column: 1 / -1; }
.dash-t { margin: 0 0 12px; font-size: .98rem; }
.dash-stack { display: flex; height: 26px; border-radius: 7px; overflow: hidden; margin-bottom: 12px; }
.dash-stack span { display: block; height: 100%; }
.dash-legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .84rem; }
.dash-legend li { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.dash-legend i { width: 11px; height: 11px; border-radius: 3px; flex: none; }
.dash-legend b { color: var(--ink); }
.dash-legend small { color: var(--muted); }
.dash-row { display: grid; grid-template-columns: 150px 1fr; gap: 10px; align-items: center; margin-bottom: 7px; }
.dash-lb { font-size: .85rem; color: var(--ink); line-height: 1.3; }
.dash-bars { display: flex; flex-direction: column; gap: 3px; }
.dash-b { position: relative; height: 18px; background: var(--line); border-radius: 5px; overflow: hidden; }
.dash-b > span { display: block; height: 100%; border-radius: 5px; transition: width .3s; }
.dash-b .dash-in { position: absolute; top: 0; left: 0; }
.dash-b em { position: absolute; right: 7px; top: 0; line-height: 18px; font-style: normal;
             font-size: .74rem; font-weight: 700; color: var(--ink); }
.dash-b2 { height: 22px; }
.dash-b2 em { line-height: 22px; }
.st-tables > summary { cursor: pointer; font-weight: 600; padding: 12px 0; color: var(--accent); font-size: .95rem; }
@media (max-width: 700px) {
    .dash-row { grid-template-columns: 1fr; gap: 3px; }
    .dash-lb { font-size: .82rem; }
}

/* ---- ติ๊กเลือกคนเข้ากลุ่มเป้าหมาย (survey_view) ---- */
.pk-sum { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.pk-bar { position: sticky; top: 0; z-index: 6; display: flex; align-items: center; gap: 12px;
          flex-wrap: wrap; margin-bottom: 12px; border-color: var(--accent); }
.pk-all { margin: 0; display: flex; align-items: center; gap: 7px; font-weight: 600; }
.pk-all input { width: auto; margin: 0; }
.pk-count { font-weight: 700; color: var(--accent); }
.pk-bar .btn:disabled { opacity: .45; cursor: not-allowed; }
tr.pk-on { background: #f0fdfa; }
.pk-row { width: auto; margin: 0; transform: scale(1.15); }
@media (max-width: 1024px) {
    .pk-bar { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
    .pk-row { transform: scale(1.35); }
}

/* ---- ผลิตภัณฑ์ & อาชีพ ---- */
.pd-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.pd-card { padding: 0; overflow: hidden; display: flex; flex-direction: column; }
.pd-cover { width: 100%; height: 168px; object-fit: cover; display: block; background: #f1f5f9; }
.pd-nocover { display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: .85rem; }
.pd-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 5px; }
.pd-name { margin: 2px 0 0; font-size: 1rem; line-height: 1.35; }
.pd-meta { margin: 0; font-size: .8rem; color: var(--muted); }
.pd-desc { margin: 2px 0; font-size: .85rem; color: var(--ink); line-height: 1.5; }
.pd-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.pd-link { margin-left: auto; font-weight: 600; }
.pd-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.pd-thumb { position: relative; display: inline-block; }
.pd-thumb img { width: 92px; height: 92px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.pd-thumb .qf-del { position: absolute; top: 2px; right: 2px; background: rgba(255,255,255,.92);
                    border-radius: 50%; width: 22px; height: 22px; line-height: 20px; }

/* ---- แถวหัวกลุ่มอำเภอในตารางเลือก node ---- */
.nd-group td { background: #f0fdfa; font-weight: 700; color: var(--accent);
               font-size: .88rem; padding: 7px 10px !important; position: sticky; left: 0; }
tr[data-d][hidden] { display: none; }

/* ---- จอเล็ก: ปุ่มตัวกรอง/ชิป ให้นิ้วกดโดน ---- */
@media (max-width: 1024px) {
    .ck-filter { gap: 8px; }
    .ck-filter button { min-height: 40px; padding: 8px 14px; font-size: .88rem; }
    .ck-noteinput { min-height: 40px; font-size: 16px; }
    .nd-group td { font-size: .92rem; }
}

/* ---- ฐาน PPAOS: คำอธิบายสัญลักษณ์ + แถวที่ติดธงคุณภาพข้อมูล ---- */
.pb-legend { background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
             padding: 10px 14px; margin-bottom: 14px; font-size: .86rem; }
.pb-legend > summary { cursor: pointer; font-weight: 600; color: var(--accent); }
.pb-legend ul { list-style: none; margin: 10px 0 0; padding: 0;
                display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 6px 18px; }
.pb-legend li { display: flex; align-items: baseline; gap: 6px; color: var(--muted); }
.pb-legend li .tag { flex: none; }
tr.pb-flagged td { background: #fef2f2; }
tr.pb-flagged.pk-on td { background: #fee2e2; }
th.pb-flag-col, td.pb-flag-col { color: var(--danger); background: #fffafa; }

/* ---- คำอธิบายขยายความในกล่อง legend ---- */
.pb-explain { margin-top: 12px; padding: 12px 14px; background: #fef2f2; border-left: 4px solid var(--danger);
              border-radius: 0 8px 8px 0; font-size: .86rem; line-height: 1.65; }
.pb-explain strong { color: var(--ink); }
.pb-explain p { margin: 8px 0 0; color: var(--muted); }
.pb-explain code { background: #fff; padding: 1px 5px; border-radius: 4px; font-size: .92em; }
.pb-explain-do { border-top: 1px dashed #fca5a5; padding-top: 8px; }

/* ---- คำอธิบายสีพื้นที่บนแผนที่สถิติ (choropleth) — คนละตัวกับ .map-legend ของแผนที่จับคู่ ---- */
.mp-legend { background: rgba(255,255,255,.95); padding: 10px 12px; border-radius: 10px;
             box-shadow: 0 1px 8px rgba(0,0,0,.22); font-size: .8rem; line-height: 1.5;
             color: var(--ink); max-width: 232px; }
.mp-legend-h { font-weight: 700; margin-bottom: 6px; }
.mp-legend-row { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.mp-legend-row i { width: 16px; height: 14px; border-radius: 3px; flex: none;
                   border: 1px solid rgba(0,0,0,.16); }
.mp-legend-sw { display: flex; gap: 6px; margin-top: 8px; border-top: 1px solid var(--line); padding-top: 8px; }
.mp-legend-sw button { flex: 1; padding: 5px 10px; font: inherit; font-size: .78rem; cursor: pointer;
                       border: 1px solid var(--line); background: #fff; border-radius: 6px; color: var(--muted); }
.mp-legend-sw button.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.mp-legend-dots { display: flex; align-items: flex-start; gap: 7px; flex-wrap: wrap;
                  margin: 8px 0 0; border-top: 1px solid var(--line); padding-top: 8px;
                  font-size: .78rem; font-weight: 600; color: var(--muted); cursor: pointer; line-height: 1.45; }
/* กันสไตล์ input ของฟอร์ม (width:100%) มาทำช่องติ๊กบวม */
.mp-legend-dots input[type="checkbox"] { width: 15px; height: 15px; min-width: 15px; margin: 2px 0 0;
                                         padding: 0; flex: none; accent-color: var(--accent); }
.mp-legend-dots span { flex-basis: 100%; font-size: .72rem; font-weight: 400; opacity: .85; }
.leaflet-tooltip.map-tip { font-size: .82rem; line-height: 1.55; padding: 7px 10px; border-radius: 8px;
                           border: 1px solid var(--line); box-shadow: 0 2px 8px rgba(0,0,0,.16); }
