/**
 * 图片懒加载样式
 * 配合 image-lazy-loader.js 使用
 */

/* 懒加载图片基础样式 */
img[data-lazy-processed] {
    transition: opacity 0.3s ease-in-out, transform 0.3s ease-in-out;
    will-change: opacity, transform;
}

/* 排除的图片不应用懒加载样式 */
.social-icon img,
.qr-popup img,
.brand-logo,
.nav-brand img,
.banner-dots img,
.carousel-btn img {
    transition: none !important;
    will-change: auto !important;
    opacity: 1 !important;
    transform: none !important;
    background: none !important;
    animation: none !important;
}

/* 音乐图标特殊处理 - 保持旋转动画 */
.music-icon {
    will-change: auto !important;
    opacity: 1 !important;
    background: none !important;
    /* 保持原有的transition，不覆盖transform和animation */
}

.music-icon.rotating {
    animation: rotate 2s linear infinite !important;
}

@keyframes rotate {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* 加载中状态 */
img.lazy-loading {
    opacity: 0.7;
    background-color: #f5f5f5;
    background-image: linear-gradient(90deg, #f5f5f5 25%, #e0e0e0 50%, #f5f5f5 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

/* 加载完成状态 */
img.lazy-loaded {
    opacity: 1;
    transform: scale(1);
}

/* 加载失败状态 */
img[data-error="true"] {
    opacity: 0.6;
    filter: grayscale(100%);
    background-color: #f0f0f0;
}

/* 闪烁动画 */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* 淡入动画 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 高质量图片淡入效果 */
img[data-quality="high-quality"] {
    animation: fadeIn 0.4s ease-out;
}

/* 低质量图片样式 */
img[data-quality="low-quality"] {
    filter: blur(1px);
    opacity: 0.8;
}

/* 占位符样式 */
.image-placeholder {
    background-color: #f0f0f0;
    background-image: 
        linear-gradient(45deg, #e0e0e0 25%, transparent 25%), 
        linear-gradient(-45deg, #e0e0e0 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #e0e0e0 75%), 
        linear-gradient(-45deg, transparent 75%, #e0e0e0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 14px;
    min-height: 100px;
}

/* 响应式图片优化 */
@media (max-width: 768px) {
    img.lazy-loading {
        animation-duration: 1s; /* 移动端加快动画 */
    }
    
    img[data-lazy-processed] {
        transition-duration: 0.2s; /* 移动端加快过渡 */
    }
}

/* 减少动画的用户偏好 */
@media (prefers-reduced-motion: reduce) {
    img[data-lazy-processed] {
        transition: none;
        animation: none;
    }
    
    img.lazy-loading {
        animation: none;
        background-image: none;
        opacity: 0.8;
    }
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
    img.lazy-loading {
        background-color: #000;
        color: #fff;
    }
    
    .image-placeholder {
        background-color: #000;
        color: #fff;
        border: 2px solid #fff;
    }
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
    img.lazy-loading {
        background-color: #2a2a2a;
        background-image: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
    }
    
    .image-placeholder {
        background-color: #2a2a2a;
        background-image: 
            linear-gradient(45deg, #3a3a3a 25%, transparent 25%), 
            linear-gradient(-45deg, #3a3a3a 25%, transparent 25%), 
            linear-gradient(45deg, transparent 75%, #3a3a3a 75%), 
            linear-gradient(-45deg, transparent 75%, #3a3a3a 75%);
        color: #ccc;
    }
    
    img[data-error="true"] {
        background-color: #2a2a2a;
    }
}

/* 打印样式 */
@media print {
    img.lazy-loading,
    img[data-lazy-processed] {
        opacity: 1 !important;
        background: none !important;
        animation: none !important;
        transition: none !important;
    }
}

/* 特殊场景样式 */

/* 首屏关键图片 */
img[data-critical="true"],
.critical-image {
    opacity: 1 !important;
    transition: none !important;
    background: none !important;
    animation: none !important;
    will-change: auto !important;
}

/* 关键图片容器样式 */
.critical-image {
    position: relative;
}

.critical-image::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1s infinite;
    z-index: -1;
}

.critical-image[src]::before {
    display: none;
}

/* 产品图片特殊样式 */
.product-image.lazy-loading {
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.product-image.lazy-loaded {
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* 轮播图片样式 */
.carousel-image.lazy-loading {
    background: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
}

/* 头像图片样式 */
.avatar-image.lazy-loading {
    border-radius: 50%;
    background: radial-gradient(circle, #f5f5f5 0%, #e0e0e0 100%);
}

/* 背景图片懒加载支持 */
.bg-lazy-loading {
    background-image: linear-gradient(135deg, #f5f5f5 0%, #e0e0e0 100%);
    background-size: 200% 200%;
    animation: gradientShift 2s ease-in-out infinite;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

.bg-lazy-loaded {
    animation: none;
}

/* 网格布局中的图片 */
.image-grid img.lazy-loading {
    aspect-ratio: 1;
    object-fit: cover;
}

/* 卡片中的图片 */
.card img.lazy-loading {
    border-radius: inherit;
}

/* 全屏图片 */
.fullscreen-image.lazy-loading {
    background: 
        radial-gradient(circle at 30% 30%, #f0f0f0 0%, transparent 50%),
        radial-gradient(circle at 70% 70%, #e0e0e0 0%, transparent 50%),
        linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
}

/* 加载进度指示器 */
.image-loading-progress {
    position: relative;
    overflow: hidden;
}

.image-loading-progress::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
    animation: progressSweep 1.5s infinite;
}

@keyframes progressSweep {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* 错误状态样式 */
.image-error {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #f8f8f8;
    border: 2px dashed #ddd;
    min-height: 120px;
}

.image-error::before {
    content: '🖼️';
    font-size: 24px;
    margin-bottom: 8px;
}

.image-error::after {
    content: '图片加载失败';
    position: absolute;
    bottom: 10px;
    font-size: 12px;
    color: #999;
}

/* 性能优化 */
img[data-lazy-processed] {
    /* 启用硬件加速 */
    transform: translateZ(0);
    /* 优化重绘 */
    backface-visibility: hidden;
    /* 优化合成 */
    isolation: isolate;
}

/* 辅助功能 */
img[data-lazy-processed][alt=""] {
    /* 对于装饰性图片，确保屏幕阅读器忽略 */
    aria-hidden: true;
}

/* 调试模式（开发时使用） */
.debug-lazy-loading img[data-lazy-processed] {
    border: 2px solid red;
    position: relative;
}

.debug-lazy-loading img[data-lazy-processed]::after {
    content: attr(data-quality);
    position: absolute;
    top: 0;
    left: 0;
    background: rgba(255,0,0,0.8);
    color: white;
    padding: 2px 4px;
    font-size: 10px;
    font-family: monospace;
} 