/* ═══════════════════════════════════════════════════════════════
   EVIDENT — Loading States & Async UI
   
   Critical for Pipeline v2.0 features:
   - Worker initialization (FFmpeg, Transformers, DuckDB)
   - Model downloads (39MB - 1.5GB)
   - File processing progress
   - Skeleton screens for feature cards
   
   All components respect prefers-reduced-motion
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS Variables ───────────────────────────────────────────── */
:root {
  --loading-skeleton-base: #e5e7eb;
  --loading-skeleton-shine: #f3f4f6;
  --loading-spinner-size-sm: 16px;
  --loading-spinner-size-md: 24px;
  --loading-spinner-size-lg: 40px;
  --loading-spinner-color: var(--color-primary, #1f3a99);
  --loading-spinner-track: rgb(31 58 153 / 15%);
  --loading-progress-height: 8px;
  --loading-progress-bg: rgb(31 58 153 / 10%);
  --loading-progress-fill: var(--color-primary, #1f3a99);
  --loading-ease: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ── Skeleton Loading ────────────────────────────────────────── */
.skeleton {
  display: block;
  background: var(--loading-skeleton-base);
  border-radius: var(--radius-sm, 4px);
  position: relative;
  overflow: hidden;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, var(--loading-skeleton-shine) 50%, transparent 100%);
  transform: translateX(-100%);
  animation: skeleton-shimmer 2s infinite;
}

@media (prefers-reduced-motion: reduce) {
  .skeleton::after {
    animation: none;
  }
}

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

/* Skeleton variants */
.skeleton--text {
  height: 1em;
  margin-bottom: 0.5em;
}

.skeleton--text:last-child {
  width: 75%;
}

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

.skeleton--avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex-shrink: 0;
}

.skeleton--thumbnail {
  width: 80px;
  height: 60px;
  border-radius: var(--radius-md, 8px);
}

.skeleton--card {
  height: 200px;
  border-radius: var(--radius-lg, 12px);
}

.skeleton--button {
  height: 40px;
  width: 120px;
  border-radius: var(--radius-md, 8px);
}

.skeleton--circle {
  border-radius: 50%;
}

/* Skeleton container for feature cards */
.skeleton-feature-card {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.5rem;
  background: var(--surface-card, white);
  border: 1px solid var(--border-subtle, #e5e7eb);
  border-radius: var(--radius-lg, 12px);
}

.skeleton-feature-card__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.skeleton-feature-card__icon {
  width: 40px;
  height: 40px;
  border-radius: 8px;
}

.skeleton-feature-card__title {
  flex: 1;
}

.skeleton-feature-card__badge {
  width: 60px;
  height: 20px;
  border-radius: 9999px;
}

/* ── Spinners ────────────────────────────────────────────────── */
.spinner {
  display: inline-flex;
  width: var(--loading-spinner-size-md);
  height: var(--loading-spinner-size-md);
  border: 2px solid var(--loading-spinner-track);
  border-top-color: var(--loading-spinner-color);
  border-radius: 50%;
  animation: spinner-rotate 0.8s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 1.5s;
  }
}

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

/* Spinner sizes */
.spinner--sm {
  width: var(--loading-spinner-size-sm);
  height: var(--loading-spinner-size-sm);
  border-width: 1.5px;
}

.spinner--lg {
  width: var(--loading-spinner-size-lg);
  height: var(--loading-spinner-size-lg);
  border-width: 3px;
}

/* Spinner with label */
.spinner-with-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-secondary, #6b7280);
  font-size: 0.875rem;
}

/* ── Progress Bars ──────────────────────────────────────────── */
.progress-bar {
  width: 100%;
  height: var(--loading-progress-height);
  background: var(--loading-progress-bg);
  border-radius: calc(var(--loading-progress-height) / 2);
  overflow: hidden;
  position: relative;
}

.progress-bar__fill {
  height: 100%;
  background: var(--loading-progress-fill);
  border-radius: calc(var(--loading-progress-height) / 2);
  transition: width 0.3s var(--loading-ease);
  position: relative;
}

.progress-bar__fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 0%, rgb(255 255 255 / 30%) 50%, transparent 100%);
  animation: progress-shine 1.5s infinite;
}

@keyframes progress-shine {
  from {
    transform: translateX(-100%);
  }

  to {
    transform: translateX(100%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .progress-bar__fill::after {
    animation: none;
  }
}

/* Indeterminate progress */
.progress-bar--indeterminate .progress-bar__fill {
  width: 40%;
  animation: progress-indeterminate 1.5s ease-in-out infinite;
}

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

  50% {
    transform: translateX(150%);
  }

  100% {
    transform: translateX(300%);
  }
}

/* Progress with label */
.progress-with-label {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.progress-with-label__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
}

.progress-with-label__title {
  color: var(--text-primary, #111827);
  font-weight: 500;
}

.progress-with-label__percent {
  color: var(--text-secondary, #6b7280);
  font-variant-numeric: tabular-nums;
}

.progress-with-label__meta {
  font-size: 0.75rem;
  color: var(--text-muted, #9ca3af);
}

/* Progress sizes */
.progress-bar--sm {
  height: 4px;
}

.progress-bar--lg {
  height: 12px;
}

/* ── Model Download Progress (Specific to Pipeline) ─────────── */
.model-download-progress {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--surface-elevated, #f9fafb);
  border-radius: var(--radius-md, 8px);
  border: 1px solid var(--border-subtle, #e5e7eb);
}

.model-download-progress__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.model-download-progress__icon {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary);
  color: white;
  border-radius: 8px;
  flex-shrink: 0;
}

.model-download-progress__info {
  flex: 1;
  min-width: 0;
}

.model-download-progress__name {
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.model-download-progress__size {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.model-download-progress__actions {
  display: flex;
  gap: 0.5rem;
}

.model-download-progress__cancel {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  background: transparent;
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  cursor: pointer;
  color: var(--text-secondary);
}

.model-download-progress__cancel:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
}

/* ── Worker Initialization States ──────────────────────────── */
.worker-init {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.worker-init__icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--color-primary), var(--color-tanzanite));
  color: white;
  border-radius: 12px;
  flex-shrink: 0;
}

.worker-init__content {
  flex: 1;
  min-width: 0;
}

.worker-init__title {
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 0.25rem;
}

.worker-init__description {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin: 0;
}

.worker-init__progress {
  width: 120px;
  flex-shrink: 0;
}

/* Worker states */
.worker-init--loading {
  border-color: var(--color-primary);
}

.worker-init--success {
  border-color: #22c55e;
  background: rgb(34 197 94 / 5%);
}

.worker-init--error {
  border-color: #ef4444;
  background: rgb(239 68 68 / 5%);
}

.worker-init--error .worker-init__icon {
  background: #ef4444;
}

/* ── Loading Overlay (for panels) ───────────────────────────── */
.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  background: rgb(255 255 255 / 90%);
  backdrop-filter: blur(4px);
  z-index: 100;
  border-radius: inherit;
}

.loading-overlay__text {
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-align: center;
}

/* Position relative required on parent */
.has-loading-overlay {
  position: relative;
}

/* ── Page Loading State ─────────────────────────────────────── */
.page-loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  background: var(--surface-base);
  z-index: 9999;
}

.page-loading__logo {
  width: 120px;
  height: auto;
}

.page-loading__spinner {
  width: 48px;
  height: 48px;
}

.page-loading__text {
  font-size: 0.875rem;
  color: var(--text-muted);
  animation: pulse 2s ease-in-out infinite;
}

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

  50% {
    opacity: 0.5;
  }
}
