:root {
  --bg: #0c1017;
  --panel: #151b26;
  --panel2: #1c2433;
  --border: #2a3548;
  --text: #eef2f8;
  --muted: #8fa0b8;
  --accent: #3b82f6;
  --camera: #3b82f6;
  --event: #ef4444;
  --roadwork: #f59e0b;
  --counter: #22c55e;
  --font: 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
}

.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
}

.sidebar-header {
  padding: 1.1rem 1rem 0.9rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
  font-size: 1.1rem;
  font-weight: 600;
}

.sidebar-header p {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.stat {
  background: var(--panel2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.65rem;
}

.stat .num {
  font-size: 1.25rem;
  font-weight: 700;
}

.stat .label {
  font-size: 0.68rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat.cameras .num { color: var(--camera); }
.stat.events .num { color: var(--event); }
.stat.roadworks .num { color: var(--roadwork); }
.stat.counters .num { color: var(--counter); }

.search-box {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.search-box input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font-size: 0.85rem;
}

.layers {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
}

.layer-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.7rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--panel2);
  margin-bottom: 0.5rem;
  cursor: pointer;
  user-select: none;
}

.layer-item input { accent-color: var(--accent); width: 16px; height: 16px; }

.layer-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.layer-dot.cameras { background: var(--camera); }
.layer-dot.events { background: var(--event); }
.layer-dot.roadworks { background: var(--roadwork); }
.layer-dot.counters { background: var(--counter); }

.layer-info { flex: 1; min-width: 0; }
.layer-info strong { font-size: 0.85rem; display: block; }
.layer-info span { font-size: 0.72rem; color: var(--muted); }

.sidebar-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.btn {
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  font-size: 0.75rem;
  cursor: pointer;
}

.btn:hover { background: var(--border); }

#map {
  width: 100%;
  height: 100vh;
}

.loading {
  position: fixed;
  inset: 0;
  background: rgba(12, 16, 23, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  font-size: 0.95rem;
}

.loading.hidden { display: none; }

.leaflet-popup-content-wrapper {
  border-radius: 10px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.35);
}

.popup-title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.popup-desc {
  font-size: 0.8rem;
  color: #444;
  line-height: 1.4;
}

.popup-meta {
  font-size: 0.72rem;
  color: #666;
  margin-top: 0.4rem;
}

.popup-img {
  width: 100%;
  max-width: 260px;
  border-radius: 6px;
  margin-top: 0.5rem;
}

.popup-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  margin-bottom: 0.35rem;
}

.popup-badge.camera { background: #dbeafe; color: #1d4ed8; }
.popup-badge.event { background: #fee2e2; color: #b91c1c; }
.popup-badge.roadwork { background: #fef3c7; color: #b45309; }
.popup-badge.counter { background: #dcfce7; color: #15803d; }

.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large {
  background: rgba(59, 130, 246, 0.25);
}

.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div {
  background: rgba(59, 130, 246, 0.85);
  color: #fff;
  font-weight: 600;
}

@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { max-height: 42vh; border-right: none; border-bottom: 1px solid var(--border); }
  #map { height: 58vh; }
}
