/* =====================================================================
   GALERIE MÉDIAS (X / Facebook / Instagram) + LIGHTBOX
   Chargée globalement : les galeries sont générées par renderMediaGallery()
   et apparaissent dans les sujets, réponses, guides et tests.
   ===================================================================== */

.sg-gallery {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 3px;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    border-radius: 12px;
    margin: 16px 0;
    background: #fff;
}
.sg-cell {
    position: relative;
    overflow: hidden;
    cursor: pointer;
    background: #0f172a;
    min-width: 0;
    min-height: 0;
}
/* Mosaïque type publication Facebook : chaque vignette remplit sa case. */
.sg-cell img,
.sg-cell video {
    width: 100%;
    max-width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.sg-hover {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .28);
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.35rem;
    transition: opacity .18s ease;
    pointer-events: none;
}
.sg-cell:hover .sg-hover,
.sg-cell:focus .sg-hover { opacity: 1; }
.sg-video-badge {
    position: absolute;
    left: 50%; top: 50%;
    transform: translate(-50%, -50%);
    width: 44px; height: 44px;
    background: rgba(15, 23, 42, .55);
    border: 2px solid rgba(255, 255, 255, .9);
    border-radius: 50%;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .9rem;
    padding-left: 3px;
    pointer-events: none;
}
.sg-extra {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, .62);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.9rem;
    font-weight: 800;
    letter-spacing: .02em;
    pointer-events: none;
}

/* ── 1 média : image entière, centrée ── */
.sg-layout-single {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #eef2f7;
    padding: 6px;
}
.sg-layout-single .sg-cell {
    background: transparent;
    width: 100%;
}
.sg-layout-single .sg-cell img {
    width: 100%;
    height: auto;
    max-height: 70vh;
    object-fit: contain;
}

/* ── 2 médias : 2 vignettes côte à côte ── */
.sg-layout-two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    aspect-ratio: 16 / 9;
}

/* ── 3 médias : 1 grande à gauche + 2 empilées à droite (Facebook) ── */
.sg-layout-three {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
        "a b"
        "a c";
    aspect-ratio: 16 / 10;
}
.sg-layout-three .sg-cell-1 { grid-area: a; }
.sg-layout-three .sg-cell-2 { grid-area: b; }
.sg-layout-three .sg-cell-3 { grid-area: c; }

/* ── 4 médias : grille 2×2 ── */
.sg-layout-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    aspect-ratio: 1 / 1;
}

/* ── 5 médias : 2 en haut, 3 en bas (Facebook) ── */
.sg-layout-collage {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    grid-template-rows: repeat(2, minmax(0, 1fr));
    grid-template-areas:
        "a a a b b b"
        "c c d d e e";
    aspect-ratio: 16 / 10;
}
.sg-layout-collage .sg-cell-1 { grid-area: a; }
.sg-layout-collage .sg-cell-2 { grid-area: b; }
.sg-layout-collage .sg-cell-3 { grid-area: c; }
.sg-layout-collage .sg-cell-4 { grid-area: d; }
.sg-layout-collage .sg-cell-5 { grid-area: e; }

/* ── Responsive ── */
@media (max-width: 767px) {
    .sg-layout-two { aspect-ratio: 4 / 3; }
    .sg-layout-three {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        grid-template-rows: minmax(0, 1.35fr) minmax(0, 1fr);
        grid-template-areas:
            "a a"
            "b c";
        aspect-ratio: 4 / 3;
    }
    .sg-layout-collage {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        grid-template-rows: repeat(3, minmax(0, 1fr));
        grid-template-areas:
            "a a"
            "b c"
            "d e";
        aspect-ratio: 4 / 3;
    }
}

/* === LIGHTBOX PLEIN ÉCRAN === */
.sg-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .92);
    z-index: 5000;
    display: none;
    align-items: center;
    justify-content: center;
}
.sg-lightbox.open { display: flex; }
.sg-lb-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 24px 68px;
}
.sg-lb-stage img,
.sg-lb-stage video {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 6px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .5);
}
.sg-lb-counter {
    position: absolute;
    bottom: 18px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    background: rgba(15, 23, 42, .75);
    padding: 6px 16px;
    border-radius: 999px;
    font-size: .85rem;
    font-weight: 600;
    letter-spacing: .03em;
}
.sg-lb-btn {
    position: absolute;
    z-index: 2;
    border: none;
    cursor: pointer;
    background: rgba(255, 255, 255, .14);
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, transform .15s;
}
.sg-lb-btn:hover { background: rgba(255, 255, 255, .3); }
.sg-lb-close { top: 16px; right: 16px; width: 44px; height: 44px; font-size: 1.1rem; }
.sg-lb-prev { left: 16px; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; font-size: 1.15rem; }
.sg-lb-next { right: 16px; top: 50%; transform: translateY(-50%); width: 48px; height: 48px; font-size: 1.15rem; }
@media (max-width: 767px) {
    .sg-lb-stage { padding: 24px 12px; }
    .sg-lb-prev { left: 8px; }
    .sg-lb-next { right: 8px; }
    .sg-lb-close { top: 10px; right: 10px; }
}
