/*
 * Header "Услуги" dropdown with a second level (inc/header-menu.php).
 * Kept out of style.css/big.css on purpose: editing those invalidates the critical CSS.
 * Desktop: categories list, services fly out to the right on hover/focus.
 * Mobile (≤991px, inside the burger menu): the services unfold under the category.
 */

/* Second level: same look as the old dropdown items (style.css: ul.sub_menu > li > a) */
.mrd-hm-l2 {
	list-style: none;
	margin: 0;
	padding: 0;
}
.mrd-hm-l2 a {
	display: table;
	padding: 0.5em 0;
	margin-bottom: 0.5em;
	text-transform: uppercase;
	font-size: 0.9em;
	line-height: 1;
	color: #031615;
	font-weight: bold;
	text-decoration: none;
}
.mrd-hm-head {
	display: none; /* mobile only */
}
.mrd-hm-l2 li:last-child > a {
	margin-bottom: 0;
}
.mrd-hm-l2 a:hover,
.mrd-hm-l2 a:focus-visible,
.mrd-hm-l2 li.is-current > a,
.mrd-hm-l1 > li.is-current > a > span:last-child {
	color: #031615;
	text-decoration: underline;
}
.mrd-hm-toggle {
	display: none;
	flex: 0 0 auto;
	width: 2.75em;
	height: 2.75em;
	margin: -0.5em 0 0 auto;
	padding: 0;
	border: 0;
	background: transparent;
	cursor: pointer;
	position: relative;
}
.mrd-hm-toggle::before {
	content: "";
	position: absolute;
	top: 50%;
	left: 50%;
	width: 0.55em;
	height: 0.55em;
	border-right: 2px solid #031615;
	border-bottom: 2px solid #031615;
	transform: translate(-50%, -75%) rotate(45deg); /* ˅ */
}

/* Desktop flyout */
@media (min-width: 992px) {
	#menu-services.mrd-hm:focus-within > ul.sub_menu {
		opacity: 1;
		visibility: visible;
		z-index: 9;
		pointer-events: all;
	}
	.mrd-hm-l1 {
		min-width: 20em;
		/* Side padding moved into the rows: a padding strip that belongs to no row made the services panel
		   hide while the cursor crossed it slowly, and then the whole dropdown closed. */
		padding-left: 0 !important;
		padding-right: 0 !important;
	}
	.mrd-hm-l1 > li {
		padding: 0 1em;
	}
	.mrd-hm-l1 > li.has-children > a {
		padding-right: 1.75em;
		width: 100%;
		box-sizing: border-box;
	}
	.mrd-hm-l1 > li.has-children > a::after {
		content: "";
		position: absolute;
		right: 0.25em;
		top: 50%;
		width: 0.45em;
		height: 0.45em;
		border-right: 2px solid currentColor;
		border-bottom: 2px solid currentColor;
		transform: translateY(-50%) rotate(-45deg);
		opacity: 0.6;
	}
	.mrd-hm-l2 {
		position: absolute;
		top: 0;
		left: 100%;
		min-height: 100%;
		box-sizing: border-box;
		min-width: 18em;
		padding: 1em 1.5em;
		background: #fff;
		border-left: 1px solid #eef0f2;
		box-shadow: 12px 12px 30px #5f5f5f26;
		border-radius: 0 0 10px 0;
		white-space: nowrap;
		opacity: 0;
		visibility: hidden;
		/* Short delay before hiding: moving the cursor diagonally to the panel does not lose it. */
		transition: opacity 0.15s 0.12s, visibility 0s 0.27s;
	}
	/* Which panel is open: js/header-menu.js sets li.is-active with hover intent (.mrd-hm-js); until the script
	   has run, plain :hover. Keyboard: :focus-within. */
	.mrd-hm:not(.mrd-hm-js) .mrd-hm-l1 > li:hover > .mrd-hm-l2,
	.mrd-hm-js .mrd-hm-l1 > li.is-active > .mrd-hm-l2,
	.mrd-hm-l1 > li:focus-within > .mrd-hm-l2 {
		opacity: 1;
		visibility: visible;
		z-index: 1;
		transition: opacity 0.15s, visibility 0s;
	}
	/* Another category hovered: its panel wins immediately. */
	.mrd-hm:not(.mrd-hm-js) .mrd-hm-l1:hover > li:not(:hover) > .mrd-hm-l2,
	.mrd-hm-js .mrd-hm-l1 > li:not(.is-active) > .mrd-hm-l2 {
		transition: none;
	}
}

/* Mobile (burger menu): shared by both variants */
@media (max-width: 991px) {
	.mrd-hm-l1 > li {
		display: flex;
		flex-wrap: wrap;
		align-items: center;
	}
	.mrd-hm-l1 > li > a {
		flex: 1 1 0%; /* basis 0: the arrow stays on the same row however long the title is */
		min-width: 0;
		white-space: normal;
	}
	.mrd-hm-toggle {
		display: block;
		margin: 0 0 0.95em 0.5em; /* same bottom margin as the link (big.css) */
	}
	.mrd-hm-l2 {
		display: none;
		flex: 0 0 100%;
	}
	.mrd-hm-l2 .mrd-hm-all {
		display: inline-block;
		text-transform: none;
		font-size: 15px;
		font-weight: 600;
		line-height: 1.3;
		color: #18C673;
	}
	.mrd-hm-l2 .mrd-hm-all::after {
		content: " \2192";
	}
	.mrd-hm-l2 li:not(.mrd-hm-head) > a {
		display: block;
		margin: 0;
		text-transform: none;
		font-weight: 600;
		white-space: normal;
	}
	.mrd-hm-l2 li.is-current > a {
		color: #18C673;
		text-decoration: none;
	}
}

/* Mobile: the services unfold under the category, one category at a time (js/header-menu.js). */
@media (max-width: 991px) {
	.mrd-hm .mrd-hm-toggle::before {
		transition: transform 0.2s;
	}
	.mrd-hm .mrd-hm-item.is-open > .mrd-hm-toggle::before {
		transform: translate(-50%, -25%) rotate(-135deg); /* ˄ */
	}
	.mrd-hm .mrd-hm-item.is-open > .mrd-hm-l2 {
		display: block;
		animation: mrd-hm-down 0.2s ease-out;
	}
	.mrd-hm .mrd-hm-l2 {
		/* Coloured line from the centre of the category icon (2em wide) down along the list. */
		margin: -0.95em 0 1.1em calc(1em - 1px); /* -0.95em: the category link margin, so the line starts at the icon */
		padding: 6px 0 2px 18px;
		border-left: 2px solid var(--mrd-hm-c, #18C673);
	}
	.mrd-hm .mrd-hm-head {
		display: block;
	}
	.mrd-hm .mrd-hm-all {
		padding: 7px 0;
	}
	.mrd-hm .mrd-hm-l2 li:not(.mrd-hm-head) > a {
		padding: 7px 0;
		font-size: 15px;
		line-height: 1.3;
	}
}

@keyframes mrd-hm-down {
	from { opacity: 0; transform: translateY(-6px); }
	to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
	.mrd-hm-l2 {
		animation: none !important;
	}
}
