/**
 * Category Hover Menu Styles
 * 
 * @package HelloElementorChild
 */

/* Menu Container */
.category-hover-menu {
	position: relative;
	width: 100%;
}

/* Menu Trigger Wrapper */
.category-hover-menu .menu-trigger-wrapper {
	position: relative;
}

/* Add a pseudo-element to bridge the gap between trigger and menu */
.category-hover-menu .menu-trigger-wrapper::after {
	content: '';
	position: absolute;
	top: 100%;
	left: 0;
	right: 0;
	height: 10px;
	background: transparent;
	z-index: 999;
	display: none;
}

.category-hover-menu .menu-trigger-wrapper:hover::after {
	display: block;
}

/* Menu Title Trigger */
.category-hover-menu .menu-title-trigger {
	cursor: pointer;
	user-select: none;
	background: none;
	border: none;
	width: 100%;
	text-align: left;
	padding: 0;
	font-family: inherit;
	color: inherit;
	min-height: 44px; /* WCAG touch target size */
	display: flex;
	align-items: center;
}

.category-hover-menu .menu-title-trigger:hover {
	opacity: 0.8;
}

.category-hover-menu .menu-title-trigger:focus {
	outline: 2px solid #0073aa;
	outline-offset: 2px;
}

.category-hover-menu .menu-title {
	margin: 0;
	font-size: 20px;
	font-weight: 600;
	display: flex;
	align-items: center;
	justify-content: space-between;
	position: relative;
}

/* Toggle Icon (Arrow) */
.category-hover-menu .menu-toggle-icon {
	display: inline-block;
	margin-left: 10px;
	font-size: 0.8em;
	transition: transform 0.3s ease;
	color: currentColor;
}

/* Rotate arrow when menu is expanded */
.category-hover-menu .menu-trigger-wrapper:hover .menu-toggle-icon {
	transform: rotate(180deg);
}

/* Menu Icon Trigger (when title is hidden) */
.category-hover-menu .menu-icon-trigger {
	width: 30px;
	height: 24px;
	display: flex;
	flex-direction: column;
	justify-content: space-between;
	cursor: pointer;
	padding: 4px 0;
}

.category-hover-menu .menu-bars {
	display: block;
	width: 100%;
	height: 3px;
	background-color: currentColor;
	border-radius: 2px;
	transition: all 0.3s ease;
}

.category-hover-menu .menu-trigger-wrapper:hover .menu-bars:nth-child(1) {
	transform: translateY(2px) rotate(45deg);
}

.category-hover-menu .menu-trigger-wrapper:hover .menu-bars:nth-child(2) {
	opacity: 0;
}

.category-hover-menu .menu-trigger-wrapper:hover .menu-bars:nth-child(3) {
	transform: translateY(-10px) rotate(-45deg);
}

/* Main Category List - Hidden by default */
.category-hover-menu .cat-menu {
	margin: 0;
	padding: 0 0 10px 0;
	list-style: none;
	display: none;
	opacity: 0;
	visibility: hidden;
	transform: translateY(-10px);
	transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
	position: absolute;
	top: 100%;
	left: 0;
	z-index: 1000;
	margin-top: 10px;
	min-width: 200px;
	background: #fff;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Make cat-menu the positioning context for all children */
.category-hover-menu .cat-menu > .cat-item > .children {
	position: absolute;
	left: 100%;
	top: 0;
}

/* Show category list on hover - both trigger and menu itself */
.category-hover-menu .menu-trigger-wrapper:hover .cat-menu,
.category-hover-menu .menu-trigger-wrapper .cat-menu:hover {
	display: block !important;
	opacity: 1 !important;
	visibility: visible !important;
	transform: translateY(0) !important;
}

.category-hover-menu .cat-item {
	margin: 0;
	padding: 0;
	list-style: none;
	min-height: 0;
}

/* Add extra hover area to last item to prevent menu disappearing */
.category-hover-menu .cat-menu > .cat-item:last-child {
	padding-bottom: 0;
}

.category-hover-menu .cat-item > a {
	display: block;
	text-decoration: none;
	transition: all 0.3s ease;
	position: relative;
	min-height: 44px; /* WCAG touch target size */
	display: flex;
	align-items: center;
}

/* Add padding to links that have children to prevent text overflow with indicator */
.category-hover-menu .cat-parent > a {
	padding-right: 35px;
}

/* Submenu Indicator (Arrow) */
.category-hover-menu .submenu-indicator {
	position: absolute;
	right: 15px;
	top: 50%;
	transform: translateY(-50%);
	font-size: 16px;
	font-weight: bold;
	transition: transform 0.3s ease;
}

/* Product Count Badge */
.category-hover-menu .cat-count {
	font-size: 0.85em;
	opacity: 0.7;
	margin-left: 5px;
}

/* Subcategories (Children) */
.category-hover-menu .children {
	display: none;
	position: absolute;
	left: 100%;
	top: 0;
	min-width: 200px;
	max-height: calc(100vh - 100px); /* Limit to viewport height */
	margin: 0;
	margin-left: -1px;
	padding: 10px 0;
	list-style: none;
	z-index: 1001;
	opacity: 0;
	visibility: hidden;
	transform: translateX(-10px);
	transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
	overflow-y: auto; /* Add vertical scroll when content exceeds max-height */
	overflow-x: visible; /* Allow nested menus to escape horizontally */
	box-sizing: border-box;
	background: #fff;
	box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Show Subcategories on Hover - both parent and children themselves (DESKTOP ONLY) */
@media (min-width: 769px) {
	/* First level submenus */
	.category-hover-menu .cat-parent:hover > .children {
		display: block !important;
		opacity: 1 !important;
		visibility: visible !important;
		transform: translateX(0) !important;
	}
	
	/* Keep first level visible when hovering over it */
	.category-hover-menu .cat-parent > .children:hover {
		display: block !important;
		opacity: 1 !important;
		visibility: visible !important;
		transform: translateX(0) !important;
	}
	
	/* Second level and deeper - show submenu when hovering parent */
	.category-hover-menu .children .cat-parent:hover > .children {
		display: block !important;
		opacity: 1 !important;
		visibility: visible !important;
		transform: translateX(0) !important;
	}
	
	/* Keep submenu visible when hovering over the submenu itself */
	.category-hover-menu .children .cat-parent > .children:hover {
		display: block !important;
		opacity: 1 !important;
		visibility: visible !important;
		transform: translateX(0) !important;
	}
	
	/* Keep parent submenu visible while hovering child submenu */
	.category-hover-menu .cat-parent:hover > .children,
	.category-hover-menu .cat-parent:hover > .children .cat-parent:hover > .children {
		display: block !important;
		opacity: 1 !important;
		visibility: visible !important;
		transform: translateX(0) !important;
	}
	
	/* Maintain visibility for deeply nested levels (3rd, 4th, 5th) */
	.category-hover-menu .children .children .cat-parent:hover > .children,
	.category-hover-menu .children .children .children .cat-parent:hover > .children,
	.category-hover-menu .children .children .children .children .cat-parent:hover > .children {
		display: block !important;
		opacity: 1 !important;
		visibility: visible !important;
		transform: translateX(0) !important;
	}
}

/* Ensure parent item maintains position context for nested children */
.category-hover-menu .children .cat-parent {
	position: relative;
}

/* Align subcategories properly */
.category-hover-menu .cat-parent > .children {
	margin-left: 0;
}

/* Rotate Arrow on Hover (DESKTOP ONLY) */
@media (min-width: 769px) {
	.category-hover-menu .cat-parent:hover > a .submenu-indicator {
		transform: translateY(-50%) rotate(90deg);
	}
}

/* Nested Subcategories */
.category-hover-menu .children .cat-item {
	position: relative;
}

.category-hover-menu .children .cat-item > a {
	white-space: nowrap;
}

/* Third Level and Beyond */
.category-hover-menu .children .children {
	left: 100%;
	top: 0;
	z-index: 1002;
	max-height: calc(100vh - 100px); /* Limit to viewport height */
	overflow-y: auto; /* Add vertical scroll */
	overflow-x: visible; /* Allow deeper nested menus to escape */
}

/* Fourth Level and Beyond */
.category-hover-menu .children .children .children {
	z-index: 1003;
	max-height: calc(100vh - 100px); /* Limit to viewport height */
	overflow-y: auto; /* Add vertical scroll */
	overflow-x: visible; /* Allow deeper nested menus to escape */
}

/* Fifth Level */
.category-hover-menu .children .children .children .children {
	z-index: 1004;
	max-height: calc(100vh - 100px); /* Limit to viewport height */
	overflow-y: auto; /* Add vertical scroll */
	overflow-x: visible; /* Allow deeper nested menus to escape */
}

/* Custom Scrollbar for Subcategories */
.category-hover-menu .children::-webkit-scrollbar {
	width: 6px;
}

.category-hover-menu .children::-webkit-scrollbar-track {
	background: rgba(0, 0, 0, 0.05);
	border-radius: 3px;
}

.category-hover-menu .children::-webkit-scrollbar-thumb {
	background: rgba(0, 0, 0, 0.2);
	border-radius: 3px;
}

.category-hover-menu .children::-webkit-scrollbar-thumb:hover {
	background: rgba(0, 0, 0, 0.3);
}

/* Responsive Design */
@media (max-width: 768px) {
	/* Keep menu expanded on mobile after first interaction */
	.category-hover-menu .cat-menu {
		position: relative;
	}

	/* Make title tappable on mobile */
	.category-hover-menu .menu-title-trigger {
		padding: 12px 0;
		min-height: 48px; /* Larger touch target for mobile */
	}

	/* Improve tap target size for mobile */
	.category-hover-menu .cat-item > a {
		min-height: 48px;
		padding-top: 12px !important;
		padding-bottom: 12px !important;
	}

	/* Stack subcategories vertically on mobile */
	.category-hover-menu .children {
		position: static !important; /* Override desktop absolute positioning */
		display: none;
		min-width: auto;
		max-width: 100%;
		width: 100%;
		padding: 5px 0 5px 20px;
		margin: 0;
		left: auto !important; /* Remove left positioning */
		top: auto !important; /* Remove top positioning */
		transform: none !important;
		opacity: 1 !important;
		visibility: visible !important;
		box-shadow: none;
		min-height: auto !important;
		max-height: none !important;
	}

	/* Only show on active state, not hover (touch devices) */
	.category-hover-menu .cat-parent.active > .children {
		display: block;
	}

	/* Nested children also stack vertically */
	.category-hover-menu .children .children {
		position: static !important;
		left: auto !important;
		top: auto !important;
		padding-left: 20px;
	}

	.category-hover-menu .submenu-indicator {
		right: 15px;
		font-size: 18px; /* Larger indicator for mobile */
	}

	.category-hover-menu .cat-parent > a .submenu-indicator {
		transform: translateY(-50%) rotate(0deg);
		transition: transform 0.3s ease;
	}

	.category-hover-menu .cat-parent:hover > a .submenu-indicator,
	.category-hover-menu .cat-parent.active > a .submenu-indicator {
		transform: translateY(-50%) rotate(90deg);
	}

	/* Make categories tappable on mobile */
	.category-hover-menu .cat-parent > a {
		padding-right: 45px !important; /* More space for larger indicator */
	}

	/* Mobile: Allow tap to toggle menu */
	.category-hover-menu .menu-trigger-wrapper.mobile-active .cat-menu {
		display: block;
		opacity: 1;
		visibility: visible;
		transform: translateY(0);
	}

	/* Improve visual feedback on mobile */
	.category-hover-menu .cat-item > a:active {
		background-color: #e8f4f8;
		transform: scale(0.98);
	}

	/* Better spacing for mobile */
	.category-hover-menu .cat-menu {
		margin-top: 8px;
		box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
	}
}

/* Animation for smooth appearance (DESKTOP ONLY) */
@keyframes slideIn {
	from {
		opacity: 0;
		transform: translateX(-10px);
	}
	to {
		opacity: 1;
		transform: translateX(0);
	}
}

@media (min-width: 769px) {
	.category-hover-menu .cat-parent:hover > .children {
		animation: slideIn 0.3s ease forwards;
	}
}

/* Hover state improvements (DESKTOP ONLY) */
@media (min-width: 769px) {
	.category-hover-menu .cat-item > a:hover {
		transform: translateX(2px);
	}

	.category-hover-menu .children .cat-item > a:hover {
		transform: translateX(0);
	}
}

/* Focus styles for accessibility */
.category-hover-menu .cat-item > a:focus {
	outline: 2px solid #0073aa;
	outline-offset: 2px;
	background-color: #f0f6fc;
	z-index: 1;
}

.category-hover-menu .cat-item > a:focus:not(:focus-visible) {
	outline: none;
}

/* Visible focus for keyboard users */
.category-hover-menu .cat-item > a:focus-visible {
	outline: 2px solid #0073aa;
	outline-offset: 2px;
	background-color: #f0f6fc;
}

/* Alternative: Vertical Layout (uncomment to use) */
/*
.category-hover-menu.vertical-layout .cat-menu {
	display: flex;
	flex-direction: column;
}
*/

/* Alternative: Horizontal Layout (uncomment to use) */
/*
.category-hover-menu.horizontal-layout .cat-menu {
	display: flex;
	flex-direction: row;
	flex-wrap: wrap;
	gap: 10px;
}

.category-hover-menu.horizontal-layout .cat-item {
	flex: 0 0 auto;
}

.category-hover-menu.horizontal-layout .children {
	left: 0;
	top: 100%;
	transform: translateY(-10px);
}

.category-hover-menu.horizontal-layout .cat-parent:hover > .children {
	transform: translateY(0);
}
*/

/* Loading State */
.category-hover-menu.loading {
	opacity: 0.6;
	pointer-events: none;
}

/* Empty State */
.category-hover-menu .no-categories-message {
	padding: 20px;
	text-align: center;
	color: #666;
	font-style: italic;
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
	.category-hover-menu .cat-item > a:focus {
		outline: 3px solid;
		outline-offset: 3px;
	}

	.category-hover-menu .menu-title-trigger:focus {
		outline: 3px solid;
		outline-offset: 3px;
	}
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
	.category-hover-menu * {
		animation-duration: 0.01ms !important;
		animation-iteration-count: 1 !important;
		transition-duration: 0.01ms !important;
	}

	.category-hover-menu .children {
		transition: none;
	}
}
