/* ════════════════════════════════════════════════════════════════════════════
   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 — drawn checkmark + "OTWIERAM PANEL" label. */
.btn-primary .auth-btn-success {
  position: absolute;
  inset: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(6px);
  transition:
    opacity 220ms var(--auth-ease-smooth),
    transform 320ms var(--auth-ease-out-expo);
  pointer-events: none;
  z-index: 4;
  color: #fff;
  font-weight: 600;
  font-size: 0.86rem;
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.btn-primary .auth-btn-success-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.btn-primary .auth-btn-success-icon svg {
  width: 22px;
  height: 22px;
  display: block;
  filter: drop-shadow(0 0 8px rgba(255, 255, 255, 0.45));
}

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

.btn-primary .auth-btn-success-label {
  white-space: nowrap;
}

/* 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 — minimal, in-brand acknowledgment
   No emerald gradient. No expanding rings. No halo. Just: the button gently
   brightens to a lighter purple, the loading layer fades out, the success
   label fades in with a small drawn checkmark. The card itself does the
   heavy lifting (blur-out departure further down).
   ───────────────────────────────────────────────────────────────────────────── */

.btn-primary.is-success {
  pointer-events: none;
  background: linear-gradient(
    135deg,
    #7c5cff 0%,
    #8e74ff 100%
  ) !important;
  box-shadow:
    0 8px 28px rgba(var(--auth-mp-primary-rgb), 0.42),
    inset 0 1px 0 rgba(255, 255, 255, 0.32) !important;
  transition:
    background 320ms var(--auth-ease-smooth),
    box-shadow 320ms var(--auth-ease-smooth) !important;
}

/* 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: translateY(-6px);
  transition: opacity 180ms ease, transform 240ms var(--auth-ease-smooth);
}

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

/* Stroke-draw the inline checkmark in two beats: circle then path */
.btn-primary.is-success .auth-btn-success-icon svg circle {
  animation: authStrokeDraw 320ms var(--auth-ease-out-expo) 200ms forwards;
}

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

@keyframes authStrokeDraw {
  to { stroke-dashoffset: 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 on SUCCESS — almost no animation, just a tiny breath that signals
   "OK, locked in" without competing with the button's success label.
   This is intentionally subtle because the DEPARTURE (next block) is the
   real moment of theater. */
.authentication-inner .card.is-success-card {
  animation: authCardSettle 360ms var(--auth-ease-smooth) forwards;
}

@keyframes authCardSettle {
  0%   { transform: translateY(0)      scale(1); }
  100% { transform: translateY(-2px)   scale(1.005); }
}

/* DEPARTURE — the hero moment. Card blurs out, scales down (recedes),
   lifts, fades. Feels like the card is melting into the page as the panel
   takes over. Long, deliberate, single sweep. */
.authentication-inner .card.is-departing {
  animation: authCardDepart 800ms cubic-bezier(0.32, 0, 0.4, 1) forwards;
  pointer-events: none;
}

@keyframes authCardDepart {
  0% {
    opacity: 1;
    transform: translateY(-2px)  scale(1.005);
    filter: blur(0);
  }
  35% {
    opacity: 0.92;
    transform: translateY(-12px) scale(0.99);
    filter: blur(4px);
  }
  100% {
    opacity: 0;
    transform: translateY(-44px) scale(0.92);
    filter: blur(18px);
  }
}

/* Footer departs in sync with the card so the whole composition lifts away */
.is-departing-flow .authentication-inner > footer {
  animation: authFooterDepart 700ms cubic-bezier(0.32, 0, 0.4, 1) 80ms forwards;
}

@keyframes authFooterDepart {
  0%   { opacity: 0.7; transform: translateY(0)    scale(1);    filter: blur(0); }
  100% { opacity: 0;   transform: translateY(-20px) scale(0.96); filter: blur(8px); }
}

/* ─────────────────────────────────────────────────────────────────────────────
   AURORA — only intensifies during VERIFY, stays calm on SUCCESS.
   On SUCCESS we deliberately do NOT animate the orbs — the card's blur-out
   departure becomes the single hero moment, and the orbs continue their
   ambient float so the page background stays calm and "still alive".
   ───────────────────────────────────────────────────────────────────────────── */

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.2) saturate(1.1);
  opacity: 0.8;
}

/* On success we soften the orbs back down so the card is the only focal point */
body.is-success-flow .auth-orb-1,
body.is-success-flow .auth-orb-2 {
  transition:
    filter 700ms var(--auth-ease-smooth),
    opacity 700ms var(--auth-ease-smooth);
  filter: blur(80px) brightness(1.05) saturate(1);
  opacity: 0.5;
}

/* ─────────────────────────────────────────────────────────────────────────────
   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 only during verify (no celebratory bounce on success)
   ───────────────────────────────────────────────────────────────────────────── */

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

.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;
}

/* ─────────────────────────────────────────────────────────────────────────────
   PORTAL VEIL — soft in-brand wash that rises while card melts away.
   Slightly purple-tinted (matches aurora background), longer fade so it feels
   like a cinematic dissolve rather than a hard cut.
   ───────────────────────────────────────────────────────────────────────────── */

.auth-portal-veil {
  position: fixed;
  inset: 0;
  background: radial-gradient(
    ellipse at 50% 50%,
    rgba(247, 248, 255, 0.7) 0%,
    rgba(238, 241, 255, 0.88) 45%,
    rgba(225, 230, 252, 0.96) 100%
  );
  backdrop-filter: blur(24px) saturate(140%);
  -webkit-backdrop-filter: blur(24px) saturate(140%);
  opacity: 0;
  pointer-events: none;
  z-index: 9999;
  transition: opacity 600ms 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-icon svg circle,
  .btn-primary .auth-btn-success-icon svg path,
  .btn-primary::after,
  .btn-primary::before,
  .btn-primary,
  .authentication-inner .card,
  .authentication-inner .card .auth-scan-beam,
  .auth-portal-veil,
  body.is-authenticating .auth-orb-1,
  body.is-authenticating .auth-orb-2,
  body.is-success-flow .auth-orb-1,
  body.is-success-flow .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;
  }
}

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

@media (max-width: 576px) {
  .btn-primary .auth-btn-loading-label,
  .btn-primary .auth-btn-success { font-size: 0.74rem; letter-spacing: 1px; }
  .btn-primary .auth-btn-success-icon,
  .btn-primary .auth-btn-success-icon svg { width: 18px; height: 18px; }
  .btn-primary .auth-btn-success { gap: 8px; }

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