:root {
    --primary-blue: #0f81c7;
    --white: #ffffff;
    --hover-bg: #f5f8fa;
    --border-color: #e1e4e8;
}

* {
    margin: 0;
    padding: 0;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    color: #333;
    line-height: 1.6;
    background-color: #f8f9fa;
    overflow-x: hidden;
    width: 100%;
}

body.in-iframe {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding-top: 0; /* Supprimé pour éviter les conflits de positionnement */
    position: relative;
}

/* Carte avec transitions optimisées */
#map-container {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 200; /* Garantit que la carte reste au-dessus */
    background: transparent;
    padding: 1rem 0;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: none; /* Suppression de l'ombre qui peut créer des artefacts visuels */
    transition: all 0.3s ease-out; /* Transition fluide pour les changements de taille */
    will-change: transform; /* Optimisation des performances */
    backface-visibility: hidden; /* Évite les scintillements */
    transform: translateZ(0); /* Force l'accélération matérielle */
}

#map {
    height: 320px;
    width: 95%;
    max-width: 1400px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    margin: 0 auto;
    transition: height 0.3s ease-out; /* Transition douce pour les changements de hauteur */
    will-change: transform; /* Optimisation des performances */
}

/* Tableau */
.realisations-table {
    padding: 0;
    max-width: 1400px;
    margin: 0 auto;
    position: relative;
    z-index: 1;
    border: none;
    background: none;
    width: calc(100% - 40px);
}

.header-filter {
    display: block;
    width: 100%;
    max-width: 100%; /* Ajoute si manquant */
    margin-top: 0.3rem;
    padding: 0.4rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.85rem;
    background-color: var(--white);
}

.header-filter:hover {
    border-color: var(--primary-blue);
}

.header-filter:focus {
    outline: none;
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 2px rgba(15, 129, 199, 0.2);
}

.table-header table,
.table-content table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 0 0 12px 12px; /* Arrondi uniquement en bas */
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.table-header {
    position: fixed;
    width: 95%;
    max-width: 1400px;
    top: 352px; /* Position précise pour un espacement uniforme de 20px avec la carte */
    left: 50%;
    transform: translateX(-50%);
    z-index: 150;
    background-color: #0f81c7;
    border-radius: 12px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    overflow: hidden;
    margin: 0;
    padding: 0;
    border: none; /* Élimination de toute bordure potentielle */
    transition: top 0.3s ease;
}

.table-header table {
    margin: 0;
}

.table-header thead {
    background-color: #0f81c7;
}

/* Contenu du tableau avec espacement uniforme */
.table-content {
    position: fixed;
    top: 440px; /* Ajusté pour créer un espacement réellement égal au vu de la hauteur du bandeau */
    left: 50%;
    transform: translateX(-50%);
    z-index: 140;
    max-width: 1400px;
    width: 95%;
    padding: 0;
    margin: 0;
    border: none; /* Élimination de toute bordure potentielle */
    border-radius: 12px;
    overflow-y: auto;
    max-height: calc(100vh - 460px); /* Ajusté en fonction de la nouvelle position */
    background-color: white;
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
    transition: top 0.3s ease, max-height 0.3s ease;
}

.table-header th {
    padding: 0.6rem 1rem;
    color: white;
    font-weight: 500;
    text-align: left;
    white-space: nowrap;
}

.table-content td {
    padding: 0.3rem 1rem; /* Réduit davantage l'espacement vertical */
    border-bottom: 1px solid #dee2e6;
}

.table-content tr:hover {
    background-color: #f8f9fa;
    cursor: pointer;
}

.table-content tr.selected {
    background-color: #e9f4fb;
}

/* Filtres */
.filtres {
    display: flex;
    gap: 1rem;
    margin: 0 auto;
    margin-top: 12px;
    margin-bottom: 16px;
    padding: 10px 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    max-width: 1400px;
    box-sizing: border-box;
    width: 95%;
    justify-content: space-between;
}

.space-below-map {
  height: 16px; /* même que l'espace carte-bandeau */
}

/* === RESTORE BORDER-RADIUS for Desktop === */
@media (min-width: 768px) {
  .table-header {
    border-radius: 12px !important;
    overflow: hidden !important;
  }
}

select {
    flex: 1;
    padding: 0.75rem;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    background-color: white;
    font-family: inherit;
    font-size: 0.9rem;
    color: #495057;
    cursor: pointer;
    transition: all 0.2s ease;
    max-width: 100%;
    box-sizing: border-box;
    overflow-wrap: break-word;
}

select:hover {
    border-color: #0f81c7;
}

select:focus {
    outline: none;
    border-color: #0f81c7;
    box-shadow: 0 0 0 2px rgba(15,129,199,0.25);
}

/* Accordéon */
.accordion-header {
  display: flex;
  justify-content: flex-start;
  align-items: center;
  flex-wrap: nowrap;
  padding: 10px 36px 10px 12px;
  margin-bottom: 0;
  background-color: #f7f7f7;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(15,129,199,0.06);
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  font-size: 0.95em;
  font-weight: 400;
  transition: background 0.2s, box-shadow 0.2s;
  border: 1px solid #eaf3fb;
  position: relative; /* Pour le positionnement absolu de la flèche */
  max-width: 95%;
  margin: 0 auto 8px auto;
}

.toggle-arrow {
  margin-left: auto;
  transition: transform 0.3s ease;
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
}

.accordeon-actif .toggle-arrow {
  transform: rotate(90deg);
}

.accordion-content {
  display: none;
  padding: 8px 12px;
  background: #fff;
  border-left: 2px solid #0f81c7;
  margin-bottom: 4px;
  border-radius: 0 0 8px 8px;
  box-shadow: 0 1px 4px rgba(15,129,199,0.06);
  font-size: 0.9em;
  color: #222;
  animation: fadeIn 0.3s;
}

.accordion-content.active {
  display: table-cell;
  animation: slideDown 0.3s ease-out;
}

.commune-tag {
  margin-left: 1rem;
  padding: 4px 10px;
  background: #eaf3fb;
  border-radius: 12px;
  font-size: 0.8rem;
  color: #0f81c7;
}

.titre {
  font-weight: 500;
}

.metier {
  color: #666;
  margin-left: 1rem;
  max-width: 30%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.9em;
}

/* Ajuster la taille pour les métiers et services longs */
.accordion-header.long-text .metier,
.accordion-header.long-text .titre {
  font-size: 0.85em;
}

.type-intervention {
  font-size: 0.75rem;
  font-style: italic;
  color: #888;
  margin-top: 4px;
  margin-bottom: 8px;
  padding-left: 12px;
  display: block;
}

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

/* Message d'erreur et pas de résultats */
.error-message,
.no-results {
    padding: 2rem;
    text-align: center;
    color: #495057;
    background: white;
}

/* Responsive */
@media (max-width: 1024px) {
    .filtres {
        flex-wrap: wrap;
    }

    select {
        min-width: calc(50% - 0.5rem);
        flex: 0 0 calc(50% - 0.5rem);
    }
    
    .table-header {
        width: 100%;
        max-width: 1400px;
        padding: 0 1rem;
    }
}

/* Reset complet pour mobile */
@media (max-width: 768px) {
    html, body {
        padding: 0 !important;
        margin: 0 !important;
        overflow-x: hidden !important;
        width: 100% !important;
        max-width: 100vw !important;
    }
    
    .container {
        width: 100% !important;
        padding: 0 !important;
        margin: 0 !important;
        display: flex !important;
        flex-direction: column !important;
    }
    
    /* Carte adaptative */
    #map-container {
        position: relative;
        width: 100%;
        height: auto;
        padding: 0;
        margin: 0 0 8px 0;
        box-shadow: none;
    }
    
    #map {
        height: 200px;
        width: 100%;
        max-width: 100%;
        border-radius: 0; /* Sans bordures arrondies sur mobile */
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }
    
    /* Filtres et en-tête */
    .table-header {
        position: relative;
        width: 100%;
        max-width: 100%;
        left: 0;
        top: 0;
        transform: none;
        margin: 0;
        padding: 0;
        border-radius: 0;
    }
    
    .table-header table {
        width: 100%;
        border-radius: 0;
    }
    
    .table-header th {
        padding: 8px 4px;
        font-size: 14px;
    }
    
    .header-filter {
        width: 100%;
        font-size: 13px;
        padding: 6px 4px;
    }
    
    /* Contenu principal */
    .table-content {
        position: relative;
        width: 100%;
        max-width: 100%;
        top: 0;
        left: 0;
        transform: none;
        margin: 0;
        padding: 0;
        border-radius: 0;
        max-height: none;
        overflow-y: visible;
    }
    
    .table-content table {
        width: 100%;
        border-radius: 0;
    }
    
    /* Accordéons optimisés */
    .accordion-header {
        padding: 12px 36px 12px 8px;
        font-size: 14px;
        border-radius: 0;
        margin: 4px 0;
        width: 100%;
        box-sizing: border-box;
        display: flex;
        flex-wrap: wrap;
    }
    
    .titre {
        width: 100%;
        margin-bottom: 4px;
        font-size: 15px;
    }
    
    .metier {
        width: auto;
        margin: 0 8px 0 0;
        white-space: normal;
        font-size: 13px;
        max-width: 100%;
    }
    
    .commune-tag {
        margin: 4px 0 0 0;
        padding: 2px 8px;
        font-size: 12px;
    }
    
    .type-intervention {
        font-size: 11px;
        padding: 4px 8px;
        margin: 0;
    }
    
    /* Animation accordéon optimisée */
    .accordion-content.active {
        animation: slideDown 0.2s ease-out;
        padding: 8px;
    }
    
    /* Ajustements supplémentaires pour mobile */
    .accordion-content {
        padding: 6px 10px; /* Réduit espacement interne */
        margin-bottom: 3px; /* Réduit l'espace après le contenu */
        font-size: 13px;
    }
    
    /* Ajustements pour les filtres */
    .table-header th {
        font-size: 12px;
        padding: 8px 2px;
    }
    
    /* Optimisation des espaces */
    .toggle-arrow {
        right: 8px;
        font-size: 12px;
    }
    
    /* Espacement plus compact et meilleure ergonomie tactile */
    .accordion-header {
        margin: 6px 0;
        height: auto;
        min-height: 45px;
        display: flex;
        align-items: flex-start;
        flex-wrap: wrap;
    }
    
    /* Optimisation des filtres pour meilleure utilisation tactile */
    .header-filter {
        height: 38px;
        min-width: 100px;
        -webkit-appearance: none;
        appearance: none;
        background-image: url("data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23FFFFFF%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E");
        background-repeat: no-repeat;
        background-position: right 8px top 50%;
        background-size: 12px auto;
        padding-right: 24px;
    }
    
    /* Optimisation pour les appareils tactiles */
    .filtres {
        display: flex;
        flex-direction: column;
        gap: 8px;
        padding: 8px;
        margin-bottom: 12px;
    }
}
    
    .accordion-header {
        padding: 8px 24px 8px 10px;
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        align-items: center;
        flex-wrap: nowrap;
    }
    
    .titre {
        font-weight: 600;
        font-size: 0.8rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 35%;
        min-width: 0;
    }
    
    .metier {
        font-size: 0.75rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 25%;
        min-width: 0;
        margin-left: 5px;
    }
    
    .commune-tag {
        font-size: 0.7rem;
        padding: 2px 5px;
        margin-left: auto;
        margin-right: 12px;
        white-space: nowrap;
        max-width: 25%;
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    
    .toggle-arrow {
        position: absolute;
        right: 8px;
        top: 50%;
        transform: translateY(-50%);
    }
    
    .type-intervention {
        width: 100%;
        margin-left: 0;
        margin-top: 4px;
        margin-bottom: 4px;
        font-size: 0.75rem;
        color: #666;
        padding-left: 0;
        display: block;
        clear: both;
    }
    
    .filtres {
        flex-direction: column;
        padding: 0.5rem;
        gap: 0.5rem;
    }
    
    select {
        width: 100%;
    }

/* Optimisations pour très petits écrans */
@media (max-width: 600px) {
    .accordion-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .type-intervention {
        font-size: 0.75rem;
        padding-left: 0;
        margin-top: 4px;
        display: block;
        width: 100%;
    }

    .commune-tag, .metier, .titre {
        width: 100%;
        margin-bottom: 4px;
    }
}

@media (max-width: 480px) {
    .realisations-table {
        padding: 0 1rem 1rem;
    }

    .table-header th,
    .table-content td {
        padding: 0.75rem;
    }

    .filtres {
        flex-direction: column;
        padding: 1rem;
        gap: 0.75rem;
    }

    select {
        width: 100%;
        min-width: 100%;
        flex: none;
    }

    th, td {
        padding: 0.75rem;
        font-size: 0.9rem;
    }

    .description {
        padding: 1rem;
    }

    th {
        white-space: normal;
    }
}

/* Marqueur de carte */
.map-marker {
    background-color: #0f81c7;
    padding: 5px 10px;
    color: white;
    border-radius: 4px;
    font-size: 12px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Optimisations mobile spécifiques */
@media (max-width: 768px) {
  /* Positionnement pour la carte et le bandeau */
  #map-container {
    z-index: 200; /* Garantit que la carte reste au-dessus */
  }
  
  #map {
    height: 250px; /* Hauteur réduite sur mobile */
  }
  
  .table-header {
    top: 290px; /* Augmenté pour créer plus d'espace avec la carte sur mobile */
    z-index: 150;
    margin-top: 15px; /* Espacement supplémentaire sur mobile */
  }
  
  .table-content {
    top: 350px; /* Augmenté pour plus d'espace sous le bandeau sur mobile */
    z-index: 140;
    max-height: calc(100vh - 370px); /* Ajusté pour le défilement sur mobile */
    margin-top: 12px; /* Espacement supplémentaire */
  }

  /* Styles existants préservés */
  .filters {
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    margin-bottom: 24px;
  }

  .filters select {
    width: 100%;
    font-size: 0.95em;
  }

  .accordion-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .toggle-arrow {
    align-self: flex-end;
  }

  .commune-tag, .metier, .titre {
    font-size: 0.95em;
  }

  .accordion-content {
    font-size: 0.92em;
  }

  .realisations-container {
    padding: 0 12px;
  }
}

/* === RESTORE BORDER-RADIUS for Desktop === */
@media (min-width: 768px) {
  .table-header {
    border-radius: 12px !important;
    overflow: hidden !important;
  }
}

/* === DESKTOP ONLY: FORCE BORDER-RADIUS + FULL WIDTH sur .table-header === */
@media (min-width: 768px) {
  .table-header {
    border-radius: 12px !important;
    overflow: hidden !important;
    width: 100% !important;
    max-width: none !important;
  }
}

/* === Global styles communs === */
.table-header {
  width: 100% !important;
  max-width: 100% !important; 
}
