/**
 * TkProductMenu Styles - Mega Menu with Grid Layout
 * 
 * @package TkProductMenu
 * @since 1.0.0
 */

/* ============================================
   Container & Layout
   ============================================ */

.tkpm-menu-container {
	position: relative;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
	font-size: 15px;
	line-height: 1.5;
	color: #333;
	display: flex;
	gap: 0;
}

/* ============================================
   Root Menu (Main Categories)
   ============================================ */

.tkpm-menu-root {
	list-style: none;
	margin: 0;
	padding: 0;
	min-width: 220px;
	background: #fff;
	border: 1px solid #e0e0e0;
	border-radius: 4px;
	box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
	flex-shrink: 0;
}

.tkpm-menu-root > .tkpm-menu-item {
	border-bottom: 1px solid #f0f0f0;
}

.tkpm-menu-root > .tkpm-menu-item:last-child {
	border-bottom: none;
}

/* ============================================
   Menu Items
   ============================================ */

.tkpm-menu-item {
	position: relative;
	transition: background-color 0.2s ease;
}

/* Main category items */
.tkpm-menu-root > .tkpm-menu-item > .tkpm-menu-link {
	display: flex;
	align-items: center;
	padding: 14px 18px;
	color: #333;
	text-decoration: none;
	font-weight: 500;
	transition: all 0.25s ease;
	position: relative;
}

.tkpm-menu-root > .tkpm-menu-item > .tkpm-menu-link:hover,
.tkpm-menu-root > .tkpm-menu-item.tkpm-active > .tkpm-menu-link {
	background-color: #f8f9fa;
	color: #dd3333;
	padding-left: 22px;
}

.tkpm-menu-root > .tkpm-menu-item.tkpm-active > .tkpm-menu-link::before {
	content: '';
	position: absolute;
	left: 0;
	top: 0;
	bottom: 0;
	width: 4px;
	background: #dd3333;
	border-radius: 0 2px 2px 0;
}

/* ============================================
   Mega Menu Panel (Subcategories)
   ============================================ */

.tkpm-megamenu-panel {
	position: absolute;
	left: 100%;
	top: 0;
	min-width: 320px;
	max-width: 500px;
	background: #fff;
	border: 1px solid #e0e0e0;
	border-left: none;
	border-radius: 0 4px 4px 0;
	box-shadow: 4px 2px 12px rgba(0, 0, 0, 0.12);
	opacity: 0;
	visibility: hidden;
	transform: translateX(-10px);
	transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
	z-index: 1000;
	max-height: 600px;
	overflow-y: auto;
	overflow-x: hidden;
}

/* Adjust panel width for multi-column layouts */
.tkpm-megamenu-panel.tkpm-has-many-items {
	min-width: 440px;
	max-width: 600px;
}

.tkpm-megamenu-panel.tkpm-has-very-many-items {
	min-width: 600px;
	max-width: 750px;
}

/* Custom scrollbar for mega menu */
.tkpm-megamenu-panel::-webkit-scrollbar {
	width: 8px;
}

.tkpm-megamenu-panel::-webkit-scrollbar-track {
	background: #f5f5f5;
	border-radius: 0 4px 4px 0;
}

.tkpm-megamenu-panel::-webkit-scrollbar-thumb {
	background: #ccc;
	border-radius: 4px;
}

.tkpm-megamenu-panel::-webkit-scrollbar-thumb:hover {
	background: #999;
}

/* Show mega menu */
.tkpm-menu-item.tkpm-megamenu-open > .tkpm-megamenu-panel {
	opacity: 1;
	visibility: visible;
	transform: translateX(0);
}

/* ============================================
   Mega Menu Content - Grid Layout
   ============================================ */

.tkpm-megamenu-header {
	padding: 16px 20px;
	background: #f8f9fa;
	border-bottom: 1px solid #e0e0e0;
	font-weight: 600;
	color: #dd3333;
	font-size: 14px;
	text-transform: uppercase;
	letter-spacing: 0.5px;
}

/* Grid Layout for Subcategories */
.tkpm-menu-sub {
	list-style: none;
	margin: 0;
	padding: 12px;
	display: grid;
	gap: 4px;
	grid-template-columns: 1fr;
}

/* 2 columns for 5-8 items */
.tkpm-menu-sub.tkpm-grid-2col {
	grid-template-columns: repeat(2, 1fr);
}

/* 3 columns for 9+ items */
.tkpm-menu-sub.tkpm-grid-3col {
	grid-template-columns: repeat(3, 1fr);
}

/* 4 columns for 13+ items (optional) */
.tkpm-menu-sub.tkpm-grid-4col {
	grid-template-columns: repeat(4, 1fr);
}

.tkpm-menu-sub .tkpm-menu-item {
	border: none;
	break-inside: avoid;
}

.tkpm-menu-sub .tkpm-menu-link {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 10px 14px;
	color: #555;
	text-decoration: none;
	transition: all 0.2s ease;
	font-weight: 400;
	border-radius: 4px;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.tkpm-menu-sub .tkpm-menu-link:hover {
	background-color: #f0f4f8;
	color: #dd3333;
	transform: translateX(2px);
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* ============================================
   Icons & Indicators
   ============================================ */

.tkpm-menu-parent::after {
	content: '';
	display: inline-block;
	width: 0;
	height: 0;
	border-style: solid;
	border-width: 5px 0 5px 6px;
	border-color: transparent transparent transparent #999;
	margin-left: auto;
	transition: transform 0.3s ease, border-color 0.2s ease;
}

.tkpm-menu-item.tkpm-active > .tkpm-menu-link::after,
.tkpm-menu-item:hover > .tkpm-menu-link::after {
	border-color: transparent transparent transparent #dd3333;
	transform: translateX(3px);
}

/* ============================================
   Product Count Badge
   ============================================ */

.tkpm-menu-count {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 24px;
	height: 20px;
	padding: 0 6px;
	margin-left: 8px;
	background: #e8e8e8;
	color: #666;
	border-radius: 10px;
	font-size: 12px;
	font-weight: 500;
	transition: all 0.2s ease;
	flex-shrink: 0;
}

.tkpm-menu-link:hover .tkpm-menu-count {
	background: #dd3333;
	color: #fff;
}

/* ============================================
   Loading State
   ============================================ */

.tkpm-menu-loading {
	min-height: 200px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.tkpm-loading {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
	padding: 40px;
	color: #666;
}

.tkpm-spinner {
	width: 40px;
	height: 40px;
	border: 3px solid #f0f0f0;
	border-top-color: #dd3333;
	border-radius: 50%;
	animation: tkpm-spin 0.8s linear infinite;
}

@keyframes tkpm-spin {
	to {
		transform: rotate(360deg);
	}
}

.tkpm-loading-text {
	font-size: 14px;
	color: #999;
}

/* ============================================
   Error State
   ============================================ */

.tkpm-menu-error {
	min-height: 200px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.tkpm-error {
	display: flex;
	flex-direction: column;
	align-items: center;
	gap: 12px;
	padding: 40px;
	text-align: center;
}

.tkpm-error-icon {
	font-size: 32px;
	color: #ff6b6b;
}

.tkpm-error-text {
	color: #666;
	font-size: 14px;
}

.tkpm-retry-button {
	margin-top: 8px;
	padding: 8px 20px;
	background: #dd3333;
	color: #fff;
	border: none;
	border-radius: 4px;
	cursor: pointer;
	font-size: 14px;
	font-weight: 500;
	transition: background-color 0.2s ease;
}

.tkpm-retry-button:hover {
	background: #c22;
}

/* ============================================
   Empty State
   ============================================ */

.tkpm-menu-empty {
	min-height: 150px;
	display: flex;
	align-items: center;
	justify-content: center;
}

.tkpm-empty {
	padding: 40px;
	text-align: center;
	color: #999;
	font-size: 14px;
}

/* ============================================
   Fade-in Animation
   ============================================ */

.tkpm-menu-loaded {
	animation: tkpm-fadeIn 0.4s ease;
}

@keyframes tkpm-fadeIn {
	from {
		opacity: 0;
		transform: translateY(-10px);
	}
	to {
		opacity: 1;
		transform: translateY(0);
	}
}

/* ============================================
   Mega Menu Slide Animation
   ============================================ */

@keyframes tkpm-slideIn {
	from {
		opacity: 0;
		transform: translateX(-10px);
	}
	to {
		opacity: 1;
		transform: translateX(0);
	}
}

@keyframes tkpm-slideOut {
	from {
		opacity: 1;
		transform: translateX(0);
	}
	to {
		opacity: 0;
		transform: translateX(-10px);
	}
}

/* ============================================
   Focus & Accessibility
   ============================================ */

.tkpm-menu-link:focus {
	outline: 2px solid #4CAF50;
	outline-offset: -2px;
}

.tkpm-menu-link:focus:not(:focus-visible) {
	outline: none;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 768px) {
	.tkpm-menu-container {
		flex-direction: column;
	}

	.tkpm-menu-root {
		min-width: 100%;
		width: 100%;
	}

	.tkpm-megamenu-panel {
		position: static;
		width: 100%;
		max-width: 100%;
		border: none;
		border-top: 1px solid #e0e0e0;
		border-radius: 0;
		box-shadow: none;
		max-height: none;
		transform: none;
	}

	.tkpm-menu-item.tkpm-megamenu-open > .tkpm-megamenu-panel {
		transform: none;
	}

	/* Single column on mobile */
	.tkpm-menu-sub,
	.tkpm-menu-sub.tkpm-grid-2col,
	.tkpm-menu-sub.tkpm-grid-3col,
	.tkpm-menu-sub.tkpm-grid-4col {
		grid-template-columns: 1fr;
	}

	.tkpm-menu-parent::after {
		border-width: 6px 5px 0 5px;
		border-color: #999 transparent transparent transparent;
		transform: rotate(0deg);
	}

	.tkpm-menu-item.tkpm-active > .tkpm-menu-link::after {
		transform: rotate(180deg);
	}
}

/* Tablet adjustments */
@media (min-width: 769px) and (max-width: 1024px) {
	/* Reduce to 2 columns max on tablet for better fit */
	.tkpm-menu-sub.tkpm-grid-3col,
	.tkpm-menu-sub.tkpm-grid-4col {
		grid-template-columns: repeat(2, 1fr);
	}

	.tkpm-megamenu-panel.tkpm-has-very-many-items {
		max-width: 600px;
	}
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
	.tkpm-megamenu-panel {
		position: static;
		opacity: 1;
		visibility: visible;
		transform: none;
		box-shadow: none;
		border: 1px solid #ddd;
	}

	.tkpm-menu-parent::after {
		display: none;
	}

	.tkpm-menu-sub {
		grid-template-columns: repeat(2, 1fr) !important;
	}
}

/* ============================================
   Dark Mode Support - DISABLED
   Dark mode is disabled to maintain consistent
   appearance across all color schemes
   ============================================ */

/* ============================================
   Widget Styles - Shortcode in Widget Context
   ============================================ */

.tkpm_widget {
	font-family: inherit;
}

/* Override mega menu styles for widget context */
.tkpm_widget .tkpm-menu-container {
	display: block;
	font-size: 14px;
	position: relative;
}

.tkpm_widget .tkpm-menu-root {
	min-width: auto;
	background: none;
	border: none;
	box-shadow: none;
	position: static;
	width: 100%;
}

/* Improve mega menu positioning for sidebar - eliminate gap */
.tkpm_widget .tkpm-megamenu-panel {
	left: 100% !important;
	top: 0 !important;
	margin-left: 0 !important;
	min-width: 300px !important;
	max-width: 400px !important;
	z-index: 9999 !important;
	background: white !important;
	border: 1px solid #ddd !important;
	box-shadow: 0 4px 8px rgba(0,0,0,0.1) !important;
	border-radius: 0 4px 4px 4px !important;
	display: none !important;
	position: absolute !important;
}

/* Show mega menu when open */
.tkpm_widget .tkpm-megamenu-open .tkpm-megamenu-panel {
	display: block !important;
}

/* Smart positioning for viewport boundaries */
.tkpm_widget .tkpm-megamenu-panel.tkpm-panel-top {
	top: 100% !important;
	bottom: auto !important;
	transform: translateY(-100%) !important;
	border-radius: 4px 4px 0 4px !important;
}

.tkpm_widget .tkpm-megamenu-panel.tkpm-panel-center {
	top: 50% !important;
	transform: translateY(-50%) !important;
	border-radius: 4px !important;
}

.tkpm_widget .tkpm-megamenu-panel.tkpm-panel-bottom {
	top: 0 !important;
	bottom: auto !important;
	border-radius: 0 4px 4px 4px !important;
}

/* Add hover bridge to prevent menu closing */
.tkpm_widget .tkpm-has-children {
	position: relative;
}

/* Create seamless connection between menu item and panel */
.tkpm_widget .tkpm-has-children::after {
	content: '';
	position: absolute;
	top: 0;
	right: 0;
	width: 1px;
	height: 100%;
	background: transparent;
	z-index: 9998;
	pointer-events: none;
}

.tkpm_widget .tkpm-menu-item {
	border-bottom: 1px solid #e1e1e1;
	position: relative;
}

/* Ensure menu items with children have proper positioning context */
.tkpm_widget .tkpm-menu-item.tkpm-has-children {
	position: relative;
	overflow: visible;
}

.tkpm_widget .tkpm-menu-item:first-child {
	border-top: 1px solid #e1e1e1;
}

.tkpm_widget .tkpm-menu-link {
	display: block;
	padding: 12px 15px;
	color: #333;
	text-decoration: none;
	transition: all 0.3s ease;
	border-left: 3px solid transparent;
	background: none;
	border-radius: 0;
}

.tkpm_widget .tkpm-menu-link:hover {
	background-color: #f8f8f8;
	border-left-color: #0073aa;
	color: #0073aa;
	text-decoration: none;
}

.tkpm_widget .tkpm-menu-label {
	font-weight: 500;
}

.tkpm_widget .tkpm-menu-count {
	color: #666;
	font-size: 0.9em;
	font-weight: normal;
	background: none;
	border-radius: 0;
	padding: 0;
	margin-left: 5px;
}

/* Hide mega menu panels in widget */
.tkpm_widget .tkpm-megamenu-panel {
	display: none !important;
}

/* Show subcategories as simple list in widget */
.tkpm_widget .tkpm-has-children .tkpm-menu-sub {
	display: block !important;
	position: static !important;
	background: none !important;
	border: none !important;
	box-shadow: none !important;
	padding: 0 !important;
	margin: 0 !important;
	width: 100% !important;
	columns: 1 !important;
}

/* Ensure hover effects work without JavaScript in widget */
.tkpm_widget .tkpm-menu-item:hover .tkpm-menu-link {
	background-color: #f8f8f8;
	border-left-color: #0073aa;
	color: #0073aa;
}

.tkpm_widget .tkpm-menu-sub .tkpm-menu-item:hover .tkpm-menu-link {
	background-color: #f0f0f0;
}

.tkpm_widget .tkpm-menu-sub .tkpm-menu-item {
	border-bottom: 1px solid #e1e1e1;
}

.tkpm_widget .tkpm-menu-sub .tkpm-menu-link {
	padding-left: 30px;
	font-size: 0.95em;
	background-color: #fafafa;
}

.tkpm_widget .tkpm-menu-sub .tkpm-menu-link:hover {
	background-color: #f0f0f0;
}

.tkpm_widget .tkpm-menu-sub .tkpm-menu-label {
	font-weight: normal;
}

/* Smart positioning for regular (non-widget) context */
.tkpm-megamenu-panel.tkpm-panel-top {
	top: 100% !important;
	bottom: auto !important;
	transform: translateY(-100%) !important;
}

.tkpm-megamenu-panel.tkpm-panel-center {
	top: 50% !important;
	transform: translateY(-50%) !important;
}

.tkpm-megamenu-panel.tkpm-panel-bottom {
	top: 0 !important;
	bottom: auto !important;
}

/* Mobile-specific behavior */
@media (max-width: 768px) {
	/* Completely hide mega menu panels on mobile */
	.tkpm_widget .tkpm-megamenu-panel {
		position: static !important;
		left: auto !important;
		top: auto !important;
		transform: none !important;
		width: 100% !important;
		max-width: none !important;
		min-width: auto !important;
		background: transparent !important;
		border: none !important;
		box-shadow: none !important;
		border-radius: 0 !important;
		margin: 0 !important;
		padding: 0 !important;
		height: 0 !important;
		min-height: 0 !important;
		max-height: 0 !important;
		overflow: hidden !important;
		opacity: 0 !important;
		line-height: 0 !important;
		transition: none !important;
	}

	/* Show submenu as simple list when clicked - ensure no empty space */
	.tkpm_widget .tkpm-megamenu-open .tkpm-megamenu-panel {
		display: block !important;
		height: auto !important;
		min-height: auto !important;
		max-height: none !important;
		opacity: 1 !important;
		overflow: visible !important;
		line-height: normal !important;
		background: #f8f8f8 !important;
	}

	/* Ensure the panel header doesn't create empty space */
	.tkpm_widget .tkpm-megamenu-header {
		display: none !important;
	}

	/* Make sure submenu lists don't have extra spacing */
	.tkpm_widget .tkpm-menu-sub {
		margin: 0 !important;
		padding: 0 !important;
		background: transparent !important;
	}

	/* Remove white space gaps */
	.tkpm_widget .tkpm-menu-item {
		margin: 0 !important;
		border-bottom: 1px solid #e1e1e1 !important;
	}

	/* Adjust menu link styling for mobile */
	.tkpm_widget .tkpm-menu-link {
		padding: 15px 12px;
		font-size: 14px;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	/* Add expand indicator for items with children */
	.tkpm_widget .tkpm-has-children .tkpm-menu-link::after {
		content: '+';
		font-size: 18px;
		font-weight: bold;
		color: #666;
		transition: transform 0.3s ease;
	}

	/* Rotate indicator when expanded */
	.tkpm_widget .tkpm-megamenu-open .tkpm-menu-link::after {
		transform: rotate(45deg);
	}

	/* Style submenu items for mobile */
	.tkpm_widget .tkpm-menu-sub .tkpm-menu-link {
		padding: 12px 24px;
		background: #f8f8f8;
		font-size: 13px;
	}

	.tkpm_widget .tkpm-menu-sub .tkpm-menu-link::after {
		display: none;
	}

	/* Remove hover effects on mobile */
	.tkpm_widget .tkpm-menu-item:hover .tkpm-menu-link,
	.tkpm_widget .tkpm-menu-sub .tkpm-menu-item:hover .tkpm-menu-link {
		background-color: inherit;
		border-left-color: transparent;
		color: inherit;
	}
}
