/* appartenances_UI-megamenu.css */
/* Mega menu: desktop hover + mobile accordion */
/* Updated for Joomla 5 HTML structure (no level-X classes) */

/* hack urgent Joomla!6 */
:where(.mod-menu__sub[aria-hidden="true"]){display:initial}

#NavBar {
	--megamenu-margin: 1rem;
}

/* =============================================================================
   BASE STYLES (all screen sizes)
   ============================================================================= */

ul#NavBar span,
ul#NavBar a {
	font-weight: 500;
	text-decoration: none;
}

ul#NavBar > li > span,
ul#NavBar > li > a {
	white-space: nowrap;
}

/* Hide Joomla's default icons */
ul#NavBar .nav-item .fa {
	display: none;
}

/* =============================================================================
   MOBILE UI ELEMENTS (hamburger, search toggle, submenu toggle)
   ============================================================================= */

.navBar-hamburger,
.search-toggle,
.submenu-toggle {
	display: none;
	background: none;
	border: none;
	cursor: pointer;
}

/* Hamburger button */
.navBar-hamburger {
	width: 2.5rem;
	height: 2.5rem;
	padding: 0.5rem;
	position: relative;
	z-index: 1001;
}

.navBar-hamburger span {
	width: 1.5rem;
	display: block;
	height: 2px;
	background: #000;
	margin: 5px 0;
	transition: transform 0.3s, opacity 0.3s;
}

.navBar-hamburger.is-active span:nth-child(1) {
	transform: rotate(45deg) translate(5px, 5px);
}

.navBar-hamburger.is-active span:nth-child(2) {
	opacity: 0;
}

.navBar-hamburger.is-active span:nth-child(3) {
	transform: rotate(-45deg) translate(5px, -5px);
}

/* Search toggle button */
.search-toggle {
	font-size: 1.25rem;
	padding: 0.5rem;
}

/* Submenu accordion toggle */
.submenu-toggle {
	padding: 0.5rem;
	margin-left: 0.5rem;
	vertical-align: middle;
	transition: transform 0.2s;
}

li.submenu-open > .submenu-toggle {
	transform: rotate(180deg);
}

#NavBar img[src*="jpg"] { max-width: 128px; display: block; }

/* =============================================================================
   DESKTOP STYLES (above 800px)
   ============================================================================= */

@media (min-width: 800px) {

	/* --- Layout --- */

	ul#NavBar {
		gap: 0; /* Prevent hover gap flicker */
	}

	/* Level 1: direct children of NavBar with submenus */
	ul#NavBar > li.deeper {
		position: relative;
	}

	/* ALL level-1 items get horizontal padding */
	ul#NavBar > li > a,
	ul#NavBar > li > span {
		padding-left: 0.75rem;
		padding-right: 0.75rem;
	}

	/* --- Submenus: hidden by default --- */

	ul#NavBar > li.deeper > ul {
		display: none;
		position: absolute;
		z-index: 100;
		background-color: var(--HeaderBkg, #fff);
		margin-top: -1px;
		left: -0.25rem;
		padding: 1rem 1rem;
	}

	/* --- Submenus: visible on hover or JS .menu-open --- */

	ul#NavBar > li.deeper:hover > ul,
	ul#NavBar > li.deeper.menu-open > ul {
		display: block;
		box-shadow: 0 20px 20px rgba(0,0,0,0.2);
	}

	/* Dim siblings when one item is active */
	ul#NavBar:has(> li.deeper:hover) > li:not(:hover):not(.menu-open),
	ul#NavBar:has(> li.deeper.menu-open) > li:not(:hover):not(.menu-open) {
		opacity: 0.33;
	}

	/* --- Mega menu panel (for items with nested submenus) --- */

	ul#NavBar > li.deeper:has(li.deeper):hover > ul,
	ul#NavBar > li.deeper:has(li.deeper).menu-open > ul {
		position: fixed;
		width: 100%;
		left: 0;
		display: flex;
		gap: 2rem;
		padding: 2rem;
		padding-right: 4rem;
		box-shadow: 0 20px 20px rgba(0,0,0,0.2);
		border-bottom: 1px solid #ccc;
	}

	#NavBar > li > ul > li {
		overflow: hidden;
	}

	ul#NavBar > li.deeper:has(li.deeper):hover > ul *,
	ul#NavBar > li.deeper:has(li.deeper).menu-open > ul * {
		margin: 0;
		padding: 0;
	}

	ul#NavBar > li.deeper:not(:has(li.deeper)) * {
		min-width: max-content;
	}

	/* Level 2 items inside mega panel */
	ul#NavBar > li.deeper:hover > ul > li,
	ul#NavBar > li.deeper.menu-open > ul > li {
		flex: 1;
		max-width: 30ch;
		padding: 0.75em;
	}

	/* Level 2 links (section headers) */
	ul#NavBar > li.deeper:has(li.deeper):hover > ul > li > a,
	ul#NavBar > li.deeper:has(li.deeper).menu-open > ul > li > a {
		display: block;
		height: 6rem;
		margin-bottom: 0.75rem;
		border-bottom: 1px solid #ccc;
	}

	/* Level 3 links */
	ul#NavBar > li.deeper:has(li.deeper):hover > ul > li > ul > li > a,
	ul#NavBar > li.deeper:has(li.deeper).menu-open > ul > li > ul > li > a {
		display: block;
		padding: 0.75rem 0;
		line-height: 1;
	}

}

/* =============================================================================
   MOBILE STYLES (800px and below)
   ============================================================================= */

@media only screen and (max-width: 9999px) {
	header.row {
		flex-direction: row !important;
	}
}

@media (max-width: 800px) {

	/* -- Touch target size --*/
	#NavBar a {
		display: block;
		min-height: 40px;
	}

	/* --- Show mobile UI elements --- */

	.navBar-hamburger,
	.search-toggle {
		display: block;
	}

	/* --- Header layout --- */

	header {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0.5rem 1rem;
	}

	header #Logo > * > *,
	header .brand-logo > * > * {
		display: none;
	}

	header #Logo > *:after {
		display: block;
		content: url("/A.svg");
		width: 2.5rem;
	}

	/* --- Search: hidden by default --- */

	header .search,
	header form.mod-finder {
		background: var(--HeaderBkg, #fff);
		padding: 0.5rem;
		display: none;
		box-shadow: 0 4px 8px rgba(0,0,0,0.1);
	}

	header .search.search-open,
	header form.mod-finder.search-open {
		display: block;
		width: 100%;
		margin-left: -2rem;
		margin-right: -1rem;
	}

	header:has(.search.search-open) .search-toggle,
	header:has(form.mod-finder.search-open) .search-toggle {
		opacity: 0.3;
	}

	header .search input,
	header form.mod-finder input {
		width: 50vw;
	}

	/* --- NavBar: fullscreen overlay --- */

	ul#NavBar {
		display: none;
		position: fixed;
		top: 3.5rem;
		left: 0;
		right: 0;
		bottom: 0;
		min-width: unset;
		max-width: unset;
		background: var(--HeaderBkg, #fff);
		z-index: 1000;
		padding: 1rem !important;
		overflow-y: auto;
		flex-direction: column;
	}

	ul#NavBar.navBar-open {
		display: flex;
	}

	body.navBar-open {
		overflow: hidden;
	}

	/* --- Reset desktop positioning --- */

	ul#NavBar > li.deeper {
		position: static;
	}

	ul#NavBar > li > ul {
		position: static;
		display: block; /* Visible by default (flat list mode) */
		width: auto;
		padding: 0 0 0 1rem;
		margin: 0;
		box-shadow: none;
		border: none;
		background: transparent;
	}

	/* Level 3 submenus NOT visible */
	ul#NavBar > li > ul > li > ul {
		display: none;
		outline: 1px solid magenta;
		padding-left: 1rem;
	}

	/* --- Accordion mode: hide submenus by default --- */

	body.accordion-enabled ul#NavBar > li > ul {
		display: none;
	}

	body.accordion-enabled ul#NavBar > li > ul > li > ul {
		display: none;
	}

	body.accordion-enabled ul#NavBar li.submenu-open > ul {
		display: block;
	}

	body.accordion-enabled .submenu-toggle {
		display: inline-block;
	}

	/* --- Menu item styling --- */

	ul#NavBar > li {
		border-bottom: 1px solid #eee;
	}

	ul#NavBar > li > a,
	ul#NavBar > li > span.separator,
	ul#NavBar > li > span.mod-menu__separator {
		display: inline-block;
		padding: 0.5rem 0;
	}

	/* Level 2 items */
	ul#NavBar > li > ul > li {
		border-bottom: none;
	}

	ul#NavBar > li > ul > li > a {
		font-weight: 600;
		padding: 0.35rem 0;
		font-size: 0.95em;
	}

	/* Level 3 items */
	ul#NavBar > li > ul > li > ul > li > a {
		font-weight: 400;
		padding: 0.25rem 0;
		font-size: 0.9em;
	}

	/* Disable desktop opacity effect on mobile */
	ul#NavBar:has(> li.deeper:hover) > li:not(:hover) {
		opacity: 1;
	}

}

/* =============================================================================
   LEGACY: no-accordion class support
   ============================================================================= */

@media (max-width: 800px) {
	body.no-accordion ul#NavBar li > ul {
		display: block;
		padding-left: 1rem;
	}
	body.no-accordion ul#NavBar > li > ul > li > ul {
		display: none;
	}

	body.no-accordion .submenu-toggle {
		display: none;
	}
}
