/**
 * YouTube Videos Loading Fix CSS
 * Soluciona el problema del loading constante en los videos de YouTube
 * Mejora la carga y renderizado de los iframes
 */

/* ================================================
   YOUTUBE VIDEOS - FIX LOADING CONSTANTE
   ================================================ */

/* Contenedor de videos optimizado */
.video-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)) !important;
    gap: 20px !important;
    padding: 20px 0 !important;
}

/* Items de video con mejor estructura */
.video-item {
    background: #ffffff !important;
    border-radius: 12px !important;
    overflow: hidden !important;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1) !important;
    transition: all 0.3s ease !important;
}

.video-item:hover {
    transform: translateY(-3px) !important;
    box-shadow: 0 8px 25px rgba(31, 121, 113, 0.2) !important;
}

/* Wrapper de video con aspect ratio fijo */
.video-wrapper {
    position: relative !important;
    width: 100% !important;
    height: 0 !important;
    padding-bottom: 56.25% !important; /* 16:9 aspect ratio */
    background: #f0f0f0 !important;
    overflow: hidden !important;
}

/* Iframe optimizado para evitar loading constante */
.video-wrapper iframe {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border: none !important;
    
    /* Optimizaciones para evitar loading */
    opacity: 1 !important;
    visibility: visible !important;
    display: block !important;
    
    /* Renderizado mejorado */
    will-change: auto !important;
    backface-visibility: hidden !important;
    transform: translateZ(0) !important;
}

/* Loading placeholder personalizado */
.video-wrapper::before {
    content: '' !important;
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    width: 60px !important;
    height: 60px !important;
    margin: -30px 0 0 -30px !important;
    border: 4px solid #f3f3f3 !important;
    border-top: 4px solid #1f7971 !important;
    border-radius: 50% !important;
    animation: youtubeLoading 1s linear infinite !important;
    z-index: 1 !important;
    opacity: 0 !important;
    transition: opacity 0.3s ease !important;
}

/* Mostrar loading solo cuando sea necesario */
.video-wrapper.loading::before {
    opacity: 1 !important;
}

@keyframes youtubeLoading {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Información del video */
.video-info {
    padding: 15px !important;
    background: #ffffff !important;
}

.video-title {
    font-size: 16px !important;
    font-weight: 600 !important;
    color: #333 !important;
    margin: 0 0 8px 0 !important;
    line-height: 1.3 !important;
}

.video-description {
    font-size: 14px !important;
    color: #666 !important;
    margin: 0 !important;
    line-height: 1.4 !important;
}

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

/* Tablets */
@media (max-width: 991px) {
    .video-grid {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)) !important;
        gap: 18px !important;
    }
    
    .video-title {
        font-size: 15px !important;
    }
    
    .video-description {
        font-size: 13px !important;
    }
}

/* Móviles */
@media (max-width: 767px) {
    .video-grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
        padding: 15px 0 !important;
    }
    
    .video-info {
        padding: 12px !important;
    }
    
    .video-title {
        font-size: 14px !important;
    }
    
    .video-description {
        font-size: 12px !important;
    }
}

/* ================================================
   FIX ESPECÍFICOS PARA YOUTUBE
   ================================================ */

/* Deshabilitar lazy loading problemático en iframes */
iframe[src*="youtube"],
iframe[src*="youtube-nocookie"] {
    background: #000000 !important;
}

/* Optimizaciones específicas para YouTube nocookie */
iframe[src*="youtube-nocookie.com"] {
    /* Parámetros adicionales via CSS para mejor performance */
    background: #000000 !important;
}

/* ================================================
   PRELOAD Y PERFORMANCE
   ================================================ */

/* Preload para mejor performance */
.video-wrapper {
    contain: layout style paint !important;
}

/* Optimización para scroll */
.video-item {
    contain: layout style !important;
}

/* ================================================
   FALLBACK Y ERROR HANDLING
   ================================================ */

/* Fallback para cuando los videos no cargan */
.video-wrapper iframe:not([src]) {
    background: linear-gradient(45deg, #f0f0f0 25%, transparent 25%), 
                linear-gradient(-45deg, #f0f0f0 25%, transparent 25%), 
                linear-gradient(45deg, transparent 75%, #f0f0f0 75%), 
                linear-gradient(-45deg, transparent 75%, #f0f0f0 75%) !important;
    background-size: 20px 20px !important;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px !important;
}

/* Mensaje de error personalizado */
.video-wrapper.error::after {
    content: 'Video no disponible temporalmente' !important;
    position: absolute !important;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    background: rgba(0, 0, 0, 0.8) !important;
    color: white !important;
    padding: 10px 15px !important;
    border-radius: 5px !important;
    font-size: 14px !important;
    text-align: center !important;
    z-index: 10 !important;
}

/* ================================================
   MEJORAS ADICIONALES
   ================================================ */

/* Hover effects mejorados */
.video-item:hover .video-title {
    color: #1f7971 !important;
}

/* Smooth transitions */
.video-title,
.video-description {
    transition: color 0.3s ease !important;
}

/* Focus para accesibilidad */
.video-wrapper iframe:focus {
    outline: 2px solid #1f7971 !important;
    outline-offset: 2px !important;
}
