/* ============================
   SISTEMA DE LAZY LOADING
   ============================ */

/* Imagen lazy básica */
.lazy-image {
    transition: opacity 0.3s ease, transform 0.3s ease;
    will-change: opacity, transform;
}

.lazy-image:not(.lazy-loaded) {
    transform: scale(0.95);
}

.lazy-image.lazy-loaded {
    opacity: 1;
    transform: scale(1);
}

/* Contenedor placeholder */
.lazy-placeholder {
    position: relative;
    width: 100%;
    background-color: #f5f5f5;
    border-radius: 4px;
    overflow: hidden;
    display: block;
}

/* Skeleton loader animado */
.lazy-skeleton {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        #f0f0f0 25%,
        #e0e0e0 50%,
        #f0f0f0 75%
    );
    background-size: 200% 100%;
    animation: shimmer 2s infinite ease-in-out;
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* Skeleton específico para diferentes tipos de imagen */
.gallery-item .lazy-skeleton {
    background: linear-gradient(
        135deg,
        #f0f0f0 0%,
        #e8e8e8 25%,
        #f0f0f0 50%,
        #e8e8e8 75%,
        #f0f0f0 100%
    );
    background-size: 400% 400%;
    animation: galleryShimmer 3s infinite ease-in-out;
}

@keyframes galleryShimmer {
    0%, 100% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
}

/* Skeleton para product cards */
.product-card .lazy-skeleton {
    background: linear-gradient(
        45deg,
        #f8f9fa 0%,
        #e9ecef 25%,
        #f8f9fa 50%,
        #e9ecef 75%,
        #f8f9fa 100%
    );
    background-size: 300% 300%;
    animation: productShimmer 2.5s infinite ease-in-out;
}

@keyframes productShimmer {
    0%, 100% {
        background-position: 0% 0%;
    }
    50% {
        background-position: 100% 100%;
    }
}

/* Estado de error */
.lazy-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 20px;
    text-align: center;
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
    color: #6c757d;
    border: 2px dashed #dee2e6;
    border-radius: 8px;
}

.lazy-error-state {
    background: #f8f9fa;
    border: 1px solid #dee2e6;
}

.error-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
    opacity: 0.6;
}

.error-text {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 15px;
    color: #495057;
}

.retry-btn {
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.retry-btn:hover {
    background: #b8956a;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Placeholders específicos por sección */

/* Hero section placeholder */
.hero .lazy-placeholder {
    background: linear-gradient(
        135deg,
        rgba(34, 34, 34, 0.1) 0%,
        rgba(68, 68, 68, 0.1) 100%
    );
    min-height: 400px;
}

.hero .lazy-skeleton {
    background: linear-gradient(
        45deg,
        rgba(255,255,255,0.1) 0%,
        rgba(255,255,255,0.3) 50%,
        rgba(255,255,255,0.1) 100%
    );
    background-size: 200% 200%;
    animation: heroShimmer 4s infinite ease-in-out;
}

@keyframes heroShimmer {
    0%, 100% {
        background-position: 0% 50%;
    }
    50% {
        background-position: 100% 50%;
    }
}

/* Gallery placeholders mejorados */
.gallery-item {
    position: relative;
    overflow: hidden;
}

.gallery-item .lazy-placeholder {
    background: #f8f9fa;
    border-radius: 8px;
    box-shadow: inset 0 0 20px rgba(0,0,0,0.05);
}

.gallery-item .lazy-skeleton::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(201, 168, 106, 0.2);
    animation: pulse 2s infinite ease-in-out;
}

.gallery-item .lazy-skeleton::after {
    content: '🖼️';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 20px;
    opacity: 0.5;
    animation: float 3s infinite ease-in-out;
}

@keyframes pulse {
    0%, 100% {
        transform: translate(-50%, -50%) scale(1);
        opacity: 0.3;
    }
    50% {
        transform: translate(-50%, -50%) scale(1.2);
        opacity: 0.1;
    }
}

@keyframes float {
    0%, 100% {
        transform: translate(-50%, -50%) translateY(0px);
    }
    50% {
        transform: translate(-50%, -50%) translateY(-5px);
    }
}

/* Product card placeholders */
.product-card .lazy-placeholder {
    background: #ffffff;
    border: 1px solid #e9ecef;
    border-radius: 8px 8px 0 0;
}

.product-card .lazy-skeleton {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: rgba(201, 168, 106, 0.3);
}

.product-card .lazy-skeleton::before {
    content: '📦';
    animation: bounce 2s infinite ease-in-out;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-10px);
    }
    60% {
        transform: translateY(-5px);
    }
}

/* Feature cards placeholders */
.feature-card .lazy-placeholder {
    background: linear-gradient(
        to bottom,
        #f8f9fa 0%,
        #e9ecef 50%,
        #f8f9fa 100%
    );
}

.feature-card .lazy-skeleton {
    position: relative;
}

.feature-card .lazy-skeleton::before {
    content: '';
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    height: 60%;
    background: rgba(255,255,255,0.5);
    border-radius: 4px;
    animation: slideDown 2s infinite ease-in-out;
}

.feature-card .lazy-skeleton::after {
    content: '';
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 60%;
    height: 20px;
    background: rgba(255,255,255,0.3);
    border-radius: 2px;
    animation: slideRight 2s infinite ease-in-out 0.5s;
}

@keyframes slideDown {
    0%, 100% {
        opacity: 0.3;
        transform: translateY(-10px);
    }
    50% {
        opacity: 0.7;
        transform: translateY(0);
    }
}

@keyframes slideRight {
    0%, 100% {
        opacity: 0.3;
        transform: translateX(-10px);
    }
    50% {
        opacity: 0.7;
        transform: translateX(0);
    }
}

/* Estados de carga progresiva */
.lazy-image[data-lazy-status="loading"] {
    opacity: 0.6;
}

.lazy-image[data-lazy-status="loaded"] {
    opacity: 1;
}

.lazy-image[data-lazy-status="error"] {
    opacity: 0.3;
}

/* Efectos hover mejorados para imágenes cargadas */
.lazy-image.lazy-loaded:hover {
    transform: scale(1.05);
    transition: transform 0.3s ease;
}

.gallery-item .lazy-image.lazy-loaded:hover {
    transform: scale(1.1);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .lazy-placeholder {
        border-radius: 6px;
    }
    
    .error-icon {
        font-size: 2rem;
    }
    
    .error-text {
        font-size: 0.8rem;
    }
    
    .retry-btn {
        padding: 6px 12px;
        font-size: 0.7rem;
    }
    
    .lazy-skeleton::before,
    .lazy-skeleton::after {
        animation-duration: 1.5s;
    }
}

@media (max-width: 576px) {
    .lazy-placeholder {
        border-radius: 4px;
    }
    
    .gallery-item .lazy-skeleton::before {
        width: 30px;
        height: 30px;
    }
    
    .gallery-item .lazy-skeleton::after {
        font-size: 16px;
    }
    
    .error-icon {
        font-size: 1.5rem;
        margin-bottom: 8px;
    }
    
    .error-text {
        font-size: 0.75rem;
        margin-bottom: 10px;
    }
}

/* Optimizaciones de rendimiento */
.lazy-image,
.lazy-placeholder,
.lazy-skeleton {
    will-change: opacity, transform;
    backface-visibility: hidden;
    perspective: 1000px;
}

/* Mejoras de accesibilidad */
@media (prefers-reduced-motion: reduce) {
    .lazy-image,
    .lazy-skeleton,
    .lazy-skeleton::before,
    .lazy-skeleton::after,
    .retry-btn {
        animation: none !important;
        transition: none !important;
    }
    
    .lazy-skeleton {
        background: #f0f0f0 !important;
    }
}

/* Dark mode support (opcional) */
@media (prefers-color-scheme: dark) {
    .lazy-placeholder {
        background-color: #2d3238;
    }
    
    .lazy-skeleton {
        background: linear-gradient(
            90deg,
            #2d3238 25%,
            #3a4047 50%,
            #2d3238 75%
        );
    }
    
    .lazy-error {
        background: linear-gradient(135deg, #2d3238 0%, #3a4047 100%);
        color: #adb5bd;
        border-color: #495057;
    }
    
    .error-text {
        color: #ced4da;
    }
}

/* Indicador de progreso de carga (opcional) */
.lazy-loading-progress {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 2px;
    background: linear-gradient(
        90deg,
        var(--accent-color) 0%,
        transparent 100%
    );
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 9999;
}

.lazy-loading-progress.active {
    transform: translateX(0);
    animation: loadingProgress 2s ease-out;
}

@keyframes loadingProgress {
    0% {
        transform: translateX(-100%);
    }
    50% {
        transform: translateX(-20%);
    }
    100% {
        transform: translateX(0);
    }
}