/* ============================================
   Lazy Loading Styles for SishangWeb
   Handles image loading states and animations
   ============================================ */

/* ============================================
   Base Image States
   ============================================ */

/* Initial state - image not yet loaded */
img[data-src],
img.lazyload {
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
    background-color: #f6f6f6;
}

/* Loading state - while image is being fetched */
img.lazy-loading {
    opacity: 0;
    background: #f6f6f6 url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNDQiIGhlaWdodD0iNDQiIHZpZXdCb3g9IjAgMCA0NCA0NCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiBzdHJva2U9IiNjY2MiPjxnIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCIgc3Ryb2tlLXdpZHRoPSIyIj48Y2lyY2xlIGN4PSIyMiIgY3k9IjIyIiByPSIxIj48YW5pbWF0ZSBhdHRyaWJ1dGVOYW1lPSJyIiBiZWdpbj0iMHMiIGR1cj0iMS44cyIgdmFsdWVzPSIxOyAyMCIgY2FsY01vZGU9InNwbGluZSIga2V5VGltZXM9IjA7IDEiIGtleVNwbGluZXM9IjAuMTY1LCAwLjg0LCAwLjQ0LCAxIiByZXBlYXRDb3VudD0iaW5kZWZpbml0ZSIgLz48YW5pbWF0ZSBhdHRyaWJ1dGVOYW1lPSJzdHJva2Utb3BhY2l0eSIgYmVnaW49IjBzIiBkdXI9IjEuOHMiIHZhbHVlcz0iMTsgMCIgY2FsY01vZGU9InNwbGluZSIga2V5VGltZXM9IjA7IDEiIGtleVNwbGluZXM9IjAuMywgMC42MSwgMC4zNTUsIDEiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiAvPjwvY2lyY2xlPjxjaXJjbGUgY3g9IjIyIiBjeT0iMjIiIHI9IjEiPjxhbmltYXRlIGF0dHJpYnV0ZU5hbWU9InIiIGJlZ2luPSItMC45cyIgZHVyPSIxLjhzIiB2YWx1ZXM9IjE7IDIwIiBjYWxjTW9kZT0ic3BsaW5lIiBrZXlUaW1lcz0iMDsgMSIga2V5U3BsaW5lcz0iMC4xNjUsIDAuODQsIDAuNDQsIDEiIHJlcGVhdENvdW50PSJpbmRlZmluaXRlIiAvPjxhbmltYXRlIGF0dHJpYnV0ZU5hbWU9InN0cm9rZS1vcGFjaXR5IiBiZWdpbj0iLTAuOXMiIGR1cj0iMS44cyIgdmFsdWVzPSIxOyAwIiBjYWxjTW9kZT0ic3BsaW5lIiBrZXlUaW1lcz0iMDsgMSIga2V5U3BsaW5lcz0iMC4zLCAwLjYxLCAwLjM1NSwgMSIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIC8+PC9jaXJjbGU+PC9nPjwvc3ZnPg==') center center no-repeat;
    background-size: 44px 44px;
}

/* Loaded state - image has loaded successfully */
img.lazy-loaded {
    opacity: 1;
    background: transparent;
}

/* Error state - image failed to load */
img.lazy-error {
    opacity: 0.5;
    background: #f9f9f9 url('data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHZpZXdCb3g9IjAgMCA2NCA2NCIgeG1zbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cGF0aCBkPSJNMzIgNEMyMC45NTQgNCAxMiAxMi45NTQgMTIgMjRzOC45NTQgMjAgMjAgMjAgMjAtOC45NTQgMjAtMjBTNDMuMDQ2IDQgMzIgNHptMCAzNmMtOC44MzcgMC0xNi03LjE2My0xNi0xNnM3LjE2My0xNiAxNi0xNiAxNiA3LjE2MyAxNiAxNi03LjE2MyAxNi0xNiAxNnptLTItMjRoNHY4aC00di04em0wIDEyaDR2NGgtNHYtNHoiIGZpbGw9IiNjY2MiLz48L3N2Zz4=') center center no-repeat;
    background-size: 64px 64px;
}

/* ============================================
   No-script Fallback
   ============================================ */

.no-js img.lazyload {
    display: none;
}

.no-js img.lazyload + noscript img {
    display: block;
}

/* ============================================
   Blur-up Progressive Loading
   ============================================ */

img.lazyload.blur-up {
    filter: blur(5px);
    transition: filter 0.4s, opacity 0.4s;
}

img.lazyload.blur-up.lazy-loaded {
    filter: blur(0);
}

/* ============================================
   Skeleton Loading Placeholders
   ============================================ */

/* Base skeleton animation */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* Product Grid Skeleton */
.skeleton-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
    padding: 20px 0;
}

@media (max-width: 768px) {
    .skeleton-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 10px;
    }
}

/* Product Card Skeleton */
.skeleton-product {
    background: #fff;
    border: 1px solid #e5e5e5;
    border-radius: 4px;
    padding: 15px;
}

.skeleton-product-image {
    width: 100%;
    height: 250px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
    margin-bottom: 10px;
}

.skeleton-product-title {
    width: 100%;
    height: 20px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
    margin-bottom: 8px;
}

.skeleton-product-subtitle {
    width: 80%;
    height: 16px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
    margin-bottom: 8px;
}

.skeleton-product-price {
    width: 60%;
    height: 24px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
    margin-bottom: 10px;
}

.skeleton-product-button {
    width: 100%;
    height: 40px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 4px;
}

/* ============================================
   Loading Spinners
   ============================================ */

.loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #c90000;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-spinner.small {
    width: 20px;
    height: 20px;
    border-width: 2px;
}

.loading-spinner.large {
    width: 60px;
    height: 60px;
    border-width: 6px;
}

/* Loading Container */
.loading-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    padding: 20px;
}

.loading-container.full-screen {
    min-height: 100vh;
}

/* ============================================
   Loading Dots Animation
   ============================================ */

.loading-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: #c90000;
    border-radius: 50%;
    animation: loading-dots 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes loading-dots {
    0%, 80%, 100% {
        transform: scale(0);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================
   Fade-in Animation
   ============================================ */

.fade-in {
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   Shimmer Effect (Alternative)
   ============================================ */

.shimmer {
    background: linear-gradient(
        90deg,
        #f0f0f0 0%,
        #f8f8f8 20%,
        #f0f0f0 40%,
        #f0f0f0 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s linear infinite;
}

@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* ============================================
   Pulse Animation
   ============================================ */

.pulse {
    animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

/* ============================================
   Infinite Scroll Loading
   ============================================ */

.infinite-scroll-loading {
    text-align: center;
    padding: 20px;
    font-size: 14px;
    color: #999;
}

.infinite-scroll-loading .spinner {
    margin: 0 auto 10px;
}

.infinite-scroll-last {
    text-align: center;
    padding: 20px;
    color: #999;
    font-size: 14px;
    border-top: 1px solid #e5e5e5;
}

/* ============================================
   Image Container Helpers
   ============================================ */

.lazy-image-container {
    position: relative;
    overflow: hidden;
    background: #f6f6f6;
}

.lazy-image-container img {
    display: block;
    width: 100%;
    height: auto;
}

/* ============================================
   Product Grid Lazy Loading Integration
   ============================================ */

/* For .item class used in product grids */
.item img.lazyload {
    width: 100%;
    height: auto;
    display: block;
}

 .image_info {
    position: relative;
    overflow: hidden;
    background: #f6f6f6;
}

.item .image_info img.lazy-loading {
    min-height: 200px;
}

/* ============================================
   Responsive Adjustments
   ============================================ */

@media (max-width: 768px) {
    .skeleton-product-image {
        height: 180px;
    }
    
    .loading-container {
        min-height: 150px;
    }
    
    .item .image_info img.lazy-loading {
        min-height: 150px;
    }
}

@media (max-width: 480px) {
    .skeleton-product-image {
        height: 150px;
    }
    
    .skeleton-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }
    
    .item .image_info img.lazy-loading {
        min-height: 120px;
    }
}

/* ============================================
   Accessibility - Reduced Motion
   ============================================ */

@media (prefers-reduced-motion: reduce) {
    img[data-src],
    img.lazyload,
    img.lazy-loading,
    img.lazy-loaded,
    .fade-in,
    .skeleton,
    .shimmer,
    .loading-spinner,
    .loading-dots span,
    .pulse {
        animation: none !important;
        transition: none !important;
    }
    
    img.lazyload.blur-up {
        filter: none !important;
    }
    
    img.lazyload,
    img.lazy-loading {
        opacity: 1;
    }
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .skeleton,
    .skeleton-product,
    .loading-spinner,
    .loading-container,
    .infinite-scroll-loading {
        display: none !important;
    }
    
    img.lazyload,
    img.lazy-loading {
        opacity: 1 !important;
        background: none !important;
    }
}