:root {
    --bg-deep: #0f0c29;
    --bg-mid: #302b63;
    --bg-light: #24243e;
    --accent-primary: #6366f1; /* Indigo */
    --accent-secondary: #a855f7; /* Purple */
    --accent-glow: #f472b6; /* Pink */
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(255, 255, 255, 0.05);
    --error-color: #ef4444;
    --success-color: #10b981;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: "Alibaba_puhui", -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-deep);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden; /* 禁止body滚动，只让内部滚动 */
}

/* ================= 背景系统 ================= */
.bg-cosmos {
    position: fixed;
    inset: 0;
    z-index: -1;
    background: linear-gradient(to bottom, #0f0c29, #302b63, #24243e);
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: float 20s infinite ease-in-out;
}

.orb-1 { width: 400px; height: 400px; background: var(--accent-primary); top: -100px; left: -100px; }
.orb-2 { width: 500px; height: 500px; background: var(--accent-secondary); bottom: -100px; right: -100px; animation-delay: -5s; }
.orb-3 { width: 300px; height: 300px; background: var(--accent-glow); top: 40%; left: 40%; filter: blur(100px); opacity: 0.2; animation-delay: -10s; }

.grid-overlay {
    position: absolute;
    inset: 0;
    background-image: linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.03) 1px, transparent 1px);
    background-size: 50px 50px;
    mask-image: radial-gradient(circle at center, black 40%, transparent 100%);
}

@keyframes float {
    0%, 100% { transform: translate(0, 0); }
    50% { transform: translate(30px, 50px); }
}

/* ================= 布局系统 ================= */
.app-layout {
    display: grid;
    grid-template-columns: 80px 1fr 320px; /* 左导航 - 主舞台 - 右HUD */
    height: 100vh;
    position: relative;
}

/* 左侧极简导航 */
.sidebar-nav {
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem 0;
    z-index: 20;
}

.logo {
    font-family: sans-serif;
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--text-primary);
    margin-bottom: 3rem;
    background: linear-gradient(135deg, #fff 0%, var(--accent-primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-actions {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    flex: 1;
}

.nav-btn {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.nav-btn:hover, .nav-btn.active {
    background: var(--glass-bg);
    color: var(--text-primary);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.user-avatar-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--accent-primary);
    color: white;
    font-weight: bold;
    font-size: 1rem;
}

.history-drawer {
    position: absolute;
    left: 80px;
    top: 0;
    bottom: 0;
    width: 300px;
    background: rgba(20, 20, 40, 0.95); /* 加深背景，减少杂乱透视 */
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--glass-border);
    
    /* 核心修改：提高层级，覆盖输入框 (input-dock z-index: 20) */
    z-index: 30; 
    
    /* 核心修改：位移 + 可见性控制 */
    transform: translateX(-100%);
    visibility: hidden; /* 收起时完全隐藏，避免毛玻璃穿透 */
    
    /* 收起动画：延迟隐藏 visibility，等待 transform 完成 */
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0.4s;
    
    display: flex;
    flex-direction: column;
    box-shadow: 10px 0 30px rgba(0,0,0,0.5);
}

.history-drawer.open {
    transform: translateX(0);
    visibility: visible;
    /* 展开动画：立即显示 visibility */
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0s;
}

.drawer-header {
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
}

.session-list {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

/* 历史列表项优化 */
.session-item {
    padding: 1rem;
    margin-bottom: 0.8rem;
    background: var(--glass-bg);
    border-radius: 12px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    
    /* 新增：为删除按钮留位置 */
    position: relative;
    padding-right: 36px;
}

/* 新增：删除按钮样式 */
.delete-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    color: var(--text-secondary);
    opacity: 0; /* 默认隐藏 */
    transition: all 0.2s ease;
    z-index: 2;
}

.session-item:hover .delete-btn {
    opacity: 1; /* 悬停整行时显示 */
}

.delete-btn:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444; /* 红色高亮 */
    transform: translateY(-50%) scale(1.1);
}

.session-item:hover {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.1);
}

.session-title {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.4;
}

.session-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.session-tags {
    display: flex;
    gap: 0.25rem;
}

.tag {
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
}

.tag-trait {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.tag-progress {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
}

/* ================= 主舞台 (Chat) 修复滚动 ================= */
.chat-stage {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh; /* 强制占满高度 */
    overflow: hidden; /* 防止父级滚动 */
}

.chat-wrapper {
    width: 100%;
    max-width: 900px;
    height: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
}

.stage-header {
    padding: 1.5rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    z-index: 10;
    flex-shrink: 0; /* 防止header被压缩 */
}

.topic-badge {
    font-size: 0.8rem;
    color: var(--accent-glow);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 0.25rem;
    display: block;
}

#chatTitle {
    font-size: 1.5rem;
    font-weight: 300;
}

.refresh-btn {
    background: rgba(255,255,255,0.1);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
    padding: 0.5rem 1rem;
    border-radius: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.refresh-btn:hover {
    background: rgba(255,255,255,0.2);
}

/* 关键：消息容器配置 */
.messages-container {
    flex: 1; /* 占据剩余空间 */
    overflow-y: auto; /* 允许内部滚动 */
    padding: 2rem 2rem 140px 2rem; /* 底部预留大片空间给输入框，防止遮挡 */
    display: flex;
    flex-direction: column;
    gap: 2rem;
    scroll-behavior: smooth;
    /* 隐藏滚动条但保留功能 */
    scrollbar-width: thin; 
    scrollbar-color: var(--glass-border) transparent;
}

.messages-container::-webkit-scrollbar {
    width: 6px;
}
.messages-container::-webkit-scrollbar-track {
    background: transparent;
}
.messages-container::-webkit-scrollbar-thumb {
    background-color: var(--glass-border);
    border-radius: 3px;
}

/* 消息气泡样式 */
.message {
    max-width: 80%;
    padding: 1.25rem 1.75rem;
    line-height: 1.6;
    position: relative;
    animation: slideIn 0.4s ease;
    word-wrap: break-word;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 24px 24px 4px 24px;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
    color: white;
}

.message-ai {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 24px 24px 24px 4px;
    color: var(--text-primary);
}

/* 输入框区域 - 绝对定位悬浮 */
.input-dock {
    position: absolute;
    bottom: 2rem;
    left: 0;
    right: 0;
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 0 2rem;
    z-index: 20;
    pointer-events: none; /* 让点击穿透dock空白区域 */
}

.input-glass {
    pointer-events: auto; /* 恢复输入框交互 */
    width: 100%;
    max-width: 800px;
    background: rgba(20, 20, 40, 0.75); /* 加深背景防止文字重叠 */
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: 30px;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: flex-end;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    transition: all 0.3s;
}

.input-glass:focus-within {
    background: rgba(20, 20, 40, 0.9);
    border-color: var(--accent-primary);
    box-shadow: 0 0 30px rgba(99, 102, 241, 0.2);
}

#chatInput {
    flex: 1;
    background: transparent;
    border: none;
    color: white;
    padding: 1rem;
    font-size: 1rem;
    font-family: inherit;
    resize: none;
    max-height: 150px;
}

#chatInput:focus {
    outline: none;
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent-primary);
    border: none;
    color: white;
    margin-bottom: 6px;
    margin-left: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    transition: transform 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    transform: scale(1.1) rotate(-10deg);
}

.send-btn:disabled {
    background: #4b5563;
    cursor: not-allowed;
    transform: none;
}

/* ================= HUD 右侧栏 ================= */
.insight-hud {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    border-left: 1px solid rgba(255,255,255,0.05);
    background: rgba(0,0,0,0.1);
    overflow-y: auto;
}

.hud-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.25rem;
    transition: transform 0.3s, box-shadow 0.3s;
}

.hud-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    border-color: rgba(255,255,255,0.2);
}

.card-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-content, .traits-body {
    font-size: 0.9rem;
    line-height: 1.5;
    color: rgba(255,255,255,0.9);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.update-dot {
    width: 8px;
    height: 8px;
    background: #ef4444;
    border-radius: 50%;
    box-shadow: 0 0 10px #ef4444;
    animation: pulse 2s infinite;
}

.hud-link {
    display: block;
    margin-top: 1rem;
    font-size: 0.8rem;
    color: var(--accent-primary);
    text-decoration: none;
    cursor: pointer;
}

.topic-mini {
    cursor: pointer;
    display: flex;
    flex-direction: column;
    position: relative;
}

.topic-display {
    font-size: 1.1rem;
    font-weight: 500;
}

.icon-indicator {
    position: absolute;
    right: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
}

/* ================= 模态窗口 ================= */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 12, 41, 0.85);
    backdrop-filter: blur(8px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-glass {
    background: rgba(30, 30, 50, 0.95);
    border: 1px solid var(--glass-border);
    border-radius: 24px;
    padding: 2.5rem;
    width: 90%;
    max-width: 700px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    position: relative;
    transform: scale(0.95);
    transition: transform 0.3s ease;
}

.modal-overlay.active .modal-glass {
    transform: scale(1);
}

.modal-header {
    text-align: center;
    margin-bottom: 2rem;
    position: relative;
}

.modal-header h2 {
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
}

.subtitle {
    color: var(--text-secondary);
}

.refresh-icon-btn {
    position: absolute;
    right: 0;
    top: 0;
    background: none;
    border: none;
    color: var(--accent-primary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: transform 0.5s;
}

.refresh-icon-btn:hover {
    transform: rotate(180deg);
}

.topics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.topic-card {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.5rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s;
    position: relative;
    overflow: hidden;
}

.topic-card:hover {
    background: rgba(99, 102, 241, 0.2);
    transform: translateY(-5px);
    border-color: var(--accent-primary);
}

.topic-name {
    font-size: 1.1rem;
    font-weight: bold;
    margin-bottom: 0.25rem;
}

.topic-tag {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.modal-footer {
    text-align: center;
    border-top: 1px solid var(--glass-border);
    padding-top: 1.5rem;
}

.casual-btn {
    background: transparent;
    border: 1px solid var(--text-secondary);
    color: var(--text-primary);
    padding: 0.8rem 2rem;
    border-radius: 30px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.casual-btn:hover {
    background: white;
    color: black;
}

.close-icon {
    position: absolute;
    top: -1rem;
    right: 0;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.welcome-placeholder {
    text-align: center;
    margin-top: 15vh;
    opacity: 0.5;
    animation: fadeIn 1s ease;
}

/* 确认框样式 */
.confirm-box {
    background: #1f2937;
    padding: 2rem;
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    text-align: center;
    width: 90%;
    max-width: 400px;
}

.confirm-actions {
    display: flex;
    gap: 1rem;
    justify-content: center;
    margin-top: 1.5rem;
}

.btn-primary {
    background: var(--accent-primary);
    color: white;
    border: none;
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary:hover {
    background: #4f46e5;
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--glass-border);
    padding: 0.6rem 1.5rem;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-ghost:hover {
    border-color: var(--text-primary);
    color: var(--text-primary);
}

/* 思考动画 */
.thinking-animation {
    padding: 0 0.5rem;
    display: flex;
    align-items: center;
    gap: 4px;
    height: 24px;
}

.thinking-dots div {
    width: 6px;
    height: 6px;
    background: var(--accent-glow);
    border-radius: 50%;
    display: inline-block;
    animation: bounce 1.4s infinite ease-in-out both;
}

.thinking-dots div:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots div:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 0.5; }
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

/* ================= 登录/注册模态框样式 ================= */
.auth-modal {
    max-width: 400px;
}

.auth-tabs {
    display: flex;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid var(--glass-border);
}

.auth-tab {
    flex: 1;
    text-align: center;
    padding: 0.8rem;
    cursor: pointer;
    color: var(--text-secondary);
    position: relative;
    transition: all 0.3s;
}

.auth-tab.active {
    color: var(--text-primary);
    font-weight: bold;
}

.auth-tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 2px;
    background: var(--accent-primary);
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group input {
    width: 100%;
    padding: 0.8rem 1rem;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: white;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s;
}

.form-group input:focus {
    border-color: var(--accent-primary);
}

.auth-btn {
    width: 100%;
    margin-top: 0.5rem;
    padding: 0.8rem;
    font-size: 1rem;
}

.error-msg {
    color: var(--error-color);
    font-size: 0.85rem;
    text-align: center;
    min-height: 1.2em;
}

/* 响应式适配 */
@media (max-width: 1024px) {
    .app-layout {
        grid-template-columns: 60px 1fr 0px; /* 隐藏右侧 */
    }
    .insight-hud {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        transform: translateX(100%);
        transition: transform 0.3s;
        background: #1a1a2e;
        z-index: 30;
    }
    .hud-toggle-btn {
        display: block;
    }
}

@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 0 1fr 0;
    }
    .sidebar-nav {
        display: none;
    }
    .input-dock {
        padding: 0 1rem;
        bottom: 1rem;
    }
}


/* =========================================
   滚动条美化 (添加在文件末尾)
   ========================================= */
.session-list::-webkit-scrollbar {
    width: 4px;
}

.session-list::-webkit-scrollbar-track {
    background: transparent;
}

.session-list::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

.session-list::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}