/* ========================================
   FIX CRÍTICO ANDROID + iOS
   ======================================== */

/* Fix para que el modal sea más alto en iPhone */
@media (max-width: 768px) {
    .product-modal {
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        max-height: 80vh !important; /* Aumentado de 70vh a 80vh */
        height: auto !important;
        z-index: 999999 !important;
        -webkit-transform: translateY(100%);
        transform: translateY(100%);
        transition: transform 0.3s ease !important;
    }
    
    .modal-overlay.active .product-modal {
        -webkit-transform: translateY(0) !important;
        transform: translateY(0) !important;
    }
}

/* Fix específico para Android WebView y Chrome */
@supports not (-webkit-touch-callout: none) {
    /* Este es Android */
    .product-image-container,
    .product-name {
        cursor: pointer !important;
        -webkit-tap-highlight-color: rgba(0,0,0,0.1) !important;
        tap-highlight-color: rgba(0,0,0,0.1) !important;
    }
    
    .product-image-container:active,
    .product-name:active {
        opacity: 0.8 !important;
        transform: scale(0.98) !important;
    }
    
    /* Asegurar que el modal sea clickeable en Android */
    .modal-overlay {
        -webkit-backface-visibility: hidden !important;
        backface-visibility: hidden !important;
        -webkit-transform: translateZ(0) !important;
        transform: translateZ(0) !important;
    }
    
    .product-modal {
        -webkit-backface-visibility: hidden !important;
        backface-visibility: hidden !important;
    }
}

/* iPhone X y superiores (con notch) */
@supports (padding: max(0px)) {
    .product-modal {
        padding-bottom: max(1.25rem, env(safe-area-inset-bottom)) !important;
    }
    
    .modal-actions {
        padding-bottom: max(1.25rem, env(safe-area-inset-bottom)) !important;
    }
}

/* Mejorar la posición del botón cerrar */
.modal-close {
    position: absolute !important; /* Cambiado de fixed */
    top: 0.75rem !important;
    right: 0.75rem !important;
    z-index: 1000001 !important;
    background: rgba(0, 0, 0, 0.7) !important;
    color: white !important;
    width: 36px !important;
    height: 36px !important;
    border-radius: 50% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    font-size: 22px !important;
    line-height: 1 !important;
    font-weight: normal !important;
    border: 2px solid rgba(255, 255, 255, 0.3) !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3) !important;
    cursor: pointer !important;
    -webkit-tap-highlight-color: transparent !important;
    touch-action: manipulation !important;
    user-select: none !important;
    -webkit-user-select: none !important;
}

.modal-close:active {
    transform: scale(0.9) !important;
    background: rgba(0, 0, 0, 0.9) !important;
}

/* Asegurar que el overlay sea completamente visible */
.modal-overlay {
    display: none;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    background: rgba(0, 0, 0, 0.7) !important;
    z-index: 999998 !important;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease !important;
}

.modal-overlay.active {
    display: flex !important;
    opacity: 1 !important;
    visibility: visible !important;
}

/* Ajustes para diferentes tamaños de iPhone */
@media (max-width: 390px) { /* iPhone 12/13/14 */
    .product-modal {
        max-height: 85vh !important;
    }
}

@media (max-width: 428px) and (min-width: 391px) { /* iPhone 14 Pro Max */
    .product-modal {
        max-height: 85vh !important;
    }
}

@media (max-width: 375px) { /* iPhone SE, 6/7/8 */
    .product-modal {
        max-height: 75vh !important;
    }
    
    .modal-image-container {
        height: 160px !important;
    }
}

/* Fix para hacer elementos más clickeables en touch devices */
@media (hover: none) and (pointer: coarse) {
    .product-image-container,
    .product-name,
    .modal-close,
    .modal-quantity-btn,
    .modal-add-btn {
        min-height: 44px !important; /* Tamaño mínimo recomendado por Apple */
        touch-action: manipulation !important;
    }
    
    /* Feedback visual al tocar */
    .product-image-container:active,
    .product-name:active {
        opacity: 0.7 !important;
    }
}

/* Asegurar z-index para todos los elementos del modal */
#product-modal-overlay {
    z-index: 999998 !important;
}

#product-modal {
    z-index: 999999 !important;
}

#modal-close-btn {
    z-index: 1000001 !important;
}

/* Fix para el scroll en el modal */
.modal-content {
    height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
}

.modal-info {
    flex: 1 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    scroll-behavior: smooth !important;
}

/* Prevenir problemas con el body cuando el modal está abierto */
body.modal-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
    height: 100vh !important;
    touch-action: none !important;
}

/* Android específico - Chrome y WebView */
@media (max-width: 768px) {
    /* Hacer los productos más fáciles de clickear */
    .product-card {
        position: relative !important;
    }
    
    .product-image-container,
    .product-name {
        position: relative !important;
        z-index: 10 !important;
        display: block !important;
    }
    
    /* Aumentar área clickeable */
    .product-image-container::before {
        content: '';
        position: absolute;
        top: -10px;
        left: -10px;
        right: -10px;
        bottom: -10px;
        z-index: -1;
    }
}

/* Debug - Verificar que los elementos son clickeables */
.product-image-container[data-clickable="true"],
.product-name[data-clickable="true"] {
    cursor: pointer !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    -webkit-tap-highlight-color: rgba(255, 107, 53, 0.1) !important;
}

/* Animación mejorada para Android */
@keyframes slideUpAndroid {
    from {
        transform: translateY(100%);
        opacity: 0.8;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-overlay.active .product-modal {
    animation: slideUpAndroid 0.3s ease forwards;
}

/* Landscape en móviles - ajustes */
@media (max-height: 500px) and (orientation: landscape) {
    .product-modal {
        max-height: 90vh !important;
    }
    
    .modal-image-container {
        height: 120px !important;
    }
}

/* Forzar renderizado con GPU para mejor performance */
.modal-overlay,
.product-modal {
    -webkit-transform: translateZ(0);
    -moz-transform: translateZ(0);
    -ms-transform: translateZ(0);
    -o-transform: translateZ(0);
    transform: translateZ(0);
    will-change: transform, opacity;
}