/* WP Automatic: original grid remains as a safe fallback until dimensions exist. */
body.single-post .wp-posts-content .jlc-auto-image-grid,
body.single-post .wp-posts-content .jlc-auto-image-native-grid {
  box-sizing: border-box;
  display: grid !important;
  grid-template-columns: repeat(var(--jlc-img-cols, 2), minmax(0, 1fr)) !important;
  align-items: start !important;
  gap: 12px !important;
  margin: 18px 0 26px !important;
  max-width: 100%;
  min-width: 0;
  width: 100%;
}
body.single-post .wp-posts-content .jlc-auto-image-grid > figure,
body.single-post .wp-posts-content .jlc-auto-image-grid > div.wp-block-image,
body.single-post .wp-posts-content .jlc-auto-image-grid > p,
body.single-post .wp-posts-content .jlc-auto-image-grid > img,
body.single-post .wp-posts-content .jlc-auto-image-native-grid > figure {
  box-sizing: border-box;
  min-width: 0 !important;
  max-width: 100% !important;
  width: 100% !important;
  margin: 0 !important;
  flex: initial !important;
}
body.single-post .wp-posts-content .jlc-auto-image-grid img,
body.single-post .wp-posts-content .jlc-auto-image-native-grid img {
  display: block;
  max-width: 100% !important;
  width: 100% !important;
  height: auto !important;
  object-fit: contain !important;
  margin: 0 !important;
}
body.single-post .wp-posts-content .jlc-auto-image-grid figure,
body.single-post .wp-posts-content .jlc-auto-image-native-grid figure {
  max-width: 100% !important;
  min-width: 0 !important;
}
body.single-post .wp-posts-content .jlc-auto-image-grid a,
body.single-post .wp-posts-content .jlc-auto-image-native-grid a {
  max-width: 100%;
}
body.single-post .wp-posts-content .jlc-auto-image-grid figcaption,
body.single-post .wp-posts-content .jlc-auto-image-native-grid figcaption {
  max-width: 100%;
  overflow-wrap: anywhere;
}

/* Justified layout: equal height per row, proportional image widths, exact row fill. */
body.single-post .wp-posts-content .jlc-auto-image-grid.jlc-auto-image-justified,
body.single-post .wp-posts-content .jlc-auto-image-native-grid.jlc-auto-image-justified {
  display: block !important;
  grid-template-columns: none !important;
}
body.single-post .wp-posts-content .jlc-auto-image-justified > .jlc-auto-image-row {
  box-sizing: border-box;
  display: flex !important;
  flex-wrap: nowrap !important;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  align-items: flex-start !important;
  gap: var(--jlc-row-gap, 12px) !important;
  margin: 0 0 12px !important;
  padding: 0 !important;
  overflow: visible;
}
body.single-post .wp-posts-content .jlc-auto-image-justified > .jlc-auto-image-row:last-child {
  margin-bottom: 0 !important;
}
body.single-post .wp-posts-content .jlc-auto-image-row > * {
  box-sizing: border-box !important;
  display: block;
  flex: 0 0 var(--jlc-item-width) !important;
  width: var(--jlc-item-width) !important;
  max-width: var(--jlc-item-width) !important;
  min-width: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  text-indent: 0 !important;
}
body.single-post .wp-posts-content .jlc-auto-image-row img,
body.single-post .wp-posts-content .jlc-auto-image-row picture img {
  box-sizing: border-box;
  display: block !important;
  width: 100% !important;
  max-width: 100% !important;
  height: var(--jlc-row-height) !important;
  max-height: none !important;
  min-height: 0 !important;
  object-fit: contain !important;
  margin: 0 !important;
}
body.single-post .wp-posts-content .jlc-auto-image-row > * > a,
body.single-post .wp-posts-content .jlc-auto-image-row > * > picture,
body.single-post .wp-posts-content .jlc-auto-image-row > * > a > picture {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}
body.single-post .wp-posts-content .jlc-auto-image-row figcaption {
  max-width: 100%;
  overflow-wrap: anywhere;
}


/* Gutenberg sometimes wraps exactly one image inside a gallery figure.
   It must retain its natural ratio in the same justified row as plain figures. */
body.single-post .wp-posts-content .jlc-auto-image-row > figure.wp-block-gallery {
  display: block !important;
  align-items: initial !important;
  justify-content: initial !important;
  gap: 0 !important;
}
body.single-post .wp-posts-content .jlc-auto-image-row > figure.wp-block-gallery > figure.wp-block-image,
body.single-post .wp-posts-content .jlc-auto-image-row > figure.wp-block-gallery > ul.blocks-gallery-grid,
body.single-post .wp-posts-content .jlc-auto-image-row > figure.wp-block-gallery > ul.blocks-gallery-grid > li.blocks-gallery-item {
  display: block !important;
  box-sizing: border-box !important;
  flex: 0 0 100% !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
}

/* Existing grid is a non-JS or unknown-dimensions fallback. */
@media (max-width: 1000px) {
  body.single-post .wp-posts-content .jlc-auto-image-grid:not(.jlc-auto-image-justified),
  body.single-post .wp-posts-content .jlc-auto-image-native-grid:not(.jlc-auto-image-justified) {
    grid-template-columns: repeat(var(--jlc-img-cols-tablet, 2), minmax(0, 1fr)) !important;
  }
}
@media (max-width: 640px) {
  body.single-post .wp-posts-content .jlc-auto-image-grid:not(.jlc-auto-image-justified),
  body.single-post .wp-posts-content .jlc-auto-image-native-grid:not(.jlc-auto-image-justified) {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 12px !important;
  }
}
