/* ============================================================
   Header — 小米商城风格：深色工具条 + 白色吸顶主导航
   全部样式集中于此，模板内不含 <style> 块
   设计令牌来自 common.css（加载于本文件之前）
   ============================================================ */

/* ---------- 顶部工具条（细窄深色） ---------- */
.topbar {
    background: var(--ink);
    color: var(--text-3);
    font-size: 12px;
    line-height: 36px;
}
.topbar-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 36px;
}
.topbar-left {
    display: flex;
    align-items: center;
    min-width: 0;
}
.topbar-welcome { color: var(--text-3); }
.topbar-right {
    display: flex;
    align-items: center;
}
.topbar-link {
    color: var(--text-3);
    padding: 0 10px;
    font-size: 12px;
    line-height: 36px;
    display: inline-block;
    transition: color var(--fast);
}
.topbar-link:hover { color: var(--card); text-decoration: none; }
.topbar-user { color: var(--card); font-weight: 500; }
.topbar-sep {
    display: inline-block;
    width: 1px;
    height: 12px;
    background: rgba(255, 255, 255, .14);
    vertical-align: middle;
}

/* 顶部币种选择（提高优先级覆盖 currency_switcher 内联样式） */
.currency-switcher .currency-btn {
    background: transparent;
    border: none;
    color: var(--text-3);
    padding: 0 6px;
    font-size: 12px;
    gap: 4px;
    line-height: 36px;
}
.currency-switcher .currency-btn:hover { color: var(--card); }
.currency-switcher .currency-symbol { color: var(--text-3); }
.currency-switcher.open .currency-dropdown { top: 100%; }

/* 语言选择（用伪元素绘制箭头，避免硬编码颜色） */
.language-selector {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.language-selector select {
    background: transparent;
    border: none;
    color: var(--text-3);
    font-size: 12px;
    cursor: pointer;
    padding: 0 16px 0 6px;
    line-height: 36px;
    height: 36px;
    appearance: none;
    -webkit-appearance: none;
}
.language-selector select:hover { color: var(--card); }
.language-selector select option { color: var(--text-strong); }
.language-selector::after {
    content: '';
    position: absolute;
    right: 6px;
    top: 50%;
    width: 6px;
    height: 6px;
    border-right: 1.5px solid var(--text-3);
    border-bottom: 1.5px solid var(--text-3);
    transform: translateY(-70%) rotate(45deg);
    pointer-events: none;
}

/* ---------- 主导航栏（白色吸顶） ---------- */
.main-nav {
    background: var(--card);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 900;
    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; }
.brand-mark { display: inline-flex; flex-shrink: 0; }
.brand-name {
    display: inline-block;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* 导航左区 */
.nav-left {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}
.nav-item { position: relative; }
.nav-item > a {
    display: block;
    padding: 0 14px;
    font-size: 15px;
    font-weight: 400;
    color: var(--text);
    line-height: var(--header-h);
    text-decoration: none;
    white-space: nowrap;
    transition: color var(--fast);
}
.nav-item > a:hover,
.nav-item > a.active { color: var(--brand); }

/* 一级下拉面板（白底 + 1px 边框 + 轻阴影） */
.dropdown {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    min-width: 220px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-hover);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--fast), transform var(--fast), visibility var(--fast);
    z-index: 950;
    padding: 8px 0;
}
.nav-item:hover > .dropdown,
.nav-item:focus-within > .dropdown {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateX(-50%) translateY(0);
}

.dropdown-item { position: relative; }
.dropdown-item > a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 18px;
    font-size: 14px;
    color: var(--text);
    line-height: 1.4;
    white-space: nowrap;
    transition: color var(--fast), background var(--fast);
}
.dropdown-item > a:hover,
.dropdown-item > a.active { background: var(--brand-light); color: var(--brand); }
.dropdown-item > a .arrow { color: var(--text-3); font-size: 14px; }

/* 二级下拉面板 */
.submenu {
    position: absolute;
    top: 0;
    left: 100%;
    min-width: 200px;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-hover);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all var(--fast);
    z-index: 960;
    padding: 8px 0;
}
.dropdown-item:hover > .submenu,
.dropdown-item:focus-within > .submenu {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}
.submenu a {
    display: block;
    padding: 8px 18px;
    font-size: 13px;
    color: var(--text);
    line-height: 1.4;
    white-space: nowrap;
    transition: color var(--fast), background var(--fast);
}
.submenu a:hover,
.submenu a.active { background: var(--brand-light); color: var(--brand); }

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

/* 搜索 */
.nav-search {
    position: relative;
    display: flex;
    align-items: center;
}
.nav-search-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    color: var(--text-2);
    border-radius: var(--radius-s);
    cursor: pointer;
    transition: color var(--fast), background var(--fast);
}
.nav-search-btn:hover { color: var(--brand); background: var(--brand-light); }

.nav-search-box {
    display: flex;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 999px;
    overflow: hidden;
    background: var(--card);
    transition: border-color var(--fast), box-shadow var(--fast);
}
.nav-search-box:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-light);
}
.nav-search-input {
    border: none;
    outline: none;
    background: transparent;
    padding: 0 16px;
    height: 38px;
    width: 240px;
    font-size: 13px;
    color: var(--text);
}
.nav-search-input::placeholder { color: var(--text-3); }
.nav-search-submit {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 38px;
    border: none;
    background: var(--brand);
    color: var(--card);
    cursor: pointer;
    transition: background var(--fast);
}
.nav-search-submit:hover { background: var(--brand-hover); }

/* 购物车入口 */
.cart-icon-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0 14px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: var(--radius-s);
    font-size: 13px;
    color: var(--text);
    background: var(--card);
    transition: all var(--fast);
    position: relative;
}
.cart-icon-link:hover {
    border-color: var(--brand);
    color: var(--brand);
    text-decoration: none;
    background: var(--brand-light);
}
.cart-icon { width: 20px; height: 20px; flex-shrink: 0; }
.cart-text { display: none; }

.cart-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    min-width: 18px;
    height: 18px;
    background: var(--brand);
    color: var(--card);
    font-size: 11px;
    font-weight: 600;
    border-radius: 999px;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    line-height: 1;
    border: 2px solid var(--card);
}

/* 汉堡按钮 */
.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: var(--brand-light); }
.nav-toggle .icon-close { display: none; }

/* ---------- 中等宽度：给导航更多空间 ---------- */
@media (max-width: 1100px) {
    .nav-search-input { width: 170px; }
    .nav-item > a { padding: 0 10px; font-size: 14px; }
}

/* ---------- 响应式：移动端抽屉 ---------- */
@media (max-width: 992px) {
    /* 抽屉遮罩：与抽屉同处一个层叠上下文，层级低于抽屉(1000) */
    .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: 999;
    }
    .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: 1000;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    .nav-left.open { transform: translateX(0); }

    .nav-item > a {
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-height: 52px;
        line-height: 1.35;
        padding: 0 22px;
        border-bottom: 1px solid var(--line-2);
        font-size: 15px;
    }
    /* 有子菜单的父项：右侧箭头指示可展开 */
    .nav-item.has-dropdown > a::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 > a::after {
        transform: rotate(-135deg);
        border-color: var(--brand);
    }
    .nav-item.open > a { color: var(--brand); }
    .dropdown-item.open > a .arrow { transform: rotate(90deg); color: var(--brand); }

    .dropdown {
        position: static;
        transform: none;
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        display: none;
        box-shadow: none;
        border: none;
        border-top: 1px solid var(--line-2);
        border-radius: 0;
        padding: 0;
        min-width: auto;
    }
    .nav-item.open > .dropdown { display: block; }
    .dropdown-item > a {
        min-height: 46px;
        padding: 10px 22px 10px 40px;
        font-size: 14px;
    }
    .dropdown-item > a .arrow { transition: transform var(--fast); }
    .submenu {
        position: static;
        opacity: 1;
        visibility: visible;
        pointer-events: auto;
        display: none;
        box-shadow: none;
        border: none;
        border-top: 1px solid var(--line-2);
        border-radius: 0;
        padding: 0;
        min-width: auto;
    }
    .dropdown-item.open > .submenu { display: block; }
    .submenu a {
        min-height: 44px;
        display: flex;
        align-items: center;
        padding: 8px 22px 8px 56px;
        font-size: 13px;
    }

    /* 抽屉内选中态用品牌色 */
    .dropdown-item > a.active,
    .submenu a.active { color: var(--brand); background: var(--brand-light); }

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

    /* 搜索图标常显，点击展开铺满式搜索面板 */
    .nav-search-btn { display: flex; }
    .nav-container { position: relative; }
    .nav-search { position: static; }
    .nav-search-box {
        position: absolute;
        top: calc(100% + 6px);
        left: 12px;
        right: 12px;
        width: auto;
        display: none;
        z-index: 950;
        box-shadow: var(--shadow-hover);
    }
    .nav-search-box.open { display: flex; }
    .nav-search-input { width: 100%; min-width: 0; height: 40px; }
    .nav-search-submit { height: 40px; }

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

/* ---------- 窄屏：工具条横向滚动 ---------- */
@media (max-width: 640px) {
    .topbar { font-size: 11px; line-height: 34px; }
    .topbar-inner { display: block; padding: 0 8px; height: 34px; }
    .topbar-welcome { display: none; }
    .topbar-right {
        display: flex;
        align-items: center;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .topbar-right::-webkit-scrollbar { display: none; }
    .topbar-link { padding: 0 8px; line-height: 34px; white-space: nowrap; }
    .topbar-sep,
    .currency-switcher,
    .language-selector { flex-shrink: 0; }
    .language-selector select { line-height: 34px; height: 34px; }

    .nav-container { height: 56px; gap: 8px; }
    .brand-name { font-size: 17px; }
    .nav-right { gap: 6px; }
    .cart-text { display: none; }
    .cart-icon-link { padding: 0 10px; }
}

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