/* ============ 基础样式 ============ */
:root {
    --primary-color: #10a37f;
    --primary-hover: #0d8c6d;
    --secondary-color: #f7f7f8;
    --border-color: #e5e5e5;
    --text-primary: #343541;
    --text-secondary: #6e6e80;
    --bg-primary: #ffffff;
    --bg-secondary: #f7f7f8;
    --sidebar-width: 260px;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --success-color: #10b981;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* ============ 按钮样式 ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--bg-secondary);
}

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

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

.btn-block {
    width: 100%;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

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

/* ============ 表单样式 ============ */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.form-group input,
.form-input,
.api-selector {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 14px;
    background-color: var(--bg-primary);
    transition: border-color 0.2s;
}

.form-group input:focus,
.form-input:focus,
.api-selector:focus {
    outline: none;
    border-color: var(--primary-color);
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
}

/* ============ 加载动画 ============ */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

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

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

/* ============ Toast 通知 ============ */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 12px 20px;
    border-radius: 8px;
    color: white;
    font-size: 14px;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    max-width: 350px;
}

.toast.success { background-color: var(--success-color); }
.toast.error { background-color: var(--danger-color); }
.toast.warning { background-color: var(--warning-color); }
.toast.info { background-color: var(--primary-color); }

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

/* ============ 认证页面 ============ */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 420px;
}

.auth-box {
    background: white;
    border-radius: 16px;
    padding: 40px;
    box-shadow: var(--shadow-lg);
}

.auth-logo {
    text-align: center;
    margin-bottom: 30px;
}

.auth-logo img {
    width: 80px;
    height: 80px;
    object-fit: contain;
    margin-bottom: 16px;
}

.auth-logo h1 {
    font-size: 28px;
    color: var(--text-primary);
}

.auth-form h2 {
    font-size: 20px;
    margin-bottom: 24px;
    color: var(--text-primary);
}

.auth-switch {
    text-align: center;
    margin-top: 20px;
    font-size: 14px;
    color: var(--text-secondary);
}

.auth-switch a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.auth-switch a:hover {
    text-decoration: underline;
}

/* ============ 应用页面布局 ============ */
.app-page {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* 侧边栏 */
.sidebar {
    width: var(--sidebar-width);
    background-color: #202123;
    color: white;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    font-size: 18px;
    font-weight: 600;
}

.logo img {
    width: 32px;
    height: 32px;
    object-fit: contain;
}

.sidebar .btn-secondary {
    color: white;
    border-color: rgba(255, 255, 255, 0.2);
}

.sidebar .btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

/* 会话列表 */
.conversations-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
    position: relative;
}

.conversation-item:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.conversation-item.active {
    background-color: rgba(255, 255, 255, 0.15);
}

.conversation-item i {
    color: rgba(255, 255, 255, 0.5);
    font-size: 14px;
}

.conversation-title {
    flex: 1;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-actions {
    display: none;
}

.conversation-item:hover .conversation-actions {
    display: flex;
    gap: 4px;
}

.conversation-actions button {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    padding: 4px;
}

.conversation-actions button:hover {
    color: white;
}

/* 侧边栏底部 */
.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    background-color: var(--primary-color);
}

.user-actions {
    display: flex;
    justify-content: space-around;
}

.user-actions .btn-icon {
    color: rgba(255, 255, 255, 0.6);
}

.user-actions .btn-icon:hover {
    color: white;
    background-color: rgba(255, 255, 255, 0.1);
}

/* ============ 主内容区 ============ */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background-color: var(--bg-secondary);
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* API 选择器 */
.api-selector-wrapper {
    padding: 16px 20px;
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

.api-selector {
    max-width: 300px;
}

/* 消息列表 */
.messages-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.welcome-message {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.welcome-message h2 {
    font-size: 28px;
    color: var(--text-primary);
    margin-bottom: 12px;
}

.message {
    display: flex;
    gap: 16px;
    padding: 20px;
    margin-bottom: 8px;
    border-radius: 12px;
}

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

.message.assistant {
    background-color: transparent;
}

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

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

.message.assistant .message-avatar {
    background-color: #19c37d;
    color: white;
}

.message-content {
    flex: 1;
    line-height: 1.6;
}

.message-content p {
    margin-bottom: 12px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content pre {
    background-color: #f4f4f4;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}

/* Markdown 样式 */
.message-content h1,
.message-content h2,
.message-content h3,
.message-content h4,
.message-content h5,
.message-content h6 {
    margin: 16px 0 12px;
    font-weight: 600;
    line-height: 1.4;
}

.message-content h1 { font-size: 1.5em; border-bottom: 1px solid var(--border-color); padding-bottom: 8px; }
.message-content h2 { font-size: 1.3em; border-bottom: 1px solid var(--border-color); padding-bottom: 6px; }
.message-content h3 { font-size: 1.15em; }
.message-content h4 { font-size: 1.05em; }

.message-content p {
    margin-bottom: 12px;
}

.message-content ul,
.message-content ol {
    margin: 12px 0;
    padding-left: 24px;
}

.message-content li {
    margin: 6px 0;
}

.message-content code {
    font-family: 'SF Mono', Monaco, monospace;
    background-color: rgba(175, 184, 193, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.9em;
    color: #24292f;
}

.message-content pre {
    background-color: #f6f8fa;
    border-radius: 8px;
    padding: 16px;
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid var(--border-color);
}

.message-content pre code {
    padding: 0;
    background: none;
    font-size: 13px;
    line-height: 1.6;
}

.message-content blockquote {
    border-left: 4px solid var(--primary-color);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--text-secondary);
}

/* Markdown 表格样式 */
.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 14px;
    line-height: 1.5;
    display: table;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    overflow: hidden;
}

.message-content thead {
    display: table-header-group;
    vertical-align: middle;
    border-color: inherit;
}

.message-content tbody {
    display: table-row-group;
    vertical-align: middle;
    border-color: inherit;
}

.message-content tr {
    display: table-row;
    vertical-align: inherit;
    border-color: inherit;
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
}

.message-content tr:first-child {
    border-top: none;
}

.message-content tr:nth-child(2n) {
    background-color: var(--bg-secondary);
}

.message-content th,
.message-content td {
    display: table-cell;
    border: 1px solid var(--border-color);
    padding: 8px 13px;
    text-align: left;
    vertical-align: top;
}

.message-content th {
    background-color: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
}

.message-content td {
    color: var(--text-primary);
}

.message-content table > thead > tr > th {
    vertical-align: bottom;
    border-bottom: 2px solid var(--border-color);
}

.message-content a {
    color: var(--primary-color);
    text-decoration: none;
}

.message-content a:hover {
    text-decoration: underline;
}

/* ECharts 容器 */
.echarts-container {
    width: 100%;
    height: 350px;
    margin: 16px 0;
    border-radius: 8px;
    overflow: hidden;
}

/* 代码块语言标签 */
.code-block-wrapper {
    position: relative;
    margin: 12px 0;
}

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background-color: #f1f3f4;
    border-radius: 8px 8px 0 0;
    border: 1px solid var(--border-color);
    border-bottom: none;
    font-size: 12px;
    color: var(--text-secondary);
}

.code-block-wrapper pre {
    margin: 0;
    border-radius: 0 0 8px 8px;
}

.copy-code-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: 4px;
}

.copy-code-btn:hover {
    background-color: var(--border-color);
}

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

.input-wrapper {
    display: flex;
    gap: 12px;
    max-width: 800px;
    margin: 0 auto;
}

#message-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 15px;
    resize: none;
    min-height: 48px;
    max-height: 200px;
    font-family: inherit;
}

#message-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

#message-input:disabled {
    background-color: var(--bg-secondary);
    cursor: not-allowed;
}

.input-hint {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 8px;
}

/* ============ 弹窗样式 ============ */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.modal-large .modal-content {
    max-width: 900px;
}

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

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-secondary);
    cursor: pointer;
}

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

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

/* 设置弹窗 */
.settings-section {
    margin-bottom: 24px;
}

.settings-section h4 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
}

.avatar-upload,
.logo-upload {
    display: flex;
    align-items: center;
    gap: 16px;
}

.avatar-large {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
}

.logo-preview {
    width: 120px;
    height: 60px;
    object-fit: contain;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 8px;
}

/* ============ 管理后台 ============ */
.admin-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 12px;
}

.admin-tab {
    padding: 10px 16px;
    background: none;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.admin-tab:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.admin-tab.active {
    background-color: var(--primary-color);
    color: white;
}

.admin-panel {
    display: none;
}

.admin-panel.active {
    display: block;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.panel-header h4 {
    font-size: 16px;
    font-weight: 600;
}

/* 表格样式 */
.table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

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

.data-table th {
    background-color: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 12px;
    text-transform: uppercase;
}

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

.data-table tr:hover td {
    background-color: var(--bg-secondary);
}

/* API 复选框 */
.api-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 300px;
    overflow-y: auto;
    padding: 4px;
}

.api-checkbox-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-primary);
}

.api-checkbox-item:hover {
    background-color: var(--bg-secondary);
    border-color: var(--primary-color);
}

.api-checkbox-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.api-checkbox-item label {
    cursor: pointer;
    flex: 1;
    margin: 0;
    font-size: 14px;
}

.api-checkbox-item .api-meta {
    font-size: 12px;
    color: var(--text-secondary);
}

.api-selection-actions {
    display: flex;
    gap: 8px;
}

.api-selection-actions .btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.api-checkbox-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
}

.api-checkbox-item:hover {
    background-color: var(--bg-secondary);
}

.api-checkbox-item input {
    width: auto;
}

/* 当前 API 列表 */
.current-apis-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 20px;
}

.api-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background-color: var(--primary-color);
    color: white;
    border-radius: 16px;
    font-size: 13px;
}

.api-tag button {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    font-size: 12px;
}

.add-api-form {
    display: flex;
    gap: 12px;
}

.add-api-form select {
    flex: 1;
}

/* 响应式设计 */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        transition: left 0.3s;
        z-index: 100;
        height: 100vh;
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .modal-content {
        max-width: 100%;
        max-height: 100vh;
        border-radius: 0;
    }
    
    .modal-large .modal-content {
        max-width: 100%;
    }
    
    .admin-tabs {
        flex-wrap: wrap;
    }
    
    .data-table {
        font-size: 12px;
    }
    
    .data-table th,
    .data-table td {
        padding: 8px 10px;
    }
}

/* 状态标签 */
.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.status-badge.active {
    background-color: #d1fae5;
    color: #065f46;
}

.status-badge.inactive {
    background-color: #fee2e2;
    color: #991b1b;
}

.status-badge.used {
    background-color: #e5e7eb;
    color: #374151;
}

/* 打字动画 */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background-color: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out both;
}

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

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