/* ============================================================
   loader.css — OPTLYX NEOBRUTALIST LOGO LOADER
   Animated orbit + breathing logo + particles
   ============================================================ */

:root {
  --ink: #0d0d0d;
  --paper: #f5f0e8;
  --cream: #fffdf7;
  --yellow: #fef9c3;
  --muted: #78716c;
  --stone: #e7e0d3;
  --success: #16a34a;
  --error: #dc2626;
}

/* ========== WRAPPER ========== */
.jarvis-loader-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  min-height: 200px;
  font-family: 'Plus Jakarta Sans', -apple-system, sans-serif;
  box-sizing: border-box;
}

.jarvis-loader-wrapper.overlay {
  position: absolute;
  inset: 0;
  z-index: 9999;
  background: rgba(245, 240, 232, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-radius: 0;
}

/* ========== LOGO CONTAINER ========== */
.optlyx-loader-container {
  position: relative;
  width: 168px;
  height: 168px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===================================================================
   CONIC GRADIENT RING — Dual-layer spinning arc
   =================================================================== */
.optlyx-loader-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  padding: 2.5px;
  background: conic-gradient(
    from var(--ring-angle, 0deg),
    transparent 0deg,
    var(--ink) 30deg,
    var(--muted) 90deg,
    var(--stone) 150deg,
    var(--yellow) 200deg,
    transparent 240deg
  );
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2.5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 2.5px), #000 calc(100% - 2.5px));
  animation: ringSpin 1.6s linear infinite;
}

/* Secondary ring — counter-rotating */
.optlyx-loader-ring::before {
  content: '';
  position: absolute;
  inset: -5px;
  border-radius: 50%;
  padding: 1.5px;
  background: conic-gradient(
    from 180deg,
    transparent 0deg,
    rgba(13, 13, 13, 0.3) 40deg,
    rgba(120, 113, 108, 0.15) 80deg,
    transparent 120deg
  );
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 1.5px), #000 calc(100% - 1.5px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 1.5px), #000 calc(100% - 1.5px));
  animation: ringSpinReverse 2.4s linear infinite;
}

/* Glow halo */
.optlyx-loader-ring::after {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  background: conic-gradient(
    from 0deg,
    rgba(13, 13, 13, 0.08),
    rgba(120, 113, 108, 0.06),
    rgba(231, 224, 211, 0.06),
    transparent,
    rgba(13, 13, 13, 0.08)
  );
  filter: blur(10px);
  animation: ringSpin 3s linear infinite;
  z-index: -1;
}

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

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

/* ===================================================================
   LOGO — Center, breathing
   =================================================================== */
.optlyx-loader-logo {
  position: relative;
  width: 92px;
  height: 92px;
  z-index: 2;
  animation: logoBreathe 2.4s ease-in-out infinite;
  filter: drop-shadow(2px 2px 0 var(--ink));
}

.optlyx-loader-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

@keyframes logoBreathe {
  0%,
  100% {
    transform: scale(1);
    filter: drop-shadow(2px 2px 0 var(--ink));
  }

  50% {
    transform: scale(1.1);
    filter: drop-shadow(4px 4px 0 var(--ink));
  }
}

/* Shimmer sweep */
.optlyx-loader-logo::after {
  content: '';
  position: absolute;
  inset: -6px;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 253, 247, 0.55) 50%, transparent 65%);
  animation: shimmerSweep 2.4s ease-in-out infinite;
  border-radius: 0;
  pointer-events: none;
}

@keyframes shimmerSweep {
  0% {
    transform: translateX(-150%);
  }

  45% {
    transform: translateX(150%);
  }

  100% {
    transform: translateX(150%);
  }
}

/* ===================================================================
   FLOATING PARTICLES — 3 orbit layers at different depths
   =================================================================== */
.optlyx-loader-particles {
  position: absolute;
  border-radius: 50%;
}

.optlyx-loader-particles span {
  position: absolute;
  border-radius: 0;
}

/* ---- INNER ORBIT (4 dots, 90 apart) ---- */
.orbit-inner {
  inset: 6px;
  animation: ringSpin 4s linear infinite;
}

.orbit-inner span {
  width: 3px;
  height: 3px;
  animation: particlePulse 1.8s ease-in-out infinite;
}

/*  0 */
.orbit-inner span:nth-child(1) {
  top: 0%;
  left: calc(50% - 1.5px);
  background: var(--ink);
  animation-delay: 0s;
}

/* 90 */
.orbit-inner span:nth-child(2) {
  top: calc(50% - 1.5px);
  right: 0%;
  background: var(--muted);
  animation-delay: 0.45s;
}

/*180 */
.orbit-inner span:nth-child(3) {
  bottom: 0%;
  left: calc(50% - 1.5px);
  background: var(--stone);
  animation-delay: 0.9s;
}

/*270 */
.orbit-inner span:nth-child(4) {
  top: calc(50% - 1.5px);
  left: 0%;
  background: var(--ink);
  animation-delay: 1.35s;
}

/* ---- MID ORBIT (6 dots, 60 apart) ---- */
.orbit-mid {
  inset: -10px;
  animation: ringSpinReverse 6s linear infinite;
}

.orbit-mid span {
  width: 4.5px;
  height: 4.5px;
  animation: particlePulse 2.2s ease-in-out infinite;
}

/*  0 */
.orbit-mid span:nth-child(1) {
  top: 0%;
  left: calc(50% - 2.25px);
  background: var(--ink);
  animation-delay: 0s;
}

/* 60 */
.orbit-mid span:nth-child(2) {
  top: 25%;
  left: calc(93.3% - 2.25px);
  background: var(--muted);
  animation-delay: 0.36s;
}

/*120 */
.orbit-mid span:nth-child(3) {
  top: 75%;
  left: calc(93.3% - 2.25px);
  background: var(--stone);
  animation-delay: 0.72s;
}

/*180 */
.orbit-mid span:nth-child(4) {
  bottom: 0%;
  left: calc(50% - 2.25px);
  background: var(--yellow);
  animation-delay: 1.08s;
}

/*240 */
.orbit-mid span:nth-child(5) {
  top: 75%;
  left: calc(6.7% - 2.25px);
  background: var(--ink);
  animation-delay: 1.44s;
}

/*300 */
.orbit-mid span:nth-child(6) {
  top: 25%;
  left: calc(6.7% - 2.25px);
  background: var(--muted);
  animation-delay: 1.8s;
}

/* ---- OUTER ORBIT (8 dots, 45 apart) ---- */
.orbit-outer {
  inset: -28px;
  animation: ringSpin 10s linear infinite;
}

.orbit-outer span {
  width: 3.5px;
  height: 3.5px;
  opacity: 0.5;
  animation: particlePulseOuter 3s ease-in-out infinite;
}

/*  0  */
.orbit-outer span:nth-child(1) {
  top: 0%;
  left: calc(50% - 1.75px);
  background: var(--stone);
  animation-delay: 0s;
}

/* 45  */
.orbit-outer span:nth-child(2) {
  top: 14.6%;
  left: calc(85.4% - 1.75px);
  background: var(--muted);
  animation-delay: 0.38s;
}

/* 90  */
.orbit-outer span:nth-child(3) {
  top: calc(50% - 1.75px);
  right: 0%;
  background: var(--ink);
  animation-delay: 0.75s;
}

/*135  */
.orbit-outer span:nth-child(4) {
  top: 85.4%;
  left: calc(85.4% - 1.75px);
  background: var(--stone);
  animation-delay: 1.12s;
}

/*180  */
.orbit-outer span:nth-child(5) {
  bottom: 0%;
  left: calc(50% - 1.75px);
  background: var(--yellow);
  animation-delay: 1.5s;
}

/*225  */
.orbit-outer span:nth-child(6) {
  top: 85.4%;
  left: calc(14.6% - 1.75px);
  background: var(--yellow);
  animation-delay: 1.88s;
}

/*270  */
.orbit-outer span:nth-child(7) {
  top: calc(50% - 1.75px);
  left: 0%;
  background: var(--ink);
  animation-delay: 2.25s;
}

/*315  */
.orbit-outer span:nth-child(8) {
  top: 14.6%;
  left: calc(14.6% - 1.75px);
  background: var(--stone);
  animation-delay: 2.62s;
}

@keyframes particlePulse {
  0%,
  100% {
    transform: scale(0.6);
    opacity: 0.25;
  }

  50% {
    transform: scale(1.5);
    opacity: 1;
  }
}

@keyframes particlePulseOuter {
  0%,
  100% {
    transform: scale(0.5);
    opacity: 0.15;
  }

  50% {
    transform: scale(1.3);
    opacity: 0.6;
  }
}

/* ===================================================================
   PAGE TRANSITION LOADER
   Logo + scanner + status ticker
   =================================================================== */
.google-spinner-overlay {
  position: fixed;
  inset: 0;
  background: rgba(245, 240, 232, 0.98);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.google-spinner-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* -- Launch screen wrapper -- */
.prisma-launch-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Logo */
.prisma-launch-logo {
  width: 152px;
  height: 152px;
  object-fit: contain;
  display: block;
  margin-bottom: 30px;
  animation: prismaLogoBreath 2.6s ease-in-out infinite;
}

@keyframes prismaLogoBreath {
  0%,
  100% {
    opacity: 0.65;
  }

  50% {
    opacity: 1;
  }
}

/* Laser scan line */
.prisma-launch-scanner {
  width: 120px;
  height: 2px;
  background: var(--stone);
  border-radius: 0;
  position: relative;
  overflow: hidden;
  margin-bottom: 20px;
}

.prisma-launch-scanner::after {
  content: '';
  position: absolute;
  inset-block: 0;
  left: 0;
  width: 45%;
  background: var(--ink);
  will-change: transform;
  animation: prismaLaserScan 1.7s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes prismaLaserScan {
  0% {
    transform: translateX(-100%);
  }

  100% {
    transform: translateX(222%);
  }
}

/* Status ticker — 5 items x 1.8s = 9s cycle */
.prisma-launch-ticker {
  position: relative;
  height: 13px;
  width: 240px;
}

.prisma-tick-item {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  will-change: transform, opacity;
  font-family: 'Inter Tight', -apple-system, sans-serif;
  font-size: 9.5px;
  font-weight: 800;
  color: var(--muted);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
  animation: prismaTickShow 9s ease-in-out infinite;
}

@keyframes prismaTickShow {
  0% {
    opacity: 0;
    transform: translateY(4px);
  }

  4% {
    opacity: 1;
    transform: translateY(0);
  }

  17% {
    opacity: 1;
    transform: translateY(0);
  }

  20% {
    opacity: 0;
    transform: translateY(-4px);
  }

  20.01%,
  100% {
    opacity: 0;
    transform: translateY(4px);
  }
}

/* ===================================================================
   ICON CAROUSEL — accountant icons cycle one at a time
   6 icons x 1.5s each = 9s total cycle
   =================================================================== */
.loader-icon-carousel {
  position: relative;
  height: 44px;
  width: 220px;
  margin-top: 22px;
  margin-bottom: 4px;
}

.loader-icon-item {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(6px);
  will-change: opacity, transform;
  animation: iconCycleShow 9s ease-in-out infinite;
}

/* Colored icon chip */
.loader-icon-chip {
  width: 32px;
  height: 32px;
  border-radius: 0;
  border: 2px solid var(--ink);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 2px 2px 0 var(--ink);
}

.loader-icon-item span {
  font-family: 'Inter Tight', -apple-system, sans-serif;
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  white-space: nowrap;
}

@keyframes iconCycleShow {
  /* Visible window: 0%-16.67% (1.5s out of 9s) */
  0% {
    opacity: 0;
    transform: translateY(6px);
  }

  3.3% {
    opacity: 1;
    transform: translateY(0);
  }

  13.3% {
    opacity: 1;
    transform: translateY(0);
  }

  16.67% {
    opacity: 0;
    transform: translateY(-5px);
  }

  16.68%,
  100% {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ========== TEXT ========== */
.jarvis-text {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: 0;
  animation: fadeInUp 0.6s ease-out 0.4s forwards;
}

.loader-title {
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
}

.loader-sub {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

/* ========== UTILITY ANIMATIONS ========== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.animate-fade-in {
  animation: fadeIn 0.3s ease-out forwards;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

/* ===================================================================
   PRISMA IN-PAGE LOADER
   Loading indicator for data/content loading inside pages.
   =================================================================== */
.prisma-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 40px 24px;
  animation: prismaFadeIn 0.4s ease-out;
}

.prisma-loader-spinner {
  position: relative;
  width: 40px;
  height: 40px;
}

.prisma-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2.5px solid var(--stone);
  border-top-color: var(--ink);
  animation: prismaRotate 0.9s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.prisma-ring-inner {
  inset: 5px;
  border-color: var(--paper);
  border-top-color: var(--muted);
  animation-duration: 1.4s;
  animation-direction: reverse;
}

.prisma-loader-text {
  font-family: 'Inter Tight', -apple-system, sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  position: relative;
  overflow: hidden;
}

/* Shimmer text effect */
.prisma-loader-text::after {
  content: '';
  position: absolute;
  inset: -2px;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 253, 247, 0.7) 50%, transparent 100%);
  animation: prismaTextShimmer 2s ease-in-out infinite;
  pointer-events: none;
}

/* Compact variant */
.prisma-loader.compact {
  flex-direction: row;
  gap: 10px;
  padding: 16px;
}

.prisma-loader.compact .prisma-loader-spinner {
  width: 20px;
  height: 20px;
}

.prisma-loader.compact .prisma-ring {
  border-width: 2px;
}

.prisma-loader.compact .prisma-ring-inner {
  inset: 3px;
}

.prisma-loader.compact .prisma-loader-text {
  font-size: 11px;
}

.prisma-loader.compact .prisma-loader-text::after {
  display: none;
}

/* Large variant — for full-page or modal use */
.prisma-loader.large {
  padding: 60px 24px;
}

.prisma-loader.large .prisma-loader-spinner {
  width: 52px;
  height: 52px;
}

.prisma-loader.large .prisma-ring {
  border-width: 3px;
}

.prisma-loader.large .prisma-ring-inner {
  inset: 7px;
}

.prisma-loader.large .prisma-loader-text {
  font-size: 13px;
  margin-top: 4px;
}

/* Pulsing dots variant */
.prisma-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.prisma-dots span {
  width: 6px;
  height: 6px;
  border-radius: 0;
  background: var(--ink);
  animation: prismaDotPulse 1.4s ease-in-out infinite;
}

.prisma-dots span:nth-child(2) {
  animation-delay: 0.16s;
}

.prisma-dots span:nth-child(3) {
  animation-delay: 0.32s;
}

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

@keyframes prismaFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes prismaTextShimmer {
  0% {
    transform: translateX(-100%);
  }

  50% {
    transform: translateX(100%);
  }

  100% {
    transform: translateX(100%);
  }
}

@keyframes prismaDotPulse {
  0%,
  80%,
  100% {
    transform: scale(0.4);
    opacity: 0.3;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ──────────────────────────────────────────────────────────────────────────
   Text loader stile OpenAI — gemello vanilla del React <TextLoader>.
   Classi `prisma-tl-*` IDENTICHE a scadenziario-app/src/components/shared/
   TextLoader.tsx, così shell e micro-app condividono lo stesso look.
   `.prisma-fs-loader` lo monta a tutto schermo (overlay) su boot e cambio pagina.
   ────────────────────────────────────────────────────────────────────────── */
@keyframes prisma-tl-shimmer {
  0%   { background-position: 140% 0; }
  100% { background-position: -40% 0; }
}
@keyframes prisma-tl-cycle {
  0%        { opacity: 0; transform: translate(-50%, calc(-50% + 5px)); }
  3%        { opacity: 1; transform: translate(-50%, -50%); }
  17%       { opacity: 1; transform: translate(-50%, -50%); }
  20%, 100% { opacity: 0; transform: translate(-50%, calc(-50% - 5px)); }
}
.prisma-tl { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; width: 100%; }
.prisma-tl-text { position: relative; height: 1.6em; }

/* Mark premium: anello sottile a coda sfumata che ruota fluido, su un alone
   verde tenue che "respira" — profondità raffinata, niente glow vistoso. */
.prisma-tl-mark { position: relative; display: grid; place-items: center; }
.prisma-tl-mark::before {
  content: ''; position: absolute; width: 64px; height: 64px; border-radius: 50%;
  background: radial-gradient(circle, rgba(25, 195, 125, 0.13), rgba(25, 195, 125, 0) 68%);
  animation: prisma-tl-breathe 3s ease-in-out infinite;
}
.prisma-tl-ring {
  width: 30px; height: 30px; border-radius: 50%;
  background: conic-gradient(from 90deg, rgba(20, 22, 26, 0) 6%, #14161a 100%);
  -webkit-mask: radial-gradient(farthest-side, #0000 calc(100% - 2.5px), #000 calc(100% - 2.5px));
          mask: radial-gradient(farthest-side, #0000 calc(100% - 2.5px), #000 calc(100% - 2.5px));
  animation: prisma-tl-spin 0.9s linear infinite;
}
@keyframes prisma-tl-spin { to { transform: rotate(360deg); } }
@keyframes prisma-tl-breathe {
  0%, 100% { transform: scale(0.82); opacity: 0.45; }
  50%      { transform: scale(1.12); opacity: 0.9; }
}

/* Entrata in stagger: prima il mark, poi il testo — salita + dissolvenza. */
@keyframes prisma-tl-rise {
  0%   { opacity: 0; transform: translateY(7px); }
  100% { opacity: 1; transform: translateY(0); }
}
.prisma-fs-loader .prisma-tl-mark { animation: prisma-tl-rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.04s both; }
.prisma-fs-loader .prisma-tl-text { animation: prisma-tl-rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.16s both; }
.prisma-tl-text > span {
  position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  white-space: nowrap;
  font-family: 'Inter Tight', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px; font-weight: 800; letter-spacing: 0.01em;
  opacity: 0;
  background: linear-gradient(100deg, #b4b9c1 0%, #b4b9c1 38%, #14161a 50%, #b4b9c1 62%, #b4b9c1 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  animation: prisma-tl-cycle 12.5s linear infinite, prisma-tl-shimmer 2.4s linear infinite;
}

/* Overlay a tutto schermo. Agganciato a <html> (non a <body>, che resta
   display:none fino al via libera dell'auth) così è visibile già al primo boot. */
.prisma-fs-loader {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.34s ease, transform 0.34s cubic-bezier(0.4, 0, 0.2, 1);
}
/* Uscita: leggero zoom-in + dissolvenza → sensazione di "entrare" nella pagina. */
.prisma-fs-loader.is-hiding { opacity: 0; transform: scale(1.02); }

/* Barra di progresso in cima alla pagina, stile LinkedIn (NProgress-like):
   parte da sinistra, avanza con trickle indeterminato e scatta al 100% a fine
   load. Sopra l'overlay testo (z-index più alto) così resta sempre visibile. */
.prisma-topbar {
  position: fixed;
  top: 0;
  left: 0;
  height: 2px;
  width: 0;
  z-index: 100000;
  overflow: hidden;
  background: linear-gradient(90deg, #15a36b 0%, #19c37d 60%, #34d39b 100%);
  opacity: 1;
  transition: width 0.2s ease, opacity 0.45s ease;
}
/* Scia di luce che scorre dentro la barra — tocco premium, clippata alla larghezza. */
.prisma-topbar::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0; width: 55%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  animation: prisma-topbar-sheen 1.5s ease-in-out infinite;
}
@keyframes prisma-topbar-sheen {
  0%   { transform: translateX(-130%); }
  100% { transform: translateX(330%); }
}
.prisma-topbar.is-done { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .prisma-tl-text > span {
    animation: prisma-tl-cycle 12.5s linear infinite;
    background: none;
    -webkit-text-fill-color: #5b6068; color: #5b6068;
  }
  .prisma-tl-ring { animation: none; }
  .prisma-tl-mark::before { animation: none; opacity: 0.5; }
  .prisma-fs-loader .prisma-tl-mark,
  .prisma-fs-loader .prisma-tl-text { animation: none; }
}
