/* ========================================
   FIX PARA DROPDOWNS EN TABLETS (CHROME)
   ======================================== */

/* ?? Problema: Los dropdowns se abren y cierran inmediatamente en tablets con Chrome
   debido a conflictos entre eventos touch y click */

/* ? SOLUCIÓN 1: Evitar propagación de eventos táctiles en el trigger del dropdown */
.rz-dropdown-trigger,
.rz-dropdown .rz-button,
.rz-dropdown-label {
    /* Prevenir que touch events cierren el dropdown inmediatamente */
    touch-action: manipulation !important;
    -webkit-tap-highlight-color: transparent !important;
}

/* ? SOLUCIÓN 2: Agregar delay mínimo para evitar cierre inmediato en touch devices */
@media (hover: none) and (pointer: coarse) {
    /* Solo aplicar en dispositivos táctiles */
    
    .rz-dropdown-panel,
    .rz-dropdown-items {
        /* Evitar que el panel se cierre por touch fuera antes de tiempo */
        pointer-events: auto !important;
    }
    
    /* Evitar cierre accidental por touch en el overlay */
    .rz-dropdown-panel::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: -1;
        pointer-events: none;
    }
}

/* ? SOLUCIÓN 3: Aumentar el área táctil del dropdown trigger */
@media (max-width: 1024px) {
    /* Tablets y móviles */
    
    .rz-dropdown-trigger,
    .rz-dropdown .rz-button {
        min-height: 44px !important;
    }
}

/* ? SOLUCIÓN 4: Prevenir propagación de eventos en el panel desplegado */
.rz-dropdown-panel {
    /* Evitar que clicks dentro del panel lo cierren */
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
}

.rz-dropdown-item {
    /* Asegurar que los items sean clickeables en touch devices */
    touch-action: manipulation !important;
    cursor: pointer;
    min-height: 44px !important;
    display: flex !important;
    align-items: center !important;
    padding: 10px 16px !important;
}

/* ? SOLUCIÓN 5: Fix específico para Chrome en tablets */
@supports (-webkit-touch-callout: none) {
    /* Solo en dispositivos WebKit (Chrome, Safari) */
    
    .rz-dropdown-panel {
        /* Delay mínimo para evitar cierre inmediato */
        transition: opacity 0.1s ease-in-out;
    }
    
    .rz-dropdown-trigger:active {
        /* Evitar que el active state interfiera con la apertura */
        background-color: inherit !important;
    }
}

/* ? SOLUCIÓN 6: Evitar scroll del body cuando dropdown está abierto en móvil */
@media (max-width: 768px) {
    body:has(.rz-dropdown-panel[style*="display: block"]) {
        overflow: hidden;
        position: fixed;
        width: 100%;
    }
}

/* ? SOLUCIÓN 7: Fix para dropdowns dentro de formularios */
.rz-form-field .rz-dropdown-trigger {
    position: relative;
    z-index: 1;
}

.rz-form-field .rz-dropdown-panel {
    /* Asegurar que el panel esté por encima de otros elementos */
    z-index: 10000 !important;
    position: absolute !important;
}

/* ? SOLUCIÓN 8: Prevenir doble-tap zoom en iOS/Chrome móvil */
.rz-dropdown,
.rz-dropdown *,
.rz-dropdown-trigger,
.rz-dropdown-trigger * {
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

/* ? SOLUCIÓN 9: Fix para el overlay invisible que cierra el dropdown */
@media (hover: none) and (pointer: coarse) {
    /* Agregar un delay antes de que el overlay sea clickeable */
    .rz-dropdown-panel[data-popup-shown="true"] {
        animation: delayPointerEvents 0.3s;
    }
    
    @keyframes delayPointerEvents {
        0% {
            pointer-events: none;
        }
        99% {
            pointer-events: none;
        }
        100% {
            pointer-events: auto;
        }
    }
}

/* ? SOLUCIÓN 10: Incrementar el z-index del panel para tablets */
@media (max-width: 1024px) {
    .rz-dropdown-panel,
    div[id*="dropdown-panel"],
    div[id*="popup"] {
        z-index: 99999 !important;
        position: fixed !important;
    }
}

/* ? SOLUCIÓN 11: Evitar que eventos touch interfieran con la apertura */
.rz-dropdown-trigger {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* ? SOLUCIÓN 12: Fix para dropdowns que usan "AllowFiltering" */
.rz-dropdown-panel .rz-dropdown-filter {
    pointer-events: auto !important;
    touch-action: auto !important;
}

.rz-dropdown-panel .rz-dropdown-filter input {
    -webkit-user-select: text !important;
    user-select: text !important;
    touch-action: auto !important;
}

/* ? SOLUCIÓN 13: Prevenir interferencia con otros elementos en mobile */
@media (max-width: 768px) {
    .rz-dropdown-panel {
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3) !important;
        border: 1px solid rgba(0, 0, 0, 0.1) !important;
    }
    
    /* Agregar padding para evitar clicks accidentales en el borde */
    .rz-dropdown-items {
        padding: 4px 0 !important;
    }
}

/* ? TESTING: Agregar indicador visual para debugging (opcional - comentar en producción) */
/*
@media (hover: none) and (pointer: coarse) {
    .rz-dropdown-panel::after {
        content: '?? TOUCH DEVICE';
        position: fixed;
        top: 10px;
        right: 10px;
        background: red;
        color: white;
        padding: 5px 10px;
        font-size: 12px;
        z-index: 999999;
        border-radius: 4px;
    }
}
*/
