/* Polices & Global Styles */
body {
    font-family: 'DM Sans', sans-serif;
    background-color: #FFFFFF;
    color: #001414;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
}

html, body { max-width: 100%; overflow-x: hidden; }

/* Scroll lock quand une modale est ouverte */
body.modal-open {
    position: fixed;
    width: 100%;
    overflow: hidden;
}

h2 {
    font-family: 'Bricolage Grotesque', sans-serif;
    font-weight: 800; /* ExtraBold */
}

.logo-font {
    font-family: 'Bricolage Grotesque', sans-serif;
    font-weight: 800; /* ExtraBold */
}

/* Header */
header {
    background-color: #F1F1F1;
    padding: 20px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
}

header.transparent {
    background: transparent;
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    z-index: 10;
}

/* Fix iOS Safari rubber-band overscroll horizontal glitch */
@supports (-webkit-touch-callout: none) {
  body { overflow-x: hidden; }
}

header .logo {
    font-family: 'Bricolage Grotesque', sans-serif;
    font-weight: 800; /* ExtraBold */
    font-size: 28px;
    text-decoration: none;
    color: #001414;
    transition: color 0.2s ease-in-out;
}

header nav a {
    text-decoration: none;
    color: #001414;
    font-weight: 500;
    transition: color 0.2s ease-in-out;
}

header .logo:hover,
header nav a:hover {
    color: #008F8F;
}

/* Sur header transparent, le logo devient blanc au survol pour lisibilité sur le dégradé */
header.transparent .logo:hover {
    color: #FFFFFF;
}

/* Main Content */
main {
    width: 100%;
    max-width: 1200px;
    padding: 40px;
    box-sizing: border-box;
    flex-grow: 1;
}

/* Évite les débordements latéraux par défaut */
* { box-sizing: border-box; }

/* Hero section */
.hero {
    align-self: stretch;
    /* Dégradé vert (palette existante): top accent #008F8F vers bas #E9F6E9 */
    background: linear-gradient(180deg, #008F8F 0%, #27A6A6 35%, #E9F6E9 100%);
    color: #FFFFFF;
    border-radius: 0;
    padding: 120px 0 90px 0;
    margin: -72px 0 40px 0; /* remonte sous le header transparent (approx hauteur header) */
    position: relative;
    /* Par défaut: compense le padding du container */
    margin-left: -40px;
    margin-right: -40px;
}

.hero-inner {
    max-width: 1200px;
    width: 100%;
    padding: 0 40px; /* correspond au padding de main */
    margin: 0 auto;
}

.hero h1 {
    font-family: 'Bricolage Grotesque', sans-serif;
    font-weight: 800;
    font-size: clamp(32px, 6vw, 48px);
    line-height: 1.05;
    margin: 0 0 12px 0;
    word-break: normal;
    overflow-wrap: anywhere;
}

.hero p {
    margin: 0;
    font-size: clamp(16px, 2.6vw, 18px);
    line-height: 1.5;
    max-width: 720px;
}

@media (max-width: 767px) {
    .hero { padding: 120px 0 64px 0; margin-top: -64px; margin-left: -20px; margin-right: -20px; }
    .hero-inner { padding: 0 20px; }
}

/* Grand écrans: full-bleed sur toute la largeur du viewport */
@media (min-width: 1024px) {
  .hero {
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
  }
}

/* Callout */
.callout {
    background-color: #F1F1F1;
    border-radius: 8px;
    padding: 20px;
    margin: 0 auto 40px auto;
    max-width: 620px; /* 2 cards (300px each) + gap (20px) */
    box-sizing: border-box; /* To include padding in the width calculation */
    text-align: left;
}

.callout p {
    margin: 0;
    font-size: 1.1em;
    line-height: 1.5;
}

.callout .logo-font {
    font-size: 1.2em;
}

/* Dex List */
.dex-list {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 28px;
}

.card {
    position: relative;
    border-radius: 16px;
    padding: 0;
    text-decoration: none;
    color: #001414;
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    width: 300px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    cursor: pointer;
}

.card:hover,
.card:focus-visible {
    transform: translateY(-5px) scale(1.01);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}

.card:focus-visible {
    outline: 3px solid #008F8F;
    outline-offset: 2px;
}

.card img {
    display: block;
    width: 100%;
    height: 220px;
    object-fit: cover;
    border-radius: 16px 16px 0 0;
    margin: 0;
}

.card h2 {
    margin: 16px 20px 8px 20px;
    font-size: 1.5rem; /* retour à une taille plus sobre */
}

.card p {
    margin: 0 20px 20px 20px;
    font-size: 1rem; /* retour à la taille précédente */
}

.communodex-card {
    background-color: #E9F6E9;
}

/* Spacing wrapper for text below image */
.card .content {
    padding: 16px 20px 20px 20px;
}

.stationdex-card {
    background-color: #DAECFA;
}

/* Placeholders gris pour projets non publiés */
.placeholder-card {
    background: #F1F1F1;
}
.placeholder-thumb {
    display: block;
    width: 100%;
    height: 220px;
    background: #E0E0E0;
    border-radius: 16px 16px 0 0;
    border: 1px solid #D5D5D5;
    box-sizing: border-box;
}

/* Badge "Bientôt" */
.badge {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 12px;
    font-weight: 700;
    padding: 6px 8px;
    border-radius: 999px;
    border: 1px solid #000000;
}
.badge-soon { background: #FFFFFF; }

@media (min-width: 1024px) {
    .dex-list { gap: 32px; }
    .card { width: 320px; }
    .card img { height: 240px; }
}

@media (max-width: 767px) {
    .card img { height: 180px; }
}

/* ------------------- */
/* --- Communodex Page --- */
/* ------------------- */

.communodex-main {
    align-self: stretch;
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 30px;
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

/* Limiter la largeur des boutons sur desktop */
.page-actions .btn-add-capture {
    max-width: 280px;
}

.page-title h1 {
    font-family: 'Bricolage Grotesque', sans-serif;
    font-weight: 800;
    margin: 0;
    font-size: 2em;
}

.page-title p {
    margin: 0;
    color: #555;
}

.btn-add-capture {
    background-color: #E9F6E9;
    border: 1px solid #001414;
    border-radius: 999px;
    padding: 12px 18px;
    text-decoration: none;
    color: #001414;
    font-family: 'DM Sans', sans-serif;
    font-weight: 500; /* DM Sans Medium */
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: background-color 0.2s ease-in-out;
    white-space: nowrap;
    height: 44px;
    cursor: pointer;
}

.btn-add-capture:hover {
    background-color: #EDFBCC;
}

/* Stats Cards */
.stats-cards {
    display: grid;
    grid-template-columns: 1fr; /* mobile par défaut */
    gap: 20px;
    margin-bottom: 30px;
}

.stats-cards.group-2 { grid-template-columns: 1fr; }
.stats-cards.group-3 { grid-template-columns: 1fr; }

.stat-card {
    background-color: #E9F6E9; /* pastel comme la carte communodex */
    color: #001414; /* texte vert foncé */
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    box-sizing: border-box;
    width: 100%;
}

.stat-card .stat-title { margin: 0 0 6px 0; opacity: 0.9; color: #001414; }

.stat-card .stat-number {
    font-family: 'Bricolage Grotesque', sans-serif;
    font-weight: 800;
    font-size: clamp(20px, 6.5vw, 36px);
    line-height: 1;
    display: block;
}

.stat-subtext { display:block; opacity:0.9; margin-top:6px; color: #3a3a3a; }

.stat-composite { display:flex; flex-direction: column; }

/* Ajustement auto de la taille pour tenir sur une ligne */
.stat-value--fit {
    display: block;
    white-space: normal; /* autorise les retours à la ligne */
    overflow: visible;
    word-break: break-word;
    line-height: 1.15;
}

/* Ajustements mobiles pour la 2e ligne de stats afin d'aligner les tailles et largeurs */
@media (max-width: 767px) {
  .stats-cards.group-3 .stat-title { font-size: 1.05rem; }
  .stats-cards.group-3 .stat-number { font-size: clamp(16px, 5.5vw, 28px); }
  .stats-cards.group-3 .stat-subtext { font-size: 0.96rem; }
}

/* plus de section d'insights séparée: intégré dans stats-cards */

/* Stat card principale en vert foncé, texte blanc */
#total-captured-card {
    background: linear-gradient(180deg, #134B4C 0%, #008F8F 60%, #27A6A6 100%);
    color: #FFFFFF;
}
#total-captured-card .stat-title,
#total-captured-card .stat-number,
#total-captured-card .stat-subtext {
    color: #FFFFFF;
}

/* Cards cliquables (même effet que sur la page index) */
.stat-card.clickable {
    cursor: pointer;
    transition: transform 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
}
.stat-card.clickable:hover,
.stat-card.clickable:focus-visible {
    transform: translateY(-5px) scale(1.01);
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
.stat-card.clickable:focus-visible {
    outline: 3px solid #008F8F;
    outline-offset: 2px;
}

/* Divider */
hr.divider {
    border: 0;
    height: 1px;
    background-color: #1F2021;
    margin-bottom: 30px;
}

/* Participants cards */
.participants-cards {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
}

.participant-card {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 16px;
    background: #F1F1F1;
    border: 2px solid #E0E0E0;
    border-radius: 12px;
    padding: 16px 18px;
}

.participant-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #1F2021;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
}

.participant-meta { display: flex; flex-direction: column; row-gap: 6px; }
.participant-name { font-weight: 800; margin: 0 0 2px 0; }
.participant-sub { margin: 0; color: #3a3a3a; font-size: 0.96em; line-height: 1.5; }

.participant-stats { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
.participant-badge {
    background: #001414;
    color: #FFFFFF;
    border-radius: 8px;
    padding: 6px 10px;
    font-weight: 700;
}
.participant-badge.badge-solo {
    background: #FFFFFF;
    color: #001414;
    border: 1px solid #001414;
}

@media (min-width: 768px) {
  .participants-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1200px) {
  .participants-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* Regions progress list */
.regions-list { display: grid; grid-template-columns: 1fr; gap: 14px; }
.region-item { background: #F1F1F1; border: 1px solid #E0E0E0; border-radius: 10px; padding: 12px 14px; }
.region-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; margin-bottom: 8px; }
.region-name { margin: 0; font-weight: 700; }
.region-count { color: #3a3a3a; }
.progress {
    position: relative;
    width: 100%;
    height: 10px;
    background: #DAE0E0;
    border-radius: 999px;
    overflow: hidden;
}
.progress-bar {
    position: absolute;
    top: 0; left: 0; height: 100%;
    background: #134B4C;
}

@media (min-width: 768px) { .regions-list { grid-template-columns: 1fr 1fr; } }

/* Interactive Section */
.interactive-section {
    display: grid;
    grid-template-columns: 1fr; /* Default to single column for mobile */
    gap: 30px;
}

.search-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: #F1F1F1;
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 20px;
}

.search-bar input {
    border: none;
    outline: none;
    background: none;
    width: 100%;
    font-family: 'DM Sans', sans-serif;
    font-size: 1em;
}

#map {
    height: 50vh; /* Adjust height for mobile */
    min-height: 400px;
    width: 100%;
    background-color: #E9F6E9;
    border-radius: 8px;
    position: relative;
}

.map-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
    flex-wrap: wrap;
    gap: 8px;
}

.discreet-message {
    font-size: 0.8rem;
    color: #9A9A9A;
    margin: 0;
}

/* Switch (toggle) styles */
.switch {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
    position: relative;
    width: 48px; /* plus petit */
    height: 28px;
    background: #DAE0E0; /* off track */
    border-radius: 999px;
    border: 2px solid #A8A2AD; /* off border */
    box-shadow: inset 0 0 0 2px rgba(0,0,0,0.06);
    transition: background-color 0.2s ease, border-color 0.2s ease;
}
.switch-thumb {
    position: absolute;
    top: 50%;
    left: 3px;
    transform: translateY(-50%);
    width: 22px;
    height: 22px;
    background: #8E8996; /* off thumb */
    border-radius: 50%;
    transition: left 0.2s ease, background-color 0.2s ease;
}
.switch input:checked + .switch-track {
    background: #134B4C; /* on track */
    border-color: #134B4C;
}
.switch input:checked + .switch-track .switch-thumb {
    left: 23px;
    background: #FFFFFF; /* on thumb */
}
.switch-label { user-select: none; }
.switch { cursor: pointer; }

/* Loading overlay for map */
.loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    background: rgba(241,241,241,0.65);
    z-index: 3000;
    border-radius: 8px;
}
.spinner {
    width: 28px;
    height: 28px;
    border: 3px solid #134B4C;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.loading-text { margin-top: 8px; color: #134B4C; font-weight: 600; }
@keyframes spin { to { transform: rotate(360deg); } }

.info-card {
    background-color: #FFFFFF;
    border-radius: 8px;
    padding: 20px;
    border: 2px solid #E0E0E0; /* couleur ajustée dynamiquement */
}

.info-card h3 { margin-top: 0; }

/* Chips dans la fiche commune: non interactifs */
.info-card .chip {
    cursor: default;
    pointer-events: none;
    transition: none;
}

.info-card .chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px;
}

/* Suggestions dropdown */
.suggestions {
    position: absolute;
    background: #FFFFFF;
    border: 1px solid #E0E0E0;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    border-radius: 8px;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    margin-top: 0;
    width: 100%;
    max-height: 260px;
    overflow: auto;
    z-index: 5000; /* au-dessus des contrôles Leaflet */
}

.suggestions .item {
    padding: 10px 12px;
    cursor: pointer;
}
.suggestions .item:hover { background: #EDFBCC; }
.suggestions .item.active { background: #EDFBCC; }

.search-bar { position: relative; }

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 4000; /* au-dessus de Leaflet */
    overscroll-behavior: contain; /* éviter le scroll chain vers le body */
}

.modal-content {
    background: #FFFFFF;
    border-radius: 12px;
    padding: 24px;
    width: 100%;
    max-width: 640px;
    position: relative;
    max-height: 85vh; /* le contenu scroll à l'intérieur */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Bottom sheet (mobile) */
@media (max-width: 767px) {
  .modal {
    align-items: stretch; /* occupe toute la hauteur écran */
    padding: 0; /* pas de marges autour de la sheet */
  }
  .modal .modal-content {
    width: 100vw;
    max-width: 100vw;
    height: 100vh; /* fallback */
    height: 100dvh; /* plein écran mobile stable */
    max-height: 100dvh;
    border-radius: 0; /* pas coupée en haut/bas */
    margin: 0;
    transform: translateY(100%);
    transition: transform 220ms ease-out;
    overflow-y: auto; /* scroll interne */
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    padding-top: calc(24px + env(safe-area-inset-top, 0px));
  }
  .modal.is-open .modal-content {
    transform: translateY(0);
  }
}

.modal-close {
    position: absolute;
    right: 12px;
    top: 12px;
    border: none;
    background: transparent;
    font-size: 22px;
    cursor: pointer;
}

.modal-search { margin-bottom: 10px; }

/* Form modal vertical layout & spacing */
#add-capture-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

#add-capture-form label {
    font-weight: 600;
}

/* Asterix rouge sur les labels requis */
#add-capture-form label::after {
    content: ' *';
    color: #D33;
}

#add-capture-form input[type="date"],
#add-capture-form textarea {
    font-family: 'DM Sans', sans-serif;
    border: 1px solid #E0E0E0;
    border-radius: 8px;
    padding: 10px 12px;
}

#add-capture-form textarea { resize: vertical; }

.participants-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    margin: 10px 0 16px;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border-radius: 24px;
    padding: 8px 12px;
    border: 1px solid #E0E0E0;
    color: #001414;
    background: #FFFFFF;
    cursor: pointer;
    transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}
.chip .check { display:none; font-weight:700; }

.chip:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(0,143,143,0.35);
}

/* Styles actifs (sélectionné) */
.chip.active.chip-sim { background: #FFC72C; border-color: #FFC72C; }
.chip.active.chip-sach { background: #0E4A73; border-color: #0E4A73; color:#FFFFFF; }
.chip.active.chip-math { background: #1976D2; border-color: #1976D2; color:#FFFFFF; }
.chip.active.chip-hippo { background: #005B5B; border-color: #005B5B; color:#FFFFFF; }
.chip.active.chip-fio { background: #7A0B16; border-color: #7A0B16; color:#FFFFFF; }
.chip.active.chip-boco { background: #85B6E9; border-color: #85B6E9; }
.chip.active .check { display:inline; }

.btn-primary {
    width: 100%;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    background: #134B4C; /* défaut */
    color: #F4FFD6; /* texte crème */
    padding: 14px 20px;
    border: 1px solid #134B4C;
    border-radius: 999px;
    font-family: 'DM Sans', sans-serif;
    font-weight: 500;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.02s ease;
}
.btn-primary:hover { background: #0F3B3C; border-color: #0F3B3C; }
.btn-primary:active { transform: translateY(1px); }

/* Rendre le bouton "Ajouter des captures" primaire (plus foncé) */
#open-add-capture.btn-add-capture {
    background: #134B4C;
    color: #F4FFD6;
    border-color: #134B4C;
}
#open-add-capture.btn-add-capture:hover {
    background: #0F3B3C;
    border-color: #0F3B3C;
}

.feedback { margin-top: 12px; color: #008F8F; }
.feedback.error { color: #D33; }
.feedback.success { color: #008F8F; }

/* How-it-works modal rules spacing */
.rules p { margin: 0 0 14px 0; line-height: 1.6; }
.rules ul { margin: 0 0 18px 24px; padding: 0; list-style: disc; }
.rules li { margin: 8px 0; }
.rules ul ul { list-style: circle; margin-top: 8px; }

/* tiny dot markers */
.dot-marker span {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 1px solid #1F2021;
}

/* Clusters labels */
.cluster-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: #fff;
    font-weight: 800;
    font-family: 'Bricolage Grotesque', sans-serif;
    border: 1px solid #1F2021;
}

/* ------------------- */
/* --- Responsive --- */
/* ------------------- */

@media (min-width: 768px) {
    .interactive-section {
        grid-template-columns: 2fr 1fr; /* 2 columns layout for tablets and up */
    }

    #map {
        height: 600px; /* Restore desktop height */
    }
}

@media (max-width: 767px) {
    main {
        padding: 20px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .stats-cards {
        grid-template-columns: 1fr; /* 1 par ligne sur mobile */
    }
}

/* medium: 2 colonnes */
@media (min-width: 768px) {
  .stats-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  /* Aligner la 2e ligne sur les mêmes règles que la 1re à ce palier */
  .stats-cards.group-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* large: 4 colonnes */
@media (min-width: 1200px) {
  .stats-cards {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .stats-cards.group-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* 2e ligne: passe à 3 colonnes uniquement à partir de 1200px */
  .stats-cards.group-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .page-actions .btn-add-capture { min-width: 0; }
}

@media (max-width: 480px) {
    .map-toolbar {
        justify-content: center;
    }
}

/* boutons: même largeur sur mobile/tablette, ils s'empilent */
@media (max-width: 767px) {
  .page-actions { width: 100%; }
  .page-actions { flex-direction: column; }
  .page-actions .btn-add-capture { width: 100%; max-width: none; min-width: 0; justify-content: center; }
}
