/* ==========================================================================
   Raytabuk — navbar (header, mega menu, dropdowns, search overlay, mobile drawer)
   Markup: src/partials/header.mjs   Behaviour: js/navbar.js
   Colours come from theme.css tokens, so light / dark need no extra work here.
   Motion: transform + opacity only, shared tokens below, no `transition: all`.
   ========================================================================== */
:root {
  --motion-fast: 150ms;
  --motion-normal: 220ms;
  --motion-slow: 300ms;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
  --hdr-h: 76px;
  --hdr-w: 1320px;
  --z-header: 900;
  --z-drawer-scrim: 1000;
  --z-drawer: 1010;
  --z-search: 1050;
}
@media (max-width: 1159px) { :root { --hdr-h: 64px; } }
html { scroll-padding-top: calc(var(--hdr-h) + 16px); }

/* ------------------------------ bar ------------------------------------- */
.hdr {
  position: sticky; top: 0; z-index: var(--z-header);
  height: var(--hdr-h);
  background: color-mix(in srgb, var(--surface) 96%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid transparent;
  box-shadow: 0 6px 18px -16px rgba(0, 0, 0, 0);
  transition: border-color var(--motion-normal) var(--ease-standard), box-shadow var(--motion-normal) var(--ease-standard), background-color var(--motion-normal) var(--ease-standard);
}
.hdr[data-scrolled] { border-bottom-color: var(--border); box-shadow: 0 8px 20px -18px rgba(0, 0, 0, .45); }
.hdr-inner {
  position: relative; max-width: var(--hdr-w); height: 100%; margin-inline: auto;
  padding-inline: 24px; display: flex; align-items: center; gap: 20px;
}

.hdr-brand { display: inline-flex; align-items: center; gap: 10px; flex-shrink: 0; min-height: 44px; }
.hdr-logo { height: 44px; width: auto; max-width: none; object-fit: contain; flex-shrink: 0; }
.hdr-brand-name { font-weight: 800; font-size: 1.05rem; line-height: 1.2; color: var(--heading); white-space: nowrap; }
:root[data-theme="dark"] .hdr-logo { background: #fff; border-radius: 10px; padding: 3px; height: 44px; }

.hdr-nav { position: relative; margin-inline-start: 8px; }
.hdr-links { display: flex; align-items: center; gap: 2px; list-style: none; margin: 0; padding: 0; }
.hdr-link {
  position: relative; display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding-inline: 12px;
  border-radius: 10px; font-weight: 600; font-size: .96rem; color: var(--ink); white-space: nowrap;
  transition: color var(--motion-fast) var(--ease-standard), background-color var(--motion-fast) var(--ease-standard);
}
.hdr-link::after {  /* hover / focus underline: grows from the start of the text (RTL aware) */
  content: ""; position: absolute; inset-inline: 12px; bottom: 7px; height: 2px; border-radius: 2px; background: currentColor;
  transform: scaleX(0); transform-origin: left center; transition: transform var(--motion-fast) var(--ease-out);
}
[dir="rtl"] .hdr-link::after { transform-origin: right center; }
.hdr-link:focus-visible::after { transform: scaleX(1); }
.hdr-link:focus-visible { background: var(--surface-2); }
.hdr-link[aria-current="page"], .hdr-link.is-active { color: var(--action-text); font-weight: 700; }
.hdr-link .ic { transition: transform var(--motion-normal) var(--ease-out); }
.hdr-link[aria-expanded="true"] .ic { transform: rotate(180deg); }
.hdr-link[aria-expanded="true"] { background: var(--surface-2); }

/* the active page marker: one element that slides between links */
.hdr-indicator {
  position: absolute; left: 0; bottom: 3px; height: 3px; width: 0; border-radius: 3px; background: var(--action);
  transform: translateX(var(--ix, 0px)); opacity: 0; pointer-events: none;
}
.hdr-indicator.is-ready { opacity: 1; width: var(--iw, 0px); }
.hdr-indicator.is-animated { transition: transform var(--motion-slow) var(--ease-out), width var(--motion-slow) var(--ease-out), opacity var(--motion-fast); }

.hdr-tools { display: flex; align-items: center; gap: 4px; margin-inline-start: auto; }
.hdr-mobile-tools { display: none; align-items: center; gap: 2px; margin-inline-start: auto; }
.hdr-icon {
  position: relative; display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; color: var(--heading);
  transition: background-color var(--motion-fast) var(--ease-standard), transform var(--motion-fast) var(--ease-out), color var(--motion-fast);
}
.hdr-icon:focus-visible { background: var(--surface-2); }
.hdr-icon[aria-expanded="true"] { background: var(--surface-2); }
.hdr-dot { position: absolute; top: 9px; inset-inline-end: 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--action); box-shadow: 0 0 0 2px var(--surface); }
.hdr .cart-badge { position: absolute; top: 3px; inset-inline-end: 1px; }
.cart-badge.is-bump { animation: badgeBump 280ms var(--ease-out); }
@keyframes badgeBump { 0% { transform: scale(.85); } 55% { transform: scale(1.12); } 100% { transform: scale(1); } }

.hdr-cta {
  display: inline-flex; align-items: center; gap: 8px; height: 44px; padding-inline: 18px; margin-inline-start: 8px; border-radius: 12px;
  background: var(--action); color: var(--on-accent, #fff); font-weight: 700; font-size: .95rem; white-space: nowrap;
  transition: transform var(--motion-fast) var(--ease-out), background-color var(--motion-fast) var(--ease-standard), box-shadow var(--motion-fast) var(--ease-standard);
}
.hdr-cta .ic { transition: transform var(--motion-fast) var(--ease-out); }
[dir="rtl"] .hdr-cta .ic { transform: scaleX(-1); }
.hdr-cta:active { transform: scale(.98); }
.hdr-cta:focus-visible { background: var(--action-hover); }

/* hover effects only where hover is real (no sticky states on touch) */
@media (hover: hover) and (pointer: fine) {
  .hdr-link:hover { color: var(--heading); background: var(--surface-2); }
  .hdr-link:hover::after { transform: scaleX(1); }
  .hdr-link[aria-current="page"]:hover, .hdr-link.is-active:hover { color: var(--action-text); }
  .hdr-icon:hover { background: var(--surface-2); transform: scale(1.04); }
  .hdr-cta:hover { transform: translateY(-1px); background: var(--action-hover); box-shadow: 0 8px 16px -10px rgba(18, 60, 47, .6); }
  .hdr-cta:hover .ic { transform: translateX(3px); }
  [dir="rtl"] .hdr-cta:hover .ic { transform: translateX(-3px) scaleX(-1); }
  .hdr-cta:active { transform: scale(.98); }
}

/* ----------------------------- first visit entrance ---------------------- */
@keyframes hdrIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: none; } }
@keyframes itemIn { from { opacity: 0; } to { opacity: 1; } }
html.nav-first .hdr { animation: hdrIn 450ms var(--ease-out) both; }
html.nav-first .hdr [data-hdr-item] { animation: itemIn 320ms var(--ease-out) both; }
html.nav-first .hdr .hdr-brand { animation-delay: 70ms; }
html.nav-first .hdr .hdr-nav { animation-delay: 105ms; }
html.nav-first .hdr .hdr-tools, html.nav-first .hdr .hdr-mobile-tools { animation-delay: 140ms; }

/* ------------------------------ menus ----------------------------------- */
.menu {
  position: absolute; z-index: 2; top: calc(100% - 6px); left: var(--menu-x, 24px);
  min-width: 260px; max-width: calc(100vw - 16px);
  background: var(--surface-elevated); border: 1px solid var(--border); border-radius: 16px; padding: 10px;
  box-shadow: 0 22px 44px -26px rgba(0, 0, 0, .55);
  opacity: 0; transform: translateY(-6px) scale(.985); transform-origin: var(--origin, top center); pointer-events: none;
  transition: opacity 150ms var(--ease-standard), transform 150ms var(--ease-standard);
}
.menu[hidden] { display: none; }
.menu[data-state="open"] {
  opacity: 1; transform: none; pointer-events: auto;
  transition: opacity 240ms var(--ease-out), transform 240ms var(--ease-out);
}
.menu.mega { left: 24px; right: 24px; min-width: 0; padding: 22px; --origin: top center; }
.menu.narrow { min-width: 220px; }
.menu-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 8px 12px; border-radius: 10px; color: var(--ink); font-weight: 600;
  transition: background-color var(--motion-fast) var(--ease-standard), color var(--motion-fast);
}
.menu-item:focus-visible { background: var(--surface-2); }
.menu-item[aria-current="page"] { color: var(--action-text); }
@media (hover: hover) and (pointer: fine) { .menu-item:hover { background: var(--surface-2); color: var(--heading); } }
.menu-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 8px; padding: 10px 2px 2px; border-top: 1px solid var(--border); }
.menu-label { font-size: .78rem; font-weight: 700; color: var(--muted); padding: 6px 12px 4px; }
.menu-group + .menu-group { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
.menu-opt {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 44px; padding: 8px 12px; border-radius: 10px;
  color: var(--ink); font-weight: 600; text-align: start;
  transition: background-color var(--motion-fast) var(--ease-standard);
}
.menu-opt .ic, .dr-seg-opt .ic { flex-shrink: 0; }
.menu-opt .tick { margin-inline-start: auto; color: var(--action-text); visibility: hidden; }
.menu-opt[aria-checked="true"] { background: var(--accent-soft); color: var(--heading); font-weight: 700; }
.menu-opt[aria-checked="true"] .tick { visibility: visible; }
.menu-opt:focus-visible { background: var(--surface-2); }
@media (hover: hover) and (pointer: fine) { .menu-opt:hover { background: var(--surface-2); } .menu-opt[aria-checked="true"]:hover { background: var(--accent-soft); } }
.lang-glyph { display: inline-grid; place-items: center; width: 20px; font-weight: 800; font-size: .85rem; }
.menu-who { padding: 10px 12px 8px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu-who small { display: block; color: var(--muted); font-size: .78rem; }
.menu-who strong { display: block; font-size: .92rem; color: var(--heading); overflow: hidden; text-overflow: ellipsis; max-width: 240px; direction: ltr; text-align: start; }
.menu.dropdown.end { min-width: 244px; }

/* children rise in with a short, capped stagger (<= ~350ms in total) */
@keyframes rise { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }
.menu[data-state="open"] .menu-list > li,
.menu[data-state="open"] .mega-cats > li,
.menu[data-state="open"] .menu-group,
.menu[data-state="open"] .menu-foot,
.menu[data-state="open"] .menu-who {
  animation: rise 220ms var(--ease-out) both;
  animation-delay: calc(min(var(--i, 0), 12) * 22ms + 30ms);
}
.menu[data-state="open"] .mega-title { animation: rise 220ms var(--ease-out) both; animation-delay: 20ms; }
.menu[data-state="open"] .mega-all { animation: rise 220ms var(--ease-out) both; animation-delay: 240ms; }
.menu[data-state="open"] .mega-help { animation: rise 240ms var(--ease-out) both; animation-delay: 120ms; }

/* mega */
.mega-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; }
.mega-title { font-size: 1.15rem; color: var(--heading); margin: 0 0 14px; }
.mega-cats { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 12px; }
.mega-cat {
  display: flex; align-items: center; gap: 12px; min-height: 52px; padding: 8px 10px; border-radius: 12px; color: var(--ink);
  transition: background-color var(--motion-fast) var(--ease-standard);
}
.mega-cat:focus-visible { background: var(--surface-2); }
@media (hover: hover) and (pointer: fine) { .mega-cat:hover { background: var(--surface-2); } }
.mega-ic { display: inline-grid; place-items: center; width: 40px; height: 40px; flex-shrink: 0; border-radius: 10px; background: var(--accent-soft); color: var(--heading); }
.mega-name { font-weight: 700; flex: 1; min-width: 0; }
.mega-n { font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.mega-all { display: inline-flex; align-items: center; gap: 8px; margin-top: 14px; min-height: 44px; font-weight: 700; color: var(--action-text); }
[dir="rtl"] .mega-all .ic { transform: scaleX(-1); }
.mega-all:hover { text-decoration: underline; }
.mega-help { background: var(--surface-2); border-radius: 14px; padding: 18px; align-self: start; }
.mega-help h3 { font-size: 1rem; color: var(--heading); margin: 0 0 6px; }
.mega-help p { color: var(--muted); font-size: .92rem; margin: 0 0 14px; }

/* ----------------------------- search ------------------------------------ */
.search-layer { position: fixed; inset: 0; z-index: var(--z-search); }
.search-layer[hidden] { display: none; }
.search-scrim { position: absolute; inset: 0; background: rgba(6, 12, 9, .5); opacity: 0; transition: opacity var(--motion-normal) var(--ease-standard); }
.search-panel {
  position: relative; width: min(720px, calc(100% - 24px)); margin: 10vh auto 0; max-height: 78vh; overflow: hidden; display: flex; flex-direction: column;
  background: var(--surface-elevated); border: 1px solid var(--border); border-radius: 18px; box-shadow: 0 30px 60px -30px rgba(0, 0, 0, .6);
  opacity: 0; transform: translateY(-10px);
  transition: opacity var(--motion-normal) var(--ease-out), transform var(--motion-normal) var(--ease-out);
}
.search-layer[data-state="open"] .search-scrim { opacity: 1; }
.search-layer[data-state="open"] .search-panel { opacity: 1; transform: none; }
.search-layer[data-state="closed"] .search-panel, .search-layer[data-state="closed"] .search-scrim { transition-duration: 150ms; }
.search-form { display: flex; align-items: center; gap: 8px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--border); }
[dir="rtl"] .search-form { padding: 10px 16px 10px 10px; }
.search-form > .ic { color: var(--muted); flex-shrink: 0; }
.search-form input {
  flex: 1; min-width: 0; height: 48px; border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 1.05rem; outline: none;
}
.search-form input::-webkit-search-cancel-button { display: none; }
.search-body { overflow: auto; padding: 8px; min-height: 64px; }
.sr-msg { padding: 22px 16px; color: var(--muted); text-align: center; }
.sr-msg strong { display: block; color: var(--heading); margin-bottom: 4px; }
.sr-msg .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.sr-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.sr-item { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 10px; border-radius: 12px; color: var(--ink); }
.sr-item:focus-visible, .sr-item[aria-selected="true"] { background: var(--surface-2); }
@media (hover: hover) and (pointer: fine) { .sr-item:hover { background: var(--surface-2); } }
.sr-thumb { width: 44px; height: 44px; flex-shrink: 0; border-radius: 10px; background: var(--tint); color: var(--icon-muted); display: grid; place-items: center; }
.sr-name { flex: 1; min-width: 0; font-weight: 600; font-size: .94rem; unicode-bidi: plaintext; text-align: start; }
.sr-title { display: block; text-align: start; unicode-bidi: plaintext; }
.sr-cat { display: block; font-size: .76rem; color: var(--action-text); font-weight: 700; }
.sr-price { font-weight: 800; color: var(--heading); white-space: nowrap; font-size: .94rem; }
.sr-all { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; margin-top: 6px; border-radius: 12px; font-weight: 700; color: var(--action-text); background: var(--accent-soft); }
.sr-fade { animation: itemIn 140ms var(--ease-standard) both; }

/* ----------------------------- drawer ------------------------------------ */
.drawer-scrim {
  position: fixed; inset: 0; z-index: var(--z-drawer-scrim); background: rgba(6, 12, 9, .5); opacity: 0;
  transition: opacity 220ms var(--ease-standard);
}
.drawer-scrim[data-state="open"] { opacity: 1; transition-duration: var(--motion-slow); }
.drawer {
  position: fixed; top: 0; bottom: 0; inset-inline-start: 0; z-index: var(--z-drawer);
  width: min(380px, 92vw); display: flex; flex-direction: column; background: var(--surface); border-inline-end: 1px solid var(--border);
  box-shadow: 0 0 40px -10px rgba(0, 0, 0, .5);
  transform: translateX(-102%); transition: transform 220ms var(--ease-standard);
}
[dir="rtl"] .drawer { transform: translateX(102%); }
.drawer[data-state="open"] { transform: none; transition: transform var(--motion-slow) var(--ease-out); }
.drawer[hidden], .drawer-scrim[hidden] { display: none; }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 64px; padding-inline: 16px 8px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
[dir="rtl"] .drawer-head { padding-inline: 16px 8px; }
.drawer-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 8px 12px 16px; }
.drawer-foot { flex-shrink: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: var(--surface); }
.dr-list { list-style: none; margin: 0; padding: 0; }
.dr-link {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; width: 100%; min-height: 52px; padding-inline: 12px; border-radius: 12px;
  font-weight: 700; font-size: 1.02rem; color: var(--ink); text-align: start;
  transition: background-color var(--motion-fast) var(--ease-standard);
}
.dr-link:focus-visible { background: var(--surface-2); }
.dr-link[aria-current="page"], .dr-link.is-active { color: var(--action-text); box-shadow: inset 3px 0 0 var(--action); }
[dir="rtl"] .dr-link[aria-current="page"], [dir="rtl"] .dr-link.is-active { box-shadow: inset -3px 0 0 var(--action); }
.dr-link .ic { transition: transform var(--motion-normal) var(--ease-out); }
.dr-link[aria-expanded="true"] .ic { transform: rotate(180deg); }
.dr-panel { display: grid; grid-template-rows: 0fr; opacity: 0; transition: grid-template-rows var(--motion-normal) var(--ease-out), opacity var(--motion-normal) var(--ease-standard); }
.dr-panel-in { overflow: hidden; min-height: 0; }
.dr-panel ul { list-style: none; margin: 0; padding: 2px 0 8px; }
.dr-link[aria-expanded="true"] + .dr-panel { grid-template-rows: 1fr; opacity: 1; }
.dr-sub {
  display: flex; align-items: center; gap: 12px; min-height: 48px; padding-inline: 12px 8px; margin-inline-start: 10px; border-radius: 10px; color: var(--ink); font-weight: 600;
}
.dr-sub:focus-visible { background: var(--surface-2); }
.dr-sub-all { color: var(--action-text); font-weight: 700; }
.dr-block { padding: 14px 8px 4px; border-top: 1px solid var(--border); margin-top: 10px; }
.dr-block .menu-label { padding-inline: 4px; }
.dr-seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px; margin: 4px 0 12px; }
.dr-seg-opt {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; min-height: 56px; padding: 6px 4px; border-radius: 12px;
  border: 1.5px solid var(--border); background: var(--surface); color: var(--ink); font-weight: 700; font-size: .8rem; text-align: center;
}
.dr-seg-opt .tick { display: none; }
.dr-seg-opt[aria-checked="true"] { border-color: var(--action); background: var(--accent-soft); color: var(--heading); }
.dr-acct { display: grid; gap: 4px; }
.dr-acct .menu-item { min-height: 48px; }
.dr-acct .who { padding: 4px 12px 8px; }
.dr-acct .who small { display: block; color: var(--muted); font-size: .78rem; }
.dr-acct .who strong { display: block; direction: ltr; text-align: start; overflow: hidden; text-overflow: ellipsis; color: var(--heading); }
.drawer[data-state="open"] .dr-group { animation: rise 220ms var(--ease-out) both; animation-delay: calc(var(--i, 0) * 25ms + 60ms); }

/* burger -> X */
.hdr-burger { position: relative; width: 44px; height: 44px; border-radius: 12px; display: inline-block; color: var(--heading); }
.hdr-burger span { position: absolute; inset-inline-start: 11px; width: 22px; height: 2px; border-radius: 2px; background: currentColor; transition: transform var(--motion-normal) var(--ease-out), opacity var(--motion-fast); }
.hdr-burger span:nth-child(1) { top: 14px; }
.hdr-burger span:nth-child(2) { top: 21px; }
.hdr-burger span:nth-child(3) { top: 28px; }
.hdr-burger[aria-expanded="true"] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hdr-burger[aria-expanded="true"] span:nth-child(2) { opacity: 0; transform: scaleX(.2); }
.hdr-burger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
.hdr-burger:focus-visible { background: var(--surface-2); }

html.drawer-open, html.search-open { overflow: hidden; }

/* ----------------------------- responsive -------------------------------- */
@media (max-width: 1159px) {
  .hdr-nav, .hdr-tools, .menu { display: none !important; }
  .hdr-mobile-tools { display: flex; }
  .hdr-inner { padding-inline: 16px; gap: 8px; }
  .hdr-brand-name { font-size: .98rem; }
  .hdr-logo, :root[data-theme="dark"] .hdr-logo { height: 40px; }
}
@media (max-width: 380px) { .hdr-brand-name { font-size: .88rem; max-width: 110px; white-space: normal; } }
@media (min-width: 1160px) and (max-width: 1259px) {
  .hdr-inner { gap: 12px; padding-inline: 20px; }
  .hdr-link { padding-inline: 9px; font-size: .92rem; }
  .hdr-cta { padding-inline: 14px; margin-inline-start: 4px; }
  .hdr-brand-name { font-size: .98rem; }
}
@media (max-width: 640px) {
  .search-panel { margin-top: 0; width: 100%; border-radius: 0 0 18px 18px; max-height: 86vh; border-top: 0; }
}
@media (min-width: 1160px) {
  .drawer, .drawer-scrim, .search-panel { /* drawer never used on wide screens */ }
  .drawer, .drawer-scrim { display: none !important; }
}

/* ----------------------------- reduced motion ---------------------------- */
@media (prefers-reduced-motion: reduce) {
  .hdr, .hdr *, .menu, .menu *, .drawer, .drawer *, .drawer-scrim, .search-layer *, .search-layer {
    animation: none !important;
  }
  .hdr-link, .hdr-link::after, .hdr-icon, .hdr-cta, .hdr-cta .ic, .menu, .menu[data-state="open"], .drawer, .drawer[data-state="open"], .drawer-scrim,
  .dr-panel, .hdr-burger span, .hdr-indicator, .hdr-indicator.is-animated, .search-panel, .search-scrim, .menu-opt, .menu-item {
    transition-duration: .01ms !important;
    transition-delay: 0s !important;
  }
  .menu, .search-panel { transform: none; }
  .hdr-icon:hover, .hdr-cta:hover { transform: none; }
}
