/**
 * Styles spécifiques à la galerie des cartes géoréférencées
 * Gestion de la sélection multiple et des interactions
 * 
 * ⚠️ NE PAS surcharger les styles DSFR des cards
 * Les cards utilisent uniquement les classes DSFR officielles
 */

/* ===== STYLES DE SÉLECTION UNIQUEMENT ===== */

/* Styles pour les cartes sélectionnables */
.selectable-card {
    position: relative;
    cursor: pointer;
    transition: all 0.2s ease;
}

.selectable-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transform: translateY(-1px);
}

.selectable-card.selected {
    box-shadow: 0 0 0 2px var(--blue-france-main-525);
    background-color: var(--blue-france-975-75);
}

/* Statistiques plus compactes */
.statistics-card {
    border: 1px solid var(--border-default-grey);
    border-radius: 6px; /* Coins moins arrondis */
    padding: 1rem; /* Réduit de 1.5rem à 1rem */
    text-align: center;
    background: white;
    transition: box-shadow 0.2s ease;
}

.statistics-card .statistic-value {
    font-size: 1.75rem; /* Réduit de 2rem à 1.75rem */
    font-weight: 700;
    color: var(--blue-france-main-525);
    margin-bottom: 0.25rem; /* Réduit de 0.5rem à 0.25rem */
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem; /* Réduit de 0.5rem à 0.375rem */
}

.statistics-card .statistic-label {
    font-size: 0.8rem; /* Réduit de 0.875rem à 0.8rem */
    color: var(--text-mention-grey);
    margin: 0;
}

/* Checkbox de sélection sur les cartes */
.selection-checkbox {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 20px;
    height: 20px;
    border: 2px solid #fff;
    border-radius: 4px;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 2;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.selectable-card:hover .selection-checkbox,
.selectable-card.selected .selection-checkbox {
    opacity: 1;
}

.selectable-card.selected .selection-checkbox {
    background-color: var(--blue-france-main-525);
    border-color: var(--blue-france-main-525);
}

.selectable-card.selected .selection-checkbox::after {
    content: '✓';
    color: white;
    font-size: 12px;
    font-weight: bold;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Styles pour les lignes de tableau sélectionnables */
.selectable-row {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.selectable-row:hover {
    background-color: var(--blue-france-975-75);
}

.selectable-row.selected {
    background-color: var(--blue-france-950-100);
}

.row-checkbox {
    cursor: pointer;
    margin: 0;
}

/* Barre d'outils de sélection */
.selection-toolbar {
    position: sticky;
    top: 0;
    z-index: 10;
    background: white;
    border-bottom: 1px solid var(--border-default-grey);
    padding: 0.75rem 0; /* Réduit de 1rem à 0.75rem */
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); /* Ombre plus subtile */
}

.selection-toolbar.hidden {
    display: none;
}

.selection-toolbar .selection-info {
    display: flex;
    align-items: center;
    gap: 0.75rem; /* Réduit de 1rem à 0.75rem */
    margin-bottom: 0;
    font-size: 0.9rem; /* Texte légèrement plus petit */
}

.selection-counter {
    background-color: var(--blue-france-main-525);
    color: white;
    padding: 0.2rem 0.6rem; /* Réduit le padding */
    border-radius: 0.75rem; /* Moins arrondi */
    font-size: 0.8rem; /* Réduit de 0.875rem à 0.8rem */
    font-weight: 600;
    min-width: 2rem; /* Largeur minimale pour l'équilibre */
    text-align: center;
}

/* Animations pour les transitions */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== STYLES POUR LES IMAGES (NON-DSFR) ===== */

/* Amélioration des images de cartes */
.card-image {
    transition: transform 0.3s ease;
    object-fit: cover;
    width: 100%;
}

.selectable-card:hover .card-image {
    transform: scale(1.05);
}

/* Styles responsifs pour la galerie */
@media (max-width: 768px) {
    .selection-toolbar .selection-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }
    
    .selection-toolbar .fr-btns-group {
        width: 100%;
        justify-content: space-between;
    }
    
    .selection-checkbox {
        width: 24px;
        height: 24px;
        top: 15px;
        right: 15px;
    }
}

/* États de chargement */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--blue-france-main-525);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Styles pour les statistiques */
.statistics-card {
    border: 1px solid var(--border-default-grey);
    border-radius: 8px;
    padding: 1.5rem;
    text-align: center;
    background: white;
    transition: box-shadow 0.2s ease;
}

.statistics-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.statistics-card .statistic-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--blue-france-main-525);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.statistics-card .statistic-label {
    font-size: 0.875rem;
    color: var(--text-mention-grey);
    margin: 0;
}

/* Améliorations pour les boutons d'action */
.fr-btns-group .fr-btn {
    white-space: nowrap;
}

.atlas-creation-btn {
    background: linear-gradient(135deg, var(--blue-france-main-525), var(--blue-france-sun-113));
    border: none;
    color: white !important;
    font-weight: 600;
    transition: all 0.3s ease;
}

.atlas-creation-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 119, 193, 0.3);
}

.atlas-creation-btn:disabled {
    background: var(--text-disabled-grey);
    transform: none;
    box-shadow: none;
}

/* Optimisations pour les petits écrans */
@media (max-width: 576px) {
    .fr-table {
        font-size: 0.875rem;
    }
    
    .fr-table td,
    .fr-table th {
        padding: 0.5rem 0.25rem;
    }
}

/* Amélioration de l'accessibilité */
.selectable-card:focus-visible,
.selectable-row:focus-visible {
    outline: 2px solid var(--blue-france-main-525);
    outline-offset: 2px;
}

/* Styles pour les messages d'état */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-mention-grey);
}

.empty-state .fr-icon--xl {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.error-state {
    text-align: center;
    padding: 2rem;
}

.error-state .fr-alert {
    max-width: 500px;
    margin: 0 auto;
}

/* Correction du layout principal pour éviter les débordements */
html, body {
    height: 100%;
    overflow-x: hidden;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    margin: 0;
    padding: 0;
}

.main-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Container principal avec hauteur flexible */
.fr-container {
    flex: 1;
    max-width: 100%;
    overflow-x: hidden;
    padding-left: 1rem;
    padding-right: 1rem;
}

/* Correction du footer pour qu'il reste en bas sans déborder */
.footer {
    position: relative !important;
    bottom: auto !important;
    margin-top: auto !important;
    width: 100% !important;
    box-sizing: border-box !important;
    flex-shrink: 0;
    overflow: hidden;
    padding: 0.5rem 1rem !important; /* Réduit de 0.75rem à 0.5rem */
    max-width: 100vw;
    height: auto !important; /* Permet au footer de s'adapter */
    min-height: 40px; /* Hauteur minimale réduite */
}

.footer p {
    margin: 0 !important;
    padding: 0 !important;
    word-wrap: break-word;
    overflow-wrap: break-word;
    line-height: 1.3; /* Réduit de 1.4 à 1.3 */
    max-width: 100%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px; /* Réduit de 4px à 3px */
    flex-wrap: wrap;
    font-size: 0.8rem; /* Réduit la taille de police */
}

/* Éviter les débordements horizontaux sur la page */
* {
    box-sizing: border-box;
}

.fr-grid-row {
    margin-left: 0 !important;
    margin-right: 0 !important;
    max-width: 100% !important;
    overflow-x: hidden;
}

.fr-col {
    padding-left: 0.5rem !important;
    padding-right: 0.5rem !important;
    max-width: 100%;
}

/* Styles pour la barre d'outils qui ne déborde pas */
.selection-toolbar {
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
    padding-left: 1rem;
    padding-right: 1rem;
}

.selection-toolbar .fr-container {
    max-width: none;
    padding: 0;
}

/* Responsive pour les logos du footer */
.footer-logo {
    max-height: 14px !important; /* Réduit de 16px à 14px */
    width: auto !important;
    flex-shrink: 0;
}

/* Icône cœur plus petite */
.heart-icon {
    width: 14px !important; /* Réduit de 16px à 14px */
    height: 14px !important;
    color: #e74c3c;
    vertical-align: middle;
}

/* Ajustements pour mobile */
@media (max-width: 768px) {
    .footer p {
        font-size: 0.7rem;
        gap: 2px;
        text-align: center;
    }
    
    .footer-logo {
        max-height: 12px !important;
    }
    
    .heart-icon {
        width: 12px !important;
        height: 12px !important;
    }
    
    .fr-container {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
    
    .card-image {
        height: 140px;
    }
    
    .selection-checkbox {
        width: 20px;
        height: 20px;
        top: 10px;
        right: 10px;
    }
    
    .selection-toolbar {
        padding: 0.5rem 0;
    }
    
    .selection-toolbar .selection-info {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
        font-size: 0.85rem;
    }
    
    .statistics-card .statistic-value {
        font-size: 1.5rem;
    }
}

/* Prévention des débordements pour tous les éléments */
.fr-table,
.selection-toolbar,
.statistics-card {
    max-width: 100%;
    overflow: hidden;
}

/* Tables responsives */
.fr-table {
    width: 100%;
    table-layout: fixed;
}

.fr-table td,
.fr-table th {
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* ===== STYLES SPÉCIFIQUES À LA PAGE GALERIE (de index.html) ===== */

/* Layout avec header et footer fixes */
html {
    height: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    height: auto; /* Changé pour permettre l'expansion */
    overflow-x: hidden; /* Seulement horizontal, pas vertical */
    overflow-y: auto; /* Permettre le scroll vertical */
    display: flex;
    flex-direction: column;
}

/* Header fixe */
.fr-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Styles pour le bouton utilisateur dans le header */
.user-menu-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    position: relative;
    z-index: 10001 !important;
}

.user-menu-toggle:hover {
    background-color: rgba(0, 172, 140, 0.1) !important;
}

.user-menu-toggle[data-fr-opened="true"] {
    background-color: #f5f5fe !important;
}

/* Menu déroulant utilisateur */
.user-dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    min-width: 280px;
    padding: 16px;
    z-index: 99999 !important;
    margin-top: 8px;
    display: none;
}

.user-info {
    margin-bottom: 12px;
}

.user-info p {
    margin: 4px 0;
    font-size: 14px;
    color: #333;
}

.user-info strong {
    color: #000091;
}

.user-dropdown-menu hr {
    border: none;
    border-top: 1px solid #eee;
    margin: 12px 0;
}

.user-menu-actions {
    list-style: none;
    padding: 0;
    margin: 0;
}

.user-menu-actions li {
    margin: 8px 0;
}

.user-menu-actions .fr-btn {
    width: 100%;
    text-align: left;
    justify-content: flex-start;
    background-color: transparent;
    color: #333;
    border: 1px solid #ddd;
}

.user-menu-actions .fr-btn:hover {
    background-color: #f5f5fe;
    color: #000091;
}

@media (max-width: 768px) {
    .user-dropdown-menu {
        right: -16px;
        min-width: 250px;
    }
}

/* Forcer le menu utilisateur au premier plan */
.fr-header__tools-links .user-dropdown-menu {
    z-index: 99999 !important;
    position: fixed !important;
}

/* Barre de sélection sticky sous le header */
.selection-toolbar {
    position: fixed;
    top: 80px; /* Hauteur approximative du header */
    left: 0;
    right: 0;
    background: #000091;
    color: white;
    padding: 1rem 0;
    z-index: 999;
    border-bottom: 2px solid #e5e5e5;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Zone de contenu scrollable */
.main-content-wrapper {
    flex: 1;
    overflow-y: auto;
    padding-top: 80px; /* Espace pour le header fixe */
    padding-bottom: 120px; /* Espace pour le footer fixe */
}

/* Ajustement quand la barre de sélection est visible */
.main-content-wrapper.with-selection-toolbar {
    padding-top: 140px; /* Header + barre de sélection */
}

/* Scrollbar personnalisée */
.main-content-wrapper::-webkit-scrollbar {
    width: 8px;
}

.main-content-wrapper::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.main-content-wrapper::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.main-content-wrapper::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Système de sélection */
.selection-bar {
    background: #f6f6f6;
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 2rem;
    display: none; /* Masqué par défaut */
}

.selection-bar.active {
    display: block;
}

.selection-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.selection-count {
    font-weight: bold;
    color: #000091;
}

.selection-actions {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.atlas-button {
    background: #000091;
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: background-color 0.3s ease;
}

.atlas-button:hover:not(:disabled) {
    background: #1212ff;
}

.atlas-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    opacity: 0.6;
}

/* Cartes sélectionnables */
.map-card {
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.map-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.map-card.selected {
    border: 2px solid #000091;
    box-shadow: 0 0 0 2px rgba(0, 0, 145, 0.2);
}

.map-card .selection-checkbox {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 4px;
    padding: 4px;
}

/* Lignes de tableau sélectionnables */
.table-row {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.table-row:hover {
    background-color: rgba(0, 0, 145, 0.1);
}

.table-row.selected {
    background-color: rgba(0, 0, 145, 0.2);
}

.search-container {
    margin-bottom: 2rem;
}

.view-toggle-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.cards-container {
    padding-right: 10px; /* Espace pour éviter le débordement */
    padding: 1rem;
}

.cards-container.hidden {
    display: none !important;
}

.table-container {
    padding: 1rem;
}

.table-container.hidden {
    display: none !important;
}

/* Style de la scrollbar principale */
body::-webkit-scrollbar {
    width: 10px;
}

body::-webkit-scrollbar-track {
    background: #f1f1f1;
}

body::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 5px;
}

body::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

.card-image {
    height: 200px;
    object-fit: cover;
}

.loading-spinner {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 300px;
}

.error-message {
    text-align: center;
    padding: 2rem;
}

.pagination-container {
    margin-top: 2rem;
    text-align: center;
}

.stats-container {
    margin-bottom: 1rem;
    padding: 1rem;
    background: #f6f6f6;
    border-radius: 4px;
}

.filter-container {
    margin-bottom: 2rem;
}

.version-info {
    font-size: 0.85em;
    color: #666;
}

/* Réajustement de la barre de sélection */
.selection-toolbar {
    position: sticky;
    top: 0;
    background: #000091;
    color: white;
    padding: 1rem 0;
    z-index: 1000;
    border-bottom: 2px solid #e5e5e5;
}

.toolbar-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.toolbar-actions {
    display: flex;
    gap: 1rem;
}

.selectable-item.selected {
    background: #f5f5fe;
}

/* Classe pour forcer le repaint */
.force-repaint {
    transform: translateZ(0);
}

/* ===== CORRECTION AFFICHAGE MODALES DSFR ===== */

/* S'assurer que les modales DSFR s'affichent correctement */
.fr-modal {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow-y: auto !important;
    z-index: 10000 !important;
}

.fr-modal[open] {
    display: flex !important;
}

/* Container de la modale doit aussi être scrollable */
.fr-modal .fr-container {
    max-height: none !important;
    overflow: visible !important;
}

/* Body de la modale scrollable */
.fr-modal__body {
    max-height: calc(100vh - 4rem) !important;
    overflow-y: auto !important;
}

/* Content de la modale */
.fr-modal__content {
    max-height: none !important;
    overflow: visible !important;
}

/* Correction pour le backdrop */
.fr-modal::backdrop {
    background-color: rgba(0, 0, 0, 0.5) !important;
}
