/* [[[[ GLOBAL PAGE LAYOUT & GRID ]]]] */

.page-layout {
  padding: 0 var(--page-gutter);
  /* Standard page padding + bottom buffer */
  max-width: 100vw;
}

.layout-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  column-gap: 2rem;
  row-gap: var(--grid-row-gap);
  /* Macro Spacing */
  max-width: 1400px;
  padding-bottom: 3rem;
}

/* HOLISTIC GRID LOGIC: */
/* The Grid Container controls all spacing via row-gap. */
/* Direct children with layout classes must NOT have their own vertical margins. */
/* Specificity (0-2-0) ensures this beats individual component classes (0-1-0). */
.layout-grid>[class*="layout-"] {
  margin-block: 0;
}

/* HOLISTIC PAGE START SPACING: */
/* 1. Standard Pages: The first item gets top margin, UNLESS it is the sidebar */
.layout-grid>:first-child:not(.page-layout__sidebar) {
  margin-top: 3rem;
}

/* 2. Sidebar Pages: The content Next Sibling to the sidebar gets top margin */
.page-layout__sidebar+* {
  margin-top: 3rem;
}

/* =========================== */
/* [[[[ LAYOUT REGIONS ]]]]    */
/* =========================== */


.layout-subgrid {
  display: grid;
  grid-template-columns: subgrid;
}

/* Full Width (12 cols) */
.layout-full {
  grid-column: 1 / -1;
}

/* Wide Content (10 cols - centered) */
.layout-wide {
  grid-column: 2 / -2;
}

/* Standard Content (8 cols - centered) */
.layout-center {
  grid-column: 3 / 11;
}

/* Narrow Content (4 cols - centered) */
/* Useful for portrait images or focused content */
.layout-narrow-center {
  grid-column: 5 / 9;
}

/* Narrow Content (5 cols - Left Aligned) */
.layout-narrow-left {
  grid-column: 3 / 8;
}

/* Allow .prose class on subgrid for typography, but remove the container cap */
/* The Grid Columns (layout-center) will control the width instead */
.layout-subgrid.prose {
  max-width: none;
}

/* !!! SPACING SAFETY VALVE (GLOBAL) !!! */
/* Prevent double spacing if a block is the last item in a layout container */
[class*="layout-"]>*:last-child {
  margin-bottom: 0 !important;
}



/* Sidebar layout - the container for the nav */
.page-layout__sidebar {
  grid-column: span 3;
  position: relative;
  margin-top: 0;
  margin-bottom: -3rem;
  padding-top: 0;
  padding-bottom: 3rem;
}


/* Sidebar layout - the content next to nav */
.page-layout__content-wrapper {
  grid-column: span 9;
  display: flex;
  flex-direction: column;
  row-gap: 2.5rem;
}



/* ========================= */
/* [[[[ RESPONSIVE GRID ]]]] */
/* ========================= */

/* ==== TABLET (Breakpoint: 1200px) ==== */
@media (max-width: 1200px) {

  .layout-grid {
    grid-template-columns: repeat(8, 1fr);
    column-gap: 1.5rem;
    row-gap: var(--grid-row-gap);
    padding-block: 2.5rem;
  }

  /* Reset Layout Utilities for Tablet (8 Col Grid) */
  .layout-center,
  .layout-narrow-center,
  .layout-narrow-left {
    grid-column: 2 / 8;
  }

  .layout-wide {
    grid-column: 1 / -1;
  }

  .layout-full {
    grid-column: 1 / -1;
  }

  .page-layout__sidebar {
    grid-column: span 2;
    height: auto;
    margin-top: 0;
    margin-bottom: -2.5rem;
    padding-top: 0;
    padding-bottom: 2.5rem;
  }


  .page-layout__content-wrapper {
    grid-column: span 6;
    row-gap: 2.5rem;
  }

  .layout-grid>:first-child:not(.page-layout__sidebar),
  .page-layout__sidebar+* {
    margin-top: 2.5rem;
  }

}


/* ==== MOBILE (Breakpoint: 800px) ==== */

@media (max-width: 800px) {

  .page-layout {
    padding: 0 var(--page-gutter);
  }


  .layout-grid {
    grid-template-columns: repeat(4, 1fr);
    column-gap: 1rem;
    row-gap: var(--grid-row-gap);
  }

  /* Reset Layout Utilities for Mobile (4 Col Grid) */
  .layout-center,
  .layout-narrow-center,
  .layout-narrow-left,
  .layout-wide,
  .layout-full {
    grid-column: 1 / -1;
  }

  .page-layout__content-wrapper {
    row-gap: 1.5rem;
  }

  /* Responsive Holistic Spacing (Mobile) */
  .layout-grid>:first-child:not(.page-layout__sidebar),
  .page-layout__sidebar+* {
    margin-top: 1.5rem;
  }


}