/**
 * Estilos para el Selector de Mapa de Direcciones - DiMAL
 * Versión: 1.1 - CORREGIDO para checkout
 */

/* Contenedor principal del mapa */
.dimal-address-map-container {
    margin: 20px 0;
    padding: 0;
    clear: both;
    width: 100%;
    float: none;
    position: relative;
}

/* Contenedor del mapa Leaflet */
.dimal-address-map {
    height: 400px;
    width: 100%;
    border-radius: 8px;
    border: 1px solid #ddd;
    margin-bottom: 10px;
    display: block;
    clear: both;
    position: relative;
    z-index: 1;
}

/* Instrucciones sobre el mapa */
.dimal-map-instructions {
    background: #e8f4f8;
    border-left: 4px solid #2196F3;
    padding: 12px 16px;
    margin-bottom: 15px;
    border-radius: 4px;
    font-size: 14px;
    color: #333;
    display: block;
    clear: both;
    width: 100%;
    box-sizing: border-box;
    position: relative;
    z-index: 1;
}

.dimal-map-instructions::before {
    content: "ℹ️ ";
    margin-right: 8px;
}

/* Mensaje de error del mapa */
.dimal-map-error {
    background: #fef2f2;
    border-left: 4px solid #ef4444;
    padding: 12px 16px;
    margin-bottom: 15px;
    border-radius: 4px;
    font-size: 14px;
    color: #991b1b;
    display: block;
    width: 100%;
    box-sizing: border-box;
    font-weight: 500;
}

.dimal-map-error::before {
    content: "⚠️ ";
    margin-right: 8px;
}

/* Ocultar completamente los campos de latitud y longitud */
.dimal-hidden-coords,
input[name="dimal_shipping_latitude"],
input[name="dimal_shipping_longitude"],
input[name="dimal_billing_latitude"],
input[name="dimal_billing_longitude"] {
    display: none !important;
    visibility: hidden !important;
    opacity: 0 !important;
    position: absolute !important;
    left: -9999px !important;
}

/* ===================================================================
   ESTILOS ESPECÍFICOS PARA CHECKOUT
   =================================================================== */

/* Asegurar que los contenedores de mapas en checkout tengan el espacio correcto */
#dimal-map-container-billing-checkout,
#dimal-map-container-shipping-checkout {
    margin: 20px 0;
    padding: 15px;
    background: #f9f9f9;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

/* Asegurar que el mapa de shipping esté completamente oculto inicialmente */
#dimal-map-container-shipping-checkout {
    display: none;
}

/* Cuando está visible, asegurar que tenga el espacio correcto */
#dimal-map-container-shipping-checkout.visible {
    display: block;
}

/* Notificación de error general en checkout */
.dimal-checkout-error-notice {
    background: #fef2f2;
    border: 1px solid #ef4444;
    border-radius: 4px;
    padding: 15px 20px;
    margin-bottom: 20px;
    color: #991b1b;
    font-weight: 500;
    font-size: 14px;
}

/* ===================================================================
   MEJORAS VISUALES PARA LEAFLET
   =================================================================== */

/* Asegurar que los tiles del mapa se carguen correctamente */
.dimal-address-map .leaflet-tile-container {
    opacity: 1 !important;
}

/* Mejorar el estilo del popup del marcador */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: 0 3px 14px rgba(0, 0, 0, 0.15);
}

.leaflet-popup-content {
    margin: 12px 16px;
    font-size: 14px;
    line-height: 1.4;
}

/* Asegurar que el mapa sea visible durante la carga */
.dimal-address-map .leaflet-container {
    background: #f5f5f5;
}

/* ===================================================================
   RESPONSIVE
   =================================================================== */

/* Tablets y dispositivos pequeños */
@media (max-width: 768px) {
    .dimal-address-map {
        height: 300px;
    }

    .dimal-map-instructions {
        font-size: 13px;
        padding: 10px 14px;
    }

    .dimal-map-error {
        font-size: 13px;
        padding: 10px 14px;
    }

    #dimal-map-container-billing-checkout,
    #dimal-map-container-shipping-checkout {
        padding: 10px;
    }
}

/* Móviles */
@media (max-width: 480px) {
    .dimal-address-map {
        height: 250px;
        border-radius: 6px;
    }

    .dimal-map-instructions {
        font-size: 12px;
        padding: 8px 12px;
    }

    .dimal-map-error {
        font-size: 12px;
        padding: 8px 12px;
    }

    .dimal-address-map-container {
        margin: 15px 0;
    }

    #dimal-map-container-billing-checkout,
    #dimal-map-container-shipping-checkout {
        padding: 8px;
    }
}


/* ===================================================================
   MEJORAS DE ACCESIBILIDAD
   =================================================================== */

.dimal-address-map:focus-within {
    outline: 2px solid #2196F3;
    outline-offset: 2px;
}

/* ===================================================================
   PREVENIR CONFLICTOS CON OTROS PLUGINS
   =================================================================== */

.dimal-address-map * {
    box-sizing: border-box;
}

/* Asegurar que el mapa se vea bien en modales/popups de Elementor */
.elementor-popup-modal .dimal-address-map {
    height: 350px;
}

/* ===================================================================
   SOPORTE PARA RTL (idiomas de derecha a izquierda)
   =================================================================== */

[dir="rtl"] .dimal-map-instructions::before {
    margin-right: 0;
    margin-left: 8px;
}

[dir="rtl"] .dimal-map-instructions {
    border-left: none;
    border-right: 4px solid #2196F3;
}

[dir="rtl"] .dimal-map-error::before {
    margin-right: 0;
    margin-left: 8px;
}

[dir="rtl"] .dimal-map-error {
    border-left: none;
    border-right: 4px solid #ef4444;
}

/* ===================================================================
   ANIMACIONES SUTILES
   =================================================================== */

.dimal-map-error {
    animation: slideDown 0.3s ease-out;
}

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

/* ===================================================================
   LOADING SPINNER (cuando el mapa se está cargando)
   =================================================================== */

.dimal-address-map::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 4px solid #f3f3f3;
    border-top-color: #2196F3;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
}

.dimal-address-map.loading::before {
    opacity: 1;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
