/**
 * 图片懒加载样式
 * 包含加载动画、骨架屏和占位符效果
 */

/* 图片容器基础样式 */
img[data-src] {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    min-height: 200px;
    display: block;
}

/* 加载中状态 */
img.lazy-loading {
    animation: shimmer 1.5s infinite;
    filter: blur(5px);
    opacity: 0.6;
}

/* 加载完成状态 */
img.lazy-loaded {
    animation: fadeIn 0.4s ease-in;
    filter: none;
    opacity: 1;
}

/* 加载失败状态 */
img.lazy-error {
    background: #f5f5f5;
    opacity: 0.5;
}

/* 骨架屏动画 */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

/* 淡入动画 */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* 素材卡片骨架屏 */
.material-card.skeleton {
    pointer-events: none;
}

.material-card.skeleton .material-thumbnail {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    min-height: 200px;
}

.material-card.skeleton .material-title {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    height: 20px;
    border-radius: 4px;
    color: transparent;
}

/* 加载指示器 */
.loading-spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 占位符容器 */
.image-placeholder {
    position: relative;
    overflow: hidden;
    background: #f5f5f5;
}

.image-placeholder::before {
    content: '';
    display: block;
    padding-top: 75%;
}

.image-placeholder img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* 渐进式加载效果 */
.progressive-image {
    position: relative;
    overflow: hidden;
}

.progressive-image-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    filter: blur(20px);
    transform: scale(1.1);
    transition: opacity 0.3s ease;
}

.progressive-image-main {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.progressive-image-main.loaded {
    opacity: 1;
}

.progressive-image-main.loaded + .progressive-image-placeholder {
    opacity: 0;
}

/* 网格骨架屏 */
.material-grid.loading {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
}

.skeleton-card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.skeleton-image {
    width: 100%;
    height: 200px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

.skeleton-content {
    padding: 15px;
}

.skeleton-title {
    height: 20px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
    margin-bottom: 10px;
}

.skeleton-text {
    height: 14px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 4px;
    width: 60%;
}

/* 响应式优化 */
@media (max-width: 768px) {
    img[data-src] {
        min-height: 150px;
    }

    .skeleton-image {
        height: 150px;
    }
}

/* 减少动画以提升性能 */
@media (prefers-reduced-motion: reduce) {
    img.lazy-loading,
    img.lazy-loaded,
    .skeleton-image,
    .skeleton-title,
    .skeleton-text {
        animation: none;
    }

    img.lazy-loaded {
        transition: opacity 0.2s ease;
    }
}
