:root {
    --primary-color: #7b2657;
    --secondary-color: #9b1b51;
    --accent-color: #b31a47;
    --text-color: #2c3e50;
    --light-text: #7f8c8d;
    --bg-color: #ffffff;
    --white: #ffffff;
    --bg-secondary: #f8f9fa;
    --border-color: #dee2e6;
    --success-color: #27ae60;
    --error-color: #e74c3c;
    --warning-color: #f39c12;
    --info-color: #3498db;
    --shadow: 0 2px 10px rgba(0,0,0,0.1);
    --gradient: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
}

html, body {
    height: 100%;       /* occupe toute la hauteur de l'écran */
    display: flex;      
    flex-direction: column; /* empile header, main, footer */
}

/* Conteneur principal de la galerie */
.container h1 {
    text-align: center;
    margin-bottom: 2rem;
    color: var(--text-color);
    font-size: 2.5rem;
    font-weight: 700;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Liste des catégories - petites cartes */
.category-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 3rem;
    padding: 0 1rem;
}

/* Carte de catégorie compacte */
.category-item {
    background: var(--bg-color);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: all 0.3s ease;
    cursor: pointer;
    position: relative;
    border: 2px solid transparent;
    height: fit-content;
}

.category-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(123, 38, 87, 0.15);
    border-color: var(--primary-color);
}

.category-item.active {
    border-color: var(--primary-color);
    box-shadow: 0 8px 25px rgba(123, 38, 87, 0.2);
}

/* En-tête de la catégorie - compact */
.category-header {
    padding: 1.25rem;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, #f1f3f4 100%);
    border-bottom: 1px solid var(--border-color);
}

.category-item strong {
    display: block;
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

.category-item p {
    color: var(--light-text);
    font-size: 0.9rem;
    line-height: 1.3;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Conteneur des cartes de prévisualisation - horizontal */
.category-preview {
    position: relative;
    height: 100px;
    padding: 0.75rem;
    background: var(--bg-secondary);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
}

/* Petites cartes alignées horizontalement */
.preview-card {
    width: 70px;
    height: 70px;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
    cursor: pointer;
    flex-shrink: 0;
}

.preview-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.preview-card:hover img {
    transform: scale(1.1);
}

/* Animation au hover de la catégorie */
.category-item:hover .preview-card {
    transform: translateY(-2px);
}

.category-item:hover .preview-card:nth-child(1) {
    transform: translateY(-2px) scale(1.05);
}

.category-item:hover .preview-card:nth-child(2) {
    transform: translateY(-2px) scale(1.02);
}

.category-item:hover .preview-card:nth-child(3) {
    transform: translateY(-2px) scale(1.01);
}

/* Indicateur de nombre de photos - repositionné */
.photo-count {
    position: absolute;
    bottom: 8px;
    right: 12px;
    background: var(--primary-color);
    color: var(--white);
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    backdrop-filter: blur(4px);
}

/* État vide (pas de photos) */
.category-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100px;
    color: var(--light-text);
    font-style: italic;
    background: var(--bg-secondary);
}

.category-empty i {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}

.category-empty span {
    font-size: 0.85rem;
}

/* État de chargement de la prévisualisation */
.loading-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100px;
    color: var(--light-text);
}

.loading-preview .loading-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border-color);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 0.5rem;
}

.loading-preview span {
    font-size: 0.8rem;
}

/* Grid des photos (quand une catégorie est sélectionnée) */
.photos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
    padding: 0 1rem;
    margin-top: 2rem;
    margin-bottom: 50px;
}

.photos-grid.hidden {
    display: none;
}

main {
    flex: 1; /* pousse le footer en bas */
}

/* Photos individuelles dans la grid */
.photo-item {
    background: var(--white);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: all 0.3s ease;
    cursor: pointer;
}

.photo-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(123, 38, 87, 0.15);
}

.photo-item img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.photo-item:hover img {
    transform: scale(1.05);
}

.photo-info {
    padding: 1rem;
}

.photo-title {
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 0.5rem;
    font-size: 1.1rem;
}

.photo-credits {
    color: var(--light-text);
    font-size: 0.9rem;
    font-style: italic;
}

/* Bouton retour */
.back-button {
    display: inline-flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    background: var(--gradient);
    color: var(--white);
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 1.5rem;
    text-decoration: none;
}

.back-button:hover {
    background: linear-gradient(135deg, var(--secondary-color), var(--accent-color));
    transform: translateX(-2px);
}

.back-button i {
    margin-right: 0.5rem;
}

/* États de chargement */
.loading-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--light-text);
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-right: 1rem;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Header des photos avec bouton retour */
.photos-header {
    margin-bottom: 2rem;
    padding: 0 1rem;
}

.category-title {
    color: var(--text-color);
    font-size: 2rem;
    font-weight: 600;
    margin: 1rem 0;
    text-align: center;
    background: var(--gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* États d'erreur */
.error-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--error-color);
}

.error-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.7;
}

.error-state p {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
}

.retry-button {
    background: var(--primary-color);
    color: var(--white);
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.3s ease;
}

.retry-button:hover {
    background: var(--secondary-color);
}

/* Modal pour l'affichage des photos */
.photo-modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.9);
    animation: fadeIn 0.3s ease;
}

.photo-modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    position: relative;
    max-width: 90vw;
    max-height: 90vh;
    margin: auto;
    background: var(--white);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.modal-image {
    width: 100%;
    height: auto;
    display: block;
    max-height: 80vh;
    object-fit: contain;
    pointer-events: none;
    -webkit-user-drag: none;
    user-drag: none;
}

.modal-info {
    padding: 20px;
    background: var(--white);
    border-top: 1px solid var(--border-color);
}

.modal-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 8px;
}

.modal-credits {
    font-size: 14px;
    color: var(--light-text);
    font-style: italic;
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 20px;
    color: var(--white);
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    z-index: 1001;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
}

.close-modal:hover {
    background: var(--primary-color);
}

/* Container caché */
#photosContainer.hidden {
    display: none;
}

/* Responsive Design */

/* Tablettes */
@media (max-width: 768px) {
    .container h1 {
        font-size: 2rem;
        margin-bottom: 1.5rem;
    }
    
    .category-list {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
        gap: 1rem;
        padding: 0 0.5rem;
    }
    
    .category-header {
        padding: 1rem;
    }
    
    .category-item strong {
        font-size: 1.1rem;
    }
    
    .category-preview {
        height: 80px;
        padding: 0.5rem;
    }
    
    .preview-card {
        width: 60px;
        height: 60px;
    }
    
    .photos-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
        gap: 1rem;
        padding: 0 0.5rem;
    }
    
    .photo-item img {
        height: 150px;
    }
}

/* Mobiles */
@media (max-width: 480px) {
    .container h1 {
        font-size: 1.8rem;
        padding: 0 1rem;
    }
    
    .category-list {
        padding: 0;
        gap: 0.75rem;
        grid-template-columns: 1fr;
    }
    
    .category-item {
        margin: 0 0.5rem;
        border-radius: 10px;
    }
    
    .category-header {
        padding: 0.875rem;
    }
    
    .category-item strong {
        font-size: 1rem;
    }
    
    .category-item p {
        font-size: 0.85rem;
    }
    
    .category-preview {
        height: 70px;
        padding: 0.5rem;
        gap: 0.25rem;
    }
    
    .preview-card {
        width: 50px;
        height: 50px;
        border-radius: 6px;
    }
    
    .photo-count {
        bottom: 6px;
        right: 8px;
        font-size: 0.7rem;
        padding: 2px 6px;
    }
    
    .photos-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        padding: 0;
        margin: 1rem 0.5rem 0;
        margin-bottom: 40px;
    }
    
    .photo-item {
        border-radius: 8px;
    }
    
    .photo-item img {
        height: 120px;
    }
    
    .photo-info {
        padding: 0.75rem;
    }
    
    .photo-title {
        font-size: 1rem;
    }
    
    .photo-credits {
        font-size: 0.8rem;
    }
    
    .back-button {
        padding: 0.6rem 1.2rem;
        font-size: 0.9rem;
        margin: 0.5rem;
    }
    
    .category-title {
        font-size: 1.4rem;
    }
}

/* Très petits écrans */
@media (max-width: 320px) {
    .category-preview {
        height: 60px;
        gap: 0.2rem;
    }
    
    .preview-card {
        width: 45px;
        height: 45px;
    }
    
    .preview-card:nth-child(n+4) {
        display: none; /* Cache les cartes supplémentaires */
    }
    
    .photos-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}

/* Lightbox styles */
.lightbox {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox.hidden {
    display: none;
}

.lightbox-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
}

.lightbox-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.lightbox-image {
    max-width: 100%;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}

.lightbox-close {
    position: absolute;
    top: -40px;
    right: -40px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    font-size: 30px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-prev, .lightbox-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    font-size: 24px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-prev {
    left: -70px;
}

.lightbox-next {
    right: -70px;
}

.lightbox-prev:hover, .lightbox-next:hover, .lightbox-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.lightbox-info {
    margin-top: 20px;
    text-align: center;
    color: white;
    max-width: 500px;
}

.lightbox-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 8px;
}

.lightbox-credits {
    font-size: 14px;
    opacity: 0.8;
    margin-bottom: 8px;
}

.lightbox-counter {
    font-size: 14px;
    opacity: 0.6;
}

/* Style pour rendre les photos cliquables */
.photo-item {
    cursor: pointer;
    transition: transform 0.2s ease;
}

.photo-item:hover {
    transform: scale(1.02);
}

@media screen and (max-width: 768px) {
    .lightbox {
        padding: 15px;
    }
    
    .lightbox-image {
        max-height: calc(100vh - 120px);
    }
    
    .lightbox-close {
        width: 45px;
        height: 45px;
        font-size: 24px;
        top: 15px;
        right: 15px;
    }
    
    .lightbox-prev, .lightbox-next {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    
    .lightbox-prev {
        left: 15px;
    }
    
    .lightbox-next {
        right: 15px;
    }
    
    .lightbox-info {
        bottom: 15px;
        padding: 12px 16px;
        max-width: 85%;
    }
    
    .lightbox-title {
        font-size: 16px;
    }
    
    .lightbox-credits {
        font-size: 13px;
    }
    
    .lightbox-counter {
        font-size: 13px;
    }
}

/* Mobile (480px et moins) */
@media screen and (max-width: 480px) {
    .lightbox {
        padding: 10px;
    }
    
    .lightbox-image {
        max-height: calc(100vh - 100px);
        border-radius: 4px;
    }
    
    .lightbox-close {
        width: 40px;
        height: 40px;
        font-size: 20px;
        top: 10px;
        right: 10px;
    }
    
    .lightbox-prev, .lightbox-next {
        width: 45px;
        height: 45px;
        font-size: 18px;
    }
    
    .lightbox-prev {
        left: 10px;
    }
    
    .lightbox-next {
        right: 10px;
    }
    
    .lightbox-info {
        bottom: 10px;
        padding: 10px 12px;
        max-width: 90%;
        border-radius: 6px;
    }
    
    .lightbox-title {
        font-size: 14px;
        margin-bottom: 6px;
    }
    
    .lightbox-credits {
        font-size: 12px;
        margin-bottom: 6px;
    }
    
    .lightbox-counter {
        font-size: 12px;
    }
}

/* Très petits mobiles (360px et moins) */
@media screen and (max-width: 360px) {
    .lightbox {
        padding: 5px;
    }
    
    .lightbox-image {
        max-height: calc(100vh - 90px);
    }
    
    .lightbox-close {
        width: 35px;
        height: 35px;
        font-size: 18px;
        top: 5px;
        right: 5px;
    }
    
    .lightbox-prev, .lightbox-next {
        width: 40px;
        height: 40px;
        font-size: 16px;
    }
    
    .lightbox-prev {
        left: 5px;
    }
    
    .lightbox-next {
        right: 5px;
    }
    
    .lightbox-info {
        bottom: 5px;
        padding: 8px 10px;
        max-width: 95%;
    }
    
    .lightbox-title {
        font-size: 13px;
        margin-bottom: 4px;
    }
    
    .lightbox-credits {
        font-size: 11px;
        margin-bottom: 4px;
    }
    
    .lightbox-counter {
        font-size: 11px;
    }
}

/* Mode paysage sur mobile */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .lightbox {
        padding: 5px;
    }
    
    .lightbox-image {
        max-height: calc(100vh - 60px);
    }
    
    .lightbox-info {
        position: fixed;
        bottom: 5px;
        left: 50%;
        transform: translateX(-50%);
        padding: 6px 10px;
        font-size: 12px;
    }
    
    .lightbox-title {
        font-size: 12px;
        margin-bottom: 3px;
    }
    
    .lightbox-credits {
        font-size: 10px;
        margin-bottom: 3px;
    }
    
    .lightbox-counter {
        font-size: 10px;
    }
    
    .lightbox-close {
        width: 30px;
        height: 30px;
        font-size: 16px;
    }
    
    .lightbox-prev, .lightbox-next {
        width: 35px;
        height: 35px;
        font-size: 14px;
    }
}

/* Touch devices - Amélioration de la zone tactile */
@media (hover: none) and (pointer: coarse) {
    .lightbox-prev, .lightbox-next, .lightbox-close {
        min-width: 44px;
        min-height: 44px;
    }
    
    .lightbox-prev:active, .lightbox-next:active, .lightbox-close:active {
        background: rgba(255, 255, 255, 0.5);
        transform: scale(0.95);
    }
}