/* css/childh.css — หน้าศูนย์พัฒนาเด็กก่อนวัยเรียน (ฝังใน iframe ได้) ; โครงเดียวกับหน้าหอพัก/Bangkok Brand */

:root {
    --bg: #f4f6f3;
    --surface: #ffffff;
    --line: #e2e8e0;
    --ink: #1c2420;
    --ink-2: #4a5550;
    --ink-3: #66716b;
    --focus: #1d4ed8;
    --radius: 14px;
    --hero-1: #123f24; --hero-2: #17552f; --accent: #f2c14e;
    --primary: #2e7d32; --primary-ink: #1b5e20; --primary-soft: #e8f3e9;
    /* ขนาดศูนย์ = ลำดับ เล็ก→ใหญ่ ใช้สีน้ำเงินไล่ระดับสีเดียว (ตรวจแล้ว: ไล่ความสว่างชัด, ปลายสว่างตัดพื้น ≥ 2:1) */
    --sz-s: #86b6ef; --sz-m: #256abf; --sz-l: #0d366b;
    --muted-fill: #7d8a82;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Leelawadee", Tahoma, sans-serif;
    font-size: 16px;
    line-height: 1.55;
}
a { color: var(--primary-ink); }
a:focus, button:focus, input:focus, select:focus, summary:focus, [tabindex]:focus { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.bp { max-width: 1200px; margin: 0 auto; padding: 16px; }

/* ---------- การเข้าถึง ---------- */
.sr-only {
    position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
    position: absolute; left: 8px; top: -60px; z-index: 100; padding: 10px 16px;
    background: #0f172a; color: #fff; font-weight: 700; border-radius: 0 0 8px 8px; text-decoration: none;
}
.skip-link:focus { top: 0; }
.skip-inline { position: absolute; left: -9999px; }
.skip-inline:focus { position: static; display: inline-block; padding: 4px 10px; background: #0f172a; color: #fff; border-radius: 6px; font-weight: 700; }
.muted { color: var(--ink-3); }
.js .nojs-only { display: none; }
html:not(.js) .js-only { display: none; }

/* ---------- หัวหน้า ---------- */
.bp-hero {
    position: relative; overflow: hidden; padding: 26px 28px 24px; border-radius: var(--radius); color: #fff;
    background: linear-gradient(120deg, var(--hero-1) 0%, var(--hero-2) 100%);
}
.bp-hero::after {
    content: ""; position: absolute; right: -60px; top: -80px; width: 280px; height: 280px; border-radius: 50%;
    border: 36px solid rgba(255, 255, 255, .06);
}
.bp-eyebrow { margin: 0 0 4px; font-size: 14px; font-weight: 600; letter-spacing: .02em; color: var(--accent); }
.bp-hero h1 { margin: 0; font-size: 30px; line-height: 1.2; }
.bp-lead { margin: 8px 0 0; max-width: 720px; color: rgba(255, 255, 255, .88); }
.bp-meta { margin: 10px 0 0; font-size: 14px; color: var(--accent); font-weight: 600; }
.hero-admin {
    position: absolute; right: 20px; top: 20px; z-index: 1; padding: 6px 14px; border-radius: 999px;
    background: rgba(255, 255, 255, .14); color: #fff; font-size: 14px; font-weight: 600; text-decoration: none;
    border: 1px solid rgba(255, 255, 255, .45);
}
.hero-admin:hover { background: rgba(255, 255, 255, .24); }

/* ---------- ตัวเลขสรุป ---------- */
.stats { list-style: none; margin: 14px 0 0; padding: 0; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat { padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; }
.stat-v { font-size: 28px; font-weight: 800; line-height: 1.1; color: var(--ink); }
.stat-v small { font-size: 16px; font-weight: 600; color: var(--ink-3); }
.stat-l { margin-top: 4px; font-size: 14px; color: var(--ink-2); }
.stat-s { font-size: 13px; color: var(--ink-3); }
.stat-main { background: var(--primary-soft); border-color: transparent; }
.stat-main .stat-v { color: var(--primary-ink); }

/* ---------- ฟอร์ม / ปุ่ม ---------- */
.fld { flex: 1 1 150px; min-width: 0; }
.fld-search { flex: 2 1 240px; }
.fld label { display: block; margin-bottom: 4px; font-size: 14px; font-weight: 600; color: var(--ink-2); }
.fld input, .fld select {
    width: 100%; height: 42px; padding: 0 12px; font: inherit; font-size: 15px; color: var(--ink);
    background: #fff; border: 1px solid #7d8a82; border-radius: 10px;
}
.fld-actions { flex: 0 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.btn {
    display: inline-flex; align-items: center; justify-content: center; height: 42px; padding: 0 18px;
    font: inherit; font-weight: 700; border-radius: 10px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; border: 1px solid var(--primary); }
.btn-primary:hover { background: var(--primary-ink); }
.btn-ghost { background: #fff; color: var(--ink-2); border: 1px solid #7d8a82; }
.btn-ghost:hover { background: #f1f4f1; }

/* ---------- ค้นหา + แผนที่ + ตาราง ---------- */
.explore { margin-top: 14px; padding: 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.ex-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 4px 12px; }
.ex-head h2 { margin: 0; font-size: 20px; }
.ex-head h2:focus, #tbl-title:focus { outline: none; }
.res-count { margin: 0; color: var(--ink-2); font-weight: 600; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-top: 12px; padding: 14px; background: #f8faf8; border: 1px solid var(--line); border-radius: 12px; }

.map-card { margin-top: 14px; }
.map-top { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 14px; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }

/* หมุด/ป้ายขนาด (ใช้ทั้งในคำอธิบาย ตาราง และกราฟ) */
.pin {
    display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%;
    font-size: 12px; font-weight: 800; line-height: 1; flex: 0 0 auto; box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(28, 36, 32, .55);
}
.pin-s { background: var(--sz-s); color: #0b0b0b; }
.pin-m { background: var(--sz-m); color: #fff; }
.pin-l { background: var(--sz-l); color: #fff; }
.pin-cl { background: #1c2420; color: #fff; width: 26px; height: 26px; }

.map {
    position: relative; height: 520px; overflow: hidden; border-radius: 12px; border: 1px solid #c9d3cc;
    background: #e9eee9; touch-action: none; cursor: grab; -webkit-user-select: none; user-select: none;
}
.map.is-drag { cursor: grabbing; }
.map:focus { outline: 3px solid var(--focus); outline-offset: 2px; }
.map-pane, .map-tiles, .map-markers { position: absolute; left: 0; top: 0; }
.map-pane { width: 100%; height: 100%; will-change: transform; }
.map-tile { position: absolute; width: 256px; height: 256px; max-width: none; opacity: 0; transition: opacity .2s; }
.map-tile.on { opacity: 1; }
.map-markers { width: 100%; height: 100%; }

.mk, .mk-cl {
    position: absolute; transform: translate(-50%, -50%); -webkit-transform: translate(-50%, -50%);
    display: flex; align-items: center; justify-content: center; padding: 0; margin: 0; cursor: pointer;
    font: inherit; font-weight: 800; line-height: 1; border: 0; border-radius: 50%;
}
.mk { width: 24px; height: 24px; font-size: 12px; box-shadow: 0 0 0 2px #fff, 0 0 0 3px rgba(28, 36, 32, .6), 0 2px 6px rgba(0, 0, 0, .25); }
.mk::before { content: ""; position: absolute; left: -8px; right: -8px; top: -8px; bottom: -8px; }   /* พื้นที่กดใหญ่กว่าหมุด */
.mk-s { background: var(--sz-s); color: #0b0b0b; }
.mk-m { background: var(--sz-m); color: #fff; }
.mk-l { background: var(--sz-l); color: #fff; }
.mk-x { background: var(--muted-fill); color: #fff; }
.mk:hover, .mk[aria-expanded="true"] { z-index: 2; box-shadow: 0 0 0 3px #fff, 0 0 0 5px var(--ink), 0 2px 6px rgba(0, 0, 0, .3); }
.mk-cl { width: 34px; height: 34px; font-size: 13px; color: #fff; background: #1c2420; box-shadow: 0 0 0 3px rgba(255, 255, 255, .9), 0 0 0 7px rgba(28, 36, 32, .22); }
.mk-cl2 { width: 40px; height: 40px; font-size: 14px; }
.mk-cl3 { width: 48px; height: 48px; font-size: 15px; }
.mk-cl:hover { background: #000; }
.mk:focus, .mk-cl:focus { outline: 3px solid var(--focus); outline-offset: 3px; z-index: 3; }

.map-ctl { position: absolute; right: 10px; top: 10px; z-index: 5; display: flex; flex-direction: column; gap: 6px; }
.map-btn {
    width: 40px; height: 40px; font: inherit; font-size: 20px; font-weight: 700; line-height: 1; color: var(--ink);
    background: #fff; border: 1px solid #7d8a82; border-radius: 10px; cursor: pointer; box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
}
.map-btn:hover { background: #f1f4f1; }
.map-btn:disabled { color: #9aa39d; cursor: default; }
.map-attr { position: absolute; right: 0; bottom: 0; z-index: 5; padding: 2px 8px; font-size: 11px; background: rgba(255, 255, 255, .85); color: var(--ink-2); border-top-left-radius: 8px; }
.map-attr a { color: var(--ink-2); }
.map-msg {
    position: absolute; left: 50%; top: 14px; z-index: 6; transform: translateX(-50%); -webkit-transform: translateX(-50%);
    max-width: 90%; margin: 0; padding: 8px 14px; border-radius: 10px; background: rgba(15, 23, 42, .88); color: #fff; font-size: 14px; text-align: center;
}
.map-note { margin: 8px 0 0; font-size: 13px; color: var(--ink-3); }

/* ป๊อปอัป */
.pop {
    position: absolute; z-index: 4; width: 320px; max-width: calc(100vw - 60px); padding: 12px 14px 10px; border-radius: 12px;
    background: #fff; color: var(--ink); box-shadow: 0 6px 24px rgba(0, 0, 0, .22), 0 0 0 1px rgba(0, 0, 0, .08);
    transform: translate(-50%, calc(-100% - 22px)); -webkit-transform: translate(-50%, -100%) translateY(-22px);
    cursor: auto; -webkit-user-select: text; user-select: text;
}
.pop::after { content: ""; position: absolute; left: 50%; bottom: -8px; margin-left: -8px; border: 8px solid transparent; border-bottom: 0; border-top-color: #fff; }
.pop-h { margin: 0 26px 6px 0; font-size: 16px; line-height: 1.35; }
.pop-h:focus { outline: none; }
.pop-x { position: absolute; right: 6px; top: 6px; width: 32px; height: 32px; font-size: 22px; line-height: 1; border: 0; border-radius: 8px; background: none; color: var(--ink-2); cursor: pointer; }
.pop-x:hover { background: #f1f4f1; }
.pop-dl { margin: 6px 0 0; font-size: 14px; display: grid; gap: 2px; }
.pop-dl div { display: grid; grid-template-columns: 136px 1fr; gap: 8px; }
.pop-dl dt { color: var(--ink-3); }
.pop-dl dd { margin: 0; font-weight: 600; }
.pop-act { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.pop-link { font: inherit; font-size: 14px; font-weight: 700; color: var(--primary-ink); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }

/* ตาราง */
.res-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-top: 18px; }
.res-head h3 { margin: 0; font-size: 18px; }
.panel-hint { margin: 4px 0 0; font-size: 13px; color: var(--ink-3); }
.table-wrap { position: relative; margin-top: 10px; overflow: auto; max-height: 720px; border: 1px solid var(--line); border-radius: 12px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl thead th { position: sticky; top: 0; z-index: 1; background: var(--primary); color: #fff; font-weight: 700; white-space: nowrap; vertical-align: bottom; }
.tbl thead th button {
    font: inherit; font-weight: 700; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-align: inherit;
    display: inline-flex; align-items: center; gap: 4px;
}
.tbl thead th button::after { content: "\2195"; opacity: .55; font-size: 12px; }
.tbl thead th[aria-sort="ascending"] button::after { content: "\25B2"; opacity: 1; }
.tbl thead th[aria-sort="descending"] button::after { content: "\25BC"; opacity: 1; }
.tbl thead th button:focus { outline: 3px solid #fff; outline-offset: 2px; }
.tbl tbody th { font-weight: 600; min-width: 220px; }
.tbl tbody tr:nth-child(even) { background: #f8faf8; }
.tbl tbody tr.is-hl { background: #fff4c7; }
.tbl tbody th:focus { outline: 3px solid var(--focus); outline-offset: -3px; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl thead th.num button { justify-content: flex-end; }
.tbl .ctr { text-align: center; white-space: nowrap; }
.tbl .strong { font-weight: 700; }
.tbl tfoot th, .tbl tfoot td { position: sticky; bottom: 0; background: var(--primary-soft); font-weight: 800; border-top: 2px solid var(--primary); }
.badge { display: inline-block; padding: 1px 8px; margin-left: 4px; border-radius: 999px; font-size: 12px; font-weight: 700; background: #fdf3d2; color: #6e5000; white-space: nowrap; vertical-align: 1px; }
.grade { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 24px; padding: 0 6px; border-radius: 6px; font-weight: 800; background: #f1f4f1; color: var(--ink); border: 1px solid #b7c2bb; }
.grade-t { font-size: 13px; color: var(--ink-2); }
.lnk-map { font: inherit; font-size: 13px; font-weight: 700; color: var(--primary-ink); background: none; border: 1px solid #7d8a82; border-radius: 8px; padding: 3px 10px; cursor: pointer; white-space: nowrap; }
.lnk-map:hover { background: var(--primary-soft); }
.empty-filter { margin: 10px 0 0; padding: 16px; text-align: center; border: 2px dashed var(--line); border-radius: 12px; color: var(--ink-2); }
.empty { margin-top: 16px; padding: 28px; text-align: center; border: 2px dashed #c9d3cc; border-radius: 12px; color: var(--ink-2); background: #fff; }

/* ---------- กราฟ ---------- */
.charts { margin-top: 14px; }
.charts-head { margin: 4px 2px 10px; }
.charts-head h2 { margin: 0; font-size: 18px; }
.cards3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.cards3.cards2 { grid-template-columns: 1fr 1fr; }
.cards3.cards1 { grid-template-columns: 1fr; }
.ccard { padding: 16px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.ccard h3 { margin: 0 0 12px; font-size: 15px; color: var(--ink); line-height: 1.4; }
.ccard h3 .muted { font-weight: normal; font-size: 13px; }
.ccard-wide { margin-top: 12px; }

.sbars { list-style: none; margin: 0; padding: 0; }
.sb-row { display: grid; grid-template-columns: minmax(84px, 42%) 1fr; gap: 10px; align-items: center; padding: 5px 6px; margin: 0 -6px; border-radius: 6px; }
.sb-row:hover { background: #f3f6f3; }
.sb-name { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.sb-name { color: var(--primary-ink); text-decoration: underline; text-decoration-color: rgba(27, 94, 32, .35); text-underline-offset: 3px; display: block; }
a.sb-name:hover { text-decoration-color: currentColor; }
.sb-bar { display: flex; align-items: center; gap: 2px; min-width: 0; height: 16px; }
.sb-bar .seg { display: block; height: 100%; min-width: 3px; }
.sb-bar .seg:first-child { border-radius: 3px 0 0 3px; }
.sb-bar .seg:nth-last-child(2) { border-radius: 0 4px 4px 0; }
.sb-bar .seg:first-child:nth-last-child(2) { border-radius: 3px 4px 4px 3px; }
.sb-val { margin-left: 8px; font-size: 14px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.sb-val small { font-weight: 600; color: var(--ink-3); font-size: 12px; }
.seg-s { background: var(--sz-s); }
.seg-m { background: var(--sz-m); }
.seg-l { background: var(--sz-l); }
.seg-x { background: var(--muted-fill); }
.seg-g { background: var(--primary); }
.sbars-grade .sb-row { grid-template-columns: minmax(84px, 52%) 1fr; }
.sbars-2col { display: grid; grid-auto-flow: column; grid-template-columns: 1fr 1fr; column-gap: 32px; }
.sbars-2col .sb-row { grid-template-columns: 130px 1fr; }
.more { margin-top: 6px; }
.more summary { cursor: pointer; padding: 8px 0; font-weight: 600; color: var(--primary-ink); }
.nodorm { margin: 4px 0 0; font-size: 14px; line-height: 1.9; color: var(--ink-2); }

.bp-foot { margin: 14px 0 4px; text-align: center; font-size: 13px; color: var(--ink-3); }

/* ---------- จอแคบ ---------- */
@media (max-width: 1000px) {
    .cards3 { grid-template-columns: 1fr 1fr; }
    .cards3 > .ccard:first-child { grid-column: 1 / -1; }
    .cards3.cards2 > .ccard:first-child { grid-column: auto; }
}
@media (max-width: 700px) {
    .bp { padding: 10px; }
    .bp-hero { padding: 20px; }
    .bp-hero h1 { font-size: 24px; }
    .hero-admin { position: static; display: inline-block; margin-top: 12px; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stat-v { font-size: 24px; }
    .explore { padding: 12px; }
    .filters { padding: 10px; }
    .fld, .fld-search { flex: 1 1 100%; }
    .map { height: 58vh; min-height: 320px; }
    .cards3, .cards3.cards2 { grid-template-columns: 1fr; }
    .sbars-2col { grid-auto-flow: row; grid-template-columns: 1fr; grid-template-rows: none !important; }
    .sbars-2col .sb-row { grid-template-columns: 110px 1fr; }
    .tbl tbody th { min-width: 180px; }
}
@media (forced-colors: active) {
    .sb-bar .seg, .mk, .mk-cl, .pin { border: 1px solid CanvasText; forced-color-adjust: none; }
}
@media print {
    .filters, .skip-link, .hero-admin, .map-card, .lnk-map, #csvLink { display: none !important; }
    .bp-hero { color: #000; background: none; border: 1px solid #000; }
    .bp-lead, .bp-eyebrow, .bp-meta { color: #000; }
    .table-wrap { max-height: none; overflow: visible; }
    .tbl thead th, .tbl tfoot th, .tbl tfoot td { position: static; }
}
@media (prefers-reduced-motion: reduce) {
    .map-tile { transition: none; }
}
