/* ============================================================
   هدر پریمیوم — چسبان، شیشه‌ای (glassmorphism)، با جزئیات دقیق
   🧑‍🏫 نام کلاس‌ها همان قالب base.html توست؛ فقط ظاهر ارتقا یافته.
   ============================================================ */

header {
  position: relative;
  top: 0;
  z-index: 1000;
  background: var(--glass-bg);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  border-bottom: 1px solid var(--glass-border);
  box-shadow: var(--shadow-sm);
}

/* نوار اعلان بالا (announcement bar) */
.top-banner {
  background: var(--gradient-dark);
  overflow: hidden;
}
.top-banner img {
  width: 100%;
  display: block;
  max-height: 85px;
  object-fit: cover;
  opacity: 0.95;
}

/* هدر میانی */
.middle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 14px 20px;
}
.right-box {
  display: flex;
  align-items: center;
  gap: 24px;
  flex: 1;
}
.logo img {
  height: 54px;
  width: auto;
  display: block;
  transition: transform var(--t) var(--ease-spring);
}
.logo:hover img {
  transform: scale(1.04);
}
/* 🧑‍🏫 وقتی کاربر لاگین کرده، توی نوبار موبایل دکمه‌های بیشتری
   (پروفایل/سبد/خروج) هست و لوگوی فعلی کنارشون فشرده/زشت می‌شه؛
   برای همین یه لوگوی جمع‌وجورتر جایگزینش می‌کنیم — فقط در موبایل. */
.logo img.logo-img-compact {
  display: none;
}
@media (max-width: 900px) {
  .logo.has-alt-logo .logo-img-default {
    display: none;
  }
  .logo.has-alt-logo .logo-img-compact {
    display: block;
    height: 40px;
    width: auto;
  }
}

/* جستجوی مرکزی */
.middle-section {
  flex: 1;
  max-width: 580px;
}
.middle-section form {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-full);
  overflow: hidden;
  transition:
    border-color var(--t) var(--ease),
    box-shadow var(--t) var(--ease);
}
.middle-section form:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-light);
}
.search-bar {
  flex: 1;
  border: none;
  background: transparent;
  padding: 12px 18px;
  font-size: 0.95rem;
  outline: none;
  font-family: inherit;
  color: var(--text);
}
.search-bar::placeholder {
  color: var(--text-muted);
}
.search-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 0 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: color var(--t-fast) var(--ease);
}
.search-btn:hover {
  color: var(--brand);
}

/* بخش چپ: ورود/پروفایل و سبد */
.left-box {
  display: flex;
  align-items: center;
  gap: 10px;
  white-space: nowrap;
}
.partner-panel-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 11px 20px;
  border-radius: var(--radius-full, 999px);
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #fff;
  font-weight: 800;
  font-size: 0.92rem;
  text-decoration: none;
  box-shadow: 0 6px 18px rgba(217, 119, 6, 0.35);
  transition: transform var(--t-fast, 0.15s) var(--ease-spring, ease), box-shadow var(--t, 0.2s) ease;
}
.partner-panel-btn:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 10px 24px rgba(217, 119, 6, 0.45);
}
.btn-login {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  color: var(--text);
  text-decoration: none;
  background: var(--surface);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all var(--t) var(--ease);
}
.btn-login:hover {
  border-color: var(--brand);
  color: var(--brand);
  transform: translateY(-1px);
}
.divider {
  width: 1px;
  height: 30px;
  background: var(--border);
}

.header-icon {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  transition: all var(--t) var(--ease);
}
.header-icon:hover {
  border-color: var(--brand);
  color: var(--brand);
  transform: translateY(-1px);
}
#cart-count {
  position: absolute;
  top: -8px;
  left: -8px;
  background: var(--gradient-brand);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  min-width: 20px;
  height: 20px;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  box-shadow: var(--shadow-brand);
}

/* نوار پایینی ناوبری */
.bottom-header {
  border-top: 1px solid var(--border);
}
.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  list-style: none;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 6px 20px;
  height: 50px;
}
.nav-links > li > a,
.nav-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  color: var(--text-soft);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: all var(--t) var(--ease);
}
.nav-links > li > a:hover,
.nav-link:hover {
  background: var(--brand-light);
  color: var(--brand);
}

/* دکمهٔ دسته‌بندی (متمایز با گرادیان) */
.category-dropdown > .nav-link {
  background: var(--gradient-brand);
  color: #fff;
  font-weight: 700;
  box-shadow: var(--shadow-brand);
}
.category-dropdown > .nav-link:hover {
  background-color: var(--brand-light);
  color: #0716a0;
  transform: translateY(-1px);
}

/* مگامنو (شیشه‌ای، با انیمیشن ورود) */
.category-dropdown {
  position: relative;
}
.mega-menu {
  position: absolute;
  top: calc(100% + 2px);
  right: 0;
  width: 780px;
  max-width: 92vw;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: none;
  grid-template-columns: 230px 1fr;
  overflow: hidden;
  z-index: 200;
}
.mega-menu.open {
  display: grid;
  animation: fadeUp 0.3s var(--ease-out);
}
.main-categories {
  background: var(--bg-soft);
  list-style: none;
  padding: 10px 0;
  margin: 0;
}
.main-categories .category-item {
  padding: 12px 20px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  transition: all var(--t-fast) var(--ease);
  position: relative;
}
.main-categories .category-item:hover,
.main-categories .category-item.active {
  background: var(--surface);
  color: var(--brand);
}
.main-categories .category-item.active::before {
  content: "";
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--gradient-brand);
}
.sub-categories-container {
  padding: 22px;
}
.sub-content {
  display: none;
}
.sub-content.active {
  display: block;
  animation: fadeIn var(--t) var(--ease);
}
.sub-column h4 {
  margin-bottom: 14px;
  font-size: 0.95rem;
}
.sub-column h4 a {
  color: var(--brand);
  text-decoration: none;
}
.sub-column ul {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.sub-column ul li a {
  color: var(--text-soft);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color var(--t-fast);
}
.sub-column ul li a:hover {
  color: var(--brand);
}

/* پیام‌های سیستمی (alert) */
.alert {
  padding: 13px 20px;
  margin-bottom: 10px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  animation: fadeUp var(--t) var(--ease-out);
}
.alert-success {
  background: var(--success-light);
  color: #047857;
}
.alert-error,
.alert-danger {
  background: #fef2f2;
  color: #b91c1c;
}
.alert-info {
  background: var(--accent-light);
  color: #1d4ed8;
}
.alert-warning {
  background: #fffbeb;
  color: #b45309;
}

.mobile-nav-toggle {
  display: none;
}
/* واکنش‌گرا */

@media (max-width: 900px) {

  /* ========================= Header ========================= */
  .middle-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 12px;
  } /* ========================= Logo ========================= */
  .logo {
    order: 1;
    flex: 1;
    min-width: 0;
  }
  .logo img {
    display: block;
    width: 150px;
    height: auto;
    transition: transform var(--t) var(--ease-spring);
  } /* ========================= Header Buttons ========================= */
  .right-box {
    display: contents;
  }
  .left-box {
    order: 2;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 7px;
    margin: 0;
    flex: 0 0 auto;
    white-space: nowrap;
  }
  .btn-login {
    padding: 7px 10px;
    font-size: 0.78rem;
    gap: 4px;
  }
  .partner-panel-btn {
    padding: 7px 12px;
    font-size: 0.76rem;
  }
  .header-icon {
    width: 38px;
    height: 38px;
  }
  .divider {
    height: 20px;
  } /* ========================= Search + Hamburger ========================= */
  .middle-section {
    order: 3;
    flex: 0 0 100%;
    width: 100%;
    max-width: none;
    display: flex;
    align-items: center;
    gap: 8px;
  } /* Search */
  .middle-section .search-box {
    flex: 1;
    min-width: 0;
  } /* Hamburger */
  .hamburger-menu {
    flex: 0 0 42px;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
  } /* ========================= Mega Menu ========================= */
  .mega-menu,
  .mega-menu.cascade {
    width: 100%;
    max-width: 100%;
    grid-template-columns: 1fr;
    grid-auto-flow: row;
  }
  .cascade-col-2,
  .cascade-col-3,
  .cascade-col-4 {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 600px) {
  .logo img {
    height: 42px;
    width: auto;
    max-width: 140px;
    display: block;
    transition: transform var(--t) var(--ease-spring);
  }
  .mobile-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
  }
  .nav-links {
    display: none;
    flex-direction: column;
    align-items: stretch;
    height: auto;
    position: absolute;
    top: 100%;
    right: 0;
    left: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    padding: 8px 20px;
    z-index: 500;
  }
  .nav-links.open {
    display: flex;
  }
  .bottom-header {
    position: relative;
  }
  .top-banner{
    display: none;
  }

  /* 🧑‍🏫 مگامنو در موبایل: فقط دسته‌های اصلی (ستون ۱) به‌صورت یه لیست
     ساده باز می‌شه؛ ستون‌های ۲ تا ۴ (پنل‌های زیردسته که کنارش باز
     می‌شدن) کاملاً مخفی‌ان — چون روی موبایل جا نداره و باعث می‌شد
     صفحه به‌هم‌بریزه. با تپ روی هر دسته‌ی اصلی هم مستقیم به همون
     صفحهٔ دسته می‌ره (چون خودش لینکه). */
  .mega-menu.cascade {
    position: static;
    width: 100%;
    max-width: 100%;
    grid-template-columns: 1fr;
    grid-auto-flow: row;
    box-shadow: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-top: 6px;
  }
  .cascade-col-2,
  .cascade-col-3,
  .cascade-col-4 {
    display: none !important;
  }
  .cascade-item .caret {
    display: none; /* روی موبایل زیرمنویی باز نمی‌شه، پس این فلش گمراه‌کننده‌ست */
  }
}

/* ===== مگامنوی آبشاری ۴ سطحی ===== */
.mega-menu.cascade {
  display: none;
  /* 🧑‍🏫 این none حیاتیه: بدون این، مقدار grid-template-columns:230px 1fr
     که روی خودِ .mega-menu (قانون پایه) تعریف شده هنوز فعاله و
     مگامنو رو به ۲ ستون ثابت محدود می‌کنه، حتی با grid-auto-flow. */
  grid-template-columns: none;
  grid-auto-flow: column;
  grid-auto-columns: 240px;
  width: auto;
  min-width: 200px;
  max-width: 92vw;
}
.mega-menu.cascade.open {
  display: grid;
}

.cascade-col {
  border-left: 1px solid var(--border);
  padding: 8px 0;
  min-height: 100%;
  margin-bottom: 0;
}
.cascade-col:last-child {
  border-left: none;
}
.cascade-col-1 {
  background: var(--bg-soft);
  list-style: none;
  margin: 0;
}

/* پنل‌های ستون ۲ تا ۴ پیش‌فرض پنهان */
.cascade-col-2,
.cascade-col-3,
.cascade-col-4 {
  display: none;
}
.cascade-col-2.show,
.cascade-col-3.show,
.cascade-col-4.show {
  display: block;
}
.cascade-panel {
  display: none;
  list-style: none;
  margin: 0;
  padding: 0;
}
.cascade-panel.show {
  display: block;
}

.cascade-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  cursor: pointer;
  transition:
    0.15s,
    color 0.15s;
}
.cascade-item > a {
  text-decoration: none;
  color: var(--text-soft);
  font-size: 0.86rem;
  flex: 1;
}
.cascade-item:hover {
  background: var(--surface);
}
.cascade-item:hover > a,
.cascade-item.active > a {
  color: var(--brand);
  font-weight: 700;
}
.cascade-item .caret {
  color: var(--text-muted);
  font-size: 0.9rem;
}
.cascade-col-1 .cascade-item.active {
  background: var(--surface);
}

/* پل نامرئی بین دکمه و منو تا ماوس موقع عبور «بیرون» حساب نشود */
.category-dropdown .mega-menu::before {
  content: "";
  position: absolute;
  top: -12px; /* به اندازهٔ همان فاصله، رو به بالا کشیده می‌شود */
  right: 0;
  left: 0;
  height: 12px;
  background: transparent;
}


/* 🧑‍🏫 روی موبایل، دکمهٔ «پنل همکاران» از نوار بالا برداشته می‌شه (تا لوگو
   و بقیهٔ دکمه‌ها فشرده/بی‌کیفیت نشن) و به‌جاش داخل منوی همبرگری
   (لیست nav-links پایین هدر) به‌صورت یک آیتم کامل نمایش داده می‌شه. */
.mobile-only-link {
  display: none;
}
@media (max-width: 600px) {
  .partner-panel-btn {
    display: none;
  }
  .mobile-only-link {
    display: flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff !important;
    border-radius: var(--radius-sm);
    margin: 4px 0;
    font-weight: 700;
  }
  .mobile-only-link:hover {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #fff;
  }
}
