/* Post Media Gallery - Multiple Images/Videos */

.post-media-gallery {
    margin: 1rem 0;
    border-radius: 0;
    overflow: hidden;
    width: 100%;
    display: block; /* Ensure it's a block element */
}

/* Default: single column for images without count or when count is not set */
.post-media-item {
    position: relative;
    width: 100%;
    margin-bottom: 0.5rem;
    display: block;
}

.post-media-item:last-child {
    margin-bottom: 0;
}

.post-media-item img,
.post-media-item video {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
    object-fit: cover;
}

/* Single media */
.post-media-gallery[data-media-count="1"] .post-media-item {
    margin-bottom: 0;
}

.post-media-gallery[data-media-count="1"] .post-media-item img,
.post-media-gallery[data-media-count="1"] .post-media-item video {
    width: 100%;
    height: auto;
    max-height: none;
    object-fit: contain;
    background: var(--gray-100);
    border-radius: 12px;
}

/* Single media - YouTube-like video wrapper should also be auto height */
.post-media-gallery[data-media-count="1"] .youtube-like-video-wrapper,
.post-media-gallery[data-media-count="1"] .post-video-container {
    aspect-ratio: auto;
    height: auto;
    min-height: auto;
}

/* Two media - side by side */
.post-media-gallery[data-media-count="2"] {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.5rem !important;
}

.post-media-gallery[data-media-count="2"] .post-media-item {
    margin-bottom: 0;
    width: 100%;
}

.post-media-gallery[data-media-count="2"] .post-media-item img,
.post-media-gallery[data-media-count="2"] .post-media-item video {
    width: 100%;
    height: 300px;
    object-fit: cover;
    border-radius: 8px;
    display: block;
}

/* Three media - 2 on top, 1 on bottom */
.post-media-gallery[data-media-count="3"] {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    grid-template-rows: auto auto !important;
    gap: 0.5rem !important;
}

.post-media-gallery[data-media-count="3"] .post-media-item:first-child {
    grid-column: 1 / -1;
}

.post-media-gallery[data-media-count="3"] .post-media-item {
    width: 100%;
    margin-bottom: 0;
}

.post-media-gallery[data-media-count="3"] .post-media-item img,
.post-media-gallery[data-media-count="3"] .post-media-item video {
    width: 100%;
    object-fit: cover;
    border-radius: 8px;
    display: block;
}

.post-media-gallery[data-media-count="3"] .post-media-item:first-child img,
.post-media-gallery[data-media-count="3"] .post-media-item:first-child video {
    height: 300px;
}

.post-media-gallery[data-media-count="3"] .post-media-item:not(:first-child) img,
.post-media-gallery[data-media-count="3"] .post-media-item:not(:first-child) video {
    height: 200px;
}

/* Four or more media - grid */
.post-media-gallery[data-media-count="4"],
.post-media-gallery[data-media-count="5"],
.post-media-gallery[data-media-count="6"],
.post-media-gallery[data-media-count="7"],
.post-media-gallery[data-media-count="8"],
.post-media-gallery[data-media-count="9"],
.post-media-gallery[data-media-count="10"] {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 0.5rem !important;
}

.post-media-gallery[data-media-count="4"] .post-media-item,
.post-media-gallery[data-media-count="5"] .post-media-item,
.post-media-gallery[data-media-count="6"] .post-media-item,
.post-media-gallery[data-media-count="7"] .post-media-item,
.post-media-gallery[data-media-count="8"] .post-media-item,
.post-media-gallery[data-media-count="9"] .post-media-item,
.post-media-gallery[data-media-count="10"] .post-media-item {
    margin-bottom: 0;
    width: 100%;
}

.post-media-gallery[data-media-count="4"] .post-media-item img,
.post-media-gallery[data-media-count="4"] .post-media-item video,
.post-media-gallery[data-media-count="5"] .post-media-item img,
.post-media-gallery[data-media-count="5"] .post-media-item video,
.post-media-gallery[data-media-count="6"] .post-media-item img,
.post-media-gallery[data-media-count="6"] .post-media-item video,
.post-media-gallery[data-media-count="7"] .post-media-item img,
.post-media-gallery[data-media-count="7"] .post-media-item video,
.post-media-gallery[data-media-count="8"] .post-media-item img,
.post-media-gallery[data-media-count="8"] .post-media-item video,
.post-media-gallery[data-media-count="9"] .post-media-item img,
.post-media-gallery[data-media-count="9"] .post-media-item video,
.post-media-gallery[data-media-count="10"] .post-media-item img,
.post-media-gallery[data-media-count="10"] .post-media-item video {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: 8px;
    display: block;
}

/* More than 6 media - show first 6, add overlay for count */
.post-media-gallery[data-media-count] .post-media-item:nth-child(n+7) {
    display: none;
}

.post-media-gallery[data-media-count] .post-media-item:nth-child(6)::after {
    content: '+ ' attr(data-remaining);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 600;
    border-radius: 8px;
    z-index: 2;
}

/* Ensure all images in gallery are properly displayed */
.post-media-gallery .post-media-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Fix for images that might not have proper container */
.post-media-gallery .post-media-item {
    overflow: hidden;
    background: #f3f4f6;
}

.post-media-gallery .post-media-item img {
    min-height: 150px;
}

/* YouTube embeds in gallery */
.post-media-gallery .youtube-embed,
.youtube-embed {
    position: relative;
    padding-bottom: 56.25%; /* 16:9 aspect ratio */
    height: 0;
    overflow: hidden;
    border-radius: 0; /* Remove border radius for full width */
    background-color: #000;
    width: 100%;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

.post-media-gallery .youtube-embed iframe,
.youtube-embed iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 0;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 1;
}

/* Hover effect for images */
.post-media-item img,
.post-media-item video {
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.post-media-item img:hover,
.post-media-item video:hover {
    transform: scale(1.02);
    opacity: 0.95;
}

/* Media counter badge */
.media-count-badge {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    z-index: 10;
}

/* Mobile responsive */
@media (max-width: 768px) {
    /* Galerie prend 100% de la largeur - NO PADDING */
    .post-media-gallery {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        border-radius: 0 !important;
    }
    
    /* Tous les items prennent 100% de la largeur en responsive */
    .post-media-item {
        width: 100%;
        margin-bottom: 0.5rem;
    }
    
    .post-media-gallery[data-media-count="2"],
    .post-media-gallery[data-media-count="4"],
    .post-media-gallery[data-media-count="5"],
    .post-media-gallery[data-media-count="6"] {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
    
    /* Toutes les images et vidéos prennent 100% de la largeur */
    .post-media-gallery[data-media-count="1"] .post-media-item img,
    .post-media-gallery[data-media-count="1"] .post-media-item video,
    .post-media-gallery[data-media-count="2"] .post-media-item img,
    .post-media-gallery[data-media-count="2"] .post-media-item video,
    .post-media-gallery[data-media-count="4"] .post-media-item img,
    .post-media-gallery[data-media-count="4"] .post-media-item video,
    .post-media-gallery[data-media-count="5"] .post-media-item img,
    .post-media-gallery[data-media-count="5"] .post-media-item video,
    .post-media-gallery[data-media-count="6"] .post-media-item img,
    .post-media-gallery[data-media-count="6"] .post-media-item video {
        width: 100%;
        height: auto;
        max-height: none;
        object-fit: cover;
        border-radius: 0;
    }
    
    .post-media-gallery[data-media-count="3"] {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        gap: 0.5rem;
    }
    
    .post-media-gallery[data-media-count="3"] .post-media-item:first-child {
        grid-column: 1;
    }
    
    .post-media-gallery[data-media-count="3"] .post-media-item img,
    .post-media-gallery[data-media-count="3"] .post-media-item video {
        width: 100%;
        height: auto;
        max-height: none;
        object-fit: cover;
        border-radius: 0;
    }
    
    /* YouTube embeds prennent 100% de la largeur */
    .post-media-gallery .youtube-embed {
        width: 100%;
        padding-bottom: 56.25%;
    }
}

