:root {
  --bg-dark: #0a0f1d;
  --bg-card: rgba(16, 24, 40, 0.92);
  --bg-card-hover: rgba(26, 38, 64, 0.95);
  --border-card: rgba(255, 255, 255, 0.1);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --accent-blue: #0284c7;
  --accent-cyan: #06b6d4;
  --color-critico: #ef4444;
  --color-alto: #f97316;
  --color-moderado: #eab308;
  --color-bajo: #10b981;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Header & Top Filter Bar */
.app-header {
  height: 64px;
  background: rgba(10, 15, 29, 0.96);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-card);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  z-index: 1000;
}

.brand-section {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-badge {
  background: linear-gradient(135deg, #ef4444, #f97316);
  color: white;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: white;
}

.brand-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.filters-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  max-width: 820px;
  margin: 0 1.5rem;
}

.search-box {
  position: relative;
  flex: 1.2;
}

.search-box input {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-card);
  border-radius: 8px;
  padding: 0.45rem 0.75rem 0.45rem 2rem;
  color: white;
  font-size: 0.85rem;
  transition: all 0.2s;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent-cyan);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 0 10px rgba(6, 182, 212, 0.25);
}

.search-icon {
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.filter-select {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-card);
  color: white;
  padding: 0.45rem 0.65rem;
  border-radius: 8px;
  font-size: 0.82rem;
  cursor: pointer;
  outline: none;
}

.filter-select option {
  background: #0f172a;
  color: white;
}

.action-buttons {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.btn-radar {
  background: rgba(2, 132, 199, 0.18);
  border: 1px solid rgba(2, 132, 199, 0.5);
  color: #38bdf8;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-radar:hover {
  background: rgba(2, 132, 199, 0.35);
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.3);
}

.btn-report {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border: none;
  color: white;
  padding: 0.45rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35);
  transition: all 0.2s;
}

.btn-report:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(239, 68, 68, 0.5);
}

.btn-pdf {
  background: rgba(234, 179, 8, 0.15);
  border: 1px solid rgba(234, 179, 8, 0.5);
  color: #facc15;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-pdf:hover {
  background: rgba(234, 179, 8, 0.3);
  box-shadow: 0 0 12px rgba(250, 204, 21, 0.35);
}

/* Floating Action Button for Map Reporting */
.fab-report-btn {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #ef4444, #b91c1c);
  color: white;
  border: 2px solid rgba(255, 255, 255, 0.3);
  padding: 0.75rem 1.4rem;
  border-radius: 30px;
  font-size: 0.92rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  z-index: 800;
  box-shadow: 0 8px 24px rgba(239, 68, 68, 0.6);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.fab-report-btn:hover {
  transform: translateX(-50%) scale(1.05);
  box-shadow: 0 10px 28px rgba(239, 68, 68, 0.8);
}

/* Layout Main */
.main-container {
  position: relative;
  flex: 1;
  width: 100%;
  display: flex;
}

#map {
  width: 100%;
  height: 100%;
  background: #080d1a;
  z-index: 1;
}

/* Sidebar Overlay */
.sidebar {
  position: absolute;
  top: 1rem;
  right: 1rem;
  width: 360px;
  max-height: calc(100% - 2rem);
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border-card);
  border-radius: 14px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.55);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-card);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.sidebar-title {
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.stat-pills {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-card);
}

.stat-card {
  background: rgba(255, 255, 255, 0.04);
  padding: 0.6rem;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.stat-value {
  font-size: 1.1rem;
  font-weight: 700;
  color: white;
  margin-top: 0.2rem;
}

.layer-switch-bar {
  display: flex;
  gap: 0.4rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-card);
}

.layer-btn {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-card);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.4rem 0.2rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

.layer-btn.active {
  background: var(--accent-blue);
  color: white;
  border-color: var(--accent-cyan);
}

/* Reports Feed inside Sidebar */
.feed-container {
  flex: 1;
  overflow-y: auto;
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.feed-header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.incident-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-card);
  border-radius: 10px;
  padding: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
}

.incident-card:hover {
  background: var(--bg-card-hover);
  border-color: rgba(6, 182, 212, 0.4);
  transform: translateX(-2px);
}

.incident-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
}

.incident-type {
  font-size: 0.82rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.badge-exacta {
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.badge-protegida {
  background: rgba(168, 85, 247, 0.15);
  color: #c084fc;
  font-size: 0.65rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
}

.incident-sector {
  font-size: 0.75rem;
  color: #38bdf8;
  font-weight: 600;
}

.incident-desc {
  font-size: 0.78rem;
  color: #cbd5e1;
  line-height: 1.35;
  margin-bottom: 0.4rem;
}

.incident-footer {
  display: flex;
  justify-content: space-between;
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Modal Styling */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 2000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content {
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 16px;
  width: 100%;
  max-width: 540px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-card);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: white;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.25rem;
  cursor: pointer;
}

.modal-body {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  max-height: 75vh;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.privacy-banner {
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 0.75rem;
  border-radius: 8px;
  font-size: 0.78rem;
  color: #6ee7b7;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* Precision Mode Selector */
.precision-selector {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.precision-card {
  border: 2px solid var(--border-card);
  background: rgba(255, 255, 255, 0.03);
  border-radius: 10px;
  padding: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.precision-card.active {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.1);
}

.precision-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: white;
}

.precision-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #cbd5e1;
}

.crime-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.crime-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-card);
  color: white;
  padding: 0.55rem 0.6rem;
  border-radius: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s;
}

.crime-chip.active {
  background: rgba(239, 68, 68, 0.2);
  border-color: #ef4444;
  color: #fca5a5;
}

.form-input, .form-textarea, .form-select-modal {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-card);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  color: white;
  font-size: 0.85rem;
  outline: none;
}

.form-input:focus, .form-textarea:focus, .form-select-modal:focus {
  border-color: var(--accent-cyan);
}

.form-textarea {
  min-height: 70px;
  resize: vertical;
}

.time-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.4rem;
}

.time-chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-card);
  color: var(--text-muted);
  padding: 0.45rem 0.2rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
}

.time-chip.active {
  background: var(--accent-blue);
  color: white;
  border-color: var(--accent-cyan);
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-card);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border-card);
  color: var(--text-muted);
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  cursor: pointer;
}

.btn-primary {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border: none;
  color: white;
  padding: 0.55rem 1.25rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(239, 68, 68, 0.4);
}

/* Radar pulse animation for User GPS Location */
.user-radar-marker {
  width: 20px;
  height: 20px;
  background: #38bdf8;
  border: 3px solid white;
  border-radius: 50%;
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.8);
  position: relative;
}

.user-radar-pulse {
  position: absolute;
  top: -15px;
  left: -15px;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.4);
  animation: radarWave 2s infinite ease-out;
}

@keyframes radarWave {
  0% { transform: scale(0.4); opacity: 1; }
  100% { transform: scale(2.2); opacity: 0; }
}

/* Custom Crime Marker Pins */
.custom-crime-pin {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  border: 2px solid white;
  box-shadow: 0 4px 10px rgba(0,0,0,0.6);
  cursor: pointer;
  transition: transform 0.2s;
}

.custom-crime-pin:hover {
  transform: scale(1.25);
  z-index: 1000 !important;
}

.pin-atraco { background: #ef4444; }
.pin-moto { background: #f97316; }
.pin-vehiculo { background: #8b5cf6; }
.pin-hurto { background: #eab308; }
.pin-vivienda { background: #ec4899; }
.pin-otro { background: #06b6d4; }

/* Header Inner Container */
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 100%;
}

/* Controles de Navegación Móvil (Ocultos por defecto en Escritorio) */
.mobile-actions-bar {
  display: none;
}

.mobile-close-sidebar {
  display: none;
}

/* ==========================================================================
   RESPONSIVE DESIGN (Tablets y Smartphones)
   ========================================================================== */

@media (max-width: 992px) {
  .app-header {
    height: 56px;
    padding: 0 0.75rem;
    position: relative;
  }

  .brand-title {
    font-size: 0.98rem;
    font-weight: 700;
  }

  .brand-subtitle {
    display: none !important;
  }

  .brand-badge {
    font-size: 0.68rem;
    padding: 0.15rem 0.35rem;
  }

  /* Ocultar barra horizontal fija de escritorio y reemplazar por drawer móvil */
  .filters-bar {
    display: none !important;
    position: absolute;
    top: 56px;
    left: 0;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0.85rem 1rem;
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border-card);
    flex-direction: column;
    gap: 0.6rem;
    z-index: 2100;
    box-shadow: 0 14px 28px rgba(0, 0, 0, 0.75);
    box-sizing: border-box;
    animation: slideDown 0.22s ease-out;
  }

  @keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
  }

  .filters-bar.mobile-open {
    display: flex !important;
  }

  .search-box {
    width: 100%;
    flex: none;
  }

  .filter-select {
    width: 100%;
  }

  /* Ocultar botones desktop y mostrar iconos táctiles de cabecera */
  .action-buttons {
    display: none !important;
  }

  .mobile-actions-bar {
    display: flex !important;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
  }

  .btn-mobile-action {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 9px;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    padding: 0;
    box-sizing: border-box;
  }

  .btn-mobile-action:active, .btn-mobile-action.active {
    background: var(--accent-blue);
    border-color: var(--accent-cyan);
    transform: scale(0.92);
  }

  .btn-radar-mobile {
    background: rgba(2, 132, 199, 0.25);
    border-color: rgba(56, 189, 248, 0.5);
  }

  .btn-report-mobile {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    border-color: #ef4444;
  }

  /* Sidebar convertido en Bottom Sheet deslizable en Móviles (OCULTO abajo por defecto) */
  .sidebar {
    position: fixed !important;
    top: auto !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
    height: 72vh !important;
    max-height: 72vh !important;
    border-radius: 20px 20px 0 0 !important;
    transform: translateY(110%) !important;
    transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1) !important;
    z-index: 3000 !important;
    background: rgba(15, 23, 42, 0.98) !important;
    backdrop-filter: blur(20px) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    box-shadow: 0 -12px 36px rgba(0, 0, 0, 0.85) !important;
    margin: 0 !important;
  }

  .sidebar.mobile-open {
    transform: translateY(0) !important;
  }

  .mobile-close-sidebar {
    display: block;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--border-card);
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
  }

  /* Botón Flotante de Reporte en Celulares (Elevado para flotar sobre la barra de Android/iOS) */
  .fab-report-btn {
    bottom: 38px !important;
    bottom: calc(34px + env(safe-area-inset-bottom, 0px)) !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    width: auto !important;
    max-width: 90% !important;
    padding: 0.72rem 1.25rem !important;
    font-size: 0.85rem !important;
    white-space: nowrap !important;
    justify-content: center !important;
    z-index: 1200 !important;
    box-shadow: 0 8px 24px rgba(239, 68, 68, 0.7) !important;
  }

  /* Ocultar atribuciones en móviles para acabado 100% nativo y limpio */
  .leaflet-control-attribution {
    display: none !important;
  }

  /* Elevar controles inferiores de Leaflet (capas) para que no queden cortados */
  .leaflet-bottom {
    bottom: 32px !important;
    bottom: calc(28px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .leaflet-control-layers {
    background: rgba(15, 23, 42, 0.85) !important;
    backdrop-filter: blur(12px) !important;
    border: 1px solid rgba(255, 255, 255, 0.2) !important;
    border-radius: 12px !important;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.6) !important;
  }

  .leaflet-control-layers-toggle {
    filter: invert(1) brightness(1.5);
  }

  .leaflet-top.leaflet-left {
    top: 12px !important;
    left: 12px !important;
  }
}

@media (max-width: 640px) {
  /* Modal responsive full bottom-sheet */
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }

  .modal-content {
    max-width: 100%;
    width: 100%;
    max-height: 88vh;
    border-radius: 20px 20px 0 0;
    border-bottom: none;
  }

  .modal-body {
    padding: 1rem 1.1rem;
    gap: 0.9rem;
  }

  .precision-selector {
    grid-template-columns: 1fr;
  }

  .crime-grid {
    grid-template-columns: 1fr 1fr;
  }

  .time-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
