/* ═══════════════════════════════════════════════════════════════
   MEDIA LOADER — Shimmer / Skeleton loading animations
   Applied automatically to all <img> and <video> elements
   ═══════════════════════════════════════════════════════════════ */

/* Base shimmer keyframe */
@keyframes ml-shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes ml-pulse {
    0%, 100% { opacity: 0.4; }
    50%      { opacity: 0.8; }
}

/* Wrapper that gets added around each media element */
.ml-wrap {
    position: relative;
    display: inline-block;
    overflow: hidden;
    line-height: 0;
    width: 100%;
}

/* Skeleton overlay — shown before the image/video loads */
.ml-skeleton {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: inherit;
    background: linear-gradient(
        90deg,
        rgba(30, 41, 59, 0.6) 0%,
        rgba(51, 65, 85, 0.8) 25%,
        rgba(71, 85, 105, 0.6) 50%,
        rgba(51, 65, 85, 0.8) 75%,
        rgba(30, 41, 59, 0.6) 100%
    );
    background-size: 200% 100%;
    animation: ml-shimmer 1.8s ease-in-out infinite;
    transition: opacity 0.4s ease, visibility 0.4s ease;
    pointer-events: none;
}

/* Spinner icon inside skeleton */
.ml-skeleton::after {
    content: '';
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid rgba(99, 102, 241, 0.2);
    border-top-color: rgba(99, 102, 241, 0.8);
    animation: ml-spin 0.8s linear infinite;
}

@keyframes ml-spin {
    to { transform: rotate(360deg); }
}

/* Small variant for tiny images (logos, avatars) */
.ml-skeleton.ml-small::after {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

/* When media has loaded, hide the skeleton */
.ml-wrap.ml-loaded .ml-skeleton {
    opacity: 0;
    visibility: hidden;
}

/* Fade-in for the actual media element */
.ml-wrap img,
.ml-wrap video {
    transition: opacity 0.4s ease;
}

.ml-wrap:not(.ml-loaded) img,
.ml-wrap:not(.ml-loaded) video {
    opacity: 0;
}

.ml-wrap.ml-loaded img,
.ml-wrap.ml-loaded video {
    opacity: 1;
}

/* Error state — show a subtle broken-image indicator */
.ml-wrap.ml-error .ml-skeleton {
    animation: none;
    background: rgba(30, 41, 59, 0.8);
}

.ml-wrap.ml-error .ml-skeleton::after {
    content: '!';
    border: 2px solid rgba(248, 113, 113, 0.4);
    border-top-color: rgba(248, 113, 113, 0.4);
    animation: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: rgba(248, 113, 113, 0.8);
    font-family: system-ui, sans-serif;
}

/* Light-theme variant (auto-detect) */
@media (prefers-color-scheme: light) {
    .ml-skeleton {
        background: linear-gradient(
            90deg,
            rgba(226, 232, 240, 0.6) 0%,
            rgba(203, 213, 225, 0.8) 25%,
            rgba(226, 232, 240, 0.6) 50%,
            rgba(203, 213, 225, 0.8) 75%,
            rgba(226, 232, 240, 0.6) 100%
        );
        background-size: 200% 100%;
        animation: ml-shimmer 1.8s ease-in-out infinite;
    }
}
