/*
 * LOADING STATES CSS - APPLE-LEVEL ANIMATIONS
 * Superior visual feedback with accessibility support
 */

/* Base loading animations */
@keyframes fadeInLoading {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

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

@keyframes pulse {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.6;
    transform: scale(1.1);
  }
}

@keyframes dots-bounce {
  0%, 80%, 100% {
    transform: scale(0.8);
    opacity: 0.6;
  }
  40% {
    transform: scale(1.2);
    opacity: 1;
  }
}

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

/* Loading element base styles */
.loading-element {
  user-select: none;
  pointer-events: none;
  transition: all 0.3s ease;
}

/* Loading overlay styles */
.loading-overlay {
  border-radius: inherit;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  transition: all 0.3s ease;
}

.loading-overlay-content {
  z-index: 1001;
}

/* Global loader styles */
.global-loader {
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

/* Loading spinner variations */
.loading-spinner {
  box-sizing: border-box;
}

.loading-spinner.small {
  border-width: 1px;
}

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

/* Skeleton loading improvements */
.loading-skeleton {
  position: relative;
  overflow: hidden;
}

.loading-skeleton::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.8),
    transparent
  );
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
}

@keyframes skeleton-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Pulse loading variations */
.loading-pulse.small {
  animation-duration: 1s;
}

.loading-pulse.large {
  animation-duration: 2s;
}

/* Dots loading improvements */
.loading-dots {
  justify-content: center;
}

/* Button loading states */
button[aria-busy="true"] {
  position: relative;
  color: transparent !important;
  cursor: not-allowed;
  pointer-events: none;
}

button[aria-busy="true"]::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top: 2px solid #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

/* Form loading states */
form[aria-busy="true"] {
  pointer-events: none;
  opacity: 0.7;
}

form[aria-busy="true"] input,
form[aria-busy="true"] textarea,
form[aria-busy="true"] select,
form[aria-busy="true"] button {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Task item loading states */
[data-task-id][aria-busy="true"] {
  position: relative;
  overflow: hidden;
}

[data-task-id][aria-busy="true"]::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(59, 130, 246, 0.1),
    transparent
  );
  animation: loading-sweep 2s ease-in-out infinite;
  z-index: 1;
}

@keyframes loading-sweep {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* Kanban column loading */
.kanban-column[aria-busy="true"] {
  opacity: 0.6;
  pointer-events: none;
}

.kanban-column[aria-busy="true"]::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border: 2px solid #e5e7eb;
  border-top: 2px solid #3b82f6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  z-index: 1000;
}

/* Loading message styles */
.loading-message {
  text-align: center;
  font-size: 14px;
  color: #6b7280;
  font-weight: 500;
  margin-top: 8px;
  animation: fadeInLoading 0.5s ease;
}

/* Progress bar loading */
.loading-progress {
  width: 100%;
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.loading-progress::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 30%;
  background: #3b82f6;
  border-radius: 2px;
  animation: progress-indeterminate 2s ease-in-out infinite;
}

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

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .loading-overlay {
    background: rgba(17, 24, 39, 0.9);
  }

  .global-loader {
    background: rgba(17, 24, 39, 0.95);
  }

  .loading-spinner {
    border-color: #374151;
    border-top-color: #60a5fa;
  }

  .loading-skeleton {
    background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
  }

  .loading-pulse {
    background: #60a5fa;
  }

  .loading-dots div {
    background: #60a5fa;
  }

  .loading-message {
    color: #9ca3af;
  }

  button[aria-busy="true"]::after {
    border-color: rgba(255, 255, 255, 0.2);
    border-top-color: #fff;
  }

  .loading-progress {
    background: #374151;
  }

  .loading-progress::after {
    background: #60a5fa;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .loading-spinner {
    border-color: #000;
    border-top-color: #0066ff;
  }

  .loading-pulse {
    background: #0066ff;
  }

  .loading-dots div {
    background: #0066ff;
  }

  .loading-message {
    color: #000;
    font-weight: 600;
  }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
  .loading-spinner,
  .loading-pulse,
  .loading-dots div,
  .loading-skeleton,
  .loading-progress::after,
  [data-task-id][aria-busy="true"]::before {
    animation: none !important;
  }

  .loading-skeleton {
    background: #e5e7eb !important;
  }

  .loading-pulse {
    opacity: 0.6 !important;
  }

  .loading-dots div {
    opacity: 0.6 !important;
  }

  .loading-spinner {
    border: 2px solid #e5e7eb !important;
    border-left: 2px solid #3b82f6 !important;
  }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
  .loading-element {
    transform: scale(1.1);
  }

  .loading-overlay {
    backdrop-filter: blur(4px);
  }

  .global-loader {
    backdrop-filter: blur(12px);
  }
}

/* Print styles */
@media print {
  .loading-overlay,
  .global-loader,
  .loading-element,
  [aria-busy="true"]::after,
  [aria-busy="true"]::before {
    display: none !important;
  }

  [aria-busy="true"] {
    opacity: 1 !important;
    color: inherit !important;
  }
}

/* Custom loading states for specific components */
.modal[aria-busy="true"] {
  pointer-events: none;
}

.modal[aria-busy="true"] .modal-content {
  opacity: 0.7;
  filter: blur(1px);
}

.modal[aria-busy="true"]::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 32px;
  height: 32px;
  margin: -16px 0 0 -16px;
  border: 3px solid rgba(255, 255, 255, 0.3);
  border-top: 3px solid #fff;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  z-index: 10001;
}

/* Loading state for drag and drop operations */
.kanban-column.drop-loading {
  background: linear-gradient(45deg,
    rgba(59, 130, 246, 0.1) 25%,
    transparent 25%,
    transparent 75%,
    rgba(59, 130, 246, 0.1) 75%
  );
  background-size: 20px 20px;
  animation: loading-stripes 1s linear infinite;
}

@keyframes loading-stripes {
  0% { background-position: 0 0; }
  100% { background-position: 20px 20px; }
}

/* Success state animations */
@keyframes success-checkmark {
  0% {
    transform: scale(0) rotate(45deg);
    opacity: 0;
  }
  50% {
    transform: scale(1.2) rotate(45deg);
    opacity: 1;
  }
  100% {
    transform: scale(1) rotate(45deg);
    opacity: 1;
  }
}

.loading-success {
  color: #10b981;
  animation: success-checkmark 0.6s ease;
}

/* Error state animations */
@keyframes error-shake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-2px); }
  20%, 40%, 60%, 80% { transform: translateX(2px); }
}

.loading-error {
  color: #ef4444;
  animation: error-shake 0.6s ease;
}

/* Progressive loading for large datasets */
.progressive-loading {
  opacity: 0;
  transform: translateY(20px);
  animation: progressive-fade-in 0.6s ease forwards;
}

.progressive-loading:nth-child(1) { animation-delay: 0.1s; }
.progressive-loading:nth-child(2) { animation-delay: 0.2s; }
.progressive-loading:nth-child(3) { animation-delay: 0.3s; }
.progressive-loading:nth-child(4) { animation-delay: 0.4s; }
.progressive-loading:nth-child(5) { animation-delay: 0.5s; }

@keyframes progressive-fade-in {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}