/**
 * Multi-Source Video Embed Widget Styles
 *
 * Styles for embedding videos from Instagram, YouTube, TikTok, and BunnyNet
 * with facade pattern.
 *
 * @since 1.16.0
 * @since 1.16.1 Added support for video posts and featured image placeholder.
 * @since 1.16.2 Added responsive controls, icon picker, improved aspect ratios.
 * @since 1.16.4 Fixed Font Awesome icon sizing for play button.
 * @since 1.21.0 Multi-provider styles (YouTube, TikTok, BunnyNet).
 */

/* ==========================================================================
   1. CSS Custom Properties
   ========================================================================== */

.mw-reel-embed {
    --reel-width: 426px;
    --reel-height: 765px;
    --reel-aspect-ratio: 9 / 16;
    --reel-border-radius: 12px;
    --reel-bg-color: #000;
    --reel-play-size: 70px;
    --reel-play-color: #fff;
    --reel-play-bg: rgba(0, 0, 0, 0.6);
    --reel-spinner-color: #E1306C; /* Instagram pink */
}

/* ==========================================================================
   2. Container Styles
   ========================================================================== */

.mw-reel-embed {
    position: relative;
    width: var(--reel-width);
    max-width: 100%;
    aspect-ratio: var(--reel-aspect-ratio);
    background-color: var(--reel-bg-color);
    border-radius: var(--reel-border-radius);
    overflow: hidden;
    /* Center by default - can be overridden by widget alignment setting */
    margin-inline: auto;
}

/* Wrapper for alignment */
.mw-reel-embed-wrapper {
    display: flex;
    width: 100%;
}

/* ==========================================================================
   3. Facade (Initial State)
   ========================================================================== */

.mw-reel-embed__facade {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.3s ease;
    z-index: 1;
}

/* Overlay pseudo-element */
.mw-reel-embed__facade::after {
    content: '';
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.2);
    transition: background-color 0.3s ease;
    pointer-events: none;
    z-index: 1;
}

/* Thumbnail - full cover with proper sizing */
.mw-reel-embed__thumbnail {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100% !important;
    height: 100% !important;
    min-width: 100%;
    min-height: 100%;
    object-fit: cover !important;
    object-position: center center;
    display: block;
}

/* ==========================================================================
   3.1 Play Button - Force 1:1 Aspect Ratio
   ========================================================================== */

.mw-reel-embed__play {
    position: relative;
    z-index: 2;
    /* Force 1:1 aspect ratio */
    width: var(--reel-play-size);
    min-width: var(--reel-play-size);
    height: var(--reel-play-size);
    min-height: var(--reel-play-size);
    aspect-ratio: 1 / 1;
    flex-shrink: 0;
    /* Set font-size to match button size for percentage-based icon sizing */
    font-size: var(--reel-play-size);
    /* Styling */
    border: none;
    border-radius: 50%;
    background: var(--reel-play-bg);
    color: var(--reel-play-color);
    cursor: pointer;
    /* Flexbox centering for icon */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    /* Transitions */
    transition: transform 0.3s ease, background-color 0.3s ease, box-shadow 0.3s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* Play button icon sizing - SVG */
.mw-reel-embed__play svg {
    width: 40%;
    height: 40%;
    flex-shrink: 0;
    fill: currentColor;
}

/* Play button icon sizing - Font Icons (i element) */
.mw-reel-embed__play i {
    /* Default 40% of button size - Elementor control overrides this */
    font-size: 0.4em;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* Play button hover/focus states */
.mw-reel-embed__play:hover,
.mw-reel-embed__play:focus-visible {
    transform: scale(1.1);
    background: rgba(0, 0, 0, 0.8);
}

.mw-reel-embed__play:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ==========================================================================
   4. Loading State
   ========================================================================== */

.mw-reel-embed__loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--reel-bg-color);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mw-reel-embed--loading .mw-reel-embed__loading {
    opacity: 1;
    visibility: visible;
}

.mw-reel-embed--loading .mw-reel-embed__facade {
    opacity: 0;
    pointer-events: none;
}

/* Spinner - matches existing Maya search widget spinner */
.mw-reel-embed__spinner {
    width: 60px;
    height: 60px;
    color: var(--reel-spinner-color);
}

/* ==========================================================================
   5. Loaded State (Content Visible)
   ========================================================================== */

.mw-reel-embed__content {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
}

.mw-reel-embed--loaded .mw-reel-embed__content {
    opacity: 1;
    visibility: visible;
}

.mw-reel-embed--loaded .mw-reel-embed__facade,
.mw-reel-embed--loaded .mw-reel-embed__loading {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

/* Instagram embed iframe styling */
.mw-reel-embed__content iframe {
    width: 100% !important;
    height: 100% !important;
    border: none;
}

.mw-reel-embed__content .instagram-media {
    margin: 0 !important;
    max-width: 100% !important;
    min-width: 100% !important;
}

/* ==========================================================================
   6. Responsive Design
   ========================================================================== */

@media (max-width: 480px) {
    .mw-reel-embed {
        --reel-width: 100%;
        --reel-play-size: 60px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .mw-reel-embed__play,
    .mw-reel-embed__facade,
    .mw-reel-embed__loading,
    .mw-reel-embed__content {
        transition: none;
    }

    .mw-reel-embed__spinner circle {
        animation: none;
    }
}

/* ==========================================================================
   7. RTL Support (Hebrew)
   ========================================================================== */

[dir="rtl"] .mw-reel-embed__play svg {
    margin-inline-start: 4px;
    margin-inline-end: 0;
}

/* ==========================================================================
   8. Alignment Classes
   ========================================================================== */

.mw-reel-embed--align-left {
    margin-inline-start: 0;
    margin-inline-end: auto;
}

.mw-reel-embed--align-center {
    margin-inline: auto;
}

.mw-reel-embed--align-right {
    margin-inline-start: auto;
    margin-inline-end: 0;
}

/* ==========================================================================
   9. Editor Placeholder
   ========================================================================== */

.mw-reel-embed-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 426px;
    aspect-ratio: 9 / 16;
    max-width: 100%;
    background: linear-gradient(135deg, #833ab4, #fd1d1d, #fcb045);
    color: #fff;
    font-size: 14px;
    text-align: center;
    padding: 20px;
    border-radius: 12px;
}

/* ==========================================================================
   10. Error State
   ========================================================================== */

.mw-reel-embed--error .mw-reel-embed__content {
    display: flex;
    flex-direction: column;
    gap: 10px;
    color: #fff;
    font-size: 14px;
    text-align: center;
    padding: 20px;
}

.mw-reel-embed--error .mw-reel-embed__content::before {
    content: '\26A0\FE0F';
    font-size: 32px;
}

/* ==========================================================================
   11. Content Type Variations
   ========================================================================== */

/*
 * Reel-specific styles (if any visual differences needed)
 * Default styles already work for reels
 */
.mw-reel-embed--type-reel {
    /* Uses default 9:16 aspect ratio */
}

/*
 * Post-specific styles
 * Posts may have different aspect ratios (1:1, 4:5, 16:9)
 * but we maintain 9:16 for consistent embed display
 */
.mw-reel-embed--type-post {
    /* Uses same styling as reels for consistent video display */
}

/* ==========================================================================
   12. Thumbnail Placeholder (Instagram Gradient)
   ========================================================================== */

.mw-reel-embed__thumbnail-placeholder {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 50%, #fcb045 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Instagram logo icon placeholder */
.mw-reel-embed__thumbnail-placeholder::before {
    content: '';
    width: 60px;
    height: 60px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white' opacity='0.5'%3E%3Cpath d='M12 2.163c3.204 0 3.584.012 4.85.07 3.252.148 4.771 1.691 4.919 4.919.058 1.265.069 1.645.069 4.849 0 3.205-.012 3.584-.069 4.849-.149 3.225-1.664 4.771-4.919 4.919-1.266.058-1.644.07-4.85.07-3.204 0-3.584-.012-4.849-.07-3.26-.149-4.771-1.699-4.919-4.92-.058-1.265-.07-1.644-.07-4.849 0-3.204.013-3.583.07-4.849.149-3.227 1.664-4.771 4.919-4.919 1.266-.057 1.645-.069 4.849-.069zM12 0C8.741 0 8.333.014 7.053.072 2.695.272.273 2.69.073 7.052.014 8.333 0 8.741 0 12c0 3.259.014 3.668.072 4.948.2 4.358 2.618 6.78 6.98 6.98C8.333 23.986 8.741 24 12 24c3.259 0 3.668-.014 4.948-.072 4.354-.2 6.782-2.618 6.979-6.98.059-1.28.073-1.689.073-4.948 0-3.259-.014-3.667-.072-4.947-.196-4.354-2.617-6.78-6.979-6.98C15.668.014 15.259 0 12 0z'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0.5;
}

/* ==========================================================================
   13. Provider-Specific Styles
   ========================================================================== */

/* -- Instagram (default gradient - kept for backward compat) -- */
.mw-reel-embed--provider-instagram {
    --reel-spinner-color: #E1306C;
}

.mw-reel-embed--provider-instagram .mw-reel-embed__thumbnail-placeholder {
    background: linear-gradient(135deg, #833ab4 0%, #fd1d1d 50%, #fcb045 100%);
}

/* -- YouTube -- */
.mw-reel-embed--provider-youtube {
    --reel-spinner-color: #FF0000;
}

.mw-reel-embed--provider-youtube .mw-reel-embed__thumbnail-placeholder {
    background: linear-gradient(135deg, #282828 0%, #FF0000 60%, #cc0000 100%);
}

.mw-reel-embed--provider-youtube .mw-reel-embed__thumbnail-placeholder::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white' opacity='0.5'%3E%3Cpath d='M23.498 6.186a3.016 3.016 0 0 0-2.122-2.136C19.505 3.545 12 3.545 12 3.545s-7.505 0-9.377.505A3.017 3.017 0 0 0 .502 6.186C0 8.07 0 12 0 12s0 3.93.502 5.814a3.016 3.016 0 0 0 2.122 2.136c1.871.505 9.376.505 9.376.505s7.505 0 9.377-.505a3.015 3.015 0 0 0 2.122-2.136C24 15.93 24 12 24 12s0-3.93-.502-5.814zM9.545 15.568V8.432L15.818 12l-6.273 3.568z'/%3E%3C/svg%3E");
}

/* -- TikTok -- */
.mw-reel-embed--provider-tiktok {
    --reel-spinner-color: #25F4EE;
}

.mw-reel-embed--provider-tiktok .mw-reel-embed__thumbnail-placeholder {
    background: linear-gradient(135deg, #010101 0%, #25F4EE 50%, #FE2C55 100%);
}

.mw-reel-embed--provider-tiktok .mw-reel-embed__thumbnail-placeholder::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white' opacity='0.5'%3E%3Cpath d='M19.59 6.69a4.83 4.83 0 0 1-3.77-4.25V2h-3.45v13.67a2.89 2.89 0 0 1-2.88 2.5 2.89 2.89 0 0 1-2.89-2.89 2.89 2.89 0 0 1 2.89-2.89c.28 0 .54.04.79.1v-3.5a6.37 6.37 0 0 0-.79-.05A6.34 6.34 0 0 0 3.16 15a6.34 6.34 0 0 0 6.33 6.34 6.34 6.34 0 0 0 6.34-6.34V8.55a8.27 8.27 0 0 0 4.76 1.5V6.72a4.83 4.83 0 0 1-1-.03z'/%3E%3C/svg%3E");
}

/* TikTok blockquote overrides */
.mw-reel-embed--provider-tiktok .mw-reel-embed__content blockquote {
    margin: 0 !important;
    max-width: 100% !important;
}

/* -- BunnyNet -- */
.mw-reel-embed--provider-bunnynet {
    --reel-spinner-color: #FF7300;
}

.mw-reel-embed--provider-bunnynet .mw-reel-embed__thumbnail-placeholder {
    background: linear-gradient(135deg, #1a1a2e 0%, #FF7300 60%, #FFa500 100%);
}

.mw-reel-embed--provider-bunnynet .mw-reel-embed__thumbnail-placeholder::before {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='white' opacity='0.5'%3E%3Cpath d='M8 5v14l11-7z'/%3E%3C/svg%3E");
}

/* ==========================================================================
   14. Client-Side Embed Styles (YouTube iframe / BunnyNet video)
   ========================================================================== */

.mw-reel-embed--provider-youtube .mw-reel-embed__content iframe {
    width: 100% !important;
    height: 100% !important;
    border: none;
    position: absolute;
    top: 0;
    left: 0;
}

.mw-reel-embed--provider-bunnynet .mw-reel-embed__content video {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain;
    background: #000;
    position: absolute;
    top: 0;
    left: 0;
}
