/* ════════════════════════════════════════════════════════════════════════════
   AUTH MASTERPIECE — World-Class Login Choreography
   Stage 1: PRESS    (tactile compression + click ripple)
   Stage 2: VERIFY   (button morph, shimmer, card scan-beam, field defocus)
   Stage 3a: SUCCESS (checkmark draw, gradient flash, particle burst, liftoff)
   Stage 3b: REJECT  (border flash, shake, clean revert)
   Author: PD / AI — 2026-04-23
   ════════════════════════════════════════════════════════════════════════════ */

:root {
  /* Premium easing curves */
  --auth-ease-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --auth-ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --auth-ease-snap: cubic-bezier(0.2, 0, 0, 1);
  --auth-ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);
  --auth-ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);

  /* Brand */
  --auth-mp-primary: #666cff;
  --auth-mp-primary-rgb: 102, 108, 255;
  --auth-mp-primary-deep: #4d54e8;
  --auth-mp-success: #10b981;
  --auth-mp-success-soft: #34d399;
  --auth-mp-error: #ef4444;
}

/* ─────────────────────────────────────────────────────────────────────────────
   BUTTON — Foundation that supports all states
   ───────────────────────────────────────────────────────────────────────────── */

.btn-primary {
  position: relative;
  isolation: isolate; /* contain pseudo-element layers */
  overflow: hidden;
  will-change: transform, box-shadow;
}

/* Inner content wrapper (added by JS) */
.btn-primary .auth-btn-content {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: relative;
  z-index: 2;
  transition:
    transform 280ms var(--auth-ease-smooth),
    opacity 200ms var(--auth-ease-smooth),
    letter-spacing 280ms var(--auth-ease-smooth);
}

/* Loading layer (3 traveling dots + label) — hidden by default */
.btn-primary .auth-btn-loading {
  position: absolute;
  inset: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 260ms var(--auth-ease-smooth) 0ms,
    transform 320ms var(--auth-ease-out-expo) 0ms;
  pointer-events: none;
  z-index: 3;
  color: #fff;
  font-weight: 600;
  letter-spacing: 0.6px;
  font-size: 0.92rem;
  text-transform: uppercase;
}

.btn-primary .auth-btn-loading-label {
  font-size: 0.82rem;
  letter-spacing: 1.4px;
  opacity: 0.92;
}

/* The pulsing "AI thinking" cluster */
.btn-primary .auth-btn-pulse {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.btn-primary .auth-btn-pulse span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.7);
  transform: scale(0.6);
  opacity: 0.5;
}

.btn-primary .auth-btn-pulse span:nth-child(1) { animation: authPulseDot 1.05s var(--auth-ease-smooth) -0.32s infinite; }
.btn-primary .auth-btn-pulse span:nth-child(2) { animation: authPulseDot 1.05s var(--auth-ease-smooth) -0.16s infinite; }
.btn-primary .auth-btn-pulse span:nth-child(3) { animation: authPulseDot 1.05s var(--auth-ease-smooth)  0s    infinite; }

@keyframes authPulseDot {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.45;
  }
  35% {
    transform: scale(1.25);
    opacity: 1;
  }
}

/* Success layer — checkmark SVG */
.btn-primary .auth-btn-success {
  position: absolute;
  inset: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.4) rotate(-12deg);
  transition:
    opacity 240ms var(--auth-ease-out-expo),
    transform 480ms var(--auth-ease-spring);
  pointer-events: none;
  z-index: 4;
}

.btn-primary .auth-btn-success svg {
  width: 30px;
  height: 30px;
  filter: drop-shadow(0 0 14px rgba(255, 255, 255, 0.9));
}

.btn-primary .auth-btn-success svg circle,
.btn-primary .auth-btn-success svg path {
  stroke: #ffffff;
  stroke-width: 3.5;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
}

/* Click ripple (created on press) */
.btn-primary .auth-btn-ripple {
  position: absolute;
  border-radius: 50%;
  pointer-events: none;
  background: radial-gradient(
    circle,
    rgba(255, 255, 255, 0.55) 0%,
    rgba(255, 255, 255, 0.25) 35%,
    transparent 70%
  );
  transform: translate(-50%, -50%) scale(0);
  opacity: 0.85;
  z-index: 1;
  animation: authRippleExpand 720ms var(--auth-ease-out-expo) forwards;
  mix-blend-mode: screen;
}

@keyframes authRippleExpand {
  0%   { transform: translate(-50%, -50%) scale(0);    opacity: 0.85; }
  60%  { opacity: 0.4; }
  100% { transform: translate(-50%, -50%) scale(7);    opacity: 0; }
}

/* Traveling shimmer stripe across button during VERIFY */
.btn-primary::after {
  content: '';
  position: absolute;
  top: 0;
  left: -120%;
  width: 60%;
  height: 100%;
  background: linear-gradient(
    100deg,
    transparent 0%,
    rgba(255, 255, 255, 0.0) 30%,
    rgba(255, 255, 255, 0.45) 50%,
    rgba(255, 255, 255, 0.0) 70%,
    transparent 100%
  );
  transform: skewX(-18deg);
  pointer-events: none;
  opacity: 0;
  z-index: 2;
  transition: opacity 200ms ease;
}

/* ─────────────────────────────────────────────────────────────────────────────
   STATE: PRESS (instant tactile feedback on mousedown)
   ───────────────────────────────────────────────────────────────────────────── */

.btn-primary.auth-press {
  transform: translateY(0) scale(0.97);
  transition: transform 120ms var(--auth-ease-snap);
  box-shadow:
    0 2px 6px rgba(var(--auth-mp-primary-rgb), 0.3),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
}

/* ─────────────────────────────────────────────────────────────────────────────
   STATE: VERIFY (loading, AI is checking)
   ───────────────────────────────────────────────────────────────────────────── */

.btn-primary.is-verifying {
  pointer-events: none;
  cursor: progress;
  background: linear-gradient(
    135deg,
    var(--auth-mp-primary) 0%,
    var(--auth-mp-primary-deep) 100%
  ) !important;
  box-shadow:
    0 8px 28px rgba(var(--auth-mp-primary-rgb), 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.22) !important;
}

.btn-primary.is-verifying .auth-btn-content {
  opacity: 0;
  transform: translateY(-6px) scale(0.94);
  letter-spacing: 2px;
}

.btn-primary.is-verifying .auth-btn-loading {
  opacity: 1;
  transform: translateY(0);
  transition-delay: 120ms;
}

.btn-primary.is-verifying::after {
  opacity: 1;
  animation: authShimmerSweep 1.6s linear infinite;
}

@keyframes authShimmerSweep {
  0%   { left: -120%; }
  100% { left: 220%; }
}

/* Outer breathing aura around the button while verifying */
.btn-primary.is-verifying::before {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: inherit;
  background: linear-gradient(
    135deg,
    rgba(var(--auth-mp-primary-rgb), 0.45),
    rgba(var(--auth-mp-primary-rgb), 0.15)
  );
  z-index: -1;
  filter: blur(20px);
  opacity: 0;
  animation: authButtonAura 2.4s ease-in-out 200ms infinite;
}

@keyframes authButtonAura {
  0%, 100% { opacity: 0.35; transform: scale(1); }
  50%      { opacity: 0.7;  transform: scale(1.04); }
}

/* ─────────────────────────────────────────────────────────────────────────────
   STATE: SUCCESS — checkmark draw + gradient flash + particle burst
   ───────────────────────────────────────────────────────────────────────────── */

.btn-primary.is-success {
  background: linear-gradient(
    135deg,
    var(--auth-mp-primary) 0%,
    #7c5cff 35%,
    var(--auth-mp-success) 100%
  ) !important;
  background-size: 180% 180%;
  animation: authSuccessGradient 900ms var(--auth-ease-out-expo) forwards;
  pointer-events: none;
  box-shadow:
    0 0 0 0 rgba(16, 185, 129, 0),
    0 14px 42px rgba(16, 185, 129, 0.45),
    inset 0 1px 0 rgba(255, 255, 255, 0.3) !important;
}

@keyframes authSuccessGradient {
  0%   { background-position: 0% 50%; }
  100% { background-position: 100% 50%; }
}

/* Hide both idle text and loading dots once success kicks in */
.btn-primary.is-success .auth-btn-content,
.btn-primary.is-success .auth-btn-loading {
  opacity: 0;
  transform: scale(0.85);
  transition: opacity 180ms ease, transform 240ms var(--auth-ease-smooth);
}

.btn-primary.is-success .auth-btn-success {
  opacity: 1;
  transform: scale(1) rotate(0);
}

.btn-primary.is-success .auth-btn-success svg circle {
  animation: authStrokeDraw 360ms var(--auth-ease-out-expo) 60ms forwards;
}

.btn-primary.is-success .auth-btn-success svg path {
  animation: authStrokeDraw 280ms var(--auth-ease-out-expo) 320ms forwards;
}

@keyframes authStrokeDraw {
  to { stroke-dashoffset: 0; }
}

/* Success ring radiating outward from the button */
.btn-primary.is-success::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid rgba(16, 185, 129, 0.5);
  opacity: 0;
  animation: authSuccessRing 900ms var(--auth-ease-out-expo) 80ms forwards;
  z-index: -1;
  pointer-events: none;
}

@keyframes authSuccessRing {
  0%   { transform: scale(1);    opacity: 0.9; }
  100% { transform: scale(1.45); opacity: 0; }
}

/* Particle burst container (positioned at button center by JS) */
.auth-burst {
  position: absolute;
  pointer-events: none;
  width: 0;
  height: 0;
  z-index: 5;
}

.auth-burst .auth-particle {
  position: absolute;
  top: 0;
  left: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--auth-mp-primary), var(--auth-mp-success));
  box-shadow:
    0 0 12px rgba(var(--auth-mp-primary-rgb), 0.8),
    0 0 4px rgba(255, 255, 255, 0.9);
  opacity: 1;
  transform: translate(-50%, -50%);
  animation: authParticleFly 900ms var(--auth-ease-out-expo) forwards;
}

@keyframes authParticleFly {
  0% {
    transform:
      translate(-50%, -50%)
      translate(0, 0)
      scale(0.4);
    opacity: 1;
  }
  60% {
    opacity: 1;
  }
  100% {
    transform:
      translate(-50%, -50%)
      translate(var(--p-x, 0), var(--p-y, 0))
      scale(0.2);
    opacity: 0;
  }
}

/* ─────────────────────────────────────────────────────────────────────────────
   STATE: REJECT — brief red border flash + revert
   ───────────────────────────────────────────────────────────────────────────── */

.btn-primary.is-reject {
  animation: authRejectFlash 520ms var(--auth-ease-smooth) forwards;
}

@keyframes authRejectFlash {
  0%   { box-shadow: 0 4px 15px rgba(var(--auth-mp-primary-rgb), 0.3); }
  20%  { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.45), 0 8px 22px rgba(239, 68, 68, 0.35); }
  100% { box-shadow: 0 4px 15px rgba(var(--auth-mp-primary-rgb), 0.3); }
}

/* ─────────────────────────────────────────────────────────────────────────────
   FORM FIELDS — gentle defocus during VERIFY
   ───────────────────────────────────────────────────────────────────────────── */

.is-authenticating .form-floating-outline,
.is-authenticating .form-password-toggle {
  transition:
    opacity 360ms var(--auth-ease-smooth),
    transform 360ms var(--auth-ease-smooth),
    filter 360ms var(--auth-ease-smooth);
  opacity: 0.55;
  transform: translateY(2px);
  filter: saturate(0.7);
  pointer-events: none;
}

.is-authenticating .form-check,
.is-authenticating .d-flex.justify-content-between {
  transition: opacity 320ms var(--auth-ease-smooth);
  opacity: 0.45;
  pointer-events: none;
}

/* Eye icon gently dims */
.is-authenticating .pd-password-toggle {
  transition: opacity 320ms var(--auth-ease-smooth);
  opacity: 0.4;
  pointer-events: none;
}

/* ─────────────────────────────────────────────────────────────────────────────
   CARD — Scan beam + verifying glow
   ───────────────────────────────────────────────────────────────────────────── */

.authentication-inner .card {
  position: relative;
  overflow: hidden;
}

/* Scan beam — runs ONCE per verify cycle */
.authentication-inner .card .auth-scan-beam {
  position: absolute;
  left: 0;
  right: 0;
  top: -100%;
  height: 28%;
  background: linear-gradient(
    180deg,
    transparent 0%,
    rgba(var(--auth-mp-primary-rgb), 0.0) 10%,
    rgba(var(--auth-mp-primary-rgb), 0.18) 50%,
    rgba(255, 255, 255, 0.55) 50%,
    rgba(var(--auth-mp-primary-rgb), 0.18) 50%,
    rgba(var(--auth-mp-primary-rgb), 0.0) 90%,
    transparent 100%
  );
  filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  z-index: 4;
  transform: translateY(0);
  mix-blend-mode: overlay;
}

.is-authenticating .card .auth-scan-beam {
  animation: authScanSweep 1.8s var(--auth-ease-out-quart) infinite;
}

@keyframes authScanSweep {
  0%   { top: -30%;  opacity: 0; }
  10%  { opacity: 1; }
  90%  { opacity: 1; }
  100% { top: 130%;  opacity: 0; }
}

/* Subtle inner glow on the card during verify */
.authentication-inner .card.is-verifying-card {
  box-shadow:
    0 8px 32px 0 rgba(31, 38, 135, 0.07),
    0 0 0 1px rgba(var(--auth-mp-primary-rgb), 0.18) inset,
    0 0 60px rgba(var(--auth-mp-primary-rgb), 0.18) !important;
  transition: box-shadow 360ms var(--auth-ease-smooth);
}

/* Card lift + glow on SUCCESS */
.authentication-inner .card.is-success-card {
  animation: authCardLiftoff 800ms var(--auth-ease-out-expo) forwards;
}

@keyframes authCardLiftoff {
  0% {
    transform: translateY(0) scale(1);
    box-shadow:
      0 8px 32px 0 rgba(31, 38, 135, 0.07),
      0 0 0 1px rgba(var(--auth-mp-primary-rgb), 0.18) inset,
      0 0 60px rgba(var(--auth-mp-primary-rgb), 0.18);
  }
  60% {
    transform: translateY(-10px) scale(1.018);
    box-shadow:
      0 24px 60px 0 rgba(16, 185, 129, 0.18),
      0 0 0 1px rgba(16, 185, 129, 0.3) inset,
      0 0 100px rgba(16, 185, 129, 0.32);
  }
  100% {
    transform: translateY(-6px) scale(1.012);
    box-shadow:
      0 16px 50px 0 rgba(16, 185, 129, 0.14),
      0 0 0 1px rgba(16, 185, 129, 0.22) inset,
      0 0 80px rgba(16, 185, 129, 0.22);
  }
}

/* Final fade-out before redirect */
.authentication-inner .card.is-departing {
  animation: authCardDepart 500ms var(--auth-ease-smooth) forwards;
}

@keyframes authCardDepart {
  0%   { opacity: 1; transform: translateY(-6px) scale(1.012); filter: blur(0); }
  100% { opacity: 0; transform: translateY(-22px) scale(0.985); filter: blur(6px); }
}

/* ─────────────────────────────────────────────────────────────────────────────
   AURORA INTENSIFIES — background reacts to auth states
   NOTE: existing .auth-orb-* runs `animation: float 10s ...` which animates
   `transform`. We avoid touching transform here to prevent fighting with the
   float loop; instead we lean on `filter` + `opacity` which compose cleanly.
   On SUCCESS we stop the float animation so we can set our own transform.
   ───────────────────────────────────────────────────────────────────────────── */

body.is-authenticating .auth-orb-1,
body.is-authenticating .auth-orb-2 {
  transition:
    filter 600ms var(--auth-ease-smooth),
    opacity 600ms var(--auth-ease-smooth);
  filter: blur(70px) brightness(1.25) saturate(1.15);
  opacity: 0.85;
}

body.is-success-flow .auth-orb-1 {
  animation: authOrbCelebrate1 1200ms var(--auth-ease-out-expo) forwards !important;
  background: rgba(16, 185, 129, 0.32) !important;
}

body.is-success-flow .auth-orb-2 {
  animation: authOrbCelebrate2 1400ms var(--auth-ease-out-expo) forwards !important;
  background: rgba(102, 108, 255, 0.28) !important;
}

@keyframes authOrbCelebrate1 {
  0%   { transform: translate(0, 0)    scale(1);    filter: blur(80px) brightness(1.25) saturate(1.15); opacity: 0.6; }
  60%  { transform: translate(20px, 30px) scale(1.18); filter: blur(60px) brightness(1.55); opacity: 1; }
  100% { transform: translate(20px, 30px) scale(1.12); filter: blur(60px) brightness(1.4);  opacity: 0.9; }
}

@keyframes authOrbCelebrate2 {
  0%   { transform: translate(0, 0)      scale(1);    filter: blur(80px) brightness(1.25) saturate(1.15); opacity: 0.6; }
  60%  { transform: translate(-25px, -20px) scale(1.22); filter: blur(70px) brightness(1.5); opacity: 1; }
  100% { transform: translate(-20px, -15px) scale(1.16); filter: blur(70px) brightness(1.35); opacity: 0.85; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   FOOTER "AI 🤖" — subtle thinking pulse during verify
   ───────────────────────────────────────────────────────────────────────────── */

.authentication-inner > footer p {
  transition: opacity 400ms var(--auth-ease-smooth);
}

.is-authenticating > footer p {
  opacity: 1;
  animation: authFooterThink 1.6s ease-in-out infinite;
}

@keyframes authFooterThink {
  0%, 100% { opacity: 0.6; text-shadow: 0 0 0 transparent; }
  50%      { opacity: 1;   text-shadow: 0 0 12px rgba(var(--auth-mp-primary-rgb), 0.45); }
}

/* ─────────────────────────────────────────────────────────────────────────────
   LOGO & HEADING — react during verify
   ───────────────────────────────────────────────────────────────────────────── */

.is-authenticating .app-brand-link img {
  transition: filter 600ms var(--auth-ease-smooth), transform 800ms var(--auth-ease-smooth);
  filter: saturate(1.1) brightness(1.02);
  transform: translateY(-1px);
}

.is-success-flow .app-brand-link img {
  animation: authLogoCelebrate 700ms var(--auth-ease-spring) forwards;
}

@keyframes authLogoCelebrate {
  0%   { transform: translateY(-1px) scale(1); }
  40%  { transform: translateY(-3px) scale(1.04); }
  100% { transform: translateY(-2px) scale(1.02); }
}

.is-authenticating .card-body h5 {
  transition: opacity 400ms var(--auth-ease-smooth), transform 400ms var(--auth-ease-smooth), letter-spacing 600ms var(--auth-ease-smooth);
  opacity: 0.8;
  transform: translateY(-1px);
  letter-spacing: 0.4px;
}

/* ─────────────────────────────────────────────────────────────────────────────
   PAGE OVERLAY — subtle "lifting" gradient while redirecting
   ───────────────────────────────────────────────────────────────────────────── */

.auth-portal-veil {
  position: fixed;
  inset: 0;
  background: radial-gradient(
    ellipse at 50% 50%,
    rgba(255, 255, 255, 0.7) 0%,
    rgba(245, 247, 255, 0.85) 40%,
    rgba(232, 236, 255, 0.95) 100%
  );
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  transition: opacity 380ms var(--auth-ease-smooth);
}

.auth-portal-veil.is-active {
  opacity: 1;
}

/* ─────────────────────────────────────────────────────────────────────────────
   ACCESSIBILITY — respect prefers-reduced-motion
   ───────────────────────────────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  .btn-primary .auth-btn-content,
  .btn-primary .auth-btn-loading,
  .btn-primary .auth-btn-success,
  .btn-primary .auth-btn-pulse span,
  .btn-primary .auth-btn-success svg circle,
  .btn-primary .auth-btn-success svg path,
  .btn-primary::after,
  .btn-primary::before,
  .btn-primary,
  .auth-burst .auth-particle,
  .authentication-inner .card,
  .authentication-inner .card .auth-scan-beam,
  .auth-portal-veil,
  body.is-authenticating .auth-orb-1,
  body.is-authenticating .auth-orb-2,
  .is-authenticating .form-floating-outline,
  .is-authenticating .form-password-toggle,
  .is-authenticating > footer p,
  .is-authenticating .card-body h5,
  .is-authenticating .app-brand-link img {
    transition-duration: 100ms !important;
    animation-duration: 100ms !important;
    animation-iteration-count: 1 !important;
  }

  /* Skip particle burst entirely for reduced motion */
  .auth-burst { display: none !important; }
}

/* ─────────────────────────────────────────────────────────────────────────────
   MOBILE TUNING
   ───────────────────────────────────────────────────────────────────────────── */

@media (max-width: 576px) {
  .btn-primary .auth-btn-loading-label { font-size: 0.78rem; letter-spacing: 1.2px; }
  .btn-primary .auth-btn-success svg { width: 26px; height: 26px; }

  /* Lighter blur on mobile for performance */
  body.is-authenticating .auth-orb-1,
  body.is-authenticating .auth-orb-2 {
    filter: blur(50px) brightness(1.2) saturate(1.1);
  }
}
