/* Tacoma Safety — Styles */
/* Branding: Tacoma greens/blues + clean modern UI */

:root {
  --tacoma-green: #00594C;
  --tacoma-green-light: #00796B;
  --tacoma-blue: #0D47A1;
  --tacoma-blue-light: #1976D2;
  --bg-primary: #ffffff;
  --bg-secondary: #f5f7fa;
  --bg-card: #ffffff;
  --text-primary: #1a1a2e;
  --text-secondary: #555;
  --text-muted: #888;
  --border: #e0e0e0;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-card: #16213e;
  --text-primary: #e0e0e0;
  --text-secondary: #aaa;
  --text-muted: #777;
  --border: #2a2a4a;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.4);
}

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

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

/* Header */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: var(--tacoma-green);
  color: white;
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

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

.header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.header h1 span {
  font-weight: 300;
  opacity: 0.85;
}

.header-badge {
  background: rgba(255,255,255,0.15);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

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

.header-btn {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-btn:hover {
  background: rgba(255,255,255,0.22);
}

/* Search */
.search-container {
  position: fixed;
  top: 66px;
  left: 16px;
  z-index: 900;
  width: 340px;
}

.search-box {
  display: flex;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  border: 1px solid var(--border);
}

.search-box input {
  flex: 1;
  padding: 12px 16px;
  border: none;
  background: transparent;
  font-size: 14px;
  color: var(--text-primary);
  outline: none;
}

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

.search-box button {
  background: var(--tacoma-green);
  border: none;
  color: white;
  padding: 12px 16px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}

.search-box button:hover {
  background: var(--tacoma-green-light);
}

.search-results {
  margin-top: 4px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  max-height: 200px;
  overflow-y: auto;
  display: none;
}

.search-results.active { display: block; }

.search-result-item {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.search-result-item:hover {
  background: var(--bg-secondary);
}

.search-result-item:last-child { border-bottom: none; }

/* Map */
#map {
  position: fixed;
  top: 56px;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1;
}

/* Layer Controls */
.layer-controls {
  position: fixed;
  top: 66px;
  right: 16px;
  z-index: 900;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  padding: 12px 16px;
  min-width: 200px;
}

.layer-controls h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.layer-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
}

.layer-toggle input[type="checkbox"] {
  accent-color: var(--tacoma-green);
  width: 16px;
  height: 16px;
}

.layer-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.layer-count {
  margin-left: auto;
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 2px 8px;
  border-radius: 10px;
}

/* Stats Bar */
.stats-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 900;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 24px;
  font-size: 13px;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-secondary);
}

.stat-value {
  font-weight: 700;
  color: var(--text-primary);
  font-size: 16px;
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.stat-trend {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
}

.stat-trend.up {
  color: #e74c3c;
  background: rgba(231, 76, 60, 0.1);
}

.stat-trend.down {
  color: #27ae60;
  background: rgba(39, 174, 96, 0.1);
}

/* Neighborhood Panel */
.neighborhood-panel {
  position: fixed;
  bottom: 50px;
  left: 16px;
  z-index: 900;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  width: 380px;
  max-height: 50vh;
  overflow-y: auto;
  display: none;
  animation: slideUp 0.25s ease;
}

.neighborhood-panel.active { display: block; }

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
}

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

.panel-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 6px;
  transition: all 0.15s;
}

.panel-close:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.panel-summary {
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.summary-card {
  background: var(--bg-secondary);
  padding: 12px;
  border-radius: var(--radius-sm);
  text-align: center;
}

.summary-card .number {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
}

.summary-card .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.summary-card .trend {
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
}

.panel-breakdown {
  padding: 0 20px 16px;
}

.panel-breakdown h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 10px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.breakdown-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  font-size: 13px;
}

.breakdown-bar-container {
  flex: 1;
  height: 6px;
  background: var(--bg-secondary);
  border-radius: 3px;
  overflow: hidden;
}

.breakdown-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

.breakdown-count {
  font-weight: 600;
  min-width: 24px;
  text-align: right;
  font-size: 12px;
}

.breakdown-label {
  min-width: 100px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* Legend */
.legend-section {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.legend-section h4 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.legend-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-secondary);
  padding: 2px 0;
}

/* Leaflet popup customization */
.leaflet-popup-content-wrapper {
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow-lg) !important;
}

.incident-popup {
  padding: 4px;
}

.incident-popup h4 {
  font-size: 14px;
  margin-bottom: 6px;
  color: #1a1a2e;
}

.incident-popup .popup-meta {
  font-size: 12px;
  color: #666;
  margin-bottom: 4px;
}

.incident-popup .popup-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  color: white;
}

/* Custom marker styles */
.custom-marker {
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
  transition: transform 0.15s;
}

.custom-marker:hover {
  transform: scale(1.3);
  z-index: 10000 !important;
}

/* Mobile */
@media (max-width: 768px) {
  .search-container {
    width: calc(100% - 32px);
  }
  
  .layer-controls {
    top: auto;
    bottom: 56px;
    right: 16px;
    min-width: 160px;
  }

  .neighborhood-panel {
    width: calc(100% - 32px);
    left: 16px;
    bottom: 56px;
    max-height: 45vh;
  }

  .stats-bar {
    flex-wrap: wrap;
    gap: 12px;
    padding: 8px 16px;
  }

  .header h1 { font-size: 15px; }
  .header-badge { display: none; }
}

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

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

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

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

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

.loading-content p {
  color: var(--text-muted);
  font-size: 14px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
