/* ==========================================================================
   FFW Theme — Fahrzeuge Mega Menu
   ========================================================================== */

/*
 * How it works
 * ------------
 * Any primary-nav top-level item that carries the WordPress CSS class
 * "mega-menu" (set in the menu editor) also receives "has-mega-menu" from
 * the custom Walker.  Its children are rendered as .mega-menu-card divs
 * inside a .mega-menu-panel wrapper instead of a plain <ul>.
 *
 * The panel is positioned absolute relative to .site-header (position:sticky)
 * because the <li> itself has position:static, which skips it as an
 * offsetParent — the next positioned ancestor is the sticky header.
 */

/* --------------------------------------------------------------------------
   Top-level mega-menu trigger item
   -------------------------------------------------------------------------- */

/* Reset the default dropdown positioning so the panel can span full-width */
.primary-nav > li.has-mega-menu {
	position: static;
}

/* Visual indicator: slightly bolder label */
.primary-nav > li.has-mega-menu > a {
	gap: 0.3rem;
}

/* Chevron icon inside the top-level link */
.mega-menu-chevron {
	display: inline-block;
	vertical-align: middle;
	transition: transform var(--ffw-transition);
	flex-shrink: 0;
}

.primary-nav > li.has-mega-menu:hover > a .mega-menu-chevron,
.primary-nav > li.has-mega-menu:focus-within > a .mega-menu-chevron {
	transform: rotate(180deg);
}

/* Active / current indicator for the trigger */
.primary-nav > li.has-mega-menu.current-menu-ancestor > a {
	color: var(--ffw-color-primary);
}

/* --------------------------------------------------------------------------
   Mega Menu Panel
   -------------------------------------------------------------------------- */

.mega-menu-panel {
	position: absolute;
	left: 0;
	right: 0;
	top: 100%;
	background: var(--ffw-bg-card);
	border-top: 2px solid var(--ffw-color-primary);
	border-bottom: 1px solid var(--ffw-border-color);
	box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
	z-index: 200;

	/* Hidden by default */
	display: none;
	padding: var(--ffw-spacing-lg) 0;
}

/* Show on hover or keyboard focus-within */
.primary-nav > li.has-mega-menu:hover .mega-menu-panel,
.primary-nav > li.has-mega-menu:focus-within .mega-menu-panel {
	display: block;
}

/* --------------------------------------------------------------------------
   Card Grid
   -------------------------------------------------------------------------- */

.mega-menu-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
	gap: var(--ffw-spacing-md);
	max-width: var(--ffw-content-width, 1200px);
	margin: 0 auto;
	padding: 0 var(--ffw-spacing-lg);
}

/* --------------------------------------------------------------------------
   Vehicle Card
   -------------------------------------------------------------------------- */

.mega-menu-card {
	border-radius: var(--ffw-border-radius);
	overflow: hidden;
	background: var(--ffw-bg-raised);
	border: 1px solid var(--ffw-border-color);
	transition: transform var(--ffw-transition), box-shadow var(--ffw-transition),
		border-color var(--ffw-transition);
}

.mega-menu-card:hover {
	transform: translateY(-3px);
	box-shadow: 0 6px 20px rgba(0, 0, 0, 0.14);
	border-color: var(--ffw-color-primary);
}

.mega-menu-card--active {
	border-color: var(--ffw-color-primary);
}

.mega-menu-card__link {
	display: flex;
	flex-direction: column;
	text-decoration: none;
	color: inherit;
	height: 100%;
}

.mega-menu-card__link:hover {
	text-decoration: none;
}

/* ---- Image area ---------------------------------------------------------- */

.mega-menu-card__image {
	display: block;
	width: 100%;
	aspect-ratio: 3 / 2;
	object-fit: cover;
	transition: opacity var(--ffw-transition);
}

.mega-menu-card:hover .mega-menu-card__image {
	opacity: 0.9;
}

/* Placeholder when no featured image is set */
.mega-menu-card__image--placeholder {
	aspect-ratio: 3 / 2;
	background: var(--ffw-bg-deep);
	display: flex;
	align-items: center;
	justify-content: center;
}

.mega-menu-card__placeholder-icon {
	width: 48px;
	height: auto;
	opacity: 0.25;
	color: var(--ffw-text-secondary);
}

/* ---- Title bar ----------------------------------------------------------- */

.mega-menu-card__title {
	display: block;
	padding: 0.55rem 0.75rem;
	font-size: 0.8rem;
	font-weight: 600;
	letter-spacing: 0.02em;
	color: var(--ffw-text-primary);
	text-align: center;
	line-height: 1.3;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	transition: color var(--ffw-transition);
}

.mega-menu-card:hover .mega-menu-card__title,
.mega-menu-card--active .mega-menu-card__title {
	color: var(--ffw-color-primary);
}

/* --------------------------------------------------------------------------
   Mobile — collapse to standard accordion list (<992 px)
   -------------------------------------------------------------------------- */

@media (max-width: 991px) {

	/* Panel is no longer absolutely positioned on mobile */
	.mega-menu-panel {
		position: static;
		display: block; /* always visible inside the open mobile menu */
		border: none;
		border-top: 1px solid var(--ffw-border-color);
		border-bottom: none;
		box-shadow: none;
		padding: 0;
		background: var(--ffw-bg-raised);
	}

	/* Simple vertical list of links — no cards */
	.mega-menu-grid {
		display: flex;
		flex-direction: column;
		gap: 0;
		padding: 0;
		margin: 0;
		max-width: none;
	}

	.mega-menu-card {
		border-radius: 0;
		border: none;
		border-bottom: 1px solid var(--ffw-border-color);
		background: transparent;
		transform: none !important;
		box-shadow: none !important;
	}

	.mega-menu-card:last-child {
		border-bottom: none;
	}

	.mega-menu-card__link {
		flex-direction: row;
		align-items: center;
		gap: var(--ffw-spacing-sm);
		padding: 0.75rem 1.5rem;
	}

	/* Hide images on mobile */
	.mega-menu-card__image,
	.mega-menu-card__image--placeholder {
		display: none;
	}

	.mega-menu-card__title {
		padding: 0;
		text-align: left;
		font-size: 0.9rem;
		font-weight: 500;
		white-space: normal;
		color: var(--ffw-text-secondary);
	}

	.mega-menu-card:hover .mega-menu-card__title {
		color: var(--ffw-text-primary);
	}

	/* Hide the chevron on mobile since the panel is always shown */
	.mega-menu-chevron {
		display: none;
	}
}

/* --------------------------------------------------------------------------
   Reduced-motion
   -------------------------------------------------------------------------- */

@media (prefers-reduced-motion: reduce) {
	.mega-menu-card,
	.mega-menu-card__image,
	.mega-menu-chevron {
		transition: none;
	}

	.mega-menu-card:hover {
		transform: none;
	}
}
