/* Thai Hydro Watch. Copyright (c) 2026 Nguyen Xuan TINH (Ph.D.), Nippon Koei Co., Ltd. All rights reserved.
   Layout: a gauge-network console. Data bar (AOI, period, fetch) and a
   sticky view bar on top; map beside the selected station's hydrographs; every station x
   time below; the station list last. */
:root {
  --bg: #f2f5f5;
  --surface: #fcfdfd;
  --fg: #0e1517;
  --fg-2: #45545a;
  --muted: #74838a;
  --grid: #e1e7e8;
  --axis: #bfc9cc;
  --line: rgba(14, 21, 23, 0.10);
  --gap: rgba(14, 21, 23, 0.055);
  --accent: #17506b;
  --accent-ink: #fcfdfd;
  --accent-wash: rgba(23, 80, 107, 0.08);
  --sea: #e3ecef;
  --land: #fbfcfc;
  --land-2: #edf0f0;
  --border-country: #c3ced2;
  --river: #8eb2c6;
  --cat1: #2a78d6;
  --cat2: #eb6834;
  --cat3: #1baf7a;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --seq1: #cde2fb;
  --seq2: #9ec5f4;
  --seq3: #6da7ec;
  --seq4: #3987e5;
  --seq5: #256abf;
  --seq6: #104281;
  --font-sans: "IBM Plex Sans", "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", "Leelawadee UI", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0c1011; --surface: #171c1d; --fg: #eef3f3; --fg-2: #b4c0c3; --muted: #84928f;
    --grid: #252d2f; --axis: #3b4649; --line: rgba(238, 243, 243, 0.10); --gap: rgba(238, 243, 243, 0.06);
    --accent: #7fbfdc; --accent-ink: #0c1011; --accent-wash: rgba(127, 191, 220, 0.10);
    --sea: #0f1517; --land: #1d2425; --land-2: #161b1c; --border-country: #36424a; --river: #37596b;
    --cat1: #3987e5; --cat2: #d95926; --cat3: #199e70;
    --seq1: #104281; --seq2: #1c5cab; --seq3: #2a78d6; --seq4: #5598e7; --seq5: #86b6ef; --seq6: #cde2fb;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0c1011; --surface: #171c1d; --fg: #eef3f3; --fg-2: #b4c0c3; --muted: #84928f;
  --grid: #252d2f; --axis: #3b4649; --line: rgba(238, 243, 243, 0.10); --gap: rgba(238, 243, 243, 0.06);
  --accent: #7fbfdc; --accent-ink: #0c1011; --accent-wash: rgba(127, 191, 220, 0.10);
  --sea: #0f1517; --land: #1d2425; --land-2: #161b1c; --border-country: #36424a; --river: #37596b;
  --cat1: #3987e5; --cat2: #d95926; --cat3: #199e70;
  --seq1: #104281; --seq2: #1c5cab; --seq3: #2a78d6; --seq4: #5598e7; --seq5: #86b6ef; --seq6: #cde2fb;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.45 var(--font-sans);
  padding-inline: clamp(16px, 3vw, 32px);
  padding-block: 20px 48px;
}
.wrap { max-width: 1440px; margin: 0 auto; display: grid; gap: 16px; }
h1, h2, h3 { margin: 0; text-wrap: balance; font-weight: 600; }
h1 { font-size: 1.6rem; letter-spacing: -0.01em; line-height: 1.2; }
h2 { font-size: 1.15rem; line-height: 1.3; }
h3 { font-size: 0.82rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--fg-2); }
p { margin: 0; }
a { color: var(--accent); }
.sub { color: var(--fg-2); max-width: 90ch; margin-top: 4px; }
.mono { font-family: var(--font-mono); font-size: 0.93em; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Header and the about panel */
.top { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px 24px; }
.top-text { min-width: 0; flex: 1 1 420px; }
.about { position: relative; flex: none; }
.about summary { list-style: none; }
.about summary::-webkit-details-marker { display: none; }
.about[open] summary { background: var(--accent-wash); }
.about-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40; width: min(380px, calc(100vw - 32px));
  background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14); display: grid; gap: 8px; font-size: 13px;
}
.about-title { font-weight: 600; font-size: 14px; }
.about-panel address { font-style: normal; line-height: 1.6; color: var(--fg-2); }
.about-panel address b { color: var(--fg); font-weight: 600; }
.copyright { color: var(--muted); border-top: 1px solid var(--grid); padding-top: 8px; margin-top: 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer; white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg); border-radius: 8px;
  padding: 6px 12px; font-size: 13px;
}
.btn:hover { background: var(--accent-wash); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 500; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.small { padding: 3px 9px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn svg { width: 14px; height: 14px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* View bar */
.filters {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 18px;
  padding-block: 10px; background: var(--bg);
}
.group { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.group > .lbl { font-size: 12px; color: var(--muted); letter-spacing: 0.03em; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.seg button {
  border: 0; background: transparent; color: var(--fg-2); cursor: pointer;
  padding: 5px 10px; border-radius: 6px; font-size: 13px; display: inline-flex; align-items: center; gap: 6px;
}
.seg button:hover { background: var(--accent-wash); color: var(--fg); }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.seg .count { font-variant-numeric: tabular-nums; opacity: 0.75; font-size: 12px; }
.seg svg { width: 12px; height: 12px; }
.search { flex: 1 1 200px; max-width: 320px; }
.search input {
  width: 100%; font-size: 13px; color: var(--fg); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}
.spacer { flex: 1 1 auto; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; min-width: 0; }
.card-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; margin-bottom: 10px; }
.note { color: var(--muted); font-size: 12.5px; max-width: 90ch; }
.main { display: grid; gap: 16px; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); }
@media (max-width: 980px) { .main { grid-template-columns: minmax(0, 1fr); } }

/* Status chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  font-size: 12px; padding: 1px 8px 1px 6px; border-radius: 999px; border: 1px solid var(--line); color: var(--fg);
  background: var(--surface);
}
.chip svg { width: 12px; height: 12px; flex: none; }
.i-ok { fill: var(--good); }
.i-gaps { fill: var(--warning); }
.i-gaps-ring { fill: none; stroke: var(--warning); stroke-width: 2; }
.i-sparse-ring { fill: none; stroke: var(--serious); stroke-width: 2; stroke-dasharray: 2.2 1.6; }
.i-check { fill: var(--critical); }
.i-pending { fill: none; stroke: var(--axis); stroke-width: 2; }
.i-mark { fill: none; stroke: var(--surface); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }

/* Legend */
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--fg-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.key.hollow { background: transparent !important; border: 1.5px solid var(--cat3); }
.key.small { width: 7px; height: 7px; }
.bg-w { background: var(--cat1); } .bg-q { background: var(--cat2); } .bg-r { background: var(--cat3); }
.bg-ok { background: var(--good); } .bg-gaps { background: var(--warning); }
.bg-sparse { background: var(--serious); } .bg-check { background: var(--critical); }
.bg-dim, .bg-pending { background: var(--axis); }

/* Map */
.map-box { position: relative; height: clamp(420px, 74vh, 780px); border-radius: 8px; overflow: hidden; background: var(--sea); touch-action: none; }
#map { width: 100%; height: 100%; display: block; cursor: grab; user-select: none; }
#map.dragging { cursor: grabbing; }
.neigh { fill: var(--land-2); stroke: var(--border-country); stroke-width: 0.8; vector-effect: non-scaling-stroke; }
.thai { fill: var(--land); stroke: var(--border-country); stroke-width: 1; vector-effect: non-scaling-stroke; }
.aoi { fill: var(--accent); fill-opacity: 0.07; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; fill-rule: evenodd; }
.river { fill: none; stroke: var(--river); stroke-width: 1.3; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.place { fill: var(--fg-2); font-weight: 500; paint-order: stroke; stroke: var(--land); stroke-linejoin: round; }
.place-dot { fill: var(--fg-2); }
.river-label { fill: var(--river); font-style: italic; paint-order: stroke; stroke: var(--land); }
.pt { stroke: var(--surface); stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.pt.t-w { fill: var(--cat1); } .pt.t-q { fill: var(--cat2); } .pt.t-r { fill: var(--cat3); }
.pt.hollow { fill: var(--surface); stroke: var(--cat3); stroke-width: 1.2; }
.pt.s-ok { fill: var(--good); } .pt.s-gaps { fill: var(--warning); }
.pt.s-sparse { fill: var(--serious); } .pt.s-check { fill: var(--critical); }
.pt.s-pending, .pt.dim { fill: var(--axis); }
.pt.dim { opacity: 0.55; }
.pt.faded { opacity: 0.12; }
#sel-ring { fill: none; stroke: var(--fg); stroke-width: 2; vector-effect: non-scaling-stroke; pointer-events: none; }
.zoom { position: absolute; top: 10px; right: 10px; display: grid; gap: 4px; }
.zoom button {
  width: 30px; height: 30px; border-radius: 6px; border: 1px solid var(--line); background: var(--surface);
  cursor: pointer; font-size: 16px; line-height: 1; color: var(--fg-2);
}
.zoom button:hover { color: var(--fg); background: var(--accent-wash); }
.map-hint { position: absolute; left: 10px; bottom: 8px; font-size: 11.5px; color: var(--muted); }

/* Tooltip */
.tip {
  position: absolute; z-index: 30; pointer-events: none; max-width: 280px;
  background: var(--surface); color: var(--fg); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; line-height: 1.4; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}
.tip b { font-weight: 600; }
.tip .t-sub { color: var(--fg-2); }
.tip .t-row { display: flex; gap: 8px; align-items: center; margin-top: 3px; flex-wrap: wrap; }

/* Station detail */
.detail { display: grid; gap: 14px; align-content: start; }
.eyebrow { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--fg-2); letter-spacing: 0.03em; }
.detail h2 .mono { margin-right: 6px; }
.meta { color: var(--fg-2); font-size: 13px; margin-top: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chart-block { display: grid; gap: 6px; }
.chart-title { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; }
.chart-title .unit { color: var(--muted); font-size: 12.5px; text-transform: none; letter-spacing: 0; font-weight: 400; }
.chart-title .tools { display: inline-flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart:focus-visible { outline-offset: 4px; border-radius: 4px; }
.c-grid { stroke: var(--grid); stroke-width: 1; }
.c-base { stroke: var(--axis); stroke-width: 1; }
.c-tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.c-gap { fill: var(--gap); }
.c-line { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.c-line.t-w { stroke: var(--cat1); } .c-line.t-q { stroke: var(--cat2); }
.c-bar.t-r { fill: var(--cat3); }
.c-dot { stroke: var(--surface); stroke-width: 2; }
.c-dot.t-w { fill: var(--cat1); } .c-dot.t-q { fill: var(--cat2); } .c-dot.t-r { fill: var(--cat3); }
.c-spike { fill: var(--critical); stroke: var(--surface); stroke-width: 2; }
.c-label { fill: var(--fg-2); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.c-cross { stroke: var(--axis); stroke-width: 1; }
.empty { color: var(--muted); font-size: 13px; padding: 24px 0; }
.mini-legend { display: inline-flex; gap: 12px; font-size: 12px; color: var(--fg-2); align-items: center; flex-wrap: wrap; }
.mini-legend span { display: inline-flex; align-items: center; gap: 5px; }
.swatch-gap { width: 14px; height: 10px; background: var(--gap); border: 1px solid var(--line); display: inline-block; }

/* Heatmap */
.heat-scroll { position: relative; max-height: 600px; overflow-y: auto; overflow-x: hidden; border-top: 1px solid var(--grid); }
.heat-axis { position: sticky; top: 0; z-index: 2; height: 22px; background: var(--surface); border-bottom: 1px solid var(--grid); }
.heat-axis span { position: absolute; top: 4px; font-size: 11px; color: var(--muted); transform: translateX(-50%); white-space: nowrap; font-variant-numeric: tabular-nums; }
.heat-axis span.first { transform: none; }
.heat-axis span::before { content: ""; position: absolute; left: 50%; top: 15px; height: 4px; border-left: 1px solid var(--axis); }
.heat-axis span.first::before { left: 0; }
#heat { display: block; cursor: crosshair; }
.ramp { display: inline-block; width: 120px; height: 10px; border-radius: 2px; border: 1px solid var(--line); background: linear-gradient(90deg, var(--seq1), var(--seq2), var(--seq3), var(--seq4), var(--seq5), var(--seq6)); }
.sq { width: 12px; height: 10px; display: inline-block; border: 1px solid var(--line); }
.sq.blank { background: var(--surface); }

/* Table */
.table-scroll { position: relative; max-height: 560px; overflow: auto; border-top: 1px solid var(--grid); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  position: sticky; top: 0; z-index: 1; background: var(--surface); text-align: left; font-weight: 500;
  color: var(--fg-2); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--axis); white-space: nowrap;
}
th.num { text-align: right; }
td { padding: 6px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
td.name { min-width: 180px; }
td.notes { color: var(--fg-2); min-width: 160px; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--accent-wash); }
tbody tr[aria-selected="true"] { background: var(--accent-wash); box-shadow: inset 3px 0 0 var(--accent); }

footer { color: var(--fg-2); font-size: 12.5px; display: grid; gap: 6px; max-width: 110ch; }
footer code { font-family: var(--font-mono); font-size: 0.95em; }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
