/* ============================================
   INTERACTIVIDAD DEL MAPA
   Archivo: interactividad-mapa.css
   
   Propósito: Optimización de experiencia del mapa:
   - Comportamiento de marcadores
   - Clusters interactivos
   - Cursores apropiados
   - Prevención de selección accidental
   - Estabilidad de animaciones
   
   Componentes:
   - .earthquake-marker
   - .marker-cluster
   - .leaflet-interactive
   - .cluster-label
   ============================================ */

/* Prevenir selección de texto en elementos interactivos del mapa */
.leaflet-container,
.marker-cluster,
.earthquake-marker,
button,
.popup-btn {
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Cursor apropiado para elementos interactivos */
.leaflet-interactive {
    cursor: pointer !important;
}

.earthquake-marker {
    transform: none !important;
    transition: none !important;
    will-change: auto !important;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    transform-style: flat;
    -webkit-transform-style: flat;
}

.earthquake-marker:hover,
.earthquake-marker:active,
.earthquake-marker:focus {
    transform: none !important;
    animation: none !important;
}

/* Prevenir que el mapa se mueva al interactuar con marcadores */
.leaflet-marker-pane {
    pointer-events: auto !important;
    z-index: 600 !important;
}

.leaflet-popup-pane {
    pointer-events: auto !important;
    z-index: 700 !important;
}

.leaflet-tooltip-pane {
    pointer-events: none !important;
    z-index: 650 !important;
}

/* Asegurar que los marcadores sean clickeables en todos los niveles de zoom */
.leaflet-marker-icon,
.leaflet-interactive {
    pointer-events: auto !important;
    cursor: pointer !important;
}

/* Forzar visibilidad de marcadores */
.earthquake-marker,
path.leaflet-interactive {
    opacity: 1 !important;
    display: block !important;
    visibility: visible !important;
}

/* Estabilizar el canvas del mapa */
.leaflet-zoom-animated {
    transition-timing-function: cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* ============================================
   BOTONES DE HERRAMIENTAS DEL MAPA - ELEGANTES
   ============================================ */

.map-tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    position: relative;
    overflow: hidden;
}

.map-tool-btn i {
    font-size: 14px;
    transition: transform 0.2s ease;
}

.map-tool-btn span {
    font-size: 12px;
    letter-spacing: 0.3px;
}

.map-tool-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.map-tool-btn:hover i {
    transform: scale(1.1);
}

.map-tool-btn:active {
    transform: translateY(0);
}

/* Colores específicos para cada herramienta */
.map-tool-purple {
    background: linear-gradient(135deg, #9333ea, #7e22ce);
}

.map-tool-purple:hover {
    background: linear-gradient(135deg, #a855f7, #9333ea);
}

.map-tool-indigo {
    background: linear-gradient(135deg, #4f46e5, #4338ca);
}

.map-tool-indigo:hover {
    background: linear-gradient(135deg, #6366f1, #4f46e5);
}

.map-tool-teal {
    background: linear-gradient(135deg, #14b8a6, #0d9488);
}

.map-tool-teal:hover {
    background: linear-gradient(135deg, #2dd4bf, #14b8a6);
}

.map-tool-rose {
    background: linear-gradient(135deg, #e11d48, #be123c);
}

.map-tool-rose:hover {
    background: linear-gradient(135deg, #f43f5e, #e11d48);
}

.map-tool-green {
    background: linear-gradient(135deg, #16a34a, #15803d);
}

.map-tool-green:hover {
    background: linear-gradient(135deg, #22c55e, #16a34a);
}

.map-tool-blue {
    background: linear-gradient(135deg, #2563eb, #1d4ed8);
}

.map-tool-blue:hover {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
}

/* Estado activo para botones toggleables */
.map-tool-btn.active {
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.3),
                0 4px 12px rgba(0, 0, 0, 0.3);
}

.map-tool-btn.active::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.15);
    pointer-events: none;
}

/* Responsive para móviles */
@media (max-width: 640px) {
    .map-tool-btn span {
        display: none;
    }
    
    .map-tool-btn {
        padding: 8px 12px;
        min-width: 40px;
        justify-content: center;
    }
    
    .map-tool-btn i {
        font-size: 16px;
        margin: 0;
    }
}

/* Scrollbar personalizado para popups */
.leaflet-popup-content::-webkit-scrollbar {
    width: 8px;
}

.leaflet-popup-content::-webkit-scrollbar-track {
    background: var(--bg-surface);
    border-radius: 4px;
}

.leaflet-popup-content::-webkit-scrollbar-thumb {
    background: var(--mainColor);
    border-radius: 4px;
}

.leaflet-popup-content::-webkit-scrollbar-thumb:hover {
    background: #b22222;
}

/* Animaciones suaves para tooltips */
.scientific-tooltip {
    animation: tooltipFadeIn 0.2s ease-in-out;
}

@keyframes tooltipFadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 0.95;
        transform: translateY(0);
    }
}

/* Estados de carga */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    backdrop-filter: blur(5px);
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 6px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--mainColor);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Botones de herramientas */
#heatmapBtn,
#measureBtn,
#clusterBtn,
#riskMapBtn {
    position: relative;
    overflow: hidden;
}

#heatmapBtn::before,
#measureBtn::before,
#clusterBtn::before,
#riskMapBtn::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

#heatmapBtn:active::before,
#measureBtn:active::before,
#clusterBtn:active::before,
#riskMapBtn:active::before {
    width: 300px;
    height: 300px;
}

/* Transiciones suaves en el mapa */
.leaflet-fade-anim .leaflet-tile {
    will-change: opacity;
}

.leaflet-zoom-anim .leaflet-zoom-animated {
    will-change: transform;
}

/* Indicador visual de búsqueda activa */
#searchLocation:focus {
    box-shadow: 0 0 0 3px rgba(220, 20, 60, 0.3);
    border-color: var(--mainColor);
}

/* Feedback visual para acciones */
@keyframes successPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7); }
    50% { box-shadow: 0 0 0 10px rgba(34, 197, 94, 0); }
}

.success-action {
    animation: successPulse 0.6s ease-out;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Focus visible para navegación con teclado */
button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--mainColor);
    outline-offset: 2px;
}

/* Skeleton loaders */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--bg-surface) 0%,
        var(--bg-card) 50%,
        var(--bg-surface) 100%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Placeholder vacío */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 64px;
    opacity: 0.3;
    margin-bottom: 20px;
}

.empty-state-title {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.empty-state-description {
    font-size: 14px;
    max-width: 400px;
    margin: 0 auto;
}

/* Tooltips de ayuda contextuales */
.help-tooltip {
    position: relative;
    display: inline-block;
    cursor: help;
}

.help-tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 12px;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 12px;
    white-space: nowrap;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    z-index: 1000;
}

.help-tooltip:hover::after {
    opacity: 1;
}

/* Badges de estado */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.online {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.status-badge.loading {
    background: rgba(251, 191, 36, 0.2);
    color: #fbbf24;
}

.status-badge.error {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.leaflet-tile-container {
    will-change: transform;
    transform: translateZ(0);
}

/* Prevenir lag en animaciones */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
