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

:root {
  --bg-dark: #0a0e27;
  --bg-card: rgba(15, 20, 45, 0.6);
  --glass-border: rgba(255, 255, 255, 0.1);
  --neon-cyan: #00f3ff;
  --neon-purple: #b800ff;
  --neon-pink: #ff006e;
  --text-primary: #e0e6ff;
  --text-secondary: #a0a8cc;
  --shadow-glow: 0 0 20px rgba(0, 243, 255, 0.3);
  --shadow-deep: 0 8px 32px rgba(0, 0, 0, 0.4);
}

html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(135deg, #0a0e27 0%, #1a0b2e 50%, #16213e 100%);
  color: var(--text-primary);
}

.app-wrapper { display: grid; grid-template-columns: 350px 1fr; height: 100vh; }
.sidebar {
  background: linear-gradient(135deg, #0a0e27 0%, #1a0b2e 100%);
  border-right: 1px solid var(--glass-border);
  overflow-y: auto; padding: 1.5rem; display: flex; flex-direction: column; gap: 1.5rem; z-index: 10;
}
.sidebar-footer { margin-top: auto; text-align: center; padding-top: 0.5rem; }
.credit-link { color: var(--text-secondary); font-size: 0.9rem; text-decoration: none; transition: color 0.2s ease, text-shadow 0.2s ease; }
.credit-link:hover { color: var(--neon-cyan); text-shadow: 0 0 8px rgba(0,243,255,0.5); }

/* Safety Score */
.safety-score-section { padding: 1rem 0; border-top: 1px solid var(--glass-border); margin-top: 0.5rem; }
.safety-score { display: grid; gap: 0.75rem; }

.score-badge { display: flex; flex-direction: column; align-items: center; gap: 0.25rem; }
.score-number { font-size: 2rem; font-weight: 800; line-height: 1; }
.score-label { font-size: 0.875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }

.score-breakdown { display: grid; gap: 0.5rem; font-size: 0.85rem; margin: 0.5rem 0; }
.breakdown-row { display: flex; justify-content: space-between; color: var(--text-secondary); }
.breakdown-row .breakdown-label { font-weight: 500; }
.breakdown-row .breakdown-value { color: var(--text-primary); font-weight: 600; }

.score-percentile { font-size: 0.875rem; text-align: center; color: var(--text-secondary); padding: 0.5rem; background: rgba(0,243,255,0.05); border-radius: 6px; }
.score-percentile strong { color: var(--neon-cyan); }

/* Score Colors */
.score-very-safe .score-number { color: #00ff88; text-shadow: 0 0 12px rgba(0,255,136,0.5); }
.score-very-safe .score-label { color: #00ff88; }

.score-safe .score-number { color: #7eff00; text-shadow: 0 0 12px rgba(126,255,0,0.5); }
.score-safe .score-label { color: #7eff00; }

.score-moderate .score-number { color: #ffcc00; text-shadow: 0 0 12px rgba(255,204,0,0.5); }
.score-moderate .score-label { color: #ffcc00; }

.score-caution .score-number { color: #ff8800; text-shadow: 0 0 12px rgba(255,136,0,0.5); }
.score-caution .score-label { color: #ff8800; }

.score-high-caution .score-number { color: #ff3333; text-shadow: 0 0 12px rgba(255,51,51,0.5); }
.score-high-caution .score-label { color: #ff3333; }

.score-unavailable { text-align: center; }
.score-status { font-size: 0.95rem; color: var(--text-secondary); font-weight: 500; }
.score-reason { font-size: 0.8rem; color: var(--text-secondary); margin-top: 0.25rem; }

.sidebar h2 {
  font-size: 1.5rem; font-weight: 700;
  background: linear-gradient(135deg, var(--neon-cyan), var(--neon-purple));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.map-container { position: relative; overflow: hidden; background: #000; }
#map { width: 100%; height: 100%; z-index: 1; }
.map-spinner-overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(10, 14, 39, 0.55); backdrop-filter: blur(4px); z-index: 10; }
.spinner { width: 64px; height: 64px; border-radius: 50%; border: 6px solid rgba(255,255,255,0.12); border-top-color: var(--neon-cyan); animation: spin 0.9s linear infinite; box-shadow: 0 0 20px rgba(0,243,255,0.35); will-change: transform; }
@keyframes spin { to { transform: rotate(360deg); } }

.control-section { display: flex; flex-direction: column; gap: 0.75rem; }
.control-section h3 { font-size: 0.875rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--neon-cyan); }
.control-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; align-items: end; }
.input-group { display: flex; flex-direction: column; gap: 0.5rem; position: relative; }
.input-group label { font-size: 0.875rem; color: var(--text-secondary); font-weight: 500; }

/* Switch */
.visualization-header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.visualization-header h3 { margin: 0; }
.switch-group { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.switch { position: relative; display: inline-block; width: 64px; height: 32px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track { position: absolute; inset: 0; cursor: pointer; background: rgba(255, 255, 255, 0.06); border-radius: 999px; border: 1px solid var(--glass-border); transition: all 0.25s ease; box-shadow: inset 2px 2px 6px rgba(0,0,0,0.35), inset -2px -2px 6px rgba(255,255,255,0.06); }
.switch-track::before { content: ""; position: absolute; height: 24px; width: 24px; left: 4px; top: 3px; background: linear-gradient(135deg, var(--neon-cyan), #6bdcff); border-radius: 50%; box-shadow: 0 4px 10px rgba(0,0,0,0.35); transition: all 0.25s ease; }
.switch input:checked + .switch-track { background: linear-gradient(135deg, rgba(0,243,255,0.25), rgba(184,0,255,0.18)); border-color: rgba(0,243,255,0.6); }
.switch input:checked + .switch-track::before { transform: translateX(30px); background: linear-gradient(135deg, #ff8ad6, #ff479a); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(0,243,255,0.25); }

button, select, input[type="text"] {
  padding: 0.875rem 1.25rem; font-size: 0.95rem; border: 1px solid var(--glass-border);
  border-radius: 12px; background: rgba(255, 255, 255, 0.05); backdrop-filter: blur(10px);
  color: var(--text-primary); font-weight: 500; cursor: pointer; transition: all 0.3s;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2); width: 100%;
}
button { text-align: center; white-space: nowrap; }
button.primary { border-color: var(--neon-cyan); font-weight: 600; }
button.secondary { border-color: var(--neon-purple); font-weight: 600; }

button:hover { border-color: var(--neon-cyan); box-shadow: 0 0 20px rgba(0,243,255,0.4), 0 4px 16px rgba(0,0,0,0.3); transform: translateY(-1px); }
button:active { transform: translateY(0); }
input[type="text"]::placeholder { color: var(--text-secondary); }
input[type="text"]:focus { outline: none; border-color: var(--neon-cyan); box-shadow: 0 0 20px rgba(0,243,255,0.3); }

.status { padding: 1rem; background: var(--bg-card); backdrop-filter: blur(20px); border: 1px solid var(--glass-border); border-radius: 12px; color: var(--neon-cyan); font-weight: 500; text-align: center; min-height: 2.5rem; display: flex; align-items: center; justify-content: center; }
.summary { background: linear-gradient(135deg, rgba(0, 243, 255, 0.1), rgba(184, 0, 255, 0.1)); border: 1px solid var(--glass-border); border-radius: 12px; padding: 1rem; font-size: 0.9rem; line-height: 1.5; box-shadow: var(--shadow-glow), var(--shadow-deep); }
.muted { color: var(--text-secondary); }

/* Suggestions */
.suggestions { position: absolute; top: 100%; left: 0; right: 0; background: var(--bg-card); backdrop-filter: blur(20px) saturate(180%); border: 1px solid var(--glass-border); border-radius: 12px; margin-top: 0.25rem; box-shadow: var(--shadow-deep); z-index: 1000; max-height: 260px; overflow-y: auto; }
.suggestion-item { padding: 0.75rem 1rem; border-bottom: 1px solid rgba(255,255,255,0.07); cursor: pointer; display: flex; flex-direction: column; gap: 0.25rem; }
.suggestion-item:hover { background: rgba(0,243,255,0.08); }
.suggestion-title { color: var(--text-primary); font-weight: 600; }
.suggestion-sub { color: var(--text-secondary); font-size: 0.85rem; }

/* Radius Slider */
.radius-slider-container { display: flex; flex-direction: column; gap: 0.75rem; }
.radius-slider { width: 100%; height: 6px; border-radius: 3px; background: linear-gradient(90deg, rgba(0,243,255,0.2), rgba(184,0,255,0.2)); outline: none; cursor: pointer; }
.radius-value-display { background: rgba(0,243,255,0.1); border: 1px solid var(--neon-cyan); border-radius: 8px; padding: 0.75rem 1rem; text-align: center; font-weight: 600; color: var(--neon-cyan); font-size: 0.95rem; }

/* Modals */
.modal { display: none; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: rgba(0,0,0,0.7); backdrop-filter: blur(5px); }
.modal.active { display: flex; align-items: center; justify-content: center; }
.modal-content { background: var(--bg-card); backdrop-filter: blur(20px) saturate(180%); border: 1px solid var(--glass-border); border-radius: 20px; padding: 2rem; max-width: 900px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-deep); position: relative; width: 90vw; }
.modal-content.modal-small { max-width: 650px; max-height: 70vh; }
.modal-close { position: absolute; top: 1rem; right: 1rem; background: rgba(255,255,255,0.1); border: 1px solid var(--glass-border); border-radius: 50%; width: 40px; height: 40px; cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; color: var(--text-primary); }
.modal h3 { color: var(--neon-cyan); margin-bottom: 1rem; font-size: 1.25rem; }

.crime-category-list { display: grid; gap: 1rem; }
.crime-item { background: rgba(0,0,0,0.2); border-left: 3px solid var(--neon-purple); padding: 1rem; border-radius: 8px; cursor: pointer; }
.crime-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.crime-item-title { font-weight: 600; color: var(--text-primary); text-transform: capitalize; }
.crime-item-count { background: linear-gradient(135deg, var(--neon-cyan), var(--neon-purple)); color: #000; padding: 0.25rem 0.75rem; border-radius: 20px; font-size: 0.875rem; font-weight: 700; }
.crime-item-details { display: none; margin-top: 0.75rem; padding-top: 0.75rem; border-top: 1px solid rgba(255,255,255,0.1); max-height: 400px; overflow-y: auto; }
.crime-item-details.show { display: block; }
.crime-detail { font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 0.5rem; line-height: 1.4; }
.crime-detail strong { color: var(--neon-cyan); }

/* Crime count label & popup */
.crime-count-label { background: transparent; color: var(--neon-cyan); border: none; border-radius: 0; padding: 0 !important; font-size: 0.9rem; font-weight: 800; min-width: 0; text-align: center; box-shadow: none; line-height: 1; text-shadow: 0 0 8px rgba(0,243,255,0.45); }
.crime-count-popup .leaflet-popup-content { margin: 0; padding: 6px 10px; }
.crime-count-popup .leaflet-popup-content-wrapper { background: rgba(15,20,45,0.95); border: 1px solid var(--neon-cyan); border-radius: 8px; box-shadow: 0 0 15px rgba(0,243,255,0.4); }

/* Responsive */
@media (max-width: 768px) {
  .app-wrapper { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .map-container { order: -1; height: 50vh; border-bottom: 1px solid var(--glass-border); }
  .sidebar { order: 1; max-height: 50vh; border-right: none; border-bottom: none; overflow-y: auto; padding: 1.25rem; gap: 1rem; }
  .sidebar h2 { font-size: 1.25rem; }
}
@media (max-width: 480px) {
  .app-wrapper { grid-template-rows: 45vh 1fr; }
  .map-container { height: 45vh; }
  .sidebar { max-height: 55vh; padding: 1rem; padding-bottom: calc(1rem + env(safe-area-inset-bottom)); gap: 0.75rem; display: flex; flex-direction: column; }
  button, select, input[type="text"] { padding: 0.75rem 1rem; font-size: 0.9rem; min-height: 44px; }
  button { white-space: normal; line-height: 1.2; overflow: visible; text-wrap: balance; }
  .sidebar > button { margin-top: 0; width: 100%; align-self: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
  /* keep spinner functional even with reduced motion */
  .spinner { animation: spin 0.9s linear infinite !important; }
}
