:root {
  --bg: #0b1a2b;
  --panel: #12293f;
  --panel-light: #24435f;
  --accent: #38bdf8;
  --accent-dim: #0284c7;
  --text: #e8eef5;
  --text-dim: #93a7bc;
  --danger: #ef4444;
  --green: #22c55e;
  --r-lg: 18px;
  --r-md: 14px;
  --r-sm: 10px;
  --nav-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --shadow: 0 6px 24px rgba(0,0,0,.38);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}
a { color: var(--accent); text-decoration: none; }

/* ---------- Map ---------- */
#map {
  position: fixed;
  inset: 0 0 calc(var(--nav-h) + var(--safe-b)) 0;
  z-index: 1;
  background: #0a1622;
}

/* ---------- Floating icon buttons ---------- */
.icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: rgba(18,41,63,.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,.10);
  color: var(--text);
  font-size: 19px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.icon-btn:active { transform: scale(.94); }
.icon-btn.on { background: var(--accent-dim); border-color: var(--accent); color: #fff; }

.top-left  { position: fixed; top: calc(var(--safe-t) + 10px); left: 12px;  z-index: 700; }
.top-right { position: fixed; top: calc(var(--safe-t) + 10px); right: 12px; z-index: 700;
             display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }

/* ---------- Layers pill (bottom-left) ---------- */
.layers-btn {
  position: fixed;
  left: 12px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  z-index: 700;
  display: flex; align-items: center; gap: 7px;
  padding: 9px 14px;
  border-radius: 99px;
  background: rgba(18,41,63,.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,.10);
  color: var(--text);
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.layers-btn:active { transform: scale(.96); }

/* ---------- REC button ---------- */
.fab {
  position: fixed;
  right: 14px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  width: 62px; height: 62px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  border: 3px solid rgba(255,255,255,.92);
  font-size: 13px; font-weight: 800; letter-spacing: .5px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(239,68,68,.45);
  z-index: 700;
  cursor: pointer;
}
.fab:active { transform: scale(.94); }
.fab.recording { animation: pulse 1.6s infinite; }
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(239,68,68,.55); }
  70%  { box-shadow: 0 0 0 16px rgba(239,68,68,0); }
  100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}

/* ---------- Bottom sheets ---------- */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(2px);
  z-index: 1100;
  opacity: 0; pointer-events: none;
  transition: opacity .22s;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 1200;
  background: var(--panel);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  border-top: 1px solid rgba(255,255,255,.10);
  padding: 10px 16px calc(20px + var(--safe-b));
  max-height: 78vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transform: translateY(100%);
  transition: transform .26s cubic-bezier(.32,.72,0,1);
  box-shadow: 0 -8px 32px rgba(0,0,0,.45);
}
.sheet.open { transform: translateY(0); }
.sheet .grabber {
  width: 38px; height: 4px; border-radius: 99px;
  background: var(--panel-light);
  margin: 4px auto 14px;
}
.sheet h2 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .9px;
  color: var(--text-dim); margin: 16px 0 8px;
}
.sheet h2:first-of-type { margin-top: 0; }

/* Toggle rows */
.opt {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 14px;
  border-radius: var(--r-md);
  background: rgba(255,255,255,.045);
  border: 1px solid transparent;
  margin-bottom: 8px;
  cursor: pointer;
}
.opt:active { background: rgba(255,255,255,.08); }
.opt.on { background: rgba(56,189,248,.16); border-color: var(--accent-dim); }
.opt .ico { font-size: 18px; width: 24px; text-align: center; }
.opt .txt { flex: 1; }
.opt .txt b { display: block; font-size: 14px; font-weight: 600; }
.opt .txt span { font-size: 11.5px; color: var(--text-dim); }
.opt .check { font-size: 15px; color: var(--accent); opacity: 0; }
.opt.on .check { opacity: 1; }

/* Segmented control (base map) */
.seg { display: flex; gap: 6px; background: rgba(255,255,255,.05); padding: 4px; border-radius: var(--r-md); }
.seg button {
  flex: 1; padding: 10px 6px;
  border: none; background: transparent;
  color: var(--text-dim); font-size: 13px; font-weight: 600;
  border-radius: var(--r-sm); cursor: pointer;
}
.seg button.on { background: var(--accent-dim); color: #fff; }

/* Safety accordion */
.acc { border-bottom: 1px solid rgba(255,255,255,.07); }
.acc:last-child { border-bottom: none; }
.acc-h {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 2px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.acc-h .chev { color: var(--text-dim); font-size: 17px; transition: transform .2s; }
.acc.open .acc-h .chev { transform: rotate(90deg); }
.acc-b { display: none; padding: 0 2px 14px; }
.acc.open .acc-b { display: block; }
.acc-b p { font-size: 13px; line-height: 1.55; color: var(--text); margin-bottom: 8px; }
.acc-b p:last-child { margin-bottom: 0; }
.acc-b b { color: var(--accent); }

/* ---------- Trip banner ---------- */
.trip-banner {
  position: fixed;
  top: calc(var(--safe-t) + 10px);
  left: 66px; right: 66px;
  background: rgba(18,41,63,.94);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--accent-dim);
  border-radius: var(--r-md);
  padding: 8px 12px;
  z-index: 650;
  display: none;
  box-shadow: var(--shadow);
}
.trip-banner.active { display: block; }
.trip-banner .trip-name {
  font-size: 11px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 3px;
}
.trip-banner .row { display: flex; gap: 16px; }
.trip-banner .label { font-size: 9.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .4px; }
.trip-banner .value { font-size: 17px; font-weight: 700; color: var(--accent); line-height: 1.15; }

/* ---------- Status chips ---------- */
.gps-status {
  position: fixed;
  left: 12px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 64px);
  display: flex; align-items: center; gap: 5px;
  font-size: 10.5px; color: var(--text-dim);
  background: rgba(18,41,63,.9);
  backdrop-filter: blur(10px);
  padding: 4px 10px; border-radius: 99px;
  border: 1px solid rgba(255,255,255,.08);
  z-index: 640;
}
.gps-status .dot { width: 6px; height: 6px; border-radius: 50%; }
.gps-status .dot.on { background: var(--green); box-shadow: 0 0 5px var(--green); }
.gps-status .dot.off { background: var(--text-dim); }
.gps-status .dot.error { background: var(--danger); }

.buffer-indicator {
  position: fixed;
  left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + var(--safe-b) + 64px);
  background: var(--danger); color: #fff;
  font-size: 10.5px; font-weight: 700;
  padding: 4px 11px; border-radius: 99px;
  z-index: 640; display: none;
}
.buffer-indicator.show { display: block; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: calc(var(--safe-t) + 66px); left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: rgba(18,41,63,.96);
  backdrop-filter: blur(12px);
  border: 1px solid var(--accent-dim);
  color: var(--text);
  padding: 9px 15px; border-radius: 99px;
  font-size: 12.5px; z-index: 1500;
  opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
  max-width: calc(100vw - 32px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Bottom nav ---------- */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex;
  background: rgba(11,26,43,.97);
  backdrop-filter: blur(16px);
  border-top: 1px solid rgba(255,255,255,.08);
  z-index: 1000;
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 10px;
  font-weight: 600; letter-spacing: .6px;
}
.bottom-nav a.active { color: var(--accent); }
.bottom-nav a .icon { font-size: 19px; margin-bottom: 2px; }

/* ---------- Pages ---------- */
.page { padding: calc(var(--safe-t) + 18px) 16px calc(var(--nav-h) + var(--safe-b) + 24px); }
.page h1 { font-size: 24px; font-weight: 700; margin-bottom: 16px; }

.card {
  background: var(--panel);
  border-radius: var(--r-md);
  padding: 15px;
  margin-bottom: 10px;
  border: 1px solid rgba(255,255,255,.07);
}
.card h3 { font-size: 15.5px; margin-bottom: 4px; }
.card .meta { font-size: 11.5px; color: var(--text-dim); margin-bottom: 10px; }
.card .stat { display: inline-block; margin-right: 18px; }
.card .stat .n { font-size: 19px; font-weight: 700; color: var(--accent); }
.card .stat .l { font-size: 10px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }

.badge {
  display: inline-block; font-size: 9.5px;
  padding: 3px 9px; border-radius: 99px;
  font-weight: 700; letter-spacing: .5px;
}

/* ---------- Leaflet overrides ---------- */
.leaflet-container { background: #0a1622; font-family: inherit; }
.leaflet-top.leaflet-right { top: calc(var(--safe-t) + 62px); }
.leaflet-top.leaflet-right .leaflet-control-zoom { margin-right: 12px; border: none; box-shadow: var(--shadow); }
.leaflet-control-zoom a {
  width: 44px !important; height: 40px !important;
  line-height: 40px !important; font-size: 19px !important;
  background: rgba(18,41,63,.92) !important;
  backdrop-filter: blur(12px);
  color: var(--text) !important;
  border: 1px solid rgba(255,255,255,.10) !important;
}
.leaflet-control-zoom a:first-child { border-radius: var(--r-md) var(--r-md) 0 0 !important; }
.leaflet-control-zoom a:last-child  { border-radius: 0 0 var(--r-md) var(--r-md) !important; border-top: none !important; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel) !important; color: var(--text) !important;
  border-radius: var(--r-md) !important;
}
.leaflet-popup-content { font-size: 13px; line-height: 1.5; }
.leaflet-control-attribution {
  background: rgba(11,26,43,.7) !important;
  color: var(--text-dim) !important; font-size: 9px !important;
}
.leaflet-control-attribution a { color: var(--text-dim) !important; }
.depth-label span { box-shadow: 0 1px 4px rgba(0,0,0,.35); }
