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

/* Wrapper oEmbed - respeta el HTML del servidor con aspect ratio correcto */
.strimy-oembed-wrapper {
    width: 100%;
    max-width: 100%;
    margin: 10px 0;
    box-sizing: border-box;
}

.strimy-oembed-wrapper iframe {
    border: 0;
}

/* Video vertical vía oEmbed - limitar ancho y centrar */
.strimy-oembed-wrapper iframe[data-aspect-ratio="9:16"],
.strimy-oembed-wrapper iframe[data-aspect-ratio="3:4"] {
    max-width: 400px;
}

.strimy-oembed-wrapper:has(iframe[data-aspect-ratio="9:16"]),
.strimy-oembed-wrapper:has(iframe[data-aspect-ratio="3:4"]) {
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

@media (max-width: 480px) {
    .strimy-oembed-wrapper:has(iframe[data-aspect-ratio="9:16"]),
    .strimy-oembed-wrapper:has(iframe[data-aspect-ratio="3:4"]) {
        max-width: 100%;
    }
}

/* Contenedor responsive fallback - 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 - Bloques Gutenberg de STRIMY */
.wp-block-embed.is-provider-strimy,
figure.wp-block-embed.is-provider-strimy {
    width: 100% !important;
    max-width: none !important;
}

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

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

/* ===== ELEMENTOR WIDGET STRIMY VIDEO ===== */
/* Estructura HTML del widget:
   .elementor-widget-strimy-video > .elementor-widget-container >
     .elementor-wrapper.elementor-open-inline >
       .strimy-aspect-ratio-box (padding-bottom inline) >
         iframe.elementor-video-iframe (position absolute inline)
*/

/* Evitar que flexbox del contenedor Elementor estire el widget */
.elementor-widget-strimy-video {
    align-self: start;
    width: 100%;
}

/* Contenedor del widget */
.elementor-widget-strimy-video .elementor-widget-container {
    width: 100%;
}

/* Wrapper principal */
.elementor-widget-strimy-video .elementor-wrapper {
    width: 100%;
}

/* Caja de aspect ratio - usa CSS aspect-ratio (compatible con flexbox align-items) */
.elementor-widget-strimy-video .strimy-aspect-ratio-box {
    width: 100%;
    overflow: hidden;
}

/* Iframe dentro de la caja de aspect ratio */
.elementor-widget-strimy-video .strimy-aspect-ratio-box iframe.elementor-video-iframe {
    width: 100% !important;
    height: 100% !important;
    border: 0 !important;
    display: block;
}

/* Video vertical (9:16) - limitar ancho y centrar */
.elementor-widget-strimy-video .elementor-wrapper.strimy-vertical {
    max-width: 400px;
    margin-left: auto;
    margin-right: auto;
}

@media (max-width: 768px) {
    .elementor-widget-strimy-video .elementor-wrapper.strimy-vertical {
        max-width: 100%;
    }
}

/* Prevenir overflow en móviles */
@media (max-width: 768px) {
    .elementor-widget-strimy-video {
        overflow: hidden;
        max-width: 100%;
        box-sizing: border-box;
    }
}

/* ===== WORDPRESS EMBEDS ===== */

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

/* Bloque embed completo de WordPress */
.wp-block-embed.is-provider-strimy {
    width: 100% !important;
    max-width: none !important;
}

.wp-block-embed.is-provider-strimy .wp-block-embed__wrapper {
    position: relative !important;
    width: 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;
}

/* 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;
}

/* 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;
    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;
    }
}
