/* Core Design System & Tokens */
:root {
  --bg-primary: #0a0b10;
  --bg-sidebar: rgba(13, 15, 24, 0.75);
  --card-bg: rgba(22, 26, 42, 0.55);
  --card-border: rgba(255, 255, 255, 0.08);
  --card-border-focus: rgba(99, 102, 241, 0.4);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --accent-color: #6366f1; /* Indigo */
  --accent-hover: #4f46e5;
  --accent-glow: rgba(99, 102, 241, 0.25);
  
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.15);
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #06b6d4;

  --sidebar-width: 360px;
  --border-radius-lg: 16px;
  --border-radius-md: 10px;
  --border-radius-sm: 6px;
  
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base Styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
}

h1, h2, h3, h4 {
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* Layout */
.app-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  position: relative;
}

.sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-sidebar);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--card-border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  z-index: 1000;
  overflow-y: auto;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.5);
}

.map-viewport {
  flex: 1;
  height: 100%;
  background-color: #1a1d24;
}

/* Header */
.sidebar-header {
  margin-bottom: 1.5rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.logo-icon {
  font-size: 1.75rem;
  filter: drop-shadow(0 0 8px var(--accent-glow));
}

.logo h1 {
  font-size: 1.5rem;
  background: linear-gradient(135deg, #fff 30%, var(--accent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Card Style (Glassmorphism) */
.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius-lg);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
  transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

.card h3 {
  font-size: 1rem;
  margin-bottom: 1rem;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Forms & Controls */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.input-group label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

input[type="text"],
input[type="password"] {
  background: rgba(10, 11, 16, 0.6);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius-md);
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  transition: all var(--transition-fast);
}

input[type="text"]:focus,
input[type="password"]:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: rgba(10, 11, 16, 0.8);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem 1.25rem;
  border-radius: var(--border-radius-md);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all var(--transition-fast);
  width: 100%;
}

.btn.primary {
  background: var(--accent-color);
  color: white;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.btn.primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
}

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

.btn-icon {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color var(--transition-fast), transform var(--transition-normal);
  padding: 0.25rem;
  border-radius: 50%;
}

.btn-icon:hover {
  color: var(--text-primary);
  transform: rotate(180deg);
}

/* Members List */
.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.section-title-row h3 {
  margin-bottom: 0;
}

.members-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 250px;
  overflow-y: auto;
}

.placeholder-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  text-align: center;
  padding: 1rem 0;
}

.member-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  border-radius: var(--border-radius-md);
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--card-border);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.member-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.15);
}

.member-item.active {
  background: var(--accent-glow);
  border-color: var(--accent-color);
  box-shadow: 0 0 12px rgba(99, 102, 241, 0.15);
}

.member-avatar {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-color), var(--info));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
}

.member-info {
  flex: 1;
  min-width: 0;
}

.member-name {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-subtext {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.member-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.25rem;
}

.battery-badge {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 20px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.15rem;
}

.battery-high { background: rgba(16, 185, 129, 0.15); color: #34d399; }
.battery-medium { background: rgba(245, 158, 11, 0.15); color: #fbbf24; }
.battery-low { background: rgba(239, 68, 68, 0.15); color: #f87171; }

.zone-badge {
  font-size: 0.65rem;
  padding: 0.1rem 0.35rem;
  border-radius: var(--border-radius-sm);
  background: rgba(6, 182, 212, 0.15);
  color: #22d3ee;
  border: 1px solid rgba(6, 182, 212, 0.3);
  font-weight: 500;
  max-width: 70px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Stats Grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.stat-item {
  background: rgba(10, 11, 16, 0.3);
  border: 1px solid var(--card-border);
  border-radius: var(--border-radius-md);
  padding: 0.6rem 0.75rem;
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.15rem;
}

.stat-value {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
}

.last-seen {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
  margin-bottom: 0.75rem;
}

.margin-top {
  margin-top: 1rem;
}

.hidden {
  display: none !important;
}

/* Custom Range Slider */
.range-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 5px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 5px;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--accent-color);
  cursor: pointer;
  transition: transform var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

#trail-limit-val {
  font-size: 0.85rem;
  font-weight: 600;
  width: 30px;
  text-align: right;
  color: var(--text-primary);
}

/* Toggle Switch */
.trail-toggles {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.75rem;
}

.toggle-switch {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
}

.toggle-switch input {
  display: none;
}

.toggle-switch .slider {
  width: 32px;
  height: 18px;
  background-color: rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  position: relative;
  transition: background-color var(--transition-normal);
}

.toggle-switch .slider::before {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: transform var(--transition-normal);
}

.toggle-switch input:checked + .slider {
  background-color: var(--success);
}

.toggle-switch input:checked + .slider::before {
  transform: translateX(14px);
}

/* Zones List */
.zones-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.zone-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--border-radius-sm);
  background: rgba(255, 255, 255, 0.01);
  border-left: 3px solid var(--info);
}

.zone-name {
  font-weight: 500;
  color: var(--text-primary);
}

.zone-coords {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Footer status indicator */
.sidebar-footer {
  margin-top: auto;
  padding-top: 1.5rem;
  border-top: 1px solid var(--card-border);
  font-size: 0.8rem;
  color: var(--text-muted);
}

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
}

.status-indicator::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.status-indicator.online { color: var(--success); }
.status-indicator.online::before { background: var(--success); box-shadow: 0 0 8px var(--success); }

.status-indicator.offline { color: var(--danger); }
.status-indicator.offline::before { background: var(--danger); }

/* Leaflet Custom Overrides for dark theme compatibility */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--bg-primary) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--card-border);
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4) !important;
  backdrop-filter: blur(12px);
}

.leaflet-popup-content h4 {
  font-family: 'Outfit', sans-serif;
  font-size: 0.95rem;
  margin-bottom: 0.25rem;
  color: var(--text-primary);
}

.leaflet-popup-content p {
  margin: 0.15rem 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.leaflet-container a.leaflet-popup-close-button {
  color: var(--text-muted) !important;
}

.leaflet-container a.leaflet-popup-close-button:hover {
  color: var(--text-primary) !important;
}

/* Scrollbar customizations */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}
