/* Content constructor — public-facing styles for merged blocks rendered
   by BlocksMerger. Layout classes follow content-block--<layout-value>
   (underscores in enum → hyphens in CSS). */

.content-block {
  margin: 16px 0;
}

/* Per-block opt-in horizontal separator, emitted by BlocksMerger when the
   admin ticks the "add horizontal line" checkbox above and/or below the
   block. Plain CSS hairline that picks up the surrounding text colour. */
.content-block__separator {
  border: 0;
  border-top: 1px solid currentColor;
  opacity: 0.2;
  margin: 24px 0;
}

.content-block__body > :first-child {
  margin-top: 0;
}

.content-block__body > :last-child {
  margin-bottom: 0;
}

.content-block__image {
  margin: 0;
}

.content-block__image img,
.content-block__gallery img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}

/* ── Per-image captions ──────────────────────────────────────────── */

/* One-liner italic, centered relative to the image, ellipsis on overflow.
   Rendered above and/or below each <div class="content-block__media">,
   inside the figure. Empty placeholders carry .content-block__caption--placeholder
   to reserve space when sibling images in the same gallery row have a
   caption — keeping image tops/bottoms aligned across the row. */
.content-block__caption {
  font-style: italic;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.9em;
  line-height: 1.3;
  cursor: default;
}

.content-block__caption--top {
  margin-bottom: 4px;
}

.content-block__caption--bottom {
  margin-top: 4px;
}

.content-block__caption--placeholder {
  visibility: hidden;
}

/* ── NONE: text only ─────────────────────────────────────────────── */

.content-block--none {
  display: block;
}

/* ── IMAGE_LEFT / IMAGE_RIGHT: image beside body ─────────────────── */

.content-block--image-left,
.content-block--image-right {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.content-block--image-right {
  flex-direction: row-reverse;
}

.content-block--image-left > .content-block__image,
.content-block--image-right > .content-block__image {
  flex: 0 0 var(--cc-image-share, 25%);
  max-width: var(--cc-image-share, 25%);
  /* Allow shrinking below img natural width — otherwise the figure pushes
     past the configured column share when the source image is wider. */
  min-width: 0;
}

.content-block--image-left > .content-block__body,
.content-block--image-right > .content-block__body {
  min-width: 0;
}

.content-block--image-left > .content-block__body,
.content-block--image-right > .content-block__body {
  flex: 1 1 auto;
  min-width: 0;
}

/* ── IMAGE_FULL_ROW_N: image-only rows ───────────────────────────── */

.content-block[class*="--image-full-row-"] {
  display: block;
}

.content-block--image-full-row-1 > .content-block__image {
  width: 100%;
}

.content-block--image-full-row-1 > .content-block__image img {
  width: 100%;
}

.content-block__gallery {
  display: grid;
  gap: 12px;
  /* Cells stretch to the row's tallest cell (default behaviour, made
     explicit). Each image inside its figure sits at the top via normal
     block flow — so a landscape image leaves empty space below itself
     when a portrait sibling makes the row taller. */
  align-items: stretch;
}

/* Grid items default to min-width: auto = min-content = image natural width.
   Without this override, large source images blow the column out of its
   1fr share, breaking the row layout and pushing captions off-screen. */
.content-block__gallery > .content-block__image {
  min-width: 0;
}

.content-block--image-full-row-2 > .content-block__gallery {
  grid-template-columns: repeat(2, 1fr);
}

.content-block--image-full-row-3 > .content-block__gallery {
  grid-template-columns: repeat(3, 1fr);
}

.content-block--image-full-row-4 > .content-block__gallery {
  grid-template-columns: repeat(4, 1fr);
}

.content-block--image-full-row-5 > .content-block__gallery {
  grid-template-columns: repeat(5, 1fr);
}

/* ── TEXT_FULL_ROW_N: multi-column text rows ─────────────────────── */

/* Container parents have no body of their own — their direct children are
   themselves .content-block.content-block--none wrappers. The grid sizes
   to its tallest child (no overflow clipping); each column's text just
   sits at the top, leaving its bottom space empty. */
.content-block--text-full-row-2,
.content-block--text-full-row-3 {
  display: grid;
  gap: 20px;
  align-items: stretch;
}

/* Default tracks — the merger overrides via inline grid-template-columns
   when any child carries an explicit column_share. */
.content-block--text-full-row-2 {
  grid-template-columns: 1fr 1fr;
}

.content-block--text-full-row-3 {
  grid-template-columns: 1fr 1fr 1fr;
}

/* Children sit inside the column container as standalone content blocks;
   strip their default vertical margin so column tops/bottoms align with
   the row instead of stair-stepping. */
.content-block--text-full-row-2 > .content-block,
.content-block--text-full-row-3 > .content-block {
  margin: 0;
}

/* ── Mobile: stack ───────────────────────────────────────────────── */

@media (max-width: 768px) {
  .content-block--image-left {
    flex-direction: column;
  }

  /* Match desktop reading order (text-on-left, image-on-right) on mobile by
     stacking text first and image below. The DOM order is always
     image-then-body; column-reverse flips that to body-then-image. */
  .content-block--image-right {
    flex-direction: column-reverse;
  }

  .content-block--image-left > .content-block__image,
  .content-block--image-right > .content-block__image {
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
  }

  .content-block--image-full-row-3 > .content-block__gallery,
  .content-block--image-full-row-4 > .content-block__gallery,
  .content-block--image-full-row-5 > .content-block__gallery {
    grid-template-columns: repeat(2, 1fr);
  }

  .content-block--text-full-row-2,
  .content-block--text-full-row-3 {
    grid-template-columns: 1fr;
  }
}
