/**
 * Custom Instagram Feed - Default Styles (レスポンシブ対応完全版)
 * 各サイトでカスタマイズ可能な基本スタイル
 */

/* メインコンテナ */
.custom-instagram-feed {
    max-width: 100%;
    margin: 0 auto;
    padding: 0;
    position: relative;
}

/* グリッドレイアウト */
.custom-instagram-grid {
    display: grid;
    gap: 10px;
    list-style: none;
    padding: 0;
    margin: 0;
}

/* デフォルトグリッド（管理画面でレスポンシブが無効の場合） */
.custom-instagram-grid:not(.desktop-grid):not(.mobile-grid) {
    grid-template-columns: repeat(3, 1fr);
}

/* デスクトップグリッド */
.custom-instagram-grid.desktop-grid {
    display: grid;
}

/* モバイルグリッド */
.custom-instagram-grid.mobile-grid {
    display: none;
}

/* 個別アイテム */
.custom-instagram-item {
    position: relative;
    overflow: hidden;
    border-radius: 8px;
    background-color: #f9f9f9;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    aspect-ratio: 4 / 5;
    /* Instagramのデフォルト縦長比率 */
}

.custom-instagram-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* 画像 */
.custom-instagram-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: opacity 0.3s ease, filter 0.3s ease;
    background-color: #f0f0f0;
}

.custom-instagram-item:hover img {
    opacity: 0.95;
}

/* Lazy Loading 用プレースホルダー */
.custom-instagram-item img.lazy-load {
    filter: blur(5px);
    transition: filter 0.3s ease;
}

.custom-instagram-item img.lazy-load.loaded {
    filter: none;
}

/* WebP対応画像の特別処理 */
.custom-instagram-item img.webp-available {
    background-color: #f8f9fa;
}

.custom-instagram-item img.webp-loaded::after {
    content: 'WebP';
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: rgba(0, 150, 0, 0.8);
    color: white;
    font-size: 8px;
    padding: 1px 4px;
    border-radius: 2px;
    font-weight: bold;
    z-index: 1;
}

/* メディアタイプインジケーター */
.custom-instagram-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.75);
    color: white;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    backdrop-filter: blur(4px);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    z-index: 2;
}

.video-indicator {
    background: rgba(255, 59, 92, 0.9);
}

.carousel-indicator {
    background: rgba(0, 149, 246, 0.9);
}

/* キャプション */
.instagram-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px;
    font-size: 12px;
    line-height: 1.4;
    color: white;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
    transform: translateY(100%);
    transition: transform 0.3s ease;
    backdrop-filter: blur(4px);
}

.custom-instagram-item:hover .instagram-caption {
    transform: translateY(0);
}

/* 投稿日時 */
.instagram-date {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(255, 255, 255, 0.9);
    color: #333;
    padding: 2px 6px;
    font-size: 10px;
    border-radius: 8px;
    font-weight: 500;
    z-index: 2;
}

/* リンク */
.custom-instagram-item a {
    display: block;
    text-decoration: none;
    color: inherit;
    width: 100%;
    height: 100%;
    position: relative;
}

.custom-instagram-item a:hover {
    text-decoration: none;
}

.custom-instagram-item a:focus {
    outline: 2px solid #0073aa;
    outline-offset: 2px;
}

/* エラー・ローディング表示 */
.custom-instagram-error,
.custom-instagram-loading {
    text-align: center;
    padding: 40px 20px;
    border-radius: 8px;
    font-size: 14px;
    margin: 20px 0;
}

.custom-instagram-error {
    color: #e74c3c;
    background: #fdf2f2;
    border: 1px solid #fecaca;
}

.custom-instagram-loading {
    color: #666;
    background: #f8f9fa;
    border: 1px solid #e9ecef;
}

.custom-instagram-loading:before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #ddd;
    border-top: 2px solid #007cba;
    border-radius: 50%;
    animation: cif-spin 1s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes cif-spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* 画像なし表示 */
.instagram-no-image {
    background: #f0f0f0;
    padding: 20px;
    text-align: center;
    color: #666;
    font-size: 14px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.instagram-image-placeholder {
    background: #f0f0f0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    color: #666;
    font-size: 14px;
    width: 100%;
    height: 100%;
}

/* レスポンシブ対応 */
@media (max-width: 768px) {

    /* レスポンシブグリッドの切り替え */
    .custom-instagram-grid.desktop-grid {
        display: none !important;
    }

    .custom-instagram-grid.mobile-grid {
        display: grid !important;
    }

    /* 従来のグリッド（レスポンシブ無効時） */
    .custom-instagram-grid:not(.desktop-grid):not(.mobile-grid) {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px;
    }

    .custom-instagram-indicator {
        font-size: 10px;
        padding: 3px 6px;
        top: 6px;
        right: 6px;
    }

    .instagram-caption {
        padding: 8px;
        font-size: 11px;
    }

    .instagram-date {
        font-size: 9px;
        padding: 1px 4px;
    }
}

@media (max-width: 480px) {

    /* 従来のグリッド（レスポンシブ無効時） */
    .custom-instagram-grid:not(.desktop-grid):not(.mobile-grid) {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .custom-instagram-item {
        border-radius: 6px;
    }

    .custom-instagram-error,
    .custom-instagram-loading {
        padding: 30px 15px;
    }
}

/* タブレット対応 */
@media (min-width: 769px) and (max-width: 1024px) {
    .custom-instagram-grid:not(.desktop-grid):not(.mobile-grid) {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }
}

/* 大画面対応 */
@media (min-width: 1200px) {
    .custom-instagram-grid:not(.desktop-grid):not(.mobile-grid) {
        gap: 15px;
    }
}

/* 高解像度ディスプレイ対応 */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {
    .custom-instagram-item img {
        image-rendering: -webkit-optimize-contrast;
    }
}

/* アクセシビリティ */
@media (prefers-reduced-motion: reduce) {

    .custom-instagram-item,
    .custom-instagram-item img,
    .custom-instagram-indicator,
    .instagram-caption {
        transition: none;
    }

    @keyframes cif-spin {

        0%,
        100% {
            transform: rotate(0deg);
        }
    }
}

/* ダークモード対応 */
@media (prefers-color-scheme: dark) {
    .custom-instagram-item {
        background-color: #2a2a2a;
    }

    .instagram-caption {
        background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
    }

    .instagram-date {
        background: rgba(40, 40, 40, 0.9);
        color: #e1e1e1;
    }

    .custom-instagram-loading {
        background: #2a2a2a;
        color: #e1e1e1;
        border-color: #404040;
    }

    .custom-instagram-error {
        background: #2d1b1b;
        color: #ffaaaa;
        border-color: #5a2d2d;
    }
}

/* カスタマイズ用のユーティリティクラス */
.cif-rounded {
    border-radius: 12px;
}

.cif-rounded .custom-instagram-item {
    border-radius: 12px;
}

.cif-square {
    border-radius: 0;
}

.cif-square .custom-instagram-item {
    border-radius: 0;
}

.cif-shadow-light .custom-instagram-item {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.cif-shadow-heavy .custom-instagram-item {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.cif-no-hover .custom-instagram-item {
    transition: none;
}

.cif-no-hover .custom-instagram-item:hover {
    transform: none;
    box-shadow: none;
}

/* カラム数バリエーション */
.cif-cols-1 .custom-instagram-grid {
    grid-template-columns: 1fr;
}

.cif-cols-2 .custom-instagram-grid {
    grid-template-columns: repeat(2, 1fr);
}

.cif-cols-3 .custom-instagram-grid {
    grid-template-columns: repeat(3, 1fr);
}

.cif-cols-4 .custom-instagram-grid {
    grid-template-columns: repeat(4, 1fr);
}

.cif-cols-5 .custom-instagram-grid {
    grid-template-columns: repeat(5, 1fr);
}

.cif-cols-6 .custom-instagram-grid {
    grid-template-columns: repeat(6, 1fr);
}

/* ギャップサイズバリエーション */
.cif-gap-none .custom-instagram-grid {
    gap: 0;
}

.cif-gap-small .custom-instagram-grid {
    gap: 5px;
}

.cif-gap-medium .custom-instagram-grid {
    gap: 15px;
}

.cif-gap-large .custom-instagram-grid {
    gap: 25px;
}

/* キャプション表示スタイル */
.cif-caption-always .instagram-caption {
    position: static;
    transform: none;
    background: white;
    color: #333;
    border-top: 1px solid #e1e1e1;
    padding: 12px;
    font-size: 14px;
}

.cif-caption-overlay .instagram-caption {
    position: absolute;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    transform: none;
}

.cif-caption-hover .instagram-caption {
    opacity: 0;
    visibility: hidden;
}

.cif-caption-hover .custom-instagram-item:hover .instagram-caption {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* フェードイン アニメーション */
@keyframes cif-fade-in {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cif-animate-in .custom-instagram-item {
    animation: cif-fade-in 0.6s ease forwards;
    opacity: 0;
}

.cif-animate-in .custom-instagram-item:nth-child(1) {
    animation-delay: 0.1s;
}

.cif-animate-in .custom-instagram-item:nth-child(2) {
    animation-delay: 0.2s;
}

.cif-animate-in .custom-instagram-item:nth-child(3) {
    animation-delay: 0.3s;
}

.cif-animate-in .custom-instagram-item:nth-child(4) {
    animation-delay: 0.4s;
}

.cif-animate-in .custom-instagram-item:nth-child(5) {
    animation-delay: 0.5s;
}

.cif-animate-in .custom-instagram-item:nth-child(6) {
    animation-delay: 0.6s;
}

.cif-animate-in .custom-instagram-item:nth-child(7) {
    animation-delay: 0.7s;
}

.cif-animate-in .custom-instagram-item:nth-child(8) {
    animation-delay: 0.8s;
}

.cif-animate-in .custom-instagram-item:nth-child(9) {
    animation-delay: 0.9s;
}

.cif-animate-in .custom-instagram-item:nth-child(10) {
    animation-delay: 1.0s;
}

.cif-animate-in .custom-instagram-item:nth-child(11) {
    animation-delay: 1.1s;
}

.cif-animate-in .custom-instagram-item:nth-child(12) {
    animation-delay: 1.2s;
}

/* スライドアップアニメーション */
@keyframes cif-slide-up {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cif-animate-slide .custom-instagram-item {
    animation: cif-slide-up 0.8s ease forwards;
    opacity: 0;
}

/* ズームインアニメーション */
@keyframes cif-zoom-in {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.cif-animate-zoom .custom-instagram-item {
    animation: cif-zoom-in 0.5s ease forwards;
    opacity: 0;
}

/* エラー状態スタイル */
.custom-instagram-item.image-error {
    border: 2px dashed #e74c3c;
    background-color: #fdf2f2;
}

.custom-instagram-item.image-error .instagram-image-placeholder {
    color: #e74c3c;
    font-weight: 500;
}

/* ローディング状態 */
.custom-instagram-item.loading {
    background: linear-gradient(45deg, #f0f0f0 25%, transparent 25%),
        linear-gradient(-45deg, #f0f0f0 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f0f0f0 75%),
        linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    animation: cif-loading-bg 2s linear infinite;
}

@keyframes cif-loading-bg {
    0% {
        background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    }

    100% {
        background-position: 20px 20px, 20px 30px, 30px 10px, 10px 20px;
    }
}

/* 優先読み込み要素 */
.custom-instagram-item.priority-load {
    opacity: 1;
    animation: none;
}

.custom-instagram-item.delayed-load {
    animation: cif-fade-in 0.5s ease forwards;
}

/* ホバー効果のバリエーション */
.cif-hover-lift .custom-instagram-item:hover {
    transform: translateY(-8px) scale(1.02);
}

.cif-hover-glow .custom-instagram-item:hover {
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.6);
}

.cif-hover-rotate .custom-instagram-item:hover {
    transform: rotate(2deg) scale(1.05);
}

/* フォーカス状態の改善 */
.custom-instagram-item a:focus-visible {
    outline: 3px solid #0073aa;
    outline-offset: 3px;
    border-radius: 12px;
}

/* プリント時の最適化 */
@media print {
    .custom-instagram-feed {
        display: block;
    }

    .custom-instagram-grid {
        display: block;
        columns: 2;
        column-gap: 20px;
    }

    .custom-instagram-item {
        break-inside: avoid;
        margin-bottom: 20px;
    }

    .custom-instagram-indicator,
    .instagram-date {
        display: none;
    }
}

/* RTL言語対応 */
[dir="rtl"] .custom-instagram-indicator {
    right: auto;
    left: 8px;
}

[dir="rtl"] .instagram-date {
    left: auto;
    right: 8px;
}

/* カスタムプロパティ（CSS変数）*/
.custom-instagram-feed {
    --cif-border-radius: 2px;
    --cif-gap: 4px;
    --cif-hover-scale: 1.02;
    --cif-transition: 0.3s ease;
    --cif-shadow-light: 0 2px 4px rgba(0, 0, 0, 0.1);
    --cif-shadow-heavy: 0 8px 24px rgba(0, 0, 0, 0.2);
}

.custom-instagram-item {
    border-radius: var(--cif-border-radius);
    transition: transform var(--cif-transition), box-shadow var(--cif-transition);
}

.custom-instagram-grid {
    gap: var(--cif-gap);
}

.custom-instagram-item:hover {
    transform: translateY(-2px) scale(var(--cif-hover-scale));
}