/* --- Couleurs (mode clair, puis mode sombre) -------------------------------- */

:root {
  color-scheme: light;
  --fond-page: #f9f9f7;
  --fond-carte: #fcfcfb;
  --texte: #0b0b0b;
  --texte-secondaire: #52514e;
  --texte-discret: #898781;
  --grille: #e1e0d9;
  --axe: #c3c2b7;
  --bordure: rgba(11, 11, 11, 0.10);
  --serie-1: #2a78d6;      /* créations, entreprises actives */
  --serie-2: #eb6834;      /* fermetures */
  --serie-3: #1baf7a;
  --serie-4: #eda100;
  --serie-5: #e87ba4;
  --serie-6: #008300;
  --serie-7: #4a3aa7;
  --neutre: #b4b2a9;       /* « toutes activités », comparaison */
  /* échelle bleue (peu → beaucoup) */
  --seq-1: #cde2fb; --seq-2: #9ec5f4; --seq-3: #6da7ec; --seq-4: #3987e5; --seq-5: #256abf; --seq-6: #104281;
  /* échelle baisse (rouge) ↔ hausse (bleu), gris au milieu */
  --div-baisse-forte: #d03b3b; --div-baisse: #f2a7a5; --div-stable: #c9c7bf; --vide: #f3f2ee; --div-hausse: #9ec5f4; --div-hausse-forte: #2a78d6;
  --hausse: #0ca30c;
  --baisse: #d03b3b;
  --stable: #898781;
  --alerte-fond: #fff4dc;
  --alerte-bord: #fab219;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --fond-page: #0d0d0d;
    --fond-carte: #1a1a19;
    --texte: #ffffff;
    --texte-secondaire: #c3c2b7;
    --texte-discret: #898781;
    --grille: #2c2c2a;
    --axe: #383835;
    --bordure: rgba(255, 255, 255, 0.10);
    --serie-1: #3987e5;
    --serie-2: #d95926;
    --serie-3: #199e70;
    --serie-4: #c98500;
    --serie-5: #d55181;
    --serie-6: #008300;
    --serie-7: #9085e9;
    --neutre: #6b6a64;
    --seq-1: #16365e; --seq-2: #184f95; --seq-3: #256abf; --seq-4: #3987e5; --seq-5: #6da7ec; --seq-6: #b7d3f6;
    --div-baisse-forte: #e66767; --div-baisse: #7a3434; --div-stable: #55544f; --vide: #242422; --div-hausse: #1d4f8c; --div-hausse-forte: #5598e7;
    --alerte-fond: #2e2410;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --fond-page: #0d0d0d;
  --fond-carte: #1a1a19;
  --texte: #ffffff;
  --texte-secondaire: #c3c2b7;
  --texte-discret: #898781;
  --grille: #2c2c2a;
  --axe: #383835;
  --bordure: rgba(255, 255, 255, 0.10);
  --serie-1: #3987e5;
  --serie-2: #d95926;
  --serie-3: #199e70;
  --serie-4: #c98500;
  --serie-5: #d55181;
  --serie-6: #008300;
  --serie-7: #9085e9;
  --neutre: #6b6a64;
  --seq-1: #16365e; --seq-2: #184f95; --seq-3: #256abf; --seq-4: #3987e5; --seq-5: #6da7ec; --seq-6: #b7d3f6;
  --div-baisse-forte: #e66767; --div-baisse: #7a3434; --div-stable: #55544f; --vide: #242422; --div-hausse: #1d4f8c; --div-hausse-forte: #5598e7;
  --alerte-fond: #2e2410;
}

/* --- Mise en page ------------------------------------------------------------ */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--fond-page);
  color: var(--texte);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}

.conteneur {
  max-width: 1040px;
  margin: 0 auto;
  padding: 0 16px;
}

.entete {
  border-bottom: 1px solid var(--bordure);
  background: var(--fond-carte);
}
.entete .conteneur {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
  padding-top: 14px;
  padding-bottom: 14px;
}
.marque { margin: 0; font-weight: 700; font-size: 1.15rem; }
.accroche { margin: 0; color: var(--texte-secondaire); }

h1 { font-size: 1.6rem; margin: 0 0 4px; line-height: 1.25; }
h2 { font-size: 1rem; margin: 0; }
h3 { font-size: 0.9rem; margin: 16px 0 4px; color: var(--texte-secondaire); }
.secondaire { color: var(--texte-secondaire); margin: 0; }

/* Filtres */
.filtres {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 24px;
  margin: 24px 0;
}
.champ { display: flex; flex-direction: column; gap: 4px; }
.champ-recherche { flex: 2 1 320px; }
.champ-zone { flex: 1 1 220px; }
.champ label { font-size: 0.85rem; color: var(--texte-secondaire); }
input[type="search"], select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--axe);
  border-radius: 8px;
  background: var(--fond-carte);
  color: var(--texte);
  width: 100%;
}
input[type="search"] { font-size: 1.05rem; padding: 10px 12px; border-color: var(--texte-discret); }
input[type="search"]:focus, select:focus { outline: 2px solid var(--serie-1); outline-offset: 1px; }

/* Suggestions de la recherche */
.boite-recherche { position: relative; }
.suggestions {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  margin: 0;
  padding: 4px;
  list-style: none;
  background: var(--fond-carte);
  border: 1px solid var(--axe);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  max-height: 70vh;
  overflow-y: auto;
}
.suggestions li { padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.suggestions li[aria-selected="true"], .suggestions li:hover { background: var(--grille); }
.suggestions li.vide { cursor: default; color: var(--texte-secondaire); }
.suggestions li.vide:hover { background: none; }
.sugg-ligne { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.sugg-libelle { font-weight: 600; }
.sugg-code { font-size: 0.8rem; color: var(--texte-secondaire); white-space: nowrap; font-variant-numeric: tabular-nums; }
.sugg-extrait, .sugg-nombre { display: block; font-size: 0.85rem; color: var(--texte-secondaire); }
.sugg-extrait {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

/* Accueil */
.accueil { padding: 24px 0 48px; max-width: 68ch; }
.exemples { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }
.exemple {
  font: inherit;
  font-size: 0.9rem;
  padding: 4px 12px;
  border: 1px solid var(--axe);
  border-radius: 999px;
  background: var(--fond-carte);
  color: var(--texte);
  cursor: pointer;
}
.exemple:hover { border-color: var(--serie-1); }

/* Accueil : secteurs en plus forte progression / plus fort déclin (France entière) */
.palmares { margin: 8px 0 48px; }
.colonnes-palmares {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 400px), 1fr));
  gap: 16px;
  margin-top: 16px;
}
.titre-palmares { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; font-size: 1rem; color: var(--texte); }
.liste-palmares { list-style: none; margin: 0; padding: 0; }
.liste-palmares li {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--palmares-trait);
}
.liste-palmares li:first-child { border-top: 0; }
.palmares-libelle { margin: 0; font-weight: 600; line-height: 1.3; }
.palmares-detail { margin: 2px 0 0; font-size: 0.8rem; color: var(--texte-secondaire); }
.palmares-evolution { font-weight: 700; white-space: nowrap; }
.carte.carte-hausse { background: var(--palmares-hausse-fond); }
.carte.carte-baisse { background: var(--palmares-baisse-fond); }
.palmares-evolution.hausse { color: var(--palmares-hausse-texte); }
.palmares-evolution.baisse { color: var(--palmares-baisse-texte); }
.carte-baisse .icone-verdict.baisse { background: var(--palmares-baisse-icone); }
.bouton-voir {
  font: inherit;
  font-size: 0.85rem;
  padding: 4px 12px;
  border: 1px solid var(--axe);
  border-radius: 999px;
  background: var(--fond-carte);
  color: var(--texte);
  cursor: pointer;
  white-space: nowrap;
}
.bouton-voir:hover { border-color: var(--serie-1); }
@media (max-width: 520px) {
  .liste-palmares li { grid-template-columns: 1fr auto; }
  .liste-palmares .bouton-voir { grid-column: 1 / -1; justify-self: start; }
}

/* Ce que regroupe le secteur */
.perimetre { margin-bottom: 16px; }
.perimetre ul { margin: 8px 0 0; padding-left: 20px; columns: 2 320px; column-gap: 32px; }
.perimetre li { margin-bottom: 4px; break-inside: avoid; }
.perimetre details { margin-top: 12px; }
.perimetre summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.perimetre .lien-code {
  font: inherit;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}
.petit { font-size: 0.85rem; margin-top: 4px; }

.titre-secteur { margin-bottom: 16px; }

/* Messages */
.erreur, .alerte {
  padding: 12px 16px;
  border-radius: 8px;
  margin: 0 0 16px;
}
.erreur { border: 1px solid var(--baisse); }
.alerte { background: var(--alerte-fond); border-left: 4px solid var(--alerte-bord); }
/* Rappel « siège social » (région, département) : informatif, moins appuyé que l'alerte */
.rappel {
  margin-bottom: 16px;
  padding: 12px 16px;
  border-left: 4px solid var(--accent, var(--serie-1));
  border-radius: 8px;
  background: var(--accent-doux, var(--fond-carte));
  font-size: 0.92rem;
}

/* Tuiles de chiffres clés */
.tuiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.tuile, .carte {
  background: var(--fond-carte);
  border: 1px solid var(--bordure);
  border-radius: 12px;
  padding: 16px;
}
.tuile p { margin: 0; }
.tuile-libelle { font-size: 0.85rem; color: var(--texte-secondaire); }
.tuile-valeur { font-size: 1.75rem; font-weight: 600; line-height: 1.3; }
.tuile-detail { font-size: 0.85rem; color: var(--texte-secondaire); }
.verdict { font-size: 1.5rem; font-weight: 600; line-height: 1.4; display: flex; align-items: center; gap: 8px; }
.icone-verdict {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #ffffff;
  font-size: 1rem;
}
.icone-verdict.hausse { background: var(--hausse); }
.icone-verdict.baisse { background: var(--baisse); }
.icone-verdict.stable { background: var(--stable); }

.commentaire { font-size: 1.05rem; margin: 0 0 24px; max-width: 72ch; }

/* Graphiques */
.graphiques {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
figure { margin: 0; }
figcaption {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px 16px;
  margin-bottom: 12px;
}
.zone-graphique { position: relative; height: 260px; }
.note-source { font-size: 0.8rem; color: var(--texte-secondaire); margin: 12px 0 0; }

.legende { display: flex; gap: 16px; list-style: none; margin: 0; padding: 0; font-size: 0.85rem; color: var(--texte-secondaire); }
.legende li { display: flex; align-items: center; gap: 6px; }
.pastille { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.pastille-1 { background: var(--serie-1); }
.pastille-2 { background: var(--serie-2); }

/* Tableau */
.tableau-details { margin-bottom: 16px; }
.tableau-details summary { cursor: pointer; font-weight: 600; }
.tableau-defilant { overflow-x: auto; margin-top: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--grille); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-weight: 600; color: var(--texte-secondaire); }
td { font-variant-numeric: tabular-nums; }

/* Sources et limites */
.sources { margin-bottom: 40px; }
.sources ul { margin: 0; padding-left: 20px; }
.sources li { margin-bottom: 4px; }
.sources a { color: inherit; }
#date-calcul { margin-top: 16px; font-size: 0.85rem; }

/* --- Blocs du secteur ------------------------------------------------------------ */

.bloc { margin: 32px 0 16px; }
.titre-bloc { font-size: 1.25rem; margin: 0 0 12px; }
figcaption h3, .carte h3 { font-size: 1rem; margin: 0; color: var(--texte); }
.zone-basse { height: 200px; }

/* Portrait : barres empilées à 100 % */
.portrait { display: flex; flex-direction: column; gap: 18px; }
.portrait-titre { font-size: 0.85rem; color: var(--texte-secondaire); margin: 0 0 6px; }
.legende-empilee { display: flex; flex-wrap: wrap; gap: 4px 14px; list-style: none; margin: 8px 0 0; padding: 0; font-size: 0.8rem; color: var(--texte-secondaire); }
.legende-empilee li { display: flex; align-items: center; gap: 6px; }
.legende-empilee strong { color: var(--texte); font-weight: 600; }
.portrait-phrase { font-size: 0.9rem; margin: 0; }

/* Carte */
.choix-indicateur { display: inline-flex; border: 1px solid var(--axe); border-radius: 8px; overflow: hidden; }
.choix-indicateur button {
  font: inherit; font-size: 0.85rem; padding: 6px 12px; border: 0; background: var(--fond-carte);
  color: var(--texte-secondaire); cursor: pointer;
}
.choix-indicateur button[aria-checked="true"] { background: var(--texte); color: var(--fond-carte); }
.legende-carte { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; font-size: 0.8rem; color: var(--texte-secondaire); }
.legende-carte span { display: inline-flex; align-items: center; gap: 5px; }
.legende-carte i { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.conteneur-carte { position: relative; max-width: 640px; margin: 0 auto; }
#carte-departements { width: 100%; height: auto; display: block; }
#carte-departements path { stroke: var(--fond-carte); stroke-width: 0.6; cursor: pointer; }
#carte-departements path:hover { stroke: var(--texte); stroke-width: 1.2; }
#carte-departements path.choisi { stroke: var(--texte); stroke-width: 2; }
#carte-departements rect { fill: none; stroke: var(--grille); }
#carte-departements text { fill: var(--texte-discret); font-size: 9px; }
.infobulle {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--fond-carte); color: var(--texte); border: 1px solid var(--axe); border-radius: 8px;
  padding: 8px 10px; font-size: 0.85rem; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12); white-space: nowrap;
}
.infobulle strong { display: block; }

/* Dans ma ville */
.resultat-ville { margin-top: 16px; }
.resultat-ville h3 { margin-bottom: 4px; }
.comparaison-ville { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin: 12px 0 0; }
.comparaison-ville div { border: 1px solid var(--bordure); border-radius: 8px; padding: 10px 12px; }
.comparaison-ville dt { font-size: 0.8rem; color: var(--texte-secondaire); }
.comparaison-ville dd { margin: 2px 0 0; font-size: 1.3rem; font-weight: 600; }
.comparaison-ville dd small { display: block; font-size: 0.8rem; font-weight: 400; color: var(--texte-secondaire); }

/* Petits chiffres au-dessus d'un graphique */
.mini-chiffres { display: flex; flex-wrap: wrap; gap: 8px 24px; margin: 8px 0 12px; }
.mini-chiffres dt { font-size: 0.8rem; color: var(--texte-secondaire); }
.mini-chiffres dd { margin: 0; font-size: 1.15rem; font-weight: 600; }
.mini-chiffres dd small { font-size: 0.8rem; font-weight: 400; color: var(--texte-secondaire); }

/* Portrait : trois camemberts côte à côte (empilés sur téléphone) */
.graphiques.pleine-largeur { grid-template-columns: 1fr; }
.camemberts { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 24px; }
.portrait-groupe { display: flex; flex-direction: column; }
.zone-camembert { position: relative; height: 170px; margin: 4px 0 8px; }

/* Icône « ? » d'explication et sa bulle */
.aide {
  display: inline-grid; place-items: center; vertical-align: middle;
  width: 16px; height: 16px; margin-left: 5px; padding: 0;
  border: 1px solid var(--texte-discret); border-radius: 50%;
  background: none; color: var(--texte-secondaire);
  font: 600 10px/1 system-ui, -apple-system, "Segoe UI", sans-serif; cursor: help;
}
.aide:hover, .aide:focus-visible, .aide[aria-expanded="true"] { border-color: var(--serie-1); color: var(--serie-1); outline: none; }
.bulle-aide {
  position: fixed; z-index: 50; max-width: min(320px, calc(100vw - 32px));
  background: var(--fond-carte); color: var(--texte); border: 1px solid var(--axe); border-radius: 8px;
  padding: 10px 12px; font-size: 0.85rem; line-height: 1.45; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  pointer-events: none;
}

/* Case à cocher sous un titre de graphique */
.case-a-cocher { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--texte-secondaire); cursor: pointer; margin: -2px 0 4px; }
.case-a-cocher input { accent-color: var(--serie-1); margin: 0; }
.ligne-case { display: flex; align-items: center; margin: -2px 0 4px; }
.ligne-case .case-a-cocher { margin: 0; }

/* Marque (logo + nom) : lien vers l'accueil */
.marque { color: inherit; text-decoration: none; display: inline-flex; align-items: center; gap: 8px; }

/* Sources et limites : bloc repliable */
.sources > summary { cursor: pointer; list-style: none; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; }
.sources > summary::-webkit-details-marker { display: none; }
.sources > summary::before { content: "▸"; color: var(--texte-secondaire); transition: transform 0.15s; }
.sources[open] > summary::before { transform: rotate(90deg); }
.sources > summary #titre-sources { font-weight: 700; font-size: 1.05rem; }
.sources[open] > summary { margin-bottom: 8px; }
.sources-pdf { display: none; }
