/**
 * Image Styles
 * Styles for image containers, loading states, and attributions
 */

/* Image Container */
.image-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border-radius: 8px;
  background-color: #f0f0f0;
  transition: all 0.3s ease;
}

.image-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

/* Loading State */
.image-container.loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.3) 50%,
    rgba(255, 255, 255, 0) 100%
  );
  animation: shimmer 2s infinite;
}

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

/* Loaded State */
.image-container.loaded img {
  opacity: 1;
}

/* Error State */
.image-container.error {
  background-color: #ff6b6b;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-container.error::before {
  content: '⚠';
  font-size: 2rem;
  color: white;
  opacity: 0.7;
}

/* Fallback State */
.image-fallback {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.image-fallback::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: inherit;
  filter: brightness(0.9);
  z-index: 1;
}

.fallback-text {
  position: relative;
  z-index: 2;
  color: white;
  font-size: 1.5rem;
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  padding: 1rem;
  text-align: center;
  max-width: 80%;
}

/* Attribution */
.image-attribution {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(
    to top,
    rgba(0, 0, 0, 0.7) 0%,
    rgba(0, 0, 0, 0.5) 50%,
    transparent 100%
  );
  padding: 1rem 0.75rem 0.5rem;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.image-container:hover .image-attribution {
  transform: translateY(0);
}

.image-attribution a {
  color: white;
  text-decoration: none;
  font-size: 0.75rem;
  opacity: 0.9;
  transition: opacity 0.2s ease;
}

.image-attribution a:hover {
  opacity: 1;
  text-decoration: underline;
}

/* Loading Placeholder */
.image-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: #f5f5f5;
  border-radius: 8px;
}

.image-placeholder.loading {
  background: linear-gradient(
    135deg,
    #f5f5f5 0%,
    #e0e0e0 50%,
    #f5f5f5 100%
  );
  background-size: 200% 200%;
  animation: gradientShift 3s ease infinite;
}

@keyframes gradientShift {
  0%, 100% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
}

/* Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-top-color: #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

.loading-text {
  margin-bottom: 1rem;
  color: #666;
  font-size: 0.875rem;
}

/* Progressive Loading */
.image-container img.thumbnail {
  filter: blur(5px);
  transform: scale(1.05);
}

.image-container.loaded img.thumbnail {
  filter: blur(0);
  transform: scale(1);
}

/* Blur-up Effect */
.blur-up-thumbnail {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  filter: blur(10px);
  transform: scale(1.1);
  transition: opacity 0.3s ease;
  z-index: 1;
}

.image-container img {
  position: relative;
  z-index: 2;
}

/* Image Grid */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 1rem;
  padding: 1rem;
}

.image-grid .image-container {
  aspect-ratio: 4 / 3;
}

/* Responsive */
@media (max-width: 768px) {
  .image-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.75rem;
    padding: 0.75rem;
  }

  .fallback-text {
    font-size: 1.2rem;
  }

  .image-attribution {
    padding: 0.75rem 0.5rem 0.375rem;
  }

  .image-attribution a {
    font-size: 0.625rem;
  }
}

@media (max-width: 480px) {
  .image-grid {
    grid-template-columns: 1fr;
  }

  .spinner {
    width: 30px;
    height: 30px;
    border-width: 2px;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  .image-container,
  .image-container img,
  .image-attribution,
  .blur-up-thumbnail {
    transition: none;
  }

  .image-container.loading::after,
  .image-placeholder.loading,
  .spinner {
    animation: none;
  }
}

/* Print Styles */
@media print {
  .image-attribution,
  .spinner,
  .loading-text {
    display: none;
  }

  .image-container {
    break-inside: avoid;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  .image-container {
    background-color: #2a2a2a;
  }

  .image-placeholder {
    background-color: #1a1a1a;
  }

  .image-placeholder.loading {
    background: linear-gradient(
      135deg,
      #1a1a1a 0%,
      #2a2a2a 50%,
      #1a1a1a 100%
    );
  }

  .loading-text {
    color: #999;
  }

  .spinner {
    border-color: rgba(255, 255, 255, 0.1);
    border-top-color: #667eea;
  }
}

/* High Contrast Mode - using prefers-color-scheme instead */
@media (prefers-color-scheme: dark) {
  .image-attribution {
    background: rgba(0, 0, 0, 0.9);
  }

  .fallback-text {
    text-shadow: 0 0 3px black, 0 0 5px black;
  }
}
