/**
 * Nav Menu — the mega menu (paid: widgets.mega_menu).
 *
 * The free stylesheet draws the bar and the list dropdowns; this one draws
 * the PANEL a menu item opens instead of a list, in its two placements:
 *
 *   under the item   the panel sits inside its <li>, opens like a dropdown,
 *                    and takes its own width (auto / the menu / the container /
 *                    the full header);
 *   the dock         one shared area under the bar holds every panel; it grows
 *                    to the panel being shown, morphs between them, and the
 *                    content slides in the direction the pointer moved.
 *
 * Then the backdrop, the two mobile shapes (accordion / slide over), what
 * the editor's canvas holds open, and reduced motion. Every value is a
 * `--pkn-mega-*` property with the theme token behind it and a literal
 * behind that, like the free sheet's `--pkn-*`.
 *
 * `is-open` on the <li> is the runtime's; `is-mega-open` on the nav and
 * `has-mega-open` on `.peak-header` say a panel is showing.
 *
 * @package Peak
 */

.peak-nav.has-mega {
	--pkn-mega-offset: 8px;
	--pkn-mega-morph: 350ms;
	--pkn-mega-bg: var(--pkn-sub-bg);
	--pkn-mega-border: var(--pkn-sub-border);
	--pkn-mega-radius: var(--pkn-sub-radius);
	--pkn-mega-shadow-color: rgba(25, 25, 25, 0.12);
	--pkn-mega-shadow: 0 16px 48px var(--pkn-mega-shadow-color), 0 1px 2px rgba(25, 25, 25, 0.06);
	--pkn-mega-backdrop: rgba(25, 25, 25, 0.28);
	--pkn-mega-pad: 1.5rem;
	--pkn-mega-container: var(--peak-container, 1300px);
	--pkn-mega-ease: var(--pkn-ease);
}

/* ---- the panel box itself ------------------------------------------------
 * Born a row of columns (the Style rail's Display outranks this); a template
 * panel is a plain block its template lays out.
 * ------------------------------------------------------------------------ */

.pkb-el--mega-panel {
	display: var(--pkbs-d, block);
	flex-direction: var(--pkbs-fd, row);
	flex-wrap: var(--pkbs-fw, nowrap);
	gap: var(--pkbs-gap, 0px);
	align-items: var(--pkbs-ai, stretch);
	justify-content: var(--pkbs-jc, flex-start);
	grid-template-columns: var(--pkbs-gtc, none);
}
:where(.pkb-el--mega-panel) {
	--pkbs-d: flex;
	--pkbs-fd: row;
	--pkbs-gap: 2rem;
	--pkbs-ai: flex-start;
	padding: var(--pkn-mega-pad);
}
:where(.peak-nav__mega--tpl) {
	padding: var(--pkn-mega-pad);
}
/* The row folds to a column on a phone — the same fold a Quick Layout
   writes, here as the born-with default so a panel with no Display document
   of its own reads on a phone. */
@media (max-width: 767px) {
	:where(.pkb-el--mega-panel) {
		--pkbs-fd: column;
		--pkbs-gap: 1rem;
	}
}
.peak-nav__mega {
	box-sizing: border-box;
	color: var(--pkn-sub-color);
	text-align: start;
	white-space: normal;
}
.peak-nav__mega .peak-nav__link { white-space: normal; }

/* ---- under the item ------------------------------------------------------- */

.peak-nav--mega-item .peak-nav__item--mega > .peak-nav__mega {
	position: absolute;
	top: calc(100% + var(--pkn-mega-offset));
	left: 0;
	z-index: 60;
	min-width: var(--pkn-sub-w);
	background-color: var(--pkn-mega-bg);
	background-image: var(--pkn-mega-bg-i, none);
	border: 1px solid var(--pkn-mega-border);
	border-radius: var(--pkn-mega-radius);
	box-shadow: var(--pkn-mega-shadow);
	opacity: 0;
	visibility: hidden;
	transform: translateY(-6px);
	transition: opacity var(--pkn-dur) var(--pkn-mega-ease), transform var(--pkn-dur) var(--pkn-mega-ease),
		visibility 0s linear var(--pkn-dur);
}
.peak-nav--mega-item .peak-nav__item--mega.is-open > .peak-nav__mega,
.peak-nav--mega-item .peak-nav__item--mega.is-closing > .peak-nav__mega {
	opacity: 1;
	visibility: visible;
	transform: none;
	transition-delay: 0s;
}
.peak-nav--mega-item .peak-nav__item--mega.is-closing > .peak-nav__mega { pointer-events: none; }

/* The hover bridge across the gap, widened to the panel's offset. */
.peak-nav--mega-item .peak-nav__item--mega > .peak-nav__link::before { inset: 100% 0 calc(-2px - var(--pkn-mega-offset)); }

/* Width. Auto is the natural width, aligned to the item; Menu spans the
   nav; Container and Full span the header — for those the <li> and the nav
   step out of the positioning chain so the panel anchors to `.peak-header`
   (the nearest positioned ancestor left), exactly as a dropdown that spans
   a bar has always been built. */
.peak-nav--mega-item .peak-nav__item--mega > .peak-nav__mega--a-center {
	left: 50%;
	transform: translate(-50%, -6px);
}
.peak-nav--mega-item .peak-nav__item--mega.is-open > .peak-nav__mega--a-center,
.peak-nav--mega-item .peak-nav__item--mega.is-closing > .peak-nav__mega--a-center {
	transform: translate(-50%, 0);
}
.peak-nav--mega-item .peak-nav__item--mega > .peak-nav__mega--a-flex-end {
	left: auto;
	right: 0;
}

.peak-nav--mega-item .peak-nav__item--mega.peak-nav__item--w-nav,
.peak-nav--mega-item .peak-nav__item--mega.peak-nav__item--w-container,
.peak-nav--mega-item .peak-nav__item--mega.peak-nav__item--w-full { position: static; }
.peak-nav--mega-item .peak-nav__item--mega.peak-nav__item--w-nav > .peak-nav__mega { left: 0; right: 0; }

.peak-nav.has-mega.peak-nav--mega-item.peak-nav--anchors-header { position: static; }
.peak-nav--mega-item .peak-nav__item--mega.peak-nav__item--w-full > .peak-nav__mega {
	left: 0;
	right: 0;
	border-radius: 0 0 var(--pkn-mega-radius) var(--pkn-mega-radius);
}
.peak-nav--mega-item .peak-nav__item--mega.peak-nav__item--w-container > .peak-nav__mega {
	left: 50%;
	right: auto;
	width: min(100%, var(--pkn-mega-container));
	transform: translate(-50%, -6px);
}
.peak-nav--mega-item .peak-nav__item--mega.peak-nav__item--w-container.is-open > .peak-nav__mega { transform: translate(-50%, 0); }

/* ---- the dock --------------------------------------------------------------
 * One area, every panel stacked in it (absolute, hidden until shown). The
 * inner box carries the frame and animates its HEIGHT to the panel being
 * shown; the panels crossfade, and slide in the direction the pointer moved
 * (`data-dir`) unless the menu asked for a plain fade.
 * ------------------------------------------------------------------------ */

.peak-nav--mega-dock .peak-nav__item--mega { position: relative; }

.peak-nav__dock {
	position: absolute;
	top: calc(100% + var(--pkn-mega-offset));
	left: 0;
	right: 0;
	z-index: 60;
	pointer-events: none;
}
.peak-nav--mega-dock.peak-nav--mega-w-auto .peak-nav__dock,
.peak-nav--mega-dock.peak-nav--mega-w-nav .peak-nav__dock { left: 0; right: 0; }
.peak-nav--mega-dock.peak-nav--mega-w-auto .peak-nav__dock { right: auto; min-width: var(--pkn-sub-w); max-width: 100%; }
.peak-nav.has-mega.peak-nav--mega-dock.peak-nav--anchors-header { position: static; }
.peak-nav--mega-dock.peak-nav--mega-w-container .peak-nav__dock {
	left: 50%;
	right: auto;
	width: min(100%, var(--pkn-mega-container));
	transform: translateX(-50%);
}
.peak-nav--mega-dock.peak-nav--mega-w-full .peak-nav__dock .peak-nav__dock-inner { border-radius: 0 0 var(--pkn-mega-radius) var(--pkn-mega-radius); }

.peak-nav__dock-inner {
	position: relative;
	height: 0;
	overflow: hidden;
	background-color: var(--pkn-mega-bg);
	background-image: var(--pkn-mega-bg-i, none);
	border: 1px solid var(--pkn-mega-border);
	border-radius: var(--pkn-mega-radius);
	box-shadow: var(--pkn-mega-shadow);
	opacity: 0;
	visibility: hidden;
	transition: height var(--pkn-mega-morph) var(--pkn-mega-ease), opacity var(--pkn-dur) var(--pkn-mega-ease),
		visibility 0s linear var(--pkn-mega-morph);
}
.peak-nav.is-mega-open .peak-nav__dock { pointer-events: auto; }
.peak-nav.is-mega-open .peak-nav__dock-inner {
	opacity: 1;
	visibility: visible;
	transition-delay: 0s;
}
.peak-nav__dock .peak-nav__mega {
	position: absolute;
	top: 0;
	left: 0;
	right: 0;
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transform: translateX(0);
	transition: opacity calc(var(--pkn-mega-morph) * 0.6) var(--pkn-mega-ease), transform calc(var(--pkn-mega-morph) * 0.7) var(--pkn-mega-ease),
		visibility 0s linear calc(var(--pkn-mega-morph) * 0.6);
}
.peak-nav__dock .peak-nav__mega.is-open {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transform: none;
	transition-delay: 0s;
}
.peak-nav__dock .peak-nav__mega.is-closing { visibility: visible; pointer-events: none; }
/* Direction: the one leaving goes the way the pointer moved; the one coming
   rests on the other side, so its entrance is a slide from there. */
.peak-nav--mega-slide .peak-nav__dock[data-dir="next"] .peak-nav__mega:not(.is-open) { transform: translateX(32px); }
.peak-nav--mega-slide .peak-nav__dock[data-dir="prev"] .peak-nav__mega:not(.is-open) { transform: translateX(-32px); }
.peak-nav--mega-slide .peak-nav__dock[data-dir="next"] .peak-nav__mega.is-leaving { transform: translateX(-32px); }
.peak-nav--mega-slide .peak-nav__dock[data-dir="prev"] .peak-nav__mega.is-leaving { transform: translateX(32px); }
.peak-nav--mega-fade .peak-nav__dock .peak-nav__mega { transform: none !important; }

/* The item lit while its panel shows — the same soft pill hover gives it. */
.peak-nav.has-mega .peak-nav__item--mega.is-open > .peak-nav__link {
	background-color: var(--peak-inset, rgba(25, 25, 25, 0.045));
}

/* ---- the backdrop -------------------------------------------------------- */

.peak-nav__backdrop {
	position: fixed;
	inset: 0;
	z-index: 40;
	background: var(--pkn-mega-backdrop);
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	transition: opacity 0.3s var(--pkn-mega-ease), visibility 0s linear 0.3s;
}
.peak-nav__backdrop.is-blur {
	-webkit-backdrop-filter: blur(6px);
	backdrop-filter: blur(6px);
}
.peak-nav__backdrop.is-on {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transition-delay: 0s;
}
/* A transparent header turns solid while a panel is showing. */
.peak-header.has-mega-open.is-transparent:not(.is-stuck) { background: var(--_bg); }

/* ---- keyboard ------------------------------------------------------------- */

.peak-nav__mega :focus-visible { outline: 2px solid var(--peak-accent, currentColor); outline-offset: 2px; }

/* ---- mobile ----------------------------------------------------------------
 * The panel goes back into its item and becomes part of the drawer: an
 * accordion under the item, or a slide-over that moves the list aside.
 * ------------------------------------------------------------------------ */

.peak-nav.is-mobile .peak-nav__item--mega > .peak-nav__mega,
.peak-nav.is-mobile .peak-nav__dock .peak-nav__mega {
	position: static;
	display: none;
	flex: 1 1 100%;
	width: 100%;
	min-width: 0;
	margin: 0;
	padding: var(--pkn-mega-pad-m, 0.75rem 0 1rem 1rem);
	background: none;
	border: 0;
	border-left: 1px solid var(--peak-line, var(--pkn-sub-border));
	border-radius: 0;
	box-shadow: none;
	opacity: 1;
	visibility: visible;
	transform: none;
	transition: none;
}
.peak-nav.is-mobile .peak-nav__item--mega.is-open > .peak-nav__mega { display: flex; }
.peak-nav.is-mobile .peak-nav__item--mega.is-open > .peak-nav__mega.peak-nav__mega--tpl { display: block; }
.peak-nav.is-mobile .peak-nav__dock { display: none; }
.peak-nav.is-mobile .peak-nav__backdrop { display: none; }

/* Slide over: the list moves out to the left, the panel takes the drawer,
   a Back button leads the panel. The drawer keeps whatever position its
   mobile mode gave it (a dropdown under the bar, a side drawer, the whole
   screen) — only its overflow is clipped so the two slide past each other,
   and a dropdown grows to give the panel room. */
.peak-nav--mega-m-slide.is-mobile .peak-nav__panel { overflow: hidden; }
.peak-nav--mega-m-slide.is-mobile .peak-nav__panel.is-slid { min-height: min(70vh, 560px); }
.peak-nav--mega-m-slide.is-mobile .peak-nav__panel > .peak-nav__list {
	transition: transform 0.35s var(--pkn-mega-ease), opacity 0.3s var(--pkn-mega-ease);
}
.peak-nav--mega-m-slide.is-mobile .peak-nav__panel.is-slid > .peak-nav__list {
	transform: translateX(-12%);
	opacity: 0;
	pointer-events: none;
}
.peak-nav--mega-m-slide.is-mobile .peak-nav__panel > .peak-nav__mega {
	display: none;
	position: absolute;
	inset: 0;
	padding: 4.5rem var(--peak-gutter, 1rem) 1.5rem;
	overflow: auto;
	overscroll-behavior: contain;
	border: 0;
	background-color: var(--pkn-panel-bg, var(--peak-surface, #fcfbfa));
	transform: translateX(12%);
	opacity: 0;
	transition: transform 0.35s var(--pkn-mega-ease), opacity 0.3s var(--pkn-mega-ease);
}
.peak-nav--mega-m-slide.is-mobile .peak-nav__panel > .peak-nav__mega.is-active {
	display: flex;
	transform: none;
	opacity: 1;
}
.peak-nav--mega-m-slide.is-mobile .peak-nav__panel > .peak-nav__mega--tpl.is-active { display: block; }
.peak-nav__back {
	position: absolute;
	top: 1rem;
	left: var(--peak-gutter, 1rem);
	z-index: 2;
	display: none;
	align-items: center;
	gap: 0.4em;
	min-height: 44px;
	padding: 0 0.75em 0 0.5em;
	color: inherit;
	background: none;
	border: 0;
	border-radius: var(--peak-radius-sm, 6px);
	font: inherit;
	font-weight: 500;
	cursor: pointer;
}
.peak-nav__back svg { width: 18px; height: 18px; }
.peak-nav--mega-m-slide.is-mobile .peak-nav__panel.is-slid > .peak-nav__back { display: inline-flex; }

/* ---- the editor's canvas -------------------------------------------------
 * A panel the canvas holds open (the runtime's `peak:mega-hold`) shows with
 * no delay and never closes under the pointer; an empty one has room to
 * drop into. The nav's own hover/click do nothing while editing.
 * ------------------------------------------------------------------------ */

html.peak-editing .peak-nav__mega .pkb-empty { min-height: 120px; }
html.peak-editing .peak-nav.has-mega .peak-nav__item--mega.is-held > .peak-nav__mega,
html.peak-editing .peak-nav__dock .peak-nav__mega.is-held {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transform: none;
	transition: none;
}
html.peak-editing .peak-nav.is-mega-open .peak-nav__dock-inner { transition: none; }
html.peak-editing .peak-nav__backdrop { display: none; }

/* ---- reduced motion ------------------------------------------------------ */

@media (prefers-reduced-motion: reduce) {
	.peak-nav__dock-inner,
	.peak-nav__dock .peak-nav__mega,
	.peak-nav__item--mega > .peak-nav__mega,
	.peak-nav__backdrop,
	.peak-nav--mega-m-slide.is-mobile .peak-nav__panel > .peak-nav__list,
	.peak-nav--mega-m-slide.is-mobile .peak-nav__item--mega > .peak-nav__mega {
		transition-duration: 0.01ms !important;
	}
	.peak-nav--mega-slide .peak-nav__dock .peak-nav__mega { transform: none !important; }
}
