/* Loading States and Animations */

/* Loading Spinner */
.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-light);
  border-radius: 50%;
  border-top-color: var(--accent-blue);
  animation: spin 0.8s linear infinite;
}

.loading-spinner.large {
  width: 40px;
  height: 40px;
  border-width: 3px;
}

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

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

/* Loading Overlay */
.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.loading-overlay.active {
  opacity: 1;
  visibility: visible;
}

.loading-overlay.dark {
  background: rgba(0, 0, 0, 0.8);
}

.loading-content {
  text-align: center;
  padding: 2rem;
}

.loading-text {
  margin-top: 1rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  opacity: 0.8;
}

/* Skeleton Loading */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-primary) 25%,
    var(--border-light) 50%,
    var(--bg-primary) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius-sm);
}

.skeleton-text {
  height: 1rem;
  margin-bottom: 0.5rem;
}

.skeleton-title {
  height: 1.5rem;
  width: 60%;
  margin-bottom: 1rem;
}

.skeleton-card {
  height: 120px;
  margin-bottom: 1rem;
  border-radius: var(--radius-md);
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

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

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

.btn.btn-secondary.loading::after {
  border-color: rgba(74, 144, 226, 0.3);
  border-top-color: var(--accent-blue);
}

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

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

.progress-indeterminate .progress-fill {
  width: 30%;
  position: absolute;
  animation: progress-indeterminate 1.5s infinite;
}

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

/* Pulse Animation */
.pulse {
  animation: pulse 2s infinite;
}

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

/* Fade In/Out Animations */
.fade-in {
  animation: fadeIn 0.3s ease-in;
}

.fade-out {
  animation: fadeOut 0.3s ease-out;
}

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

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

/* Module Loading */
.module-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  color: var(--text-secondary);
}

.module-loading-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
  animation: bounce 1s infinite;
}

@keyframes bounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-10px);
  }
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 80px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  pointer-events: none;
}

.toast {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-md);
  padding: 1rem 1.5rem;
  min-width: 300px;
  max-width: 400px;
  box-shadow: var(--shadow-heavy);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  opacity: 0;
  transform: translateX(100%);
  animation: slideInRight 0.3s ease forwards;
  pointer-events: auto;
}

.toast.closing {
  animation: slideOutRight 0.3s ease forwards;
}

@keyframes slideInRight {
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOutRight {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

.toast-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--text-primary);
}

.toast-message {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.4;
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0;
  opacity: 0.6;
  transition: opacity 0.2s ease;
}

.toast-close:hover {
  opacity: 1;
}

/* Toast Types */
.toast.success {
  border-color: #10b981;
  background: linear-gradient(to right, rgba(16, 185, 129, 0.1), var(--bg-secondary));
}

.toast.success .toast-icon {
  color: #10b981;
}

.toast.error {
  border-color: #ef4444;
  background: linear-gradient(to right, rgba(239, 68, 68, 0.1), var(--bg-secondary));
}

.toast.error .toast-icon {
  color: #ef4444;
}

.toast.warning {
  border-color: #f59e0b;
  background: linear-gradient(to right, rgba(245, 158, 11, 0.1), var(--bg-secondary));
}

.toast.warning .toast-icon {
  color: #f59e0b;
}

.toast.info {
  border-color: var(--accent-blue);
  background: linear-gradient(to right, rgba(74, 144, 226, 0.1), var(--bg-secondary));
}

.toast.info .toast-icon {
  color: var(--accent-blue);
}

/* Visual Feedback States */
.saving {
  position: relative;
  opacity: 0.7;
}

.saving::after {
  content: 'Saving...';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-secondary);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-medium);
  font-size: 0.9rem;
  color: var(--text-primary);
  pointer-events: none;
}

.saved {
  position: relative;
}

.saved::after {
  content: '✓ Saved';
  position: absolute;
  top: -30px;
  right: 0;
  background: #10b981;
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  animation: fadeInOut 2s ease forwards;
  pointer-events: none;
}

@keyframes fadeInOut {
  0% {
    opacity: 0;
    transform: translateY(10px);
  }
  20% {
    opacity: 1;
    transform: translateY(0);
  }
  80% {
    opacity: 1;
    transform: translateY(0);
  }
  100% {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* Click Feedback */
.click-ripple {
  position: relative;
  overflow: hidden;
}

.click-ripple::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.5);
  transform: translate(-50%, -50%);
  transition: width 0.6s, height 0.6s;
}

.click-ripple:active::before {
  width: 300px;
  height: 300px;
  opacity: 0;
}

/* Error States */
.error-message {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid #ef4444;
  border-radius: var(--radius-md);
  padding: 1rem;
  color: #dc2626;
  margin: 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: shake 0.3s ease;
}

.error-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-5px);
  }
  75% {
    transform: translateX(5px);
  }
}

/* Success States */
.success-message {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid #10b981;
  border-radius: var(--radius-md);
  padding: 1rem;
  color: #059669;
  margin: 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideDown 0.3s ease;
}

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

/* Mobile Loading States */
@media (max-width: 768px) {
  .toast-container {
    top: 70px;
    right: 10px;
    left: 10px;
  }

  .toast {
    min-width: unset;
    max-width: unset;
    width: 100%;
  }

  .module-loading {
    min-height: 300px;
  }
}

/* Performance Optimizations */
@media (prefers-reduced-motion: reduce) {
  .loading-spinner,
  .skeleton,
  .progress-indeterminate .progress-fill {
    animation: none;
  }

  .toast {
    animation: none;
    transform: none;
    opacity: 1;
  }

  .fade-in,
  .fade-out {
    animation: none;
  }
}