/* Enhanced Loading Animations for Dashboard */

/* Loading Container */
.loading-container {
  padding: 2rem;
  min-height: 400px;
  animation: fadeIn 0.3s ease-in;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Dashboard loading screen keyframes (#4490). They must be global: the screen picks an animation by name through
   custom properties (--rc-head-anim, --rc-off, --pp-anim, --pp-dot-anim), and CSS isolation renames @keyframes in
   a .razor.css but cannot rewrite a name held in var() or a custom property. */

/* One hop: squash, rise, squash on landing, then rest for the other two portions' turns. */
@keyframes rc-hop {
  0% {
    transform: translateY(0) scale(1, 1);
    animation-timing-function: ease-in;
  }
  5% {
    transform: translateY(0) scale(1.1, 0.88);
    animation-timing-function: cubic-bezier(0.2, 0.7, 0.4, 1);
  }
  20% {
    transform: translateY(var(--rc-h, -26px)) scale(0.95, 1.06);
    animation-timing-function: cubic-bezier(0.6, 0, 0.8, 0.3);
  }
  35% {
    transform: translateY(0) scale(1.12, 0.86);
    animation-timing-function: ease-out;
  }
  42%,
  100% {
    transform: translateY(0) scale(1, 1);
  }
}

/* The head leans toward each hop and rises as the middle portion peaks. */
@keyframes rc-peek {
  0%,
  100% {
    transform: translateY(0) rotate(-2deg);
  }
  14% {
    transform: translateY(0) rotate(-4deg);
  }
  36% {
    transform: translateY(-1px) rotate(-1deg);
  }
  53% {
    transform: translateY(-8px) rotate(0deg);
  }
  70% {
    transform: translateY(0) rotate(2deg);
  }
  82% {
    transform: translateY(0) rotate(4deg);
  }
}

@keyframes rc-ear {
  0%,
  22%,
  100% {
    transform: rotate(0deg);
  }
  6% {
    transform: rotate(14deg);
  }
  12% {
    transform: rotate(2deg);
  }
  17% {
    transform: rotate(9deg);
  }
}

/* After 20 s: play stops and only a slow bob is left, so he reads as working, not having fun. */
@keyframes rc-steady {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(3px);
  }
}

@keyframes pp-breathe {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

@keyframes pp-dot {
  0%,
  60%,
  100% {
    opacity: 0.3;
  }
  30% {
    opacity: 1;
  }
}

@keyframes pp-dot-still {
  0%,
  100% {
    opacity: 0.5;
  }
  50% {
    opacity: 1;
  }
}

/* Food Selection Loading State */
.food-selection-loading {
  position: relative;
  overflow: hidden;
}

.food-selection-loading::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--fs-primary-a10) 50%,
    transparent 100%
  );
  animation: shimmer 2s infinite;
}

@keyframes shimmer {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}

/* Meal Card Loading Animation */
.meal-card-loading {
  background: linear-gradient(
    90deg,
    var(--fs-bg-secondary) 25%,
    var(--fs-border-default) 50%,
    var(--fs-bg-secondary) 75%
  );
  background-size: 200% 100%;
  /* Same skeleton shimmer as SkeletonLoader — share the one token (design-tokens.css). */
  animation: skeleton-loading var(--fs-dur-skeleton, 1.5s) infinite;
  border-radius: 0.5rem;
  height: 120px;
  margin-bottom: 1rem;
}

/* Progress Bar Smooth Transitions */
.progress-bar {
  transition: width 0.6s ease-out;
}

/* Loading Step Text Animation */
.loading-step {
  animation: fadeInOut 1.5s ease-in-out infinite;
}

@keyframes fadeInOut {
  0%,
  100% {
    opacity: 0.7;
  }
  50% {
    opacity: 1;
  }
}

/* Staggered Loading Animation for List Items */
.loading-item {
  opacity: 0;
  animation: fadeInUp 0.4s ease-out forwards;
}

.loading-item:nth-child(1) {
  animation-delay: 0.1s;
}
.loading-item:nth-child(2) {
  animation-delay: 0.2s;
}
.loading-item:nth-child(3) {
  animation-delay: 0.3s;
}
.loading-item:nth-child(4) {
  animation-delay: 0.4s;
}
.loading-item:nth-child(5) {
  animation-delay: 0.5s;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Spinner Variations */
.spinner-dots {
  display: inline-flex;
  gap: 0.3rem;
}

.spinner-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--fs-text-primary);
  animation: dotPulse 1.4s infinite ease-in-out both;
}

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

@keyframes dotPulse {
  0%,
  80%,
  100% {
    transform: scale(0);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Success Animation - successPulse keyframes defined in animations.css */
.loading-success {
  animation: successPulse 0.5s ease-out;
}

/* Error Animation - errorShake keyframes defined in animations.css */
.loading-error {
  animation: errorShake 0.5s ease-out;
}

/* Optimized Performance with GPU Acceleration */
.loading-spinner,
.skeleton-card,
.skeleton-list-item,
.progress-bar {
  will-change: transform, opacity;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Mobile Optimizations */
@media (max-width: 768px) {
  .loading-container {
    padding: 1rem;
  }

  /* NOTE: no .skeleton-card height here. A fixed 100px was 44px shorter than the card's own
     content (16 padding + 24 header + 16 margin + 3x24 lines + 16 padding = 144px), and nothing
     clips the overflow, so the third line escaped below the card border and the next list item
     painted over it. Let the card size to its content. */

  @keyframes fadeInUp {
    from {
      transform: translateY(5px);
    }
  }
}
