/**
 * Lazy Loading Styles
 * Styles for image lazy loading, placeholders, and blur-up effects
 */

/* ============================================
   Lazy Image States
   ============================================ */

/* Base lazy image - not yet loaded */
.lazy-image {
    background-color: var(--surface-dark, #1a1a2e);
    transition: opacity 0.3s ease-in-out, filter 0.3s ease-in-out;
    will-change: opacity, filter;
}

/* Loading state - shimmer effect */
.lazy-image.loading {
    position: relative;
    overflow: hidden;
}

.lazy-image.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0) 0%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0) 100%
    );
    animation: shimmer 1.5s infinite;
}

@keyframes shimmer {
    0% {
        left: -100%;
    }
    100% {
        left: 100%;
    }
}

/* Loaded state - fade in with blur-up effect */
.lazy-image {
    filter: blur(10px);
    opacity: 0.6;
}

.lazy-image.loaded {
    filter: blur(0);
    opacity: 1;
}

/* Error state - show error indicator */
.lazy-image.load-error {
    background-color: rgba(255, 0, 0, 0.1);
    border: 2px dashed rgba(255, 0, 0, 0.3);
    opacity: 0.5;
    filter: none;
}

/* ============================================
   Aspect Ratio Containers
   ============================================ */

/* Prevent layout shift by maintaining aspect ratio */
.lazy-image-container {
    position: relative;
    overflow: hidden;
    background-color: var(--surface-dark, #1a1a2e);
}

.lazy-image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Default aspect ratios for common media */
.aspect-ratio-16-9 {
    aspect-ratio: 16 / 9;
}

.aspect-ratio-4-3 {
    aspect-ratio: 4 / 3;
}

.aspect-ratio-1-1 {
    aspect-ratio: 1 / 1;
}

.aspect-ratio-3-4 {
    aspect-ratio: 3 / 4;
}

/* ============================================
   Placeholder Animations
   ============================================ */

/* Skeleton placeholder with gradient animation */
.image-placeholder {
    background: linear-gradient(
        90deg,
        rgba(255, 255, 255, 0.05) 25%,
        rgba(255, 255, 255, 0.1) 50%,
        rgba(255, 255, 255, 0.05) 75%
    );
    background-size: 200% 100%;
    animation: loading-skeleton 1.5s infinite;
}

@keyframes loading-skeleton {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Pulse animation for loading state */
.pulse-placeholder {
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

/* ============================================
   Generation Card Integration
   ============================================ */

/* Apply lazy loading styles to generation cards */
.generation-card .lazy-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.generation-preview .lazy-image,
.image-container .lazy-image {
    display: block;
}

/* Ensure smooth transitions in grid view */
.generation-card.grid-view .lazy-image {
    border-radius: 8px 8px 0 0;
}

/* List view adjustments */
.generation-card.list-view .lazy-image {
    border-radius: 4px;
    max-width: 80px;
    max-height: 80px;
}

/* ============================================
   Loading Indicator Overlay
   ============================================ */

/* Optional spinner overlay for loading images */
.lazy-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.3);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
}

.lazy-image.loading + .lazy-loading-overlay {
    opacity: 1;
}

.lazy-loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================
   Performance Optimizations
   ============================================ */

/* Optimize rendering with GPU acceleration */
.lazy-image {
    transform: translateZ(0);
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

/* Reduce reflows during scroll */
.lazy-image-container {
    contain: layout style paint;
}

/* ============================================
   Responsive Adjustments
   ============================================ */

/* Mobile optimizations */
@media (max-width: 768px) {
    /* Reduce blur for faster rendering on mobile */
    .lazy-image {
        filter: blur(5px);
    }

    /* Smaller spinner on mobile */
    .lazy-loading-spinner {
        width: 24px;
        height: 24px;
        border-width: 2px;
    }
}

/* High-DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Ensure sharp images on retina displays */
    .lazy-image.loaded {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ============================================
   Accessibility
   ============================================ */

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .lazy-image {
        transition: opacity 0.1s;
        filter: none;
    }

    .lazy-image.loading::after {
        animation: none;
    }

    .image-placeholder {
        animation: none;
        background: rgba(255, 255, 255, 0.1);
    }

    .lazy-loading-spinner {
        animation: none;
        border-top-color: rgba(255, 255, 255, 0.5);
    }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    /* Force load all images for printing */
    .lazy-image {
        opacity: 1 !important;
        filter: none !important;
    }

    .lazy-image.loading::after {
        display: none;
    }

    .lazy-loading-overlay {
        display: none;
    }
}

/* ============================================
   Debug Helpers (remove in production)
   ============================================ */

/* Show loading states with colored borders for debugging */
.debug-lazy-loading .lazy-image {
    border: 3px solid yellow;
}

.debug-lazy-loading .lazy-image.loading {
    border-color: orange;
}

.debug-lazy-loading .lazy-image.loaded {
    border-color: green;
}

.debug-lazy-loading .lazy-image.load-error {
    border-color: red;
}
