/* ============ 以下为用户原版 CSS（一字未改） ============ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', 'Microsoft YaHei', sans-serif;
}

body {
    background: linear-gradient(135deg, #f5f7fa 0%, #e4e7eb 100%);
    color: #333;
    height: 100vh;
    overflow: hidden;
    font-size: 16px;
    padding: 20px;           /* 四周留白 */
    box-sizing: border-box;
}

.container {
    display: flex;
    height: 100%;
    width: 100%;
    max-width: 1400px;       /* 最大宽度，不撑满 */
    margin: 0 auto;          /* 水平居中 */
    gap: 20px;               /* 两栏间距 */
}
.chat-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.knowledge-panel { width: 320px; display: flex; flex-direction: column; border-left: 1px solid #eee; background: #fff; }
@media (max-width: 1024px) { .knowledge-panel { width: 280px; } .history-panel { width: 180px; } }
@media (max-width: 768px) { .knowledge-panel { display: none; } .history-panel { display: none; } }

.chat-panel, .knowledge-panel {
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

.chat-panel { flex: 3; }
.knowledge-panel { flex: 1.5; }

/* 顶部栏 */
.panel-header {
    padding: 20px 24px;
    background: linear-gradient(135deg, #4361ee 0%, #3a0ca3 100%);
    color: white;
    flex-shrink: 0;
}

.panel-header h2 {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.5rem;
    font-weight: 600;
}

.panel-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 24px;
    overflow: hidden;
    position: relative;
}

/* 聊天头部 */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    width: 44px;
    height: 44px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #4361ee;
    font-weight: bold;
    font-size: 1.2rem;
    box-shadow: 0 6px 12px rgba(0,0,0,0.1);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.2);
    padding: 8px 16px;
    border-radius: 24px;
    font-size: 0.95rem;
    backdrop-filter: blur(4px);
}

.status-dot {
    width: 12px;
    height: 12px;
    background: #4ade80;
    border-radius: 50%;
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%{opacity:1; transform:scale(1);}
    50%{opacity:0.6; transform:scale(0.9);}
    100%{opacity:1; transform:scale(1);}
}

/* 聊天记录 */
.chat-history {
    flex: 1;
    background: #f8fafc;
    border-radius: 20px;
    padding: 24px;
    overflow-y: auto;
    margin-bottom: 20px;
    border: 1px solid #f0f4f9;
    scrollbar-gutter: stable;
}

.message {
    padding: 16px 20px;
    border-radius: 20px;
    margin-bottom: 20px;
    max-width: 85%;
    line-height: 1.6;
}

.ai-message {
    background: white;
    border:1px solid #f0f4f9;
    box-shadow: 0 2px 8px rgba(0,0,0,0.03);
}

.user-message {
    background: linear-gradient(135deg, #4361ee 0%, #4895ef 100%);
    color: white;
    margin-left: auto;
    box-shadow: 0 4px 12px rgba(67, 97, 238, 0.2);
}

/* 功能按钮 */
.function-buttons {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-bottom: 16px;
    flex-shrink: 0;
    flex-wrap: nowrap;
    width: 100%;
}
.func-btn {
    padding: 8px 10px;
    border-radius: 20px;
    background: #f1f5f9;
    border: 1px solid #e8edf3;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    transition: all 0.2s ease;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.func-btn:hover {
    background: #e8edf3;
}

.func-btn.active {
    background: linear-gradient(135deg, #4361ee 0%, #3a0ca3 100%);
    color:white;
    border-color: transparent;
    box-shadow: 0 4px 12px rgba(67, 97, 238, 0.2);
}

/* 输入框区域 */
.input-container {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-shrink: 0;
}

#user-input {
    flex: 1;
    min-height: 80px;
    max-height: 200px;
    padding: 18px 24px;
    border: 1px solid #e8edf3;
    border-radius: 30px;
    resize: none;
    font-size: 1rem;
    line-height: 1.5;
    transition: border-color 0.2s ease;
    overflow-y: auto;
}

#user-input:focus {
    outline: none;
    border-color: #4361ee;
    box-shadow: 0 0 0 3px rgba(67, 97, 238, 0.1);
}

#send-button, #stop-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    color: white;
    font-size: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

#send-button {
    background: linear-gradient(135deg, #4361ee 0%, #3a0ca3 100%);
    box-shadow: 0 4px 12px rgba(67, 97, 238, 0.3);
}

#send-button:hover {
    transform: scale(1.05);
}

#stop-button {
    background: #ff5454;
    display:none;
    box-shadow: 0 4px 12px rgba(255, 84, 84, 0.3);
}

#stop-button:hover {
    transform: scale(1.05);
}

/* 知识库样式 */
.kb-info {
    display: flex;
    gap: 16px;
    margin-bottom: 24px;
    flex-shrink: 0;
}

.kb-info-item {
    flex: 1;
    background: #f8fafc;
    padding: 16px 20px;
    border-radius: 16px;
    border: 1px solid #f0f4f9;
}

.info-label {
    font-size:13px;
    color:#64748b;
    margin-bottom: 4px;
}

.info-value {
    font-weight:600;
    font-size:16px;
    color: #252a34;
}

.source-list {
    flex:1;
    background: #f8fafc;
    border-radius:16px;
    padding:20px;
    border:1px solid #f0f4f9;
    overflow-y:auto;
    min-height: 0;
    scrollbar-gutter: stable;
}

.source-title {
    font-weight:600;
    margin-bottom:16px;
    display:flex;
    align-items:center;
    gap:8px;
    font-size: 1rem;
    color: #252a34;
}

.source-item {
    padding:12px 8px;
    border-bottom:1px solid #f0f4f9;
    display:flex;
    align-items:center;
    gap:10px;
    transition: background 0.2s ease;
}

.source-item:hover {
    background: #f1f5f9;
    border-radius: 8px;
}

.source-icon {
    color:#4361ee;
    font-size: 1.1rem;
}

.source-name {
    font-size: 0.95rem;
    color: #252a34;
}

/* 滚动条美化 */
.chat-history::-webkit-scrollbar, .source-list::-webkit-scrollbar, #user-input::-webkit-scrollbar {
    width: 6px;
}

.chat-history::-webkit-scrollbar-track, .source-list::-webkit-scrollbar-track, #user-input::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}

.chat-history::-webkit-scrollbar-thumb, .source-list::-webkit-scrollbar-thumb, #user-input::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

.chat-history::-webkit-scrollbar-thumb:hover, .source-list::-webkit-scrollbar-thumb:hover, #user-input::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* 手机适配 */
@media (max-width:900px) {
    .container{
        flex-direction:column;
        gap: 20px;
        padding: 16px;
        height: 100vh;
        overflow-y: auto;
    }
    .knowledge-panel{
        min-height:100px;
        height: auto;
        flex: none;
    }
    .chat-panel {
        height: calc(100vh - 80px);
        flex: none;
    }
    .chat-panel, .knowledge-panel {border-radius: 16px;}
    .panel-content {padding: 16px;}
    .chat-history {padding: 16px; margin-bottom: 16px;}
    .function-buttons {margin-bottom: 16px;}
    #user-input {min-height: 60px; height: 60px; padding: 14px 18px;}
    #send-button, #stop-button {width: 50px; height: 50px;}
}

/* 图标样式重置 */
#send-button i, #stop-button i {
    margin: 0;
    padding: 0;
    font-size: 1.1rem;
}

/* 焦点样式优化 */
:focus-visible {
    outline: 2px solid #4361ee;
    outline-offset: 2px;
}

/* 选中文本样式 */
::-moz-selection {
    background: #4361ee;
    color: white;
}
::selection {
    background: #4361ee;
    color: white;
}

/* 知识库统计信息样式 */
.kb-info {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid #e9ecef;
    margin-bottom: 12px;
}

.kb-info-item {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 10px 12px;
    text-align: center;
    transition: all 0.2s ease;
}

.kb-info-item:hover {
    background: #e9ecef;
    transform: translateY(-1px);
}

.kb-info-item .info-label {
    font-size: 11px;
    color: #6c757d;
    margin-bottom: 4px;
    font-weight: 500;
}

.kb-info-item .info-value {
    font-size: 16px;
    font-weight: 600;
    color: #2d3436;
}

.kb-info-item:last-child {
    grid-column: span 2;
}

/* 响应式调整 */
@media (max-width: 768px) {
    .kb-info {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .kb-info-item {
        padding: 8px 10px;
    }

    .kb-info-item .info-value {
        font-size: 14px;
    }
}

/* 三列标签样式 */
.kb-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid #e9ecef;
    margin-bottom: 12px;
}

.kb-tab {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 12px 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    border: 2px solid transparent;
}

.kb-tab:hover {
    background: #e9ecef;
    transform: translateY(-2px);
}

.kb-tab.active {
    background: #e8f0fe;
    border-color: #4361ee;
    box-shadow: 0 4px 12px rgba(67, 97, 238, 0.15);
}

.kb-tab .tab-icon {
    font-size: 24px;
    margin-bottom: 4px;
}

.kb-tab .tab-label {
    font-size: 13px;
    font-weight: 600;
    color: #333;
    margin-bottom: 2px;
}

.kb-tab .tab-count {
    font-size: 12px;
    color: #6c757d;
}

.kb-tab.active .tab-count {
    color: #4361ee;
    font-weight: 600;
}

/* 列表标题动态 */
.source-title {
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    color: #252a34;
}

/* AI正在输入的光标动画 */
@keyframes blink-caret {
    from, to { border-right-color: transparent }
    50% { border-right-color: #009933; }
}
.ai-typing {
    border-right: 2px solid #009933;
    animation: blink-caret 0.75s step-end infinite;
    padding-right: 4px;
}

/* ============ 追加：历史会话抽屉（仿 DeepSeek 滑出式） ============ */
.chat-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.menu-btn {
    background: rgba(255,255,255,0.18);
    border: none;
    color: white;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    font-size: 17px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}
.menu-btn:hover { background: rgba(255,255,255,0.32); }

.drawer-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.45);
    z-index: 1050;
    opacity: 0;
    transition: opacity 0.3s ease;
}
.drawer-overlay.open { display: block; opacity: 1; }

.history-drawer {
    position: fixed;
    top: 0; left: -300px;
    width: 280px; height: 100%;
    background: #fff;
    z-index: 1100;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: 4px 0 24px rgba(0,0,0,0.15);
}
.history-drawer.open { left: 0; }

.drawer-header {
    padding: 18px 20px;
    background: linear-gradient(135deg, #4361ee 0%, #3a0ca3 100%);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}
.drawer-header h3 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.drawer-new {
    background: rgba(255,255,255,0.22);
    border: none; color: white;
    width: 30px; height: 30px;
    border-radius: 50%;
    cursor: pointer; font-size: 13px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.2s;
}
.drawer-new:hover { background: rgba(255,255,255,0.4); }

.drawer-content {
    flex: 1; overflow-y: auto;
    padding: 12px;
    background: #f8fafc;
}

.session-item {
    position: relative;
    padding: 12px 14px;
    border-radius: 10px;
    cursor: pointer;
    margin-bottom: 8px;
    background: #fff;
    border: 1px solid #e8edf3;
    transition: all 0.2s;
}
.session-item:hover, .session-item.active {
    background: #e8edff;
    border-color: #c7d2fe;
}
.session-title {
    font-size: 13px; font-weight: 500; color: #333;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    padding-right: 22px;
}
.session-date {
    font-size: 11px; color: #999; margin-top: 4px;
}
.session-del {
    position: absolute; top: 8px; right: 8px;
    background: none; border: none; color: #bbb;
    cursor: pointer; font-size: 12px;
    display: none;
}
.session-item:hover .session-del,
.session-item.active .session-del { display: block; }
.session-del:hover { color: #e74c3c; }

.drawer-empty {
    padding: 24px 12px;
    color: #999;
    text-align: center;
    font-size: 13px;
}



@media (max-width: 900px) {
    body {
        padding: 12px;
        overflow-y: auto;
    }
    .container {
        flex-direction: column;
        gap: 16px;
        height: auto;
        min-height: calc(100vh - 24px);
    }
    .chat-panel {
        flex: none;
        width: 100%;          /* 关键：宽度撑满容器 */
        height: 90vh;
    }
    .knowledge-panel {
        flex: none;
        width: 100%;          /* 关键：宽度撑满容器，和上面等宽 */
        min-height: 400px;
        height: auto;
    }
}