/* Instagram Gallery Plugin - フロントエンドスタイル */

.igp-gallery {
    margin: 20px 0;
    padding: 0;
}

/* CSS Grid レイアウト */
.igp-gallery.igp-grid {
    display: grid;
    gap: 20px;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    justify-content: center;
}

/* 2件以下の場合の中央配置 */
.igp-gallery.igp-grid.igp-center {
    display: flex !important;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    max-width: 600px;
    margin: 20px auto;
    padding: 0;
    text-align: center;
}

.igp-gallery.igp-grid.igp-center .igp-gallery-item {
    flex: 0 0 auto;
    max-width: 500px;
    width: 100%;
    margin: 0 auto;
    display: block;
}

/* デスクトップでの2件表示は横並び */
@media (min-width: 768px) {
    .igp-gallery.igp-grid.igp-center {
        flex-direction: row;
        flex-wrap: wrap;
        max-width: 900px;
    }
    
    .igp-gallery.igp-grid.igp-center .igp-gallery-item {
        max-width: 400px;
        flex: 0 0 calc(50% - 10px);
    }
    
    /* 1件の場合は完全中央 */
    .igp-gallery.igp-grid.igp-center .igp-gallery-item:only-child {
        max-width: 500px;
        flex: 0 0 auto;
    }
}

/* スマートフォンでの中央配置強化 */
@media (max-width: 767px) {
    .igp-gallery.igp-grid.igp-center {
        max-width: 100%;
        padding: 0 10px;
    }
    
    .igp-gallery.igp-grid.igp-center .igp-gallery-item {
        max-width: 400px;
        width: 100%;
    }
}

/* デスクトップでのカラム数制御 */
@media (min-width: 769px) {
    .igp-gallery.igp-grid[data-columns="2"] {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .igp-gallery.igp-grid[data-columns="3"] {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .igp-gallery.igp-grid[data-columns="4"] {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* タブレット */
@media (max-width: 768px) and (min-width: 481px) {
    .igp-gallery.igp-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
}

/* スマートフォン */
@media (max-width: 480px) {
    .igp-gallery.igp-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
}

/* Masonry レイアウト */
.igp-gallery.igp-masonry {
    column-gap: 20px;
    column-fill: balance;
}

@media (min-width: 769px) {
    .igp-gallery.igp-masonry[data-columns="2"] {
        column-count: 2;
    }
    
    .igp-gallery.igp-masonry[data-columns="3"] {
        column-count: 3;
    }
    
    .igp-gallery.igp-masonry[data-columns="4"] {
        column-count: 4;
    }
}

@media (max-width: 768px) and (min-width: 481px) {
    .igp-gallery.igp-masonry {
        column-count: 2;
        column-gap: 15px;
    }
}

@media (max-width: 480px) {
    .igp-gallery.igp-masonry {
        column-count: 1;
        column-gap: 0;
    }
}

/* ギャラリーアイテム */
.igp-gallery-item {
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 20px;
}

.igp-masonry .igp-gallery-item {
    display: inline-block;
    width: 100%;
    margin-bottom: 20px;
}

/* 投稿コンテナ */
.igp-post-container {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: 1px solid #e1e5e9;
}

.igp-post-container:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
}

/* Instagram埋め込み要素の調整 */
.igp-post-container iframe {
    width: 100% !important;
    border: none !important;
    border-radius: 0 !important;
    display: block;
}

.igp-post-container blockquote {
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
}

/* Instagram埋め込みの最小高さ設定 */
.igp-post-container iframe[src*="instagram.com"] {
    min-height: 400px;
}

/* ローディング状態 */
.igp-gallery-item.loading {
    opacity: 0.6;
}

.igp-gallery-item.loading .igp-post-container {
    position: relative;
}

.igp-gallery-item.loading .igp-post-container::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 30px;
    height: 30px;
    margin: -15px 0 0 -15px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #405de6;
    border-radius: 50%;
    animation: igp-spin 1s linear infinite;
    z-index: 10;
}

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

/* エラー状態 */
.igp-gallery-item.error .igp-post-container {
    background: #f8f9fa;
    border-color: #dee2e6;
    padding: 20px;
    text-align: center;
    color: #6c757d;
}

.igp-gallery-item.error .igp-post-container::before {
    content: '⚠️ 投稿を読み込めませんでした';
    font-size: 14px;
}

/* 投稿なしメッセージ */
.igp-no-posts {
    text-align: center;
    padding: 40px 20px;
    background: #f8f9fa;
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    color: #6c757d;
    font-style: italic;
    margin: 20px 0;
}

/* レスポンシブ調整 */
@media (max-width: 480px) {
    .igp-gallery {
        margin: 15px 0;
    }
    
    .igp-gallery-item {
        margin-bottom: 15px;
    }
    
    .igp-post-container {
        border-radius: 8px;
    }
    
    .igp-post-container iframe[src*="instagram.com"] {
        min-height: 350px;
    }
}

/* Instagram特有のスタイル調整 */
.igp-post-container .instagram-media {
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
}

/* ダークモード対応 */
@media (prefers-color-scheme: dark) {
    .igp-post-container {
        background: #1a1a1a;
        border-color: #333;
    }
    
    .igp-no-posts {
        background: #2d2d2d;
        border-color: #444;
        color: #ccc;
    }
    
    .igp-gallery-item.error .igp-post-container {
        background: #2d2d2d;
        border-color: #444;
        color: #ccc;
    }
}

/* アニメーション効果 */
.igp-gallery-item {
    opacity: 0;
    animation: igp-fadeIn 0.6s ease forwards;
}

.igp-gallery-item:nth-child(1) { animation-delay: 0.1s; }
.igp-gallery-item:nth-child(2) { animation-delay: 0.2s; }
.igp-gallery-item:nth-child(3) { animation-delay: 0.3s; }
.igp-gallery-item:nth-child(4) { animation-delay: 0.4s; }
.igp-gallery-item:nth-child(5) { animation-delay: 0.5s; }
.igp-gallery-item:nth-child(6) { animation-delay: 0.6s; }

@keyframes igp-fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* アクセシビリティ対応 */
@media (prefers-reduced-motion: reduce) {
    .igp-post-container {
        transition: none;
    }
    
    .igp-post-container:hover {
        transform: none;
    }
    
    .igp-gallery-item {
        animation: none;
        opacity: 1;
    }
    
    .igp-gallery-item.loading .igp-post-container::before {
        animation: none;
    }
}
