
/* ==========================================================================
   KI-PRO — feuille de style (kipro-ui)
   1. Jetons          2. Base          3. Coque applicative
   4. Composants      5. Responsive    6. Impression
   ========================================================================== */

/* --- 1. Jetons ---------------------------------------------------------- */
:root {
  /* Échelle de gris, froide et neutre. 1 = fond, 12 = texte. */
  --g1:  #fcfcfd;  --g2:  #f8f9fb;  --g3:  #f1f2f5;  --g4:  #e9eaee;
  --g5:  #e0e2e7;  --g6:  #d6d9e0;  --g7:  #c6cad3;  --g8:  #aeb3bf;
  --g9:  #8b909c;  --g10: #6e727d;  --g11: #52565f;  --g12: #1c1e23;

  /* Surfaces */
  --bg:            var(--g2);
  --panel:         #ffffff;
  --panel-subtle:  var(--g1);
  --panel-hover:   var(--g3);
  --panel-active:  var(--g4);
  --overlay:       rgba(28, 30, 35, 0.32);

  /* Traits */
  --line:          var(--g4);
  --line-strong:   var(--g6);

  /* Texte */
  --text:          var(--g12);
  --text-muted:    var(--g10);
  --text-subtle:   var(--g9);
  --text-invert:   #ffffff;

  /* Interaction : un seul bleu, pour la sélection, le focus et les liens. */
  --accent:        #3b5bdb;
  --accent-hover:  #364fc7;
  --accent-soft:   #eef1fd;
  --accent-line:   #c3ccf7;
  --accent-text:   #2f44a8;

  /* Action principale : encre, pas rouge. Le rouge est réservé au danger. */
  --solid:         #22242a;
  --solid-hover:   #101216;
  --solid-text:    #ffffff;

  /* Sémantique — chacune : fond doux, trait, texte */
  --ok-soft:  #e7f6ec;  --ok-line:  #b3e0c2;  --ok-text:  #17663a;
  --warn-soft:#fdf2dc;  --warn-line:#f0d79a;  --warn-text:#8a5a09;
  --bad-soft: #fdeaea;  --bad-line: #f4bdbd;  --bad-text: #a71d1d;
  --info-soft:#e8f1fd;  --info-line:#bcd4f5;  --info-text:#1a4f9c;
  --neut-soft:var(--g3);--neut-line:var(--g5);--neut-text:var(--g10);

  /* Rouge suisse : identité de marque uniquement (logo). */
  --swiss: #dc0018;

  /* Rayons */
  --r-xs: 3px; --r-sm: 5px; --r: 7px; --r-lg: 10px; --r-xl: 14px; --r-full: 999px;

  /* Profondeur — discrète : un trait fait souvent mieux qu'une ombre. */
  --sh-1: 0 1px 2px rgba(20, 22, 28, .05);
  --sh-2: 0 1px 3px rgba(20, 22, 28, .07), 0 8px 24px -8px rgba(20, 22, 28, .14);
  --sh-3: 0 2px 6px rgba(20, 22, 28, .08), 0 24px 48px -12px rgba(20, 22, 28, .22);

  /* Typographie */
  --font: "Inter var", "Inter", ui-sans-serif, system-ui, -apple-system,
          "Segoe UI Variable Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo, monospace;

  --t-xs: 11px; --t-sm: 12px; --t-md: 13px; --t-base: 14px;
  --t-lg: 16px; --t-xl: 20px; --t-2xl: 26px;

  /* Espacement, base 4 */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px;
  --s6: 24px; --s8: 32px; --s10: 40px; --s12: 48px;

  /* Coque — rail d'icônes + panneau contextuel */
  --rail-w: 56px;
  --panel-w: 216px;
  --topbar-h: 48px;
  --row-h: 36px;          /* densité confortable */

  /* Le rail a ses propres surfaces : il reste sombre dans les deux
     thèmes. Piocher `--g12` (une couleur de TEXTE) comme fond serait une
     faute — l'échelle de gris s'inverse en thème sombre et le rail
     deviendrait blanc. Une surface se déclare, elle ne s'emprunte pas. */
  --rail-bg:     #1c1e23;
  --rail-fg:     #9aa0ae;
  --rail-fg-on:  #ffffff;
  --rail-hover:  rgba(255, 255, 255, .08);
  --rail-active: rgba(255, 255, 255, .13);

  --speed: 120ms;
  --ease: cubic-bezier(.2, .6, .35, 1);
}

/* Densité compacte : plus de lignes visibles, pour la saisie en série. */
:root[data-density="compact"] { --row-h: 29px; --t-base: 13px; }

/* Cibles tactiles : sur chantier, au doigt. */
@media (pointer: coarse) { :root { --row-h: 44px; } }

/* Thème sombre : seuls les jetons changent, aucun composant ne bouge. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --g1:  #0d0e11;  --g2:  #131519;  --g3:  #1a1d22;  --g4:  #23262c;
    --g5:  #2c3038;  --g6:  #383d46;  --g7:  #474d58;  --g8:  #5c626e;
    --g9:  #7a8090;  --g10: #9aa0ae;  --g11: #c2c7d0;  --g12: #f0f1f4;

    --bg: var(--g1); --panel: var(--g2); --panel-subtle: var(--g2);
    --panel-hover: var(--g3); --panel-active: var(--g4);
    --overlay: rgba(0, 0, 0, .6);
    --line: var(--g4); --line-strong: var(--g6);
    --text-invert: #0d0e11;

    --accent: #7c92f5; --accent-hover: #93a5f8; --accent-soft: #1a1f33;
    --accent-line: #2f3a63; --accent-text: #a8b7fa;

    --solid: #f0f1f4; --solid-hover: #ffffff; --solid-text: #14161a;

    --ok-soft:  #10261a;  --ok-line:  #1e4a30;  --ok-text:  #6ede9c;
    --warn-soft:#2a2010;  --warn-line:#4d3c15;  --warn-text:#e8b562;
    --bad-soft: #2b1416;  --bad-line: #55232a;  --bad-text: #f08b8b;
    --info-soft:#111d33;  --info-line:#1f365e;  --info-text:#7fb0f5;

    --rail-bg: #08090b; --rail-fg: #7a8090;

    --sh-1: 0 1px 2px rgba(0, 0, 0, .4);
    --sh-2: 0 1px 3px rgba(0, 0, 0, .5), 0 8px 24px -8px rgba(0, 0, 0, .6);
    --sh-3: 0 2px 6px rgba(0, 0, 0, .5), 0 24px 48px -12px rgba(0, 0, 0, .7);
  }
}

/* --- 2. Base ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--t-base);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.011em; color: var(--text); }
h1 { font-size: var(--t-xl); }
h2 { font-size: var(--t-lg); }
h3 { font-size: var(--t-base); }
p  { margin: 0 0 var(--s3); }

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

/* Un seul anneau de focus, visible, jamais supprimé sans remplacement. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-radius: var(--r-xs);
}
:focus:not(:focus-visible) { outline: none; }

/* Une icône a toujours une taille : sans cette règle, un SVG posé dans
   un contexte non prévu s'effondre ou déborde. Les composants la
   surchargent, mais aucun ne part de rien. */
.ico { width: 16px; height: 16px; flex: 0 0 auto; }

/* Tous les chiffres comparables sont tabulaires. */
.num, td.num, th.num, .amount, input[type="number"] {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
.amount { text-align: right; white-space: nowrap; }
.muted   { color: var(--text-muted); }
.subtle  { color: var(--text-subtle); }
.mono    { font-family: var(--mono); font-size: var(--t-sm); }
.nowrap  { white-space: nowrap; }
.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;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* --- 3. Coque applicative ----------------------------------------------- */
/* Rail d'icônes (domaines) + panneau contextuel (écrans du domaine
   ouvert). L'intérêt tient en une phrase : on ne voit jamais les 25
   écrans à la fois, seulement les trois à cinq du domaine courant. */
.app {
  display: grid;
  grid-template-columns: var(--rail-w) var(--panel-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas: "rail panel topbar" "rail panel main";
  min-height: 100vh;
}
/* Un domaine sans sous-écrans (l'accueil) n'affiche pas de panneau vide. */
.app[data-panel="none"] {
  grid-template-columns: var(--rail-w) 1fr;
  grid-template-areas: "rail topbar" "rail main";
}

/* Rail */
.rail {
  grid-area: rail;
  display: flex; flex-direction: column; align-items: center; gap: var(--s1);
  padding: var(--s2) 0;
  background: var(--rail-bg);
  border-right: 1px solid var(--line);
  overflow: hidden;
}
.rail-logo {
  width: 30px; height: 30px; flex: 0 0 30px; margin-bottom: var(--s2);
  border-radius: var(--r-sm); background: var(--swiss);
  display: grid; place-items: center; color: #fff;
}
.rail-item {
  position: relative; flex: 0 0 auto;
  width: 40px; height: 40px; display: grid; place-items: center;
  border: 0; border-radius: var(--r); background: transparent;
  color: var(--rail-fg); cursor: pointer; text-decoration: none;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.rail-item:hover { background: var(--rail-hover); color: var(--rail-fg-on); text-decoration: none; }
.rail-item[aria-current="page"] { background: var(--rail-active); color: var(--rail-fg-on); }
/* Repère d'appartenance : un trait, pas une couleur — il reste lisible
   pour qui distingue mal les teintes. */
.rail-item[aria-current="page"]::before {
  content: ""; position: absolute; left: -8px; top: 10px; bottom: 10px;
  width: 3px; border-radius: 0 3px 3px 0; background: var(--rail-fg-on);
}
.rail-item .ico { width: 19px; height: 19px; }
.rail-item .rail-count {
  position: absolute; top: 4px; right: 4px;
  min-width: 15px; height: 15px; padding: 0 4px;
  border-radius: var(--r-full); background: var(--bad-text); color: #fff;
  font-size: 10px; font-weight: 700; line-height: 15px; text-align: center;
  font-variant-numeric: tabular-nums;
}
.rail-spacer { flex: 1 1 auto; }

/* Panneau contextuel */
.panel {
  grid-area: panel;
  background: var(--panel-subtle);
  border-right: 1px solid var(--line);
  padding: var(--s3) var(--s2);
  overflow-y: auto;
}
.panel::-webkit-scrollbar { width: 8px; }
.panel::-webkit-scrollbar-thumb {
  background: var(--g5); border-radius: var(--r-full);
  border: 2px solid transparent; background-clip: content-box;
}
.panel-title {
  padding: var(--s2); margin-bottom: var(--s1);
  font-size: var(--t-lg); font-weight: 650; letter-spacing: -0.02em;
}
.panel-group { margin-top: var(--s4); }
.panel-group > .nav-label {
  padding: var(--s1) var(--s2);
  font-size: var(--t-xs); font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-subtle);
}

.nav-link {
  display: flex; align-items: center; gap: var(--s3);
  height: 30px; padding: 0 var(--s2);
  border-radius: var(--r-sm);
  color: var(--text-muted); font-size: var(--t-md); font-weight: 500;
  text-decoration: none; white-space: nowrap;
  transition: background var(--speed) var(--ease), color var(--speed) var(--ease);
}
.nav-link:hover { background: var(--panel-hover); color: var(--text); text-decoration: none; }
.nav-link[aria-current="page"] { background: var(--panel-active); color: var(--text); font-weight: 600; }
.nav-link .ico { opacity: .75; }
.nav-link[aria-current="page"] .ico { opacity: 1; }
.nav-link .nav-text { overflow: hidden; text-overflow: ellipsis; }
.nav-count {
  margin-left: auto; font-size: var(--t-xs); font-variant-numeric: tabular-nums;
  color: var(--text-subtle); background: var(--panel-hover);
  padding: 1px 6px; border-radius: var(--r-full);
}

/* Barre supérieure */
.topbar {
  grid-area: topbar;
  display: flex; align-items: center; gap: var(--s3);
  height: var(--topbar-h); padding: 0 var(--s4);
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 30;
}
.topbar-spacer { flex: 1 1 auto; }

/* Recherche globale : c'est aussi le déclencheur de la palette. */
.omni {
  display: flex; align-items: center; gap: var(--s2);
  width: min(420px, 42vw); height: 30px; padding: 0 var(--s2) 0 var(--s3);
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--r); color: var(--text-subtle);
  font-size: var(--t-md); cursor: pointer; font-family: inherit;
  transition: border-color var(--speed) var(--ease), background var(--speed) var(--ease);
}
.omni:hover { border-color: var(--line-strong); background: var(--panel); }
.omni .ico { width: 15px; height: 15px; flex: 0 0 15px; }
.omni-text { flex: 1 1 auto; text-align: left; }

kbd {
  font-family: var(--font); font-size: var(--t-xs); font-weight: 600;
  color: var(--text-subtle); background: var(--panel);
  border: 1px solid var(--line); border-bottom-width: 2px;
  border-radius: var(--r-xs); padding: 1px 5px; line-height: 1.4;
}

/* Zone de contenu */
.main { grid-area: main; min-width: 0; padding: var(--s6) var(--s6) var(--s12); }
.wrap { max-width: 1320px; margin: 0 auto; }
.wrap-narrow { max-width: 780px; margin: 0 auto; }

/* En-tête de page */
.page-head {
  display: flex; align-items: flex-start; gap: var(--s4);
  margin-bottom: var(--s5);
}
.page-head h1 { font-size: var(--t-2xl); line-height: 1.2; }
.page-head .lede { margin: var(--s1) 0 0; color: var(--text-muted); font-size: var(--t-md); }
.page-head .actions { margin-left: auto; display: flex; gap: var(--s2); flex: 0 0 auto; }

.crumbs { display: flex; align-items: center; gap: var(--s1); font-size: var(--t-md); color: var(--text-subtle); margin-bottom: var(--s2); }
.crumbs a { color: var(--text-muted); }
.crumbs .sep { opacity: .5; }

/* --- 4. Composants ------------------------------------------------------ */

/* Boutons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  height: 30px; padding: 0 var(--s3);
  border: 1px solid var(--line-strong); border-radius: var(--r);
  background: var(--panel); color: var(--text);
  font: inherit; font-size: var(--t-md); font-weight: 500;
  cursor: pointer; white-space: nowrap; text-decoration: none;
  box-shadow: var(--sh-1);
  transition: background var(--speed) var(--ease), border-color var(--speed) var(--ease),
              color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.btn:hover { background: var(--panel-hover); text-decoration: none; }
.btn:active { background: var(--panel-active); box-shadow: none; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn .ico { width: 15px; height: 15px; flex: 0 0 15px; }

.btn-primary { background: var(--solid); border-color: var(--solid); color: var(--solid-text); }
.btn-primary:hover { background: var(--solid-hover); border-color: var(--solid-hover); }
.btn-danger { background: var(--panel); border-color: var(--bad-line); color: var(--bad-text); }
.btn-danger:hover { background: var(--bad-soft); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-muted); }
.btn-ghost:hover { background: var(--panel-hover); color: var(--text); }
.btn-lg { height: 36px; padding: 0 var(--s4); font-size: var(--t-base); }
.btn-sm { height: 26px; padding: 0 var(--s2); font-size: var(--t-sm); }
.btn-icon { width: 30px; padding: 0; }
.btn-sm.btn-icon { width: 26px; }

.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; margin-left: -1px; }
.btn-group .btn:first-child { border-radius: var(--r) 0 0 var(--r); margin-left: 0; }
.btn-group .btn:last-child { border-radius: 0 var(--r) var(--r) 0; }

/* Cartes / panneaux */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--sh-1);
}
.card + .card { margin-top: var(--s4); }
.card-head {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4);
  border-bottom: 1px solid var(--line);
}
.card-head h2, .card-head h3 { font-size: var(--t-base); }
.card-head .actions { margin-left: auto; display: flex; gap: var(--s2); }
.card-body { padding: var(--s4); }
.table-scroll + .card-body, .card-body + .card-body { border-top: 1px solid var(--line); }
.card-foot { padding: var(--s3) var(--s4); border-top: 1px solid var(--line); background: var(--panel-subtle); border-radius: 0 0 var(--r-lg) var(--r-lg); }

/* Cartes statistiques */
.stat-grid { display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: var(--s5); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); padding: var(--s4); box-shadow: var(--sh-1); }
.stat-label { font-size: var(--t-sm); color: var(--text-muted); font-weight: 500; }
.stat-value { margin-top: var(--s1); font-size: var(--t-2xl); font-weight: 620; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-value .unit { font-size: var(--t-md); font-weight: 500; color: var(--text-subtle); margin-left: 3px; }
.stat-delta { margin-top: var(--s1); font-size: var(--t-sm); display: flex; align-items: center; gap: var(--s1); }
.stat-delta.up { color: var(--ok-text); }
.stat-delta.down { color: var(--bad-text); }
.stat-value-sm { font-size: var(--t-lg); }

/* Onglets */
.tabs { display: flex; gap: var(--s1); border-bottom: 1px solid var(--line); margin-bottom: var(--s4); overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: var(--s2);
  padding: var(--s2) var(--s3); margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  color: var(--text-muted); font-size: var(--t-md); font-weight: 500;
  text-decoration: none; white-space: nowrap;
}
.tab:hover { color: var(--text); text-decoration: none; }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--solid); font-weight: 600; }
.tab .nav-count { margin-left: 0; }

/* Barre d'outils : UNE seule rangée au-dessus d'un tableau. */
.toolbar { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s3); flex-wrap: wrap; }
.toolbar .spacer { flex: 1 1 auto; }

/* Champs */
.field { display: flex; flex-direction: column; gap: var(--s1); }
.field > label, .label { font-size: var(--t-sm); font-weight: 550; color: var(--text-muted); }
.req::after { content: "*"; color: var(--bad-text); margin-left: 2px; }
.hint { font-size: var(--t-sm); color: var(--text-subtle); }
.error-text { font-size: var(--t-sm); color: var(--bad-text); }

.input, .select, .textarea {
  width: 100%; height: 30px; padding: 0 var(--s2);
  background: var(--panel); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--r);
  font: inherit; font-size: var(--t-md);
  transition: border-color var(--speed) var(--ease), box-shadow var(--speed) var(--ease);
}
.textarea { height: auto; min-height: 72px; padding: var(--s2); resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--text-subtle); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--g7); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--bad-line); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--bad-soft); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--panel-hover); color: var(--text-subtle); cursor: not-allowed; }
.select { appearance: none; padding-right: var(--s6);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236e727d' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right var(--s2) center; }
.input-amount { text-align: right; font-variant-numeric: tabular-nums; }
.input-search { padding-left: var(--s8);
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b909c' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left var(--s2) center; }

.checkbox, .radio {
  appearance: none; width: 15px; height: 15px; flex: 0 0 15px; margin: 0;
  border: 1px solid var(--g7); background: var(--panel);
  border-radius: var(--r-xs); cursor: pointer; position: relative;
  transition: background var(--speed) var(--ease), border-color var(--speed) var(--ease);
}
.radio { border-radius: var(--r-full); }
.checkbox:hover, .radio:hover { border-color: var(--g8); }
.checkbox:checked, .radio:checked { background: var(--accent); border-color: var(--accent); }
.checkbox:checked::after {
  content: ""; position: absolute; inset: 0;
  background: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m5 13 4 4L19 7'/%3E%3C/svg%3E") center/11px no-repeat;
}
.radio:checked::after { content: ""; position: absolute; inset: 3px; border-radius: var(--r-full); background: #fff; }
.check-line { display: flex; align-items: center; gap: var(--s2); font-size: var(--t-md); cursor: pointer; }

/* Grille de formulaire */
.form-grid { display: grid; gap: var(--s4); grid-template-columns: repeat(12, 1fr); }
.col-2 { grid-column: span 2; } .col-3 { grid-column: span 3; }
.col-4 { grid-column: span 4; } .col-6 { grid-column: span 6; }
.col-8 { grid-column: span 8; } .col-12 { grid-column: span 12; }

/* Badges de statut */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 1px var(--s2); border-radius: var(--r-full);
  font-size: var(--t-sm); font-weight: 550; line-height: 18px;
  border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: var(--r-full); background: currentColor; flex: 0 0 5px; }
.badge-neutral { background: var(--neut-soft); border-color: var(--neut-line); color: var(--neut-text); }
.badge-info    { background: var(--info-soft); border-color: var(--info-line); color: var(--info-text); }
.badge-ok      { background: var(--ok-soft);   border-color: var(--ok-line);   color: var(--ok-text); }
.badge-warn    { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn-text); }
.badge-bad     { background: var(--bad-soft);  border-color: var(--bad-line);  color: var(--bad-text); }
.badge-plain::before { display: none; }

/* Tableaux */
.table-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--sh-1); overflow: hidden; }
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--t-md); }
table.data th {
  position: sticky; top: 0; z-index: 2;
  background: var(--panel-subtle);
  padding: 0 var(--s3); height: 32px;
  text-align: left; font-size: var(--t-sm); font-weight: 600;
  color: var(--text-muted); white-space: nowrap;
  border-bottom: 1px solid var(--line);
}
table.data th.num, table.data td.num { text-align: right; }
table.data th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
table.data th a:hover { color: var(--text); text-decoration: none; }
table.data td { padding: 0 var(--s3); height: var(--row-h); border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr { transition: background var(--speed) var(--ease); }
table.data tbody tr:hover { background: var(--panel-hover); }
table.data tbody tr[aria-selected="true"] { background: var(--accent-soft); }
table.data tfoot td { height: 34px; font-weight: 600; background: var(--panel-subtle); border-top: 1px solid var(--line); }
.cell-strong { font-weight: 550; color: var(--text); }
table.data td a.cell-strong { white-space: nowrap; }
.col-tight { width: 1%; white-space: nowrap; }

/* Actions de ligne : révélées au survol, toujours accessibles au clavier. */
.row-actions { display: flex; gap: var(--s1); justify-content: flex-end; opacity: 0; transition: opacity var(--speed) var(--ease); }
tr:hover .row-actions, tr:focus-within .row-actions { opacity: 1; }
@media (pointer: coarse) { .row-actions { opacity: 1; } }

/* Ligne éditable (saisie des positions d'un devis / d'une facture) */
table.editable td { padding: 0 var(--s1); }
table.editable td:first-child { padding-left: var(--s3); }
table.editable .cell-input {
  width: 100%; height: calc(var(--row-h) - 8px); padding: 0 var(--s2);
  border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; color: var(--text); font: inherit; font-size: var(--t-md);
}
table.editable .cell-input:hover { border-color: var(--line); background: var(--panel); }
table.editable .cell-input:focus { outline: none; border-color: var(--accent); background: var(--panel); box-shadow: 0 0 0 3px var(--accent-soft); }
table.editable .cell-input.num { text-align: right; font-variant-numeric: tabular-nums; }
/* Grille d'un formulaire : chaque case se voit au repos, on y saisit. */
table.entry-grid .cell-input { border-color: var(--line-strong); background: var(--panel); }
table.entry-grid .cell-input:hover { border-color: var(--g7); }
table.entry-grid .cell-input[readonly] { background: transparent; border-color: transparent; }

/* Poignée de réordonnancement */
.grip { cursor: grab; color: var(--text-subtle); display: grid; place-items: center; width: 20px; }
.grip:active { cursor: grabbing; }

/* Vide, chargement */
.empty { padding: var(--s12) var(--s6); text-align: center; }
.empty .ico { width: 28px; height: 28px; color: var(--text-subtle); margin-bottom: var(--s3); }
.empty h3 { font-size: var(--t-lg); margin-bottom: var(--s1); }
.empty p { color: var(--text-muted); max-width: 380px; margin: 0 auto var(--s4); }

.skeleton { background: linear-gradient(90deg, var(--g3) 25%, var(--g4) 37%, var(--g3) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: var(--r-sm); }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* Bandeaux */
.banner { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) var(--s4); border: 1px solid; border-radius: var(--r-lg); font-size: var(--t-md); margin-bottom: var(--s4); }
.banner .ico { width: 17px; height: 17px; flex: 0 0 17px; margin-top: 1px; }
.banner-info { background: var(--info-soft); border-color: var(--info-line); color: var(--info-text); }
.banner-ok   { background: var(--ok-soft);   border-color: var(--ok-line);   color: var(--ok-text); }
.banner-warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn-text); }
.banner-bad  { background: var(--bad-soft);  border-color: var(--bad-line);  color: var(--bad-text); }

/* Menus et fenêtres modales */
.menu {
  min-width: 190px; padding: var(--s1);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-lg); box-shadow: var(--sh-2);
}
.menu-item {
  display: flex; align-items: center; gap: var(--s2);
  width: 100%; height: 30px; padding: 0 var(--s2);
  border: 0; border-radius: var(--r-sm); background: transparent;
  color: var(--text); font: inherit; font-size: var(--t-md); text-align: left;
  cursor: pointer; text-decoration: none;
}
.menu-item:hover, .menu-item[aria-selected="true"] { background: var(--panel-hover); text-decoration: none; }
.menu-item .ico { width: 15px; height: 15px; flex: 0 0 15px; color: var(--text-muted); }
.menu-item .kbd-hint { margin-left: auto; }
.menu-item-danger { color: var(--bad-text); }
.menu-item-danger:hover { background: var(--bad-soft); }
.menu-sep { height: 1px; margin: var(--s1) 0; background: var(--line); }

dialog.modal {
  padding: 0; border: 1px solid var(--line); border-radius: var(--r-xl);
  background: var(--panel); color: var(--text);
  box-shadow: var(--sh-3); max-width: min(560px, calc(100vw - 32px)); width: 100%;
}
dialog.modal::backdrop { background: var(--overlay); backdrop-filter: blur(1.5px); }
.modal-head { padding: var(--s4) var(--s5) var(--s3); }
.modal-body { padding: 0 var(--s5) var(--s4); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s3) var(--s5); border-top: 1px solid var(--line); background: var(--panel-subtle); border-radius: 0 0 var(--r-xl) var(--r-xl); }

/* Palette de commandes */
dialog.palette { max-width: min(620px, calc(100vw - 32px)); margin-top: 12vh; }
.palette-input { width: 100%; height: 46px; padding: 0 var(--s5); border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); font: inherit; font-size: var(--t-lg); }
.palette-input:focus { outline: none; }
.palette-list { max-height: 44vh; overflow-y: auto; padding: var(--s2); }
.palette-group { padding: var(--s2) var(--s2) var(--s1); font-size: var(--t-xs); font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-subtle); }
.palette-foot { display: flex; gap: var(--s4); padding: var(--s2) var(--s5); border-top: 1px solid var(--line); font-size: var(--t-sm); color: var(--text-subtle); }

/* Pagination */
.pager { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s4); border-top: 1px solid var(--line); background: var(--panel-subtle); font-size: var(--t-md); color: var(--text-muted); }
.pager .spacer { flex: 1 1 auto; }

/* Mise en page « document » : édition à gauche, actions à droite */
.doc { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: var(--s5); align-items: start; }
.doc-side { position: sticky; top: calc(var(--topbar-h) + var(--s6)); display: flex; flex-direction: column; gap: var(--s3); }

/* Deux cartes côte à côte, l'une sous l'autre sur un écran étroit */
.split { display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); align-items: start; }
.split > .card { margin: 0; }

/* Liste de propriétés */
.props { display: grid; grid-template-columns: auto 1fr; gap: var(--s2) var(--s4); font-size: var(--t-md); }
.props dt { color: var(--text-muted); }
.props dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }

/* Pages de formulaire : une grille de cartes, sur une ou deux colonnes */
.form-cards { display: grid; gap: var(--s4); align-items: start; }
.form-cards-2 { grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr)); }
.form-cards .card { margin: 0; }
.form-cards .card.wide { grid-column: 1 / -1; }
.form-column { display: flex; flex-direction: column; gap: var(--s4); min-width: 0; }
.form-section { grid-column: 1 / -1; margin-top: var(--s4); }
.form-section h2 { font-size: var(--t-xl); }
.form-section p { margin: var(--s1) 0 0; font-size: var(--t-md); }
.page-note { margin: 0 0 var(--s4); }
.check-list { display: flex; flex-direction: column; gap: var(--s3); }
.static-value { min-height: 32px; display: flex; align-items: center; font-size: var(--t-md); }
/* Logo, signature : souvent sombres sur fond transparent, posés sur blanc. */
.card-image { display: block; max-height: 180px; max-width: 100%; margin-bottom: var(--s4); background: #fff; padding: var(--s2); border: 1px solid var(--line); border-radius: var(--r); }
.sig-pad { display: block; width: 100%; max-width: 520px; height: 180px; background: #fff; border: 1px dashed var(--g7); border-radius: var(--r); touch-action: none; }
.sig-line { max-width: 520px; margin: var(--s1) 0 var(--s2); font-size: var(--t-sm); color: var(--text-subtle); }
.card .props { margin: 0 0 var(--s4); }
.card .props:last-child { margin-bottom: 0; }
.form-buttons { display: flex; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s4); }
.card-note { margin: var(--s3) 0 0; }
.check-hint { margin: var(--s1) 0 0 23px; }
.cell-sub { font-size: var(--t-sm); color: var(--text-muted); margin-top: 2px; }
.note-banner { margin-top: var(--s3); }
.note-banner > .banner { margin-bottom: 0; }
.head-badges { display: flex; gap: var(--s2); margin: calc(-1 * var(--s3)) 0 var(--s4); }

/* Détail dépliable sous une ligne de tableau (livre auxiliaire) */
.disclosure > summary { cursor: pointer; padding: var(--s2) 0; font-size: var(--t-sm); color: var(--text-muted); }
.disclosure > summary:hover { color: var(--text); }
.disclosure[open] > summary { margin-bottom: var(--s2); }
.disclosure .table-scroll { border: 1px solid var(--line); border-radius: var(--r-sm); }
table.data tr.detail:hover { background: transparent; }
table.data tr.detail > td { height: auto; }

/* Annexe aux comptes annuels */
.annex-help { margin: 0 0 var(--s3); }
.annex-text { margin: 0 0 var(--s2); font-size: var(--t-md); }
.annex-table { border: 1px solid var(--line); border-radius: var(--r-sm); margin-bottom: var(--s2); }
.annex-entry { margin-top: var(--s3); border-top: 1px solid var(--line); padding-top: var(--s1); }
.annex-lines { border: 1px solid var(--line); border-radius: var(--r-sm); margin-bottom: var(--s3); }
.annex-form + .annex-form { margin-top: var(--s4); padding-top: var(--s4); border-top: 1px dashed var(--line); }
.annex-verdicts .banner:last-child { margin-bottom: 0; }
.issue-list { margin: var(--s2) 0 0; padding-left: var(--s5); }

/* Comptes annuels : bilan et compte de résultat */
table.statement td.num { white-space: nowrap; }
.neg { color: var(--bad-text); }
table.statement tr.stmt-section td { background: var(--panel-subtle); font-size: var(--t-sm); font-weight: 600; color: var(--text-muted); }
table.statement tr.stmt-subtotal td, table.statement tr.stmt-intermediate td { background: var(--panel-subtle); font-weight: 600; }
table.statement tr.stmt-intermediate td { font-style: italic; }
table.statement tr.stmt-total td { font-weight: 700; border-top: 2px solid var(--line-strong); }
table.statement tr.stmt-empty td { font-size: var(--t-sm); }
.stmt-no { color: var(--text-muted); font-weight: 600; margin-right: var(--s1); }
.stmt-ref { color: var(--text-subtle); font-size: var(--t-xs); margin-left: var(--s2); font-weight: 400; }
.stmt-detail > summary { cursor: pointer; }
.stmt-accounts { width: 100%; margin: var(--s2) 0 var(--s1); border-collapse: collapse; font-size: var(--t-sm); color: var(--text-muted); }
.stmt-accounts th, .stmt-accounts td { padding: 2px var(--s2); border-bottom: 1px solid var(--line); text-align: left; font-weight: 400; }
.stmt-accounts .num { text-align: right; white-space: nowrap; }
.result-box { margin: var(--s4); padding: var(--s4); border: 1px solid; border-radius: var(--r-lg); }
.result-ok { background: var(--ok-soft); border-color: var(--ok-line); color: var(--ok-text); }
.result-bad { background: var(--bad-soft); border-color: var(--bad-line); color: var(--bad-text); }
.result-box .stat-label, .result-box .stat-value .unit { color: inherit; }

/* Totaux d'un document */
.totals { margin-left: auto; width: min(320px, 100%); font-size: var(--t-md); }
.totals-row { display: flex; justify-content: space-between; gap: var(--s4); padding: var(--s2) 0; }
.totals-row .amount { font-variant-numeric: tabular-nums; }
.totals-row.total { border-top: 1px solid var(--line-strong); margin-top: var(--s1); padding-top: var(--s3); font-size: var(--t-lg); font-weight: 650; }

/* Indicateur d'activité réseau (interactivité ciblée) */
.busy { position: fixed; top: 0; left: 0; right: 0; height: 2px; z-index: 100; background: var(--accent); transform: scaleX(0); transform-origin: left; transition: transform .3s var(--ease), opacity .3s; }
:root[data-busy] .busy { transform: scaleX(.8); }
[aria-busy="true"] { opacity: .6; pointer-events: none; }

/* Pages hors application : offre et bon publics, connexion, erreur.
   Ni rail ni panneau — le client n'a pas à voir notre navigation. */
.public-top { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s6); background: var(--panel); border-bottom: 1px solid var(--line); }
.public-brand { display: inline-flex; align-items: center; gap: var(--s2); font-size: var(--t-lg); font-weight: 700; letter-spacing: .02em; }
.public-mark { width: 26px; height: 26px; flex: 0 0 26px; border-radius: var(--r-sm); background: var(--swiss); color: #fff; display: grid; place-items: center; }
.public-company { margin-left: auto; color: var(--text-muted); font-size: var(--t-md); font-weight: 600; text-align: right; }
.public-main { max-width: 900px; margin: 0 auto; padding: var(--s8) var(--s5) var(--s12); }
.public-main > * + * { margin-top: var(--s4); }
.public-main > .public-section { margin-top: var(--s8); font-size: var(--t-xl); }
.public-text { white-space: pre-line; }
.public-description { margin: var(--s4) 0 0; }
.public-comment + .public-comment { margin-top: var(--s3); padding-top: var(--s3); border-top: 1px solid var(--line); }
.public-foot { text-align: center; color: var(--text-subtle); font-size: var(--t-sm); padding: 0 var(--s5) var(--s8); }
.parties { display: grid; gap: var(--s5); grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.party-label { font-size: var(--t-xs); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); margin-bottom: var(--s1); }
.party-name { font-weight: 650; }
.party-address { font-style: normal; font-size: var(--t-md); color: var(--text-muted); }
.public-center { min-height: 100%; display: grid; place-items: center; padding: var(--s6) var(--s4); }
.public-card { width: min(400px, 100%); }
.public-card .public-brand { margin-bottom: var(--s6); }
.public-card h1 { margin-bottom: var(--s4); }
.btn-block { display: flex; width: 100%; }

/* --- 5. Responsive ------------------------------------------------------ */

/* Portable 13-15" : le panneau se resserre, on rend de la largeur au
   tableau sans rien cacher. */
@media (max-width: 1280px) {
  :root { --panel-w: 188px; }
  .main { padding: var(--s5) var(--s4) var(--s10); }
}

/* Tablette : le panneau bascule à l'horizontale sous la barre du haut.
   Même balisage, même ordre de lecture — seule la direction change. */
@media (max-width: 900px) {
  .app {
    grid-template-columns: var(--rail-w) 1fr;
    grid-template-rows: var(--topbar-h) auto 1fr;
    grid-template-areas: "rail topbar" "rail panel" "rail main";
  }
  .app[data-panel="none"] {
    grid-template-columns: var(--rail-w) 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas: "rail topbar" "rail main";
  }
  .panel {
    display: flex; align-items: center; gap: var(--s1);
    padding: var(--s2) var(--s3);
    border-right: 0; border-bottom: 1px solid var(--line);
    background: var(--panel);
    overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
  }
  .panel::-webkit-scrollbar { display: none; }
  .panel-title, .panel-group > .nav-label { display: none; }
  .panel-group { display: contents; }
  .nav-link { flex: 0 0 auto; }

  .doc { grid-template-columns: minmax(0, 1fr); }
  .doc-side { position: static; }
  .form-grid > [class*="col-"] { grid-column: span 12; }
  .col-6, .col-4 { grid-column: span 6; }
}

/* Téléphone : le rail descend en barre d'onglets, là où va le pouce.
   Le panneau reste la rangée horizontale des écrans du domaine. */
@media (max-width: 720px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) auto 1fr;
    grid-template-areas: "topbar" "panel" "main";
    padding-bottom: calc(var(--rail-w) + env(safe-area-inset-bottom, 0px));
  }
  /* Sans panneau (l'accueil) : une seule colonne aussi. Sans cette
     remise à zéro, la grille à deux colonnes de la tablette s'appliquait
     encore et le contenu se tassait dans la colonne étroite du rail. */
  .app[data-panel="none"] {
    grid-template-columns: 1fr;
    grid-template-rows: var(--topbar-h) 1fr;
    grid-template-areas: "topbar" "main";
  }
  .rail {
    position: fixed; inset: auto 0 0 0; z-index: 50;
    flex-direction: row; justify-content: space-around;
    height: calc(var(--rail-w) + env(safe-area-inset-bottom, 0px));
    padding: var(--s1) var(--s2) env(safe-area-inset-bottom, 0px);
    border-right: 0; border-top: 1px solid var(--line);
    overflow-x: auto; scrollbar-width: none;
  }
  .rail::-webkit-scrollbar { display: none; }
  .rail-logo, .rail-spacer { display: none; }
  .rail-item[aria-current="page"]::before {
    left: 50%; right: auto; top: -5px; bottom: auto;
    width: 18px; height: 3px; transform: translateX(-50%);
    border-radius: 0 0 3px 3px;
  }

  .main { padding: var(--s4) var(--s3) var(--s10); }
  .public-top { padding: var(--s3) var(--s4); }
  .public-main { padding: var(--s5) var(--s3) var(--s10); }
  .page-head { flex-direction: column; gap: var(--s3); }
  .page-head .actions { margin-left: 0; width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; }
  .omni { width: auto; flex: 1 1 auto; }
  .omni-text, .omni kbd { display: none; }

  /* Un tableau devient une pile de fiches : chaque cellule porte son
     intitulé via `data-label`, aucun défilement horizontal. */
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data thead, table.data tfoot { display: none; }
  table.data tr { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
  table.data td { height: auto; padding: 2px 0; border: 0; display: flex; justify-content: space-between; gap: var(--s4); }
  table.data td::before { content: attr(data-label); color: var(--text-muted); font-size: var(--t-sm); }
  table.data td:empty { display: none; }
  table.data td.num, table.data td.amount { text-align: right; }
  .row-actions { opacity: 1; justify-content: flex-start; margin-top: var(--s2); }
  .totals { width: 100%; }
}

/* --- 6. Impression ------------------------------------------------------ */
@media print {
  .rail, .panel, .topbar, .toolbar, .tabs, .row-actions, .pager, .doc-side, .busy { display: none !important; }
  .app { display: block; padding: 0; }
  .main { padding: 0; }
  .card, .table-wrap { border: 0; box-shadow: none; }
  body { background: #fff; font-size: 11pt; }
  table.data th { background: transparent; }
  a { color: inherit; text-decoration: none; }
}
