/* Dana FloodRoute — colours from the Dana Modern Blue system (brand-blue #0085ca, navy #041e41) */
:root {
  --navy: #041e41;
  --blue: #0085ca;
  --blue-deep: #005eb8;
  --sky: #69b3e7;
  --azure: #1b8af0;
  --bg: #e8eef4;
  --panel: #ffffff;
  --panel-2: #f2f6fa;
  --panel-3: #e4f1fe;
  --ink: #253c4d;
  --ink-strong: #041e41;
  --muted: #56697a;
  --line: #d6dee6;
  --line-strong: #c1c6c8;
  --label: #007bac;
  --focus: #1b8af0;

  --ok: #17754f;
  --ok-bg: #e2f3eb;
  --wet: #1f6594;
  --wet-bg: #e3eff8;
  --warn: #945400;
  --warn-bg: #fcefd9;
  --bad: #b3261e;
  --bad-bg: #fbe4e2;

  --r-ok: #0085ca;
  --r-wet: #0085ca;
  --r-warn: #e28a00;
  --r-bad: #d63a33;
  --r-alt: #7f8f9d;
  --r-casing: #ffffff;
  --traffy: #9a5310;

  --w0: #ffffff;
  --w1: #bfe3f8;
  --w2: #5eb3ea;
  --w3: #1766b5;
  --w4: #0a2f6b;

  --bar: #041e41;
  --bar-ink: #ffffff;
  --bar-2: #0f3263;

  --shadow: 0 1px 2px rgba(4, 30, 65, 0.08), 0 8px 24px rgba(4, 30, 65, 0.12);
  --radius: 16px;
  --radius-sm: 10px;
  --font: "IBM Plex Sans Thai", Tahoma, "Noto Sans Thai", "Leelawadee UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Menlo, Consolas, monospace;
  --gutter: 12px;
  --left-w: 392px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #07121f;
    --panel: #0e1c2c;
    --panel-2: #13263a;
    --panel-3: #16304a;
    --ink: #d5e1ec;
    --ink-strong: #ffffff;
    --muted: #93a7b9;
    --line: #22384e;
    --line-strong: #2f4a64;
    --label: #70d4ff;
    --blue: #2aa3e6;
    --ok: #52d19b;
    --ok-bg: #11342a;
    --wet: #8ccaf3;
    --wet-bg: #12304a;
    --warn: #ffb54d;
    --warn-bg: #3a2a10;
    --bad: #ff8078;
    --bad-bg: #401b1a;
    --r-ok: #35b0f0;
    --r-wet: #35b0f0;
    --r-warn: #ffab2e;
    --r-bad: #ff5f57;
    --r-alt: #6f8397;
    --r-casing: #07121f;
    --traffy: #e9a45a;
    --w0: #0e1c2c;
    --bar: #0b2a52;
    --bar-2: #15407a;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #07121f;
  --panel: #0e1c2c;
  --panel-2: #13263a;
  --panel-3: #16304a;
  --ink: #d5e1ec;
  --ink-strong: #ffffff;
  --muted: #93a7b9;
  --line: #22384e;
  --line-strong: #2f4a64;
  --label: #70d4ff;
  --blue: #2aa3e6;
  --ok: #52d19b;
  --ok-bg: #11342a;
  --wet: #8ccaf3;
  --wet-bg: #12304a;
  --warn: #ffb54d;
  --warn-bg: #3a2a10;
  --bad: #ff8078;
  --bad-bg: #401b1a;
  --r-ok: #35b0f0;
  --r-wet: #35b0f0;
  --r-warn: #ffab2e;
  --r-bad: #ff5f57;
  --r-alt: #6f8397;
  --r-casing: #07121f;
  --traffy: #e9a45a;
  --w0: #0e1c2c;
  --bar: #0b2a52;
  --bar-2: #15407a;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, select, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

#map { position: fixed; inset: 0; }

/* ---------- left column: status + routes ---------- */
.left {
  position: fixed;
  z-index: 5;
  top: calc(var(--gutter) + env(safe-area-inset-top, 0px));
  left: var(--gutter);
  bottom: calc(var(--gutter) + env(safe-area-inset-bottom, 0px));
  width: var(--left-w);
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  transition: transform 0.25s ease, opacity 0.2s ease, visibility 0s linear 0s;
}
.left > * { pointer-events: auto; }
body.panel-hidden .left {
  transform: translateX(calc(-100% - 2 * var(--gutter)));
  opacity: 0;
  visibility: hidden;
  transition: transform 0.25s ease, opacity 0.2s ease, visibility 0s linear 0.25s;
}
body.panel-hidden .actionbar { left: var(--gutter); max-width: calc(100% - var(--gutter) * 2); }
.meta-btns { display: flex; gap: 6px; }
.icon-btn { display: inline-grid; place-items: center; padding: 3px 7px; }
.icon-btn svg { display: block; width: 16px; height: 16px; }
.ab-btn.icon-btn { padding: 0; }
.ab-btn.icon-btn svg { width: 20px; height: 20px; }
.panel-show {
  position: fixed;
  z-index: 5;
  top: calc(var(--gutter) + env(safe-area-inset-top, 0px));
  left: var(--gutter);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px 8px 10px;
  border: 0;
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink-strong);
  font-weight: 600;
  font-size: 13.5px;
  box-shadow: var(--shadow);
}
.panel-show svg { width: 20px; height: 20px; color: var(--blue); }
.panel-show:hover { background: var(--panel-2); }
.card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.status { padding: 14px 16px 14px; }
.status-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.eyebrow {
  margin: 0 0 2px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--label);
}
.status h1 {
  margin: 0;
  font-size: 19px;
  line-height: 1.3;
  font-weight: 700;
  color: var(--ink-strong);
  text-wrap: balance;
}
.brandbar {
  display: block;
  width: 56px;
  height: 4px;
  margin-top: 7px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--blue-deep), var(--blue) 55%, var(--sky));
}
.status-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.stamp { font: 500 11.5px/1 var(--mono); color: var(--muted); }
.status-summary { margin: 10px 0 12px; font-size: 13px; color: var(--muted); line-height: 1.5; }
.metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 1px solid var(--line);
  padding-top: 10px;
  gap: 8px;
}
.metric { display: flex; flex-direction: column; min-width: 0; }
.metric + .metric { border-left: 1px solid var(--line); padding-left: 10px; }
.m-label { font-size: 11.5px; color: var(--muted); font-weight: 500; }
.m-value {
  font: 600 20px/1.25 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--ink-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.m-value small { font: 500 12px var(--font); color: var(--muted); margin-left: 2px; }
.m-value.lv2 { color: var(--warn); }
.m-value.lv3 { color: var(--bad); }
.m-value.txt { font-family: var(--font); font-size: 16px; font-weight: 700; line-height: 1.5; }
.m-sub { font-size: 11.5px; color: var(--muted); line-height: 1.35; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.chip-btn {
  border: 1px solid var(--line-strong);
  background: var(--panel);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-strong);
}
.chip-btn:hover { background: var(--panel-2); }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.6;
}
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill[data-level="0"] { color: var(--ok); background: var(--ok-bg); }
.pill[data-level="1"] { color: var(--wet); background: var(--wet-bg); }
.pill[data-level="2"] { color: var(--warn); background: var(--warn-bg); }
.pill[data-level="3"] { color: var(--bad); background: var(--bad-bg); }

/* ---------- routes panel ---------- */
.routes { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.sheet-handle { display: none; }
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin: 12px 12px 0;
  padding: 4px;
  background: var(--panel-2);
  border-radius: 12px;
}
.tabs button {
  border: 0;
  background: transparent;
  border-radius: 9px;
  padding: 7px 8px;
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
}
.tabs button[aria-selected="true"] { background: var(--panel); color: var(--ink-strong); box-shadow: 0 1px 3px rgba(4, 30, 65, 0.12); }
.routes-body { flex: 1; overflow-y: auto; padding: 12px 12px 14px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.routes-body > * { flex-shrink: 0; }
.st-expand, .status-grip, .sheet-peek { display: none; }

.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.seg { display: inline-flex; background: var(--panel-2); border-radius: 999px; padding: 3px; gap: 2px; }
.seg button {
  border: 0;
  background: transparent;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
}
.seg button[aria-pressed="true"] { background: var(--navy); color: #fff; }

.section-title { margin: 2px 0 0; font-size: 12px; font-weight: 600; color: var(--label); letter-spacing: 0.02em; }
.hint { margin: 0; font-size: 12.5px; color: var(--muted); }

.hub-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.hub {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  align-items: center;
  width: 100%;
  text-align: left;
  border: 0;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 9px 12px;
}
.hub:first-child { border-top: 0; }
.hub:hover { background: var(--panel-2); }
.hub-name { font-weight: 600; color: var(--ink-strong); font-size: 13.5px; }
.hub-via { grid-column: 1; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hub-right { grid-row: 1 / span 2; grid-column: 2; display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.eta { font: 600 13px var(--mono); font-variant-numeric: tabular-nums; color: var(--ink-strong); }
.eta small { font: 500 11px var(--font); color: var(--muted); }

.back { border: 0; background: none; padding: 0; color: var(--label); font-weight: 600; font-size: 13px; }
.view-title { margin: 0; font-size: 15px; font-weight: 700; color: var(--ink-strong); }
.view-sub { margin: 0; font-size: 12.5px; color: var(--muted); }

.route {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
}
.route[aria-pressed="true"] { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue) inset; background: linear-gradient(135deg, var(--panel), var(--panel-3)); }
.route-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.route-name { font-weight: 700; font-size: 14px; color: var(--ink-strong); }
.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 6px;
  background: var(--navy);
  color: #fff;
  margin-right: 6px;
  vertical-align: 1px;
}
.tag.alt { background: var(--panel-2); color: var(--ink); }
.route-stats { font-size: 12.5px; color: var(--muted); }
.route-stats b { font: 600 14px var(--mono); color: var(--ink-strong); font-variant-numeric: tabular-nums; }
.via { font-size: 12px; color: var(--muted); }
.hazards { list-style: none; margin: 2px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.hazards li { display: grid; grid-template-columns: 10px 1fr; gap: 8px; font-size: 12.5px; line-height: 1.4; }
.hazards li::before { content: ""; width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; background: var(--wet); }
.hazards li[data-level="0"]::before { background: var(--ok); }
.hazards li[data-level="2"]::before { background: var(--r-warn); }
.hazards li[data-level="3"]::before { background: var(--r-bad); }
.hazards b { color: var(--ink-strong); font-weight: 600; }
.hazards .km { font-family: var(--mono); color: var(--muted); font-size: 11.5px; }
.route-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  line-height: 1.3;
}
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-deep); }
.btn.primary:disabled { background: var(--line-strong); color: var(--panel); cursor: not-allowed; }
.btn.ghost { background: var(--panel); border-color: var(--line-strong); color: var(--ink-strong); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.block { width: 100%; padding: 10px 12px; }
.btn.small { padding: 5px 10px; font-size: 12.5px; }

.site-duo { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.site-box { background: var(--panel-2); border-radius: 12px; padding: 9px 11px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.site-box b { font-size: 12.5px; color: var(--ink-strong); }
.site-box span { font-size: 12px; color: var(--muted); }

.empty { padding: 14px; border: 1px dashed var(--line-strong); border-radius: 12px; color: var(--muted); font-size: 13px; text-align: center; }
.skeleton { height: 54px; border-radius: 12px; background: linear-gradient(90deg, var(--panel-2), var(--panel-3), var(--panel-2)); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- action bar ---------- */
.actionbar {
  position: fixed;
  z-index: 6;
  bottom: calc(var(--gutter) + env(safe-area-inset-bottom, 0px));
  left: calc(var(--left-w) + var(--gutter) * 2);
  right: var(--gutter);
  margin: 0 auto;
  width: max-content;
  max-width: calc(100% - var(--left-w) - var(--gutter) * 3);
  display: flex;
  gap: 6px;
  padding: 6px;
  background: var(--bar);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.ab-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 46px;
  height: 46px;
  padding: 0 12px;
  border: 0;
  border-radius: 11px;
  background: var(--bar-2);
  color: var(--bar-ink);
  font-weight: 600;
  font-size: 14px;
}
.ab-btn svg { width: 21px; height: 21px; }
.ab-btn:hover { filter: brightness(1.15); }
.ab-primary { background: var(--blue); padding: 0 22px; font-size: 15px; }
.ab-layers span { white-space: nowrap; }
/* Map credits sit under the zoom buttons (top-right) so nothing covers them. */
.maplibregl-ctrl-top-right .maplibregl-ctrl-attrib { margin-top: 10px; }
/* Keep map controls above the HTML markers (which carry their own z-index). */
.maplibregl-ctrl-top-left, .maplibregl-ctrl-top-right, .maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right { z-index: 10; }
.ab-sos { background: #c62f2a; }
.ab-sos b { font-family: var(--mono); letter-spacing: 0.04em; }

.pick-hint {
  position: fixed;
  z-index: 7;
  top: calc(var(--gutter) + env(safe-area-inset-top, 0px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 16px;
  background: var(--navy);
  color: #fff;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 13.5px;
  max-width: calc(100% - 24px);
}
.pick-hint .chip-btn { background: transparent; color: #fff; border-color: rgba(255, 255, 255, 0.5); }

.toast {
  position: fixed;
  z-index: 20;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--navy);
  color: #fff;
  padding: 9px 16px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  font-size: 13.5px;
  max-width: calc(100% - 32px);
}

/* ---------- dialogs ---------- */
dialog.sheet {
  border: 0;
  padding: 0;
  width: min(460px, calc(100% - 24px));
  max-height: min(86vh, 760px);
  border-radius: 18px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}
dialog.sheet::backdrop { background: rgba(4, 18, 36, 0.45); }
.sheet-body { padding: 18px 18px 16px; display: flex; flex-direction: column; gap: 12px; }
.sheet-body h2 { margin: 0; font-size: 18px; color: var(--ink-strong); }
.sheet-body h3 { margin: 6px 0 0; font-size: 14px; color: var(--ink-strong); }
.sheet-body p { margin: 0; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.levels { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.level {
  display: grid;
  grid-template-columns: 26px 1fr;
  grid-template-rows: auto auto;
  column-gap: 8px;
  text-align: left;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--panel);
  padding: 9px 10px;
}
.level i { grid-row: 1 / span 2; align-self: center; }
.level b { font-size: 14px; color: var(--ink-strong); }
.level span { font-size: 12px; color: var(--muted); }
.level[aria-pressed="true"] { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue) inset; background: var(--panel-3); }
.drop { display: block; width: 22px; height: 26px; background: currentColor; -webkit-mask: var(--drop) center / contain no-repeat; mask: var(--drop) center / contain no-repeat; }
:root { --drop: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 28'%3E%3Cpath d='M12 1S3 11.5 3 17.5a9 9 0 0 0 18 0C21 11.5 12 1 12 1Z'/%3E%3C/svg%3E"); }
.d1 { color: var(--w1); }
.d2 { color: var(--w2); }
.d3 { color: var(--w3); }
.d4 { color: var(--w4); }
:root[data-theme="dark"] .d4 { color: #7aa7ff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .d4 { color: #7aa7ff; } }

.photo-row { display: flex; flex-direction: column; gap: 6px; }
.photo-pick {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 92px;
  padding: 0;
  overflow: hidden;
  border: 1.5px dashed var(--line-strong);
  border-radius: 12px;
  background: var(--panel-2);
  color: var(--ink-strong);
}
.photo-pick:hover { border-color: var(--blue); }
.photo-pick img { display: block; width: 100%; max-height: 220px; object-fit: cover; }
.photo-cta { display: inline-flex; align-items: center; gap: 8px; padding: 12px; font-weight: 600; font-size: 13.5px; }
.photo-cta svg { width: 22px; height: 22px; color: var(--blue); }
.photo-pick.has-photo { border-style: solid; }
.photo-pick.has-photo .photo-cta { position: absolute; right: 8px; bottom: 8px; padding: 5px 10px; border-radius: 999px; background: rgba(4, 30, 65, 0.78); color: #fff; font-size: 12px; }
.photo-pick.has-photo .photo-cta svg { width: 16px; height: 16px; color: #fff; }
.field textarea { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--panel); font-weight: 400; resize: vertical; min-height: 56px; }
.field small { align-self: flex-end; font-weight: 400; font-size: 11.5px; }
.pp-note { margin: 6px 0 0; font-size: 13px; color: var(--ink-strong); overflow-wrap: anywhere; }
.btn.warn-ghost { background: transparent; border-color: transparent; color: var(--bad); }
.pos-row { display: flex; align-items: center; gap: 6px 10px; flex-wrap: wrap; background: var(--panel-2); border-radius: 12px; padding: 8px 10px; }
.pos-info { flex: 1 1 180px; display: flex; flex-direction: column; min-width: 0; }
.pos-info b { font-size: 13.5px; color: var(--ink-strong); overflow-wrap: anywhere; }
.pos-text { font: 500 12px/1.4 var(--mono); color: var(--muted); }
.pos-btns { display: flex; gap: 6px; flex-wrap: wrap; }

/* Pin confirmation: the map with a draggable pin and this panel, nothing else. */
body.placing .left,
body.placing .actionbar,
body.placing .panel-show { display: none !important; }
.place-panel {
  position: fixed;
  z-index: 8;
  left: var(--gutter);
  bottom: calc(var(--gutter) + env(safe-area-inset-bottom, 0px));
  width: var(--left-w);
  max-height: 62vh;
  overflow-y: auto;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.place-panel h2 { margin: 0; font-size: 16.5px; color: var(--ink-strong); }
.place-panel p { margin: 0; }
.pl-where { display: flex; flex-direction: column; gap: 2px; padding: 8px 10px; border-radius: 12px; background: var(--panel-2); }
.pl-where b { font-size: 14px; color: var(--ink-strong); overflow-wrap: anywhere; }
.pl-where .num { font-size: 12px; color: var(--muted); }
.pl-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.pl-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; }
.pl-chip span { font-weight: 500; color: var(--muted); }
.mk-pin { width: 36px; height: 46px; cursor: grab; filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.35)); }
.mk-pin:active { cursor: grabbing; }
.mk-pin svg { display: block; width: 100%; height: 100%; }

.layer-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.layer {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 9px 12px;
  border-top: 1px solid var(--line);
  cursor: pointer;
}
.layer:first-child { border-top: 0; }
.layer b { display: block; font-size: 13.5px; color: var(--ink-strong); font-weight: 600; }
.layer span { display: block; font-size: 12px; color: var(--muted); line-height: 1.4; }
.layer input { width: 18px; height: 18px; accent-color: var(--blue); }
.swatch { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font: 600 10px var(--mono); }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-strong); }
.field select { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line-strong); background: var(--panel); font-weight: 500; }

.sos-list { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.sos-item {
  display: grid;
  grid-template-columns: minmax(64px, auto) 1fr;
  gap: 10px;
  align-items: center;
  padding: 9px 12px;
  border-top: 1px solid var(--line);
  color: inherit;
  text-decoration: none;
}
.sos-item:first-child { border-top: 0; }
.sos-item:hover { background: var(--panel-2); }
.sos-num { font: 600 18px var(--mono); color: var(--bad); }
.sos-item b { display: block; font-size: 13.5px; color: var(--ink-strong); }
.sos-item span { display: block; font-size: 12px; color: var(--muted); }
.sos-group { margin: 0 0 6px; font-size: 12px; font-weight: 600; color: var(--label); }

.src-list { display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.src-row { display: flex; justify-content: space-between; gap: 10px; }
.src-row b { font-weight: 600; color: var(--ink-strong); }
.src-row .bad { color: var(--bad); }

/* ---------- map markers ---------- */
.mk-site {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px 4px 5px;
  border-radius: 10px;
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  font-size: 12.5px;
  box-shadow: 0 2px 8px rgba(4, 30, 65, 0.35);
  white-space: nowrap;
  cursor: pointer;
}
.mk-site i { width: 22px; height: 22px; border-radius: 7px; background: var(--blue); display: grid; place-items: center; }
.mk-site svg { width: 14px; height: 14px; }
.mk-site.wh i { background: #fff; color: var(--navy); }
.mk-hub {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink-strong);
  border: 1.5px solid var(--navy);
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(4, 30, 65, 0.2);
}
.mk-hub[data-level="2"] { border-color: var(--r-warn); }
.mk-hub[data-level="3"] { border-color: var(--r-bad); }
.mk-lm {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 2px;
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(4, 30, 65, 0.18);
}
.mk-lm i { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; background: var(--panel-3); color: var(--label); flex-shrink: 0; }
.mk-lm svg { width: 12px; height: 12px; }
.mk-lm[data-type="hospital"] i { color: var(--bad); }
.mk-lm[data-type="temple"] i { color: var(--warn); }
.lm-compact .mk-lm { padding: 2px; }
.lm-compact .mk-lm span { display: none; }
.mk-sensor {
  min-width: 24px;
  padding: 1px 5px;
  border-radius: 6px;
  font: 600 11.5px/1.5 var(--mono);
  text-align: center;
  background: var(--w0);
  color: var(--ink-strong);
  border: 1.5px solid var(--w2);
  box-shadow: 0 1px 3px rgba(4, 30, 65, 0.25);
  cursor: pointer;
}
.mk-sensor.dry { border-color: var(--line-strong); color: var(--muted); }
.mk-sensor.stale { opacity: 0.45; }
.mk-sensor.d1 { background: var(--w1); color: #041e41; border-color: var(--w2); }
.mk-sensor.d2 { background: var(--w2); color: #041e41; border-color: var(--w3); }
.mk-sensor.d3 { background: var(--w3); color: #fff; border-color: var(--w4); }
.mk-sensor.d4 { background: var(--w4); color: #fff; border-color: #000; }
.mk-report { width: 26px; height: 30px; cursor: pointer; filter: drop-shadow(0 1px 2px rgba(4, 30, 65, 0.45)); }
.mk-report .drop { width: 26px; height: 30px; }
.mk-canal {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px 1px 4px;
  border-radius: 6px;
  background: var(--panel);
  border: 1.5px solid var(--sky);
  font: 600 11px/1.6 var(--mono);
  color: var(--ink-strong);
  cursor: pointer;
  white-space: nowrap;
}
.mk-canal.over { border-color: var(--r-bad); color: var(--bad); }
.mk-canal svg { width: 14px; height: 14px; color: var(--blue); }

.maplibregl-popup-content {
  background: var(--panel);
  color: var(--ink);
  border-radius: 12px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  font: 13px/1.45 var(--font);
  max-width: 280px;
}
.maplibregl-popup-tip { border-top-color: var(--panel) !important; border-bottom-color: var(--panel) !important; }
.maplibregl-popup-close-button { color: var(--muted); font-size: 18px; padding: 0 6px; }
.pp-title { font-weight: 700; color: var(--ink-strong); margin: 0 18px 2px 0; }
.pp-sub { font-size: 12px; color: var(--muted); }
.pp-big { font: 600 20px var(--mono); color: var(--ink-strong); }
.detail-body { font-size: 14px; line-height: 1.5; }
.detail-body .pp-title { margin: 0 0 2px; font-size: 16px; }
.detail-body .pp-img { max-height: 240px; }
.pp-src { margin-top: 8px; padding-top: 6px; border-top: 1px solid var(--line); font-size: 11.5px; line-height: 1.45; color: var(--muted); }
.pp-src a { color: var(--label); font-weight: 600; text-decoration: none; }
.pp-src a:hover { text-decoration: underline; }
.pp-img { display: block; width: 100%; max-height: 140px; object-fit: cover; border-radius: 8px; margin-top: 6px; }
.pp-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.maplibregl-ctrl-group { background: var(--panel); }
.maplibregl-ctrl-group button + button { border-top-color: var(--line); }
.maplibregl-ctrl-attrib { font-size: 10.5px; }

/* ---------- phone layout ---------- */
@media (max-width: 860px) {
  :root { --gutter: 10px; }
  .left {
    width: auto;
    right: var(--gutter);
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    justify-content: space-between;
  }
  .status { padding: 11px 13px; }
  .status h1 { font-size: 16.5px; }
  .status-summary { display: none; }
  .metrics { margin-top: 8px; padding-top: 8px; }
  .m-value { font-size: 17px; }
  .m-value.txt { font-size: 14px; }
  .routes { flex: 0 1 auto; max-height: 38vh; transition: max-height 0.25s ease; }
  .routes.expanded { max-height: 72vh; }
  /* Swipe zones: the browser must not claim vertical drags here, or the gesture never arrives. */
  .sheet-grip, .status { touch-action: none; }
  .sheet-grip .sheet-handle { width: 100%; }
  /* 16px or more stops iPhone Safari zooming in on focus (and staying zoomed after typing). */
  .field textarea, .field select, .field input { font-size: 16px; }
  .place-panel { right: var(--gutter); width: auto; max-height: 55vh; }
  .routes.collapsed { max-height: 64px; }
  .routes.collapsed .tabs, .routes.collapsed .routes-body { display: none; }
  .sheet-peek:not([hidden]) {
    display: block;
    width: 100%;
    padding: 4px 12px 12px;
    border: 0;
    background: none;
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
  }
  .status { position: relative; padding-bottom: 16px; transition: padding 0.2s ease; }
  .status-grip { display: block; position: absolute; left: 50%; bottom: 5px; width: 36px; height: 4px; margin-left: -18px; border-radius: 4px; background: var(--line-strong); }
  .status.collapsed { padding: 9px 44px 13px 13px; cursor: pointer; }
  .status.collapsed .eyebrow,
  .status.collapsed .brandbar,
  .status.collapsed .status-meta,
  .status.collapsed .metrics { display: none; }
  .status.collapsed h1 { font-size: 15px; }
  .status.collapsed .st-expand { display: grid; place-items: center; position: absolute; right: 10px; top: 50%; width: 28px; height: 28px; margin-top: -16px; color: var(--muted); }
  .status.collapsed .st-expand svg { width: 22px; height: 22px; }
  body.status-collapsed .maplibregl-ctrl-top-right { top: 64px; }
  .sheet-handle {
    display: flex;
    justify-content: center;
    border: 0;
    background: none;
    padding: 8px 0 0;
  }
  .sheet-handle span { width: 40px; height: 4px; border-radius: 4px; background: var(--line-strong); }
  .tabs { margin-top: 6px; }
  .actionbar { left: var(--gutter); right: var(--gutter); width: auto; max-width: none; justify-content: space-between; }
  .ab-btn { flex: 0 0 auto; padding: 0 10px; }
  .ab-primary { flex: 1; padding: 0 12px; }
  .ab-sos span { display: none; }
  .maplibregl-ctrl-top-right { top: 170px; }
  body.panel-hidden .maplibregl-ctrl-top-right { top: 0; }
  dialog.sheet { width: 100%; max-width: none; margin: auto 0 0; border-radius: 18px 18px 0 0; max-height: 88vh; padding-bottom: env(safe-area-inset-bottom, 0px); }
}
@media (max-width: 380px) {
  .metrics { grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
  .metric + .metric { padding-left: 6px; }
  .ab-layers span { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  .left, body.panel-hidden .left, .status { transition: none; }
  .routes { transition: none; }
}
