/* 
 * 画像最適化用スタイル
 * ファイル: wwwroot/css/image-optimization.css
 * 目的: パフォーマンス向上と表示品質改善
 */

/* ===== CSS変数定義 ===== */
:root {
    --image-transition-duration: 0.3s;
    --image-border-radius: 0.5rem;
    --image-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    --image-placeholder-bg: #f8f9fa;
    --image-error-bg: #f8d7da;
    --image-error-border: #f5c6cb;
    --image-margin: 1.5rem 0;
}

/* ===== 基本的な画像最適化 ===== */
.img-fluid {
    height: auto;
    max-width: 100%;
    object-fit: cover;
}

/* ===== レスポンシブ画像対応 ===== */
picture {
    display: block;
    width: 100%;
}

picture img {
    width: 100%;
    height: auto;
    display: block;
}

/* ===== 遅延読み込み対応 ===== */

/* loading="lazy" 属性用のスタイル */
img[loading="lazy"] {
    opacity: 0;
    transition: opacity var(--image-transition-duration) ease;
}

img[loading="lazy"].loaded,
img[loading="lazy"]:not([loading]) {
    opacity: 1;
}

/* data-src 属性を持つ画像の初期状態 */
img[data-src] {
    opacity: 0;
    transition: opacity var(--image-transition-duration) ease;
    background-color: var(--image-placeholder-bg);
    min-height: 50px;
    display: block;
}

/* 読み込み完了状態 */
img[data-src].loaded {
    opacity: 1;
}

/* フェードイン効果 */
img[data-src].fade-in {
    opacity: 1;
}

/* エラー状態 */
img[data-src].load-error {
    opacity: 0.6;
    background-color: var(--image-error-bg);
    border: 1px solid var(--image-error-border);
    position: relative;
}

/* エラー時のアイコン表示 */
img[data-src].load-error::after {
    content: "🖼️";
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 2rem;
    opacity: 0.7;
}

/* ===== プレースホルダー効果 ===== */
.image-placeholder {
    background: 
        linear-gradient(90deg, #f0f0f0 25%, transparent 25%), 
        linear-gradient(#f0f0f0 50%, transparent 50%);
    background-size: 20px 20px;
    animation: placeholder-shimmer 1.5s infinite;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #999;
    font-size: 0.9rem;
    border-radius: var(--image-border-radius);
}

@keyframes placeholder-shimmer {
    0% { 
        background-position: 0 0, 0 0; 
    }
    100% { 
        background-position: 20px 20px, 20px 20px; 
    }
}

/* ===== 記事内画像の調整 ===== */
.post-content img,
.post-content picture,
.articlepage-body img,
.articlepage-body picture {
    margin: var(--image-margin);
    border-radius: var(--image-border-radius);
    box-shadow: var(--image-shadow);
    max-width: 100%;
    height: auto;
}

.post-content figure,
.articlepage-body figure {
    margin: 2rem 0;
    text-align: center;
}

.post-content figcaption,
.articlepage-body figcaption {
    margin-top: 0.5rem;
    font-size: 0.9rem;
    color: #6c757d;
    font-style: italic;
    text-align: center;
}

/* ===== アクセシビリティ改善 ===== */

/* 動きの削減設定時 */
@media (prefers-reduced-motion: reduce) {
    img[loading="lazy"],
    img[data-src] {
        transition: none;
    }
    
    .image-placeholder {
        animation: none;
        background: var(--image-placeholder-bg);
    }
}

/* ハイコントラストモード対応 */
@media (prefers-contrast: high) {
    img[data-src].load-error {
        border-width: 2px;
        border-style: solid;
    }
}

/* ===== ブラウザ最適化 ===== */

/* WebP対応ブラウザでの最適化 */
@supports (background-image: url('data:image/webp;base64,')) {
    .webp-supported picture source[type="image/webp"] {
        display: block;
    }
}

/* ===== 印刷時の最適化 ===== */
@media print {
    picture {
        break-inside: avoid;
        page-break-inside: avoid;
    }
    
    img {
        max-width: 100% !important;
        height: auto !important;
        opacity: 1 !important;
        box-shadow: none !important;
    }
    
    .image-placeholder {
        display: none;
    }
}

/* ===== 記事ヘッダーのスタイル ===== */
.article-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #e9ecef;
}

.article-header h1 {
    margin-bottom: 0.5rem;
    color: #212529;
}

.article-date {
    color: #6c757d;
    font-size: 0.9rem;
    display: block;
}
