/**
 * @file
 * AAG Full Page Layout
 *
 * Desktop (>=900px) structure:
 *
 *   .app__container (flex column)
 *     .app__body (flex row)
 *       .app__navigation   ← position: sticky, top: 70px, left column
 *       .app__main         ← flex: 1, right column
 *         .app__hero       ← negative margin-left to become full-bleed,
 *                            sidebar overlays its left edge
 *         .app__main-container
 *     .app__footer (sibling of .app__body)
 *
 * Why flex-row + sticky (not CSS grid with grid-row span): sticky works
 * reliably when the sticky element is a direct flex item whose natural
 * height is less than its flex container's height. The sidebar then
 * pins at top: 70px during scroll and — because the flex container
 * .app__body ends *before* the footer — it slides away above the
 * footer, leaving the footer fully visible.
 *
 * Why the hero lives inside .app__main (not as a sibling of
 * .app__navigation): placing the hero inside the sticky scroll context
 * means the sidebar reaches the top of the banner. Using negative
 * margin-left on the hero lets the banner span full viewport width
 * while the sidebar still occupies its left column.
 *
 * The old aag-base ref used max-height: 595px on the nav content,
 * which clipped tall menus. Here the sticky wrapper clamps to
 * calc(100vh - 70px) and scrolls internally instead.
 */

/**
 * Ancestor sticky-trap neutraliser.
 *
 * The admu2026 theme sets overflow on several ancestors of our layout
 * that all break `position: sticky`:
 *
 *   theme.css:2074  body       { overflow-x: hidden }
 *   nav.css:648     .body-cont { overflow-x: hidden }
 *   theme.css:2200  .body-block{ overflow: hidden }   ← both axes!
 *
 * Per CSS spec, any `overflow` other than `visible` makes that element
 * a scroll container, and `position: sticky` sticks against the nearest
 * such ancestor. Since these ancestors span the full document, the
 * sidebar has nothing to pin against and just scrolls with content.
 *
 * js/layout-sticky-fix.js tags <body> with `has-aag-sticky-layout` when
 * an AAG sticky layout is present. Here we undo the trap *only* on AAG
 * pages by swapping those rules to either `visible` (for .body-block,
 * which never needed clipping) or `clip` (for the x-axis clippers,
 * which wanted to suppress horizontal scrollbars only). `overflow: clip`
 * clips visually without creating a scroll container, so sticky keeps
 * pinning to the viewport.
 *
 * Must stay inside this module — we do not modify the base theme.
 */
body.has-aag-sticky-layout,
body.has-aag-sticky-layout .body-cont {
  overflow-x: clip !important;
}

body.has-aag-sticky-layout .body-block {
  overflow: visible !important;
}

/**
 * Site main nav stacking.
 *
 * The admu2026 theme gives its fixed top navbar z-index: 5
 * (nav.css:.navbar). The AAG sticky sidebar wrapper .app__navigation
 * sits at z-index 9999 so it beats hero overlays (which top out at
 * z-index 30 in components/hero.css). Without intervention, that means
 * the AAG sidebar would cover the site main nav in the top-left
 * overlap region.
 *
 * Per project requirement, the *site* main nav must win over every
 * other element — including banner overlays and the AAG sidebar. We
 * lift the theme's .navbar above our sidebar from within this module
 * so the rule only applies on AAG pages and we never touch the theme.
 */
body.has-aag-sticky-layout .navbar {
  z-index: 10000 !important;
}

/**
 * Mobile header composition (below 900px).
 *
 * The Ateneo de Manila navbar is the main header. Our own fixed
 * .navigation-left__mobile-bar (components/navigation-left.css) sits in the
 * same strip, and the z-index lift above puts the theme navbar on top of
 * it, so every control we drew there was shadowed by the theme's — all of
 * them white-on-white and invisible, but still taking the taps. The left
 * half of the visible hamburger opened the site menu, not AAG nav; a
 * transparent theme container sat over our search icon as a dead zone; and
 * the 220px brand link covered our logo, sending taps to the site home
 * page rather than AAG home.
 *
 * So the theme navbar keeps its wordmark and search, and our strip drops to
 * a band directly beneath it carrying the AAG logo and the hamburger that
 * opens the AAG section drawer.
 *
 * The hamburger is kept because the drawer is the only route to AAG section
 * nav — the theme's hamburger opens the site main menu, which is a
 * different menu. It is safe to keep now that the two bars are stacked
 * rather than overlapping: the theme's controls no longer shadow ours.
 * Search stays hidden, since the theme navbar above already has one.
 *
 * Centring the bar centres the logo, and the hamburger is taken out of flow
 * so it does not pull the logo off-centre. This band renders on every page
 * carrying the nav-left block, not just the AAG home page.
 *
 * --aag-navbar-height is published per frame by js/layout-sticky-fix.js;
 * it has to be measured because the theme navbar changes height as it
 * collapses on scroll, and a hardcoded offset would leave a gap or overlap
 * in every state but one.
 */
@media (max-width: 899px) {
  body.has-aag-sticky-layout .navigation-left__mobile-bar {
    top: var(--aag-navbar-height, 41px);
    justify-content: center;
  }

  body.has-aag-sticky-layout .navigation-left__hamburger {
    position: absolute;
    left: 1.5rem;
    top: 50%;
    transform: translateY(-50%);
  }

  body.has-aag-sticky-layout .navigation-left__search {
    display: none;
  }

  /* While open the drawer is a modal layer, so it has to clear the theme
     navbar that the rule above lifted to 10000 — otherwise the site navbar
     paints a strip across the top of the open drawer.

     It has to be lifted here rather than on the drawer itself:
     .app__navigation sets isolation: isolate, so the drawer's own z-index
     is resolved inside that context and can never exceed its parent's.
     js/components/navigation-left.js sets .aag-drawer-open while open, and
     only while open — the closed drawer slides off-screen behind the
     navbar, which is where it belongs. */
  body.has-aag-sticky-layout.aag-drawer-open .app__navigation {
    z-index: 10001;
  }

  /* Clear both bars, not just ours (aag-base.css assumes ours alone). */
  body.has-aag-sticky-layout .app__main {
    padding-top: calc(var(--aag-navbar-height, 41px) + 54px);
  }

  /* AAG runs nav-style--transparent, which blanks the theme navbar's
     backdrop. Its wordmark and controls are white, so as the main header
     over the offwhite page background they were unreadable. Give it the
     same solid blue the theme uses in its own collapsed state.

     The nav-style rules carry !important at (0,2,1), so these have to be
     (0,3,1) to win regardless of stylesheet order. */
  body.has-aag-sticky-layout.nav-style--transparent .navbar::before,
  body.has-aag-sticky-layout.nav-style--solid .navbar::before,
  body.has-aag-sticky-layout.nav-style--gradient .navbar::before {
    background: var(--color-primary, #001196) !important;
    height: 100% !important;
  }
}

.aag-layout--full-page {
  width: 100%;
  min-height: 100vh;
}

.aag-layout--full-page .app__container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.aag-layout--full-page .app__body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.aag-layout--full-page .app__hero {
  position: relative;
  width: 100%;
  /*
   * display: flex collapses whitespace-only text nodes between the
   * section tag and the hero block, preventing phantom line-height
   * gaps that would make the section slightly taller than the hero
   * content and expose the body background as a white strip.
   */
  display: flex;
  flex-direction: column;
  /*
   * No min-height here. hero-exhibition already enforces min-height: 100vh
   * on its own component class for full-bleed hero pages. Simple/page hero
   * styles use aspect-ratio to set height; forcing 100vh here would create
   * a large empty gap below the image on those pages.
   */
}

.aag-layout--full-page .app__navigation {
  /* Above hero overlays, banner gradients, showcase CTAs, etc. */
  position: relative;
  z-index: 9999;
  isolation: isolate;
}

.aag-layout--full-page .app__main {
  position: relative;
  min-width: 0;
  /* Establish a positioning context so the hero's negative margin
     stays inside this column in terms of DOM flow. */
}

.aag-layout--full-page .app__main-container {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0 1rem;
  width: 100%;
  box-sizing: border-box;
}

@media (min-width: 600px) {
  .aag-layout--full-page .app__main-container {
    padding-left: 2rem;
    padding-right: 2rem;
  }
}

@media (min-width: 900px) {
  .aag-layout--full-page .app__main-container {
    position: relative;
    z-index: 50;
  }

  /* Overshoot: articles overlap the hero only on the home page
     (identified by the full_video hero style). */
  .aag-layout--full-page .app__main:has(.hero-page--style-full_video) .app__main-container {
    margin-top: -4rem;
  }
}

.aag-layout--full-page .app__footer {
  margin-top: auto;
}

@media (min-width: 900px) {
  .aag-layout--full-page .app__body {
    flex-direction: row;
    align-items: flex-start;
  }

  /*
   * Sidebar pins exactly at the site navbar's bottom edge.
   *
   * `--aag-navbar-height` is published by js/layout-sticky-fix.js, which
   * measures .navbar on every scroll/resize/class mutation. That keeps
   * the sidebar flush against the navbar across admu2026's three
   * navbar states (transparent ≈96px, .active ≈72px, .further-scroll
   * ≈44px). Fallback `70px` matches the static aag-base ref so the
   * layout still looks right if JS fails to attach.
   */
  .aag-layout--full-page .app__navigation {
    position: sticky;
    top: var(--aag-navbar-height, 70px);
    flex-shrink: 0;
    align-self: flex-start;
    max-height: calc(100vh - var(--aag-navbar-height, 70px));
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .aag-layout--full-page .app__main {
    flex: 1 1 auto;
  }

  /* Hero escapes the main column to become full-bleed across the
     viewport. The sticky sidebar overlays its left 330px. */
  .aag-layout--full-page .app__main > .app__hero {
    margin-left: -330px;
    width: calc(100% + 330px);
  }

  /*
   * Left-aligned hero content (hero-exhibition-item used on /aag/about,
   * /aag/vital-points, exhibition detail pages, etc.) must be pushed
   * past the 330px sidebar, otherwise the title and label start at x=0
   * of the full-bleed hero and get covered by the sidebar. The base
   * component sets padding-left: 3rem; we stack that on top of the
   * sidebar width so text lands just inside the right edge of the nav.
   */
  .aag-layout--full-page .app__main > .app__hero .hero-exhibition-item__content {
    padding-left: calc(330px + 3rem);
    max-width: calc(900px + 330px);
  }

  /*
   * Non-image hero content (e.g. .vital-points) uses its own
   * `.X__container` with `max-width + margin: auto` to center itself.
   * Inside the full-bleed .app__hero that centering happens relative
   * to the full viewport, which pulls the content ~half the sidebar
   * width to the left — so the title gets tucked behind the sidebar.
   *
   * Pad the hero's left edge by the sidebar width so the inner
   * auto-centered container re-centers inside the main column.
   */
  .aag-layout--full-page .app__main > .app__hero .vital-points {
    padding-left: 330px;
    box-sizing: border-box;
  }
}

@media (min-width: 1200px) {
  .aag-layout--full-page .app__main > .app__hero {
    margin-left: -359px;
    width: calc(100% + 359px);
  }

  .aag-layout--full-page .app__main > .app__hero .hero-exhibition-item__content {
    padding-left: calc(359px + 3rem);
    max-width: calc(1000px + 359px);
  }

  .aag-layout--full-page .app__main > .app__hero .vital-points {
    padding-left: 359px;
  }
}

/*
 * Layout Builder off-canvas dialog fix.
 * Drupal's off-canvas drawer uses z-index: 501. The AAG navigation sits at
 * z-index: 9999 (app__navigation) and the theme navbar is lifted to 10000 on
 * AAG pages. Without this rule the drawer slides in behind the sidebar, making
 * the block-configure form unreachable on the left side.
 */
#drupal-off-canvas-wrapper {
  z-index: 10001 !important;
}
