/* Chicago Safety — Dark-first design */
:root {
  --bg: #0f1117;
  --bg2: #1a1d27;
  --bg3: #252836;
  --text: #e4e6eb;
  --text2: #9ca3af;
  --accent: #3b82f6;
  --accent2: #60a5fa;
  --red: #ef4444;
  --orange: #f59e0b;
  --green: #22c55e;
  --purple: #a855f7;
  --pink: #ec4899;
  --border: #2d3140;
  --radius: 10px;
  --shadow: 0 4px 20px rgba(0,0,0,0.3);
}

[data-theme="light"] {
  --bg: #f8fafc;
  --bg2: #ffffff;
  --bg3: #f1f5f9;
  --text: #1e293b;
  --text2: #64748b;
  --border: #e2e8f0;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  height: 100vh;
}

/* Header */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  z-index: 1000;
  position: relative;
}

.header h1 {
  font-size: 18px;
  font-weight: 700;
}

.header h1 span { color: var(--accent); }

.header-badge {
  background: var(--red);
  color: white;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 8px;
  font-weight: 600;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-right {
  display: flex;
  gap: 8px;
  align-items: center;
}

.header-btn {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}

.header-btn:hover { background: var(--accent); color: white; }
.header-btn.active { background: var(--accent); color: white; }

/* Stats bar */
.stats-bar {
  display: flex;
  gap: 12px;
  padding: 8px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-wrap: nowrap;
}

.stat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg3);
  border-radius: 20px;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.2s;
}

.stat-pill:hover { border-color: var(--accent); }
.stat-pill.active { border-color: var(--accent); background: rgba(59,130,246,0.15); }

.stat-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stat-pill .count {
  font-weight: 700;
  color: var(--text);
}

.stat-pill .label {
  color: var(--text2);
}

/* Category colors */
.cat-violent .dot { background: var(--red); }
.cat-property .dot { background: var(--orange); }
.cat-drugs .dot { background: var(--purple); }
.cat-weapons .dot { background: var(--pink); }
.cat-fraud .dot { background: var(--accent); }
.cat-other .dot { background: var(--text2); }
.cat-vice .dot { background: #14b8a6; }

/* Controls bar */
.controls {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  align-items: center;
}

.time-btn {
  padding: 4px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s;
}

.time-btn:hover { border-color: var(--accent); }
.time-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

.controls .spacer { flex: 1; }

.search-box {
  display: flex;
  align-items: center;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px;
}

.search-box input {
  background: none;
  border: none;
  color: var(--text);
  padding: 4px 8px;
  font-size: 12px;
  width: 200px;
  outline: none;
}

.search-box input::placeholder { color: var(--text2); }

.view-toggle {
  display: flex;
  gap: 4px;
}

/* Map container */
#map {
  width: 100%;
  height: calc(100vh - 120px);
}

/* Leaflet popup customization */
.leaflet-popup-content-wrapper {
  background: var(--bg2) !important;
  color: var(--text) !important;
  border-radius: var(--radius) !important;
  box-shadow: var(--shadow) !important;
  border: 1px solid var(--border);
}

.leaflet-popup-tip { background: var(--bg2) !important; }

.crime-popup {
  min-width: 200px;
}

.crime-popup h3 {
  font-size: 14px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.crime-popup .cat-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
  color: white;
}

.crime-popup .details {
  font-size: 12px;
  color: var(--text2);
  line-height: 1.6;
}

.crime-popup .details strong { color: var(--text); }

.badge-violent { background: var(--red); }
.badge-property { background: var(--orange); }
.badge-drugs { background: var(--purple); }
.badge-weapons { background: var(--pink); }
.badge-fraud { background: var(--accent); }
.badge-other { background: #6b7280; }
.badge-vice { background: #14b8a6; }

/* Side panel */
.side-panel {
  position: absolute;
  top: 120px;
  right: 16px;
  width: 280px;
  max-height: calc(100vh - 140px);
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1000;
  overflow-y: auto;
  display: none;
}

.side-panel.open { display: block; }

.side-panel h3 {
  padding: 12px 16px 8px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}

.hood-list {
  padding: 8px 0;
}

.hood-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 16px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
}

.hood-item:hover { background: var(--bg3); }

.hood-item .name { color: var(--text); flex: 1; }
.hood-item .bar-wrap {
  width: 80px;
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  margin: 0 8px;
  overflow: hidden;
}
.hood-item .bar {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
}
.hood-item .num {
  color: var(--text2);
  font-weight: 600;
  min-width: 36px;
  text-align: right;
}

/* Loading */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s;
}

.loading-overlay.hidden { opacity: 0; pointer-events: none; }

.loading-content { text-align: center; }

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

.data-note {
  font-size: 11px;
  color: var(--text2);
  padding: 0 4px;
}

/* Heatmap legend */
.legend {
  position: absolute;
  bottom: 30px;
  left: 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  z-index: 1000;
  font-size: 11px;
}

.legend h4 { margin-bottom: 6px; font-size: 12px; }

.legend-gradient {
  width: 120px;
  height: 10px;
  background: linear-gradient(to right, #3b82f6, #22c55e, #f59e0b, #ef4444);
  border-radius: 5px;
  margin-bottom: 4px;
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  color: var(--text2);
}

/* Mobile */
@media (max-width: 768px) {
  .stats-bar { padding: 6px 10px; gap: 6px; }
  .stat-pill { font-size: 11px; padding: 3px 8px; }
  .controls { padding: 6px 10px; flex-wrap: wrap; }
  .search-box input { width: 140px; }
  .side-panel { width: 240px; right: 8px; top: 130px; }
  .header h1 { font-size: 15px; }
  #map { height: calc(100vh - 130px); }
}
