/* Visual language follows HyperUI application components (Tailwind defaults):
   gray-50…900 neutrals, thin gray-200 borders, rounded-lg, soft tinted badges, blue-600 accent. */
:root {
  --gray-50: #f9fafb; --gray-100: #f3f4f6; --gray-200: #e5e7eb; --gray-300: #d1d5db;
  --gray-400: #9ca3af; --gray-500: #6b7280; --gray-600: #4b5563; --gray-700: #374151; --gray-900: #111827;
  --blue-50: #eff6ff; --blue-100: #dbeafe; --blue-600: #2563eb; --blue-700: #1d4ed8;

  --ink: var(--gray-900);
  --muted: var(--gray-500);
  --line: var(--gray-200);
  --bg: var(--gray-50);
  --card: #ffffff;
  --accent: var(--blue-600);

  /* situation levels (map + dots) */
  --lvl0: #60a5fa; --lvl1: #c2410c; --lvl2: #eab308; --lvl3: #10b981; --lvl4: #f59e0b; --lvl5: #dc2626;
  --road: #2563eb; --gate: #7c3aed; --pump: #059669; --rain: #38bdf8;

  --panel-w: 360px;
  --top-h: 56px;
  --radius: 8px;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / .05);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / .1), 0 4px 6px -4px rgb(0 0 0 / .1);
  font-family: "IBM Plex Sans Thai", ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* component display rules must never un-hide elements */
html, body { margin: 0; height: 100%; background: var(--bg); }
body { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
a { color: var(--accent); }

/* ---------------------------------------------------------------- header + tabs */
.topbar {
  height: var(--top-h); flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 20px; background: #fff; border-bottom: 1px solid var(--line); z-index: 3;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { display: grid; place-items: center; width: 32px; height: 32px; border-radius: 6px; background: var(--blue-600); color: #fff; flex: none; }
.brand h1 { margin: 0; font-size: 16px; font-weight: 600; line-height: 1.2; color: var(--gray-900); }
.brand .sub { margin: 0; font-size: 12px; color: var(--muted); white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex: none; }
.lang-toggle {
  display: inline-flex; align-items: center; gap: 2px; background: var(--gray-100); border-radius: 999px; padding: 2px;
}
.lang-toggle button {
  font: inherit; font-size: 13px; font-weight: 500; line-height: 1; border: 0; border-radius: 999px; cursor: pointer;
  padding: 5px 10px; background: transparent; color: var(--gray-700);
}
.lang-toggle button.active { background: var(--blue-600); color: #fff; }
.updated {
  display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500;
  color: #047857; background: #ecfdf5; border-radius: 999px; padding: 3px 10px;
}
.updated .dot { width: 6px; height: 6px; border-radius: 50%; background: #10b981; }
.updated.warn { color: #b45309; background: #fffbeb; }
.updated.warn .dot { background: #f59e0b; }

.tabs {
  flex: none; display: flex; gap: 4px; padding: 0 12px; background: #fff; border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none; z-index: 3;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: none; display: inline-flex; align-items: center; gap: 6px; padding: 10px 12px; margin-bottom: -1px;
  color: var(--gray-600); text-decoration: none; font-size: 14px; font-weight: 500; white-space: nowrap;
  border-bottom: 2px solid transparent; transition: color .15s, border-color .15s;
}
.tabs a:hover { color: var(--gray-900); border-bottom-color: var(--gray-300); }
.tabs a.active { color: var(--blue-600); border-bottom-color: var(--blue-600); }
.pill { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 999px; background: #fee2e2; color: #b91c1c; font-size: 12px; line-height: 18px; text-align: center; }

.alert-banner {
  flex: none; display: block; padding: 8px 20px; background: #fffbeb; color: #92400e; font-size: 13px;
  border-bottom: 1px solid #fde68a; text-decoration: none;
}
.alert-banner b { color: #b45309; font-weight: 600; }
.alert-banner:hover { background: #fef3c7; }
.alert-banner .src-tag { color: #b45309; opacity: .8; white-space: nowrap; }

/* ---------------------------------------------------------------- badges (soft / tinted) */
.badge, .lvbadge {
  display: inline-flex; align-items: center; border-radius: 999px; padding: 1px 10px;
  font-size: 12px; font-weight: 500; white-space: nowrap; background: var(--gray-100); color: var(--gray-700);
}
.tone-red { background: #fee2e2; color: #b91c1c; }
.tone-amber { background: #fef3c7; color: #b45309; }
.tone-emerald { background: #d1fae5; color: #047857; }
.tone-yellow { background: #fef9c3; color: #a16207; }
.tone-orange { background: #ffedd5; color: #c2410c; }
.tone-blue { background: var(--blue-100); color: var(--blue-700); }
.tone-gray { background: var(--gray-100); color: var(--gray-700); }

/* ---------------------------------------------------------------- map layout + panel */
.layout { position: relative; flex: 1; display: flex; min-height: 0; overflow: hidden; }
#map { flex: 1; min-width: 0; }

.panel {
  width: var(--panel-w); flex: none; background: #fff; border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0; order: -1;
}
.panel-body { overflow-y: auto; padding: 0 16px 24px; }
.panel h2 { font-size: 13px; font-weight: 600; margin: 20px 0 8px; color: var(--gray-900); }
.sheet-handle { display: none; }
.prov-select { display: flex; align-items: center; gap: 8px; padding: 14px 16px 0; font-size: 13px; color: var(--gray-700); }
.prov-select select { flex: 1; font: inherit; font-size: 14px; color: var(--gray-900); padding: 6px 10px; min-height: 36px;
  border: 1px solid var(--gray-300); border-radius: 6px; background: #fff; box-shadow: var(--shadow-sm); }

/* stats: HyperUI "title + value" cards */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 16px 16px 4px; }
.summary .stat span { white-space: nowrap; }
.stat {
  border: 1px solid var(--gray-100); border-radius: var(--radius); background: #fff; padding: 12px;
  box-shadow: var(--shadow-sm); display: flex; flex-direction: column-reverse; gap: 2px;
}
.stat b { display: block; font-size: 24px; font-weight: 500; line-height: 1.15; color: var(--gray-900); font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; line-height: 1.35; }
.stat span::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--gray-400); flex: none; }
.stat-red span::before { background: var(--lvl5); }
.stat-orange span::before { background: var(--lvl4); }
.stat-blue span::before { background: var(--road); }

/* layer toggles */
.toggles { display: grid; gap: 2px; }
.toggles label {
  display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--gray-700);
  min-height: 36px; padding: 4px 8px; border-radius: 6px; cursor: pointer;
}
.toggles label:hover { background: var(--gray-50); }
.toggles input, .filters input[type=checkbox] {
  width: 16px; height: 16px; accent-color: var(--blue-600); border-radius: 4px; margin: 0; flex: none;
}
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 50%; flex: none; }
.sw-flow { border-radius: 2px; height: 4px; background: repeating-linear-gradient(90deg, var(--blue-600) 0 5px, transparent 5px 8px); }
.sw-wl { background: var(--lvl4); box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--gray-200); }
.sw-road { background: var(--road); border-radius: 3px; }
.sw-gate { background: var(--gate); border-radius: 2px; transform: rotate(45deg) scale(.8); }
.sw-pump { background: var(--pump); }
.sw-dam { background: var(--blue-600); border-radius: 50%; box-shadow: inset 0 0 0 3px #fff, 0 0 0 1px var(--blue-600); }
.sw-flowst { background: #0891b2; }
.sw-rain { background: var(--rain); opacity: .6; }
.sw-alert { background: #fef2f2; border: 1.5px dashed var(--lvl5); border-radius: 3px; }
.sw-shelter { background: #ea580c; border-radius: 3px; }

/* watchlist: one bordered list with dividers */
.watchlist { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.watchlist li + li { border-top: 1px solid var(--line); }
.watchlist li button {
  width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; border: 0; background: #fff;
  display: grid; grid-template-columns: 8px 1fr auto; gap: 10px; align-items: center; padding: 10px 12px;
}
.watchlist li button:hover { background: var(--gray-50); }
.watchlist .lv { width: 8px; height: 8px; border-radius: 50%; }
.watchlist .nm { font-size: 14px; font-weight: 500; color: var(--gray-900); }
.watchlist .meta { font-size: 12px; color: var(--muted); }
.watchlist .val { font-size: 13px; font-weight: 500; color: var(--gray-700); text-align: right; white-space: nowrap; }
.watchlist li.muted { padding: 12px; }
.muted { color: var(--muted); font-size: 14px; }

.note { font-size: 12px; color: var(--muted); line-height: 1.6; margin: 8px 0 0; }
.note b { color: var(--gray-700); font-weight: 600; }

/* ---------------------------------------------------------------- pages */
.view[hidden] { display: none !important; }
.page { flex: 1; overflow-y: auto; min-height: 0; }
.page-inner { max-width: 1120px; margin: 0 auto; padding: 28px 20px 56px; }
.page-title { font-size: 20px; font-weight: 600; margin: 0 0 4px; color: var(--gray-900); }
.page-lead { color: var(--muted); margin: 0 0 20px; font-size: 14px; line-height: 1.6; max-width: 72ch; }
.page h3 { font-size: 15px; font-weight: 600; margin: 32px 0 10px; color: var(--gray-900); }

.filters { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; margin: 8px 0 16px; font-size: 14px; color: var(--gray-700); }
.filters label { display: inline-flex; align-items: center; gap: 8px; }
.filters select, .filters input[type=search] {
  font: inherit; font-size: 14px; color: var(--gray-900); padding: 7px 12px; min-height: 38px;
  border: 1px solid var(--gray-300); border-radius: 6px; background: #fff; box-shadow: var(--shadow-sm);
}
.filters select:focus, .filters input[type=search]:focus { outline: 2px solid var(--blue-100); border-color: var(--blue-600); }
.filters input[type=search] { min-width: 220px; flex: 1; max-width: 360px; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.cards .stat { padding: 16px 20px; }
.cards .stat b { font-size: 26px; }

/* tables: HyperUI divide-y style */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; box-shadow: var(--shadow-sm); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 10px 14px; text-align: left; vertical-align: top; }
table.data th {
  font-weight: 500; color: var(--gray-900); font-size: 13px; white-space: nowrap;
  border-bottom: 2px solid var(--line); background: #fff; position: sticky; top: 0;
}
table.data td { border-bottom: 1px solid var(--line); color: var(--gray-700); }
table.data td:first-child { color: var(--gray-900); font-weight: 500; }
table.data tbody tr:hover td { background: var(--gray-50); }
#ovDam tbody tr[data-id], #ovWaterlevel tbody tr[data-id], #ovFlow tbody tr[data-id], #ovRain tbody tr[data-id], #roadsTable tbody tr[data-id] { cursor: pointer; }
.cd-empty { padding: 40px 0; text-align: center; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
table.data tr.stale td { opacity: .55; }
table.data .sub { color: var(--muted); font-size: 12px; font-weight: 400; }
table.data td.nw { white-space: nowrap; }
table.data a.maplink { color: var(--blue-600); text-decoration: none; font-size: 13px; font-weight: 500; white-space: nowrap; }
table.data a.maplink:hover { color: var(--blue-700); text-decoration: underline; }
.empty { padding: 16px; color: var(--muted); font-size: 14px; }

.feed-warn { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; border-radius: 8px; padding: 8px 12px; font-size: 13px; margin: 0 0 12px; }
.road-legend { list-style: none; padding: 0; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 8px 20px; font-size: 13px; color: var(--gray-700); }
.road-legend .d, .dchip { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: 0; margin-right: 6px; }
.d0 { background: #93c5fd; } .d1 { background: #3b82f6; } .d2 { background: #1d4ed8; } .d3 { background: #1e3a8a; }

/* alerts */
.alert-list { display: grid; gap: 12px; }
.alert-card { border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 16px 20px; box-shadow: var(--shadow-sm); }
.alert-card.expired { background: var(--gray-50); box-shadow: none; }
.alert-card.expired h4 { color: var(--gray-600); }
.alert-card h4 { margin: 0 0 4px; font-size: 15px; font-weight: 600; color: var(--gray-900); }
.alert-card .meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.alert-card .tag { margin-right: 2px; }
.alert-card p { margin: 6px 0; font-size: 14px; line-height: 1.65; white-space: pre-line; color: var(--gray-700); }
.alert-card .area { font-size: 13px; color: var(--muted); }
.alert-card .area b { color: var(--gray-700); font-weight: 500; }
.alert-card details summary { cursor: pointer; font-size: 13px; color: var(--blue-600); font-weight: 500; }
.alert-card .src-line { font-size: 12px; color: var(--muted); margin-top: 8px; }
.alert-card .actions { margin-top: 10px; display: flex; gap: 16px; font-size: 13px; }
.alert-card .actions a { color: var(--blue-600); text-decoration: none; font-weight: 500; }

/* history chart */
.hist-chart { display: grid; gap: 16px; margin-bottom: 20px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow-sm); }
.hist-row { display: grid; grid-template-columns: 120px 1fr; gap: 12px; align-items: center; font-size: 13px; }
.hist-row > b { font-weight: 500; color: var(--gray-900); }
.hist-bars { display: flex; align-items: flex-end; gap: 8px; height: 120px; border-bottom: 1px solid var(--line); }
.hist-bar { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.hist-bar i { display: block; width: 100%; max-width: 44px; background: var(--blue-600); border-radius: 4px 4px 0 0; }
.hist-bar span { font-size: 12px; font-weight: 500; color: var(--gray-700); margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.hist-years { display: flex; gap: 8px; padding-top: 4px; }
.hist-years span { flex: 1; text-align: center; font-size: 12px; color: var(--muted); }
ul.plain { padding-left: 20px; font-size: 14px; line-height: 1.8; color: var(--gray-700); }

/* ---------------------------------------------------------------- floating map legend */
.map-legend { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  font-size: 12px; max-width: 232px; overflow: hidden; color: var(--gray-700); }
.map-legend .lg-toggle { display: flex; justify-content: space-between; align-items: center; gap: 12px; width: 100%; border: 0;
  background: transparent; font: inherit; font-size: 13px; font-weight: 600; color: var(--gray-900); padding: 8px 12px; cursor: pointer; min-height: 36px; }
.map-legend .lg-toggle:hover { background: var(--gray-50); }
.map-legend .lg-toggle span { color: var(--gray-400); transition: transform .15s; }
.map-legend.collapsed .lg-toggle span { transform: rotate(-90deg); }
.map-legend.collapsed .lg-body { display: none; }
.map-legend .lg-body { padding: 4px 12px 12px; border-top: 1px solid var(--gray-100); }
.map-legend .lg-title { color: var(--muted); font-size: 11px; font-weight: 500; margin: 8px 0 6px; }
.map-legend ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.map-legend li { display: flex; align-items: center; gap: 8px; }
.map-legend li i { display: inline-block; width: 18px; height: 4px; border-radius: 2px; flex: none; }
.map-legend .lg-arrow { color: #fff; background: var(--blue-600); border-radius: 3px; font-size: 9px; padding: 0 5px; line-height: 14px; }
.map-legend .lg-gate { font-weight: 500; font-size: 11px; color: var(--gray-600); }
.map-legend .lg-gate.open { color: #047857; }
.map-legend .lg-dot { width: 10px; height: 10px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px var(--gray-200); }
.map-legend .lg-note { color: var(--muted); font-size: 11px; line-height: 1.45; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--gray-100); }

/* ---------------------------------------------------------------- trends + charts */
.trend { white-space: nowrap; font-weight: 500; font-variant-numeric: tabular-nums; }
.trend-up { color: #b91c1c; }
.trend-down { color: #047857; }
.trend-steady { color: var(--gray-500); }
.trend-h { color: var(--gray-400); font-weight: 400; font-size: 12px; }
.watchlist .val .trend { font-size: 12px; }
svg.chart { display: block; max-width: 100%; height: auto; }
svg.chart .ax { font-size: 10px; fill: var(--gray-400); font-family: inherit; }
.chart-open { margin-top: 8px; border: 0; background: none; padding: 0; font: inherit; font-size: 12px; font-weight: 500; color: var(--blue-600); cursor: pointer; }
.chart-open:hover { color: var(--blue-700); text-decoration: underline; }

.chart-dialog { width: min(920px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 10px; padding: 0;
  box-shadow: 0 20px 25px -5px rgb(0 0 0 / .1), 0 8px 10px -6px rgb(0 0 0 / .1); color: var(--ink); font-family: inherit; }
.chart-dialog::backdrop { background: rgb(17 24 39 / .45); }
.cd-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 16px 20px 8px; }
.cd-title { margin: 0; font-size: 16px; font-weight: 600; }
.cd-sub { margin: 2px 0 0; font-size: 12px; color: var(--muted); }
.cd-close { border: 0; background: none; font-size: 16px; color: var(--gray-400); cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.cd-close:hover { background: var(--gray-100); color: var(--gray-700); }
.cd-ranges { display: flex; gap: 6px; padding: 0 20px 8px; }
.cd-ranges button { border: 0; border-radius: 999px; padding: 4px 12px; font: inherit; font-size: 13px; font-weight: 500;
  background: var(--gray-100); color: var(--gray-700); cursor: pointer; }
.cd-ranges button[aria-pressed="true"] { background: var(--blue-600); color: #fff; }
.cd-chart { position: relative; padding: 0 20px; min-height: 120px; }
.cd-tip { position: absolute; top: 4px; transform: translateX(-50%); background: var(--gray-900); color: #fff; font-size: 12px;
  padding: 3px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none; }
.cd-foot { padding: 8px 20px 16px; font-size: 13px; color: var(--gray-700); }
.cd-foot .src { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---------------------------------------------------------------- popup */
.maplibregl-popup-content {
  font-family: inherit; border-radius: var(--radius); padding: 14px 16px; min-width: 240px;
  border: 1px solid var(--line); box-shadow: var(--shadow-lg);
}
.maplibregl-popup-close-button { font-size: 18px; color: var(--gray-400); padding: 2px 8px; border-radius: 6px; }
.maplibregl-popup-close-button:hover { background: var(--gray-100); color: var(--gray-700); }
.pp h3 { margin: 0 20px 2px 0; font-size: 15px; font-weight: 600; color: var(--gray-900); }
.pp .where { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.pp .badge { margin-bottom: 10px; }
.pp dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; font-size: 13px; }
.pp dt { color: var(--muted); }
.pp dd { margin: 0; font-weight: 500; color: var(--gray-900); font-variant-numeric: tabular-nums; }
.pp .sub { color: var(--muted); font-size: 12px; font-weight: 400; }
.pp .src { margin-top: 10px; font-size: 11px; color: var(--gray-400); line-height: 1.5; }
.pp .stale { color: #b45309; background: #fffbeb; border-radius: 6px; padding: 6px 8px; font-weight: 500; font-size: 12px; margin-top: 8px; line-height: 1.5; }
.pp svg { display: block; margin-top: 10px; }
.pp .dam-down { margin-top: 8px; font-size: 12px; line-height: 1.55; background: var(--blue-50); color: var(--gray-700); border-radius: 6px; padding: 6px 8px; }
.pp .dam-down b { color: var(--blue-700); font-weight: 600; }
.gate2 { display: grid; grid-template-columns: 1fr auto 1fr; gap: 6px; align-items: stretch; margin-top: 10px; }
.g2-side { background: var(--gray-50); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.g2-lbl { font-size: 11px; color: var(--muted); }
.g2-val { font-size: 18px; font-weight: 600; color: var(--gray-900); font-variant-numeric: tabular-nums; line-height: 1.2; }
.g2-val.warn { color: #b45309; } .g2-val.crit { color: #b91c1c; }
.g2-unit { font-size: 11px; color: var(--muted); }
.g2-thr { font-size: 11px; color: var(--gray-500); }
.g2-mid { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 0 2px; }
.g2-arrow { font-size: 20px; line-height: 1; color: var(--gray-400); }
.g2-arrow.in, .g2-arrow.out { color: var(--blue-600); }
.g2-leaf { font-size: 11px; white-space: nowrap; padding: 1px 6px; border-radius: 999px; background: var(--gray-100); color: var(--gray-700); }
.g2-leaf.open { background: #d1fae5; color: #047857; }
.g2-note { font-size: 12px; color: var(--gray-700); margin-top: 6px; }
.pp .gmap { display: inline-block; margin-top: 10px; font-size: 12px; font-weight: 500; color: var(--blue-600); text-decoration: none; }

/* desktop popup never taller than the map */
.maplibregl-popup-content { max-height: min(62vh, 560px); overflow-y: auto; }  /* fits above a point placed at ~78% of map height */

/* phones: station/feature details as a compact bottom card */
.info-sheet { display: none; }
.info-sheet[hidden] { display: none !important; }

/* ---------------------------------------------------------------- mobile: panel becomes a bottom sheet */
@media (max-width: 760px) {
  :root { --top-h: 52px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .brand .sub { display: none; }
  .topbar-right { gap: 6px; }
  .lang-toggle button { padding: 5px 8px; }
  .updated { font-size: 12px; white-space: nowrap; }
  .updated .long { display: none; }
  .panel {
    position: absolute; left: 0; right: 0; bottom: 0; width: auto; border-right: 0;
    height: min(72vh, calc(100% - 24px)); border-radius: 12px 12px 0 0; border-top: 1px solid var(--line);
    box-shadow: 0 -10px 15px -3px rgb(0 0 0 / .08);
    transform: translateY(calc(min(72vh, 100% - 24px) - 132px - env(safe-area-inset-bottom)));
    transition: transform .25s ease; z-index: 2;
  }
  .panel.open { transform: translateY(0); }
  .sheet-handle { display: block; border: 0; background: transparent; padding: 8px 0 0; cursor: pointer; width: 100%; }
  .sheet-handle span { display: block; margin: 0 auto; width: 36px; height: 4px; border-radius: 2px; background: var(--gray-300); }
  .summary { padding-top: 8px; }
  .stat b { font-size: 22px; }
  .panel-body { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .maplibregl-ctrl-bottom-right, .maplibregl-ctrl-bottom-left { bottom: 132px; }
  .maplibregl-ctrl-scale { display: none; }  /* would sit under the bottom sheet */
  .tabs { padding: 0 8px; -webkit-mask-image: linear-gradient(90deg, #000 85%, transparent); mask-image: linear-gradient(90deg, #000 85%, transparent); padding-right: 32px; }
  .tabs a { padding: 10px 10px; }
  .alert-banner { padding: 6px 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .page-inner { padding: 20px 16px 48px; }
  .page-title { font-size: 18px; }
  table.data th, table.data td { padding: 8px 10px; }
  .hist-row { grid-template-columns: 1fr; }
  .hist-chart { padding: 16px; }
  /* tables become stacked cards */
  table.stack thead { display: none; }
  table.stack, table.stack tbody { display: block; }
  table.stack tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
  table.stack tr:last-child { border-bottom: 0; }
  table.stack td { border: 0; padding: 0; }
  table.stack td:first-child { grid-column: 1 / -1; }
  table.stack td[data-label]::before { content: attr(data-label) " "; color: var(--muted); font-size: 12px; font-weight: 400; }
  table.stack td.num { text-align: left; }
  table.stack td.blank { display: none; }  /* no data: don't show a lone dash on phones */
  table.stack tbody tr:hover td { background: transparent; }
  .info-sheet { display: block; position: absolute; left: 0; right: 0; bottom: 0; z-index: 5; background: #fff;
    border-radius: 12px 12px 0 0; border-top: 1px solid var(--line); box-shadow: 0 -10px 20px -5px rgb(0 0 0 / .15);
    max-height: 78%; overflow-y: auto; padding: 14px 16px calc(12px + env(safe-area-inset-bottom)); }
  .info-sheet .is-close { position: absolute; top: 8px; right: 8px; border: 0; background: var(--gray-100); color: var(--gray-600);
    width: 32px; height: 32px; border-radius: 50%; font-size: 14px; cursor: pointer; }
  .info-sheet .pp h3 { margin-right: 40px; font-size: 16px; }
  .info-sheet .pp .where { margin-bottom: 6px; }
  .info-sheet .pp .badge { margin-bottom: 6px; }
  /* two label/value pairs per row so everything fits without scrolling */
  .info-sheet .pp dl { grid-template-columns: auto 1fr auto 1fr; gap: 4px 10px; font-size: 13px; }
  .info-sheet .pp .src { margin-top: 6px; }
  .info-sheet .pp svg.chart { margin-top: 6px; }
  body.sheet-open .map-legend { display: none; }  /* the card needs the space */
}
