/**
 * Estilos para Lazy Loading de Vídeos do YouTube
 * Performance optimization - carrega vídeos apenas no clique
 */

/* Container do preview do vídeo */
.youtube-lazy-preview {
    position: relative;
    width: 100%;
    max-width: 560px;
    aspect-ratio: 16 / 9;
    cursor: pointer;
    overflow: hidden;
    border-radius: 8px;
    background: #000;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.youtube-lazy-preview:hover {
    transform: scale(1.02);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.3);
}

/* Thumbnail do vídeo */
.youtube-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 0.3s ease;
}

.youtube-lazy-preview:hover .youtube-thumbnail {
    opacity: 0.85;
}

/* Botão de play */
.youtube-play-button {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(1);
    width: 68px;
    height: 48px;
    background: transparent;
    border: none;
    cursor: pointer;
    z-index: 2;
    transition: transform 0.2s ease;
    padding: 0;
    outline: none;
}

.youtube-play-button:hover {
    transform: translate(-50%, -50%) scale(1.15);
}

.youtube-play-button:focus {
    outline: 2px solid #fff;
    outline-offset: 4px;
}

.youtube-play-button svg {
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.3));
}

/* Overlay escuro para melhor contraste do botão */
.youtube-lazy-preview::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        to bottom,
        rgba(0, 0, 0, 0) 0%,
        rgba(0, 0, 0, 0.1) 50%,
        rgba(0, 0, 0, 0.2) 100%
    );
    pointer-events: none;
    z-index: 1;
    transition: opacity 0.3s ease;
}

.youtube-lazy-preview:hover::before {
    opacity: 0.7;
}

/* Animação de loading enquanto o vídeo carrega */
.youtube-lazy-preview.loading {
    pointer-events: none;
}

.youtube-lazy-preview.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    z-index: 3;
}

@keyframes spin {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* Responsividade Mobile Melhorada */
@media (max-width: 768px) {
    .youtube-lazy-preview {
        max-width: 100%;
        border-radius: 12px;
    }
    
    /* Botão play MAIOR para touch em tablets */
    .youtube-play-button {
        width: 80px;
        height: 56px;
        /* Área de toque mínima recomendada: 48x48px */
    }
    
    .youtube-play-button:hover {
        transform: translate(-50%, -50%) scale(1.1);
    }
}

@media (max-width: 480px) {
    /* Botão play ainda MAIOR em smartphones */
    .youtube-play-button {
        width: 88px;
        height: 62px;
        /* Área de toque confortável em mobile */
    }
    
    /* Reduz efeito hover em mobile (touch) */
    .youtube-lazy-preview:hover {
        transform: scale(1);
    }
    
    .youtube-lazy-preview:hover .youtube-thumbnail {
        opacity: 1;
    }
    
    .youtube-play-button:hover {
        transform: translate(-50%, -50%) scale(1.05);
    }
    
    /* Overlay mais visível em telas pequenas */
    .youtube-lazy-preview::before {
        opacity: 0.3;
    }
}

/* Compatibilidade com containers existentes */
.video-container-main .youtube-lazy-preview,
.depoimento-video .youtube-lazy-preview,
.depoimento-pequeno .youtube-lazy-preview {
    /* Modo absolute para preencher container com aspect ratio */
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
    margin: 0 !important;
}

/* Quando dentro de um grid */
.depoimentos-videos .youtube-lazy-preview,
.depoimentos-grid-pequenos .youtube-lazy-preview,
.alunos-dizendo .youtube-lazy-preview {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: none !important;
}

/* Estado de foco para acessibilidade */
.youtube-lazy-preview:focus-within {
    outline: 3px solid #d4af37;
    outline-offset: 4px;
}

/* Otimização de performance - desabilita animações em conexões lentas */
@media (prefers-reduced-motion: reduce) {
    .youtube-lazy-preview,
    .youtube-thumbnail,
    .youtube-play-button {
        transition: none;
    }
    
    .youtube-play-button:hover {
        transform: translate(-50%, -50%) scale(1);
    }
    
    .youtube-lazy-preview:hover {
        transform: none;
    }
}

/* Loading skeleton para imagens que ainda não carregaram */
.youtube-thumbnail[loading="lazy"] {
    background: linear-gradient(
        90deg,
        #2c3e50 0%,
        #34495e 50%,
        #2c3e50 100%
    );
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}