/**
 * index.css — App shell (layout + polish global + compat tokens)
 * Objectif: harmonie + stabilité avec design-system-v2.css + navbar-dynamic.css + sidebar-dynamic.css
 */

/* -------------------------------------------------------------------------- */
/* Compat tokens (alias) — évite les bugs de variables manquantes              */
/* -------------------------------------------------------------------------- */
:root {
  /* alias old naming -> new naming */
  --maxw: var(--content-max-w, 1440px);
  --pad-page: var(--page-padding, 24px);

  /* motion aliases (certains fichiers utilisent --fast/--med/--ease) */
  --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));

  /* palette aliases */
  --primary-2: var(--primary-light, #6366f1);
  --accent-2: var(--accent-light, #fbbf24);

  /* status aliases (toastr / badges legacy) */
  --ok: var(--success, #10b981);
  --warn: var(--warning, #f59e0b);
  --bad: var(--error, #ef4444);
  --info: var(--info, #3b82f6);

  /* borders legacy */
  --border: var(--stroke, rgba(15, 23, 42, 0.08));
}

/* -------------------------------------------------------------------------- */
/* Base polish                                                                 */
/* -------------------------------------------------------------------------- */
html { scroll-behavior: smooth; }

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

/* Sélection propre */
::selection {
  background: rgba(79, 70, 229, 0.18);
}

/* Scrollbar (soft) */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: rgba(15, 23, 42, 0.14);
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.55);
}
*::-webkit-scrollbar-track { background: transparent; }

/* Focus visible cohérent */
: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),
    0 18px 44px rgba(15, 23, 42, 0.12);
  border-radius: 12px;
}

/* Utilitaire accessibilité */
.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;
}

/* -------------------------------------------------------------------------- */
/* App layout                                                                    */
/* (La sidebar-dynamic.css gère déjà beaucoup, ici on harmonise + sécurise)     */
/* -------------------------------------------------------------------------- */

/* évite les doubles paddings si sidebar-dynamic ajoute padding sur .content > * */
.content > #main-content {
  padding-left: 0 !important;
  padding-right: 0 !important;
}

/* -------------------------------------------------------------------------- */
/* Main content container (#main-content)                                      */
/* -------------------------------------------------------------------------- */
.main-content {
  margin: var(--pad-page) auto;
  transition: opacity 220ms cubic-bezier(.2,.9,.2,1), 
              transform 220ms cubic-bezier(.2,.9,.2,1);
}

/* Animations de page - OPTIMISÉES pour rapidité */
.main-content.page-enter {
  animation: pageEnter 200ms cubic-bezier(.2,.9,.2,1);
}

.main-content.page-leave {
  opacity: 0.7;
  transform: translateY(-4px);
}

.main-content.is-loading {
  pointer-events: none;
  user-select: none;
}

@keyframes pageEnter {
  0% {
    opacity: 0;
    transform: translateY(16px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Loader */
.loader-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  padding: 60px 20px;
}

.loader {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(72,97,165,.12);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.main-content {
  max-width: var(--maxw);
  padding: clamp(18px, 2vw, 28px);

  background: var(--card, rgba(255, 255, 255, 0.86));

  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transform: translateZ(0);
}

/* transitions SPA - OPTIMISÉES */
.main-content.page-enter {
  animation: pageEnter 200ms var(--ease) both;
}
.main-content.page-leave {
  animation: pageLeave 150ms var(--ease) both;
}

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

/* state loading */
.main-content.is-loading {
  pointer-events: none;
  user-select: none;
  filter: saturate(0.98);
}

/* -------------------------------------------------------------------------- */
/* Loader                                                                        */
/* -------------------------------------------------------------------------- */
.loader-container {
  display: grid;
  place-items: center;
  min-height: 52vh;

  background: rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.loader {
  width: 56px;
  height: 56px;
  border-radius: 999px;
  border: 6px solid rgba(72, 97, 165, 0.14);
  border-top-color: var(--primary);
  animation: spin 900ms linear infinite;
}

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

/* -------------------------------------------------------------------------- */
/* Toastr (premium glass)                                                      */
/* -------------------------------------------------------------------------- */
#toast-container .toast {
  opacity: 1;
  border-radius: 14px;
  box-shadow: var(--shadow-md, 0 12px 30px rgba(15, 23, 42, 0.12));
  background: var(--card, rgba(255, 255, 255, 0.90));
  border: 1px solid var(--border);
  color: var(--ink, #0f172a);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

#toast-container .toast-success { border-left: 6px solid var(--ok); }
#toast-container .toast-error   { border-left: 6px solid var(--bad); }
#toast-container .toast-info    { border-left: 6px solid var(--info); }
#toast-container .toast-warning { border-left: 6px solid var(--warn); }

/* -------------------------------------------------------------------------- */
/* Fix: active state sidebar (ton JS met .active, pas .is-active)              */
/* -------------------------------------------------------------------------- */
.sidebar .item.active {
  background: linear-gradient(135deg, rgba(244,178,60,.26), rgba(245,158,11,.14));
  border-color: rgba(245,158,11,.26);
  box-shadow: 0 18px 40px rgba(245,158,11,.16);
  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));
  box-shadow: 0 10px 18px rgba(245,158,11,.22);
}

/* -------------------------------------------------------------------------- */
/* Responsive                                                                  */
/* -------------------------------------------------------------------------- */

/* Tablet */
@media (max-width: 980px) {
  .main-content {
    margin: 16px;
    padding: 20px;
  }
}

/* Mobile */
@media (max-width: 640px) {
  .main-content {
    margin: 12px;
    padding: 16px;
    max-width: 100%;
  }
  
  .loader {
    width: 44px;
    height: 44px;
    border-width: 5px;
  }
}

/* Motion safety */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  .main-content.page-enter,
  .main-content.page-leave { animation: none !important; }

  .loader { animation: none !important; }

  * { transition-duration: 0.01ms !important; }
}
