/*
 * The site-wide primary navigation - see _templates/site-nav.html.
 *
 * A hand port of the Tailwind classes in shared/siteNav/SiteNav.tsx, which both
 * landing pages render and which is itself a port of the marketing site's
 * header. Sphinx has no Tailwind, so every class there is written out here;
 * the values are that file's values, utility for utility:
 *
 *   h-20 = 5rem     h-14 = 3.5rem       text-sm = .875rem   py-4 = 1rem
 *   px-6 = 1.5rem   lg:px-10 = 2.5rem   text-lg = 1.125rem  pl-4 = 1rem
 *   md:  = 48rem    lg:  = 64rem        max-w-7xl = 80rem   gap-8 = 2rem
 *
 * Changing the look of the bar means changing it in all three places, or they
 * stop matching - which is the whole point of the bar.
 *
 * The one value that is deliberately this site's own is the background. There
 * it is each app's dark brand field, passed in per app (purple on researcher,
 * teal on participant); here it is the navy the documentation's own chrome
 * already uses - see the .wy-side-nav-search and .wy-nav-top rules in
 * custom.css - so the bar reads as the top of this site rather than as a
 * transplant from one of the other two. It is opaque rather than the React
 * bar's 80% + backdrop blur, because what scrolls under it here is a white
 * page, and white text over a white page tinted 80% navy is not readable.
 */

:root {
  /* The bar's own height: h-20 at rest, h-14 once the page has scrolled, as in
     SiteNav.tsx (`scrolled ? 'h-14' : 'h-20'`) and the marketing theme's
     primary-header.twig. site-nav.js puts .vera-nav-scrolled on <html>.
     This used to be a flat 3.5rem - the shrunken height - which left the bar
     1.5rem shorter than the other two sites' at the top of the page. */
  --vera-nav-height: 5rem;
  /* The room the layout leaves for the bar, pinned to the bar's EXPANDED height
     and deliberately not following it down.

     .wy-grid-for-nav is absolutely positioned in the document rather than
     fixed, so animating its top would shift the whole page up by 1.5rem as the
     bar shrank, mid-scroll. At rest the two values are equal, which is when it
     matters; once scrolled, the content has already passed under the bar and
     the difference cannot be seen. The sidebar does follow the bar, because it
     is fixed and moving it shifts nothing. */
  --vera-nav-layout-offset: 5rem;
  --vera-nav-navy: #160335;
  /* The hairline gradient that marks the current item. Literal hex, as in
     SiteNav.tsx: the landing pages' Tailwind configs deliberately disagree
     about the brand colours while this bar must not. */
  --vera-nav-accent-from: #a78bfa;
  --vera-nav-accent-to: #22d3ee;
}

/* ---------------------------------------------------------------------------
   Room for the bar.

   The theme's whole layout is one absolutely positioned box filling the
   viewport (.wy-grid-for-nav) with a fixed sidebar beside it, so making room
   at the top means shortening both rather than adding a margin anywhere.
   .wy-nav-side needs its min-height cut as well as its top moved: it is
   min-height:100% of the viewport, which would otherwise push the foot of the
   sidebar - and the last items of the table of contents - below the fold.
   --------------------------------------------------------------------------- */

/* The layout offset, not the live bar height - see the note on the variables. */
.wy-grid-for-nav {
  top: var(--vera-nav-layout-offset);
  height: calc(100% - var(--vera-nav-layout-offset));
}

/* Fixed, so this one does follow the bar: left at the expanded offset it would
   leave a 1.5rem strip of page between the shrunken bar and the top of the
   sidebar. Moving it shifts no document content, so it is free to animate. */
.wy-nav-side {
  top: var(--vera-nav-height);
  min-height: calc(100% - var(--vera-nav-height));
}

/* Gated on .vera-nav-ready - see the note by the bar's own transition. */
.vera-nav-ready .wy-nav-side {
  transition:
    top 300ms ease,
    min-height 300ms ease;
}

/* An in-page anchor - every heading link and every entry in a page's own
   contents - would otherwise land with its target hidden behind the bar. The
   expanded height, so a target clears the bar in either state. */
html {
  scroll-padding-top: var(--vera-nav-layout-offset);
}

/* The shrunken bar. Only the custom property changes; every rule above reads
   it, so the bar and the sidebar follow from this one declaration. */
html.vera-nav-scrolled {
  --vera-nav-height: 3.5rem;
}

@media (prefers-reduced-motion: reduce) {
  .vera-nav-ready .wy-nav-side {
    transition: none;
  }
}

/* ---------------------------------------------------------------------------
   The bar
   --------------------------------------------------------------------------- */

.vera-site-nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  /* Clear of the theme's own chrome: .wy-nav-side is 200, .rst-versions 400,
     .wy-body-mask 499. */
  z-index: 600;
  height: var(--vera-nav-height);
  background-color: var(--vera-nav-navy);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* transition-[height] duration-300, as on the inner row of the other two bars.
   The background does not transition with it: unlike theirs this one is opaque
   in both states, for the reason in the file header.

   Gated on .vera-nav-ready, which site-nav.js adds a frame after load, so the
   height a page opens at is never animated into place. These pages are
   navigated between as full loads, and the browser restores the scroll position
   (Back) or jumps to an anchor (any contents link) only after first layout -
   so the bar would otherwise slide 5rem -> 3.5rem in front of the reader every
   time one of those loads, which is exactly the flash on navigation that must
   not happen. Once the class is on, a genuine scroll animates as it does on the
   other two sites. */
.vera-nav-ready .vera-site-nav {
  transition: height 300ms ease;
}

@media (prefers-reduced-motion: reduce) {
  .vera-nav-ready .vera-site-nav {
    transition: none;
  }
}

/* Below the desktop breakpoint there is nothing to centre — the items are
   display:none and only the toggle is left — so the row is a plain flex, as it
   is in SiteNav.tsx. There the distinction matters because the landing pages
   put Log In / Sign Up in this row and three equal columns left them too little
   width; here there is nothing beside the toggle, and the structure is kept the
   same only so the two stay readable against each other. */
.vera-site-nav__bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
  height: 100%;
  max-width: 80rem;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* The left slot: the documentation's own controls below the breakpoint, an
   empty cell above it (where a missing cell would collapse its column and pull
   the nav off centre). See the markup for why they live here. */
.vera-site-nav__spacer {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  /* The bar is justify-content:flex-end below the breakpoint, for the toggle on
     its own. With something in the left slot too, the two ends want pushing
     apart instead. */
  margin-right: auto;
}

.vera-site-nav__brand {
  display: inline-flex;
  align-items: center;
  /* -ml-2 against the bar's px-6, so the mark reads as aligned to the edge
     rather than inset by a full gutter — the mirror of the toggle's -mr-3. */
  margin-left: -0.5rem;
}

.vera-site-nav__brand img {
  display: block;
  height: 2.25rem;
  width: 2.25rem;
}

/* Sized like the menu toggle opposite it, so the two ends of the bar match. */
.vera-site-nav__contents {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 3rem;
  width: 3rem;
  padding: 0;
  border: 0;
  border-radius: 9999px;
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  touch-action: manipulation;
  transition: color 0.15s ease;
}

.vera-site-nav__contents:hover,
.vera-site-nav__contents:focus {
  color: #fff;
}

.vera-site-nav__contents svg {
  height: 1.75rem;
  width: 1.75rem;
}

@media screen and (min-width: 48rem) {
  .vera-site-nav__bar {
    display: grid;
    /* Equal side slots with an auto-width middle: the nav is centred between
       the sides whatever sits in them, so it cannot be pushed off centre. */
    grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  }

  /* Back to an empty cell: the sidebar is on screen from here up, carrying the
     logo at its head, so neither control has anything left to do. */
  .vera-site-nav__spacer {
    display: block;
    margin-right: 0;
  }

  .vera-site-nav__brand,
  .vera-site-nav__contents {
    display: none;
  }
}

@media screen and (min-width: 64rem) {
  .vera-site-nav__bar {
    padding: 0 2.5rem;
  }
}

.vera-site-nav__items {
  display: none;
  align-items: center;
  gap: 2rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
}

@media screen and (min-width: 48rem) {
  .vera-site-nav__items {
    display: flex;
  }
}

/* The theme styles bare `a:visited`, which outranks a single class, so each
   colour has to name the visited state too or half the items turn purple. */
.vera-site-nav__item,
.vera-site-nav__item:visited {
  position: relative;
  color: rgba(255, 255, 255, 0.6);
  text-decoration: none;
  transition: color 0.15s ease;
}

/* The gradient hairline under the current item: scaled out from its left edge,
   so it animates in if the item ever becomes current without a page load. As
   in SiteNav.tsx, hover only lightens the label - the underline marks the
   current page alone. */
.vera-site-nav__item::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -0.375rem;
  height: 0.125rem;
  border-radius: 9999px;
  background-image: linear-gradient(
    to right,
    var(--vera-nav-accent-from),
    var(--vera-nav-accent-to)
  );
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.3s;
}

.vera-site-nav__item:hover,
.vera-site-nav__item:focus,
.vera-site-nav__item[aria-current],
.vera-site-nav__item[aria-current]:visited {
  color: #fff;
}

.vera-site-nav__item[aria-current]::after {
  transform: scaleX(1);
}

.vera-site-nav__actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* Named explicitly because the items between are display:none below the
   breakpoint: without it this cell would fall into the middle column and the
   toggle would end up centred. Inside the query because there is no grid to
   place it in below that width. */
@media screen and (min-width: 48rem) {
  .vera-site-nav__actions {
    grid-column-start: 3;
  }
}

/* Icon-only buttons, sized for a thumb rather than for the glyph. */
.vera-site-nav__toggle {
  margin-right: -0.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 3rem;
  width: 3rem;
  padding: 0;
  border: 0;
  border-radius: 9999px;
  background: transparent;
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  touch-action: manipulation;
  transition: color 0.15s ease;
}

.vera-site-nav__toggle:hover,
.vera-site-nav__toggle:focus {
  color: #fff;
}

.vera-site-nav__icon {
  height: 2rem;
  width: 2rem;
}

@media screen and (min-width: 48rem) {
  .vera-site-nav__bar .vera-site-nav__toggle {
    display: none;
  }
}

/* ---------------------------------------------------------------------------
   The mobile panel

   Closed, it stays in the DOM - it has to, to slide back out - so it is moved
   off-canvas rather than hidden, and site-nav.js takes it out of the tab order
   and the accessibility tree with `inert`. Above the breakpoint it is
   display:none, which is also why site-nav.js closes it on a widening viewport:
   left open, it would be holding the scroll lock and the focus.

   One behaviour of the marketing site's header is dropped here as it is in
   SiteNav.tsx: it slides the whole page left as the panel comes in, which needs
   every page wrapper to take part. The panel slides over a dimmed page instead.
   --------------------------------------------------------------------------- */

.vera-site-nav__scrim {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 610;
  background-color: rgba(0, 0, 0, 0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease-out;
}

.vera-site-nav__scrim[data-open] {
  opacity: 1;
  pointer-events: auto;
}

.vera-site-nav__panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 620;
  display: flex;
  flex-direction: column;
  width: min(20rem, 85vw);
  overflow-y: auto;
  overscroll-behavior: contain;
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  background-color: var(--vera-nav-navy);
  transform: translateX(100%);
  transition: transform 0.3s ease-out;
}

.vera-site-nav__panel[data-open] {
  transform: translateX(0);
}

@media screen and (min-width: 48rem) {
  .vera-site-nav__scrim,
  .vera-site-nav__panel {
    display: none;
  }
}

.vera-site-nav__panel-head {
  display: flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: space-between;
  /* The bar's expanded height, so the heading lines up with it. */
  height: 5rem;
  padding: 0 1.5rem;
}

.vera-site-nav__panel-title {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  color: rgba(255, 255, 255, 0.4);
}

.vera-site-nav__panel-list {
  margin: 0 1.5rem;
  padding: 0;
  list-style: none;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.vera-site-nav__panel-list li + li {
  border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.vera-site-nav__panel-link,
.vera-site-nav__panel-link:visited {
  position: relative;
  display: block;
  padding: 1rem 0 1rem 1rem;
  font-size: 1.125rem;
  line-height: 1.75rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.7);
  text-decoration: none;
  transition: color 0.15s ease;
}

/* The same gradient as the desktop underline, as a bar down the left of the
   current item. */
.vera-site-nav__panel-link::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  height: 1.25rem;
  width: 0.125rem;
  transform: translateY(-50%);
  border-radius: 9999px;
  background-image: linear-gradient(
    to bottom,
    var(--vera-nav-accent-from),
    var(--vera-nav-accent-to)
  );
  opacity: 0;
}

.vera-site-nav__panel-link:hover,
.vera-site-nav__panel-link:focus,
.vera-site-nav__panel-link[aria-current],
.vera-site-nav__panel-link[aria-current]:visited {
  color: #fff;
}

.vera-site-nav__panel-link[aria-current]::before {
  opacity: 1;
}

/* Printing a page should not spend 3.5rem of the first sheet on navigation. */
@media print {
  .vera-site-nav,
  .vera-site-nav__scrim,
  .vera-site-nav__panel {
    display: none;
  }

  .wy-grid-for-nav {
    top: 0;
    height: 100%;
  }
}
