/* ============================================================
   TABAC — Design system
   Style : logiciel financier premium, sobre, pédagogique.
   Thèmes : clair (défaut) + sombre via [data-theme="dark"] ou OS.
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  color-scheme: light;

  /* Surfaces */
  --page: #f7f6f3;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --surface-3: #e9e8e2;

  /* Encres (--ink-3 : ≥ 4,5:1 sur toutes les surfaces claires — WCAG AA) */
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #6e6c66;

  /* Traits */
  --hairline: #e1e0d9;
  --border: rgba(11, 11, 11, 0.1);
  --baseline: #c3c2b7;

  /* Identité : laiton (accent de marque) + bleu (interactif)
     --accent : ≥ 4,5:1 sur toutes les surfaces claires (WCAG AA, audit 2026-07-22) */
  --brass: #8a6c20;
  --brass-soft: rgba(176, 141, 62, 0.14);
  --accent: #256abf;
  --accent-soft: rgba(42, 120, 214, 0.12);

  /* Statuts (rouge/orange réservés aux alertes, jamais pour des séries) */
  --ok: #0ca30c;
  --ok-text: #006300;
  --warn: #fab219;
  --warn-text: #7a5410;
  --serious: #ec835a;
  --serious-text: #8f3c1a;
  --critical: #d03b3b;
  --critical-text: #a02323;

  /* Séries graphiques (palette validée CVD — ordre fixe, jamais recyclé) */
  --s1: #2a78d6;
  --s2: #eb6834;
  --s3: #1baf7a;
  --s4: #eda100;
  --s5: #e87ba4;
  --s6: #008300;
  --s7: #4a3aa7;
  --s8: #e34948;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.05);
  --shadow-pop:
    0 4px 12px rgba(11, 11, 11, 0.12), 0 12px 40px rgba(11, 11, 11, 0.14);

  --sidebar-w: 264px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222221;
    --surface-3: #2c2c2a;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --ink-3: #898781;
    --hairline: #2c2c2a;
    --border: rgba(255, 255, 255, 0.1);
    --baseline: #383835;
    --brass: #d8b25e;
    --brass-soft: rgba(216, 178, 94, 0.12);
    --accent: #3987e5;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --ok-text: #0ca30c;
    --warn-text: #fab219;
    --serious-text: #ec835a;
    --critical-text: #e66767;
    --s1: #3987e5;
    --s2: #d95926;
    --s3: #199e70;
    --s4: #c98500;
    --s5: #d55181;
    --s6: #008300;
    --s7: #9085e9;
    --s8: #e66767;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
    --shadow-pop: 0 4px 12px rgba(0, 0, 0, 0.5), 0 12px 40px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222221;
  --surface-3: #2c2c2a;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --ink-3: #898781;
  --hairline: #2c2c2a;
  --border: rgba(255, 255, 255, 0.1);
  --baseline: #383835;
  --brass: #d8b25e;
  --brass-soft: rgba(216, 178, 94, 0.12);
  --accent: #3987e5;
  --accent-soft: rgba(57, 135, 229, 0.16);
  --ok-text: #0ca30c;
  --warn-text: #fab219;
  --serious-text: #ec835a;
  --critical-text: #e66767;
  --s1: #3987e5;
  --s2: #d95926;
  --s3: #199e70;
  --s4: #c98500;
  --s5: #d55181;
  --s6: #008300;
  --s7: #9085e9;
  --s8: #e66767;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-pop: 0 4px 12px rgba(0, 0, 0, 0.5), 0 12px 40px rgba(0, 0, 0, 0.5);
}

/* ---------- Reset & base ---------- */
* {
  box-sizing: border-box;
}
html {
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}
h1,
h2,
h3,
h4 {
  line-height: 1.25;
  margin: 0 0 0.5em;
  letter-spacing: -0.01em;
}
h1 {
  font-size: 1.7rem;
  font-weight: 700;
}
h2 {
  font-size: 1.25rem;
  font-weight: 650;
  margin-top: 1.6em;
}
h3 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-top: 1.2em;
}
p {
  margin: 0.4em 0 0.9em;
}
a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}
code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.86em;
  background: var(--surface-2);
  padding: 0.1em 0.35em;
  border-radius: 5px;
}
small {
  color: var(--ink-2);
}
::selection {
  background: var(--accent-soft);
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.num,
.table td[data-num],
.kpi-value {
  font-variant-numeric: tabular-nums;
}

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--hairline);
  padding: 18px 12px 24px;
  scrollbar-width: thin;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 16px;
}
.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  flex: none;
  background: linear-gradient(
    135deg,
    var(--brass) 0%,
    color-mix(in oklab, var(--brass), var(--ink) 30%) 100%
  );
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 0.02em;
}
.brand-name {
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: -0.01em;
}
.brand-sub {
  font-size: 0.7rem;
  color: var(--ink-3);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.nav-group {
  margin: 14px 0 4px;
  padding: 0 10px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
}
.nav a .ico {
  width: 18px;
  text-align: center;
  flex: none;
  opacity: 0.8;
}
.nav a:hover {
  background: var(--surface-2);
  color: var(--ink);
  text-decoration: none;
}
.nav a.active {
  background: var(--brass-soft);
  color: var(--brass);
  font-weight: 650;
}

.main {
  min-width: 0;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 26px;
  background: color-mix(in oklab, var(--page) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
}
.topbar-title {
  font-weight: 650;
  font-size: 0.95rem;
}
.topbar-spacer {
  flex: 1;
}
.content {
  padding: 26px;
  max-width: 1160px;
  margin: 0 auto;
}

#menu-btn {
  display: none;
}

/* ---------- Cartes & grilles ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin: 0 0 16px;
}
.card > h2:first-child,
.card > h3:first-child {
  margin-top: 0;
}
.grid {
  display: grid;
  gap: 16px;
}
.grid.c2 {
  grid-template-columns: repeat(2, 1fr);
}
.grid.c3 {
  grid-template-columns: repeat(3, 1fr);
}
.grid.c4 {
  grid-template-columns: repeat(4, 1fr);
}

.kicker {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--brass);
  margin-bottom: 6px;
}
.lead {
  font-size: 1.02rem;
  color: var(--ink-2);
  max-width: 70ch;
}

/* KPI */
.kpi {
  padding: 14px 16px;
}
.kpi-label {
  font-size: 0.78rem;
  color: var(--ink-2);
  font-weight: 550;
  display: flex;
  align-items: center;
  gap: 6px;
}
.kpi-value {
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 2px 0;
}
.kpi-sub {
  font-size: 0.78rem;
  color: var(--ink-3);
}
.kpi-value .unit {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-3);
  margin-left: 2px;
}
.delta-up {
  color: var(--ok-text);
  font-weight: 600;
}
.delta-down {
  color: var(--critical-text);
  font-weight: 600;
}

/* ---------- Callouts (niveaux d'alerte) ---------- */
.callout {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 12px 0;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 0.92rem;
}
.callout .co-ico {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  margin-top: 1px;
}
.callout .co-body {
  min-width: 0;
}
.callout.info {
  border-left: 3px solid var(--accent);
}
.callout.info .co-ico {
  color: var(--accent);
  background: var(--accent-soft);
}
.callout.ok {
  border-left: 3px solid var(--ok);
}
.callout.ok .co-ico {
  color: var(--ok-text);
  background: color-mix(in oklab, var(--ok) 14%, transparent);
}
.callout.vigilance {
  border-left: 3px solid var(--warn);
}
.callout.vigilance .co-ico {
  color: var(--warn-text);
  background: color-mix(in oklab, var(--warn) 16%, transparent);
}
.callout.risque {
  border-left: 3px solid var(--serious);
}
.callout.risque .co-ico {
  color: var(--serious-text);
  background: color-mix(in oklab, var(--serious) 15%, transparent);
}
.callout.bloquant {
  border-left: 3px solid var(--critical);
}
.callout.bloquant .co-ico {
  color: var(--critical-text);
  background: color-mix(in oklab, var(--critical) 13%, transparent);
}
.callout.juridique {
  border-left: 3px solid var(--brass);
}
.callout.juridique .co-ico {
  color: var(--brass);
  background: var(--brass-soft);
}
.callout .t {
  font-weight: 650;
  display: block;
  margin-bottom: 2px;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  padding: 2px 9px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink-2);
  vertical-align: middle;
  white-space: nowrap;
}
.badge.officiel {
  background: color-mix(in oklab, var(--ok) 12%, var(--surface));
  color: var(--ok-text);
  border-color: color-mix(in oklab, var(--ok) 30%, transparent);
}
.badge.professionnel {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: color-mix(in oklab, var(--accent) 30%, transparent);
}
.badge.presse {
  background: var(--surface-2);
  color: var(--ink-2);
}
.badge.estimation {
  background: color-mix(in oklab, var(--warn) 14%, var(--surface));
  color: var(--warn-text);
  border-color: color-mix(in oklab, var(--warn) 35%, transparent);
}
.badge.hypothese {
  background: color-mix(in oklab, var(--serious) 13%, var(--surface));
  color: var(--serious-text);
  border-color: color-mix(in oklab, var(--serious) 32%, transparent);
}
.badge.contractuel {
  background: color-mix(in oklab, var(--critical) 10%, var(--surface));
  color: var(--critical-text);
  border-color: color-mix(in oklab, var(--critical) 28%, transparent);
}

/* ---------- Aide pédagogique (infobulle) ---------- */
.help-btn {
  display: inline-grid;
  place-items: center;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 1px solid var(--baseline);
  background: transparent;
  color: var(--ink-3);
  font-size: 0.68rem;
  font-weight: 700;
  cursor: help;
  vertical-align: text-top;
  padding: 0;
  margin-left: 4px;
}
.help-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.tooltip {
  position: fixed;
  z-index: 200;
  max-width: 340px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-pop);
  padding: 10px 13px;
  font-size: 0.84rem;
  line-height: 1.5;
}
.tooltip .src {
  display: block;
  margin-top: 6px;
  color: var(--ink-3);
  font-size: 0.76rem;
}

/* ---------- Tableaux ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.table th {
  text-align: left;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 650;
  padding: 9px 12px;
  border-bottom: 1px solid var(--hairline);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}
.table th.sortable {
  cursor: pointer;
  user-select: none;
}
.table th.sortable:hover {
  color: var(--ink);
}
.table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--hairline);
  vertical-align: top;
}
.table tr:last-child td {
  border-bottom: 0;
}
.table tbody tr:hover {
  background: var(--surface-2);
}
.table td[data-num] {
  text-align: right;
  white-space: nowrap;
}
.table tfoot td {
  font-weight: 650;
  background: var(--surface-2);
}

/* ---------- Formulaires ---------- */
.field {
  margin: 0 0 12px;
}
.field label {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 4px;
}
input[type="number"],
input[type="text"],
select,
textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--baseline);
  border-radius: 8px;
  padding: 7px 10px;
}
input[type="number"] {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
input:hover,
select:hover {
  border-color: var(--ink-3);
}
input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 2px solid var(--accent-soft);
}
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}
.field .suffix {
  position: relative;
}
.field .suffix input {
  padding-right: 34px;
}
.field .suffix::after {
  content: attr(data-unit);
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-3);
  font-size: 0.8rem;
  pointer-events: none;
}
fieldset {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin: 0 0 14px;
}
legend {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--brass);
  padding: 0 6px;
}

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid var(--baseline);
  background: var(--surface);
  color: var(--ink);
}
.btn:hover {
  background: var(--surface-2);
  border-color: var(--ink-3);
}
.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn.primary:hover {
  background: color-mix(in oklab, var(--accent), #000 12%);
}
.btn.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--ink-2);
}
.btn.ghost:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.btn.small {
  font-size: 0.78rem;
  padding: 4px 10px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 550;
  padding: 4px 12px;
  border-radius: 99px;
  border: 1px solid var(--baseline);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}
.chip:hover {
  border-color: var(--ink-3);
  color: var(--ink);
}
.chip.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 650;
}

/* ---------- Graphiques ---------- */
.viz {
  margin: 14px 0;
}
.viz-title {
  font-size: 0.9rem;
  font-weight: 650;
  margin-bottom: 2px;
}
.viz-sub {
  font-size: 0.78rem;
  color: var(--ink-3);
  margin-bottom: 8px;
}
.viz svg {
  display: block;
  width: 100%;
  height: auto;
  overflow: visible;
}
.viz .grid-line {
  stroke: var(--hairline);
  stroke-width: 1;
}
.viz .axis-line {
  stroke: var(--baseline);
  stroke-width: 1;
}
.viz .tick-label,
.viz .axis-label {
  fill: var(--ink-3);
  font-size: 11px;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}
.viz .mark-label {
  fill: var(--ink-2);
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
}
.viz-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--ink-2);
}
.viz-legend .sw {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: -1px;
}
.viz-tip {
  position: fixed;
  z-index: 210;
  pointer-events: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow-pop);
  padding: 7px 11px;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}
.viz-tip .tt {
  font-weight: 650;
  margin-bottom: 2px;
}

/* ---------- Score / jauge de risque ---------- */
.score-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.05rem;
  padding: 6px 16px;
  border-radius: 99px;
  border: 2px solid var(--baseline);
}
.score-pill.n-info {
  border-color: var(--accent);
  color: var(--accent);
}
.score-pill.n-ok {
  border-color: var(--ok);
  color: var(--ok-text);
}
.score-pill.n-vigilance {
  border-color: var(--warn);
  color: var(--warn-text);
}
.score-pill.n-risque {
  border-color: var(--serious);
  color: var(--serious-text);
}
.score-pill.n-bloquant {
  border-color: var(--critical);
  color: var(--critical-text);
}

/* ---------- Divers ---------- */
.muted {
  color: var(--ink-3);
}
.sep {
  border: 0;
  border-top: 1px solid var(--hairline);
  margin: 18px 0;
}
.tag-source {
  font-size: 0.72rem;
  color: var(--ink-3);
}
.footnote {
  font-size: 0.78rem;
  color: var(--ink-3);
  border-top: 1px solid var(--hairline);
  margin-top: 14px;
  padding-top: 8px;
}
.two-col {
  columns: 2;
  column-gap: 28px;
}
.avoid-break {
  break-inside: avoid;
}
details {
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin: 10px 0;
  background: var(--surface);
}
details summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.92rem;
}
details[open] summary {
  margin-bottom: 8px;
}
.skeleton {
  color: var(--ink-3);
  font-style: italic;
}

/* Écran de chargement */
#loading {
  display: grid;
  place-items: center;
  min-height: 60vh;
  color: var(--ink-3);
}

/* ---------- Responsive ---------- */
@media (max-width: 1040px) {
  .grid.c4 {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid.c3 {
    grid-template-columns: repeat(2, 1fr);
  }
  .two-col {
    columns: 1;
  }
}
@media (max-width: 780px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: min(82vw, 300px);
    transform: translateX(-104%);
    transition: transform 0.22s ease;
    z-index: 100;
    box-shadow: var(--shadow-pop);
    height: 100dvh;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  #scrim {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 90;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
  }
  #scrim.show {
    opacity: 1;
    pointer-events: auto;
  }
  #menu-btn {
    display: inline-flex;
  }
  .content {
    padding: 16px;
  }
  .grid.c2,
  .grid.c3,
  .grid.c4 {
    grid-template-columns: 1fr;
  }
  .kpi-value {
    font-size: 1.3rem;
  }
  h1 {
    font-size: 1.35rem;
  }
}

/* ---------- Impression (rapport) ---------- */
@media print {
  .sidebar,
  .topbar,
  .no-print,
  #scrim {
    display: none !important;
  }
  .app {
    display: block;
  }
  body {
    background: #fff;
    color: #000;
    font-size: 11pt;
  }
  .content {
    max-width: none;
    padding: 0;
  }
  .card {
    box-shadow: none;
    border-color: #ccc;
    break-inside: avoid;
  }
  a {
    color: inherit;
  }
  .print-only {
    display: block;
  }
}
.print-only {
  display: none;
}

/* ---------- Carte Leaflet (thème sombre + popups) ---------- */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .leaflet-tile {
    filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9)
      saturate(0.7);
  }
  :root:where(:not([data-theme="light"])) .leaflet-container {
    background: #1a1a19;
  }
}
:root[data-theme="dark"] .leaflet-tile {
  filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.9)
    saturate(0.7);
}
:root[data-theme="dark"] .leaflet-container {
  background: #1a1a19;
}
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-pop);
}
.leaflet-container a.leaflet-popup-close-button {
  color: var(--ink-3);
}
@media print {
  #carte-bloc {
    display: none;
  }
}

/* Topbar compacte en mobile : le titre cède la place, les boutons se resserrent */
@media (max-width: 780px) {
  .topbar {
    gap: 6px;
    padding: 10px 12px;
  }
  .topbar-title {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .topbar .btn {
    padding: 4px 8px;
  }
}

/* ---------- Polish : icônes SVG, survols, chevrons, chargement ---------- */
.ico-svg {
  display: inline-block;
  vertical-align: -3px;
}
.nav a .ico {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  opacity: 0.75;
}
.nav a.active .ico {
  opacity: 1;
}
.nav a {
  transition:
    background 0.15s ease,
    color 0.15s ease;
}
.nav a.active {
  box-shadow: inset 3px 0 0 var(--brass);
}
.btn .ico-svg {
  vertical-align: -3px;
  margin-right: 2px;
}
.btn,
.chip {
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    transform 0.12s ease;
}
.btn:active,
.chip:active {
  transform: scale(0.97);
}

.card {
  transition:
    box-shadow 0.2s ease,
    transform 0.2s ease;
}
.grid > .card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-pop);
}

details > summary {
  list-style: none;
  position: relative;
  padding-left: 22px;
}
details > summary::-webkit-details-marker {
  display: none;
}
details > summary::before {
  content: "";
  position: absolute;
  left: 2px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--ink-3);
  border-bottom: 2px solid var(--ink-3);
  transform: translateY(-70%) rotate(-45deg);
  transition: transform 0.18s ease;
}
details[open] > summary::before {
  transform: translateY(-70%) rotate(45deg);
}
details > summary:hover {
  color: var(--accent);
}

/* Squelette de chargement (remplace le texte « Chargement… ») */
#loading {
  min-height: 40vh;
}
.skeleton-block {
  border-radius: var(--radius);
  background: linear-gradient(
    100deg,
    var(--surface-2) 40%,
    var(--surface-3) 50%,
    var(--surface-2) 60%
  );
  background-size: 200% 100%;
  animation: shimmer 1.1s linear infinite;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}

/* Respect de prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }
  .sidebar {
    transition: none;
  }
}

/* ---------- Accessibilité (audit WCAG 2.2 AA du 2026-07-22) ---------- */
/* Lien actif de nav : encre pleine + identité portée par l'icône et la barre laiton */
.nav a.active {
  color: var(--ink);
}
.nav a.active .ico {
  color: var(--brass);
}
/* Les liens dans le texte courant ne reposent jamais sur la seule couleur */
p a,
li a,
td a,
.footnote a,
.kpi-sub a,
.callout a {
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: color-mix(in oklab, var(--accent) 55%, transparent);
}

/* Badges en thème sombre : textes éclaircis pour tenir 4,5:1 sur fonds teintés */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .badge.officiel { color: #43cf43; }
  :root:where(:not([data-theme="light"])) .badge.professionnel { color: #74aef2; }
  :root:where(:not([data-theme="light"])) .badge.hypothese { color: #f0906c; }
  :root:where(:not([data-theme="light"])) .badge.contractuel { color: #ef8686; }
}
:root[data-theme="dark"] .badge.officiel { color: #43cf43; }
:root[data-theme="dark"] .badge.professionnel { color: #74aef2; }
:root[data-theme="dark"] .badge.hypothese { color: #f0906c; }
:root[data-theme="dark"] .badge.contractuel { color: #ef8686; }
