/**
 * Estilos para el frontend del plugin Strimy Video
 *
 * @since      1.0.0
 * @package    Strimy_Video
 */

/* Contenedor responsive WordPress oficial - Aspect ratio 16:9 */
.strimy-responsive-wrapper {
    position: relative;
    width: 100% !important;
    max-width: none !important;
    height: 0;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    overflow: hidden;
    box-sizing: border-box !important;
    margin: 10px 0;
}

.strimy-responsive-wrapper iframe {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border: 0;
}





/* WordPress oEmbed - Forzar aspect ratio 16:9 para bloques Gutenberg */
.wp-block-embed.is-provider-strimy,
figure.wp-block-embed.is-provider-strimy {
    aspect-ratio: 16 / 9 !important;
    width: 100% !important;
    max-width: none !important;
}

.wp-block-embed.is-provider-strimy .wp-block-embed__wrapper {
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
}

.wp-block-embed.is-provider-strimy iframe {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
}

/* Contenedor STRIMY dentro del wrapper de WordPress */
.wp-block-embed__wrapper .strimy-video-container.strimy-responsive {
    position: relative !important;
}

/* ===== ELEMENTOR WIDGET STRIMY VIDEO ===== */
/* Soporte para el widget STRIMY Video personalizado */

/* CSS específico para las clases exactas generadas por el widget */
.elementor-widget-strimy-video .elementor-wrapper.elementor-fit-aspect-ratio {
    position: relative !important;
    width: 100% !important;
    height: 0 !important;
    overflow: hidden !important;
}

/* Aspect ratios nativos de Elementor - Forzar que funcionen */
.elementor-widget-strimy-video .elementor-wrapper.elementor-aspect-ratio-widescreen {
    padding-bottom: 56.25% !important; /* 16:9 */
}

.elementor-widget-strimy-video .elementor-wrapper.elementor-aspect-ratio-classic {
    padding-bottom: 75% !important; /* 4:3 */
}

.elementor-widget-strimy-video .elementor-wrapper.elementor-aspect-ratio-square {
    padding-bottom: 100% !important; /* 1:1 */
}

.elementor-widget-strimy-video .elementor-wrapper.elementor-aspect-ratio-cinema {
    padding-bottom: 42.857% !important; /* 21:9 */
}

/* Iframe dentro del contenedor con aspect ratio - Máxima especificidad */
.elementor-widget-strimy-video .elementor-wrapper.elementor-fit-aspect-ratio iframe.elementor-video-iframe {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border: 0 !important;
}

/* Asegurar que el contenedor padre no interfiera */
.elementor-widget-strimy-video-extended .elementor-widget-container {
    width: 100% !important;
    max-width: none !important;
}

/* CSS SOLO para FRONTEND - NO aplicar en editor de Elementor */
body:not(.elementor-editor-active) .elementor-widget-strimy-video-extended .elementor-wrapper.elementor-fit-aspect-ratio {
    position: relative;
    width: 100%;
    height: 0;
    overflow: hidden;
}

/* Todos los aspect ratios soportados por Elementor - SOLO FRONTEND */
body:not(.elementor-editor-active) .elementor-widget-strimy-video-extended .elementor-wrapper.elementor-aspect-ratio-widescreen {
    padding-bottom: 56.25%; /* 16:9 */
}

body:not(.elementor-editor-active) .elementor-widget-strimy-video-extended .elementor-wrapper.elementor-aspect-ratio-classic {
    padding-bottom: 75%; /* 4:3 */
}

body:not(.elementor-editor-active) .elementor-widget-strimy-video-extended .elementor-wrapper.elementor-aspect-ratio-square {
    padding-bottom: 100%; /* 1:1 */
}

body:not(.elementor-editor-active) .elementor-widget-strimy-video-extended .elementor-wrapper.elementor-aspect-ratio-cinema {
    padding-bottom: 42.857%; /* 21:9 */
}

/* Iframe posicionado correctamente - SOLO FRONTEND */
body:not(.elementor-editor-active) .elementor-widget-strimy-video-extended .elementor-wrapper iframe.elementor-video-iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* CSS específico para el EDITOR de Elementor - MISMA implementación que frontend */
.elementor-editor-active .elementor-widget-strimy-video-extended .elementor-wrapper.elementor-fit-aspect-ratio {
    position: relative;
    width: 100%;
    height: 0;
    overflow: hidden;
}

/* Aspect ratios en el editor - EXACTAMENTE igual que frontend */
.elementor-editor-active .elementor-widget-strimy-video-extended .elementor-wrapper.elementor-aspect-ratio-widescreen {
    padding-bottom: 56.25%; /* 16:9 */
}

.elementor-editor-active .elementor-widget-strimy-video-extended .elementor-wrapper.elementor-aspect-ratio-classic {
    padding-bottom: 75%; /* 4:3 */
}

.elementor-editor-active .elementor-widget-strimy-video-extended .elementor-wrapper.elementor-aspect-ratio-square {
    padding-bottom: 100%; /* 1:1 */
}

.elementor-editor-active .elementor-widget-strimy-video-extended .elementor-wrapper.elementor-aspect-ratio-cinema {
    padding-bottom: 42.857%; /* 21:9 */
}

/* Iframe posicionado correctamente - EXACTAMENTE igual que frontend */
.elementor-editor-active .elementor-widget-strimy-video-extended .elementor-wrapper iframe.elementor-video-iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Estilos para el iframe de STRIMY responsive dentro del wrapper de WordPress */
.wp-block-embed__wrapper .strimy-responsive iframe[src*="strimy.pro"],
.wp-block-embed__wrapper .strimy-responsive iframe[src*="strimy.test"] {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border: 0 !important;
    border-radius: 8px !important;
    object-fit: contain !important;
    background: #000 !important;
}

/* Estilos para el iframe de STRIMY con dimensiones fijas */
.wp-block-embed__wrapper .strimy-video-fixed iframe[src*="strimy.pro"],
.wp-block-embed__wrapper .strimy-video-fixed iframe[src*="strimy.test"] {
    border: 0 !important;
    border-radius: 8px !important;
    object-fit: contain !important;
    background: #000 !important;
    max-width: 100% !important;
}

/* Bloque embed completo de WordPress */
.wp-block-embed {
    margin-top: 0.5em !important;
    margin-bottom: 0.5em !important;
}

.wp-block-embed.is-type-video {
    margin-top: 0 !important;
}

/* Permitir que WordPress maneje el aspect ratio correctamente */
.wp-block-embed.is-provider-strimy {
    margin-top: 0.5em !important;
    margin-bottom: 0.5em !important;
}

/* Forzar aspect ratio 16:9 para STRIMY */
figure.wp-block-embed.is-provider-strimy {
    aspect-ratio: 16 / 9 !important;
}

figure.wp-block-embed.is-provider-strimy .wp-block-embed__wrapper {
    position: relative !important;
    width: 100% !important;
    height: 100% !important;
}

/* Eliminar márgenes del tema en embeds */
.entry-content .strimy-video-container,
.post-content .strimy-video-container,
.content .strimy-video-container {
    margin-top: 5px !important;
}

/* ==========================================================================
   ESTILOS ESPECÍFICOS PARA ELEMENTOR
   ========================================================================== */

/* Widget de Elementor - Contenedor principal */
.elementor-widget-strimy-video .strimy-elementor-widget {
    width: 100%;
    display: block;
}

/* Modo responsive en Elementor - Siguiendo documentación oficial WordPress */
.elementor-widget-strimy-video .strimy-video-responsive {
    overflow: hidden;
    padding-top: 56.25%;
    position: relative;
}

.elementor-widget-strimy-video .strimy-video-responsive iframe {
    border: 0;
    height: 100%;
    left: 0;
    position: absolute;
    top: 0;
    width: 100%;
}

/* Modo fijo en Elementor */
.elementor-widget-strimy-video .strimy-video-fixed {
    position: relative !important;
    margin: 0 !important;
}

.elementor-widget-strimy-video .strimy-video-fixed iframe {
    width: 100% !important;
    height: 100% !important;
    border: 0 !important;
    border-radius: 8px !important;
}

/* Asegurar que no haya conflictos con otros estilos de Elementor */
.elementor-widget-strimy-video .strimy-elementor-widget * {
    box-sizing: border-box;
}

/* Responsive en diferentes breakpoints de Elementor - CSS moderno */
@media (max-width: 1024px) {
    .elementor-widget-strimy-video .strimy-video-responsive {
        aspect-ratio: 16 / 9 !important;
        width: 100% !important;
    }
}

@media (max-width: 767px) {
    .elementor-widget-strimy-video .strimy-video-responsive {
        aspect-ratio: 16 / 9 !important;
        width: 100% !important;
    }
}

/* Soporte para Picture-in-Picture */
.elementor-widget-strimy-video iframe:picture-in-picture {
    position: static !important;
    width: auto !important;
    height: auto !important;
}

/* Asegurar que PinP funcione correctamente */
.elementor-widget-strimy-video iframe {
    /* Permitir que el navegador maneje PinP correctamente */
    contain: none !important;
}

/* Iframe base */
.strimy-video-container iframe {
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: box-shadow 0.3s ease;
    display: block;
}

.strimy-video-container iframe:hover {
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

/* Contenedor responsivo para mantener aspect ratio 16:9 */
.strimy-video-responsive {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    overflow: hidden;
    border-radius: 8px;
}

.strimy-video-responsive iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
    border-radius: 8px;
}

/* Contenedor con dimensiones fijas */
.strimy-video-fixed {
    display: inline-block;
    max-width: 100%;
}

.strimy-video-fixed iframe {
    max-width: 100%;
    height: auto;
    aspect-ratio: 16 / 9; /* CSS moderno para aspect ratio */
}

/* Fallback para navegadores que no soportan aspect-ratio */
@supports not (aspect-ratio: 16 / 9) {
    .strimy-video-fixed iframe {
        height: auto;
    }
}

/* Mensaje de error */
.strimy-error {
    background: #f8d7da;
    color: #721c24;
    padding: 12px 16px;
    border: 1px solid #f1aeb5;
    border-radius: 4px;
    margin: 10px 0;
    font-size: 14px;
}

.strimy-error:before {
    content: "⚠ ";
    font-weight: bold;
}

/* Mensaje de carga */
.strimy-loading {
    background: #d1ecf1;
    color: #0c5460;
    padding: 12px 16px;
    border: 1px solid #bee5eb;
    border-radius: 4px;
    margin: 10px 0;
    font-size: 14px;
    text-align: center;
}

.strimy-loading:before {
    content: "⏳ ";
    font-weight: bold;
}

/* Estilos para temas específicos */
.strimy-theme-dark .strimy-video-container {
    background: #1a1a1a;
    border-radius: 8px;
    padding: 10px;
}

.strimy-theme-light .strimy-video-container {
    background: #ffffff;
    border: 1px solid #e1e5e9;
    border-radius: 8px;
    padding: 10px;
}

/* Media queries para responsividad */
@media (max-width: 768px) {
    .strimy-video-container {
        margin: 15px 0;
    }
    
    .strimy-video-container iframe {
        border-radius: 4px;
    }
    
    .strimy-video-responsive {
        border-radius: 4px;
    }
    
    .strimy-video-responsive iframe {
        border-radius: 4px;
    }
}

@media (max-width: 480px) {
    .strimy-video-container {
        margin: 10px 0;
    }
}

/* Animaciones */
@keyframes strimy-fade-in {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.strimy-video-container {
    animation: strimy-fade-in 0.3s ease-out;
}

/* Accesibilidad */
.strimy-video-container:focus-within {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* Sobrescribir estilos restrictivos de WordPress para iframes de STRIMY */
iframe[src*="strimy.pro"],
iframe[src*="strimy.test"] {
    max-width: 100% !important;
    border: 0 !important;
    border-radius: 8px !important;
}

/* Asegurar que los iframes de STRIMY en contenedores responsive funcionen */
.strimy-video-responsive iframe[src*="strimy.pro"],
.strimy-video-responsive iframe[src*="strimy.test"] {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border: 0 !important;
    border-radius: 8px !important;
}

/* Corregir iframes de WordPress embebidos de STRIMY */
iframe.wp-embedded-content[src*="strimy.pro"],
iframe.wp-embedded-content[src*="strimy.test"] {
    width: 100% !important;
    height: auto !important;
    aspect-ratio: 16 / 9 !important;
    min-height: 300px !important;
    border: 0 !important;
    border-radius: 8px !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

/* Print styles */
@media print {
    .strimy-video-container {
        display: none;
    }
    
    .strimy-video-container:after {
        content: "Video de STRIMY: " attr(data-video-url);
        display: block;
        padding: 10px;
        background: #f0f0f0;
        border: 1px solid #ccc;
        font-size: 12px;
        color: #666;
    }
}
