/* ==========================================================================
   Percepción de inseguridad en la ZMG
   Dashboard · Dark theme · Insecurity semantic scale
   ========================================================================== */

:root {
  /* Fondos y capas */
  --bg-main: #000000;
  --bg-surface: #0d0d0d;
  --bg-elevated: #1a1a1a;
  --border-muted: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(255, 255, 255, 0.15);

  /* Tipografía */
  --text-primary: #f5f5f5;
  --text-secondary: #c0c0c0;
  --text-muted: #808080;

  /* Semántica de inseguridad */
  --status-critical: #ff0000;
  --status-high: #ff8c00;
  --status-medium: #ffe700;
  --status-low: #fff400;

  /* Glow */
  --glow-red: 0 0 20px rgba(255, 0, 0, 0.3);
  --glow-orange: 0 0 20px rgba(255, 140, 0, 0.25);
  --glow-subtle: 0 0 40px rgba(255, 0, 0, 0.06);

  /* Acento */
  --accent: #ff8c00;

  /* Typography */
  --font-title: "Zilla Slab Highlight", serif;
  --font-body: "Instrument Sans", sans-serif;
  --font-data: "IBM Plex Mono", monospace;
  --font-mono: "IBM Plex Mono", monospace;

  /* Layout */
  --max-width: 1400px;
  --radius: 4px;
  --transition: 200ms ease-out;
}

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-main);
  color: var(--text-primary);
  line-height: 1.6;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition), text-shadow var(--transition);
}

a:hover {
  color: #ffaa44;
  text-shadow: 0 0 8px rgba(255, 140, 0, 0.4);
}

/* --- Header --- */
.dashboard-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: linear-gradient(180deg, var(--bg-main) 0%, rgba(0,0,0,0.95) 100%);
  margin-bottom: 2rem;
  padding: 1.25rem 0 1rem;
  border-bottom: 1px solid var(--border-muted);
  text-align: center;
}

.dashboard-header.scrolled {
  background: rgba(0, 0, 0, 0.97);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 4px 30px rgba(255, 0, 0, 0.05);
  padding: 0.5rem 0;
}

.header-collapsible { overflow: hidden; }
.dashboard-header.scrolled .header-collapsible { display: none; }

.title-main {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  line-height: 1.1;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  text-shadow: 0 0 40px rgba(255, 0, 0, 0.15), 0 0 80px rgba(255, 0, 0, 0.05);
  letter-spacing: 0.01em;
}

.subtitle {
  font-family: var(--font-body);
  font-size: 0.8125rem;
  color: var(--text-muted);
  line-height: 1.4;
  letter-spacing: 0.03em;
}

.author-credit {
  font-family: var(--font-body);
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 0.5rem;
}

.author-site {
  font-family: var(--font-body);
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 0.125rem;
}

/* --- KPI Strip --- */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  padding: 0.75rem;
  cursor: pointer;
  text-align: center;
  position: relative;
  overflow: hidden;
  transition: border-color 0.3s ease, box-shadow 0.3s ease, transform 0.3s ease;
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--status-critical), transparent);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.kpi-card:hover {
  border-color: var(--border-hover);
  transform: translateY(-3px);
  box-shadow: var(--glow-red);
}

.kpi-card:hover::before { opacity: 1; }

.kpi-card.active {
  border-color: var(--status-critical);
  box-shadow: 0 0 0 1px var(--status-critical), var(--glow-red);
}

.kpi-card.active::before { opacity: 1; }

.kpi-name {
  font-family: var(--font-body);
  font-size: 0.625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.kpi-value {
  font-family: var(--font-data);
  font-variant-numeric: tabular-nums;
  font-size: 1.75rem;
  font-weight: 500;
  color: var(--status-critical);
  line-height: 1;
  margin-bottom: 0.25rem;
  text-shadow: 0 0 30px rgba(255, 0, 0, 0.4);
}

.kpi-delta {
  font-family: var(--font-data);
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
}

.kpi-delta.up { color: var(--status-critical); }
.kpi-delta.down { color: var(--status-medium); }

.kpi-delta-label {
  color: var(--text-muted);
  font-size: 0.625rem;
}

/* --- Slider Section --- */
.slider-section {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding: 0.625rem 1.25rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
}

.slider-label {
  font-family: var(--font-body);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  white-space: nowrap;
}

#quarter-slider {
  flex: 1;
  height: 3px;
  -webkit-appearance: none;
  appearance: none;
  background: linear-gradient(90deg, var(--status-medium) 0%, var(--status-critical) 100%);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
  opacity: 0.5;
  transition: opacity var(--transition);
}

#quarter-slider:hover { opacity: 0.8; }

#quarter-slider:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

#quarter-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-primary);
  border: none;
  cursor: pointer;
  box-shadow: 0 0 10px rgba(255, 255, 255, 0.3);
  transition: transform var(--transition), box-shadow var(--transition);
}

#quarter-slider::-webkit-slider-thumb:hover {
  transform: scale(1.3);
  box-shadow: 0 0 16px rgba(255, 255, 255, 0.5);
}

#quarter-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-primary);
  border: none;
  cursor: pointer;
}

.quarter-display {
  font-family: var(--font-data);
  font-variant-numeric: tabular-nums;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  min-width: 5.5rem;
  text-align: right;
}

.play-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-muted);
  border-radius: 50%;
  width: 32px;
  height: 32px;
  font-size: 0.75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.3s ease;
}

.play-btn:hover {
  color: var(--text-primary);
  border-color: var(--text-primary);
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.15);
}

.play-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Panels --- */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  padding: 1.5rem;
  position: relative;
  transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.panel:hover {
  border-color: var(--border-hover);
  box-shadow: var(--glow-subtle);
}

.panel-title {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.8125rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 0.125rem;
  text-align: center;
}

.panel-period {
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 1rem;
  font-variant-numeric: tabular-nums;
}

/* --- Grids --- */
.grid-main {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.grid-secondary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

#map-container {
  height: 420px;
  border-radius: var(--radius);
  background: var(--bg-main);
}

#timeline-container { height: 420px; }

/* --- Map Legend --- */
.map-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-family: var(--font-data);
  font-size: 0.6875rem;
  color: var(--text-muted);
  align-items: center;
}

.map-legend .legend-gradient {
  width: 180px;
  height: 8px;
  border-radius: 4px;
  display: inline-block;
}

#spaces-container,
#antisocial-container,
#behavior-container,
#gender-container {
  width: 100%;
  min-height: 350px;
}

/* --- Tooltip --- */
.tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(13, 13, 13, 0.96);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 6px;
  padding: 0.625rem 0.875rem;
  font-family: var(--font-data);
  font-size: 0.8125rem;
  color: var(--text-primary);
  z-index: 1000;
  white-space: nowrap;
  max-width: 320px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255,255,255,0.04);
  transition: opacity 100ms ease;
}

.tooltip-title {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.tooltip-value {
  font-family: var(--font-data);
  font-variant-numeric: tabular-nums;
  font-size: 0.9375rem;
  color: var(--text-primary);
}

.tooltip.visible { opacity: 1; }

/* --- Leaflet Dark --- */
.leaflet-container { background: var(--bg-main); }

.leaflet-control-attribution {
  background: rgba(0, 0, 0, 0.8) !important;
  color: var(--text-muted) !important;
  font-size: 0.5625rem;
}

.leaflet-control-attribution a { color: var(--text-muted) !important; }

.leaflet-control-zoom a {
  background: var(--bg-elevated) !important;
  color: var(--text-secondary) !important;
  border-color: var(--border-muted) !important;
}

.leaflet-control-zoom a:hover {
  background: var(--bg-surface) !important;
  color: var(--text-primary) !important;
}

/* --- Footer --- */
.dashboard-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding-top: 2rem;
  margin-top: 1.5rem;
  border-top: 1px solid var(--border-muted);
}

.footer-credits {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.footer-link { font-size: 0.75rem; }

.footer-location {
  font-family: var(--font-body);
  font-size: 0.6875rem;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  margin-top: 0.75rem;
  width: 100%;
  text-align: center;
}

.methodology-btn {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  padding: 0.5rem 1.25rem;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.3s ease;
}

.methodology-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--glow-orange);
}

.methodology-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-content {
  background: var(--bg-elevated);
  border: 1px solid var(--border-muted);
  border-radius: 6px;
  padding: 2.5rem;
  max-width: 700px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  color: var(--text-primary);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6), var(--glow-subtle);
}

.modal-content h3 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.modal-content p {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  line-height: 1.7;
}

.modal-close {
  position: absolute;
  top: 1rem; right: 1.25rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
  transition: color var(--transition);
}

.modal-close:hover { color: var(--text-primary); }

.modal-downloads {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.download-btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: transparent;
  border: 1px solid var(--border-muted);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  text-decoration: none;
  letter-spacing: 0.02em;
  transition: all 0.3s ease;
}

.download-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: var(--glow-orange);
}

/* --- SVG / D3 defaults --- */
svg text {
  font-family: var(--font-data);
  fill: var(--text-muted);
  font-size: 0.6875rem;
}

svg .axis line, svg .axis path {
  stroke: rgba(255, 255, 255, 0.06);
}

svg .axis text {
  fill: var(--text-muted);
  font-size: 0.625rem;
}

/* --- Responsive --- */
@media (min-width: 1440px) {
  :root { --max-width: 1600px; }
}

@media (max-width: 1024px) {
  .panel { padding: 1rem; }
}

@media (max-width: 900px) {
  .grid-main { grid-template-columns: 1fr; }
  .grid-secondary { grid-template-columns: 1fr; }
  .kpi-strip { grid-template-columns: repeat(3, 1fr); }
  #map-container { height: 320px; }
  #timeline-container { height: 320px; }
  #spaces-container, #antisocial-container, #behavior-container, #gender-container { min-height: 280px; }
  .dashboard-footer { flex-direction: column; gap: 1rem; }
  .footer-credits { flex-direction: column; gap: 0.5rem; }
}

@media (max-width: 600px) {
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .slider-section { flex-wrap: wrap; }
  #quarter-slider { order: 3; flex-basis: 100%; }
  #map-container { height: 280px; }
  #timeline-container { height: 280px; }
  #spaces-container, #antisocial-container, #behavior-container, #gender-container { min-height: 240px; }
  .panel { padding: 1rem 0.75rem; }
}

@media (max-width: 480px) {
  body { padding: 0.75rem 0.5rem; }
  .panel { padding: 0.75rem 0.5rem; }
  .kpi-strip { gap: 0.5rem; }
  .grid-main { gap: 0.5rem; }
  .grid-secondary { gap: 0.5rem; }
  .title-main { font-size: 1.25rem; }
  .tooltip { max-width: 220px; white-space: normal; }
  #map-container { height: 250px; }
  #timeline-container { height: 250px; }
  .panel-title { font-size: 0.75rem; }
}

@media (max-width: 375px) {
  .kpi-strip { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .kpi-value { font-size: 1.25rem; }
  .kpi-name { font-size: 0.5625rem; }
  .slider-label { font-size: 0.5625rem; }
  .quarter-display { font-size: 0.75rem; min-width: 4.5rem; }
}

/* --- Accessibility --- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
