/* Responsive Image Base Styles */
img {
  max-width: 100%;
  height: auto;
  display: block;
  object-fit: cover;
}

/* Paragraph Image Constraints */
p {
  max-width: 100%;
  position: relative;
}

p img {
  max-width: min(100%, var(--paragraph-width, 100%));
  width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
  border-radius: 4px;
  transition: transform 0.3s ease;
}

/* Art Direction with Picture Element */
picture {
  display: block;
  width: 100%;
}

picture source {
  width: 100%;
}

picture img {
  width: 100%;
}

/* Lazy Loading Container */
.lazy-container {
  position: relative;
  width: 100%;
  overflow: hidden;
  background-color: #f0f0f0;
}

.lazy-container::before {
  content: "";
  display: block;
  padding-top: 56.25%; /* 16:9 aspect ratio */
}

.lazy-container img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.lazy-container img.loaded {
  opacity: 1;
}

/* Responsive Container Classes */
.img-container {
  width: 100%;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

.img-fluid {
  width: 100%;
  height: auto;
}

/* Aspect Ratio Containers */
.aspect-16-9 {
  padding-top: 56.25%;
}

.aspect-4-3 {
  padding-top: 75%;
}

.aspect-1-1 {
  padding-top: 100%;
}

/* Background Image Fallbacks */
.bg-image {
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
}

/* Add padding around images for visual balance */
.img-wrapper {
  padding: 1rem;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  margin: 1rem 0;
  border-radius: 8px;
}

/* Responsive Breakpoints */
@media (max-width: 1200px) {
  .img-container {
      max-width: 960px;
  }
  
  p img {
      margin: 1.25rem auto;
  }
  
  .img-wrapper {
      padding: 0.875rem;
  }
}

@media (max-width: 992px) {
  .img-container {
      max-width: 720px;
  }
}

@media (max-width: 768px) {
  .img-container {
      max-width: 540px;
  }
  
  p img {
      margin: 1rem auto;
  }
  
  .img-wrapper {
      padding: 0.75rem;
  }
}

@media (max-width: 576px) {
  .img-container {
      max-width: 100%;
      padding: 0 15px;
  }
  
  p img {
      margin: 0.875rem auto;
  }
  
  .img-wrapper {
      padding: 0.625rem;
  }
}

/* High DPI (Retina) Support */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .retina-ready {
      display: none;
  }
  
  .retina-image {
      display: block;
  }
}

/* Print Styles */
@media print {
  img {
      max-width: 100% !important;
      page-break-inside: avoid;
  }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  img {
      transition: none !important;
  }
}

/* Loading States */
.img-loading {
  filter: blur(10px);
  transition: filter 0.3s ease;
}

.img-loaded {
  filter: blur(0);
}

/* Fallback Styles */
.img-fallback {
  background-color: #f0f0f0;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  font-size: 0.875rem;
}

/* Image Grid System */
.img-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
}

/* Image Gallery */
.img-gallery {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
}

.img-gallery img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: 4px;
}

/* Focus Styles */
img:focus-visible {
  outline: 3px solid #003366;
  outline-offset: 2px;
}

/* Error Handling */
img.error {
  position: relative;
}

img.error::after {
  content: "Image failed to load";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(0, 0, 0, 0.7);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  font-size: 0.875rem;
}

/* Prevent image stretching */
img {
  object-fit: contain;
}

/* Lazy loading placeholder styles */
.lazy-image {
  opacity: 0;
  transition: opacity 0.3s ease-in;
}

.lazy-image.loaded {
  opacity: 1;
}

/* Fallback for older browsers */
@supports not (object-fit: contain) {
  img {
      width: 100%;
      height: 100%;
  }
}