/* 全局重置 + 应用外壳（侧边栏 / 顶栏 / 内容区） */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
}

body {
    font-family: var(--font-sans);
    font-size: var(--fs-md);
    background: var(--bg-body);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button {
    font-family: inherit;
}

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-surface-3);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

/* ---------- 外壳 ---------- */

.app-shell {
    display: flex;
    min-height: 100vh;
}

.app-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-content {
    flex: 1;
    padding: var(--space-6);
    min-width: 0;
}

/* ---------- 侧边栏 ---------- */

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    transition: width 0.18s ease;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    height: var(--topbar-height);
    padding: 0 var(--space-4);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-brand:hover {
    text-decoration: none;
}

.sidebar-logo {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: var(--accent-contrast);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: var(--fs-sm);
}

.sidebar-title {
    font-size: var(--fs-md);
    font-weight: 600;
    color: var(--text-strong);
    white-space: nowrap;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: var(--space-3) var(--space-2);
}

.nav-item {
    margin-bottom: 2px;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 9px var(--space-3);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    font-size: var(--fs-sm);
    width: 100%;
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
}

.nav-link:hover {
    background: var(--bg-surface-2);
    color: var(--text-strong);
    text-decoration: none;
}

.nav-link.active {
    background: var(--accent-soft);
    color: var(--accent);
    font-weight: 600;
}

.nav-icon {
    width: 20px;
    flex-shrink: 0;
    text-align: center;
    font-size: 1rem;
    line-height: 1;
}

.nav-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.nav-caret {
    flex-shrink: 0;
    font-size: 0.65rem;
    color: var(--text-faint);
    transition: transform 0.18s ease;
}

.nav-item.open > .nav-link .nav-caret {
    transform: rotate(90deg);
}

.nav-children {
    list-style: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.2s ease;
}

.nav-item.open > .nav-children {
    max-height: 640px;
}

.nav-children .nav-link {
    padding-left: 46px;
    font-size: var(--fs-xs);
}

.sidebar-footer {
    padding: var(--space-3);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* 折叠态：只留图标，子菜单整体隐藏 */
.sidebar-collapsed .sidebar {
    width: var(--sidebar-width-collapsed);
}

.sidebar-collapsed .sidebar-title,
.sidebar-collapsed .nav-label,
.sidebar-collapsed .nav-caret,
.sidebar-collapsed .nav-children {
    display: none;
}

.sidebar-collapsed .nav-link {
    justify-content: center;
    padding-left: var(--space-2);
    padding-right: var(--space-2);
}

.sidebar-collapsed .sidebar-brand {
    justify-content: center;
    padding: 0;
}

/* ---------- 顶栏 ---------- */

.topbar {
    height: var(--topbar-height);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: 0 var(--space-6);
    background: var(--bg-topbar);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-muted);
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}

.topbar-toggle:hover {
    background: var(--bg-surface-2);
    color: var(--text-strong);
}

.topbar-breadcrumb {
    font-size: var(--fs-sm);
    color: var(--text-muted);
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-breadcrumb strong {
    color: var(--text-strong);
    font-weight: 600;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    flex-shrink: 0;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 5px var(--space-3);
    color: var(--text);
    font-size: var(--fs-sm);
    cursor: pointer;
}

.topbar-user:hover {
    background: var(--bg-surface-2);
}

.avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: var(--accent-contrast);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--fs-xs);
    font-weight: 600;
    flex-shrink: 0;
}

/* ---------- 移动端 ---------- */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        z-index: var(--z-drawer);
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

    .sidebar-open .sidebar {
        transform: translateX(0);
    }

    /* 移动端忽略折叠态，抽屉式展开 */
    .sidebar-collapsed .sidebar {
        width: var(--sidebar-width);
    }

    .sidebar-collapsed .sidebar-title,
    .sidebar-collapsed .nav-label,
    .sidebar-collapsed .nav-caret {
        display: initial;
    }

    .sidebar-collapsed .nav-children {
        display: block;
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: 0;
        background: var(--bg-overlay);
        z-index: calc(var(--z-drawer) - 1);
    }

    .sidebar-open .sidebar-backdrop {
        display: block;
    }

    .app-content,
    .topbar {
        padding-left: var(--space-4);
        padding-right: var(--space-4);
    }
}
