/* ========================================================================
   AST-326 Animations
   Source: AST-326 Dashboard Comp (dashboard-comp.html)
   Updated: AST-212 — Viewport edge cases, reduced-motion, GPU hints
   ======================================================================== */

/* ---- Keyframes ---- */

@keyframes ast-fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes ast-fade-in-up {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes ast-fade-in-scale {
  from { opacity: 0; transform: scale(0.97); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes ast-slide-in-right {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

@keyframes ast-page-enter {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

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

@keyframes ast-skeleton-pulse {
  0%   { opacity: 1; }
  50%  { opacity: 0.4; }
  100% { opacity: 1; }
}

@keyframes ast-skeleton-shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ---- Shell Entry Animation ---- */

.ast-shell {
  animation: ast-fade-in 0.3s var(--ease-out);
  will-change: opacity, transform;
}

/* ---- Page Enter Animation ---- */

.ast-page-enter {
  animation: ast-page-enter 0.4s var(--ease-out);
  will-change: opacity, transform;
}

/* ---- Card Stagger Animation ---- */

.ast-card-stagger > .ast-card,
.ast-card-stagger > .status-grid-card,
.ast-card-stagger > [class*="ast-card"] {
  opacity: 0;
  will-change: opacity, transform;
  animation: ast-fade-in-up 0.4s var(--ease-out) forwards;
}

.ast-card-stagger > *:nth-child(1)  { animation-delay: calc(var(--motion-duration-stagger, 0.05s) * 1); }
.ast-card-stagger > *:nth-child(2)  { animation-delay: calc(var(--motion-duration-stagger, 0.05s) * 2); }
.ast-card-stagger > *:nth-child(3)  { animation-delay: calc(var(--motion-duration-stagger, 0.05s) * 3); }
.ast-card-stagger > *:nth-child(4)  { animation-delay: calc(var(--motion-duration-stagger, 0.05s) * 4); }
.ast-card-stagger > *:nth-child(5)  { animation-delay: calc(var(--motion-duration-stagger, 0.05s) * 5); }
.ast-card-stagger > *:nth-child(6)  { animation-delay: calc(var(--motion-duration-stagger, 0.05s) * 6); }
.ast-card-stagger > *:nth-child(7)  { animation-delay: calc(var(--motion-duration-stagger, 0.05s) * 7); }
.ast-card-stagger > *:nth-child(8)  { animation-delay: calc(var(--motion-duration-stagger, 0.05s) * 8); }
.ast-card-stagger > *:nth-child(9)  { animation-delay: calc(var(--motion-duration-stagger, 0.05s) * 9); }
.ast-card-stagger > *:nth-child(10) { animation-delay: calc(var(--motion-duration-stagger, 0.05s) * 10); }
.ast-card-stagger > *:nth-child(11) { animation-delay: calc(var(--motion-duration-stagger, 0.05s) * 11); }
.ast-card-stagger > *:nth-child(12) { animation-delay: calc(var(--motion-duration-stagger, 0.05s) * 12); }

/* ---- List Row Stagger (for tables, journal lists, etc.) ---- */

.ast-row-stagger > * {
  opacity: 0;
  will-change: opacity, transform;
  animation: ast-fade-in 0.3s var(--ease-out) forwards;
}
.ast-row-stagger > *:nth-child(1)  { animation-delay: 0.02s; }
.ast-row-stagger > *:nth-child(2)  { animation-delay: 0.04s; }
.ast-row-stagger > *:nth-child(3)  { animation-delay: 0.06s; }
.ast-row-stagger > *:nth-child(4)  { animation-delay: 0.08s; }
.ast-row-stagger > *:nth-child(5)  { animation-delay: 0.10s; }
.ast-row-stagger > *:nth-child(6)  { animation-delay: 0.12s; }
.ast-row-stagger > *:nth-child(7)  { animation-delay: 0.14s; }
.ast-row-stagger > *:nth-child(8)  { animation-delay: 0.16s; }
.ast-row-stagger > *:nth-child(9)  { animation-delay: 0.18s; }
.ast-row-stagger > *:nth-child(10) { animation-delay: 0.20s; }

/* ---- Skeleton Pulse Animation ---- */

.ast-skeleton {
  animation: ast-skeleton-pulse 1.5s ease-in-out infinite;
}

.ast-skeleton--shimmer {
  animation: ast-skeleton-shimmer 1.8s ease-in-out infinite;
}

/* ===== Reduced Motion (WCAG 2.1 AA — SC 2.3.3) ===== */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  /* Preserve opacity end-states so content stays visible */
  .ast-card-stagger > *,
  .ast-row-stagger > *,
  .ast-skeleton,
  .ast-skeleton--shimmer {
    opacity: 1 !important;
    animation: none !important;
  }
}
