/* ==========================================================================
   Global navigation loader
   --------------------------------------------------------------------------
   Two pieces that page-loader.js drives independently:

   1. .page-loader-bar  - a thin top progress bar, shown the instant a
                          navigation starts so the click feels acknowledged.
   2. .page-loader      - a full-screen brand overlay, shown only after the
                          navigation has taken longer than the JS threshold,
                          so fast pages never flash it.

   Both are inert (hidden, non-interactive) until .is-active is added, which
   keeps them harmless when JavaScript is unavailable.
   ========================================================================== */

/* --------------------------------------------------------------------------
   Top progress bar
   -------------------------------------------------------------------------- */
.page-loader-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0;
  z-index: 20001;
  border-radius: 0 3px 3px 0;
  background: linear-gradient(90deg,
      var(--brand-primary, #8A26A4) 0%,
      var(--brand-primary-dark, #48439F) 55%,
      var(--brand-accent-light, #FFB955) 100%);
  box-shadow: 0 0 10px rgba(138, 38, 164, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 200ms ease-out;
}

.page-loader-bar.is-active {
  opacity: 1;
  /* Creeps towards - but never reaches - 90%. The remaining 10% is only
     covered by .is-done, so the bar cannot look finished while the server is
     still thinking. */
  animation: page-loader-bar-creep 12s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

/* Applied just before the bar fades out, so it completes rather than
   vanishing mid-track. */
.page-loader-bar.is-done {
  width: 100%;
  animation: none;
  opacity: 0;
  transition: width 180ms ease-out, opacity 320ms ease-out 140ms;
}

@keyframes page-loader-bar-creep {
  0%   { width: 0; }
  12%  { width: 28%; }
  40%  { width: 62%; }
  70%  { width: 80%; }
  100% { width: 90%; }
}

/* --------------------------------------------------------------------------
   Full-screen overlay
   -------------------------------------------------------------------------- */
.page-loader {
  position: fixed;
  inset: 0;
  z-index: 20000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(248, 245, 252, 0.86);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 220ms ease-in-out, visibility 0s linear 220ms;
}

.page-loader.is-active {
  opacity: 1;
  visibility: visible;
  /* Swallow clicks while a navigation is in flight so the user cannot fire a
     second request on top of the one already running. */
  pointer-events: auto;
  transition: opacity 220ms ease-in-out, visibility 0s linear 0s;
}

.page-loader-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  transform: translateY(8px);
  transition: transform 260ms ease-out;
}

.page-loader.is-active .page-loader-panel {
  transform: translateY(0);
}

.page-loader-mark {
  position: relative;
  width: 96px;
  height: 96px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-loader-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  fill: none;
  transform-origin: 50% 50%;
  animation: page-loader-spin 1.15s linear infinite;
}

.page-loader-ring-track {
  stroke: var(--brand-border, #E7E1F5);
  stroke-width: 4;
}

.page-loader-ring-arc {
  stroke: var(--brand-primary, #8A26A4);
  stroke-width: 4;
  stroke-linecap: round;
  /* r=33 -> circumference ~207.3; a 52px dash leaves a quarter-circle arc. */
  stroke-dasharray: 52 156;
}

.page-loader-badge {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 12px;
  box-shadow: var(--brand-shadow-soft, 2px 2px 10px rgba(33, 29, 54, 0.08));
  animation: page-loader-pulse 1.6s ease-in-out infinite;
}

.page-loader-text {
  font-family: var(--font-body, "Inter", sans-serif);
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--brand-muted, #6E6683);
}

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

@keyframes page-loader-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.07); }
}

/* --------------------------------------------------------------------------
   Reduced motion: keep the loader, drop the movement.
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .page-loader-bar.is-active {
    width: 60%;
    animation: none;
  }

  .page-loader-bar.is-done {
    transition: opacity 200ms ease-out;
  }

  .page-loader-panel {
    transform: none;
  }

  .page-loader-ring {
    animation: none;
  }

  .page-loader-ring-arc {
    stroke-dasharray: none;
    opacity: 0.5;
  }

  .page-loader-badge {
    animation: none;
  }
}
