/* ==========================================================================
   GeoTrack Pro - Modern Glassmorphism & Precision Real-time Location CSS
   ========================================================================== */

:root {
  --bg-primary: #0b0f19;
  --bg-surface: rgba(18, 24, 38, 0.85);
  --bg-surface-hover: rgba(30, 41, 59, 0.9);
  --border-color: rgba(255, 255, 255, 0.1);
  --border-focus: #3b82f6;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-primary: #3b82f6;
  --accent-gradient: linear-gradient(135deg, #3b82f6, #6366f1);
  --accent-glow: rgba(59, 130, 246, 0.35);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;

  --glass-blur: blur(16px);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

body.light {
  --bg-primary: #f1f5f9;
  --bg-surface: rgba(255, 255, 255, 0.88);
  --bg-surface-hover: rgba(241, 245, 249, 0.95);
  --border-color: rgba(0, 0, 0, 0.08);
  --border-focus: #2563eb;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --accent-primary: #2563eb;
  --accent-gradient: linear-gradient(135deg, #2563eb, #4f46e5);
  --accent-glow: rgba(37, 99, 235, 0.25);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-primary);
}

/* Ensure Leaflet icon rendering is unaffected by global box-sizing */
.leaflet-marker-icon,
.leaflet-marker-shadow {
  box-sizing: content-box !important;
}

#map {
  width: 100vw;
  height: 100vh;
  z-index: 1;
}

/* ==========================================================================
   Top Navigation Bar
   ========================================================================== */
.top-nav {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.brand-badge {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px 8px 12px;
  background: var(--bg-surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.brand-icon-wrap {
  width: 36px;
  height: 36px;
  background: var(--accent-gradient);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
  box-shadow: 0 0 14px var(--accent-glow);
  position: relative;
}

.brand-icon-wrap .radar-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 12px;
  border: 2px solid var(--accent-primary);
  animation: radar-ping 2s cubic-bezier(0, 0, 0.2, 1) infinite;
  opacity: 0.7;
}

@keyframes radar-ping {
  0% { transform: scale(0.9); opacity: 0.8; }
  80%, 100% { transform: scale(1.4); opacity: 0; }
}

.brand-info h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
  line-height: 1.2;
}

.brand-info span {
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.live-dot {
  width: 7px;
  height: 7px;
  background-color: var(--success);
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 8px var(--success);
  animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.8); }
}

.nav-actions {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.room-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--bg-surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  transition: all 0.2s ease;
}

.room-pill:hover {
  background: var(--bg-surface-hover);
  border-color: var(--border-focus);
}

.room-pill .code {
  color: var(--accent-primary);
  letter-spacing: 0.05em;
  font-family: monospace;
  font-size: 13px;
}

.share-toggle-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: all 0.25s ease;
  white-space: nowrap;
}

.share-toggle-btn.sharing-active {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
  color: #10b981;
  box-shadow: 0 0 16px rgba(16, 185, 129, 0.25);
}

.share-toggle-btn.sharing-paused {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #ef4444;
  box-shadow: 0 0 16px rgba(239, 68, 68, 0.2);
}

.share-toggle-btn:hover {
  transform: translateY(-1px);
}

.bg-mode-card {
  background: rgba(59, 130, 246, 0.08);
  border: 1px solid rgba(59, 130, 246, 0.25);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bg-mode-card .header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-primary);
}

.bg-mode-card .desc {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.btn-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: all 0.2s ease;
  font-size: 18px;
}

.btn-icon:hover {
  background: var(--bg-surface-hover);
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}

.btn-icon:active {
  transform: translateY(0);
}

/* ==========================================================================
   Collapsible Sidebar Control Panel
   ========================================================================== */
.sidebar {
  position: absolute;
  top: 76px;
  left: 16px;
  bottom: 16px;
  width: 360px;
  max-width: calc(100vw - 32px);
  background: var(--bg-surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  overflow: hidden;
}

.sidebar.closed {
  transform: translateX(-390px);
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-title {
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
}

.sidebar-content {
  padding: 16px 20px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar-content::-webkit-scrollbar {
  width: 5px;
}

.sidebar-content::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

/* Sections & Form Groups */
.panel-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.section-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.input-row {
  display: flex;
  gap: 8px;
}

.custom-input {
  width: 100%;
  padding: 10px 14px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13.5px;
  outline: none;
  transition: all 0.2s;
}

body.light .custom-input {
  background: rgba(255, 255, 255, 0.8);
}

.custom-input:focus {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.btn-primary {
  padding: 10px 16px;
  background: var(--accent-gradient);
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 4px 12px var(--accent-glow);
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-primary:hover {
  opacity: 0.95;
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s;
}

body.light .btn-secondary {
  background: rgba(0, 0, 0, 0.04);
}

.btn-secondary:hover {
  background: var(--bg-surface-hover);
  border-color: var(--accent-primary);
}

/* Telemetry Grid */
.telemetry-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.telemetry-card {
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}

body.light .telemetry-card {
  background: rgba(0, 0, 0, 0.03);
}

.telemetry-card .t-title {
  font-size: 10.5px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-weight: 600;
}

.telemetry-card .t-val {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  margin-top: 2px;
  font-family: monospace;
}

/* User Card List */
.user-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-item {
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.2s ease;
}

body.light .user-item {
  background: rgba(255, 255, 255, 0.6);
}

.user-item.is-me {
  border-color: var(--accent-primary);
  background: rgba(59, 130, 246, 0.08);
}

.user-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 13px;
  text-transform: uppercase;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.user-name-box {
  display: flex;
  flex-direction: column;
}

.user-name {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.user-sub {
  font-size: 11px;
  color: var(--text-secondary);
}

/* Distance Highlight Badge */
.distance-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: var(--success);
  padding: 4px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  font-family: monospace;
}

.user-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.btn-action-sm {
  flex: 1;
  padding: 6px 10px;
  font-size: 11.5px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.2s;
}

.btn-action-sm:hover {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

.btn-action-sm.active {
  background: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

/* ==========================================================================
   Floating Map Controls (Bottom-Right)
   ========================================================================== */
.map-controls {
  position: absolute;
  right: 16px;
  bottom: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.map-control-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: all 0.2s ease;
}

.map-control-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--accent-primary);
  transform: scale(1.05);
}

/* ==========================================================================
   Custom Map Markers & Radars (Leaflet)
   ========================================================================== */
.custom-user-marker {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  transform: translate(-50%, -50%);
}

/* Pulsing radar waves for markers */
.marker-pulse-ring {
  position: absolute;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid currentColor;
  opacity: 0.8;
  animation: marker-pulse 2s cubic-bezier(0.2, 0.8, 0.2, 1) infinite;
  pointer-events: none;
}

@keyframes marker-pulse {
  0% { transform: scale(0.6); opacity: 0.9; }
  100% { transform: scale(1.8); opacity: 0; }
}

.marker-avatar-core {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: #1e293b;
  border: 2.5px solid white;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  position: relative;
  z-index: 2;
  transition: transform 0.2s ease;
}

.marker-avatar-core:hover {
  transform: scale(1.15);
}

.marker-label-tag {
  position: absolute;
  bottom: -22px;
  white-space: nowrap;
  background: rgba(15, 23, 42, 0.9);
  color: white;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 10.5px;
  font-weight: 600;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.15);
  pointer-events: none;
  z-index: 3;
}

/* Heading arrow for user orientation */
.marker-heading-arrow {
  position: absolute;
  top: -12px;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-bottom: 9px solid currentColor;
  transition: transform 0.2s ease;
  z-index: 1;
}

/* Midpoint Distance Badge on Polyline */
.midpoint-distance-label {
  background: rgba(15, 23, 42, 0.92);
  color: #10b981;
  border: 1px solid rgba(16, 185, 129, 0.4);
  padding: 3px 8px;
  border-radius: 14px;
  font-size: 11px;
  font-weight: 700;
  font-family: monospace;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* ==========================================================================
   Toast Notification System
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast-msg {
  padding: 10px 18px;
  background: var(--bg-surface);
  backdrop-filter: var(--glass-blur);
  -webkit-backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  border-radius: var(--radius-lg);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
  display: flex;
  align-items: center;
  gap: 8px;
}

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

/* ==========================================================================
   Responsive Mobile Adjustments
   ========================================================================== */
@media (max-width: 640px) {
  .top-nav {
    top: 10px;
    left: 10px;
    right: 10px;
  }
  
  .brand-info h1 {
    font-size: 13.5px;
  }
  
  .sidebar {
    top: 68px;
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    max-width: none;
  }
  
  .map-controls {
    right: 10px;
    bottom: 16px;
  }
}
