/**
 * Header navigation layout. Loaded after style.css so it wins at equal
 * specificity.
 */

/*
 * While the mobile menu is open, only <html> stops scrolling (style.css also
 * locked <body>). Hidden overflow on <body> turns it into its own scroll box,
 * which unsticks the header: on a scrolled page the header, and the menu
 * inside it, jumped back to the top of the document, off screen.
 */
html.ivy-nav-locked body {
	overflow: visible;
}

/* Logged in, keep the sticky header below the WordPress toolbar. */
.admin-bar .site-header {
	top: 32px;
}

@media screen and (max-width: 782px) {
	.admin-bar .site-header {
		top: 46px;
	}
}

/* The toolbar scrolls away with the page at this size. */
@media screen and (max-width: 600px) {
	.admin-bar .site-header {
		top: 0;
	}
}

@media screen and (min-width: 1181px) {
	/*
	 * Top-level links stay on one row. The gap shrinks on narrower screens
	 * instead of pushing the last link onto a second line.
	 */
	.main-navigation > .mobile-menu-container > ul {
		position: relative;
		flex-wrap: nowrap;
		column-gap: clamp(1.25rem, 2.2vw, 2.25rem);
	}

	.main-navigation > .mobile-menu-container > ul > li > a {
		white-space: nowrap;
	}

	/*
	 * Every dropdown starts right at the bottom of the link row. The link's
	 * own bottom padding is the visual gap, so the pointer never crosses
	 * empty space and the old hover bridge isn't needed.
	 */
	.main-navigation > .mobile-menu-container > ul > li.menu-item-has-children::after,
	.main-navigation > .mobile-menu-container > ul > li.page_item_has_children::after {
		content: none;
	}

	.main-navigation > .mobile-menu-container > ul > li.menu-item-has-children > .sub-menu,
	.main-navigation > .mobile-menu-container > ul > li.page_item_has_children > .sub-menu {
		top: 100%;
	}

	/*
	 * Wide (mega) panels span the nav column: their edges line up with the
	 * nav and they stop short of the header button instead of covering it
	 * or running off the side of the screen.
	 */
	.main-navigation > .mobile-menu-container > ul > li.menu-item--mega {
		position: static;
	}

	.main-navigation > .mobile-menu-container > ul > li.menu-item--mega > .sub-menu {
		left: 0;
		right: 0;
		width: auto;
		max-width: none;
		transform: none;
	}

	/*
	 * Regular dropdowns on the last two links open leftward, so they line up
	 * with the nav's right edge rather than spilling over the header button.
	 */
	.main-navigation > .mobile-menu-container > ul > li:nth-last-child(-n+2):not(.menu-item--mega):hover > .sub-menu,
	.main-navigation > .mobile-menu-container > ul > li:nth-last-child(-n+2):not(.menu-item--mega).focus > .sub-menu {
		left: auto;
		right: 0;
	}
}

@media screen and (max-width: 1180px) {
	/*
	 * The open menu is pinned to the screen right under the header.
	 * navigation.js measures the header and sets --ivy-menu-top, so the panel
	 * lines up and fills the rest of the screen however far the page is
	 * scrolled, with or without the WordPress toolbar.
	 */
	.main-navigation > .mobile-menu-container {
		position: fixed;
		top: var(--ivy-menu-top, 0px);
		bottom: 0;
		height: auto;
		overscroll-behavior: contain;
		-webkit-overflow-scrolling: touch;
	}

	/*
	 * The panel is a fixed-height flex column. Without this, Safari (iOS)
	 * squashes the link list to fit when a long submenu opens, and the links
	 * spill over the search, Patient Portal and Find Care button below.
	 * Each section keeps its full height and the panel scrolls instead.
	 */
	.main-navigation > .mobile-menu-container > * {
		flex-shrink: 0;
	}

	/*
	 * Submenus keep the desktop dropdown's z-index: 99999 from style.css.
	 * In the mobile menu they're grid items, which honor z-index without
	 * being positioned, so an open submenu painted over the sticky Find Care
	 * button and the search box. Let them stack in normal order.
	 */
	.main-navigation > .mobile-menu-container ul ul {
		z-index: auto;
	}
}

/*
 * Tablets and small laptops: the menu opens as a drawer on the right rather
 * than a full-screen sheet, which left the links hugging the left edge and
 * stretched the Find Care button across the whole screen.
 */
@media screen and (min-width: 601px) and (max-width: 1180px) {
	.main-navigation > .mobile-menu-container {
		left: auto;
		right: 0;
		width: min(100%, 26rem);
		box-shadow: -24px 0 48px rgba(0, 20, 16, 0.16);
	}
}

/*
 * From 851px the top bar already shows the search and Patient Portal, so the
 * copies at the bottom of the menu panel aren't needed.
 */
@media screen and (min-width: 851px) and (max-width: 1180px) {
	/* style.css shows it with !important at every size up to 1180px. */
	.main-navigation .mobile-nav-bottom {
		display: none !important;
	}
}
