/* ==========================================================================
   Qualitas Hub — Design system
   Charte : bleu Qualitas #005489 · marine #0B1F33 · cyan #00B8D9 (accent rare)
   Principes : neutres froids, une seule couleur d'action, ombres très légères,
   hiérarchie par la typographie et l'espace plutôt que par la couleur.
   ========================================================================== */

/* ---------- Tokens ---------- */
:root {
  --brand-50: #eef5fa; --brand-100: #d6e7f2; --brand-200: #a9cbe2; --brand-500: #0a6aa6;
  --brand-600: #005489; --brand-700: #00436e; --navy: #0b1f33; --cyan: #00b8d9;

  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #fafbfc; --sunken: #f1f3f6;
  --border: #e4e7ec; --border-strong: #d0d5dd;
  --text: #0b1f33; --text-2: #3d4b5c; --muted: #5d6b7c; --faint: #8a96a6;
  --primary: var(--brand-600); --primary-hover: var(--brand-700); --primary-soft: var(--brand-50); --primary-line: var(--brand-200);
  --on-primary: #fff; --link: var(--brand-600);
  --focus: 0 0 0 3px rgba(0, 84, 137, .22);

  --ok: #0f7a4a; --ok-bg: #e9f7ef; --ok-bd: #bfe5cf;
  --warn: #8a5300; --warn-bg: #fff5e5; --warn-bd: #f5d9a8;
  --soon: #6f5b00; --soon-bg: #fffbe0; --soon-bd: #efe3a0;
  --danger: #b42318; --danger-bg: #fef1f0; --danger-bd: #f8c9c4;
  --info: var(--brand-700); --info-bg: var(--brand-50); --info-bd: var(--brand-100);
  --note-bg: #fffbeb; --note-bd: #f3d77a;
  --ev-rdv: #e8f1f8; --ev-interv: #fdeee4; --ev-form: #f0ecfb; --ev-reunion: #e8f5ee; --ev-abs: #f0f2f5;

  --shadow-xs: 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --shadow-md: 0 4px 12px -2px rgba(16, 24, 40, .08), 0 2px 4px -2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 16px 40px -12px rgba(11, 31, 51, .22);

  --r-sm: 6px; --r: 10px; --r-lg: 14px; --r-pill: 999px;
  --side-w: 248px; --top-h: 60px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  --font: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}
/* Thème sombre : suit le système, sauf choix explicite de l'utilisateur (data-theme) */
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --dark: 1; } }
:root[data-theme="dark"], :root.auto-dark {
  --bg: #0a111c; --surface: #101a28; --surface-2: #132031; --sunken: #0d1622;
  --border: #1f2c3d; --border-strong: #2b3a4f;
  --text: #e8edf4; --text-2: #c3cddb; --muted: #95a3b6; --faint: #6d7c90;
  --primary: #2f8fcf; --primary-hover: #4aa3dd; --primary-soft: rgba(47, 143, 207, .14); --primary-line: rgba(74, 163, 221, .45);
  --link: #6cb8ea; --focus: 0 0 0 3px rgba(74, 163, 221, .35);
  --ok: #4cc58b; --ok-bg: rgba(76, 197, 139, .12); --ok-bd: rgba(76, 197, 139, .3);
  --warn: #f0b354; --warn-bg: rgba(240, 179, 84, .12); --warn-bd: rgba(240, 179, 84, .3);
  --soon: #e7d26b; --soon-bg: rgba(231, 210, 107, .1); --soon-bd: rgba(231, 210, 107, .3);
  --danger: #f2877d; --danger-bg: rgba(242, 135, 125, .12); --danger-bd: rgba(242, 135, 125, .3);
  --info: #6cb8ea; --info-bg: rgba(108, 184, 234, .12); --info-bd: rgba(108, 184, 234, .28);
  --note-bg: rgba(243, 215, 122, .07); --note-bd: rgba(243, 215, 122, .4);
  --ev-rdv: rgba(47, 143, 207, .16); --ev-interv: rgba(232, 125, 64, .16); --ev-form: rgba(155, 125, 235, .16);
  --ev-reunion: rgba(76, 197, 139, .14); --ev-abs: rgba(149, 163, 182, .12);
  --shadow-xs: none; --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3); --shadow-md: 0 6px 16px -4px rgba(0, 0, 0, .5);
  --shadow-lg: 0 20px 48px -12px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.6 var(--font); letter-spacing: -.003em;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
a { color: var(--link); text-decoration: none; transition: color .15s var(--ease); }
a:hover { color: var(--primary-hover); }
h1, h2, h3 { color: var(--text); letter-spacing: -.018em; line-height: 1.25; }
h1 { font-size: 22px; font-weight: 650; margin: 0 0 20px; }
h1 small { display: inline-block; font-size: 14px; font-weight: 450; color: var(--muted); margin-left: 10px; letter-spacing: 0; }
h1 small a { color: var(--muted); } h1 small a:hover { color: var(--link); }
h2 { font-size: 14.5px; font-weight: 620; margin: 0 0 14px; }
h3 { font-size: 13px; font-weight: 600; }
p { margin: 0 0 10px; }
b, strong { font-weight: 600; }
::selection { background: var(--brand-100); color: var(--navy); }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }
.muted { color: var(--muted); } .err { color: var(--danger); }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 14px; height: 14px; vertical-align: -2px; }

/* ---------- Layout : sidebar + topbar ---------- */
.app { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 2px;
  background: var(--surface); border-right: 1px solid var(--border); padding: 18px 14px; overflow-y: auto;
}
.logo { display: flex; align-items: center; gap: 10px; padding: 2px 6px 16px; color: var(--text); }
.logo:hover { color: var(--text); }
.logo img { height: 46px; width: auto; display: block; }
.logo .logo-dark { display: none; }
:root[data-theme="dark"] .logo .logo-light, :root.auto-dark .logo .logo-light { display: none; }
:root[data-theme="dark"] .logo .logo-dark, :root.auto-dark .logo .logo-dark { display: block; }
.logo-mark { width: 32px; height: 32px; border-radius: 9px; flex: none; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--brand-500), var(--navy)); box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, .15); }
.logo-mark svg { width: 18px; height: 18px; stroke: #fff; stroke-width: 2.6; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.logo-word { font-weight: 700; font-size: 15px; letter-spacing: .12em; text-transform: uppercase; line-height: 1.15; }
.logo-word span { display: block; font-size: 11px; font-weight: 500; letter-spacing: .01em; color: var(--muted); text-transform: none; }
.nav-section { font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); padding: 16px 10px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 8px 10px; border-radius: 8px;
  color: var(--text-2); font-weight: 500; transition: background .15s var(--ease), color .15s var(--ease);
}
.nav-link .icon { color: var(--faint); transition: color .15s var(--ease); }
.nav-link:hover { background: var(--sunken); color: var(--text); }
.nav-link:hover .icon { color: var(--text-2); }
.nav-link.on { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-link.on .icon { color: var(--primary); }
.nav-link .badge { margin-left: auto; }
.side-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: var(--top-h); display: flex; align-items: center; gap: 12px; padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: saturate(160%) blur(12px); -webkit-backdrop-filter: saturate(160%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.search { flex: 1; max-width: 460px; position: relative; margin: 0; }
.search > div { margin: 0; }
.search .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.search input { padding-left: 38px; padding-right: 64px; background: var(--surface); }
.search kbd { position: absolute; right: 9px; top: 50%; transform: translateY(-50%); }
kbd { font: 500 11px/1 var(--font); color: var(--muted); background: var(--sunken); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 3px 6px; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.top-actions form { margin: 0; }
.icon-btn {
  display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r); padding: 0;
  border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease), border-color .15s var(--ease);
}
.icon-btn:hover { background: var(--surface); border-color: var(--border); color: var(--text); }
.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun, :root.auto-dark .theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .moon, :root.auto-dark .theme-toggle .moon { display: block; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 0 6px 0 12px; margin-left: 6px; border-left: 1px solid var(--border); color: var(--text-2); font-weight: 550; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: linear-gradient(140deg, var(--brand-500), var(--navy)); color: #fff; font-size: 12px; font-weight: 650; letter-spacing: .03em;
}
.menu-btn { display: none; }
main { padding: 30px 32px 72px; max-width: 1320px; width: 100%; margin: 0 auto; animation: rise .35s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; z-index: 40; left: 0; width: 280px; transform: translateX(-100%); transition: transform .25s var(--ease); box-shadow: var(--shadow-lg); }
  body.nav-open .side { transform: none; }
  body.nav-open::after { content: ""; position: fixed; inset: 0; background: rgba(11, 31, 51, .35); z-index: 30; }
  .menu-btn { display: inline-grid; }
  .topbar { padding: 0 16px; }
  .search kbd, .user-chip .name { display: none; }
  main { padding: 20px 16px 56px; }
}

/* ---------- En-tête de page ---------- */
.bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.bar h1, .bar h2 { margin: 0; }
.bar > div { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.bar > div > form { margin: 0; }
.card .bar { margin-bottom: 14px; }
.card .bar > a:not(.btn) { font-size: 13px; font-weight: 550; }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 36px; padding: 0 14px;
  font: 550 13.5px/1 var(--font); letter-spacing: -.005em; white-space: nowrap; cursor: pointer; text-decoration: none;
  color: var(--on-primary); background: var(--primary); border: 1px solid var(--primary); border-radius: var(--r);
  box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255, 255, 255, .12);
  transition: background .15s var(--ease), border-color .15s var(--ease), box-shadow .15s var(--ease), transform .1s var(--ease);
}
.btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: var(--on-primary); box-shadow: var(--shadow-md); }
.btn:active { transform: translateY(1px); box-shadow: none; }
.btn.ghost { background: var(--surface); color: var(--text-2); border-color: var(--border); box-shadow: var(--shadow-xs); }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--text); }
.btn.on, .btn.ghost.on { background: var(--primary-soft); color: var(--primary); border-color: var(--primary-line); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(.94); }
.btn.small { height: 30px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
button.link { background: none; border: 0; padding: 0; color: var(--link); cursor: pointer; font: inherit; }
button.link:hover { color: var(--primary-hover); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0 0 !important; padding-top: 20px; border-top: 1px solid var(--border); grid-column: 1 / -1; }
.seg { display: inline-flex; padding: 3px; background: var(--sunken); border: 1px solid var(--border); border-radius: var(--r); }
.seg a { padding: 5px 12px; border-radius: 7px; color: var(--muted); font-weight: 550; font-size: 13px; }
.seg a:hover { color: var(--text); }
.seg a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Cartes ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  padding: 20px 22px; margin-bottom: 18px; box-shadow: var(--shadow-sm); overflow-x: auto;
}
.card.narrow { max-width: 800px; margin-inline: auto; padding: 30px 34px; }
.card.narrow h1 { font-size: 20px; margin-bottom: 24px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; }
.grid2.rev { align-items: start; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; align-items: start; }
.grid2 > .card, .grid3 > .card { margin: 0; }
.grid2 + .card, .grid2 + .tabs, .grid3 + .card { margin-top: 18px; }
@media (max-width: 900px) { .grid2, .grid2.rev { grid-template-columns: minmax(0, 1fr); } }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 0; padding: 9px 0; border-bottom: 1px solid var(--border); }
.row:last-child, .row:has(+ h3), .row:has(+ form) { border-bottom: 0; }
.row > a { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.row > span { flex: none; }
h3.sub { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); margin: 18px 0 2px; padding-top: 14px; border-top: 1px solid var(--border); }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  display: flex; flex-direction: column-reverse; justify-content: flex-end; gap: 8px; position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 16px 18px;
  box-shadow: var(--shadow-sm); transition: border-color .2s var(--ease), box-shadow .2s var(--ease), transform .2s var(--ease);
}
.kpi::after { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--primary); opacity: 0; transition: opacity .2s var(--ease); }
.kpi:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.kpi:hover::after { opacity: 1; }
.kpi b { font-size: 26px; font-weight: 650; letter-spacing: -.03em; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--text); }
.kpi span { font-size: 12px; color: var(--muted); font-weight: 550; line-height: 1.4; text-transform: uppercase; letter-spacing: .045em; }
.kpi span .tag { text-transform: none; letter-spacing: 0; }
.kpi.alert { border-color: var(--danger-bd); }
.kpi.alert::after { background: var(--danger); opacity: 1; }
.kpi.alert b { color: var(--danger); }

/* ---------- Tableaux ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--faint); white-space: nowrap; padding-top: 4px; }
td { font-variant-numeric: tabular-nums; color: var(--text-2); }
td a { font-weight: 550; }
tr:last-child td { border-bottom: 0; }
tr { transition: background .12s var(--ease); }
tr:has(td):hover { background: var(--surface-2); }
th:first-child, td:first-child { padding-left: 4px; } th:last-child, td:last-child { padding-right: 4px; }
td .muted { font-size: 12.5px; }
td form { margin: 0; }
/* Tableau clé / valeur (fiches) */
.card > table tr > th:not(:only-child) + td { color: var(--text); }
.card > table tr:not(:first-child) > th { text-transform: none; letter-spacing: 0; font-size: 13px; font-weight: 550; color: var(--muted); padding-top: 11px; }

/* ---------- Pastilles ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px; border-radius: var(--r-pill);
  font-size: 12px; font-weight: 550; white-space: nowrap; line-height: 1; vertical-align: middle;
  color: var(--text-2); background: var(--sunken); border: 1px solid var(--border);
}
.tag:is(.ok, .expire, .urgent, .bientot, .a_surveiller, .p-CRITIQUE, .p-HAUTE) { padding-left: 8px; }
.tag:is(.ok, .expire, .urgent, .bientot, .a_surveiller, .p-CRITIQUE, .p-HAUTE)::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.tag.ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-bd); }
.tag.expire, .tag.urgent, .tag.p-CRITIQUE { color: var(--danger); background: var(--danger-bg); border-color: var(--danger-bd); }
.tag.bientot, .tag.p-HAUTE { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-bd); }
.tag.a_surveiller { color: var(--soon); background: var(--soon-bg); border-color: var(--soon-bd); }
.badge, .tabs i {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; margin-left: 7px;
  border-radius: var(--r-pill); font: 600 11px/1 var(--font); font-style: normal; font-variant-numeric: tabular-nums;
  color: var(--muted); background: var(--sunken); border: 1px solid var(--border);
}
.badge, .tabs i.warn { color: #fff; background: var(--danger); border-color: transparent; }

/* ---------- Onglets & filtres ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.tabs a {
  display: inline-flex; align-items: center; padding: 10px 12px; margin-bottom: -1px; color: var(--muted); font-weight: 550;
  border-bottom: 2px solid transparent; transition: color .15s var(--ease), border-color .15s var(--ease);
}
.tabs a:hover { color: var(--text); border-color: var(--border-strong); }
.tabs a.on { color: var(--text); border-color: var(--primary); }
.tabs a.on i { color: var(--primary); background: var(--primary-soft); border-color: var(--primary-line); }
.tabs a.on i.warn { color: #fff; background: var(--danger); border-color: transparent; }
.filters { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filters > input:not([type=checkbox]):not([type=hidden]), .filters > select { width: auto; min-width: 260px; flex: 0 1 auto; }
.filters > input[name=q] { flex: 1 1 260px; max-width: 420px; }
.who-filter { gap: 6px; }
.chip {
  display: inline-flex !important; align-items: center; gap: 7px; height: 30px; padding: 0 12px; margin: 0 !important;
  border: 1px solid var(--border); border-radius: var(--r-pill); background: var(--surface); cursor: pointer;
  font-weight: 550 !important; font-size: 13px !important; color: var(--text-2) !important; transition: all .15s var(--ease);
}
.chip:hover { border-color: var(--border-strong); }
.chip:has(input:checked) { background: var(--primary-soft); border-color: var(--primary-line); color: var(--primary) !important; }
.chip input { width: 14px !important; min-width: 0 !important; height: 14px; margin: 0; }
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; color: var(--muted); margin-top: 6px; }
.pager a { padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); font-weight: 550; }
.pager a:hover { border-color: var(--border-strong); }

/* ---------- Formulaires ---------- */
input, select, textarea {
  font: inherit; color: var(--text); width: 100%; padding: 8px 12px; min-height: 38px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r);
  box-shadow: var(--shadow-xs); transition: border-color .15s var(--ease), box-shadow .15s var(--ease);
}
textarea { min-height: 88px; resize: vertical; line-height: 1.55; }
select { 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' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238a96a6' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
select[multiple] { background-image: none; padding-right: 12px; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:hover, select:hover, textarea:hover { border-color: var(--faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
input[type=checkbox], input[type=radio] { width: 16px; height: 16px; min-height: 0; padding: 0; margin: 0; box-shadow: none; accent-color: var(--primary); cursor: pointer; flex: none; }
form label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
form > div { margin-bottom: 18px; }
.helptext { display: block; color: var(--muted); font-size: 12px; margin-top: 6px; line-height: 1.45; }
.errorlist { list-style: none; padding: 0; margin: 0 0 6px; color: var(--danger); font-size: 12.5px; font-weight: 550; }
.errorlist.nonfield { grid-column: 1 / -1; padding: 10px 12px; margin-bottom: 18px; background: var(--danger-bg); border: 1px solid var(--danger-bd); border-radius: var(--r); }
div:has(> .errorlist) input, div:has(> .errorlist) select, div:has(> .errorlist) textarea { border-color: var(--danger); }
/* Case à cocher seule : libellé en ligne, présentée comme une option */
form > div:has(> input[type=checkbox]) { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface-2); cursor: pointer; }
form > div:has(> input[type=checkbox]) > label { order: 2; margin: 0; font-weight: 550; font-size: 13.5px; color: var(--text); cursor: pointer; }
form > div:has(> input[type=checkbox]) > input { order: 1; }
form > div:has(> input[type=checkbox]) > .helptext { order: 3; flex-basis: 100%; margin: 0 0 0 26px; }
/* Choix multiples / boutons radio : pastilles cliquables */
form div:has(> div > label > input[type=checkbox]), form div:has(> div > label > input[type=radio]) { display: flex; flex-wrap: wrap; gap: 8px; }
form div > div > label:has(> input[type=checkbox]), form div > div > label:has(> input[type=radio]) {
  display: inline-flex; align-items: center; gap: 8px; margin: 0; padding: 7px 12px; font-weight: 550; font-size: 13px; color: var(--text-2);
  border: 1px solid var(--border); border-radius: var(--r); background: var(--surface); cursor: pointer; transition: all .15s var(--ease);
}
form div > div > label:has(> input:checked) { border-color: var(--primary-line); background: var(--primary-soft); color: var(--primary); }
/* Formulaire principal sur 2 colonnes */
.card.narrow form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 20px; }
.card.narrow form > div:has(textarea), .card.narrow form > div:has(> input[type=checkbox]),
.card.narrow form > div:has(> div > div > label > input), .card.narrow form > p, .card.narrow form > .errorlist { grid-column: 1 / -1; }
@media (max-width: 640px) { .card.narrow form { grid-template-columns: minmax(0, 1fr); } .card.narrow { padding: 22px 18px; } }
.inline-form { border-top: 1px solid var(--border); padding-top: 18px; margin-top: 18px; }
.inline-form h2 { font-size: 13px; }

/* ---------- Messages (toasts) ---------- */
.toasts { position: fixed; z-index: 60; top: 72px; right: 24px; display: flex; flex-direction: column; gap: 10px; width: min(420px, calc(100vw - 32px)); pointer-events: none; }
.msg {
  display: block; padding: 12px 16px; margin-bottom: 16px; border-radius: var(--r); line-height: 1.5;
  font-weight: 500; color: var(--ok); background: var(--ok-bg); border: 1px solid var(--ok-bd);
}
.msg.warn, .msg.warning { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-bd); }
.msg.error { color: var(--danger); background: var(--danger-bg); border-color: var(--danger-bd); }
.msg.info { color: var(--info); background: var(--info-bg); border-color: var(--info-bd); }
.msg a { font-weight: 600; text-decoration: underline; text-underline-offset: 2px; color: inherit; }
.msg form { display: inline; }
.toasts .msg {
  pointer-events: auto; margin: 0; padding: 13px 16px 13px 18px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg); position: relative; overflow: hidden; animation: toast .35s var(--ease) both;
}
.toasts .msg::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--ok); }
.toasts .msg.warning::before { background: var(--warn); } .toasts .msg.error::before { background: var(--danger); } .toasts .msg.info::before { background: var(--primary); }
.toasts .msg.hide { opacity: 0; transform: translateX(16px); transition: all .3s var(--ease); }
@keyframes toast { from { opacity: 0; transform: translateY(-8px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Fil de discussion (tickets, activités) ---------- */
.msgbox { padding: 16px 18px; }
.msgbox.IN { box-shadow: inset 3px 0 0 var(--border-strong), var(--shadow-sm); }
.msgbox.OUT { box-shadow: inset 3px 0 0 var(--primary), var(--shadow-sm); }
.msgbox.NOTE { box-shadow: inset 3px 0 0 var(--note-bd), var(--shadow-sm); background: var(--note-bg); }
.mhead { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; font-size: 13px; flex-wrap: wrap; }
.msgbox > div:last-child { color: var(--text-2); line-height: 1.7; }

/* ---------- Cartes projet ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.pcard { display: flex; flex-direction: column; gap: 9px; margin: 0; color: var(--text-2); padding: 20px;
  transition: transform .2s var(--ease), box-shadow .2s var(--ease), border-color .2s var(--ease); }
.pcard b { color: var(--text); font-size: 15px; letter-spacing: -.01em; }
.pcard:hover { color: var(--text-2); transform: translateY(-2px); box-shadow: var(--shadow-md); border-color: var(--border-strong); }
.progress { height: 6px; background: var(--sunken); border-radius: var(--r-pill); overflow: hidden; box-shadow: inset 0 0 0 1px var(--border); }
.progress > div { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--brand-600), var(--cyan)); transition: width .6s var(--ease); }
.progress.big { height: 8px; margin-bottom: 14px; }

/* ---------- Kanban ---------- */
.kanban { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 14px; overflow-x: auto; padding-bottom: 12px; scroll-snap-type: x proximity; }
.kanban.pipe { grid-auto-columns: minmax(215px, 1fr); }
.kb-col { background: var(--sunken); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 12px; min-height: 280px; scroll-snap-align: start; transition: background .15s var(--ease), border-color .15s var(--ease); }
.kb-col.over { background: var(--primary-soft); border-color: var(--primary); border-style: dashed; }
.kb-col h3 { display: flex; align-items: center; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 2px 2px 10px; }
.kb-col h3 i { font-style: normal; margin-left: auto; min-width: 22px; height: 20px; display: inline-grid; place-items: center; padding: 0 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-pill); font-size: 11px; color: var(--text-2); }
.kb-total { font-size: 12px; color: var(--muted); margin: -4px 2px 12px; font-variant-numeric: tabular-nums; font-weight: 500; }
.kb-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 12px 13px; margin-bottom: 8px;
  cursor: grab; box-shadow: var(--shadow-xs); transition: box-shadow .15s var(--ease), border-color .15s var(--ease), transform .15s var(--ease);
}
.kb-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.kb-card:active { cursor: grabbing; }
.kb-card.dragging { opacity: .5; transform: rotate(1.5deg) scale(1.01); box-shadow: var(--shadow-lg); }
.kb-card.late { box-shadow: inset 3px 0 0 var(--danger), var(--shadow-xs); }
.kb-card > a { display: block; font-weight: 600; color: var(--text); line-height: 1.4; margin-bottom: 6px; }
.kb-card > a:hover { color: var(--link); }
.kb-card .muted { font-size: 12px; display: flex; flex-wrap: wrap; gap: 3px 10px; align-items: center; }
.kb-card .next { font-size: 12px; margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--border); color: var(--primary); font-weight: 550; }
.kb-card .next.err { color: var(--danger); }
.stage-GAGNEE { background: linear-gradient(180deg, var(--ok-bg), var(--sunken) 140px); border-color: var(--ok-bd); }
.stage-PERDUE { opacity: .78; }
.meta { display: inline-flex; align-items: center; gap: 4px; }

/* ---------- Agenda ---------- */
.cal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.cal-head, .cal-week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-head div { padding: 10px 12px; font-size: 11px; font-weight: 600; letter-spacing: .07em; text-transform: uppercase; color: var(--faint); background: var(--surface-2); border-bottom: 1px solid var(--border); }
.cal-day { min-height: 116px; padding: 6px 6px 8px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); font-size: 12px; transition: background .12s var(--ease); }
.cal-week .cal-day:nth-child(7) { border-right: 0; } .cal-week:last-child .cal-day { border-bottom: 0; }
.cal-week .cal-day:nth-child(n+6) { background: var(--surface-2); }
.cal-day:hover { background: var(--sunken); }
.cal.semaine .cal-day { min-height: 440px; }
.cal-day.other { background: var(--sunken); } .cal-day.other .cal-num a:first-child { color: var(--faint); }
.cal-num { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.cal-num a:first-child { display: inline-grid; place-items: center; min-width: 26px; height: 26px; border-radius: 50%; color: var(--text-2); font-weight: 550; font-variant-numeric: tabular-nums; }
.cal-num a:first-child:hover { background: var(--surface); }
.cal-day.today .cal-num a:first-child { background: var(--primary); color: #fff; }
.cal-num .add { width: 24px; height: 24px; display: inline-grid; place-items: center; border-radius: 6px; color: var(--muted); opacity: 0; font-size: 17px; transition: opacity .15s var(--ease), background .15s var(--ease); }
.cal-num .add:hover { background: var(--primary-soft); color: var(--primary); }
.cal-day:hover .add, .cal-num .add:focus-visible { opacity: 1; }
.ev {
  display: block; padding: 3px 7px; margin: 3px 0; border-radius: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12px; font-weight: 500; color: var(--text); background: var(--sunken); border-left: 3px solid var(--faint);
  transition: filter .15s var(--ease), transform .15s var(--ease);
}
.ev b { font-weight: 650; font-variant-numeric: tabular-nums; }
.ev:hover { color: var(--text); filter: brightness(.96); transform: translateX(1px); }
.cal.semaine .ev { white-space: normal; padding: 6px 8px; }
.ev-APPEL { background: var(--ev-rdv); border-color: #0891b2; }
.ev-RDV { background: var(--ev-rdv); border-color: #0a6aa6; } .ev-INTERV { background: var(--ev-interv); border-color: #d0662c; }
.ev-FORM { background: var(--ev-form); border-color: #7a56d6; } .ev-REUNION { background: var(--ev-reunion); border-color: #15936a; }
.ev-ABS { background: var(--ev-abs); border-color: var(--faint); color: var(--muted); } .ev-AUTRE { background: var(--ev-abs); border-color: #5b7c99; }
.ev-overlay { background: transparent; border: 1px dashed var(--border-strong); color: var(--muted); }
.legend { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.legend .ev { display: inline-block; margin: 0; }
@media (max-width: 760px) { .cal-day { min-height: 76px; padding: 3px; } .ev { font-size: 11px; padding: 2px 4px; } .cal-head div { padding: 8px 2px; text-align: center; letter-spacing: 0; } }

/* ---------- Écran de connexion ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); }
.auth-brand {
  position: relative; overflow: hidden; color: #fff; padding: 48px 56px; display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(110% 80% at 0% 0%, #0a6aa6 0%, transparent 58%), radial-gradient(80% 70% at 100% 100%, rgba(0, 184, 217, .32) 0%, transparent 60%), var(--navy);
}
.auth-brand::after { content: ""; position: absolute; inset: 0; pointer-events: none;
  background-image: linear-gradient(rgba(255, 255, 255, .045) 1px, transparent 1px), linear-gradient(90deg, rgba(255, 255, 255, .045) 1px, transparent 1px);
  background-size: 44px 44px; -webkit-mask-image: linear-gradient(180deg, transparent, #000 30%, #000 70%, transparent); mask-image: linear-gradient(180deg, transparent, #000 30%, #000 70%, transparent); }
.auth-brand > * { position: relative; z-index: 1; }
.auth-brand .logo { padding: 0; color: #fff; }
.auth-brand .logo-word span { color: rgba(255, 255, 255, .6); }
.auth-brand h2 { color: #fff; font-size: 36px; line-height: 1.12; font-weight: 650; letter-spacing: -.035em; max-width: 460px; margin: 0 0 16px; }
.auth-brand p { color: rgba(255, 255, 255, .72); font-size: 15px; max-width: 430px; line-height: 1.65; }
.auth-brand ul { list-style: none; padding: 0; margin: 30px 0 0; display: grid; gap: 12px; color: rgba(255, 255, 255, .86); }
.auth-brand li { display: flex; gap: 12px; align-items: center; }
.auth-brand li::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 0 4px rgba(0, 184, 217, .18); }
.auth-brand footer { color: rgba(255, 255, 255, .45); font-size: 12.5px; }
.auth-form { display: grid; place-items: center; padding: 40px 24px; background: var(--bg); }
.auth-form .box { width: 100%; max-width: 380px; }
.auth-form h1 { font-size: 24px; margin-bottom: 6px; }
.auth-form .box > p { color: var(--muted); margin-bottom: 28px; }
.auth-form .btn { width: 100%; height: 42px; margin-top: 4px; }
.auth-form .logo { display: none; padding: 0 0 28px; }
@media (max-width: 860px) { .auth { grid-template-columns: 1fr; } .auth-brand { display: none; } .auth-form .logo { display: flex; } }

/* ---------- États vides ---------- */
td.muted[colspan] { text-align: center; padding: 26px 0 !important; color: var(--faint); }
.empty { text-align: center; padding: 26px 8px; color: var(--muted); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; padding: 0; }
@media (max-width: 640px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 13px 14px; } .kpi b { font-size: 20px; } .kpi span { font-size: 11px; }
  h1 { font-size: 20px; } h1 small { display: block; margin: 4px 0 0; }
}

/* ---------- Licences : étapes de régularisation ---------- */
.steps { display: grid; gap: 10px; }
.step { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--r); background: var(--surface-2); }
.step > b { flex: 1 1 220px; font-weight: 600; }
.step > form { margin: 0; }
.step.done { background: var(--ok-bg); border-color: var(--ok-bd); }
.step.done > b { color: var(--ok); }
.step.done > b::before { content: "✓ "; }
.inline-step { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; flex-basis: 100%; }
.inline-step > div { margin: 0; flex: 1 1 180px; }

.auth-brand .logo img { height: 64px; }
.auth-form .logo img { height: 56px; }

/* ---------- Historique des échanges client ---------- */
.timeline { display: grid; gap: 0; }
.tl-item { display: grid; grid-template-columns: 120px minmax(0, 1fr) auto; gap: 8px 20px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.tl-item:last-child { border-bottom: 0; padding-bottom: 2px; } .tl-item:first-child { padding-top: 2px; }
.tl-date { display: flex; flex-direction: column; gap: 3px; align-items: flex-start; }
.tl-date b { font-size: 14px; font-variant-numeric: tabular-nums; } .tl-date span:not(.tag) { color: var(--muted); font-size: 12.5px; }
.tl-date .tag { margin-top: 4px; }
.tl-title { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-bottom: 6px; font-size: 14px; }
.tl-title .muted { font-size: 12.5px; font-weight: 500; }
.tl-row { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 12px; padding: 3px 0; color: var(--text-2); }
.tl-label { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); padding-top: 3px; }
.tl-row .done { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--border-strong); }
.tl-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-size: 13px; font-weight: 550; }
.tl-actions form { margin: 0; }
.tl-item.upcoming .tl-date b { color: var(--primary); }
@media (max-width: 760px) { .tl-item { grid-template-columns: 1fr; } .tl-row { grid-template-columns: 1fr; gap: 0; } .tl-actions { flex-direction: row; align-items: center; } }
.card.narrow form > div:has(> input#id_motif), .card.narrow form > div:has(> input#id_titre), .card.narrow form > div:has(> input#id_sujet) { grid-column: 1 / -1; }

.releve-form { display: inline; margin: 0; }
.releve-info { margin: -8px 0 16px; font-size: 12.5px; }
.releve-info code { font-size: 12px; background: var(--sunken); padding: 1px 5px; border-radius: 4px; }

/* ---------- Suivi des renouvellements ---------- */
.kanban.ren { grid-auto-columns: minmax(235px, 1fr); }
.kb-card.soon { box-shadow: inset 3px 0 0 #d98a1b, var(--shadow-xs); }
.kb-card.done { cursor: default; opacity: .92; } .kb-card.done:hover { transform: none; }
.kb-card.done.lost { box-shadow: inset 3px 0 0 var(--danger), var(--shadow-xs); }
.kb-card .muted > b { color: var(--text); font-weight: 650; }
.stage-RENOUVELE { background: linear-gradient(180deg, var(--ok-bg), var(--sunken) 140px); border-color: var(--ok-bd); }
.stage-NON { background: linear-gradient(180deg, var(--danger-bg), var(--sunken) 140px); border-color: var(--danger-bd); }
.stepper { display: flex; gap: 0; margin: 4px 0 2px; }
.stepper .st { flex: 1; position: relative; text-align: center; padding-top: 22px; font-size: 12px; color: var(--faint); font-weight: 550; }
.stepper .st i { position: absolute; top: 4px; left: 50%; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border-strong); z-index: 1; }
.stepper .st::before { content: ""; position: absolute; top: 10px; left: -50%; right: 50%; height: 2px; background: var(--border-strong); }
.stepper .st:first-child::before { display: none; }
.stepper .st.now { color: var(--primary); font-weight: 650; } .stepper .st.now i { background: var(--primary); border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.stepper .st.end i { border-color: var(--ok); }

/* ---------- Tri des colonnes ---------- */
th.sortable { padding: 0; }
th.sortable a { display: flex; align-items: center; gap: 6px; padding: 4px 12px 11px; color: inherit; white-space: nowrap; transition: color .15s var(--ease); }
th.sortable:first-child a { padding-left: 4px; }
th.sortable a:hover { color: var(--text); }
th.sortable.right a { justify-content: flex-end; }
.sort-ind { font-style: normal; font-size: 12px; letter-spacing: 0; opacity: .35; transition: opacity .15s var(--ease); }
th.sortable:hover .sort-ind { opacity: .8; }
th.sortable.on a { color: var(--text); } th.sortable.on .sort-ind { opacity: 1; color: var(--primary); font-weight: 700; }
.sortbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0 0 14px; font-size: 13px; }
.chip-sort { padding: 3px 12px; border: 1px solid var(--border); border-radius: var(--r-pill); background: var(--surface); color: var(--text-2); font-weight: 550; }
.chip-sort:hover { border-color: var(--border-strong); color: var(--text); }
.chip-sort.on { background: var(--primary-soft); border-color: var(--primary-line); color: var(--primary); }
