
/* ============================================================
   A1 — DESIGN TOKENS  (source de vérité unique)
   ============================================================ */
:root {
  /* Espacement — base 4px */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px; --sp-5: 20px;
  --sp-6: 24px; --sp-8: 32px; --sp-10: 40px; --sp-12: 48px; --sp-16: 64px;

  /* Échelle typographique */
  --fs-xs: 11px; --fs-sm: 12.5px; --fs-base: 14px; --fs-md: 15px;
  --fs-lg: 18px; --fs-xl: 22px; --fs-2xl: 28px; --fs-3xl: 36px;

  --font-ui: 'Hanken Grotesk', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  /* Rayons */
  --r-sm: 7px; --r-md: 11px; --r-lg: 16px; --r-full: 999px;

  /* Ombres */
  --sh-sm: 0 1px 2px rgba(15,30,40,.06), 0 1px 1px rgba(15,30,40,.04);
  --sh-md: 0 4px 14px rgba(15,30,40,.07), 0 1px 3px rgba(15,30,40,.05);
  --sh-lg: 0 18px 44px rgba(15,30,40,.14), 0 4px 12px rgba(15,30,40,.08);

  /* Marque + sémantique (thème clair par défaut) */
  --brand: #0d8b7d; --brand-600: #0b7568; --brand-050: #e6f4f2; --brand-100: #c9e8e3;
  --ink: #12201f; --ink-2: #3a4a48; --muted: #6b7b78; --faint: #98a5a2;
  --bg: #f2f0ea; --surface: #ffffff; --surface-2: #faf9f5; --surface-3: #f0eee7;
  --line: #e4e0d6; --line-2: #d7d2c6;

  --success: #0f8a4d; --success-bg: #e3f3e9;
  --info: #1d6fd6; --info-bg: #e5eefb;
  --warn: #b0740a; --warn-bg: #fbf0d8;
  --danger: #c53a26; --danger-bg: #fbe6e1;

  --focus: #0d8b7d;
}

[data-theme="dark"] {
  --brand: #2cc0ae; --brand-600: #4fd2c2; --brand-050: #12312d; --brand-100: #164039;
  --ink: #eaf1ef; --ink-2: #c3cfcc; --muted: #8fa09c; --faint: #66756f;
  --bg: #0c1615; --surface: #12201e; --surface-2: #162725; --surface-3: #1d302d;
  --line: #25403c; --line-2: #2f4d48;

  --success: #3bc978; --success-bg: #122d20;
  --info: #5fa0f0; --info-bg: #11253d;
  --warn: #e0a53a; --warn-bg: #2e2611;
  --danger: #ec6a56; --danger-bg: #331a15;

  --focus: #2cc0ae;
  --sh-sm: 0 1px 2px rgba(0,0,0,.3);
  --sh-md: 0 4px 16px rgba(0,0,0,.35);
  --sh-lg: 0 20px 48px rgba(0,0,0,.55);
}

/* ============================================================
   RESET + BASE
   ============================================================ */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  color: var(--ink);
  /* Un halo de marque tres dilue donne de la profondeur sans colorer la page */
  background:
    radial-gradient(1200px 600px at 15% -10%, color-mix(in srgb, var(--brand) 8%, transparent), transparent 60%),
    radial-gradient(900px 500px at 95% 0%, color-mix(in srgb, var(--info) 6%, transparent), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button { font-family: inherit; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, p { margin: 0; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* Focus visible partout */
:focus-visible { outline: 2.5px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
:focus:not(:focus-visible) { outline: none; }

/* ============================================================
   BOUTONS — inspiration MUI (contained / outlined / text)
   Deux signatures reprises : l'ONDE qui part du point clique, et
   l'ELEVATION du bouton plein, qui monte au survol et redescend
   quand on l'enfonce — le relief dit ou l'on agit.
   Ce qui n'est PAS repris : les majuscules automatiques de MUI.
   « GENERER LE RAPPORT » se lit moins bien qu'en casse normale,
   surtout accentue, et contredirait la microcopie (§A6).
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  font-family: var(--font-ui); font-size: var(--fs-base); font-weight: 600;
  padding: 0 var(--sp-4); height: 38px; border-radius: var(--r-sm);
  border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  transition: background .14s, border-color .14s, box-shadow .14s, color .14s, transform .05s;
  user-select: none; text-decoration: none;
  position: relative; overflow: hidden;
}
.btn:active:not(:disabled) { transform: translateY(.5px); }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn-sm { height: 31px; font-size: var(--fs-sm); padding: 0 var(--sp-3); border-radius: 6px; }
.btn-lg { height: 44px; font-size: var(--fs-md); padding: 0 var(--sp-6); }
.btn-full { width: 100%; }
/* Desactive : plus de relief non plus — un bouton en creux qui reste
   souleve promet une action qu'il ne rendra pas. */
.btn:disabled { opacity: .55; cursor: not-allowed; box-shadow: none; }

.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--sh-sm); }
.btn-primary:hover:not(:disabled) { background: var(--brand-600); box-shadow: var(--sh-md); }
.btn-primary:active:not(:disabled) { box-shadow: var(--sh-sm); }
.btn-outline { background: var(--surface); color: var(--ink); border-color: var(--line-2); }
.btn-outline:hover:not(:disabled) { background: var(--surface-3); border-color: var(--muted); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--ink); }
.btn-danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }

/* L'onde part du point clique : app.js pose l'origine et le diametre,
   le CSS joue l'animation. Sans JS, le bouton reste normal — l'onde
   est un agrement, jamais une confirmation d'action. */
.btn::after {
  content: ""; position: absolute; pointer-events: none;
  top: var(--onde-y, 50%); left: var(--onde-x, 50%);
  width: 0; height: 0; border-radius: 50%;
  background: currentColor; opacity: 0;
  transform: translate(-50%, -50%);
}
.btn.onde::after { animation: onde .5s cubic-bezier(.4, 0, .2, 1); }
@keyframes onde {
  from { width: 0; height: 0; opacity: .22; }
  to { width: var(--onde-d, 240px); height: var(--onde-d, 240px); opacity: 0; }
}

/* Spinner état loading */
.spinner { width: 15px; height: 15px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   LAYOUT + SIDEBAR
   ============================================================ */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }

.sidebar {
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border-right: 1px solid var(--line);
  box-shadow: inset -1px 0 0 color-mix(in srgb, var(--brand) 8%, transparent);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.side-head { padding: var(--sp-5) var(--sp-5) var(--sp-4); display: flex; align-items: center; gap: var(--sp-3); }
.brand-mark { width: 32px; height: 32px; border-radius: 9px; background: linear-gradient(140deg, var(--brand) 0%, var(--brand-600) 100%); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 16px; flex: none; box-shadow: var(--sh-sm), inset 0 1px 0 rgba(255,255,255,.25); }
.brand-name { font-weight: 800; font-size: var(--fs-md); letter-spacing: -.01em; line-height: 1.1; }
.brand-name .a { color: var(--brand); }
.brand-sub { font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: .11em; font-weight: 600; margin-top: 1px; }

.side-search { padding: 0 var(--sp-4) var(--sp-3); }
.search-box { display: flex; align-items: center; gap: var(--sp-2); height: 36px; padding: 0 var(--sp-3); background: var(--surface-3); border: 1px solid transparent; border-radius: var(--r-sm); cursor: text; }
.search-box:focus-within { border-color: var(--brand); background: var(--surface); }
.search-box svg { width: 15px; height: 15px; color: var(--muted); flex: none; }
.search-box input { border: none; background: none; outline: none; font-family: inherit; font-size: var(--fs-sm); color: var(--ink); width: 100%; }
.search-box kbd { font-family: var(--font-mono); font-size: 10px; color: var(--faint); background: var(--surface); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; }

.nav-group { padding: var(--sp-2) var(--sp-3); }
.nav-label { font-size: 9.5px; text-transform: uppercase; letter-spacing: .13em; color: var(--faint); font-weight: 700; padding: var(--sp-3) var(--sp-3) var(--sp-2); }
.nav-link {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%;
  padding: 9px var(--sp-3); border-radius: var(--r-sm);
  font-size: var(--fs-base); font-weight: 500; color: var(--ink-2);
  border: none; background: none; cursor: pointer; text-align: left; position: relative;
  transition: background .12s, color .12s; text-decoration: none;
}
.nav-link svg { width: 18px; height: 18px; flex: none; color: var(--muted); }
.nav-link:hover { background: var(--surface-3); color: var(--ink); }
.nav-link.active { background: var(--brand-050); color: var(--brand-600); font-weight: 600; }
.nav-link.active svg { color: var(--brand); }
.nav-link .count { margin-left: auto; font-family: var(--font-mono); font-size: 11px; font-weight: 600; background: var(--surface-3); color: var(--muted); border-radius: var(--r-full); padding: 1px 7px; min-width: 20px; text-align: center; }
.nav-link.active .count { background: var(--brand); color: #fff; }
.nav-link .count.alert { background: var(--danger); color: #fff; }

.side-foot { margin-top: auto; padding: var(--sp-3); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: var(--sp-1); }
.user-card { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2); border-radius: var(--r-sm); width: 100%; }
.user-card:hover { background: var(--surface-3); }
.avatar { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, var(--brand), var(--brand-600)); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; }
.user-name { font-weight: 600; font-size: var(--fs-sm); color: var(--ink); }
.user-role { font-size: 11px; color: var(--muted); }
/* Bouton-icone : un disque, comme l'IconButton de MUI — une icone n'a
   pas de coins, son fond de survol non plus. */
.icon-btn { width: 34px; height: 34px; border-radius: 50%; border: none; background: none; color: var(--muted); display: grid; place-items: center; cursor: pointer; flex: none; text-decoration: none; transition: background .14s, color .14s; }
.icon-btn:hover { background: var(--surface-3); color: var(--ink); }
.icon-btn svg { width: 18px; height: 18px; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main { min-width: 0; display: flex; flex-direction: column; flex: 1; }
.topbar { display: none; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 20; }
.wrap { padding: var(--sp-8) var(--sp-10); max-width: 1180px; width: 100%; margin: 0 auto; flex: 1; }

.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-8); }
.crumb { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); color: var(--muted); margin-bottom: var(--sp-3); flex-wrap: wrap; }
.crumb a { color: var(--muted); }
.crumb a:hover { color: var(--brand-600); }
.crumb .sep { color: var(--line-2); }
.crumb .cur { color: var(--ink); font-weight: 600; }
.page-title { font-size: var(--fs-3xl); font-weight: 800; letter-spacing: -.028em; line-height: 1.05; background: linear-gradient(120deg, var(--ink) 25%, color-mix(in srgb, var(--brand) 55%, var(--ink)) 100%); -webkit-background-clip: text; background-clip: text; color: transparent; }
.page-sub { font-size: var(--fs-md); color: var(--muted); margin-top: var(--sp-2); }
/* flex-wrap : sans lui, une barre d'actions chargee poussait la page en
   defilement horizontal et forcait le fil d'Ariane a la ligne (07.09). */
.page-actions { display: flex; gap: var(--sp-3); flex: none; align-items: center;
  flex-wrap: wrap; justify-content: flex-end; }

/* Navigation d'un mandant : onglets persistants sur toutes ses pages. */
.subnav {
  display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
  margin: calc(-1 * var(--sp-5)) 0 var(--sp-6);
}
.subnav a {
  padding: 8px 12px; font-size: var(--fs-sm); font-weight: 600;
  color: var(--muted); text-decoration: none; white-space: nowrap;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
  border-radius: var(--r-sm) var(--r-sm) 0 0; transition: color .12s, background .12s;
}
.subnav a:hover { color: var(--ink); background: var(--surface-2); }
.subnav a[aria-current="page"] { color: var(--brand); border-bottom-color: var(--brand); }

.section { margin-bottom: var(--sp-10); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-4); }
.section-title { font-size: var(--fs-lg); font-weight: 700; letter-spacing: -.01em; }
.section-note { font-size: var(--fs-sm); color: var(--muted); }
.card-title { font-size: var(--fs-base); font-weight: 700; letter-spacing: -.01em; margin: 0 0 var(--sp-2); }
.text-danger { color: var(--danger); }

/* ============================================================
   CARTES — inspiration MUI (elevation / outlined)
   Un seul vocabulaire de relief pour toutes les surfaces :
   au repos --sh-sm, souleve --sh-md, et le relief ne bouge QUE
   si la carte mene quelque part. Une carte qui se souleve sans
   etre cliquable promet un geste qui n'existe pas.
   ============================================================ */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--sh-sm); }
.card-pad { position: relative; }
.card-pad { padding: var(--sp-6); }

/* Le message seul dans une carte : etat vide leger, sans icone ni
   titre (l'etat vide complet reste .empty). Dix pages le composaient
   en style en ligne — donc dix occasions de diverger. */
.card-note { padding: var(--sp-6); text-align: center; color: var(--muted); }

/* KPI cards actionnables */
.kpi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }
.kpi {
  background: linear-gradient(170deg, var(--surface) 0%, var(--surface-2) 130%);
  border: 1px solid var(--line); border-radius: var(--r-md);
  padding: var(--sp-5); box-shadow: var(--sh-sm); cursor: pointer; text-align: left;
  position: relative; overflow: hidden;
  transition: box-shadow .16s, border-color .16s, transform .1s; display: flex; flex-direction: column; gap: var(--sp-3);
  text-decoration: none; color: inherit;
}
.kpi::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: linear-gradient(90deg, var(--brand), color-mix(in srgb, var(--brand) 25%, transparent)); opacity: .9; }
.kpi:hover { box-shadow: var(--sh-md); border-color: color-mix(in srgb, var(--brand) 30%, var(--line-2)); transform: translateY(-2px); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.kpi-ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex: none; }
.kpi-ic svg { width: 16px; height: 16px; }
.kpi-row { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-3); }
.kpi-value { font-size: var(--fs-3xl); font-weight: 800; letter-spacing: -.03em; line-height: 1; font-family: var(--font-mono); }
.kpi-foot { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-sm); }
.trend { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; font-family: var(--font-mono); }
.trend.up { color: var(--success); } .trend.down { color: var(--danger); } .trend.flat { color: var(--muted); }
.trend svg { width: 13px; height: 13px; }
.kpi-hint { color: var(--muted); font-size: var(--fs-sm); }
.spark { height: 34px; width: 100%; }

/* Items à traiter */
/* Ligne cliquable : la surface repond au survol, comme un element de
   liste MUI. Sans cela, rien ne disait que la ligne entiere menait
   quelque part. */
.todo-item { display: flex; align-items: center; gap: var(--sp-4); padding: var(--sp-4); border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; transition: background .14s; }
.todo-item:hover { background: var(--surface-2); }
.todo-item:last-child { border-bottom: none; }
.todo-ic { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.todo-ic svg { width: 17px; height: 17px; }
.todo-body { flex: 1; min-width: 0; }
.todo-title { font-weight: 600; font-size: var(--fs-base); }
.todo-meta { font-size: var(--fs-sm); color: var(--muted); margin-top: 1px; }

/* Mandants */
.mandate-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--sp-4); }
.mandate { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--sh-sm); overflow: hidden; transition: box-shadow .16s, border-color .16s; }
.mandate:hover { box-shadow: var(--sh-md); border-color: color-mix(in srgb, var(--brand) 30%, var(--line-2)); }
.mandate-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-5) var(--sp-5) var(--sp-4); }
.mandate-logo { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; font-weight: 800; font-size: 18px; color: #fff; flex: none; }
.mandate-name { font-size: var(--fs-lg); font-weight: 700; letter-spacing: -.01em; }
.mandate-name a:hover { color: var(--brand-600); }
.mandate-info { font-size: var(--fs-sm); color: var(--muted); margin-top: 1px; display: flex; align-items: center; gap: var(--sp-2); }
.mandate-body { padding: 0 var(--sp-5) var(--sp-4); display: flex; gap: var(--sp-2); flex-wrap: wrap; }
.mandate-foot { display: flex; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--line); background: var(--surface-2); }
.mandate-foot .btn { flex: 1; }
.mandate-gen { display: flex; flex-wrap: wrap; gap: var(--sp-2); align-items: center; padding: 0 var(--sp-5) var(--sp-4); background: var(--surface-2); }
.mandate-gen .select { flex: 1; min-width: 0; }
.mandate-gen .btn { flex: none; }
.select-sm { height: 31px; padding: 0 26px 0 var(--sp-3); font-size: var(--fs-sm); border-radius: 6px; background-position: right 8px center; }
.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; }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-xs); font-weight: 600; padding: 3px 9px; border-radius: var(--r-full); line-height: 1.4; }
.badge svg { width: 11px; height: 11px; }
.badge .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: var(--surface-3); color: var(--muted); }

/* Info tooltip ('i' survolable) */
.info { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; border-radius: 50%; border: 1.5px solid var(--line-2); color: var(--muted); font-size: 9.5px; font-weight: 700; font-style: italic; font-family: var(--font-ui); cursor: help; vertical-align: middle; flex: none; user-select: none; padding: 0; background: none; }
.info:hover, .info:focus-visible { border-color: var(--brand); color: var(--brand); }
.info .tip { position: absolute; bottom: calc(100% + 9px); left: 50%; transform: translateX(-50%) translateY(4px); width: 230px; background: var(--surface); color: var(--ink-2); border: 1px solid var(--line-2); border-radius: var(--r-sm); box-shadow: var(--sh-lg); padding: 10px 12px; font-size: 12px; font-weight: 400; font-style: normal; line-height: 1.5; text-align: left; letter-spacing: normal; text-transform: none; opacity: 0; visibility: hidden; pointer-events: none; transition: opacity .15s, transform .15s; z-index: 60; }
.info:hover .tip, .info:focus-visible .tip { opacity: 1; visibility: visible; transform: translateX(-50%) translateY(0); }
.info .tip::after { content: ""; position: absolute; top: 100%; left: 50%; transform: translateX(-50%); border: 6px solid transparent; border-top-color: var(--surface); }

/* Tables */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--sh-sm); overflow: visible; }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; }
table.data thead th:first-child { border-top-left-radius: var(--r-md); }
table.data thead th:last-child { border-top-right-radius: var(--r-md); }
table.data tbody tr:last-child td:first-child { border-bottom-left-radius: var(--r-md); }
table.data tbody tr:last-child td:last-child { border-bottom-right-radius: var(--r-md); }
table.data th { font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 700; text-align: left; padding: var(--sp-3) var(--sp-4); background: var(--surface-2); border-bottom: 1px solid var(--line); }
table.data td { padding: var(--sp-4); border-bottom: 1px solid var(--line); font-size: var(--fs-base); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-2); }
.cell-actions { display: flex; gap: var(--sp-2); justify-content: flex-end; align-items: center; }

/* ============================================================
   CHAMPS DE SAISIE — inspiration MUI (variante « outlined »)
   Trois signatures reprises de MUI : la bordure qui s'epaissit a
   2px dans la couleur de marque au focus, le halo circulaire des
   controles a cocher, et des cases/interrupteurs DESSINES plutot
   que laisses au navigateur — ils etaient natifs, donc plats et
   differents sur chaque systeme (demande du 09.09).
   Tout passe par les jetons : le theme sombre suit sans regle en
   double, sauf pour les chevrons (une image ne lit pas var()).
   ============================================================ */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.form-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-4); }
.inline-form { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }
.label .req { color: var(--danger); }

.input, .select {
  height: 40px; padding: 0 var(--sp-3); font-family: inherit; font-size: var(--fs-base); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-sm); width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
.input:hover:not(:disabled):not(:focus), .select:hover:not(:disabled):not(:focus) { border-color: var(--muted); }
/* Focus : la bordure passe a 2px SANS decaler la mise en page —
   l'ombre interne double le trait au lieu d'elargir la boite. */
.input:focus, .select:focus {
  outline: none; border-color: var(--brand);
  box-shadow: inset 0 0 0 1px var(--brand), 0 0 0 3px var(--brand-050);
}
textarea.input { height: auto; padding: var(--sp-3); resize: vertical; min-height: 88px; }
.input:disabled, .select:disabled { background-color: var(--surface-3); color: var(--muted); cursor: not-allowed; }
.input::placeholder { color: var(--faint); }
.hint { font-size: 12px; color: var(--muted); }
.form-actions { display: flex; justify-content: flex-end; gap: var(--sp-3); margin-top: var(--sp-6); padding-top: var(--sp-5); border-top: 1px solid var(--line); }

/* Listes deroulantes : le chevron du systeme est remplace par le
   notre, identique sur tous les navigateurs. Deux declarations
   (clair / sombre) : une image encodee ne peut pas lire un jeton. */
select.select, select.input {
  appearance: none; -webkit-appearance: none;
  padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7b78' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 15px;
}
[data-theme="dark"] select.select, [data-theme="dark"] select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238fa09c' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}
/* Variante compacte : le chevron se resserre avec le champ (sinon
   la regle select.select, plus specifique, imposait ses 34px). */
select.select-sm { padding-right: 26px; background-position: right 8px center; background-size: 13px; }

/* Cases a cocher : dessinees, avec le halo de survol de MUI. */
input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 18px; height: 18px; margin: 0; flex: none; position: relative;
  display: inline-grid; place-content: center;
  border: 2px solid var(--muted); border-radius: 4px; background: var(--surface);
  cursor: pointer; vertical-align: middle;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
input[type="checkbox"]:hover:not(:disabled) {
  border-color: var(--brand);
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--brand) 10%, transparent);
}
input[type="checkbox"]:focus-visible {
  outline: none;
  box-shadow: 0 0 0 6px color-mix(in srgb, var(--brand) 24%, transparent);
}
input[type="checkbox"]:checked { background: var(--brand); border-color: var(--brand); }
/* Le crochet est trace, pas un caractere : meme dessin partout. */
input[type="checkbox"]::after {
  content: ""; width: 10px; height: 5px; margin-top: -3px;
  border: 2px solid #fff; border-top: 0; border-right: 0;
  transform: rotate(-45deg) scale(.5); opacity: 0;
  transition: opacity .12s, transform .12s;
}
input[type="checkbox"]:checked::after { opacity: 1; transform: rotate(-45deg) scale(1); }
input[type="checkbox"]:disabled { background: var(--surface-3); border-color: var(--line-2); cursor: not-allowed; }
/* Une case isolee (tableau) ne fait que 18px : l'etiquette qui l'entoure
   porte la cible tactile a 40px sans changer le dessin ni la mise en page
   (la marge negative annule son propre remplissage). */
.case-cible { display: inline-flex; align-items: center; justify-content: center; padding: 11px; margin: -11px; cursor: pointer; }

/* Interrupteur : pour un reglage qui s'applique aussitot (la case
   a cocher suggere un formulaire a valider, l'interrupteur non). */
input[type="checkbox"].switch {
  width: 40px; height: 22px; border-radius: var(--r-full);
  border: none; background: var(--line-2); display: inline-block;
}
input[type="checkbox"].switch:hover:not(:disabled) { border-color: transparent; box-shadow: none; }
input[type="checkbox"].switch:focus-visible { box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 24%, transparent); }
input[type="checkbox"].switch:checked { background: var(--brand); }
input[type="checkbox"].switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; margin: 0; border: 0; border-radius: 50%;
  background: var(--surface); box-shadow: var(--sh-sm);
  opacity: 1; transform: none;
  transition: transform .18s cubic-bezier(.4, 0, .2, 1);
}
input[type="checkbox"].switch:checked::after { transform: translateX(18px); }
input[type="checkbox"].switch:disabled { background: var(--surface-3); }

/* Choix de fichier : le bouton du systeme prend l'allure des notres. */
input[type="file"] { font-size: var(--fs-sm); color: var(--muted); max-width: 100%; }
input[type="file"]::file-selector-button {
  font-family: inherit; font-size: var(--fs-sm); font-weight: 600;
  height: 31px; padding: 0 var(--sp-4); margin-right: var(--sp-3);
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--r-sm); cursor: pointer;
  transition: background .14s, border-color .14s;
}
input[type="file"]::file-selector-button:hover { background: var(--surface-3); border-color: var(--muted); }

/* Selecteur de couleur : une pastille, pas un widget brut. */
input[type="color"] {
  appearance: none; -webkit-appearance: none;
  width: 40px; height: 40px; padding: 3px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-sm);
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 4px; }
input[type="color"]::-moz-color-swatch { border: none; border-radius: 4px; }

/* White-label swatches & preview */
.swatches { display: flex; gap: var(--sp-3); flex-wrap: wrap; }
.swatch { width: 38px; height: 38px; border-radius: 9px; cursor: pointer; border: 2px solid transparent; position: relative; transition: transform .1s; }
.swatch:hover { transform: scale(1.08); }
.swatch[aria-pressed="true"] { border-color: var(--ink); }
.swatch[aria-pressed="true"]::after { content: "✓"; position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 15px; font-weight: 800; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
.wl-preview { border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; }
.wl-prev-head { padding: var(--sp-4) var(--sp-5); color: #fff; display: flex; align-items: center; gap: var(--sp-3); }
.wl-prev-logo { width: 30px; height: 30px; border-radius: 8px; background: rgba(255,255,255,.25); display: grid; place-items: center; font-weight: 800; }
.wl-prev-body { padding: var(--sp-5); background: var(--surface); font-size: var(--fs-sm); color: var(--muted); }

/* Detail rows */
.kv { display: flex; align-items: center; gap: var(--sp-4); padding: var(--sp-4) 0; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: none; }
.kv-k { width: 200px; font-size: var(--fs-sm); color: var(--muted); font-weight: 600; flex: none; }
.kv-v { font-size: var(--fs-base); }

/* Bexio status */
.bexio { display: flex; align-items: center; gap: var(--sp-4); }
.status-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; position: relative; }
.status-dot.green { background: var(--success); }
.status-dot.green::after { content: ""; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--success); opacity: .35; animation: pulse 2s ease-out infinite; }
@keyframes pulse { 0% { transform: scale(.7); opacity: .5; } 100% { transform: scale(1.5); opacity: 0; } }

/* Empty state */
.empty { text-align: center; padding: var(--sp-16) var(--sp-6); }
.empty-ic { width: 60px; height: 60px; border-radius: 16px; background: var(--surface-3); display: grid; place-items: center; margin: 0 auto var(--sp-4); }
.empty-ic svg { width: 28px; height: 28px; color: var(--muted); }
.empty h3 { font-size: var(--fs-lg); font-weight: 700; margin-bottom: var(--sp-2); }
.empty p { color: var(--muted); max-width: 34ch; margin: 0 auto var(--sp-5); }

/* Skeleton */
.skel { background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%); background-size: 400% 100%; animation: shim 1.3s ease infinite; border-radius: 6px; }
@keyframes shim { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* Narrative */
.narrative { background: linear-gradient(180deg, var(--brand-050), var(--surface)); border: 1px solid var(--brand-100); border-radius: var(--r-md); padding: var(--sp-6); }
.narrative-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.narrative-text { font-size: var(--fs-md); line-height: 1.7; color: var(--ink-2); text-wrap: pretty; }

/* Flashes & Toasts */
.flash { display: flex; align-items: center; justify-content: space-between; padding: var(--sp-3) var(--sp-4); border-radius: var(--r-sm); margin-bottom: var(--sp-4); font-size: var(--fs-sm); font-weight: 500; }
.flash-info { background: var(--info-bg); color: var(--info); border: 1px solid color-mix(in srgb, var(--info) 30%, transparent); }
.flash-success { background: var(--success-bg); color: var(--success); border: 1px solid color-mix(in srgb, var(--success) 30%, transparent); }
.flash-error { background: var(--danger-bg); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 30%, transparent); }
.flash-close { background: none; border: none; font-size: 18px; cursor: pointer; color: inherit; line-height: 1; padding: 0 4px; }

.toasts { position: fixed; bottom: var(--sp-5); right: var(--sp-5); z-index: 200; display: flex; flex-direction: column; gap: var(--sp-3); pointer-events: none; }
.toast { display: flex; align-items: flex-start; gap: var(--sp-3); background: var(--surface); border: 1px solid var(--line); border-left: 3px solid var(--brand); border-radius: var(--r-md); box-shadow: var(--sh-lg); padding: var(--sp-3) var(--sp-4); min-width: 0; width: max-content; max-width: min(360px, calc(100vw - 2 * var(--sp-5))); pointer-events: auto; animation: toastIn .28s cubic-bezier(.2,.9,.3,1); }
.toast.out { animation: toastOut .25s forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(20px); } }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-info { border-left-color: var(--info); }
.toast-ic { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.toast-success .toast-ic { color: var(--success); }
.toast-error .toast-ic { color: var(--danger); }
.toast-info .toast-ic { color: var(--info); }
.toast-body { flex: 1; min-width: 0; font-size: var(--fs-sm); }
.toast-title { font-weight: 600; color: var(--ink); overflow-wrap: anywhere; }
.toast-msg { color: var(--muted); margin-top: 1px; overflow-wrap: anywhere; }

/* Overlay & Modal IA */
.overlay { position: fixed; inset: 0; background: rgba(15,25,24,.5); backdrop-filter: blur(3px); z-index: 150; display: none; place-items: center; padding: var(--sp-4); }
.overlay.on { display: grid; }
.modal { background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--sh-lg); width: 100%; max-width: 440px; padding: var(--sp-8); animation: toastIn .25s; }
.modal h2 { font-size: var(--fs-xl); font-weight: 700; letter-spacing: -.01em; }

/* LOGIN */
.login-page { background: var(--bg); min-height: 100vh; display: flex; }
.login { min-height: 100vh; width: 100%; display: grid; grid-template-columns: 1.05fr 1fr; }
.login-aside { background: linear-gradient(155deg, var(--brand-600), var(--brand) 55%, #0a5f55); color: #fff; padding: var(--sp-12); display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-aside::after { content: ""; position: absolute; inset: 0; background: radial-gradient(600px 400px at 80% 10%, rgba(255,255,255,.12), transparent); pointer-events: none; }
.login-aside .brand-name { color: #fff; font-size: var(--fs-lg); }
.login-aside .brand-name .a { color: #bff0e8; }
.login-quote { font-size: var(--fs-2xl); font-weight: 700; letter-spacing: -.02em; line-height: 1.2; max-width: 14ch; }
.login-feats { display: flex; flex-direction: column; gap: var(--sp-3); }
.login-feat { display: flex; align-items: center; gap: var(--sp-3); font-size: var(--fs-md); color: #dcf5f0; }
.login-feat svg { width: 18px; height: 18px; flex: none; }
.login-main { display: grid; place-items: center; padding: var(--sp-8); background: var(--surface); }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { font-size: var(--fs-2xl); font-weight: 800; letter-spacing: -.02em; }
.login-card .sub { color: var(--muted); margin: var(--sp-2) 0 var(--sp-6); }
.login-foot { margin-top: var(--sp-8); font-size: var(--fs-sm); color: var(--faint); text-align: center; }

/* RESPONSIVE */
.scrim { position: fixed; inset: 0; background: rgba(15,25,24,.45); z-index: 40; display: none; }
.scrim.on { display: block; }

@media(max-width: 960px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .mandate-grid { grid-template-columns: 1fr; }
  .wrap { padding: var(--sp-6); }
  .page-head { flex-direction: column; }
  .login { grid-template-columns: 1fr; }
  .login-aside { display: none; }
}

@media(max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; width: 270px; transform: translateX(-100%); transition: transform .24s ease; }
  .sidebar.open { transform: none; box-shadow: var(--sh-lg); }
  .topbar { display: flex; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .page-title { font-size: var(--fs-2xl); }
  
  /* tables → cartes */
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data tr { border-bottom: 1px solid var(--line); padding: var(--sp-2) 0; }
  table.data td { border: none; padding: 6px var(--sp-4); display: flex; justify-content: space-between; gap: var(--sp-4); }
  table.data td::before { content: attr(data-label); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
  .cell-actions { justify-content: flex-start; }
  .mandate-gen { flex-wrap: wrap; }
  .mandate-gen .select { flex: 1 1 40%; }
  .toasts { left: var(--sp-4); right: var(--sp-4); bottom: var(--sp-4); }
  .toast { width: auto; max-width: 100%; }
}

/* ============================================================
   RECHERCHE GLOBALE — liste de resultats
   ============================================================ */
.search-box { position: relative; }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 80;
  background: var(--surface); border: 1px solid var(--line-2); border-radius: var(--r-md);
  box-shadow: var(--sh-lg); overflow: hidden; max-height: 320px; overflow-y: auto;
}
.search-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); text-decoration: none; color: var(--ink);
  border-bottom: 1px solid var(--line);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover, .search-item.active { background: var(--brand-050); }
.search-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.search-dot.on { background: var(--success); }
.search-dot.off { background: var(--faint); }
.search-text { display: flex; flex-direction: column; min-width: 0; }
.search-name { font-weight: 600; font-size: var(--fs-sm); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-sub { font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-empty { padding: var(--sp-4); font-size: var(--fs-sm); color: var(--muted); text-align: center; }

/* ============================================================
   BARRE DE FILTRES — page « Mes rapports »
   ============================================================ */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: var(--sp-4); align-items: flex-end;
}
.filter-bar .field { flex: 1 1 150px; min-width: 0; margin: 0; }
.filter-actions { display: flex; gap: var(--sp-2); align-items: center; flex: 0 0 auto; }
.link-strong { color: var(--ink); font-weight: 600; text-decoration: none; }
.link-strong:hover { color: var(--brand); text-decoration: underline; }

@media(max-width: 760px) {
  .filter-bar .field { flex: 1 1 100%; }
  .filter-actions { width: 100%; }
  .filter-actions .btn { flex: 1; }
}

/* ============================================================
   MOUVEMENT REDUIT
   Un reglage systeme, pas un confort : chez certaines personnes
   les animations declenchent nausees ou migraines. On coupe le
   decoratif (onde, soulevement, glissement) et on garde ce qui
   porte une information — le tourniquet d'attente reste, ralenti,
   car sans lui plus rien ne dit qu'un traitement est en cours.
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
  .spinner { animation-duration: 1.2s !important; animation-iteration-count: infinite !important; }
  .btn.onde::after { animation: none; }
  .btn:active:not(:disabled), a.card:hover, button.card:hover, .kpi:hover { transform: none; }
}
