/* WP homepage topbar mega only — do not load full home-aliexpress.css on Elementor home */
:root {
  --ae-max: 1200px;
  --ae-text: #222;
  --ae-accent: #e43225;
  --ae-muted: #666;
  --ae-z-mega-backdrop: 5990;
  --ae-z-mega-panel: 6005;
}
/* Top bar mega trigger (not using .ae-nav-pill) */
.ae-mega-trigger.ae-mega-trigger--topbar,
a.ae-mega-trigger.ae-mega-trigger--topbar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  color: #fff !important;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.22);
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  box-sizing: border-box;
}

button.ae-mega-trigger.ae-mega-trigger--topbar {
  -webkit-appearance: none;
  appearance: none;
}

/* ---- Mobile topbar: 2 rows (categories + logo + search | tools), no locale ---- */
@media (max-width: 768px) {
  .ae-topbar {
    padding: calc(8px + env(safe-area-inset-top, 0px)) 0 8px;
  }

  .ae-topbar-inner {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    grid-template-rows: auto auto;
    gap: 8px 6px;
    align-items: center;
    padding: 0 10px;
  }

  .ae-topbar-lead {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
  }

  .ae-topbar-lead .ae-mega {
    display: block;
    width: 100%;
    min-width: 0;
  }

  .ae-logo {
    grid-column: 2;
    grid-row: 1;
    font-size: 16px;
  }

  .ae-search {
    grid-column: 1 / -1;
    grid-row: 2;
    min-width: 0;
    max-width: none;
    width: 100%;
    border-radius: 18px;
    border-width: 1px;
  }

  .ae-search .ae-search-field-wrap .ae-search-input-el {
    padding: 6px 34px 6px 10px;
    font-size: 12px;
  }

  .ae-search .ae-search-clear {
    width: 24px;
    height: 24px;
    font-size: 15px;
    right: 4px;
  }

  .ae-search .ae-search-submit {
    width: 36px;
    min-width: 36px;
    background-size: 18px;
  }

  .ae-topbar-tools {
    grid-column: 3;
    grid-row: 1;
    width: auto;
    margin-left: 0;
    justify-content: flex-end;
    gap: 0;
    flex-wrap: nowrap;
    box-sizing: border-box;
  }

  .ae-topbar-tools .ae-app-summary {
    padding: 4px 8px;
    font-size: 10px;
  }

  .ae-account-text {
    max-width: 64px;
  }

  .ae-mega-trigger.ae-mega-trigger--topbar,
  a.ae-mega-trigger.ae-mega-trigger--topbar {
    padding: 4px 6px;
    font-size: 10px;
    gap: 4px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .ae-mega-trigger--topbar .ae-mega-trigger-chev {
    display: none;
  }

  .ae-mega-trigger--topbar .ae-mega-trigger-icon {
    flex-shrink: 0;
  }
}
/* ---- Mega menu (AliExpress-style full-width flyout) ---- */
.ae-mega {
  position: relative;
  display: inline-block;
}

.ae-mega-trigger {
  font-weight: 600;
  gap: 8px;
}

.ae-mega-trigger-chev {
  font-size: 10px;
  opacity: 0.65;
  margin-left: 2px;
  transition: transform 0.15s ease;
}

.ae-mega.is-open .ae-mega-trigger-chev {
  transform: rotate(-180deg);
}

/* Mega 打开时禁止背后页面滚动（与 JS body.ae-mega-open 配套） */
body.ae-mega-open {
  overflow: hidden;
}

/* PDP：All Categories 打开时压低移动采购底栏，避免 z-index:12000 盖住 mega backdrop/panel */
body.ae-mega-open.ae-pdp .pdp-mobile-dock {
  z-index: 5000;
}

.ae-mega-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--ae-z-mega-backdrop, 5990);
  background: rgba(0, 0, 0, 0.35);
  border: none;
  padding: 0;
  margin: 0;
}

.ae-mega-panel {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: var(--ae-z-mega-panel, 6005);
  width: 100%;
  max-width: none;
  min-height: 320px;
  max-height: min(72vh, 560px);
  background: #fff;
  border-radius: 0;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.14);
  border: none;
  border-top: 1px solid #e8e8e8;
  border-bottom: 1px solid #e8e8e8;
  overflow: hidden;
}

/* 打开态：固定在视口、顶缘锚定 sticky 顶栏底部（由 JS 写入 --ae-mega-panel-top） */
.ae-mega.is-open .ae-mega-panel {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--ae-mega-panel-top, 0px);
  z-index: var(--ae-z-mega-panel, 6005);
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - var(--ae-mega-panel-top, 0px) - env(safe-area-inset-bottom, 0px) - 16px);
  max-height: calc(100dvh - var(--ae-mega-panel-top, 0px) - env(safe-area-inset-bottom, 0px) - 16px);
}

.ae-mega.is-open .ae-mega-panel-inner {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
}

.ae-mega-panel-inner {
  display: flex;
  align-items: stretch;
  min-height: 320px;
  max-height: min(72vh, 560px);
  max-width: var(--ae-max);
  margin: 0 auto;
  width: 100%;
  padding: 0 16px;
  box-sizing: border-box;
}

.ae-mega-col--roots {
  flex: 0 0 min(260px, 34vw);
  max-width: 280px;
  border-right: 1px solid #ebebeb;
  background: #f7f7f7;
  overflow-y: auto;
  overflow-x: hidden;
}

.ae-mega-roots {
  list-style: none;
  margin: 0;
  padding: 6px 0 10px;
}

/* 左侧大类与右侧子链共用同一行样式 */
.ae-mega-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  padding: 11px 12px 11px 10px;
  font-size: 13px;
  line-height: 1.25;
  color: var(--ae-text);
  text-decoration: none;
  border: none;
  background: transparent;
  cursor: pointer;
  font-family: inherit;
}

.ae-mega-row-thumb {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 4px;
  background: #e5e7eb;
  flex-shrink: 0;
}

.ae-mega-row-thumb--ph {
  display: inline-block;
  background: linear-gradient(135deg, #e8e8e8 0%, #f0f0f0 100%);
  border: 1px solid #e0e0e0;
}

.ae-mega-row-label {
  flex: 1;
  min-width: 0;
}

.ae-mega-row-chev {
  margin-left: auto;
  font-size: 14px;
  font-weight: 400;
  color: #9ca3af;
  flex-shrink: 0;
}

.ae-mega-row--tab:hover,
.ae-mega-row--tab:focus-visible {
  background: #ececec;
}

.ae-mega-row--tab.is-active {
  background: #fff;
  font-weight: 700;
  box-shadow: inset 3px 0 0 var(--ae-accent);
  color: #111;
}

.ae-mega-row--tab.is-active .ae-mega-row-chev {
  color: var(--ae-accent);
}

.ae-mega-row--link {
  color: #222;
  border-radius: 2px;
}

.ae-mega-row--link:hover,
.ae-mega-row--link:focus-visible {
  background: #ececec;
  color: #111;
  text-decoration: none;
}

.ae-mega-row--link:hover .ae-mega-row-chev,
.ae-mega-row--link:focus-visible .ae-mega-row-chev {
  color: var(--ae-accent);
}

.ae-mega-see-all.ae-mega-row--link {
  font-weight: 700;
}

/* 右侧：与 AliExpress 类似，白底多列子类目（一级仅在左侧） */
.ae-mega-col--detail {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 14px 12px 14px 24px;
  background: #fff;
  border-left: 1px solid #ebebeb;
}

.ae-mega-detail--hidden {
  display: none !important;
}

.ae-mega-detail-head {
  flex-shrink: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
  margin-bottom: 14px;
}

.ae-mega-detail-grid {
  display: grid;
  grid-template-columns: 1fr minmax(132px, 168px);
  gap: 20px 24px;
  align-items: start;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding-right: 4px;
}

/* 子类目：多列栅格，每列一组竖排链接（对标 AliExpress 右侧） */
.ae-mega-groups-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px 28px;
  align-items: start;
  min-width: 0;
}

@media (max-width: 1100px) {
  .ae-mega-groups-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .ae-mega-groups-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.ae-mega-group {
  margin: 0;
  padding: 0;
  min-width: 0;
}

.ae-mega-group-title {
  font-size: 13px;
  font-weight: 600;
  color: #111;
  margin: 0 0 8px;
  padding: 0 4px;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.3;
  min-height: 2.6em;
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 8px;
  margin-bottom: 10px;
}

.ae-mega-links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: block;
}

.ae-mega-links li {
  margin: 0;
  padding: 0;
  list-style: none;
}

.ae-mega-sublink {
  display: block;
  font-size: 13px;
  color: #333;
  text-decoration: none;
  padding: 5px 4px;
  margin: 0;
  line-height: 1.4;
  border-radius: 2px;
}

.ae-mega-sublink:hover,
.ae-mega-sublink:focus-visible {
  color: var(--ae-accent);
  background: #fff5f5;
}

/* 默认（full）模式：子类缩略图 + 名称同行，右侧不再单独展示 promo 大图 */
.ae-mega:not(.ae-mega--storefront) .ae-mega-sublink--row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
}

/* 窄屏保持较小缩略图，避免抽屉里一行过高 */
.ae-mega:not(.ae-mega--storefront) .ae-mega-sublink-thumbwrap {
  flex: 0 0 44px;
  width: 44px;
  height: 44px;
  border-radius: 6px;
  overflow: hidden;
  background: #f3f4f6;
  border: 1px solid #ebebeb;
}

@media (min-width: 769px) {
  /* 与 ae-mega--storefront 瓷砖 ae-mega-tile-img-wrap（76×76）同尺寸，电脑端与首页子类图一致 */
  .ae-mega:not(.ae-mega--storefront) .ae-mega-sublink--row {
    gap: 12px;
    padding: 8px 6px;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-sublink-thumbwrap {
    flex: 0 0 76px;
    width: 76px;
    height: 76px;
    border-radius: 8px;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-sublink-txt {
    font-size: 14px;
  }
}

.ae-mega:not(.ae-mega--storefront) .ae-mega-sublink-thumbwrap--ph {
  border-style: dashed;
  opacity: 0.65;
}

.ae-mega:not(.ae-mega--storefront) .ae-mega-sublink-thumb {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  vertical-align: middle;
}

.ae-mega:not(.ae-mega--storefront) .ae-mega-sublink-txt {
  flex: 1;
  min-width: 0;
  font-weight: 500;
}

.ae-mega:not(.ae-mega--storefront) .ae-mega-promo {
  display: none;
}

.ae-mega:not(.ae-mega--storefront) .ae-mega-detail-grid {
  grid-template-columns: 1fr;
}

.ae-mega-promo-card {
  display: block;
  text-decoration: none;
  color: inherit;
  border-radius: var(--ae-radius);
  overflow: hidden;
  border: 1px solid #ebebeb;
  background: #fafafa;
}

.ae-mega-promo-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
}

.ae-mega-promo-cap {
  display: block;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  color: #333;
}

.ae-mega-close {
  position: absolute;
  top: 10px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: none;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 8px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: #374151;
  z-index: 2;
}

.ae-mega-close:hover {
  background: rgba(0, 0, 0, 0.1);
}

/* Storefront mega（详情页镜像 WP 主页）：横向标签 + 小图卡片类目 */
.ae-mega--storefront .ae-mega-panel-inner {
  flex-direction: column;
  max-height: min(78vh, 640px);
}

.ae-mega--storefront .ae-mega-col--roots {
  flex: none;
  width: 100%;
  max-width: none;
  border-right: none;
  border-bottom: 1px solid #ebebeb;
  background: #fff;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.ae-mega--storefront .ae-mega-roots {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: 6px;
  padding: 10px 8px 12px;
}

.ae-mega--storefront .ae-mega-roots li {
  flex: 0 0 auto;
}

.ae-mega--storefront .ae-mega-col--roots .ae-mega-row-thumb,
.ae-mega--storefront .ae-mega-col--roots .ae-mega-row-thumb--ph {
  display: none !important;
}

.ae-mega--storefront .ae-mega-col--roots .ae-mega-row {
  padding: 10px 14px;
  white-space: nowrap;
  border-radius: 8px;
}

.ae-mega--storefront .ae-mega-col--roots .ae-mega-row-chev {
  display: none;
}

.ae-mega--storefront .ae-mega-row--tab.is-active {
  background: rgba(237, 28, 36, 0.08);
  font-weight: 700;
  color: var(--ae-accent);
  box-shadow: inset 0 -3px 0 var(--ae-accent);
}

.ae-mega--storefront .ae-mega-col--detail {
  border-left: none;
  flex: 1;
  min-height: 0;
}

.ae-mega--storefront .ae-mega-detail-head {
  border-bottom: none;
  margin-bottom: 8px;
  padding-bottom: 0;
}

.ae-mega--storefront .ae-mega-detail-grid {
  grid-template-columns: 1fr;
}

.ae-mega--storefront .ae-mega-promo {
  display: none;
}

.ae-mega--storefront .ae-mega-groups-grid {
  display: block;
}

.ae-mega--storefront .ae-mega-group {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
  align-items: start;
}

.ae-mega--storefront .ae-mega-links--tiles {
  display: contents;
  margin: 0;
  padding: 0;
}

.ae-mega--storefront .ae-mega-links--tiles li {
  display: contents;
}

.ae-mega--storefront .ae-mega-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  text-decoration: none;
  color: #222;
  border-radius: 10px;
  padding: 10px 6px;
  border: 1px solid #ececec;
  background: #fafafa;
  min-height: 118px;
  box-sizing: border-box;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ae-mega--storefront .ae-mega-tile:hover,
.ae-mega--storefront .ae-mega-tile:focus-visible {
  border-color: var(--ae-accent);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
  color: var(--ae-accent);
  outline: none;
}

.ae-mega--storefront .ae-mega-tile-img-wrap {
  width: 76px;
  height: 76px;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 8px;
  background: #e8e8e8;
  flex-shrink: 0;
}

.ae-mega--storefront .ae-mega-tile-img-wrap--ph {
  background: linear-gradient(135deg, #e8e8e8 0%, #f2f2f2 100%);
}

.ae-mega--storefront .ae-mega-tile-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ae-mega--storefront .ae-mega-tile-cap {
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  line-height: 1.25;
  max-width: 100%;
}

@media (max-width: 768px) {
  /* storefront：保持原有移动端行为 */
  .ae-mega--storefront .ae-mega-panel-inner {
    max-height: min(82vh, 620px);
  }

  .ae-mega--storefront .ae-mega-col--roots {
    max-height: none;
    border-bottom: 1px solid #ebebeb;
  }

  .ae-mega--storefront .ae-mega-col--detail {
    border-top: none;
    padding-left: 4px;
    padding-right: 4px;
  }

  .ae-mega--storefront .ae-mega-group {
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  }

  /* full（默认 PDP）：与首页 Mega V2 — 左侧根类 + 右侧 3 列卡片网格 */
  .ae-mega:not(.ae-mega--storefront).is-open .ae-mega-panel {
    left: 8px;
    right: 8px;
    bottom: 8px;
    max-height: calc(100vh - var(--ae-mega-panel-top, 0px) - env(safe-area-inset-bottom, 0px) - 16px);
    max-height: calc(100dvh - var(--ae-mega-panel-top, 0px) - env(safe-area-inset-bottom, 0px) - 16px);
    border-radius: 10px;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-panel-inner {
    flex-direction: row;
    align-items: stretch;
    padding: 0;
    max-height: none;
    min-height: 0;
  }

  .ae-mega:not(.ae-mega--storefront).is-open .ae-mega-panel-inner {
    flex: 1 1 auto;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-col--roots {
    flex: 0 0 102px;
    width: 102px;
    max-width: 102px;
    max-height: none;
    min-height: 0;
    border-right: 1px solid #ebebeb;
    border-bottom: none;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-col--roots .ae-mega-row {
    padding: 9px 6px;
    font-size: 12px;
    line-height: 1.25;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-col--roots .ae-mega-row-thumb,
  .ae-mega:not(.ae-mega--storefront) .ae-mega-col--roots .ae-mega-row-thumb--ph,
  .ae-mega:not(.ae-mega--storefront) .ae-mega-col--roots .ae-mega-row-chev {
    display: none !important;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-col--roots .ae-mega-row-label {
    flex: 1;
    min-width: 0;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-col--detail {
    flex: 1;
    min-width: 0;
    min-height: 0;
    border-left: none;
    border-top: none;
    padding: 8px 8px 10px;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-detail-head {
    display: none;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-promo {
    display: none;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-detail-grid {
    display: flex;
    flex-direction: column;
    grid-template-columns: unset;
    gap: 0;
    overflow: visible;
    padding-right: 0;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-groups-grid {
    display: block;
    grid-template-columns: unset;
    min-width: 0;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-group {
    margin-bottom: 12px;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-group:last-child {
    margin-bottom: 0;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-group-title {
    font-size: 12px;
    min-height: 0;
    padding: 0 2px 6px;
    margin-bottom: 8px;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-links {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-sublink--row {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0;
    margin: 0;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    overflow: hidden;
    background: #fff;
    color: #0f172a;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-sublink--row:hover,
  .ae-mega:not(.ae-mega--storefront) .ae-mega-sublink--row:focus-visible {
    border-color: var(--ae-accent);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    color: inherit;
    background: #fff;
    outline: none;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-sublink-thumbwrap {
    flex: 0 0 auto;
    width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    border-radius: 0;
    border: none;
    background: #e8eaed;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-sublink-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
  }

  .ae-mega:not(.ae-mega--storefront) .ae-mega-sublink-txt {
    flex: none;
    padding: 5px 5px 6px;
    font-size: 11px;
    line-height: 1.2;
    font-weight: 600;
    text-align: center;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  @media (max-width: 360px) {
    .ae-mega:not(.ae-mega--storefront) .ae-mega-links {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
  }

  .ae-mega.is-open .ae-mega-panel-inner {
    max-height: none;
  }

  .ae-mega-close {
    right: 12px;
  }
}
