/* ===================================
   MOBILE RESPONSIVE FIXES - ABTV Streaming
   Correcciones específicas para móviles
   =================================== */

/* ===== RESET Y BASE MÓVIL ===== */
@media (max-width: 768px) {
    
    /* Fix para el body en móvil */
    body {
        overflow-x: hidden;
        min-height: 100vh;
        margin: 0;
        padding: 0;
        background: #0a0a0a;
        position: relative;
    }
    
    /* Fix para el viewport en móvil */
    html {
        -webkit-text-size-adjust: 100%;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Contenedor principal optimizado */
    .container {
        padding: 0 1rem;
        max-width: 100%;
    }
}

/* ===== SECCIONES DE PELÍCULAS MÓVIL ===== */
@media (max-width: 768px) {
    
    .movie-section {
        margin-bottom: 2.5rem !important;
        padding: 0 1rem !important;
        position: relative;
    }
    
    .movie-section.recommended {
        margin-top: 1rem !important;
        margin-bottom: 2rem !important;
    }
    
    .movie-section:last-of-type {
        margin-bottom: 1rem !important;
        padding-bottom: 0 !important;
    }
    
    /* Header de sección móvil */
    .section-header {
        margin-bottom: 1rem !important;
        padding: 0 0.5rem !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 1rem;
    }
    
    .section-title {
        font-size: 1.3rem !important;
        font-weight: 600 !important;
        margin: 0 !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex: 1;
    }
    
    .view-all {
        font-size: 0.8rem !important;
        padding: 0.4rem 0.8rem !important;
        white-space: nowrap;
        flex-shrink: 0;
        border-radius: 1rem !important;
    }
}

/* ===== CAROUSELES MÓVIL ===== */
@media (max-width: 768px) {
    
    .movie-row {
        margin: 0 !important;
        padding: 0 !important;
        overflow: visible;
    }
    
    .movie-row.with-nav {
        padding: 0 !important;
    }
    
    .movie-carousel {
        display: flex !important;
        gap: 0.9rem !important; /* Aumentado gap para mejor espaciado */
        overflow-x: auto !important;
        overflow-y: visible !important;
        scroll-behavior: smooth !important;
        padding: 0.7rem 1rem 2rem 1rem !important; /* Más espacio vertical */
        margin: 0 !important;
        
        /* Scroll optimizado para móvil con momentum */
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
        
        /* Scroll snap más suave */
        scroll-snap-type: x proximity;
        
        /* Mejor momentum en iOS */
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        
        /* Cursor para indicar scroll */
        cursor: grab;
    }
    
    .movie-carousel:active {
        cursor: grabbing;
    }
    
    .movie-carousel::-webkit-scrollbar {
        display: none !important;
        width: 0 !important;
        height: 0 !important;
        background: transparent !important;
    }
    
    /* Quitar gradientes en móvil */
    .movie-carousel::before,
    .movie-carousel::after {
        display: none !important;
    }
    
    /* Ocultar botones de navegación en móvil */
    .carousel-nav {
        display: none !important;
    }
}

/* ===== TARJETAS DE PELÍCULAS MÓVIL ===== */
@media (max-width: 768px) {
    
    .movie-card {
        flex: 0 0 auto !important;
        width: 160px !important; /* Aumentado de 140px a 160px */
        cursor: pointer;
        transition: transform 0.2s ease !important;
        scroll-snap-align: center;
        scroll-snap-stop: normal;
        position: relative;
        z-index: 1;
        
        /* Mejor área de toque */
        touch-action: pan-y;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    /* Hover más suave en móvil */
    .movie-card:active,
    .movie-card.touch-active {
        transform: scale(0.95) !important;
    }
    
    .movie-poster {
        border-radius: 0.5rem !important;
        overflow: hidden;
        background: #1a1a1a;
        box-shadow: 0 3px 12px rgba(0, 0, 0, 0.5) !important; /* Sombra más prominente */
        position: relative;
        /* Aspect ratio 2:3 optimizado para móvil */
        aspect-ratio: 2/3;
        width: 100%;
    }
    
    .movie-poster img {
        transition: opacity 0.3s ease !important;
        object-fit: cover;
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background: linear-gradient(135deg, #2a2a2a 0%, #1a1a1a 100%);
    }
    
    .movie-poster img:not(.loaded) {
        opacity: 0;
    }
    
    .movie-poster img.loaded {
        opacity: 1;
    }
    
    .movie-title {
        font-size: 0.8rem !important; /* Aumentado ligeramente */
        margin-top: 0.6rem !important;
        padding: 0 0.3rem !important;
        line-height: 1.35 !important;
        height: auto !important; /* Permitir altura automática */
        min-height: 2.7em; /* Altura mínima para 2 líneas */
        max-height: 4.05em; /* Máximo 3 líneas */
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 3; /* Permitir hasta 3 líneas */
        -webkit-box-orient: vertical;
        color: #e0e0e0 !important;
        word-wrap: break-word;
        word-break: break-word;
        hyphens: auto;
        -webkit-hyphens: auto;
        text-align: center;
        margin-bottom: 0.4rem !important;
    }
    
    /* Overlay simplificado para móvil */
    .movie-overlay {
        display: none !important;
    }
    
    .movie-rating {
        position: absolute !important;
        top: 0.5rem !important;
        right: 0.5rem !important;
        font-size: 0.65rem !important;
        padding: 0.2rem 0.4rem !important;
        background: rgba(0, 0, 0, 0.8) !important;
        border-radius: 0.3rem !important;
        backdrop-filter: blur(10px);
    }
}

/* ===== MÓVIL PEQUEÑO (< 480px) ===== */
@media (max-width: 480px) {
    
    .movie-section {
        padding: 0 0.8rem !important;
        margin-bottom: 2rem !important;
    }
    
    .section-title {
        font-size: 1.1rem !important;
    }
    
    .view-all {
        font-size: 0.7rem !important;
        padding: 0.3rem 0.6rem !important;
    }
    
    .movie-card {
        width: 140px !important; /* Aumentado de 120px a 140px */
    }
    
    .movie-carousel {
        gap: 0.7rem !important; /* Ligeramente más espacio */
        padding: 0.5rem 0.5rem 1.5rem 0.5rem !important;
    }
    
    .movie-title {
        font-size: 0.75rem !important; /* Mantenemos legible */
        margin-top: 0.5rem !important;
        min-height: 2.25em !important;
        max-height: 3.75em !important; /* 3 líneas en móviles pequeños */
    }
    
    .movie-rating {
        font-size: 0.6rem !important;
        padding: 0.15rem 0.3rem !important;
    }
}

/* ===== OCULTAR SCROLLBARS EN TODOS LOS NAVEGADORES ===== */
@media (max-width: 768px) {
    
    /* Webkit (Chrome, Safari, Edge) */
    .movie-carousel::-webkit-scrollbar {
        display: none !important;
        width: 0px !important;
        height: 0px !important;
        background: transparent !important;
        -webkit-appearance: none !important;
    }
    
    .movie-carousel::-webkit-scrollbar-track {
        background: transparent !important;
        display: none !important;
    }
    
    .movie-carousel::-webkit-scrollbar-thumb {
        background: transparent !important;
        display: none !important;
    }
    
    .movie-carousel::-webkit-scrollbar-corner {
        background: transparent !important;
        display: none !important;
    }
    
    /* Firefox */
    .movie-carousel {
        scrollbar-width: none !important;
        scrollbar-color: transparent transparent !important;
    }
    
    /* IE/Edge legacy */
    .movie-carousel {
        -ms-overflow-style: none !important;
    }
    
    /* Asegurar que no aparezcan en hover/focus */
    .movie-carousel:hover::-webkit-scrollbar,
    .movie-carousel:focus::-webkit-scrollbar,
    .movie-carousel:active::-webkit-scrollbar {
        display: none !important;
    }
}

/* ===== FIXES ESPECÍFICOS PARA iOS ===== */
@supports (-webkit-overflow-scrolling: touch) {
    
    .movie-carousel {
        -webkit-overflow-scrolling: touch !important;
        /* Forzar aceleración de hardware */
        transform: translate3d(0, 0, 0) !important;
        -webkit-transform: translate3d(0, 0, 0) !important;
    }
    
    /* Fix para el bounce effect en iOS */
    body {
        position: relative;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Mejorar rendering en iOS */
    .movie-card {
        -webkit-transform: translateZ(0);
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }
}

/* ===== MEJORAS DE PERFORMANCE MÓVIL ===== */
@media (max-width: 768px) {
    
    /* Reducir animaciones en móvil */
    .movie-card,
    .movie-poster img,
    .view-all {
        transition-duration: 0.2s !important;
    }
    
    /* Optimizar will-change para móvil */
    .movie-carousel {
        will-change: scroll-position;
    }
    
    .movie-card {
        will-change: transform;
    }
    
    /* Mejorar el rendering */
    .movie-poster {
        transform: translateZ(0);
        backface-visibility: hidden;
    }
}

/* ===== DARK MODE Y ALTO CONTRASTE ===== */
@media (max-width: 768px) {
    
    .movie-title {
        text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9) !important;
        color: #f0f0f0 !important; /* Más contraste */
        font-weight: 400 !important; /* Ligeramente más grueso */
        letter-spacing: 0.01em !important; /* Mejor legibilidad */
    }
    
    .section-title {
        text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7) !important;
        color: #ffffff !important;
        font-weight: 500 !important;
    }
    
    .view-all {
        background: rgba(255, 255, 255, 0.08) !important;
        backdrop-filter: blur(12px);
        border: 1px solid rgba(255, 255, 255, 0.15) !important;
        color: #ffffff !important;
        font-weight: 500 !important;
    }
    
    .view-all:active {
        background: rgba(255, 255, 255, 0.15) !important;
        transform: scale(0.95);
        border-color: rgba(255, 255, 255, 0.25) !important;
    }
    
    /* Mejor contraste para ratings */
    .movie-rating {
        background: rgba(0, 0, 0, 0.85) !important;
        backdrop-filter: blur(12px);
        color: #ffffff !important;
        font-weight: 600 !important;
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
}

/* ===== LANDSCAPE MÓVIL Y TABLETS ===== */
@media (max-width: 768px) and (orientation: landscape) {
    
    .movie-section {
        margin-bottom: 1.8rem !important;
    }
    
    .movie-card {
        width: 130px !important; /* Aumentado para landscape */
    }
    
    .section-title {
        font-size: 1.3rem !important;
    }
    
    .movie-carousel {
        padding: 0.6rem 0.8rem 1.5rem 0.8rem !important;
        gap: 0.8rem !important;
    }
    
    .movie-title {
        font-size: 0.75rem !important;
        min-height: 2.25em !important;
    }
}

/* ===== TABLETS GRANDES (768px - 1024px) ===== */
@media (min-width: 769px) and (max-width: 1024px) {
    
    .movie-card {
        width: 180px !important; /* Tamaño intermedio para tablets */
    }
    
    .movie-carousel {
        gap: 1rem !important;
        padding: 0.8rem 1.2rem 2rem 1.2rem !important;
    }
    
    .movie-title {
        font-size: 0.85rem !important;
        min-height: 2.55em !important;
        max-height: 4.25em !important;
    }
    
    .section-title {
        font-size: 1.6rem !important;
    }
}

/* ===== ACCESIBILIDAD MÓVIL ===== */
@media (max-width: 768px) {
    
    /* Área de toque mínima */
    .movie-card,
    .view-all {
        min-height: 44px;
        min-width: 44px;
    }
    
    .view-all {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Focus mejorado para móvil */
    .movie-card:focus-within {
        outline: 2px solid #e50914;
        outline-offset: 4px;
        border-radius: 0.5rem;
    }
}

/* ===== PREVENIR ZOOM ACCIDENTAL ===== */
@media (max-width: 768px) {
    
    input, textarea, select {
        font-size: 16px !important;
    }
    
    /* Prevenir double-tap zoom */
    .movie-card,
    .view-all {
        touch-action: manipulation;
    }
}

/* ===== LOADING STATES MÓVIL ===== */
@media (max-width: 768px) {
    
    .movie-poster img:not(.loaded) {
        background: linear-gradient(90deg, #1a1a1a 0%, #2a2a2a 50%, #1a1a1a 100%);
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
    }
    
    @keyframes shimmer {
        0% { background-position: -200% 0; }
        100% { background-position: 200% 0; }
    }
}

/* ===== MODO AHORRO DE DATOS ===== */
@media (max-width: 768px) {
    
    .save-data .movie-poster img {
        image-rendering: optimizeSpeed;
        filter: blur(0.3px);
    }
    
    .save-data .movie-card {
        background: #1a1a1a;
    }
}