/**
 * 图片懒加载样式
 * Image Lazy Loading Styles
 */

/* ========================================
   图片包装器
   ======================================== */
.lazy-image-wrapper {
    position: relative;
    display: inline-block;
    width: 100%;
    overflow: hidden;
    background: #f5f5f5;
}

.lazy-image-wrapper.lazy-wrapper-loaded {
    background: transparent;
}

/* ========================================
   骨架屏动画
   ======================================== */
.lazy-image-skeleton {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg,
            #f0f0f0 0%,
            #e0e0e0 20%,
            #f0f0f0 40%,
            #f0f0f0 100%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    z-index: 1;
    transition: opacity 0.3s ease;
}

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

    100% {
        background-position: 200% 0;
    }
}

/* ========================================
   加载指示器
   ======================================== */
.lazy-image-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    transition: opacity 0.3s ease;
}

/* 加载旋转器 */
.loader-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(0, 102, 204, 0.1);
    border-top-color: #0066cc;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* 加载文本 */
.loader-text {
    font-size: 14px;
    color: #666;
    font-weight: 400;
    white-space: nowrap;
}

/* ========================================
   错误状态
   ======================================== */
.loader-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: #999;
}

.loader-error svg {
    width: 48px;
    height: 48px;
    color: #ccc;
}

.loader-error .loader-text {
    color: #999;
    font-size: 13px;
}

/* ========================================
   图片状态
   ======================================== */

/* 加载中的图片 */
.lazy-image.lazy-loading {
    opacity: 0;
    min-height: 200px;
    /* 防止布局抖动 */
}

/* 加载完成的图片 */
.lazy-image.lazy-loaded {
    opacity: 1;
    position: relative;
    z-index: 3;
}

/* 淡入动画 */
.lazy-image.lazy-fade-in {
    animation: fadeIn 0.6s ease-out forwards;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* 加载失败的图片 */
.lazy-image.lazy-error {
    opacity: 0.3;
    filter: grayscale(100%);
}

/* ========================================
   响应式优化
   ======================================== */

/* 确保图片保持宽高比 */
.lazy-image-wrapper img {
    display: block;
    width: 100%;
    height: auto;
}

/* 圆形图片支持 */
.lazy-image-wrapper.lazy-circle {
    border-radius: 50%;
    overflow: hidden;
}

.lazy-image-wrapper.lazy-circle img {
    border-radius: 50%;
}

/* 圆角图片支持 */
.lazy-image-wrapper.lazy-rounded {
    border-radius: 8px;
    overflow: hidden;
}

.lazy-image-wrapper.lazy-rounded img {
    border-radius: 8px;
}

/* ========================================
   特殊场景优化
   ======================================== */

/* Hero 大图优化 */
.hero-section .lazy-image-wrapper {
    min-height: 400px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.hero-section .lazy-image-skeleton {
    background: linear-gradient(90deg,
            rgba(255, 255, 255, 0.1) 0%,
            rgba(255, 255, 255, 0.2) 20%,
            rgba(255, 255, 255, 0.1) 40%,
            rgba(255, 255, 255, 0.1) 100%);
}

/* 产品图片优化 */
.product-card .lazy-image-wrapper {
    aspect-ratio: 4 / 3;
    background: #fafafa;
}

.product-card .lazy-image-wrapper img {
    height: 100%;
    object-fit: cover;
    object-position: top;
}

/* 新闻卡片图片优化 */
.news-card .lazy-image-wrapper {
    aspect-ratio: 16 / 9;
    background: #f8f9fa;
}

/* Logo 图片优化 */
.logo.lazy-image {
    min-height: auto;
}

.logo.lazy-image-wrapper {
    background: transparent;
}

/* ========================================
   移动端优化
   ======================================== */
@media (max-width: 767px) {
    .lazy-image-skeleton {
        animation-duration: 1.2s;
        /* 移动端稍快的动画 */
    }

    .loader-spinner {
        width: 32px;
        height: 32px;
        border-width: 2px;
    }

    .loader-text {
        font-size: 12px;
    }

    .hero-section .lazy-image-wrapper {
        min-height: 250px;
    }

    .lazy-image.lazy-loading {
        min-height: 150px;
    }
}

/* ========================================
   性能优化
   ======================================== */

/* 使用 GPU 加速 */
.lazy-image-skeleton,
.lazy-image-loader,
.lazy-image.lazy-fade-in {
    will-change: transform, opacity;
}

/* 减少重绘 */
.lazy-image-wrapper {
    contain: layout style paint;
}

/* ========================================
   无障碍支持
   ======================================== */

/* 减少动画(尊重用户偏好) */
@media (prefers-reduced-motion: reduce) {
    .lazy-image-skeleton {
        animation: none;
        background: #f0f0f0;
    }

    .loader-spinner {
        animation: none;
        border-top-color: #0066cc;
        opacity: 0.5;
    }

    .lazy-image.lazy-fade-in {
        animation: none;
        opacity: 1;
        transform: none;
    }
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
    .lazy-image-skeleton {
        background: #e0e0e0;
    }

    .loader-text {
        color: #000;
        font-weight: 500;
    }
}

/* ========================================
   打印样式
   ======================================== */
@media print {

    .lazy-image-skeleton,
    .lazy-image-loader {
        display: none !important;
    }

    .lazy-image {
        opacity: 1 !important;
    }
}

/* ========================================
   深色模式支持
   ======================================== */
@media (prefers-color-scheme: dark) {
    .lazy-image-wrapper {
        background: #2a2a2a;
    }

    .lazy-image-skeleton {
        background: linear-gradient(90deg,
                #2a2a2a 0%,
                #3a3a3a 20%,
                #2a2a2a 40%,
                #2a2a2a 100%);
    }

    .loader-text {
        color: #aaa;
    }

    .loader-error {
        color: #888;
    }

    .loader-error svg {
        color: #666;
    }
}