/**
 * Loading Indicator Styles
 * Spinners, skeleton screens, and loading states
 */

/* ============================================
   LOADING SPINNER
   ============================================ */

.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  min-height: 200px;
}

.spinner-circle {
  width: 48px;
  height: 48px;
  border: 4px solid var(--surface-color);
  border-top-color: var(--primary-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-text {
  margin-top: 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.loading-spinner.large .spinner-circle {
  width: 64px;
  height: 64px;
  border-width: 5px;
}

.loading-spinner.large .spinner-text {
  font-size: 1rem;
  margin-top: 1.5rem;
}

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

/* ============================================
   SKELETON LOADING
   ============================================ */

/* Base skeleton element */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--color-bg-secondary) 0%,
    var(--color-bg-elevated) 50%,
    var(--color-bg-secondary) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

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

/* Skeleton container */
.skeleton-container {
  pointer-events: none;
  user-select: none;
}

/* ============================================
   VEHICLE CARD SKELETON
   ============================================ */

.skeleton-vehicle-card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
  margin-bottom: var(--space-lg);
}

.skeleton-vehicle-image {
  width: 100%;
  height: 200px;
  margin-bottom: var(--space-lg);
}

.skeleton-vehicle-title {
  width: 70%;
  height: 24px;
  margin-bottom: var(--space-md);
}

.skeleton-vehicle-text {
  width: 100%;
  height: 16px;
  margin-bottom: var(--space-sm);
}

.skeleton-vehicle-text.short {
  width: 60%;
}

.skeleton-vehicle-actions {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-lg);
}

.skeleton-vehicle-button {
  width: 100px;
  height: 40px;
}

/* ============================================
   MARKETPLACE LISTING SKELETON
   ============================================ */

.skeleton-listing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: var(--space-xl);
}

.skeleton-listing-card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.skeleton-listing-image {
  width: 100%;
  height: 200px;
}

.skeleton-listing-content {
  padding: var(--space-lg);
}

.skeleton-listing-title {
  width: 80%;
  height: 20px;
  margin-bottom: var(--space-md);
}

.skeleton-listing-price {
  width: 50%;
  height: 24px;
  margin-bottom: var(--space-sm);
}

.skeleton-listing-meta {
  display: flex;
  gap: var(--space-sm);
  margin-bottom: var(--space-md);
}

.skeleton-listing-badge {
  width: 60px;
  height: 20px;
}

.skeleton-listing-description {
  width: 100%;
  height: 14px;
  margin-bottom: var(--space-xs);
}

.skeleton-listing-description.short {
  width: 75%;
}

/* ============================================
   FORUM THREAD SKELETON
   ============================================ */

.skeleton-thread-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.skeleton-thread-item {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  display: flex;
  gap: var(--space-lg);
}

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

.skeleton-thread-content {
  flex: 1;
}

.skeleton-thread-title {
  width: 70%;
  height: 20px;
  margin-bottom: var(--space-sm);
}

.skeleton-thread-text {
  width: 100%;
  height: 14px;
  margin-bottom: var(--space-xs);
}

.skeleton-thread-text.short {
  width: 60%;
}

.skeleton-thread-meta {
  display: flex;
  gap: var(--space-md);
  margin-top: var(--space-md);
}

.skeleton-thread-stat {
  width: 80px;
  height: 16px;
}

/* ============================================
   PARTS SEARCH RESULT SKELETON
   ============================================ */

.skeleton-parts-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-lg);
}

.skeleton-part-item {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  display: flex;
  gap: var(--space-lg);
}

.skeleton-part-image {
  width: 120px;
  height: 120px;
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.skeleton-part-content {
  flex: 1;
}

.skeleton-part-title {
  width: 60%;
  height: 20px;
  margin-bottom: var(--space-md);
}

.skeleton-part-number {
  width: 40%;
  height: 16px;
  margin-bottom: var(--space-sm);
}

.skeleton-part-description {
  width: 100%;
  height: 14px;
  margin-bottom: var(--space-xs);
}

.skeleton-part-description.short {
  width: 80%;
}

.skeleton-part-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: var(--space-md);
}

.skeleton-part-price {
  width: 80px;
  height: 24px;
}

.skeleton-part-button {
  width: 120px;
  height: 36px;
}

/* ============================================
   TABLE SKELETON
   ============================================ */

.skeleton-table {
  width: 100%;
  border-collapse: collapse;
}

.skeleton-table-row {
  border-bottom: 1px solid var(--color-border);
}

.skeleton-table-cell {
  padding: var(--space-lg);
}

.skeleton-table-text {
  height: 16px;
}

.skeleton-table-text.wide {
  width: 100%;
}

.skeleton-table-text.medium {
  width: 70%;
}

.skeleton-table-text.narrow {
  width: 40%;
}

/* ============================================
   PROFILE SKELETON
   ============================================ */

.skeleton-profile-header {
  display: flex;
  gap: var(--space-xl);
  margin-bottom: var(--space-2xl);
  padding: var(--space-xl);
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
}

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

.skeleton-profile-info {
  flex: 1;
}

.skeleton-profile-name {
  width: 200px;
  height: 28px;
  margin-bottom: var(--space-md);
}

.skeleton-profile-tagline {
  width: 300px;
  height: 16px;
  margin-bottom: var(--space-lg);
}

.skeleton-profile-stats {
  display: flex;
  gap: var(--space-xl);
}

.skeleton-profile-stat {
  width: 80px;
  height: 40px;
}

/* ============================================
   DASHBOARD WIDGETS SKELETON
   ============================================ */

.skeleton-widget {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-xl);
}

.skeleton-widget-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-lg);
}

.skeleton-widget-title {
  width: 150px;
  height: 20px;
}

.skeleton-widget-icon {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
}

.skeleton-widget-value {
  width: 120px;
  height: 48px;
  margin-bottom: var(--space-md);
}

.skeleton-widget-label {
  width: 100px;
  height: 14px;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 768px) {
  .skeleton-listing-grid {
    grid-template-columns: 1fr;
  }

  .skeleton-part-item {
    flex-direction: column;
  }

  .skeleton-part-image {
    width: 100%;
    height: 180px;
  }

  .skeleton-profile-header {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .skeleton-profile-stats {
    justify-content: center;
  }

  .skeleton-thread-item {
    flex-direction: column;
  }

  .skeleton-thread-avatar {
    width: 40px;
    height: 40px;
  }
}

/* ============================================
   UTILITY CLASSES
   ============================================ */

.skeleton-text {
  height: 16px;
  border-radius: var(--radius-sm);
}

.skeleton-text.large {
  height: 24px;
}

.skeleton-text.small {
  height: 12px;
}

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

.skeleton-rounded {
  border-radius: var(--radius-md);
}

.skeleton-full-width {
  width: 100%;
}

.skeleton-half-width {
  width: 50%;
}

.skeleton-quarter-width {
  width: 25%;
}

/* Hide real content while loading */
.loading .content {
  display: none;
}

.loading .skeleton-container {
  display: block;
}

.skeleton-container {
  display: none;
}

/* ============================================
   OLD STYLES (Keep for compatibility)
   ============================================ */

.skeleton-card {
  background: var(--color-bg-elevated);
  border: 1px solid var(--color-border);
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1rem;
}

.skeleton-header {
  width: 60%;
  height: 24px;
  margin-bottom: 1rem;
}

.skeleton-line {
  width: 100%;
  height: 16px;
  margin-bottom: 0.75rem;
}

.skeleton-line.short {
  width: 70%;
}

.skeleton-button {
  width: 120px;
  height: 40px;
  margin-top: 1rem;
}

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

/* Skeleton color variables */
:root {
  --skeleton-color: rgba(0, 0, 0, 0.08);
}

[data-theme="dark"] {
  --skeleton-color: rgba(255, 255, 255, 0.08);
}

/* ============================================
   BUTTON LOADING STATE
   ============================================ */

.btn-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}

.btn-spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-right: 0.5rem;
  vertical-align: middle;
}

/* ============================================
   INLINE LOADING
   ============================================ */

.inline-loader {
  display: inline-block;
  margin-left: 0.5rem;
}

.inline-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--primary-color);
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

/* ============================================
   PAGE LOADING OVERLAY
   ============================================ */

.page-loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ============================================
   PROGRESS BAR
   ============================================ */

.progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--surface-color);
  z-index: 9999;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.progress-bar.active {
  opacity: 1;
}

.progress-fill {
  height: 100%;
  background: var(--primary-color);
  width: 0%;
  transition: width 0.3s ease;
  box-shadow: 0 0 10px var(--primary-color);
}

/* ============================================
   LOADING STATE CLASSES
   ============================================ */

.loading-state {
  pointer-events: none;
  user-select: none;
}

/* Empty state for no results */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1rem;
  text-align: center;
  min-height: 300px;
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--text-color);
}

.empty-state-description {
  color: var(--text-muted);
  margin-bottom: 1.5rem;
}

/* ============================================
   MOBILE OPTIMIZATIONS
   ============================================ */

@media (max-width: 768px) {
  .loading-spinner {
    min-height: 150px;
    padding: 2rem 1rem;
  }

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

  .skeleton-card {
    padding: 1rem;
  }

  .empty-state {
    min-height: 200px;
    padding: 2rem 1rem;
  }

  .empty-state-icon {
    font-size: 2rem;
  }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  .spinner-circle,
  .btn-spinner,
  .inline-spinner {
    animation: none;
    border-left-color: transparent;
    border-right-color: transparent;
  }

  .skeleton-card {
    animation: none;
    opacity: 0.7;
  }

  .progress-fill {
    transition: none;
  }
}

/* Screen reader only text */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}
