/**
 * Loading States and Feedback CSS
 * Purpose: Skeleton screens, progress indicators, and toast notifications
 * Version: 1.0.0
 * Created: 2025-10-15
 */

/* ===================================
   SKELETON LOADING ANIMATIONS
   =================================== */

@keyframes skeleton-loading {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.skeleton-loading {
  background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s ease-in-out infinite;
  border-radius: var(--mobile-radius-md, 8px);
  overflow: hidden;
  position: relative;
}

.skeleton-loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.4) 50%, transparent 100%);
  animation: skeleton-shimmer 2s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(100%);
  }
}

/* Skeleton variants */
.skeleton-text {
  height: 1rem;
  margin-bottom: 0.5rem;
}

.skeleton-text:last-child {
  margin-bottom: 0;
}

.skeleton-text.skeleton-title {
  height: 1.5rem;
  width: 60%;
}

.skeleton-text.skeleton-subtitle {
  height: 1rem;
  width: 40%;
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.skeleton-card {
  padding: 1rem;
  border-radius: var(--mobile-radius-lg, 12px);
  background: white;
  box-shadow: var(--mobile-shadow-sm, 0 1px 2px 0 rgba(0, 0, 0, 0.05));
}

.skeleton-button {
  height: 44px;
  border-radius: var(--mobile-radius-md, 8px);
}

.skeleton-image {
  height: 200px;
  border-radius: var(--mobile-radius-md, 8px);
}

/* ===================================
   PROGRESS INDICATORS
   =================================== */

.progress-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: var(--mobile-z-modal, 1050);
  backdrop-filter: blur(2px);
}

.progress-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid var(--mobile-primary, #3b82f6);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.progress-text {
  font-size: var(--mobile-font-size-sm, 0.875rem);
  color: var(--mobile-text-secondary, #6b7280);
  text-align: center;
}

.progress-bar-container {
  width: 200px;
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  overflow: hidden;
  margin-top: 1rem;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--mobile-primary, #3b82f6), var(--mobile-primary-hover, #2563eb));
  border-radius: 2px;
  transition: width 0.3s ease;
}

/* Inline progress indicators */
.progress-inline {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: var(--mobile-font-size-sm, 0.875rem);
  color: var(--mobile-text-secondary, #6b7280);
}

.progress-inline .progress-spinner {
  width: 16px;
  height: 16px;
  border-width: 2px;
  margin-bottom: 0;
}

/* ===================================
   TOAST NOTIFICATIONS
   =================================== */

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: var(--mobile-z-toast, 9999);
  max-width: 320px;
}

@media (max-width: 767px) {
  .toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }
}

.mobile-toast {
  background: white;
  border-radius: var(--mobile-radius-lg, 12px);
  box-shadow: var(--mobile-shadow-lg, 0 10px 15px -3px rgba(0, 0, 0, 0.1));
  padding: 1rem;
  margin-bottom: 0.5rem;
  border-left: 4px solid var(--mobile-primary, #3b82f6);
  animation: toast-slide-in 0.3s ease-out;
  position: relative;
  overflow: hidden;
}

@keyframes toast-slide-in {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.mobile-toast.toast-success {
  border-left-color: var(--mobile-success, #10b981);
}

.mobile-toast.toast-warning {
  border-left-color: var(--mobile-warning, #f59e0b);
}

.mobile-toast.toast-error {
  border-left-color: var(--mobile-danger, #ef4444);
}

.mobile-toast.toast-info {
  border-left-color: var(--mobile-info, #06b6d4);
}

.toast-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.toast-title {
  font-weight: 600;
  font-size: var(--mobile-font-size-sm, 0.875rem);
  color: var(--mobile-text-primary, #1f2937);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toast-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--mobile-text-tertiary, #9ca3af);
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.2s ease;
}

.toast-close:hover {
  background: rgba(0, 0, 0, 0.1);
}

.toast-body {
  font-size: var(--mobile-font-size-sm, 0.875rem);
  color: var(--mobile-text-secondary, #6b7280);
  line-height: 1.4;
}

.toast-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  justify-content: flex-end;
}

.toast-actions .btn {
  padding: 0.375rem 0.75rem;
  font-size: var(--mobile-font-size-xs, 0.75rem);
  min-height: 32px;
}

/* Toast auto-dismiss animation */
.mobile-toast.toast-dismissing {
  animation: toast-slide-out 0.3s ease-in;
}

@keyframes toast-slide-out {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(100%);
    opacity: 0;
  }
}

/* ===================================
   LOADING STATES FOR SPECIFIC COMPONENTS
   =================================== */

/* Button loading states */
.btn-loading {
  position: relative;
  color: transparent !important;
}

.btn-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  border: 2px solid transparent;
  border-top: 2px solid currentColor;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.btn-loading.btn-primary::after {
  border-top-color: white;
}

.btn-loading.btn-secondary::after {
  border-top-color: var(--mobile-text-primary, #1f2937);
}

/* Form loading states */
.form-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.6;
}

.form-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 32px;
  height: 32px;
  border: 3px solid #f3f3f3;
  border-top: 3px solid var(--mobile-primary, #3b82f6);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Card loading states */
.card-loading {
  position: relative;
  overflow: hidden;
}

.card-loading::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  animation: card-shimmer 2s ease-in-out infinite;
}

@keyframes card-shimmer {
  0% {
    left: -100%;
  }
  100% {
    left: 100%;
  }
}

/* Table loading states */
.table-loading {
  position: relative;
}

.table-loading tbody tr {
  opacity: 0.3;
}

.table-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 40px;
  border: 4px solid #f3f3f3;
  border-top: 4px solid var(--mobile-primary, #3b82f6);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* ===================================
   PULL-TO-REFRESH INDICATORS
   =================================== */

.pull-to-refresh-indicator {
  position: fixed;
  top: -100px;
  left: 0;
  right: 0;
  height: 80px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: white;
  z-index: var(--mobile-z-toast, 9999);
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.pull-to-refresh-indicator.ready {
  background: var(--mobile-primary-light, #dbeafe);
}

.pull-to-refresh-indicator.visible {
  transform: translateY(100px);
  opacity: 1;
}

.pull-to-refresh-spinner {
  margin-bottom: 0.5rem;
}

.pull-to-refresh-text {
  font-size: var(--mobile-font-size-sm, 0.875rem);
  color: var(--mobile-text-secondary, #6b7280);
  font-weight: 500;
}

/* ===================================
   DARK MODE SUPPORT
   =================================== */

@media (prefers-color-scheme: dark) {
  .skeleton-loading {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
  }

  .mobile-toast {
    background: #1f2937;
    color: #f9fafb;
  }

  .progress-overlay {
    background: rgba(31, 41, 55, 0.9);
  }

  .pull-to-refresh-indicator {
    background: #1f2937;
  }
}
