/* ========================================
   Gallery Styles
   Phase 2 - Gallery System
   ======================================== */

/* Gallery Introduction */
.gallery-intro {
  text-align: center;
  margin-bottom: var(--spacing-xxl);
}

.gallery-intro h1 {
  margin-bottom: var(--spacing-md);
}

.gallery-description {
  font-size: var(--font-size-large);
  color: var(--color-text-secondary);
  max-width: 800px;
  margin: 0 auto;
}

/* Gallery Grid - Masonry Layout */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  grid-auto-rows: 200px; /* Fixed row height for masonry */
  gap: var(--spacing-lg);
  margin-bottom: var(--spacing-xxl);
}

/* Masonry row spanning based on image aspect ratio */
.gallery-item[data-row-span="1"] {
  grid-row: span 1;
}

.gallery-item[data-row-span="2"] {
  grid-row: span 2;
}

.gallery-item[data-row-span="3"] {
  grid-row: span 3;
}

/* Gallery Loading State */
.gallery-loading {
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--spacing-xxl);
  color: var(--color-text-secondary);
}

/* Gallery Item (placeholder for Phase 2) */
.gallery-item {
  position: relative;
  overflow: hidden;
  border-radius: var(--border-radius-md);
  background-color: var(--color-background-lighter);
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
  cursor: pointer;
}

.gallery-item:hover,
.gallery-item:focus-visible {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
}

.gallery-item:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.gallery-item img {
  width: 100%;
  height: 100%; /* Fill container for masonry layout */
  object-fit: cover; /* Maintain aspect ratio, fill space */
  display: block;
  transition: transform var(--transition-slow);
}

.gallery-item:hover img {
  transform: scale(1.05);
}

/* Responsive adjustments for masonry layout */
@media (max-width: 1024px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    grid-auto-rows: 180px; /* Slightly smaller rows for medium screens */
  }
}

@media (max-width: 768px) {
  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    grid-auto-rows: 160px; /* Smaller rows for tablets */
    gap: var(--spacing-md);
  }
}

@media (max-width: 480px) {
  .gallery-grid {
    grid-template-columns: 1fr; /* Single column on mobile */
    grid-auto-rows: auto; /* Let images determine height on mobile */
    gap: var(--spacing-sm);
  }

  /* On mobile, reset row spanning since we have single column */
  .gallery-item[data-row-span="1"],
  .gallery-item[data-row-span="2"],
  .gallery-item[data-row-span="3"] {
    grid-row: span 1;
  }

  .gallery-item img {
    height: auto; /* Let aspect ratio determine height on mobile */
    object-fit: contain; /* Show full image on mobile */
  }
}

/* Gallery Error State */
.gallery-error {
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--spacing-xxl);
  background-color: var(--color-background-lighter);
  border-radius: var(--border-radius-md);
  border: 1px solid #ff6b6b;
}

.gallery-error p {
  color: var(--color-text-primary);
  margin-bottom: var(--spacing-sm);
}

.gallery-error .error-details {
  color: var(--color-text-secondary);
  font-size: var(--font-size-small);
}

/* Gallery Empty State */
.gallery-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: var(--spacing-xxl);
  color: var(--color-text-secondary);
  font-style: italic;
}

/* Screen reader only text */
.gallery-item .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;
}

/* ========================================
   Phase 4 - Lazy Loading States
   ======================================== */

/* Skeleton loading state - animated gradient */
.gallery-item--loading {
  background: linear-gradient(
    90deg,
    var(--color-background-lighter) 0%,
    rgba(255, 255, 255, 0.1) 50%,
    var(--color-background-lighter) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
}

/* Skeleton shimmer animation */
@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Image starts invisible for fade-in */
.gallery-item--loading img {
  opacity: 0;
}

/* Fade-in animation when image loads */
.lazy-loaded img {
  opacity: 1;
  transition: opacity 300ms ease-in-out;
}

/* Loading state - active loading */
.lazy-loading {
  /* Optional: could add additional loading indicator here */
}

/* Error state - image failed to load */
.lazy-error {
  background-color: rgba(255, 107, 107, 0.1);
  border: 1px dashed rgba(255, 107, 107, 0.3);
}

.lazy-error::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 48px;
  height: 48px;
  background-image: url('data:image/svg+xml,%3Csvg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23ff6b6b" stroke-width="2"%3E%3Ccircle cx="12" cy="12" r="10"/%3E%3Cline x1="12" y1="8" x2="12" y2="12"/%3E%3Cline x1="12" y1="16" x2="12.01" y2="16"/%3E%3C/svg%3E');
  background-size: contain;
  background-repeat: no-repeat;
  opacity: 0.5;
}

/* Accessibility: Disable animations for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  .gallery-item--loading {
    animation: none;
    background: var(--color-background-lighter);
  }

  .lazy-loaded img {
    transition: none;
  }

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