/**
 * nx-loader.css — habillage du chargement asynchrone (voir Assets/JS/nx-loader.js).
 *
 * Les couleurs proviennent des variables de thème du site : le voile suit donc
 * automatiquement les thèmes Nexion / Clair / Sombre, sans duplication.
 */

/* ── Voile plein écran ─────────────────────────────────────────────────── */

.nx-loader {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: color-mix(in srgb, var(--page-bg, #0b0c10) 96%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 1;
  transition: opacity 300ms ease;
}

/* ── Le voile ne doit PAS suivre les fondus de page ─────────────────────────
 *
 * Le site fait deux fondus sur le <body> : `bodyFadeIn` à l'arrivée, et
 * `.page-fade-out` au départ vers une autre page. Une opacité posée sur un
 * parent s'applique à TOUS ses descendants, et rien dans un enfant ne peut
 * l'annuler : le voile s'effaçait donc exactement pendant les deux moments où
 * il est le plus utile — au chargement initial, et pendant la navigation.
 *
 * On déplace donc le fondu du <body> vers SES ENFANTS, en excluant le voile.
 * L'effet visuel du site est identique ; seul le voile reste opaque.
 */
html.nx-loading body,
html.nx-page-leaving body {
  animation: none !important;
  opacity: 1 !important;
  transition: none !important;
}

html.nx-loading body > *:not(.nx-loader) {
  animation: bodyFadeIn 550ms cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

html.nx-page-leaving body > *:not(.nx-loader) {
  opacity: 0;
  transition: opacity 380ms cubic-bezier(0.22, 1, 0.36, 1);
}

/* Voile de navigation : il apparaît sur un clic, pas sur une attente réseau.
   Une apparition instantanée donnerait un à-coup ; 120 ms suffisent à le
   rendre fluide sans donner l'impression d'un retard. */
.nx-loader--nav {
  animation: nx-loader-appear 120ms ease-out;
}

@keyframes nx-loader-appear {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.nx-loader--done {
  opacity: 0;
  pointer-events: none;
}

.nx-loader-body {
  text-align: center;
  max-width: 460px;
}

.nx-loader-title {
  margin: 1.25rem 0 0.35rem 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-color, #f5f5f5);
  letter-spacing: 0.01em;
}

.nx-loader-sub {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.55;
  color: var(--text-muted, #9aa0a6);
}

/* ── Astuce affichée pendant le chargement ─────────────────────────────
   Le libellé est une pastille distincte du texte : d'un coup d'œil, on
   voit qu'il s'agit d'un conseil et non d'un message d'état. */
.nx-loader-tip-label {
  display: inline-block;
  margin-bottom: 0.4rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent, #4ade80) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent, #4ade80) 32%, transparent);
  color: var(--accent, #4ade80);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.nx-loader-tip-text {
  display: block;
  min-height: 2.6em; /* évite que le panneau saute d'une astuce à l'autre */
}

/* ── Anneau animé ──────────────────────────────────────────────────────── */
/* Trois arcs concentriques déphasés : lisible même à 60 px, et sans image. */

.nx-loader-ring {
  position: relative;
  width: 64px;
  height: 64px;
  margin: 0 auto;
}

.nx-loader-ring span {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2.5px solid transparent;
  border-top-color: var(--accent, #4ade80);
  animation: nx-loader-spin 1.15s cubic-bezier(0.55, 0.15, 0.45, 0.85) infinite;
}

.nx-loader-ring span:nth-child(2) {
  inset: 9px;
  border-top-color: color-mix(in srgb, var(--accent, #4ade80) 60%, transparent);
  animation-duration: 1.5s;
  animation-direction: reverse;
}

.nx-loader-ring span:nth-child(3) {
  inset: 18px;
  border-top-color: color-mix(in srgb, var(--accent, #4ade80) 35%, transparent);
  animation-duration: 1.9s;
}

.nx-loader-ring--sm { width: 38px; height: 38px; }
.nx-loader-ring--sm span:nth-child(2) { inset: 6px; }
.nx-loader-ring--sm span:nth-child(3) { inset: 12px; }

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

/* Respect de la préférence système : une animation continue peut déclencher
   des troubles vestibulaires. On garde un repère visuel, sans rotation. */
@media (prefers-reduced-motion: reduce) {
  .nx-loader-ring span {
    animation: nx-loader-pulse 1.6s ease-in-out infinite;
    border-color: var(--accent, #4ade80);
    opacity: 0.35;
  }
  @keyframes nx-loader-pulse {
    0%, 100% { opacity: 0.2; }
    50% { opacity: 0.55; }
  }
}

/* ── État d'erreur ─────────────────────────────────────────────────────── */

.nx-loader-error-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
}

.nx-loader--error .nx-loader-title { color: #ef4444; }

.nx-loader-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1.25rem;
}

.nx-loader-btn {
  padding: 0.55rem 1.1rem;
  font-size: 0.86rem;
  font-family: inherit;
  font-weight: 600;
  border-radius: var(--radius-sm, 8px);
  border: 1px solid var(--border-color, #2a2d34);
  background: var(--surface, #16181d);
  color: var(--text-color, #f5f5f5);
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease;
}

.nx-loader-btn:hover {
  background: var(--surface-strong, #1e2128);
  border-color: var(--accent, #4ade80);
}

.nx-loader-btn--primary {
  background: var(--accent, #4ade80);
  border-color: var(--accent, #4ade80);
  color: var(--button-text, #0b0c10);
}

.nx-loader-btn--sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
}

/* ── Neutralisation des interactions ───────────────────────────────────── */
/*
 * Pendant le chargement, la page ne doit pas réagir aux clics — SAUF la
 * navigation. On coupe donc les interactions globalement, puis on les rend
 * explicitement aux éléments de navigation, qui sont aussi remontés au-dessus
 * du voile. Quitter une page lente doit toujours rester possible.
 */

html.nx-loading body > *:not(.nx-loader) {
  pointer-events: none;
  user-select: none;
}

html.nx-loading .sidebar,
html.nx-loading .navbar,
html.nx-loading header,
html.nx-loading [data-site-header],
html.nx-loading [data-site-footer],
html.nx-loading [data-nx-nav],
html.nx-loading .mobile-toggle,
html.nx-loading .sidebar-backdrop {
  pointer-events: auto;
  user-select: auto;
  position: relative;
  z-index: 9100;
}

/* La sidebar du panel staff est déjà positionnée : on ne fait qu'élever son
   plan, sans toucher à son `position: fixed`. */
html.nx-loading .sidebar { position: fixed; z-index: 9100; }

/* ── Voile par module ──────────────────────────────────────────────────── */

.nx-module-veil {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: inherit;
  background: color-mix(in srgb, var(--surface, #16181d) 78%, transparent);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: nx-module-in 180ms ease;
}

@keyframes nx-module-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.nx-module-loading {
  pointer-events: none;
  /* Hauteur plancher : un bloc encore vide ne doit pas s'effondrer à zéro,
     sinon la page saute au moment où le contenu arrive. */
  min-height: 120px;
}

.nx-module-veil--error {
  background: color-mix(in srgb, var(--surface, #16181d) 92%, transparent);
  pointer-events: auto;
}

.nx-module-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  text-align: center;
  padding: 1rem;
  font-size: 0.86rem;
  color: var(--text-muted, #9aa0a6);
}

/* ── Impression ────────────────────────────────────────────────────────── */
/* Une facture ou un devis ne doit jamais partir à l'imprimante avec un voile. */
@media print {
  .nx-loader,
  .nx-module-veil { display: none !important; }
  html.nx-loading body > * { pointer-events: auto !important; }
}
