/* ============================================================
   Header — 对齐 vivo.com.cn：顶部工具条 + 白底单行极简导航
   工具条：品牌 / OriginOS / 体验店 / 官网社区 + 下载APP / 购物车 / 个人中心
   主导航：纯黑 vivo 字标 + 系列菜单 + 圆形搜索图标 + 购物车图标
   设计令牌来自 common.css（加载于本文件之前）
   ============================================================ */

/* 让 .main-nav 的 sticky 参照 body 而非 <header>：
   <header> 仅 108px 高，sticky 会被父容器限制、随 header 一起滚出视口；
   display:contents 后 header 不生成盒子，导航在 topbar 滚离后吸附视口顶部，
   回滚到顶部时自动归位到 topbar 下方，无需 JS 占位 */
body > header { display: contents; }

/* ---------- 顶部工具条（桌面端，滚动即离开视口）
   对齐 vivo 官网 .vp-head-topbar-pc：深色 #242933，高 40px，层级 1002 ---------- */
.vivo-topbar {
    position: relative;
    z-index: 1002;
    height: var(--topbar-h);
    background: #242933;
    font-size: 0;
}
.vivo-topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--topbar-h);
}
.vivo-topbar-navs {
    display: flex;
    align-items: center;
    gap: 28px;
}
.vivo-topbar-navs a {
    font-size: 12px;
    color: rgba(255, 255, 255, .62);
    line-height: var(--topbar-h);
    transition: color var(--fast);
}
.vivo-topbar-navs a:hover { color: #fff; }
.vivo-topbar-user {
    display: flex;
    align-items: center;
    gap: 20px;
}
.vivo-topbar-sep {
    width: 1px;
    height: 12px;
    background: rgba(255, 255, 255, .18);
}
.vivo-topbar-user a {
    font-size: 12px;
    color: rgba(255, 255, 255, .62);
    line-height: var(--topbar-h);
    transition: color var(--fast);
}
.vivo-topbar-user a:hover { color: #fff; }

/* 下载APP：悬停展示二维码（对齐 vivo .vp-vivo-app-qrCode） */
.vivo-topbar-app {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.vivo-topbar-ico { flex-shrink: 0; }
.vivo-topbar-app:hover .vivo-topbar-pop,
.vivo-topbar-app:focus-within .vivo-topbar-pop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* 浮层基础：白色圆角卡 + 顶部小三角 + 轻投影 */
.vivo-topbar-pop {
    position: absolute;
    top: calc(100% + 12px);
    right: -10px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, .14);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .18s ease, visibility .18s ease;
    z-index: 1003;
}
.vivo-pop-arrow {
    position: absolute;
    top: -5px;
    left: 50%;
    margin-left: -5px;
    width: 10px;
    height: 10px;
    background: #fff;
    border-radius: 2px;
    transform: rotate(45deg);
}

/* 悬停热区：填补入口与浮层之间的 12px 空隙，
   避免鼠标下移途中 :hover 中断导致浮层收起、菜单点不到 */
.vivo-topbar-app::after,
.vivo-topbar-member::after {
    content: '';
    position: absolute;
    top: 100%;
    left: -16px;
    right: -16px;
    height: 16px;
}

/* 二维码浮层 */
.vivo-app-qr {
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    width: 232px;
    padding: 22px 20px 14px;
    text-align: center;
}
.vivo-app-qr img {
    display: block;
    width: 168px;
    height: 168px;
    margin: 0 auto 10px;
    object-fit: contain;
}
.vivo-app-qr-tip {
    display: block;
    font-size: 12px;
    line-height: 1.45;
    color: #9096a3;
    white-space: nowrap;
}

/* 个人中心：悬停下拉（未登录→登录/注册；已登录→会员中心等） */
.vivo-topbar-member { position: relative; display: inline-flex; }
.vivo-topbar-member > a {
    font-size: 12px;
    color: rgba(255, 255, 255, .62);
    line-height: var(--topbar-h);
    transition: color var(--fast);
}
.vivo-topbar-member:hover > a { color: #fff; }
.vivo-topbar-member:hover .vivo-topbar-pop,
.vivo-topbar-member:focus-within .vivo-topbar-pop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}
.vivo-member-pop {
    min-width: 196px;
    padding: 4px 0;
}
.vivo-member-pop .vivo-pop-arrow { right: 26px; left: auto; margin-left: 0; }
.vivo-member-pop a {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 54px;
    padding: 0 20px;
    font-size: 14px;
    line-height: 1;
    color: #2a2f3a;
    white-space: nowrap;
    transition: color var(--fast), background var(--fast);
}
.vivo-member-pop a + a { position: relative; }
.vivo-member-pop a + a::before {
    content: '';
    position: absolute;
    top: 0;
    left: 24px;
    right: 24px;
    height: 1px;
    background: #f0f1f4;
}
.vivo-member-pop a:first-of-type { border-radius: 10px 10px 0 0; }
.vivo-member-pop a:last-of-type { border-radius: 0 0 10px 10px; }
.vivo-member-pop a svg { flex-shrink: 0; color: #5a6170; transition: color var(--fast); }
.vivo-member-pop a:hover { background: #fafbfc; color: #171b26; }
.vivo-member-pop a:hover svg { color: #171b26; }

/* ---------- 主导航栏（白色吸顶） ---------- */
.main-nav {
    background: var(--card);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 1000;
    transition: box-shadow var(--fast);
}
.main-nav.is-scrolled { box-shadow: var(--shadow); }

.nav-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-h);
    gap: 20px;
}

/* 品牌 Logo */
.brand-logo {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    font-size: 20px;
    font-weight: 700;
    color: var(--text-strong);
    letter-spacing: .5px;
    text-decoration: none;
    min-width: 0;
}
.brand-logo:hover { color: var(--text-strong); text-decoration: none; }
/* vivo 官方字标：默认深墨 #242933，悬停转品牌蓝（对齐官网 .vp-head-logo a:before） */
.brand-mark {
    display: inline-flex;
    flex-shrink: 0;
    color: #242933;
    transition: color .4s var(--ease);
}
.brand-mark svg { display: block; width: 104px; height: auto; }
.brand-logo:hover .brand-mark { color: var(--brand); }
.brand-name {
    display: inline-block;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 导航左区 */
.nav-left {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    min-width: 0;
}
/* 巨幕菜单以 .main-nav 为定位参照，故一级项不能创建定位上下文 */
.nav-item { position: static; }

/* 一级菜单项：主/副文字上下翻转（对齐 vivo .vp-head-series 悬停效果） */
.nav-link {
    position: relative;
    display: block;
    height: var(--header-h);
    padding: 0 18px;
    font-size: 15px;
    font-weight: 400;
    color: #3a4050;
    line-height: var(--header-h);
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    transition: color var(--fast);
}
.nav-link .main,
.nav-link .sub {
    display: block;
    transition: transform .32s cubic-bezier(.4, 0, .2, 1);
}
.nav-link .sub {
    position: absolute;
    left: 18px;
    right: 18px;
    top: 100%;
    height: var(--header-h);
    line-height: var(--header-h);
}
.nav-item.has-mega:hover .nav-link .main,
.nav-item.has-mega:hover .nav-link .sub { transform: translateY(-100%); }
.nav-link:hover,
.nav-link.active { color: #171b26; }

/* ---------- 通栏巨幕菜单（对应 vivo .vp-head-menu-series） ---------- */
.nav-mega {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid var(--line-2);
    box-shadow: 0 14px 30px rgba(23, 27, 38, .08);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .2s ease, visibility .2s ease;
    z-index: 1009;
}
@media (min-width: 993px) {
    .nav-item.has-mega:hover > .nav-mega,
    .nav-item.has-mega:focus-within > .nav-mega {
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
    }
}
.nav-mega-inner { padding-top: 36px; padding-bottom: 44px; }
.nav-mega-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.nav-mega-title {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: .01em;
    color: #171b26;
}
.nav-mega-all { font-size: 13px; color: var(--text-2); }
.nav-mega-all:hover { color: var(--brand); }
.nav-mega-list {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 2px 24px;
}
.nav-mega-link {
    display: block;
    padding: 9px 0;
    font-size: 14px;
    color: #171b26;
}
.nav-mega-link:hover,
.nav-mega-link.active { color: var(--brand); }
.nav-mega-sub { margin: 0 0 8px; }
.nav-mega-sub a {
    display: block;
    padding: 6px 0;
    font-size: 12px;
    color: var(--text-2);
}
.nav-mega-sub a:hover,
.nav-mega-sub a.active { color: var(--brand); }

/* ---------- 产品巨幕：热门产品横向卡片（对齐 vivo 产品下拉） ---------- */
.nav-hot {
    display: flex;
    align-items: center;
    gap: 16px;
}
.nav-hot-track {
    display: flex;
    gap: 20px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    scroll-behavior: smooth;
    scrollbar-width: none;
    padding: 2px 0;
}
.nav-hot-track::-webkit-scrollbar { display: none; }
.nav-hot-tip,
.nav-hot-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 190px;
    font-size: 13px;
    color: #9096a3;
}
.nav-hot-card {
    flex: 0 0 168px;
    display: block;
    text-align: center;
}
.nav-hot-thumb {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 168px;
    background: #f5f6f8;
    border-radius: 12px;
    overflow: hidden;
    transition: background var(--fast);
}
.nav-hot-card:hover .nav-hot-thumb { background: #eceef2; }
.nav-hot-thumb img {
    max-width: 78%;
    max-height: 78%;
    object-fit: contain;
    transition: transform .3s ease;
}
.nav-hot-card:hover .nav-hot-thumb img { transform: scale(1.04); }
.nav-hot-name {
    display: block;
    margin-top: 14px;
    font-size: 13px;
    color: #171b26;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.nav-hot-nav {
    flex: 0 0 40px;
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: #f5f6f8;
    color: #171b26;
    cursor: pointer;
    transition: background var(--fast);
}
.nav-hot-nav:hover { background: #eceef2; }
.nav-hot-nav:disabled { opacity: .35; cursor: default; }
.nav-hot-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-top: 26px;
}
.nav-hot-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 40px;
    padding: 0 22px;
    border-radius: 999px;
    background: #f5f6f8;
    font-size: 13px;
    color: #171b26;
    transition: background var(--fast);
}
.nav-hot-pill:hover { background: #eceef2; }

/* ---------- 导航右区 ---------- */
.nav-right {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

/* 搜索（vivo 官网式：点击放大镜展开整幅白色搜索面板） */
.nav-search {
    position: relative;
    display: flex;
    align-items: center;
}
.nav-search-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: #171b26;
    border-radius: 50%;
    cursor: pointer;
    transition: color var(--fast), background var(--fast);
}
.nav-search-btn:hover { background: #f2f2f2; color: #171b26; }

/* 搜索面板：盖住导航行并向下展开 */
.search-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: #fff;
    z-index: 1012;
    box-shadow: 0 16px 32px rgba(17, 20, 28, .10);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity .2s ease, visibility .2s ease, transform .2s ease;
}
.search-panel.open { opacity: 1; visibility: visible; transform: none; }
.search-panel-inner { position: relative; }
.search-panel-col {
    width: 520px;
    max-width: 100%;
    margin-left: clamp(140px, 24%, 300px);
}
.search-panel-row {
    display: flex;
    align-items: center;
    height: var(--header-h);
}
.search-field {
    display: flex;
    align-items: center;
    width: 520px;
    max-width: 100%;
    height: 44px;
    border-bottom: 1px solid #e5e7eb;
    transition: border-color var(--fast);
}
.search-field:focus-within { border-color: #171b26; }
.search-input {
    flex: 1;
    min-width: 0;
    height: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    font-size: 15px;
    color: #171b26;
}
.search-input::placeholder { color: #b3b8c4; }
.search-submit {
    flex: 0 0 36px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: none;
    color: #171b26;
    cursor: pointer;
}
.search-submit:hover { color: #000; }

/* 关闭按钮：导航行右侧 */
.search-close {
    position: absolute;
    top: 0;
    right: 0;
    width: 56px;
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: none;
    color: #171b26;
    cursor: pointer;
    transition: color var(--fast), transform var(--fast);
}
.search-close:hover { color: #000; transform: rotate(90deg); }

/* 面板内容：历史记录 + 搜索发现 */
.search-panel-body { padding: 16px 0 34px; }
.search-sec[hidden] { display: none; }
.search-sec + .search-sec { margin-top: 20px; }
.search-sec-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 22px;
    margin-bottom: 10px;
}
.search-sec-head > span { font-size: 12px; color: #9096a3; }
.search-sec-btn {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: none;
    color: #9096a3;
    cursor: pointer;
    transition: color var(--fast);
}
.search-sec-btn:hover { color: #171b26; }

.search-chips { display: flex; flex-wrap: wrap; gap: 10px; }
.search-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 32px;
    padding: 0 8px 0 14px;
    border-radius: 999px;
    background: #f5f6f8;
    font-size: 12px;
    color: #3a4050;
}
.search-chip:hover { background: #eceef2; }
.search-chip a { color: inherit; }
.search-chip-del {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: none;
    padding: 0;
    color: #9096a3;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
}
.search-chip-del:hover { color: #171b26; }

.search-discover { display: flex; flex-direction: column; }
.search-discover a {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 30px;
    font-size: 13px;
    color: #171b26;
    transition: color var(--fast);
}
.search-discover a:hover { color: var(--brand); }
.search-badge {
    display: inline-flex;
    align-items: center;
    height: 16px;
    padding: 0 4px;
    border-radius: 3px;
    background: #ff3b30;
    color: #fff;
    font-size: 10px;
    line-height: 1;
}
.search-new-label { display: none; }

/* 展开时：隐藏导航项，保留 vivo 字标；页面其余部分压暗 */
.main-nav.search-open .nav-left,
.main-nav.search-open .nav-right { opacity: 0; pointer-events: none; }
.main-nav.search-open .brand-logo { position: relative; z-index: 1013; }
.search-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(17, 20, 28, .5);
    z-index: 1010;
    opacity: 0;
    visibility: hidden;
    transition: opacity .2s ease, visibility .2s ease;
}
.search-overlay.open { opacity: 1; visibility: visible; }
body.search-open { overflow: hidden; }

/* 购物车入口（官网式：纯图标） */
.cart-icon-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    font-size: 13px;
    color: #171b26;
    background: transparent;
    transition: all var(--fast);
    position: relative;
}
.cart-icon-link:hover {
    color: #171b26;
    text-decoration: none;
    background: #f2f2f2;
}
.cart-icon { width: 22px; height: 22px; flex-shrink: 0; }
.cart-text { display: none; }

.cart-badge {
    position: absolute;
    top: 0;
    right: 0;
    min-width: 16px;
    height: 16px;
    background: #171b26;
    color: #fff;
    font-size: 10px;
    font-weight: 600;
    border-radius: 999px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
    border: 2px solid #fff;
}

/* 汉堡按钮 */
.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    border-radius: var(--radius-s);
    transition: background var(--fast);
}
.nav-toggle:hover { background: #f2f2f2; }
.nav-toggle .icon-close { display: none; }

/* ---------- 响应式：移动端抽屉 ---------- */
@media (max-width: 992px) {
    /* 移动端隐藏顶部工具条（与 vivo 官网一致） */
    .vivo-topbar { display: none; }

    /* 抽屉遮罩：与抽屉同处一个层叠上下文，层级低于抽屉(1001) */
    .nav-backdrop {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .45);
        opacity: 0;
        visibility: hidden;
        transition: opacity var(--mid), visibility var(--mid);
        z-index: 1000;
    }
    .nav-backdrop.open { opacity: 1; visibility: visible; }

    /* 抽屉展开时锁定页面滚动 */
    body.nav-open { overflow: hidden; }

    .nav-left {
        position: fixed;
        top: 0;
        right: 0;
        width: min(300px, 86vw);
        height: 100vh;
        height: 100dvh;
        background: var(--card);
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        padding: calc(16px + env(safe-area-inset-top, 0px)) 0 calc(20px + env(safe-area-inset-bottom, 0px));
        box-shadow: -4px 0 24px rgba(0, 0, 0, .12);
        transform: translateX(100%);
        transition: transform var(--mid);
        z-index: 1001;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    .nav-left.open { transform: translateX(0); }

    .nav-link {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: auto;
        min-height: 52px;
        line-height: 1.35;
        padding: 0 22px;
        border-bottom: 1px solid var(--line-2);
        font-size: 15px;
        overflow: visible;
    }
    /* 移动端不显示翻转用的副文字 */
    .nav-link .sub { display: none; }
    .nav-item.has-mega:hover .nav-link .main { transform: none; }
    /* 有子菜单的父项：右侧箭头指示可展开 */
    .nav-item.has-mega > .nav-link::after {
        content: '';
        width: 7px;
        height: 7px;
        border-right: 2px solid var(--text-3);
        border-bottom: 2px solid var(--text-3);
        transform: rotate(45deg);
        transition: transform var(--fast);
        flex-shrink: 0;
        margin-left: 12px;
    }
    .nav-item.open > .nav-link::after {
        transform: rotate(-135deg);
        border-color: #171b26;
    }
    .nav-item.open > .nav-link { color: #171b26; }

    /* 巨幕菜单在移动端变为手风琴 */
    .nav-mega {
        position: static;
        transform: none;
        width: auto;
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        display: none;
        box-shadow: none;
        border-top: 1px solid var(--line-2);
        background: var(--bg);
    }
    .nav-item.open > .nav-mega { display: block !important; }
    .nav-mega-inner { padding: 6px 0 10px; }
    .nav-mega-head { display: none; }
    .nav-mega-list {
        display: block;
        padding: 0 22px 8px 40px;
    }
    .nav-mega-link {
        min-height: 42px;
        display: flex;
        align-items: center;
        padding: 8px 0;
        font-size: 14px;
        border-bottom: 1px solid var(--line-2);
    }
    .nav-mega-sub { margin: 0; padding-left: 14px; }
    .nav-mega-sub a {
        min-height: 38px;
        display: flex;
        align-items: center;
        font-size: 13px;
        color: var(--text-2);
    }

    /* 产品巨幕：移动端隐藏翻页按钮，卡片缩小，横向滑动 */
    .nav-hot { gap: 0; }
    .nav-hot-nav { display: none; }
    .nav-hot-track { gap: 12px; margin: 0 -22px; padding: 4px 22px 0; }
    .nav-hot-card { flex-basis: 128px; }
    .nav-hot-thumb { height: 128px; border-radius: 10px; }
    .nav-hot-name { margin-top: 10px; font-size: 12px; }
    .nav-hot-actions { margin-top: 14px; padding-bottom: 6px; }
    .nav-hot-pill { height: 36px; padding: 0 16px; font-size: 12px; }

    /* 抽屉内选中态用品牌色 */
    .nav-mega-link.active,
    .nav-mega-sub a.active { color: var(--brand); }

    .nav-toggle.is-active .icon-menu { display: none; }
    .nav-toggle.is-active .icon-close { display: block; }

    /* 搜索：圆形图标常显，点击展开全屏搜索面板 */
    .nav-search-btn { display: flex; }
    .nav-search { position: static; }
    .search-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        overflow-y: auto;
        z-index: 1012;
    }
    .search-panel-col {
        width: auto;
        max-width: none;
        margin: 0;
        padding: 0 56px 0 20px;
    }
    .search-panel-row { height: 56px; }
    .search-field { width: 100%; height: 40px; }
    .search-close { height: 56px; width: 44px; }
    .search-panel-body { padding: 12px 0 24px; }

    .nav-toggle { display: flex; }
    .cart-text { display: inline; }
    .cart-icon-link { height: 40px; width: 40px; }
}

/* ---------- 窄屏 ---------- */
@media (max-width: 640px) {
    .nav-container { height: 56px; gap: 8px; }
    .brand-name { font-size: 17px; }
    .nav-right { gap: 2px; }
    .cart-text { display: none; }
    .cart-icon-link { padding: 0; }
}

/* ---------- 超窄屏：隐藏文字品牌名，仅留图形标识 ---------- */
@media (max-width: 360px) {
    .brand-name { display: none; }
}
