/*
 * Site chrome state CSS (header + slide-out nav).
 *
 * Owns the header's visual states, replacing the imperative jQuery that used
 * to set these as inline styles from index.php/page.php:
 *   - default (>=982px, top of page): transparent 140px bar, full nav, full logo
 *   - .is-scrolled (>=982px, scrolled): compact white bar, hamburger, compact logo
 *   - <=981px: always the compact white bar (pure media query, no JS)
 *
 * Selectors use div.top-header (element+class) so they beat the single-class
 * rules emitted later in the document by classes/common.php's body <style>.
 * The .is-scrolled class is toggled by assets/scripts/chrome.js.
 */

/* Anchor targets land below the fixed header instead of underneath it. */
html {
  scroll-padding-top: 150px;
}

/* --- top-of-page desktop state --- */

/* Legibility scrim: the header is transparent by design (white nav text over
   a dark hero), which is unreadable on light-topped pages. A subtle top
   gradient plus a text-shadow on the plain nav links keeps the design while
   making the nav legible everywhere. */
div.top-header {
  background: linear-gradient(180deg, rgba(25, 40, 55, 0.45) 0%, rgba(25, 40, 55, 0) 100%);
}

div.top-header #nav-bar li a {
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

/* Filled elements (CONTACT US button, phone box) need no shadow. */
div.top-header #nav-bar li a.spc-btn,
div.top-header #nav-bar li a.ph-num-menu {
  text-shadow: none;
}

/* --- logo variants (all three are in the DOM; CSS picks one) --- */

div.top-header .logo-compact,
div.top-header .logo-mobile {
  display: none;
}

/* Clearance spacer emitted by page.php for DB pages whose content has no
   self-clearing .top-banner (they would otherwise start under the header). */
.header-clearance {
  height: 140px;
}

/* --- scrolled desktop state --- */

div.top-header.is-scrolled {
  background: #fff;
  height: 100px;
  box-shadow: 0px 1px 2px #7c7d7d;
}

div.top-header.is-scrolled #nav-bar {
  display: none;
}

div.top-header.is-scrolled .on-scroll-div {
  display: block;
}

div.top-header.is-scrolled .menu-bar {
  text-align: right;
}

div.top-header.is-scrolled .logo-section {
  padding-top: 13px;
  padding-left: 55px;
}

div.top-header.is-scrolled .logo-full {
  display: none;
}

div.top-header.is-scrolled .logo-compact {
  display: inline-block;
}

/* --- dropdowns on hover (replaces showSubMenu/hideSubMenu/dropdownMenu) --- */

#nav-bar li:hover > .sub-menu {
  display: block;
}

/* Open dropdowns must be an opaque panel that floats above every other nav
   item. The base .sub-menu is transparent with white text — legible over the
   dark hero, but on medium widths the CONTACT US button and phone box wrap onto
   a second row directly over where these menus open. Those items are opaque and
   come later in source order, so without help they paint on top of the menu:
   it can't be seen and its links can't be clicked. Fix both by lifting the
   hovered item (and thus its menu) above its siblings, and by giving the panel
   a translucent navy background (the header scrim colour) with a backdrop blur,
   padding and a shadow so it reads as a distinct surface in every header state.
   The panel is also centred under its trigger via left:50% + translateX. */
div.top-header #nav-bar li:hover {
  z-index: 1000;
}

div.top-header .sub-menu {
  z-index: 1000;
  min-width: 160px;
  padding: 12px 14px 6px;
  top: calc(100% + 12px); /* drop the panel below the item, leaving a gap */
  left: 50%;
  transform: translateX(-50%); /* centre the panel under its trigger */
  background: rgba(25, 40, 55, 0.9); /* navy scrim, slightly translucent */
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-radius: 6px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
}

/* Invisible bridge across the gap: the pointer moving from the label down into
   the panel would otherwise cross dead space and drop the :hover, closing the
   menu. This ::before is a descendant of .sub-menu, so hovering it keeps the
   parent li :hover alive all the way down. */
div.top-header .sub-menu::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 12px;
}

/* --- desktop nav: single-row flex (>=982px) --- */

/* The legacy nav gave every item a fixed width (max-width:170 / width:125-140)
   times eight items, which overflowed the menu bar and wrapped CONTACT US + the
   phone box onto a second row on essentially every screen below ~1800px. A
   nowrap flex row of content-sized items keeps all eight on one line from 1920
   down to the 982px hamburger breakpoint.

   Prefixed with div.top-header so it beats the later single-id nav rules in
   common.css, and scoped to >=982px so the mobile (.to-disp-desk) and scrolled
   (.is-scrolled) hide rules still win. Vertical placement is left to the base
   #nav-bar padding, which align-items:center then centres the single row in.
   clamp() on padding/type scales everything with viewport width — tight enough
   at 982px that all eight items still clear the logo, roomy on wide screens —
   so there is no hard breakpoint step. */
@media (min-width: 982px) {
  div.top-header #nav-bar {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-end;
  }

  div.top-header #nav-bar > li {
    width: auto;
    max-width: none;
    margin-bottom: 0;
    /* symmetric padding doubles as the inter-item spacer: ~6px at 982 (so the
       row still fits beside the logo), opening to 18px on wide screens */
    padding: 4px clamp(6px, 1.9vw - 12.6px, 18px);
    border-right: none;
    white-space: nowrap;
    flex: 0 0 auto;
  }

  /* Short divider centred on each item's trailing edge — a lighter, modern
     replacement for the old full-height border-right. Skipped on the trailing
     CONTACT US button and phone box (.no-border-right). */
  div.top-header #nav-bar > li:not(.no-border-right)::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 0;
    width: 1px;
    height: 16px;
    background: #7d7d7d;
    transform: translateY(-50%);
  }

  div.top-header #nav-bar > li > a {
    font-size: clamp(13px, 0.34vw + 9.7px, 14px);
  }

  div.top-header #nav-bar > li a.ph-num-menu {
    font-size: clamp(13px, 0.5vw + 9px, 16px);
    padding: 7px clamp(10px, 1vw, 20px);
  }
}

/* Slide-out nav submenus (accordion).
   Desktop (has hover): expand the section under the pointer.
   Touch/narrow (no hover): each section is collapsed until tapped, when
   chrome.js toggles .is-expanded. The old build forced every submenu open on
   mobile; this restores the tap-to-expand behavior prod always intended. */
@media (min-width: 982px) {
  #scroll-sidebar li:hover > .sidebar-dropdown {
    display: block;
  }
}

#scroll-sidebar .sidebar-dropdown.is-expanded {
  display: block;
}

/* +/- affordance so collapsed sections read as tappable (drawer text is
   right-aligned, so the marker sits at the opposite, left edge). Mobile only —
   desktop expands on hover, where a static "+" would be misleading. */
@media (max-width: 981px) {
  #scroll-sidebar .has-submenu > a::after {
    content: "+";
    float: left;
    margin-top: -1px;
    font-weight: bold;
    color: #38a1da;
  }

  #scroll-sidebar .has-submenu.is-open > a::after {
    content: "\2212"; /* minus */
  }
}

/* --- slide-out nav open state (chrome.js toggles .is-open) --- */

/* The old jQuery width/height toggle reflowed the drawer mid-animation: menu
   items wrapped to two lines while the box grew, then snapped into place. A
   transform slide cannot reflow. Open animates briefly; close is instant. */
#scroll-sidebar.is-open {
  display: block;
  animation: bmw-drawer-in 0.18s ease-out;
}

@keyframes bmw-drawer-in {
  from {
    transform: translateX(60px);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

/* --- compact white bar below the desktop breakpoint (no JS involved) --- */

@media (max-width: 981px) {
  html {
    scroll-padding-top: 110px;
  }

  .header-clearance {
    height: 100px;
  }

  div.top-header {
    background: #fff;
    height: 100px;
    box-shadow: 0px 1px 2px #7c7d7d;
  }

  div.top-header .on-scroll-div {
    display: block;
    margin-right: 30px;
  }

  div.top-header .menu-bar {
    text-align: right;
  }

  div.top-header .logo-section {
    padding-top: 13px;
    padding-left: 30px;
  }

  div.top-header .logo-full,
  div.top-header .logo-compact {
    display: none !important;
  }

  div.top-header .logo-mobile {
    display: inline-block;
    width: 60px;
  }
}

@media (max-width: 480px) {
  html {
    scroll-padding-top: 80px;
  }

  .header-clearance {
    height: 70px;
  }

  div.top-header .logo-mobile {
    width: 50px;
  }
}
