/**
 * Lazy Loading - Estilos para carregamento progressivo de imagens
 */

/* Animação de fade-in para imagens lazy */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
}

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

/* Placeholder com blur enquanto carrega */
.lazy-blur-wrapper {
    position: relative;
    overflow: hidden;
    background: linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

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

/* Efeito de desfoque progressivo */
img.blur-loading {
    filter: blur(10px);
    transition: filter 0.3s ease-out;
}

img.blur-loading.loaded {
    filter: blur(0);
}

/* Container de imagem com aspect ratio para evitar layout shift */
.lazy-image-container {
    position: relative;
    overflow: hidden;
    background-color: #f3f4f6;
}

.lazy-image-container::before {
    content: '';
    display: block;
    padding-bottom: 75%; /* Aspect ratio 4:3 - ajustar conforme necessário */
}

.lazy-image-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Spinner de carregamento (opcional) */
.lazy-spinner {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid #f3f4f6;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    opacity: 0.5;
}

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

/* Otimização para mobile - reduz qualidade em telas menores */
@media (max-width: 768px) {
    img[loading="lazy"] {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* Prevenção de layout shift */
img:not([width]):not([height]) {
    width: 100%;
    height: auto;
    display: block;
}

/* Efeito para imagens em cards de produtos */
.product-card img {
    transition: transform 0.3s ease, opacity 0.3s ease;
}

.product-card img:not(.lazy-loaded) {
    opacity: 0;
    transform: scale(0.95);
}

.product-card img.lazy-loaded {
    opacity: 1;
    transform: scale(1);
}

/* Performance: Força GPU acceleration */
img[loading="lazy"] {
    will-change: opacity;
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Remove blur após carregar */
img.lazy-loaded {
    filter: none !important;
}
