/**
 * index.css — App shell (layout + compat tokens)
 * Version propre et sans doublons.
 */

/* ─────────────────────────────────────────────────────────────────────────── */
/* 1. COMPAT TOKENS                                                            */
/* ─────────────────────────────────────────────────────────────────────────── */
:root {
  /* Aliases naming (compatibilité) */
  --maxw:     var(--content-max-w,  1440px);
  --pad-page: var(--page-padding,   24px);
  --fast:     var(--duration-fast,  150ms);
  --med:      var(--duration-base,  250ms);
  --slow:     var(--duration-slow,  400ms);
  --ease:     var(--ease-default,   cubic-bezier(0.4, 0, 0.2, 1));
  --easeIn:   var(--ease-in,        cubic-bezier(0.4, 0, 1, 1));
  --easeOut:  var(--ease-out,       cubic-bezier(0, 0, 0.2, 1));
  --easeInOut:var(--ease-in-out,    cubic-bezier(0.4, 0, 0.2, 1));

  --primary-2:   var(--primary-light, #6366f1);
  --accent-2:    var(--accent-light,  #fbbf24);

  --ok:         var(--success,  #10b981);
  --warn:       var(--warning,  #f59e0b);
  --bad:        var(--error,    #ef4444);
  --info-legacy:var(--info,     #3b82f6);

  --border:     var(--stroke,   rgba(15, 23, 42, 0.08));

  /* Alias "text-N" / "surface-N" utilisés dans les pages */
  --text-1:   var(--ink,       #1e293b);
  --text-2:   var(--ink-light, #4a5568);
  --text-3:   var(--ink-muted, #718096);
  --surface-1:var(--card,      rgba(255,255,255,0.88));
  --surface-2:var(--surface,   rgba(79,70,229,0.04));
}

/* ─────────────────────────────────────────────────────────────────────────── */
/* 2. BASE POLISH                                                               */
/* ─────────────────────────────────────────────────────────────────────────── */
html { scroll-behavior: smooth; }

body {
  min-height: 100vh;
  overflow-x: hidden;
  text-rendering: optimizeLegibility;
}

::selection { background: rgba(79, 70, 229, 0.18); }

*::-webkit-scrollbar { width: 6px; height: 6px; }
*::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.14);
  border-radius: 999px;
}
*::-webkit-scrollbar-track { background: transparent; }

:where(a,button,input,select,textarea,[tabindex]):focus { outline: none; }
:where(a,button,input,select,textarea,[tabindex]):focus-visible {
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.18);
  border-radius: 8px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/* 3. LAYOUT — TRANSPARENCE UNIFORME                                           */
/* L'app-bg (position:fixed, z-index:-2) + body background fournissent        */
/* le fond pour TOUTE la page. Les containers sont transparents pour           */
/* éviter toute "coupure" visuelle.                                            */
/* ─────────────────────────────────────────────────────────────────────────── */
.app-layout,
.content {
  background: transparent !important;
}

/* Éviter le double-padding (sidebar-dynamic ajoute déjà padding via .content>*) */
.content > #main-content {
  padding-left:  0 !important;
  padding-right: 0 !important;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/* 4. .main-content — CONTENEUR TRANSPARENT                                   */
/* Pas de fond propre : le fond est fourni par l'ensemble body + app-bg        */
/* Les .card Bootstrap internes ont leur propre fond.                          */
/* ─────────────────────────────────────────────────────────────────────────── */
.main-content {
  max-width: var(--maxw);
  width: 100%;
  padding: clamp(16px, 2vw, 24px);
  background: transparent;
  position: relative;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/* 5. TRANSITIONS SPA                                                          */
/* ─────────────────────────────────────────────────────────────────────────── */
.main-content.page-enter {
  animation: pageEnter 220ms cubic-bezier(0, 0, .2, 1) both;
}
.main-content.page-leave {
  animation: pageLeave 150ms cubic-bezier(.4, 0, 1, 1) both;
}

@keyframes pageEnter {
  from { opacity: 0;   transform: translateY(10px); }
  to   { opacity: 1;   transform: translateY(0);    }
}
@keyframes pageLeave {
  to   { opacity: 0.6; transform: translateY(-5px); }
}

/* ─────────────────────────────────────────────────────────────────────────── */
/* 6. ÉTAT is-loading                                                          */
/* ─────────────────────────────────────────────────────────────────────────── */
.main-content.is-loading {
  pointer-events: none;
  user-select: none;
  overflow: hidden;
}
.main-content.is-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.32);
  backdrop-filter: blur(2px);
  animation: loadingPulse 1.1s ease-in-out infinite;
  z-index: 10;
}
@keyframes loadingPulse {
  0%, 100% { opacity: .40; }
  50%       { opacity: .70; }
}

/* ─────────────────────────────────────────────────────────────────────────── */
/* 7. LOADER                                                                   */
/* ─────────────────────────────────────────────────────────────────────────── */
.loader-container {
  display: grid;
  place-items: center;
  min-height: 52vh;
}
.loader {
  width: 44px; height: 44px;
  border-radius: 999px;
  border: 4px solid rgba(72, 97, 165, .12);
  border-top-color: var(--primary);
  animation: spin 800ms linear infinite;
}
.loader-lg { width: 56px; height: 56px; border-width: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

.page-empty {
  display: grid;
  place-items: center;
  min-height: 30vh;
  color: var(--ink-muted);
  font-size: 14px;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/* 8. SPA PROGRESS BAR                                                         */
/* ─────────────────────────────────────────────────────────────────────────── */
#spa-progress {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 9999;
  height: 3px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease;
}
#spa-progress.spa-active { opacity: 1; }
#spa-progress.spa-done   { opacity: 1; transition: opacity 320ms ease; }
#spa-progress:not(.spa-active):not(.spa-done) {
  opacity: 0; transition: opacity 240ms ease 80ms;
}
#spa-progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 100%);
  border-radius: 0 2px 2px 0;
  transition: width 180ms cubic-bezier(.4, 0, .2, 1);
  box-shadow: 0 0 8px rgba(72, 97, 165, .45);
}
#spa-progress.spa-error #spa-progress-bar { background: var(--error); }

/* ─────────────────────────────────────────────────────────────────────────── */
/* 9. TOASTR (glass)                                                           */
/* ─────────────────────────────────────────────────────────────────────────── */
#toast-container .toast {
  opacity: 1;
  border-radius: 14px;
  box-shadow: var(--shadow-md);
  background: var(--card, rgba(255, 255, 255, 0.92));
  border: 1px solid var(--border);
  color: var(--ink);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
#toast-container .toast-success { border-left: 4px solid var(--ok); }
#toast-container .toast-error   { border-left: 4px solid var(--bad); }
#toast-container .toast-info    { border-left: 4px solid var(--info-legacy); }
#toast-container .toast-warning { border-left: 4px solid var(--warn); }

/* ─────────────────────────────────────────────────────────────────────────── */
/* 10. SIDEBAR — item actif                                                    */
/* ─────────────────────────────────────────────────────────────────────────── */
.sidebar .item.active {
  background: linear-gradient(135deg, rgba(244,178,60,.26), rgba(245,158,11,.14));
  border-color: rgba(245,158,11,.26);
  color: rgba(15,23,42,.92);
}
.sidebar .item.active::before {
  content: "";
  position: absolute;
  left: 8px; top: 50%;
  transform: translateY(-50%);
  width: 6px; height: 22px;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}

/* ─────────────────────────────────────────────────────────────────────────── */
/* 11. RESPONSIVE                                                              */
/* ─────────────────────────────────────────────────────────────────────────── */
@media (max-width: 980px) {
  .main-content { padding: 16px; }
}
@media (max-width: 640px) {
  .main-content { padding: 12px; max-width: 100%; }
  .loader { width: 36px; height: 36px; border-width: 3px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .main-content.page-enter,
  .main-content.page-leave,
  .main-content.is-loading::after,
  #spa-progress-bar,
  .loader { animation: none !important; transition: none !important; }
}

/* ─────────────────────────────────────────────────────────────────────────── */
/* 12. BREADCRUMBS                                                             */
/* ─────────────────────────────────────────────────────────────────────────── */
.breadcrumb-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 0 0;      /* padding-top seulement — padding H vient de .content>* */
  margin-bottom: 0;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-muted);
  flex-wrap: wrap;
  min-height: 40px;
}
.breadcrumb-bar:empty {
  min-height: 0;
  padding: 0;
}
.breadcrumb-bar a {
  color: var(--ink-muted);
  text-decoration: none;
  transition: color var(--duration-fast) var(--ease-default);
}
.breadcrumb-bar a:hover { color: var(--primary); }
.breadcrumb-bar .bc-sep {
  opacity: .40;
  font-size: 11px;
  user-select: none;
}
.breadcrumb-bar .bc-current {
  color: var(--ink);
  font-weight: 600;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/* 13. OFFLINE BANNER                                                          */
/* ─────────────────────────────────────────────────────────────────────────── */
#offline-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 9990;
  padding: 10px 20px;
  background: linear-gradient(90deg, #1a1a2e, #16213e);
  border-top: 2px solid var(--error);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  transform: translateY(100%);
  transition: transform 280ms cubic-bezier(0.2, 0.9, 0.2, 1);
  pointer-events: none;
}
#offline-banner.show {
  transform: translateY(0);
  pointer-events: auto;
}
#offline-banner .offline-dot {
  width: 8px; height: 8px;
  border-radius: 999px;
  background: var(--error);
  flex: 0 0 auto;
  animation: offlinePulse 1.5s ease-in-out infinite;
}
@keyframes offlinePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ─────────────────────────────────────────────────────────────────────────── */
/* 14. PAGE HEADER (titre + actions en haut de chaque page)                   */
/* ─────────────────────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-header .page-title {
  font-size: clamp(18px, 2.5vw, 24px);
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.02em;
  margin: 0;
}
.page-header .page-subtitle {
  font-size: 13px;
  color: var(--ink-muted);
  margin: 4px 0 0;
  font-weight: 400;
}
.page-header .page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

/* ─────────────────────────────────────────────────────────────────────────── */
/* 15. STAT CARDS                                                              */
/* ─────────────────────────────────────────────────────────────────────────── */
.stat-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 18px 20px;
  background: #fff;
  border-radius: var(--radius-lg);
  border: 1px solid var(--stroke);
  box-shadow: var(--shadow-sm);
  transition: transform var(--duration-fast) var(--ease-default),
              box-shadow var(--duration-fast) var(--ease-default);
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.stat-card .stat-label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-muted);
}
.stat-card .stat-value {
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -0.03em;
  line-height: 1;
}
.stat-card .stat-delta {
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}
.stat-card .stat-delta.up   { color: var(--success); }
.stat-card .stat-delta.down { color: var(--error); }

/* Dark mode stat cards */
[data-theme="dark"] .stat-card {
  background: rgba(22,27,34,0.98) !important;
  border-color: rgba(240,246,252,.08) !important;
}
[data-theme="dark"] .breadcrumb-bar a { color: var(--ink-muted); }
[data-theme="dark"] .breadcrumb-bar .bc-current { color: var(--ink); }

/* ═══════════════════════════════════════════════════════════════════════════ */
/* MODE SOMBRE — [data-theme="dark"]                                          */
/* ═══════════════════════════════════════════════════════════════════════════ */

/* .main-content reste transparent en dark aussi → pas de coupure */
[data-theme="dark"] .main-content {
  background: transparent !important;
}

/* is-loading overlay dark */
[data-theme="dark"] .main-content.is-loading::after {
  background: rgba(0, 0, 0, 0.40) !important;
}

/* Loader dark */
[data-theme="dark"] .loader {
  border-color: rgba(240,246,252,.10) !important;
  border-top-color: var(--primary) !important;
}

/* Progress bar dark */
[data-theme="dark"] #spa-progress-bar {
  background: linear-gradient(90deg, var(--primary-light), #818cf8) !important;
}

/* Toastr dark */
[data-theme="dark"] #toast-container .toast {
  background: rgba(22, 27, 34, 0.96) !important;
  border-color: rgba(240,246,252,.10) !important;
  color: var(--ink) !important;
  box-shadow: 0 8px 32px rgba(0,0,0,.45) !important;
}

/* Sélection dark */
[data-theme="dark"] ::selection { background: rgba(99,102,241,.30); color: #fff; }

/* Scrollbar dark (override design-system) */
[data-theme="dark"] *::-webkit-scrollbar-thumb {
  background: rgba(240,246,252,.12);
  border-color: transparent;
}

/* Active sidebar item dark */
[data-theme="dark"] .sidebar .item.active {
  background: rgba(99,102,241,.18) !important;
  border-color: rgba(99,102,241,.30) !important;
  color: #a5b4fc !important;
}
[data-theme="dark"] .sidebar .item.active::before {
  background: linear-gradient(180deg, #6366f1, #818cf8) !important;
}

/* body background dark (renfort si variable pas encore résolue) */
[data-theme="dark"] body {
  background-color: #0d1117 !important;
}
