:root {
  --bg: #0A0B0D; --surface: #15171C; --surface-hi: #1E222A; --stroke: #2A2F3A;
  --text: #F5F7FA; --dim: #9AA3B2;
  --red: #FF2A3A; --green: #1FD17B; --amber: #FFB020;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
body { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px;
  border-bottom: 1px solid var(--stroke); background: rgba(10,11,13,.9); position: sticky; top: 0; z-index: 1000; backdrop-filter: blur(8px); }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo { background: var(--red); color: #fff; font-weight: 900; letter-spacing: 1px; padding: 10px 12px; border-radius: 12px; }
.who { font-size: 20px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { color: var(--dim); font-size: 13px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.pill { display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 999px; font-weight: 800; font-size: 14px;
  letter-spacing: .5px; border: 1px solid var(--stroke); background: var(--surface); white-space: nowrap; }
.pill i { width: 10px; height: 10px; border-radius: 50%; background: var(--dim); display: inline-block; }
.pill.live { color: var(--green); border-color: rgba(31,209,123,.5); background: rgba(31,209,123,.08); }
.pill.live i { background: var(--green); animation: pulse 1.4s infinite; }
.pill.wait { color: var(--amber); border-color: rgba(255,176,32,.5); background: rgba(255,176,32,.08); }
.pill.wait i { background: var(--amber); }
.pill.lost { color: var(--amber); border-color: rgba(255,176,32,.5); background: rgba(255,176,32,.08); }
.pill.lost i { background: var(--amber); animation: pulse 1s infinite; }
.pill.end { color: var(--red); border-color: rgba(255,42,58,.5); background: rgba(255,42,58,.08); }
.pill.end i { background: var(--red); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 currentColor; } 70% { box-shadow: 0 0 0 9px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.banner { padding: 10px 18px; background: rgba(255,176,32,.12); color: var(--amber); font-weight: 700; text-align: center; border-bottom: 1px solid var(--stroke); }
.banner.red { background: rgba(255,42,58,.14); color: #ff7480; }

.grid { display: grid; gap: 14px; padding: 14px; max-width: 1400px; margin: 0 auto;
  grid-template-columns: repeat(12, 1fr); }
.card { background: var(--surface); border: 1px solid var(--stroke); border-radius: 18px; padding: 14px; min-width: 0; }
.card-title { color: var(--dim); font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; font-weight: 700; margin-bottom: 10px; }
.map-card { grid-column: span 7; display: flex; flex-direction: column; }
.video-card { grid-column: span 5; }
#batteryCard, #medicalCard, #infoCard { grid-column: span 4; }
#map { flex: 1; min-height: 380px; border-radius: 12px; overflow: hidden; background: #111; }
.fallback { padding: 24px; color: var(--dim); text-align: center; }
.bar { display: flex; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.btn { background: var(--surface-hi); color: var(--text); border: 1px solid var(--stroke); border-radius: 12px; padding: 12px 16px;
  font-weight: 700; font-size: 14px; cursor: pointer; text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.btn:hover { border-color: #3b4252; }
.btn.ghost { background: transparent; }
.btn[hidden] { display: none; }

.video-wrap { position: relative; aspect-ratio: 4 / 3; background: #000; border-radius: 12px; overflow: hidden; }
.video-wrap video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 16px;
  color: var(--dim); background: rgba(0,0,0,.55); font-weight: 600; }
.overlay[hidden] { display: none; }
.live-badge { position: absolute; top: 10px; left: 10px; background: var(--red); color: #fff; font-weight: 900; font-size: 12px; padding: 5px 10px;
  border-radius: 8px; display: flex; align-items: center; gap: 6px; letter-spacing: 1px; }
.live-badge i { width: 8px; height: 8px; border-radius: 50%; background: #fff; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }

.big { font-size: 46px; font-weight: 900; line-height: 1; }
.batt-row { display: flex; align-items: baseline; gap: 12px; }
.meter { height: 14px; border-radius: 8px; background: var(--surface-hi); margin-top: 12px; overflow: hidden; }
.fill { height: 100%; width: 0; background: var(--green); transition: width .4s, background .4s; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; margin: 0; }
.kv dt { color: var(--dim); font-size: 13px; }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }
.kv dd.sub { grid-column: 1 / -1; font-weight: 400; }
.extra { margin-top: 12px; padding: 12px; border-radius: 12px; background: var(--surface-hi); font-weight: 700; }
.vehicle { font-size: 26px; letter-spacing: 2px; font-weight: 900; }

.ended { position: fixed; inset: 0; z-index: 2000; background: rgba(10,11,13,.96); display: flex; align-items: center; justify-content: center; padding: 24px; }
.ended[hidden] { display: none; }
.ended-box { max-width: 460px; text-align: center; }
.ended-icon { width: 72px; height: 72px; margin: 0 auto 18px; border-radius: 50%; background: rgba(255,42,58,.15); color: var(--red);
  display: flex; align-items: center; justify-content: center; font-size: 28px; }
.ended h1 { margin: 0 0 10px; font-size: 28px; }
.ended p { color: var(--dim); line-height: 1.5; }

.pulse-marker { width: 22px; height: 22px; border-radius: 50%; background: var(--red); border: 3px solid #fff; box-shadow: 0 0 0 0 rgba(255,42,58,.7); animation: ring 1.8s infinite; }
@keyframes ring { 70% { box-shadow: 0 0 0 16px rgba(255,42,58,0); } 100% { box-shadow: 0 0 0 0 rgba(255,42,58,0); } }
.leaflet-container { background: #0e1013; font-family: inherit; }
.leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9) saturate(.55); }

@media (max-width: 1000px) {
  .map-card, .video-card { grid-column: span 12; }
  #batteryCard, #medicalCard, #infoCard { grid-column: span 12; }
  #map { min-height: 300px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; } }
