:root {
  --surface-0: #f6f7f8;
  --surface-1: #ffffff;
  --border: #e3e5e8;
  --text-primary: #191919;
  --text-secondary: #666666;
  --grid: #ececec;
  --series-1: #257de0;      /* discharge / arsenic line */
  --series-7: #6a4ce2;      /* weather */
  --river-line: #6aabf1;
  --dam: #4a4a4a;
  --level: #0f8b8d;          /* water-level gauge */
  --st-ok: #0aac23;
  --st-watch: #fbb315;
  --st-over: #dc3c3d;
  --st-none: #9c9c9c;
  --accent: #1b64be;
  font-family: "Sarabun", "Noto Sans Thai", "Leelawadee UI", "Tahoma", system-ui, sans-serif;
  color: var(--text-primary);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--surface-0); height: 100vh; display: flex; flex-direction: column; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface-1); border-bottom: 1px solid var(--border); }
.brand strong { font-size: 18px; margin-right: 10px; }
.brand span { color: var(--text-secondary); font-size: 14px; }
.sync { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--text-secondary); }
button { font: inherit; cursor: pointer; border-radius: 6px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; padding: 6px 12px; }
button:disabled { opacity: .6; cursor: wait; }
button.ghost { background: transparent; color: var(--accent); }

.banner { background: #fff6dd; border-bottom: 1px solid #f2d27a; padding: 6px 16px; font-size: 13px; }

.layout { flex: 1; display: flex; min-height: 0; }
.side { width: 300px; overflow-y: auto; padding: 12px; border-right: 1px solid var(--border); background: var(--surface-1); }
.map-wrap { flex: 1; position: relative; }
#map { position: absolute; inset: 0; }
.detail { width: 400px; overflow-y: auto; padding: 14px 16px; border-left: 1px solid var(--border);
  background: var(--surface-1); position: relative; }
.close { position: absolute; right: 8px; top: 6px; background: none; border: none; color: var(--text-secondary);
  font-size: 22px; padding: 2px 8px; }

.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.kpi { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.kpi-label { font-size: 12px; color: var(--text-secondary); line-height: 1.3; }
.kpi-value { font-size: 28px; font-weight: 600; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; color: var(--text-secondary); }

.box { border-top: 1px solid var(--border); padding: 10px 0; }
.box h2 { font-size: 13px; margin: 4px 0 8px; color: var(--text-secondary); font-weight: 600; }
.box label { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 3px 0; cursor: pointer; }
.legend { list-style: none; margin: 0 0 8px; padding: 0; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 8px; padding: 2px 0; }

.dot, .sq, .sym { display: inline-block; width: 12px; height: 12px; flex: none; }
.dot { border-radius: 50%; }
.sq { border-radius: 3px; }
.st-ok { background: var(--st-ok); } .st-watch { background: var(--st-watch); }
.st-over { background: var(--st-over); } .st-none { background: var(--st-none); }
.sym-arsenic { border-radius: 50%; background: var(--st-over); }
.sym-intake { border-radius: 3px; background: var(--st-none); }
.sym-river { background: var(--series-1); transform: rotate(45deg) scale(.8); }
.sym-level { width: 7px; height: 14px; border-radius: 2px; background: var(--level); }
.sym-weather { border-radius: 50%; border: 3px solid var(--series-7); }
.sym-line { height: 3px; background: var(--river-line); }
.sym-dam { width: 16px; height: 6px; border-radius: 2px; background: var(--dam); }

.ann, .src { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.ann li { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.ann .meta, .src .meta { color: var(--text-secondary); font-size: 12px; }
.ann a, .src a { color: var(--accent); text-decoration: none; }
.src li { padding: 4px 0; }
.dams { list-style: none; margin: 0; padding: 0; font-size: 13px; }
.dams li { padding: 4px 0; display: flex; gap: 8px; align-items: baseline; }
.dams button.link { background: none; border: none; color: var(--accent); padding: 0; text-align: left; font-size: 13px; }
.dams .meta { color: var(--text-secondary); font-size: 12px; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 10px; border: 1px solid var(--border);
  color: var(--text-secondary); margin-left: 4px; white-space: nowrap; }
.tag.sample { border-color: #f2d27a; background: #fff6dd; color: #7a5a00; }

/* map markers */
.mk { cursor: pointer; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.25); }
.mk-arsenic { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-size: 11px; font-weight: 700; line-height: 1; }
.mk-intake { width: 22px; height: 22px; border-radius: 5px; display: grid; place-items: center;
  color: #fff; font-size: 12px; font-weight: 700; }
.mk-river { width: 14px; height: 14px; background: var(--series-1); transform: rotate(45deg); }
.mk-level { width: 9px; height: 18px; border-radius: 2px; background: var(--level); }
.mk-weather { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 3px solid var(--series-7); }
.mk-dam { width: 16px; height: 7px; border-radius: 2px; background: var(--dam); }
.mk-dam.major { width: 26px; height: 10px; }
.mk-dam.planned { background: #fff; border: 2px dashed var(--dam); box-shadow: none; }
.mk.approx { outline: 1px dashed rgba(0,0,0,.45); outline-offset: 2px; }
.mk.selected { box-shadow: 0 0 0 3px var(--text-primary); }

/* detail */
.detail h3 { margin: 0 28px 2px 0; font-size: 17px; }
.detail .sub { color: var(--text-secondary); font-size: 13px; margin-bottom: 10px; }
.badge { display: inline-flex; gap: 6px; align-items: center; font-size: 13px; font-weight: 600;
  padding: 2px 10px; border-radius: 12px; color: var(--text-primary); border: 1px solid var(--border); }
.badge::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--st-none)); }
.big { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; }
.big small { font-size: 14px; color: var(--text-secondary); font-weight: 400; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 13px; margin: 10px 0; }
.kv dt { color: var(--text-secondary); }
.kv dd { margin: 0; }
.section-title { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 16px 0 6px; }
.note { font-size: 12px; color: var(--text-secondary); }

.form { display: grid; gap: 8px; margin-top: 6px; }
.form .opts { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.form .opts label { border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; font-size: 14px;
  display: flex; gap: 6px; align-items: center; cursor: pointer; }
.form .opts input:checked + .sq + span { font-weight: 600; }
.form input[type=text], .form textarea { font: inherit; font-size: 14px; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 6px; width: 100%; }
.form .msg { font-size: 13px; }
.hist { list-style: none; padding: 0; margin: 0; font-size: 13px; }
.hist li { padding: 4px 0; border-bottom: 1px dashed var(--border); display: flex; gap: 8px; align-items: baseline; }

/* chart */
.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .axis text { font-size: 11px; fill: var(--text-secondary); }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: #c9c9c9; stroke-width: 1; }
.chart .thresh { stroke: var(--st-over); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart .thresh.ref { stroke: var(--text-secondary); stroke-width: 1; }
.chart-legend i.ref { border-top: 1px dashed var(--text-secondary); }
.chart .thresh-label { font-size: 11px; fill: var(--text-primary); }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .line.fc { stroke-dasharray: 4 4; }
.chart .pt { fill: var(--series-1); stroke: var(--surface-1); stroke-width: 2; }
.chart .pt.hollow { fill: var(--surface-1); stroke: var(--series-1); stroke-width: 1.5; }
.chart .direct-label { font-size: 11px; font-weight: 600; }
.chart-legend .hollow-key { display: inline-block; width: 8px; height: 8px; border-radius: 50%; border: 1.5px solid var(--series-1);
  vertical-align: middle; margin-right: 4px; }
.chart-legend i.bar-key { width: 10px; height: 10px; border: none; background: var(--series-7); border-radius: 2px; }
.tooltip .tip-date { color: var(--text-secondary); }
.chart .bar { fill: var(--series-7); }
.chart .cross { stroke: var(--text-secondary); stroke-width: 1; }
.chart .now-label { font-size: 11px; fill: var(--text-secondary); }
.chart-legend { font-size: 12px; color: var(--text-secondary); display: flex; gap: 14px; flex-wrap: wrap; margin-top: 4px; }
.chart-legend i { display: inline-block; width: 18px; height: 0; border-top: 2px solid var(--series-1); vertical-align: middle; margin-right: 4px; }
.chart-legend i.dash { border-top-style: dashed; }
.chart-legend i.red { border-top: 2px dashed var(--st-over); }
.table-toggle { font-size: 12px; padding: 2px 8px; margin-top: 6px; }
table.data { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 6px; }
table.data th, table.data td { text-align: left; padding: 3px 6px; border-bottom: 1px solid var(--border); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { max-height: 220px; overflow-y: auto; }

.tooltip { position: fixed; z-index: 10; pointer-events: none; background: var(--surface-1); border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,.12); border-radius: 6px; padding: 6px 8px; font-size: 12px; max-width: 260px; }
.tooltip b { font-variant-numeric: tabular-nums; }

/* all-data panel */
.detail.wide { width: 560px; }
.range { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 8px; }
.range button { font-size: 12px; padding: 3px 9px; }
.range button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.group-title { font-size: 13px; margin: 14px 0 4px; padding-top: 8px; border-top: 1px solid var(--border); }
.sm { margin-bottom: 10px; }
.sm-title { font-size: 13px; font-weight: 600; }
.sm .table-toggle { margin-top: 2px; }
.empty { padding: 10px 0; }
.compare-open { margin-top: 8px; }
.wide-btn { width: 100%; margin-bottom: 10px; }
.sim-link { display: block; text-align: center; padding: 8px; border: 1px solid var(--border); border-radius: 6px; color: var(--text-primary); text-decoration: none; background: var(--surface-1); font-size: 13px; }

/* comparison overlay */
.compare { position: absolute; inset: 12px; z-index: 5; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 6px 24px rgba(0,0,0,.18); padding: 14px 16px; overflow-y: auto; }
.compare h3 { margin: 0 28px 8px 0; font-size: 17px; }
.cmp-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.cmp-controls select { font: inherit; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; }
.cmp-grid { display: grid; grid-template-columns: 240px 1fr; gap: 16px; margin-top: 8px; }
.cmp-sites { max-height: 420px; overflow-y: auto; font-size: 13px; }
.cmp-sites label { display: flex; gap: 6px; align-items: baseline; padding: 2px 0; cursor: pointer; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .side { width: 100%; max-height: 40vh; }
  .map-wrap { min-height: 50vh; }
  .detail, .detail.wide { width: 100%; }
  .cmp-grid { grid-template-columns: 1fr; }
}
