/**
 * Video em Modal - Estilos Otimizados
 * 
 * @package Video_Em_Modal
 * @since 2.1.8
 * @author Alessandro Torres
 */

/* DECISÃO: Reset básico para evitar conflitos com temas */
.vem-video-button,
.vem-modal,
.vem-modal-content,
.vem-modal-close {
    box-sizing: border-box;
}

/* ===== BOTÃO DE VÍDEO ===== */
.vem-video-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
    border: none;
    background: rgba(0, 0, 0, 0.7);
    color: #ffffff;
    padding: 20px;
    margin: 0;
    line-height: 1;
    border-radius: 50%;
    position: relative;
    min-width: 44px;
    min-height: 44px;
    /* MELHORIA 1: Centralização perfeita do ícone */
    /* DECISÃO: Variáveis CSS para personalização dinâmica */
    --glow-color: #1e90ff;
    --glow-intensity: 0.7;
    --glow-diameter: 15px;
    --glow-speed: 2s;
    transform: scale(1);
}

/* CORREÇÃO: Garantir centralização perfeita de todos os elementos filhos */
.vem-video-button > * {
    display: flex !important;
    align-items: center;
    justify-content: center;
    margin: 0;
    padding: 0;
    text-align: center;
}

.vem-video-button:hover,
.vem-video-button:focus {
    transform: scale(1.1);
    opacity: 0.9;
    background: rgba(0, 0, 0, 0.9);
}

/* DECISÃO: Suporte a navegação por teclado */
.vem-video-button:focus-visible {
    outline: 3px solid #0073aa;
    outline-offset: 2px;
}

/* CORREÇÃO: Estilos específicos para ícones Dashicons com fallbacks */
.vem-video-button .dashicons {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-family: dashicons, 'Dashicons', sans-serif;
    text-decoration: inherit;
    font-weight: normal;
    font-style: normal;
    transition: color 0.1s ease-in;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* CORREÇÃO: Garantir que o ícone seja visível mesmo se a fonte não carregar */
    width: 1em;
    height: 1em;
    margin: 0;
    padding: 0;
    speak: none;
    vertical-align: middle;
}

/* CORREÇÃO: Fallback para quando Dashicons não carrega */
.vem-video-button .dashicons:before {
    content: attr(data-fallback);
}

/* CORREÇÃO: Fallback específico para ícones de vídeo */
.vem-video-button .dashicons-video-alt3:before,
.vem-video-button .dashicons-controls-play:before,
.vem-video-button .dashicons-media-video:before {
    content: '▶';
}

/* CORREÇÃO: Garantir visibilidade em caso de problemas de carregamento */
.vem-video-button .dashicons:empty:before {
    content: '▶';
    font-family: Arial, sans-serif;
}

/* DECISÃO: Estilos para ícones Font Awesome */
.vem-video-button i[class*="fa-"] {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    margin: 0;
    padding: 0;
    vertical-align: middle;
    width: 1em;
    height: 1em;
}

/* DECISÃO: Estilos para texto personalizado */
.vem-video-button .vem-custom-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-weight: bold;
    margin: 0;
    padding: 0;
    vertical-align: middle;
    width: 1em;
    height: 1em;
}

/* ===== EFEITO GLOW ===== */
.vem-glow-effect {
    position: relative;
    z-index: 2;
}

.vem-glow-effect::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    background: transparent;
    opacity: 1;
    transform: translate(-50%, -50%);
    z-index: -1;
    pointer-events: none;
    animation: vem-glow-pulse var(--glow-speed, 2s) infinite;
}

@keyframes vem-glow-pulse {
    0% {
        transform: translate(-50%, -50%) scale(1);
        box-shadow: 0 0 0 0 var(--glow-color, #1e90ff);
        opacity: var(--glow-intensity, 0.7);
    }
    70% {
        transform: translate(-50%, -50%) scale(1.2);
        box-shadow: 0 0 var(--glow-diameter, 15px) 20px var(--glow-color, #1e90ff);
        opacity: 0;
    }
    100% {
        transform: translate(-50%, -50%) scale(1);
        box-shadow: 0 0 0 0 var(--glow-color, #1e90ff);
        opacity: 0;
    }
}

/* ===== MODAL ===== */
.vem-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 999999;
    justify-content: center;
    align-items: center;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.vem-modal.active {
    display: flex;
    visibility: visible;
    opacity: 1;
}

/* ===== CONTEÚDO DO MODAL ===== */
.vem-modal-content {
    position: relative;
    /* AJUSTE: Modal se adapta ao conteúdo do vídeo */
    width: auto;
    height: auto;
    max-width: 95vw;
    max-height: 95vh;
    background: transparent;
    border-radius: 8px;
    padding-top: 50px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    transform: scale(0.8);
    transition: transform 0.3s ease;
    /* AJUSTE: Flex container que se adapta ao conteúdo */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

.vem-modal.active .vem-modal-content {
    transform: scale(1);
}

/* ===== CONTAINER DE VÍDEO ===== */
.vem-video-container {
    position: relative;
    background: #000;
    border-radius: 8px;
    overflow: hidden;
    /* AJUSTE: Container se adapta ao iframe do vídeo */
    width: auto;
    height: auto;
    min-width: 320px;
    min-height: 180px;
    max-width: 90vw;
    max-height: 85vh;
    /* AJUSTE: Permite que o container se ajuste ao conteúdo */
    margin: auto;
}

/* AJUSTE: Diferentes proporções baseadas no tipo de vídeo - adaptáveis */
.vem-modal[data-video-type="youtube"] .vem-video-container,
.vem-modal[data-video-type="vimeo"] .vem-video-container,
.vem-modal[data-video-type="hosted"] .vem-video-container {
    aspect-ratio: 16 / 9;
    width: clamp(320px, 80vw, 1280px);
    height: auto;
}

.vem-modal[data-video-type="instagram"] .vem-video-container {
    aspect-ratio: 1 / 1;
    width: clamp(320px, 60vh, 720px);
    height: auto;
}

.vem-modal[data-video-type="tiktok"] .vem-video-container {
    aspect-ratio: 9 / 16;
    width: clamp(280px, 40vh, 500px);
    height: auto;
}

/* AJUSTE: Fallback para navegadores sem suporte a aspect-ratio */
@supports not (aspect-ratio: 16 / 9) {
    .vem-modal[data-video-type="youtube"] .vem-video-container,
    .vem-modal[data-video-type="vimeo"] .vem-video-container,
    .vem-modal[data-video-type="hosted"] .vem-video-container {
        width: clamp(320px, 80vw, 1280px);
        height: 0;
        padding-bottom: 56.25%; /* 16:9 */
    }
    
    .vem-modal[data-video-type="instagram"] .vem-video-container {
        width: clamp(320px, 60vh, 720px);
        height: 0;
        padding-bottom: 100%; /* 1:1 */
    }
    
    .vem-modal[data-video-type="tiktok"] .vem-video-container {
        width: clamp(280px, 40vh, 500px);
        height: 0;
        padding-bottom: 177.78%; /* 9:16 */
    }
}

/* ===== IFRAME ===== */
.vem-video-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    border-radius: 8px;
    object-fit: contain;
}

/* ===== BOTÃO DE FECHAR ===== */
.vem-modal-close {
    position: absolute;
    top: 5px;
    right: 5px;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.8);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: all 0.2s ease;
    z-index: 1000;
    backdrop-filter: blur(5px);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.vem-modal-close:hover,
.vem-modal-close:focus {
    background: rgba(255, 255, 255, 0.9);
    color: #000;
    border-color: rgba(255, 255, 255, 0.8);
    transform: scale(1.05);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.4);
}

.vem-modal-close:focus-visible {
    outline: 3px solid #ffffff;
    outline-offset: 2px;
}

/* ===== RESPONSIVIDADE ===== */
/* DECISÃO: Mobile-first - vídeo ocupa toda a tela em dispositivos móveis */
@media (max-width: 767px) {
    .vem-modal {
        padding: 0;
        align-items: stretch;
        justify-content: stretch;
    }
    
    .vem-modal-content {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        padding: 0;
        border-radius: 0;
        transform: none;
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        margin: 0;
    }
    
    .vem-modal.active .vem-modal-content {
        transform: none;
    }
    
    .vem-video-container {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        min-width: 100vw;
        min-height: 100vh;
        border-radius: 0;
        margin: 0;
        /* DECISÃO: Forçar aspect-ratio para ocupar toda a tela */
        aspect-ratio: unset;
    }
    
    /* CORREÇÃO: Garantir que todos os tipos de vídeo ocupem a tela toda em mobile */
    .vem-modal[data-video-type="youtube"] .vem-video-container,
    .vem-modal[data-video-type="vimeo"] .vem-video-container,
    .vem-modal[data-video-type="hosted"] .vem-video-container,
    .vem-modal[data-video-type="instagram"] .vem-video-container,
    .vem-modal[data-video-type="tiktok"] .vem-video-container {
        width: 100vw;
        height: 100vh;
        aspect-ratio: unset;
    }
    
    /* CORREÇÃO: Fallback para navegadores sem suporte a aspect-ratio em mobile */
    @supports not (aspect-ratio: 16 / 9) {
        .vem-modal[data-video-type="youtube"] .vem-video-container,
        .vem-modal[data-video-type="vimeo"] .vem-video-container,
        .vem-modal[data-video-type="hosted"] .vem-video-container,
        .vem-modal[data-video-type="instagram"] .vem-video-container,
        .vem-modal[data-video-type="tiktok"] .vem-video-container {
            width: 100vw;
            height: 100vh;
            padding-bottom: 0;
        }
    }
    
    .vem-video-container iframe {
        border-radius: 0;
        object-fit: cover;
    }
    
    /* AJUSTE: Botão de fechar mais visível e acessível em mobile */
    .vem-modal-close {
        top: 20px;
        right: 20px;
        width: 50px;
        height: 50px;
        font-size: 28px;
        background: rgba(0, 0, 0, 0.9);
        border: 3px solid rgba(255, 255, 255, 0.8);
        z-index: 10001;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.6);
    }
}

/* DECISÃO: Tablets em modo retrato */
@media (min-width: 480px) and (max-width: 767px) {
    .vem-modal-content {
        max-width: 95vw;
        max-height: 95vh;
    }
    
    .vem-video-container {
        max-width: 90vw;
        max-height: 85vh;
    }
}

@media (min-width: 768px) {
    .vem-modal-content {
        width: 90%;
        max-width: 800px;
    }
}

@media (min-width: 1024px) {
    .vem-modal-content {
        width: 80%;
        max-width: 900px;
    }
}

/* ===== ESTADOS DE CARREGAMENTO ===== */
.vem-video-container iframe[data-src],
.vem-video-container iframe.vem-loading {
    background: #000 url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDAiIGhlaWdodD0iNDAiIHZpZXdCb3g9IjAgMCA0MCA0MCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBzdHJva2U9IiNmZmYiPjxnIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCI+PGcgdHJhbnNmb3JtPSJ0cmFuc2xhdGUoMSAxKSIgc3Ryb2tlLXdpZHRoPSIyIj48Y2lyY2xlIHN0cm9rZS1vcGFjaXR5PSIuNSIgY3g9IjE4IiBjeT0iMTgiIHI9IjE4Ii8+PHBhdGggZD0ibTM5IDM5YzAtOS45NC04LjA2LTE4LTE4LTE4Ij48YW5pbWF0ZVRyYW5zZm9ybSBhdHRyaWJ1dGVOYW1lPSJ0cmFuc2Zvcm0iIHR5cGU9InJvdGF0ZSIgZnJvbT0iMCAzOSAzOSIgdG89IjM2MCAzOSAzOSIgZHVyPSIxcyIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiLz48L3BhdGg+PC9nPjwvZz48L3N2Zz4=') no-repeat center center;
    background-size: 40px 40px;
    transition: all 0.3s ease;
}

.vem-video-container iframe.vem-loading {
    opacity: 0.7;
}

.vem-video-container iframe.vem-error {
    background: #300;
    opacity: 0.5;
}

/* ===== MENSAGEM DE ERRO ===== */
.vem-video-error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    z-index: 10;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 0, 0, 0.3);
}

.vem-video-error p {
    margin: 10px 0;
    font-size: 16px;
    line-height: 1.4;
}

.vem-video-error strong {
    color: #ff6b6b;
}

/* ===== ACESSIBILIDADE ===== */
.screen-reader-text {
    position: absolute !important;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    width: 1px;
    height: 1px;
    overflow: hidden;
    word-wrap: normal !important;
}

/* DECISÃO: Prevenção de scroll no body quando modal aberto */
.vem-modal-open {
    overflow: hidden !important;
    /* CORREÇÃO: Remover position fixed que interfere com scroll restoration */
}

/* DECISÃO: Garantir que o modal ocupe toda a viewport em mobile */
@media (max-width: 767px) {
    .vem-modal-open {
        /* CORREÇÃO: Remover position fixed para permitir restauração de scroll */
        width: 100vw;
        height: 100vh;
    }
    
    /* MELHORIA: Forçar o iframe a ocupar todo o espaço disponível */
    .vem-video-container iframe {
        width: 100% !important;
        height: 100% !important;
        position: absolute;
        top: 0;
        left: 0;
        object-fit: cover;
        /* DECISÃO: Garantir que o vídeo cubra toda a área */
        min-width: 100%;
        min-height: 100%;
    }
    
    /* CORREÇÃO: Remover qualquer padding ou margin que possa interferir */
    .vem-modal,
    .vem-modal-content,
    .vem-video-container {
        padding: 0 !important;
        margin: 0 !important;
        border: none !important;
        box-shadow: none !important;
    }
}

/* ===== MELHORIAS PARA DISPOSITIVOS TOUCH ===== */
@media (hover: none) and (pointer: coarse) {
    .vem-video-button:hover {
        transform: scale(1);
    }
    
    .vem-modal-close {
        width: 44px;
        height: 44px;
        font-size: 24px;
    }
    
    .vem-video-button {
        min-width: 44px;
        min-height: 44px;
    }
}

/* ===== ORIENTAÇÃO PAISAGEM EM MOBILE ===== */
@media (max-width: 767px) and (orientation: landscape) {
    .vem-modal-content {
        width: 100vw;
        height: 100vh;
    }
    
    .vem-video-container {
        width: 100vw;
        height: 100vh;
        /* DECISÃO: Em paisagem, garantir que o vídeo ocupe toda a tela */
        aspect-ratio: unset;
    }
    
    /* AJUSTE: Botão de fechar menor em modo paisagem para não atrapalhar */
    .vem-modal-close {
        top: 10px;
        right: 10px;
        width: 40px;
        height: 40px;
        font-size: 24px;
    }
}

/* ===== DISPOSITIVOS MUITO PEQUENOS ===== */
@media (max-width: 320px) {
    .vem-modal-close {
        top: 15px;
        right: 15px;
        width: 45px;
        height: 45px;
        font-size: 26px;
    }
}

/* ===== DISPOSITIVOS GRANDES EM MODO RETRATO ===== */
@media (min-width: 768px) and (max-width: 1024px) and (orientation: portrait) {
    .vem-modal-content {
        width: 95vw;
        max-width: 95vw;
        max-height: 90vh;
    }
    
    .vem-video-container {
        max-width: 90vw;
        max-height: 80vh;
    }
}

/* ===== MODO DE ALTO CONTRASTE ===== */
@media (prefers-contrast: high) {
    .vem-modal {
        background: rgba(0, 0, 0, 0.95);
    }
    
    .vem-modal-close {
        background: rgba(255, 255, 255, 0.9);
        color: #000;
    }
    
    .vem-video-button {
        background: rgba(255, 255, 255, 0.9);
        color: #000;
        border: 2px solid #000;
    }
}

/* ===== RESPEITAR PREFERÊNCIA DE MOVIMENTO REDUZIDO ===== */
@media (prefers-reduced-motion: reduce) {
    .vem-video-button,
    .vem-modal,
    .vem-modal-content,
    .vem-modal-close {
        transition: none;
        animation: none;
    }
    
    .vem-glow-effect::before {
        animation: none;
    }
    
    .vem-video-button:hover {
        opacity: 0.8;
        transform: none;
    }
}

/* ===== MELHORIAS PARA IMPRESSÃO ===== */
@media print {
    .vem-video-button,
    .vem-modal {
        display: none !important;
    }
}

/* ===== SUPORTE A MODO ESCURO ===== */
@media (prefers-color-scheme: dark) {
    .vem-video-button {
        background: rgba(255, 255, 255, 0.1);
        color: #ffffff;
    }
    
    .vem-video-button:hover {
        background: rgba(255, 255, 255, 0.2);
    }
}

/* ===== OTIMIZAÇÕES PARA PERFORMANCE ===== */
.vem-video-button,
.vem-modal-content {
    will-change: transform;
}

.vem-glow-effect::before {
    will-change: box-shadow, transform;
}