/* ════════════════════════════════════════════════════════════════════════
   Shared green-header nav (v3)
   Pairs with template-parts/template-custom-nav-v3.php.
   Load this AFTER a page's own stylesheet so these rules win by load order
   (selectors match the older per-page nav rules, same specificity).
   Green is inlined (rgba(68,214,44,1)) so it doesn't depend on a page :root.
   ════════════════════════════════════════════════════════════════════════ */

/* ── BURGER ───────────────────────────────── */
.nav-burger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  z-index: 101;
}

.nav-burger span {
  display: block;
  width: 24px;
  height: 2px;
  background: white;
  border-radius: 2px;
  transition: transform 0.3s, opacity 0.3s;
}

.nav-burger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav-burger.open span:nth-child(2) { opacity: 0; }
.nav-burger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

/* ── NAV ──────────────────────────────────── */
nav {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(68, 214, 44, 1);
  backdrop-filter: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.45);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 60px;
  height: 96px;
}

/* WordPress admin bar offset for logged-in users */
.admin-bar nav { top: 32px; }
@media screen and (max-width: 782px) {
  .admin-bar nav { top: 46px; }
}

.nav-logo {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.nav-logo img {
  height: 100% !important;
  max-height: 70px !important;
  width: auto;
  display: block;
}

.nav-logo-icon { display: none; }
.nav-logo-text { display: none; }

.nav-links {
  display: flex;
  align-items: center;
  gap: 32px;
  height: 100%;
  list-style: none;
}

.nav-links > li {
  position: relative;
  display: flex;
  align-items: center;
  height: 100%;
}

.nav-links > li > a {
  color: white;
  text-decoration: none;
  font-size: clamp(14px, calc(7.14px + 0.67vw), 20px);
  font-weight: 700;
  transition: color 0.2s;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 20px 0;
  cursor: pointer;
}

.nav-links > li > a:hover { color: white; }

/* Dropdown */
.nav-dropdown {
  position: absolute;
  top: calc(100% - 30px);
  left: -12px;
  background: rgba(68, 214, 44, 1);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 8px;
  padding: 12px 0;
  width: max-content;
  min-width: 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
  z-index: 200;
  backface-visibility: hidden;
}

.nav-links > li:hover .nav-dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.nav-dropdown a,
.nav-dropdown .nav-subdropdown-toggle {
  display: block;
  padding: 8px 28px;
  font-size: clamp(12px, calc(7.43px + 0.45vw), 16px);
  font-weight: 700;
  color: white;
  text-decoration: none;
  transition: background-color 0.15s;
  background-color: transparent;
}

/* ── NESTED SUBMENU ("Other VERITY Products") ─ */
.nav-subdropdown-wrap { position: relative; }

/* the checkbox is a mobile-only accordion toggle; hidden on desktop */
.nav-sub-toggle-check { display: none; }

.nav-dropdown .nav-subdropdown-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  cursor: pointer;
}

.nav-sub-caret {
  font-size: 10px;
  margin-left: 10px;
  transition: transform 0.3s ease;
}

.nav-subdropdown {
  position: absolute;
  top: -13px;               /* line the flyout up with the parent padding */
  left: calc(100% + 6px);   /* keep a small visual gap between the two panels */
  background: rgba(68, 214, 44, 1);
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 8px;
  padding: 12px 0;
  width: max-content;
  opacity: 0;
  visibility: hidden;
  transform: translateX(8px);
  transition: opacity 0.2s, transform 0.2s, visibility 0.2s;
  z-index: 210;
}

/* Transparent hover bridge so the submenu stays open while the pointer
   crosses the intentional gap between panels. */
.nav-subdropdown::before {
  content: "";
  position: absolute;
  top: 0;
  right: 100%;
  width: 7px;
  height: 100%;
}

.nav-subdropdown-wrap:hover .nav-subdropdown {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}

.nav-cta {
  background: white;
  color: rgba(68, 214, 44, 1) !important;
  height: auto !important;
  padding: 11px 26px !important;
  border-radius: 8px;
  font-weight: 700 !important;
  font-size: clamp(14px, calc(7.14px + 0.67vw), 20px) !important;
  transition: background 0.2s, transform 0.2s !important;
  text-decoration: none;
  align-self: center;
}

.nav-cta:hover {
  background: white !important;
  transform: translateY(-1px);
}

/* ── MOBILE (≤960px) ──────────────────────── */
@media (max-width: 960px) {
  /* Lock page scroll while the mobile menu is open.
     body.nav-open covers pages whose JS sets that class (e.g. landing);
     body:has(.nav-links.open) covers pages whose nav JS only toggles
     .open on the menu itself. */
  html:has(.nav-links.open),
  body.nav-open,
  body:has(.nav-links.open) {
    overflow: hidden;
    overscroll-behavior: none;
  }

  nav {
    height: 80px;
    padding: 0 24px;
  }

  /* The scroll-lock above sets overflow:hidden on <html>, which breaks
     position:sticky — so the header would scroll off when the menu is opened
     after scrolling down. While the menu is open, pin the nav as fixed so the
     logo + close button stay visible at the top. */
  body.nav-open nav,
  body:has(.nav-links.open) nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
  }
  .admin-bar body.nav-open nav,
  .admin-bar body:has(.nav-links.open) nav {
    top: 46px;
  }

  .nav-logo img {
    height: 50px;
    max-height: 50px !important;
  }

  .nav-burger { display: flex; }

  .nav-links {
    display: none;
    flex-direction: column;
    position: fixed;
    top: 80px;
    left: 0;
    right: 0;
    background: rgba(68, 214, 44, 1);
    border-top: 1px solid rgba(255, 255, 255, 0.45);
    padding: 16px 24px calc(24px + env(safe-area-inset-bottom, 0px));
    gap: 0;
    height: calc(100vh - 80px);
    height: calc(100dvh - 80px);
    max-height: calc(100vh - 80px);
    max-height: calc(100dvh - 80px);
    overflow-y: auto;
    overscroll-behavior: contain;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    z-index: 100;
  }

  /* Keep the fixed menu below WordPress's mobile admin bar when logged in. */
  .admin-bar .nav-links {
    top: 126px;
    height: calc(100vh - 126px);
    height: calc(100dvh - 126px);
    max-height: calc(100vh - 126px);
    max-height: calc(100dvh - 126px);
  }

  .nav-links.open {
    display: flex;
    animation: navSlideDown 0.25s ease forwards;
  }

  @keyframes navSlideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .nav-links > li {
    display: block;
    height: auto;
    width: 100%;
    padding: 0; /* some pages (sgmom) add li padding that makes the menu taller */
  }

  .nav-links > li > a {
    color: white;
    font-size: 13px;
    height: auto;
    padding: 12px 0;
    width: 100%;
    border-bottom: none; /* override per-page v2 nav which adds a divider line */
  }

  .nav-links > li:last-child > a { border-bottom: none; }

  .nav-dropdown {
    position: static;
    opacity: 1;
    visibility: visible;
    transform: none;
    background: transparent;
    border: none;
    border-radius: 8px;
    padding: 0;
    margin: 0 0 8px; /* full reset — some pages add a left margin that misaligns the dropdown */
    width: auto;
  }

  .nav-dropdown > a,
  .nav-dropdown .nav-subdropdown-toggle {
    background: rgba(0, 0, 0, 0.1);
    font-size: 13px;
    color: white !important;
    padding: 10px 20px;
    border: none; /* override any per-page v2 dropdown divider */
  }

  .nav-dropdown > a:first-child { border-radius: 0; }

  .nav-dropdown > a:last-child { border-radius: 0 0 8px 8px; }

  .nav-dropdown .nav-subdropdown-toggle {
    border-radius: 0 0 8px 8px;
  }

  /* Nested submenu: JS-free accordion — collapsed by default; tapping the
     label toggles the checkbox, which expands it. (No JS, so it never closes
     the whole menu the way an <a> click handler would.)
     Two height mechanisms, layered:
     1. Base (all browsers): max-height 0 → capped value. The cap only needs
        bumping if the submenu ever outgrows it AND the visitor's browser
        lacks :has() — modern browsers ignore it entirely (see 2).
     2. @supports selector(:has(*)) below: grid 0fr→1fr animates to the true
        item count, so the open height always fits however many products the
        submenu holds. Gated on :has() because the open state needs it — a
        browser without :has() would otherwise be stuck at 0fr (clipped shut),
        and the 0fr track would also defeat the max-height fallback. */
  .nav-subdropdown {
    position: static;
    display: block;
    max-height: 0;
    min-height: 0;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    overflow: hidden;
    transform: translateY(-4px);
    background: rgba(0, 0, 0, 0.18);
    border: none;
    border-radius: 8px;
    padding: 0;
    margin: 0;
    width: auto;
    transition:
      max-height 0.3s ease,
      opacity 0.2s ease,
      transform 0.3s ease,
      visibility 0s linear 0.3s;
  }

  .nav-subdropdown::before { display: none; }

  .nav-sub-toggle-check:checked ~ .nav-subdropdown {
    max-height: 480px; /* fallback cap — only governs browsers without :has() */
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
    padding: 6px 0;
    margin-top: 8px;
    transition-delay: 0s;
  }

  @supports selector(:has(*)) {
    .nav-subdropdown-wrap {
      display: grid;
      /* row 1: toggle label, row 2: submenu. Row 1 must be min-content, not
         auto — while the row transition runs, Chrome dumps interpolation
         slack into an auto row, so the stretched label visibly bounces. */
      grid-template-rows: min-content 0fr;
      transition: grid-template-rows 0.22s ease-out;
    }

    .nav-subdropdown-wrap:has(.nav-sub-toggle-check:checked) {
      grid-template-rows: min-content 1fr;
    }

    /* The grid row governs height here; the fallback cap must not clip.
       One unified, snappy timing — the base 0.3s multi-speed transitions
       (opacity finishing before height, plus a 4px slide fighting the row
       growth) read as laggy when layered on the grid animation. */
    .nav-subdropdown,
    .nav-sub-toggle-check:checked ~ .nav-subdropdown {
      max-height: none;
      transform: none;
      transition:
        opacity 0.18s ease-out,
        padding 0.22s ease-out,
        margin-top 0.22s ease-out,
        visibility 0s linear 0.22s;
    }

    /* opening: become visible immediately (delay only applies on close) */
    .nav-sub-toggle-check:checked ~ .nav-subdropdown {
      transition-delay: 0s;
    }
  }

  .nav-subdropdown a {
    font-size: 13px;
    color: white !important;
    padding: 10px 20px;
  }

  /* caret points right when collapsed, down when expanded */
  .nav-sub-caret { transform: rotate(0deg); }
  .nav-sub-toggle-check:checked ~ .nav-subdropdown-toggle .nav-sub-caret { transform: rotate(90deg); }
}

/* ── DESKTOP NAV GUARD (≥961px) ───────────── */
/* Re-assert the horizontal green nav so pages whose own CSS switches to a
   mobile/burger nav at a WIDER breakpoint (e.g. SGMOM at ≤1024px) don't leak
   mobile styles — absolute position, column, white bg — into the 961–1024px
   range. Harmless on pages that already show the desktop nav here. */
@media (min-width: 961px) {
  nav { padding: 0 60px; }

  .nav-burger { display: none; }

  .nav-links {
    display: flex;
    flex-direction: row;
    align-items: center;
    position: static;
    top: auto;
    left: auto;
    right: auto;
    gap: 32px;
    height: 100%;
    max-height: none;
    padding: 0;
    background: transparent;
    border-top: none;
    border-bottom: none;
    box-shadow: none;
    overflow: visible;
  }

  .nav-dropdown {
    position: absolute;
    top: calc(100% - 30px);
    background: rgba(68, 214, 44, 1);
    opacity: 0;
    visibility: hidden;
    transform: translateY(8px);
    margin: 0;
  }

  .nav-links > li:hover .nav-dropdown {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }

  .nav-subdropdown {
    position: absolute;
    top: -13px;
    left: calc(100% + 6px);
    opacity: 0;
    visibility: hidden;
    transform: translateX(8px);
    margin: 0;
    background: rgba(68, 214, 44, 1);
  }

  .nav-subdropdown-wrap:hover .nav-subdropdown {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
  }

  .nav-sub-caret { transform: none; }
}

/* ── LARGE SCREENS (nav scaling only) ─────── */
@media (min-width: 1920px) {
  nav { height: 110px; }
  .nav-logo img { height: 80px; max-height: 80px !important; }
  .nav-links > li > a { font-size: clamp(20px, calc(8px + 0.625vw), 24px); }
  .nav-dropdown { top: calc(100% - 30px); }
  .nav-dropdown a,
  .nav-dropdown .nav-subdropdown-toggle { font-size: clamp(16px, calc(4px + 0.625vw), 20px); }
  .nav-cta { font-size: clamp(20px, calc(8px + 0.625vw), 24px) !important; }
}

@media (min-width: 2560px) {
  nav { height: 128px; }
  .nav-logo img { height: 94px; max-height: 94px !important; }
  .nav-links > li > a { font-size: clamp(24px, calc(12px + 0.469vw), 30px); }
  .nav-dropdown a,
  .nav-dropdown .nav-subdropdown-toggle { font-size: clamp(20px, calc(12px + 0.3125vw), 24px); }
  .nav-cta { font-size: clamp(24px, calc(12px + 0.469vw), 30px) !important; }
}

@media (min-width: 3840px) {
  nav { height: 150px; }
  .nav-logo img { height: 112px; max-height: 112px !important; }
  .nav-links > li > a { font-size: 30px; }
  .nav-dropdown a,
  .nav-dropdown .nav-subdropdown-toggle { font-size: 24px; }
  .nav-cta { font-size: 30px !important; }
}
