/**
 * @file
 * MLT Modern — Page layout (container + sidebar grid).
 *
 * Wraps the main content area + optional sidebars in a centred 1200px
 * container. Uses CSS Grid with template columns driven by classes the
 * page.html.twig template adds based on which sidebar regions have blocks.
 *
 *   .mlt-layout                     → no sidebars, main is 100%
 *   .mlt-layout--has-left           → left + main
 *   .mlt-layout--has-right          → main + right
 *   .mlt-layout--has-left.has-right → left + main + right
 *
 * Landing pages skip this whole layout — they use page--node--mlt-landing-
 * page.html.twig which renders the node body raw without this wrapper.
 *
 * Mobile (<992px): everything stacks to a single column. The three regions
 * stack in this visual order regardless of source order:
 *   1. sidebar_first  (above main content)
 *   2. content        (the main column)
 *   3. sidebar_second (below main content)
 *
 * STICKY GOTCHA — IMPORTANT:
 * We do NOT use `align-items: start` on the grid. If we did, grid items
 * (the sidebars and main content) would shrink to their content height,
 * which makes the sidebars only as tall as their blocks — and that breaks
 * position: sticky on those blocks (sticky needs a parent taller than the
 * sticky element, with somewhere to scroll past).
 *
 * Instead we let the grid use its default `align-items: stretch`. All grid
 * items stretch to the height of the tallest one (almost always the main
 * content column on a long article page). The sidebar asides become as
 * tall as the main content, which gives sticky elements inside them
 * plenty of scroll space.
 *
 * For sticky elements specifically, css/components/section-appearance.css
 * sets `align-self: start` on .mlt-section--sticky so the sticky element
 * itself shrinks to its content height inside the tall aside — leaving
 * scroll room around it.
 */

.mlt-layout {
  max-width: var(--mlt-container-max);
  margin: 0 auto;
  padding: 40px var(--mlt-container-pad);
  display: grid;
  gap: 32px;

  /* Default (no sidebars): single column, main takes full width. */
  grid-template-columns: 1fr;

  /* No align-items declaration here — we want the default `stretch` so
   * sidebars match main content height (essential for sticky to work).
   * See header comment for full explanation. */
}

/* Left sidebar only: left | main */
.mlt-layout--has-left:not(.mlt-layout--has-right) {
  grid-template-columns: 300px 1fr;
}

/* Right sidebar only: main | right */
.mlt-layout--has-right:not(.mlt-layout--has-left) {
  grid-template-columns: 1fr 300px;
}

/* Both sidebars: left | main | right */
.mlt-layout--has-left.mlt-layout--has-right {
  grid-template-columns: 280px 1fr 280px;
}

/* Mobile: collapse to single column, sidebars stack around main. */
@media (max-width: 991px) {
  .mlt-layout.mlt-layout,
  .mlt-layout--has-left.mlt-layout--has-left,
  .mlt-layout--has-right.mlt-layout--has-right,
  .mlt-layout--has-left.mlt-layout--has-right {
    grid-template-columns: 1fr;
    padding: 24px var(--mlt-container-pad);
    gap: 24px;
  }

  .mlt-region--sidebar-first {
    order: 1;
  }
  .mlt-region--content {
    order: 2;
  }
  .mlt-region--sidebar-second {
    order: 3;
  }
}
