/* =====================================================================
   Entreprise de dépannage — système visuel
   Surface : panneau d'administration (Operate) + tableau de bord (Monitor).
   Parti pris : monochrome type Geist/Vercel ; la couleur ne sert qu'à l'état ;
   bordures par ombre (shadow-as-border) ; chiffres en tabular-nums.
   ===================================================================== */

:root {
  /* Marque Bernabé : bleu nuit #2B2A6E + rouge accent #E8232A (mesurés sur le logo).
     Le bleu porte la navigation, les boutons et les chiffres ; le rouge sert
     aux alertes et à la pastille du logo uniquement. */
  --brand:      #2B2A6E;
  --brand-deep: #211F58;
  --brand-ink:  #1A1849;
  --brand-soft: #EDEDF6;
  --brand-line: #D8D8E8;
  --accent:     #E8232A;
  --alert:      #B3111B;
  --alert-bg:   #FDECEC;

  /* Encres et surfaces */
  --ink:        #171717;
  --ink-2:      #4d4d4d;
  --ink-3:      #666666;
  --ink-4:      #707070;
  --surface:    #ffffff;
  --surface-2:  #fafafa;
  --surface-3:  #f4f4f5;
  --line:       #ebebeb;
  --line-strong:#d4d4d4;

  /* Ombres — technique shadow-as-border */
  --ring:       0 0 0 1px rgba(0, 0, 0, .08);
  --ring-light: 0 0 0 1px #ebebeb;
  --elev-1:     0 0 0 1px rgba(0,0,0,.08), 0 2px 2px rgba(0,0,0,.04), #fafafa 0 0 0 1px;

  /* Anneau de focus clavier (accessibilité) */
  --focus: hsla(212, 100%, 48%, 1);

  /* États : b-ok est bleu nuit (marque), b-warn orange, b-ko rouge accent */
  --ok-bg:   #e8f6ee; --ok-fg:   #0c6b45; --ok-dot:   #17a673;
  --warn-bg: #fdf3e3; --warn-fg: #8a5200; --warn-dot: #e0930c;
  --info-bg: #eef2f7; --info-fg: #4b5c70; --info-dot: #94a3b8;

  --radius:    6px;
  --radius-lg: 8px;
  --sidebar:   252px;
  /* Dégradé du bandeau finances (rôles dédiés : ne pas confondre avec
     --brand-ink, qui devient une couleur de texte en thème sombre) */
  --hero-a:     #211F58;
  --hero-b:     #1A1849;
  --mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: 'Geist', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--surface-2);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  font-feature-settings: "liga" 1;
  -webkit-font-smoothing: antialiased;
}

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

:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; border-radius: 3px; }

/* ---------- Grille applicative : barre latérale + contenu ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar);
  flex: 0 0 var(--sidebar);
  background: var(--brand-deep);
  color: #EDEDF6;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { padding: 1.15rem 1.15rem .95rem; box-shadow: 0 1px 0 rgba(255, 255, 255, .14); }
.brand a { color: #fff; text-decoration: none; display: block; }
.brand a:hover { text-decoration: none; }
.brand strong { font-weight: 600; letter-spacing: -.02em; font-size: 1.02rem; }
.brand-logo { display: block; width: 46px; height: 46px; border-radius: 9px; margin-bottom: .55rem; box-shadow: 0 0 0 1px rgba(255,255,255,.22); }
.brand-nom { display: block; font-weight: 600; font-size: 1.06rem; letter-spacing: -.02em; }
.brand-sub {
  display: block;
  margin-top: .3rem;
  font-family: var(--mono);
  font-size: .66rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #C9C9E4;
}

.sidebar nav { padding: .7rem .6rem; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav {
  /* Fenêtres basses : la nav défile, la marque et le pied restent visibles */
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.25) transparent;
}
.sidebar-foot { flex: none; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: .55rem;
  padding: .48rem .65rem;
  border-radius: var(--radius);
  color: #D9D9EE;
  font-size: .89rem;
  font-weight: 500;
  text-decoration: none;
}
.sidebar nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar nav a.active { background: #fff; color: var(--brand-ink); font-weight: 600; }
.sidebar nav a.active:hover { background: #fff; }

.sidebar-foot {
  margin-top: auto;
  padding: .9rem 1.15rem 1.1rem;
  box-shadow: 0 -1px 0 rgba(255, 255, 255, .14);
  font-size: .78rem;
  color: #B9B9D9;
}
.sidebar-foot a { display: block; margin-top: .3rem; font-size: .78rem; color: #EDEDF6; }
.sidebar-foot code { font-family: var(--mono); font-size: .72rem; color: #EDEDF6; }

/* ---------- Colonne de contenu ---------- */
.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.page-head {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.6rem;
  background: var(--surface);
  box-shadow: 0 1px 0 var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}
.page-head h1 { margin: 0; font-size: 1.12rem; font-weight: 600; letter-spacing: -.02em; }

/* Fil d'Ariane : toujours savoir où l'on est et revenir d'où l'on vient */
.ariane {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .45rem;
  margin-top: .25rem;
  font-family: var(--mono);
  font-size: .7rem;
  letter-spacing: .02em;
}
.ariane a { color: var(--brand); text-decoration: none; }
.ariane a:hover { text-decoration: underline; }
.ariane .sep { color: var(--ink-4); }
.ariane .ici { color: var(--ink-2); font-weight: 500; }
.page-head .spacer { margin-left: auto; }

.content { padding: 1.4rem 1.6rem 2.6rem; max-width: 1220px; width: 100%; }

/* Le titre de page est rendu par le gabarit : le <h1> de la vue est masqué */
.content > h1:first-child { display: none; }
.content > h1 { font-size: 1rem; font-weight: 600; margin: 1.8rem 0 .7rem; letter-spacing: -.01em; }
.content > h2 { font-size: 1.05rem; font-weight: 600; margin: 1.7rem 0 .6rem; letter-spacing: -.01em; }
.content > p.card { line-height: 1.6; color: var(--ink-2); font-size: .9rem; }

/* ---------- Cartes ---------- */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-1);
  padding: 1.1rem 1.2rem 1.2rem;
  margin-bottom: 1.1rem;
}
.card > h1 { font-size: 1.28rem; margin: 0 0 .7rem; letter-spacing: -.02em; }
.card > h2 {
  margin: 0 0 .85rem;
  font-size: .95rem;
  font-weight: 600;
  letter-spacing: -.01em;
  display: flex;
  align-items: center;
  gap: .6rem;
  flex-wrap: wrap;
}
.card h3 {
  font-family: var(--mono);
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-4);
  font-weight: 500;
  margin: 1.2rem 0 .5rem;
}
.card h3:first-child { margin-top: 0; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 1.1rem; align-items: stretch; }
.grid-2 > * { min-width: 0; }   /* un contenu long (URL…) ne force plus la piste à s'élargir */
.grid-2 > .card { margin-bottom: 0; display: flex; flex-direction: column; }
/* Le donut se centre dans l'espace restant quand la carte est étirée */
.grid-2 > .card .donut-wrap { margin-top: auto; margin-bottom: auto; }

/* ---------- Carte identité de l'entreprise (liseré bleu nuit en tête) ---------- */
.ent-card { padding: 1.2rem 1.3rem 1.3rem; border-top: 3px solid var(--brand); }
.ent-top { display: flex; gap: 1.1rem; align-items: flex-start; }
.ent-logo { width: 104px; height: 104px; border-radius: 10px; box-shadow: var(--ring); flex: none; }
.ent-top h2 { margin-top: 0; }
.ent-baseline { font-size: 1.02rem; font-weight: 500; margin: .15rem 0 .5rem; }
.ent-chiffres {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: .5rem .9rem;
  margin: .9rem 0 1.1rem;
  padding-top: .9rem;
  box-shadow: inset 0 1px 0 var(--line);
}
.ent-chiffres .k {
  display: block;
  font-family: var(--mono);
  font-size: .64rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-4);
}
.ent-chiffres .v { font-size: .95rem; font-weight: 600; }
.ent-stat { min-width: 0; }
.ent-chiffres .v { overflow-wrap: anywhere; }
.ent-photos { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: .9rem; }
.ent-photos figure { margin: 0; }
.ent-photos img { display: block; width: 100%; height: auto; border-radius: 8px; box-shadow: var(--ring); }
.ent-photos figcaption { font-size: .78rem; color: var(--ink-4); margin-top: .35rem; }

/* ---------- Bandeau d'indicateurs (un seul bloc, séparateurs internes) ---------- */
.kpi-band {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-1);
  overflow: hidden;
  margin-bottom: 1.1rem;
}
.kpi { padding: .85rem 1.05rem; box-shadow: 1px 0 0 var(--line); position: relative; }
.kpi:last-child { box-shadow: none; }
.kpi::before {
  content: "";
  position: absolute;
  left: 0;
  top: .85rem;
  bottom: .85rem;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--brand);
}
.kpi .k {
  font-family: var(--mono);
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-4);
}
.kpi .v {
  font-size: 1.34rem;
  font-weight: 600;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  margin-top: .16rem;
}
.kpi .v.small { font-size: .95rem; letter-spacing: -.01em; }
.kpi .n { font-size: .73rem; color: var(--ink-4); margin-top: .1rem; }

/* Blocs .stat conservés pour les pages qui en utilisent */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; margin-bottom: 1.1rem; }
.stat {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-1);
  padding: .8rem 1rem;
}
.stat .label { font-family: var(--mono); font-size: .65rem; text-transform: uppercase; letter-spacing: .07em; color: var(--ink-4); }
.stat .value { font-size: 1.28rem; font-weight: 600; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.stat .value.small { font-size: .95rem; letter-spacing: -.01em; }

/* ---------- Barres : données réelles uniquement ---------- */
.bars { display: flex; flex-direction: column; gap: .5rem; }
.bar-row { display: grid; grid-template-columns: 9.5rem 1fr 4rem; align-items: center; gap: .7rem; }
.bar-row .bl { font-size: .84rem; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 7px; background: #E6E6F2; border-radius: 999px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; min-width: 3px; }
.bar-row .bv {
  font-family: var(--mono);
  font-size: .76rem;
  text-align: right;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.bar-row.alt .bar > span { background: var(--ink-4); }

/* ---------- Pagination ---------- */
.pagination {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .45rem;
  margin-top: .8rem;
}
.pagination .page-info {
  font-family: var(--mono);
  font-size: .72rem;
  color: var(--ink-2);
  margin-right: .4rem;
  font-variant-numeric: tabular-nums;
}
.pagination .numero {
  display: inline-block;
  min-width: 1.9rem;
  text-align: center;
  padding: .26rem .4rem;
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
  border-radius: var(--radius);
  box-shadow: var(--ring-light);
  color: var(--ink);
  text-decoration: none;
  background: var(--surface);
}
.pagination .numero:hover { background: var(--surface-3); }
.pagination .numero.courant { background: var(--brand); color: #fff; font-weight: 600; }
.pagination .ellipse { color: var(--ink-4); padding: 0 .15rem; }
.pagination .inactif {
  opacity: .45;
  cursor: default;
  color: var(--ink-3);
}

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; margin: 0 -.3rem; padding: 0 .3rem; }
table { width: 100%; border-collapse: collapse; font-size: .855rem; font-variant-numeric: tabular-nums; }
th, td { padding: .48rem .7rem; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); }
th {
  font-family: var(--mono);
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 500;
  color: var(--ink-4);
  background: var(--surface-2);
  white-space: nowrap;
}
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.actions { text-align: right; white-space: nowrap; width: 1%; }
td.actions .btn.small + .btn.small { margin-left: .3rem; }

/* ---------- Filtres façon Excel + tri au clic ---------- */
th a.tri { color: inherit; text-decoration: none; display: inline-block; }
th a.tri:hover { color: var(--ink); text-decoration: underline; }
th a.tri .fleche { color: var(--brand); font-weight: 700; }
tr.filtres td { background: var(--surface-2); padding: .3rem .5rem; border-bottom: 2px solid var(--line); }
tr.filtres input, tr.filtres select {
  width: 100%;
  min-width: 4.5rem;
  padding: .22rem .4rem;
  font-size: .8rem;
  border-radius: 4px;
}
tr.filtres td.actions { vertical-align: middle; }
/* Le formulaire GET des filtres est invisible : seuls ses champs (dans le tableau) comptent. */
form.form-filtres { display: contents; }

/* ---------- Édition en ligne d'une ligne de tableau ---------- */
.liste-bloc { min-height: 1.5rem; }
tr.ligne-edition {
  background: #fbfdff;
  box-shadow: inset 0 0 0 2px rgba(0, 114, 245, .22);
  scroll-margin-top: 5.5rem;   /* la ligne reste visible sous l'en-tête collant */
}
tr.ligne-edition:hover { background: #fbfdff; }
td input, td select {
  padding: .22rem .4rem;
  font-size: .84rem;
  border-radius: 4px;
  min-width: 6rem;
  max-width: 100%;
}
td input[type=date], td input[type=number] { min-width: 5.5rem; }
td select { min-width: 7rem; }
td.actions button { padding: .3rem .6rem; font-size: .8rem; }
.empty { color: var(--ink-4); font-style: italic; margin: .3rem 0; }

/* ---------- Formulaires ---------- */
form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: .75rem 1rem;
  align-items: end;
}
label { display: flex; flex-direction: column; gap: .28rem; font-size: .78rem; color: var(--ink-2); font-weight: 500; }
input, select, textarea {
  padding: .45rem .55rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: .87rem;
}
input:hover, select:hover { border-color: var(--ink-4); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(43, 42, 110, .15);
}
.form-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: .55rem; align-items: center; margin: .25rem 0 0; }

button, .btn {
  display: inline-block;
  font: inherit;
  font-size: .855rem;
  font-weight: 500;
  padding: .46rem .9rem;
  border-radius: var(--radius);
  border: none;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.3;
}
button:hover, .btn:hover { background: var(--brand-deep); text-decoration: none; }
button:active, .btn:active { background: var(--brand-ink); }
.btn.small {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--ring-light);
  padding: .26rem .6rem;
  font-size: .78rem;
  font-weight: 400;
}
.btn.small:hover { background: var(--surface-3); }

.sous-form {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: .75rem 1rem;
  align-items: end;
  padding-top: .6rem;
  box-shadow: 0 -1px 0 var(--line);
  margin-top: .4rem;
}

/* ---------- Messages : succès vert conservé (pas de confusion avec le bleu de marque), erreur rouge accent ---------- */
.flash, .error { border-radius: var(--radius); padding: .6rem .85rem; font-size: .86rem; margin: 0 0 1rem; }
.flash { background: var(--ok-bg); color: var(--ok-fg); box-shadow: 0 0 0 1px rgba(12,107,69,.18); }
.error { background: var(--alert-bg); color: var(--alert); box-shadow: 0 0 0 1px rgba(179,17,27,.22); }

/* ---------- Badges d'état ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  font-size: .74rem;
  font-weight: 500;
  padding: .08rem .5rem .08rem .45rem;
  border-radius: 999px;
  background: var(--info-bg);
  color: var(--info-fg);
  white-space: nowrap;
}
.badge::before { content: ""; width: .38rem; height: .38rem; border-radius: 50%; background: var(--info-dot); flex: none; }
.badge.b-ok   { background: var(--brand-soft); color: var(--brand-ink); }
.badge.b-ok::before   { background: var(--brand); }
.badge.b-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge.b-warn::before { background: var(--warn-dot); }
.badge.b-ko   { background: var(--alert-bg); color: var(--alert); }
.badge.b-ko::before   { background: var(--accent); }
.badge.b-muted { background: var(--info-bg); color: var(--info-fg); }

/* Puces de section : pastille rouge Bernabé devant chaque titre de carte */
.card > h2::before {
  content: "";
  width: .5rem;
  height: .5rem;
  border-radius: 2px;
  background: var(--accent);
  flex: none;
}

/* Carte entreprise : liseré bleu nuit en tête */
.ent-card { border-top: 3px solid var(--brand); }

/* ---------- Divers ---------- */
.muted { color: var(--ink-4); }
p.info { margin: .22rem 0; font-size: .88rem; display: flex; gap: .6rem; min-width: 0; overflow-wrap: anywhere; }
p.info span {
  flex: 0 0 9rem;
  color: var(--ink-4);
  font-family: var(--mono);
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding-top: .2rem;
}
p.total { margin: 1rem 0 0; font-size: .95rem; }
p.total strong { font-variant-numeric: tabular-nums; }

pre.sql {
  background: #0f0f0f;
  color: #e5e5e5;
  padding: .85rem 1rem;
  border-radius: var(--radius);
  overflow-x: auto;
  font-family: var(--mono);
  font-size: .78rem;
  line-height: 1.55;
  margin: 0 0 .8rem;
}

.arbre { margin: .2rem 0 .7rem 1rem; padding-left: .9rem; border-left: 1px solid var(--line); font-size: .85rem; }
.arbre li { margin: .18rem 0; }
.arbre .qte { color: var(--ink-4); font-family: var(--mono); font-size: .74rem; }

code { font-family: var(--mono); font-size: .84em; background: var(--surface-3); padding: .1rem .3rem; border-radius: 4px; }

/* ---------- Assistant IA & Recherche ---------- */
.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;
}

.form-assistant {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .5rem;
  margin: .2rem 0 .9rem;
}
.form-assistant input[type="text"] {
  flex: 1 1 22rem;
  min-width: 12rem;
  padding: .55rem .75rem;
  font-size: .95rem;
  border-radius: var(--radius);
}
.form-assistant button { flex: 0 0 auto; }

.exemples { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; margin-top: .5rem; }
.chip {
  display: inline-block;
  padding: .22rem .6rem;
  font-size: .78rem;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-ink);
  text-decoration: none;
  box-shadow: var(--ring-light);
}
.chip:hover { background: var(--brand); color: #fff; }

.fiche { border-top: 1px solid var(--line); }
.fiche-ligne {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: .45rem .1rem;
  border-bottom: 1px solid var(--line);
}
.fiche-ligne .cle { color: var(--ink-2); font-size: .86rem; }
.fiche-ligne .val { font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; }

.section-titre {
  margin: 1.1rem 0 .4rem;
  font-size: .82rem;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-3);
}
.section-titre:first-of-type { margin-top: .3rem; }

.sql-details { margin-top: .9rem; }
.sql-details summary {
  cursor: pointer;
  font-size: .8rem;
  color: var(--ink-2);
  padding: .25rem 0;
}
.sql-details summary:hover { color: var(--brand); }
pre.sql {
  overflow-x: auto;
  font-family: var(--mono);
  font-size: .78rem;
  line-height: 1.5;
  background: var(--surface-3);
  border-left: 3px solid var(--brand);
  padding: .6rem .8rem;
  margin: .4rem 0 0;
  border-radius: 4px;
  white-space: pre;
  color: var(--ink);
}

.synthese { border-left: 3px solid var(--brand); }
.synthese p { margin: .3rem 0; }

/* ---------- Impression ---------- */
@media print {
  body { background: #fff; font-size: 11.5pt; }
  .sidebar, .no-print, footer, form, .btn, button { display: none !important; }
  .app { display: block; }
  .page-head { position: static; padding: 0 0 .3cm; box-shadow: none; }
  .page-head h1 { font-size: 15pt; }
  .content { padding: 0; max-width: none; }
  .content > h1:first-child { display: none; }
  .card, .kpi-band, .stat {
    box-shadow: none !important;
    border: 1px solid #999;
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: .4cm;
  }
  .card > h2 { border-bottom: 1px solid #ccc; padding-bottom: .12cm; }
  .ent-logo { width: 72px; height: 72px; }
  .ent-photos { gap: .4cm; }
  .ent-photos img { max-height: 5.5cm; width: auto; }
  .ent-chiffres { break-inside: avoid; }
  table { font-size: 9.5pt; }
  th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  th, td { border: 1px solid #999; padding: 2px 4px; }
  tbody tr:hover { background: transparent; }
  .badge { box-shadow: 0 0 0 1px #999; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  pre.sql { background: #f5f5f5; color: #111; border: 1px solid #999; break-inside: avoid; }
  .bar > span { background: #555 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  a { color: #000; text-decoration: none; }
}

/* =====================================================================
   COMPLÉMENTS DE SYSTÈME — composants du gabarit et des vues,
   thème sombre (data-theme="dark").
   Même langage visuel : shadow-as-border, micro-libellés mono
   majuscules, tabular-nums, bleu nuit Bernabé + rouge accent.
   ===================================================================== */

/* ---------- Taille d'icône normalisée (nav + boutons) ---------- */
.nav-ico { width: 1.05rem; height: 1.05rem; flex: none; }
.btn-ico { width: .95rem; height: .95rem; flex: none; }
.btn.small { display: inline-flex; align-items: center; gap: .35rem; }

/* ---------- Barre latérale : marque, groupes de nav, pied ---------- */
.brand-link { display: block; }
.brand-meta { display: block; }
.brand-pill {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  margin-top: .75rem;
  padding: .24rem .65rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, .09);
  font-size: .72rem;
  color: #C9C9E4;
}
.brand-pill code {
  font-family: var(--mono);
  font-size: .7rem;
  background: rgba(255, 255, 255, .12);
  color: #EDEDF6;
  padding: .05rem .35rem;
}
.status-dot {
  width: .45rem;
  height: .45rem;
  border-radius: 50%;
  background: #3ddc84;
  box-shadow: 0 0 0 2px rgba(61, 220, 132, .22);
  flex: none;
}

.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-group + .nav-group { margin-top: .7rem; }
.nav-group-label {
  font-family: var(--mono);
  font-size: .62rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #9998C4;
  padding: .3rem .65rem .25rem;
}
.nav-group-label:first-child { padding-top: 0; }
.sidebar nav a .nav-text { flex: 1 1 auto; min-width: 0; }
.nav-kbd {
  margin-left: auto;
  font-family: var(--mono);
  font-size: .64rem;
  line-height: 1;
  padding: .16rem .34rem;
  border-radius: 4px;
  background: rgba(255, 255, 255, .1);
  color: #C9C9E4;
}
.sidebar nav a.active .nav-kbd { background: rgba(43, 42, 110, .14); color: var(--brand-ink); }

.sidebar-foot-row { display: flex; align-items: center; justify-content: space-between; gap: .5rem; }
.foot-label { font-family: var(--mono); font-size: .64rem; text-transform: uppercase; letter-spacing: .06em; }
.pma-link { color: #fff; text-decoration: none; box-shadow: 0 0 0 1px rgba(255,255,255,.25); border-radius: 999px; padding: .12rem .55rem; font-size: .72rem; display: inline-block; margin-top: 0; white-space: nowrap; }
.pma-link:hover { background: rgba(255, 255, 255, .12); text-decoration: none; }

/* ---------- En-tête de page : toolbar, recherche omnibox ---------- */
.page-head-titles { min-width: 0; }
.head-toolbar { display: flex; align-items: center; gap: .5rem; flex: none; }

.omni-search {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: min(400px, 36vw);
  padding: 0 .6rem;
  background: var(--surface-2);
  border-radius: var(--radius);
  box-shadow: var(--ring-light);
}
.omni-search:focus-within {
  box-shadow: 0 0 0 1px var(--brand), 0 0 0 3px rgba(43, 42, 110, .15);
  background: var(--surface);
}
.omni-search input {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  background: transparent;
  padding: .44rem 0;
  font-size: .85rem;
  box-shadow: none;
}
.omni-search input:hover { border: none; }
.omni-search input:focus { border: none; box-shadow: none; outline: none; }
.omni-ico { width: .95rem; height: .95rem; color: var(--ink-4); flex: none; }
.omni-kbd {
  font-family: var(--mono);
  font-size: .64rem;
  line-height: 1;
  color: var(--ink-4);
  background: var(--surface);
  box-shadow: var(--ring-light);
  border-radius: 4px;
  padding: .18rem .36rem;
  flex: none;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.05rem;
  height: 2.05rem;
  padding: 0;
  background: transparent;
  color: var(--ink-2);
  border-radius: var(--radius);
}
.btn-icon svg { width: 1.05rem; height: 1.05rem; }
.btn-icon:hover { background: var(--surface-3); }
.btn-icon:active { background: var(--line); }
/* Soleil visible en sombre, lune en clair */
.ico-sun { display: none; }
[data-theme="dark"] .ico-sun { display: block; }
[data-theme="dark"] .ico-moon { display: none; }

/* ---------- Messages flash : pastille d'état ---------- */
.flash, .error { display: flex; align-items: center; gap: .55rem; }
.flash-dot { width: .45rem; height: .45rem; border-radius: 50%; background: currentColor; flex: none; }

/* ---------- Cartes : en-tête avec actions, sous-titre, séparateur ---------- */
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .6rem 1rem;
  flex-wrap: wrap;
  margin-bottom: .85rem;
}
.card-head > div { min-width: 0; }
.card-head h2 { margin-bottom: 0; }
.card-sub { margin: .3rem 0 0; font-size: .82rem; color: var(--ink-4); max-width: 75ch; line-height: 1.5; }
.card-sub a { color: var(--brand); }
.card-actions { display: flex; align-items: center; gap: .5rem; flex: none; flex-wrap: wrap; }

.form-divider { grid-column: 1 / -1; height: 1px; background: var(--line); margin: .35rem 0; }

.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(255px, 1fr)); gap: 1.1rem; align-items: stretch; margin-bottom: 1.1rem; }
.grid-3 > .card { margin-bottom: 0; }

.small { font-size: .8rem; }

/* ---------- Tableau de bord : bandeau finances (focal bleu nuit) ---------- */
.fin-hero {
  position: relative;
  display: flex;
  align-items: stretch;
  flex-wrap: wrap;
  gap: 0;
  background: linear-gradient(135deg, var(--hero-a) 0%, var(--hero-b) 100%);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-1);
  color: #fff;
  overflow: hidden;
  margin-bottom: 1.1rem;
}
/* Liseré rouge Bernabé en tête du bandeau */
.fin-hero::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: var(--accent);
}
.fin-main {
  flex: 1 1 300px;
  padding: 1.35rem 1.5rem 1.3rem;
  box-shadow: 1px 0 0 rgba(255, 255, 255, .14);
}
.fin-main .k {
  display: block;
  font-family: var(--mono);
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #B9B9D9;
}
.fin-main .v {
  display: block;
  margin-top: .3rem;
  font-size: 2.3rem;
  font-weight: 600;
  letter-spacing: -.035em;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.fin-main .n {
  display: block;
  margin-top: .45rem;
  font-size: .8rem;
  color: #C9C9E4;
}
.fin-grid {
  flex: 2 1 420px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
}
.fin-cell {
  padding: 1.35rem 1.2rem 1.3rem;
  box-shadow: 1px 0 0 rgba(255, 255, 255, .14);
}
.fin-cell:last-child { box-shadow: none; }
.fin-cell .k {
  display: block;
  font-family: var(--mono);
  font-size: .64rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #B9B9D9;
  line-height: 1.4;
  min-height: 2.8em;   /* deux lignes de libellé : montants sur une base commune */
}
.fin-cell .v {
  display: block;
  margin-top: .35rem;
  font-size: 1.18rem;
  font-weight: 600;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- Barre de répartition cumulée (statuts) ---------- */
.stack-bar {
  display: flex;
  height: 11px;
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface-3);
  margin: .9rem 0 .2rem;
}
.stack-bar .seg { display: block; height: 100%; min-width: 4px; }
.seg-ok   { background: var(--brand); }
.seg-warn { background: var(--warn-dot); }
.seg-info { background: var(--info-dot); }
.seg-avance { background: var(--info-dot); }
.seg-inter  { background: var(--ink-4); }

/* ---------- Ligne de légende (statuts, donut) ---------- */
.stack-legend, .donut-legend { display: flex; flex-direction: column; gap: .42rem; }
.stack-legend { margin-top: .85rem; }
.dist-row {
  display: grid;
  grid-template-columns: .55rem 1fr auto 3.6rem;
  gap: .6rem;
  align-items: center;
  font-size: .85rem;
}
.dist-row .dot { width: .55rem; height: .55rem; border-radius: 50%; }
.dist-row .lb { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dist-row .ct { font-weight: 600; font-variant-numeric: tabular-nums; }
.dist-row .pc {
  font-family: var(--mono);
  font-size: .74rem;
  color: var(--ink-4);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ---------- Donut CSS (parc matériel) ---------- */
.donut-wrap {
  display: flex;
  align-items: center;
  gap: 1.6rem;
  flex-wrap: wrap;
  margin-top: .9rem;
}
.donut {
  position: relative;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  flex: none;
}
.donut-hole {
  position: absolute;
  inset: 21%;
  background: var(--surface);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .05rem;
}
.donut-hole .v { font-size: 1.55rem; font-weight: 600; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.donut-hole .k {
  font-family: var(--mono);
  font-size: .6rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-4);
}
.donut-legend { flex: 1 1 180px; min-width: 0; }

/* Viewurs étroits (< 1300 px) : cellules finances en 2×2, montants sans débord */
@media (max-width: 1300px) {
  .fin-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fin-cell { box-shadow: 1px 0 0 rgba(255, 255, 255, .14), 0 1px 0 rgba(255, 255, 255, .14); }
  .fin-cell:nth-child(2n) { box-shadow: 0 1px 0 rgba(255, 255, 255, .14); }
  .fin-cell:nth-last-child(-n+2) { box-shadow: none; }
  .fin-main { box-shadow: 0 1px 0 rgba(255, 255, 255, .14); flex-basis: 100%; }
}

/* ---------- Tableau de bord : bandeau finances + faits saillants ---------- */
.kpi-finances .kpi::before { background: var(--accent); }

.highlights-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(225px, 1fr)); gap: .9rem; }
.highlight-item {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: .12rem;
  padding: .8rem .95rem .8rem calc(.95rem + 3px);
  background: var(--surface-2);
  border-radius: var(--radius);
  box-shadow: var(--ring-light);
  overflow: hidden;
}
.highlight-item::before {
  content: "";
  position: absolute;
  left: 0;
  top: .8rem;
  bottom: .8rem;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--brand);
}
.highlight-item.hl-accent::before { background: var(--accent); }
.hl-k {
  font-family: var(--mono);
  font-size: .64rem;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--ink-4);
}
.hl-v { font-size: .98rem; font-weight: 600; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }
.hl-n { font-size: .76rem; color: var(--ink-4); }

/* Pastille de numéro d'intervention */
.id-pill {
  font-family: var(--mono);
  font-size: .74rem;
  font-variant-numeric: tabular-nums;
  background: var(--brand-soft);
  color: var(--brand-ink);
  padding: .1rem .5rem;
  border-radius: 999px;
  text-decoration: none;
  white-space: nowrap;
}
.id-pill:hover { background: var(--brand); color: #fff; text-decoration: none; }

/* ---------- Assistant IA ---------- */
.assistant-hero { border-top: 3px solid var(--brand); }
.assistant-input-wrap { position: relative; flex: 1 1 22rem; min-width: 12rem; }
.assistant-ico {
  position: absolute;
  left: .75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.05rem;
  height: 1.05rem;
  color: var(--ink-4);
  pointer-events: none;
}
.assistant-input-wrap input {
  width: 100%;
  padding: .58rem .75rem .58rem 2.4rem;
  font-size: .95rem;
  border-radius: var(--radius);
}
.exemples-label {
  font-family: var(--mono);
  font-size: .66rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-4);
  margin-right: .2rem;
}
.reponse-lead { font-size: 1rem; font-weight: 500; margin: .15rem 0 .55rem; }
.section-block { margin-top: 1.3rem; }
.section-block:first-of-type { margin-top: .4rem; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .6rem;
  flex-wrap: wrap;
}
.section-head .section-titre { margin: 0; }

/* ---------- Assistant : conversation ---------- */
.chat-card { display: flex; flex-direction: column; }
.chat {
  display: flex;
  flex-direction: column;
  gap: .8rem;
  max-height: min(64vh, 660px);
  overflow-y: auto;
  padding: .25rem .2rem .35rem;
  scroll-behavior: smooth;
}
.chat-accueil { padding: .3rem .2rem .6rem; }
.chat-accueil .reponse-lead { margin-top: 0; }

.tour { display: flex; flex-direction: column; gap: .5rem; }

.bulle {
  border-radius: 14px;
  padding: .6rem .85rem;
  max-width: 96%;
}
.bulle > :first-child { margin-top: 0; }
.bulle > :last-child { margin-bottom: 0; }

/* Question de l'utilisateur : à droite, en couleur de marque */
.bulle-moi {
  align-self: flex-end;
  max-width: 78%;
  background: var(--brand);
  color: #fff;
  border-bottom-right-radius: 5px;
}
.bulle-moi p { margin: 0; }

/* Réponse de l'assistant : à gauche, sur la surface de la page */
.bulle-assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 5px;
}
.bulle-entete {
  font-weight: 600;
  font-size: .95rem;
  letter-spacing: -.01em;
  margin-bottom: .3rem;
  color: var(--brand-ink);
}
.synthese {
  border-left: 3px solid var(--brand);
  padding-left: .6rem;
  margin: .6rem 0 .2rem;
  font-style: italic;
  color: var(--ink-2);
}

.chat-compose {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
  margin-top: .9rem;
}
.chat-compose button { flex: 0 0 auto; }
.chat-compose .chat-send svg { display: none; }
.chat-compose .assistant-input-wrap { flex: 1 1 22rem; }
.chat-compose .voice-status { flex: 1 0 100%; }
.assistant-voice {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border-radius: 50%;
  background: var(--surface);
  color: var(--brand);
  box-shadow: var(--ring-light);
}
.assistant-voice[hidden] { display: none; }
.assistant-voice:hover { background: var(--brand-soft); color: var(--brand); }
.assistant-voice svg { width: 1.15rem; height: 1.15rem; }
.assistant-voice.en-ecoute {
  background: var(--alert-bg);
  color: var(--alert);
  box-shadow: 0 0 0 2px var(--accent);
  animation: chargement-pulse 1.2s ease-in-out infinite;
}
.voice-status { color: var(--ink-3); font-size: .82rem; }
.assistant-pop-foot .assistant-voice { width: 2.3rem; height: 2.3rem; }
.assistant-pop-foot .voice-status { flex: 1 0 100%; }
.voice-status:empty { display: none; }
.voice-status:not(:empty) {
  display: block;
  flex: 1 0 100%;
  line-height: 1.4;
}

.chat-outils {
  display: flex;
  align-items: center;
  gap: .8rem;
  flex-wrap: wrap;
  margin-top: .7rem;
  padding-top: .7rem;
  border-top: 1px solid var(--line);
}
.chat-outils form { margin: 0; }
.exemples-bloc { flex: 1 1 100%; }
.exemples-bloc summary {
  cursor: pointer;
  font-size: .8rem;
  color: var(--ink-2);
  padding: .1rem 0;
}
.exemples-bloc summary:hover { color: var(--brand); }
.exemples-bloc .exemples { margin-top: .5rem; }

/* Formulaire préparé par l'assistant : il vit dans la bulle, en grille compacte */
.form-fiche { margin-top: .5rem; gap: .6rem .8rem; }
.form-fiche label { font-size: .74rem; }
.form-fiche .form-actions { margin-top: .1rem; }

/* Choix d'une fiche parmi plusieurs */
.choix { display: flex; flex-direction: column; gap: .3rem; margin-top: .5rem; }
.choix-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .8rem;
  padding: .42rem .6rem;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--ring-light);
  color: var(--ink);
  text-decoration: none;
}
.choix-item:hover { background: var(--brand); color: #fff; }
.choix-item .choix-id { font-family: var(--mono); font-size: .72rem; color: var(--ink-4); }
.choix-item:hover .choix-id { color: inherit; }

/* Le bleu de marque s'éclaircit en thème sombre : la bulle utilise l'indigo soutenu */
[data-theme="dark"] .bulle-moi { background: #4C4BB0; color: #fff; }
[data-theme="dark"] .bulle-assistant { background: var(--surface); }

/* À l'impression, la conversation se déroule en entier (pas de zone défilante) */
@media print {
  .chat { max-height: none; overflow: visible; display: block; }
  .tour { display: block; margin-bottom: .35cm; }
  .bulle { max-width: 100%; border: 1px solid #999; break-inside: avoid; page-break-inside: avoid; }
  .bulle-moi { background: #eee !important; color: #000 !important; }
}

/* ---------- Carte entreprise : blocs complémentaires ---------- */
.ent-intro { min-width: 0; }
.ent-title-row { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem; }
.ent-title-row h2 { margin: 0; font-size: 1.22rem; letter-spacing: -.02em; }
.ent-stat { display: block; }
.photo-frame { border-radius: 8px; overflow: hidden; box-shadow: var(--ring); }
.photo-frame img { display: block; width: 100%; height: auto; }
.sites-list { display: flex; flex-direction: column; }
.ent-footer-grid {
  margin-top: 1.1rem;
  padding-top: 1rem;
  box-shadow: inset 0 1px 0 var(--line);
}
p.info span.bullet-dot {
  flex: 0 0 .45rem;
  width: .45rem;
  height: .45rem;
  border-radius: 50%;
  background: var(--accent);
  margin-top: .5rem;
  font-size: 0;
  padding: 0;
}

/* ---------- Parc matériel : arbre de composition ---------- */
.arbre-box { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; align-items: start; margin: .5rem 0 .3rem; }
.arbre-group {
  background: var(--surface-2);
  border-radius: var(--radius);
  box-shadow: var(--ring-light);
  padding: .8rem 1rem .9rem;
}
.arbre-group h3 { margin-top: 0; display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

/* =====================================================================
   THÈME SOMBRE — mêmes rôles, valeurs recalibrées.
   Le bleu nuit de marque s'éclaircit pour rester lisible sur fond sombre.
   ===================================================================== */
[data-theme="dark"] {
  --brand:      #8F8EE6;
  --brand-deep: #14132E;
  --brand-ink:  #C9C8F2;
  --brand-soft: #232249;
  --brand-line: #32315E;
  --accent:     #FF5C61;
  --alert:      #FF7A7E;
  --alert-bg:   #2C1518;

  --ink:        #ECECEF;
  --ink-2:      #B7B7C2;
  --ink-3:      #9C9CA8;
  --ink-4:      #8B8B98;
  --surface:    #17171F;
  --surface-2:  #111118;
  --surface-3:  #20202B;
  --line:       #272733;
  --line-strong:#3A3A48;

  --ring:       0 0 0 1px rgba(255, 255, 255, .09);
  --ring-light: 0 0 0 1px #272733;
  --elev-1:     0 0 0 1px rgba(255,255,255,.07), 0 2px 6px rgba(0,0,0,.35);

  --focus: #8AA2FF;

  --ok-bg:   #12291F; --ok-fg:   #7FD8AE; --ok-dot:   #2FBE87;
  --warn-bg: #2B2113; --warn-fg: #E8BE7A; --warn-dot: #D99A2B;
  --info-bg: #1D232C; --info-fg: #9FADBE; --info-dot: #5C6B7F;

  --hero-a: #1C1B44;
  --hero-b: #121130;

  color-scheme: dark;
}

/* Boutons : fond indigo soutenu (le --brand éclairci servirait de texte) */
[data-theme="dark"] button,
[data-theme="dark"] .btn { background: #4C4BB0; color: #fff; }
[data-theme="dark"] button:hover,
[data-theme="dark"] .btn:hover { background: #5A59C2; }
[data-theme="dark"] button:active,
[data-theme="dark"] .btn:active { background: #41409B; }
[data-theme="dark"] .btn.small { background: var(--surface); color: var(--ink); box-shadow: var(--ring-light); }
[data-theme="dark"] .btn.small:hover { background: var(--surface-3); }

/* Sidebar : le lien actif reste une pastille claire (contraste fort) */
[data-theme="dark"] .sidebar nav a.active { background: #ECEAFB; color: #1A1849; }
[data-theme="dark"] .sidebar nav a.active .nav-kbd { background: rgba(43, 42, 110, .16); color: #2B2A6E; }

/* Champs : anneau de focus adapté */
[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(143, 142, 230, .22);
}
[data-theme="dark"] .omni-search:focus-within { box-shadow: 0 0 0 1px var(--brand), 0 0 0 3px rgba(143, 142, 230, .22); }

/* Valeurs codées en dur en clair, recalibrées en sombre */
[data-theme="dark"] .bar { background: #2A2A3D; }
[data-theme="dark"] tr.ligne-edition,
[data-theme="dark"] tr.ligne-edition:hover {
  background: #1B2233;
  box-shadow: inset 0 0 0 2px rgba(138, 162, 255, .3);
}
[data-theme="dark"] pre.sql { background: #101017; color: #D6D6DE; border-left-color: var(--brand); }
[data-theme="dark"] .pagination .numero.courant { background: #4C4BB0; color: #fff; }
[data-theme="dark"] .chip:hover { background: var(--brand); color: #14132E; }
[data-theme="dark"] code { background: var(--surface-3); color: var(--ink); }
[data-theme="dark"] .flash { box-shadow: 0 0 0 1px rgba(127, 216, 174, .22); }
[data-theme="dark"] .error { box-shadow: 0 0 0 1px rgba(255, 122, 126, .28); }

/* ---------- Voile de chargement (logo Bernabé) ---------- */
.chargement {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(250, 250, 252, .72);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}
.chargement.actif { display: flex; }
.chargement-carte {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .95rem;
  padding: 1.7rem 2.2rem 1.5rem;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--elev-1), 0 14px 38px rgba(0, 0, 0, .14);
}
.chargement-anneau {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 88px;
  height: 88px;
}
.chargement-anneau::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 3px solid var(--brand-soft);
  border-top-color: var(--accent);
  animation: chargement-rot 1s linear infinite;
}
.chargement-logo {
  width: 58px;
  height: 58px;
  border-radius: 11px;
  box-shadow: var(--ring);
  animation: chargement-pulse 1.6s ease-in-out infinite;
}
.chargement-txt {
  font-family: var(--mono);
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--ink-3);
}
@keyframes chargement-rot { to { transform: rotate(360deg); } }
@keyframes chargement-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50%      { transform: scale(.92); opacity: .82; }
}
@media (prefers-reduced-motion: reduce) {
  .chargement-anneau::before, .chargement-logo { animation: none; }
}
[data-theme="dark"] .chargement { background: rgba(10, 10, 16, .68); }
[data-theme="dark"] .chargement-carte { box-shadow: var(--elev-1), 0 14px 38px rgba(0, 0, 0, .5); }

.connexion-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background: var(--brand-deep);
}
.connexion-carte {
  width: min(100%, 420px);
  padding: 2rem;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .24);
}
.connexion-logo { display: block; width: 62px; height: 62px; margin: 0 auto 1rem; border-radius: 12px; }
.connexion-carte h1 { margin: 0; text-align: center; font-size: 1.5rem; }
.connexion-sous-titre { margin: .35rem 0 1.5rem; color: var(--ink-3); text-align: center; font-size: .9rem; }
.connexion-form { display: grid; gap: .55rem; }
.connexion-form label { margin-top: .45rem; font-weight: 600; font-size: .88rem; }
.connexion-form input { width: 100%; padding: .7rem .75rem; border: 1px solid var(--line-strong); border-radius: var(--radius); font: inherit; }
.connexion-submit { width: 100%; margin-top: .8rem; padding: .7rem; }
.connexion-aide { padding: .7rem; background: var(--surface-3); border-radius: var(--radius); font-size: .86rem; }
.deconnexion-form { display: flex; align-items: center; gap: .45rem; color: var(--ink-3); font-size: .82rem; }

/* Impression depuis le thème sombre : on revient au clair papier */
@media print {
  [data-theme="dark"] pre.sql { background: #f5f5f5 !important; color: #111 !important; }
  [data-theme="dark"] .chip { background: #eee !important; color: #111 !important; }
  .fin-hero { background: #fff !important; color: #000; border: 1px solid #999; box-shadow: none; }
  .fin-hero::before { display: none; }
  .fin-main .k, .fin-main .n, .fin-cell .k { color: #444 !important; }
  .fin-main, .fin-cell { box-shadow: 1px 0 0 #ccc; }
  .stack-bar .seg, .dist-row .dot, .donut { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- Responsive : garde-fous anti-débord (toutes largeurs) ---------- */
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(min(400px, 100%), 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(min(255px, 100%), 1fr)); }
.highlights-grid { grid-template-columns: repeat(auto-fit, minmax(min(225px, 100%), 1fr)); }
.kpi-band { grid-template-columns: repeat(auto-fit, minmax(min(148px, 100%), 1fr)); }
.ent-chiffres { grid-template-columns: repeat(auto-fit, minmax(min(185px, 100%), 1fr)); }
.ent-photos { grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); }
.arbre-box { grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); }
form:not(.omni-search):not(.form-filtres):not(.chat-compose):not(.form-assistant):not(.assistant-pop-foot),
.sous-form { grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
.sous-form > h3 { grid-column: 1 / -1; margin: .2rem 0 0; }
.fin-main .v { font-size: clamp(1.65rem, 6.5vw, 2.3rem); }
.bulle { min-width: 0; overflow-wrap: anywhere; }
.bulle-assistant { width: 100%; }

/* Bouton de menu mobile et barre d'onglets basse masqués sur grand écran */
.btn-menu-mobile,
.bottom-nav { display: none; }
.head-toolbar [hidden] { display: none !important; }
html { -webkit-tap-highlight-color: transparent; }

/* ---------- Bulle de conversation flottante (Assistant IA) ---------- */
.assistant-fab-wrap {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .75rem;
  pointer-events: none;
}
.assistant-fab-wrap > * { pointer-events: auto; }
.assistant-fab-wrap [hidden] { display: none !important; }

.assistant-fab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  height: 3.1rem;
  padding: 0 1.1rem 0 .95rem;
  border-radius: 999px;
  border: none;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-deep) 100%);
  color: #fff;
  font-family: var(--sans);
  font-size: .88rem;
  font-weight: 600;
  letter-spacing: -.01em;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .14), 0 8px 24px rgba(26, 24, 73, .34);
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}
.assistant-fab:hover {
  transform: translateY(-1px);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .2), 0 12px 28px rgba(26, 24, 73, .42);
}
.assistant-fab svg { width: 1.2rem; height: 1.2rem; flex: none; }
.assistant-fab .fab-ico-close { display: none; }
.assistant-fab-wrap.ouvert .assistant-fab .fab-ico-chat { display: none; }
.assistant-fab-wrap.ouvert .assistant-fab .fab-ico-close { display: block; }
.fab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.25rem;
  height: 1.25rem;
  padding: 0 .35rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-family: var(--mono);
  font-size: .68rem;
  font-weight: 600;
  line-height: 1;
}
[data-theme="dark"] .assistant-fab {
  background: linear-gradient(135deg, #4C4BB0 0%, #2B2A6E 100%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .16), 0 10px 28px rgba(0, 0, 0, .55);
}

.assistant-pop {
  width: min(410px, calc(100vw - 2rem));
  height: min(560px, calc(100vh - 6.2rem));
  height: min(560px, calc(100dvh - 6.2rem));
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: var(--elev-1), 0 18px 44px rgba(0, 0, 0, .22);
  overflow: hidden;
  border-top: 3px solid var(--brand);
}
[data-theme="dark"] .assistant-pop {
  box-shadow: var(--elev-1), 0 20px 48px rgba(0, 0, 0, .65);
}

.assistant-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  padding: .65rem .85rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.assistant-pop-title {
  display: flex;
  align-items: center;
  gap: .45rem;
  min-width: 0;
  font-size: .9rem;
}
.assistant-pop-dot {
  width: .5rem;
  height: .5rem;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}
.assistant-pop-actions {
  display: flex;
  align-items: center;
  gap: .2rem;
  flex: none;
}
.assistant-pop-actions form { display: contents; }
.assistant-pop-actions .btn-icon { width: 1.85rem; height: 1.85rem; }
.assistant-pop-actions .btn-icon svg { width: .95rem; height: .95rem; }

.assistant-pop-body.chat {
  flex: 1 1 auto;
  max-height: none;
  min-height: 0;
  padding: .75rem .8rem;
  gap: .65rem;
  overflow-y: auto;
}
.assistant-pop-body .bulle { font-size: .84rem; padding: .5rem .7rem; }
.assistant-pop-body .bulle-entete { font-size: .88rem; }
.assistant-pop-body .reponse-lead { font-size: .9rem; }
.assistant-pop-body table { font-size: .76rem; }
.assistant-pop-body th,
.assistant-pop-body td { padding: .32rem .45rem; }
.assistant-pop-body .table-wrap { margin: 0 -.45rem; padding: 0 .45rem; }

.assistant-pop-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .45rem;
  padding: .6rem .75rem;
  background: var(--surface-2);
  border-top: 1px solid var(--line);
  flex: none;
  margin: 0;
}
.assistant-pop-foot input[type="text"] {
  flex: 1 1 0;
  width: auto;
  min-width: 0;
  padding: .48rem .7rem;
  font-size: 16px;
  border-radius: 999px;
}
.assistant-pop-foot button {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.3rem;
  height: 2.3rem;
  padding: 0;
  border-radius: 50%;
}
.assistant-pop-foot button svg { width: 1rem; height: 1rem; }

/* ---------- Tablette / petit écran (≤ 900 px) : menu déroulant propre (sans scroll horizontal) ---------- */
@media (max-width: 900px) {
  .app { display: block; }
  .sidebar { width: auto; height: auto; position: static; }

  /* Barre supérieure : logo + nom à gauche, bouton menu (burger) à droite */
  .brand {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .65rem .95rem;
  }
  .brand a.brand-link { display: flex; align-items: center; gap: .65rem; min-width: 0; }
  .brand-logo { width: 34px; height: 34px; margin-bottom: 0; flex: none; }
  .brand-meta { min-width: 0; }
  .brand-nom { font-size: .96rem; line-height: 1.2; }
  .brand-sub { margin-top: .12rem; }
  .brand-pill { display: none; }

  .btn-menu-mobile {
    display: inline-flex;
    color: #EDEDF6;
    background: rgba(255, 255, 255, .1);
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius);
    flex: none;
  }
  .btn-menu-mobile:hover { background: rgba(255, 255, 255, .18); }
  .btn-menu-mobile .ico-close { display: none; }
  .sidebar.menu-open .btn-menu-mobile .ico-burger { display: none; }
  .sidebar.menu-open .btn-menu-mobile .ico-close { display: block; }

  /* Navigation repliée par défaut ; s'ouvre en grille au clic sur le bouton menu */
  .sidebar nav {
    display: none;
    padding: .65rem .9rem .85rem;
    gap: .65rem;
    overflow: visible;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12);
  }
  .sidebar.menu-open nav {
    display: flex;
    flex-direction: column;
  }
  .nav-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .3rem;
  }
  .nav-group + .nav-group { margin-top: .15rem; }
  .nav-group-label {
    grid-column: 1 / -1;
    padding: .15rem .35rem .1rem;
  }
  .sidebar nav a { font-size: .85rem; padding: .52rem .65rem; }
  .nav-kbd { display: none; }
  .sidebar-foot { display: none; }

  .content { padding: 1rem 1rem calc(5.2rem + env(safe-area-inset-bottom, 0px)); }
  .page-head { padding: .8rem 1rem; }
  .bar-row { grid-template-columns: 7rem 1fr 3.4rem; }
  .table-wrap { -webkit-overflow-scrolling: touch; }

  /* Barre d'onglets basse de navigation mobile */
  .bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    background: var(--surface);
    box-shadow: 0 -1px 0 var(--line), 0 -4px 16px rgba(0, 0, 0, .05);
    padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom, 0px));
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
  }
  .bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .18rem;
    padding: .32rem .15rem;
    border-radius: var(--radius);
    color: var(--ink-3);
    font-size: .66rem;
    font-weight: 500;
    text-decoration: none;
    line-height: 1.1;
  }
  .bottom-nav-item .nav-ico { width: 1.15rem; height: 1.15rem; }
  .bottom-nav-item:hover { text-decoration: none; color: var(--ink); }
  .bottom-nav-item.active {
    color: var(--brand);
    font-weight: 600;
  }
  .bottom-nav-item.active .nav-ico { stroke-width: 2.2; }
  [data-theme="dark"] .bottom-nav {
    box-shadow: 0 -1px 0 var(--line), 0 -6px 20px rgba(0, 0, 0, .4);
  }

  /* Décaler la bulle d'assistant au-dessus de la barre d'onglets basse */
  .assistant-fab-wrap {
    bottom: calc(4.35rem + env(safe-area-inset-bottom, 0px));
  }
  .assistant-pop {
    height: min(540px, calc(100vh - 9.2rem));
    height: min(540px, calc(100dvh - 9.2rem));
  }
}

/* ---------- Smartphone (≤ 640 px) : en-tête empilé, typographie fluide ---------- */
@media (max-width: 640px) {
  /* En-tête : ligne 1 = titre (gauche) + boutons icônes (droite) ; ligne 2 = recherche pleine largeur */
  .page-head {
    position: static;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto auto auto;
    align-items: center;
    gap: .55rem .35rem;
    padding: .75rem .9rem;
  }
  .page-head .spacer { display: none; }
  .page-head-titles { min-width: 0; }
  .page-head h1 { font-size: 1.02rem; line-height: 1.25; }
  .ariane { font-size: .64rem; margin-top: .15rem; }
  .head-toolbar {
    display: contents;
  }
  .omni-search {
    grid-column: 1 / -1;
    order: 10;
    width: 100%;
  }
  .omni-kbd { display: none; }           /* raccourci clavier sans sens sur tactile */
  /* Bouton Imprimer réduit à son icône sur petit écran */
  .head-toolbar > .btn.small {
    font-size: 0;
    gap: 0;
    width: 2.15rem;
    height: 2.15rem;
    padding: 0;
    justify-content: center;
  }
  .btn-icon { width: 2.15rem; height: 2.15rem; }

  .content { padding: .85rem .85rem calc(8.4rem + env(safe-area-inset-bottom, 0px)); }
  .card { padding: .95rem .95rem 1.05rem; margin-bottom: .9rem; }

  /* Bulle d'assistant sur mobile : bouton compact au-dessus de la barre d'onglets */
  .assistant-fab-wrap {
    right: .85rem;
    left: .85rem;
    bottom: calc(4.25rem + env(safe-area-inset-bottom, 0px));
  }
  .assistant-pop {
    width: 100%;
    height: min(68vh, 500px);
    height: min(68dvh, 500px);
  }
  .assistant-fab {
    height: 3rem;
    padding: 0 .95rem;
  }

  /* Bandeau d'indicateurs en grille 2 colonnes propre avec séparateurs internes */
  .kpi-band { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi {
    padding: .75rem .85rem;
    box-shadow: 1px 0 0 var(--line), 0 1px 0 var(--line);
  }
  .kpi:nth-child(2n) { box-shadow: 0 1px 0 var(--line); }
  .kpi:last-child:nth-child(odd) {
    grid-column: 1 / -1;
    box-shadow: none;
  }
  .kpi:nth-last-child(-n+2):nth-child(odd),
  .kpi:last-child:nth-child(even) {
    box-shadow: 1px 0 0 var(--line);
  }
  .kpi:last-child { box-shadow: none; }
  .kpi .v { font-size: 1.15rem; }
  .kpi .v.small { font-size: .88rem; }

  /* Bandeau finances : empilé, paddings réduits */
  .fin-hero { border-radius: var(--radius); }
  .fin-main { padding: 1rem 1rem .95rem; }
  .fin-main .n { font-size: .74rem; }
  .fin-cell { padding: .8rem .85rem .75rem; }
  .fin-cell .k { min-height: 0; }
  .fin-cell .v { font-size: .96rem; white-space: normal; }

  /* Grilles et formulaires en une colonne */
  .grid-2, .grid-3, .arbre-box { grid-template-columns: 1fr; gap: .85rem; }
  form:not(.omni-search):not(.form-filtres):not(.chat-compose):not(.form-assistant):not(.assistant-pop-foot),
  .sous-form { grid-template-columns: 1fr; gap: .65rem; }
  .form-actions button,
  .form-actions .btn { flex: 1 1 auto; text-align: center; justify-content: center; }

  /* Tableaux plus denses sur mobile pour limiter le défilement horizontal */
  .table-wrap { margin: 0 -.95rem; padding: 0 .95rem; }
  table { font-size: .8rem; }
  th, td { padding: .42rem .55rem; }

  /* Graphiques (donut, barres, légendes) */
  .grid-2 > .card .donut-wrap { justify-content: center; gap: 1.1rem; }
  .donut { width: 128px; height: 128px; }
  .donut-hole .v { font-size: 1.3rem; }
  .bar-row { grid-template-columns: minmax(5.5rem, 36%) 1fr 2.8rem; gap: .45rem; }
  .bar-row .bl { font-size: .78rem; }
  .dist-row { grid-template-columns: .55rem 1fr auto 2.8rem; gap: .45rem; font-size: .8rem; }

  /* Lignes d'information (fiches, coordonnées) et fiches de l'assistant */
  p.info { flex-direction: column; gap: .1rem; margin: .45rem 0; }
  p.info span { flex: none; padding-top: 0; }
  p.info:has(> span.bullet-dot) { flex-direction: row; gap: .55rem; }
  .fiche-ligne { flex-direction: column; align-items: flex-start; gap: .15rem; }
  .fiche-ligne .val { text-align: left; }

  /* Carte entreprise */
  .ent-logo { width: 68px; height: 68px; }
  .ent-top { gap: .8rem; }
  .ent-title-row h2 { font-size: 1.05rem; }
  .ent-chiffres { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem .75rem; }
  .ent-photos { grid-template-columns: 1fr; }

  /* Assistant IA : bulles et saisie sur une seule ligne */
  .chat { max-height: none; padding: .15rem 0 .25rem; }
  .bulle { max-width: 100%; padding: .55rem .75rem; }
  .bulle-moi { max-width: 88%; }
  .bulle-assistant .table-wrap { margin: 0 -.75rem; padding: 0 .75rem; }
  .chat-compose { flex-wrap: wrap; gap: .45rem; }
  .chat-compose .assistant-input-wrap { flex: 1 1 0; min-width: 0; }
  .chat-compose .assistant-input-wrap input { font-size: 16px; padding: .5rem .65rem .5rem 2.2rem; }
  .chat-compose .chat-send {
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
  }
  .chat-compose .chat-send svg { display: block; width: 1.1rem; height: 1.1rem; }

  /* Pagination & cibles tactiles */
  .pagination { gap: .35rem; }
  .pagination .page-info { flex: 1 1 100%; margin: 0 0 .15rem; }
  .pagination .numero { padding: .38rem .52rem; min-width: 2rem; }
  .chip { padding: .34rem .7rem; }
  .btn.small { padding: .38rem .65rem; }
  td.actions button { padding: .38rem .6rem; }
  .form-assistant button { flex: 1 1 auto; }

  /* Lisibilité mobile : corps à 16 px, textes secondaires et commandes à 14 px minimum. */
  body { font-size: 16px; }
  .page-head h1 { font-size: 1.12rem; }
  .ariane { font-size: .76rem; }
  .sidebar nav a { font-size: .95rem; }
  .bottom-nav-item { font-size: .75rem; }
  label, .form-fiche label { font-size: .9rem; }
  input, select, textarea, button, .btn { font-size: .95rem; }
  .btn.small, .small, td.actions button { font-size: .88rem; }
  .flash, .error, .card-sub, p.info, .fiche-ligne .cle { font-size: .94rem; }
  .badge { font-size: .82rem; }
  table { font-size: .9rem; }
  th, td { padding: .48rem .6rem; }
  .sql-details summary, pre.sql { font-size: .86rem; }
  .bar-row .bl, .dist-row { font-size: .9rem; }
  .assistant-pop-body .bulle,
  .assistant-pop-body .bulle-entete,
  .assistant-pop-body .reponse-lead { font-size: .95rem; }
  .assistant-pop-body table { font-size: .86rem; }
  .voice-status { font-size: .9rem; }
}

/* ---------- Très petit écran (≤ 420 px) ---------- */
@media (max-width: 420px) {
  .nav-group { grid-template-columns: 1fr; }
  .kpi-band { grid-template-columns: 1fr; }
  .kpi,
  .kpi:nth-child(2n),
  .kpi:nth-last-child(-n+2):nth-child(odd),
  .kpi:last-child:nth-child(even) {
    grid-column: auto;
    box-shadow: 0 1px 0 var(--line);
  }
  .kpi:last-child { box-shadow: none; }
  .fin-grid { grid-template-columns: 1fr; }
  .fin-cell,
  .fin-cell:nth-child(2n),
  .fin-cell:nth-last-child(-n+2) {
    box-shadow: 0 1px 0 rgba(255, 255, 255, .14);
  }
  .fin-cell:last-child { box-shadow: none; }
  .highlights-grid { grid-template-columns: 1fr; }
  .ent-chiffres { grid-template-columns: 1fr; }
  .ent-top { flex-wrap: wrap; }
}
