/* ═══════════════════════════════════════════════════════════════
   SellerAgent — 销售智能体 样式
   面向零基础用户：清晰、直观、易操作
   ═══════════════════════════════════════════════════════════════ */

:root {
    --primary: #4f46e5;
    --primary-light: #e0e7ff;
    --primary-dark: #3730a3;
    --success: #059669;
    --success-light: #d1fae5;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --bg: #f8fafc;
    --bg-white: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --radius: 10px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07), 0 2px 4px rgba(0, 0, 0, 0.06);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Microsoft YaHei", "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════
   顶部导航栏
   ═══════════════════════════════════════════════════════════════ */

.header {
    background: var(--bg-white);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow);
    z-index: 10;
    position: relative;
}

.header-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-title .icon {
    font-size: 24px;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 16px;
    font-size: 13px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse 2s infinite;
}

.status-dot.offline {
    background: var(--danger);
    animation: none;
}

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

/* ═══════════════════════════════════════════════════════════════
   主布局：左右两栏
   ═══════════════════════════════════════════════════════════════ */

.main-container {
    display: flex;
    height: calc(100vh - 56px);
}

/* ═══════════════════════════════════════════════════════════════
   左侧：对话面板
   ═══════════════════════════════════════════════════════════════ */

.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--bg-white);
    border-right: 1px solid var(--border);
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* 消息气泡 */
.message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: fadeIn 0.3s ease;
}

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

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

.message.agent {
    align-self: flex-start;
}

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

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

.message.agent .message-avatar {
    background: var(--success-light);
    color: var(--success);
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
}

.message.user .message-bubble {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.agent .message-bubble {
    background: #f1f5f9;
    color: var(--text);
    border-bottom-left-radius: 4px;
}

/* 来源引用 */
.message-sources {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    font-size: 12px;
    color: var(--text-muted);
}

.message-sources .source-tag {
    display: inline-block;
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 2px 8px;
    border-radius: 12px;
    margin: 2px 4px 2px 0;
    font-size: 11px;
}

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

.chat-input-row {
    display: flex;
    gap: 10px;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    min-height: 48px;
    max-height: 120px;
}

.chat-input:focus {
    border-color: var(--primary);
}

.btn-send {
    padding: 12px 24px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    white-space: nowrap;
}

.btn-send:hover {
    background: var(--primary-dark);
}

.btn-send:disabled {
    background: #cbd5e1;
    cursor: not-allowed;
}

/* ═══════════════════════════════════════════════════════════════
   右侧：知识库管理面板
   ═══════════════════════════════════════════════════════════════ */

/* 会话侧边栏 */
.session-sidebar {
    width: 200px;
    min-width: 180px;
    background: var(--bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.session-sidebar-header {
    padding: 10px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.session-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 4px;
}

.session-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 2px;
    font-size: 13px;
    color: var(--text);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.15s;
    position: relative;
}

.session-item:hover {
    background: var(--primary-light);
}

.session-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
}

.session-item-preview {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 4px;
}

.session-item-delete {
    opacity: 0;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 14px;
    padding: 2px 4px;
    border-radius: 4px;
    flex-shrink: 0;
    transition: opacity 0.15s;
}

.session-item:hover .session-item-delete {
    opacity: 1;
}

.session-item-delete:hover {
    color: var(--danger);
    background: var(--danger-light);
}

.session-item-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.kb-panel {
    width: 420px;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    min-height: 0; /* 关键：允许 flex 子元素按比例收缩 */
}

.kb-section {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0; /* 统计和添加区域不收缩 */
}

.kb-section:last-child {
    flex: 1;
    flex-shrink: 1;
    overflow-y: auto;
    min-height: 150px;
    display: flex;
    flex-direction: column;
}

.kb-section-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* 统计卡片 */
.stats-row {
    display: flex;
    gap: 10px;
}

.stat-card {
    flex: 1;
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 12px;
    text-align: center;
    box-shadow: var(--shadow);
}

.stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* 添加文档表单 */
.kb-add-form {
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: var(--shadow);
}

.form-group {
    margin-bottom: 12px;
}

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

.form-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.form-input,
.form-textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.form-input:focus,
.form-textarea:focus {
    border-color: var(--primary);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
    max-height: 150px;
}

.form-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* 按钮 */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

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

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

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

.btn-success:hover {
    background: #047857;
}

.btn-danger {
    background: var(--bg-white);
    color: var(--danger);
    border: 1px solid var(--danger-light);
}

.btn-danger:hover {
    background: var(--danger-light);
}

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

.btn-block {
    width: 100%;
    justify-content: center;
}

/* 文件上传按钮 */
.file-upload-wrapper {
    position: relative;
}

.file-upload-input {
    display: none;
}

.btn-upload {
    background: var(--bg-white);
    color: var(--primary);
    border: 1px dashed var(--primary);
    padding: 10px;
    border-radius: 8px;
    text-align: center;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s;
}

.btn-upload:hover {
    background: var(--primary-light);
}

/* 上传进度条 */
.upload-progress {
    margin-top: 10px;
    padding: 0 2px;
}

.progress-bar-wrapper {
    width: 100%;
    height: 8px;
    background: #e2e8f0;
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #4f46e5, #818cf8);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-bar-fill.active {
    animation: progressPulse 1.5s ease-in-out infinite;
}

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

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

/* 文档列表 */
.doc-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.doc-item {
    background: var(--bg-white);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s;
}

.doc-item:hover {
    box-shadow: var(--shadow-md);
}

.doc-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
}

.doc-item-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}

.doc-item-meta {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    gap: 12px;
}

.doc-item-preview {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-top: 4px;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-muted);
}

.empty-state .icon {
    font-size: 40px;
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 13px;
}

/* Toast 提示 */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    color: white;
    z-index: 1000;
    animation: slideIn 0.3s ease;
    box-shadow: var(--shadow-md);
}

.toast.success {
    background: var(--success);
}

.toast.error {
    background: var(--danger);
}

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

/* 加载状态 */
.loading {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* 流式输出闪烁光标 */
.streaming-cursor {
    display: inline-block;
    width: 2px;
    height: 1.2em;
    background: var(--primary);
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: blink 0.8s step-end infinite;
}
@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* 图标 — 统一使用 SVG，可通过 font-size 控制大小 */
.icon-img {
    width: 1em;
    height: 1em;
    vertical-align: -0.15em;
    display: inline-block;
}

/* 文档查看弹窗 */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

.modal-content {
    background: var(--bg-white);
    border-radius: 12px;
    width: min(700px, 90vw);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

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

.modal-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px 8px;
    border-radius: 4px;
}

.modal-close:hover {
    background: #f1f5f9;
    color: var(--text);
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.8;
}

/* Markdown 渲染样式（弹窗 + 对话气泡共用） */
.markdown-body table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
    font-size: 13px;
}
.markdown-body th, .markdown-body td {
    border: 1px solid var(--border);
    padding: 8px 12px;
    text-align: left;
}
.markdown-body th {
    background: #f1f5f9;
    font-weight: 600;
}
.markdown-body h1, .markdown-body h2, .markdown-body h3 {
    margin: 16px 0 8px;
    font-weight: 700;
}
.markdown-body h2 { font-size: 18px; }
.markdown-body h3 { font-size: 16px; }
.markdown-body ul, .markdown-body ol {
    padding-left: 24px;
    margin: 8px 0;
}
.markdown-body p { margin: 8px 0; }
.markdown-body code {
    background: #f1f5f9;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}
.markdown-body pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 12px 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
}
.markdown-body pre code {
    background: none;
    padding: 0;
    color: inherit;
}

/* 文档列表项点击样式 */
.doc-item {
    cursor: pointer;
}

/* ═══════════════════════════════════════════════════════════════
   上传弹窗（宝塔风格）
   ═══════════════════════════════════════════════════════════════ */

.upload-modal-content {
    background: var(--bg-white);
    border-radius: 12px;
    width: 560px;
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2);
    animation: fadeIn 0.2s ease;
}

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

.upload-modal-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 工具栏 */
.upload-modal-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--bg);
}

.upload-hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* 文件队列列表 */
.upload-file-list {
    flex: 1;
    min-height: 200px;
    max-height: 360px;
    overflow-y: auto;
    padding: 0;
    background: var(--bg-white);
}

.upload-empty {
    text-align: center;
    padding: 40px 16px;
    color: var(--text-muted);
}

.upload-empty p {
    font-size: 13px;
    margin: 0;
}

/* 单个文件项 */
.upload-file-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s;
}

.upload-file-item:hover {
    background: #f8fafc;
}

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

.upload-file-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 700;
    color: white;
}

.upload-file-icon.pdf  { background: #ef4444; }
.upload-file-icon.docx { background: #3b82f6; }
.upload-file-icon.xlsx { background: #22c55e; }
.upload-file-icon.pptx { background: #f97316; }
.upload-file-icon.txt  { background: #64748b; }
.upload-file-icon.md   { background: #6366f1; }
.upload-file-icon.html { background: #ec4899; }
.upload-file-icon.img  { background: #14b8a6; }
.upload-file-icon.other { background: #94a3b8; }

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

.upload-file-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-file-size {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* 单个文件状态 */
.upload-file-status {
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
    min-width: 56px;
    text-align: right;
}

.upload-file-status.waiting {
    color: var(--text-muted);
}

.upload-file-status.uploading {
    color: var(--primary);
}

.upload-file-status.success {
    color: var(--success);
}

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

/* 移除文件按钮 */
.upload-file-remove {
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
}

.upload-file-remove:hover {
    background: var(--danger-light);
    color: var(--danger);
}

/* 文件项内的进度条 */
.upload-file-progress {
    width: 100%;
    height: 3px;
    background: #e2e8f0;
    border-radius: 2px;
    margin-top: 6px;
    overflow: hidden;
}

.upload-file-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #4f46e5, #818cf8);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.upload-file-progress-bar.active {
    animation: progressPulse 1.5s ease-in-out infinite;
}

/* 底部操作栏 */
.upload-modal-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.upload-summary {
    font-size: 12px;
    color: var(--text-secondary);
}

.upload-modal-actions {
    display: flex;
    gap: 8px;
}

/* ═══════════════════════════════════════════════════════════════
   移动端元素 — 桌面端默认隐藏
   ═══════════════════════════════════════════════════════════════ */
.mobile-menu-btn,
.mobile-kb-btn,
.mobile-panel-close,
.mobile-overlay,
.header-title-short,
.session-sidebar-label {
    display: none !important;
}

/* ═══════════════════════════════════════════════════════════════
   响应式 — 768px 断点（手机端）
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 768px) {

    /* 真机滚动修复：body 不能 overflow:hidden 否则 iOS 阻止所有子元素滚动 */
    body {
        position: static;
        width: 100%;
        height: 100dvh;
        overflow: visible;
        overscroll-behavior: none;
    }

    /* ── 全局 ── */
    :root {
        --radius: 8px;
    }

    /* ── Header：固顶、缩高度 ── */
    .header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 100;
        padding: 0 12px;
        height: 48px;
    }

    .header-title {
        font-size: 15px;
        gap: 6px;
        flex: 1;
        justify-content: center;
    }
    .header-title .icon-img { font-size: 20px !important; }

    /* 标题：手机用短版 */
    .header-title-text   { display: none; }
    .header-title-short  { display: inline !important; }

    /* header 中的统计文字在手机上隐藏 */
    .header-stat-item { display: none; }
    .header-status    { gap: 10px; font-size: 12px; }

    /* ── 汉堡菜单 ── */
    .mobile-menu-btn {
        display: flex !important;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        gap: 4px;
        width: 36px;
        height: 36px;
        padding: 6px;
        background: none;
        border: none;
        border-radius: 6px;
        cursor: pointer;
        flex-shrink: 0;
        order: -1;
    }
    .mobile-menu-btn:active { background: var(--primary-light); }

    .hamburger-line {
        display: block;
        width: 20px;
        height: 2px;
        background: var(--text);
        border-radius: 2px;
        transition: all 0.25s ease;
        transform-origin: center;
    }
    .mobile-menu-btn.open .hamburger-line:nth-child(1) { transform: translateY(6px) rotate(45deg); }
    .mobile-menu-btn.open .hamburger-line:nth-child(2) { opacity: 0; }
    .mobile-menu-btn.open .hamburger-line:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

    /* ── 知识库按钮 ── */
    .mobile-kb-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        padding: 4px;
        background: none;
        border: none;
        border-radius: 6px;
        cursor: pointer;
        flex-shrink: 0;
    }
    .mobile-kb-btn:active { background: var(--primary-light); }

    /* ── 遮罩层 ── */
    .mobile-overlay {
        display: block !important;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.35);
        z-index: 80;
        opacity: 0;
        visibility: hidden;
		pointer-events: none;
        transition: opacity 0.25s ease, visibility 0.25s ease;
    }
    .mobile-overlay.open { opacity: 1; visibility: visible; pointer-events: auto; }

    /* ── 主容器：留出 header 高度 ── */
    .main-container {
        margin-top: 48px;
        height: calc(100vh - 48px); height: calc(100dvh - 48px);
        overflow: hidden;
    }

    /* ── 会话侧栏：左抽屉 ── */
    .session-sidebar {
        position: fixed;
        top: 48px;
        left: 0;
        bottom: 0;
        width: 280px;
        max-width: 85vw;
        min-width: unset;
        z-index: 90;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: none;
        border-right: none;
    }
    .session-sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }
    /* 抽屉内恢复被 1100px 收缩隐藏的文字 */
    .session-sidebar .session-item-preview,
    .session-sidebar .session-item-time,
    .session-sidebar .session-item-delete { display: unset; }
    .session-sidebar .session-sidebar-header button { font-size: 13px; }

    .session-sidebar-header {
        display: flex;
        flex-direction: column;
        gap: 8px;
        padding: 12px;
    }
    .session-sidebar-label {
        display: block !important;
        font-size: 14px;
        font-weight: 700;
        color: var(--text);
    }

    /* 面板关闭按钮 */
    .mobile-panel-close {
        display: flex !important;
        align-items: center;
        justify-content: center;
        position: absolute;
        top: 2px;
        right: 10px;
        width: 30px;
        height: 30px;
        padding: 0;
        background: none;
        border: none;
        border-radius: 50%;
        font-size: 18px;
        color: var(--text-muted);
        cursor: pointer;
        z-index: 5;
    }
    .mobile-panel-close:active { background: #f1f5f9; color: var(--text); }

    /* ── 对话面板 ── */
    .chat-panel {
        flex: 1;
        min-width: 0;
        border-right: none;
    }
    .chat-messages { padding: 12px; gap: 12px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; touch-action: pan-y; }

    .message       { max-width: 92%; }
    .message.user  { max-width: 88%; }
    .message-avatar { width: 30px; height: 30px; font-size: 15px; }
    .message-bubble { padding: 10px 12px; font-size: 14px; line-height: 1.55; }
    .message.user .message-bubble  { border-bottom-right-radius: 3px; }
    .message.agent .message-bubble { border-bottom-left-radius: 3px; }

    .message-sources          { font-size: 11px; }
    .message-sources .source-tag { font-size: 10px; padding: 1px 6px; margin: 1px 3px 1px 0; }

    /* ── 输入区域 ── */
    .chat-input-area { padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
    .chat-input-row  { gap: 8px; }
    .chat-input {
        padding: 10px 12px;
        font-size: 15px;
        min-height: 42px;
        max-height: 100px;
        border-radius: 8px;
    }
    .btn-send { padding: 10px 16px; font-size: 14px; border-radius: 8px; }

    /* ── 知识库面板：右抽屉 ── */
    .kb-panel {
        position: fixed;
        top: 48px;
        right: 0;
        bottom: 0;
        width: 340px;
        max-width: 90vw;
        z-index: 90;
        transform: translateX(100%);
        transition: transform 0.25s ease;
        box-shadow: none;
    }
    .kb-panel.open {
        transform: translateX(0);
        box-shadow: -4px 0 20px rgba(0,0,0,0.15);
    }
    .kb-panel .kb-section-title { position: relative; }
    .kb-section   { padding: 12px; }
    /* 真机滚动 */
    .session-list, .kb-section:last-child {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        touch-action: pan-y;
    }
    .stats-row    { gap: 8px; }
    .stat-card    { padding: 10px; }
    .stat-value   { font-size: 20px; }
    .stat-label   { font-size: 11px; }
    .kb-add-form  { padding: 10px; }
    .form-group   { margin-bottom: 10px; }
    .form-label   { font-size: 12px; }
    .form-input, .form-textarea { padding: 8px 10px; font-size: 14px; }
    .form-textarea { min-height: 60px; max-height: 120px; }
    .btn          { font-size: 13px; padding: 8px 14px; }
    .btn-upload   { padding: 14px 10px; font-size: 13px; }
    .btn-upload small { font-size: 11px; }
    .doc-item       { padding: 10px; }
    .doc-item-title { font-size: 13px; }
    .doc-item-meta  { font-size: 10px; gap: 8px; }

    /* ── 弹窗：底部弹出 ── */
    .modal-overlay  { align-items: flex-end; }
    .modal-content  { width: 100%; max-width: 100%; max-height: 85vh; border-radius: 16px 16px 0 0; }
    .modal-header   { padding: 14px 16px; position: sticky; top: 0; background: var(--bg-white); z-index: 1; border-radius: 16px 16px 0 0; }
    .modal-title    { font-size: 15px; }
    .modal-close    { font-size: 22px; padding: 6px 10px; }
    .modal-body     { padding: 16px; font-size: 14px; }

    /* ── 上传弹窗：移动端全屏 ── */
    .upload-modal-content { width: 100%; max-width: 100%; max-height: 90vh; border-radius: 16px 16px 0 0; }
    .upload-modal-header  { padding: 14px 16px; }
    .upload-modal-title   { font-size: 15px; }
    .upload-modal-toolbar { padding: 10px 16px; gap: 8px; flex-wrap: wrap; }
    .upload-hint          { font-size: 11px; width: 100%; }
    .upload-file-list     { max-height: 40vh; }
    .upload-file-item     { padding: 10px 16px; }
    .upload-file-name     { font-size: 12px; }
    .upload-file-size     { font-size: 10px; }
    .upload-file-icon     { width: 32px; height: 32px; font-size: 12px; }
    .upload-modal-footer  { padding: 12px 16px; flex-wrap: wrap; gap: 8px; }
    .upload-summary       { width: 100%; text-align: center; }

    /* Markdown 表格横向滚动 */
    .markdown-body table { display: block; overflow-x: auto; white-space: nowrap; font-size: 12px; }
    .markdown-body th, .markdown-body td { padding: 6px 10px; }
    .markdown-body pre  { padding: 10px 12px; font-size: 12px; }
    .markdown-body h2   { font-size: 16px; }
    .markdown-body h3   { font-size: 14px; }

    /* ── Toast：顶部居中 ── */
    .toast {
        top: 56px;
        left: 50%;
        right: auto;
        transform: translateX(-50%);
        max-width: 90vw;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 13px;
        padding: 10px 18px;
        animation: toastSlideDown 0.3s ease;
    }
    @keyframes toastSlideDown {
        from { transform: translateX(-50%) translateY(-12px); opacity: 0; }
        to   { transform: translateX(-50%) translateY(0);    opacity: 1; }
    }

    .empty-state          { padding: 24px 12px; }
    .empty-state .icon    { font-size: 32px; }
}

/* ═══════════════════════════════════════════════════════════════
   响应式 — 480px（小屏手机微调）
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 480px) {
    .header           { padding: 0 8px; height: 44px; }
    .header-title     { font-size: 14px; }
    .header-title .icon-img { font-size: 18px !important; }
    .main-container   { margin-top: 44px; height: calc(100vh - 44px); height: calc(100dvh - 44px); }
    .session-sidebar  { top: 44px; }
    .kb-panel         { top: 44px; width: 100%; max-width: 100vw; }

    .chat-messages    { padding: 10px; gap: 10px; }
    .message          { max-width: 96%; }
    .message.user     { max-width: 92%; }
    .message-bubble   { font-size: 13px; padding: 8px 10px; }

    .chat-input-area  { padding: 8px 10px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
    .chat-input       { font-size: 14px; padding: 8px 10px; min-height: 38px; }
    .btn-send         { padding: 8px 14px; font-size: 13px; }

    .toast            { top: 50px; font-size: 12px; padding: 8px 14px; }
}

/* ═══════════════════════════════════════════════════════════════
   响应式 — 1100px（中等屏幕，侧栏收窄）
   必须在 768px 断点之后，以免覆盖手机样式
   ═══════════════════════════════════════════════════════════════ */

@media (min-width: 769px) and (max-width: 1100px) {
    .session-sidebar {
        width: 60px;
        min-width: 60px;
    }
    .session-sidebar .session-item-preview,
    .session-sidebar .session-item-time,
    .session-sidebar .session-item-delete {
        display: none;
    }
    .session-sidebar .session-sidebar-header button {
        font-size: 0;
    }
    .session-sidebar .session-sidebar-header button .icon-img {
        margin: 0;
    }
    .kb-panel {
        width: 340px;
    }
}
