/* CSS Fix específico para el problema de dropdown en móviles */

/* Asegurar que el contenedor se muestre correctamente */
.cfm-flags-container {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative;
}

/* Dropdown base - asegurar que funcione en todos los dispositivos */
.cfm-dropdown {
    position: relative;
    display: inline-block !important;
    width: 100%;
    max-width: 200px;
}

.cfm-dropdown-toggle {
    display: flex !important;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 12px 16px;
    border: 1px solid #ddd;
    border-radius: 6px;
    background-color: #f9f9f9;
    cursor: pointer;
    font-size: 16px;
    min-height: 44px;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: all 0.3s ease;
}

.cfm-dropdown-toggle:active,
.cfm-dropdown-toggle:focus {
    background-color: #e8e8e8;
    outline: none;
}

.cfm-current-country-name {
    flex-grow: 1;
    text-align: left;
    margin-left: 8px;
    font-weight: 500;
}

.cfm-dropdown-arrow {
    margin-left: 8px;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

/* Estado activo del dropdown */
.cfm-dropdown.active .cfm-dropdown-arrow {
    transform: rotate(180deg);
}

/* Contenido del dropdown - DESKTOP */
.cfm-dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    z-index: 9999;
    margin-top: 4px;
    overflow: hidden;
}

/* Mostrar contenido cuando está activo */
.cfm-dropdown.active .cfm-dropdown-content {
    display: block !important;
    animation: cfm-fadeIn 0.3s ease-out;
}

@keyframes cfm-fadeIn {
    from { 
        opacity: 0; 
        transform: translateY(-10px); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

/* Links dentro del dropdown */
.cfm-dropdown .cfm-flag-link {
    display: flex !important;
    align-items: center;
    padding: 14px 16px;
    border-bottom: 1px solid #f0f0f0;
    text-decoration: none;
    color: inherit;
    transition: background-color 0.2s ease;
    min-height: 44px;
}

.cfm-dropdown .cfm-flag-link:last-child {
    border-bottom: none;
}

.cfm-dropdown .cfm-flag-link:hover,
.cfm-dropdown .cfm-flag-link:focus {
    background-color: #f8f9fa;
    outline: none;
}

.cfm-dropdown .cfm-flag-link:active,
.cfm-dropdown .cfm-flag-link.cfm-touch-active {
    background-color: #e9ecef;
}

.cfm-flag {
    max-width: 28px;
    height: auto;
    border: 1px solid #ddd;
    flex-shrink: 0;
}

.cfm-country-name {
    margin-left: 12px;
    font-size: 14px;
}

/* ESTILOS ESPECÍFICOS PARA MÓVIL */
@media (max-width: 768px) {
    .cfm-flags-container {
        width: 100% !important;
        justify-content: center;
    }
    
    .cfm-dropdown {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .cfm-dropdown-toggle {
        width: 100% !important;
        padding: 16px 20px;
        font-size: 16px;
        min-height: 48px;
    }
    
    /* Contenido del dropdown en móvil - POSICIÓN FIJA */
    .cfm-dropdown.cfm-mobile-active .cfm-dropdown-content {
        position: fixed !important;
        top: auto !important;
        left: 15px !important;
        right: 15px !important;
        bottom: 20px !important;
        max-height: 60vh !important;
        overflow-y: auto !important;
        z-index: 999999 !important;
        border-radius: 12px !important;
        box-shadow: 0 20px 40px rgba(0,0,0,0.3) !important;
        animation: cfm-slideUp 0.4s ease-out !important;
    }
    
    /* Overlay de fondo en móvil */
    .cfm-dropdown.cfm-mobile-active::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999998;
        animation: cfm-fadeInBg 0.3s ease-out;
    }
    
    .cfm-dropdown .cfm-flag-link {
        padding: 18px 20px;
        font-size: 16px;
        min-height: 52px;
    }
    
    .cfm-country-name {
        font-size: 16px;
        margin-left: 15px;
    }
}

/* Animación específica para móvil */
@keyframes cfm-slideUp {
    from { 
        opacity: 0; 
        transform: translateY(100%); 
    }
    to { 
        opacity: 1; 
        transform: translateY(0); 
    }
}

@keyframes cfm-fadeInBg {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Prevenir scroll del body cuando dropdown está abierto */
body.cfm-dropdown-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100% !important;
}

/* Clase para dispositivos móviles */
.cfm-mobile-device .cfm-dropdown-toggle {
    -webkit-appearance: none;
    appearance: none;
}

/* Optimizaciones para touch */
.cfm-mobile-optimized .cfm-dropdown-toggle {
    touch-action: manipulation;
}

/* Estados de focus mejorados */
.cfm-dropdown-toggle:focus {
    outline: 2px solid #4285f4;
    outline-offset: 2px;
}

/* Compatibilidad con temas populares */
.et_pb_section .cfm-flags-container,
.et_pb_row .cfm-flags-container,
.et_pb_column .cfm-flags-container {
    display: flex !important;
}

/* Para menús móviles específicos */
#et_mobile_nav_menu .cfm-flags-container,
.mobile-menu .cfm-flags-container,
.navbar-collapse .cfm-flags-container {
    width: 100% !important;
    flex-direction: column !important;
}

/* Fix para z-index en diferentes temas */
.cfm-dropdown-content {
    z-index: 999999 !important;
}

@media (max-width: 768px) {
    .cfm-dropdown.cfm-mobile-active .cfm-dropdown-content {
        z-index: 9999999 !important;
    }
}

/* Debug styles (solo si debug está habilitado) */
.cfm-debug-mode .cfm-dropdown {
    border: 2px dashed red !important;
}

.cfm-debug-mode .cfm-dropdown-toggle {
    background-color: yellow !important;
}

/* Prevenir interferencias de otros plugins */
.cfm-dropdown * {
    box-sizing: border-box;
}

/* Asegurar que funcione incluso con CSS agresivo de temas */
.cfm-flags-container.cfm-force-display {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    position: relative !important;
}

.cfm-dropdown.cfm-force-display {
    display: inline-block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Responsive adicional para tablets */
@media (min-width: 769px) and (max-width: 1024px) {
    .cfm-dropdown {
        max-width: 180px;
    }
    
    .cfm-dropdown-toggle {
        padding: 10px 14px;
        font-size: 14px;
    }
}