/* 圖片優化樣式 - 輕量化設計 */

/* ===== 延遲載入動畫 ===== */
img[data-src],
img.loading {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    filter: blur(0.5px);
    transition: filter 0.3s ease;
}

img.loaded {
    filter: none;
    animation: none;
    background: none;
}

img.error {
    background: #f8f9fa url('data:image/svg+xml;charset=utf-8,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23dee2e6"%3E%3Cpath d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-2 15l-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8l-9 9z"/%3E%3C/svg%3E') center/contain no-repeat;
    filter: grayscale(1);
}

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

/* ===== 響應式圖片 ===== */
img {
    max-width: 100%;
    height: auto;
    /* display: block; */
}

/* 圖片容器 */
.image-container {
    position: relative;
    overflow: hidden;
    background: #f8f9fa;
}

.image-container::before {
    content: '';
    display: block;
    padding-top: 56.25%; /* 16:9 比例 */
}

.image-container img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ===== 圖片品質優化 ===== */
/* 高 DPI 螢幕優化 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .hero-image,
    .featured-image {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* ===== 圖片懸停效果 ===== */
.gallery-item img,
.service-image img,
.course-image img {
    transition: transform 0.3s ease, filter 0.3s ease;
}

.gallery-item:hover img,
.service-card:hover .service-image img,
.course-card:hover .course-image img {
    transform: scale(1.05);
    filter: brightness(1.1);
}

/* ===== WebP 支援檢測 ===== */
.no-webp .webp-only {
    display: none;
}

.webp .fallback-only {
    display: none;
}

/* ===== 圖片載入狀態 ===== */
.image-loading-container {
    position: relative;
    background: #f8f9fa;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #e0e0e0;
    border-top: 3px solid var(--primary-color, #d4a574);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== 圖片錯誤處理 ===== */
.image-error {
    background: #f8f9fa;
    color: #6c757d;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 150px;
    font-size: 0.875rem;
    text-align: center;
    border: 1px dashed #dee2e6;
}

.image-error::before {
    content: "🖼️";
    display: block;
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

/* ===== 性能優化 ===== */
/* 預載入關鍵圖片的佔位符 */
.critical-image {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

/* 縮圖優化 */
.thumbnail {
    width: 150px;
    height: 150px;
    object-fit: cover;
    border-radius: 8px;
    background: #f8f9fa;
    transition: all 0.2s ease;
}

.thumbnail:hover {
    transform: scale(1.02);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* ===== 輕量化設計 ===== */
/* 減少重繪和回流 */
.optimized-image {
    will-change: transform;
    backface-visibility: hidden;
    perspective: 1000px;
}

/* 節省帶寬的佔位符 */
.placeholder-image {
    background: linear-gradient(135deg, 
        var(--accent-color, #f4e4c1) 0%, 
        var(--primary-color, #d4a574) 100%);
    position: relative;
}

.placeholder-image::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 48px;
    height: 48px;
    background-image: url('data:image/svg+xml;charset=utf-8,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%23ffffff"%3E%3Cpath d="M21 19V5c0-1.1-.9-2-2-2H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2zM8.5 13.5l2.5 3.01L14.5 12l4.5 6H5l3.5-4.5z"/%3E%3C/svg%3E');
    background-size: contain;
    opacity: 0.5;
}

/* ===== 列印樣式 ===== */
@media print {
    img {
        page-break-inside: avoid;
        max-width: 100% !important;
        height: auto !important;
    }
    
    .image-loading-spinner,
    .shimmer {
        display: none !important;
    }
}

/* ===== 可訪問性 ===== */
@media (prefers-reduced-motion: reduce) {
    img,
    .gallery-item img,
    .service-image img,
    .course-image img,
    .thumbnail {
        transition: none !important;
        animation: none !important;
    }
    
    .image-loading-spinner {
        animation: none;
        border-top-color: transparent;
    }
}

/* ===== 深色模式支援 ===== */
@media (prefers-color-scheme: dark) {
    img.loading,
    img[data-src] {
        background: linear-gradient(90deg, #2a2a2a 25%, #3a3a3a 50%, #2a2a2a 75%);
    }
    
    .image-container,
    .critical-image {
        background: #2a2a2a;
    }
    
    .image-error {
        background: #2a2a2a;
        color: #a0a0a0;
        border-color: #4a4a4a;
    }
}
