/* ========== 1. 全局变量与重置 ========== */
:root {
    /* 🔥 核心修改：全局背景色改为图5的深灰蓝，不再是纯黑或死黑 */
    --bg-dark: #121216;       
    
    /* 侧边栏背景：稍微亮一点点，形成微妙层次 */
    --bg-sidebar: #18181c;    
    
    /* 卡片/弹窗背景：加一点深蓝灰，更有质感 */
    --bg-card: #1e1e24;       
    
    /* 品牌主色 (保持紫色) */
    --primary: #6c5ce7;       
    --primary-hover: #5649c0;
    
    /* 文字颜色 */
    --text-white: #e0e0e0;    /* 稍微柔和的白 */
    --text-gray: #a0a0a0;
    
    /* 边框线条颜色：调淡一点，融合背景 */
    --border-color: #2f2f3d;  
    
    --danger: #ff4757;
}

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

body {
    font-family: 'Segoe UI', 'Microsoft YaHei', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-dark); /* 应用新背景色 */
    color: var(--text-white);
    height: 100vh;
    overflow: hidden; /* 防止整个页面滚动 */
}

a { text-decoration: none; color: inherit; }
ul { list-style: none; }

/* 🆕 滚动条美化 (保留你的样式) */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #3f3f4b; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* ========== 2. 布局容器 ========== */
.app-container {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ========== 3. 左侧侧边栏 (Sidebar) ========== */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
    flex-shrink: 0;
    z-index: 100; /* 提高层级 */
    transition: width 0.3s ease, transform 0.3s ease; /* 丝滑过渡 */
    overflow: hidden; /* 防止收起时内容溢出 */
}

/* 🔥 PC端侧边栏完全收起 (保留你的逻辑) */
body.sidebar-closed .sidebar {
    width: 80px; /* ⚠️ 修改：通常 Sidebar Layout 收起时不建议为0，改为80px显示图标，如果你确实想完全隐藏改为 0 */
}

/* 如果你确实想要完全隐藏 (width: 0)，保持你原来的代码如下：
   (但我建议如果是 Sidebar Dashboard Layout，收起变成图标栏体验更好。
    下面保留你原始的 width: 0 逻辑，如果你想改图标栏，把上面改成80px，下面 width:0 删掉)
*/
body.sidebar-closed .sidebar {
    width: 0; 
    border-right: none;
}

/* 收起时隐藏 Logo 文字 */
body.sidebar-closed .brand-name { display: none; }
body.sidebar-closed .brand { justify-content: center; padding: 0; }
body.sidebar-closed .brand-icon { margin-right: 0; font-size: 24px; }

/* 收起时隐藏菜单文字 */
body.sidebar-closed .nav-item span { display: none; }
body.sidebar-closed .nav-item { justify-content: center; padding: 14px 0; }
body.sidebar-closed .nav-item i { width: auto; margin: 0; font-size: 20px; }

/* 收起时隐藏用户信息细节 */
body.sidebar-closed .user-info, 
body.sidebar-closed .btn-logout,
body.sidebar-closed .guest-info span, 
body.sidebar-closed .btn-login-trigger {
    display: none !important;
}
body.sidebar-closed .user-profile-link { justify-content: center; margin: 0; }
body.sidebar-closed .mini-avatar { margin: 0; }

/* Logo */
.brand {
    height: 70px; /* 稍微调矮一点 */
    display: flex;
    align-items: center;
    padding: 0 24px;
    font-size: 22px;
    font-weight: bold;
    color: var(--primary);
    border-bottom: 1px solid transparent; /* 预留 */
}
.brand-icon { margin-right: 10px; color: #fab1a0; }

/* 导航菜单 */
.nav-menu {
    flex: 1;
    padding: 20px 15px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--text-gray);
    border-radius: 12px;
    margin-bottom: 5px;
    transition: all 0.2s ease;
    font-size: 15px;
    cursor: pointer;
}

.nav-item i { width: 30px; font-size: 18px; }

.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: var(--text-white);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(108, 92, 231, 0.2) 0%, transparent 100%);
    color: var(--primary);
    border-left: 3px solid var(--primary);
}

/* 底部用户信息区 */
.sidebar-footer {
    padding: 20px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-sidebar);
}

/* 已登录样式 */
.user-card { display: flex; align-items: center; gap: 10px; }

.user-profile-link {
    display: flex; align-items: center; gap: 10px;
    flex: 1; overflow: hidden;
    cursor: pointer; color: inherit;
    transition: opacity 0.2s;
}
.user-profile-link:hover { opacity: 0.8; }

.user-avatar {
    width: 38px; height: 38px; border-radius: 50%; object-fit: cover;
    border: 2px solid var(--border-color); /* 改为淡色边框 */
    flex-shrink: 0;
}
.user-info { flex: 1; overflow: hidden; }
.user-name { font-weight: bold; font-size: 14px; white-space: nowrap; text-overflow: ellipsis; overflow: hidden;}
.user-points { font-size: 12px; color: #fab1a0; margin-top: 2px; }

.btn-logout {
    color: var(--text-gray); opacity: 0.7; transition: 0.3s;
    cursor: pointer; padding: 6px;
}
.btn-logout:hover { opacity: 1; color: var(--danger); }

/* 未登录样式 */
.guest-card { display: flex; flex-direction: column; gap: 15px; }
.guest-info { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--text-gray); }
.mini-avatar { width: 30px; height: 30px; border-radius: 50%; background: #333; }

.btn-login-trigger {
    width: 100%; padding: 10px;
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-white);
    border-radius: 6px; cursor: pointer; transition: 0.3s; font-size: 14px;
}
.btn-login-trigger:hover {
    background-color: var(--primary);
    border-color: var(--primary);
}

/* ========== 4. 右侧主内容区 ========== */
.content-area {  
    flex: 1;    
    width: 0;   
    height: 100vh;
    overflow-y: auto; 
    position: relative;
    background-color: var(--bg-dark); /* 🔥 确保内容区使用深灰蓝 */
}

/* ========== 5. 弹窗 (Modal) 样式 ========== */
.hidden { display: none !important; }

.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    z-index: 100001;
    display: flex; justify-content: center; align-items: center;
}

.modal-container {
    background: var(--bg-card); /* 🔥 使用新的卡片背景色 */
    width: 420px;
    border-radius: 16px;
    padding: 30px;
    position: relative;
    box-shadow: 0 20px 50px rgba(0,0,0,0.6);
    border: 1px solid var(--border-color);
}

.modal-close {
    position: absolute; top: 15px; right: 20px;
    font-size: 24px; cursor: pointer; color: var(--text-gray);
    transition: 0.2s;
}
.modal-close:hover { color: white; }

.modal-tabs {
    display: flex; border-bottom: 2px solid var(--border-color); margin-bottom: 25px;
}

.modal-tab {
    flex: 1; text-align: center; padding: 12px; cursor: pointer; color: var(--text-gray); position: relative; transition: 0.3s;
}

.modal-tab.active { color: var(--text-white); font-weight: bold; }
.modal-tab.active::after {
    content: ''; position: absolute; bottom: -2px; left: 0; width: 100%; height: 2px; background-color: var(--primary);
}

.form-group { margin-bottom: 20px; }
.form-group input {
    width: 100%; padding: 12px; 
    background: #121216; /* 输入框背景比卡片更深 */
    border: 1px solid var(--border-color); 
    border-radius: 8px; color: white; outline: none; transition: 0.3s;
}
.form-group input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(108, 92, 231, 0.2); }

.code-group { display: flex; gap: 10px; }
.btn-code { flex: 1; background: #3e3e5e; border: none; color: white; border-radius: 8px; cursor: pointer; }

.btn-primary-block {
    width: 100%; padding: 12px; background-color: var(--primary); color: white; border: none; border-radius: 8px; font-size: 16px; cursor: pointer; transition: 0.3s; margin-top: 10px; font-weight: bold;
}
.btn-primary-block:hover { background-color: var(--primary-hover); }

/* =========================================
   📱 移动端全局适配 (侧滑抽屉模式)
   ========================================= */
@media screen and (max-width: 768px) {
    /* 1. 布局调整 */
    .app-container { position: relative; }

    /* 2. 侧边栏：左侧抽屉 */
    .sidebar {
        position: fixed; top: 0; left: 0;
        /* bottom: 0; <--- 删除这行，我们要用高度来控制 */
        
        width: 260px !important;
        
        /* 🔥 核心修改开始：解决遮挡问题的关键 */
        height: 100vh;             /* 兼容旧版浏览器 */
        height: 100dvh !important; /* 关键：动态计算高度，减去浏览器工具栏区域 */
        /* 🔥 核心修改结束 */

        transform: translateX(-100%);
        z-index: 9999;
        box-shadow: 2px 0 10px rgba(0,0,0,0.5);
        
        /* 确保它是 Flex 布局，这样中间的 nav-menu 才会自动收缩，把 footer 露出来 */
        display: flex !important;
        flex-direction: column !important;
    }

    /* 🔥 新增：给底部增加一点安全距离，防止手指太粗点不到 */
    .sidebar .sidebar-footer {
        padding-bottom: calc(20px + env(safe-area-inset-bottom)) !important;
    }
    
    /* 激活状态 */
    body.mobile-nav-open .sidebar { transform: translateX(0); }

    /* 3. 恢复显示 */
    .sidebar .nav-menu { display: block; }
    .nav-item {
        flex-direction: row !important;
        justify-content: flex-start !important;
        font-size: 15px !important;
        margin-bottom: 8px !important;
    }
    .sidebar .brand { display: flex !important; }
    .sidebar .sidebar-footer { display: block !important; }

    /* 4. 内容区域 */
    .content-area { width: 100% !important; padding-bottom: 0 !important; }
}

/* ========== 6. 顶部导航条与汉堡按钮 (配合JS使用) ========== */
.top-bar {
    height: 60px;
    display: flex; align-items: center;
    padding: 0 20px;
    /* 如果你的页面设计里需要这个TopBar常驻在内容区上方，可以保留 */
}

.btn-toggle-nav {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-gray);
    width: 36px; height: 36px;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.3s;
    display: flex; align-items: center; justify-content: center;
}
.btn-toggle-nav:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}