/* ===================================
   LOADING STATES & SKELETONS
   =================================== */

/* Shimmer Animation */
@keyframes shimmer {
  0% {
    background-position: -1000px 0;
  }
  100% {
    background-position: 1000px 0;
  }
}

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

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Skeleton Base */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-card) 0%,
    var(--bg-tertiary) 50%,
    var(--bg-card) 100%
  );
  background-size: 1000px 100%;
  animation: shimmer 2s infinite linear;
  border-radius: 8px;
  position: relative;
  overflow: hidden;
}

.skeleton::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.05) 50%,
    transparent 100%
  );
  animation: shimmer 2s infinite;
}

/* Skeleton Variants */
.skeleton-text {
  height: 1em;
  margin-bottom: 0.5em;
  border-radius: 4px;
}

.skeleton-text.short {
  width: 60%;
}

.skeleton-text.medium {
  width: 80%;
}

.skeleton-text.long {
  width: 100%;
}

.skeleton-title {
  height: 1.5em;
  width: 70%;
  margin-bottom: 1em;
  border-radius: 6px;
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.skeleton-thumbnail {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 8px;
}

.skeleton-button {
  height: 40px;
  width: 120px;
  border-radius: 8px;
}

/* Skeleton Card */
.skeleton-card {
  background: var(--bg-card);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.skeleton-card__thumbnail {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: linear-gradient(
    90deg,
    #1a1a1a 0%,
    #2a2a2a 50%,
    #1a1a1a 100%
  );
  background-size: 1000px 100%;
  animation: shimmer 2s infinite linear;
}

.skeleton-card__content {
  padding: 1rem;
}

.skeleton-card__title {
  height: 1.2em;
  background: linear-gradient(
    90deg,
    #1a1a1a 0%,
    #2a2a2a 50%,
    #1a1a1a 100%
  );
  background-size: 1000px 100%;
  animation: shimmer 2s infinite linear;
  border-radius: 4px;
  margin-bottom: 0.75rem;
}

.skeleton-card__meta {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
}

.skeleton-card__meta-item {
  height: 0.9em;
  width: 60px;
  background: linear-gradient(
    90deg,
    #1a1a1a 0%,
    #2a2a2a 50%,
    #1a1a1a 100%
  );
  background-size: 1000px 100%;
  animation: shimmer 2s infinite linear;
  border-radius: 4px;
}

/* Loading Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--bg-tertiary);
  border-top-color: var(--accent-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.spinner-small {
  width: 20px;
  height: 20px;
  border-width: 2px;
}

.spinner-large {
  width: 60px;
  height: 60px;
  border-width: 6px;
}

/* Loading Container */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  gap: 1rem;
}

.loading-text {
  color: var(--text-secondary);
  font-size: 0.95rem;
  animation: pulse 2s infinite;
}

/* Fade In Animation for Loaded Content */
.fade-in {
  animation: fadeIn 0.5s ease-out forwards;
}

.fade-in-delay-1 {
  animation: fadeIn 0.5s ease-out 0.1s forwards;
  opacity: 0;
}

.fade-in-delay-2 {
  animation: fadeIn 0.5s ease-out 0.2s forwards;
  opacity: 0;
}

.fade-in-delay-3 {
  animation: fadeIn 0.5s ease-out 0.3s forwards;
  opacity: 0;
}

/* Staggered Grid Animation */
.stagger-grid > * {
  opacity: 0;
  animation: fadeIn 0.5s ease-out forwards;
}

.stagger-grid > *:nth-child(1) { animation-delay: 0.05s; }
.stagger-grid > *:nth-child(2) { animation-delay: 0.1s; }
.stagger-grid > *:nth-child(3) { animation-delay: 0.15s; }
.stagger-grid > *:nth-child(4) { animation-delay: 0.2s; }
.stagger-grid > *:nth-child(5) { animation-delay: 0.25s; }
.stagger-grid > *:nth-child(6) { animation-delay: 0.3s; }
.stagger-grid > *:nth-child(7) { animation-delay: 0.35s; }
.stagger-grid > *:nth-child(8) { animation-delay: 0.4s; }
.stagger-grid > *:nth-child(9) { animation-delay: 0.45s; }
.stagger-grid > *:nth-child(10) { animation-delay: 0.5s; }
.stagger-grid > *:nth-child(11) { animation-delay: 0.55s; }
.stagger-grid > *:nth-child(12) { animation-delay: 0.6s; }

/* Progress Bar */
.progress-bar {
  width: 100%;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.progress-bar__fill {
  height: 100%;
  background: var(--accent-primary);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.progress-bar__indeterminate {
  position: absolute;
  height: 100%;
  width: 30%;
  background: var(--accent-primary);
  animation: indeterminate 1.5s infinite;
}

@keyframes indeterminate {
  0% {
    left: -30%;
  }
  100% {
    left: 100%;
  }
}

/* Skeleton Grid Layout */
.skeleton-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1.25rem;
  padding: 1rem 0;
}

@media (max-width: 600px) {
  .skeleton-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.875rem;
  }
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.loading-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.loading-overlay__content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 2rem;
  background: var(--bg-secondary);
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

/* Pulse Animation for Loading Elements */
.pulse {
  animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

/* Loaded State */
.loaded {
  animation: fadeIn 0.5s ease-out;
}

/* Hide Skeleton When Content Loads */
.content-loaded .skeleton-card {
  display: none;
}
