/**
 * SGLE Theme - Loading States System
 * 
 * Comprehensive loading indicators for improved UX
 * Includes: Skeleton loaders, Spinners, Progress bars, Shimmer effects
 * 
 * @version 2.0.0
 * @date 2026-01-15
 * @task 4.3 Loading States
 */

/* ========================================
   SKELETON LOADERS
   Modern shimmer-based loading placeholders
   ======================================== */

/* Base Skeleton Style */
.skeleton {
  background: linear-gradient(
    90deg,
    #f1f5f9 0%,
    #e2e8f0 20%,
    #f1f5f9 40%,
    #f1f5f9 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: 0.5rem;
  position: relative;
  overflow: hidden;
}

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

/* Skeleton Variants - Different Shapes */
.skeleton-text {
  height: 1rem;
  border-radius: 0.25rem;
  margin-bottom: 0.5rem;
}

.skeleton-text-sm {
  height: 0.75rem;
}

.skeleton-text-lg {
  height: 1.25rem;
}

.skeleton-heading {
  height: 2rem;
  width: 60%;
  margin-bottom: 1rem;
  border-radius: 0.5rem;
}

.skeleton-paragraph {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.skeleton-paragraph .skeleton-text:nth-child(1) {
  width: 100%;
}

.skeleton-paragraph .skeleton-text:nth-child(2) {
  width: 95%;
}

.skeleton-paragraph .skeleton-text:nth-child(3) {
  width: 80%;
}

/* Skeleton Avatar */
.skeleton-avatar {
  width: 3rem;
  height: 3rem;
  border-radius: 9999px;
}

.skeleton-avatar-sm {
  width: 2rem;
  height: 2rem;
}

.skeleton-avatar-lg {
  width: 4rem;
  height: 4rem;
}

/* Skeleton Button */
.skeleton-button {
  height: 2.5rem;
  width: 8rem;
  border-radius: 0.5rem;
}

.skeleton-button-sm {
  height: 2rem;
  width: 6rem;
}

.skeleton-button-lg {
  height: 3rem;
  width: 10rem;
}

/* Skeleton Card */
.skeleton-card {
  background: white;
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  padding: 1.5rem;
}

.skeleton-card-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
}

.skeleton-card-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

/* Skeleton Table */
.skeleton-table {
  width: 100%;
  border-spacing: 0;
}

.skeleton-table-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid #e2e8f0;
}

.skeleton-table-cell {
  height: 1.25rem;
  border-radius: 0.25rem;
}

/* Skeleton List Item */
.skeleton-list-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid #e2e8f0;
}

.skeleton-list-item:last-child {
  border-bottom: none;
}

/* Skeleton Image */
.skeleton-image {
  width: 100%;
  height: 12rem;
  border-radius: 0.5rem;
}

.skeleton-image-square {
  aspect-ratio: 1 / 1;
  height: auto;
}

.skeleton-image-wide {
  aspect-ratio: 16 / 9;
  height: auto;
}

/* Skeleton Badge */
.skeleton-badge {
  width: 4rem;
  height: 1.5rem;
  border-radius: 9999px;
}

/* ========================================
   SPINNERS
   Modern rotating loading indicators
   ======================================== */

/* Base Spinner Animation */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Default Spinner (Border Style) */
.spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* Spinner Sizes */
.spinner-sm {
  width: 1.5rem;
  height: 1.5rem;
  border-width: 2px;
}

.spinner-lg {
  width: 4rem;
  height: 4rem;
  border-width: 4px;
}

.spinner-xl {
  width: 6rem;
  height: 6rem;
  border-width: 5px;
}

/* Spinner Color Variants */
.spinner-primary {
  border-top-color: #3b82f6;
}

.spinner-success {
  border-top-color: #10b981;
}

.spinner-warning {
  border-top-color: #f59e0b;
}

.spinner-error {
  border-top-color: #ef4444;
}

.spinner-white {
  border-color: rgba(255, 255, 255, 0.3);
  border-top-color: white;
}

/* Dots Spinner */
.spinner-dots {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.spinner-dots span {
  width: 0.75rem;
  height: 0.75rem;
  background-color: #3b82f6;
  border-radius: 50%;
  animation: spinner-dots-bounce 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 spinner-dots-bounce {
  0%, 80%, 100% {
    transform: scale(0);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Pulse Spinner */
.spinner-pulse {
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background-color: #3b82f6;
  animation: spinner-pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

@keyframes spinner-pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(0.8);
  }
  50% {
    opacity: 0.5;
    transform: scale(1.2);
  }
}

/* Ring Spinner (Double Border) */
.spinner-ring {
  width: 3rem;
  height: 3rem;
  border: 3px solid transparent;
  border-top-color: #3b82f6;
  border-bottom-color: #3b82f6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Growing Circle Spinner */
.spinner-grow {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 50%;
  background-color: #3b82f6;
  animation: spinner-grow 0.75s linear infinite;
}

@keyframes spinner-grow {
  0% {
    transform: scale(0);
    opacity: 1;
  }
  100% {
    transform: scale(1);
    opacity: 0;
  }
}

/* ========================================
   PROGRESS BARS
   Linear progress indicators
   ======================================== */

/* Base Progress Bar */
.progress-bar {
  width: 100%;
  height: 0.5rem;
  background-color: #e2e8f0;
  border-radius: 9999px;
  overflow: hidden;
  position: relative;
}

/* Progress Bar Fill */
.progress-bar-fill {
  height: 100%;
  background-color: #3b82f6;
  border-radius: 9999px;
  transition: width 0.3s ease;
}

/* Progress Bar Sizes */
.progress-bar-sm {
  height: 0.375rem;
}

.progress-bar-lg {
  height: 0.75rem;
}

.progress-bar-xl {
  height: 1rem;
}

/* Progress Bar Color Variants */
.progress-bar-fill.primary {
  background-color: #3b82f6;
}

.progress-bar-fill.success {
  background-color: #10b981;
}

.progress-bar-fill.warning {
  background-color: #f59e0b;
}

.progress-bar-fill.error {
  background-color: #ef4444;
}

.progress-bar-fill.gradient {
  background: linear-gradient(90deg, #3b82f6 0%, #8b5cf6 100%);
}

/* Indeterminate Progress Bar */
.progress-bar-indeterminate .progress-bar-fill {
  width: 30%;
  animation: progress-indeterminate 1.5s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(400%);
  }
}

/* Striped Progress Bar */
.progress-bar-striped .progress-bar-fill {
  background-image: linear-gradient(
    45deg,
    rgba(255, 255, 255, 0.15) 25%,
    transparent 25%,
    transparent 50%,
    rgba(255, 255, 255, 0.15) 50%,
    rgba(255, 255, 255, 0.15) 75%,
    transparent 75%,
    transparent
  );
  background-size: 1rem 1rem;
}

/* Animated Stripes */
.progress-bar-striped.active .progress-bar-fill {
  animation: progress-stripes 1s linear infinite;
}

@keyframes progress-stripes {
  from {
    background-position: 1rem 0;
  }
  to {
    background-position: 0 0;
  }
}

/* Progress Bar with Label */
.progress-bar-labeled {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.progress-bar-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: #475569;
  min-width: 3rem;
  text-align: right;
}

/* Circular Progress */
.progress-circle {
  width: 5rem;
  height: 5rem;
  border-radius: 50%;
  background: conic-gradient(#3b82f6 0%, #3b82f6 var(--progress, 0%), #e2e8f0 var(--progress, 0%));
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.progress-circle::before {
  content: '';
  width: 80%;
  height: 80%;
  background-color: white;
  border-radius: 50%;
  position: absolute;
}

.progress-circle-value {
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
  position: relative;
  z-index: 1;
}

/* ========================================
   SHIMMER EFFECTS
   Standalone shimmer overlays
   ======================================== */

/* Wave Shimmer */
.shimmer-wave {
  position: relative;
  overflow: hidden;
  background-color: #f8fafc;
}

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

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

/* Gradient Shimmer */
.shimmer-gradient {
  background: linear-gradient(
    -45deg,
    #f1f5f9,
    #e2e8f0,
    #f1f5f9,
    #e2e8f0
  );
  background-size: 400% 400%;
  animation: shimmer-gradient 3s ease infinite;
}

@keyframes shimmer-gradient {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

/* ========================================
   LOADING CONTAINERS & OVERLAYS
   Full-page and component loading states
   ======================================== */

/* Full Page Loading Overlay */
.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  animation: fade-in 0.2s ease-out;
}

/* Component Loading Overlay */
.loading-overlay-component {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: inherit;
  z-index: 10;
}

/* Loading Container with Text */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.loading-text {
  font-size: 0.875rem;
  font-weight: 500;
  color: #64748b;
}

.loading-text-lg {
  font-size: 1rem;
  font-weight: 600;
  color: #475569;
}

/* Inline Loading State */
.loading-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

/* Button Loading State */
.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.btn-loading.btn-light::after {
  border-color: rgba(0, 0, 0, 0.1);
  border-top-color: #1e293b;
}

/* ========================================
   PULSE ANIMATIONS
   Alternative loading indicators
   ======================================== */

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

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

/* Breathing Effect (slower pulse) */
.breathing {
  animation: breathing 3s ease-in-out infinite;
}

@keyframes breathing {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.8;
    transform: scale(1.02);
  }
}

/* ========================================
   SPECIALIZED LOADING STATES
   Pre-built loading components
   ======================================== */

/* Table Loading State */
.table-loading {
  padding: 3rem 1.5rem;
  text-align: center;
}

.table-loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

/* Empty State with Loading */
.empty-loading {
  padding: 4rem 2rem;
  text-align: center;
  background-color: #f8fafc;
  border-radius: 0.75rem;
  border: 2px dashed #cbd5e1;
}

/* Card Loading State */
.card-loading {
  min-height: 12rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #f8fafc;
  border-radius: 0.75rem;
  position: relative;
}

/* ========================================
   UTILITY CLASSES
   Helper classes for loading states
   ======================================== */

/* Loading State Visibility */
.loading-hidden {
  display: none !important;
}

.loading-visible {
  display: block !important;
}

/* Disable Interactions During Loading */
.loading-disabled {
  pointer-events: none;
  opacity: 0.6;
  cursor: not-allowed;
}

/* Loading Z-Index Utilities */
.loading-z-10 {
  z-index: 10;
}

.loading-z-50 {
  z-index: 50;
}

.loading-z-max {
  z-index: 9999;
}

/* ========================================
   RESPONSIVE ADJUSTMENTS
   Mobile-friendly loading states
   ======================================== */

@media (max-width: 640px) {
  .skeleton-heading {
    width: 80%;
  }

  .spinner-xl {
    width: 4rem;
    height: 4rem;
    border-width: 4px;
  }

  .progress-circle {
    width: 4rem;
    height: 4rem;
  }

  .loading-overlay {
    padding: 1rem;
  }

  .loading-text-lg {
    font-size: 0.875rem;
  }
}

/* ========================================
   ACCESSIBILITY
   Loading states for screen readers
   ======================================== */

/* Visually hidden but accessible loading message */
.sr-loading {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* ARIA live region for loading announcements */
[aria-live="polite"],
[aria-live="assertive"] {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* ========================================
   PERFORMANCE OPTIMIZATIONS
   GPU acceleration for smooth animations
   ======================================== */

.skeleton,
.spinner,
.spinner-dots span,
.spinner-pulse,
.spinner-grow,
.progress-bar-fill,
.shimmer-wave::after,
.loading-overlay,
.btn-loading::after {
  will-change: transform, opacity;
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* Reduce animations for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  .skeleton,
  .spinner,
  .spinner-dots span,
  .spinner-pulse,
  .spinner-ring,
  .spinner-grow,
  .pulse,
  .breathing,
  .shimmer-wave::after,
  .shimmer-gradient,
  .progress-bar-indeterminate .progress-bar-fill,
  .progress-bar-striped.active .progress-bar-fill,
  .btn-loading::after {
    animation: none !important;
    transition: none !important;
  }
  
  .spinner,
  .spinner-ring {
    border-top-color: currentColor;
    opacity: 0.7;
  }
}
