/* ============================================================
   AYA2 SCHOOL MAP+ — สไตล์หลัก
   ============================================================ */
:root {
  --navy: #12294d;
  --navy-dark: #0b1a33;
  --gold: #c9962c;
  --gold-light: #e8c877;
  --blue: #1e5aa8;
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #1f2937;
  --text-mute: #6b7280;
  --border: #e5e7eb;
  --success: #059669;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 4px 16px rgba(18, 41, 77, 0.08);
  --shadow-lg: 0 12px 32px rgba(18, 41, 77, 0.14);
  /* พื้นผิว/สีเน้นรอง — เปลี่ยนค่าตาม dark mode ด้านล่าง (สีแบรนด์หลัก navy/gold ด้านบนไม่เปลี่ยนตามธีม) */
  --tint-blue: #eef2ff;
  --tint-blue-text: #1e40af;
  --tint-green: #ecfdf5;
  --tint-green-text: #065f46;
  --tint-red: #fef2f2;
  --tint-red-text: #991b1b;
  --tint-red-soft: #fee2e2;
  --tint-red-soft-hover: #fecaca;
  --tint-orange: #fff7ed;
  --tint-orange-text: #9a3412;
  --surface-alt: #f1f4fa;
  --surface-soft: #fafbff;
  --tint-gold: #fdf3e0;
  --tint-gold-text: #92660f;
  --heading: var(--navy);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1626; --card: #182338; --text: #e5eaf5; --text-mute: #97a3c2; --border: #2c3a5c;
    --shadow: 0 4px 16px rgba(0,0,0,.35); --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
    --tint-blue: #1d2a4d; --tint-blue-text: #9db8ff;
    --tint-green: #123527; --tint-green-text: #6ee7ab;
    --tint-red: #3a1c22; --tint-red-text: #fca5a5;
    --tint-red-soft: #4a2129; --tint-red-soft-hover: #5c2a33;
    --tint-orange: #3a2a14; --tint-orange-text: #fbbf74;
    --surface-alt: #1e2a47; --surface-soft: #1a2540;
    --tint-gold: #3a2e14; --tint-gold-text: #e0b463;
    --heading: #eef2ff;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1626; --card: #182338; --text: #e5eaf5; --text-mute: #97a3c2; --border: #2c3a5c;
  --shadow: 0 4px 16px rgba(0,0,0,.35); --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
  --tint-blue: #1d2a4d; --tint-blue-text: #9db8ff;
  --tint-green: #123527; --tint-green-text: #6ee7ab;
  --tint-red: #3a1c22; --tint-red-text: #fca5a5;
  --tint-red-soft: #4a2129; --tint-red-soft-hover: #5c2a33;
  --tint-orange: #3a2a14; --tint-orange-text: #fbbf74;
  --surface-alt: #1e2a47; --surface-soft: #1a2540;
  --tint-gold: #3a2e14; --tint-gold-text: #e0b463;
  --heading: #eef2ff;
}
html { background: var(--bg); }
body { transition: background-color .2s, color .2s; }

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: "Sarabun", "Noto Sans Thai", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }
img { max-width: 100%; display: block; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-family: "Sarabun", sans-serif; font-weight: 700; margin: 0 0 .5em; color: var(--heading); }
p { margin: 0 0 1em; }
.container { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.section { padding: 56px 0; }
.section-tight { padding: 32px 0; }
.text-center { text-align: center; }
.text-mute { color: var(--text-mute); }
.badge {
  display: inline-block; padding: 4px 12px; border-radius: 999px;
  font-size: .78rem; font-weight: 600; background: var(--tint-blue); color: var(--blue);
}
.badge-gold { background: var(--tint-gold); color: var(--tint-gold-text); }

/* ---------- Header / Nav ---------- */
#site-header {
  position: sticky; top: 0; z-index: 100;
  background: linear-gradient(180deg, var(--navy) 0%, var(--navy-dark) 100%);
  box-shadow: var(--shadow);
}
.nav-wrap {
  max-width: 1180px; margin: 0 auto; padding: 10px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; flex-shrink: 0; }
.brand:hover { text-decoration: none; }
.brand-mark {
  height: 46px; width: auto; flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; white-space: nowrap; }
.brand-text strong { font-size: 1rem; letter-spacing: .3px; }
.brand-text small { color: #c7d2e8; font-size: .74rem; }
.nav-links { display: flex; gap: 2px; flex-wrap: wrap; }
.nav-links a {
  color: #dce4f4; padding: 6px 6px; border-radius: 8px; font-size: .83rem;
  font-weight: 500; transition: .15s; white-space: nowrap;
}
.nav-links a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.nav-links a.active { background: var(--gold); color: var(--navy-dark); font-weight: 700; }
.nav-toggle {
  display: none; background: none; border: none; color: #fff; font-size: 1.4rem; cursor: pointer;
}
.theme-toggle {
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.2); color: #fff;
  font-size: 1rem; width: 34px; height: 34px; border-radius: 50%; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; transition: .15s;
}
.theme-toggle:hover { background: rgba(255,255,255,.18); }
.session-role-badge {
  background: rgba(201,150,44,.18); border: 1px solid rgba(201,150,44,.45); color: var(--gold-light);
  font-size: .74rem; font-weight: 700; padding: 5px 9px; border-radius: 999px; white-space: nowrap; flex-shrink: 0;
}
@media (max-width: 1179px) {
  .nav-toggle { display: block; }
  .nav-links {
    display: none; position: absolute; left: 0; right: 0; top: 100%;
    background: var(--navy-dark); flex-direction: column; padding: 10px 20px 16px; gap: 2px;
  }
  .nav-links.open { display: flex; }
  #site-header { position: relative; }
}

/* ---------- Hero ---------- */
.hero {
  background: radial-gradient(1200px 500px at 80% -10%, rgba(201,150,44,.25), transparent),
              linear-gradient(135deg, rgba(18,41,77,.88) 0%, rgba(26,58,107,.85) 60%, rgba(30,90,168,.82) 100%),
              url('../images/hero-bg.jpg') center/cover no-repeat;
  color: #fff; padding: 72px 0 64px; position: relative; overflow: hidden;
}
.hero::after {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(circle at 15% 30%, rgba(255,255,255,.06) 0, transparent 40%);
}
.hero-inner { position: relative; z-index: 1; display: grid; grid-template-columns: 1.2fr .8fr; gap: 40px; align-items: center; }
@media (max-width: 900px) { .hero-inner { grid-template-columns: 1fr; } }
.hero h1 { color: #fff; font-size: clamp(1.7rem, 3.4vw, 2.7rem); margin-bottom: .4em; }
.hero p.lead { color: #dce4f4; font-size: 1.08rem; max-width: 560px; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 22px; }
.hero-stats {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px 12px;
  background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.15);
  border-radius: var(--radius); padding: 20px; backdrop-filter: blur(6px);
}
.hero-stat { text-align: center; }
.hero-stat .num { font-size: 1.9rem; font-weight: 800; color: var(--gold-light); }
.hero-stat .lbl { font-size: .78rem; color: #dce4f4; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 11px 22px;
  border-radius: 10px; font-weight: 600; font-size: .95rem; cursor: pointer;
  border: 1px solid transparent; transition: .15s; font-family: inherit;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--gold); color: var(--navy-dark); }
.btn-primary:hover { background: var(--gold-light); }
.btn-outline { background: transparent; border-color: rgba(255,255,255,.5); color: #fff; }
.btn-outline:hover { background: rgba(255,255,255,.12); }
.btn-navy { background: var(--navy); color: #fff; }
.btn-navy:hover { background: var(--navy-dark); }
.btn-danger { background: var(--tint-red-soft); color: var(--danger); }
.btn-danger:hover { background: var(--tint-red-soft-hover); }
.btn-sm { padding: 7px 14px; font-size: .84rem; border-radius: 8px; }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards / Grid ---------- */
.grid { display: grid; gap: 20px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-6 { grid-template-columns: repeat(6, 1fr); }
@media (max-width: 900px) { .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-6 { grid-template-columns: repeat(3,1fr); } }
@media (max-width: 560px) { .grid-3, .grid-4, .grid-6 { grid-template-columns: 1fr 1fr; } }

.card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 1px solid var(--border); padding: 22px;
}
.card-hover { transition: .18s; }
.card-hover:hover { box-shadow: var(--shadow-lg); transform: translateY(-2px); }
.icon-box {
  width: 46px; height: 46px; border-radius: 12px; display: flex; align-items: center;
  justify-content: center; font-size: 1.3rem; background: var(--tint-blue); color: var(--blue); margin-bottom: 12px;
}
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 28px; flex-wrap: wrap; }
.section-head h2 { margin: 0 0 6px; }
.section-eyebrow { color: var(--gold); font-weight: 700; font-size: .85rem; letter-spacing: .06em; text-transform: uppercase; margin-bottom: 6px; }

/* amphoe chip colors */
.amphoe-chip { display: inline-flex; align-items: center; gap: 6px; font-size: .78rem; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------- School list ---------- */
.toolbar {
  display: flex; gap: 12px; flex-wrap: wrap; align-items: center;
  background: var(--card); padding: 16px; border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: 22px; border: 1px solid var(--border);
}
.input, select.input, textarea.input {
  padding: 10px 14px; border-radius: 9px; border: 1px solid var(--border);
  font-family: inherit; font-size: .94rem; background: var(--card); color: var(--text);
}
.input:focus, select.input:focus, textarea.input:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.searchable-select { position: relative; width: 100%; }
.searchable-select .input { width: 100%; }
.searchable-select-options {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: var(--shadow-lg); max-height: 240px; overflow-y: auto; z-index: 50;
}
.searchable-select-option { padding: 10px 14px; font-size: .9rem; cursor: pointer; }
.searchable-select-option:hover, .searchable-select-option.active { background: var(--tint-blue); }
.searchable-select-empty { padding: 10px 14px; font-size: .85rem; color: var(--text-mute); }
.toolbar .input[type="search"] { flex: 1; min-width: 200px; }
.chip-filter { display: flex; gap: 8px; flex-wrap: wrap; }
.chip-filter button {
  border: 1px solid var(--border); background: var(--card); padding: 6px 14px; border-radius: 999px;
  font-size: .82rem; cursor: pointer; font-weight: 600; color: var(--text-mute);
}
.chip-filter button.active { background: var(--navy); color: #fff; border-color: var(--navy); }

.school-card { display: flex; flex-direction: column; gap: 8px; }
.school-card h3 { font-size: 1.02rem; margin: 0; }
.school-card .meta { font-size: .82rem; color: var(--text-mute); }
.result-count { color: var(--text-mute); font-size: .9rem; margin-bottom: 14px; }
.update-badge { font-size: .76rem; font-weight: 600; color: var(--text-mute); display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.update-badge-date { color: var(--danger); font-weight: 700; }
.update-badge-fresh .update-badge-date { color: #16a34a; }
.update-badge-stale { color: var(--danger); }

/* ---------- เปรียบเทียบโรงเรียน ---------- */
.school-card-wrap { position: relative; }
.compare-check {
  position: absolute; top: 10px; right: 10px; z-index: 2;
  display: flex; align-items: center; gap: 4px; background: var(--card); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 9px 3px 6px; font-size: .74rem; font-weight: 600; color: var(--text-mute);
  box-shadow: var(--shadow); cursor: pointer;
}
.compare-check input { margin: 0; cursor: pointer; }
.compare-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 150;
  background: var(--navy-dark); color: #fff; box-shadow: 0 -6px 20px rgba(0,0,0,.25);
}
.compare-bar-inner { display: flex; align-items: center; gap: 14px; padding: 12px 20px; flex-wrap: wrap; }
.compare-bar-chip {
  display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,.1);
  border-radius: 999px; padding: 4px 10px; font-size: .82rem;
}
.compare-bar-chip button { background: none; border: none; color: #dce4f4; cursor: pointer; font-size: .9rem; line-height: 1; padding: 0; }
@media (max-width: 700px) { .compare-bar-inner { justify-content: center; } }

/* ---------- ป้ายลอยผู้ออนไลน์ขณะนี้ ---------- */
.online-badge {
  position: fixed; left: 16px; bottom: 16px; z-index: 140;
  display: flex; align-items: center; gap: 7px;
  background: var(--navy-dark); color: #fff; border-radius: 999px;
  padding: 8px 14px 8px 12px; font-size: .82rem; font-weight: 600;
  box-shadow: var(--shadow-lg); cursor: default;
}
.online-badge #onlineBadgeCount { font-variant-numeric: tabular-nums; }
.online-badge-label { color: #b9c4dc; font-weight: 500; }
.online-dot {
  width: 9px; height: 9px; border-radius: 50%; background: #22c55e; flex-shrink: 0;
  box-shadow: 0 0 0 rgba(34,197,94,.6); animation: online-pulse 2s infinite;
}
@keyframes online-pulse {
  0% { box-shadow: 0 0 0 0 rgba(34,197,94,.6); }
  70% { box-shadow: 0 0 0 7px rgba(34,197,94,0); }
  100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}
@media (prefers-reduced-motion: reduce) { .online-dot { animation: none; } }
@media (max-width: 600px) { .online-badge { left: 10px; bottom: 10px; padding: 7px 12px 7px 10px; font-size: .78rem; } }
/* หน้า schools.html มีแถบเปรียบเทียบลอยเต็มความกว้างที่ด้านล่างเช่นกัน — ยกป้ายออนไลน์ขึ้นกันไม่ให้ซ้อนทับกัน */
#compareBar:not(.hidden) ~ .online-badge { bottom: 76px; }

/* ---------- ทัวร์แนะนำเว็บไซต์ ---------- */
.tour-overlay { position: fixed; inset: 0; z-index: 400; pointer-events: none; }
.tour-highlight {
  position: fixed; border-radius: 10px; pointer-events: none;
  box-shadow: 0 0 0 9999px rgba(8, 15, 28, .68);
  transition: top .25s, left .25s, width .25s, height .25s;
}
.tour-tooltip {
  position: fixed; z-index: 401; max-width: 320px; background: var(--card); color: var(--text);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); padding: 16px 18px; transition: top .25s, left .25s;
}
.tour-tooltip-title { font-weight: 700; color: var(--heading); margin-bottom: 6px; font-size: 1rem; }
.tour-tooltip-text { font-size: .88rem; color: var(--text-mute); line-height: 1.6; }
.tour-tooltip-actions { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.tour-skip { background: none; border: none; color: var(--text-mute); font-size: .82rem; cursor: pointer; text-decoration: underline; padding: 0; }
.tour-progress { font-size: .78rem; color: var(--text-mute); }
@media (max-width: 600px) { .tour-tooltip { max-width: calc(100vw - 24px); } }

/* ---------- เอฟเฟกต์สายฝน (สถานการณ์น้ำท่วมระดับหนัก) ---------- */
.flood-rain-overlay { position: fixed; inset: 0; z-index: 5; pointer-events: none; overflow: hidden; }
.flood-rain-drop {
  position: absolute; top: -10%; width: 1px; height: 55px;
  background: linear-gradient(180deg, transparent, rgba(147,197,253,.4));
  animation-name: flood-rain-fall; animation-timing-function: linear; animation-iteration-count: infinite;
}
@keyframes flood-rain-fall {
  from { transform: translateY(-10vh); }
  to { transform: translateY(110vh); }
}

table.data-table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; }
table.data-table th, table.data-table td { padding: 12px 14px; border-bottom: 1px solid var(--border); text-align: left; font-size: .92rem; }
table.data-table th { background: var(--surface-alt); color: var(--heading); font-weight: 700; }
table.data-table tr:hover td { background: var(--surface-soft); }

/* ---------- Map ---------- */
.map-layout { display: grid; grid-template-columns: 280px 1fr 300px; gap: 20px; align-items: start; }
.map-sidebar {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border);
  padding: 18px; display: flex; flex-direction: column; gap: 18px;
  position: sticky; top: 84px;
}
.map-main { min-width: 0; }
.map-info { display: flex; flex-direction: column; gap: 16px; position: sticky; top: 84px; }
.map-info .alert { margin-bottom: 0; }
.map-filter-toggle, .map-sheet-head, .map-sheet-foot, .map-sheet-backdrop { display: none; }
.map-fs-control, .map-fs-filter { display: none; }
@media (max-width: 700px) { .amphoe-label-count { display: none; } } /* มือถือ: ป้ายอำเภอแสดงเฉพาะชื่อ กันตัวหนังสือของอำเภอที่อยู่ติดกันซ้อนกัน */
.map-fs-control a { display: flex; align-items: center; justify-content: center; cursor: pointer; }
/* แผนที่เต็มจอ (มือถือ/แท็บเล็ต — js/map.js สลับคลาส map-fs) ลำดับชั้น: แผนที่ 260 < การ์ดหมุด 265 < ฉากหลังแผ่นตัวกรอง 270 < แผ่นตัวกรอง 280 */
#schoolMap.map-fs { position: fixed; inset: 0; z-index: 260; width: 100%; height: 100vh; height: 100dvh; min-height: 0; border-radius: 0; border: 0; box-shadow: none; }
body.map-fs-active .map-fs-filter { display: flex; }
/* การ์ดรายละเอียดหมุดบนมือถือ (แทนป๊อปอัปลอยของ Leaflet ที่เล็กและบังแผนที่) — สร้างด้วย js/map.js, ใช้เฉพาะจอไม่เกิน 700px */
.map-card {
  display: none; position: fixed; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 265;
  max-height: 52vh; max-height: 52dvh; overflow-y: auto; overscroll-behavior: contain;
  background: #fff; color: #1f2937; border-radius: 16px; box-shadow: 0 10px 34px rgba(0,0,0,.45); padding: 16px 16px 14px;
  --heading: #12294d; --border: #cbd5e1; --text: #1f2937;
}
.map-card.open { display: block; animation: mapCardUp .2s ease; }
@keyframes mapCardUp { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .map-card.open { animation: none; } }
.map-card-close { position: absolute; top: 6px; right: 8px; background: none; border: none; font-size: 1.2rem; color: #6b7280; cursor: pointer; padding: 6px 10px; }
.map-card-body { padding-right: 22px; line-height: 1.6; }
@media (min-width: 701px) { .map-card { display: none !important; } }
@media (max-width: 1100px) {
  .map-layout { grid-template-columns: 1fr; }
  .map-info { position: static; }
  /* มือถือ/แท็บเล็ต: แสดงแผนที่ก่อน แล้วซ่อนเมนูตัวกรองเป็นแผ่นเลื่อนขึ้นจากด้านล่าง (สร้างปุ่ม/หัว/ท้ายแผ่นด้วย js/map.js) */
  .map-main { order: 1; }
  .map-info { order: 2; }
  .map-fs-control { display: block; }
  .map-filter-toggle {
    display: flex; align-items: center; gap: 10px; width: 100%; margin-bottom: 10px; text-align: left; justify-content: flex-start;
  }
  .map-filter-toggle .map-filter-summary { flex: 1; min-width: 0; font-size: .82rem; font-weight: 500; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .map-sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; z-index: 280;
    max-height: 66vh; max-height: 66dvh; overflow-y: auto; overscroll-behavior: contain;
    border-radius: 18px 18px 0 0; border-bottom: none; padding: 0 18px calc(18px + env(safe-area-inset-bottom));
    box-shadow: 0 -10px 34px rgba(0,0,0,.4);
    transform: translateY(110%); visibility: hidden;
    transition: transform .25s ease, visibility 0s linear .25s;
  }
  .map-sidebar.open { transform: translateY(0); visibility: visible; transition: transform .25s ease, visibility 0s; }
  .map-sheet-head, .map-sheet-foot { display: flex; position: sticky; z-index: 2; background: var(--card); align-items: center; justify-content: space-between; gap: 10px; }
  .map-sheet-head { top: 0; padding: 14px 0 10px; border-bottom: 1px solid var(--border); font-size: 1rem; }
  .map-sheet-head .map-sheet-close { background: none; border: none; color: var(--heading); font-size: 1.2rem; cursor: pointer; padding: 4px 8px; }
  .map-sheet-foot { bottom: 0; padding-top: 10px; margin-top: 4px; border-top: 1px solid var(--border); }
  .map-sheet-backdrop { position: fixed; inset: 0; z-index: 270; background: transparent; }
  .map-sheet-backdrop.open { display: block; }
}
@media (prefers-reduced-motion: reduce) { .map-sidebar, .map-sidebar.open { transition: none; } }
#schoolMap { width: 100%; height: 560px; border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); background: var(--bg); }
.map-legend { display: flex; flex-wrap: wrap; gap: 10px 18px; margin-top: 14px; }
.map-legend .item { display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--text-mute); }
/* ป๊อปอัปพื้นขาวเสมอ แม้เว็บอยู่ในโหมดมืด — ตั้งค่าสีตัวแปรให้ปุ่มขอบ/ตัวอักษรในป๊อปอัป (เช่น ปุ่ม "นำทาง") อ่านออกบนพื้นขาว */
.leaflet-popup-content { font-family: "Sarabun", sans-serif; --heading: #12294d; --border: #cbd5e1; --text: #1f2937; }
/* Leaflet วางเลเยอร์ภายใน (ปุ่ม +/-, popup) ด้วย z-index สูงถึง 1000 ทำให้ทับแถบเมนูบนสุด (z-index:100) ตอนเลื่อนหน้าจอ
   ครอบด้วย stacking context ใหม่ที่ z-index ต่ำกว่าแถบเมนู เพื่อกันไม่ให้ชิ้นส่วนภายในแผนที่หลุดออกไปทับเมนู */
.leaflet-container { position: relative; z-index: 1; -webkit-tap-highlight-color: transparent; }
/* แตะพื้นที่อำเภอ/หมุดบนมือถือแล้วเบราว์เซอร์วาดกรอบโฟกัสสีดำรอบวัตถุค้างไว้ — ปิดกรอบ (พื้นที่อำเภอไม่ได้ใช้งานด้วยคีย์บอร์ดอยู่แล้ว) */
.leaflet-container .leaflet-interactive:focus, .leaflet-container path:focus, .leaflet-container svg:focus { outline: none; }
/* หมุดโรงเรียนที่น้ำท่วมระดับ "หนัก" กระพริบเบาๆ ให้สังเกตเห็นจุดวิกฤตได้ไวขึ้น */
.flood-pulse-ring {
  position: absolute; inset: 0; border-radius: 50%;
  animation: flood-marker-pulse 1.8s ease-out infinite;
}
@keyframes flood-marker-pulse {
  0% { transform: scale(1); opacity: .55; }
  100% { transform: scale(2.4); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) { .flood-pulse-ring { display: none; } }

/* ---------- Quiz ---------- */
.quiz-shell { max-width: 720px; margin: 0 auto; }
.quiz-progress { height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; margin-bottom: 24px; }
.quiz-progress-bar { height: 100%; background: linear-gradient(90deg, var(--gold), var(--blue)); transition: width .3s; }
.quiz-q { font-size: 1.15rem; font-weight: 700; margin-bottom: 18px; }
.quiz-options { display: grid; gap: 10px; }
.quiz-option {
  text-align: left; padding: 14px 16px; border-radius: 10px; border: 1.5px solid var(--border);
  background: var(--card); cursor: pointer; font-family: inherit; font-size: .96rem; transition: .12s;
}
.quiz-option:hover { border-color: var(--blue); background: var(--tint-blue); }
.quiz-option.selected { border-color: var(--blue); background: var(--tint-blue); font-weight: 700; }
.quiz-option.correct { border-color: var(--success); background: var(--tint-green); font-weight: 700; }
.quiz-option.wrong { border-color: var(--danger); background: var(--tint-red); font-weight: 700; }
.quiz-option:disabled { cursor: default; }

#certificateCanvas { width: 100%; max-width: 800px; border-radius: 10px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }

.leaderboard-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.leaderboard-rank { width: 28px; height: 28px; border-radius: 50%; background: var(--tint-blue); color: var(--blue); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: .82rem; flex-shrink:0; }
.leaderboard-rank.gold { background: var(--gold); color: #fff; }

/* ---------- Forms / Admin ---------- */
.form-row { margin-bottom: 16px; display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-weight: 600; font-size: .88rem; color: var(--heading); }
.login-box { max-width: 380px; margin: 60px auto; }
.stat-mini { background: var(--card); border-radius: 12px; padding: 16px 18px; border: 1px solid var(--border); box-shadow: var(--shadow); }
.stat-mini .num { font-size: 1.6rem; font-weight: 800; color: var(--heading); }
.stat-mini .lbl { font-size: .8rem; color: var(--text-mute); }
.alert { padding: 12px 16px; border-radius: 10px; font-size: .9rem; margin-bottom: 16px; }
.alert-info { background: var(--tint-blue); color: var(--tint-blue-text); }
.alert-warn { background: var(--tint-orange); color: var(--tint-orange-text); }
.alert-danger { background: var(--tint-red); color: var(--tint-red-text); }
.alert-success { background: var(--tint-green); color: var(--tint-green-text); }
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(11,26,51,.55); display: none;
  align-items: center; justify-content: center; z-index: 200; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal-box { background: var(--card); border-radius: var(--radius); padding: 26px; max-width: 520px; width: 100%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-lg); }

/* ---------- Dashboard bar charts ---------- */
.dash-kpi .num { font-size: 2rem; }
.barchart { display: flex; flex-direction: column; gap: 12px; }
.barchart-row {
  display: grid; grid-template-columns: 150px 1fr 60px; align-items: center; gap: 12px;
  text-decoration: none; border-radius: 8px; padding: 4px 6px; margin: -4px -6px;
  transition: background .12s;
}
a.barchart-row:hover { background: var(--surface-alt); text-decoration: none; }
.barchart-label { font-size: .86rem; color: var(--text); text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.barchart-track { display: block; background: var(--surface-alt); border-radius: 999px; height: 18px; overflow: hidden; }
.barchart-fill { display: block; height: 100%; border-radius: 0 4px 4px 0; min-width: 4px; transition: width .8s cubic-bezier(.16,1,.3,1); }
@media (prefers-reduced-motion: reduce) { .barchart-fill { transition: none; } }
.barchart-value { font-weight: 700; font-size: .9rem; color: var(--heading); font-variant-numeric: tabular-nums; }
.dash-section-note { font-size: .82rem; color: var(--text-mute); margin: -8px 0 18px; }

/* ---------- Timeline / About ---------- */
.timeline { border-left: 3px solid var(--border); padding-left: 22px; margin-left: 10px; }
.timeline .t-item { position: relative; padding-bottom: 26px; }
.timeline .t-item::before { content: ""; position: absolute; left: -28px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--gold); border: 2px solid var(--card); box-shadow: 0 0 0 2px var(--gold); }

/* ---------- Footer ---------- */
#site-footer { background: var(--navy-dark); color: #cfd8ea; margin-top: 60px; }
.footer-wrap {
  max-width: 1180px; margin: 0 auto; padding: 44px 20px 20px;
  display: grid; grid-template-columns: 1.3fr 1fr 1.3fr; gap: 30px;
}
@media (max-width: 760px) { .footer-wrap { grid-template-columns: 1fr; } }
.footer-col strong { color: #fff; display: block; margin-bottom: 10px; }
.footer-col a { display: block; color: #b9c4dc; margin-bottom: 6px; font-size: .9rem; }
.footer-col p { font-size: .85rem; color: #a9b6d1; }
.footer-bottom { text-align: center; padding: 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: .8rem; color: #93a0bd; }

/* ---------- Login tabs (admin.html) ---------- */
.login-tabs { display: flex; gap: 6px; background: var(--surface-alt); border-radius: 10px; padding: 4px; margin-bottom: 22px; }
.login-tabs button {
  flex: 1; border: none; background: transparent; padding: 10px; border-radius: 8px;
  font-family: inherit; font-weight: 600; font-size: .88rem; color: var(--text-mute); cursor: pointer;
}
.login-tabs button.active { background: var(--card); color: var(--heading); box-shadow: var(--shadow); }

/* ---------- Profile editor (ที่อยู่/เบอร์โทร/รูป/วีดีโอ/บุคลากร) ---------- */
.upload-zone {
  border: 2px dashed var(--border); border-radius: 12px; padding: 22px; text-align: center;
  cursor: pointer; background: var(--surface-soft); transition: .15s;
}
.upload-zone:hover { border-color: var(--blue); background: var(--tint-blue); }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; margin-top: 14px; }
.gallery-thumb { position: relative; border-radius: 10px; overflow: hidden; aspect-ratio: 1/1; box-shadow: var(--shadow); border: 1px solid var(--border); }
.gallery-thumb img { width: 100%; height: 100%; object-fit: cover; cursor: pointer; }
.gallery-thumb .remove-btn {
  position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%;
  background: rgba(220,38,38,.92); color: #fff; border: none; cursor: pointer; font-size: .8rem; line-height: 1;
}
.gallery-view { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.gallery-view img { width: 100%; aspect-ratio: 4/3; object-fit: cover; border-radius: 12px; box-shadow: var(--shadow); cursor: zoom-in; border: 1px solid var(--border); transition: .15s; }
.gallery-view img:hover { transform: scale(1.02); box-shadow: var(--shadow-lg); }

/* แกลเลอรีภาพกิจกรรม (สุ่มแสดงหน้าแรก) — แถบเลื่อนแนวนอนต่อเนื่อง ขนาดภาพเท่ากันทุกรูป ต่อชิดกัน */
.activity-gallery-viewport {
  overflow: hidden; width: 100%; -webkit-mask-image: linear-gradient(90deg, transparent, #000 4%, #000 96%, transparent);
  mask-image: linear-gradient(90deg, transparent, #000 4%, #000 96%, transparent);
}
.activity-gallery-track { display: flex; width: max-content; animation: activity-scroll linear infinite; }
.activity-gallery-track:hover { animation-play-state: paused; }
.activity-gallery-item { position: relative; flex: 0 0 auto; width: 260px; height: 190px; overflow: hidden; }
.activity-gallery-item img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; transition: .25s; }
.activity-gallery-item:hover img { transform: scale(1.06); }
.activity-gallery-item .activity-caption {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 12px 8px;
  background: linear-gradient(0deg, rgba(11,26,51,.85), transparent);
  color: #fff; font-size: .8rem; font-weight: 600; pointer-events: none;
}
@keyframes activity-scroll {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}
@media (prefers-reduced-motion: reduce) {
  .activity-gallery-track { animation: none; }
}

.video-embed { position: relative; width: 100%; padding-top: 56.25%; border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); background: #000; }
.video-embed iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }

/* หน้าต่างตัวอย่างเว็บไซต์/เพจ Facebook แบบฝัง (iframe) */
.site-embed { width: 100%; height: 480px; border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); border: 1px solid var(--border); background: var(--card); }
.site-embed iframe { width: 100%; height: 100%; border: 0; }

.staff-card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 14px; text-align: center; position: relative; }
.staff-photo { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; margin: 0 auto 10px; border: 3px solid var(--card); box-shadow: 0 0 0 2px var(--border); background: var(--tint-blue); }
.staff-card h4 { margin: 0 0 2px; font-size: .92rem; }
.staff-card .pos { color: var(--text-mute); font-size: .8rem; }
.staff-card .remove-btn {
  position: absolute; top: 8px; right: 8px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--tint-red-soft); color: var(--danger); border: none; cursor: pointer; font-size: .8rem;
}
.staff-card .edit-btn {
  position: absolute; top: 8px; left: 8px; width: 24px; height: 24px; border-radius: 50%;
  background: var(--tint-blue); color: var(--blue); border: none; cursor: pointer; font-size: .75rem;
}
.staff-form-row { display: grid; grid-template-columns: 132px 1fr 1fr auto; gap: 10px; align-items: start; margin-bottom: 10px; }
@media (max-width: 700px) { .staff-form-row { grid-template-columns: 1fr; } }
.avatar-preview { width: 84px; height: 84px; border-radius: 50%; object-fit: cover; background: var(--tint-blue); border: 1px solid var(--border); cursor: pointer; display: block; margin: 0 auto; }

.lightbox {
  position: fixed; inset: 0; background: rgba(11,26,51,.9); display: none; align-items: center;
  justify-content: center; z-index: 300; padding: 30px; cursor: zoom-out;
}
.lightbox.open { display: flex; }
.lightbox img { max-width: 100%; max-height: 90vh; border-radius: 10px; box-shadow: var(--shadow-lg); }
.lightbox .close-btn { position: absolute; top: 20px; right: 26px; color: #fff; font-size: 2rem; background: none; border: none; cursor: pointer; }

/* Utility spacing */
.mt-0{margin-top:0} .mt-1{margin-top:8px} .mt-2{margin-top:16px} .mt-3{margin-top:24px} .mt-4{margin-top:36px}
.mb-0{margin-bottom:0} .mb-1{margin-bottom:8px} .mb-2{margin-bottom:16px} .mb-3{margin-bottom:24px}
.flex { display: flex; } .items-center{align-items:center} .justify-between{justify-content:space-between} .gap-1{gap:8px} .gap-2{gap:16px}
.hidden { display: none !important; }

/* ---------- Responsive: ตาราง, กราฟ/รายละเอียดสองคอลัมน์, แผนที่, การ์ดจัดการ (มือถือ/แท็บเล็ต) ---------- */
.dash-split { display: grid; grid-template-columns: 1.1fr .9fr; gap: 24px; align-items: start; }
@media (max-width: 900px) { .dash-split { grid-template-columns: 1fr; } }
.school-detail-split { display: grid; grid-template-columns: 1.3fr .9fr; gap: 26px; align-items: start; }
@media (max-width: 900px) { .school-detail-split { grid-template-columns: 1fr; } }
@media (max-width: 700px) {
  table.data-table { display: block; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; }
  #schoolMap { height: 68vh; height: 68dvh; min-height: 380px; } /* มือถือ: ให้แผนที่สูงเกือบเต็มจอ */
  .map-hero-lead { display: none; } /* ซ่อนคำอธิบายใต้หัวข้อหน้าแผนที่บนมือถือ เพื่อให้เห็นแผนที่เร็วขึ้น */
  .map-hero { padding-top: 14px; padding-bottom: 14px; }
  .map-hero h1 { font-size: 1.3rem; margin-bottom: 0 !important; }
  .map-hero .badge { margin-bottom: 6px !important; }
  .map-section { padding-top: 16px; padding-bottom: 24px; }
  /* หน้าแรกบนมือถือ: ย่อส่วนหัวให้เห็นแผนที่/เนื้อหาเร็วขึ้น — ซ่อนป้ายและคำโปรย ปุ่มเรียงสองคอลัมน์ สถิติเป็นแถวเดียว */
  .hero-home { padding: 22px 0 20px; }
  .hero-home .hero-inner { gap: 16px; }
  .hero-home .badge { display: none; }
  .hero-home h1 { font-size: 1.3rem; margin-bottom: .5em; }
  .hero-home p.lead { display: none; }
  .hero-home .hero-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
  .hero-home .hero-actions .btn { width: 100%; justify-content: center; padding: 10px 8px; font-size: .84rem; }
  .hero-home .hero-stats { grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 12px 4px; }
  .hero-home .hero-stat .num { font-size: 1.25rem; }
  .hero-home .hero-stat .lbl { font-size: .64rem; line-height: 1.3; }
}
@media (max-width: 600px) {
  .quiz-question-row { flex-direction: column; }
  .quiz-question-actions { flex-direction: row !important; }
}
