/* ============================================================
   PatiBul - Apple-Inspired Dark Theme
   ============================================================ */

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
  margin: 0; padding: 0; box-sizing: border-box;
}

:root {
  /* Colors - refined dark */
  --bg-primary: #0c0f1a;
  --bg-secondary: #141829;
  --bg-card: rgba(22, 27, 48, 0.65);
  --bg-card-solid: #161b30;
  --bg-glass: rgba(20, 24, 41, 0.72);
  --border-color: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --text-primary: #f1f3f9;
  --text-secondary: #9da4b8;
  --text-muted: #5b6178;
  --accent-1: #818cf8;
  --accent-2: #06b6d4;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;

  /* Spacing & Shape */
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 22px;
  --header-height: 52px;
  --mobile-bar-height: 54px;
  --transition: all 0.2s ease;

  /* Typography */
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;
}

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: var(--font-main);
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body { position: relative; }

/* ---------- Loading Screen ---------- */
#loading-screen {
  position: fixed; inset: 0;
  z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-primary);
}

.loader-content {
  text-align: center;
  animation: fadeUp 0.6s ease;
}

.loader-icon {
  margin-bottom: 20px;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.7; }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.loader-content h2 {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 6px;
  background: linear-gradient(135deg, #818cf8, #06b6d4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.loader-content p {
  font-size: 13px;
  color: var(--text-muted);
  letter-spacing: 0.2px;
}

#loading-screen.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  z-index: 6000;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
}

.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 32px;
  max-width: 380px;
  width: 90%;
  text-align: center;
}

.modal-icon {
  margin-bottom: 16px;
}

.modal-box h3 {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
  margin-bottom: 8px;
}

.modal-box p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.modal-actions {
  display: flex; gap: 10px;
}

.modal-actions .control-btn { flex: 1; }

/* ---------- Header ---------- */
#app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-height);
  padding: 0 16px;
  padding-top: env(safe-area-inset-top, 0px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(12, 15, 26, 0.82);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-bottom: 1px solid var(--border-color);
  z-index: 1000;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
}

.header-title h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.4px;
  background: linear-gradient(135deg, #818cf8, #06b6d4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-color);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

/* Style Switcher */
.style-switcher {
  display: flex;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  overflow: hidden;
}

.style-btn {
  width: 32px; height: 30px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}

.style-btn:hover { color: var(--text-secondary); }

.style-btn.active {
  background: rgba(129, 140, 248, 0.15);
  color: var(--accent-1);
}

/* Connection Badge */
.status-badge {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  letter-spacing: 0.1px;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}

.status-badge.online .status-dot { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-badge.online { border-color: rgba(52, 211, 153, 0.2); }
.status-badge.offline .status-dot { background: var(--danger); }

/* ---------- Map ---------- */
#map {
  position: fixed;
  inset: 0;
  top: var(--header-height);
  z-index: 1;
}

/* Leaflet overrides */
.leaflet-control-zoom {
  border: 1px solid var(--border-color) !important;
  border-radius: var(--radius-xs) !important;
  overflow: hidden;
  background: var(--bg-glass) !important;
  backdrop-filter: blur(12px) !important;
}

.leaflet-control-zoom a {
  background: transparent !important;
  color: var(--text-primary) !important;
  border-color: var(--border-color) !important;
  width: 32px !important;
  height: 32px !important;
  line-height: 32px !important;
  font-size: 16px !important;
}

.leaflet-control-zoom a:hover {
  background: rgba(255, 255, 255, 0.06) !important;
}

.leaflet-control-attribution {
  background: rgba(12, 15, 26, 0.6) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
  border-radius: 4px !important;
  padding: 2px 6px !important;
  backdrop-filter: blur(6px);
}

.leaflet-control-attribution a { color: var(--text-secondary) !important; }

/* ---------- Speed HUD ---------- */
.speed-hud {
  position: fixed;
  bottom: 20px;
  left: 16px;
  width: 56px; height: 56px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(12, 15, 26, 0.75);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border-color);
  z-index: 500;
}

#speed-value {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-2);
  line-height: 1;
}

.speed-unit {
  font-size: 9px;
  color: var(--text-muted);
  line-height: 1;
  margin-top: 1px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  padding: 10px 20px;
  background: var(--bg-card-solid);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: 24px;
  font-size: 13px;
  font-weight: 500;
  z-index: 5000;
  opacity: 0;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: none;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Sidebar ---------- */
#sidebar {
  position: fixed;
  top: var(--header-height);
  right: 0;
  bottom: 0;
  width: 360px;
  background: rgba(12, 15, 26, 0.88);
  backdrop-filter: blur(24px) saturate(1.3);
  -webkit-backdrop-filter: blur(24px) saturate(1.3);
  border-left: 1px solid var(--border-color);
  z-index: 999;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 20px 16px 100px;
  -webkit-overflow-scrolling: touch;
}

.sidebar-closed { transform: translateX(100%); }
.sidebar-open { transform: translateX(0); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.sidebar-header h2 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

/* Device Card */
.device-card {
  display: flex; align-items: center; gap: 12px;
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.device-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: rgba(129, 140, 248, 0.08);
  display: flex; align-items: center; justify-content: center;
  color: var(--accent-1);
  flex-shrink: 0;
}

.device-name {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.2px;
}

.device-type {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
  margin-top: 2px;
}

/* Filter Tabs */
.filter-tabs {
  display: flex;
  gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  padding: 3px;
  margin-bottom: 16px;
}

.filter-tab {
  flex: 1;
  padding: 7px 0;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-main);
  cursor: pointer;
  border-radius: 6px;
  transition: var(--transition);
}

.filter-tab:hover { color: var(--text-secondary); }

.filter-tab.active {
  background: var(--accent-1);
  color: #fff;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.stat-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.stat-card:hover {
  border-color: var(--border-hover);
}

.stat-card.wide {
  grid-column: 1 / -1;
}

.distance-to-device-card {
  background: linear-gradient(135deg, rgba(6, 182, 212, 0.06), rgba(129, 140, 248, 0.06));
  border-color: rgba(6, 182, 212, 0.15);
}

.stat-icon {
  width: 32px; height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.stat-content {
  display: flex; flex-direction: column;
  min-width: 0;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-top: 3px;
}

/* History */
.history-section {
  margin-bottom: 16px;
}

.history-section h3 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: -0.1px;
  margin-bottom: 10px;
}

.history-list {
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  -webkit-overflow-scrolling: touch;
}

.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
}

.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: var(--transition);
}

.history-item:hover {
  border-color: var(--border-hover);
  background: rgba(255, 255, 255, 0.03);
}

.history-coords {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
}

.history-time {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  margin-left: 8px;
}

.history-empty {
  text-align: center;
  padding: 24px 0;
  color: var(--text-muted);
  font-size: 13px;
}

/* Controls */
.controls-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  cursor: pointer;
  user-select: none;
}

.toggle-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  display: flex;
  align-items: center;
}

.toggle-input { display: none; }

.toggle-switch {
  width: 40px;
  height: 22px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  position: relative;
  flex-shrink: 0;
  transition: var(--transition);
}

.toggle-switch::after {
  content: '';
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-muted);
  position: absolute;
  top: 2px;
  left: 2px;
  transition: var(--transition);
}

.toggle-input:checked + .toggle-switch {
  background: var(--accent-1);
  border-color: var(--accent-1);
}

.toggle-input:checked + .toggle-switch::after {
  left: 20px;
  background: #fff;
}

.control-btn {
  width: 100%;
  padding: 11px 16px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.control-btn:hover {
  border-color: var(--border-hover);
  background: rgba(255, 255, 255, 0.04);
}

.control-btn.primary {
  background: rgba(129, 140, 248, 0.12);
  border-color: rgba(129, 140, 248, 0.2);
  color: var(--accent-1);
}

.control-btn.primary:hover {
  background: rgba(129, 140, 248, 0.2);
}

.control-btn.secondary {
  color: var(--text-secondary);
}

.location-btn {
  background: rgba(6, 182, 212, 0.08);
  border-color: rgba(6, 182, 212, 0.18);
  color: var(--accent-2);
}

.location-btn:hover {
  background: rgba(6, 182, 212, 0.16);
}

.navigate-btn {
  background: rgba(52, 211, 153, 0.08);
  border-color: rgba(52, 211, 153, 0.18);
  color: var(--success);
}

.navigate-btn:hover {
  background: rgba(52, 211, 153, 0.16);
}

.danger-btn {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.15);
}

.danger-btn:hover {
  background: rgba(248, 113, 113, 0.08);
}

.control-btn.danger {
  background: rgba(248, 113, 113, 0.12);
  border-color: rgba(248, 113, 113, 0.2);
  color: var(--danger);
}

/* ---------- Mobile Bottom Bar ---------- */
#mobile-bar {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 1001;
  background: rgba(12, 15, 26, 0.88);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border-top: 1px solid var(--border-color);
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
}

.mobile-bar-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mobile-bar-left {
  display: flex; align-items: center; gap: 8px;
  min-width: 0;
}

.mobile-bar-status {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}

#mobile-bar-text {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mobile-bar-btn {
  padding: 7px 14px;
  border-radius: 20px;
  border: none;
  background: var(--accent-1);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-main);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.mobile-bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-action-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.mobile-action-btn.locate {
  border-color: rgba(6, 182, 212, 0.25);
  color: var(--accent-2);
  background: rgba(6, 182, 212, 0.08);
}

.mobile-action-btn.navigate {
  border-color: rgba(52, 211, 153, 0.25);
  color: var(--success);
  background: rgba(52, 211, 153, 0.08);
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  :root {
    --header-height: calc(48px + env(safe-area-inset-top, 0px));
    --mobile-bar-height: calc(54px + env(safe-area-inset-bottom, 0px));
  }

  #app-header {
    padding: 0 12px;
    padding-top: env(safe-area-inset-top, 0px);
  }

  .status-badge .status-text { display: none; }
  .status-badge { padding: 5px 8px; min-width: 0; }

  .style-switcher { display: none; }

  #mobile-bar { display: block; }

  /* Sidebar on Mobile */
  #sidebar {
    width: 100%;
    top: var(--header-height);
    bottom: var(--mobile-bar-height);
    padding: 16px 14px 24px;
    border-left: none;
  }

  .sidebar-header {
    margin-top: 0;
    padding-top: 4px;
  }

  .stats-grid { gap: 6px; }

  .stat-card { padding: 10px; }

  .stat-value { font-size: 13px; }

  .stat-label { font-size: 9px; }

  .stat-icon {
    width: 28px; height: 28px;
    border-radius: 6px;
  }

  .stat-icon svg {
    width: 14px; height: 14px;
  }

  /* Speed HUD above mobile bar */
  .speed-hud {
    bottom: calc(var(--mobile-bar-height) + 10px);
    left: 12px;
    width: 50px; height: 50px;
  }

  #speed-value { font-size: 16px; }
  .speed-unit { font-size: 8px; }

  /* Toast above mobile bar */
  .toast {
    bottom: calc(var(--mobile-bar-height) + 12px);
    font-size: 12px;
    padding: 8px 16px;
  }

  /* Leaflet controls */
  .leaflet-control-zoom {
    margin-left: 10px !important;
  }

  .leaflet-control-attribution {
    margin-bottom: calc(var(--mobile-bar-height) + 4px) !important;
    margin-right: 8px !important;
  }

  .leaflet-bottom.leaflet-left {
    bottom: calc(var(--mobile-bar-height) + 4px);
  }

  .control-btn {
    padding: 10px 14px;
    font-size: 12px;
  }

  .history-list { max-height: 180px; }
}

/* Small screens */
@media (max-width: 380px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }

  .stat-card.wide {
    grid-column: 1;
  }

  .mobile-bar-btn {
    padding: 6px 10px;
    font-size: 11px;
  }
}

/* Scrollbar global */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.12);
}

/* ---------- Map Markers ---------- */

/* Device Pulse Marker */
.pulse-marker {
  position: relative;
}

.pulse-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #818cf8;
  border: 2.5px solid #fff;
  position: absolute;
  top: 0; left: 0;
  box-shadow: 0 0 8px rgba(129, 140, 248, 0.6);
  z-index: 3;
}

.pulse-ring {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid rgba(129, 140, 248, 0.4);
  position: absolute;
  top: -9px; left: -9px;
  animation: pulseRing 2s ease-out infinite;
  z-index: 1;
}

.pulse-ring-2 {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1.5px solid rgba(129, 140, 248, 0.2);
  position: absolute;
  top: -17px; left: -17px;
  animation: pulseRing 2s ease-out 0.6s infinite;
  z-index: 0;
}

@keyframes pulseRing {
  0% { transform: scale(0.5); opacity: 1; }
  100% { transform: scale(1.6); opacity: 0; }
}

/* User Location Marker */
.user-marker {
  position: relative;
}

.user-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #06b6d4;
  border: 2.5px solid #fff;
  position: absolute;
  top: 0; left: 0;
  box-shadow: 0 0 8px rgba(6, 182, 212, 0.6);
  z-index: 3;
}

.user-ring {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(6, 182, 212, 0.12);
  border: 1.5px solid rgba(6, 182, 212, 0.3);
  position: absolute;
  top: -8px; left: -8px;
  animation: userGlow 3s ease-in-out infinite;
  z-index: 1;
}

@keyframes userGlow {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 0.4; }
}

/* Distance Line */
.leaflet-distance-line {
  stroke-dasharray: 8 6;
}

/* ---------- Popup Styles ---------- */
.leaflet-popup .leaflet-popup-content-wrapper,
.leaflet-popup-content-wrapper {
  background: rgba(12, 15, 26, 0.95) !important;
  backdrop-filter: blur(20px) !important;
  -webkit-backdrop-filter: blur(20px) !important;
  border: 1px solid rgba(255, 255, 255, 0.1) !important;
  border-radius: 14px !important;
  color: #f1f3f9 !important;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.04) !important;
  padding: 0 !important;
}

.leaflet-popup .leaflet-popup-content,
.leaflet-popup-content {
  margin: 0 !important;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif !important;
  font-size: 13px !important;
  color: #f1f3f9 !important;
  line-height: 1.5 !important;
}

.leaflet-popup .leaflet-popup-tip-container .leaflet-popup-tip,
.leaflet-popup-tip {
  background: rgba(12, 15, 26, 0.95) !important;
  border: none !important;
  box-shadow: none !important;
}

.leaflet-popup-close-button {
  color: #9da4b8 !important;
  font-size: 18px !important;
  padding: 6px 8px !important;
}

.popup-content {
  padding: 14px 16px;
}

.popup-content h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-1);
  margin-bottom: 10px;
  letter-spacing: -0.2px;
}

.popup-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.popup-row:last-child {
  border-bottom: none;
}

.popup-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.popup-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-primary);
  font-weight: 500;
}

/* ---------- Final Polish ---------- */

/* Header subtle glow */
#app-header::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(129, 140, 248, 0.15), rgba(6, 182, 212, 0.15), transparent);
}

/* Stat card subtle hover animation */
.stat-card {
  transform: translateY(0);
}

.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

/* Filter tab active glow */
.filter-tab.active {
  box-shadow: 0 2px 12px rgba(129, 140, 248, 0.3);
}

/* Control buttons hover lift */
.control-btn:active {
  transform: scale(0.98);
}

/* History item active state */
.history-item:active {
  transform: scale(0.98);
  background: rgba(129, 140, 248, 0.06);
}

/* Status badge pulse when online */
.status-badge.online .status-dot {
  animation: statusPulse 2.5s ease-in-out infinite;
}

@keyframes statusPulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 6px var(--success); }
  50% { opacity: 0.6; box-shadow: 0 0 12px var(--success); }
}

/* Mobile action btn hover/active */
.mobile-action-btn:active {
  transform: scale(0.9);
}

/* Speed HUD subtle gradient border */
.speed-hud {
  background: linear-gradient(135deg, rgba(12, 15, 26, 0.8), rgba(20, 24, 41, 0.8));
}

/* Device card accent line */
.device-card {
  border-left: 3px solid var(--accent-1);
}

/* Distance card accent */
.distance-to-device-card {
  border-left: 3px solid var(--accent-2);
}

/* Sidebar subtle top border glow */
#sidebar::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(129, 140, 248, 0.2), transparent);
  z-index: 1;
}

/* Mobile bar top border glow */
#mobile-bar::before {
  content: '';
  position: absolute;
  top: -1px; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(129, 140, 248, 0.15), rgba(6, 182, 212, 0.15), transparent);
}

/* Toggle row hover */
.toggle-row:hover {
  border-color: var(--border-hover);
}

/* Smooth sidebar scroll */
#sidebar {
  scroll-behavior: smooth;
}

/* Loading spinner refined */
.loader-icon svg {
  filter: drop-shadow(0 0 20px rgba(129, 140, 248, 0.3));
}
