/* =========================================================
   MOBILE NAV — direct port of the MSEn pattern
   Environmental Sciences and Engineering · AUTH

   Pairs with the hamburger button + inline script added to
   nav.ejs. Toggle class .is-open is applied to #siteHeader.

   Desktop (>960px) is UNTOUCHED: the toggle button is hidden
   and every existing nav rule applies exactly as before.
   ========================================================= */


/* Toggle button — hidden on desktop */
.nav-toggle { display: none; }


@media (max-width: 960px) {

  /* --------------------------------------------------------
     HEADER WRAP: allow children to wrap to a new row.
     Top row keeps logo + hamburger; .nav-primary wraps below
     when the drawer is opened.
     -------------------------------------------------------- */
  .site-header .wrap {
    flex-wrap: wrap;
    row-gap: 0;
  }


  /* --------------------------------------------------------
     HAMBURGER BUTTON
     Shows on mobile. 44 × 44 tap target. Pushed to the far
     right of the top row via margin-left: auto.
     -------------------------------------------------------- */
  .nav-toggle {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;

    width: 44px;
    height: 44px;
    flex-shrink: 0;

    margin-left: auto;
    padding: 0;

    background: transparent;
    border: 1px solid var(--rule);
    border-radius: 3px;

    color: var(--ink);
    cursor: pointer;

    transition: border-color 0.2s, background 0.2s, color 0.2s;
  }

  .nav-toggle:hover {
    border-color: var(--marble-red);
    color: var(--marble-red);
  }

  .nav-toggle:focus-visible {
    outline: 2px solid var(--marble-red);
    outline-offset: 3px;
  }

  .nav-toggle-bar {
    display: block;
    width: 20px;
    height: 2px;
    background: currentColor;
    border-radius: 1px;
    transition: transform 0.25s ease, opacity 0.2s ease;
  }

  /* Hamburger → × when the header has .is-open */
  .site-header.is-open .nav-toggle-bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
  }
  .site-header.is-open .nav-toggle-bar:nth-child(2) {
    opacity: 0;
  }
  .site-header.is-open .nav-toggle-bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
  }


  /* --------------------------------------------------------
     NAV-PRIMARY — hidden by default on mobile.
     Opens as a full-width wrapped row below the logo+hamburger.
     -------------------------------------------------------- */
  .nav-primary {
    display: none;
    flex-basis: 100%;
    width: 100%;
  }

  .site-header.is-open .nav-primary {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;

    padding: 8px 0 20px;

    /* If the drawer ever gets taller than the viewport, scroll it
       internally rather than letting the whole page scroll. */
    max-height: calc(100vh - 76px);
    max-height: calc(100dvh - 76px);
    overflow-y: auto;
    overscroll-behavior: contain;
  }


  /* --------------------------------------------------------
     NAV LINKS — large serif rows with hairline dividers
     -------------------------------------------------------- */
  .site-header.is-open .nav-primary > a:not(.btn-apply) {
    display: block;
    padding: 16px 2px;

    font-family: var(--serif);
    font-size: 20px;
    font-weight: 400;
    line-height: 1.3;
    letter-spacing: -0.005em;

    color: var(--ink);
    border-top: 1px solid var(--rule);

    transition: color 0.2s;
  }

  .site-header.is-open .nav-primary > a:not(.btn-apply):first-of-type {
    margin-top: 6px;
  }

  .site-header.is-open .nav-primary > a:not(.btn-apply):hover {
    color: var(--marble-red);
  }


  /* --------------------------------------------------------
     SOCIAL — small horizontal row, below the links
     Removes the desktop's left border/padding; adds top border
     -------------------------------------------------------- */
  .site-header.is-open .nav-primary .nav-social {
    display: flex;
    align-items: center;
    gap: 12px;

    margin: 0;
    padding: 18px 0 0;

    border-left: 0;
    border-top: 1px solid var(--rule);
  }

  .site-header.is-open .nav-primary .nav-social a {
    width: 40px;
    height: 40px;
  }

  .site-header.is-open .nav-primary .nav-social svg {
    width: 16px;
    height: 16px;
  }


  /* --------------------------------------------------------
     APPLY CTA — full-width button, below the social row
     -------------------------------------------------------- */
  .site-header.is-open .nav-primary .btn-apply {
    display: flex;
    justify-content: space-between;
    align-items: center;

    width: 100%;
    margin: 22px 0 0;
    padding: 14px 12px 14px 20px;

    font-size: 13px !important;
  }


  /* --------------------------------------------------------
     LANGUAGE SWITCHER (if uncommented in nav.ejs later)
     -------------------------------------------------------- */
  .site-header.is-open .nav-primary .nav-lang {
    display: flex;
    margin: 16px 0 0;
    padding-left: 0;
    border-left: 0;
  }


  /* --------------------------------------------------------
     PAGE SCROLL LOCK — the inline script adds .nav-locked
     to <html> when the drawer is open. Keeps the page behind
     from scrolling.
     -------------------------------------------------------- */
  html.nav-locked,
  html.nav-locked body {
    overflow: hidden;
  }

}


/* =========================================================
   SMALL PHONES — tighten padding so the top row fits
   ========================================================= */

@media (max-width: 480px) {

  .site-header .wrap {
    padding: 0 20px;
  }

  .header-left {
    gap: 12px;
  }

  .site-header.is-open .nav-primary > a:not(.btn-apply) {
    font-size: 18px;
    padding: 14px 2px;
  }

}


/* =========================================================
   VERY NARROW (≤360px) — hide the wordmark; logo alone
   stays as the brand mark so the top row fits.
   ========================================================= */

@media (max-width: 360px) {

  .header-wm,
  .header-divider {
    display: none;
  }

}


/* =========================================================
   REDUCED MOTION — honour the OS/browser preference
   ========================================================= */

@media (prefers-reduced-motion: reduce) {

  .nav-toggle-bar {
    transition: none;
  }

}