/* WaterNet — mobile water distribution modeling */

:root {
  --bg: #edf4f7;
  --bg-soft: #f6fafc;
  --surface: #ffffff;
  --surface-2: #f3f8fa;
  --surface-3: #e5eef3;
  --text: #102a35;
  --text-2: #405c69;
  --muted: #738d99;
  --line: #dbe8ee;
  --line-strong: #c8dae2;
  --primary: #087a96;
  --primary-strong: #05627a;
  --primary-soft: #e0f3f7;
  --accent: #00b0c7;
  --danger: #cf4444;
  --danger-soft: #fdecec;
  --warn: #a96600;
  --warn-soft: #fff5df;
  --ok: #13875a;
  --ok-soft: #e3f7ee;
  --header-a: #052f40;
  --header-b: #075a72;
  --header-c: #0a8aa3;
  --shadow-sm: 0 2px 8px rgba(8, 42, 56, .06);
  --shadow-md: 0 8px 24px rgba(8, 42, 56, .09);
  --shadow-lg: 0 20px 50px rgba(8, 42, 56, .16);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: calc(62px + var(--safe-top));
  --tab-h: calc(62px + var(--safe-bottom));
  --glass: rgba(255, 255, 255, .88);
  --map-bg: #e7f0f4;
  --map-grid: rgba(19, 73, 91, .075);
  --map-grid-major: rgba(19, 73, 91, .12);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  --bg: #071820;
  --bg-soft: #0b2029;
  --surface: #0e2630;
  --surface-2: #123039;
  --surface-3: #183b46;
  --text: #e9f5f8;
  --text-2: #b2ccd5;
  --muted: #7e9ba6;
  --line: #1c3f4b;
  --line-strong: #27535f;
  --primary: #3fc3d9;
  --primary-strong: #75d8e7;
  --primary-soft: #103c47;
  --accent: #57d5e6;
  --danger: #ff7373;
  --danger-soft: #3a1d20;
  --warn: #ffb74d;
  --warn-soft: #3a2c12;
  --ok: #4bd998;
  --ok-soft: #103229;
  --header-a: #031c26;
  --header-b: #053544;
  --header-c: #075365;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, .28);
  --shadow-lg: 0 20px 50px rgba(0, 0, 0, .45);
  --glass: rgba(10, 32, 41, .9);
  --map-bg: #081c24;
  --map-grid: rgba(139, 195, 208, .055);
  --map-grid-major: rgba(139, 195, 208, .1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 15% 0%, #bfe0ea 0%, transparent 60%),
    radial-gradient(900px 700px at 90% 100%, #cfe7ee 0%, transparent 55%),
    #dbe8ee;
  color: var(--text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
:root[data-theme="dark"] body {
  background:
    radial-gradient(1100px 600px at 10% 0%, #0b3443 0%, transparent 60%),
    radial-gradient(800px 700px at 100% 100%, #092a36 0%, transparent 55%),
    #04121a;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
svg.icon use { pointer-events: none; }

#app {
  width: 100%; max-width: 600px;
  height: 100vh; height: 100dvh;
  margin: 0 auto;
  display: flex; flex-direction: column;
  background: var(--bg);
  position: relative;
  overflow: hidden;
}

/* ---------------- app bar ---------------- */
.appbar {
  flex: none;
  height: var(--header-h);
  padding: calc(var(--safe-top) + 10px) 14px 10px;
  display: flex; align-items: center; gap: 10px;
  background:
    radial-gradient(220px 90px at 12% 0%, rgba(86, 210, 230, .28), transparent 70%),
    linear-gradient(118deg, var(--header-a) 0%, var(--header-b) 58%, var(--header-c) 130%);
  color: #fff;
  position: relative;
  z-index: 5;
  box-shadow: 0 4px 18px rgba(3, 31, 43, .18);
}
.appbar::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,.06), transparent 50%);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; position: relative; z-index: 1; }
.brand-mark {
  width: 39px; height: 39px; flex: none;
  border-radius: 13px;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(145deg, rgba(255,255,255,.23), rgba(255,255,255,.08));
  border: 1px solid rgba(255,255,255,.25);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.28), 0 4px 12px rgba(0,0,0,.12);
}
.brand-mark .icon { width: 25px; height: 25px; }
.brand-copy { min-width: 0; }
.brand-name { font-size: 17.5px; font-weight: 800; letter-spacing: -.2px; line-height: 1.15; }
.brand-sub {
  font-size: 10.5px; font-weight: 500; color: rgba(255,255,255,.7);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 210px; margin-top: 2px; letter-spacing: .1px;
}
.appbar-actions { margin-left: auto; display: flex; gap: 2px; position: relative; z-index: 1; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 12px;
  display: grid; place-items: center;
  color: var(--text-2);
  transition: background .15s ease, color .15s ease, transform .1s ease;
}
.icon-btn .icon { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--surface-3); }
.icon-btn:active { transform: scale(.94); }
.icon-btn:disabled { opacity: .32; pointer-events: none; }
.appbar .icon-btn { color: rgba(255,255,255,.9); }
.appbar .icon-btn:hover { background: rgba(255,255,255,.13); }
.icon-btn.solid { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.icon-btn.solid:hover { background: var(--primary-strong); }

/* ---------------- layout ---------------- */
main { flex: 1; position: relative; overflow: hidden; }
.view { display: none; position: absolute; inset: 0; }
.view.active { display: block; animation: viewIn .22s ease both; }
#view-map.active { display: flex; flex-direction: column; }
@keyframes viewIn { from { opacity: .4; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.page-view { overflow-y: auto; overscroll-behavior: contain; }
.page { padding: 18px 16px 30px; max-width: 620px; margin: 0 auto; }
.page-head { display: flex; align-items: flex-start; gap: 12px; margin: 2px 2px 16px; }
.page-head h1 { margin: 0; font-size: 25px; letter-spacing: -.6px; line-height: 1.15; font-weight: 800; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.page-head > :last-child { margin-left: auto; flex: none; }

.tabbar {
  flex: none;
  height: var(--tab-h);
  padding: 6px 8px calc(var(--safe-bottom) + 5px);
  display: flex;
  background: var(--glass);
  backdrop-filter: blur(18px) saturate(1.2);
  -webkit-backdrop-filter: blur(18px) saturate(1.2);
  border-top: 1px solid var(--line);
  position: relative;
  z-index: 6;
}
.tab {
  flex: 1;
  height: 50px;
  border-radius: 14px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted);
  font-size: 9.5px; font-weight: 650; letter-spacing: .15px;
  transition: color .15s ease, background .15s ease;
}
.tab .icon { width: 21px; height: 21px; }
.tab.active { color: var(--primary); background: var(--primary-soft); }
.tab:active { transform: scale(.97); }

/* ---------------- map ---------------- */
.map-shell {
  position: relative; flex: 1; min-height: 0;
  overflow: hidden;
  background: var(--map-bg);
}
#mapCanvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
.map-top {
  position: absolute; top: 10px; left: 12px; right: 12px;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  pointer-events: none; z-index: 2;
}
.hud-chip {
  pointer-events: auto;
  height: 34px; padding: 0 12px;
  display: inline-flex; align-items: center; gap: 7px;
  border-radius: 999px;
  background: var(--glass);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,.55);
  box-shadow: var(--shadow-sm);
  color: var(--text-2);
  font-size: 11.5px; font-weight: 650;
  white-space: nowrap;
  max-width: 62%;
  overflow: hidden;
}
:root[data-theme="dark"] .hud-chip { border-color: rgba(255,255,255,.08); }
.hud-chip .icon { width: 16px; height: 16px; color: var(--primary); }
.hud-chip:active { transform: scale(.97); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
.hud-chip.live .status-dot { background: var(--accent); box-shadow: 0 0 0 3px rgba(0,176,199,.18); animation: pulse 2.4s infinite; }
.hud-chip.stale .status-dot { background: var(--warn); }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 3px rgba(0,176,199,.16); } 50% { box-shadow: 0 0 0 6px rgba(0,176,199,0); } }
.icon-chip { max-width: none; }
#mapStatusText { overflow: hidden; text-overflow: ellipsis; }

.map-bottom {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 10px 12px 12px;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  pointer-events: none;
  z-index: 3;
  background: linear-gradient(180deg, transparent, rgba(231, 240, 244, .5) 40%, rgba(231, 240, 244, .85));
}
:root[data-theme="dark"] .map-bottom { background: linear-gradient(180deg, transparent, rgba(8,28,36,.5) 40%, rgba(8,28,36,.9)); }
.map-legend, .timebar, .tool-dock { pointer-events: auto; }
.map-legend {
  align-self: flex-start;
  width: 158px;
  padding: 9px 11px 8px;
  border-radius: 13px;
  background: var(--glass);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255,255,255,.5);
  box-shadow: var(--shadow-sm);
  font-size: 9.5px; color: var(--text-2);
}
:root[data-theme="dark"] .map-legend { border-color: rgba(255,255,255,.07); }
.legend-title { display: flex; justify-content: space-between; align-items: baseline; font-weight: 700; font-size: 10px; color: var(--text); margin-bottom: 4px; }
.legend-title span { font-weight: 500; color: var(--muted); font-size: 9px; }
.legend-bar { height: 6px; border-radius: 99px; border: 1px solid rgba(0,0,0,.05); }
.legend-scale { display: flex; justify-content: space-between; margin-top: 2px; color: var(--muted); font-size: 8.5px; }
.legend-item + .legend-item { margin-top: 8px; }

.timebar {
  width: 100%;
  padding: 7px 12px 8px;
  border-radius: 14px;
  background: var(--glass);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255,255,255,.5);
  box-shadow: var(--shadow-md);
}
:root[data-theme="dark"] .timebar { border-color: rgba(255,255,255,.07); }
.timebar-top { display: flex; align-items: center; gap: 8px; }
#timebarLabel { font-size: 13px; font-weight: 800; letter-spacing: -.1px; font-variant-numeric: tabular-nums; }
.timebar-meta { flex: 1; color: var(--muted); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-btn {
  width: 28px; height: 28px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--primary); color: #fff;
  box-shadow: 0 3px 8px rgba(8,122,150,.3);
}
.mini-btn .icon { width: 14px; height: 14px; }
.mini-btn:active { transform: scale(.93); }
.timebar .range { margin-top: 4px; }

.tool-dock {
  display: flex; gap: 2px;
  padding: 5px;
  border-radius: 18px;
  background: var(--glass);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255,255,255,.55);
  box-shadow: var(--shadow-md);
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
  overscroll-behavior-x: contain;
}
.tool-dock::-webkit-scrollbar { display: none; }
.tool {
  flex: none;
  width: 42px; height: 48px;
  border-radius: 13px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--text-2);
  transition: background .14s ease, color .14s ease, transform .1s ease;
}
.tool .icon { width: 20px; height: 20px; }
.tool span { font-size: 8.4px; font-weight: 650; letter-spacing: .05px; }
.tool:hover { background: var(--surface-2); }
.tool:active { transform: scale(.94); }
.tool.active { background: linear-gradient(150deg, var(--primary), var(--primary-strong)); color: #fff; box-shadow: 0 5px 14px rgba(8,122,150,.32); }
.tool.active span { color: rgba(255,255,255,.9); }
.tool-sep { margin-left: 4px; border-left: 1px solid var(--line); border-radius: 0 13px 13px 0; }
:root[data-theme="dark"] .tool.active { box-shadow: 0 5px 16px rgba(0,0,0,.4); }

.map-empty {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 30px 26px 150px;
  text-align: center;
  background: radial-gradient(400px 300px at 50% 40%, var(--bg-soft), transparent 75%);
  pointer-events: none;
}
.empty-icon {
  width: 66px; height: 66px; border-radius: 22px;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(145deg, var(--accent), var(--primary-strong));
  box-shadow: 0 14px 30px rgba(8,122,150,.28);
  margin-bottom: 16px;
}
.empty-icon .icon { width: 34px; height: 34px; }
.map-empty h2 { margin: 0 0 6px; font-size: 20px; letter-spacing: -.3px; }
.map-empty p { margin: 0 0 18px; max-width: 280px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }
.empty-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; pointer-events: auto; }

/* ---------------- generic UI ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: 999px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .2px;
  background: var(--surface-3); color: var(--text-2);
  white-space: nowrap;
}
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.badge.live { background: var(--primary-soft); color: var(--primary); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px;
  margin-bottom: 13px;
}
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h3 { margin: 0; font-size: 14px; font-weight: 750; letter-spacing: -.1px; }
.card-head .sub { color: var(--muted); font-size: 11px; margin-top: 1px; }
.card-head > :last-child { margin-left: auto; }
.card-title { margin: 0 0 4px; font-size: 14px; font-weight: 750; }
.muted { color: var(--muted); }
.tiny { font-size: 10.5px; line-height: 1.4; }
.hint { margin: 10px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }

.btn {
  height: 44px; padding: 0 16px;
  border-radius: 13px;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-size: 13px; font-weight: 700; letter-spacing: .05px;
  white-space: nowrap;
  transition: transform .1s ease, filter .15s ease, background .15s ease;
}
.btn .icon { width: 18px; height: 18px; }
.btn:active { transform: scale(.975); }
.btn-primary { background: linear-gradient(150deg, var(--primary), var(--primary-strong)); color: #fff; box-shadow: 0 7px 18px rgba(8,122,150,.25); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: var(--surface-2); color: var(--text-2); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { filter: brightness(.98); }
.btn-block { width: 100%; }
.btn-sm { height: 34px; padding: 0 11px; font-size: 11.5px; border-radius: 10px; }
.btn:disabled { opacity: .55; pointer-events: none; }
.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label, .field-label { font-size: 11px; font-weight: 650; color: var(--muted); letter-spacing: .15px; }
.input, .select, .field input, .field select {
  width: 100%; height: 45px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  padding: 0 12px;
  font-size: 14px; font-weight: 550;
  color: var(--text);
  outline: none;
  transition: border .15s ease, box-shadow .15s ease, background .15s ease;
}
.field input:focus, .field select:focus, .input:focus, .select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8,122,150,.13);
  background: var(--surface);
}
.field .hint { margin: 0; font-size: 10px; }
select.select, .field select {
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 16px) 20px, calc(100% - 11px) 20px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.form-grid .full { grid-column: 1 / -1; }
.divider { height: 1px; background: var(--line); margin: 14px 0; }

.segmented {
  display: flex; gap: 3px; padding: 3px;
  background: var(--surface-3); border-radius: 12px;
  margin: 12px 0;
}
.segmented button {
  flex: 1; height: 34px; border-radius: 9px;
  font-size: 11.5px; font-weight: 700; color: var(--muted);
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.segmented button.active { background: var(--surface); color: var(--primary); box-shadow: 0 2px 7px rgba(8,42,56,.08); }

.range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; background: transparent; outline: none;
  margin: 0;
}
.range::-webkit-slider-runnable-track { height: 5px; border-radius: 99px; background: var(--surface-3); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; margin-top: -7.5px;
  border-radius: 50%; background: var(--primary);
  border: 3px solid var(--surface);
  box-shadow: 0 2px 7px rgba(8,42,56,.28);
}
.range::-moz-range-track { height: 5px; border-radius: 99px; background: var(--surface-3); }
.range::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--primary); border: 3px solid var(--surface); }

/* ---------------- results ---------------- */
.kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 13px; }
.kpi {
  background: var(--surface); border: 1px solid var(--line); border-radius: 15px;
  padding: 12px 13px 11px; box-shadow: var(--shadow-sm); min-width: 0;
}
.kpi .k-label { font-size: 9.5px; font-weight: 700; letter-spacing: .55px; text-transform: uppercase; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .k-value { font-size: 23px; font-weight: 800; letter-spacing: -.7px; margin-top: 3px; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi .k-value small { font-size: 11px; font-weight: 650; letter-spacing: 0; color: var(--muted); margin-left: 4px; }
.kpi .k-sub { color: var(--muted); font-size: 10px; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.good .k-value { color: var(--ok); }
.kpi.warn .k-value { color: var(--warn); }
.kpi.bad .k-value { color: var(--danger); }
.kpi.info .k-value { color: var(--primary); }

.run-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin-bottom: 12px; }
.run-options .field > label { font-size: 10px; }
.run-options .field input, .run-options .field select { height: 42px; font-size: 13px; padding: 0 10px; }
.run-status { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.run-status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.run-status .dot.ok { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-soft); }
.run-status .dot.warn { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); }
.run-status .dot.bad { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
.run-status div { min-width: 0; }
.run-status strong { display: block; font-size: 12.5px; font-weight: 700; }
.run-status span { display: block; color: var(--muted); font-size: 10.5px; margin-top: 1px; }

.time-card { display: flex; flex-direction: column; gap: 6px; }
.time-head { display: flex; align-items: center; gap: 10px; }
.time-big { font-size: 26px; font-weight: 800; letter-spacing: -.8px; font-variant-numeric: tabular-nums; line-height: 1; }
.time-sub { color: var(--muted); font-size: 10.5px; line-height: 1.35; flex: 1; }
.time-actions { display: flex; gap: 6px; }

.chart-wrap { position: relative; width: 100%; height: 190px; margin-top: 4px; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }
.chart-head { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.chart-head h3 { margin: 0; font-size: 14px; font-weight: 750; }
.chart-head select { height: 32px; border-radius: 9px; border: 1px solid var(--line); background: var(--surface-2); font-size: 11px; padding: 0 24px 0 9px; max-width: 130px; appearance: none; }
.chart-legend { display: flex; gap: 12px; color: var(--muted); font-size: 10px; margin-top: 6px; }
.chart-legend i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: 4px; }

.critical-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.critical-row:last-child { border-bottom: 0; padding-bottom: 2px; }
.critical-name { width: 62px; font-size: 11.5px; font-weight: 700; flex: none; overflow: hidden; text-overflow: ellipsis; }
.critical-bar { flex: 1; height: 7px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.critical-bar i { display: block; height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--danger), #f6a623); }
.critical-val { width: 64px; text-align: right; font-size: 11px; font-weight: 650; font-variant-numeric: tabular-nums; flex: none; }
.critical-val small { color: var(--muted); font-weight: 500; }

.warning-row { display: flex; gap: 9px; align-items: flex-start; padding: 7px 0; font-size: 11.5px; line-height: 1.45; color: var(--text-2); border-bottom: 1px solid var(--line); }
.warning-row:last-child { border-bottom: 0; }
.warning-row .icon { width: 16px; height: 16px; color: var(--warn); margin-top: 1px; }

.empty-state { text-align: center; padding: 34px 20px 28px; }
.empty-state .icon-wrap {
  width: 58px; height: 58px; border-radius: 19px; margin: 0 auto 12px;
  display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary);
}
.empty-state .icon-wrap .icon { width: 28px; height: 28px; }
.empty-state h3 { margin: 0 0 4px; font-size: 15px; }
.empty-state p { margin: 0 auto 14px; color: var(--muted); font-size: 11.5px; line-height: 1.5; max-width: 270px; }

/* ---------------- data ---------------- */
.stat-strip {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  padding: 11px 4px;
  margin-bottom: 13px;
}
.stat { flex: 1; text-align: center; padding: 0 4px; border-right: 1px solid var(--line); min-width: 0; }
.stat:last-child { border-right: 0; }
.stat b { display: block; font-size: 16px; font-weight: 800; letter-spacing: -.3px; font-variant-numeric: tabular-nums; }
.stat span { display: block; color: var(--muted); font-size: 8.8px; text-transform: uppercase; letter-spacing: .45px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.search-box { position: relative; margin-bottom: 2px; }
.search-box .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--muted); }
.search-box input {
  width: 100%; height: 44px; border-radius: 13px;
  border: 1px solid var(--line); background: var(--surface);
  padding: 0 12px 0 37px; font-size: 13px; outline: none;
}
.search-box input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(8,122,150,.12); }

.data-list { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-sm); }
.data-row {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 13px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background .13s ease;
}
.data-row:last-child { border-bottom: 0; }
.data-row:hover { background: var(--surface-2); }
.data-row:active { background: var(--surface-3); }
.row-icon {
  width: 34px; height: 34px; border-radius: 11px; flex: none;
  display: grid; place-items: center;
  background: var(--surface-3); color: var(--text-2);
}
.row-icon .icon { width: 17px; height: 17px; }
.row-icon.junction { background: var(--primary-soft); color: var(--primary); }
.row-icon.reservoir { background: #e5efff; color: #2f6dc4; }
.row-icon.tank { background: #e7f4ff; color: #247fa8; }
.row-icon.pipe { background: var(--surface-3); color: var(--text-2); }
.row-icon.pump { background: #f0ecff; color: #5f51b5; }
.row-icon.valve { background: var(--warn-soft); color: var(--warn); }
:root[data-theme="dark"] .row-icon.reservoir { background: #14304d; color: #78b1ff; }
:root[data-theme="dark"] .row-icon.tank { background: #12384a; color: #78cbec; }
:root[data-theme="dark"] .row-icon.pump { background: #2b2851; color: #b2a8ff; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-size: 13px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-sub { font-size: 10px; color: var(--muted); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-value { text-align: right; flex: none; }
.row-value b { display: block; font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.row-value span { display: block; font-size: 8.8px; color: var(--muted); text-transform: uppercase; letter-spacing: .35px; margin-top: 1px; }
.row-chevron { color: var(--line-strong); flex: none; }
.row-chevron .icon { width: 15px; height: 15px; }
.list-empty { padding: 30px 18px; text-align: center; color: var(--muted); font-size: 12px; line-height: 1.5; }

/* ---------------- more ---------------- */
.project-hero {
  position: relative;
  border-radius: 20px;
  padding: 18px;
  margin-bottom: 13px;
  color: #fff;
  background:
    radial-gradient(180px 100px at 90% 10%, rgba(117, 228, 244, .32), transparent 70%),
    linear-gradient(135deg, #06384a, #075d74 60%, #0a8aa3);
  box-shadow: 0 12px 30px rgba(5, 48, 64, .22);
  overflow: hidden;
}
.project-hero::after {
  content: ""; position: absolute; right: -24px; bottom: -38px;
  width: 130px; height: 130px; border-radius: 50%;
  border: 22px solid rgba(255,255,255,.07);
}
.project-hero .hero-label { font-size: 9.5px; text-transform: uppercase; letter-spacing: .8px; color: rgba(255,255,255,.65); font-weight: 700; }
.project-hero input {
  width: 100%; background: transparent; border: 0; outline: none;
  color: #fff; font-size: 21px; font-weight: 800; letter-spacing: -.4px;
  padding: 2px 0 4px; border-bottom: 1px dashed rgba(255,255,255,.25);
}
.project-hero .hero-meta { font-size: 10.5px; color: rgba(255,255,255,.72); margin-top: 5px; position: relative; z-index: 1; }
.project-hero .hero-stats { display: flex; gap: 18px; margin-top: 13px; position: relative; z-index: 1; }
.project-hero .hero-stats b { display: block; font-size: 17px; font-weight: 800; }
.project-hero .hero-stats span { display: block; font-size: 9px; color: rgba(255,255,255,.65); text-transform: uppercase; letter-spacing: .5px; }

.menu-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-sm); margin-bottom: 13px; }
.menu-row {
  width: 100%; display: flex; align-items: center; gap: 11px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  transition: background .13s ease;
}
.menu-row:last-child { border-bottom: 0; }
.menu-row:hover { background: var(--surface-2); }
.menu-row:active { background: var(--surface-3); }
.menu-row .row-icon { width: 32px; height: 32px; }
.menu-row .row-icon .icon { width: 16px; height: 16px; }
.menu-main { flex: 1; min-width: 0; }
.menu-title { font-size: 12.5px; font-weight: 650; }
.menu-sub { font-size: 10px; color: var(--muted); margin-top: 1px; line-height: 1.35; }
.menu-row .row-chevron .icon { width: 15px; height: 15px; }
.switch { width: 40px; height: 24px; border-radius: 99px; background: var(--surface-3); position: relative; transition: background .18s ease; flex: none; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .18s ease; }
.switch.on { background: var(--primary); }
.switch.on::after { transform: translateX(16px); }
.more-footer { text-align: center; color: var(--muted); font-size: 10px; line-height: 1.6; padding: 6px 20px 10px; }
.more-footer b { color: var(--text-2); }

/* ---------------- sheets ---------------- */
.sheet-layer { position: fixed; inset: 0; z-index: 100; pointer-events: none; }
.sheet-layer.open { pointer-events: auto; }
.sheet-scrim {
  position: absolute; inset: 0;
  background: rgba(4, 21, 28, .48);
  backdrop-filter: blur(2px);
  opacity: 0; transition: opacity .25s ease;
}
.sheet-layer.open .sheet-scrim { opacity: 1; }
.sheet {
  position: absolute; left: 50%; bottom: 0;
  width: 100%; max-width: 600px;
  max-height: 92vh; max-height: 92dvh;
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -18px 50px rgba(4, 21, 28, .28);
  transform: translate(-50%, 104%);
  transition: transform .3s cubic-bezier(.2, .8, .2, 1);
  display: flex; flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-bottom: 0;
}
.sheet-layer.open .sheet { transform: translate(-50%, 0); }
.sheet-handle { width: 40px; height: 4px; border-radius: 99px; background: var(--line-strong); margin: 9px auto 2px; flex: none; }
#sheetContent { overflow-y: auto; overscroll-behavior: contain; padding: 4px 18px calc(18px + var(--safe-bottom)); }
.sheet-head { display: flex; align-items: center; gap: 11px; padding: 8px 0 14px; }
.sheet-head .row-icon { width: 42px; height: 42px; border-radius: 13px; }
.sheet-head .row-icon .icon { width: 21px; height: 21px; }
.sheet-title { font-size: 18px; font-weight: 800; letter-spacing: -.25px; line-height: 1.2; }
.sheet-sub { font-size: 10.5px; color: var(--muted); margin-top: 2px; }
.sheet-close { margin-left: auto; }
.sheet-body { padding-bottom: 4px; }
.sheet-actions { display: flex; gap: 8px; padding-top: 14px; }
.sheet-actions .btn { flex: 1; }
.sheet-actions .btn.icon-only { flex: none; width: 46px; padding: 0; }
.metric-box {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 13px; padding: 11px 12px; margin: 12px 0 2px;
}
.metric-box .metric { min-width: 0; }
.metric-box .m-label { font-size: 9px; text-transform: uppercase; letter-spacing: .45px; color: var(--muted); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric-box .m-value { font-size: 14px; font-weight: 750; margin-top: 2px; font-variant-numeric: tabular-nums; }
.metric-box .m-value small { font-size: 9.5px; font-weight: 600; color: var(--muted); margin-left: 2px; }
.endpoint-row { display: flex; align-items: center; gap: 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 9px 11px; font-size: 12px; }
.endpoint-row .node-pill { font-weight: 700; color: var(--primary); }
.endpoint-row .arrow { color: var(--muted); }
.endpoint-row .swap { margin-left: auto; }

.sheet-list { display: flex; flex-direction: column; }
.sheet-list .menu-row { border-radius: 0; padding: 13px 2px; }
.sheet-list .menu-row:first-child { padding-top: 6px; }
.sheet-list .menu-row:last-child { border-bottom: 0; }
.sheet-list .row-icon { width: 38px; height: 38px; border-radius: 12px; }
.sheet-list .menu-title { font-size: 13.5px; }
.sheet-list .menu-sub { font-size: 10.5px; }

.confirm-body { color: var(--text-2); font-size: 13px; line-height: 1.55; padding: 2px 2px 4px; }
.confirm-body strong { color: var(--text); }
.sheet-note { background: var(--warn-soft); color: var(--warn); border-radius: 12px; padding: 10px 12px; font-size: 11px; line-height: 1.45; margin-top: 10px; }
.sheet-note.bad { background: var(--danger-soft); color: var(--danger); }

/* ---------------- toast ---------------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + 14px);
  transform: translate(-50%, 12px);
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 16px;
  background: #0a2a35;
  color: #f2fbfd;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 13px;
  font-size: 11.5px; font-weight: 550; line-height: 1.4;
  box-shadow: 0 10px 28px rgba(0,0,0,.3);
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 200;
  text-align: left;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast b { font-weight: 750; }
:root[data-theme="dark"] .toast { background: #dff5fa; color: #062633; }

/* ---------------- desktop frame ---------------- */
@media (min-width: 720px) {
  body { padding: 18px; }
  #app {
    height: calc(100vh - 36px); height: calc(100dvh - 36px);
    border-radius: 28px;
    box-shadow: 0 40px 100px rgba(6, 38, 50, .32), 0 0 0 1px rgba(255,255,255,.4);
  }
  .appbar { padding-top: 10px; }
  .brand-sub { max-width: 260px; }
  .map-empty { padding-bottom: 120px; }
}
@media (max-width: 380px) {
  .tool { width: 39px; }
  .tool span { font-size: 7.8px; }
  .kpi .k-value { font-size: 21px; }
  .run-options { gap: 7px; }
  .brand-sub { max-width: 160px; }
  .timebar-meta { display: none; }
}
@media (max-width: 340px) {
  .tool { width: 34px; height: 42px; }
  .tool-dock { gap: 0; }
  .tool span { display: none; }
  .tool .icon { width: 18px; height: 18px; }
  .map-legend { width: 140px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
::selection { background: rgba(0,176,199,.25); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
