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

:root, .theme-deep-slate {
    --primary: #00d4ff;
    --primary-dark: #0099cc;
    --secondary: #7c3aed;
    --accent: #22c55e;
    --danger: #ef4444;
    --bg-dark: #1a1b2e;
    --bg-card: #23254a;
    --bg-input: #2a2d54;
    --text: #e6e6f0;
    --text-muted: #8b8ba8;
    --border: #3d3f6a;
    --glow: 0 0 20px rgba(0, 212, 255, 0.3);
}

/* 深空黑 — 原版极暗 */
body.theme-deep-space {
    --primary: #00d4ff;
    --primary-dark: #0099cc;
    --secondary: #7c3aed;
    --accent: #22c55e;
    --danger: #ef4444;
    --bg-dark: #0a0a0f;
    --bg-card: #12121a;
    --bg-input: #1a1a25;
    --text: #e4e4e7;
    --text-muted: #71717a;
    --border: #27272a;
    --glow: 0 0 20px rgba(0, 212, 255, 0.3);
}

/* 暮光紫 */
body.theme-twilight {
    --primary: #c084fc;
    --primary-dark: #a855f7;
    --secondary: #818cf8;
    --accent: #34d399;
    --danger: #f87171;
    --bg-dark: #1c1427;
    --bg-card: #2a1f3d;
    --bg-input: #352a4a;
    --text: #e8e0f0;
    --text-muted: #9a8ab0;
    --border: #4a3a62;
    --glow: 0 0 20px rgba(192, 132, 252, 0.25);
}

/* 极简白 */
body.theme-light {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --secondary: #7c3aed;
    --accent: #16a34a;
    --danger: #dc2626;
    --bg-dark: #f4f5f7;
    --bg-card: #ffffff;
    --bg-input: #e8eaed;
    --text: #1a1a2e;
    --text-muted: #6b7280;
    --border: #d1d5db;
    --glow: 0 0 15px rgba(37, 99, 235, 0.15);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans SC', sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

.container {
    position: relative;
    z-index: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* 头部 */
.header {
    text-align: center;
    padding: 40px 20px;
}

.logo {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 10px;
    animation: glow 2s ease-in-out infinite alternate;
}

@keyframes glow {
    from { filter: drop-shadow(0 0 5px rgba(0, 212, 255, 0.5)); }
    to { filter: drop-shadow(0 0 20px rgba(0, 212, 255, 0.8)); }
}

.subtitle {
    color: var(--text-muted);
    font-size: 1rem;
}

/* 导航标签 */
.nav-tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 20px 0;
    flex-wrap: wrap;
}

.nav-tab {
    padding: 10px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}

.nav-tab:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.nav-tab.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-color: transparent;
    color: white;
}

/* 卡片 */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    transition: all 0.3s;
}

.card:hover {
    border-color: var(--primary);
    box-shadow: var(--glow);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* 输入框 */
.input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

input[type="text"], input[type="password"], select, textarea {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    transition: all 0.3s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 212, 255, 0.1);
}

/* 按钮 */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0, 212, 255, 0.4);
}

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

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

.btn-secondary:hover {
    border-color: var(--primary);
}

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

/* 状态消息 */
.status {
    padding: 12px 16px;
    border-radius: 8px;
    margin-top: 16px;
    display: none;
}

.status.show {
    display: block;
    animation: fadeIn 0.3s;
}

.status.success {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid var(--accent);
    color: var(--accent);
}

.status.error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid var(--danger);
    color: var(--danger);
}

.status.info {
    background: rgba(0, 212, 255, 0.1);
    border: 1px solid var(--primary);
    color: var(--primary);
}

/* 进度条 */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    margin: 16px 0;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    transition: width 0.3s;
    animation: progressPulse 1.5s ease-in-out infinite;
}

@keyframes progressPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* 工具列表 */
.tool-list {
    max-height: 400px;
    overflow-y: auto;
}

.tool-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: all 0.3s;
}

.tool-item:hover {
    border-color: var(--primary);
    background: rgba(0, 212, 255, 0.05);
}

.tool-item.selected {
    border-color: var(--accent);
    background: rgba(34, 197, 94, 0.1);
}

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

.tool-info {
    flex: 1;
    min-width: 0;
}

.tool-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tool-desc {
    font-size: 0.875rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* 知识库列表 */
/* 知识库列表外框 */
.kb-wrapper {
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow-x: auto;
    background: var(--bg-input);
}

.kb-list {
    display: grid;
    gap: 1px;
    background: var(--border);  /* 分割线由背景色提供 */
}

.kb-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: var(--bg-card);
    cursor: pointer;
    transition: all 0.2s;
    overflow: hidden;
}

.kb-item .kb-row {
    overflow: hidden;
}

.kb-item:first-child {
    border-radius: 10px 10px 0 0;
}

.kb-item:last-child {
    border-radius: 0 0 10px 10px;
}

.kb-item:only-child {
    border-radius: 10px;
}

.kb-item:hover {
    background: rgba(0, 212, 255, 0.06);
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(26, 27, 46, 0.92);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal.show {
    display: flex;
    animation: fadeIn 0.3s;
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 100%;
    max-width: 800px;
    max-height: 90vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
}

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

/* Markdown 渲染 */
.markdown-content h1 { font-size: 1.75rem; margin: 1.5rem 0 1rem; }
.markdown-content h2 { font-size: 1.5rem; margin: 1.25rem 0 0.75rem; color: var(--primary); }
.markdown-content h3 { font-size: 1.25rem; margin: 1rem 0 0.5rem; }
.markdown-content p { margin: 0.75rem 0; line-height: 1.6; }
.markdown-content ul, .markdown-content ol { margin: 0.75rem 0; padding-left: 1.5rem; }
.markdown-content li { margin: 0.25rem 0; }
.markdown-content code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Fira Code', monospace;
    font-size: 0.9em;
}
.markdown-content pre {
    background: var(--bg-input);
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 1rem 0;
}
.markdown-content pre code {
    background: none;
    padding: 0;
}
.markdown-content a {
    color: var(--primary);
    text-decoration: none;
}
.markdown-content a:hover {
    text-decoration: underline;
}
.markdown-content blockquote {
    border-left: 4px solid var(--primary);
    padding-left: 16px;
    margin: 1rem 0;
    color: var(--text-muted);
}

/* 动画 */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* 响应式 */
@media (max-width: 768px) {
    .logo { font-size: 1.75rem; }
    
    .input-group {
        flex-direction: column;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
    }
    
    .card {
        padding: 16px;
    }
    
    .nav-tab {
        padding: 8px 10px;
        font-size: 0.8rem;
        text-align: center;
    }

    .nav-tabs {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
        flex-wrap: nowrap;
    }

    /* 知识库行：窄屏只显示序号+内容+时间，按钮隐藏（可在详情页操作） */
    .kb-item .kb-row {
        gap: 6px !important;
    }

    .kb-item .btn-refresh {
        display: none;
    }

    .kb-item .kb-row .kb-meta {
        display: flex;
        flex-direction: row;
        gap: 6px;
        align-items: center;
        flex-shrink: 0;
        min-width: auto;
    }

    .kb-item .kb-row .kb-number {
        min-width: 26px !important;
        height: 26px !important;
        font-size: 0.7rem !important;
    }

    /* 模态框头部：标题和按钮分两行 */
    .modal-header {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
        padding: 12px 16px;
    }

    .modal-header h3 {
        font-size: 1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .modal-header > div:last-child {
        justify-content: flex-end;
    }

    .modal-header .btn {
        width: auto;
    }
}

/* 超窄屏 (480px 以下) */
@media (max-width: 480px) {
    .container { padding: 10px; }
    .card { padding: 12px; }
    .kb-item { padding: 10px 12px; }

    .kb-item .kb-row .kb-meta {
        flex-direction: row;
        gap: 4px;
        font-size: 0.65rem;
    }
}

/* 滚动条 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

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

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

/* 隐藏面板 */
.panel {
    display: none;
}

.panel.active {
    display: block;
    animation: fadeIn 0.3s;
}

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

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

/* ── 极简白主题额外适配 ── */

body.theme-light .logo {
    animation: none;
    filter: none;
}

body.theme-light .nav-tab.active {
    color: white;
}

body.theme-light .btn-primary {
    color: white;
}

body.theme-light .kb-item:hover {
    background: rgba(37, 99, 235, 0.06);
}

body.theme-light .task-item:hover {
    background: rgba(37, 99, 235, 0.03);
}

body.theme-light .task-group-header:hover {
    background: rgba(37, 99, 235, 0.06);
}

body.theme-light .modal {
    background: rgba(244, 245, 247, 0.95);
}

body.theme-light .modal-content {
    background: var(--bg-card);
}

body.theme-light .markdown-content code {
    background: var(--bg-input);
}

body.theme-light ::-webkit-scrollbar-track {
    background: var(--bg-dark);
}

body.theme-light ::-webkit-scrollbar-thumb {
    background: #c4c7d0;
}

body.theme-light ::-webkit-scrollbar-thumb:hover {
    background: #a0a4b0;
}

/* 暂停状态进度条 */
.progress-fill.paused {
    animation: none;
    background: linear-gradient(90deg, #f59e0b, #d97706);
}

/* ── 批量任务列表增强 ── */

/* 过滤器栏 */
.task-filter-bar {
    display: flex;
    gap: 6px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.task-filter-btn {
    padding: 4px 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
}

.task-filter-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.task-filter-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-color: transparent;
    color: white;
}

/* 任务分组 */
.task-group {
    margin-bottom: 4px;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    transition: border-color 0.2s;
}

.task-group:hover {
    border-color: rgba(0, 212, 255, 0.3);
}

.task-group-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    user-select: none;
    font-size: 0.8rem;
    font-weight: 500;
    background: var(--bg-input);
    transition: background 0.2s;
}

.task-group-header:hover {
    background: rgba(0, 212, 255, 0.08);
}

.task-group-header .arrow {
    transition: transform 0.2s;
    font-size: 0.7rem;
}

.task-group-header .arrow.collapsed {
    transform: rotate(-90deg);
}

.task-group-body {
    max-height: 2000px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.task-group-body.collapsed {
    max-height: 0;
}

/* 工具状态条目 */
.task-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 12px 7px 16px;
    border-bottom: 1px solid rgba(39, 39, 42, 0.5);
    font-size: 0.8rem;
    transition: background 0.2s;
}

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

.task-item:hover {
    background: rgba(0, 212, 255, 0.03);
}

.task-item .status-icon {
    flex-shrink: 0;
    width: 22px;
    text-align: center;
    font-size: 0.85rem;
}

.task-item .task-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.task-item .task-detail {
    flex-shrink: 0;
    color: var(--text-muted);
    font-size: 0.75rem;
    min-width: 60px;
    text-align: right;
}

/* 正在运行的脉冲动画 */
.task-item.running .status-icon {
    animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* 正在运行的进度闪烁条 */
.task-item.running {
    border-left: 3px solid var(--primary);
    padding-left: 13px;
    background: linear-gradient(90deg, rgba(0, 212, 255, 0.04), transparent);
}

.task-item.failed {
    border-left: 3px solid var(--danger);
    padding-left: 13px;
}

.task-item.completed {
    border-left: 3px solid var(--accent);
    padding-left: 13px;
}

.task-item.pending {
    border-left: 3px solid var(--border);
    padding-left: 13px;
    opacity: 0.6;
}

/* 失败原因的标签 */
.error-badge {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.7rem;
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.error-badge.rate_limit {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.error-badge.timeout {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
}

/* 空状态 */
.task-list-empty {
    text-align: center;
    padding: 20px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ── 知识库刷新按钮 ── */

.btn-refresh {
    flex-shrink: 0;
    padding: 6px 12px;
    font-size: 0.85rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.25s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    line-height: 1;
}

.btn-refresh:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: rgba(0, 212, 255, 0.06);
    box-shadow: 0 0 12px rgba(0, 212, 255, 0.15);
}

.btn-refresh:active {
    transform: scale(0.95);
}

/* 刷新中动画 */
.btn-refresh.spinning .refresh-icon {
    display: inline-block;
    animation: spin 0.8s linear infinite;
}
