/*
 * Rahkar theme — desktop header catbar (Digikala-style two-row header).
 *
 * NOT part of the verbatim WP port. This file ADDS to header.css (which stays
 * untouched) the new desktop layout the user asked for:
 *
 *   Row 1 (.rh-row--main)      logo · wide search · account/cart
 *   Row 2 (.rh-row--menu_row)  [ دسته‌بندی کالاها ▾ ]  quick-links…
 *
 * The category trigger opens a pure-CSS mega panel: a vertical list of the
 * top categories on the start side (right, in RTL) and, on hover/focus of a
 * row, a flyout filling the rest of the panel with that category's children.
 *
 * Design notes (speed is the priority):
 *   - ZERO JS. Open/close is :hover + :focus-within only; GPU-composited
 *     (opacity/visibility), no reflow. The panel is in the cache-clean shell,
 *     identical for every anonymous visitor (data = $rahkar_chrome.menu, the
 *     same per-lang cached tree the mobile drawer already uses).
 *   - Desktop only. The .rh-row--menu_row visibility (desktop block / mobile
 *     none) + on-scroll collapse are ALREADY defined in header.css; this file
 *     only styles the bar's contents. Mobile header is unchanged.
 *   - Colors/spacing come from the same theme tokens header.css exposes
 *     (--rh-*  →  --wp--preset--color--*), so it matches the theme palette.
 *
 * Loaded globally right after header.css (theme.yml: priority 33).
 */

/* =====================================================================
 *  Row 1 — make the search the wide center element (logo right, icons left)
 * ===================================================================== */
.rahkar-site-header .rh-row--main .rh-zone--start,
.rahkar-site-header .rh-row--main .rh-zone--end {
	flex: 0 0 auto;
}
.rahkar-site-header .rh-row--main .rh-zone--center {
	flex: 1 1 auto;
	justify-content: center;
}
.rahkar-site-header .rh-row--main .rh-item--search_form {
	width: 100%;
}
/* Override header.css's 320px cap so the field stretches like Digikala. */
.rahkar-site-header .rh-row--main .rh-search,
.rahkar-site-header .rh-row--main .rh-search-wrap {
	width: 100%;
	max-width: 760px;
	margin-inline: auto;
}

/* =====================================================================
 *  Row 2 — the category bar
 * ===================================================================== */
.rh-catbar {
	gap: 8px;
	justify-content: flex-start;
}

/* ----------------------------------------------------------------------
 *  Category trigger + panel wrapper
 * ---------------------------------------------------------------------- */
.rh-cat {
	position: static; /* panel anchors to the full row, mega-menu style */
	display: flex;
	align-items: center;
	flex: 0 0 auto;
}

.rh-cat__trigger {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	height: 38px;
	padding-inline: 16px;
	border: 0;
	border-radius: 10px;
	background: var(--wp--preset--color--primary, #0a66c2);
	color: #fff;
	font: inherit;
	font-weight: var(--rh-fw-strong);
	font-size: 0.9375rem;
	line-height: 1;
	cursor: pointer;
	white-space: nowrap;
	transition: background-color 120ms linear;
}
.rh-cat:hover .rh-cat__trigger,
.rh-cat:focus-within .rh-cat__trigger {
	background: var(--wp--preset--color--primary-dark, #074a8d);
}
.rh-cat__trigger-label {
	display: inline-block;
}
/* trailing chevron flips when the panel is open */
.rh-cat__caret-down {
	transition: transform 150ms ease;
}
.rh-cat:hover .rh-cat__caret-down,
.rh-cat:focus-within .rh-cat__caret-down {
	transform: rotate(180deg);
}

/* ----------------------------------------------------------------------
 *  The mega panel — full-width-ish dropdown under the row
 * ---------------------------------------------------------------------- */
.rh-cat__panel {
	position: absolute;
	inset-block-start: 100%;
	inset-inline-start: 0;
	z-index: var(--rh-z-mega, 100);

	display: flex;
	width: min(980px, calc(100vw - 32px));
	height: min(440px, 70vh);
	margin-block-start: 6px;
	background: var(--rh-bg, #fff);
	border: 1px solid var(--rh-border, #e2e4e9);
	border-radius: 14px;
	box-shadow: 0 16px 48px rgba(15, 17, 21, 0.14);
	overflow: hidden;

	opacity: 0;
	visibility: hidden;
	transform: translateY(6px);
	transition: opacity 140ms linear, transform 140ms linear, visibility 0s linear 140ms;
}
/* Position the panel under the trigger: the row__inner is the positioning
 * context (the catbar inner), anchored to the start (right in RTL). */
.rh-row--menu_row .rh-row__inner {
	position: relative;
}
.rh-cat:hover .rh-cat__panel,
.rh-cat:focus-within .rh-cat__panel {
	opacity: 1;
	visibility: visible;
	transform: translateY(0);
	transition-delay: 0s;
}

/* Right-hand vertical list of top categories */
.rh-cat__col {
	flex: 0 0 248px;
	max-width: 248px;
	height: 100%;
	overflow-y: auto;
	overscroll-behavior: contain;
	padding: 8px;
	border-inline-end: 1px solid var(--rh-border, #e2e4e9);
	background: var(--wp--preset--color--surface, #f7f7f8);
}
.rh-cat__item {
	position: static;
}
.rh-cat__link {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 10px;
	border-radius: 8px;
	color: var(--rh-fg, #1a1d23);
	font-weight: var(--rh-fw-base);
	font-size: 0.875rem;
	line-height: 1.3;
	transition: background-color 120ms linear, color 120ms linear;
}
.rh-cat__item:hover > .rh-cat__link,
.rh-cat__item:focus-within > .rh-cat__link {
	background: var(--rh-bg, #fff);
	color: var(--rh-primary, #0a66c2);
}
.rh-cat__icon {
	flex: 0 0 auto;
	width: 28px;
	height: 28px;
	border-radius: 6px;
	object-fit: cover;
	background: var(--rh-bg, #fff);
}
.rh-cat__icon--ph {
	display: inline-block;
	background: var(--rh-bg, #fff);
	border: 1px solid var(--rh-border, #e2e4e9);
}
.rh-cat__name {
	flex: 1 1 auto;
	min-width: 0;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}
.rh-cat__caret {
	flex: 0 0 auto;
	color: var(--rh-fg-muted, #5b6271);
}

/* The flyout — fills the area to the start-inline of the column */
.rh-cat__flyout {
	position: absolute;
	inset-block: 0;
	inset-inline-start: 248px; /* = .rh-cat__col width */
	inset-inline-end: 0;
	padding: 18px 22px;
	overflow-y: auto;
	overscroll-behavior: contain;

	opacity: 0;
	visibility: hidden;
	transition: opacity 120ms linear, visibility 0s linear 120ms;
	content-visibility: auto; /* skip rendering hidden flyouts */
}
.rh-cat__item:hover > .rh-cat__flyout,
.rh-cat__item:focus-within > .rh-cat__flyout {
	opacity: 1;
	visibility: visible;
	transition-delay: 0s;
}
/* Keep the first category's flyout visible by default — but ONLY while the
 * panel is actually open (hover/focus on .rh-cat). Without this gate the first
 * flyout stays visibility:visible even when the panel is hidden, and a VISIBLE
 * descendant of a hidden parent still captures pointer events — so moving the
 * mouse over the area the panel used to occupy would re-trigger :hover and
 * reopen the panel. Gating it behind .rh-cat:hover/:focus-within means nothing
 * inside the closed panel is pointer-active, so it can't self-reopen. */
.rh-cat:hover .rh-cat__item:first-child > .rh-cat__flyout,
.rh-cat:focus-within .rh-cat__item:first-child > .rh-cat__flyout {
	opacity: 1;
	visibility: visible;
}
/* …but once any item is hovered/focused, the default one must yield. */
.rh-cat__col:hover .rh-cat__item:first-child:not(:hover) > .rh-cat__flyout,
.rh-cat__col:focus-within .rh-cat__item:first-child:not(:focus-within) > .rh-cat__flyout {
	opacity: 0;
	visibility: hidden;
}

.rh-cat__flyout-all {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	margin-block-end: 12px;
	color: var(--rh-primary, #0a66c2);
	font-weight: var(--rh-fw-strong);
	font-size: 0.9375rem;
}
.rh-cat__flyout-all:hover {
	text-decoration: none;
}
.rh-cat__sublist {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
	gap: 2px 16px;
	align-content: start;
}
.rh-cat__sublist a {
	display: block;
	padding: 7px 8px;
	border-radius: 6px;
	color: var(--rh-fg-muted, #5b6271);
	font-size: 0.8125rem;
	line-height: 1.4;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
	transition: color 120ms linear, background-color 120ms linear;
}
.rh-cat__sublist a:hover {
	background: var(--wp--preset--color--surface, #f7f7f8);
	color: var(--rh-primary, #0a66c2);
}

/* ----------------------------------------------------------------------
 *  Quick links beside the category trigger
 * ---------------------------------------------------------------------- */
.rh-quick {
	display: flex;
	align-items: center;
	gap: 2px;
	min-width: 0;
	overflow: hidden;
}
.rh-quick__link {
	display: inline-flex;
	align-items: center;
	height: 38px;
	padding-inline: 12px;
	border-radius: 8px;
	color: var(--rh-fg, #1a1d23);
	font-weight: var(--rh-fw-base);
	font-size: 0.875rem;
	white-space: nowrap;
	transition: background-color 120ms linear, color 120ms linear;
}
.rh-quick__link:hover {
	background: var(--wp--preset--color--surface, #f7f7f8);
	color: var(--rh-primary, #0a66c2);
}
/* The "شگفت‌انگیزها" highlight — uses the theme's accent red (Digikala-style). */
.rh-quick__link--hot {
	color: var(--wp--preset--color--accent, #e63946);
	font-weight: var(--rh-fw-strong);
}
.rh-quick__link--hot:hover {
	color: var(--wp--preset--color--accent, #e63946);
	background: var(--wp--preset--color--surface, #f7f7f8);
}

/* Hide quick links before the layout gets cramped (keep the category menu). */
@media (max-width: 1100px) {
	.rh-quick__link:nth-child(n+3) {
		display: none;
	}
}
@media (max-width: 980px) {
	.rh-quick {
		display: none;
	}
}
