:root {
  --teal: #0f766e; --teal-dark: #0b5c56; --teal-light: #e6f4f2;
  --vert: #16a34a; --vert-bg: #dcfce7;
  --or: #d97706; --or-bg: #fef3c7;
  --rouge: #dc2626; --rouge-bg: #fee2e2;
  --bleu: #2563eb; --bleu-bg: #dbeafe;
  --violet: #7c3aed; --violet-bg: #ede9fe;
  --gris: #64748b; --gris-bg: #f1f5f9;
  --bg: #f4f6f8; --card-bg: #fff; --border: #e2e8f0;
  --text: #1e293b; --text-muted: #64748b;
  --radius: 10px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--teal); text-decoration: none; }

.d-flex { display: flex; }
.align-center { align-items: center; }
.gap-8 { gap: 8px; }
.text-small { font-size: 12px; }
.text-muted { color: var(--text-muted); }

/* Layout (sans menu latéral — navigation via la page Accueil) : coquille à
   trois zones, rails gauche/droit colorés par le thème (mêmes variables que
   la page de connexion) encadrant une carte blanche centrale. */
.app-shell { display: flex; min-height: 100vh; background: linear-gradient(160deg, var(--teal-dark), var(--teal)); }
.brand-sub { font-weight: 400; opacity: .85; }
.user-avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--teal-light); color: var(--teal-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0; }
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }

/* Rails latéraux */
.app-rail { flex: 0 0 230px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 30px 20px; text-align: center; color: #fff; }
.app-rail-logo-img { max-height: 84px; max-width: 160px; object-fit: contain; filter: drop-shadow(0 6px 14px rgba(0,0,0,.25)); }
.app-rail-emoji { font-size: 52px; line-height: 1; }
.app-rail-brand { font-size: 22px; font-weight: 800; line-height: 1.2; }
.app-rail-tagline { font-size: 12.5px; opacity: .9; line-height: 1.4; max-width: 160px; }
.app-rail-version { font-size: 11px; opacity: .75; letter-spacing: .06em; text-transform: uppercase; margin-top: 6px; }
.app-rail-right { justify-content: flex-start; padding-top: 60px; }
.module-info-card { background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.28); border-radius: 14px; padding: 22px 18px; width: 100%; }
.module-info-icon { font-size: 34px; margin-bottom: 10px; }
.module-info-title { font-size: 15px; font-weight: 800; margin-bottom: 10px; }
.module-info-text { font-size: 12.5px; line-height: 1.55; opacity: .95; }

/* Centre : carte blanche contenant la barre du haut et le contenu */
.app-center { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 18px 20px 20px; }
.app-card { flex: 1; display: flex; flex-direction: column; min-height: 0; background: var(--card-bg); border-radius: 18px; box-shadow: 0 20px 50px rgba(0,0,0,.2); overflow: hidden; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 0 16px; background: transparent; }
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-logo { font-size: 15px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 6px; flex-shrink: 0; background: #fff; border-radius: 999px; padding: 10px 16px; box-shadow: 0 4px 14px rgba(0,0,0,.16); }
.topbar-logo-img { height: 24px; max-width: 110px; object-fit: contain; }
.topbar-title-pill { font-size: 13.5px; font-weight: 700; color: var(--text); background: #fff; border-radius: 999px; padding: 10px 16px; box-shadow: 0 4px 14px rgba(0,0,0,.16); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-content { padding: 20px 22px 40px; max-width: 1280px; width: 100%; margin: 0 auto; flex: 1; }

/* Menu utilisateur (déconnexion, profil, date/heure) — un seul contrôle
   compact plutôt que plusieurs éléments alignés séparément dans la barre du
   haut : plus lisible, toujours bien aligné quel que soit le nom affiché. */
.topbar-user-menu { position: relative; flex-shrink: 0; }
.user-menu-trigger {
  display: flex; align-items: center; gap: 8px; background: #fff; border: none;
  border-radius: 999px; padding: 4px 14px 4px 4px; cursor: pointer; font-family: inherit; color: var(--text);
  box-shadow: 0 4px 14px rgba(0,0,0,.16); transition: box-shadow .12s ease;
}
.user-menu-trigger:hover { box-shadow: 0 6px 18px rgba(0,0,0,.22); }
.user-menu-info { text-align: left; min-width: 0; max-width: 140px; }
.user-menu-info .user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-caret { font-size: 10px; color: var(--text-muted); transition: transform .15s ease; }
.topbar-user-menu.open .user-menu-caret { transform: rotate(180deg); }
.user-menu-dropdown {
  display: none; position: absolute; top: calc(100% + 8px); right: 0; min-width: 210px;
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0,0,0,.14); overflow: hidden; z-index: 50;
}
.user-menu-dropdown.show { display: block; }
.user-menu-date { padding: 10px 14px; font-size: 12px; color: var(--text-muted); border-bottom: 1px solid var(--border); }
.user-menu-item { display: flex; align-items: center; gap: 8px; padding: 10px 14px; font-size: 13.5px; color: var(--text); text-decoration: none; }
.user-menu-item:hover { background: var(--teal-light); }
.user-menu-item.user-menu-logout { color: var(--rouge); }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, var(--teal-dark), var(--teal)); padding: 20px; }
.login-shell { display: flex; align-items: center; justify-content: center; gap: 36px; width: 100%; max-width: 900px; }
.login-logo-side { flex: 0 0 auto; opacity: .95; }
.login-logo-side img { max-height: 90px; max-width: 160px; object-fit: contain; filter: drop-shadow(0 6px 14px rgba(0,0,0,.25)); }
.login-box { background: #fff; border-radius: 16px; padding: 36px 32px; width: 100%; max-width: 380px; box-shadow: 0 20px 50px rgba(0,0,0,.25); flex-shrink: 0; }
.login-brand { text-align: center; margin-bottom: 22px; }
.login-brand h1 { margin: 0 0 4px; color: var(--teal-dark); }
.login-brand-logo { max-height: 64px; max-width: 100%; object-fit: contain; margin-bottom: 6px; }
.login-brand p { margin: 0; font-weight: 600; color: var(--text); }
.login-brand small { color: var(--text-muted); }
@media (max-width: 760px) {
  .login-shell { flex-direction: column; gap: 16px; }
  .login-logo-side img { max-height: 56px; }
}

/* Alerts */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 14px; font-size: 14px; }
.alert-success { background: var(--vert-bg); color: #14532d; }
.alert-error { background: var(--rouge-bg); color: #7f1d1d; }
.alert-warn { background: var(--or-bg); color: #78350f; }

/* Cards & metrics */
.card { background: var(--card-bg); border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 22px; overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; gap: 10px; }
.card-title { font-weight: 700; font-size: 15px; }
.card-body { padding: 16px 18px; }

.metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 22px; }
.metric-card { background: var(--card-bg); border-radius: var(--radius); border: 1px solid var(--border); padding: 16px 18px; border-left: 4px solid var(--gris); }
.metric-card.vert { border-left-color: var(--vert); }
.metric-card.or { border-left-color: var(--or); }
.metric-card.rouge { border-left-color: var(--rouge); }
.metric-card.bleu { border-left-color: var(--bleu); }
.metric-card.violet { border-left-color: var(--violet); }
.metric-label { font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.metric-value { font-size: 26px; font-weight: 800; }

/* Table */
.search-bar { margin-bottom: 4px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: #fafbfc; font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); }
tbody tr:hover { background: #fafbfc; }
.table-empty { text-align: center; color: var(--text-muted); padding: 30px !important; white-space: normal; }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.badge-vert   { background: var(--vert-bg); color: #14532d; }
.badge-or     { background: var(--or-bg); color: #78350f; }
.badge-rouge  { background: var(--rouge-bg); color: #7f1d1d; }
.badge-bleu   { background: var(--bleu-bg); color: #1e3a8a; }
.badge-violet { background: var(--violet-bg); color: #4c1d95; }
.badge-gris   { background: var(--gris-bg); color: #334155; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 8px; border: none; font-size: 13.5px; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-secondary { background: var(--gris-bg); color: var(--text); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-danger { background: var(--rouge-bg); color: #7f1d1d; }
.btn-danger:hover { background: #fecaca; }
.btn-success { background: var(--vert-bg); color: #14532d; }
.btn-success:hover { background: #bbf7d0; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; }
.btn-block { width: 100%; justify-content: center; }

/* Forms */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12.5px; font-weight: 700; margin-bottom: 5px; text-transform: uppercase; letter-spacing: .02em; color: var(--text-muted); }
.form-control { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; font-family: inherit; background: #fff; color: var(--text); }
.form-control:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-light); }
textarea.form-control { resize: vertical; min-height: 70px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }

/* Arbre d'habilitations module + sous-onglet (modales Habilitations / Rôles) */
.perm-tree { columns: 260px; column-gap: 18px; max-height: 56vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; }
.perm-module-row { break-inside: avoid; margin-bottom: 4px; padding: 4px 0; }
.perm-module-head { display: flex; align-items: center; gap: 4px; }
.perm-module-head label { display: flex; align-items: center; gap: 8px; font-size: 13px; flex: 1; cursor: pointer; }
.perm-module-head input[type=checkbox] { width: auto; }
.perm-caret { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 11px; width: 20px; height: 20px; flex-shrink: 0; transition: transform .12s ease; }
.perm-caret.open { transform: rotate(90deg); }
.perm-sous-list { display: none; flex-direction: column; gap: 3px; margin: 4px 0 2px 26px; padding-left: 10px; border-left: 2px solid var(--border); }
.perm-sous-list.open { display: flex; }
.perm-sous-list label { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-muted); cursor: pointer; }
.perm-sous-list input[type=checkbox] { width: auto; }

/* Sélecteur de thème (Administration) */
.theme-swatch-grid { display: flex; flex-wrap: wrap; gap: 14px; }
.theme-swatch { display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; padding: 12px 10px; border-radius: 12px; border: 2px solid transparent; }
.theme-swatch:hover { background: var(--bg); }
.theme-swatch.selected { border-color: var(--teal); background: var(--teal-light); }
.theme-swatch input[type=radio] { position: absolute; opacity: 0; width: 0; height: 0; }
.theme-swatch-color { width: 44px; height: 44px; border-radius: 50%; box-shadow: inset 0 0 0 3px #fff, 0 0 0 1px var(--border); }
.theme-swatch-label { font-size: 12.5px; font-weight: 600; }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(15,23,42,.55); align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal-overlay.show { display: flex; }
.modal-box { background: #fff; border-radius: var(--radius); width: 100%; max-width: 620px; max-height: 92vh; display: flex; flex-direction: column; }
.modal-box.modal-wide { max-width: 96vw; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-title { font-weight: 700; font-size: 15px; }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* BPMN editor */
.bpmn-toolbar { display: flex; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); background: #fafbfc; flex-wrap: wrap; align-items: center; }
.bpmn-canvas { height: 62vh; min-height: 420px; border-bottom: 1px solid var(--border); background: #fff repeating-linear-gradient(0deg, transparent, transparent 24px, #f4f6f8 25px), repeating-linear-gradient(90deg, transparent, transparent 24px, #f4f6f8 25px); }
.version-pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--teal-light); color: var(--teal-dark); font-size: 12px; font-weight: 700; }

/* KPI mini bar */
.kpi-bar-track { background: var(--gris-bg); border-radius: 6px; height: 8px; overflow: hidden; }
.kpi-bar-fill { height: 100%; border-radius: 6px; }
.kpi-bar-fill.vert { background: var(--vert); }
.kpi-bar-fill.or { background: var(--or); }
.kpi-bar-fill.rouge { background: var(--rouge); }

/* Process card grid (module Processus) */
.process-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.process-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.process-card h3 { margin: 0; font-size: 15px; }
.process-card .meta { font-size: 12px; color: var(--text-muted); }
.process-card .actions { margin-top: auto; display: flex; gap: 8px; flex-wrap: wrap; }

/* Page d'accueil (grille des modules — gros pictogrammes colorés, icône + nom uniquement) */
.home-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 30px 18px; max-width: 980px; margin: 12px auto 0; padding: 0 8px;
}
.home-tile {
  background: transparent; border: none; padding: 0;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  text-align: center; text-decoration: none; color: var(--text);
  transition: transform .15s ease;
}
.home-tile:hover { transform: translateY(-4px); }
.home-tile:hover .home-tile-icon { box-shadow: 0 10px 22px rgba(0,0,0,.16); }
.home-tile .home-tile-icon {
  width: 88px; height: 88px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 42px; line-height: 1; border-radius: 24px;
  background: var(--teal-light); box-shadow: 0 3px 8px rgba(0,0,0,.07);
  transition: box-shadow .15s ease;
}
.home-tile .home-tile-label { font-size: 13.5px; font-weight: 600; line-height: 1.25; }
/* Rotation de couleurs pour que la grille reste vivante, comme un écran d'icônes */
.home-tile:nth-of-type(7n+1) .home-tile-icon { background: var(--teal-light); }
.home-tile:nth-of-type(7n+2) .home-tile-icon { background: var(--vert-bg); }
.home-tile:nth-of-type(7n+3) .home-tile-icon { background: var(--or-bg); }
.home-tile:nth-of-type(7n+4) .home-tile-icon { background: var(--bleu-bg); }
.home-tile:nth-of-type(7n+5) .home-tile-icon { background: var(--violet-bg); }
.home-tile:nth-of-type(7n+6) .home-tile-icon { background: var(--rouge-bg); }
.home-tile:nth-of-type(7n+7) .home-tile-icon { background: var(--gris-bg); }
@media (max-width: 480px) {
  .home-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 22px 10px; }
  .home-tile .home-tile-icon { width: 68px; height: 68px; font-size: 32px; border-radius: 18px; }
}

/* Sous-onglets (RH, MyRH, Formation, Paie...) */
.subtabs-bar { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 18px; border-bottom: 1px solid var(--border); padding-bottom: 0; }
.subtab { padding: 9px 14px; font-size: 13px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.subtab:hover { color: var(--teal-dark); }
.subtab.active { color: var(--teal-dark); border-bottom-color: var(--teal); }

/* Vue maître-détail (Dossiers RH) */
.master-detail { display: grid; grid-template-columns: 320px 1fr; gap: 18px; align-items: start; }
.master-list { max-height: 78vh; overflow-y: auto; }
.master-list-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.master-list-item:hover { background: var(--teal-light); }
.master-list-item.active { background: var(--teal-light); border-left: 3px solid var(--teal); }
.master-list-item .avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--teal-light); color: var(--teal-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; flex-shrink: 0; overflow: hidden; }
.master-list-item .avatar img { width: 100%; height: 100%; object-fit: cover; }
.master-list-item .name { font-weight: 600; font-size: 13.5px; }
.master-list-item .sub { font-size: 11.5px; color: var(--text-muted); }
@media (max-width: 900px) { .master-detail { grid-template-columns: 1fr; } }

/* Organigramme */
.org-node { border-left: 2px solid var(--border); margin-left: 14px; padding-left: 14px; margin-top: 10px; }
.org-node-card { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: #fff; max-width: 340px; }
.org-node-card .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--teal-light); color: var(--teal-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; overflow: hidden; flex-shrink: 0; }
.org-node-card .avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Circuit de validation congés */
.validation-chain { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.validation-step { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.validation-step .num { width: 22px; height: 22px; border-radius: 50%; background: var(--gris-bg); display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; flex-shrink: 0; }

/* Badge / carte biométrique */
.badge-card { border-radius: 10px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.12); width: 244px; }
.qr-box { display: inline-flex; padding: 10px; background: #fff; border: 1px solid var(--border); border-radius: 8px; }
.scanner-input { font-size: 16px; padding: 14px; text-align: center; letter-spacing: 1px; }

/* Responsive */
@media (max-width: 992px) {
  .app-rail { display: none; }
  .app-center { padding: 12px; }
}
@media (max-width: 768px) {
  .topbar-title-pill { display: none; }
  .user-menu-info { display: none; }
  .page-content { padding: 16px; }
  .app-card { border-radius: 12px; }
  th, td { white-space: normal; }
}
