/* =========================================================================
 * CATEGORY BAR — the shelf row under the site header
 *
 * Two presentations, one markup:
 *   >= 768px  a single row of categories; a parent with children opens a
 *             flyout on hover and on keyboard focus.
 *   <  768px  a horizontally scrollable chip row; every parent links straight
 *             to its archive, and the "همه دسته‌ها" chip opens a bottom sheet
 *             with the full tree, because a hover flyout has no place on glass.
 *
 * Tokens come from the parent theme (:root in main.css): --ink, --line, --soft.
 * ========================================================================= */

/* One gutter value for the whole archive: the category row, the filter row and
   the product grid all line up on it. Declared here and repeated in
   product-filters.css so each file stands on its own. */
body.mg-cat-archive {
	--mg-gutter: clamp(14px, 3vw, 56px);
}

.mg-catbar {
	position: relative;
	z-index: 30; /* under the header (50), above product cards */
	background: var(--bg, #fff);
	border-top: 1px solid var(--line, #e9e9e9);
}

.mg-catbar-list {
	display: flex;
	align-items: stretch;
	justify-content: space-between;
	flex-wrap: wrap;
	gap: 0;
	margin: 0;
	padding: 0 var(--mg-gutter, clamp(14px, 3vw, 56px));
	list-style: none;
}

.mg-catbar-item {
	position: relative;
}

.mg-catbar-link {
	display: flex;
	align-items: center;
	gap: 5px;
	padding: 13px 11px;
	color: var(--ink, #0a0a0a);
	font-family: var(--mg-font, sans-serif);
	font-size: 13px;
	line-height: 1;
	letter-spacing: 0;
	text-decoration: none;
	white-space: nowrap;
	transition: color .18s ease;
}

.mg-catbar-link:hover,
.mg-catbar-link:focus-visible {
	color: #000;
}

.mg-catbar-item.is-active > .mg-catbar-link {
	font-weight: 700;
}

.mg-catbar-item.is-active > .mg-catbar-link::after {
	content: "";
	position: absolute;
	inset-inline: 11px;
	bottom: 6px;
	height: 1px;
	background: currentColor;
}

.mg-catbar-chev {
	flex: none;
	fill: none;
	stroke: currentColor;
	stroke-width: 1.6;
	stroke-linecap: round;
	stroke-linejoin: round;
	transition: transform .18s ease;
}

/* The flyout: children of one parent. */
.mg-catbar-flyout {
	position: absolute;
	top: 100%;
	inset-inline-start: 0;
	z-index: 5;
	min-width: 190px;
	padding: 8px;
	background: var(--bg, #fff);
	border: 1px solid var(--line, #e9e9e9);
	box-shadow: 0 14px 34px rgba(10, 10, 10, .10);
	opacity: 0;
	visibility: hidden;
	transform: translateY(6px);
	transition: opacity .16s ease, transform .16s ease, visibility .16s;
}

.mg-catbar-item.has-kids:hover > .mg-catbar-flyout,
.mg-catbar-item.has-kids:focus-within > .mg-catbar-flyout {
	opacity: 1;
	visibility: visible;
	transform: translateY(0);
}

.mg-catbar-item.has-kids:hover > .mg-catbar-link .mg-catbar-chev,
.mg-catbar-item.has-kids:focus-within > .mg-catbar-link .mg-catbar-chev {
	transform: rotate(180deg);
}

.mg-catbar-sub {
	margin: 0;
	padding: 0;
	list-style: none;
}

.mg-catbar-sub a {
	display: block;
	padding: 9px 10px;
	color: var(--ink, #0a0a0a);
	font-family: var(--mg-font, sans-serif);
	font-size: 13px;
	text-decoration: none;
	white-space: nowrap;
}

.mg-catbar-sub a:hover,
.mg-catbar-sub a:focus-visible {
	background: var(--soft, #f2f2f2);
}

.mg-catbar-sub a[aria-current="page"] {
	font-weight: 700;
}

/* The sheet trigger only exists for touch layouts. */
.mg-catbar-all {
	display: none;
}

/* -------------------------------------------------------------------------
 * Bottom sheet (mobile tree)
 * ---------------------------------------------------------------------- */
.mg-catbar-sheet {
	position: fixed;
	inset: 0;
	z-index: 120;
	display: flex;
	align-items: flex-end;
	justify-content: center;
	background: rgba(10, 10, 10, .38);
}

.mg-catbar-sheet[hidden] {
	display: none;
}

.mg-catbar-sheet-card {
	width: 100%;
	max-width: 560px;
	max-height: 78vh;
	overflow: auto;
	background: var(--bg, #fff);
	border-radius: 18px 18px 0 0;
	padding: 0 0 max(12px, env(safe-area-inset-bottom));
	animation: mg-catbar-rise .22s ease both;
}

@keyframes mg-catbar-rise {
	from { transform: translateY(16px); opacity: .6; }
	to   { transform: translateY(0);    opacity: 1; }
}

.mg-catbar-sheet-head {
	position: sticky;
	top: 0;
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 16px 18px 12px;
	background: var(--bg, #fff);
	border-bottom: 1px solid var(--line, #e9e9e9);
	font-family: var(--mg-font-display, var(--mg-font, sans-serif));
	font-size: 15px;
}

.mg-catbar-sheet-close {
	width: 36px;
	height: 36px;
	border: 0;
	background: var(--soft, #f2f2f2);
	border-radius: 50%;
	font-size: 19px;
	line-height: 1;
	cursor: pointer;
}

.mg-catbar-sheet-list {
	margin: 0;
	padding: 6px 0;
	list-style: none;
}

.mg-catbar-sheet-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 8px;
	padding-inline: 18px;
}

.mg-catbar-sheet-row > a {
	flex: 1;
	padding: 13px 0;
	color: var(--ink, #0a0a0a);
	font-size: 14px;
	text-decoration: none;
}

.mg-catbar-sheet-toggle {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 40px;
	height: 40px;
	border: 0;
	background: transparent;
	cursor: pointer;
	color: var(--ink, #0a0a0a);
}

.mg-catbar-sheet-item.is-open .mg-catbar-sheet-toggle .mg-catbar-chev {
	transform: rotate(180deg);
}

.mg-catbar-sheet-sub {
	margin: 0;
	padding: 0 34px 8px;
	list-style: none;
}

.mg-catbar-sheet-sub a {
	display: block;
	padding: 10px 0;
	color: #4a4a4a;
	font-size: 13px;
	text-decoration: none;
	border-top: 1px dashed var(--line, #e9e9e9);
}

/* -------------------------------------------------------------------------
 * Tablet: same row, a little tighter
 * ---------------------------------------------------------------------- */
@media (max-width: 1023px) {
	.mg-catbar-list {
		justify-content: flex-start;
	}
	.mg-catbar-link {
		padding: 12px 9px;
		font-size: 12.5px;
	}
}

/* -------------------------------------------------------------------------
 * Mobile: the model row is not shown
 *
 * On a phone this row spent the whole first screen above the products, and the
 * filter bar directly below it already answers "which products?" with fewer,
 * shorter controls. So the row is turned off here — and with it the
 * «همه دسته‌ها» chip and its sheet, which nothing can reach any more.
 *
 * The rest of this block is the chip-row styling, left in place on purpose: it
 * describes how the row should look on mobile if it is ever switched back on,
 * which is a one-word change to this rule.
 * ---------------------------------------------------------------------- */
@media (max-width: 767px) {
	.mg-catbar {
		display: none;
	}

	.mg-catbar-all {
		display: inline-flex;
		align-items: center;
		gap: 6px;
		flex: none;
		height: 38px;
		padding: 0 12px;
		border: 1px solid var(--line, #e9e9e9);
		border-radius: 999px;
		background: var(--sub, #fafafa);
		color: var(--ink, #0a0a0a);
		font-family: var(--mg-font, sans-serif);
		font-size: 12.5px;
		line-height: 1;
		cursor: pointer;
	}

	.mg-catbar-all .mg-catbar-chev {
		transform: rotate(180deg);
	}

	.mg-catbar-list {
		display: flex;
		flex-wrap: nowrap;
		justify-content: flex-start;
		gap: 8px;
		padding: 10px 0;
		overflow-x: auto;
		overflow-y: hidden;
		scrollbar-width: none;
		-webkit-overflow-scrolling: touch;
		scroll-snap-type: x proximity;
	}

	.mg-catbar-list::-webkit-scrollbar {
		display: none;
	}

	.mg-catbar-item {
		flex: none;
		scroll-snap-align: start;
	}

	.mg-catbar-link {
		height: 38px;
		padding: 0 14px;
		border: 1px solid var(--line, #e9e9e9);
		border-radius: 999px;
		font-size: 12.5px;
	}

	.mg-catbar-item.is-active > .mg-catbar-link {
		background: var(--ink, #0a0a0a);
		border-color: var(--ink, #0a0a0a);
		color: #fff;
	}

	.mg-catbar-item.is-active > .mg-catbar-link::after {
		display: none;
	}

	/* No hover on glass: the chevron would promise a menu that cannot open. */
	.mg-catbar-item.has-kids > .mg-catbar-link .mg-catbar-chev {
		display: none;
	}

	.mg-catbar-flyout {
		display: none;
	}

	.mg-catbar-shop {
		margin-inline-start: 2px;
	}
}

@media (prefers-reduced-motion: reduce) {
	.mg-catbar-link,
	.mg-catbar-chev,
	.mg-catbar-flyout,
	.mg-catbar-sheet-card {
		transition: none;
		animation: none;
	}
}
