/* ==========================================================================
   Post Image Layout System
   Supports: Alignment, Grids, Resizing, Captions, Lightbox
   ========================================================================== */

/* Container for post content images to isolate styles */
.post-content img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 2rem auto; /* Default: Center aligned with vertical spacing */
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

/* Hover effect for interactive images */
.post-content img.interactive:hover {
  transform: scale(1.02);
  box-shadow: var(--shadow-lg);
  cursor: zoom-in;
}

/* --- Layout Wrappers --- */

/* Basic Figure Wrapper */
.post-figure {
  margin: 2.5rem 0;
  display: block;
  text-align: center;
}

/* Full Width Image (Breaks container width) */
.img-full-width {
  width: 100vw;
  position: relative;
  left: 50%;
  right: 50%;
  margin-left: -50vw;
  margin-right: -50vw;
  border-radius: 0 !important;
}

.img-full-width img {
  width: 100%;
  max-width: 1200px; /* Limit max width on very large screens */
  margin: 0 auto;
  border-radius: 0;
}

/* --- Alignments (Float style for desktop) --- */
@media (min-width: 769px) {
  .img-left {
    float: left;
    margin: 0.5rem 2rem 1.5rem 0;
    max-width: 45%;
    clear: left;
  }

  .img-right {
    float: right;
    margin: 0.5rem 0 1.5rem 2rem;
    max-width: 45%;
    clear: right;
  }
}

/* --- Grid Layouts --- */
.img-grid {
  display: grid;
  gap: 1.5rem;
  margin: 2.5rem 0;
  width: 100%;
}

.img-grid-2 {
  grid-template-columns: repeat(2, 1fr);
}

.img-grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

/* Grid items */
.img-grid figure {
  margin: 0;
}

.img-grid img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  margin: 0; /* Remove default margin inside grid */
  aspect-ratio: 4/3; /* Default aspect ratio for uniformity */
}

/* --- Captions --- */
figcaption {
  margin-top: 0.75rem;
  font-size: 0.9rem;
  color: var(--color-muted);
  text-align: center;
  font-style: italic;
  line-height: 1.4;
}

/* --- Lightbox Styles --- */
.lightbox-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.9);
  z-index: 9999;
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  backdrop-filter: blur(5px);
}

.lightbox-overlay.active {
  opacity: 1;
  visibility: visible;
}

.lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
}

.lightbox-image {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  transform: scale(0.9);
  transition: transform 0.3s cubic-bezier(0.2, 0, 0.2, 1);
}

.lightbox-overlay.active .lightbox-image {
  transform: scale(1);
}

.lightbox-caption {
  position: absolute;
  bottom: -3rem;
  left: 0;
  width: 100%;
  text-align: center;
  color: #fff;
  font-size: 1rem;
  font-weight: 500;
  text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  color: #fff;
  font-size: 2.5rem;
  cursor: pointer;
  z-index: 10000;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.lightbox-close:hover {
  opacity: 1;
}

/* --- Mobile Responsiveness --- */
@media (max-width: 768px) {
  .img-left, .img-right {
    float: none;
    max-width: 100%;
    margin: 2rem 0;
  }
  
  .img-full-width {
    margin-left: -1rem; /* Container padding compensation */
    margin-right: -1rem;
    width: calc(100% + 2rem);
    left: auto;
    right: auto;
  }
  
  .img-grid-2, .img-grid-3 {
    grid-template-columns: 1fr; /* Stack images on mobile */
    gap: 1.5rem;
  }
  
  .img-grid img {
    aspect-ratio: 16/9; /* Wider on mobile */
  }
}
