/* ============================================================
   GeoPWA — Tokyo Night palette (mobile-first)
   ============================================================ */
:root {
  /* Tokyo Night core */
  --bg: #1a1b26;
  --bg-dark: #16161e;
  --bg-highlight: #292e42;
  --bg-terminal: #414868;
  --fg: #c0caf5;
  --fg-dark: #a9b1d6;
  --comment: #565f89;

  /* Accents */
  --blue: #7aa2f7;
  --cyan: #7dcfff;
  --green: #9ece6a;
  --magenta: #bb9af7;
  --red: #f7768e;
  --yellow: #e0af68;
  --orange: #ff9e64;
  --teal: #1abc9c;

  /* Semantic */
  --ok: var(--green);
  --warn: var(--yellow);
  --err: var(--red);

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 24px rgba(0, 0, 0, .45);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */
.app-header {
  position: relative;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + var(--safe-t)) 14px 10px;
  background: var(--bg-dark);
  border-bottom: 1px solid var(--bg-highlight);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--bg-highlight);
  flex: none;
}

.brand-text h1 {
  margin: 0;
  font-size: 1.15rem;
  line-height: 1.1;
  letter-spacing: .3px;
  color: var(--fg);
}

.brand-text p {
  margin: 2px 0 0;
  font-size: .72rem;
  color: var(--comment);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Status badge ---------- */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--bg-highlight);
  border: 1px solid var(--bg-terminal);
  font-size: .78rem;
  font-weight: 600;
  color: var(--fg-dark);
  flex: none;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--comment);
  box-shadow: 0 0 0 0 rgba(158, 206, 106, .6);
}

.status-badge[data-state="locating"] .status-dot {
  background: var(--yellow);
  animation: pulse 1.2s infinite;
}
.status-badge[data-state="tracking"] .status-dot {
  background: var(--green);
  animation: pulse 1.6s infinite;
}
.status-badge[data-state="arrived"] .status-dot {
  background: var(--cyan);
  animation: pulse .9s infinite;
}
.status-badge[data-state="error"] .status-dot { background: var(--red); }

@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(158, 206, 106, .55); }
  70%  { box-shadow: 0 0 0 10px rgba(158, 206, 106, 0); }
  100% { box-shadow: 0 0 0 0 rgba(158, 206, 106, 0); }
}

/* ---------- Main / Map ---------- */
.app-main {
  position: relative;
  height: calc(100% - 65px - var(--safe-t));
}

.map {
  position: absolute;
  inset: 0;
  background: var(--bg-dark);
  z-index: 1;
}

/* ---------- Controls ---------- */
.controls {
  position: absolute;
  z-index: 1300;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(300px + var(--safe-b));
  display: flex;
  gap: 10px;
  padding: 8px;
  border-radius: 999px;
  background: rgba(22, 22, 30, .82);
  backdrop-filter: blur(10px);
  border: 1px solid var(--bg-highlight);
  box-shadow: var(--shadow);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  cursor: pointer;
  padding: 11px 16px;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--bg);
  background: var(--fg);
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.95); }
.btn-ico { font-size: 1rem; line-height: 1; }

.btn-primary { background: var(--blue); }
.btn-accent  { background: var(--green); }
.btn-warn    { background: var(--yellow); }
.btn-accent[aria-pressed="true"] {
  background: var(--red);
  color: #fff;
  box-shadow: 0 0 0 2px rgba(247, 118, 142, .35);
}

/* ---------- Panel ---------- */
.panel {
  position: absolute;
  z-index: 1100;
  left: 12px;
  right: 12px;
  bottom: calc(12px + var(--safe-b));
  background: rgba(26, 27, 38, .92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--bg-highlight);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
}

.panel-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 3px;
  background: var(--bg-highlight);
  border: 1px solid var(--bg-terminal);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  min-width: 0;
}
.stat-wide { grid-column: 1 / -1; }

.stat-label {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--comment);
  font-weight: 700;
}
.stat-value {
  font-size: .95rem;
  font-weight: 600;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hint {
  margin: 12px 2px 0;
  font-size: .76rem;
  line-height: 1.4;
  color: var(--comment);
}
.hint b { color: var(--cyan); font-weight: 700; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  z-index: 2000;
  left: 50%;
  top: calc(72px + var(--safe-t));
  transform: translateX(-50%);
  max-width: min(92vw, 420px);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: var(--bg-highlight);
  border: 1px solid var(--red);
  color: var(--fg);
  font-size: .85rem;
  line-height: 1.35;
  box-shadow: var(--shadow);
}
.toast[data-kind="ok"]   { border-color: var(--green); }
.toast[data-kind="warn"] { border-color: var(--yellow); }
.toast[data-kind="info"] { border-color: var(--cyan); }

/* ---------- Leaflet marker (pulsing dot) ---------- */
.geo-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--blue);
  border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(122, 162, 247, .25);
}
.dest-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--red);
  border: 3px solid #fff;
  box-shadow: 0 0 0 6px rgba(247, 118, 142, .25);
}

/* Leaflet tiles tint to match dark theme */
.leaflet-tile-pane { filter: brightness(.92) contrast(1.05) saturate(.9); }
.leaflet-container { background: var(--bg-dark); font-family: inherit; }
.leaflet-control-zoom a {
  background: var(--bg-highlight) !important;
  color: var(--fg) !important;
  border-color: var(--bg-terminal) !important;
}
.leaflet-control-attribution {
  background: rgba(22, 22, 30, .7) !important;
  color: var(--comment) !important;
}
.leaflet-control-attribution a { color: var(--cyan) !important; }

/* ---------- Responsive (tablet / desktop) ---------- */
@media (min-width: 720px) {
  .app-main { height: calc(100% - 69px - var(--safe-t)); }
  .controls { bottom: calc(210px + var(--safe-b)); }
  .panel { left: auto; right: 16px; width: 340px; bottom: calc(16px + var(--safe-b)); }
  .panel-grid { grid-template-columns: repeat(2, 1fr); }
  .brand-text h1 { font-size: 1.3rem; }
}

@media (prefers-reduced-motion: reduce) {
  .status-dot, .btn { animation: none !important; transition: none !important; }
}