/* ------------------------------------------------------------------
   Galerie Photos Moderne - CSS Responsive
   Inspiré de Google Photos, Pinterest et memento.photo
------------------------------------------------------------------ */

/* Reset de base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Évite les variations de largeur quand la scrollbar apparaît (sinon colWidth change pendant le reveal) */
html {
    scrollbar-gutter: stable;
}

body {
    overflow-y: scroll;
}

/* ------------------------------------------------------------------
   Conteneurs principaux
------------------------------------------------------------------ */

.gallery-container {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
}

/* Autres conteneurs logiques */
.gallery-container,
#my-photos,
#all-photos {
    width: 100%;
    max-width: 100%;
}

/* ------------------------------------------------------------------
   Header & titres
------------------------------------------------------------------ */

.gallery-header {
    text-align: center;
    margin-bottom: 40px;
}

.gallery-header h1 {
    font-size: 2.5rem;
    font-weight: 400;
    color: var(--text, #e6e7ff);
    margin-bottom: 10px;
    font-family: 'Pacifico', cursive;
    text-shadow: 0 0 6px rgba(138, 43, 226, 0.6),
                 0 0 18px rgba(57, 255, 20, 0.35);
}

.gallery-header .subtitle {
    font-size: 1.1rem;
    color: var(--muted, #a7a9d6);
    font-weight: 400;
}

.gallery-section {
    margin-bottom: 60px;
}

.gallery-section-title {
    font-size: 1.8rem;
    font-weight: 400;
    color: var(--text, #e6e7ff);
    margin-bottom: 25px;
    padding-left: 5px;
    border-left: 4px solid var(--neon-purple, #8a2be2);
    text-shadow: 0 0 10px rgba(138, 43, 226, 0.35);
}

/* ------------------------------------------------------------------
   Layout grille principale
------------------------------------------------------------------ */

/* Conteneur de grille : .modern-gallery uniquement
   (les IDs #myModernGallery / #allModernGallery restent des wrappers) */
.modern-gallery {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    grid-row-gap: 4px;
    align-items: start;
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding: 0;
}

/* Au cas où, on s'assure que les wrappers occupent toute la largeur */
#myModernGallery,
#allModernGallery {
    width: 100%;
    max-width: 100%;
}

/* ------------------------------------------------------------------
   Cartes photo
------------------------------------------------------------------ */

.gallery-photo-card {
    position: relative;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s ease;
    cursor: pointer;
    background: transparent;
    animation: fadeInUp 0.6s ease forwards;
    opacity: 0;
    transform: translateY(20px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    touch-action: pan-y;
}

/* Classe pour photos qui ont besoin de centrage avec effet flou */
.gallery-photo-card.needs-centering {
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.gallery-photo-card.needs-centering::before {
    content: '';
    position: absolute;
    top: -20px;
    left: -20px;
    right: -20px;
    bottom: -20px;
    background-image: var(--bg-image);
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    filter: blur(30px) brightness(0.7) saturate(1.2);
    transform: scale(1.2);
    z-index: 0;
    opacity: 0.8;
}

.gallery-photo-card.needs-centering img {
    max-width: 100%;
    max-height: 100%;
    width: auto;
    height: auto;
    object-fit: contain;
    position: relative;
    z-index: 1;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

/* Image dans une carte standard */
.gallery-photo-card img {
    width: 100%;
    height: 100%;
    display: block;
    transition: transform 0.3s ease;
    object-fit: contain;
}

.gallery-photo-card.loading {
    opacity: 0;
    box-shadow: none;
    background: transparent;
    pointer-events: none;
}

.gallery-photo-card.loaded {
    opacity: 1;
    background: #000;
.gallery-photo-card.loading img {
    opacity: 0;
}

.gallery-photo-card.loaded img {
    opacity: 1;
    transition: opacity 0.25s ease, transform 0.3s ease;
}

.gallery-photo-card.row-pending {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.gallery-photo-card.row-ready {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.gallery-photo-card.row-pending img {
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease;
}

.gallery-photo-card.row-ready img {
    opacity: 1;
    visibility: visible;
    transition: opacity 0.25s ease, transform 0.3s ease;
}

    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    pointer-events: auto;
}

/* Etat hover */
.gallery-photo-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 35px rgba(0, 0, 0, 0.4),
                0 0 20px rgba(138, 43, 226, 0.3);
}

.gallery-photo-card:hover img {
    transform: scale(1.02);
}

/* Overlay d'interaction */
.gallery-photo-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(60% 100% at 30% 20%, rgba(138, 43, 226, 0.55), rgba(0,0,0,0) 60%),
        radial-gradient(60% 100% at 70% 80%, rgba(57, 255, 20, 0.4), rgba(0,0,0,0) 60%),
        linear-gradient(45deg, rgba(13, 13, 28, 0.85), rgba(13, 13, 28, 0.65));
    opacity: 0;
    transition: opacity 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.6);
    pointer-events: none; /* Pour ne pas bloquer le clic sur mobile */
}

.gallery-photo-card:hover .gallery-photo-overlay {
    opacity: 1;
}

/* Cas particuliers */
.gallery-photo-card.wide-landscape {
    max-width: 100%;
}

.gallery-photo-card.tall-portrait img {
    max-height: 600px;
    object-fit: cover;
}

/* ------------------------------------------------------------------
   Lightbox / Modal
------------------------------------------------------------------ */

.gallery-lightbox {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.gallery-lightbox.active {
    display: flex;
}

/* Android pinch-zoom: Wrapper to contain zoomed image */
.gallery-lightbox-image-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    overflow: hidden;
    /* Android pinch-zoom: Allow pinch and pan gestures */
    touch-action: pan-x pan-y pinch-zoom;
}

.gallery-lightbox img {
    max-width: 95%;
    max-height: 95%;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    /* Android pinch-zoom: Allow pinch gestures on the image */
    touch-action: pan-x pan-y pinch-zoom;
    /* Ensure image can be transformed for zoom/pan */
    transform-origin: center center;
    user-select: none;
    -webkit-user-select: none;
}

/* Masquer le hamburger quand la lightbox est ouverte */
.hamburger-menu {
    transition: opacity 0.15s ease;
}

body.lightbox-open .hamburger-menu {
    display: none !important;
}

/* Bouton de téléchargement/enregistrement */
.gallery-download-btn {
    position: absolute;
    bottom: 24px;
    right: 24px;
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
    border: 1px solid rgba(138, 43, 226, 0.35);
    border-radius: 24px;
    padding: 10px 14px;
    font-size: 14px;
    cursor: pointer;
    backdrop-filter: blur(6px);
    transition: all 0.2s ease;
    box-shadow: 0 0 12px rgba(138, 43, 226, 0.35);
}

.gallery-download-btn:hover {
    background: rgba(138, 43, 226, 0.18);
    box-shadow: 0 0 16px rgba(138, 43, 226, 0.55),
                0 0 8px rgba(57, 255, 20, 0.25);
}

/* Contrôles du lightbox */
.gallery-lightbox-close {
    position: absolute;
    top: 20px;
    right: 30px;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

.gallery-lightbox-close:hover {
    background: rgba(0, 0, 0, 0.8);
}

.gallery-lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: white;
    font-size: 30px;
    font-weight: bold;
    cursor: pointer;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
    user-select: none;
}

.gallery-lightbox-nav:hover {
    background: rgba(0, 0, 0, 0.8);
}

.gallery-lightbox-prev {
    left: 30px;
}

.gallery-lightbox-next {
    right: 30px;
}

.gallery-photo-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
}

/* ------------------------------------------------------------------
   États de chargement & empty state
------------------------------------------------------------------ */

.gallery-photo-loading {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(13, 13, 28, 0.9);
    color: var(--muted, #a7a9d6);
    z-index: 2;
}

.gallery-photo-card.loading .gallery-photo-loading {
    display: flex;
}

.gallery-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--muted, #a7a9d6);
}

.gallery-empty-state h3 {
    font-size: 1.5rem;
    margin-bottom: 10px;
    font-weight: 400;
}

.gallery-empty-state p {
    font-size: 1rem;
    opacity: 0.8;
}

/* ------------------------------------------------------------------
   Animations séquentielles
------------------------------------------------------------------ */

.gallery-photo-card:nth-child(1)  { animation-delay: 0.1s; }
.gallery-photo-card:nth-child(2)  { animation-delay: 0.2s; }
.gallery-photo-card:nth-child(3)  { animation-delay: 0.3s; }
.gallery-photo-card:nth-child(4)  { animation-delay: 0.4s; }
.gallery-photo-card:nth-child(5)  { animation-delay: 0.5s; }
.gallery-photo-card:nth-child(6)  { animation-delay: 0.6s; }
.gallery-photo-card:nth-child(7)  { animation-delay: 0.7s; }
.gallery-photo-card:nth-child(8)  { animation-delay: 0.8s; }
.gallery-photo-card:nth-child(9)  { animation-delay: 0.9s; }
.gallery-photo-card:nth-child(10) { animation-delay: 1s; }

@keyframes fadeInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ------------------------------------------------------------------
   Thèmes & variantes
------------------------------------------------------------------ */

.gallery-theme-dark {
    background: #1a1a1a;
    color: white;
}

.gallery-theme-dark .gallery-header h1 {
    color: white;
}

.gallery-theme-dark .gallery-section-title {
    color: #e0e0e0;
    border-left-color: #64b5f6;
}

.gallery-theme-dark .gallery-photo-card {
    background: #2a2a2a;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

/* Variantes de taille de grille */
.gallery-compact .modern-gallery {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 8px;
}

.gallery-large .modern-gallery {
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 24px;
}

/* Effet de focus pour accessibilité */
.gallery-photo-card:focus {
    outline: 3px solid #1976d2;
    outline-offset: 2px;
}

.gallery-lightbox-nav:focus,
.gallery-lightbox-close:focus {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* ------------------------------------------------------------------
   Responsive
------------------------------------------------------------------ */

/* <= 1024px : on reste sur 2 colonnes, on peut ajuster les espacements si besoin */
@media (max-width: 1024px) {
    .modern-gallery {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
        grid-row-gap: 4px;
    }
}

/* <= 768px : 2 colonnes, full width + ajustements typographiques */
@media (max-width: 768px) {
    .modern-gallery {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
        grid-row-gap: 4px;
        width: 100%;
        margin: 0;
        padding: 0;
        align-items: start;
    }

    /* Les conteneurs occupent simplement 100% de la largeur dispo */
    #my-photos,
    #all-photos,
    #myPhotosList,
    #allPhotosList {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        position: static !important;
        left: auto !important;
        transform: none !important;
    }

    .gallery-container {
        padding: 0;
    }

    .gallery-header h1 {
        font-size: 2rem;
    }

    .gallery-section-title {
        font-size: 1.5rem;
    }

    .gallery-lightbox-nav {
        width: 40px;
        height: 40px;
        font-size: 24px;
    }

    .gallery-lightbox-close {
        width: 40px;
        height: 40px;
        font-size: 24px;
    }

    /* Couleur du titre d'événement pour matcher le fond countdown */
    .event-title {
        color: rgba(255,255,255,0.92) !important;
        text-shadow: none !important;
        -webkit-text-stroke: none !important;
    }
}

/* <= 480px : mêmes 2 colonnes mais espacement plus serré + boutons repositionnés */
@media (max-width: 480px) {
    .modern-gallery {
        grid-template-columns: repeat(2, 1fr);
        gap: 2px;
        grid-row-gap: 2px;
        width: 100%;
        margin: 0;
        padding: 0;
        align-items: start;
    }

    .gallery-container {
        padding: 0;
    }

    .event-title {
        color: rgba(255,255,255,0.92) !important;
        text-shadow: none !important;
        -webkit-text-stroke: none !important;
    }

    .gallery-lightbox-prev {
        left: 10px;
    }

    .gallery-lightbox-next {
        right: 10px;
    }

    .gallery-lightbox-close {
        top: 10px;
        right: 10px;
    }
}
