/**
 * Video Embedding Styles for Inside Talk
 * Responsive design for YouTube and Twitter embeds
 */

/* Base video embed container */
.video-embed {
    margin: 12px 0;
    border-radius: 8px;
    overflow: hidden;
    background: var(--surface-color, #f8f9fa);
    transition: all 0.3s ease;
}

.video-embed:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* YouTube embed specific styles */
.youtube-embed {
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    background: #000 !important;
    overflow: hidden;
}

.youtube-embed iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    border-radius: 8px;
    background: #000;
}

/* Twitter embed specific styles */
.twitter-embed {
    max-width: 100%;
    margin: 12px auto;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent !important;
}

.twitter-embed .twitter-tweet {
    margin: 0 auto !important;
    max-width: 100% !important;
    border-radius: 8px !important;
    width: 100% !important;
}

.twitter-embed iframe {
    max-width: 100% !important;
    width: 100% !important;
    background: #fff !important;
}

/* Instagram embed specific styles */
.instagram-embed {
    max-width: 100%;
    margin: 12px auto;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.instagram-embed .instagram-media {
    margin: 0 auto !important;
    max-width: 540px !important;
    border-radius: 8px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
}

/* Instagram loading state */
.instagram-loading {
    background: linear-gradient(45deg, #f9f9f9 25%, transparent 25%), 
                linear-gradient(-45deg, #f9f9f9 25%, transparent 25%), 
                linear-gradient(45deg, transparent 75%, #f9f9f9 75%), 
                linear-gradient(-45deg, transparent 75%, #f9f9f9 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    animation: instagram-loading 1.5s linear infinite;
}

@keyframes instagram-loading {
    0% { background-position: 0 0, 0 10px, 10px -10px, -10px 0px; }
    100% { background-position: 20px 20px, 20px 30px, 30px 10px, 10px 20px; }
}

/* Instagram simple embed fallback */
.instagram-simple-embed {
    background: linear-gradient(135deg, #E4405F, #C13584, #833AB4);
    color: white;
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    transition: all 0.3s ease;
}

.instagram-simple-embed:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px rgba(228, 64, 95, 0.3);
}

.instagram-simple-embed a:hover {
    background: rgba(255,255,255,0.3) !important;
    transform: scale(1.05);
}

/* Loading state for Twitter embeds */
.twitter-embed:not(.twitter-tweet-rendered) {
    background: linear-gradient(45deg, #f0f0f0 25%, transparent 25%), 
                linear-gradient(-45deg, #f0f0f0 25%, transparent 25%), 
                linear-gradient(45deg, transparent 75%, #f0f0f0 75%), 
                linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    animation: twitter-loading 1s linear infinite;
}

.twitter-embed:not(.twitter-tweet-rendered)::before {
    content: "🐦 Loading tweet...";
    color: #1da1f2;
    font-weight: 500;
    text-align: center;
}

@keyframes twitter-loading {
    0% { background-position: 0 0, 0 10px, 10px -10px, -10px 0px; }
    100% { background-position: 20px 20px, 20px 30px, 30px 10px, 10px 20px; }
}

/* Hide loading animation once Twitter widget is rendered */
.twitter-tweet-rendered .twitter-embed {
    background: none;
    animation: none;
    min-height: auto;
}

.twitter-tweet-rendered .twitter-embed::before {
    display: none;
}

/* Twitter fallback styles */
.twitter-fallback-shown .twitter-embed {
    background: none;
    animation: none;
    min-height: auto;
}

.twitter-fallback-shown .twitter-embed::before {
    display: none;
}

.twitter-fallback {
    transition: all 0.3s ease;
}

.twitter-fallback:hover {
    background: #f0f8ff !important;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(29, 161, 242, 0.2);
}

.twitter-fallback a:hover {
    background: #1991db !important;
    transform: scale(1.05);
    transition: all 0.2s ease;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .video-embed {
        margin: 8px auto;
        border-radius: 6px;
    }
    
    /* Flock Feed mobile centering and full-width */
    .flock-post-content .video-embed,
    .flock-post .video-embed {
        margin-left: -12px !important;
        margin-right: -12px !important;
        display: block;
        width: calc(100% + 24px) !important;
        max-width: calc(100% + 24px) !important;
    }
    
    .flock-post .youtube-embed,
    .flock-post .twitter-embed,
    .flock-post .instagram-embed {
        margin-left: -12px !important;
        margin-right: -12px !important;
        width: calc(100% + 24px) !important;
        max-width: calc(100% + 24px) !important;
    }
    
    .flock-post .twitter-embed iframe {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .youtube-embed {
        padding-bottom: 56.25%; /* Maintain 16:9 on mobile */
    }
    
    .twitter-embed {
        margin: 8px 0;
    }
    
    .twitter-embed .twitter-tweet {
        border-radius: 6px !important;
    }
}

/* Small mobile devices */
@media (max-width: 480px) {
    .video-embed {
        margin: 6px 0;
        border-radius: 4px;
    }
    
    .youtube-embed iframe {
        border-radius: 4px;
    }
    
    .twitter-embed .twitter-tweet {
        border-radius: 4px !important;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .video-embed {
        background: var(--dark-surface-color, #1a1a1a);
    }
}

.dark-mode .video-embed {
    background: var(--dark-surface-color, #1a1a1a);
}

/* Loading state for embeds */
.video-embed.loading {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s infinite;
}

@keyframes loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Inside Talk specific integration */
.tweet-content .video-embed {
    margin-top: 8px;
    margin-bottom: 8px;
}

.tweet-text + .video-embed {
    margin-top: 12px;
}

/* Ensure embeds don't break tweet layout */
.tweet .video-embed {
    max-width: 100%;
    overflow: hidden;
}

/* Flock Feed specific integration */
.flock-post-content .video-embed {
    margin: 12px auto 8px auto;
    display: block;
    width: 100%;
}

.flock-post-text + .video-embed {
    margin-top: 12px;
}

/* Ensure embeds don't break flock post layout */
.flock-post .video-embed {
    max-width: 100%;
    overflow: hidden;
    background: #000 !important; /* Solid background to prevent transparency issues */
    margin-left: auto;
    margin-right: auto;
    display: block;
}

.flock-post .youtube-embed {
    background: #000 !important;
    position: relative;
    width: 100%;
    height: 0;
    padding-bottom: 56.25%;
    margin-left: auto;
    margin-right: auto;
}

.flock-post .youtube-embed iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

.flock-post .twitter-embed {
    background: transparent !important;
    max-width: 550px;
    margin: 12px auto;
    min-height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.flock-post .twitter-embed iframe {
    max-width: 100% !important;
    width: 100% !important;
}

.flock-post .instagram-embed {
    background: transparent !important;
    max-width: 540px;
    margin: 12px auto;
    min-height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Error state for failed embeds */
.video-embed.error {
    background: #fee;
    border: 1px solid #fcc;
    padding: 16px;
    text-align: center;
    color: #c33;
    border-radius: 8px;
}

.video-embed.error::before {
    content: "⚠️ ";
    font-size: 1.2em;
}

/* Accessibility improvements */
.video-embed iframe {
    outline: none;
}

.video-embed:focus-within {
    outline: 2px solid var(--primary-color, #007bff);
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .video-embed {
        display: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .video-embed {
        border: 2px solid;
    }
    
    .video-embed:hover {
        border-width: 3px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .video-embed {
        transition: none;
    }
    
    .video-embed:hover {
        transform: none;
    }
    
    .video-embed.loading {
        animation: none;
        background: #f0f0f0;
    }
}
