/* =====================
   Variables & Reset
   (repris de swa-grbi-vmorchestrateur-*, mêmes tokens)
   ===================== */
:root {
  --bg: #0a0f1e;
  --bg-card: #111827;
  --bg-card-hover: #1a2236;
  --border: #1e2d45;
  --border-hover: #2d4a6e;
  --accent: #0ea5e9;
  --accent-hover: #38bdf8;
  --accent-glow: rgba(14, 165, 233, 0.2);
  --text-primary: #f0f6ff;
  --text-secondary: #8ba3c0;
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.1);
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.1);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.1);
  --font: 'Segoe UI', system-ui, sans-serif;
  --radius: 12px;
  --radius-lg: 16px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse at 20% 20%, rgba(14,165,233,0.05) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 80%, rgba(14,165,233,0.03) 0%, transparent 60%);
}

/* =====================
   Header
   ===================== */
header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  background: rgba(10, 15, 30, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  font-size: 22px;
  color: var(--accent);
  filter: drop-shadow(0 0 8px var(--accent));
}

.logo-text {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-primary);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

#user-name {
  font-size: 13px;
  color: var(--text-secondary);
}

#btn-logout {
  font-size: 12px;
  padding: 6px 14px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
}

#btn-logout:hover {
  border-color: var(--border-hover);
  color: var(--text-primary);
}

/* =====================
   Screens
   ===================== */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 80px 24px 40px;
}

/* Le tableau de bord ne doit JAMAIS être centré verticalement comme les
   autres écrans (login/chargement/no-access ont une hauteur de contenu
   fixe, donc le centrage ne pose pas de problème là). Sa hauteur varie
   énormément selon l'onglet actif et la taille des résultats d'une
   requête -- avec un centrage vertical, ça faisait "sauter" tout le bloc
   (menu de gauche inclus) du centre vers le haut de l'écran à chaque
   clic. Voir aussi .app-shell/.sidebar-nav plus bas. */
#screen-dashboard.screen {
  display: block;
  padding: 0;
}

.hidden { display: none !important; }

/* =====================
   Login
   ===================== */
.login-box {
  text-align: center;
  max-width: 420px;
  padding: 48px 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: 0 0 60px rgba(14, 165, 233, 0.06);
}

.login-icon {
  font-size: 48px;
  color: var(--accent);
  filter: drop-shadow(0 0 16px var(--accent));
  margin-bottom: 24px;
}

.login-box h1 {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 12px;
  letter-spacing: -0.5px;
}

.login-box p {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 32px;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 13px 28px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 0 20px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 30px rgba(14, 165, 233, 0.35);
  transform: translateY(-1px);
}

/* =====================
   Loading
   ===================== */
.loading-box {
  text-align: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}

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

.loading-box p {
  color: var(--text-secondary);
  font-size: 14px;
}

/* =====================
   No Access
   ===================== */
.no-access-box {
  text-align: center;
  max-width: 420px;
  padding: 48px 40px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

.no-access-box span {
  font-size: 48px;
  display: block;
  margin-bottom: 16px;
}

.no-access-box p {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 8px;
}

.no-access-box small {
  color: var(--text-secondary);
  font-size: 13px;
}

/* =====================
   Dashboard
   ===================== */
.dashboard-inner {
  max-width: 1100px;
  width: 100%;
}

.dashboard-header {
  margin-bottom: 24px;
}

.dashboard-header h2 {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 8px;
}

.dashboard-header p {
  color: var(--text-secondary);
  font-size: 14px;
}

/* =====================
   Disposition générale (menu de gauche indépendant + contenu)
   ===================== */
.app-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

/* Menu de gauche : complètement indépendant du contenu de droite --
   sticky sous l'en-tête (fixed, 60px de haut), occupe toute la hauteur de
   la fenêtre. Comme il vit en dehors de .dashboard-inner/.app-main, il ne
   bouge jamais peu importe la taille de la liste retournée par une
   requête ou le sous-onglet actif. */
.sidebar-nav {
  flex: 0 0 260px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 60px;
  align-self: flex-start;
  height: calc(100vh - 60px);
  padding: 32px 20px;
  border-right: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.015);
}

.app-main {
  flex: 1;
  min-width: 0;
  padding: 100px 24px 40px;
  display: flex;
  justify-content: center;
}

/* Le menu passe en rangée horizontale sur petit écran, pour rester
   utilisable sur mobile/tablette. */
@media (max-width: 760px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar-nav {
    flex: 0 0 auto;
    flex-direction: row;
    overflow-x: auto;
    position: static;
    height: auto;
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 76px 16px 16px;
  }
  .app-main {
    padding: 24px 16px 40px;
  }
}

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

/* =====================
   Onglets
   ===================== */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

/* Menu de gauche des sections principales (Aperçu / Licences / Anciens
   Comptes) : réutilise .tab-btn comme base, mais en disposition verticale,
   taille de texte plus grande (demande d'Eric), et un indicateur d'état
   actif à gauche plutôt qu'en soulignement -- plus adapté à un menu qu'à
   des onglets horizontaux. */
.sidebar-nav .tab-btn {
  text-align: left;
  width: 100%;
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 600;
  border-bottom: none;
  border-left: 3px solid transparent;
  border-radius: 8px;
}

.sidebar-nav .tab-btn:hover {
  background: var(--bg-card-hover);
}

.sidebar-nav .tab-btn.active {
  background: var(--bg-card);
  border-bottom-color: transparent;
  border-left-color: var(--accent);
}

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

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

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

.tab-panel[hidden] { display: none; }

/* Sous-onglets (imbriqués dans "Licences" et dans "Comptes anciens") :
   même look que les onglets de niveau supérieur (.tabs/.tab-btn) — seule
   la nav elle-même (.tabs.subtabs) garde une marge du bas un peu plus
   petite pour rester visuellement "imbriquée" sous l'onglet parent. */
.tabs.subtabs {
  margin-bottom: 20px;
}

.subtab-btn {
  border: none;
  background: transparent;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

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

.subtab-panel[hidden] { display: none; }

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

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

.panel-meta {
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 16px;
}

/* =====================
   Filtres de tableau (Compte Entra ID / Licences)
   ===================== */
.filtres-table {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}

.filtre-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
}

.filtre-select {
  background: var(--bg-card);
  color: var(--text-primary);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
}

.filtre-select:hover {
  border-color: var(--border-hover);
}

.filtre-select:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-refresh {
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}
.btn-refresh:hover { border-color: var(--border-hover); color: var(--text-primary); }

.panel-compte {
  color: var(--text-secondary);
  font-size: 12px;
  margin: 8px 0 0;
}

.status-msg {
  padding: 12px 0;
  color: var(--text-secondary);
  font-size: 13px;
}
.status-msg.error { color: #f87171; }

/* =====================
   Tableaux
   ===================== */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.data-table th, .data-table td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.data-table th {
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(255,255,255,0.02);
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--bg-card-hover); }

/* Tri par colonne (clic sur l'en-tête) — ajouté à la demande d'Eric,
   2026-09-22. Flèche neutre (haut-bas) par défaut sur toute colonne
   triable, remplacée par une flèche pleine (haut ou bas) une fois cette
   colonne active pour indiquer le sens du tri courant. */
.data-table th.th-sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.data-table th.th-sortable:hover {
  color: var(--text-primary);
}

.data-table th.th-sortable::after {
  content: "\2195";
  display: inline-block;
  margin-left: 4px;
  opacity: 0.35;
  font-size: 11px;
}

.data-table th.th-sortable.tri-asc::after {
  content: "\2191";
  opacity: 1;
}

.data-table th.th-sortable.tri-desc::after {
  content: "\2193";
  opacity: 1;
}

/* Ajustement de largeur pour les tableaux de comptes (récents/3 mois/6 mois/
   Exclusion — même forme de données, même gabarit de colonnes) :
   colonnes Nom, Courriel, Licences (1-4) et Statut (7) prennent l'espace
   restant ; Carnet d'adresses (5) est réduite, Depuis le (6) est élargie
   pour que la date ne soit jamais coupée. */
#recent-table th:nth-child(5), #recent-table td:nth-child(5),
#old3-table th:nth-child(5), #old3-table td:nth-child(5),
#old6-table th:nth-child(5), #old6-table td:nth-child(5),
#exclusion-table th:nth-child(5), #exclusion-table td:nth-child(5) {
  width: 90px;
}

#recent-table th:nth-child(6), #recent-table td:nth-child(6),
#old3-table th:nth-child(6), #old3-table td:nth-child(6),
#old6-table th:nth-child(6), #old6-table td:nth-child(6),
#exclusion-table th:nth-child(6), #exclusion-table td:nth-child(6) {
  width: 110px;
  white-space: nowrap;
}

.num { text-align: right; }

.usage-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.usage-bar {
  flex: 1;
  height: 6px;
  background: rgba(255,255,255,0.06);
  border-radius: 4px;
  overflow: hidden;
}

.usage-bar-fill {
  height: 100%;
  background: var(--accent);
}
.usage-bar-fill.warn { background: var(--warning); }
.usage-bar-fill.danger { background: var(--error); }

.usage-pct {
  font-size: 11px;
  color: var(--text-secondary);
  width: 36px;
  text-align: right;
}

/* =====================
   Badges
   ===================== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
}
.badge-recent { background: rgba(14, 165, 233, 0.1); color: var(--accent); border-color: var(--accent-glow); }
.badge-old3 { background: var(--warning-bg); color: var(--warning); border-color: rgba(245, 158, 11, 0.2); }
.badge-old6 { background: var(--error-bg); color: #f87171; border-color: rgba(239, 68, 68, 0.2); }
.badge-exclude { background: rgba(255,255,255,0.06); color: var(--text-secondary); margin-left: 6px; }
.badge-enabled { background: var(--warning-bg); color: var(--warning); border-color: rgba(245, 158, 11, 0.2); }
.badge-disabled { background: rgba(255,255,255,0.06); color: var(--text-secondary); }
.badge-licence { background: var(--error-bg); color: #f87171; border-color: rgba(239, 68, 68, 0.2); }
.badge-hidden { background: rgba(255,255,255,0.06); color: var(--text-secondary); }

.texte-muted { color: var(--text-secondary); font-size: 12px; }
.texte-attention { color: #f87171; font-size: 12px; font-weight: 600; }

/* Nom dont le displayName ne contient pas "_OLD" — convention de
   renommage au départ d'un employé possiblement oubliée, à vérifier. */
.nom-attention { color: #f87171; font-weight: 600; }

/* =====================
   Toast
   ===================== */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 14px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  z-index: 999;
  animation: slideIn 0.3s ease;
  max-width: 360px;
}

.toast.success {
  background: var(--success-bg);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
}

.toast.error {
  background: var(--error-bg);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #f87171;
}

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