/* ============================================================
   CYBERENTA — Design System
   Apple-inspired, premium, clean & luxurious
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── CSS Reset ──────────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--text-primary);
  background-color: var(--bg-primary);
}

/* ── Design Tokens ──────────────────────────────────────────── */
:root {
  /* Backgrounds */
  --bg-primary: #ffffff;
  --bg-secondary: #f5f5f7;
  --bg-tertiary: #fbfbfd;
  --bg-elevated: #ffffff;

  /* Surfaces */
  --surface: #ffffff;
  --surface-hover: #f9f9fb;
  --surface-active: #f0f0f2;

  /* Borders */
  --border: #d2d2d7;
  --border-light: #e8e8ed;
  --border-focus: #0071e3;

  /* Accent */
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-active: #006edb;
  --accent-light: rgba(0, 113, 227, 0.08);
  --accent-lighter: rgba(0, 113, 227, 0.04);

  /* Text */
  --text-primary: #1d1d1f;
  --text-secondary: #6e6e73;
  --text-tertiary: #86868b;
  --text-inverse: #ffffff;
  --text-accent: #0071e3;

  /* Status */
  --success: #34c759;
  --success-bg: rgba(52, 199, 89, 0.08);
  --success-border: rgba(52, 199, 89, 0.2);
  --warning: #ff9f0a;
  --warning-bg: rgba(255, 159, 10, 0.08);
  --warning-border: rgba(255, 159, 10, 0.2);
  --danger: #ff3b30;
  --danger-bg: rgba(255, 59, 48, 0.08);
  --danger-border: rgba(255, 59, 48, 0.2);
  --info: #5ac8fa;
  --info-bg: rgba(90, 200, 250, 0.08);
  --info-border: rgba(90, 200, 250, 0.2);

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.04), 0 2px 4px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.06), 0 4px 10px rgba(0, 0, 0, 0.04);
  --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.08), 0 8px 16px rgba(0, 0, 0, 0.04);
  --shadow-focus: 0 0 0 4px rgba(0, 113, 227, 0.15);

  /* Radius */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;
  --space-24: 96px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-base: 250ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-slow: 400ms cubic-bezier(0.25, 0.1, 0.25, 1);
  --transition-spring: 500ms cubic-bezier(0.34, 1.56, 0.64, 1);

  /* Typography Scale */
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;
  --text-4xl: 2.25rem;
  --text-5xl: 3rem;
  --text-6xl: 3.75rem;
  --text-7xl: 4.5rem;

  /* Font Weights */
  --font-light: 300;
  --font-regular: 400;
  --font-medium: 500;
  --font-semibold: 600;
  --font-bold: 700;
  --font-extrabold: 800;

  /* Z-index */
  --z-dropdown: 100;
  --z-sticky: 200;
  --z-modal-backdrop: 300;
  --z-modal: 400;
  --z-toast: 500;

  /* Container */
  --container-max: 1200px;
  --container-narrow: 800px;
  --sidebar-width: 260px;
}

/* ── Typography ─────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-semibold);
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

h1 { font-size: var(--text-5xl); font-weight: var(--font-bold); letter-spacing: -0.03em; }
h2 { font-size: var(--text-4xl); }
h3 { font-size: var(--text-2xl); }
h4 { font-size: var(--text-xl); }
h5 { font-size: var(--text-lg); }
h6 { font-size: var(--text-base); }

p { color: var(--text-secondary); line-height: 1.7; }

a {
  color: var(--accent);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover { color: var(--accent-hover); }

small { font-size: var(--text-sm); color: var(--text-tertiary); }

.text-gradient {
  background: linear-gradient(135deg, var(--accent) 0%, #6e5ce6 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ── Layout ─────────────────────────────────────────────────── */
.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--space-6);
}

.container-narrow {
  max-width: var(--container-narrow);
  margin: 0 auto;
  padding: 0 var(--space-6);
}

.section {
  padding: var(--space-24) 0;
}

.section-header {
  text-align: center;
  margin-bottom: var(--space-16);
}

.section-header h2 {
  margin-bottom: var(--space-4);
}

.section-header p {
  font-size: var(--text-lg);
  max-width: 600px;
  margin: 0 auto;
}

.grid {
  display: grid;
  gap: var(--space-6);
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  h1 { font-size: var(--text-4xl); }
  h2 { font-size: var(--text-3xl); }
  .section { padding: var(--space-16) 0; }
}

.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-col { display: flex; flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }
.gap-8 { gap: var(--space-8); }

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: all var(--transition-base);
}

.card:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-md);
}

.card-elevated {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-base);
}

.card-elevated:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.card-glass {
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  /* Padding vertical réduit (12px -> 9px) pour des boutons plus compacts/moins imposants (#228) ; horizontal inchangé pour préserver l'alignement */
  padding: 9px var(--space-5);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  line-height: 1;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  text-decoration: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-md);
  color: var(--text-inverse);
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border-light);
}

.btn-secondary:hover {
  background: var(--surface-hover);
  border-color: var(--border);
}

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1.5px solid var(--accent);
}

.btn-outline:hover {
  background: var(--accent-light);
}

.btn-danger {
  background: var(--danger);
  color: var(--text-inverse);
}

.btn-danger:hover {
  background: #e8352b;
}

.btn-success {
  background: var(--success);
  color: var(--text-inverse);
}

.btn-success:hover {
  background: #2db84e;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn-ghost:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.btn-sm {
  /* padding vertical 8px -> 6px (#228) */
  padding: 6px var(--space-3);
  font-size: var(--text-xs);
}

.btn-lg {
  /* padding vertical 16px -> 12px (#228) */
  padding: 12px var(--space-8);
  font-size: var(--text-base);
}

.btn-xl {
  /* padding vertical 20px -> 14px (#228) */
  padding: 14px var(--space-10);
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
}

.btn-icon {
  /* 36px -> 34px pour rester proportionné aux boutons texte compacts (#228) */
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: var(--radius-sm);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

/* ── Toggle de permission (chip cliquable) ──────────────────────
   Boutons-pastilles pour cocher une permission : remplacent la
   case à cocher brute par un chip stylé, cohérent avec le design
   system. La <input> est masquée mais reste la source de vérité
   (state .checked) ; le style suit l'état :checked du frère input.
   Variables de thème uniquement -> compatible clair/sombre (#227). */
.perm-toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  padding: 7px 12px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-full);
  background: var(--bg-secondary);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  line-height: 1;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition-fast), border-color var(--transition-fast),
              color var(--transition-fast), box-shadow var(--transition-fast);
}

/* Masque la case native sans la retirer du DOM ni du flux de focus. */
.perm-toggle input[type="checkbox"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  margin: 0;
}

/* Pastille indicatrice à gauche du libellé. */
.perm-toggle .perm-toggle-dot {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  transition: background var(--transition-fast), border-color var(--transition-fast),
              box-shadow var(--transition-fast);
}

.perm-toggle:hover {
  border-color: var(--accent);
  color: var(--text-primary);
  background: var(--surface-hover);
}

.perm-toggle:active {
  transform: scale(0.97);
}

/* État sélectionné : chip teinté accent, pastille pleine. */
.perm-toggle:has(input:checked) {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: var(--font-medium);
}

.perm-toggle:has(input:checked) .perm-toggle-dot {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px var(--bg-secondary);
}

/* Accessibilité clavier : anneau de focus quand l'input frère est focus. */
.perm-toggle:has(input:focus-visible) {
  box-shadow: 0 0 0 3px var(--accent-light);
}

/* État désactivé (rôle admin en lecture seule). */
.perm-toggle:has(input:disabled) {
  cursor: not-allowed;
  opacity: 0.6;
}

.perm-toggle:has(input:disabled):hover {
  border-color: var(--border-light);
  color: var(--text-secondary);
  background: var(--bg-secondary);
}

/* Conteneur des chips d'une catégorie. */
.perm-toggle-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

/* ── Form Elements ──────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.form-label {
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-primary);
}

.form-hint {
  font-size: var(--text-xs);
  color: var(--text-tertiary);
}

.input,
.textarea,
.select {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  outline: none;
}

.input:hover,
.textarea:hover,
.select:hover {
  border-color: var(--text-tertiary);
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-tertiary);
}

.textarea {
  min-height: 120px;
  resize: vertical;
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2386868b' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 6l3.5 3.5L11.5 6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

.input-error {
  border-color: var(--danger) !important;
}

.form-error {
  font-size: var(--text-xs);
  color: var(--danger);
}

.input-group {
  display: flex;
  gap: 0;
}

.input-group .input {
  border-radius: var(--radius-md) 0 0 var(--radius-md);
}

.input-group .btn {
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px 10px;
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  border-radius: var(--radius-full);
  white-space: nowrap;
}

.badge-success {
  color: var(--success);
  background: var(--success-bg);
  border: 1px solid var(--success-border);
}

.badge-warning {
  color: #b47800;
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
}

.badge-danger {
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
}

.badge-info {
  color: #0a7cc4;
  background: var(--info-bg);
  border: 1px solid var(--info-border);
}

.badge-neutral {
  color: var(--text-secondary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
}

.badge-dot::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
}

.table-modern {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table-modern thead {
  background: var(--bg-secondary);
}

.table-modern th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-light);
}

.table-modern td {
  padding: var(--space-4);
  border-bottom: 1px solid var(--border-light);
  color: var(--text-primary);
}

.table-modern tbody tr {
  transition: background var(--transition-fast);
}

.table-modern tbody tr:hover {
  background: var(--surface-hover);
}

.table-modern tbody tr:last-child td {
  border-bottom: none;
}

/* ── Stat Cards ─────────────────────────────────────────────── */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  transition: all var(--transition-base);
}

.stat-card:hover {
  box-shadow: var(--shadow-md);
}

.stat-card .stat-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  background: var(--accent-light);
  color: var(--accent);
}

.stat-card .stat-value {
  font-size: var(--text-3xl);
  font-weight: var(--font-bold);
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.stat-card .stat-label {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.stat-card .stat-change {
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
}

.stat-card .stat-change.positive { color: var(--success); }
.stat-card .stat-change.negative { color: var(--danger); }

/* Bouton « Gérer » ancré en haut à droite de la carte stat (#118) */
.stat-card.has-action { position: relative; }
.stat-card .stat-card-action {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  margin: 0;
}

/* ── Navigation — Topbar ────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border-light);
  height: 52px;
  display: flex;
  align-items: center;
}

.topbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.topbar-brand {
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  letter-spacing: -0.02em;
  text-decoration: none;
}

.topbar-nav {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  list-style: none;
}

.topbar-nav a {
  padding: var(--space-2) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--font-regular);
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-full);
  transition: all var(--transition-fast);
}

.topbar-nav a:hover,
.topbar-nav a.active {
  color: var(--text-primary);
  background: var(--bg-secondary);
}

/* ── Navigation — Sidebar ───────────────────────────────────── */
.layout-sidebar {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-light);
  padding: var(--space-6) var(--space-4);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
}

.sidebar-brand {
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-8);
  font-size: var(--text-lg);
  font-weight: var(--font-semibold);
  color: var(--text-primary);
  letter-spacing: -0.02em;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.sidebar-section {
  margin-bottom: var(--space-6);
}

.sidebar-section-title {
  font-size: var(--text-xs);
  font-weight: var(--font-semibold);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-1);
}

.sidebar-nav {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--font-regular);
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.sidebar-nav a:hover {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-primary);
}

.sidebar-nav a.active {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-weight: var(--font-medium);
  box-shadow: var(--shadow-xs);
}

/* L'icône finale ET son placeholder lucide (<i data-lucide>) réservent la même
   boîte : sans dimension sur le placeholder, le label se décalait de 18px quand
   lucide.createIcons() remplaçait le <i> par le <svg> (flash/décalage au chargement). */
.sidebar-nav a svg,
.sidebar-nav a i[data-lucide] {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: var(--space-6);
  border-top: 1px solid var(--border-light);
}

/* ── Personnalisation de la barre (#229) + repli au clic sur le nom (#254) ── */
/* L'en-tête de section EST le bouton de repli : tout le nom est cliquable.
   Sélecteur scopé sur `button` pour ne pas affecter les titres décoratifs
   (Portal, grille des rôles) qui restent de simples <div class="sidebar-section-title">. */
button.sidebar-section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  /* La règle de base .sidebar-section-title impose déjà font-size/weight/color/
     transform/letter-spacing ; on ne touche QUE la font-family et la line-height
     (un <button> hérite sinon de la police/hauteur système de l'UA, ce qui
     désalignerait le titre). On NE redéclare PAS font-size/weight pour laisser
     la règle de base gagner. */
  font-family: inherit;
  line-height: inherit;
  transition: color var(--transition-fast);
}
button.sidebar-section-title:hover { color: var(--text-secondary); }
button.sidebar-section-title:focus-visible {
  outline: 2px solid var(--brand-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
/* Chevron vertical : toujours visible, pivote selon l'état (replié = pointe à droite). */
.sidebar-section-chevron {
  display: inline-flex;
  flex-shrink: 0;
  color: var(--text-tertiary);
  transition: transform var(--transition-base);
}
.sidebar-section-chevron svg { width: 14px; height: 14px; }
.sidebar-section.is-collapsed .sidebar-section-chevron { transform: rotate(-90deg); }
/* Section repliée : on masque la liste en douceur (max-height + opacity) tout en
   gardant le titre. max-height généreux : la nav d'une section ne l'atteint jamais. */
.sidebar-section .sidebar-nav {
  overflow: hidden;
  max-height: 1000px;
  opacity: 1;
  transition: max-height var(--transition-base), opacity var(--transition-base);
}
.sidebar-section.is-collapsed .sidebar-nav {
  max-height: 0;
  opacity: 0;
}

/* Barre de boutons de personnalisation. */
.sidebar-customize-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.sidebar-customize {
  flex: 1;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--font-medium);
  color: var(--text-tertiary);
  background: none;
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}
.sidebar-customize:hover { color: var(--text-primary); border-color: var(--border-default, var(--border-light)); }
.sidebar-customize[aria-pressed="true"] {
  color: var(--brand-primary);
  border-color: var(--brand-primary);
  border-style: solid;
}
.sidebar-customize svg { width: 14px; height: 14px; flex-shrink: 0; }
/* Le bouton « Réinitialiser » n'apparaît qu'en mode édition. */
.sidebar-customize-reset {
  display: none;
  padding: var(--space-2);
  font-size: var(--text-xs);
  color: var(--text-tertiary);
  background: none;
  border: 1px dashed var(--border-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.sidebar-customize-reset:hover { color: var(--text-primary); }
body.sidebar-editing .sidebar-customize-reset { display: inline-flex; }

/* Entrée de navigation en mode édition : poignée + bouton épingle. */
.sidebar-nav-item { position: relative; }
body.sidebar-editing .sidebar-nav-item { cursor: grab; }
body.sidebar-editing .sidebar-nav-item.dragging { opacity: 0.4; }
.sidebar-pin {
  display: none;
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 2px;
}
body.sidebar-editing .sidebar-pin { display: inline-flex; }
.sidebar-pin:hover { color: var(--text-primary); }
.sidebar-pin svg, .sidebar-pin i[data-lucide] { width: 14px; height: 14px; }
/* Entrée épinglée : la punaise reste visible (couleur de marque) même hors édition. */
.sidebar-nav-item.is-pinned > a::after {
  content: "";
  display: inline-block;
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand-primary);
  flex-shrink: 0;
}
.sidebar-nav-item.is-pinned .sidebar-pin { color: var(--brand-primary); }
body.sidebar-editing .sidebar-nav-item.is-pinned > a::after { display: none; }

.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding: var(--space-8);
  min-height: 100vh;
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; }
}

/* ── Modal ──────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal-backdrop);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-base);
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  transform: scale(0.95) translateY(10px);
  transition: transform var(--transition-base);
}

.modal-backdrop.active .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-6) var(--space-6) 0;
}

.modal-header h3 {
  font-size: var(--text-lg);
}

.modal-body {
  padding: var(--space-6);
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: 0 var(--space-6) var(--space-6);
}

/* ── Toast / Notifications ──────────────────────────────────── */
/* Notifications discrètes, ancrées en haut au centre de l'écran. */
.toast-container {
  position: fixed;
  top: var(--space-6);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  pointer-events: none;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 260px;
  max-width: 420px;
  animation: toast-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
  font-size: var(--text-sm);
  pointer-events: auto;
}

.toast-label { flex: 1; }

/* Badge multiplicateur (×N) quand la même notification se répète. */
.toast-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-danger  { border-left: 3px solid var(--danger); }
.toast.toast-warning { border-left: 3px solid var(--warning); }
.toast.toast-info    { border-left: 3px solid var(--info); }

.toast-out {
  animation: toast-out 0.3s ease forwards;
}

/* ── Champ de recherche dynamique (combobox) ────────────────────
   Remplace le couple « textbox + <select> » : saisie filtrante + liste
   de résultats sous la barre. */
.search-select { position: relative; }
.search-select-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 50;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 4px;
}
.search-select-option {
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: var(--text-sm);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.search-select-option:hover { background: var(--surface-hover); }
.search-select-empty {
  padding: 10px;
  color: var(--text-tertiary);
  font-size: var(--text-sm);
  text-align: center;
}

/* ── Pagination ─────────────────────────────────────────────── */
.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: var(--space-4);
}
.pager-size { display: flex; align-items: center; gap: 10px; }
.pager-info { color: var(--text-tertiary); font-size: var(--text-sm); }
.pager-select {
  padding: 6px 28px 6px 10px;
  font-family: inherit;
  font-size: var(--text-sm);
  color: var(--text-primary);
  background: var(--bg-primary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2386868b' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 6l3.5 3.5L11.5 6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.pager-nav { display: flex; align-items: center; gap: 4px; }
.pager-btn {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text-primary);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.pager-btn:hover:not(:disabled):not(.active) { background: var(--surface-hover); }
.pager-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); cursor: default; }
.pager-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.pager-ellipsis { padding: 0 4px; color: var(--text-tertiary); }

/* ── En-têtes de colonnes triables ──────────────────────────── */
.table-modern th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.table-modern th.sortable:hover { color: var(--text-primary); }
.sort-ind {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
}

/* ── Bascule de vue (slider segmenté) ───────────────────────── */
.view-switch {
  position: relative;
  display: inline-flex;
  padding: 4px;
  background: var(--surface-active);
  border-radius: var(--radius-full);
  margin-bottom: var(--space-6);
}
.view-switch-btn {
  position: relative;
  z-index: 1;
  border: none;
  background: transparent;
  padding: 8px 18px;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--text-tertiary);
  cursor: pointer;
  border-radius: var(--radius-full);
  white-space: nowrap;
  transition: color 0.2s ease;
}
.view-switch-btn.active { color: var(--text-primary); }
.view-switch-thumb {
  position: absolute;
  top: 4px;
  bottom: 4px;
  left: 4px;
  width: 0;
  background: var(--surface);
  border-radius: var(--radius-full);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
  transition: left 0.25s ease, width 0.25s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-16px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(-16px); }
}

/* ── Empty States ───────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: var(--space-16) var(--space-6);
  color: var(--text-tertiary);
}

.empty-state svg {
  width: 48px;
  height: 48px;
  margin-bottom: var(--space-4);
  opacity: 0.4;
}

.empty-state h3 {
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
}

.empty-state p {
  margin-bottom: var(--space-6);
}

/* ── Loading ────────────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.skeleton {
  background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--border-light) 50%, var(--bg-secondary) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ── Avatars ────────────────────────────────────────────────── */
.avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--text-sm);
  font-weight: var(--font-semibold);
  color: var(--text-inverse);
  background: var(--accent);
  flex-shrink: 0;
}

.avatar-sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar-lg { width: 48px; height: 48px; font-size: var(--text-lg); }
.avatar-xl { width: 64px; height: 64px; font-size: var(--text-2xl); }

/* ── Dividers ───────────────────────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--border-light);
  margin: var(--space-6) 0;
}

/* ── Page Header ────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-8);
  flex-wrap: wrap;
  gap: var(--space-4);
}

.page-header h1 {
  font-size: var(--text-2xl);
}

.page-header p {
  font-size: var(--text-sm);
}

/* ── Tabs ───────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border-light);
  margin-bottom: var(--space-6);
}

.tab {
  padding: var(--space-3) var(--space-4);
  font-size: var(--text-sm);
  font-weight: var(--font-medium);
  color: var(--text-secondary);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-bottom: -1px;
}

.tab:hover {
  color: var(--text-primary);
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Pagination ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  margin-top: var(--space-8);
}

.pagination button {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-light);
  background: var(--surface);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pagination button:hover {
  background: var(--bg-secondary);
}

.pagination button.active {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}

/* ── Search ─────────────────────────────────────────────────── */
.search-bar {
  position: relative;
}

.search-bar svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-tertiary);
}

.search-bar .input {
  padding-left: 40px;
}

/* ── Login Page ─────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-secondary);
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-xl);
  padding: var(--space-10);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-light);
}

.login-card h1 {
  font-size: var(--text-2xl);
  text-align: center;
  margin-bottom: var(--space-2);
}

.login-card p {
  text-align: center;
  margin-bottom: var(--space-8);
}

.login-card .form-group {
  margin-bottom: var(--space-5);
}

.login-card .btn {
  width: 100%;
  margin-top: var(--space-4);
}

/* ── Utility ────────────────────────────────────────────────── */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-lg { font-size: var(--text-lg); }
.text-muted { color: var(--text-secondary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.font-medium { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold { font-weight: var(--font-bold); }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }
.ml-auto { margin-left: auto; }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }
.w-full { width: 100%; }
.hidden { display: none !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Animations ─────────────────────────────────────────────── */
.fade-in {
  animation: fadeIn 0.5s ease both;
}

.fade-in-up {
  animation: fadeInUp 0.6s cubic-bezier(0.25, 0.1, 0.25, 1) both;
}

.stagger-1 { animation-delay: 0.1s; }
.stagger-2 { animation-delay: 0.2s; }
.stagger-3 { animation-delay: 0.3s; }
.stagger-4 { animation-delay: 0.4s; }
.stagger-5 { animation-delay: 0.5s; }

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── Tab panels (contenu d'onglet, masqué sauf actif) ───────── */
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeInUp var(--transition-base); }

/* ── Toggle switch (interrupteur on/off) ────────────────────── */
.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; inset: 0; cursor: pointer; border-radius: 9999px;
  background: var(--border); transition: background var(--transition-fast);
}
.switch .slider::before {
  content: ""; position: absolute; height: 20px; width: 20px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:disabled + .slider { opacity: 0.55; cursor: not-allowed; }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Liste de modules (grille d'activation) ─────────────────── */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: var(--space-3); }
.module-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-4); border: 1px solid var(--border-light);
  border-radius: var(--radius-lg); background: var(--surface);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.module-row.is-on { border-color: color-mix(in srgb, var(--accent) 35%, var(--border-light)); }
.module-row .module-ico {
  width: 40px; height: 40px; flex-shrink: 0; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-subtle, var(--bg-tertiary)); color: var(--text-secondary);
}
.module-row .module-ico svg { width: 20px; height: 20px; }
.module-row.is-on .module-ico { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.module-row .module-meta { flex: 1; min-width: 0; }
.module-row .module-name { font-weight: var(--font-semibold); font-size: var(--text-sm); display: flex; align-items: center; gap: 6px; }
.module-row .module-desc { color: var(--text-tertiary); font-size: var(--text-xs); margin-top: 2px; line-height: 1.4; }

/* ── Radios personnalisés (cartes sélectionnables) ──────────── */
.radio-group { display: flex; gap: var(--space-3); flex-wrap: wrap; }
.radio-card {
  position: relative;
  display: inline-flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px; min-width: 220px;
  border: 1.5px solid var(--border-light); border-radius: var(--radius-lg);
  background: var(--surface); cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast);
}
.radio-card:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border-light)); }
.radio-card input { position: absolute; opacity: 0; width: 0; height: 0; }
.radio-card .radio-dot {
  flex-shrink: 0; width: 18px; height: 18px; margin-top: 1px;
  border-radius: 50%; border: 2px solid var(--text-tertiary);
  position: relative; transition: border-color var(--transition-fast);
}
.radio-card .radio-dot::after {
  content: ''; position: absolute; inset: 0; margin: auto;
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  transform: scale(0); transition: transform var(--transition-fast);
}
.radio-card .radio-label { font-size: var(--text-sm); font-weight: var(--font-medium, 500); color: var(--text-primary); line-height: 1.3; }
.radio-card .radio-sub { display: block; margin-top: 2px; font-size: var(--text-xs); font-weight: 400; color: var(--text-tertiary); }
.radio-card:has(input:checked) { border-color: var(--accent); background: var(--accent-light); }
.radio-card:has(input:checked) .radio-dot { border-color: var(--accent); }
.radio-card:has(input:checked) .radio-dot::after { transform: scale(1); }
.radio-card:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Accessibilité : focus clavier visible (#182) ───────────────
   Les contrôles interactifs (boutons, champs, liens de nav, onglets,
   pagination) n'avaient aucun indicateur de focus au clavier : un
   utilisateur naviguant au Tab ne voyait pas où il se trouvait.
   `:focus-visible` ne se déclenche QUE pour le focus clavier (pas au
   clic souris) — aucune régression visuelle pour l'usage à la souris.
   On réutilise les tokens existants (--accent, --shadow-focus) : ces
   variables sont redéfinies en thème sombre, l'anneau reste donc
   lisible en light comme en dark. */
.btn:focus-visible,
.pager-btn:focus-visible,
.pagination button:focus-visible,
.view-switch-btn:focus-visible,
.tab:focus-visible,
.checkbox-group input[type="checkbox"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Champs de saisie : on s'aligne sur l'état :focus déjà défini
   (anneau diffus --shadow-focus) pour rester cohérent. */
.input:focus-visible,
.textarea:focus-visible,
.select:focus-visible,
.pager-select:focus-visible {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-focus);
  outline: none;
}

/* Liens de navigation (sidebar / topbar) et liens texte : anneau
   compact, légèrement décalé pour ne pas être rogné par le radius. */
.sidebar-nav a:focus-visible,
.topbar-nav a:focus-visible,
.topbar-brand:focus-visible,
.sidebar-brand:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* On retire l'anneau par défaut du navigateur uniquement quand le
   focus n'est PAS clavier, pour éviter le double-contour disgracieux
   au clic, sans jamais masquer l'accessibilité clavier. */
.btn:focus:not(:focus-visible),
.tab:focus:not(:focus-visible),
.pager-btn:focus:not(:focus-visible),
.pagination button:focus:not(:focus-visible),
.view-switch-btn:focus:not(:focus-visible) {
  outline: none;
}

/* ── Print ──────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .btn, .no-print { display: none !important; }
  .main-content { margin-left: 0; padding: 0; }
  body { background: white; color: black; }
}
