/* ========================================
   DISTANCE TRACKER — STYLES
   Same design tokens as ruler page
   ======================================== */
:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card: #1a1a28;
  --surface-glass: rgba(255, 255, 255, 0.04);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-glow: rgba(99, 102, 241, 0.3);

  --text-primary: #f0f0f5;
  --text-secondary: #8888a0;
  --text-muted: #55556a;

  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.25);
  --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);

  --green: #22c55e;
  --green-glow: rgba(34, 197, 94, 0.25);
  --yellow: #eab308;
  --yellow-glow: rgba(234, 179, 8, 0.25);
  --red: #ef4444;
  --red-glow: rgba(239, 68, 68, 0.25);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;

  --header-height: 56px;

  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ========================================
   RESET & BASE
   ======================================== */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  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;
  user-select: none;
  -webkit-user-select: none;
}

.hidden {
  display: none !important;
}

/* ========================================
   PERMISSION OVERLAY
   ======================================== */
.permission-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.3s ease;
}

.permission-content {
  text-align: center;
  padding: 40px 32px;
  max-width: 360px;
}

.permission-icon {
  font-size: 56px;
  margin-bottom: 16px;
  animation: pulse-glow 2s ease-in-out infinite;
}

.permission-content h2 {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 10px;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.permission-content p {
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 28px;
}

.permission-btn {
  display: block;
  width: 100%;
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--accent-gradient);
  color: #fff;
  font-family: var(--font-main);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 4px 24px var(--accent-glow);
}

.permission-btn:active {
  transform: scale(0.97);
}

.permission-error {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.25);
  color: #fca5a5;
  font-size: 13px;
  line-height: 1.5;
}

/* ========================================
   APP CONTAINER
   ======================================== */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ========================================
   TOP BAR
   ======================================== */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--header-height);
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
  z-index: 100;
}

.back-link {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--accent-light);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 6px 10px 6px 4px;
  border-radius: var(--radius-sm);
  transition: background 0.2s, color 0.2s;
}

.back-link:hover {
  background: rgba(99, 102, 241, 0.1);
  color: #a5b4fc;
}

.page-title {
  display: flex;
  align-items: center;
  gap: 6px;
}

.page-title-icon {
  font-size: 18px;
}

.page-title-text {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.icon-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg-primary);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.icon-btn:hover {
  border-color: var(--border-glow);
  color: var(--accent-light);
  background: rgba(99, 102, 241, 0.08);
}

/* ========================================
   MAIN TRACKER LAYOUT
   ======================================== */
.tracker-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ========================================
   MAP
   ======================================== */
.map-container {
  flex: 1;
  position: relative;
  min-height: 200px;
}

#map {
  width: 100%;
  height: 100%;
  z-index: 1;
  background: #0a0a14;
}

/* Dark map tiles filter */
.leaflet-tile-pane {
  filter: brightness(0.7) contrast(1.15) saturate(0.8) hue-rotate(180deg) invert(1);
}

/* Override leaflet controls */
.leaflet-control-zoom {
  border: none !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4) !important;
}

.leaflet-control-zoom a {
  background: var(--bg-card) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border-subtle) !important;
  width: 34px !important;
  height: 34px !important;
  line-height: 34px !important;
  font-size: 16px !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-secondary) !important;
}

.leaflet-control-attribution {
  background: rgba(10, 10, 15, 0.7) !important;
  color: var(--text-muted) !important;
  font-size: 10px !important;
}

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

/* GPS accuracy badge */
.gps-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: 50px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.gps-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  transition: background 0.3s, box-shadow 0.3s;
}

.gps-dot.good {
  background: var(--green);
  box-shadow: 0 0 8px var(--green-glow);
  animation: dot-pulse 2s ease-in-out infinite;
}

.gps-dot.medium {
  background: var(--yellow);
  box-shadow: 0 0 8px var(--yellow-glow);
}

.gps-dot.poor {
  background: var(--red);
  box-shadow: 0 0 8px var(--red-glow);
}

/* Recenter button */
.recenter-btn {
  position: absolute;
  bottom: 16px;
  right: 12px;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--border-subtle);
  background: rgba(10, 10, 15, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.recenter-btn:hover {
  border-color: var(--border-glow);
  color: var(--accent-light);
}

.recenter-btn:active {
  transform: scale(0.92);
}

/* ========================================
   STATS PANEL
   ======================================== */
.stats-panel {
  flex-shrink: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-subtle);
  padding: 20px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Primary stat */
.stat-primary {
  text-align: center;
}

.stat-value {
  font-size: 52px;
  font-weight: 800;
  letter-spacing: -2px;
  line-height: 1;
  background: linear-gradient(180deg, #fff 0%, var(--text-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.stat-label {
  font-size: 14px;
  font-weight: 500;
  color: var(--accent-light);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-top: 2px;
}

/* Secondary stats */
.stats-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0;
  padding: 12px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.stat-item {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.stat-item-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.stat-item-data {
  display: flex;
  flex-direction: column;
}

.stat-item-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

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

.stat-divider {
  width: 1px;
  height: 32px;
  background: var(--border-subtle);
  flex-shrink: 0;
}

/* ========================================
   CONTROLS
   ======================================== */
.controls-row {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-main);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.ctrl-btn:active {
  transform: scale(0.96);
}

.ctrl-start {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  box-shadow: 0 4px 20px var(--green-glow);
  flex: 1;
  max-width: 240px;
}

.ctrl-pause {
  background: linear-gradient(135deg, #eab308, #ca8a04);
  color: #1a1a28;
  box-shadow: 0 4px 20px var(--yellow-glow);
  flex: 1;
  max-width: 180px;
}

.ctrl-resume {
  background: linear-gradient(135deg, #22c55e, #16a34a);
  color: #fff;
  box-shadow: 0 4px 20px var(--green-glow);
  flex: 1;
  max-width: 180px;
}

.ctrl-reset {
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  box-shadow: none;
  padding: 12px 20px;
}

.ctrl-reset:hover {
  border-color: var(--border-glow);
  color: var(--text-primary);
}

/* ========================================
   UNIT SELECTOR
   ======================================== */
.unit-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.unit-chip {
  padding: 6px 18px;
  border: 1px solid var(--border-subtle);
  border-radius: 50px;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-main);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.25s;
}

.unit-chip:hover {
  border-color: var(--border-glow);
  color: var(--text-secondary);
}

.unit-chip.active {
  background: var(--accent-gradient);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}

/* ========================================
   TRACKING ACTIVE — PULSE ON MAP MARKER
   ======================================== */
.tracking-marker {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: 3px solid #fff;
  box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.5);
}

.tracking-marker.active {
  animation: marker-pulse 2s ease-in-out infinite;
}

.start-marker {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--green);
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* ========================================
   ANIMATIONS
   ======================================== */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes pulse-glow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

@keyframes dot-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes marker-pulse {
  0% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.5); }
  70% { box-shadow: 0 0 0 16px rgba(99, 102, 241, 0); }
  100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0); }
}

/* ========================================
   MOBILE RESPONSIVE
   ======================================== */
@media (max-width: 600px) {
  :root {
    --header-height: 50px;
  }

  .back-link span {
    display: none;
  }

  .page-title-text {
    font-size: 14px;
  }

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

  .stat-item-value {
    font-size: 14px;
  }

  .stat-item-icon {
    font-size: 16px;
  }

  .stats-panel {
    padding: 14px 12px 20px;
    gap: 12px;
  }

  .ctrl-btn {
    padding: 11px 20px;
    font-size: 14px;
  }

  .unit-chip {
    padding: 5px 14px;
    font-size: 12px;
  }
}

@media (max-width: 360px) {
  .stat-value {
    font-size: 38px;
  }

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

  .stats-row {
    padding: 10px 4px;
  }

  .ctrl-btn {
    padding: 10px 16px;
    font-size: 13px;
    gap: 6px;
  }
}

/* Landscape on mobile */
@media (max-height: 500px) {
  :root {
    --header-height: 42px;
  }

  .tracker-main {
    flex-direction: row;
  }

  .map-container {
    flex: 1;
  }

  .stats-panel {
    width: 280px;
    border-top: none;
    border-left: 1px solid var(--border-subtle);
    overflow-y: auto;
    padding: 12px;
    gap: 10px;
  }

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

  .controls-row {
    flex-wrap: wrap;
  }
}

/* Desktop widescreen */
@media (min-width: 900px) {
  .stats-panel {
    padding: 20px 40px 28px;
  }

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

  .stats-row {
    max-width: 500px;
    margin: 0 auto;
  }

  .controls-row {
    max-width: 400px;
    margin: 0 auto;
  }

  .unit-row {
    max-width: 320px;
    margin: 0 auto;
  }
}

/* ========================================
   SCROLLBAR HIDE
   ======================================== */
::-webkit-scrollbar {
  display: none;
}

* {
  scrollbar-width: none;
}
