/* ============================================================================
   CATHEDIS ERP — Styles principaux
   ============================================================================
   Branding CATHEDIS : rouge affiné #f5273a -> #d81124 (restyling 2026)
   Police : Segoe UI (native Windows) — pas de Google Fonts (app offline)
   Layout : sidebar fixe + zone de contenu dynamique
   ============================================================================ */

/* ── Variables ──
   Restyling 2026 : langage plus doux, aéré et arrondi (inspiration
   TastyIgniter) tout en gardant le ROUGE CATHEDIS (affiné) et la densité
   d'un vrai ERP. Mêmes noms de variables qu'avant → les styles inline des
   pages restent valides ; seules les VALEURS changent. */
:root {
  /* Rouge CATHEDIS affiné (un peu plus vif et net que l'ancien #c0000d) */
  --primary: #d81124;
  --primary-dark: #a80d1a;
  --primary-light: #f5273a;
  --primary-bg: #fdeced;
  --primary-border: #f6bcc1;

  /* Rouge grisé (sourd) : modèle UNIQUE des titres de section de la sidebar */
  --sec-red: #9b535d;
  --sec-red-soft: #f1e7e9;
  --sidebar-bg: #fbeef1;   /* fond de sidebar rougeâtre (au lieu de blanc) */

  /* Neutres : canvas plus clair/aéré, bordures « fil de cheveu » */
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-alt: #f7f9fc;
  --border: #eceff4;
  --border-dark: #d4dae3;

  --text: #161b22;
  --text-secondary: #5a6473;
  --text-muted: #98a2b3;

  --success: #0f9d6a;
  --success-bg: #e4f6ee;
  --warning: #b9770a;
  --warning-bg: #fbf0da;
  --danger: #d64545;
  --danger-bg: #fdecec;
  --info: #2f6bd6;
  --info-bg: #e7effc;

  /* ── Palette GRAPHIQUES CATHEDIS ──────────────────────────────────────────
     Catégorielle, ancrée sur le rouge marque + tokens ERP (fini les couleurs
     bariolées type orange/indigo/rose/lime). RÈGLE : tout graphique de l'ERP
     utilise ces variables (ou window.CHART_COLORS côté JS). Ordre = priorité
     visuelle : la 1re série tombe sur le rouge marque. */
  --chart-1: #d81124;   /* rouge marque */
  --chart-2: #2f6bd6;   /* bleu info */
  --chart-3: #0f9d6a;   /* vert succès */
  --chart-4: #b9770a;   /* ambre */
  --chart-5: #9b535d;   /* rouge grisé (sec-red) */
  --chart-6: #7a5cc0;   /* violet sourd */
  --chart-positive: #0f9d6a;   /* montant positif / marge */
  --chart-negative: #d64545;   /* déficit / négatif */
  --chart-axis: #98a2b3;       /* axes + libellés muets */
  --chart-grid: #eceff4;       /* lignes de grille */

  /* Coins plus arrondis + ombres douces et diffuses (valeurs du showcase) */
  --radius: 18px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --shadow: 0 1px 2px rgba(20,26,34,.04), 0 10px 26px -12px rgba(20,26,34,.14);
  --shadow-md: 0 2px 4px rgba(20,26,34,.05), 0 12px 28px -12px rgba(20,26,34,.16);
  --shadow-lg: 0 24px 60px -20px rgba(20,26,34,.30);

  /* Liquid glass (clair) — verre dépoli translucide : sidebar ouverte + onglets.
     Plus transparent + flou fort pour bien laisser voir le contenu flouté dessous. */
  --glass-bg: rgba(255,255,255,.38);
  --glass-bg-strong: rgba(255,255,255,.44);
  --glass-blur: saturate(185%) blur(40px);
  --glass-border: rgba(255,255,255,.55);
  --glass-hi: rgba(255,255,255,.85);      /* liseré de rehaut en haut */
  --glass-shadow: 0 18px 50px -18px rgba(20,26,34,.28);

  --sidebar-width: 240px;
  --header-height: 56px;

  --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Consolas', 'Courier New', monospace;
}

/* Alignement propre de tous les chiffres, sans imposer la police mono */
body { font-variant-numeric: tabular-nums; }

/* Navigateur : neutralise le geste « balayage = page précédente » (tactile /
   2 doigts sur pavé) et le pull-to-refresh partout dans l'ERP — un swipe au
   bord d'un canvas (organigramme, grilles) ne doit JAMAIS quitter la page. */
html, body { overscroll-behavior: none; }

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

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  /* Léger halo rouge en haut à droite (showcase) — visible aussi dans les
     iframes d'onglets puisque chaque page a son propre body. */
  background: radial-gradient(680px 320px at 100% -6%, rgba(216,17,36,.055), transparent 60%) no-repeat, var(--bg);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

/* ── App Layout ── */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  /* 3 rangees : header / barre d'onglets (auto, 0 si masquee) / contenu */
  grid-template-rows: var(--header-height) auto minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

/* ── Header (barre titre) ── */
.app-header {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, var(--primary-light) 0%, var(--primary) 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  -webkit-app-region: drag; /* permet de deplacer la fenetre */
  user-select: none;
  z-index: 100;
}

.app-header-logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header-logo img {
  height: 32px;
}

.app-header-logo h1 {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
}

.app-header-logo .subtitle {
  font-size: 11px;
  opacity: 0.8;
  font-weight: 400;
  letter-spacing: 0.5px;
}

/* Badge « mes tâches » dans l'en-tête (clic → onglet Projets & Tâches) */
.header-taches-badge {
  -webkit-app-region: no-drag;
  margin-left: 18px;
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.16);
  border: 1px solid rgba(255,255,255,0.28);
  color: #fff; font-family: var(--font); font-size: 12px; font-weight: 600;
  padding: 5px 12px 5px 10px; border-radius: 999px; cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}
.header-taches-badge:hover { background: rgba(255,255,255,0.28); }
.header-taches-badge:active { transform: scale(.97); }
.header-taches-badge .htb-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px;
  background: #fff; color: var(--primary); font-size: 12px; font-weight: 800;
}
.header-taches-badge.is-zero .htb-count { background: rgba(255,255,255,0.35); color: #fff; }
.header-taches-badge .htb-label { opacity: .95; }

.app-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  -webkit-app-region: no-drag;
}

.header-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: white;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.2s;
  font-family: var(--font);
}

.header-btn:hover {
  background: rgba(255,255,255,0.25);
}

/* ── Menu deroulant d'en-tete (Parametres) ── */
.header-dropdown {
  position: relative;
  display: inline-block;
}
.header-dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 210px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  z-index: 1000;
}
.header-dropdown.open .header-dropdown-menu {
  display: block;
}
.header-dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  white-space: nowrap;
}
.header-dropdown-item:hover {
  background: var(--surface-alt);
  color: var(--primary);
}

/* ── Horaires de prière (widget en-tête) ── */
#btn-prayer { white-space: nowrap; }
#btn-prayer.prayer-now {
  background: rgba(255,255,255,0.92);
  color: var(--primary);
  font-weight: 700;
  animation: prayer-pulse 1.6s ease-in-out infinite;
}
@keyframes prayer-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.55); }
  50%      { box-shadow: 0 0 0 6px rgba(255,255,255,0); }
}
.prayer-menu { min-width: 240px; }
.prayer-menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  margin-bottom: 6px;
}
.prayer-menu-head select {
  font-family: var(--font);
  font-size: 12px;
  padding: 3px 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
}
.prayer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
}
.prayer-row small { color: var(--text-soft, #98a2b3); font-size: 11px; }
.prayer-row b { font-variant-numeric: tabular-nums; }
.prayer-row.next {
  background: var(--surface-alt);
  color: var(--primary);
  font-weight: 700;
}
.prayer-menu-foot {
  margin-top: 6px;
  padding: 8px 10px 4px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-soft, #98a2b3);
}

/* ── Sidebar ── */
.app-sidebar {
  grid-column: 1;
  grid-row: 2 / 4; /* longe la barre d'onglets ET le contenu */
  background: var(--sidebar-bg);
  border-right: 1px solid #f0dfe3;
  overflow-y: auto;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
}

/* Citation CATHEDIS, collee en bas a gauche de la sidebar (memes "quotes" que le login) */
.sidebar-quote {
  position: sticky;
  bottom: 0;
  margin-top: auto;
  padding: 12px 18px 14px;
  background: linear-gradient(180deg, rgba(251,238,241,0), var(--sidebar-bg) 32%);
  border-top: 1px solid #f0dfe3;
  display: flex;
  gap: 7px;
  align-items: flex-start;
  min-height: 44px;
}
.sidebar-quote-mark {
  font-size: 22px;
  line-height: 0.9;
  color: var(--primary);
  font-weight: 800;
  flex: 0 0 auto;
}
.sidebar-quote-text {
  font-style: italic;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted);
  transition: opacity 0.45s ease;
}
.sidebar-quote-text.fading { opacity: 0; }

.sidebar-section {
  margin-bottom: 8px;
}

.sidebar-section-title {
  font-family: var(--font-mono);   /* écriture « terminal » comme les libellés de login.html */
  font-size: 11px;
  font-weight: 600;
  color: var(--sec-red);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 8px 16px 6px;
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;      /* pas de retour à la ligne pendant l'animation du rail */
  overflow: hidden;
  cursor: pointer;          /* titre = bouton replier/deplier */
  user-select: none;
}

/* Idem pour toutes les lignes de nav (y compris les sous-titres texte) :
   rognées pendant l'expansion du rail au lieu de wrapper (tressautement). */
.sidebar-nav li { white-space: nowrap; overflow: hidden; }
.sidebar-section-title:hover {
  opacity: 0.8;
}

/* Chevron a droite du titre : pointe vers le bas (deplie), vers la droite (replie) */
.sidebar-section-title::after {
  content: "";
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  opacity: 0.7;
  flex: 0 0 auto;
}
.sidebar-section.collapsed .sidebar-section-title::after {
  transform: rotate(-45deg);
}

/* ── Animation d'ouverture / fermeture des sections ──
   Le <ul.sidebar-nav> est enveloppe dans .sidebar-nav-wrap par
   js/sidebar-collapse.js. On anime la hauteur via grid-template-rows
   1fr -> 0fr (permet d'animer jusqu'a la hauteur naturelle, ce que
   height:auto ne permet pas), avec un fondu du contenu. */
.sidebar-nav-wrap {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-section.collapsed .sidebar-nav-wrap {
  grid-template-rows: 0fr;
}
.sidebar-nav-wrap > .sidebar-nav {
  overflow: hidden;
  min-height: 0;
  visibility: visible;
  transition: opacity 0.22s ease, visibility 0s;
}
.sidebar-section.collapsed .sidebar-nav-wrap > .sidebar-nav {
  opacity: 0;
  /* sort les liens repliés de l'ordre de tabulation (focus clavier) */
  visibility: hidden;
  transition: opacity 0.22s ease, visibility 0s 0.3s;
}
/* Premier rendu : pas d'animation (sinon repli visible au demarrage) */
.sidebar-no-anim .sidebar-nav-wrap,
.sidebar-no-anim .sidebar-nav-wrap > .sidebar-nav {
  transition: none !important;
}

/* ── Modèle UNIQUE des titres de section (mono rouge grisé) ──
   Plus aucune couleur par section : toutes identiques. L'icône vit dans une
   petite puce arrondie ; c'est le seul repère visuel (repère fonctionnel). */
.sidebar-section-title .sec-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--sec-red);
  flex: 0 0 auto;
  transition: width .28s cubic-bezier(.4,0,.2,1),
              height .28s cubic-bezier(.4,0,.2,1),
              background .15s, color .15s;
}
.sidebar-section-title .sec-icon svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: width .28s cubic-bezier(.4,0,.2,1),
              height .28s cubic-bezier(.4,0,.2,1);
}
/* Section courante : pastille pleine autour de l'icône (repère « vous êtes ici ») */
.sidebar-section:has(.sidebar-nav a.active) .sec-icon {
  background: var(--sec-red);
  color: #fff;
}

.sidebar-nav {
  list-style: none;
}

/* En-tête de sous-groupe FORT à l'intérieur d'une section (ex. RH → Paie
   Freelance / Paie CDI / Paie Intérim). Style « terminal » accentué pour se
   distinguer des libellés muets internes. */
.sidebar-nav li.nav-group-strong {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--sec-red);
  padding: 11px 16px 5px;
  margin-top: 4px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 7px;
}
.sidebar-nav li.nav-group-strong:first-child {
  border-top: none;
  margin-top: 0;
}
.sidebar-nav li.nav-group-strong .g-ico {
  font-size: 13px;
  line-height: 1;
}

/* ── Sous-groupes RH repliables (accordeon niveau 2) ──
   js/sidebar-subgroups.js transforme chaque <li.nav-group-strong> en titre
   cliquable et enveloppe ses entrees dans un <li.nav-subgroup-wrap> anime
   (grid-template-rows 1fr <-> 0fr, comme les sections). Repli par defaut. */
.sidebar-nav li.nav-group-strong.is-toggle {
  cursor: pointer;
  user-select: none;
}
.sidebar-nav li.nav-group-strong.is-toggle:hover { opacity: 0.8; }
/* Chevron a droite : bas = deplie, droite = replie (identique aux sections) */
.sidebar-nav li.nav-group-strong.is-toggle::after {
  content: "";
  margin-left: auto;
  width: 6px;
  height: 6px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
  opacity: 0.7;
  flex: 0 0 auto;
}
.sidebar-nav li.nav-group-strong.is-toggle.collapsed::after {
  transform: rotate(-45deg);
}
/* Conteneur anime des entrees d'un sous-groupe */
.sidebar-nav li.nav-subgroup-wrap {
  display: grid;
  grid-template-rows: 1fr;
  transition: grid-template-rows 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 0;
  margin: 0;
}
.sidebar-nav li.nav-group-strong.collapsed + li.nav-subgroup-wrap {
  grid-template-rows: 0fr;
}
.sidebar-nav li.nav-subgroup-wrap > ul.nav-subgroup {
  overflow: hidden;
  min-height: 0;
  list-style: none;
  margin: 0;
  padding: 0;
  transition: opacity 0.2s ease, visibility 0s;
}
.sidebar-nav li.nav-group-strong.collapsed + li.nav-subgroup-wrap > ul.nav-subgroup {
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0s 0.28s;
}
/* Premier rendu : pas d'animation du repli initial des sous-groupes */
.sidebar-no-anim .nav-subgroup-wrap,
.sidebar-no-anim .nav-subgroup-wrap > .nav-subgroup {
  transition: none !important;
}

.sidebar-nav li a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  margin: 1px 10px;
  border-radius: 999px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  transition: background 0.15s, color 0.15s;
  cursor: pointer;
}

/* Sous-items indentés (ex-style inline padding-left:32px) */
.sidebar-nav li a.nav-sub { padding-left: 32px; }

.sidebar-nav li a:hover {
  background: rgba(155,83,93,.10);
  color: var(--text);
}

/* Onglet actif : pill pleine rouge CATHEDIS, texte blanc (réf. Dribbble) */
.sidebar-nav li a.active {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  color: #fff;
  font-weight: 600;
  box-shadow: 0 6px 14px -6px rgba(216,17,36,.5);
}
.sidebar-nav li a.active .nav-badge {
  background: rgba(255,255,255,.22);
  color: #fff;
}

.sidebar-nav li a .nav-icon {
  display: none;   /* icônes UNIQUEMENT sur les grands titres (sections) */
}

.sidebar-nav li a .nav-badge {
  margin-left: auto;
  background: var(--primary-bg);
  color: var(--primary);
  font-size: 11px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
}

/* ── Content Area ── */
/* ── Barre d'onglets de travail (facon Delivery Tracker) — js/tabs.js ── */
.tab-bar {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding: 6px 10px 0;
  /* Liquid glass : verre dépoli translucide (comme la sidebar ouverte) */
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 var(--glass-hi);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  white-space: nowrap;
  user-select: none;
}
.tab-bar:empty { display: none; } /* pas d'onglet -> la rangee se replie */

.tab-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 8px 8px 12px;
  max-width: 220px;
  font-size: 13px;
  color: var(--text-muted);
  border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  flex: 0 0 auto;
}
.tab-item:hover { background: var(--bg); color: var(--text); }
.tab-item.active {
  color: var(--primary);
  font-weight: 600;
  background: var(--primary-bg);
  border-bottom-color: var(--primary);
}
.tab-icon { font-size: 13px; line-height: 1; }
.tab-label { overflow: hidden; text-overflow: ellipsis; }
.tab-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 17px;
  height: 17px;
  margin-left: 2px;
  border-radius: 50%;
  font-size: 14px;
  line-height: 1;
  color: inherit;
  opacity: 0.55;
}
.tab-close:hover { opacity: 1; background: var(--primary-bg); color: var(--primary); }

/* Onglet "dormant" : ouvert dans la barre mais frame non chargee (restauration
   de session ou dechargement LRU) — rechargera au clic */
.tab-item.dormant { opacity: 0.62; }

@media print { .tab-bar { display: none; } }

.app-content {
  grid-column: 2;
  grid-row: 3;
  overflow-y: auto;
  padding: 24px;
  background: radial-gradient(680px 320px at 100% -6%, rgba(216,17,36,.055), transparent 60%) no-repeat, var(--bg);
}

/* ── Onglets vivants : conteneur des frames (index.html) ──
   Chaque page vit dans sa propre iframe tab-host.html, empilees ici ; seule
   l'active est visible. visibility (et non display) : la mise en page des
   frames cachees reste calculee, les grilles AG Grid ne se recalent pas a
   chaque bascule et les traitements en cours continuent. */
.app-content.tab-frames {
  position: relative;
  padding: 0;
  overflow: hidden;
}
.tab-frame {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
  visibility: hidden;
}
.tab-frame.active { visibility: visible; }
/* Frame en arriere-plan mais tenue « rendue » (gros job client type html2canvas) :
   visible pour que le navigateur continue son rendu/rAF, mais poussee hors-ecran
   pour ne pas recouvrir l'onglet actif. Meme origine -> pas de throttling rAF. */
.tab-frame.render-hold { visibility: visible; transform: translateX(-200vw); }
.tab-frame.render-hold.active { transform: none; }

/* ── Page Header ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.page-title {
  font-size: 25px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text);
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
}

.card-body {
  padding: 20px;
}

.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-alt);
  border-radius: 0 0 var(--radius) var(--radius);
}

/* ── Stat Cards (dashboard) ── */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.stat-card .stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  font-size: 19px;
  background: var(--primary-bg);
  color: var(--primary);
  margin-bottom: 14px;
}

.stat-card .stat-value {
  font-size: 27px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.stat-card .stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: 999px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  line-height: 1.4;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary-light), var(--primary));
  color: white;
  box-shadow: 0 6px 16px -8px rgba(216,17,36,.55);
}
.btn-primary:hover { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-dark);
}
.btn-secondary:hover { background: var(--surface-alt); border-color: var(--primary-border); }

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover { filter: brightness(0.9); }

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { filter: brightness(0.9); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 6px 10px;
}
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Forms ── */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

.form-input::placeholder {
  color: var(--text-muted);
}

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

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-row-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
}

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form-error {
  font-size: 11px;
  color: var(--danger);
  margin-top: 4px;
}

/* ── Tables ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table thead {
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}

.data-table th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

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

.data-table tbody tr.selected {
  background: var(--primary-bg);
}

/* --- Tri par colonne --- */
.data-table th.th-sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 22px;
}
.data-table th.th-sortable::after {
  content: '\2195'; /* ⇕ */
  position: absolute;
  right: 7px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.28;
  font-size: 10px;
}
.data-table th.th-sortable:hover::after { opacity: 0.55; }
.data-table th.th-sortable.sorted-asc::after { content: '\25B2'; opacity: 0.95; } /* ▲ */
.data-table th.th-sortable.sorted-desc::after { content: '\25BC'; opacity: 0.95; } /* ▼ */

/* --- Recherche par colonne --- */
.data-table thead tr.filter-row th {
  padding: 4px 6px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.data-table thead tr.filter-row input.col-filter {
  width: 100%;
  box-sizing: border-box;
  padding: 4px 7px;
  font-size: 11px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}
.data-table thead tr.filter-row input.col-filter:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-bg);
}

.data-table .cell-mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.data-table .cell-amount {
  font-family: var(--font-mono);
  font-weight: 600;
  text-align: right;
}

.data-table .cell-actions {
  text-align: right;
  white-space: nowrap;
}

/* ── AG Grid (surcouche des tableaux .data-table) ──
   Theme Quartz reskinne aux couleurs CATHEDIS + police Segoe UI. */
.ag-erp-grid {
  --ag-font-family: var(--font);
  --ag-font-size: 13px;
  --ag-foreground-color: var(--text);
  --ag-border-color: var(--border);
  --ag-header-background-color: var(--surface-alt);
  --ag-header-foreground-color: var(--text-muted);
  --ag-header-column-resize-handle-color: var(--border-dark);
  --ag-odd-row-background-color: #ffffff;
  --ag-row-hover-color: var(--surface-alt);
  --ag-selected-row-background-color: var(--primary-bg);
  --ag-active-color: var(--primary-light);
  --ag-range-selection-border-color: var(--primary-light);
  --ag-input-focus-border-color: var(--primary-light);
  --ag-cell-horizontal-padding: 14px;
  --ag-borders: solid 1px;
  --ag-wrapper-border-radius: var(--radius);
  /* Un peu plus d'air dans les lignes + séparateurs un poil plus visibles
     que la bordure générale (les grilles gardent des milliers de lignes
     lisibles malgré le canvas plus clair). */
  --ag-row-height: 44px;
  --ag-header-height: 44px;
  --ag-row-border-color: #e8ebf1;
  width: 100%;
}
.ag-erp-grid .ag-header-cell-text {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.ag-erp-grid .ag-erp-center { text-align: center; }
.ag-erp-grid .ag-erp-actions { text-align: right; }
/* Boutons / badges conserves dans les cellules : compacts pour tenir dans 40px */
.ag-erp-grid .ag-cell .btn { padding: 3px 8px; font-size: 12px; vertical-align: middle; }
.ag-erp-grid .ag-cell .badge,
.ag-erp-grid .ag-cell .pill { vertical-align: middle; }

/* ── Toolbar (au dessus des tables) ── */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.toolbar-search {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 400px;
}

.toolbar-search input {
  width: 100%;
  padding: 8px 14px 8px 36px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-size: 13px;
  font-family: var(--font);
}

.toolbar-search input:focus {
  outline: none;
  border-color: var(--primary-border);
  box-shadow: 0 0 0 3px var(--primary-bg);
}

.toolbar-search::before {
  content: '\1F50D';
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
}

.toolbar-right {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

/* ── Badges / Tags ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
}
/* Puce colorée devant le libellé (showcase) */
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger);  }
.badge-info    { background: var(--info-bg);    color: var(--info);    }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

/* Modales pilotees par le style inline `display:flex` (achats, echeancier,
   creances, paie freelance...) : les rendre visibles des qu'elles passent en
   display:flex, sans dependre de la classe .open. Sans ceci, le `opacity:0;
   visibility:hidden` de .modal-overlay les laisse invisibles meme ouvertes. */
.modal-overlay[style*="display: flex"],
.modal-overlay[style*="display:flex"] {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(20px);
  transition: transform 0.2s;
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--danger); }

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: var(--surface-alt);
}

/* ── Toast notifications ── */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toast-in 0.3s ease;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 280px;
}

.toast-success { background: var(--success); color: white; }
.toast-error   { background: var(--danger);  color: white; }
.toast-warning { background: var(--warning); color: white; }
.toast-info    { background: var(--info);    color: white; }

@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
}

.empty-state h3 {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 13px;
  margin-bottom: 16px;
}

/* ── Tabs (dans les pages) ── */
.tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}

.tab-btn {
  padding: 10px 20px;
  border: none;
  background: none;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}

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

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

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Utilities ── */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-mono   { font-family: var(--font-mono); }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.flex  { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }

/* ════════════════════════════════════════════════════════════════════
   SIDEBAR « RAIL » (desktop) — barre d'icônes 76px, expansion en
   OVERLAY au survol / focus clavier (réf. Dribbble Web Sidebar Menu).
   Scopé min-width:1121px UNIQUEMENT (en-dessous : tiroir mobile de mobile.css).
   ⚠️ AUCUNE condition de survol dans la media query : ni hover:hover ni
   any-hover:hover. Raison (bug Maher 01/09/2026) : sur certains PC Windows
   TACTILES, Chrome rapporte hover:none ET any-hover:none MÊME avec une souris
   branchée → toute media query gatée sur le survol échouait et la sidebar
   restait bloquée à sa largeur de base (240px). Or la pseudo-classe :hover,
   elle, se déclenche au VRAI passage de la souris quelle que soit la valeur
   (fausse) rapportée par ces media-features → l'expansion au survol marche
   toujours. Le rail est donc activé par la LARGEUR seule (toujours vraie sur
   un écran ≥1121px) ; sur un pur tactile sans souris, un TAP déclenche :hover
   (survol collant) et ouvre le rail. Ne PAS remettre de gate hover ici.
   ════════════════════════════════════════════════════════════════════ */
@media (min-width: 1121px) {
  :root { --sidebar-width: 76px; }

  .app-sidebar {
    position: fixed;
    top: var(--header-height);
    bottom: 0;
    left: 0;
    width: var(--sidebar-width);
    z-index: 80;             /* < 100 : le menu Paramètres du header reste devant ;
                                modales (1000) et toasts (2000) le couvrent */
    overflow-x: hidden;
    /* ── REPLIÉ : fond identique au reste de l'app (canvas), juste les icônes.
       Pas de couleur de sidebar, pas de bordure visible ni d'ombre. ── */
    background: var(--bg);
    border-right: 1px solid transparent;
    box-shadow: none;
    /* léger délai au repli pour éviter le clignotement en traversée de souris */
    transition: width 0.2s ease 0.15s, box-shadow 0.28s ease 0.15s,
                background 0.28s ease 0.15s, border-color 0.28s ease 0.15s;
  }
  /* :has(:focus-visible) et non :focus-within : un clic souris laisse le focus
     dans la sidebar et la bloquerait ouverte ; seul le clavier la maintient. */
  /* ── OUVERT (survol / focus clavier) : panneau LIQUID GLASS qui floute le
     contenu derrière (verre dépoli translucide clair). ── */
  .app-sidebar:hover,
  .app-sidebar:has(:focus-visible) {
    width: 252px;
    background: var(--glass-bg-strong);
    -webkit-backdrop-filter: var(--glass-blur);
    backdrop-filter: var(--glass-blur);
    border-right: 1px solid var(--glass-border);
    box-shadow: inset 1px 0 0 var(--glass-hi), var(--glass-shadow);
    transition-delay: 0.08s;
  }
  /* La citation du bas ne doit pas poser un fond rose opaque sur le verre. */
  .app-sidebar:hover .sidebar-quote,
  .app-sidebar:has(:focus-visible) .sidebar-quote {
    background: transparent;
    border-top-color: rgba(155,83,93,.18);
  }

  /* ── État replié (ni survol ni focus) : SEULEMENT les puces des grands
     titres. Les listes d'items sont masquées et réapparaissent au survol. ── */
  .app-sidebar:not(:hover):not(:has(:focus-visible)) .sidebar-nav-wrap { display: none; }
  .app-sidebar:not(:hover):not(:has(:focus-visible)) .sidebar-quote { display: none; }
  .app-sidebar:not(:hover):not(:has(:focus-visible)) .sidebar-section-title {
    justify-content: center;
    gap: 0;
    padding: 9px 0;
    font-size: 0;            /* masque le texte ; la puce .sec-icon reste */
    letter-spacing: 0;
  }
  .app-sidebar:not(:hover):not(:has(:focus-visible)) .sidebar-section-title::after {
    display: none;           /* chevron d'accordéon masqué */
  }
  .app-sidebar:not(:hover):not(:has(:focus-visible)) .sidebar-section-title .sec-icon {
    width: 42px;
    height: 42px;
  }
  .app-sidebar:not(:hover):not(:has(:focus-visible)) .sidebar-section-title .sec-icon svg {
    width: 22px;
    height: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar { transition: none !important; }
}

/* Un élément fixed se répète sur chaque page imprimée : on masque, et la
   grille passe en colonne unique (sinon bande morte de 240px à gauche). */
@media print {
  .app-sidebar, .sidebar-backdrop { display: none; }
  .app-layout { grid-template-columns: 1fr; }
  .tab-bar, .app-content { grid-column: 1; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Animations d'entrée des graphes & valeurs (validé par Maher 06/08/2026,
   vitesse « normale » 0,9 s). Compteurs : moteur dans app.js (observateur
   .stat-value / [data-countup-auto]). Ici : barres qui poussent du néant.
   ⚠ JAMAIS dans les rendus DOCUMENTS (factures, états imprimables) :
   garde-fous @media print + [data-no-anim].
   ═══════════════════════════════════════════════════════════════════════════ */
@keyframes erp-hbar-grow  { from { width: 0; } }
@keyframes erp-vbar-grow  { from { transform: scaleY(0); } }
@keyframes erp-hbar-scale { from { transform: scaleX(0); } }
@keyframes erp-fadein     { from { opacity: 0; } }

/* Barres horizontales en div (top clients, listes du dashboard) */
.dash-top-bar { animation: erp-hbar-grow .55s cubic-bezier(.2,.7,.3,1) both; }
.dash-top-row:nth-child(2)  .dash-top-bar { animation-delay: .04s; }
.dash-top-row:nth-child(3)  .dash-top-bar { animation-delay: .08s; }
.dash-top-row:nth-child(4)  .dash-top-bar { animation-delay: .12s; }
.dash-top-row:nth-child(5)  .dash-top-bar { animation-delay: .16s; }
.dash-top-row:nth-child(6)  .dash-top-bar { animation-delay: .20s; }
.dash-top-row:nth-child(7)  .dash-top-bar { animation-delay: .24s; }
.dash-top-row:nth-child(8)  .dash-top-bar { animation-delay: .28s; }
.dash-top-row:nth-child(9)  .dash-top-bar { animation-delay: .32s; }
.dash-top-row:nth-child(10) .dash-top-bar { animation-delay: .36s; }

/* Barres SVG : verticales (.abar, origine bas), horizontales (.abar-h, origine
   gauche), valeur au-dessus (.abar-val, fondu après la pousse). Décalage en
   cascade optionnel via style="--d:0.12s" posé par le générateur. */
svg .abar   { transform-box: fill-box; transform-origin: bottom; animation: erp-vbar-grow  .55s cubic-bezier(.2,.7,.3,1) both; animation-delay: var(--d, 0s); }
svg .abar-h { transform-box: fill-box; transform-origin: left;   animation: erp-hbar-scale .55s cubic-bezier(.2,.7,.3,1) both; animation-delay: var(--d, 0s); }
svg .abar-val { animation: erp-fadein .35s ease both; animation-delay: calc(var(--d, 0s) + .3s); }

/* Garde-fous : impression, rendus marqués, et réglage système « réduire les animations » */
@media print {
  .dash-top-bar, svg .abar, svg .abar-h, svg .abar-val { animation: none !important; }
}
[data-no-anim] .dash-top-bar, [data-no-anim] svg .abar, [data-no-anim] svg .abar-h, [data-no-anim] svg .abar-val { animation: none !important; }
@media (prefers-reduced-motion: reduce) {
  .dash-top-bar, svg .abar, svg .abar-h, svg .abar-val { animation: none !important; }
}

/* Réglage ⚙ Paramètres (app.js pose data-anim + --anim-k sur <html>) :
   --anim-k = vitesse / 0,9 (1 = « normale ») ; data-anim="off" = tout coupé. */
.dash-top-bar, svg .abar, svg .abar-h { animation-duration: calc(.55s * var(--anim-k, 1)); }
svg .abar-val { animation-duration: calc(.35s * var(--anim-k, 1)); }
html[data-anim="off"] .dash-top-bar, html[data-anim="off"] svg .abar,
html[data-anim="off"] svg .abar-h, html[data-anim="off"] svg .abar-val { animation: none !important; }

/* Déclenchement au défilement (06/08/2026) : les barres restent EN PAUSE tant
   qu'elles ne sont pas entrées dans le champ de vision — l'IntersectionObserver
   d'app.js pose .anim-vu à l'apparition (le délai de cascade court à partir de
   là). Sans effet à l'impression (animation:none plus haut). */
.dash-top-bar, svg .abar, svg .abar-h, svg .abar-val { animation-play-state: paused; }
.dash-top-bar.anim-vu, svg .abar.anim-vu, svg .abar-h.anim-vu, svg .abar-val.anim-vu { animation-play-state: running; }

/* Bouton « Tout fermer » (barre d'onglets, tabs.js) : sticky au bord droit,
   reste visible pendant le défilement horizontal de la barre. */
.tab-close-all {
  position: sticky; right: 0; margin-left: auto; flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 0 12px; cursor: pointer; font-size: 12px; font-weight: 600;
  color: #5a6473; background: #f4f5f8;
  border-left: 1px solid #e3e7ee; box-shadow: -8px 0 8px -6px rgba(23,30,45,.12);
}
.tab-close-all:hover { color: #d81124; background: #faeef0; }
