/*
 * IncubeSocial — Mega Navigation.
 * New 2026-07-11, replacing the flat wp_nav_menu() 10-item list. Loaded
 * site-wide (header.php is shared by every template) via style.css or a
 * dedicated enqueue — see functions.php for the enqueue call.
 * Uses design-tokens.css custom properties exclusively for color/type.
 */

.mega-nav__list {
	display: flex;
	align-items: center;
	gap: 0.25rem;
	list-style: none;
	margin: 0;
	padding: 0;
}

.mega-nav__item {
	position: relative;
}

.mega-nav__item > a,
.mega-nav__trigger {
	display: inline-flex;
	align-items: center;
	gap: 0.35rem;
	font-family: var(--font-body);
	font-weight: 600;
	font-size: 0.9375rem;
	color: var(--color-navy-dark);
	text-decoration: none;
	background: none;
	border: none;
	cursor: pointer;
	padding: 0.6rem 0.85rem;
	border-radius: 8px;
	transition: background-color 0.15s ease, color 0.15s ease;
}

.mega-nav__item > a:hover,
.mega-nav__trigger:hover,
.mega-nav__item--has-mega:hover .mega-nav__trigger {
	background: var(--color-grey-light);
	color: var(--color-purple-primary);
}

.mega-nav__trigger svg {
	transition: transform 0.2s ease;
}

.mega-nav__item--has-mega:hover .mega-nav__trigger svg,
.mega-nav__item--has-mega:focus-within .mega-nav__trigger svg {
	transform: rotate(180deg);
}

/* ---------- Mega panel ---------- */

.mega-nav__panel {
	position: absolute;
	top: calc(100% + 0.5rem);
	left: 50%;
	transform: translate(-50%, 8px);
	min-width: 560px;
	/* Never let a panel exceed the viewport — a centered panel on a trigger near
	   the right edge would otherwise push document width past the viewport and
	   create a page-wide horizontal scrollbar even while the menu is CLOSED
	   (the panel is laid out even when visibility:hidden). Verified bug + fix
	   2026-07-11. */
	max-width: calc(100vw - 2rem);
	background: #fff;
	border-radius: 16px;
	box-shadow: 0 16px 40px rgba(13, 19, 43, 0.16);
	border: 1px solid rgba(13, 19, 43, 0.06);
	opacity: 0;
	visibility: hidden;
	pointer-events: none;
	/* Transition opacity + transform with a DURATION, but visibility only via a
	   DELAY (0s duration). Never give `visibility` a timed duration alongside
	   opacity: it is a discrete/non-interpolatable property, and animating it
	   deadlocked the .is-open class-toggle render path (opacity stuck at 0 even
	   though the show rule correctly won the cascade — verified live 2026-07-11).
	   Here visibility flips instantly, delayed 0.18s on close so the fade-out is
	   still seen; on open it flips immediately (delay 0s) so the panel fades in. */
	transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0.18s;
	z-index: 60;
}

/* Right-edge items (e.g. Company, the last mega item) anchor their panel to the
   RIGHT of the item and open leftward, instead of centering on the trigger —
   otherwise a 560px centered panel overflows the viewport's right edge. The
   transform loses its -50% X so the panel's own right edge aligns to the item. */
.mega-nav__item--align-right .mega-nav__panel {
	left: auto;
	right: 0;
	transform: translate(0, 8px);
}

/* Desktop mouse (:hover) and keyboard (:focus-within) get the smooth fade —
   these paths repaint continuously so the opacity transition advances fine. */
.mega-nav__item--has-mega:hover .mega-nav__panel,
.mega-nav__item--has-mega:focus-within .mega-nav__panel {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transform: translate(-50%, 0);
	transition: opacity 0.18s ease, transform 0.18s ease, visibility 0s linear 0s;
}

/* Touch / click (.is-open, toggled by mega-nav.js) snaps open with NO opacity
   transition. A one-shot class toggle does not reliably tick the opacity
   transition to completion on every renderer (it could leave opacity stuck at
   0 while the cascade still resolves to 1 — the exact bug hit here 2026-07-11),
   so on this path we skip the fade entirely and show the panel instantly.
   Correctness (panel actually appears on tap) beats a 0.18s cosmetic fade. */
.mega-nav__item--has-mega.is-open .mega-nav__panel {
	opacity: 1;
	visibility: visible;
	pointer-events: auto;
	transform: translate(-50%, 0);
	transition: none;
}

.mega-nav__panel-inner {
	display: grid;
	grid-template-columns: repeat(3, 1fr);
	gap: 0.25rem;
	padding: 1.25rem;
}

.mega-nav__col {
	display: flex;
	flex-direction: column;
	gap: 0.6rem;
	padding: 0.75rem;
	border-radius: 12px;
	text-decoration: none;
	color: var(--color-navy-dark);
	transition: background-color 0.15s ease;
}

.mega-nav__col:hover {
	background: var(--color-grey-light);
}

.mega-nav__col-title {
	font-family: var(--font-heading);
	font-weight: 700;
	font-size: 0.9375rem;
}

.mega-nav__col-desc {
	font-size: 0.8125rem;
	opacity: 0.7;
	line-height: 1.35;
}

.mega-nav__panel-foot {
	display: flex;
	justify-content: space-between;
	gap: 1rem;
	padding: 0.85rem 1.25rem;
	border-top: 1px solid rgba(13, 19, 43, 0.06);
}

.mega-nav__panel-foot a {
	font-size: 0.8125rem;
	font-weight: 600;
	color: var(--color-purple-primary);
	text-decoration: none;
}

.mega-nav__panel-foot a:hover {
	text-decoration: underline;
}

/* ---------- Animated thumbnail slider (per column) ----------
   3 stacked images per .mega-nav__thumbs, cross-fading on a loop while
   the mega panel is open/hovered — "keep things moving" per Adam's
   explicit request. Uses opacity cross-fade (not a translating slide)
   so the column's layout height never shifts. Respects
   prefers-reduced-motion by freezing on the first image. */

.mega-nav__thumbs {
	position: relative;
	width: 100%;
	aspect-ratio: 16 / 10;
	border-radius: 10px;
	overflow: hidden;
	background: var(--color-grey-light);
}

.mega-nav__thumbs img {
	position: absolute;
	inset: 0;
	width: 100%;
	height: 100%;
	object-fit: cover;
	opacity: 0;
}

.mega-nav__thumbs img:nth-child(1) {
	opacity: 1;
	animation: mega-thumb-cycle-1 6s ease-in-out infinite;
}

.mega-nav__thumbs img:nth-child(2) {
	animation: mega-thumb-cycle-2 6s ease-in-out infinite;
}

.mega-nav__thumbs img:nth-child(3) {
	animation: mega-thumb-cycle-3 6s ease-in-out infinite;
}

@keyframes mega-thumb-cycle-1 {
	0%, 28% { opacity: 1; }
	33%, 100% { opacity: 0; }
}

@keyframes mega-thumb-cycle-2 {
	0%, 28% { opacity: 0; }
	33%, 61% { opacity: 1; }
	66%, 100% { opacity: 0; }
}

@keyframes mega-thumb-cycle-3 {
	0%, 61% { opacity: 0; }
	66%, 94% { opacity: 1; }
	100% { opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
	.mega-nav__thumbs img {
		animation: none;
	}

	.mega-nav__thumbs img:nth-child(1) {
		opacity: 1;
	}
}

/* ---------- Mobile: mega panels become plain stacked lists ---------- */

@media (max-width: 900px) {
	.mega-nav__list {
		flex-wrap: wrap;
	}

	.mega-nav__panel {
		position: static;
		min-width: 0;
		opacity: 1;
		visibility: visible;
		pointer-events: auto;
		transform: none;
		box-shadow: none;
		border: none;
		display: none;
	}

	.mega-nav__item--has-mega:hover .mega-nav__panel,
	.mega-nav__item--has-mega:focus-within .mega-nav__panel {
		display: block;
	}

	.mega-nav__panel-inner {
		grid-template-columns: 1fr;
	}
}
