/* ========================= */
/*       GALERIA FOTOS       */
/* ========================= */

body {
    padding-top: 60px;
    margin: 0;
    font-family: 'Arial', sans-serif;
    -webkit-overflow-scrolling: touch;
    /* Scroll suave no iOS */
}

/* ===== Container ===== */
.galeria-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 60px 20px;
    min-height: calc(100vh - 60px);
}

.galeria-title {
    font-size: 36px;
    color: #333;
    text-align: center;
    margin-bottom: 50px;
    font-weight: 700;
}

.galeria-temas {
    display: flex;
    flex-direction: column;
    gap: 60px;
}

/* ===== Tema ===== */
.tema-galeria {
    animation: fadeIn 0.5s ease;
    position: relative;
    /* Para o hr ficar relativo ao tema */
}

/* HR CORRIGIDO - Agora está DENTRO de cada tema-galeria */
.tema-galeria hr {
    border: none;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    margin: 40px auto 0 auto;
    width: 90%;
    max-width: 800px;
}

/* Remove o último hr do último tema */
.tema-galeria:last-child hr {
    display: none;
}

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

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.tema-titulo {
    font-size: 28px;
    text-align: center;
    margin-bottom: 8px;
    font-weight: 700;
}

.tema-descricao {
    font-size: 16px;
    text-align: center;
    margin-bottom: 30px;
    color: #666;
}

/* ===== Grid ===== */
.fotos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 15px;
    align-items: start;
}

/* ===== Card ===== */
.foto-item {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    background: #000;
    aspect-ratio: 9 / 16;
    width: 100%;
    max-width: 250px;
    cursor: pointer;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    touch-action: manipulation;
    /* Melhora comportamento touch */
    -webkit-tap-highlight-color: transparent;
    /* Remove highlight no iOS */
}

.foto-item:hover {
    transform: translateY(-6px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.2);
}

/* ===== IMAGEM ===== */
.foto-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.3s ease;
    pointer-events: none;
    /* Evita eventos na imagem dentro do card */
}

.foto-item:hover .foto-thumbnail {
    transform: scale(1.05);
}

/* ===== Overlay ===== */
.foto-overlay {
    position: absolute;
    inset: 0;
    background: rgba(117, 187, 214, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
    /* Não interfere no clique */
}

.foto-item:hover .foto-overlay {
    opacity: 1;
}

.foto-overlay span {
    color: #fff;
    font-size: 18px;
    font-weight: 600;
}

/* ===== Modal ===== */
.modal-foto {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
    touch-action: pan-y pinch-zoom;
}

.modal-foto.show {
    display: flex;
}

/* Container para a imagem - ATUALIZADO */
.modal-foto-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    max-width: 90vw;
    max-height: 90vh;
    overflow: hidden;
}

/* ===== Imagem do Modal - CORREÇÃO PRINCIPAL ===== */
.modal-imagem {
    display: block;
    object-fit: contain;
    border-radius: 12px;
    transition: transform 0.3s ease;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;

    /* LIMITES MÁXIMOS ABSOLUTOS - CORREÇÃO DO PROBLEMA */
    max-width: 100% !important;
    max-height: 100% !important;
    width: auto !important;
    height: auto !important;

    /* Garante que a imagem nunca ultrapasse a tela */
    max-width: calc(100vw - 40px) !important;
    max-height: calc(100vh - 40px) !important;

    transform-origin: center center;
}

/* Classe para animação de swipe para esquerda */
.swipe-left {
    transform: translateX(-100%);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* Classe para animação de swipe para direita */
.swipe-right {
    transform: translateX(100%);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}

/* ===== Fechar Modal ===== */
.modal-fechar {
    position: absolute;
    top: 20px;
    right: 30px;
    font-size: 40px;
    color: white;
    cursor: pointer;
    z-index: 1001;
    background: none;
    border: none;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}

.modal-fechar:hover {
    transform: scale(1.2);
    background: rgba(255, 255, 255, 0.1);
}

/* ===== Setas externas ===== */
.seta-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid white;
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    font-size: 28px;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 1001;
    border: none;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.seta-nav:hover {
    background: rgba(255, 255, 255, 0.4);
}

.seta-nav.seta-esquerda {
    left: 40px;
}

.seta-nav.seta-direita {
    right: 40px;
}

/* ========================= */
/* CORREÇÃO ESPECÍFICA PARA IMAGENS GRANDES */
/* ========================= */
@media (min-width: 481px) {
    .modal-imagem {
        /* FORÇA a imagem a se ajustar ao container */
        width: auto !important;
        height: auto !important;
        max-width: min(90vw, 1200px) !important;
        max-height: min(90vh, 800px) !important;

        /* Previne zoom excessivo no desktop */
        image-rendering: auto;
    }

    .modal-foto-container {
        /* Container mais restritivo */
        max-width: 95vw;
        max-height: 95vh;
    }
}

/* ========================= */
/* RESPONSIVO */
/* ========================= */
@media (max-width: 1024px) {
    .fotos-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }

    .seta-nav.seta-esquerda {
        left: 25px;
    }

    .seta-nav.seta-direita {
        right: 25px;
    }

    .modal-imagem {
        max-width: 85vw !important;
        max-height: 85vh !important;
    }
}

@media (max-width: 768px) {
    .galeria-title {
        font-size: 24px;
    }

    .tema-titulo {
        font-size: 20px;
    }

    .fotos-grid {
        gap: 12px;
    }

    .foto-item {
        max-width: 180px;
    }

    .seta-nav.seta-esquerda {
        left: 15px;
    }

    .seta-nav.seta-direita {
        right: 15px;
    }

    .seta-nav {
        width: 40px;
        height: 40px;
        font-size: 24px;
    }

    .tema-galeria hr {
        margin: 30px auto 0 auto;
        width: 95%;
    }

    .modal-imagem {
        max-width: 90vw !important;
        max-height: 80vh !important;
    }
}

@media (max-width: 480px) {
    .galeria-title {
        font-size: 20px;
    }

    .fotos-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 30px;
        justify-items: center;
    }

    .foto-item {
        max-width: 140px;
    }

    .modal-imagem {
        /* Em mobile, usa mais espaço */
        max-width: 95vw !important;
        max-height: 85vh !important;
        touch-action: pan-y pinch-zoom;
    }

    .modal-foto-container {
        max-width: 100vw;
        max-height: 90vh;
    }

    .seta-nav {
        width: 35px;
        height: 35px;
        font-size: 20px;
    }

    .seta-nav.seta-esquerda {
        left: 10px;
    }

    .seta-nav.seta-direita {
        right: 10px;
    }

    .modal-fechar {
        top: 15px;
        right: 15px;
        font-size: 30px;
    }
}

/* ========================= */
/* CORREÇÃO EXTRA PARA NAVEGADORES ESPECÍFICOS */
/* ========================= */
@supports (-webkit-touch-callout: none) {

    /* iOS Safari */
    .modal-imagem {
        max-width: 100% !important;
        max-height: 100% !important;
    }
}

@supports not (object-fit: contain) {

    /* Fallback para navegadores antigos */
    .modal-imagem {
        width: 100% !important;
        height: auto !important;
    }
}


/* ===========================
   BUSCA GALERIA PÚBLICA
   =========================== */

.busca-galeria {
    display: flex;
    gap: 12px;
    margin: 20px 0 30px 0;
    align-items: center;
}

#buscar-tema-publico-site {
    padding: 10px 14px;
    border: 2px solid #ccc;
    border-radius: 6px;
    font-size: 1rem;
    flex: 1;
}

/* ===========================
   GALERIA PÚBLICA
   =========================== */

#galeria-publica {
    display: flex;
    flex-direction: column;
    gap: 35px;
}

.galeria-tema {
    width: 100%;
}

.galeria-tema-titulo {
    font-size: 1.4rem;
    margin-bottom: 15px;
    font-weight: 600;
}

.galeria-fotos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
}

.galeria-foto-item {
    position: relative;
    overflow: hidden;
    border-radius: 6px;
    aspect-ratio: 1 / 1;
}

.galeria-foto-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.galeria-foto-nome {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    padding: 6px 8px;
    font-size: 0.85rem;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===========================
   BOTÕES
   =========================== */

.btn-primary,
.btn-danger {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s ease, box-shadow 0.3s ease, transform 0.2s ease;
}

.btn-primary {
    background-color: #75BBD6;
    color: white;
}

.btn-primary:hover {
    background-color: #45B7D1;
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(75, 183, 209, 0.4);
}

.btn-danger {
    background-color: #ff6b6b;
    color: white;
}

.btn-danger:hover {
    background-color: #ff5252;
    transform: translateY(-2px);
}

/* ===========================
   TABLET (769px até 1024px)
   =========================== */

@media (max-width: 1024px) {
    .galeria-tema-titulo {
        font-size: 1.25rem;
    }

    .galeria-fotos-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 12px;
    }
}

/* ===========================
   MOBILE (até 768px)
   =========================== */

@media (max-width: 768px) {
    .busca-galeria {
        flex-direction: column;
        align-items: stretch;
    }

    #buscar-tema-publico-site {
        width: 100%;
    }

    #galeria-publica {
        gap: 20px;
    }

    .galeria-tema-titulo {
        font-size: 1.1rem;
        margin-bottom: 10px;
    }

    .galeria-fotos-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 10px;
    }

    .galeria-foto-nome {
        font-size: 0.75rem;
        padding: 5px 6px;
    }

    /* botões quebram linha */
    .busca-galeria button,
    .acoes button {
        width: 100%;
    }
}