/* ============================================================
   Phase 8: Loading Skeletons & Performance Styles
   ============================================================ */

/* Shared skeleton pulse animation */
@keyframes skeleton-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.7; }
}

.skeleton {
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

/* Skeleton block primitives */
.skeleton-line {
  height: 14px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-line--sm { height: 10px; width: 60%; }
.skeleton-line--md { height: 14px; width: 80%; }
.skeleton-line--lg { height: 18px; width: 90%; }
.skeleton-line--xl { height: 28px; width: 50%; }

.skeleton-circle {
  border-radius: 50%;
  background: var(--surface-alt);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-rect {
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

/* Stagger the pulse for multiple skeletons */
.skeleton-stagger > :nth-child(2) { animation-delay: 0.15s; }
.skeleton-stagger > :nth-child(3) { animation-delay: 0.3s; }
.skeleton-stagger > :nth-child(4) { animation-delay: 0.45s; }
.skeleton-stagger > :nth-child(5) { animation-delay: 0.6s; }

/* ---- 8.1a Race Clock Skeleton ---- */
.skeleton-clock {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.skeleton-clock__time {
  width: 200px;
  height: 48px;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-clock__lap {
  width: 120px;
  height: 24px;
  background: var(--surface-alt);
  border-radius: var(--radius-pill);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  animation-delay: 0.2s;
}
.skeleton-clock__sub {
  width: 160px;
  height: 14px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  animation-delay: 0.4s;
}

/* ---- 8.1b Stat Card Skeleton ---- */
.skeleton-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.skeleton-stat-card__value {
  width: 80px;
  height: 32px;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-stat-card__label {
  width: 100px;
  height: 12px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  animation-delay: 0.15s;
}
.skeleton-stat-card__bar {
  width: 100%;
  height: 4px;
  background: var(--surface-alt);
  border-radius: 2px;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  animation-delay: 0.3s;
  margin-top: var(--space-1);
}

/* Stat card grid */
.skeleton-stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: var(--space-4);
}

/* ---- 8.1c Lap Table Skeleton ---- */
.skeleton-table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.skeleton-table__header {
  display: flex;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  background: var(--surface-alt);
  border-bottom: 1px solid var(--border);
}
.skeleton-table__header-cell {
  height: 12px;
  background: var(--surface);
  border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-table__header-cell:nth-child(1) { width: 48px; }
.skeleton-table__header-cell:nth-child(2) { width: 80px; }
.skeleton-table__header-cell:nth-child(3) { width: 64px; }
.skeleton-table__header-cell:nth-child(4) { width: 64px; }
.skeleton-table__header-cell:nth-child(5) { width: 64px; }
.skeleton-table__header-cell:nth-child(6) { flex: 1; }

.skeleton-table__row {
  display: flex;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
}
.skeleton-table__row:last-child { border-bottom: none; }
.skeleton-table__cell {
  height: 14px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-table__cell:nth-child(1) { width: 48px; }
.skeleton-table__cell:nth-child(2) { width: 80px; animation-delay: 0.1s; }
.skeleton-table__cell:nth-child(3) { width: 64px; animation-delay: 0.2s; }
.skeleton-table__cell:nth-child(4) { width: 64px; animation-delay: 0.3s; }
.skeleton-table__cell:nth-child(5) { width: 64px; animation-delay: 0.4s; }
.skeleton-table__cell:nth-child(6) { flex: 1; animation-delay: 0.5s; }

/* ---- 8.1d Chart Skeleton ---- */
.skeleton-chart {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}
.skeleton-chart__title {
  width: 140px;
  height: 16px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  margin-bottom: var(--space-4);
}
.skeleton-chart__area {
  position: relative;
  height: 200px;
  background: var(--surface-inset);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.skeleton-chart__area::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60%;
  background: linear-gradient(180deg, transparent, var(--surface-alt));
  opacity: 0.3;
  animation: skeleton-pulse 2s ease-in-out infinite;
}
/* Y-axis labels */
.skeleton-chart__y-labels {
  position: absolute;
  left: 8px;
  top: 8px;
  bottom: 8px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.skeleton-chart__y-label {
  width: 24px;
  height: 8px;
  background: var(--surface-alt);
  border-radius: 2px;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}
/* X-axis labels */
.skeleton-chart__x-labels {
  display: flex;
  justify-content: space-between;
  padding-top: var(--space-2);
}
.skeleton-chart__x-label {
  width: 32px;
  height: 8px;
  background: var(--surface-alt);
  border-radius: 2px;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}

/* ---- 8.1e Nutrition Bar Skeleton ---- */
.skeleton-nutrition-bar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.skeleton-nutrition-bar__label {
  width: 60px;
  height: 12px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
}
.skeleton-nutrition-bar__track {
  flex: 1;
  height: 8px;
  background: var(--surface-alt);
  border-radius: 4px;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  animation-delay: 0.2s;
}
.skeleton-nutrition-bar__value {
  width: 40px;
  height: 12px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  animation-delay: 0.4s;
}

/* ---- 8.1f Full Page Loading Skeleton (Race Day layout) ---- */
.skeleton-page {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: var(--space-4);
  max-width: 1200px;
}

/* ---- Update Available Banner ---- */
.update-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-4);
  background: var(--primary-subtle);
  border-bottom: 1px solid rgba(6, 182, 212, 0.2);
  font-size: var(--text-sm);
  color: var(--primary);
  text-align: center;
  animation: update-banner-enter 0.3s ease-out;
}
.update-banner__btn {
  padding: var(--space-1) var(--space-3);
  background: var(--primary);
  color: var(--text-on-primary);
  border: none;
  border-radius: var(--radius-md);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  font-family: var(--font-sans);
  cursor: pointer;
  transition: background var(--transition-fast);
}
.update-banner__btn:hover {
  background: var(--primary-hover);
}
.update-banner__dismiss {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: var(--space-1);
  opacity: 0.6;
  transition: opacity var(--transition-fast);
}
.update-banner__dismiss:hover {
  opacity: 1;
}

@keyframes update-banner-enter {
  0% { max-height: 0; opacity: 0; padding: 0; }
  100% { max-height: 48px; opacity: 1; }
}

/* ---- Lazy-loading fade-in ---- */
.lazy-fade-in {
  animation: lazy-fade 0.4s ease-out;
}
@keyframes lazy-fade {
  0% { opacity: 0; }
  100% { opacity: 1; }
}

/* Image lazy-load placeholder */
img[loading="lazy"] {
  background: var(--surface-alt);
}
