/**
 * 访客页顶栏（.www-header）：窄屏折叠主导航 + 语言 + 账户（登录/未登录均适用）。
 * 断点 1024px 与 WwwAdaptiveEnv.BREAKPOINTS.lg 一致。须在 www-public-layout.css 之后加载。
 */

.www-header {
    padding-top: env(safe-area-inset-top, 0);
}

.www-header__inner {
    max-width: 72rem;
    margin: 0 auto;
    padding-left: max(1rem, env(safe-area-inset-left, 0));
    padding-right: max(1rem, env(safe-area-inset-right, 0));
    padding-top: 0.55rem;
    padding-bottom: 0.55rem;
    min-height: var(--www-header-h);
    height: auto;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
        'brand toggle'
        'menu menu';
    align-items: center;
    column-gap: 0.65rem;
    row-gap: 0.5rem;
}

.www-header__inner > .www-brand {
    grid-area: brand;
    min-width: 0;
}

.www-header__menu-toggle {
    grid-area: toggle;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    margin: 0;
    padding: 0;
    border: 1px solid color-mix(in srgb, var(--www-color-text, #eef3f9) 14%, transparent);
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.06);
    color: var(--www-color-text, #eef3f9);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.www-header__menu-toggle:hover,
.www-header__menu-toggle:focus-visible {
    background: rgba(255, 255, 255, 0.1);
    outline: none;
}

.www-header__menu-toggle .www-header__menu-icon {
    display: flex;
    flex-direction: column;
    gap: 0.22rem;
    width: 1.1rem;
}

.www-header__menu-toggle .www-header__menu-icon span {
    display: block;
    height: 2px;
    border-radius: 1px;
    background: currentColor;
}

.www-header__tools {
    grid-area: menu;
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0.85rem;
    padding: 0.75rem 0 0.35rem;
    margin-top: 0.15rem;
    border-top: 1px solid color-mix(in srgb, var(--www-color-text, #eef3f9) 10%, transparent);
    flex-wrap: nowrap;
    width: 100%;
    min-width: 0;
}

.www-header.is-nav-open .www-header__tools {
    display: flex;
}

/*
 * 窄屏：基础壳 www-public-layout.css 给 .www-header__inner 固定高度，会把第二行网格（折叠菜单）裁掉，
 * 表现为点击汉堡无「展开」。此处强制增高与 overflow，并与 .www-header__tools { display:flex } 用 !important 对齐优先级。
 */
@media (max-width: 1023px) {
    .www-header {
        overflow: visible;
    }

    .www-header__inner {
        height: auto !important;
        min-height: var(--www-header-h);
        overflow: visible;
    }

    .www-header__tools {
        display: none !important;
    }

    .www-header.is-nav-open .www-header__tools {
        display: flex !important;
        position: relative;
        z-index: 25;
        width: 100%;
        box-sizing: border-box;
        margin-top: 0.25rem;
        padding: 0.75rem 0.65rem 0.85rem;
        border-radius: 0.65rem;
        background: color-mix(in srgb, var(--www-color-surface, #121a24) 94%, transparent);
        border: 1px solid color-mix(in srgb, var(--www-color-text, #eef3f9) 12%, transparent);
        box-shadow: 0 0.75rem 1.75rem rgba(0, 0, 0, 0.4);
    }
}

/* 主导航：窄屏纵向，触控区域 */
.www-header__tools .www-nav {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: stretch;
    gap: 0.15rem;
    width: 100%;
}

.www-header__tools .www-nav a {
    padding: 0.55rem 0.5rem;
    border-radius: 0.4rem;
    border-bottom: none;
}

.www-header__tools .www-nav a:hover {
    background: rgba(255, 255, 255, 0.06);
}

.www-header__tools .www-nav a.is-active {
    background: rgba(255, 255, 255, 0.08);
}

.www-header__tools .www-header__auth {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    width: 100%;
}

.www-header__tools .www-header__user {
    max-width: 100%;
    white-space: normal;
    word-break: break-word;
    line-height: 1.35;
}

.www-header__tools .www-header__auth-combined {
    width: 100%;
    justify-content: flex-start;
}

.www-header__tools .www-header__auth-link {
    padding: 0.45rem 0.5rem;
}

.www-header__tools .www-header__logout-form {
    display: block;
}

.www-header__tools .www-header__logout-form .www-btn {
    width: 100%;
    justify-content: center;
}

/* 账户：折叠面板内纵向展开，不依赖悬停 */
.www-header__tools .www-header__account {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
}

/* 窄屏：折叠面板内已有大号头像与账户入口，隐藏顶栏小头像按钮 */
.www-header__tools .www-header__avatar-trigger {
    display: none;
}

.www-header__tools .www-header__account-menu {
    display: block;
    position: static;
    margin-top: 0.35rem;
    min-width: 0;
    width: 100%;
    box-shadow: none;
    border-radius: 0.45rem;
}

.www-header__tools .www-header__account-menu-inner .www-header__auth-link {
    text-align: left;
}

.www-header__tools .www-header__user--menu {
    text-align: left;
}

@media (min-width: 1024px) {
    .www-header__inner {
        display: flex;
        flex-wrap: nowrap;
        align-items: center;
        justify-content: space-between;
        gap: 1rem;
        height: var(--www-header-h);
        min-height: var(--www-header-h);
        padding-top: 0;
        padding-bottom: 0;
        row-gap: 0;
    }

    .www-header__menu-toggle {
        display: none !important;
    }

    .www-header__tools {
        display: flex !important;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: flex-end;
        gap: 0.65rem 1rem;
        flex: 1;
        padding: 0;
        margin: 0;
        border-top: none;
        width: auto;
    }

    .www-header__tools .www-nav {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.35rem 1.25rem;
        width: auto;
    }

    .www-header__tools .www-nav a {
        padding: 0.35rem 0;
        border-radius: 0;
        border-bottom: 2px solid transparent;
        background: transparent;
    }

    .www-header__tools .www-nav a:hover {
        background: transparent;
    }

    .www-header__tools .www-nav a.is-active {
        background: transparent;
    }

    .www-header__tools .www-header__auth {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        width: auto;
    }

    .www-header__tools .www-header__auth-combined {
        width: auto;
    }

    .www-header__tools .www-header__user {
        max-width: 12rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .www-header__tools .www-header__logout-form {
        display: inline;
    }

    .www-header__tools .www-header__logout-form--menu {
        display: block;
    }

    .www-header__tools .www-header__logout-form .www-btn {
        width: auto;
    }

    .www-header__tools .www-header__logout-form--menu .www-btn {
        width: 100%;
    }

    .www-header__tools .www-header__account {
        flex-direction: row;
        align-items: center;
        width: auto;
    }

    .www-header__tools .www-header__avatar-trigger {
        display: inline-flex;
        align-self: center;
    }

    .www-header__tools .www-header__account-menu {
        display: none;
        position: absolute;
        top: 100%;
        right: 0;
        width: auto;
        min-width: 12rem;
        box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.35);
    }

    .www-header__tools .www-header__account:hover .www-header__account-menu,
    .www-header__tools .www-header__account:focus-within .www-header__account-menu {
        display: block;
    }

    .www-header__tools .www-header__account-menu-inner .www-header__auth-link {
        text-align: center;
    }

    .www-header__tools .www-header__user--menu {
        text-align: center;
    }
}

/* 窄屏但非极小：语言条不必占满宽 */
@media (min-width: 480px) and (max-width: 1023px) {
    .www-header__tools .www-header__auth {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
    }

    .www-header__tools .www-header__auth-combined {
        width: auto;
    }

    .www-header__tools .www-header__logout-form .www-btn {
        width: auto;
    }
}
