/* ==========================================================
   SafeWay · Hoja de estilos principal
   Tema claro basado estrictamente en UI_GUIDE.md
   ========================================================== */

/* Variables globales */
:root {
  /* Colores institucionales de la guía */
  --azul-institucional: #1e3a8a;
  --azul-hover: #172c6b;
  --azul-suave: #eff6ff;
  --azul-borde: #bfdbfe;
  --blanco: #ffffff;
  --texto: #1f2937;
  --texto-suave: #6b7280;

  /* Bordes y fondos */
  --borde: #e5e7eb;
  --borde-input: #d1d5db;
  --fondo-pagina: #f3f4f6;
  --fondo-panel: rgba(255, 255, 255, 0.95);

  /* Colores de categorías y estados */
  --peligro: #ef4444;
  --amarillo: #f59e0b;
  --verde: #22c55e;
  --azul-categoria: #3b82f6;

  /* Sombras suaves */
  --sombra-panel: 0 10px 30px rgba(15, 23, 42, 0.12);
  --sombra-modal: 0 24px 60px rgba(15, 23, 42, 0.22);

  /* Radios */
  --radio: 12px;
  --radio-modal: 8px;
}

/* Reset básico */
* {
  box-sizing: border-box;
}

html,
body {
  width: 100vw;
  height: 100vh;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background: var(--fondo-pagina);
  color: var(--texto);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* Utilidad para ocultar elementos */
.oculto {
  display: none !important;
}

/* ==========================================================
   Mapa a pantalla completa
   ========================================================== */
#mapa {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100vw;
  height: 100vh;
  background: #e5e7eb;
}

/* Cursor especial cuando el usuario va a reportar */
#mapa.modo-reporte {
  cursor: crosshair;
}

#mapa.modo-seleccion {
  cursor: crosshair;
}

.leaflet-container {
  font-family: inherit;
  background: #e5e7eb;
}

/* Popups de Leaflet con estilo claro */
.leaflet-popup-content-wrapper {
  border-radius: var(--radio-modal);
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
  color: var(--texto);
}

.leaflet-popup-content {
  margin: 12px 14px;
}

/* Pines temporales para marcar Origen y Destino en el mapa */
.marcador-seleccion {
  background: transparent;
  border: none;
}

.marcador-seleccion span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 3px solid var(--blanco);
  border-radius: 50% 50% 50% 0;
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.25);
  transform: rotate(-45deg);
}

.marcador-seleccion b {
  color: var(--blanco);
  font-size: 0.72rem;
  font-weight: 800;
  transform: rotate(45deg);
}

/* ==========================================================
   Panel lateral izquierdo
   ========================================================== */
.panel {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 1000;
  width: 300px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  padding: 20px;
  overflow-y: auto;
  border: 1px solid rgba(229, 231, 235, 0.9);
  border-radius: var(--radio);
  background: var(--fondo-panel);
  color: var(--texto);
  box-shadow: var(--sombra-panel);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  scrollbar-width: thin;
  scrollbar-color: #cbd5e1 transparent;
}

.panel::-webkit-scrollbar {
  width: 6px;
}

.panel::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 999px;
}

.panel-encabezado h1 {
  margin: 0;
  font-size: 1.9rem;
  letter-spacing: -0.03em;
  line-height: 1;
  color: var(--texto);
}

.panel-encabezado h1 span {
  color: var(--azul-institucional);
}

.panel-encabezado p {
  margin: 8px 0 0;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--texto-suave);
}

/* ==========================================================
   Área de sesión
   ========================================================== */
.auth-area {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 14px;
}

.usuario-email {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  color: var(--texto-suave);
  font-size: 0.72rem;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-auth {
  flex-shrink: 0;
  width: auto;
  padding: 6px 10px;
  border: 1px solid var(--azul-borde);
  border-radius: var(--radio-modal);
  background: var(--azul-suave);
  color: var(--azul-institucional);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-auth:hover {
  border-color: #93c5fd;
  background: #dbeafe;
}

/* Variante visual cuando el botón cierra la sesión */
.btn-auth.cerrar {
  border-color: #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

.btn-auth.cerrar:hover {
  background: #fee2e2;
}

.btn-auth:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

/* ==========================================================
   Botones generales
   ========================================================== */
.btn {
  width: 100%;
  border: none;
  border-radius: var(--radio-modal);
  padding: 12px 14px;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease,
    transform 0.15s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
  transform: none;
}

/* Botón de reportar problema */
.btn-reportar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  margin: 16px 0 22px;
  background: var(--azul-institucional);
  color: var(--blanco);
  box-shadow: 0 6px 16px rgba(30, 58, 138, 0.18);
}

.btn-reportar:hover {
  background: var(--azul-hover);
  box-shadow: 0 8px 20px rgba(30, 58, 138, 0.24);
}

.btn-reportar .icono {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  color: var(--blanco);
  font-size: 0.8rem;
  font-weight: 900;
}

/* ==========================================================
   Sección Buscar Ruta
   ========================================================== */
.seccion-ruta {
  padding-top: 18px;
  border-top: 1px solid var(--borde);
}

.seccion-ruta h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
  color: var(--texto);
}

.ayuda {
  margin: 5px 0 4px;
  font-size: 0.74rem;
  line-height: 1.4;
  color: var(--texto-suave);
}

.nota-ruta {
  margin: 9px 0 0;
  color: var(--texto-suave);
  font-size: 0.72rem;
  line-height: 1.4;
}

.seccion-ruta label {
  display: block;
  margin: 11px 0 6px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #374151;
}

/* Inputs y selector del panel */
.seccion-ruta input,
.seccion-ruta select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--borde-input);
  border-radius: var(--radio-modal);
  background: var(--blanco);
  color: var(--texto);
  font: inherit;
  font-size: 0.86rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.seccion-ruta input::placeholder {
  color: #9ca3af;
}

.seccion-ruta input:focus,
.seccion-ruta select:focus {
  border-color: var(--azul-institucional);
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.12);
}

.btn-marcar {
  margin-top: 12px;
  border: 1px solid var(--azul-borde);
  background: var(--blanco);
  color: var(--azul-institucional);
  box-shadow: none;
}

.btn-marcar:hover {
  background: var(--azul-suave);
  box-shadow: none;
}

.btn-marcar.activo {
  border-color: var(--azul-institucional);
  background: var(--azul-suave);
}

.btn-trazar {
  margin-top: 14px;
  background: var(--azul-institucional);
  color: var(--blanco);
  box-shadow: 0 6px 16px rgba(30, 58, 138, 0.16);
}

.btn-trazar:hover {
  background: var(--azul-hover);
  box-shadow: 0 8px 20px rgba(30, 58, 138, 0.22);
}

.mensaje-seleccion {
  margin: 10px 0 0;
  padding: 9px 11px;
  border: 1px solid #bbf7d0;
  border-radius: var(--radio-modal);
  background: #f0fdf4;
  color: #15803d;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.4;
}

.info-ruta {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #dbeafe;
  border-radius: var(--radio-modal);
  background: var(--azul-suave);
  color: var(--texto);
  font-size: 0.8rem;
  line-height: 1.5;
}

.info-ruta:empty {
  display: none;
}

.info-riesgo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--texto);
}

.info-riesgo strong {
  color: var(--texto);
}

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

.detalle-reportes {
  display: block;
  margin-top: 3px;
  color: var(--texto-suave);
  font-size: 0.74rem;
}

.alerta-riesgo {
  margin-top: 8px;
  padding: 8px 10px;
  border-left: 3px solid var(--verde);
  border-radius: 6px;
  background: #f0fdf4;
  color: #166534;
  font-size: 0.76rem;
  font-weight: 600;
  line-height: 1.4;
}

.alerta-riesgo.alta {
  border-left-color: var(--peligro);
  background: #fef2f2;
  color: #991b1b;
}

.alerta-riesgo.media {
  border-left-color: var(--amarillo);
  background: #fffbeb;
  color: #92400e;
}

.leyenda-alternativa {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 9px;
  color: var(--texto-suave);
  font-size: 0.72rem;
  font-weight: 600;
}

.leyenda-alternativa::before {
  content: "";
  width: 24px;
  border-top: 3px dashed #9ca3af;
}

.nota-alternativa {
  display: block;
  margin-top: 7px;
  color: var(--texto-suave);
  font-size: 0.7rem;
  line-height: 1.35;
}

/* ==========================================================
   Leyenda y pie del panel
   ========================================================== */
.leyenda {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--borde);
}

.leyenda h3 {
  margin: 0 0 10px;
  color: var(--texto-suave);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.leyenda ul {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--texto);
  font-size: 0.84rem;
}

.leyenda li {
  display: flex;
  align-items: center;
  gap: 8px;
}

.punto {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(15, 23, 42, 0.06);
}

.punto.seguridad {
  background: var(--peligro);
}

.punto.pavimento {
  background: var(--amarillo);
}

.punto.iluminacion {
  background: var(--azul-categoria);
}

.panel-pie {
  margin-top: 16px;
  color: var(--texto-suave);
  font-size: 0.72rem;
  line-height: 1.4;
}

/* ==========================================================
   Modales (reporte e inicio de sesión)
   ========================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(31, 41, 55, 0.35);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.modal {
  width: 100%;
  max-width: 420px;
  padding: 22px;
  border: 1px solid var(--borde);
  border-radius: var(--radio-modal);
  background: var(--blanco);
  color: var(--texto);
  box-shadow: var(--sombra-modal);
  animation: aparecer-modal 0.2s ease-out;
}

@keyframes aparecer-modal {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-encabezado {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.modal h2 {
  margin: 0;
  color: var(--texto);
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.modal-subtitulo {
  margin: 4px 0 0;
  color: var(--texto-suave);
  font-size: 0.78rem;
  line-height: 1.4;
}

.btn-icono {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 50%;
  background: #f3f4f6;
  color: #4b5563;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.15s ease;
}

.btn-icono:hover {
  background: var(--borde);
}

.modal label {
  display: block;
  margin: 12px 0 6px;
  color: #374151;
  font-size: 0.84rem;
  font-weight: 700;
}

/* Campos del modal: fondo blanco y bordes grises claros */
.modal input,
.modal select,
.modal textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--borde-input);
  border-radius: var(--radio-modal);
  background: var(--blanco);
  color: var(--texto);
  font: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.modal textarea {
  min-height: 100px;
  resize: vertical;
}

.modal input::placeholder,
.modal textarea::placeholder {
  color: #9ca3af;
}

.modal input:focus,
.modal select:focus,
.modal textarea:focus {
  border-color: var(--azul-institucional);
  box-shadow: 0 0 0 3px rgba(30, 58, 138, 0.12);
}

.modal-acciones {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.modal-acciones .btn {
  flex: 1;
  width: auto;
}

.btn-secundario {
  border: 1px solid var(--borde);
  background: #f3f4f6;
  color: #374151;
}

.btn-secundario:hover {
  background: var(--borde);
}

.btn-primario {
  background: var(--azul-institucional);
  color: var(--blanco);
}

.btn-primario:hover {
  background: var(--azul-hover);
}

/* Mensajes dentro del modal de reporte */
.error-reporte {
  margin: 12px 0 0;
  padding: 9px 11px;
  border: 1px solid #fecaca;
  border-radius: var(--radio-modal);
  background: #fef2f2;
  color: #b91c1c;
  font-size: 0.8rem;
  line-height: 1.4;
}

/* Mensajes del modal de sesión */
.mensaje-auth {
  margin: 12px 0 0;
  padding: 9px 11px;
  border-radius: var(--radio-modal);
  font-size: 0.8rem;
  line-height: 1.4;
}

.mensaje-auth.error {
  border: 1px solid #fecaca;
  background: #fef2f2;
  color: #b91c1c;
}

.mensaje-auth.exito {
  border: 1px solid #bbf7d0;
  background: #f0fdf4;
  color: #15803d;
}

.mensaje-auth.info {
  border: 1px solid #dbeafe;
  background: var(--azul-suave);
  color: var(--azul-institucional);
}

/* ==========================================================
   Popups dentro del mapa
   ========================================================== */
.popup-reporte {
  min-width: 180px;
  color: var(--texto);
  font-family: inherit;
}

.popup-titulo {
  display: block;
  margin-bottom: 6px;
  color: var(--texto);
  font-size: 0.9rem;
  line-height: 1.3;
}

.popup-categoria {
  display: inline-block;
  margin-bottom: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  color: var(--blanco);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.popup-reporte p {
  margin: 0 0 8px;
  color: #374151;
  font-size: 0.85rem;
  line-height: 1.4;
}

.popup-reporte small {
  color: var(--texto-suave);
  font-size: 0.72rem;
}

.popup-votos {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--borde);
}

.btn-voto {
  display: inline-flex;
  flex: 1;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 7px 9px;
  border: 1px solid var(--borde-input);
  border-radius: 999px;
  background: var(--blanco);
  color: var(--texto);
  font: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  cursor: pointer;
  transition:
    background 0.2s ease,
    border-color 0.2s ease,
    transform 0.15s ease;
}

.btn-voto:hover:not(:disabled) {
  transform: translateY(-1px);
}

.btn-voto-util:hover:not(:disabled) {
  border-color: var(--verde);
  background: #f0fdf4;
}

.btn-voto-no-util:hover:not(:disabled) {
  border-color: var(--peligro);
  background: #fef2f2;
}

.btn-voto:disabled {
  cursor: wait;
  opacity: 0.6;
}

.contador-voto {
  min-width: 16px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--fondo-pagina);
  color: var(--texto-suave);
  font-size: 0.68rem;
  font-weight: 700;
  text-align: center;
}

/* ==========================================================
   Notificaciones flotantes (toast)
   ========================================================== */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  z-index: 3000;
  max-width: min(90vw, 460px);
  padding: 12px 18px;
  border: 1px solid var(--borde);
  border-left: 4px solid var(--azul-categoria);
  border-radius: var(--radio-modal);
  background: var(--blanco);
  color: var(--texto);
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.18);
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 20px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.exito {
  border-left-color: var(--verde);
}

.toast.error {
  border-left-color: var(--peligro);
}

.toast.info {
  border-left-color: var(--azul-categoria);
}

/* ==========================================================
   Accesibilidad y pantallas pequeñas
   ========================================================== */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--azul-institucional);
  outline-offset: 2px;
}

@media (max-width: 420px) {
  .panel {
    top: 10px;
    left: 10px;
    max-height: calc(100vh - 20px);
    padding: 16px;
  }

  .panel-encabezado h1 {
    font-size: 1.6rem;
  }

  .modal {
    padding: 18px;
  }
}
