/* Lazy Loading Image System */

/* Images that will be lazy loaded */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.3s ease-in-out;
}

img[loading="lazy"].loaded {
    opacity: 1;
}

/* Blur placeholder effect */
.lazy-image-wrapper {
    position: relative;
    overflow: hidden;
    background: var(--bg-tertiary);
}

.lazy-image {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: opacity 0.3s ease-in-out, filter 0.3s ease-in-out;
}

.lazy-image.lazy-loading {
    opacity: 0;
}

.lazy-image.lazy-loaded {
    opacity: 1;
}

/* Blur-up effect (loads tiny blurred image first) */
.lazy-image-blur {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(20px);
    transform: scale(1.1);
    opacity: 1;
    transition: opacity 0.3s ease-in-out;
}

.lazy-image-blur.hidden {
    opacity: 0;
}

/* Loading skeleton/placeholder */
.image-skeleton {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        #f0f0f0 0%,
        #f8f8f8 50%,
        #f0f0f0 100%
    );
    background-size: 200% 100%;
    animation: loading-skeleton 1.5s ease-in-out infinite;
}

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

/* Fade in animation */
.fade-in {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

/* Auction card image specific styles */
.auction-card .lazy-image-wrapper {
    aspect-ratio: 16/9;
    background: var(--bg-tertiary);
}

.auction-card .lazy-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Auction detail page main image */
.auction-detail .lazy-image-wrapper {
    background: var(--bg-tertiary);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

/* Thumbnail images */
.thumbnail.lazy-loading {
    opacity: 0.5;
}

.thumbnail.lazy-loaded {
    opacity: 1;
}

/* Progressive image loading indicator */
.lazy-image-wrapper::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 3px solid rgba(0, 0, 0, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spinner 0.8s linear infinite;
    opacity: 0;
    pointer-events: none;
}

.lazy-image-wrapper.loading::before {
    opacity: 1;
}

.lazy-image-wrapper.loaded::before {
    opacity: 0;
}

@keyframes spinner {
    to {
        transform: translate(-50%, -50%) rotate(360deg);
    }
}

/* Error state for failed image loads */
.lazy-image-error {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.lazy-image-error::before {
    content: '📷';
    font-size: 2rem;
    display: block;
    margin-bottom: 0.5rem;
}

/* Responsive performance optimizations */
@media (prefers-reduced-motion: reduce) {
    .lazy-image,
    .lazy-image-blur,
    img[loading="lazy"] {
        transition: none;
    }
    
    .fade-in {
        animation: none;
    }
}

/* Print optimization */
@media print {
    .lazy-image-wrapper::before,
    .image-skeleton {
        display: none;
    }
    
    .lazy-image {
        opacity: 1 !important;
        filter: none !important;
    }
}
