:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #6b7280;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-light: #f9fafb;
    --border-color: #e5e7eb;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --sidebar-width: 280px;
    --sidebar-width-sm: 60px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: var(--bg-light);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.navbar {
    box-shadow: var(--shadow-md);
}

/* 三栏布局 */
.main-container {
    display: flex;
    flex: 1;
    height: calc(100vh - 56px - 50px);
    overflow: hidden;
}

/* 侧边栏通用样式 */
.sidebar {
    width: var(--sidebar-width);
    background: white;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

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

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

.sidebar-header h6 {
    margin: 0;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem;
}

/* 左侧对话历史 */
.sidebar-left {
    background: #f8fafc;
}

#history-list {
    padding: 0;
}

.history-item {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 10px;
}

.history-item:hover {
    background: rgba(79, 70, 229, 0.1);
}

.history-item.active {
    background: rgba(79, 70, 229, 0.15);
}

.history-item i {
    color: var(--primary-color);
    flex-shrink: 0;
}

.history-item-content {
    flex: 1;
    overflow: hidden;
}

.history-item-title {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.empty-hint {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-secondary);
}

.empty-hint i {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    opacity: 0.5;
}

.empty-hint p {
    margin: 0;
    font-size: 0.875rem;
}

/* 右侧状态面板 */
.status-section {
    margin-bottom: 1rem;
}

.status-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px dashed var(--border-color);
}

.status-item:last-child {
    border-bottom: none;
}

.status-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    display: flex;
    align-items: center;
}

.status-label i {
    width: 20px;
}

.status-value {
    font-weight: 500;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.status-value.idle {
    color: var(--success-color);
}

.status-value.working {
    color: var(--primary-color);
}

.status-value.error {
    color: var(--danger-color);
}

/* 思考过程 */
#thinking-section h6 {
    font-size: 0.875rem;
    color: var(--warning-color);
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
}

.thinking-text {
    padding: 0.75rem;
    background: #fffbeb;
    border-radius: 8px;
    font-size: 0.8rem;
    color: #92400e;
    line-height: 1.5;
    max-height: 200px;
    overflow-y: auto;
    white-space: pre-wrap;
}

.thinking-text:empty::before {
    content: '正在分析...';
    color: var(--text-secondary);
    font-style: italic;
}

/* 主聊天区域 */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem;
    min-width: 0;
    background: var(--bg-light);
}

.chat-container {
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    background: #f8fafc;
}

.message {
    display: flex;
    margin-bottom: 1rem;
    animation: fadeIn 0.3s ease;
}

.welcome-message {
    opacity: 0.7;
}

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

.message.user-message {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.bot-message .message-avatar {
    background: linear-gradient(135deg, var(--primary-color), #7c3aed);
    color: white;
}

.user-message .message-avatar {
    background: var(--success-color);
    color: white;
}

.message-content {
    max-width: 75%;
    padding: 0.75rem 1rem;
    border-radius: 12px;
    background: white;
    box-shadow: var(--shadow-sm);
    margin: 0 0.75rem;
}

.user-message .message-content {
    background: var(--primary-color);
    color: white;
}

.message-content p {
    margin: 0;
    line-height: 1.6;
}

.message-content code {
    background: rgba(0, 0, 0, 0.1);
    padding: 0.125rem 0.25rem;
    border-radius: 4px;
    font-size: 0.875em;
}

.user-message .message-content code {
    background: rgba(255, 255, 255, 0.2);
}

.message-content pre {
    background: #1f2937;
    color: #e5e7eb;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0.5rem 0;
}

.message-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.message.typing .message-content::after {
    content: '...';
    animation: typing 1s infinite;
}

@keyframes typing {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

.model-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: white;
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 10px;
    margin-bottom: 8px;
    font-weight: 500;
}

.model-badge i {
    font-size: 0.65rem;
}

.thinking-section {
    margin-top: 12px;
    border-top: 1px dashed #e5e7eb;
    padding-top: 10px;
}

.thinking-section summary {
    cursor: pointer;
    color: #f59e0b;
    font-size: 0.8rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 6px;
}

.thinking-section summary:hover {
    color: #d97706;
}

.thinking-content {
    margin-top: 8px;
    padding: 10px;
    background: #fffbeb;
    border-radius: 8px;
    font-size: 0.85rem;
    color: #92400e;
    max-height: 200px;
    overflow-y: auto;
    line-height: 1.5;
}

.thinking-content p {
    margin: 0;
}

.typing-text {
    color: var(--text-secondary);
    font-style: italic;
}

.typing-dots {
    display: inline-flex;
    gap: 4px;
    margin-left: 8px;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--primary-color);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.message.system-message {
    justify-content: center;
}

.message.system-message .message-content {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    border-radius: 8px;
    padding: 8px 12px;
}

.message.error .message-content {
    background: #fef2f2;
    border: 1px solid #fecaca;
}

.message.warning .message-content {
    background: #fffbeb;
    border: 1px solid #fde68a;
}

.text-success {
    color: #10b981;
}

.agent-info {
    margin-bottom: 10px;
    padding: 6px 10px;
    background: linear-gradient(135deg, #dbeafe, #e0e7ff);
    border-radius: 8px;
    font-size: 0.75rem;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.agent-label {
    color: #4338ca;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

.agent-chip {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: white;
    padding: 3px 10px;
    border-radius: 12px;
    font-weight: 500;
}

.elapsed-time {
    color: #6b7280;
    font-size: 0.7rem;
    margin-left: auto;
}

.chat-input-area {
    padding: 1rem 1.5rem;
    background: white;
    border-top: 1px solid var(--border-color);
}

.chat-input-area textarea {
    resize: none;
    border-radius: 8px;
    padding: 0.75rem 1rem;
}

.chat-input-area textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

#send-btn {
    border-radius: 8px;
    padding: 0 1.5rem;
}

.nav-tabs .nav-link {
    color: var(--text-secondary);
    border: none;
    padding: 0.75rem 1rem;
}

.nav-tabs .nav-link.active {
    color: var(--primary-color);
    border-bottom: 2px solid var(--primary-color);
    font-weight: 500;
}

.footer {
    margin-top: auto;
}

/* 追问样式 */
.clarification-box {
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border: 1px solid #fbbf24;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
}

.clarification-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    color: #92400e;
    font-weight: 600;
}

.clarification-header i {
    color: #f59e0b;
}

.clarification-round {
    font-size: 0.8rem;
    color: #b45309;
    margin-left: auto;
}

.clarification-questions {
    margin-bottom: 12px;
}

.clarification-question {
    display: flex;
    gap: 8px;
    margin-bottom: 8px;
    padding: 8px;
    background: rgba(255,255,255,0.6);
    border-radius: 8px;
}

.q-num {
    color: #f59e0b;
    font-weight: 600;
    min-width: 20px;
}

.q-text {
    color: #78350f;
    line-height: 1.4;
}

.file-upload-section {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-top: 12px;
    border-top: 1px dashed #fbbf24;
}

.clarification-message {
    margin-bottom: 12px;
    color: #78350f;
}

/* 响应式布局 */
@media (max-width: 1024px) {
    .sidebar {
        width: var(--sidebar-width-sm);
    }
    
    .sidebar-header h6,
    .empty-hint p,
    .history-item-title,
    .history-item-meta,
    .status-label span,
    .status-value {
        display: none;
    }
    
    .sidebar-header {
        justify-content: center;
    }
    
    .history-item {
        justify-content: center;
        padding: 0.75rem;
    }
    
    .status-section {
        display: none;
    }
    
    #thinking-section {
        display: none;
    }
}

@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
        height: auto;
    }
    
    .sidebar {
        width: 100%;
        height: auto;
        max-height: 200px;
        border: none;
        border-bottom: 1px solid var(--border-color);
    }
    
    .sidebar-right {
        border-bottom: none;
        border-top: 1px solid var(--border-color);
    }
    
    .chat-main {
        padding: 0.5rem;
        min-height: 400px;
    }
    
    .chat-container {
        height: calc(100vh - 56px - 50px - 420px);
    }
    
    .message-content {
        max-width: 85%;
    }
}

/* 角色选择 */
.role-select-modal .modal-body {
    padding: 2rem;
}

.role-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-top: 1rem;
}

.role-card {
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.role-card:hover {
    border-color: var(--primary-color);
    transform: translateY(-2px);
}

.role-card.selected {
    border-color: var(--primary-color);
    background: rgba(79, 70, 229, 0.05);
}

.role-card i {
    font-size: 2rem;
    color: var(--primary-color);
    margin-bottom: 0.5rem;
}

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 文件预览样式 */
.file-preview .card {
    background: #fffbeb;
    border: 1px solid #fde68a;
}

.file-preview .card-body {
    display: flex;
    align-items: center;
    gap: 10px;
}

.file-preview i {
    font-size: 1.5rem;
    color: #f59e0b;
}

.upload-progress {
    margin-top: 12px;
}

.upload-progress .progress {
    height: 8px;
    border-radius: 4px;
}

.file-attached {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.file-attached i {
    color: #10b981;
}

.thumbnail-preview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 8px;
    margin: 12px 0;
}

.thumbnail-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #e5e7eb;
}

.thumbnail-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumbnail-item .remove-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}
