/**
 * Adaptive page body: always 3 tracks (left | main | right).
 * Empty side regions keep a gutter; widgets inflate that column.
 * Cap body width so side 1fr tracks never exceed --db-sidebar-max
 * (otherwise wide viewports make sides ≈ main — three equal columns).
 * Outer leftover is true page margin via margin-inline: auto.
 * Hero stays full-width above .db-page-body. Grid is on the body
 * wrapper — never on .db-page (chrome/admin must stay full bleed).
 */
:root {
  --db-content-max: var(--max-width, var(--max-width-content, 52rem));
  --db-sidebar-max: 16rem;
  --db-gutter-min: 1.25rem;
  /* Length unit required — unitless 0 breaks max-width calc() below. */
  --db-page-gap: 0px;
}

.db-page-body {
  display: grid;
  grid-template-columns:
    minmax(var(--db-gutter-min), 1fr)
    minmax(0, var(--db-content-max))
    minmax(var(--db-gutter-min), 1fr);
  column-gap: var(--db-page-gap);
  width: 100%;
  /* Cap so each side 1fr ≤ --db-sidebar-max; leftover viewport is true margin. */
  max-width: calc(
    var(--db-content-max) + (2 * var(--db-sidebar-max)) + (2 * var(--db-page-gap))
  );
  margin-inline: auto;
  box-sizing: border-box;
  align-items: start;
}

.db-page-body > .region-sidebar-left,
.db-page-body > .region-sidebar-right,
.db-page-body > .region-main {
  min-width: 0;
  box-sizing: border-box;
}

.db-page-body > .region-main {
  width: 100%;
}

/* Side tracks: empty = gutter; filled = content capped toward main */
.db-page-body > .region-sidebar-left,
.db-page-body > .region-sidebar-right {
  max-width: var(--db-sidebar-max);
  width: 100%;
}

.db-page-body > .region-sidebar-left {
  justify-self: end;
}

.db-page-body > .region-sidebar-right {
  justify-self: start;
}

.db-page-body > .region-sidebar-left[data-region-empty="1"],
.db-page-body > .region-sidebar-right[data-region-empty="1"] {
  /* Track ≤ --db-sidebar-max via body max-width; box hugs main. */
  min-height: 0;
}

/* Inside the body grid, the center track is the content band — don't double-center. */
.db-page-body .region-main > section.db-widget.db-content-band {
  max-width: none;
  margin-inline: 0;
  width: 100%;
}

.db-page-body .region-sidebar-left > section.db-widget.db-content-band,
.db-page-body .region-sidebar-right > section.db-widget.db-content-band {
  max-width: none;
  margin-inline: 0;
  width: 100%;
  padding-inline: var(--spacing-sm, 0.75rem);
}

/* Hero region sits above the body grid — always full viewport width */
.region-hero {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.region-hero > section.db-widget {
  width: 100%;
  max-width: none;
  margin-inline: 0;
  box-sizing: border-box;
}

/* Bleed widgets break out of their column to the viewport */
.db-page-body section.db-widget.db-widget--bleed,
.db-page-body section.db-widget.widget--bleed {
  width: 100vw;
  max-width: 100vw;
  margin-left: calc(50% - 50vw);
  margin-right: calc(50% - 50vw);
  box-sizing: border-box;
}

/*
 * Hero cover fill + slideshow stack — unlayered so theme `img { max-width }`
 * and missing @layer support cannot collapse slides into a vertical stack.
 * Band chrome (titles, positions) stays in hero.css (@layer).
 */
.hero-jumbo {
  position: relative;
  width: 100%;
  overflow: hidden;
  box-sizing: border-box;
  aspect-ratio: var(--hero-aspect-ratio, 16 / 9);
  max-height: var(--hero-max-height, min(48vh, 480px));
}

/* Fit natural image proportions (best for a single image; slideshow uses first image) */
.hero-jumbo[data-aspect="auto"] {
  max-height: var(--hero-max-height, min(70vh, 720px));
}

.hero-jumbo[data-aspect="ultrawide"] {
  --hero-aspect-ratio: 21 / 9;
  --hero-max-height: min(40vh, 420px);
}

.hero-jumbo[data-aspect="wide"] {
  --hero-aspect-ratio: 16 / 9;
  --hero-max-height: min(48vh, 480px);
}

.hero-jumbo[data-aspect="landscape"] {
  --hero-aspect-ratio: 3 / 2;
  --hero-max-height: min(52vh, 520px);
}

.hero-jumbo[data-aspect="standard"] {
  --hero-aspect-ratio: 4 / 3;
  --hero-max-height: min(56vh, 560px);
}

.hero-jumbo[data-aspect="tall"] {
  --hero-aspect-ratio: 4 / 5;
  --hero-max-height: min(70vh, 640px);
}

.hero-media {
  position: absolute;
  inset: 0;
  display: block;
}

.hero-media img {
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
  object-position: center 40%;
  display: block;
}

.hero-jumbo[data-fit="contain"] .hero-media img {
  object-fit: contain;
  object-position: center center;
  background: color-mix(in srgb, var(--color-primary, #334) 12%, var(--color-bg, #111));
}

/* Slideshow: all slides occupy the same band; opacity crossfade only */
.hero-jumbo--rotating .hero-media-stack {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.hero-jumbo--rotating .hero-slide {
  position: absolute;
  inset: 0;
  margin: 0;
  padding: 0;
  opacity: 0;
}

.hero-jumbo--rotating .hero-slide:first-child {
  opacity: 1;
}

.hero-jumbo--rotating .hero-slide .hero-media {
  position: absolute;
  inset: 0;
}

/* Layout mode: empty sides stay droppable */
html.db-layout-active .db-page-body > .region-sidebar-left[data-region-empty="1"],
html.db-layout-active .db-page-body > .region-sidebar-right[data-region-empty="1"] {
  min-height: 3rem;
  outline: 1px dashed color-mix(in srgb, var(--db-edit-stroke) 45%, transparent);
  outline-offset: -2px;
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--db-edit-halo) 35%, transparent);
}

@media (max-width: 900px) {
  .db-page-body {
    grid-template-columns: minmax(0, 1fr);
  }

  .db-page-body > .region-sidebar-left {
    order: 2;
    justify-self: stretch;
    max-width: none;
  }

  .db-page-body > .region-main {
    order: 1;
  }

  .db-page-body > .region-sidebar-right {
    order: 3;
    justify-self: stretch;
    max-width: none;
  }

  .db-page-body > .region-sidebar-left[data-region-empty="1"],
  .db-page-body > .region-sidebar-right[data-region-empty="1"] {
    display: none;
  }

  html.db-layout-active .db-page-body > .region-sidebar-left[data-region-empty="1"],
  html.db-layout-active .db-page-body > .region-sidebar-right[data-region-empty="1"] {
    display: block;
  }
}
