:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --text: #17212b;
  --muted: #5d6b7a;
  --border: #dfe4ea;
  --accent: #0b6fbf;
  --accent-soft: #e3f0fb;
  --fc: #e8590c;
  --shadow: 0 2px 10px rgba(16, 32, 48, .08);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e141b; --surface: #16202a; --surface-2: #1b2733; --text: #e6edf3; --muted: #93a3b3;
    --border: #2a3846; --accent: #4aa3f0; --accent-soft: #15324c; --fc: #ff8a4c;
    --shadow: 0 2px 12px rgba(0, 0, 0, .4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e141b; --surface: #16202a; --surface-2: #1b2733; --text: #e6edf3; --muted: #93a3b3;
  --border: #2a3846; --accent: #4aa3f0; --accent-soft: #15324c; --fc: #ff8a4c;
  --shadow: 0 2px 12px rgba(0, 0, 0, .4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 "IBM Plex Sans Thai", system-ui, sans-serif;
  display: flex; flex-direction: column;
}
button { font: inherit; color: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.block { display: block; margin: 8px 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.logo { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px; background: var(--accent); color: #fff; font-size: 20px; }
.brand h1 { font-size: 16px; margin: 0; line-height: 1.2; }
.brand .sub { margin: 0; font-size: 12px; color: var(--muted); }
.top-actions { display: flex; align-items: center; gap: 8px; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface-2); }
.seg button { border: 0; background: transparent; padding: 5px 12px; font-weight: 500; }
.seg button.on { background: var(--accent); color: #fff; }
.seg.small button { padding: 2px 8px; font-size: 12px; }
.icon-btn { border: 1px solid var(--border); background: var(--surface-2); border-radius: 8px; width: 32px; height: 32px; }
.btn { border: 0; background: var(--accent); color: #fff; border-radius: 8px; padding: 6px 14px; font-weight: 500; }

.layout { flex: 1; display: grid; grid-template-columns: 1fr 420px; min-height: 0; }
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; }
.card-title { font-weight: 600; margin-bottom: 6px; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }

.layer-box { position: absolute; top: 12px; left: 12px; font-size: 13px; padding: 10px 12px; max-width: 230px; }
.layer-box label { display: flex; gap: 6px; align-items: center; margin: 2px 0; cursor: pointer; }
.lb-title { font-weight: 600; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.legend { position: absolute; left: 12px; bottom: 140px; padding: 8px 10px; font-size: 11px; }
.ramp { display: flex; height: 10px; border-radius: 4px; overflow: hidden; width: 170px; }
.ramp span { flex: 1; }
.ramp-l { display: flex; justify-content: space-around; width: 170px; color: var(--muted); }

.timeline { position: absolute; left: 12px; right: 12px; bottom: 28px; padding: 10px 14px; }
.tl-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.tl-label { font-size: 14px; }
.tl-area { margin-left: auto; font-size: 13px; color: var(--muted); }
#tlSlider, #scSlider { width: 100%; margin: 8px 0 0; accent-color: var(--fc); }
.tl-ticks { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }

.loader { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 8px 14px; font-size: 13px; z-index: 5; }
.loader.hide { display: none; }
.spin { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: sp 1s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.probe { position: absolute; top: 12px; right: 12px; font-size: 13px; padding: 8px 12px; max-width: 260px; }

.panel { border-left: 1px solid var(--border); background: var(--bg); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; overflow-x: auto; background: var(--surface); border-bottom: 1px solid var(--border); }
.tabs button { flex: 1; border: 0; background: none; padding: 10px 8px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.tab-body { overflow-y: auto; padding: 12px; flex: 1; }
.tab-body > section { display: none; flex-direction: column; gap: 12px; }
.tab-body > section.on { display: flex; }

.hero-top { display: flex; justify-content: space-between; align-items: flex-start; }
.big { font-size: 40px; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; }
.big small { font-size: 16px; font-weight: 500; color: var(--muted); }
.mid { font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.badge { padding: 4px 10px; border-radius: 999px; color: #fff; font-weight: 600; font-size: 13px; background: var(--muted); white-space: nowrap; }
.gauge { margin-top: 10px; position: relative; height: 34px; }
.gauge .bar { position: absolute; left: 0; right: 0; top: 6px; height: 10px; border-radius: 5px; display: flex; overflow: hidden; }
.gauge .bar span { height: 100%; }
.gauge .mark { position: absolute; top: 0; width: 3px; height: 22px; background: var(--text); border-radius: 2px; transform: translateX(-1px); }
.gauge .mark.fc { background: var(--fc); }
.gauge .lbl { position: absolute; top: 20px; font-size: 10px; color: var(--muted); transform: translateX(-50%); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stat { padding: 10px 12px; }
.note { background: var(--accent-soft); border-color: transparent; box-shadow: none; font-size: 13px; }
.note.warn { background: #fdecea; color: #7a1a12; }
:root[data-theme="dark"] .note.warn { background: #3d1714; color: #ffd2cc; }

.chart-box { position: relative; height: 260px; }
.chart-box.sm { height: 170px; }

.input { width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); font: inherit; margin-bottom: 8px; }
.list { display: flex; flex-direction: column; }
.st-row { display: grid; grid-template-columns: 10px 1fr auto; gap: 8px; align-items: center; padding: 7px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.st-row:hover { background: var(--surface-2); }
.dot { width: 10px; height: 10px; border-radius: 50%; }
.st-row .r { text-align: right; font-variant-numeric: tabular-nums; }

.dam-card h3 { margin: 0 0 4px; font-size: 15px; }
.pbar { height: 12px; background: var(--surface-2); border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.pbar > span { display: block; height: 100%; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; font-size: 13px; margin-top: 8px; }
.kv span:nth-child(even) { text-align: right; font-variant-numeric: tabular-nums; font-weight: 500; }

.wx-now { display: flex; gap: 14px; align-items: center; }
.wx-now .ico { font-size: 44px; }
.wx-daily { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; font-size: 12px; }
.wx-daily .d { background: var(--surface-2); border-radius: 8px; padding: 6px 2px; }
.wx-daily .ico { font-size: 20px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 4px 6px; border-bottom: 1px solid var(--border); text-align: right; }
.tbl th:first-child, .tbl td:first-child { text-align: left; }
input[type=range] { accent-color: var(--accent); width: 100%; }

.maplibregl-popup-content { background: var(--surface); color: var(--text); border-radius: 10px; font: 13px/1.45 "IBM Plex Sans Thai", sans-serif; box-shadow: var(--shadow); }
.maplibregl-popup-tip { border-top-color: var(--surface) !important; border-bottom-color: var(--surface) !important; }
.pop h4 { margin: 0 0 4px; font-size: 14px; }

@media (max-width: 900px) {
  body { height: auto; }
  .layout { grid-template-columns: 1fr; }
  .map-wrap { height: 70vh; }
  .panel { border-left: 0; }
  .layer-box { font-size: 12px; max-width: 180px; padding: 8px; }
  .legend { display: none; }
  .timeline { left: 8px; right: 8px; bottom: 24px; padding: 8px 10px; }
  .tl-area { margin-left: 0; width: 100%; }
  .brand .sub, #updated { display: none; }
}
