/* =====================================================
   Tutorial Studio
   Topbar Account
===================================================== */

.account-area {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-shrink: 0;
    margin-left: 6px;
    z-index: 120;
}

.account-area *,
.account-area *::before,
.account-area *::after {
    box-sizing: border-box;
}

/* =====================================================
   未登录账户
===================================================== */

.account-guest {
    display: flex;
    align-items: center;
    gap: 7px;
}

.account-login-btn,
.account-register-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 34px;
    padding: 0 13px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition:
        background-color 0.18s ease,
        border-color 0.18s ease,
        color 0.18s ease;
}

.account-login-btn {
    color: #ffffff;
    background: #6366f1;
    border: 1px solid #6366f1;
}

.account-login-btn:hover {
    background: #4f46e5;
    border-color: #4f46e5;
}

.account-register-btn {
    color: #374151;
    background: #ffffff;
    border: 1px solid #e5e7eb;
}

.account-register-btn:hover {
    color: #4f46e5;
    background: #f5f5ff;
    border-color: #c7d2fe;
}

/* =====================================================
   已登录账户
===================================================== */

.account-user {
    position: relative;
    display: flex;
    align-items: center;
}

.account-user[hidden],
.account-guest[hidden],
.account-dropdown[hidden] {
    display: none !important;
}

.account-user-trigger {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 36px;
    padding: 3px 9px 3px 4px;
    color: #374151;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 9px;
    font-family: inherit;
    cursor: pointer;
    transition:
        background-color 0.18s ease,
        border-color 0.18s ease;
}

.account-user-trigger:hover,
.account-user-trigger[aria-expanded="true"] {
    background: #f8fafc;
    border-color: #e5e7eb;
}

.account-avatar,
.account-dropdown-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #ffffff;
    background: linear-gradient(135deg, #818cf8, #6366f1);
    font-weight: 700;
    user-select: none;
}

.account-avatar {
    width: 29px;
    height: 29px;
    border-radius: 8px;
    font-size: 13px;
}

.account-username {
    display: inline-block;
    max-width: 100px;
    overflow: hidden;
    color: #374151;
    font-size: 13px;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-chevron {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #9ca3af;
    transition: transform 0.18s ease;
}

.account-user-trigger[aria-expanded="true"] .account-chevron {
    transform: rotate(180deg);
}

/* =====================================================
   账户下拉菜单
===================================================== */

.account-dropdown {
    position: absolute;
    top: calc(100% + 9px);
    right: 0;
    z-index: 1200;

    width: 240px;
    max-width: calc(100vw - 24px);

    padding: 8px;

    color: #374151;
    background: #ffffff;

    border: 1px solid #e5e7eb;
    border-radius: 12px;

    box-shadow:
        0 12px 32px rgb(15 23 42 / 10%),
        0 2px 6px rgb(15 23 42 / 4%);

    box-sizing: border-box;
    animation: account-dropdown-enter 0.16s ease-out;
}

.account-dropdown[hidden] {
    display: none !important;
}

/* =====================================================
   下拉菜单用户信息
===================================================== */

.account-dropdown-header {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    min-width: 0;
    padding: 10px 8px 12px;
}

.account-dropdown-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;

    flex: 0 0 38px;

    width: 38px;
    height: 38px;

    border-radius: 10px;
    font-size: 15px;
}

.account-dropdown-info {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;

    min-width: 0;
    overflow: hidden;
}

.account-dropdown-info strong {
    display: block;
    width: 100%;
    min-width: 0;

    overflow: hidden;
    color: #111827;

    font-size: 13px;
    font-weight: 650;
    line-height: 1.5;

    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-dropdown-info > span {
    display: block;
    max-width: 100%;

    color: #9ca3af;
    font-size: 12px;
    line-height: 1.5;

    white-space: normal;
    overflow-wrap: anywhere;
}

/* 分隔线 */

.account-dropdown-divider {
    height: 1px;
    margin: 5px 0;
    background: #f1f5f9;
}

/* =====================================================
   下拉菜单操作按钮
===================================================== */

.account-dropdown-item {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: nowrap !important;

    align-items: center !important;
    justify-content: flex-start !important;

    gap: 12px !important;

    width: 100%;
    min-width: 0;
    min-height: 42px;

    margin: 2px 0;
    padding: 0 12px;

    color: #4b5563;
    background: transparent;

    border: none;
    border-radius: 8px;

    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.5;

    text-align: left;
    white-space: nowrap;
    word-break: keep-all;
    overflow-wrap: normal;
    writing-mode: horizontal-tb;

    cursor: pointer;

    box-sizing: border-box;

    transition:
        color 0.15s ease,
        background-color 0.15s ease;
}

/*
 * 图标区域：
 * 只处理按钮的第一个直接子元素。
 *
 * 这样不会再把文字 span 一起当作图标。
 */
.account-dropdown-item > span:first-child {
    display: inline-flex !important;
    flex: 0 0 20px !important;

    align-items: center !important;
    justify-content: center !important;

    width: 20px !important;
    min-width: 20px !important;
    height: 20px;

    margin: 0 !important;
    padding: 0 !important;

    color: #9ca3af;
    font-size: 16px;
    line-height: 1;

    white-space: nowrap;
    writing-mode: horizontal-tb;

    box-sizing: border-box;
}

/*
 * 如果按钮中使用 SVG 图标，
 * 也固定其占位宽度。
 */
.account-dropdown-item > svg:first-child {
    display: block;
    flex: 0 0 20px;

    width: 20px;
    height: 20px;

    margin: 0;
    padding: 0;

    color: #9ca3af;

    box-sizing: border-box;
}

/*
 * 文字区域：
 * 仅当文字被单独放在第二个直接子元素中时应用。
 */
.account-dropdown-item > span:nth-child(2) {
    display: block;

    flex: 1 1 auto;
    min-width: 0;

    margin: 0;
    padding: 0;

    color: inherit;
    font-size: inherit;
    font-weight: inherit;
    line-height: 1.5;

    text-align: left;
    white-space: nowrap;
    word-break: keep-all;
    overflow-wrap: normal;
    writing-mode: horizontal-tb;
}

/* 兼容按钮直接包含文字、没有文字 span 的情况 */
.account-dropdown-item:not(:has(> span:nth-child(2))) {
    column-gap: 12px;
}

/* 菜单悬停效果 */

.account-dropdown-item:hover {
    color: #4338ca;
    background: #f5f5ff;
}

.account-dropdown-item:hover > span:first-child,
.account-dropdown-item:hover > svg:first-child {
    color: #6366f1;
}

/* 退出登录 */

.account-logout-item {
    color: #dc2626;
}

.account-logout-item:hover {
    color: #dc2626;
    background: #fef2f2;
}

.account-logout-item:hover > span:first-child,
.account-logout-item:hover > svg:first-child {
    color: #dc2626;
}

/* =====================================================
   动画与键盘焦点
===================================================== */

@keyframes account-dropdown-enter {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.account-area button:focus-visible {
    outline: 2px solid #818cf8;
    outline-offset: 2px;
}

/* =====================================================
   移动端
===================================================== */

@media (max-width: 640px) {
    .account-area {
        margin-left: 0;
    }

    .account-guest {
        gap: 5px;
    }

    .account-login-btn,
    .account-register-btn {
        min-height: 32px;
        padding: 0 9px;
        font-size: 12px;
    }

    .account-user-trigger {
        gap: 0;
        padding: 3px;
    }

    .account-username,
    .account-chevron {
        display: none;
    }

    .account-dropdown {
        width: 230px;
        max-width: calc(100vw - 20px);
    }
}

/* 减少动态效果 */

@media (prefers-reduced-motion: reduce) {
    .account-dropdown {
        animation: none;
    }

    .account-dropdown-item,
    .account-user-trigger {
        transition: none;
    }
}
