/**
 * Loading States and Lazy Loading Styles
 * Provides visual feedback for async operations and lazy-loaded content
 */

/* ============================================
   LAZY LOADING STYLES
   ============================================ */

/* Base lazy image state */
img.lazy {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.02) 100%
  );
  opacity: 0;
  transition: opacity 0.3s ease-in-out;
}

/* Loading state */
img.lazy-loading {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.03) 0%,
    rgba(255, 255, 255, 0.08) 50%,
    rgba(255, 255, 255, 0.03) 100%
  );
  background-size: 200% 100%;
  animation: lazy-shimmer 1.5s infinite;
}

/* Loaded state */
img.lazy-loaded {
  opacity: 1;
  background: transparent;
}

/* Error state */
img.lazy-error {
  opacity: 0.5;
  background: rgba(239, 68, 68, 0.1);
}

/* Shimmer animation for loading images */
@keyframes lazy-shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* Placeholder skeleton for images */
.image-placeholder {
  position: relative;
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.02) 100%
  );
  border-radius: var(--radius-lg, 12px);
  overflow: hidden;
}

.image-placeholder::before {
  content: "";
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.1),
    transparent
  );
  animation: skeleton-wave 1.5s infinite;
}

@keyframes skeleton-wave {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}

/* ============================================
   BUTTON LOADING STATES
   ============================================ */

/* Base button loading state */
.btn-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.8;
}

.btn-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: btn-spinner 0.8s linear infinite;
}

@keyframes btn-spinner {
  0% {
    transform: rotate(0deg);
  }
  100% {
    transform: rotate(360deg);
  }
}

/* Button with spinner icon */
.btn-spinner {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-spinner .spinner {
  width: 16px;
  height: 16px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: btn-spinner 0.8s linear infinite;
}

/* Primary button loading */
.btn-primary.btn-loading {
  background: linear-gradient(
    135deg,
    var(--color-accent-primary, #06b6d4),
    var(--color-accent-secondary, #8b5cf6)
  );
}

/* Secondary button loading */
.btn-secondary.btn-loading {
  background: rgba(255, 255, 255, 0.1);
}

/* Glass button loading */
.btn-glass.btn-loading {
  background: rgba(255, 255, 255, 0.05);
  backdrop-filter: blur(10px);
}

/* ============================================
   FORM LOADING STATES
   ============================================ */

/* Form submission loading */
.form-loading {
  position: relative;
  pointer-events: none;
}

.form-loading::after {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(10, 14, 26, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}

/* Input loading state */
.input-loading {
  position: relative;
}

.input-loading::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  border: 2px solid transparent;
  border-top-color: var(--color-accent-primary, #06b6d4);
  border-radius: 50%;
  animation: btn-spinner 0.8s linear infinite;
}

/* ============================================
   PAGE LOADING OVERLAY
   ============================================ */

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(10, 14, 26, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.loading-overlay.removing {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  text-align: center;
  color: #ffffff;
}

.loading-content .spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--color-accent-primary, #06b6d4);
  border-radius: 50%;
  animation: btn-spinner 0.8s linear infinite;
  margin: 0 auto 1rem;
}

.loading-content p {
  font-size: 0.875rem;
  color: rgba(255, 255, 255, 0.7);
}

/* ============================================
   SKELETON LOADERS
   ============================================ */

/* Base skeleton */
.skeleton {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-wave 1.5s infinite;
  border-radius: var(--radius-md, 8px);
}

/* Skeleton variants */
.skeleton-text {
  height: 1rem;
  margin-bottom: 0.5rem;
}

.skeleton-text:last-child {
  width: 60%;
}

.skeleton-title {
  height: 2rem;
  width: 40%;
  margin-bottom: 1rem;
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.skeleton-image {
  width: 100%;
  height: 200px;
}

.skeleton-button {
  width: 120px;
  height: 40px;
  border-radius: var(--radius-lg, 12px);
}

.skeleton-card {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.08) 0%,
    rgba(255, 255, 255, 0.02) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-xl, 16px);
  padding: 1.5rem;
}

/* ============================================
   CONTENT PLACEHOLDERS
   ============================================ */

/* Card skeleton */
.card-skeleton {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.08) 0%,
    rgba(255, 255, 255, 0.02) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-xl, 16px);
  overflow: hidden;
}

.card-skeleton .card-image {
  height: 180px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.03) 0%,
    rgba(255, 255, 255, 0.08) 50%,
    rgba(255, 255, 255, 0.03) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-wave 1.5s infinite;
}

.card-skeleton .card-content {
  padding: 1.5rem;
}

.card-skeleton .card-title {
  height: 1.5rem;
  width: 70%;
  margin-bottom: 0.75rem;
}

.card-skeleton .card-text {
  height: 1rem;
  margin-bottom: 0.5rem;
}

.card-skeleton .card-text:nth-child(2) {
  width: 90%;
}

.card-skeleton .card-text:nth-child(3) {
  width: 60%;
}

/* ============================================
   SPINNER VARIANTS
   ============================================ */

/* Small spinner */
.spinner-sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

/* Medium spinner */
.spinner-md {
  width: 24px;
  height: 24px;
  border-width: 2px;
}

/* Large spinner */
.spinner-lg {
  width: 48px;
  height: 48px;
  border-width: 3px;
}

/* Primary color spinner */
.spinner-primary {
  border-color: transparent;
  border-top-color: var(--color-accent-primary, #06b6d4);
}

/* White spinner */
.spinner-white {
  border-color: rgba(255, 255, 255, 0.2);
  border-top-color: #ffffff;
}

/* ============================================
   PROGRESS INDICATORS
   ============================================ */

/* Linear progress */
.progress-linear {
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.progress-linear .progress-bar {
  height: 100%;
  background: linear-gradient(
    90deg,
    var(--color-accent-primary, #06b6d4),
    var(--color-accent-secondary, #8b5cf6)
  );
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* Indeterminate progress */
.progress-linear.indeterminate .progress-bar {
  width: 30%;
  animation: progress-indeterminate 1.5s infinite ease-in-out;
}

@keyframes progress-indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(400%);
  }
}

/* ============================================
   ASYNC CONTENT STATES
   ============================================ */

/* Content loading wrapper */
.async-content {
  position: relative;
  min-height: 100px;
}

.async-content.loading .async-inner {
  opacity: 0.5;
  pointer-events: none;
}

.async-content .async-loader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: none;
}

.async-content.loading .async-loader {
  display: block;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 768px) {
  .loading-content .spinner {
    width: 36px;
    height: 36px;
  }

  .skeleton-image {
    height: 150px;
  }
}

@media (max-width: 480px) {
  .loading-content .spinner {
    width: 32px;
    height: 32px;
  }

  .skeleton-image {
    height: 120px;
  }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .lazy-loading,
  .skeleton,
  .card-skeleton .card-image,
  .progress-linear.indeterminate .progress-bar,
  .btn-loading::after,
  .spinner,
  .image-placeholder::before {
    animation: none;
  }

  img.lazy {
    opacity: 1;
    transition: none;
  }
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus visible for loading buttons */
.btn-loading:focus-visible {
  outline: 2px solid var(--color-accent-primary, #06b6d4);
  outline-offset: 2px;
}

/* ============================================
   IMP-04: DASHBOARD PAGE LOADING SKELETON
   CSS-only overlay that displays immediately
   and fades out when content is ready
   ============================================ */

.dashboard-skeleton-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(10, 14, 26, 0.97);
  z-index: 9998;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  transition:
    opacity 0.4s ease,
    visibility 0.4s ease;
}

.dashboard-skeleton-overlay.loaded {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.dashboard-skeleton-overlay .skeleton-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--color-accent-primary, #06b6d4);
  border-radius: 50%;
  animation: btn-spinner 0.8s linear infinite;
}

.dashboard-skeleton-overlay .skeleton-text {
  color: rgba(255, 255, 255, 0.5);
  font-size: 0.875rem;
  letter-spacing: 0.05em;
}

/* Dashboard content skeleton placeholders */
.dashboard-content-skeleton {
  padding: 1rem 0;
}

.dashboard-content-skeleton .skeleton-stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}

.dashboard-content-skeleton .skeleton-stat-card {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.06) 0%,
    rgba(255, 255, 255, 0.02) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-xl, 16px);
  padding: 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.dashboard-content-skeleton .skeleton-stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-wave 1.5s infinite;
  flex-shrink: 0;
}

.dashboard-content-skeleton .skeleton-stat-info {
  flex: 1;
}

.dashboard-content-skeleton .skeleton-stat-value {
  height: 1.75rem;
  width: 40%;
  margin-bottom: 0.5rem;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-wave 1.5s infinite;
  border-radius: var(--radius-md, 8px);
}

.dashboard-content-skeleton .skeleton-stat-label {
  height: 0.875rem;
  width: 60%;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.03) 0%,
    rgba(255, 255, 255, 0.06) 50%,
    rgba(255, 255, 255, 0.03) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-wave 1.5s infinite;
  border-radius: var(--radius-md, 8px);
}

.dashboard-content-skeleton .skeleton-section-title {
  height: 1.5rem;
  width: 30%;
  margin-bottom: 1rem;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-wave 1.5s infinite;
  border-radius: var(--radius-md, 8px);
}

.dashboard-content-skeleton .skeleton-cards-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.dashboard-content-skeleton .skeleton-card-item {
  background: linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.06) 0%,
    rgba(255, 255, 255, 0.02) 100%
  );
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: var(--radius-xl, 16px);
  padding: 1.25rem;
}

.dashboard-content-skeleton .skeleton-card-thumb {
  height: 120px;
  margin-bottom: 0.75rem;
  border-radius: var(--radius-lg, 12px);
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.03) 0%,
    rgba(255, 255, 255, 0.08) 50%,
    rgba(255, 255, 255, 0.03) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-wave 1.5s infinite;
}

.dashboard-content-skeleton .skeleton-card-title {
  height: 1rem;
  width: 80%;
  margin-bottom: 0.5rem;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.05) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    rgba(255, 255, 255, 0.05) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-wave 1.5s infinite;
  border-radius: var(--radius-md, 8px);
}

.dashboard-content-skeleton .skeleton-card-subtitle {
  height: 0.75rem;
  width: 50%;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0.03) 0%,
    rgba(255, 255, 255, 0.06) 50%,
    rgba(255, 255, 255, 0.03) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-wave 1.5s infinite;
  border-radius: var(--radius-md, 8px);
}

/* Responsive skeleton */
@media (max-width: 768px) {
  .dashboard-content-skeleton .skeleton-stats-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .dashboard-content-skeleton .skeleton-cards-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .dashboard-content-skeleton .skeleton-stats-row {
    grid-template-columns: 1fr;
  }
}
