/*
 * 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)
 *
 *  :not(.rh-row--split) — this row layout is for the mega-menu/catbar header
 *  mode ONLY, where the centre zone holds a wide search input that should
 *  stretch. RAHKAR_HEADER_MODE='split' also renders its row with the
 *  `.rh-row--main` class (header.tpl), but its centre zone holds the LOGO,
 *  which needs the base `.rh-zone{flex:1 1 0}` equal-thirds from header.css
 *  (so it sits at the row's true centre regardless of how wide the start/end
 *  zones' content is) rather than "shrink to content, centre keeps leftover
 *  space" — without this exclusion the unequal start/end content widths
 *  (nav links vs. icon cluster) pushed the leftover centre space off-centre,
 *  so the logo no longer lined up with anything centred below it on the page.
 * ===================================================================== */
.rahkar-site-header .rh-row--main:not(.rh-row--split) .rh-zone--start,
.rahkar-site-header .rh-row--main:not(.rh-row--split) .rh-zone--end {
	flex: 0 0 auto;
}
.rahkar-site-header .rh-row--main:not(.rh-row--split) .rh-zone--center {
	flex: 1 1 auto;
	justify-content: center;
}
.rahkar-site-header .rh-row--main:not(.rh-row--split) .rh-item--search_form {
	width: 100%;
}
/* Override header.css's 320px cap so the field stretches like Digikala. */
.rahkar-site-header .rh-row--main:not(.rh-row--split) .rh-search,
.rahkar-site-header .rh-row--main:not(.rh-row--split) .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;
	}
}

/* =============================================================================
 *  CATBAR ROW LAYER — moved here from header.css / header-glass.css.
 *
 *  The upstream (Gunesh) header has no second row, so its header.css and
 *  header-glass.css carry NO `.rh-row--menu_row` rules at all. Keeping those
 *  two files byte-identical to upstream makes future syncs a straight copy, so
 *  every rule the category row needs lives here instead — this sheet is already
 *  Arama-only and loads right after header.css (priority 33 vs 30).
 *
 *  No mode guard is needed: header.tpl renders `.rh-row--menu_row` (and the
 *  main row's inline `.rh-item--search_form`) ONLY when RAHKAR_HEADER_MODE is
 *  'catbar', so on the transparent/solid modes these selectors match nothing.
 * ========================================================================== */

/* ---- Visibility: desktop shows the row, mobile never does ---------------- */
.rh-row--menu_row { display: block; --rh-row-h: 48px; }

@media (max-width: 900px) {
	.rh-row--menu_row { display: none; }
}

/* ---- Sticky scroll: collapse the category row once the page scrolls ------
 * No overflow:hidden at rest — it would clip the mega panel, which is
 * position:absolute and drops BELOW this row. Clipping is reintroduced only
 * in the collapsed state, where it is actually needed. */
@media (min-width: 901px) {
	.rh-row--menu_row {
		max-height: var(--rh-row-h);
		transition: max-height 200ms ease-out, border-top-width 200ms ease-out;
	}
	.rahkar-site-header.is-scrolled .rh-row--menu_row {
		max-height: 0;
		overflow: hidden;
		border-top-width: 0;
	}
}

/* ---- HOME (hero behind the header) --------------------------------------
 * header.js always adds `.is-scrolled`, which the rule above collapses. On
 * home we drive the header from `rh-scrolled` instead, so undo that collapse
 * first and then re-express it in terms of `rh-nav-hidden`. */
html.rh-home-hero .rahkar-site-header.is-scrolled .rh-row--menu_row {
	max-height: 999px;
	overflow: visible;
}

@media (min-width: 901px) {
	/* Top state over the hero: no category row and no inline search field —
	 * the empty center zone stays as a flex spacer so the logo keeps to the
	 * start (visual right in RTL) and cart/account to the end. */
	html.rh-home-hero:not(.rh-scrolled) .rahkar-site-header .rh-row--main .rh-item--search_form,
	html.rh-home-hero:not(.rh-scrolled) .rahkar-site-header .rh-row--menu_row {
		display: none !important;
	}

	/* Scrolled on home → the category row is shown, unclipped (mega panel). */
	html.rh-home-hero.rh-scrolled .rahkar-site-header .rh-row--menu_row {
		display: block !important;
		max-height: 999px !important;
		transition: max-height .25s ease, opacity .2s ease;
		opacity: 1;
	}
	/* Scrolling DOWN → smart-hide it (logo + search + icons stay put). */
	html.rh-home-hero.rh-scrolled.rh-nav-hidden .rahkar-site-header .rh-row--menu_row {
		max-height: 0 !important;
		overflow: hidden;
		opacity: 0;
		border-top-width: 0;
		pointer-events: none;
	}
}

/* ---- EVERY OTHER PAGE — same direction-aware smart-hide ------------------
 * The base collapse above is one-way (it never reopens until you scroll back
 * to the very top). Off home we instead follow `rh-nav-hidden`, which header.js
 * toggles from the scroll DIRECTION: open when scrolling up, hidden when
 * scrolling down. The home rules are scoped to .rh-home-hero, so the
 * :not(.rh-home-hero) guard keeps the two behaviours fully separate. */
@media (min-width: 901px) {
	html:not(.rh-home-hero) .rahkar-site-header.is-scrolled .rh-row--menu_row {
		max-height: 999px;
		overflow: hidden;
		border-top-width: 1px;
		transition: max-height .25s ease, opacity .2s ease, border-top-width .2s ease;
		opacity: 1;
	}
	html:not(.rh-home-hero).rh-nav-hidden .rahkar-site-header.is-scrolled .rh-row--menu_row {
		max-height: 0;
		opacity: 0;
		border-top-width: 0;
		pointer-events: none;
	}
}
