/* BCE · orvo — feuille de style commune
   Thème sombre par défaut (:root). Le clair s'active via [data-theme="light"],
   posé par le script inline du <head>. Contrastes vérifiés WCAG AA/AAA. */

:root {
  /* ---- SOMBRE (défaut) ---- */
  --bg:      #131518;
  --panel:   #1d2025;
  --panel-2: #23272d;
  --ink:     #eceef0;   /* 14.0:1 sur panel */
  --dim:     #adb4bd;   /*  7.8:1 */
  --faint:   #8b929c;   /*  5.2:1 */
  --line:    #2b2f36;
  --line-2:  #3e444d;
  --accent:  #79b4dc;   /*  7.3:1 */
  --accent-w:#1b2c39;
  --danger:  #ef9084;   /*  7.0:1 */
  --danger-w:#33201d;
  --warn:    #e0b355;   /*  8.4:1 */
  --warn-w:  #2e2513;
  --ok:      #84c39c;   /*  8.0:1 */
  --ok-w:    #17291f;
  --shadow:  0 1px 3px rgba(0,0,0,.45);
  --radius:  7px;
  --mono:    ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

:root[data-theme="light"] {
  /* ---- CLAIR (contrastes renforcés) ---- */
  --bg:      #f1f1ee;
  --panel:   #ffffff;
  --panel-2: #f7f7f4;
  --ink:     #111318;   /* 18.6:1 sur panel */
  --dim:     #4c515a;   /*  8.0:1 */
  --faint:   #666c76;   /*  5.3:1 */
  --line:    #dcdcd6;
  --line-2:  #c2c2bc;
  --accent:  #12547e;   /*  8.1:1 */
  --accent-w:#e4eef6;
  --danger:  #8f2b22;   /*  8.3:1 */
  --danger-w:#fae9e7;
  --warn:    #71510f;   /*  7.3:1 */
  --warn-w:  #faf1dc;
  --ok:      #245c3b;   /*  7.9:1 */
  --ok-w:    #e2f1e8;
  --shadow:  0 1px 3px rgba(0,0,0,.10);
  color-scheme: light;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { background: var(--bg); }

body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------------------------------------------------- barre haute */
.topbar {
  display: flex; align-items: center; gap: 22px;
  padding: 0 20px; height: 52px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 900;
  flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: -.02em; font-size: 16px; color: var(--ink); }
.brand span { color: var(--accent); margin: 0 2px; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  padding: 6px 11px; border-radius: 6px; color: var(--dim);
  font-size: 14px; font-weight: 500;
}
.topbar nav a:hover { background: var(--panel-2); text-decoration: none; color: var(--ink); }
.topbar nav a.on { background: var(--accent-w); color: var(--accent); }
.freshness {
  font-family: var(--mono); font-size: 11.5px; color: var(--faint);
  border: 1px solid var(--line-2); padding: 3px 8px; border-radius: 20px;
  white-space: nowrap;
}

/* bascule de thème */
.themetog {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0;
  background: transparent; border: 1px solid var(--line-2);
  border-radius: 6px; color: var(--dim); cursor: pointer;
  flex-shrink: 0;
}
.themetog:hover { color: var(--ink); border-color: var(--accent); background: var(--panel-2); filter: none; }
.themetog svg { width: 16px; height: 16px; display: block; }
.themetog .i-sun  { display: none; }
.themetog .i-moon { display: block; }
:root[data-theme="light"] .themetog .i-sun  { display: block; }
:root[data-theme="light"] .themetog .i-moon { display: none; }

main { max-width: 1280px; margin: 0 auto; padding: 26px 20px 60px; }

footer {
  max-width: 1280px; margin: 0 auto; padding: 20px;
  border-top: 1px solid var(--line);
  color: var(--faint); font-size: 12.5px;
}

/* ------------------------------------------------------------ titrages */
h1 { font-size: 25px; letter-spacing: -.02em; margin-bottom: 5px; font-weight: 650; }
h2 { font-size: 16px; margin-bottom: 12px; font-weight: 620; letter-spacing: -.01em; }
.lede { color: var(--dim); margin-bottom: 24px; max-width: 70ch; font-size: 14.5px; }

/* -------------------------------------------------------------- cartes */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px;
}
a.panel:hover { border-color: var(--accent); text-decoration: none; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.mt { margin-top: 22px; }

/* ------------------------------------------------------------- chiffres */
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 17px; }
.kpi .k { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); font-weight: 650; }
.kpi .v { font-size: 27px; font-weight: 660; letter-spacing: -.025em; margin-top: 5px; font-variant-numeric: tabular-nums; }
.kpi .s { font-size: 12.5px; color: var(--dim); margin-top: 2px; }
.kpi.bad  .v { color: var(--danger); }
.kpi.warn .v { color: var(--warn); }

/* ------------------------------------------------------------- tableaux */
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--faint); font-weight: 700; padding: 7px 9px;
  border-bottom: 1px solid var(--line-2); white-space: nowrap;
}
td { padding: 8px 9px; border-bottom: 1px solid var(--line); vertical-align: top; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 12.5px; }
.scroll { overflow-x: auto; }
.vat { font-family: var(--mono); font-size: 12.5px; white-space: nowrap; }

/* -------------------------------------------------------------- badges */
.tag {
  display: inline-block; padding: 1.5px 7px; border-radius: 4px;
  font-size: 11px; font-weight: 650; white-space: nowrap;
  border: 1px solid transparent;
}
.tag.ok   { background: var(--ok-w);     color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.tag.bad  { background: var(--danger-w); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.tag.warn { background: var(--warn-w);   color: var(--warn);   border-color: color-mix(in srgb, var(--warn) 30%, transparent); }
.tag.mut  { background: var(--panel-2);  color: var(--dim);    border-color: var(--line-2); }

/* ------------------------------------------------------- barres inline */
.bar { height: 6px; background: var(--line-2); border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar.bad > i { background: var(--danger); }

/* ----------------------------------------------------------- formulaires */
input[type=text], input[type=search], input[type=password], input[type=email], select {
  font: inherit; padding: 9px 12px; border: 1px solid var(--line-2);
  border-radius: 6px; background: var(--panel); color: var(--ink); width: 100%;
}
input::placeholder { color: var(--faint); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.controls { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.controls label { font-size: 12.5px; color: var(--dim); font-weight: 600; white-space: nowrap; }
.controls .fld { display: flex; align-items: center; gap: 7px; }
button {
  font: inherit; font-weight: 550; padding: 9px 16px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--panel); border-radius: 6px; cursor: pointer;
}
/* Le blanc ne vaut QUE pour les boutons a fond plein. Sans cette
   restriction, sa specificite (0,1,1) ecrasait .themetog et .navdrop-btn
   (0,1,0) : texte blanc sur fond transparent, donc invisibles en clair. */
:root[data-theme="light"] button:not(.ghost):not(.themetog):not(.navdrop-btn) { color: #fff; }
button:hover { filter: brightness(1.1); }
button.ghost { background: transparent; color: var(--accent); }

/* --------------------------------------------------------------- carte */
#map { height: 640px; border-radius: var(--radius); border: 1px solid var(--line); z-index: 1; background: var(--panel-2); }
.legend {
  background: var(--panel); color: var(--ink); padding: 9px 11px; border-radius: 6px;
  border: 1px solid var(--line-2); font-size: 12px; line-height: 1.7;
  box-shadow: var(--shadow);
}
.legend i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; vertical-align: -1px; }

/* Leaflet : habillage selon le thème */
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--panel); color: var(--ink); box-shadow: var(--shadow);
}
.leaflet-popup-content { margin: 11px 13px; font-size: 13px; }
.leaflet-popup-content b { font-size: 13.5px; }
.leaflet-popup-content a { color: var(--accent); }
.leaflet-container a.leaflet-popup-close-button { color: var(--faint); }
.leaflet-container a.leaflet-popup-close-button:hover { color: var(--ink); }
.leaflet-bar a, .leaflet-bar a:hover {
  background: var(--panel); color: var(--ink); border-bottom-color: var(--line);
}
.leaflet-control-attribution {
  background: color-mix(in srgb, var(--panel) 82%, transparent) !important;
  color: var(--faint) !important;
}
.leaflet-control-attribution a { color: var(--accent) !important; }
.marker-cluster-small  { background: color-mix(in srgb, var(--accent) 32%, transparent); }
.marker-cluster-small div  { background: color-mix(in srgb, var(--accent) 62%, transparent); color: #fff; }
.marker-cluster-medium { background: color-mix(in srgb, var(--warn) 32%, transparent); }
.marker-cluster-medium div { background: color-mix(in srgb, var(--warn) 65%, transparent); color: #1a1a1a; }
.marker-cluster-large  { background: color-mix(in srgb, var(--danger) 32%, transparent); }
.marker-cluster-large div  { background: color-mix(in srgb, var(--danger) 68%, transparent); color: #fff; }
.marker-cluster div { font-weight: 650; }

/* -------------------------------------------------------------- divers */
.muted { color: var(--dim); }
.small { font-size: 12.5px; }
.spin { color: var(--faint); padding: 26px 0; text-align: center; font-size: 13.5px; }
.note {
  background: var(--accent-w); border: 1px solid color-mix(in srgb, var(--accent) 35%, transparent);
  border-radius: 6px; padding: 11px 14px; font-size: 13px; color: var(--ink); margin-bottom: 18px;
}
.note.rgpd { background: var(--danger-w); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.note code { font-family: var(--mono); font-size: 12px; background: var(--panel-2); padding: 1px 5px; border-radius: 3px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 7px 18px; font-size: 13.5px; }
.kv dt { color: var(--faint); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; font-weight: 650; padding-top: 1px; }
.kv dd { font-variant-numeric: tabular-nums; }
.hits { margin-top: 14px; }
.hit {
  display: block; padding: 11px 13px; border: 1px solid var(--line);
  border-radius: 6px; margin-bottom: 7px; background: var(--panel); color: inherit;
}
.hit:hover { border-color: var(--accent); text-decoration: none; background: var(--panel-2); }
.hit .n { font-weight: 600; }
.hit .m { color: var(--dim); font-size: 12.5px; margin-top: 2px; }

@media (max-width: 700px) {
  .topbar { height: auto; padding: 9px 14px; gap: 10px; }
  .topbar nav { order: 3; width: 100%; overflow-x: auto; }
  main { padding: 18px 14px 40px; }
  #map { height: 460px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* identité connectée en barre haute */
.whoami {
  font-size: 12.5px; color: var(--dim); font-weight: 600;
  white-space: nowrap; display: inline-flex; align-items: center;
}
.topbar > a.small { font-size: 12.5px; white-space: nowrap; }

/* réglage booléen : deux positions explicites plutôt qu'une case ambiguë */
.switch { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 9px; }
.switch-opt {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 13px; border: 1px solid var(--line-2);
  border-radius: 6px; cursor: pointer; background: var(--panel);
}
.switch-opt:hover { border-color: var(--accent); }
.switch-opt.sel { border-color: var(--accent); background: var(--accent-w); }
.switch-opt input { width: auto; margin-top: 3px; flex-shrink: 0; }
.switch-opt b { font-size: 13px; }

/* tuile KPI cliquable */
a.kpi-link { display: block; color: inherit; transition: border-color .12s, background .12s; }
a.kpi-link:hover { border-color: var(--accent); background: var(--panel-2); text-decoration: none; }
a.kpi-link:hover .s { color: var(--accent); }
a.kpi-link .s { transition: color .12s; }

/* menu déroulant de la barre haute */
.navdrop { position: relative; }
.navdrop-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 11px; border-radius: 6px; border: none;
  background: transparent; color: var(--dim);
  font: inherit; font-size: 14px; font-weight: 500; cursor: pointer;
}
.navdrop-btn:hover { background: var(--panel-2); color: var(--ink); filter: none; }
.navdrop.on .navdrop-btn { background: var(--accent-w); color: var(--accent); }
.navdrop-btn svg { transition: transform .15s; }
.navdrop.open .navdrop-btn svg { transform: rotate(180deg); }
.navdrop-menu {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; min-width: 210px;
  background: var(--panel); border: 1px solid var(--line-2);
  border-radius: 7px; box-shadow: var(--shadow); padding: 5px; z-index: 950;
}
.navdrop.open .navdrop-menu { display: block; }
.navdrop-menu a {
  display: block; padding: 8px 11px; border-radius: 5px;
  color: var(--ink); font-size: 13.5px; white-space: nowrap;
}
.navdrop-menu a:hover { background: var(--accent-w); color: var(--accent); text-decoration: none; }

/* grille de filtres alignée */
.filters {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px 16px; align-items: end;
}
.filters .f label {
  display: block; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--faint); font-weight: 650; margin-bottom: 5px;
}
.filters .f select, .filters .f input { width: 100%; }
.filters .f-range { display: flex; align-items: center; gap: 7px; }
.filters .f-range input { min-width: 0; }
.filters .f-actions { display: flex; gap: 8px; align-items: center; }
.filterbar { padding: 15px 18px; margin-bottom: 18px; }
.filterbar .foot {
  margin-top: 12px; padding-top: 11px; border-top: 1px solid var(--line);
  font-size: 12.5px; color: var(--dim); display: flex; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; align-items: center;
}

/* graphiques */
.chart-donut { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; }
.chart-donut svg { flex-shrink: 0; }
.chart-legend { list-style: none; flex: 1; min-width: 240px; font-size: 12.5px; }
.chart-legend li {
  display: flex; align-items: center; gap: 8px; padding: 3px 5px;
  border-radius: 4px; line-height: 1.3;
}
.chart-legend li.pick { cursor: pointer; }
.chart-legend li.pick:hover { background: var(--panel-2); }
.chart-legend i { width: 10px; height: 10px; border-radius: 2px; flex-shrink: 0; }
.chart-legend .lbl {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--dim);
}
.chart-legend .val { font-family: var(--mono); font-size: 11.5px; font-variant-numeric: tabular-nums; }
.chart-legend .pct { font-family: var(--mono); font-size: 11px; color: var(--faint); min-width: 46px; text-align: right; }


/* Boutons a fond transparent : couleur imposee dans les deux themes, pour
   qu aucune regle plus specifique sur `button` ne puisse les effacer. */
:root .themetog,
:root[data-theme="light"] .themetog { background: transparent; color: var(--dim); }
:root .themetog:hover,
:root[data-theme="light"] .themetog:hover { color: var(--ink); border-color: var(--accent); background: var(--panel-2); }
:root .navdrop-btn,
:root[data-theme="light"] .navdrop-btn { background: transparent; color: var(--dim); }
:root .navdrop-btn:hover,
:root[data-theme="light"] .navdrop-btn:hover { background: var(--panel-2); color: var(--ink); }
:root .navdrop.on .navdrop-btn,
:root[data-theme="light"] .navdrop.on .navdrop-btn { background: var(--accent-w); color: var(--accent); }
:root button.ghost,
:root[data-theme="light"] button.ghost { background: transparent; color: var(--accent); }

/* cellule de filtre occupant deux colonnes (plages de dates) */
.filters .f-wide { grid-column: span 2; }
@media (max-width: 640px) { .filters .f-wide { grid-column: span 1; } }

/* pagination */
.pager {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line);
  font-size: 13px;
}
.pager button {
  background: transparent; border: 1px solid var(--line-2); color: var(--dim);
  padding: 5px 10px; border-radius: 5px; font-size: 13px; font-weight: 550;
  min-width: 34px;
}
.pager button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); filter: none; }
.pager button.on {
  background: var(--accent-w); border-color: var(--accent); color: var(--accent);
}
.pager button:disabled { opacity: .4; cursor: default; }
:root .pager button, :root[data-theme="light"] .pager button { color: var(--dim); }
:root .pager button.on, :root[data-theme="light"] .pager button.on { color: var(--accent); }
.pager .gap { color: var(--faint); padding: 0 2px; }
.pager .info { margin-left: auto; color: var(--faint); font-size: 12.5px; }

/* légende des courbes */
.chart-lg { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; font-size: 12.5px; }
.chart-lg .lg { display: inline-flex; align-items: center; gap: 6px; color: var(--dim); }
.chart-lg i { width: 11px; height: 3px; border-radius: 2px; display: inline-block; }

/* Fond de carte sombre.
   OpenStreetMap ne publie pas de variante sombre : on inverse les tuiles et on
   recale la teinte pour retrouver un rendu coherent avec le reste du theme.
   Le filtre ne s applique qu au calque de tuiles, jamais aux marqueurs. */
.leaflet-pane.tiles-dark img.leaflet-tile {
  filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9) saturate(.7);
}

/* Bulle de regroupement portant son chiffre.
   Un cercle vectoriel Leaflet ne peut pas contenir de texte : la bulle chiffree
   est donc un marqueur HTML.  `mbub-wrap` remplace la classe par defaut de
   Leaflet, qui poserait un carre blanc borde de gris derriere chaque bulle. */
.mbub-wrap { background: none; border: 0; }
.mbub {
  display: flex; align-items: center; justify-content: center;
  box-sizing: border-box; border-radius: 50%;
  color: #fff; font-weight: 600; font-size: 11px; line-height: 1;
  /* Chiffres de largeur fixe : sans cela les bulles voisines paraissent
     decalees les unes par rapport aux autres. */
  font-variant-numeric: tabular-nums; white-space: nowrap;
  /* Une bulle doit laisser voir le fond de carte et ses voisines : opaques,
     elles formaient un mur de pastilles identiques. */
  border: 1.5px solid rgba(255, 255, 255, .85);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  opacity: .78;
  text-shadow: 0 1px 2px rgba(0, 0, 0, .5);
  cursor: pointer;
  transition: opacity .12s, transform .12s;
}
.mbub:hover { opacity: .97; transform: scale(1.08); }
