/* =========================================================
   MEGA MENU (FINAL - Alpine Controlled) — Optimised
   Goals:
   1) Logo ↔ Title group closer (controlled by --logo-nav-gap)
   2) As screen shrinks: NO WRAP; instead reduce font-size, gaps, paddings
   ========================================================= */

/* Alpine */
[x-cloak] { display: none !important; }

/* =========================================================
   0) VARIABLES (✅ 主要在这里控制间距/缩放)
   ========================================================= */
:root {
  /* header height (dropdown fixed top uses this) */
  --header-h: 12rem;

  /* ✅ A) 控制 “logo 和右边 title/menu 组”的距离（越小越贴近） */
  --logo-nav-gap: 30px;

  /* ✅ B) 控制 header 左右内边距（桌面） */
  --header-pad-x: clamp(16px, 2.2vw, 44px);

  /* ✅ C) nav item 的字体/间距/左右 padding（桌面基础） */
  --nav-font-size: 16px;
  --nav-item-gap: 4px;          /* 每个一级类目之间的 gap */
  --nav-item-pad-x: 10px;       /* 每个一级 title 的左右 padding */

  /* ✅ D) 右侧 actions（Hair Loss + Button）之间的 gap */
  --actions-gap: 16px;
}

@media (max-width: 760px) {
  :root { --header-h: 72px; }
}

/* =========================================================
   1) STICKY / LAYERING / OVERFLOW
   ========================================================= */
.header {
  position: sticky;
  top: 0;
  z-index: 2000;

  /* ✅ 用变量统一控制 header 左右距离 */
  padding-left: var(--header-pad-x) !important;
  padding-right: var(--header-pad-x) !important;
}

.header,
.pageHeaderNav__nav,
.header__nav {
  overflow: visible !important;
}

/* =========================================================
   2) IMPORTANT LAYOUT OVERRIDES (fix huge gap issue)
   - 很多项目里 .flex class 可能自带 justify-content: space-between
   - ✅ 这里强制 header 内部为 flex-start，避免 logo 和 nav 被拉开
   ========================================================= */
header.header.gutter {
  width: 100% !important;
}

/* inner wrapper full width */
header.header > .flex {
  max-width: 100%;
  margin: 0;

  display: flex;
  align-items: center;

  /* ✅ 关键：不要 space-between，避免中间出现巨大空带 */
  justify-content: space-between;

  /* ✅ logo 和 nav 的距离在这里控制 */
  gap: var(--logo-nav-gap);
}

/* logo never shrink */
.header__logo {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
}

/* =========================================================
   3) DESKTOP NAV ITEM ALIGNMENT + NO WRAP
   ========================================================= */
@media (min-width: 761px) {

  /* nav container */
  .header__nav {
    display: flex;
    align-items: center;

    /* ✅ 让 nav 占据剩余空间 */
    flex: 1 1 auto;
    min-width: 0;

    /* ✅ 不换行 */
    flex-wrap: nowrap;
    white-space: nowrap;

    /* ✅ 控制一级类目之间距离 */
    gap: var(--nav-item-gap);
  }

  /* li 作为 flex item（因为你 nav 里直接放 li） */
  .header__nav .dropdown.headerBar__item {
    flex: 0 0 auto;
    list-style: none;
  }

  /* unify all nav links */
  .header__nav .headerBar__link,
  .header__nav .header__link,
  .header__nav .dropdown__title {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    height: 56px;
    line-height: 56px;

    /* ✅ 不换行 */
    white-space: nowrap;

    /* ✅ 字体缩放由变量控制 */
    font-size: var(--nav-font-size);

    /* ✅ 每个 title 左右 padding（更小=更紧凑） */
    padding: 0 var(--nav-item-pad-x);

    vertical-align: middle;
  }

  /* 你之前单独写的 title padding override（保留但由变量统一） */
  .header__nav .dropdown__title.headerBar__link{
    padding-left: var(--nav-item-pad-x) !important;
    padding-right: var(--nav-item-pad-x) !important;
  }

  /* right actions pinned to right */
  .header__actions--right{
    margin-left: auto;
    display:flex;
    align-items:center;

    /* ✅ Hair Loss 和按钮距离 */
    gap: var(--actions-gap);

    white-space: nowrap;
    flex: 0 0 auto;
  }
}

/* =========================================================
   4) DESKTOP DROPDOWN PANEL (FIXED TOP + FULL WIDTH)
   ========================================================= */
@media (min-width: 761px) {

  .header__nav { position: static; }

  .header__nav .dropdown.headerBar__item { position: relative; }

  .header__nav .dropdown.headerBar__item > a,
  .header__nav .dropdown.headerBar__item > .dropdown__title {
    padding-bottom: 0;
  }

  .header__nav .dropdown__menu {
    position: fixed;
    left: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;

    top: var(--header-h);
    transform: none;
    margin: 0;

    z-index: 2100;

    background: #fffef2 !important;
    color: #2f2d29;
    border-top: 1px solid rgba(47,45,41,.14);
    box-shadow: 0 10px 24px rgba(0,0,0,.08);

    /* x-show controls visibility */
    display: grid;
    grid-template-columns: repeat(3, minmax(220px, 1fr));
    column-gap: 64px;
    row-gap: 28px;

    padding: 28px 0;
    padding-left: max(24px, calc((100vw - 1200px) / 2));
    padding-right: max(24px, calc((100vw - 1200px) / 2));

    pointer-events: auto;
  }
}

/* =========================================================
   5) DESKTOP GROUP TYPOGRAPHY
   ========================================================= */
@media (min-width: 761px) {

  .header__nav .dropdown__menu ul {
    background: transparent !important;
  }

  .header__nav .dropdown__menu .menuGroup {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: transparent !important;
  }

  .header__nav .dropdown__menu .menuGroupTitle {
    font-family: "Optima","URW Classico","Segoe UI",serif;
    font-weight: 700;
    font-size: 22px;
    line-height: 1.2;
    margin: 0 0 14px;
    color: #2f2d29;
  }

  .header__nav .dropdown__menu .menuGroup > a {
    font-family: "Suisse Int'l","Suisse Intl","Inter",-apple-system,
                 BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
    font-weight: 400;
    font-size: 16px;
    line-height: 1.35;
    color: #2f2d29;

    text-decoration: none;
    display: block;
    margin: 0 0 12px;

    transition: color .18s ease, opacity .18s ease;
  }

  .header__nav .dropdown__menu .menuGroup > a:hover { color: #1888a3; }
  .header__nav .dropdown__menu .menuGroup > a.active { font-weight: 600; }
}

/* =========================================================
   6) DESKTOP HEADER COLOR REVERSE ON MENU OPEN
   ========================================================= */
@media (min-width: 761px) {

  .header {
    background: #2f2d29;
    transition: background .28s ease;
  }

  .header__nav .headerBar__link,
  .header__nav .dropdown__title {
    color: #fffef2;
    transition: color .28s ease, opacity .28s ease;
  }

  .header__nav .headerBar__link:hover,
  .header__nav .dropdown__title:hover {
    opacity: .85;
  }

  /* hover (modern) */
  .header:has(.dropdown.headerBar__item:hover) {
    background: #fffef2;
  }
  .header:has(.dropdown.headerBar__item:hover) .headerBar__link,
  .header:has(.dropdown.headerBar__item:hover) .dropdown__title {
    color: #2f2d29;
  }

  /* open state fallback */
  .header:has(.dropdown__menu--active) {
    background: #fffef2;
  }
  .header:has(.dropdown__menu--active) .headerBar__link,
  .header:has(.dropdown__menu--active) .dropdown__title {
    color: #2f2d29;
  }
}

/* =========================================================
   7) DESKTOP UNDERLINE (PER ITEM ONLY)
   ========================================================= */
@media (min-width: 761px) {

  .header__nav .headerBar__link { position: relative; }

  .header__nav .headerBar__link::after {
    content: "";
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: 10px;
    height: 2px;
    background: #2f2d29;

    transform: scaleX(0);
    transform-origin: center;
    transition: transform .28s ease;
  }

  .header__nav .headerBar__link:hover::after,
  .header__nav .headerBar__link.active::after {
    transform: scaleX(1);
  }
}

/* =========================================================
   8) RESPONSIVE SHRINK (✅ 关键：变小不换行，改为缩字/缩 gap/缩 padding)
   - 只在桌面导航还显示的区间生效（>1300px，因为你 1300 以下会隐藏 nav）
   ========================================================= */

/* 1600 -> 1401: 轻微收紧 */
@media (max-width: 1600px) and (min-width: 1401px) {
  :root{
    --header-pad-x: clamp(14px, 1.8vw, 36px);
    --logo-nav-gap: 14px;
    --nav-font-size: 15px;
    --nav-item-gap: 6px;
    --nav-item-pad-x: 8px;
    --actions-gap: 14px;
  }
}

/* 1400 -> 1301: 明显收紧（保持不换行） */
@media (max-width: 1400px) and (min-width: 1301px) {
  :root{
    --header-pad-x: clamp(12px, 1.5vw, 28px);
    --logo-nav-gap: 10px;
    --nav-font-size: 14px;
    --nav-item-gap: 4px;
    --nav-item-pad-x: 6px;
    --actions-gap: 12px;
  }

  /* 进一步避免挤压导致换行 */
  .header__nav .headerBar__link,
  .header__nav .dropdown__title {
    height: 52px;
    line-height: 52px;
  }
}

/* =========================================================
   9) MOBILE MENU STYLES (<= 760px)
   ========================================================= */
@media (max-width: 760px) {

  .menu .mega__trigger.headerBar__link {
    font-size: 22px !important;
    font-weight: 500 !important;
    line-height: 1.2 !important;
    padding: 18px 0 !important;
    text-align: center;
  }

  .menu .mega__heading {
    font-family: "Optima","URW Classico","Segoe UI",serif !important;
    font-size: 1.6rem !important;
    font-weight: 600 !important;
    line-height: 1.25 !important;
    margin: 14px 0 8px !important;
    text-align: center;
  }

  .menu .mega__link {
    font-family: "Suisse Int'l","Suisse Intl","Inter",-apple-system,
                 BlinkMacSystemFont,"Segoe UI",Roboto,Helvetica,Arial,sans-serif !important;
    font-size: 1.6rem !important;
    font-weight: 400 !important;
    line-height: 1.35 !important;

    display: block;
    text-align: center;

    padding: 16px 0 !important;
    margin: 0 !important;
    border-top: 1px solid rgba(0,0,0,.06) !important;

    transition: .18s ease;
  }

  .menu .mega__link:hover { color: #1888a3; }
  .menu .mega__link.is-active { font-weight: 300 !important; }
  .menu .mega__group--all { display: none !important; }

  .menu .menu__list > a {
    font-family: inherit !important;
    font-size: 22px !important;
    font-weight: 500 !important;
    line-height: 1.2 !important;

    display: block;
    text-align: center;
    padding: 18px 0 !important;

    border-top: 1px solid rgba(0,0,0,.06);
  }
}

/* =========================================================
   10) EARLY MOBILE MENU BREAKPOINT (collapse earlier)
   ========================================================= */
@media (max-width: 1300px) {

  .header__nav { display: none !important; }

  .menu__toggle {
    display: inline-flex !important;
    align-items: center;
  }
}

