:root {
  --bg: #0b0f14;
  --panel: #121821;
  --panel-2: #17202b;
  --line: #22303f;
  --text: #dfe7ef;
  --muted: #7c8ea0;
  --accent: #35d6a4;
  --accent-dim: #1b8f6b;
  --warn: #ffb020;
  --danger: #ff5d5d;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 14px/1.5 system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 11.5px; }
.mono { font-family: var(--mono); font-size: 12.5px; }
.spacer { flex: 1; }

/* ---------------------------------------------------------------- login -- */

.login {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(1200px 600px at 70% -10%, #14203000, #0b0f14), var(--bg);
}
.login-card {
  width: min(420px, 92vw); padding: 30px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 18px; display: grid; gap: 14px;
  box-shadow: 0 30px 80px -30px #000;
}
.login-card input {
  width: 100%; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text);
  font-family: var(--mono); font-size: 13px;
}
.login-card input:focus { outline: none; border-color: var(--accent-dim); }

.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: .3px; font-size: 16px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); }

.error { color: var(--danger); font-size: 12.5px; }

/* ------------------------------------------------------------------ app -- */

.app { height: 100%; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 18px; border-bottom: 1px solid var(--line);
  background: #0e141c; position: sticky; top: 0; z-index: 500;
}

.pill {
  font-size: 12px; padding: 5px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  white-space: nowrap;
}
.pill.ok { color: var(--accent); border-color: #1d5643; }
.pill.bad { color: var(--danger); border-color: #5a2424; }

.select {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 9px; padding: 7px 10px; font: inherit; font-size: 13px;
}

.grid {
  flex: 1; display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(330px, 1fr);
  gap: 14px; padding: 14px; overflow: auto;
}

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.panel h3 { margin: 0 0 12px; font-size: 12px; text-transform: uppercase; letter-spacing: 1.1px; color: var(--muted); font-weight: 600; }

.map-wrap { padding: 0; position: relative; overflow: hidden; min-height: 420px; }
#map { position: absolute; inset: 0; background: #0d1117; }
.map-overlay { position: absolute; top: 12px; left: 12px; z-index: 400; }

.seg { display: flex; gap: 2px; background: #131a23cc; padding: 3px; border-radius: 10px; border: 1px solid var(--line); backdrop-filter: blur(6px); }
.seg button {
  background: transparent; border: 0; color: var(--muted); padding: 5px 11px;
  border-radius: 8px; cursor: pointer; font: inherit; font-size: 12.5px;
}
.seg button.on { background: var(--panel-2); color: var(--text); }

.playbar {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 400;
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  background: #131a23dd; border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(6px);
}
.playbar input[type=range] { flex: 1; accent-color: var(--accent); }

.side { display: grid; gap: 14px; align-content: start; }

.kv { display: flex; justify-content: space-between; gap: 10px; padding: 4.5px 0; border-bottom: 1px dashed #1a2431; }
.kv:last-of-type { border-bottom: 0; }
.kv span { color: var(--muted); font-size: 12.5px; }
.kv b { font-weight: 600; text-align: right; }

.battery { position: relative; height: 26px; margin-top: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.battery-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent-dim), var(--accent)); transition: width .4s; }
.battery span { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; font-weight: 600; text-shadow: 0 1px 3px #000; }
.battery.low .battery-fill { background: linear-gradient(90deg, #7a3b12, var(--danger)); }

.actions { display: grid; gap: 8px; }

.btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; font: inherit; font-size: 13px;
  cursor: pointer; transition: .15s; text-align: center;
}
.btn:hover { border-color: #35506b; background: #1c2836; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: linear-gradient(180deg, #1f9d76, #177456); border-color: #1f9d76; color: #eafff7; font-weight: 600; }
.btn.primary:hover { background: linear-gradient(180deg, #23b286, #17805f); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 10px; font-size: 12px; }

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.list li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 7px 9px; background: var(--bg); border: 1px solid #1a2431; border-radius: 9px; }
.list li .grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list li button { background: transparent; border: 0; color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px; }
.list li button:hover { color: var(--danger); }

.events li { gap: 10px; }
.events li.warn { border-color: #4d3a12; background: #1b1608; }
.events li.sos { border-color: #5a2424; background: #1c0d0d; }
.events time { color: var(--muted); font-family: var(--mono); font-size: 11px; flex-shrink: 0; }

.geo-form { display: grid; grid-template-columns: 1fr 84px; gap: 7px; margin-top: 10px; }
.geo-form input { background: var(--bg); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 8px 10px; font: inherit; font-size: 12.5px; }
.geo-form input:focus { outline: none; border-color: var(--accent-dim); }
.geo-form button { grid-column: 1 / -1; }

.list li.audio-row { display: grid; gap: 6px; align-items: center; }
audio { width: 100%; height: 32px; }

/* Device manager rows */
.list li.dev-row { display: grid; gap: 7px; align-items: start; }
.list li.dev-row.on { border-color: var(--accent-dim); }
.dev-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; width: 100%; }
.dev-head b { font-size: 13px; }
.dev-head input {
  flex: 1; min-width: 120px; background: var(--bg); border: 1px solid var(--line);
  color: var(--text); border-radius: 8px; padding: 6px 8px; font: inherit; font-size: 12.5px;
}
.list li .actions { grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); }
.list li button.btn {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 6px 9px; font-size: 12px; line-height: 1.2;
}
.list li button.btn:hover { color: var(--text); border-color: var(--accent-dim); }
.pair-form { grid-template-columns: 1fr; }
.token-out {
  margin-top: 9px; padding: 8px 10px; background: #0f1a12; border: 1px solid #235c3a;
  border-radius: 9px; font-family: var(--mono); font-size: 12px; word-break: break-all;
}

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #16202b; border: 1px solid var(--line); color: var(--text);
  padding: 11px 18px; border-radius: 11px; z-index: 2000; font-size: 13px;
  box-shadow: 0 12px 40px -12px #000; animation: rise .25s ease-out;
}
.toast.bad { border-color: #5a2424; }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }

/* marker pulse */
.child-marker { position: relative; }
.child-marker .core { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 3px solid #0b0f14; box-shadow: 0 0 0 2px var(--accent); }
.child-marker.stale .core { background: var(--muted); box-shadow: 0 0 0 2px var(--muted); }
.child-marker::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 2px solid var(--accent); opacity: .5; animation: pulse 2.4s infinite; }
.child-marker.stale::after { animation: none; border-color: var(--muted); }
@keyframes pulse { 0% { transform: scale(.6); opacity: .7; } 100% { transform: scale(1.7); opacity: 0; } }

.leaflet-container { background: #0d1117; font: inherit; }
/* keyless OSM raster tiles, inverted into a dark basemap. Leaflet puts
   className on the tile container, not on each img. */
.basemap { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9) saturate(.75); }
.leaflet-control-zoom a { background: var(--panel) !important; color: var(--text) !important; border-color: var(--line) !important; }
.leaflet-popup-content-wrapper { background: var(--panel-2); color: var(--text); border-radius: 10px; }
.leaflet-popup-tip { background: var(--panel-2); }

@media (max-width: 1000px) {
  .grid { grid-template-columns: 1fr; }
  .map-wrap { min-height: 380px; }
}
