/* 聊天容器样式 */
.chat-container {
    display: flex;
    flex-direction: column;
    background-color: var(--sidebar-bg);
    box-shadow: -1px 0 5px var(--shadow-color);
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    background-color: var(--sidebar-bg);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-color);
    font-size: 1rem;
    box-shadow: 0 1px 2px var(--shadow-color);
    position: relative;
}

.chat-header-left {
    display: flex;
    align-items: center;
    width: 100%;
    justify-content: center;
    position: absolute;
    left: 0;
    right: 0;
}

.chat-header-right {
    display: flex;
    align-items: center;
    z-index: 1;
    position: relative;
    margin-left: auto;
}

.chat-top-controls {
    display: flex;
    justify-content: space-between;
    padding: 14px 20px;
    background-color: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-color);
}

.chat-top-controls .btn {
    font-size: 0.85rem;
    padding: 6px 12px;
}

/* API设置面板 */
#api_settings {
    padding: 20px;
    background-color: var(--bg-color);
    border-bottom: 1px solid var(--border-color);
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
    max-height: 0;
    opacity: 0;
    padding-top: 0;
    padding-bottom: 0;
}

#api_settings.show {
    max-height: 300px;
    opacity: 1;
    padding: 20px;
}

.setting-group {
    margin-bottom: 16px;
}

.setting-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    color: var(--light-text);
    font-size: 0.9rem;
}

.setting-group select, 
.setting-group input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background-color: var(--input-bg);
    font-size: 0.9rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.setting-group select:focus, 
.setting-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-light);
}

/* 聊天消息区域 */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background-color: var(--bg-color);
}

.message {
    margin-bottom: 0;
    max-width: 90%;
    border-radius: var(--radius-md);
    padding: 14px 16px;
    position: relative;
    font-size: 0.95rem;
    line-height: 1.5;
    animation: messageAppear 0.3s ease;
    box-shadow: 0 1px 2px var(--shadow-color);
}

@keyframes messageAppear {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.ai-message {
    background-color: var(--sidebar-bg);
    align-self: flex-start;
    margin-right: auto;
    border: 1px solid var(--border-color);
}

/* 增强AI消息中JSON格式显示 */
.ai-message .json-content {
    margin-top: 12px;
    margin-bottom: 12px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.9rem;
    background-color: #f8f9fa;
    color: #333;
    padding: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid #e5e7eb;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-x: auto;
    max-height: 500px;
    overflow-y: auto;
    line-height: 1.5;
}

/* JSON语法高亮 */
.json-content .json-key {
    color: #0550ae;
    font-weight: 500;
}

.json-content .json-string {
    color: #22863a;
}

.json-content .json-number {
    color: #986801;
}

.json-content .json-boolean {
    color: #005cc5;
    font-weight: 500;
}

.json-content .json-null {
    color: #5a5a5a;
    font-style: italic;
}

.user-message {
    background-color: var(--primary-light);
    align-self: flex-end;
    margin-left: auto;
    border: 1px solid var(--primary-light);
}

/* 聊天控制区域 */
.chat-controls {
    padding: 16px 20px;
    background-color: var(--sidebar-bg);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 12px;
    position: relative;
}

#chat_input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    outline: none;
    resize: none;
    height: 50px;
    min-height: 50px;
    max-height: 150px;
    font-family: inherit;
    overflow-y: auto;
    background-color: var(--input-bg);
    font-size: 0.95rem;
    box-shadow: 0 1px 3px var(--shadow-color);
    transition: border-color 0.2s, box-shadow 0.2s;
}

#chat_input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-light);
}

#send_button {
    padding: 12px;
    min-width: 50px;
    height: 50px;
    background-color: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#send_button:hover {
    background-color: var(--primary-dark);
    transform: translateY(-1px);
}

#send_button:active {
    transform: translateY(0);
}

/* 思维导图修改建议 */
.mindmap-modification {
    margin-top: 10px;
    padding: 12px;
    background-color: #f0f7ff;
    border: 1px solid #d0e3ff;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    max-height: 300px;
    overflow-y: auto;
}

.modification-controls {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 8px;
}

.modification-controls button {
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.apply-button {
    background-color: var(--primary-color);
    color: white;
    border: 1px solid var(--primary-color);
}

.apply-button:hover {
    background-color: var(--primary-dark);
}

.reject-button {
    background-color: white;
    color: #666;
    border: 1px solid #ddd;
}

.reject-button:hover {
    background-color: #f5f5f5;
    color: #333;
}

/* 侧边编辑器样式 */
.sidebar-editor {
    position: fixed;
    top: 0;
    right: -400px; /* 默认隐藏在右侧 */
    width: 400px;
    height: 100vh;
    background: var(--sidebar-bg);
    box-shadow: -2px 0 15px rgba(0,0,0,0.12);
    z-index: 1000;
    transition: right 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-left: 1px solid var(--border-color);
}

.sidebar-editor.show {
    right: 0;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--sidebar-bg);
}

.sidebar-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-color);
    font-weight: 600;
}

.sidebar-close {
    cursor: pointer;
    font-size: 22px;
    color: var(--light-text);
    transition: color 0.2s;
}

.sidebar-close:hover {
    color: var(--text-color);
}

.sidebar-content {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: var(--bg-color);
}

.latex-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 14px;
    min-height: 100px;
    margin-bottom: 20px;
    font-family: monospace;
    resize: vertical;
    background-color: var(--input-bg);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.latex-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.complete-button {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    margin-bottom: 24px;
    transition: all 0.2s;
}

.complete-button:hover {
    background: var(--primary-dark);
    transform: translateY(-1px);
}

.complete-button:active {
    transform: translateY(0);
}

.common-formulas-title {
    font-size: 1rem;
    font-weight: 600;
    margin: 24px 0 16px 0;
    color: var(--text-color);
}

.formula-table {
    width: 100%;
    border-collapse: collapse;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border-color);
}

.formula-table th, .formula-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.formula-table th {
    background-color: var(--sidebar-bg);
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.9rem;
}

.formula-table tr:last-child td {
    border-bottom: none;
}

.formula-table tr:hover {
    background-color: var(--hover-bg);
}

.formula-name {
    font-weight: 500;
    color: var(--text-color);
}

.formula-latex {
    font-family: monospace;
    color: var(--light-text);
    font-size: 0.9rem;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    backdrop-filter: blur(4px);
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid var(--border-color);
    border-radius: 50%;
    border-top-color: var(--primary-color);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 响应式设计 */
@media (max-width: 768px) {
    .chat-container, .sidebar-editor {
        width: 100%;
        right: -100%;
    }
    
    .message {
        max-width: 95%;
    }
}

/* 按钮行 */
.button-row {
    display: flex;
    justify-content: flex-end;
    padding: 16px 20px;
    gap: 12px;
    background-color: var(--sidebar-bg);
    border-top: 1px solid var(--border-color);
}

/* 编辑器区域样式 */
.editor-section {
    margin-bottom: 20px;
}

.node-textarea {
    width: 100%;
    min-height: 150px;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    line-height: 1.5;
    resize: vertical;
    background-color: var(--input-bg);
    color: var(--text-color);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.node-textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px var(--primary-light);
}

/* 公式预览区域 */
.preview-area {
    margin: 20px 0;
    padding: 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    min-height: 70px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-color);
}

#node_summary {
    width: 100%;
    padding: 8px;
}
