/* 基础重置和变量 */
:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --background-color: #f8fafc;
    --surface-color: #ffffff;
    --border-color: #e2e8f0;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --code-bg: #f1f5f9;
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* 密码验证遮罩 */
.auth-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.auth-box {
    background: var(--surface-color);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.auth-box h2 {
    margin-bottom: 1rem;
    color: var(--primary-color);
}

.auth-box p {
    margin-bottom: 1.5rem;
    color: var(--text-muted);
}

.auth-box input {
    width: 100%;
    padding: 0.75rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
}

.auth-box input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* 主应用布局 */
.main-app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 顶部栏 */
.header {
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.logo {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-color);
}

.status-indicators {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.status-indicator {
    font-size: 0.875rem;
    padding: 0.25rem 0.5rem;
    background: var(--code-bg);
    border-radius: 4px;
}

.model-info {
    font-size: 0.875rem;
    color: var(--text-muted);
    background: var(--code-bg);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    padding: 0.5rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.header-btn:hover {
    background: var(--code-bg);
}

.header-btn.logout:hover {
    background: #fee2e2;
}

/* 主内容区 */
.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* 侧边栏 */
.sidebar {
    background: var(--surface-color);
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    scrollbar-width: thin;
}

.left-sidebar {
    width: 280px;
    padding: 1rem;
}

.right-sidebar {
    width: 320px;
    border-left: 1px solid var(--border-color);
    border-right: none;
}

.sidebar-section {
    margin-bottom: 2rem;
}

.sidebar-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-color);
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-color);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.875rem;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.checkbox-label input {
    width: auto !important;
}

/* 按钮样式 */
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-small {
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-secondary {
    background: var(--code-bg);
    color: var(--text-color);
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.btn-danger {
    background: var(--danger-color);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.75rem;
}

/* 统计信息 */
.stats {
    background: var(--code-bg);
    padding: 1rem;
    border-radius: 8px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
    font-size: 0.875rem;
}

.stat-item:last-child {
    margin-bottom: 0;
}

/* 聊天区域 */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-container {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    scrollbar-width: thin;
}

.welcome-message {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-muted);
}

.welcome-message h2 {
    color: var(--text-color);
    margin-bottom: 1rem;
}

/* 消息样式 */
.message {
    margin-bottom: 1.5rem;
    max-width: 100%;
}

.message-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}

.message-role {
    font-weight: 600;
    font-size: 0.875rem;
}

.message-role.user {
    color: var(--primary-color);
}

.message-role.assistant {
    color: var(--success-color);
}

.message-actions {
    display: flex;
    gap: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s;
}

.message:hover .message-actions {
    opacity: 1;
}

.message-content {
    background: var(--surface-color);
    padding: 1rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    line-height: 1.6;
}

.message.user .message-content {
    background: #eff6ff;
    border-left: 3px solid var(--primary-color);
}

.message.assistant .message-content {
    background: #f0fdf4;
    border-left: 3px solid var(--success-color);
}

/* 代码块样式 */
.code-block {
    position: relative;
    margin: 1rem 0;
}

.code-header {
    background: var(--code-bg);
    padding: 0.5rem 1rem;
    border-radius: 8px 8px 0 0;
    font-size: 0.875rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.code-actions {
    display: flex;
    gap: 0.5rem;
}

.code-block pre {
    margin: 0;
    background: var(--code-bg) !important;
    padding: 1rem;
    border-radius: 0 0 8px 8px;
    overflow-x: auto;
    font-size: 0.875rem;
}

.code-block code {
    background: none !important;
}

/* 项目检测 */
.project-detection {
    background: #fefce8;
    border: 1px solid #fde047;
    border-radius: 8px;
    padding: 1rem;
    margin: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.project-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.project-icon {
    font-size: 1.25rem;
}

/* 输入区域 */
.input-area {
    background: var(--surface-color);
    border-top: 1px solid var(--border-color);
    padding: 1rem;
}

.input-container {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    margin-bottom: 1rem;
}

#messageInput {
    flex: 1;
    min-height: 80px;
    max-height: 200px;
    resize: vertical;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem;
    font-family: inherit;
    font-size: 0.95rem;
}

#messageInput:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.input-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.bottom-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

/* 文件管理器 */
.file-manager {
    display: flex;
    flex-direction: column;
}

.file-manager-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
}

.close-btn:hover {
    background: var(--code-bg);
}

.file-manager-toolbar {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 0.5rem;
}

.file-tree {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem;
}

.file-preview {
    height: 200px;
    border-top: 1px solid var(--border-color);
    padding: 1rem;
    overflow-y: auto;
    background: var(--code-bg);
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.8rem;
}

.no-selection {
    color: var(--text-muted);
    text-align: center;
    padding-top: 2rem;
}

/* 文件树项目 */
.tree-item {
    padding: 0.25rem 0.5rem;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tree-item:hover {
    background: var(--code-bg);
}

.tree-item.selected {
    background: #dbeafe;
    color: var(--primary-color);
}

.tree-item.folder {
    font-weight: 500;
}

.tree-children {
    margin-left: 1rem;
    border-left: 1px solid var(--border-color);
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    z-index: 10000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal-content {
    background-color: var(--surface-color);
    margin: 5% auto;
    padding: 0;
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.modal-close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    padding: 1rem;
    cursor: pointer;
}

.modal-close:hover {
    color: #000;
}

#modalBody {
    padding: 1rem 2rem 2rem;
}

/* 错误消息 */
.error-msg {
    color: var(--danger-color);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* 加载动画 */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* 打字效果 */
.typing {
    display: inline-block;
    overflow: hidden;
    border-right: 2px solid var(--primary-color);
    animation: blink-cursor 1s infinite;
}

@keyframes blink-cursor {
    0%, 50% { border-color: transparent; }
    51%, 100% { border-color: var(--primary-color); }
}
/* 响应式设计 */
@media (max-width: 768px) {
    .left-sidebar {
        width: 240px;
    }
    
    .right-sidebar {
        width: 280px;
    }
    
    .header {
        padding: 0.5rem;
    }
    
    .logo {
        font-size: 1rem;
    }
    
    .input-container {
        flex-direction: column;
        align-items: stretch;
    }
    
    .bottom-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    .main-content {
        position: relative;
    }
    
    .sidebar {
        position: absolute;
        top: 0;
        height: 100%;
        z-index: 100;
        box-shadow: var(--shadow-lg);
    }
    
    .left-sidebar {
        left: -280px;
        transition: left 0.3s ease;
    }
    
    .left-sidebar.open {
        left: 0;
    }
    
    .right-sidebar {
        right: -320px;
        transition: right 0.3s ease;
    }
    
    .right-sidebar.open {
        right: 0;
    }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--background-color);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* 特殊状态 */
.hidden {
    display: none !important;
}

.disabled {
    opacity: 0.6;
    pointer-events: none;
}

/* 动画 */
.fade-in {
    animation: fadeIn 0.3s ease-in;
}

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

.slide-in {
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from { transform: translateX(-100%); }
    to { transform: translateX(0); }
}

/* 高亮效果 */
.highlight {
    background-color: #fef3cd;
    animation: highlight-fade 2s ease-out;
}

@keyframes highlight-fade {
    0% { background-color: #fff3cd; }
    100% { background-color: transparent; }
}

/* 代码语法高亮主题调整 */
.hljs {
    background: var(--code-bg) !important;
    color: var(--text-color) !important;
}

/* 文件图标 */
.file-icon {
    width: 16px;
    height: 16px;
    display: inline-block;
}

/* 进度条 */
.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s ease;
}

/* 提示工具 */
.tooltip {
    position: relative;
    cursor: help;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 1000;
}

.tooltip:hover::after {
    opacity: 1;
}