/* =============================================================================
 * Rahkar — sticky + glassmorphism header (SITE-WIDE) and the homepage hero overlap.
 *
 * Loaded globally, AFTER header.css (a verbatim base). Uses the standard glass
 * tokens from glass.css so the header matches every other frosted surface.
 *
 * Behaviour (per the owner):
 *   • EVERY non-home page: the header is frosted-glass + sticky.
 *   • HOMEPAGE, at the very top (over the 100vh hero video): the header is FULLY
 *     TRANSPARENT and shows only the logo + icons (desktop: cart/account; mobile:
 *     hamburger + cart). Search form + category bar are hidden.
 *   • HOMEPAGE, once you start scrolling: the WHOLE header turns to frosted glass
 *     and everything comes back — desktop = logo + search + category bar + icons;
 *     mobile = the mobile row + the search row — and it stays floating (fixed)
 *     over the content all the way to the bottom of the page.
 *
 * The scrolled/at-top switch is driven by home-hero.js, which toggles
 * `rh-scrolled` on <html> from the scroll position (NOT an IntersectionObserver
 * sentinel — a 100vh hero put the sentinel at the fold and mis-fired on load).
 *
 * Header breakpoint matches header.css: desktop ≥ 901px, mobile ≤ 900px.
 * Header root: `.rahkar-site-header`, wrapped by `<header id="header">` (page.tpl).
 * ========================================================================== */

:root { --rh-header-h: 68px; }

/* ---- STICKY GLASS on every page (default) --------------------------------- */
#header {
  position: -webkit-sticky;
  position: sticky;
  top: 0;
  z-index: 95;
}
/* MOBILE (≤900px): pin ONLY the search bar. The header stays sticky but is
 * pulled up by exactly the mobile (logo / cart / hamburger) row height, so that
 * row scrolls off the top and the search row catches at top:0 and stays there
 * for the whole page. Pure CSS — no dependency on the JS is-scrolled toggle.
 * (Home-hero overrides #header to position:fixed at higher specificity, so this
 * doesn't affect the homepage hero behaviour.) */
@media (max-width: 900px) {
  /* Scoped with :has() to the full shop header only — the cart/checkout funnel
   * header is also #header but has no search row, so it stays pinned at top:0.
   * Browsers without :has() simply keep the previous whole-header-sticky
   * behaviour (graceful degradation).
   *
   * `position: sticky` is RE-DECLARED here on purpose: the forked classic
   * theme.css sets `#header{position:relative}` and loads AFTER this file, so at
   * the bare `#header` (specificity 1,0,0) it wins — leaving the header merely
   * shifted up by -56px (logo row permanently hidden), NOT sticky. This selector
   * is (1,1,0) via :has(.rh-row--search), so it reclaims `position: sticky`
   * regardless of load order. Net effect on mobile shop pages: the FULL header
   * (logo/hamburger/cart row + search row) shows at the top, and on scroll the
   * logo row scrolls off while the search row pins at top:0. */
  #header:has(.rh-row--search) {
    position: -webkit-sticky;
    position: sticky;
    top: calc(var(--rh-row-h-mobile, 56px) * -1);
  }
}
.rahkar-site-header {
  transition: background .3s ease, box-shadow .3s ease,
              -webkit-backdrop-filter .3s ease, backdrop-filter .3s ease;
  background: var(--rh-glass-bg, rgba(255, 255, 255, 0.72));
  -webkit-backdrop-filter: blur(var(--rh-glass-blur, 20px)) saturate(var(--rh-glass-saturate, 180%));
  backdrop-filter: blur(var(--rh-glass-blur, 20px)) saturate(var(--rh-glass-saturate, 180%));
  border-bottom: 1px solid var(--rh-glass-border, rgba(255, 255, 255, 0.30));
  box-shadow: 0 1px 0 rgba(0, 0, 0, .04), 0 6px 24px rgba(0, 0, 0, .05);
}
/* Inner rows transparent so a single glass layer shows through (base header.css
 * gives the rows a solid bg + borders). */
.rahkar-site-header .rh-row { background: transparent; }
.rahkar-site-header .rh-row + .rh-row { border-top-color: rgba(0, 0, 0, .05); }

@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .rahkar-site-header { background: rgba(255, 255, 255, 0.96); }
}

/* =============================================================================
 * HOMEPAGE HERO OVERLAP — both breakpoints.
 * On home the WHOLE #header is fixed (out of flow) so the full-bleed, flush-top
 * hero fills the viewport from y=0 with the header floating over it, and the
 * frosted glass keeps floating over the content as you scroll down.
 * ========================================================================== */
html.rh-home-hero #header {
  position: fixed;
  left: 0; right: 0; top: 0;
}

/* CRITICAL: neutralise the BASE header.js collapse on home. header.js always
 * adds `.is-scrolled` (collapsing the desktop menu bar / the mobile search row to
 * max-height:0). That fought our own rh-scrolled logic — causing the flicker and
 * the menu/search never appearing on scroll. On home we drive everything from
 * `rh-scrolled` instead, so force the base-collapsed rows back to full height. */
html.rh-home-hero .rahkar-site-header.is-scrolled .rh-row--menu_row,
html.rh-home-hero .rahkar-site-header.is-scrolled .rh-row--mobile,
html.rh-home-hero .rahkar-site-header.is-scrolled .rh-row--search {
  max-height: 999px;
  overflow: visible;
}

/* TOP STATE (not scrolled) — FULLY TRANSPARENT over the video, on both sizes.
 * !important beats the default glass background defined above (same specificity,
 * but we must be certain there is zero band over the hero). A soft drop-shadow
 * keeps the logo/icons legible instead of a background scrim. */
html.rh-home-hero:not(.rh-scrolled) .rahkar-site-header {
  background: transparent !important;
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
  border-bottom-color: transparent !important;
  box-shadow: none !important;
}

/* DESKTOP (≥901px) top state: hide the search FORM + the category bar; keep the
 * empty center zone as a flex spacer so the logo stays at the start (visual RIGHT
 * in RTL) and cart/account sit at the end (visual LEFT) — not clustered. */
@media (min-width: 901px) {
  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;
  }
}

/* MOBILE (≤900px) top state: keep the mobile row (logo + hamburger + cart);
 * hide ONLY the search row. It returns on scroll. */
@media (max-width: 900px) {
  html.rh-home-hero:not(.rh-scrolled) .rahkar-site-header .rh-row--search {
    display: none !important;
  }
}

/* SCROLLED STATE (both sizes) — the FULL header returns as strong frosted glass,
 * floating over the content to the bottom of the page. The rows hidden above are
 * scoped to :not(.rh-scrolled), so they reappear here; we also re-assert their
 * display so nothing the base collapsed stays hidden. */
html.rh-home-hero.rh-scrolled .rahkar-site-header {
  background: var(--rh-glass-bg-strong, rgba(255, 255, 255, 0.82)) !important;
  -webkit-backdrop-filter: blur(var(--rh-glass-blur, 20px)) saturate(var(--rh-glass-saturate, 180%)) !important;
  backdrop-filter: blur(var(--rh-glass-blur, 20px)) saturate(var(--rh-glass-saturate, 180%)) !important;
  border-bottom-color: var(--rh-glass-border, rgba(255, 255, 255, 0.30)) !important;
  box-shadow: 0 1px 0 rgba(0, 0, 0, .06), 0 6px 24px rgba(0, 0, 0, .06) !important;
  color: var(--wp--preset--color--text, #1a1d23);
}
@media (min-width: 901px) {
  /* Scrolled UP (or just left the top) → the category/menu bar is shown.
     NO overflow:hidden in this shown state: the «دسته‌بندی کالاها» mega panel is
     position:absolute and drops BELOW this row (inset-block-start:100%), so a
     clip here hides the panel — that was exactly why the dropdown refused to open
     on the homepage (it works on other pages because the base header.css keeps
     the row unclipped at rest). Clipping is reintroduced only in the collapsed
     (.rh-nav-hidden) state below, mirroring that base pattern. */
  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 the menu bar (logo + search + icons stay).
     overflow:hidden lives here so the bar clips cleanly as it collapses. */
  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;
  }
}
@media (max-width: 900px) {
  html.rh-home-hero.rh-scrolled .rahkar-site-header .rh-row--search {
    display: block !important;
    max-height: 999px !important;
    overflow: visible;
  }
}

/* =============================================================================
 * NON-HOME PAGES — direction-aware menu bar (desktop).
 * Brings the homepage's smart-hide behaviour to every other page that uses this
 * header (category / CMS pages / looks & sets / search / … — cart & checkout use
 * a separate funnel header and are unaffected). The main row stays pinned at
 * top:0 (the #header sticky rule above); the category/menu row hides while
 * scrolling DOWN and returns while scrolling UP.
 *
 * The base header.css collapses .rh-row--menu_row whenever .is-scrolled is set
 * (a one-way collapse that never reopens until you reach the top). We override
 * that for non-home pages so the bar instead follows `rh-nav-hidden` (toggled by
 * header.js from the scroll direction): open when scrolled-up, hidden when
 * scrolled-down. Home rules above are scoped to .rh-home-hero, so the
 * :not(.rh-home-hero) guard keeps the two behaviours fully separate.
 * ========================================================================== */
@media (min-width: 901px) {
  /* MAKE IT STICKY FIRST. The forked classic theme.css sets
     `#header{position:relative}` and loads AFTER header-glass.css, so the bare
     `#header{position:sticky}` at the top of this file (specificity 1,0,0) loses
     and the whole header scrolls away on desktop — which is why the menu-bar
     smart-hide below was invisible (no part of the header stayed on screen).
     Mobile reclaims sticky via `:has(.rh-row--search)` and home via
     `html.rh-home-hero #header{fixed}`; this is the missing desktop-non-home
     reclaim. `html:not(.rh-home-hero) #header` = (1,1,1) > theme.css's (1,0,0). */
  html:not(.rh-home-hero) #header {
    position: -webkit-sticky;
    position: sticky;
    top: 0;
  }

  /* Scrolled, but NOT scrolling down → the menu bar is shown (beats the base
     `.is-scrolled .rh-row--menu_row{max-height:0}` via higher specificity). */
  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;
  }
  /* Scrolling DOWN → smart-hide the menu bar (logo + search + icons stay). */
  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;
  }
}

/* =============================================================================
 * FULLSCREEN SEARCH OVERLAY — escape the glass containing block.
 * The glass `backdrop-filter` above makes `.rahkar-site-header` the CONTAINING
 * BLOCK for every position:fixed descendant. The mobile search overlay
 * (`.rh-search-wrap.is-open { position: fixed; inset: 0 }`, header-search.css)
 * lives inside the header, so its `inset: 0` resolves against the ~115px header
 * box instead of the viewport — the overlay covers only the top strip and the
 * page (filters + product grid) bleeds through below it.
 *
 * While the overlay is open (header-search.js adds `html.rh-search-open`, mobile
 * only) we drop the header's backdrop-filter so `.rahkar-site-header` stops
 * establishing a containing block and the fixed overlay fills the real viewport.
 * `!important` + later source order beats the home `.rh-scrolled` glass rule
 * above. No visual cost: the opaque white overlay already covers the header, so
 * removing the blur underneath is invisible. */
html.rh-search-open .rahkar-site-header {
  -webkit-backdrop-filter: none !important;
  backdrop-filter: none !important;
}

/* ---- Mobile bottom-nav glass lives in bottom-nav.css (the authoritative dock
 *      styles, gated by its own media query) so it isn't overridden by load
 *      order. See `.rh-bnav` there. --------------------------------------- */
