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

:root {
    --primary: #2d2d3f;
    --primary-light: #3d3d5a;
    --primary-dark: #1f1f2e;
    --bg-body: #f5f5f7;
    --bg-card: #ffffff;
    --bg-msg-user: var(--primary);
    --bg-msg-assistant: rgba(237, 243, 254);
    --text-primary: #1a1a1e;
    --text-secondary: #555;
    --text-light: #888;
    --border-color: #e5e5e8;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    --radius: 16px;
    --radius-sm: 10px;
    --transition: 0.25s ease;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

html,
body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg-body);
    color: var(--text-primary);
}

/* ================================================================
   应用根容器
   ================================================================ */
.app {
    max-width: 1200px;
    margin: 0 auto;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 12px;
}

/* ================================================================
   顶栏
   ================================================================ */
.app-header {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px 20px;
    box-shadow: var(--shadow);
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 20px;
    color: var(--primary);
}

.brand span {
    font-size: 26px;
}

.nav-tabs {
    display: flex;
    gap: 4px;
    background: #f0f0f2;
    padding: 4px;
    border-radius: 30px;
}

.nav-tab {
    padding: 8px 22px;
    border: none;
    border-radius: 30px;
    background: transparent;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    color: var(--text-secondary);
}

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

.nav-tab.active {
    background: var(--bg-card);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    color: var(--primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-actions button {
    background: transparent;
    border: none;
    font-size: 16px;
    cursor: pointer;
    padding: 6px 14px;
    border-radius: 30px;
    transition: var(--transition);
    color: var(--text-secondary);
    font-weight: 500;
}

.header-actions button:hover {
    background: #f0f0f2;
    color: var(--text-primary);
}

/* ================================================================
   主体区域
   ================================================================ */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-top: 12px;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    min-height: 0;
}

/* ================================================================
   视图容器
   ================================================================ */
.view {
    display: none;
    flex-direction: column;
    height: 100%;
}

.view.active {
    display: flex;
}

/* ================================================================
   聊天视图
   ================================================================ */
.chat-view {
    height: 100%;
}

.mode-tabs {
    display: flex;
    gap: 0;
    padding: 12px 24px 0 24px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.mode-tab {
    padding: 10px 20px;
    border: none;
    background: transparent;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 3px solid transparent;
    transition: var(--transition);
}

.mode-tab:hover {
    color: var(--text-primary);
}

.mode-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    background: #fafafa;
}

.message {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
}

.message.user {
    align-items: flex-end;
}

.message.assistant {
    align-items: flex-start;
}

.bubble {
    max-width:87%;
    padding: 12px 18px;
    border-radius: 18px;
    line-height: 1.6;
    word-wrap: break-word;
    white-space: pre-wrap;
    font-size: 15px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

/* 聊天气泡内的超链接：可点击跳转 */
.bubble a {
    color: #1d4ed8;
    text-decoration: underline;
    word-break: break-all;
}
.bubble a:hover {
    color: #1e40af;
}

.user .bubble {
    background: #9aefa5;
    color: black;
    border-bottom-right-radius: 4px;
}

.assistant .bubble {
    background: var(--bg-msg-assistant);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.context-info {
    font-size: 12px;
    color: #00000069;
    margin-top: 4px;
    padding: 4px 12px;
    background: #d7ebf3;
    border-radius: 8px;
    max-width: 82%;
    word-break: break-all;
    border: 1px solid #2d3b8524;
    white-space: pre-wrap;
}

.debug-toggle {
    margin-top: 6px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    opacity: 0.7;
    transition: var(--transition);
}

.debug-toggle:hover {
    opacity: 1;
}

.debug-details {
    background: #f4f4f6;
    border-radius: 8px;
    padding: 10px 14px;
    margin-top: 4px;
    font-family: monospace;
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-all;
    width: 87%;
    max-width: 87%;
    border: 1px solid #e0e0e4;
    display: none;
}

.debug-details.open {
    display: block;
}

.input-area {
    display: flex;
    padding: 12px 24px 20px 24px;
    background: white;
    border-top: 1px solid var(--border-color);
    gap: 10px;
    flex-shrink: 0;
}

.input-area textarea {
    flex: 1;
    resize: none;
    padding: 12px 18px;
    border: 1px solid #ddd;
    border-radius: 24px;
    font-size: 15px;
    outline: none;
    font-family: inherit;
    min-height: 50px;
    max-height: 120px;
    transition: border-color 0.2s;
    background: #fafafa;
}

.input-area textarea:focus {
    border-color: var(--primary);
    background: white;
}

.input-area button {
    background: #edf3fe;
    color: #959595e3;
    border: none;
    border-radius: 24px;
    padding: 0 28px;
    font-size: 16px;
    cursor: pointer;
    font-weight: 500;
    white-space: nowrap;
    transition: var(--transition);
}

.input-area button:hover {
    background: var(--primary-dark);
}

.input-area button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ================================================================
   工具集视图（分组展示，无标题）
   ================================================================ */
.tools-view {
    padding: 24px 28px;
    overflow-y: auto;
    height: 100%;
}

.tools-view .tools-header {
    margin-bottom: 24px;
}

.tools-view .tools-header h2 {
    font-size: 22px;
    font-weight: 600;
}

/* 每组工具独立成行 */
.tool-group {
    margin-bottom: 28px;
}

.tool-group:last-child {
    margin-bottom: 0;
}

.tool-group-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 18px;
}

/* 工具卡片样式 */
.tool-card {
    background: #fafafa;
    border-radius: var(--radius-sm);
    padding: 20px 18px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid transparent;
    position: relative;
}

.tool-card:hover {
    background: white;
    border-color: var(--border-color);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
    transform: translateY(-2px);
}

.tool-card .icon {
    font-size: 36px;
    display: block;
    margin-bottom: 10px;
}

.tool-card .name {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 4px;
}

.tool-card .desc {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.tool-card .tag {
    position: absolute;
    top: 10px;
    right: 10px;
    font-size: 11px;
    background: #e8e8ec;
    padding: 2px 10px;
    border-radius: 20px;
    color: var(--text-secondary);
}

/* ================================================================
   工具模态框
   ================================================================ */
.tool-modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(3px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.tool-modal-overlay.active {
    display: flex;
}

.tool-modal {
    background: white;
    border-radius: var(--radius);
    max-width: 770px;
    width: 100%;
    max-height: 520px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    animation: modalIn 0.25s ease;
}

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

.tool-modal .modal-header {
    padding: 28px 32px 0 32px;
    flex-shrink: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.tool-modal .modal-header h3 {
    font-size: 20px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tool-modal .modal-header button#modalCloseBtn {
    background: none;
    border: none;
    font-size: 26px;
    cursor: pointer;
    color: var(--text-light);
    padding: 0 4px;
    line-height: 1;
}

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

.tool-modal .modal-body::-webkit-scrollbar {
    width: 5px;
}

.tool-modal .modal-body::-webkit-scrollbar-track {
    background: transparent;
}

.tool-modal .modal-body::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 10px;
}

.tool-modal .modal-body::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

.tool-modal .modal-body .field {
    margin-bottom: 14px;
}

.tool-modal .modal-body label {
    display: block;
    font-weight: 500;
    margin-bottom: 4px;
    font-size: 14px;
}

.tool-modal .modal-body input,
.tool-modal .modal-body textarea,
.tool-modal .modal-body select {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: var(--transition);
    background: white;
}

.tool-modal .modal-body input:focus,
.tool-modal .modal-body textarea:focus,
.tool-modal .modal-body select:focus {
    border-color: var(--primary);
}

.tool-modal .modal-body textarea {
    min-height: 80px;
    resize: vertical;
}

.tool-modal .modal-body .btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 28px;
    border-radius: 24px;
    font-size: 15px;
    cursor: pointer;
    font-weight: 500;
    transition: var(--transition);
}

.tool-modal .modal-body .btn-primary:hover {
    background: var(--primary-dark);
}

.tool-modal .modal-body .btn-secondary {
    background: #e8e8ec;
    color: var(--text-primary);
    border: none;
    padding: 10px 20px;
    border-radius: 24px;
    font-size: 15px;
    cursor: pointer;
    font-weight: 500;
    transition: var(--transition);
}

.tool-modal .modal-body .btn-secondary:hover {
    background: #d5d5da;
}

.tool-modal .modal-body .result-box {
    margin-top: 14px;
    background: #f5f5f7;
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    word-break: break-all;
    font-family: monospace;
    font-size: 14px;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid #e8e8ec;
    white-space: pre-wrap;
}

/* ================================================================
   帮助按钮
   ================================================================ */
.help-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #f0f2f5;
    border: 1px solid #d0d4da;
    border-radius: 14px;
    padding: 2px 12px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    color: #555;
    transition: all 0.2s ease;
    line-height: 1.6;
    white-space: nowrap;
}

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

/* ================================================================
   操作模式按钮组
   ================================================================ */
.choice-group {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.choice-btn {
    flex: 1;
    min-width: 120px;
    padding: 10px 16px;
    border: 2px solid #ddd;
    border-radius: 10px;
    background: #f9f9f9;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    text-align: center;
    color: var(--text-secondary);
}

.choice-btn:hover {
    border-color: #bbb;
    background: #f0f0f2;
}

.choice-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
    box-shadow: 0 2px 8px rgba(45, 45, 63, 0.2);
}

.choice-btn.active:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

/* ================================================================
   Toast 轻提示
   ================================================================ */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--primary-dark);
    color: white;
    padding: 12px 28px;
    border-radius: 30px;
    font-size: 14px;
    opacity: 0;
    transition: all 0.35s ease;
    z-index: 2000;
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* ================================================================
   滚动条美化
   ================================================================ */
.chat-messages::-webkit-scrollbar,
.tools-view::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-track,
.tools-view::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.tools-view::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.tools-view::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

/* ================================================================
   响应式适配
   ================================================================ */
@media (max-width: 640px) {
    .app {
        padding: 8px;
    }

    .app-header {
        padding: 10px 16px;
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .brand {
        font-size: 18px;
        justify-content: center;
    }

    .nav-tabs {
        justify-content: center;
    }

    .nav-tab {
        padding: 6px 16px;
        font-size: 14px;
    }

    .mode-tabs {
        padding: 8px 12px 0 12px;
        overflow-x: auto;
    }

    .mode-tab {
        padding: 8px 14px;
        font-size: 13px;
        white-space: nowrap;
    }

    .chat-messages {
        padding: 14px 16px;
    }

    .input-area {
        padding: 10px 16px 16px 16px;
        flex-wrap: wrap;
    }

    .input-area textarea {
        min-height: 44px;
        font-size: 14px;
    }

    .input-area button {
        padding: 0 18px;
        font-size: 14px;
    }

    .tools-view {
        padding: 16px;
    }

    .tool-group-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 12px;
    }

    .tool-card {
        padding: 14px 12px;
    }

    .tool-card .icon {
        font-size: 28px;
    }

    .bubble {
        max-width: 90%;
        font-size: 14px;
        padding: 10px 14px;
    }
}

/* ----- 工作流步骤时间线 (沿用主色调) ----- */
.workflow-steps {
    margin-top: 12px;
    background: #f8fafc;
    border-radius: 14px;
    border: 1px solid #e2e8f0;
    overflow: hidden;
    width: 100%;
}

.steps-header {
    padding: 10px 16px;
    background: #f1f4f9;
    font-size: 13px;
    font-weight: 600;
    color: #2d3748;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: default;
    border-bottom: 1px solid #e2e8f0;
}

.steps-body {
    padding: 4px 0;
}

.step-item {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 10px 16px 10px 20px;
    border-bottom: 1px solid #edf2f7;
}

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

.step-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #e2e8f0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 2px;
    color: #2d3748;
}

.step-icon.done {
    background: #48bb78;
    color: #fff;
}

.step-icon.running {
    background: #ed8936;
    color: #fff;
    animation: pulse 1.2s infinite;
}

.step-icon.error {
    background: #fc8181;
    color: #fff;
}

.step-content {
    flex: 1;
    min-width: 0;
}

.step-title {
    font-size: 14px;
    font-weight: 600;
    color: #2d3748;
}

.step-desc {
    font-size: 13px;
    color: #4a5568;
    margin-top: 2px;
    word-break: break-word;
    white-space: pre-wrap;
}

.step-detail-toggle {
    font-size: 12px;
    color: #805ad5;
    cursor: pointer;
    margin-top: 4px;
    display: inline-block;
}

.step-detail-toggle:hover {
    text-decoration: underline;
}

.step-extra {
    margin-top: 6px;
    background: #edf2f7;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-family: 'Courier New', monospace;
    color: #1a202c;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 160px;
    overflow-y: auto;
    display: none; /* 默认隐藏 */
}

.final-answer {
    margin-top: 12px;
    padding: 14px 18px;
    background: #ebf8ff;
    border-radius: 12px;
    border-left: 4px solid #3182ce;
    font-size: 15px;
    line-height: 1.6;
    color: #1a365d;
}

.source-tag:hover {
    background: #d2e0f0;
    transform: scale(1.02);
}
.source-tag:active {
    background: #b0c4de;
}

/* 模态框样式（已有，可微调） */
.tool-modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.tool-modal {
    background: white;
    border-radius: 12px;
    padding: 20px;
    max-width: 770px;
    max-height: 475px;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}
.modal-header h3 { margin: 0; }
#docModalCloseBtn, #historyModalCloseBtn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
}
.btn-primary {
    background: #4a90d9;
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 4px;
    cursor: pointer;
}
.btn-primary:hover { background: #357abd; }
.btn-primary:disabled { opacity: 0.6; }

.meta-chip, .meta-file, .meta-user {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 12px; border-radius: 20px;
    font-size: 13px; line-height: 1.6; white-space: nowrap;
}
.meta-chip  { background: #e0f2fe; color: #0369a1; font-weight: 500; }
.meta-file  { background: #f0fdf4; color: #166534; word-break: break-all; }
.meta-user  { background: #fef3c7; color: #92400e; }

/* ================================================================
   参考资料条目（压缩高度 + 美观链接）
   ================================================================ */
/* 注意：此处已合并并替换原有的两处重复定义 */
.source-item {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    max-width: 100%;
    padding: 4px 10px;          /* 适当增加上下内边距，视觉更均衡 */
    margin-bottom: 4px;
    min-height: 50px;           /* 固定最小高度，展开后自动增高 */
    display: flex;
    flex-direction: column;     /* 纵向排列，方便 content 在下方 */
    justify-content: center;    /* 垂直居中，让 info 在垂直方向居中 */
}
.source-item:last-child {
    margin-bottom: 0;
}

.source-info {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    font-size: 12px;
    line-height: 1.6;
    width: 100%;
    flex: 0 0 auto;            /* 不占用额外垂直空间 */
}

.source-file {
    max-width: 500px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex-shrink: 1;
}

.source-score {
    color: #d97706;
    background: #fffbeb;
    border: 1px solid #fde68a;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 12px;
    white-space: nowrap;
}

/* ===== 美观的链接样式 + 靠右对齐 ===== */
.source-link {
    color: #2563eb;
    cursor: pointer;
    text-decoration: none;
    font-size: 13px;
    white-space: nowrap;            /* 强制不换行，水平排列 */
    background: #eff6ff;
    padding: 0 12px;
    border-radius: 14px;
    line-height: 24px;              /* 固定高度，垂直居中 */
    transition: all 0.2s;
    /* 让第一个 link 靠右，第二个跟随，实现整体靠右 */
}
/* 第一个 link 推到右侧 */
.source-link:first-of-type {
    margin-left: auto;
}
/* 两个 link 之间间距由 gap 和 margin 共同控制，这里可额外微调 */
.source-link + .source-link {
    margin-left: 2px;               /* 保持紧凑 */
}
.source-link:hover {
    background: #dbeafe;
    color: #1d4ed8;
}

.source-content {
    display: none;
    margin-top: 6px;
    padding: 6px;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: 6px;
    max-height: 200px;
    overflow-y: auto;
    font-size: 13px;
    color: #475569;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.6;               /* 内容区恢复正常行高，避免叠加 */
}

/* ===== 收起详情中的其他元素 ===== */
.debug-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 6px 0;
    font-size: 13px;
    line-height: 1.6;
    border-bottom: 1px dashed #e2e8f0;
}
.debug-row:last-of-type { border-bottom: none; }

.debug-label {
    color: #475569;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.debug-value {
    color: #1e293b;
    word-break: break-all;
}

.debug-doc-section { margin-top: 8px; }

.debug-doc-title {
    font-size: 13px;
    font-weight: 600;
    color: #334155;
    margin-bottom: 6px;
}

/* ===== 数据库模式：查询结果表 ===== */
.db-table-wrap {
    margin-top: 8px;
    max-width: 100%;
    overflow-x: auto;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
}

.db-table-wrap .data-table {
    border-collapse: collapse;
    font-size: 13px;
    width: 100%;
    background: #fff;
}

.db-table-wrap .data-table th,
.db-table-wrap .data-table td {
    border: 1px solid #d1d5db;
    padding: 5px 10px;
    white-space: nowrap;
    text-align: left;
    color: #1f2937;
}

.db-table-wrap .data-table thead th {
    background: #edf3fe;
    font-weight: 600;
    color: #1e3a5f;
    position: sticky;
    top: 0;
}

.db-table-wrap .data-table tr:nth-child(even) {
    background: #fafbfc;
}

/* ===== 数据库模式：下载链接按钮 ===== */
.download-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.download-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #93c5fd;
    padding: 6px 16px;
    border-radius: 20px;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s ease;
}

.download-btn:hover {
    background: #dbeafe;
    color: #1e40af;
    box-shadow: 0 2px 6px rgba(29, 78, 216, 0.15);
}

/* ===== 管理页面 ===== */
.mgmt-section {
    background: #ffffff;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    border: 1px solid #e5e7eb;
}

.mgmt-title {
    font-size: 16px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.mgmt-input-group {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}

.mgmt-input {
    flex: 1;
    padding: 8px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.mgmt-input:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.category-chips {
    list-style: none;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.category-chip {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    color: #374151;
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 13px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s;
}
.category-chip:hover { background: #e5e7eb; }

.category-chip .delete {
    background: none;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    padding: 0;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}
.category-chip .delete:hover {
    background: #fee2e2;
    color: #ef4444;
}

/* 上传表单：选择文件 / 选择分类 / 上传按钮 同一行 */
.upload-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 18px 20px;
}

.upload-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1 1 220px;
    min-width: 0;
}
.upload-label {
    font-size: 14px;
    color: #374151;
    font-weight: 500;
    white-space: nowrap;
}
.upload-control {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    min-width: 0;
}
.upload-field .mgmt-select {
    width: 100%;
}
.upload-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
    padding-bottom: 1px;
}
.upload-status {
    font-size: 13px;
    color: #4b5563;
}

.file-input-wrapper {
    position: relative;
    display: inline-flex;
    align-items: center;
}
.file-input-wrapper input[type="file"] {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}
.file-input-btn {
    display: inline-block;
    padding: 6px 14px;
    background: #f3f4f6;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 13px;
    color: #374151;
    cursor: pointer;
    transition: background 0.2s;
}
.file-input-btn:hover { background: #e5e7eb; }

.file-name {
    font-size: 13px;
    color: #4b5563;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 5px 10px;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mgmt-select {
    padding: 8px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    background: #fff;
    outline: none;
    cursor: pointer;
}
.mgmt-select:focus { border-color: #3b82f6; }

/* 视图元数据编辑：启用复选框行（提高特异性以覆盖 .tool-modal .modal-body 的全局 input/label 规则） */
.tool-modal .modal-body .meta-active-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 14px;
    margin-top: 16px;
    padding: 10px 14px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
}
.tool-modal .modal-body .meta-active-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: #1f2937;
    cursor: pointer;
    margin-bottom: 0;
    flex-shrink: 0;
    white-space: nowrap;
}
.tool-modal .modal-body .meta-active-check {
    width: 16px;
    height: 16px;
    margin: 0;
    padding: 0;
    accent-color: #3b82f6;
    cursor: pointer;
    flex-shrink: 0;
}
.tool-modal .modal-body .meta-active-hint {
    font-size: 12px;
    color: #9ca3af;
    line-height: 1.4;
    min-width: 0;
}

.empty-tip {
    color: #9ca3af;
    font-size: 13px;
}

/* 分类选择器（内嵌输入框，向上展开） */
.cat-select-wrap { position: relative; flex-shrink: 0; display: flex; align-items: center; margin-right: 8px; }
.cat-select-btn {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 14px; border-radius: 20px;
    border: 1px solid var(--primary); background: #edf3fe; color: #1e40af;
    cursor: pointer; font-size: 13px; white-space: nowrap; max-width: 180px;
    min-height: 30px;
}
.cat-select-label { overflow: hidden; text-overflow: ellipsis; }
.cat-caret { font-size: 10px; transition: transform .2s; }
.cat-select-wrap.open .cat-caret { transform: rotate(180deg); }
.cat-menu {
    position: absolute; bottom: calc(100% + 8px); left: 0;
    min-width: 200px; max-height: 260px; overflow-y: auto;
    background: #fff; border: 1px solid #e5e7eb; border-radius: 10px;
    box-shadow: 0 -6px 20px rgba(0,0,0,.12); padding: 6px;
    display: none; z-index: 50; list-style: none;
}
.cat-select-wrap.open .cat-menu { display: block; }
.cat-menu .cat-option {
    padding: 8px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
    color: #374151; display: flex; justify-content: space-between; align-items: center;
}
.cat-menu .cat-option:hover { background: #f0f6ff; }
.cat-menu .cat-option.selected { color: #1e40af; font-weight: 600; }
.cat-option .cat-tip { color: #9ca3af; font-size: 11px; font-weight: 400; }

/* 分类 chip 可点击 + 文档数徽章 */
.category-chip .cat-name { cursor: pointer; font-weight: 600; }
.category-chip .cat-count { color: #6b7280; font-size: 11px; background: #e5e7eb; padding: 1px 6px; border-radius: 10px; }

/* 分类编辑弹窗 */
.cat-edit-modal { max-width: 640px !important; max-height: 90vh !important; overflow-y: auto; }
.cat-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.cat-meta span { font-size: 12px; background: #f3f4f6; padding: 4px 10px; border-radius: 14px; color: #4b5563; }
.field-label { display: block; font-weight: 600; font-size: 13px; margin: 10px 0 6px; color: #374151; }
.cat-edit-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 12px; }
.btn-danger { background: #ef4444; color: #fff; border: none; padding: 8px 16px; border-radius: 8px; cursor: pointer; }
.btn-danger:hover { background: #dc2626; }

/* 管理页整体可滚动（修复下方内容被截断无法访问的问题） */
.manage-view { overflow-y: auto; height: 100%; }

.manage-view h2 {
    margin-bottom: 24px;
}

/* 通用按钮（分类管理 / 提示词卡片） */
.btn-secondary {
    background: #f3f4f6; color: #374151; border: 1px solid #d1d5db;
    padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.btn-secondary:hover { background: #e5e7eb; }
.mgmt-input-group .btn-secondary { white-space: nowrap; }

/* 系统提示词卡片 */
.prompt-list {
    display: flex; flex-wrap: wrap; gap: 14px; margin-top: 12px;
}
.prompt-card {
    flex: 1 1 260px; min-width: 230px; max-width: 340px;
    background: #fafbfc; border: 1px solid #e5e7eb; border-radius: 10px;
    padding: 14px 14px 12px; cursor: pointer;
    transition: box-shadow .15s ease, border-color .15s ease;
    display: flex; flex-direction: column;
}
.prompt-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); border-color: #93c5fd; }
.prompt-card-title { font-weight: 700; color: #1f2937; margin-bottom: 6px; }
.prompt-card-preview {
    font-size: 12px; color: #6b7280; line-height: 1.5; white-space: pre-line;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
    overflow: hidden; margin-bottom: 8px;
}
.prompt-card-actions { margin-top: auto; }
.prompt-edit-btn { display: inline-block; font-size: 12px; padding: 5px 14px; }
.empty-tip { color: #9ca3af; font-size: 13px; padding: 16px 0; }

/* 提示词编辑弹窗 */
.prompt-edit-modal { max-width: 860px !important; width: min(860px, 94vw); }
.prompt-edit-modal .modal-body { max-height: 72vh; overflow-y: auto; }
.prompt-edit-area {
    font-family: Consolas, Monaco, 'Courier New', monospace;
    font-size: 13px; line-height: 1.55; min-height: 320px !important;
    tab-size: 4; white-space: pre-wrap;
}

/* ===== 知识库原始文件卡片（聊天模式配置） ===== */
.kb-file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}
.kb-file-card {
    background: #fafbfc;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    cursor: pointer;
    transition: box-shadow .15s ease, border-color .15s ease;
}
.kb-file-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); border-color: #93c5fd; }
.kb-file-name { font-weight: 700; color: #1f2937; word-break: break-all; line-height: 1.4; }
.kb-file-info { font-size: 12px; color: #6b7280; display: flex; flex-wrap: wrap; gap: 6px 12px; }
.kb-file-info span { background: #f3f4f6; padding: 1px 8px; border-radius: 10px; }
.kb-file-view { margin-top: auto; font-size: 12px; padding: 5px 14px; align-self: flex-start; }
.kb-file-meta {
    font-size: 13px; color: #6b7280; margin-bottom: 10px;
    display: flex; flex-wrap: wrap; gap: 8px 16px;
}
.kb-file-meta span { background: #f3f4f6; padding: 2px 10px; border-radius: 10px; }
.kb-file-content {
    background: #f8fafc; border: 1px solid #e5e7eb; border-radius: 8px;
    padding: 14px; max-height: 60vh; overflow: auto; white-space: pre-wrap; word-break: break-word;
    font-family: Consolas, Monaco, 'Courier New', monospace; font-size: 13px; line-height: 1.6;
    color: #1f2937; margin: 0;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: #f1f3f5;
    border-radius: 50%;
    font-size: 18px;
    line-height: 1;
    color: #6b7280;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s, transform 0.15s;
}

.modal-close:hover {
    background: #e5e7eb;
    color: #1f2937;
    transform: rotate(90deg);
}

.modal-close:active {
    transform: scale(0.9);
}


@keyframes pulse {
    0% {
        opacity: 1;
        transform: scale(1);
    }
    50% {
        opacity: 0.6;
        transform: scale(1.05);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

@media (max-width: 400px) {
    .tool-group-grid {
        grid-template-columns: 1fr 1fr;
    }

    .nav-tab {
        font-size: 13px;
        padding: 5px 12px;
    }
}

/* ================================================================
   管理面板 → 顶栏操作人标识
   ================================================================ */
.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    color: #3730a3;
    font-size: 13px;
    padding: 3px 12px;
    border-radius: 20px;
    white-space: nowrap;
    cursor: default;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ================================================================
   管理面板 → 三大模块（系统设置 / 聊天模式配置 / 数据库配置）
   ================================================================ */
.manage-view {
    overflow-y: auto;
    height: 100%;
}

/* 与聊天页一致的顶部页签 */
.manage-view .manage-tabs {
    flex-wrap: wrap;
}

/* 页签下每个模块内容区 */
.manage-pane {
    display: none;
    margin-top: 20px;
}

.manage-pane.active {
    display: block;
}

/* 区块内提示小字 */
.config-hint {
    font-size: 13px;
    color: #6b7280;
    line-height: 1.7;
    margin: -6px 0 16px;
    background: #f8fafc;
    border: 1px solid #eef0f3;
    border-radius: 8px;
    padding: 8px 12px;
}

.config-hint code {
    background: #eef2ff;
    color: #3730a3;
    padding: 1px 6px;
    border-radius: 6px;
    font-size: 12px;
}

/* ---- 系统设置：表单网格 ---- */
.setting-grid {
    display: grid;
    gap: 12px 16px;
}

.setting-grid.two {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.setting-item.span2 {
    grid-column: span 2;
}

@media (max-width: 640px) {
    .setting-item.span2 {
        grid-column: span 1;
    }
}

/* 密码显示/隐藏 */
.pw-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.pw-wrap .mgmt-input {
    padding-right: 42px;
}

.pw-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 4px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.pw-toggle:hover {
    opacity: 1;
}

/* 区块保存按钮行 */
.setting-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.setting-status {
    font-size: 13px;
    color: #4b5563;
}

/* 管理面板内主按钮与现有 .btn-secondary 统一尺寸 */
.manage-view .btn-primary {
    background: #2563eb;
    border: 1px solid #2563eb;
    color: #fff;
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}

.manage-view .btn-primary:hover {
    background: #1d4ed8;
    border-color: #1d4ed8;
}

.manage-view .btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* 系统提示词（折叠进系统设置模块） */
details.prompt-section {
    display: block;
}

details.prompt-section > summary.mgmt-title {
    cursor: pointer;
    margin-bottom: 0;
    list-style: none;
    user-select: none;
}

details.prompt-section > summary.mgmt-title::-webkit-details-marker {
    display: none;
}

details.prompt-section[open] > summary.mgmt-title {
    margin-bottom: 12px;
}

/* ---- 数据库配置卡片 ---- */
.db-config-card {
    background: #f9fafb;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    padding: 16px 18px;
    margin-bottom: 16px;
}

.db-config-title {
    font-size: 15px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.db-config-tag {
    font-size: 12px;
    color: #6b7280;
    font-weight: 400;
    background: #eef2ff;
    color: #3730a3;
    padding: 2px 10px;
    border-radius: 12px;
}

.db-fields {
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.db-fields .mgmt-input {
    width: 100%;
}

.db-test-cell {
    display: flex;
    align-items: flex-end;
}

.db-test-result {
    display: none;
    margin-top: 10px;
    padding: 7px 12px;
    border-radius: 8px;
    font-size: 13px;
    line-height: 1.6;
}

.db-test-result.ok {
    display: block;
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.db-test-result.err {
    display: block;
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
    word-break: break-all;
}

/* ---- 视图元数据：工具栏 ---- */
.viewmeta-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.viewmeta-import,
.viewmeta-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.toolbar-label {
    font-size: 13px;
    color: #374151;
    font-weight: 500;
    white-space: nowrap;
}

.index-status {
    font-size: 12px;
    padding: 3px 12px;
    border-radius: 12px;
    background: #f3f4f6;
    color: #6b7280;
    white-space: nowrap;
}

.index-status.ok {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.index-status.off {
    background: #fffbeb;
    color: #92400e;
    border: 1px solid #fde68a;
}

/* ---- 视图元数据：表格 ---- */
.db-table-wrap .meta-table {
    font-size: 13px;
}

.db-table-wrap .meta-table th,
.db-table-wrap .meta-table td {
    padding: 7px 12px;
    vertical-align: middle;
}

.db-table-wrap .meta-table td {
    word-break: break-all;
}

.meta-table .view-name {
    font-weight: 600;
    color: #1e40af;
    word-break: break-all;
}

.meta-table .view-desc {
    color: #4b5563;
    max-width: 360px;
    white-space: normal;
    word-break: break-word;
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px;
}

.field-count-badge {
    background: #e0e7ff;
    color: #3730a3;
    font-size: 12px;
    padding: 1px 8px;
    border-radius: 10px;
    white-space: nowrap;
}

.meta-table .view-time {
    color: #6b7280;
    font-size: 12px;
    white-space: nowrap;
}

.pill-on,
.pill-off {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 12px;
    white-space: nowrap;
}

.pill-on {
    background: #dcfce7;
    color: #15803d;
}

.pill-off {
    background: #f3f4f6;
    color: #9ca3af;
}

.btn-sm {
    display: inline-block;
    padding: 3px 10px;
    font-size: 12px;
    border: 1px solid #d1d5db;
    background: #f3f4f6;
    color: #374151;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    white-space: nowrap;
}

.btn-sm:hover {
    background: #e5e7eb;
}

.btn-sm.vm-edit {
    background: #eff6ff;
    color: #1d4ed8;
    border-color: #bfdbfe;
}

.btn-sm.vm-edit:hover {
    background: #dbeafe;
}

.btn-sm.vm-del {
    background: #fef2f2;
    color: #dc2626;
    border-color: #fecaca;
}

.btn-sm.vm-del:hover {
    background: #fee2e2;
}

/* 视图元数据编辑弹窗 */
#viewMetaModal .tool-modal {
    max-width: 720px;
}

#viewMetaModal .prompt-textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    resize: vertical;
    transition: border-color 0.2s;
}

#viewMetaModal .prompt-textarea:focus {
    border-color: #3b82f6;
}

/* 响应式：管理面板窄屏微调 */
@media (max-width: 640px) {
    .manage-view .viewmeta-toolbar,
    .manage-view .viewmeta-import,
    .manage-view .viewmeta-actions {
        align-items: stretch;
    }

    .manage-view .viewmeta-import .mgmt-select {
        width: 100%;
    }

    .manage-view .setting-actions {
        align-items: flex-start;
        flex-direction: column;
    }
}