/**
 * AppsInsight — premium light-mode mega menu (Listeo-compatible).
 * Works with Appearance → Menus: enable “Megamenu” + column width on parent items.
 * Optional menu item CSS classes (Screen Options → CSS Classes):
 *   - appsinsight-mega-featured — full-width row below columns (featured listings strip).
 *
 * @package Listeo_Child
 */

/* -------------------------------------------------------------------------
   Design tokens (honours Listeo Customizer primary colour when present)
-------------------------------------------------------------------------- */
body:not(#dark-mode) {
	--appsinsight-mega-surface: #ffffff;
	--appsinsight-mega-surface-muted: #f4f6f9;
	--appsinsight-mega-border: rgba(15, 23, 42, 0.08);
	--appsinsight-mega-text: #1e293b;
	--appsinsight-mega-text-soft: #64748b;
	--appsinsight-mega-accent: var(--primary-color, #c17f45);
	--appsinsight-mega-shadow: 0 22px 56px rgba(15, 23, 42, 0.1), 0 0 1px rgba(15, 23, 42, 0.06);
	--appsinsight-mega-radius: 14px;
	--appsinsight-mega-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* -------------------------------------------------------------------------
   Viewport-safe position (overrides Listeo translate3d(-42%, …))
   Wide megas are shifted left by ~42% of their own width — clips the panel
   when the trigger sits near the left edge of the screen.
-------------------------------------------------------------------------- */
#navigation ul li .mega-menu:not(.mm-panel) {
	left: 0 !important;
	right: auto;
	transform: translate3d(0, 14px, 0) !important;
	max-width: calc(100vw - 24px);
	box-sizing: border-box;
	z-index: 90000 !important;
}

#navigation ul li:hover .mega-menu:not(.mm-panel) {
	transform: translate3d(0, 10px, 0) !important;
}

@media (min-width: 1025px) {
	/* Anchor from the right for trailing items so wide panels don’t clip off-screen right */
	#navigation.style-1 > ul > li:last-child .mega-menu:not(.mm-panel),
	#navigation.style-1 > ul > li:nth-last-child(2) .mega-menu:not(.mm-panel) {
		left: auto !important;
		right: 0 !important;
	}
}

/* -------------------------------------------------------------------------
   Panel container — airy, elevated, readable
-------------------------------------------------------------------------- */
body:not(#dark-mode) #navigation ul li .mega-menu:not(.mm-panel) {
	background-color: var(--appsinsight-mega-surface);
	border-radius: var(--appsinsight-mega-radius);
	box-shadow: var(--appsinsight-mega-shadow);
	border: 1px solid var(--appsinsight-mega-border);
	padding: 12px 0 18px;
	font-family: var(--appsinsight-mega-font);
	font-size: 15px;
	line-height: 1.45;
	color: var(--appsinsight-mega-text);
	margin-top: 0;
	overflow: hidden;
}

/* Widen panels slightly for hierarchy + breathing room */
body:not(#dark-mode) .mega-menu.two-columns:not(.mm-panel) {
	width: min(520px, calc(100vw - 32px));
}

body:not(#dark-mode) .mega-menu.three-columns:not(.mm-panel) {
	width: min(780px, calc(100vw - 32px));
}

body:not(#dark-mode) .mega-menu.four-columns:not(.mm-panel) {
	width: min(980px, calc(100vw - 32px));
}

/* -------------------------------------------------------------------------
   Grid layout: column 1 = parent categories (muted rail), rest = sub-links
-------------------------------------------------------------------------- */
body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul {
	display: grid !important;
	grid-template-columns: minmax(220px, 260px) repeat(auto-fit, minmax(168px, 1fr));
	grid-auto-flow: dense;
	align-items: start;
	gap: 0;
	width: 100% !important;
	float: none !important;
}

body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul > li {
	float: none !important;
	width: auto !important;
	display: block;
	border-right: 1px solid var(--appsinsight-mega-border);
	padding: 18px 22px 22px !important;
	margin: 0 !important;
	vertical-align: top;
}

body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul > li:last-child {
	border-right: none;
}

/* First column: “parent” rail */
body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul > li:first-child {
	background: linear-gradient(180deg, var(--appsinsight-mega-surface-muted) 0%, #fafbfc 100%);
	border-radius: 0;
	position: relative;
}

body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul > li:first-child::before {
	content: "";
	position: absolute;
	left: 0;
	top: 12px;
	bottom: 12px;
	width: 3px;
	border-radius: 2px;
	background: var(--appsinsight-mega-accent);
	opacity: 0.4;
	pointer-events: none;
}

/* -------------------------------------------------------------------------
   Typography — headlines + links
-------------------------------------------------------------------------- */
body:not(#dark-mode) .mega-menu-headline {
	font-family: var(--appsinsight-mega-font);
	font-size: 11px !important;
	font-weight: 700 !important;
	letter-spacing: 0.1em;
	text-transform: uppercase;
	color: var(--appsinsight-mega-text-soft) !important;
	padding: 8px 6px 12px !important;
	margin: 0 0 6px !important;
	line-height: 1.35 !important;
	opacity: 1 !important;
	border-bottom: 1px solid var(--appsinsight-mega-border);
}

body:not(#dark-mode) #navigation ul .mega-menu:not(.mm-panel) ul a,
body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul > li > a {
	color: var(--appsinsight-mega-text) !important;
	font-size: 15px !important;
	font-weight: 500;
	padding: 10px 12px !important;
	line-height: 1.4 !important;
	border-radius: 8px;
	opacity: 1 !important;
	transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}

body:not(#dark-mode) #navigation ul .mega-menu:not(.mm-panel) ul a:hover,
body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul > li > a:hover {
	background-color: rgba(15, 23, 42, 0.04);
	color: var(--appsinsight-mega-text) !important;
	transform: none !important;
}

body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul > li:first-child ul a:hover,
body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul > li:first-child > a:hover {
	background-color: rgba(255, 255, 255, 0.85);
	box-shadow: inset 0 0 0 1px var(--appsinsight-mega-border);
}

/* Nested lists inside a column */
body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) ul ul {
	padding: 4px 0 0 !important;
	margin: 0 !important;
}

body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) ul ul li {
	padding: 2px 0 !important;
	width: 100% !important;
}

/* Icons from Listeo menu fields */
body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) ul a i {
	font-size: 15px;
	opacity: 0.85;
	margin-right: 8px;
	vertical-align: -2px;
}

/* -------------------------------------------------------------------------
   Optional: full-width featured strip (add CSS class on menu item)
-------------------------------------------------------------------------- */
body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul > li.appsinsight-mega-featured {
	grid-column: 1 / -1;
	border-right: none !important;
	border-top: 1px solid var(--appsinsight-mega-border);
	margin-top: 4px;
	padding-top: 20px !important;
	padding-bottom: 16px !important;
	background: var(--appsinsight-mega-surface);
	width: 100% !important;
}

body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul > li.appsinsight-mega-featured .mega-menu-headline {
	border-bottom: none;
	padding-top: 0 !important;
}

/* Featured row: horizontal link chips */
body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul > li.appsinsight-mega-featured ul {
	display: flex;
	flex-wrap: wrap;
	gap: 10px 14px;
	align-items: stretch;
}

body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul > li.appsinsight-mega-featured ul li {
	width: auto !important;
	padding: 0 !important;
}

body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul > li.appsinsight-mega-featured ul a {
	padding: 12px 16px !important;
	background: var(--appsinsight-mega-surface-muted);
	border: 1px solid var(--appsinsight-mega-border);
	font-size: 14px !important;
}

body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) > ul > li.appsinsight-mega-featured ul a:hover {
	background: #fff;
	border-color: var(--appsinsight-mega-accent);
}

/* -------------------------------------------------------------------------
   Top-level nav — megamenu parent affordance
-------------------------------------------------------------------------- */
body:not(#dark-mode) #navigation.style-1 > ul > li.has-megamenu > a {
	padding-right: 26px !important;
	position: relative;
}

body:not(#dark-mode) #navigation.style-1 > ul > li.has-megamenu > a::after {
	content: "";
	position: absolute;
	right: 8px;
	top: 50%;
	width: 0;
	height: 0;
	margin-top: -2px;
	border-left: 4px solid transparent;
	border-right: 4px solid transparent;
	border-top: 5px solid currentColor;
	opacity: 0.45;
	transition: opacity 0.2s ease, transform 0.2s ease;
}

body:not(#dark-mode) #navigation.style-1 > ul > li.has-megamenu:hover > a::after {
	opacity: 0.75;
	transform: translateY(1px);
}

/* Active / hover top-level — subtle accent tint */
body:not(#dark-mode) #navigation.style-1 > ul > li.has-megamenu.current-menu-ancestor > a,
body:not(#dark-mode) #navigation.style-1 > ul > li.has-megamenu.current-menu-item > a {
	color: var(--appsinsight-mega-accent) !important;
}

/* -------------------------------------------------------------------------
   Focus visibility (keyboard)
-------------------------------------------------------------------------- */
body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) a:focus-visible {
	outline: 2px solid var(--appsinsight-mega-accent);
	outline-offset: 2px;
}

/* -------------------------------------------------------------------------
   Paragraph / HTML blocks inside mega (link role)
-------------------------------------------------------------------------- */
body:not(#dark-mode) #navigation .mega-menu:not(.mm-panel) p {
	font-size: 14px;
	line-height: 1.55;
	color: var(--appsinsight-mega-text-soft);
	padding: 6px 8px;
	margin: 0;
}

/* -------------------------------------------------------------------------
   Stacking: panel above search / header siblings; keep below #wpadminbar (99999)
-------------------------------------------------------------------------- */
#navigation.style-1 {
	position: relative;
	z-index: 500;
}

#navigation.style-1 > ul > li.has-megamenu.appsinsight-mega-open {
	z-index: 90001;
	position: relative;
}

body.appsinsight-mega-open-active #header-container {
	z-index: 99980 !important;
	position: relative;
}

body.appsinsight-mega-open-active #header.cloned.sticky {
	z-index: 99980 !important;
}

/* -------------------------------------------------------------------------
   Desktop: click-to-toggle (script). Disables hover-only open; keeps panel open
   until outside click or Escape. Inner columns stay visible while moving pointer
   into the dropdown (Listeo otherwise ties inner ul opacity to :hover).
-------------------------------------------------------------------------- */
@media (min-width: 1025px) {
	#navigation.style-1 ul > li:not(.appsinsight-mega-open) > .mega-menu:not(.mm-panel) {
		opacity: 0 !important;
		visibility: hidden !important;
		pointer-events: none !important;
	}

	#navigation.style-1 ul > li.appsinsight-mega-open > .mega-menu:not(.mm-panel) {
		opacity: 1 !important;
		visibility: visible !important;
		pointer-events: all !important;
	}

	#navigation.style-1 ul > li.appsinsight-mega-open > .mega-menu:not(.mm-panel) ul,
	#navigation.style-1 ul > li.appsinsight-mega-open > .mega-menu:not(.mm-panel) ul li {
		opacity: 1 !important;
		visibility: visible !important;
	}

	#navigation.style-1 ul > li:hover:not(.appsinsight-mega-open) > .mega-menu:not(.mm-panel) {
		opacity: 0 !important;
		visibility: hidden !important;
		pointer-events: none !important;
	}
}
