/* ==================== 布局系统 ==================== */
.app-layout {
    display: grid;
    grid-template-columns: 80px 1fr 320px;
    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);
}

/* ==================== 🎨 优化后的历史侧边栏动画 ==================== */
.history-drawer {
    position: absolute;
    left: 80px;
    top: 0;
    bottom: 0;
    width: 300px;
    background: rgba(20, 20, 40, 0.98);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--glass-border);
    z-index: 30;
    
    /* 🎨 初始状态 */
    transform: translateX(-100%);
    opacity: 0;
    visibility: hidden;
    
    display: flex;
    flex-direction: column;
    
    /* 🎨 关键优化：阴影从无到有的过渡 */
    box-shadow: 10px 0 30px rgba(0,0,0,0);
    
    /* 🎨 流畅的多属性过渡 */
    transition: 
        transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),  /* 轻微回弹效果 */
        opacity 0.25s ease-out,                              /* 透明度淡出 */
        box-shadow 0.35s ease-out,                          /* 阴影消失 */
        visibility 0s linear 0.35s;                          /* 延迟隐藏 */
    
    /* 🎨 性能优化提示 */
    will-change: transform, opacity;
}

/* 🎨 展开状态 */
.history-drawer.open {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
    box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    
    /* 🎨 展开时的过渡（稍有不同的时序） */
    transition: 
        transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1),  /* 轻微回弹 */
        opacity 0.25s ease-in,                               /* 透明度淡入 */
        box-shadow 0.35s ease-in,                           /* 阴影出现 */
        visibility 0s linear 0s;                             /* 立即可见 */
}

/* 🎨 内容项的渐入动画 */
.history-drawer.open .session-item {
    animation: slideInFromLeft 0.4s ease-out backwards;
}

.history-drawer.open .session-item:nth-child(1) { animation-delay: 0.05s; }
.history-drawer.open .session-item:nth-child(2) { animation-delay: 0.08s; }
.history-drawer.open .session-item:nth-child(3) { animation-delay: 0.11s; }
.history-drawer.open .session-item:nth-child(4) { animation-delay: 0.14s; }
.history-drawer.open .session-item:nth-child(5) { animation-delay: 0.17s; }

@keyframes slideInFromLeft {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.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;
    transition: color 0.2s;
}

.icon-btn:hover {
    color: var(--text-primary);
}

.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;
}

.session-item:hover {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.1);
}

.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;
    background: none;
    border: none;
    cursor: pointer;
}

.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-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-progress {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
}

/* ==================== 主聊天区域 ==================== */
.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;
}

.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;
}

.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;
}

.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;
}

.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);
}

/* ==================== 话题选择模态框 ==================== */
.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);
}

.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);
}

.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;
}

/* ==================== 🆕 优化后的删除确认弹窗 ==================== */
.delete-confirm-box {
    background: rgba(30, 30, 50, 0.98);
    padding: 1.5rem;
    border-radius: 16px;
    border: none;
    text-align: left;
    width: 90%;
    max-width: 420px;
    box-shadow: 0 0 30px rgba(239, 68, 68, 0.2);
}

.delete-confirm-box h3 {
    font-size: 1.2rem;
    font-weight: 500;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.delete-confirm-box .warning-text {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 1rem;
    line-height: 1.5;
}

.delete-confirm-box .dimgaai-link {
    color: var(--accent-primary);
    text-decoration: underline;
    cursor: pointer;
    transition: color 0.2s;
}

.delete-confirm-box .dimgaai-link:hover {
    color: var(--accent-secondary);
}

.delete-confirm-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* ==================== 🆕 用户菜单弹窗 ==================== */
.user-menu-popup {
    position: fixed;
    left: 90px;
    bottom: 20px;
    background: rgba(30, 30, 50, 0.98);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 0.75rem 0;
    min-width: 240px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    z-index: 101;
    transform: scale(0.95);
    opacity: 0;
    transition: all 0.2s ease;
}

.modal-overlay.active .user-menu-popup {
    transform: scale(1);
    opacity: 1;
}

.user-info {
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
}

.user-email {
    font-size: 0.9rem;
    color: var(--text-primary);
}

.menu-divider {
    height: 1px;
    background: var(--glass-border);
    margin: 0.5rem 0;
}

.menu-item {
    width: 100%;
    background: none;
    border: none;
    padding: 0.75rem 1.25rem;
    text-align: left;
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.menu-item:hover:not(.disabled) {
    background: var(--glass-bg);
}

.menu-item.disabled {
    color: var(--text-secondary);
    cursor: not-allowed;
    opacity: 0.5;
}

.menu-item.logout {
    color: var(--error-color);
}

.menu-item i {
    font-size: 1.1rem;
    width: 20px;
}

/* ==================== 其他 ==================== */
.welcome-placeholder {
    text-align: center;
    margin-top: 15vh;
    opacity: 0.5;
    animation: fadeIn 1s ease;
}

.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; }
}

.quit-prompt {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    padding: 1.5rem;
    margin: 1rem 0;
    text-align: center;
    animation: slideIn 0.4s ease;
}

/* ==================== 认证模态框 ==================== */
.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);
}

.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 {
        display: none;
    }
}

@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 0 1fr 0;
    }
    .sidebar-nav {
        display: none;
    }
    .input-dock {
        padding: 0 1rem;
        bottom: 1rem;
    }
    
    .user-menu-popup {
        left: 10px;
        bottom: 10px;
    }
}

/* ==================== 🆕 历史记录高亮样式==================== */

/* 当前活动会话的高亮样式 */
.session-item {
    transition: all 0.3s ease;
}

.session-item.active {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 1px var(--accent-primary) inset;
}

.session-item.active:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: var(--accent-primary);
}

/* 为当前会话添加左侧指示条 */
.session-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: linear-gradient(to bottom, var(--accent-primary), var(--accent-secondary));
    border-radius: 12px 0 0 12px;
}

/* 当前会话的标题更醒目 */
.session-item.active .session-title {
    color: var(--accent-glow);
    font-weight: 500;
}