/* ============================================================================
   สายน้ำระยอง · vx — ธีมสว่างเป็นค่าเริ่มต้น (สลับมืดด้วยปุ่ม ☾)
   ========================================================================== */

:root,
html[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f7f9;
  --bg-2: #eef3f6;
  --surface: #ffffff;
  --surface-2: #f8fbfc;
  --line: #e1e9ef;
  --line-2: #edf3f6;
  --ink: #0c2233;
  --ink-2: #3e5a70;
  --muted: #7d93a7;
  --brand: #0a7ea4;
  --brand-2: #12a2c6;
  --brand-soft: #e6f4f9;
  --brand-ink: #06546f;
  --sea: #0f9bb0;
  --ok: #2e9e6b;
  --warn: #e08a0b;
  --danger: #d9453a;
  --crit: #9b1c1c;
  --shadow: 0 1px 2px rgba(12, 34, 51, 0.05), 0 8px 24px -12px rgba(12, 34, 51, 0.16);
  --shadow-lg: 0 2px 6px rgba(12, 34, 51, 0.06), 0 24px 48px -20px rgba(12, 34, 51, 0.22);
  --radius: 16px;
  --radius-sm: 11px;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #08131f;
  --bg-2: #0d1c2a;
  --surface: #102131;
  --surface-2: #132739;
  --line: #1d3548;
  --line-2: #172c3d;
  --ink: #e9f2f9;
  --ink-2: #a9c1d5;
  --muted: #7f97ac;
  --brand: #3fbcdf;
  --brand-2: #63cdea;
  --brand-soft: #0d2b3b;
  --brand-ink: #8fd8ee;
  --sea: #2ec4d6;
  --ok: #43b985;
  --warn: #f0a92e;
  --danger: #f0685c;
  --crit: #d8453f;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 12px 32px -16px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 2px 8px rgba(0, 0, 0, 0.45), 0 30px 60px -24px rgba(0, 0, 0, 0.75);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { background: var(--bg); }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "IBM Plex Sans Thai", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  padding-top: 64px;
  transition: background 0.25s ease, color 0.25s ease;
}
body.no-scroll { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
.num, .kpi-v, .card-value, table td.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ══════════════════════════════ top bar ══════════════════════════════ */
.topbar {
  position: fixed; inset: 0 0 auto 0; z-index: 60;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}
.tb-inner {
  max-width: 1360px; margin: 0 auto; height: 63px;
  display: flex; align-items: center; gap: 22px; padding: 0 20px;
}
.brand { display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(150deg, var(--brand) 0%, var(--sea) 100%);
  box-shadow: 0 4px 12px -4px color-mix(in srgb, var(--brand) 70%, transparent);
}
.brand-mark svg { width: 19px; height: 19px; fill: #fff; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.brand-text small { font-size: 8.5px; letter-spacing: 0.14em; color: var(--muted); font-weight: 500; }

.mainnav {
  display: flex; align-items: center; gap: 2px; flex: 1 1 auto; min-width: 0;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain; scroll-padding-inline: 12px;
}
.mainnav::-webkit-scrollbar { display: none; }
.mainnav a {
  padding: 8px 13px; border-radius: 999px; font-size: 13.5px; color: var(--ink-2);
  font-weight: 500; white-space: nowrap; transition: 0.15s; flex: 0 0 auto;
}
.mainnav a:hover { background: var(--bg-2); color: var(--ink); }
.mainnav a.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
html[data-theme="dark"] .mainnav a.active { color: var(--brand-2); }

.tb-actions { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.tb-live {
  display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted);
  padding: 5px 11px 5px 9px; border-radius: 999px; background: var(--surface-2);
  border: 1px solid var(--line-2); margin-right: 2px;
}
.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 2.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); } 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
/* ── ความสดของข้อมูล (Round 2) — ต่อท้าย pill เดียวกัน ไม่เพิ่มแถบใหม่ ── */
.tb-sep { color: var(--line-2); margin: 0 -2px; }
.tb-data { font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.tb-data.fresh { color: var(--ok); }
.tb-data.stale { color: var(--warn); }
.tb-data.missing { color: var(--muted); font-weight: 500; }
.tb-data.unavailable { color: var(--danger); }
html[data-freshness="stale"] .pulse { background: var(--warn); animation: none; }
html[data-freshness="unavailable"] .pulse { background: var(--danger); animation: none; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2); font-size: 15px; cursor: pointer;
  display: grid; place-items: center; transition: 0.15s;
}
.icon-btn:hover { background: var(--bg-2); color: var(--ink); border-color: var(--line); }
.icon-btn.spinning { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tb-progress { height: 2px; background: transparent; overflow: hidden; }
.tb-progress.on::after {
  content: ""; display: block; height: 2px; width: 40%;
  background: linear-gradient(90deg, transparent, var(--brand), transparent);
  animation: slide 1.1s ease-in-out infinite;
}
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(320%); } }

/* ══════════════════════════════ layout ══════════════════════════════ */
.wrap { max-width: 1360px; margin: 0 auto; padding: 24px 20px 44px; }
.view { animation: fade 0.28s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
section[hidden] { display: none !important; }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 18px;
  margin: 8px 0 18px; flex-wrap: wrap;
}
.page-head h2 { margin: 0 0 3px; font-size: 23px; font-weight: 600; letter-spacing: -0.015em; }
.page-head p { margin: 0; color: var(--muted); font-size: 13px; max-width: 62ch; }
.ghost-link { font-size: 12.5px; color: var(--brand); border-bottom: 1px dashed color-mix(in srgb, var(--brand) 45%, transparent); padding-bottom: 1px; }

/* ══════════════════════════════ cards ══════════════════════════════ */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); grid-column: span 4;
  display: flex; flex-direction: column; min-width: 0;
}
.card.w6 { grid-column: span 6; }
.card.w8 { grid-column: span 8; }
.card.w12 { grid-column: span 12; }
.card.w3 { grid-column: span 3; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-title { font-size: 13px; font-weight: 600; color: var(--ink); display: flex; align-items: center; gap: 7px; }
.card-title .ico { width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; font-size: 11px; background: var(--brand-soft); color: var(--brand-ink); }
html[data-theme="dark"] .card-title .ico { color: var(--brand-2); }
.card-sub { font-size: 11.5px; color: var(--muted); }

.rows { display: flex; flex-direction: column; gap: 2px; }
.row { display: flex; align-items: center; gap: 10px; padding: 8px 2px; border-bottom: 1px solid var(--line-2); }
.row:last-child { border-bottom: 0; }
.row-main { flex: 1 1 auto; min-width: 0; }
.row-t { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-s { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-v { text-align: right; font-variant-numeric: tabular-nums; flex: 0 0 auto; }
.row-v b { font-size: 14px; font-weight: 600; }
.row-v small { font-size: 10.5px; color: var(--muted); margin-left: 2px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 12%, transparent); }

.bar { height: 7px; border-radius: 99px; background: var(--bg-2); overflow: hidden; margin-top: 7px; }
.bar i { display: block; height: 100%; border-radius: 99px; background: var(--brand); transition: width 0.8s cubic-bezier(0.3, 1, 0.4, 1); }
.bar i.high { background: var(--warn); }
.bar i.over { background: var(--danger); }

/* ══════════════════════════════ charts ══════════════════════════════ */
svg.chart { width: 100%; display: block; overflow: visible; }
.chart-grid { stroke: var(--line-2); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 9px; font-family: "Inter", sans-serif; }
.chart-line { fill: none; stroke-width: 1.9; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart-area { opacity: 0.14; }
.chart-bar { opacity: 0.85; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; font-size: 11px; color: var(--ink-2); }
.chart-legend i { display: inline-block; width: 9px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.chart-note { font-size: 11px; color: var(--muted); margin-top: 8px; }

/* ══════════════════════════════ map view ══════════════════════════════ */
.view-map { position: relative; }
.map-stage { position: relative; height: calc(100dvh - 64px); min-height: 420px; }
#map { position: absolute; inset: 0; background: var(--bg-2); }
.maplibregl-ctrl-attrib { font-size: 10px; }

.map-panel {
  position: absolute; top: 16px; left: 16px; width: 344px; max-height: calc(100% - 32px);
  background: color-mix(in srgb, var(--surface) 96%, transparent); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; overflow: hidden; z-index: 5;
}
.mp-search { padding: 12px 12px 8px; position: relative; }
.mp-search input {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--ink); font-family: inherit; font-size: 13px; outline: none;
}
.mp-search input:focus { border-color: var(--brand); background: var(--surface); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 14%, transparent); }
.mp-results {
  position: absolute; left: 12px; right: 12px; top: 52px; z-index: 9;
  background: var(--surface); border: 1px solid var(--line); border-radius: 11px;
  box-shadow: var(--shadow-lg); overflow: hidden; max-height: 300px; overflow-y: auto;
}
.mp-results.hidden { display: none; }
.mp-res { padding: 8px 11px; font-size: 12.5px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.mp-res:hover { background: var(--bg-2); }
.mp-res span { color: var(--muted); font-size: 11px; }
.mp-tabs { display: flex; gap: 3px; padding: 0 12px 10px; }
.mp-tab {
  flex: 1; border: 0; background: transparent; color: var(--ink-2); font-size: 12px;
  padding: 7px 4px; border-radius: 9px; cursor: pointer; white-space: nowrap; transition: 0.15s;
}
.mp-tab:hover { background: var(--bg-2); }
.mp-tab.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
html[data-theme="dark"] .mp-tab.active { color: var(--brand-2); }
.mp-body { overflow-y: auto; padding: 0 12px 12px; }
.mp-item {
  display: flex; align-items: center; gap: 9px; padding: 9px 8px; border-radius: 9px;
  cursor: pointer; border-bottom: 1px solid var(--line-2);
}
.mp-item:hover { background: var(--bg-2); }
.mp-item.active { background: var(--brand-soft); }
.mp-item .row-t { font-size: 12.5px; }
.mp-item .row-s { font-size: 10.5px; }
.mp-empty { padding: 18px 8px; text-align: center; color: var(--muted); font-size: 12px; }

.map-tools { position: absolute; top: 16px; right: 16px; display: flex; gap: 6px; z-index: 5; align-items: flex-start; }
.mt-btn {
  width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 96%, transparent); backdrop-filter: blur(10px);
  color: var(--ink-2); font-size: 12.5px; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow); display: grid; place-items: center; transition: 0.15s;
}
.mt-btn:hover { color: var(--ink); border-color: var(--brand); }
.mt-btn.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.panel-toggle { display: none; }
.legend-toggle { display: none; }
.legend-close { display: none; }
.legend-toggle:focus-visible, .legend-close:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px;
}
.mt-menu { position: relative; }
.mt-pop {
  position: absolute; top: 46px; right: 0; width: 236px; padding: 8px; z-index: 6;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}
.mt-pop.hidden { display: none; }
.mt-pop-title { font-size: 10.5px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); padding: 4px 8px 6px; }
.mt-pop label { display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 8px; font-size: 12.5px; cursor: pointer; }
.mt-pop label:hover { background: var(--bg-2); }
.mt-pop input { accent-color: var(--brand); width: 15px; height: 15px; }
.lg-dots { margin-left: auto; }

.map-legend {
  position: absolute; left: 16px; bottom: 18px; z-index: 4;
  background: color-mix(in srgb, var(--surface) 95%, transparent); backdrop-filter: blur(10px);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow);
}
.ml-title { font-size: 10.5px; color: var(--muted); margin-bottom: 6px; }
.ml-scale { display: flex; gap: 3px; }
.ml-scale span {
  width: 24px; height: 17px; border-radius: 5px; background: var(--c); color: #fff;
  font-size: 9.5px; font-weight: 600; display: grid; place-items: center;
}
.ml-note { font-size: 9.5px; color: var(--muted); margin-top: 6px; }
/* ฝน 24 ชม. — ช่วง/สีเดียวกับ RAIN_BANDS ใน app.js */
.ml-scale.ml-rain { gap: 4px; }
.ml-scale.ml-rain span {
  width: auto; min-width: 42px; padding: 0 6px;
  font-size: 9px; white-space: nowrap;
}
/* คำอธิบายสี/ขนาดจุดอ่างเก็บน้ำ = ความจุน้ำ */
.ml-sep { height: 1px; background: var(--line); margin: 9px 0 7px; }
.ml-scale.lg-dams { gap: 10px; }
.ml-scale.lg-dams span {
  width: auto; height: auto; background: none; color: var(--muted);
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 9px; font-weight: 500; letter-spacing: 0.01em;
}
.ml-scale.lg-dams span::before {
  content: ''; width: var(--s); height: var(--s); border-radius: 50%;
  background: var(--c); box-shadow: 0 0 0 1.5px var(--surface), 0 0 0 2.5px color-mix(in srgb, var(--c) 45%, transparent);
}

/* drawer */
.drawer {
  position: fixed; top: 64px; right: 0; bottom: 0; width: 400px; max-width: 92vw; z-index: 70;
  background: var(--surface); border-left: 1px solid var(--line); box-shadow: var(--shadow-lg);
  overflow-y: auto; padding: 20px 22px 40px; animation: slidein 0.24s ease;
}
.drawer[hidden] { display: none; }
@keyframes slidein { from { transform: translateX(24px); opacity: 0.6; } to { transform: none; opacity: 1; } }
.drawer-close {
  position: fixed; top: 76px; right: 12px; z-index: 71; width: 32px; height: 32px;
  border-radius: 9px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2);
  cursor: pointer; font-size: 13px;
}
.drawer-close.hidden { display: none; }
.dw-kicker { font-size: 11px; color: var(--brand); font-weight: 600; letter-spacing: 0.04em; }
.dw-title { margin: 4px 0 4px; font-size: 21px; font-weight: 600; letter-spacing: -0.02em; padding-right: 34px; }
.dw-sub { color: var(--muted); font-size: 12.5px; margin-bottom: 16px; }
.dw-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.dw-cell { background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 9px 11px; }
.dw-cell .k { font-size: 10.5px; color: var(--muted); }
.dw-cell .v { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.dw-cell .v small { font-size: 10px; font-weight: 400; color: var(--muted); margin-left: 2px; }
.dw-note { font-size: 11.5px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 12px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.badge.warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.badge.crit { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }

/* map labels (DOM markers) */
.ml {
  font-size: 10px; font-weight: 500; color: #0b4a66; white-space: nowrap; pointer-events: none;
  text-shadow: 0 0 3px #fff, 0 0 6px #fff, 0 1px 2px rgba(255, 255, 255, 0.9);
}
.ml.river { font-style: italic; color: #0f5c7a; }
.ml.river.major { font-weight: 600; color: #083f59; }
.ml.amphoe { font-size: 10.5px; color: #58788c; letter-spacing: 0.01em; }
.ml.province { font-size: 12px; font-weight: 600; color: #3c5d72; letter-spacing: 0.06em; }
.ml.dam { font-size: 10px; font-weight: 700; color: #3b0f8f; letter-spacing: 0.01em; }
.ml.station { font-size: 9.5px; color: #22607e; }
.ml.hide { opacity: 0; }
html[data-theme="dark"] .ml { text-shadow: 0 0 4px rgba(0, 0, 0, 0.9), 0 0 9px rgba(0, 0, 0, 0.8); color: #cfe8f3; }
html[data-theme="dark"] .ml.river { color: #a9dcef; }
html[data-theme="dark"] .ml.river.major { color: #c8ecff; }
html[data-theme="dark"] .ml.amphoe { color: #8fa9ba; }
html[data-theme="dark"] .ml.province { color: #b7cfdd; }
html[data-theme="dark"] .ml.dam { color: #ddd6fe; }
html[data-theme="dark"] .ml.station { color: #c3e4f4; }

/* ══════════════════════════════ pages ══════════════════════════════ */

/* หน้าพยากรณ์ = ฝังหน้าแรกของ v2 (หน้ารวมการ์ด) */
.view-frame { display: flex; flex-direction: column; height: calc(100dvh - 64px); }
.frame-bar {
  flex: 0 0 auto; background: var(--surface); border-bottom: 1px solid var(--line);
}
.fb-inner {
  max-width: 1360px; margin: 0 auto; padding: 9px 20px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.fb-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; }
.fb-title b { font-size: 13.5px; font-weight: 600; }
.fb-title span { font-size: 11.5px; color: var(--muted); }
.v2-frame { flex: 1 1 auto; width: 100%; border: 0; display: block; background: var(--bg-2); }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; }
.seg-btn { border: 0; background: transparent; color: var(--ink-2); font-size: 12.5px; padding: 6px 14px; border-radius: 999px; cursor: pointer; }
.seg-btn.active { background: var(--brand); color: #fff; font-weight: 500; }

.player { position: relative; border-radius: 12px; overflow: hidden; background: var(--bg-2); border: 1px solid var(--line); }
.player img { display: block; width: 100%; height: auto; }
.player-cap {
  position: absolute; left: 10px; bottom: 10px; display: flex; gap: 6px; align-items: center;
  background: rgba(8, 22, 33, 0.72); color: #fff; font-size: 11px; padding: 4px 9px; border-radius: 999px;
  backdrop-filter: blur(6px);
}
.player-pos { position: absolute; right: 10px; bottom: 10px; background: rgba(8, 22, 33, 0.72); color: #fff; font-size: 10.5px; padding: 3px 8px; border-radius: 999px; }
.range { width: 100%; accent-color: var(--brand); margin-top: 10px; }

table.tbl { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.tbl th {
  text-align: left; font-size: 10.5px; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--muted); font-weight: 500; padding: 7px 8px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.tbl td { padding: 8px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl td.num, table.tbl th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 10.5px; background: var(--bg-2); color: var(--ink-2); border: 1px solid var(--line-2); }

.dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 12.5px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; }

.sitefoot { border-top: 1px solid var(--line); background: var(--surface); margin-top: 8px; }
/* หน้าแผนที่ = แผนที่เต็มจอ ไม่มี scroll → ซ่อน footer (เครดิตแผนที่อยู่ในตัวแผนที่แล้ว) */
html[data-view="map"] .sitefoot { display: none; }
.sf-inner { display: flex; justify-content: space-between; gap: 20px; padding: 18px 20px; flex-wrap: wrap; }
.sf-brand { font-size: 12.5px; font-weight: 600; }
.sf-src { font-size: 11px; color: var(--muted); max-width: 80ch; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 16px); z-index: 90;
  background: var(--ink); color: var(--bg); font-size: 12.5px; padding: 9px 16px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: 0.22s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ══════════════════════════════ responsive ══════════════════════════════ */
@media (max-width: 1340px) {
  .mainnav a { padding: 8px 9px; font-size: 12.5px; }
  /* เดิมซ่อนทั้ง pill (นาฬิกา) · Round 2: เก็บ pill ไว้แต่เหลือเฉพาะ "ความสดของข้อมูล"
     เพราะตัวบอกความสดต้องเห็นได้บนจอโน้ตบุ๊ก 1280–1340px ด้วย
     (วัดจริงที่ 1340/1280/1200/1100/1024/960px แล้วไม่ทับเมนู) */
  .tb-live { display: flex; }
  .tb-live #tb-time,
  .tb-live .tb-sep { display: none; }
}
@media (max-width: 1180px) {
  .card { grid-column: span 6; }
  .card.w6, .card.w8, .card.w3 { grid-column: span 6; }
}
@media (max-width: 920px) {
  body { padding-top: 109px; }
  .tb-inner {
    height: 106px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: 62px 44px;
    align-items: center;
    gap: 0 10px;
    padding: 0 12px;
  }
  .brand { grid-column: 1; grid-row: 1; }
  .tb-actions { grid-column: 2; grid-row: 1; }
  .mainnav {
    grid-column: 1 / -1; grid-row: 2;
    position: static; top: auto; left: auto; right: auto;
    display: flex; flex-direction: row; align-items: center;
    width: 100%; height: 44px; min-width: 0;
    padding: 0 0 6px; gap: 2px;
    background: transparent; border-bottom: 0; box-shadow: none;
    overflow-x: auto; overflow-y: hidden;
  }
  .mainnav a {
    display: inline-flex; align-items: center;
    min-height: 38px; padding: 8px 11px; border-radius: 999px;
    font-size: 13px;
  }
  .tb-live { display: none; }
  .map-stage, .view-frame { height: calc(100dvh - 109px); }
  .map-stage { min-height: 380px; }
  .wrap { padding: 16px 14px 32px; }
  .card, .card.w6, .card.w8, .card.w3, .card.w12 { grid-column: span 12; }
  .fb-title span { display: none; }
  .fb-inner { padding: 8px 14px; }
  .map-panel {
    left: 10px; right: 10px; top: auto; bottom: 10px; width: auto;
    max-height: 46vh; border-radius: 16px;
    display: none;
  }
  .map-panel.open { display: flex; }
  .map-tools { top: 10px; right: 10px; flex-direction: column; align-items: flex-end; gap: 6px; }
  .panel-toggle { display: grid; }
  /* Mobile legend is an icon until opened; the full panel is the same
     MAP-002 layout, with a collapse control inside its top-right corner. */
  .legend-toggle {
    display: grid; position: absolute; top: 10px; left: 10px; z-index: 5;
  }
  .legend-toggle[aria-expanded="true"] { display: none; }
  .map-legend {
    display: none; left: 10px; top: 10px; bottom: auto;
    padding: 8px 9px; max-width: 210px;
  }
  .map-legend.open { display: block; }
  .legend-close {
    display: none; position: absolute; top: 5px; right: 5px; z-index: 1;
    width: 26px; height: 26px; border-radius: 8px; border: 1px solid var(--line);
    background: var(--surface); color: var(--ink-2); font-size: 11px; line-height: 1;
    cursor: pointer; place-items: center;
  }
  .map-legend.open .legend-close { display: grid; }
  .legend-close:hover { color: var(--ink); border-color: var(--brand); }
  .map-legend > .ml-title:first-of-type { padding-right: 28px; }
  .ml-title { font-size: 9.5px; margin-bottom: 4px; }
  .ml-scale { gap: 2px; flex-wrap: wrap; }
  .ml-scale span { width: 20px; height: 14px; font-size: 8.5px; border-radius: 4px; }
  .ml-scale.ml-rain { max-width: 192px; gap: 3px; }
  .ml-scale.ml-rain span { min-width: 34px; padding: 0 4px; font-size: 8px; }
  .ml-note { font-size: 8.5px; margin-top: 4px; line-height: 1.4; }
  .ml-sep { margin: 6px 0 5px; }
  .ml-scale.lg-dams { gap: 6px; }
  .ml-scale.lg-dams span { font-size: 8px; }
  .drawer { width: 100%; top: auto; height: 72vh; border-left: 0; border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; z-index: 70; }
  .drawer-close { top: auto; bottom: calc(72vh - 12px); right: 12px; }
  .ml.station, .ml.dam, .ml.river { display: none; }
}
@media (max-width: 560px) {
  .card { padding: 14px; }
  .map-panel { max-height: 42vh; }
  .mp-item { padding: 9px 4px; }
}
/* 360px: the data tables are the only remaining source of page-level horizontal
   overflow. Keep them inside the card (no wide table stretching the document). */
@media (max-width: 380px) {
  /* 360px: tighten only the nav rhythm so all five Thai labels fit without
     shrinking the 13px type or turning the row into a scroll-only menu. */
  .mainnav { gap: 1px; }
  .mainnav a { padding-left: 9px; padding-right: 9px; }
  table.tbl { table-layout: fixed; width: 100%; }
  table.tbl th, table.tbl td { overflow-wrap: anywhere; word-break: break-word; }
  table.tbl td.num, table.tbl th.num { white-space: normal; }
}

/* ══════════════ หน้า "ข้อมูล" — รวมเนื้อหาจาก v2 #data ══════════════ */
.list-note { margin: 0; padding-left: 18px; font-size: 12.5px; color: var(--ink-2); line-height: 1.75; }
.list-note li { margin-bottom: 5px; }
.list-note b { color: var(--ink); font-weight: 600; }
.card code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 11.5px;
  background: var(--bg-2); border: 1px solid var(--line-2); padding: 0 4px; border-radius: 5px;
}
.nwp-line { margin: 0 0 8px; font-size: 12.5px; line-height: 1.7; color: var(--ink-2); }
.nwp-line:last-child { margin-bottom: 0; }
.nwp-line.muted { color: var(--muted); font-size: 12px; }
.nwp-todo { border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; background: var(--surface-2); font-size: 12.5px; color: var(--ink-2); }
.nwp-todo b { color: var(--ink); }
.sb-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.sb-ok { background: var(--ok); }
.sb-bad { background: var(--danger); }
.list-note.cols2 { columns: 2; column-gap: 28px; }
.list-note.cols2 li { break-inside: avoid; -webkit-column-break-inside: avoid; }
@media (max-width: 920px) { .list-note.cols2 { columns: 1; } }
/* คอลัมน์ขวาแบบซ้อนการ์ด (สรุปชุดข้อมูล + ข้อจำกัด) ให้สูงใกล้ตารางแหล่งข้อมูล */
.stack { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; align-content: start; }
.stack.w4 { grid-column: span 4; }
.stack > .card { grid-column: auto; min-width: 0; }
@media (max-width: 1180px) { .stack.w4 { grid-column: span 6; } }
@media (max-width: 920px) { .stack.w4 { grid-column: span 12; } }
