/* ============================================================
 * Facebook-style Photo Gallery
 *
 * Layout tự arrange theo số lượng ảnh (1/2/3/4/5+).
 * Dùng được cả trong TinyMCE editor preview lẫn frontend.
 *
 * HTML structure:
 *   <figure class="fb-gallery-figure">
 *     <div class="fb-gallery fb-N" data-count="N" data-more="M">
 *       <a class="fb-gallery-cell"><img></a>
 *       <a class="fb-gallery-cell"><img></a>
 *       ...
 *       <a class="fb-gallery-cell"><img><span class="fb-gallery-more">+M</span></a>
 *     </div>
 *     <figcaption class="fb-gallery-caption">Caption</figcaption>
 *   </figure>
 * ============================================================ */

.fb-gallery-figure {
    margin: 1rem 0;
    max-width: 100%;
}

.fb-gallery {
    display: grid;
    gap: 3px;
    border-radius: 8px;
    overflow: hidden;
    max-width: 720px;
    margin: 0 auto;
}

.fb-gallery-cell {
    position: relative;
    overflow: hidden;
    display: block;
    background: #f0f0f0;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

.fb-gallery-cell img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
}

.fb-gallery-cell:hover img {
    transform: scale(1.03);
}

/* === Overlay "+N" on 5th cell when count > 5 === */
.fb-gallery-more {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.5rem, 4vw, 2.5rem);
    font-weight: 700;
    pointer-events: none;
    z-index: 2;
}

/* === Caption === */
.fb-gallery-caption {
    margin-top: 0.5rem;
    color: #6c757d;
    font-size: 0.875rem;
    text-align: center;
}

/* ============================================================
 * Layout per count
 * ============================================================ */

/* 1 image — full width, 16:9 aspect */
.fb-gallery.fb-1 {
    grid-template-columns: 1fr;
}
.fb-gallery.fb-1 .fb-gallery-cell {
    aspect-ratio: 16 / 9;
}

/* 2 images — side by side, square aspect */
.fb-gallery.fb-2 {
    grid-template-columns: 1fr 1fr;
}
.fb-gallery.fb-2 .fb-gallery-cell {
    aspect-ratio: 1 / 1;
}

/* 3 images — 1 big left (span 2 rows) + 2 stacked right */
.fb-gallery.fb-3 {
    grid-template-columns: 2fr 1fr;
    grid-template-rows: 1fr 1fr;
    aspect-ratio: 16 / 10;
}
.fb-gallery.fb-3 .fb-gallery-cell:first-child {
    grid-row: span 2;
}

/* 4 images — 2×2 grid */
.fb-gallery.fb-4 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    aspect-ratio: 1 / 1;
}

/* 5+ images — 3 columns, first cell spans 2×2; cells 6+ hidden */
.fb-gallery.fb-5plus {
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(2, 1fr);
    aspect-ratio: 3 / 2;
}
.fb-gallery.fb-5plus .fb-gallery-cell:first-child {
    grid-column: span 2;
    grid-row: span 2;
}
.fb-gallery.fb-5plus .fb-gallery-cell:nth-child(n+6) {
    display: none;
}

/* ============================================================
 * Mobile responsive — đơn giản hoá grid trên màn nhỏ
 * ============================================================ */
@media (max-width: 480px) {
    .fb-gallery {
        gap: 2px;
        border-radius: 4px;
    }
    .fb-gallery-more {
        font-size: 1.5rem;
    }
}
