/* ── Grid de thumbnails ── */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin: 24px 0;
}

.gallery-thumb {
    position: relative;
    aspect-ratio: 4 / 3;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    border: 1px solid rgba(61, 195, 235, 0.2);
    transition: transform 0.22s ease, border-color 0.22s ease;
}

.gallery-thumb:hover {
    transform: scale(1.04);
    border-color: rgba(61, 195, 235, 0.7);
}

.gallery-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.gallery-thumb-caption {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.75));
    color: rgba(255,255,255,0.85);
    font-size: 0.65rem;
    font-family: 'Fira Code', monospace;
    padding: 20px 8px 6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.gallery-thumb:hover .gallery-thumb-caption {
    opacity: 1;
}

/* ── Modal — estrutura em grid de 3 linhas ── */
#gallery-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

#gallery-modal.open {
    display: grid;
    grid-template-rows: 52px 1fr auto;
    grid-template-columns: 1fr;
    width: 100%;
    height: 100%;
    height: 100dvh;
    animation: galleryFadeIn 0.22s ease;
}

@keyframes galleryFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Linha 1: topo (contador + fechar) ── */
.gallery-topbar {
    grid-row: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255,255,255,0.06);
}

.gallery-counter {
    font-family: 'Fira Code', monospace;
    font-size: 0.75rem;
    color: rgba(255,255,255,0.4);
    letter-spacing: 0.05em;
}

.gallery-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.55);
    font-size: 1.3rem;
    cursor: pointer;
    transition: color 0.2s;
    padding: 6px 8px;
    line-height: 1;
    border-radius: 6px;
}

.gallery-close:hover { color: #fff; }

/* ── Linha 2: imagem + botões nav ── */
.gallery-stage {
    grid-row: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    min-height: 0;      /* permite que o grid shrink corretamente */
    overflow: hidden;
    padding: 12px 0;
}

.gallery-nav {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    background: rgba(61,195,235,0.08);
    border: 1px solid rgba(61,195,235,0.25);
    color: #3dc3eb;
    border-radius: 50%;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 8px;
}

.gallery-nav:hover    { background: rgba(61,195,235,0.22); }
.gallery-nav:disabled { opacity: 0.18; cursor: default; pointer-events: none; }

/* Wrap da imagem — ocupa o espaço restante entre os dois botões */
.gallery-img-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    height: 100%;
}

#gallery-modal-img {
    display: block;
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    border-radius: 10px;
    border: 1px solid rgba(61,195,235,0.15);
    box-shadow: 0 0 50px rgba(61,195,235,0.07);
    transition: opacity 0.18s ease;
}

#gallery-modal-img.loading {
    opacity: 0;
}

#gallery-modal-caption {
    color: rgba(255,255,255,0.45);
    font-family: 'Fira Code', monospace;
    font-size: 0.72rem;
    text-align: center;
    margin-top: 10px;
    padding: 0 12px;
    min-height: 16px;
    flex-shrink: 0;
}

/* ── Linha 3: thumbnails ── */
.gallery-thumbs {
    grid-row: 3;
    display: flex;
    gap: 7px;
    justify-content: center;
    flex-wrap: wrap;
    padding: 10px 12px 14px;
    border-top: 1px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}

.gallery-thumbs img {
    width: 50px;
    height: 36px;
    object-fit: cover;
    border-radius: 5px;
    cursor: pointer;
    border: 2px solid rgba(255,255,255,0.1);
    opacity: 0.4;
    transition: opacity 0.2s, border-color 0.2s, transform 0.15s;
    flex-shrink: 0;
}

.gallery-thumbs img:hover {
    opacity: 0.75;
    transform: scale(1.06);
}

.gallery-thumbs img.active {
    border-color: #3dc3eb;
    opacity: 1;
}

/* ── Mobile ── */
@media (max-width: 600px) {
    .gallery-nav {
        width: 36px;
        height: 36px;
        font-size: 0.8rem;
        margin: 0 4px;
    }

    #gallery-modal-img {
        border-radius: 7px;
    }

    .gallery-thumbs img {
        width: 40px;
        height: 30px;
    }

    #gallery-modal-caption {
        font-size: 0.68rem;
    }
}
