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

:root, [data-theme="dark"] {
  --primary: #4f46e5;
  --primary-light: #818cf8;
  --primary-dark: #3730a3;
  --accent: #06b6d4;
  --success: #10b981;
  --error: #ef4444;
  --bg: #0f0e17;
  --card-bg: #1a1929;
  --card-border: rgba(255,255,255,0.07);
  --text: #f0eff7;
  --text-muted: #a09fc0;
  --radius: 20px;
}

/* ── Body & Background ── */
html, body {
  height: 100%;
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 10%, rgba(79,70,229,0.25) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 80% 80%, rgba(6,182,212,0.15) 0%, transparent 60%),
    radial-gradient(ellipse 40% 40% at 60% 40%, rgba(129,140,248,0.08) 0%, transparent 50%);
  z-index: 0;
  pointer-events: none;
}

/* ── Map ── */
#map {
  height: 100vh;
  width: 100%;
  position: relative;
  z-index: 1;
}

/* ── UI Elements ── */
.header {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  padding: 12px 20px;
  border-radius: 9999px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(20px);
  z-index: 2000;
  display: flex;
  align-items: center;
  gap: 12px;
}

.header h1 { font-size: 17px; font-weight: 800; }
.badge { background: rgba(79,70,229,0.2); color: var(--primary-light); padding: 5px 14px; border-radius: 9999px; font-size: 13px; font-weight: 600; }

.btn-back {
  position: absolute;
  top: 20px;
  left: 20px;
  background: var(--card-bg);
  color: var(--text-muted);
  border: 1px solid var(--card-border);
  padding: 12px 20px;
  border-radius: 9999px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  z-index: 2000;
  transition: all 0.25s ease;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.sidebar {
  position: absolute;
  top: 84px;
  right: 20px;
  width: 300px;
  background: rgba(26, 25, 41, 0.8);
  backdrop-filter: blur(25px);
  border-radius: var(--radius);
  padding: 24px 16px;
  box-shadow: 0 32px 64px rgba(0, 0, 0, 0.4);
  z-index: 1500;
  border: 1px solid var(--card-border);
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.sidebar h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 20px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
  padding-left: 8px;
}

/* ── Styled Device Item ── */
.device-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
  padding: 16px;
  border-radius: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.device-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 4px;
  background: var(--item-color);
  opacity: 0.8;
}

.device-item:hover {
  background: rgba(255, 255, 255, 0.07);
  transform: translateY(-2px);
  border-color: rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

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

.device-id {
  font-weight: 800;
  font-size: 15px;
  letter-spacing: -0.2px;
}

.device-info {
  display: grid;
  gap: 6px;
}

.info-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.info-row svg { opacity: 0.6; }

.device-time {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
  margin-top: 4px;
}

/* ── Status Bar ── */
.status-bar {
  position: absolute;
  bottom: 20px;
  left: 20px;
  background: var(--card-bg);
  padding: 10px 18px;
  border-radius: 9999px;
  font-size: 13px;
  z-index: 1500;
  border: 1px solid var(--card-border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.dot { width: 8px; height: 8px; background: var(--success); border-radius: 50%; animation: pulse 2s infinite; }

/* ── Custom Marker ── */
.custom-marker { display: flex; align-items: center; justify-content: center; }
.marker-pin {
  width: 30px; height: 30px; border-radius: 50% 50% 50% 0;
  background: var(--marker-color); position: absolute; transform: rotate(-45deg);
  left: 50%; top: 50%; margin: -15px 0 0 -15px; border: 2px solid white;
}
.marker-pin::after { content: ''; width: 12px; height: 12px; background: white; border-radius: 50%; transform: rotate(45deg); }

@keyframes pulse { 0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(16,185,129,0.4); } 50% { opacity: 0.7; box-shadow: 0 0 0 4px rgba(16,185,129,0); } }

/* ── Leaflet Popup Overrides ── */
.leaflet-popup-content-wrapper {
  background: var(--card-bg) !important;
  color: var(--text) !important;
  border-radius: 16px !important;
  border: 1px solid var(--card-border) !important;
  font-family: inherit !important;
}
.leaflet-popup-tip { background: var(--card-bg) !important; }