/* =========================================================================
 *  nav.css — Shafa Shahd Modern Luxury Navigation
 * ========================================================================= */

.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: var(--z-nav);
  display: flex; align-items: center; justify-content: space-between;
  height: calc(var(--nav-height, 72px) + env(safe-area-inset-top, 0px));
  padding-inline: max(clamp(1rem, 3vw, 2.5rem), env(safe-area-inset-start, 0px)) max(clamp(1rem, 3vw, 2.5rem), env(safe-area-inset-end, 0px));
  padding-block: env(safe-area-inset-top, 0px) 0;
  background: var(--shafa-nav-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid rgba(197, 160, 89, 0.16);
  box-shadow: 0 4px 24px rgba(24, 22, 20, 0.03);
  /* Translate follows scroll for a "slide-in" feel rather than a hard jump */
  transform: translateY(-10px);
  opacity: 0;
  transition: background var(--t-base) var(--ease),
              backdrop-filter var(--t-base) var(--ease),
              border-color var(--t-base) var(--ease),
              box-shadow var(--t-base) var(--ease),
              transform var(--t-base) var(--ease),
              opacity var(--t-base) var(--ease);
}
.nav.is-visible {
  transform: translateY(0);
  opacity: 1;
}
.nav--hidden {
  transform: translateY(-105%);
  opacity: 0;
}
.nav--filled {
  background: var(--shafa-nav-bg-filled);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-bottom: 1px solid rgba(197, 160, 89, 0.28);
  box-shadow: 0 10px 30px -5px rgba(24, 22, 20, 0.06), 0 1px 3px rgba(197, 160, 89, 0.08);
}
.nav__logo {
  display: flex; align-items: center; gap: .75rem;
  font-weight: 700; font-size: 1.3rem;
  font-family: 'Vazirmatn', 'Inter', system-ui, sans-serif;
  text-decoration: none;
  transition: transform var(--t-base) var(--ease);
}
.nav__logo:hover {
  transform: scale(1.02);
}
.nav__logo img {
  width: 38px; height: 38px;
  filter: drop-shadow(0 2px 6px rgba(197, 160, 89, 0.3));
}
.nav__logo .brand-name {
  /* نسخهٔ متن‌گرادیانی (نه نسخهٔ عمومی) — پالت روشن برند روی زمینهٔ روشن
     ۱.۶۶:۱ بود و نام برند عملاً ناخوانا. نسخهٔ جدید در تم روشن ۵.۰۶:۱ و در
     تم تاریک (که توکن برمی‌گردد) ۴.۸۷:۱ می‌دهد. */
  color: var(--shafa-gold-text);
  background: var(--shafa-gold-gradient-text);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: var(--shafa-tracking-normal);
  font-weight: 700;
}
/* بدون این قاعده، -webkit-text-fill-color: transparent هنگام انتخاب متن هم
   فعال می‌ماند و نام برند روی هایلایت انتخاب نامرئی می‌شود. */
.nav__logo .brand-name::selection {
  background: var(--shafa-gold-satin);
  color: var(--shafa-on-gold);
  -webkit-text-fill-color: var(--shafa-on-gold);
}
.nav__links { display: flex; align-items: center; gap: var(--s-2); }
.nav__actions { display: flex; align-items: center; gap: var(--s-3); }

/* خوش‌آمدگویی کاربر واردشده — متن متغیر طول («علی، خوش برگشتی.») بدون
   سقف عرض می‌تواند ردیف اکشن‌ها را سرریز کند و نوبار را به‌هم بریزد.
   clamp عرضی + ellipsis تضمین می‌کند هر نامی در ردیف بماند. */
.nav__actions .nav__user-name {
  display: inline-block;
  max-width: clamp(5.5rem, 14vw, 10rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}

/* Search Input */
.nav__search { position: relative; display: flex; align-items: center; }
.nav__search-label {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.nav__search input {
  background: var(--shafa-input-bg);
  border: 1px solid var(--shafa-hairline);
  border-radius: var(--radius-pill);
  /* آیکون در inline-end (چپ در RTL) — فضای رزروشده هم باید همان‌جا باشد */
  padding-block: 8px; padding-inline: 18px 42px;
  font-size: .88rem; width: 200px;
  color: var(--shafa-text-primary);
  /* outline پیش‌فرض اینجا حذف نمی‌شود؛ فقط برای کلیک ماوس خنثی می‌شود تا
     حلقهٔ native در focus/keyboard و در forced-colors mode باقی بماند. */
  backdrop-filter: blur(8px);
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.02);
  transition: box-shadow var(--t-base) var(--ease),
              width var(--t-base) var(--ease),
              border-color var(--t-base) var(--ease),
              background var(--t-base) var(--ease);
}
.nav__search input::placeholder { color: var(--shafa-text-tertiary); }
.nav__search input:focus {
  background: var(--shafa-input-bg-strong);
  border-color: var(--shafa-gold-satin);
  box-shadow: var(--shafa-focus-ring), 0 4px 12px rgba(24, 22, 20, 0.04);
  width: 240px;
}
/* حلقه فقط برای کلیک ماوس برداشته می‌شود؛ برای کیبورد حتماً می‌ماند. */
.nav__search input:focus:not(:focus-visible) {
  outline: none;
}
.nav__search .material-symbols-outlined {
  position: absolute; inset-inline-end: 14px; pointer-events: none; color: var(--shafa-text-tertiary); font-size: 20px;
}
.nav__search--desktop { display: flex; }
.nav__search--mobile { display: none; }
.nav__search--drawer { display: flex; width: 100%; margin-bottom: var(--s-4); }
.nav__search--drawer input { width: 100%; }

/* دکمهٔ جستجوی موبایل — در navbar (کنار سبد/مقایسه) */
.nav__search-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-width: var(--shafa-touch);
  min-height: var(--shafa-touch);
  padding: 0 0.6rem;
  border-radius: var(--shafa-radius-full);
  background: var(--shafa-icon-btn-bg);
  border: 1px solid var(--shafa-hairline);
  color: var(--shafa-text-primary);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 500;
  transition:
    background var(--t-base) var(--ease),
    border-color var(--t-base) var(--ease),
    color var(--t-base) var(--ease);
}
.nav__search-toggle:hover,
.nav__search-toggle:focus-visible {
  background: var(--shafa-input-bg-strong);
  border-color: var(--shafa-gold-satin);
  color: var(--shafa-text-primary);
}
.nav__search-toggle__label { display: inline; }
.nav__search-toggle .material-symbols-outlined { font-size: 20px; }

/* Base: hamburger hidden on desktop/tablet; shown by the mobile media query below.
   Placed BEFORE the media query so the media query can correctly override it.
   (Pre-existing bug: a later bare .nav__burger { display: none } used to win
   over the mobile .nav__burger { display: flex } on every viewport.) */
.nav__burger {
  display: none; width: var(--touch); height: var(--touch);
  align-items: center; justify-content: center;
  border-radius: var(--shafa-radius-md);
  color: var(--shafa-text-primary);
  background: transparent;
  border: none;
  cursor: pointer;
  /* Touch target amplification for WCAG — 44×44 hit area, visual 24×24 icon */
}
.nav__burger::after {
  content: "";
  position: absolute;
  inset: 50% 50% 50% 50%;
  min-width: var(--shafa-touch);
  min-height: var(--shafa-touch);
  transform: translate(-50%, -50%);
}
.nav__burger svg { width: 26px; height: 26px; }

/* Base CTA sizing (desktop/tablet). Must be placed BEFORE the mobile media
   query so the mobile override can win — otherwise a later bare .nav__cta
   rule (padding 8px 22px + var(--fs-small)) would overflow the 56px mobile
   navbar on every viewport, same cascade bug as .nav__burger above. */
.nav__cta {
  min-height: var(--touch-sm);
  padding: 8px 22px;
  font-size: var(--fs-small);
  font-weight: 500;
  border-radius: var(--shafa-radius-full);
}

/* ============================================================
 *  RESPONSIVE: Mobile → Hamburger Menu
 * ============================================================ */
@media (max-width: 900px) {
  /* Desktop links hidden on mobile */
  .nav__links { display: none; }

  /* Desktop search hidden on mobile */
  .nav__search--desktop { display: none; }

  /* Mobile search also hidden in nav bar — drawer has its own search */
  .nav__search--mobile { display: none; }

  /* Desktop CTA button hidden on mobile.
     Uses .btn.nav__cta (0,2,0) — not bare .nav__cta (0,1,0) — because the
     CTA element also carries class="btn", and .btn from buttons.css (loaded
     LATER in the cascade) sets display: inline-flex. Without the compound
     selector, .btn would win on every viewport and the CTA would show on
     mobile with .btn's large padding, overflowing the 56px navbar. */
  .btn.nav__cta { display: none; }

  /* CTA sizing on mobile — when the CTA is visible (e.g. 768–900px range
     where the tablet query also matches), it must fit within the 56px
     navbar without overflowing. .btn.nav__cta (0,2,0) beats .btn (0,1,0)
     from buttons.css, which would otherwise apply padding 0.75rem 1.85rem
     + var(--shafa-fs-body) + min-height var(--shafa-touch-lg). */
  .btn.nav__cta {
    min-height: var(--touch-sm);
    padding: 6px 14px;
    font-size: 0.8rem;
    font-weight: 600;
  }

  /* Desktop user/login link hidden on mobile */
  .nav__actions .nav-link:not(.nav__cart):not(.nav__compare):not(.nav__search-toggle) {
    display: none;
  }

  /* Show hamburger */
  .nav__burger {
    display: flex;
  }

  /* Compact nav height on mobile */
  .nav {
    height: var(--nav-height-mobile, 60px);
    padding: 0 clamp(0.75rem, 4vw, 1.25rem);
  }

  /* Smaller logo on mobile — reduce both image and brand text.
     flex-shrink: 0 prevents the logo from being crushed by the nav bar,
     and the brand-name truncates with ellipsis rather than wrapping. */
  .nav__logo {
    font-size: 1rem;
    gap: 0.5rem;
    flex-shrink: 0;
  }
  .nav__logo .brand-name {
    font-size: 1rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .nav__logo img {
    width: 30px;
    height: 30px;
  }

  /* Hide compare badge text on mobile, keep icon */
  .nav__compare .compare-badge { display: none; }

  /* WCAG 2.5.5: cart/compare/search-toggle must be ≥44px touch target on mobile.
     Previously 36×36px — below the 44×44px minimum. Now uses --shafa-touch. */
  .nav__cart, .nav__compare, .nav__search-toggle {
    width: var(--shafa-touch);
    height: var(--shafa-touch);
  }
  .nav__search-toggle__label { display: none; }

  /* Smaller drawer CTA button on mobile — override base .btn properties */
  .drawer__footer .drawer__cta {
    min-height: 40px;
    padding: 0.55rem 1rem;
    font-size: 0.85rem;
    gap: 0.4rem;
  }
}

/* Very narrow phones: hide brand text, keep icon-only logo */
@media (max-width: 360px) {
  .nav__logo .brand-name { display: none; }
  .nav__search-toggle__label { display: none; }
}

/* ── Tablet breakpoint (768px – 1024px) ──
   No dedicated breakpoint existed before; drawer layout was used from
   900px downward. On a 768px tablet the drawer becomes ~660px wide,
   leaving only ~100px of content visible behind it. Now we keep the
   horizontal nav but condense it so it fits comfortably. */
@media (min-width: 768px) and (max-width: 1024px) {
  .nav__links { display: flex; }
  .nav__cta { display: inline-flex; }

  /* Condensed nav links on tablet — عمداً قبل از قاعدهٔ زنجیرهٔ :not()
     آمده تا ترتیب specificity برای stylelint صعودی بماند. */
  .nav__links {
    gap: var(--s-1);
  }
  .nav-link {
    font-size: 0.85rem;
    padding: 5px 9px;
  }

  /* خوش‌آمدگویی (.nav__user) عمداً از این فهرست مستثنی است — در تبلت
     جا نمی‌شود (متن متغیر + CTA + اینماد ردیف را سرریز می‌کرد). لینکش
     فقط داشبورد است که از منوی اصلی هم قابل دسترسی است. */
  .nav__actions .nav-link:not(.nav__cart):not(.nav__compare):not(.nav__search-toggle):not(.nav__user) {
    display: inline-flex;
  }
  .nav__actions .nav__user { display: none; }
  .nav__search--mobile { display: none; }
  .nav__search-toggle { display: none; }

  /* Shorten search width on tablet so all actions still fit */
  .nav__search input {
    width: 160px;
    font-size: 0.84rem;
  }
  .nav__search input:focus {
    width: 200px;
  }
  .nav__logo {
    font-size: 1.15rem;
    gap: 0.6rem;
  }
  .nav__logo img {
    width: 34px;
    height: 34px;
  }
  .nav__logo .brand-name { font-size: 1.15rem; }
  .nav__cta {
    padding: 6px 16px;
    font-size: 0.82rem;
  }
}

/* Desktop: the mobile search toggle is hidden (search input visible) */
@media (min-width: 1025px) {
  .nav__search-toggle { display: none; }
}
.nav__cart, .nav__compare {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  border-radius: var(--shafa-radius-full);
  background: var(--shafa-icon-btn-bg);
  border: 1px solid var(--shafa-hairline);
  transition:
    background var(--t-base) var(--ease),
    border-color var(--t-base) var(--ease),
    box-shadow var(--t-base) var(--ease),
    transform var(--t-base) var(--ease);
  color: var(--shafa-text-primary);
}
.nav__cart:hover, .nav__compare:hover {
  background: var(--shafa-input-bg-strong);
  border-color: var(--shafa-gold-satin);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(197, 160, 89, 0.16);
}
.nav__cart img { width: 20px; height: 20px; }

.cart-badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 18px; height: 18px;
  border-radius: var(--shafa-radius-full);
  background: var(--shafa-green-alpine);
  color: var(--shafa-on-emerald);
  font-size: 0.7rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--shafa-surface-card);
  box-shadow: 0 2px 6px rgba(22, 43, 33, 0.35);
  padding: 0 4px;
}
.compare-badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 18px; height: 18px;
  border-radius: var(--shafa-radius-full);
  background: var(--shafa-gold-satin);
  color: var(--shafa-on-gold);
  font-size: 0.7rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--shafa-surface-card);
  box-shadow: 0 2px 6px rgba(197, 160, 89, 0.35);
  padding: 0 4px;
}

/* Drawer */
.drawer {
  position: fixed; inset: 0; z-index: var(--z-drawer);
  visibility: hidden; opacity: 0; pointer-events: none;
  transition: opacity var(--t-base) var(--ease), visibility var(--t-base);
}
.drawer.is-open { visibility: visible; opacity: 1; pointer-events: auto; }
.drawer__backdrop { position: absolute; inset: 0; background: rgba(18, 20, 19, 0.45); backdrop-filter: blur(8px); }
.drawer__panel {
  position: absolute; top: 0; right: 0; height: 100%;
  /* min(300px, 85vw) so on a 768px tablet it's ~650px — still wide but
     acceptable with the semi-transparent backdrop. max-width: 400px caps
     it so it never dominates the screen on larger viewports. */
  width: min(300px, 85vw);
  max-width: 400px;
  background: var(--shafa-surface-card); border-inline-start: 1px solid rgba(197, 160, 89, 0.2);
  transform: translateX(100%); transition: transform var(--t-slow) var(--ease);
  display: flex; flex-direction: column;   padding: var(--s-5) max(var(--s-4), env(safe-area-inset-start, 0px)) max(var(--s-4), env(safe-area-inset-end, 0px));
  padding-bottom: calc(var(--s-5) + env(safe-area-inset-bottom, 0px));
  overflow-y: auto;
  box-shadow: -10px 0 30px rgba(0,0,0,0.08);
}
.drawer.is-open .drawer__panel { transform: translateX(0); }
.drawer__item {
  display: flex; align-items: center; gap: .75rem;
  min-height: var(--touch-lg); padding: 12px 14px; border-radius: var(--shafa-radius-md);
  font-weight: 500; color: var(--shafa-text-secondary);
  border-bottom: 1px solid var(--shafa-hairline-soft);
  transition:
    background var(--t-base) var(--ease),
    color var(--t-base) var(--ease),
    font-weight var(--t-base) var(--ease);
}
.drawer__item:hover { color: var(--shafa-text-primary); background: rgba(197, 160, 89, 0.08); }
.drawer__item.is-active { color: var(--shafa-green-alpine); font-weight: 700; background: var(--shafa-emerald-tint-bg); }
.drawer__item img { width: 22px; height: 22px; }
.drawer__close { align-self: flex-end; width: var(--touch); height: var(--touch); display: flex; align-items: center; justify-content: center; color: var(--shafa-text-secondary); border: none; background: transparent; cursor: pointer; }

/* Links */
.nav-link {
  position: relative;
  color: var(--shafa-text-secondary);
  font-weight: 500;
  font-size: 0.95rem;
  padding: 6px 12px;
  border-radius: var(--shafa-radius-full);
  text-decoration: none;
  transition:
    background var(--shafa-duration-base) var(--shafa-ease-natural),
    color var(--shafa-duration-base) var(--shafa-ease-natural),
    font-weight var(--shafa-duration-base) var(--shafa-ease-natural);
}
.nav-link:hover {
  color: var(--shafa-text-primary);
  background: rgba(197, 160, 89, 0.08);
}
.nav-link.is-active {
  color: var(--shafa-emerald-ink);
  font-weight: 700;
  background: var(--shafa-emerald-tint-bg);
}

/* Drawer Footer */
.drawer__footer {
  margin-top: auto;
  border-top: 1px solid rgba(197, 160, 89, 0.18);
  padding-top: var(--shafa-space-md);
}
.drawer__footer .nav__search { margin-bottom: 0; }
.drawer__cta {
  display: block;
  width: 100%;
  margin-top: var(--shafa-space-md);
}

/* ── Scroll padding برای anchor links — جلوگیری از مخفی شدن زیر nav ثابت ──
   ارتفاع nav شامل safe-area-inset-top می‌شود؛ متغیر --nav-height
   در base.css (۷۶۸px) از ۷۲px به ۵۶px تغییر می‌کند. */
html {
  scroll-padding-top: calc(var(--nav-height, 72px) + env(safe-area-inset-top, 0px) + 1rem);
}

/* ── prefers-reduced-motion: nav transitions must be instant ──
   The nav slide-in/out (translateY) and drawer slide should not animate
   for users who opt out of motion. tokens.css already handles this
   globally, but we add an explicit override here so the nav's
   transform/opacity transitions are zero-duration even if a future
   edit forgets to check the media query. */
@media (prefers-reduced-motion: reduce) {
  .nav,
  .nav.is-visible,
  .nav--hidden,
  .nav--filled,
  .drawer,
  .drawer.is-open,
  .drawer__panel {
    transition-duration: 0.001ms !important;
    transition-delay: 0ms !important;
  }
}

/* ── Nav link overflow fallback (medium desktops) ──
   On laptops (1024–1280px) with all 8 links + search + actions present,
   the horizontal nav may overflow. white-space: nowrap keeps links
   on a single line; if they still don't fit, the browser clips them
   rather than wrapping into a broken second row. The drawer remains
   the progressive-disclosure fallback for secondary links. */
.nav__links {
  white-space: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.nav__links::-webkit-scrollbar { display: none; }

/* ============================================================
 *  Enamad Trust Seal
 * ============================================================ */
.nav__enamad {
  display: flex;
  align-items: center;
  margin-inline-end: var(--s-3);
}
.nav__enamad a {
  display: block;
  border-radius: var(--shafa-radius-md);
  overflow: hidden;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.nav__enamad a:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 16px rgba(197, 160, 89, 0.24);
}
.nav__enamad img {
  display: block;
  width: 80px;
  height: 80px;
}

.drawer__enamad {
  padding: var(--s-2);
}
.drawer__enamad a {
  display: inline-block;
  border-radius: var(--shafa-radius-md);
  overflow: hidden;
  transition: transform var(--t-fast) var(--ease);
}
.drawer__enamad a:hover {
  transform: scale(1.03);
}
.drawer__enamad img {
  width: 100px;
  height: 100px;
  margin: 0 auto;
}
.drawer__enamad .text-xs {
  font-size: 0.7rem;
}
.drawer__enamad .text-muted {
  color: var(--shafa-text-tertiary);
}
.drawer__enamad .mt-1 {
  margin-top: var(--s-1);
}
