/* Ordago — Statistiques SVI (prototype)
   Charte : rouge #F93939, gris #1D1D1D, noir #080808, blanc #FFFFFF.
   Les couleurs de séries (calées et validées CVD) vivent dans app.js.

   Rôles de couleur, alignés sur le mapping validé de la charte :
     rouge  = marque + états critiques (erreur, filtre vide) — jamais un simple « actif » ;
     bleu   = sélection, navigation, focus (#1B72B8 texte, #33A3FF aplat, #EAF4FF fond) ;
     vert   = variation favorable (#3F7D18).
   Toute couleur passe par un token : aucun hex en dur hors de ce bloc. */

:root {
  --accent: #F93939;          /* marque Ordago */
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --chevron: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2.5 4.5 6 8l3.5-3.5' fill='none' stroke='%23838d9c' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  font-size: 15px;
}
:root[data-theme="light"] {
  --bg: #eef1f7;
  --surface: #ffffff;
  --surface-2: #f5f8fc;
  --ink: #1d1d1d;
  --ink2: #515a68;
  --muted: #838d9c;
  --border: #e4e9f1;
  --border-2: #d3dbe7;
  --grid: #edf1f7;
  --hover: rgba(27, 114, 184, 0.07);
  --sel: #1B72B8;
  --sel-2: #33A3FF;
  --sel-soft: #EAF4FF;
  --pos: #3F7D18;
  --pos-soft: #EDF6E6;
  --neg: #C21122;
  --neg-soft: #FDECEE;
  --shadow-1: 0 1px 2px rgba(23, 34, 56, 0.06), 0 1px 3px rgba(23, 34, 56, 0.05);
  --shadow-2: 0 2px 6px rgba(23, 34, 56, 0.06), 0 10px 24px -8px rgba(23, 34, 56, 0.16);
  --shadow-3: 0 18px 46px -12px rgba(23, 34, 56, 0.28);
  --canvas:
    radial-gradient(1100px 480px at 12% -10%, #ffffff 0%, rgba(255, 255, 255, 0) 62%),
    radial-gradient(900px 420px at 100% -6%, #e6ecfa 0%, rgba(230, 236, 250, 0) 58%),
    linear-gradient(180deg, #f3f5fa 0%, #eef1f7 100%);
}
:root[data-theme="dark"] {
  --bg: #080808;
  --surface: #1d1d1d;
  --surface-2: #262a30;
  --ink: #f2f3f5;
  --ink2: #aab2bd;
  --muted: #7e8794;
  --border: #333333;
  --border-2: #3f444c;
  --grid: #2c2c2c;
  --hover: rgba(51, 163, 255, 0.12);
  --sel: #6fbcff;
  --sel-2: #33A3FF;
  --sel-soft: rgba(51, 163, 255, 0.16);
  --pos: #7bc555;
  --pos-soft: rgba(123, 197, 85, 0.16);
  --neg: #ff6259;
  --neg-soft: rgba(255, 98, 89, 0.16);
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.45);
  --shadow-2: 0 2px 6px rgba(0, 0, 0, 0.45), 0 12px 28px -10px rgba(0, 0, 0, 0.6);
  --shadow-3: 0 20px 50px -12px rgba(0, 0, 0, 0.7);
  --canvas: linear-gradient(180deg, #101010 0%, #080808 100%);
}

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

body {
  min-height: 100vh;
  background: var(--bg);
  background-image: var(--canvas);
  background-attachment: fixed;
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

/* barres de défilement discrètes */
* { scrollbar-width: thin; scrollbar-color: var(--border-2) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-2); border: 3px solid transparent; background-clip: content-box; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

/* ---------- entête ---------- */
.topbar {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-1);
}
.brand { display: flex; align-items: center; gap: 13px; }
.brand svg { border-radius: 11px; box-shadow: 0 5px 14px -4px rgba(249, 57, 57, 0.55); flex: none; }
.brand-name { font-weight: 700; font-size: 1.12rem; letter-spacing: -0.012em; }
.brand-sub { color: var(--ink2); font-weight: 500; }
.brand-range {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  padding: 2px 10px 2px 8px;
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--ink2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
}
.brand-range::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--pos);
  flex: none;
}

:root[data-theme="light"] [data-when="dark"] { display: none; }
:root[data-theme="dark"] [data-when="light"] { display: none; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

/* onglets : pastille blanche qui glisse, pas d'aplat rouge */
.tabs {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
}
.tab {
  display: inline-flex;
  align-items: center;
  border: 0;
  background: transparent;
  color: var(--ink2);
  font: inherit;
  font-size: 0.86rem;
  font-weight: 600;
  text-decoration: none;
  padding: 6px 15px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}
.tab:hover { color: var(--ink); background: var(--hover); }
.tab.is-active { background: var(--surface); color: var(--sel); box-shadow: var(--shadow-1); }

/* ---------- filtres ---------- */
body[data-view="ia"] .filters { display: none; }

.filters {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 9px 20px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
@supports (backdrop-filter: blur(1px)) {
  .filters {
    background: color-mix(in srgb, var(--surface) 80%, transparent);
    backdrop-filter: blur(14px) saturate(150%);
  }
}
.filter-block { display: flex; align-items: center; gap: 8px; }
.filter-label {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}
.filter-sep { color: var(--muted); }

.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.segmented button {
  border: 0;
  background: transparent;
  color: var(--ink2);
  padding: 4px 11px;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: 7px;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease;
}
.segmented button + button { border-left: 0; }
.segmented button:hover { background: var(--hover); color: var(--ink); }
.segmented button.is-active {
  background: var(--sel);
  color: #fff;
  box-shadow: 0 1px 3px rgba(27, 114, 184, 0.45);
}

select, input[type="date"] {
  font: inherit;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border-2);
  border-radius: 9px;
  padding: 5px 9px;
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}
select {
  appearance: none;
  padding-right: 27px;
  background-image: var(--chevron);
  background-repeat: no-repeat;
  background-position: right 9px center;
}
select:hover, input[type="date"]:hover { border-color: var(--sel-2); }
select:focus-visible, input:focus-visible, button:focus-visible, a:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--sel-2);
  outline-offset: 1px;
}

.btn-ghost {
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--ink2);
  font: inherit;
  font-size: 0.83rem;
  font-weight: 600;
  padding: 5px 12px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}
.btn-ghost:hover { background: var(--sel-soft); color: var(--sel); border-color: var(--sel-2); }

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

/* ---------- disposition ---------- */
main { width: 95%; max-width: 1760px; margin: 0 auto; padding: 22px 0 48px; }
@media (max-width: 720px) { main { width: 100%; padding: 16px 14px 32px; } }

.dash-layout {
  display: grid;
  grid-template-columns: 296px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.dash-main { min-width: 0; }
@media (max-width: 1080px) { .dash-layout { grid-template-columns: 1fr; } }

/* ---------- panneau latéral : agences puis numéros ---------- */
.side {
  position: sticky;
  top: 66px;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 84px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 15px 11px 8px;
}
@media (max-width: 1080px) { .side { position: static; max-height: 440px; } }

.side-head { padding: 0 5px; }
.side-head h2 { font-size: 1rem; font-weight: 700; letter-spacing: -0.01em; }
.side-sub { font-size: 0.76rem; color: var(--muted); margin-top: 3px; }
.side-back {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  border: 0;
  background: transparent;
  color: var(--sel);
  font: inherit;
  font-size: 0.79rem;
  font-weight: 600;
  padding: 0 0 8px;
  cursor: pointer;
  border-radius: 6px;
}
.side-back:hover { text-decoration: underline; }

.side-search {
  font: inherit;
  font-size: 0.84rem;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 11px;
  margin: 11px 5px 6px;
  transition: border-color 0.16s ease, background 0.16s ease;
}
.side-search:hover { border-color: var(--border-2); }
.side-search:focus { background: var(--surface); }

.side-list { overflow-y: auto; overscroll-behavior: contain; padding: 0 3px 8px; }
.side-group {
  font-size: 0.67rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 14px 7px 5px;
}
.side-item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 1px 10px;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  border-radius: 9px;
  padding: 8px 10px;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease;
}
.side-item:hover { background: var(--hover); }
.side-item.is-active { background: var(--sel-soft); color: var(--sel); }
.side-item.is-active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 7px;
  bottom: 7px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--sel-2);
}
.side-item.is-zero:not(.is-active) { opacity: 0.45; }
.side-item.is-active .side-num { color: var(--sel); opacity: 0.8; }
.side-item.is-active .side-vol { color: var(--sel); background: rgba(51, 163, 255, 0.16); }
.side-name { font-size: 0.87rem; font-weight: 600; }
.side-num {
  grid-column: 1;
  font-size: 0.79rem;
  color: var(--ink2);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}
.side-vol {
  grid-row: 1 / span 2;
  grid-column: 2;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--ink2);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 2px 8px;
  font-variant-numeric: tabular-nums;
}
.side-empty { font-size: 0.82rem; color: var(--muted); padding: 16px 9px; }

/* ---------- carte « numéro sélectionné » ---------- */
.card-num { position: relative; overflow: hidden; padding-left: 22px; }
.card-num::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--sel-2), var(--sel));
}
.num-head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px 14px; }
.num-head .num-big {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.num-head .num-lab { font-size: 0.95rem; color: var(--ink2); font-weight: 600; }
.num-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 2px; }
.num-tag {
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--ink2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 11px;
}
.num-note { font-size: 0.8rem; color: var(--muted); margin-top: 10px; max-width: 92ch; }
.num-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(152px, 1fr));
  gap: 10px;
  margin-top: 15px;
}
.num-kpi {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
}
.num-kpi .k-lab { font-size: 0.73rem; font-weight: 600; color: var(--ink2); }
.num-kpi .k-val {
  font-size: 1.32rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.num-kpi .k-sub { font-size: 0.73rem; color: var(--muted); }
.num-grid { display: grid; grid-template-columns: 1.35fr 1fr; gap: 20px; margin-top: 18px; }
@media (max-width: 860px) { .num-grid { grid-template-columns: 1fr; } }
.num-sec h3 {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 8px;
}
.num-close {
  margin-left: auto;
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--ink2);
  font: inherit;
  font-size: 0.79rem;
  font-weight: 600;
  border-radius: 9px;
  padding: 4px 11px;
  cursor: pointer;
  transition: background 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}
.num-close:hover { background: var(--neg-soft); color: var(--neg); border-color: var(--neg); }

/* ---------- tuiles d'indicateurs ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(196px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.kpi {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 16px 16px;
  box-shadow: var(--shadow-1);
  transition: box-shadow 0.18s ease, transform 0.18s ease;
}
.kpi:hover { box-shadow: var(--shadow-2); transform: translateY(-2px); }
.kpi::after {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--sel-2), var(--sel));
}
.kpi:has(svg) { padding-bottom: 0; }
.kpi-label {
  font-size: 0.71rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.kpi-value {
  font-size: 2.05rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.12;
  margin-top: 5px;
  font-variant-numeric: tabular-nums;
}
.kpi-delta {
  display: flex;
  align-items: center;
  gap: 7px;
  flex-wrap: wrap;
  font-size: 0.74rem;
  color: var(--muted);
  margin-top: 8px;
}
.kpi-delta .d-val {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  color: var(--ink2);
  border-radius: 999px;
  padding: 2px 9px;
}
.kpi-delta.is-good .d-val { background: var(--pos-soft); color: var(--pos); }
.kpi-delta.is-bad .d-val { background: var(--neg-soft); color: var(--neg); }
.kpi svg { display: block; width: calc(100% + 32px); height: auto; margin: 12px -16px 0; }

/* ---------- cartes ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 17px 19px 19px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-1);
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--grid);
  flex-wrap: wrap;
}
.card h2 { font-size: 1rem; font-weight: 700; letter-spacing: -0.012em; }
.card-head h2 { display: flex; align-items: center; gap: 9px; }
.card-head h2::before {
  content: "";
  width: 3px;
  height: 15px;
  border-radius: 2px;
  background: var(--sel-2);
  flex: none;
}
.card-sub { font-size: 0.79rem; color: var(--muted); margin-top: 3px; }

.legend { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 0.78rem; color: var(--ink2); }
.legend .key {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 3px 10px 3px 8px;
  font-weight: 600;
}
.legend .swatch { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex: none; }
.legend .ramp { display: inline-flex; height: 10px; border-radius: 3px; overflow: hidden; }
.legend .ramp i { width: 14px; height: 10px; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart text { font-family: inherit; }

/* ---------- tooltip ---------- */
.tooltip {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-3);
  padding: 10px 13px;
  font-size: 0.81rem;
  max-width: 290px;
}
.tooltip .tt-title { font-weight: 700; margin-bottom: 6px; letter-spacing: -0.01em; }
.tooltip .tt-row { display: flex; align-items: center; gap: 8px; margin-top: 3px; }
.tooltip .tt-key { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.tooltip .tt-val { font-weight: 700; margin-left: auto; padding-left: 16px; font-variant-numeric: tabular-nums; }
.tooltip .tt-label { color: var(--ink2); }

/* ---------- tableau ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--grid); border-radius: var(--radius-sm); }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 0.84rem; }
th, td { text-align: right; padding: 9px 14px; font-variant-numeric: tabular-nums; }
th:first-child, td:first-child { text-align: left; }
th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--ink2);
  font-weight: 700;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td { border-bottom: 1px solid var(--grid); }
tbody tr:last-child td { border-bottom: 0; }
td:first-child { font-weight: 600; }
tbody tr:hover td { background: var(--sel-soft); }

.foot { margin-top: 22px; font-size: 0.77rem; color: var(--muted); text-align: center; }
.foot code { font-family: ui-monospace, monospace; background: var(--surface-2); border-radius: 5px; padding: 1px 5px; }

/* ---------- onglet Analyse IA ---------- */
.ia-intro {
  font-size: 0.84rem;
  color: var(--ink2);
  margin-bottom: 18px;
  max-width: 78ch;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-2);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-1);
  padding: 12px 16px;
}
.insights { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 980px) { .insights { grid-template-columns: 1fr; } }
.insight { padding: 20px 22px 22px; }
.insight h2 { margin: 13px 0 10px; font-size: 1.14rem; font-weight: 700; letter-spacing: -0.018em; line-height: 1.3; }
.insight p { font-size: 0.87rem; color: var(--ink2); margin-bottom: 12px; }
.insight .chart { margin: 14px 0; }
.insight .legend { margin-bottom: 12px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 4px 11px;
  border-radius: 999px;
}
.badge-alerte { background: var(--neg-soft); color: var(--badge-alerte); }
.badge-constat { background: var(--sel-soft); color: var(--badge-constat); }
.badge-oppo { background: var(--badge-oppo-soft); color: var(--badge-oppo); }
.badge-positif { background: var(--pos-soft); color: var(--badge-positif); }
:root[data-theme="light"] {
  --badge-alerte: #C21122;
  --badge-constat: #1B72B8;
  --badge-oppo: #7C6A00;
  --badge-oppo-soft: #FAF3D6;
  --badge-positif: #3F7D18;
}
:root[data-theme="dark"] {
  --badge-alerte: #ff6259;
  --badge-constat: #6fbcff;
  --badge-oppo: #d9c64a;
  --badge-oppo-soft: rgba(217, 198, 74, 0.16);
  --badge-positif: #7bc555;
}

.hero-num {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.032em;
  line-height: 1.05;
  margin: 4px 0 14px;
  font-variant-numeric: tabular-nums;
}
.hero-num .hero-sub {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--ink2);
  margin-top: 7px;
  max-width: 46ch;
}
.insight-reco {
  margin-top: 4px;
  margin-bottom: 0 !important;
  padding: 12px 14px;
  background: var(--sel-soft);
  border-left: 3px solid var(--sel-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.85rem;
  color: var(--ink) !important;
}

/* ---------- panneau Assistant (chatbot RAG) ---------- */
:root { --chat-w: 380px; }

body.chat-open { padding-right: var(--chat-w); }
body { transition: padding-right 0.22s ease; }

.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  width: var(--chat-w);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-2);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.22s ease, visibility 0.22s;
}
body.chat-open .chat-panel { transform: none; visibility: visible; }

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.chat-head h2 { font-size: 0.98rem; font-weight: 650; }
.chat-head .chat-sub { font-size: 0.75rem; color: var(--muted); }
.chat-head-actions { margin-left: auto; display: flex; gap: 6px; }
.btn-icon {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--ink2);
  font: inherit;
  font-size: 0.85rem;
  line-height: 1;
  padding: 6px 9px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-icon:hover { background: var(--hover); }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
}

.chat-msg { display: flex; flex-direction: column; gap: 6px; max-width: 100%; }
.chat-msg.is-user { align-items: flex-end; }

.chat-bubble {
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 0.86rem;
  line-height: 1.5;
  max-width: 90%;
  overflow-wrap: anywhere;
}
.is-bot .chat-bubble { background: var(--surface-2); color: var(--ink); border-top-left-radius: 4px; }
.is-user .chat-bubble { background: var(--sel); color: #fff; border-bottom-right-radius: 4px; }
.is-error .chat-bubble {
  background: transparent;
  border: 1px solid var(--badge-alerte);
  color: var(--ink);
}
.chat-bubble p + p { margin-top: 8px; }
.chat-bubble code {
  font-family: ui-monospace, monospace;
  font-size: 0.92em;
  background: var(--grid);
  border-radius: 4px;
  padding: 1px 4px;
}
.is-user .chat-bubble code { background: rgba(255, 255, 255, 0.22); }
.chat-bubble a { color: inherit; }

.chat-typing { display: inline-flex; gap: 4px; padding: 3px 0; }
.chat-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: chat-blink 1.1s infinite ease-in-out;
}
.chat-typing i:nth-child(2) { animation-delay: 0.18s; }
.chat-typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes chat-blink { 0%, 70%, 100% { opacity: 0.25; } 35% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  body, .chat-panel { transition: none; }
  .chat-typing i { animation: none; opacity: 0.5; }
}

.chat-sources { font-size: 0.78rem; color: var(--ink2); max-width: 90%; }
.chat-sources summary { cursor: pointer; color: var(--muted); }
.chat-sources summary:hover { color: var(--ink2); }
.chat-sources ol { margin: 6px 0 0 18px; display: flex; flex-direction: column; gap: 6px; }
.chat-sources .src-title { font-weight: 600; }
.chat-sources .src-snippet { color: var(--muted); margin-top: 2px; }

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.chat-form textarea {
  flex: 1;
  resize: none;
  font: inherit;
  font-size: 0.86rem;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  max-height: 140px;
}
.chat-form textarea:disabled { opacity: 0.6; }
.chat-send, .chat-stop {
  border: 0;
  border-radius: 10px;
  color: #fff;
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 13px;
  cursor: pointer;
  flex: none;
}
.chat-send { background: var(--sel); }
.chat-stop { background: var(--ink2); }
.chat-send:hover, .chat-stop:hover { filter: brightness(1.08); }

.chat-foot { padding: 0 16px 12px; font-size: 0.72rem; color: var(--muted); }

/* En dessous de 1100 px le panneau se superpose au lieu de comprimer la page */
@media (max-width: 1100px) {
  body.chat-open { padding-right: 0; }
  .chat-panel {
    width: min(var(--chat-w), 100%);
    box-shadow: var(--shadow-3);
  }
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- carte des agences ---------- */
.map-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 258px;
  gap: 18px;
  align-items: start;
}
@media (max-width: 900px) { .map-layout { grid-template-columns: 1fr; } }

.map-chart svg { display: block; width: 100%; height: auto; max-height: 540px; }
.map-region { pointer-events: none; }
.map-bg.is-zoom { cursor: zoom-out; }

.map-pt { cursor: pointer; }
.map-pt circle { transition: fill-opacity 0.12s ease; }
.map-pt:hover circle { fill-opacity: 1; }
.map-pt:focus { outline: none; }
.map-pt:focus-visible circle { stroke: var(--sel-2); stroke-width: 3; }
.map-label { paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }

/* fil d'Ariane : France › ville › agence › numéro */
.map-crumb { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; margin: 4px 0 12px; }
.crumb {
  border: 0;
  background: transparent;
  color: var(--ink2);
  font: inherit;
  font-size: 0.85rem;
  padding: 3px 8px;
  border-radius: 7px;
  cursor: pointer;
}
.crumb:hover { background: var(--hover); }
.crumb.is-on { color: var(--sel); font-weight: 700; background: var(--sel-soft); cursor: default; }
.crumb-sep { color: var(--muted); font-size: 0.85rem; }

/* agences sans lieu */
.map-aside h3 { font-size: 0.82rem; font-weight: 650; color: var(--ink2); }
.map-aside-sub { font-size: 0.76rem; color: var(--muted); margin: 3px 0 10px; }
.map-aside-foot { font-size: 0.76rem; color: var(--muted); margin-top: 10px; }
.map-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.85rem;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 7px 11px;
  margin-bottom: 5px;
  cursor: pointer;
  transition: background 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}
.map-chip:hover { background: var(--hover); border-color: var(--border); }
.map-chip.is-active { background: var(--sel-soft); color: var(--sel); border-color: var(--sel-2); font-weight: 600; }
.map-chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.map-chip .chip-vol { margin-left: auto; font-variant-numeric: tabular-nums; color: var(--muted); }
.map-chip.is-active .chip-vol { color: var(--sel); opacity: 0.75; }

/* ---------- modules réorganisables ---------- */
.dash-modules {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  align-items: start;
}
.dash-modules > * { margin-bottom: 0; }
.dash-modules > [data-w="full"] { grid-column: 1 / -1; }
@media (max-width: 900px) { .dash-modules { grid-template-columns: 1fr; } }
.dash-modules > .kpis { margin-bottom: 0; }

/* tiroir des modules masqués */
.mod-tray {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 12px;
}
.tray-label { font-size: 0.78rem; font-weight: 600; color: var(--ink2); text-transform: uppercase; letter-spacing: 0.04em; }
.tray-list { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tray-chip, .tray-reset {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  font-size: 0.82rem;
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
}
.tray-chip:hover, .tray-reset:hover { background: var(--hover); }
.tray-reset { border-style: dashed; color: var(--ink2); }
.tray-empty { font-size: 0.8rem; color: var(--muted); }

/* barre d'outils d'un module, visible seulement en mode organisation */
body.is-editing .dash-modules > [data-mod] {
  position: relative;
  outline: 1px dashed var(--border);
  outline-offset: 2px;
}
body.is-editing .dash-modules > [data-mod]:hover { outline-color: var(--sel-2); }
.mod-bar {
  position: absolute;
  top: -12px;
  left: 10px;
  right: 10px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  box-shadow: var(--shadow-2);
}
.mod-name {
  font-size: 0.76rem;
  font-weight: 650;
  color: var(--ink2);
  margin-right: auto;
  padding-left: 4px;
  cursor: grab;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mod-btn {
  border: 0;
  background: transparent;
  color: var(--ink2);
  font: inherit;
  font-size: 0.82rem;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 6px;
  cursor: pointer;
}
.mod-btn:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
.mod-btn:disabled { opacity: 0.3; cursor: default; }

.dash-modules > .is-dragging { opacity: 0.45; }
.dash-modules > .is-over { outline: 2px solid var(--sel-2); outline-offset: 2px; }

/* outils d'une tuile KPI, en mode organisation */
.kpi { position: relative; }
.kpi-bar {
  position: absolute;
  top: 5px;
  right: 5px;
  display: flex;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
}
.kpi-btn {
  border: 0;
  background: transparent;
  color: var(--ink2);
  font: inherit;
  font-size: 0.72rem;
  line-height: 1;
  padding: 3px 5px;
  border-radius: 5px;
  cursor: pointer;
}
.kpi-btn:hover:not(:disabled) { background: var(--hover); color: var(--ink); }
.kpi-btn:disabled { opacity: 0.3; cursor: default; }

#layout-toggle.is-active { background: var(--sel); color: #fff; border-color: var(--sel); }

/* ---------- recherche globale : numéro entrant / sortant ---------- */
.filter-search { flex: 1 1 280px; min-width: 220px; }
.search-box { position: relative; flex: 1; }
#q-num {
  width: 100%;
  padding: 7px 11px;
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink);
  background: var(--surface-2);
  border: 1px solid var(--border-2);
  border-radius: 9px;
  transition: background 0.16s ease, border-color 0.16s ease;
}
#q-num:hover { border-color: var(--sel-2); }
#q-num:focus { background: var(--surface); outline: 2px solid var(--sel-2); outline-offset: 1px; }

.search-pop {
  position: absolute;
  z-index: 40;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  min-width: 420px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-3);
  padding: 6px;
}
@media (max-width: 620px) { .search-pop { min-width: 0; } }
.pop-head {
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 8px 10px 4px;
}
.pop-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 10px;
  border-radius: 8px;
}
.pop-row:hover { background: var(--hover); }
.pop-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.pop-tel { font-size: 0.9rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.pop-lab { font-size: 0.8rem; color: var(--ink2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-sub { font-size: 0.74rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pop-acts { display: flex; gap: 6px; flex: none; align-items: center; }
.pop-act {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--ink);
  font: inherit;
  border-radius: 9px;
  padding: 4px 11px;
  cursor: pointer;
  line-height: 1.15;
  transition: background 0.14s ease, border-color 0.14s ease, color 0.14s ease;
}
.pop-act b { font-size: 0.74rem; font-weight: 650; }
.pop-act span { font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.pop-act:hover { background: var(--hover); border-color: var(--sel-2); }
.pop-act.is-on { background: var(--sel); border-color: var(--sel); color: #fff; }
.pop-act.is-on span { color: rgba(255, 255, 255, 0.85); }
.pop-none { font-size: 0.76rem; color: var(--muted); }
.pop-ag {
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 0.88rem;
  color: var(--ink);
  background: transparent;
  border: 0;
  cursor: pointer;
}
.pop-empty, .pop-more { font-size: 0.82rem; color: var(--muted); padding: 10px; }

/* pastilles des filtres de numéro actifs */
.num-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.num-filter {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--sel);
  color: #fff;
  border-radius: 999px;
  padding: 4px 6px 4px 12px;
  font-size: 0.83rem;
  box-shadow: 0 1px 3px rgba(27, 114, 184, 0.4);
}
.num-filter b { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.85; }
.num-filter-x {
  border: 0;
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
  font: inherit;
  font-size: 0.72rem;
  line-height: 1;
  border-radius: 999px;
  padding: 4px 7px;
  cursor: pointer;
}
.num-filter-x:hover { background: rgba(255, 255, 255, 0.4); }
.num-filter-note { font-size: 0.78rem; color: var(--muted); }
.num-filter-empty { font-size: 0.8rem; font-weight: 600; color: var(--accent); }
