:root {
    --primary: #4f46e5;
    --primary-hover: #6366f1;
    --primary-active: #4338ca;
    --primary-light: rgba(79, 70, 229, 0.08);
    --primary-lighter: rgba(79, 70, 229, 0.04);
    --secondary: #0891b2;
    --secondary-light: rgba(8, 145, 178, 0.08);
    --accent: #d97706;
    --accent-light: rgba(217, 119, 6, 0.08);
    --success: #059669;
    --success-light: rgba(5, 150, 105, 0.08);
    --danger: #dc2626;
    --danger-light: rgba(220, 38, 38, 0.08);
    --warning: #d97706;
    --warning-light: rgba(217, 119, 6, 0.08);
    --info: #2563eb;
    --info-light: rgba(37, 99, 235, 0.08);

    --bg-base: #f5f6f8;
    --bg-surface: #ffffff;
    --bg-elevated: #f0f2f5;
    --bg-hover: #e6e9ee;
    --bg-active: #d9dde5;
    --bg-input: #ffffff;
    --bg-overlay: rgba(15, 23, 42, 0.4);

    --border: #e0e3ea;
    --border-light: #d0d4de;
    --border-focus: var(--primary);
    --border-subtle: #ebeef3;

    --text-primary: #1a1d2e;
    --text-secondary: #5a5f78;
    --text-muted: #9198b0;
    --text-inverse: #ffffff;
    --text-on-primary: #ffffff;

    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.05);
    --shadow-primary: 0 4px 14px rgba(79, 70, 229, 0.15);
    --shadow-inset: inset 0 1px 2px rgba(15, 23, 42, 0.06);

    --transition-fast: 120ms ease;
    --transition: 200ms ease;
    --transition-slow: 300ms ease;
    --transition-spring: 300ms cubic-bezier(0.34, 1.56, 0.64, 1);

    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;

    --text-xs: 11px;
    --text-sm: 12px;
    --text-base: 13px;
    --text-md: 14px;
    --text-lg: 15px;
    --text-xl: 17px;
    --text-2xl: 20px;
    --text-3xl: 24px;

    --leading-tight: 1.25;
    --leading-snug: 1.375;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;

    --header-h: 50px;
    --sidebar-w: 300px;
}

/* P11: 深色主题完善 */
[data-theme="dark"] {
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --primary-active: #4f46e5;
    --primary-light: rgba(129, 140, 248, 0.12);
    --primary-lighter: rgba(129, 140, 248, 0.06);
    --secondary: #22d3ee;
    --secondary-light: rgba(34, 211, 238, 0.12);
    --accent: #fbbf24;
    --accent-light: rgba(251, 191, 36, 0.12);
    --success: #34d399;
    --success-light: rgba(52, 211, 153, 0.12);
    --danger: #f87171;
    --danger-light: rgba(248, 113, 113, 0.12);
    --warning: #fbbf24;
    --warning-light: rgba(251, 191, 36, 0.12);
    --info: #60a5fa;
    --info-light: rgba(96, 165, 250, 0.12);

    --bg-base: #0f1117;
    --bg-surface: #1a1b26;
    --bg-elevated: #24253a;
    --bg-hover: #2a2b40;
    --bg-active: #353650;
    --bg-input: #1e1f30;
    --bg-overlay: rgba(0, 0, 0, 0.6);

    --border: #2e3045;
    --border-light: #383a52;
    --border-subtle: #252640;

    --text-primary: #e2e4f0;
    --text-secondary: #a0a3bd;
    --text-muted: #6b6f8d;
    --text-inverse: #0f1117;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.25), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.35), 0 4px 6px -4px rgba(0, 0, 0, 0.2);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
    --shadow-primary: 0 4px 14px rgba(129, 140, 248, 0.2);
    --shadow-inset: inset 0 1px 2px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] body { background: var(--bg-base); color: var(--text-primary); }
[data-theme="dark"] input, [data-theme="dark"] textarea, [data-theme="dark"] select {
    background: var(--bg-input); color: var(--text-primary); border-color: var(--border);
}
[data-theme="dark"] ::-webkit-scrollbar { width: 6px; height: 6px; }
[data-theme="dark"] ::-webkit-scrollbar-track { background: var(--bg-base); }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
[data-theme="dark"] .sidebar { background: var(--bg-surface); border-color: var(--border); }
[data-theme="dark"] .main-content { background: var(--bg-base); }
[data-theme="dark"] .chat-bubble { background: var(--bg-elevated); color: var(--text-primary); }
[data-theme="dark"] .chat-msg.user .chat-bubble { background: var(--primary); color: var(--text-inverse); }
[data-theme="dark"] .source-item { background: var(--bg-elevated); border-color: var(--border); }
[data-theme="dark"] .source-item:hover { background: var(--bg-hover); }
[data-theme="dark"] .toolbar { background: var(--bg-surface); border-color: var(--border); }
[data-theme="dark"] .toolbar button { color: var(--text-secondary); }
[data-theme="dark"] .toolbar button:hover { background: var(--bg-hover); color: var(--text-primary); }
[data-theme="dark"] .wiki-content { background: var(--bg-surface); color: var(--text-primary); }
[data-theme="dark"] .wiki-sidebar-item { color: var(--text-secondary); }
[data-theme="dark"] .wiki-sidebar-item:hover, [data-theme="dark"] .wiki-sidebar-item.active { background: var(--bg-hover); color: var(--text-primary); }
[data-theme="dark"] .kg-container canvas { background: var(--bg-base); }
[data-theme="dark"] .login-container { background: var(--bg-surface); }
[data-theme="dark"] .settings-panel { background: var(--bg-surface); border-color: var(--border); }
[data-theme="dark"] .modal-content { background: var(--bg-surface); border-color: var(--border); }
[data-theme="dark"] .toast { background: var(--bg-elevated); color: var(--text-primary); border-color: var(--border); }

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

body {
    font-family: var(--font-sans);
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: var(--leading-normal);
    height: 100vh;
    overflow: hidden;
    font-size: var(--text-md);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

svg {
    flex-shrink: 0;
}

.icon-btn svg {
    width: 16px;
    height: 16px;
}

.icon-btn.sm svg {
    width: 14px;
    height: 14px;
}

.view-tab svg {
    width: 14px;
    height: 14px;
}

.toolbar-btn svg {
    width: 14px;
    height: 14px;
}

.send-btn svg {
    width: 16px;
    height: 16px;
}

.logo svg {
    width: 24px;
    height: 24px;
}

.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.header {
    height: var(--header-h);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 16px;
    flex-shrink: 0;
    z-index: 100;
    position: relative;
}

.header {
    background: var(--bg-surface);
    box-shadow: var(--shadow-xs);
}

.header-left { display: flex; align-items: center; gap: 12px; }

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--text-primary);
    cursor: pointer;
    text-decoration: none;
    letter-spacing: -0.4px;
    transition: opacity var(--transition-fast);
}

.logo:hover { opacity: 0.85; }
.logo svg { color: var(--primary); }

.nav-tabs {
    display: flex;
    gap: 2px;
    background: var(--bg-elevated);
    padding: 3px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
}

.nav-tab {
    padding: 7px 18px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--text-md);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
    letter-spacing: -0.1px;
}

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

.nav-tab.active {
    background: var(--primary);
    color: var(--text-on-primary);
    box-shadow: var(--shadow-primary);
}

.nav-tab svg {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
}

.header-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.header-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-sm);
    color: var(--text-muted);
    font-weight: 500;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: var(--radius-full);
    background: var(--success);
    box-shadow: 0 0 6px rgba(16, 185, 129, 0.4);
    animation: statusPulse 2s ease-in-out infinite;
}

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

.workspace {
    display: flex;
    flex: 1;
    overflow: hidden;
    background: #ffffff;
}

.sidebar {
    width: var(--sidebar-w);
    min-width: 240px;
    max-width: 420px;
    background: #fbfbfc;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    overflow: hidden;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-direction: row;
    gap: 10px;
    padding: 16px 14px 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-title {
    font-size: 18px;
    font-weight: 800;
    color: #151922;
    text-transform: none;
    letter-spacing: 0;
    flex: 0 0 auto;
    white-space: nowrap;
}

.sidebar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    padding: 4px;
    border: 1px solid #e6e9ee;
    border-radius: 8px;
    background: #f7f8fa;
    flex: 0 0 auto;
    width: auto;
    min-width: 0;
    max-width: none;
}

.sidebar-actions .icon-btn {
    width: 30px;
    height: 30px;
    flex: 0 0 30px;
    border-radius: 6px;
    background: #ffffff;
    border: 1px solid transparent;
    color: #4b5563;
}

.sidebar-actions .icon-btn:hover {
    border-color: #d7dce4;
    background: #ffffff;
    color: #111827;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.sidebar-actions .icon-btn:nth-child(1),
.sidebar-actions .icon-btn:nth-child(2) {
    color: #5b45d9;
    background: #f4f1ff;
}

@media (max-width: 1180px) {
    .sidebar-header {
        align-items: stretch;
        flex-direction: column;
    }

    .sidebar-actions {
        max-width: none;
        justify-content: space-between;
    }
}

.sidebar-search {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 18px 8px;
    padding: 8px 10px;
    border: 1px solid #dfe3ea;
    border-radius: 6px;
    background: #ffffff;
}

.sidebar-search svg { color: var(--text-muted); flex-shrink: 0; width: 14px; height: 14px; }

.sidebar-search input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
    font-family: var(--font-sans);
}

.sidebar-search input::placeholder { color: var(--text-muted); }

.sidebar-tree {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 0 16px;
}

.tree-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 24px;
    gap: 8px;
}

.tree-empty svg { opacity: 0.3; width: 44px; height: 44px; }
.tree-empty p { font-size: var(--text-md); }
.tree-empty .hint { font-size: var(--text-sm); opacity: 0.6; }

.tree-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 4px 12px 4px calc(18px + var(--depth, 0) * 18px);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 14px;
    color: #20242d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    user-select: none;
    border-radius: 0;
    position: relative;
}

.tree-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--primary);
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.tree-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.tree-item.active {
    background: transparent;
    color: #6d4cff;
}
.tree-item.active::before { opacity: 1; }

.tree-item .icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.tree-item .icon svg { width: 15px; height: 15px; }
.tree-item .icon.folder svg { color: var(--accent); }
.tree-item .icon.file-md svg { color: var(--primary); }
.tree-item .icon.file-txt svg { color: var(--text-muted); }
.tree-item .icon.file-img svg { color: var(--secondary); }
.tree-item .icon.file-pdf svg { color: #ef4444; }
.tree-item .icon.file-docx svg { color: #3b82f6; }
.tree-item .icon.file-xlsx svg { color: #22c55e; }
.tree-item .icon.file-pptx svg { color: #f97316; }
.tree-item .icon.file-csv svg { color: #22c55e; }
.tree-item .icon.file-json svg { color: #eab308; }
.tree-item .icon.file-html svg { color: #f97316; }
.tree-item .icon.file-default svg { color: var(--text-muted); }

.tree-item .name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tree-item .badge {
    font-size: var(--text-xs);
    padding: 1px 6px;
    border-radius: var(--radius-full);
    background: transparent;
    color: #a0a6b2;
    flex-shrink: 0;
    font-weight: 500;
}

.tree-file-actions {
    display: none;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
    margin-left: auto;
}

.tree-file-item:hover .tree-file-actions {
    display: flex;
}

.tree-item.dragging {
    opacity: 0.4;
    background: var(--primary-lighter);
}

.tree-item.drop-before {
    box-shadow: inset 0 2px 0 0 var(--primary);
}

.tree-item.drop-after {
    box-shadow: inset 0 -2px 0 0 var(--primary);
}

.tree-item.drop-inside {
    background: var(--primary-light);
    outline: 1px dashed var(--primary);
    outline-offset: -1px;
    border-radius: var(--radius-sm);
}

.tree-item[draggable="true"] {
    cursor: grab;
}

.tree-item[draggable="true"]:active {
    cursor: grabbing;
}

#file-tree.drag-over-root {
    background: var(--primary-lighter);
    outline: 1px dashed var(--primary);
    outline-offset: -2px;
    border-radius: var(--radius-sm);
}

.tree-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: var(--transition);
    padding: 0;
}

.tree-action-btn:hover {
    background: var(--bg-active);
    color: var(--primary);
}

.tree-action-convert:hover {
    color: var(--secondary);
}

.tree-action-delete {
    color: var(--text-muted);
}

.tree-action-delete:hover {
    color: var(--danger) !important;
    background: var(--danger-light);
}

.tree-dir-item .tree-file-actions {
    display: none;
    align-items: center;
    gap: 2px;
    margin-left: auto;
    flex-shrink: 0;
}

.tree-dir-item:hover .tree-file-actions {
    display: flex;
}

.tree-action-btn svg {
    width: 12px;
    height: 12px;
}

.sidebar-footer {
    padding: 10px 14px;
    border-top: 1px solid var(--border);
}

.sidebar-stats {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
    color: #6b7280;
    font-weight: 600;
}

.sidebar-stats span {
    min-width: 0;
    padding: 5px 8px;
    border: 1px solid #e6e9ee;
    border-radius: 6px;
    background: #ffffff;
    white-space: nowrap;
}

.resizer {
    width: 4px;
    cursor: col-resize;
    background: transparent;
    flex-shrink: 0;
    transition: background var(--transition);
    position: relative;
    z-index: 10;
}

.resizer:hover,
.resizer.active {
    background: var(--primary);
}

.main-content {
    flex: 1;
    overflow: hidden;
    display: flex;
    background: #ffffff;
}

.page {
    display: none;
    width: 100%;
    height: 100%;
}

.page.active { display: flex; }

.three-col {
    display: flex;
    width: 100%;
    height: 100%;
}

.col-center {
    flex: 1;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.col-right {
    width: 340px;
    min-width: 240px;
    max-width: 500px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.3s ease, min-width 0.3s ease;
}

.col-right.panel-collapsed {
    width: 40px !important;
    min-width: 40px !important;
}

.col-right.panel-collapsed .panel-body,
.col-right.panel-collapsed .right-view-tabs,
.col-right.panel-collapsed .panel-title {
    display: none;
}

.col-right.panel-collapsed .panel-header {
    flex-direction: column;
    padding: 8px 4px;
    justify-content: flex-start;
}

.col-right.panel-collapsed .panel-header button {
    margin-left: 0 !important;
}

.col-right.panel-collapsed .panel-header > div {
    margin-left: 0 !important;
}

.col-right.panel-collapsed .panel-header button svg {
    transform: rotate(180deg);
}

.panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-surface);
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-height: 42px;
    gap: 8px;
}

.panel-title {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text-primary);
}

.panel-title svg { color: var(--primary); width: 15px; height: 15px; }

.panel-actions {
    display: flex;
    align-items: center;
    gap: 3px;
}

.panel-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.graph-area {
    position: relative;
    background: var(--bg-base);
}

.graph-area canvas {
    width: 100%;
    height: 100%;
    display: block;
}

#page-kg.three-col,
#page-kg .three-col {
    background: #ffffff;
}

.kg-reader-col {
    background: #ffffff;
}

.kg-reader-shell {
    height: 100%;
    overflow-y: auto;
    background: #ffffff;
}

.kg-reader {
    max-width: 760px;
    min-height: 100%;
    margin: 0 auto;
    padding: 24px 36px 96px;
    color: #111827;
    font-size: 16px;
    line-height: 1.72;
}

.kg-reader-titlebar {
    margin-bottom: 28px;
}

.kg-reader-heading-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.kg-reader-actions {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
    padding: 3px;
    border: 1px solid #e5e7eb;
    border-radius: 7px;
    background: #f8fafc;
}

.kg-reader-mode-btn,
.kg-reader-save-btn {
    height: 28px;
    padding: 0 10px;
    border: 0;
    border-radius: 5px;
    background: transparent;
    color: #667085;
    font-size: 12px;
    cursor: pointer;
}

.kg-reader-mode-btn.active {
    background: #ffffff;
    color: #1f2937;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

.kg-reader-save-btn {
    color: #5b45d9;
    font-weight: 600;
}

.kg-reader-editor {
    width: 100%;
    min-height: calc(100vh - 220px);
    resize: vertical;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 18px 20px;
    background: #fbfcfe;
    color: #111827;
    font: 14px/1.75 Consolas, "SFMono-Regular", "Microsoft YaHei", monospace;
    outline: none;
}

.kg-reader-editor:focus {
    border-color: #b8aef8;
    box-shadow: 0 0 0 3px rgba(112, 76, 255, 0.10);
}

.kg-reader-editor.is-doc-drag-over {
    border-color: #7c5cff;
    background: #fbf9ff;
    box-shadow: 0 0 0 3px rgba(124, 92, 255, 0.14);
}

.markdown-blank-line {
    height: 1.35em;
}

.math-display {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 48px;
    margin: 18px 0 22px;
    padding: 12px 18px;
    overflow-x: auto;
    color: #172033;
    font-family: "Cambria Math", "STIX Two Math", "Times New Roman", serif;
    font-size: 1.12em;
    line-height: 1.8;
    text-align: center;
}

.math-inline {
    display: inline-flex;
    align-items: baseline;
    margin: 0 2px;
    color: #172033;
    font-family: "Cambria Math", "STIX Two Math", "Times New Roman", serif;
    white-space: nowrap;
}

.math-cmd {
    font-family: "Cambria Math", "STIX Two Math", "Times New Roman", serif;
}

.math-frac {
    display: inline-flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    margin: 0 4px;
    vertical-align: middle;
    line-height: 1.05;
    text-align: center;
}

.math-frac .math-num {
    padding: 0 5px 3px;
    border-bottom: 1px solid currentColor;
}

.math-frac .math-den {
    padding: 3px 5px 0;
}

.math-sqrt {
    display: inline-flex;
    align-items: flex-start;
    margin-right: 2px;
    vertical-align: middle;
}

.math-sqrt::before {
    content: "√";
    font-size: 1.35em;
    line-height: 1;
    margin-right: 2px;
}

.math-sqrt .math-radicand {
    display: inline-block;
    min-width: 18px;
    padding: 2px 5px 0;
    border-top: 1px solid currentColor;
}

.math-display sup,
.math-inline sup {
    font-size: 0.7em;
    line-height: 0;
    vertical-align: super;
}

.math-display sub,
.math-inline sub {
    font-size: 0.7em;
    line-height: 0;
    vertical-align: sub;
}

.kg-reader table,
.editor-preview table,
.markdown-preview table {
    width: 100%;
    border-collapse: collapse;
    margin: 18px 0 22px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #fff;
    font-size: 14px;
}

.kg-reader th,
.kg-reader td,
.editor-preview th,
.editor-preview td,
.markdown-preview th,
.markdown-preview td {
    padding: 10px 12px;
    border: 1px solid #e5e7eb;
    vertical-align: top;
}

.kg-reader th,
.editor-preview th,
.markdown-preview th {
    background: #f8fafc;
    color: #111827;
    font-weight: 700;
}

.kg-reader tr:nth-child(even) td,
.editor-preview tr:nth-child(even) td,
.markdown-preview tr:nth-child(even) td {
    background: #fbfcfe;
}

.kg-reader img,
.editor-preview img,
.markdown-preview img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
}

.model-key-dialog {
    width: min(760px, calc(100vw - 32px));
    max-height: min(86vh, 780px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.model-key-dialog-head,
.model-key-card-head,
.model-key-footer {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.model-key-dialog-head {
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.model-key-dialog-title {
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 750;
}

.model-key-dialog-note,
.model-key-subtitle {
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.5;
}

.model-key-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    padding: 14px 2px;
}

.model-key-card {
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
}

.model-key-card-head {
    align-items: center;
    margin-bottom: 11px;
}

.model-key-title {
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 700;
}

.model-key-toggle,
.model-key-clear {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 12px;
    white-space: nowrap;
}

.model-key-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 9px 12px;
}

.model-key-grid label:not(.model-key-toggle):not(.model-key-clear) {
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: var(--text-muted);
    font-size: 11px;
}

.model-key-grid input:not([type="checkbox"]) {
    width: 100%;
    min-height: 32px;
    padding: 7px 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font: inherit;
    outline: none;
}

.model-key-grid input:not([type="checkbox"]):focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.model-key-wide,
.model-key-clear {
    grid-column: 1 / -1;
}

.model-key-clear {
    margin-top: 1px;
}

.model-key-footer {
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 11px;
}

.model-key-actions {
    display: flex;
    gap: 8px;
    flex: 0 0 auto;
}

@media (max-width: 640px) {
    .model-key-grid {
        grid-template-columns: 1fr;
    }

    .model-key-wide,
    .model-key-clear {
        grid-column: auto;
    }

    .model-key-footer {
        align-items: stretch;
        flex-direction: column;
    }
}

.kg-reader-path {
    color: #9aa0aa;
    font-size: 12px;
    margin-bottom: 10px;
}

.kg-reader h1,
.kg-reader-titlebar h1 {
    font-size: 36px;
    line-height: 1.15;
    margin: 0;
    color: #10141f;
}

.kg-reader h2 {
    font-size: 24px;
    margin: 34px 0 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid #e5e7eb;
    color: #111827;
}

.kg-reader h3 {
    font-size: 20px;
    margin: 26px 0 10px;
}

.kg-reader a {
    color: #714cff;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.kg-reader a.kg-doc-link {
    color: #6845d9;
    text-decoration: none;
    border-bottom: 1px solid rgba(104, 69, 217, 0.32);
    background: linear-gradient(transparent 62%, rgba(126, 87, 255, 0.10) 62%);
    cursor: pointer;
}

.kg-reader a.kg-doc-link:hover {
    color: #4326a8;
    border-bottom-color: rgba(67, 38, 168, 0.52);
    background: linear-gradient(transparent 54%, rgba(126, 87, 255, 0.16) 54%);
}

.kg-reader ol,
.kg-reader ul {
    padding-left: 28px;
}

.kg-reader li {
    margin: 4px 0;
}

.kg-reader img {
    display: block;
    max-width: 100%;
    height: auto;
    margin: 14px 0;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: #ffffff;
}

.kg-reader p > img:only-child {
    margin-top: 18px;
    margin-bottom: 18px;
}

.kg-reader-anchor-heading {
    scroll-margin-top: 22px;
}

.kg-heading-highlight {
    animation: kgHeadingFlash 1.2s ease;
}

@keyframes kgHeadingFlash {
    0% { background: rgba(109, 74, 255, 0.16); }
    100% { background: transparent; }
}

.kg-reader-empty {
    min-height: 60vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #8b929e;
    text-align: center;
}

.kg-reader-empty-title {
    font-size: 22px;
    font-weight: 700;
    color: #222733;
    margin-bottom: 8px;
}

.kg-reader-empty-subtitle {
    font-size: 14px;
}

.kg-reader-muted {
    color: #8b929e;
}

.kg-media-preview {
    width: 100%;
    min-height: 420px;
}

.kg-media-preview img {
    max-width: 100%;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
}

.kg-pdf-preview iframe {
    width: 100%;
    height: 100%;
    min-height: 680px;
    display: block;
    border: 0;
    border-radius: 0;
    background: #f3f4f6;
}

#page-kg .kg-reader.kg-reader-pdf-mode {
    max-width: none;
    width: 100%;
    height: 100%;
    min-height: 100%;
    box-sizing: border-box;
    padding: 18px 22px 24px;
    display: flex;
    flex-direction: column;
}

#page-kg .kg-reader.kg-reader-pdf-mode .kg-reader-titlebar {
    margin-bottom: 14px;
}

#page-kg .kg-reader.kg-reader-pdf-mode .kg-reader-body {
    flex: 1 1 auto;
    height: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#page-kg .kg-reader.kg-reader-pdf-mode .pdf-preview-container {
    flex: 1 1 auto;
    width: 100%;
    height: auto;
    min-height: 0;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    overflow: hidden;
    background: #f3f4f6;
}

#page-kg .kg-reader.kg-reader-pdf-mode .pdf-preview-frame {
    width: 100%;
    height: 100%;
    min-height: 0;
    display: block;
    border: 0;
}

#page-kg .kg-reader-body.is-doc-drag-over,
#page-kg .kg-reader-editor.is-doc-drag-over {
    outline: 2px solid rgba(99, 102, 241, 0.35);
    outline-offset: -4px;
    background: rgba(99, 102, 241, 0.035);
}

.pdf-preview-unavailable {
    align-items: center;
    justify-content: center;
}

.pdf-preview-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    color: #667085;
    font-size: 13px;
    text-align: center;
}

.pdf-preview-message strong {
    color: #1f2937;
    font-size: 15px;
}

.pdf-preview-message button {
    border: 1px solid #cfc8ff;
    border-radius: 6px;
    padding: 6px 12px;
    background: #f5f2ff;
    color: #5b45d9;
    cursor: pointer;
}

#page-kg .col-right {
    width: 360px;
    min-width: 300px;
    border-left: 1px solid #e5e7eb;
    background: #ffffff;
}

#page-kg .col-right .panel {
    background: #ffffff;
}

.kg-side-graph {
    padding: 16px 16px 10px;
    flex-shrink: 0;
}

.kg-side-graph-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #111827;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.8px;
    margin-bottom: 8px;
}

.kg-side-graph-actions {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 2px;
    border-radius: 6px;
    background: rgba(248, 250, 252, 0.86);
}

.kg-side-graph-actions .icon-btn {
    width: 24px;
    height: 24px;
    border-radius: 5px;
    color: #5f6672;
    background: transparent;
}

.kg-side-graph-actions .icon-btn:hover {
    color: #24272e;
    background: #eef1f5;
}

.kg-side-graph-box {
    height: 206px;
    border: 1px solid #e2e6ed;
    border-radius: 6px;
    overflow: hidden;
    background: linear-gradient(180deg, #ffffff 0%, #fbfcfe 100%);
    cursor: default;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.kg-side-graph-box:hover {
    border-color: #cfd6e2;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.85), 0 8px 22px rgba(15,23,42,0.05);
}

.kg-side-graph-box canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

#page-kg #kg-node-info-panel {
    overflow: hidden;
}

#page-kg #kg-node-info {
    min-height: 0;
    overflow: hidden;
}

.kg-outline {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
    padding: 14px 12px 12px;
    background: #ffffff;
}

.kg-outline-title {
    padding: 0 4px 10px;
    color: #111827;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.7px;
}

.kg-outline-list {
    min-height: 0;
    overflow-y: auto;
    padding: 2px 2px 12px;
}

.kg-outline-item {
    width: 100%;
    min-height: 30px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    margin-bottom: 2px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: #4b5563;
    font-size: 12px;
    line-height: 1.35;
    text-align: left;
    cursor: pointer;
}

.kg-outline-item:hover {
    background: #f4f1ff;
    color: #35206f;
}

.kg-outline-item.is-active {
    background: #f0ecff;
    color: #2f1c71;
    font-weight: 700;
}

.kg-outline-item span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kg-outline-item.level-1 {
    color: #111827;
    font-weight: 700;
}

.kg-outline-item.level-2 { padding-left: 16px; }
.kg-outline-item.level-3 { padding-left: 28px; }
.kg-outline-item.level-4 { padding-left: 40px; }

.kg-outline-muted,
.kg-outline-empty {
    height: 100%;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 20px;
    color: #8b929e;
    font-size: 13px;
    text-align: center;
}

.kg-outline-empty-icon {
    width: 30px;
    height: 30px;
    border-radius: 999px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e5e7eb;
    color: #6b7280;
    font-weight: 700;
    font-family: var(--font-mono);
}

.kg-backlinks {
    margin-top: 28px;
    padding-top: 16px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: clamp(220px, 28vh, 340px);
    overflow: hidden;
}

.kg-backlinks.is-doc-drag-over {
    border-top-color: #8b6cff;
    background: #fbf9ff;
    outline: 2px dashed rgba(124, 92, 255, 0.34);
    outline-offset: 8px;
}

.kg-backlinks-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.kg-backlinks-title {
    color: #111827;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.7px;
}

.kg-backlinks-count {
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: #f4f1ff;
    color: #5b45d9;
    font-size: 12px;
    font-weight: 700;
}

.kg-backlinks-list {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    overflow-y: auto;
    overflow-x: hidden;
    max-height: clamp(140px, 20vh, 260px);
    width: 100%;
    padding-right: 4px;
    box-sizing: border-box;
}

.kg-backlinks-text-link {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #714cff;
    border-bottom: 0;
    background: transparent;
    font-size: 14px;
    line-height: 1.55;
    text-decoration: underline;
    text-underline-offset: 2px;
    cursor: pointer;
}

.kg-backlinks-text-link:hover {
    color: #4326a8;
    background: transparent;
}

.kg-backlinks-empty {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #8b929e;
    font-size: 12px;
}

.kg-backlinks-empty {
    padding: 8px 0;
}

.kg-graph-modal {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    background: #ffffff;
    animation: kgGraphModalIn 0.18s ease-out both;
}

.kg-graph-modal canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

.kg-graph-modal-toolbar {
    position: absolute;
    top: 18px;
    left: 22px;
    right: 22px;
    z-index: 2;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    pointer-events: none;
}

.kg-graph-modal-title {
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.9px;
    color: #111827;
}

.kg-graph-modal-subtitle {
    margin-top: 4px;
    font-size: 12px;
    color: #8b929e;
}

.kg-graph-modal-actions {
    pointer-events: auto;
    display: flex;
    gap: 3px;
    padding: 4px;
    border: 1px solid #e0e5ed;
    border-radius: 7px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(10px);
}

.kg-graph-modal-actions .icon-btn.active {
    color: #2563eb;
    background: #eef5ff;
    border-color: #cfe2ff;
}

.kg-graph-powered {
    position: absolute;
    right: 20px;
    bottom: 14px;
    color: #8b929e;
    font-size: 11px;
}

@keyframes kgGraphModalIn {
    from {
        opacity: 0;
        transform: scale(0.995);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.graph-controls {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    gap: 3px;
    z-index: 10;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 3px;
}

.graph-controls .icon-btn svg {
    width: 14px;
    height: 14px;
}

.graph-legend-item svg {
    width: 12px;
    height: 12px;
}

.graph-legend {
    position: absolute;
    bottom: 10px;
    left: 10px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    z-index: 10;
    padding: 8px 14px;
    background: rgba(17, 20, 32, 0.92);
    backdrop-filter: blur(8px);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    font-size: var(--text-sm);
}

.graph-legend {
    background: rgba(255, 255, 255, 0.92);
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
    color: var(--text-secondary);
}

.legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.legend-line {
    height: 0;
    margin: 0 2px;
    vertical-align: middle;
}

.graph-tooltip {
    position: absolute;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    font-size: var(--text-md);
    color: var(--text-primary);
    pointer-events: none;
    z-index: 20;
    max-width: 260px;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(8px);
}

.chat-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.rag-chat-panel {
    min-height: 0;
}

.rag-chat-scroll-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: #ffffff;
}

.rag-chat-scroll-wrap .chat-messages {
    height: 100%;
    overflow-x: hidden;
}

.rag-turn-index {
    display: none !important;
    pointer-events: none;
}

.rag-turn-index::before {
    content: "";
    position: absolute;
    top: 4px;
    bottom: 4px;
    left: 13px;
    width: 1px;
    background: repeating-linear-gradient(
        to bottom,
        #d7dce5 0,
        #d7dce5 7px,
        transparent 7px,
        transparent 14px
    );
}

.rag-turn-index-btn {
    position: relative;
    width: 18px;
    height: 18px;
    margin: 4px 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: #9aa3b2;
    cursor: pointer;
    pointer-events: auto;
    transition: transform 0.18s ease, color 0.18s ease;
}

.rag-turn-index-btn::before {
    content: "";
    position: absolute;
    left: 7px;
    top: 8px;
    width: 4px;
    height: 4px;
    border-radius: 999px;
    background: currentColor;
    box-shadow: 0 0 0 3px #ffffff;
    transition: width 0.18s ease, height 0.18s ease, left 0.18s ease, top 0.18s ease, background 0.18s ease;
}

.rag-turn-index-btn:hover,
.rag-turn-index-btn.is-active {
    color: #2563eb;
    transform: scale(1.08);
}

.rag-turn-index-btn.is-active::before {
    left: 4px;
    top: 7px;
    width: 10px;
    height: 4px;
    background: #111827;
}

.rag-turn-index-empty {
    display: none;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.chat-msg {
    display: flex;
    gap: 10px;
    max-width: 88%;
    animation: msgIn 0.25s ease;
}

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

.chat-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
    justify-content: flex-start;
    width: fit-content;
    max-width: min(760px, 78%);
}

.chat-avatar {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xs);
    font-weight: 700;
    flex-shrink: 0;
    letter-spacing: 0.3px;
}

.chat-msg.user .chat-avatar {
    background: var(--primary);
    color: var(--text-on-primary);
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);
}
.chat-msg.assistant .chat-avatar {
    background: var(--secondary);
    color: var(--text-inverse);
    box-shadow: 0 2px 6px rgba(6, 182, 212, 0.3);
}

.chat-bubble {
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    font-size: var(--text-md);
    line-height: var(--leading-relaxed);
    word-break: break-word;
}

.chat-msg.user .chat-bubble {
    background: var(--primary);
    color: var(--text-on-primary);
    border-bottom-right-radius: var(--radius-xs);
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
    width: max-content;
    max-width: 100%;
    min-width: 96px;
    white-space: pre-wrap;
    word-break: normal;
    overflow-wrap: break-word;
}

.chat-msg.assistant .chat-bubble {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-bottom-left-radius: var(--radius-xs);
}

.chat-bubble .sources {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.chat-bubble .sources .source-item {
    margin-top: 5px;
    padding: 5px 10px;
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: var(--text-sm);
}

.chat-bubble .sources .source-item:hover {
    background: var(--bg-active);
    color: var(--text-primary);
}

.chat-input-box {
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    flex-shrink: 0;
}

.chat-input-box textarea {
    flex: 1;
    padding: 9px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--text-md);
    font-family: var(--font-sans);
    resize: none;
    outline: none;
    line-height: var(--leading-normal);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.chat-input-box textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-lighter);
}
.chat-input-box textarea::placeholder { color: var(--text-muted); }

.send-btn {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-md);
    border: none;
    background: var(--primary);
    color: var(--text-on-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
    flex-shrink: 0;
    align-self: flex-end;
    box-shadow: var(--shadow-primary);
}

.send-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}
.send-btn:active { transform: translateY(0); }

.chunks-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 24px;
    gap: 8px;
}

.chunks-empty svg { opacity: 0.3; width: 44px; height: 44px; }
.chunks-empty p { font-size: var(--text-md); }

.chunk-card {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: all var(--transition-fast);
    min-width: 0;
}

.chunk-card:hover { background: var(--bg-hover); }

.chunk-card .chunk-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 5px;
    min-width: 0;
}

.chunk-card .chunk-title {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 5px;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chunk-card .chunk-score {
    font-size: var(--text-sm);
    color: var(--primary);
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.chunk-card .chunk-text {
    font-size: var(--text-md);
    color: var(--text-secondary);
    line-height: var(--leading-relaxed);
    display: -webkit-box;
    -webkit-line-clamp: 4;
    line-clamp: 4;
    -webkit-box-orient: vertical;
    overflow: hidden;
    overflow-wrap: anywhere;
}

.chunk-card .chunk-meta {
    margin-top: 7px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.chunk-card .chunk-meta span {
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.icon-btn {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.icon-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}
.icon-btn:active { transform: scale(0.95); }
.icon-btn.danger:hover { background: var(--danger-light); color: var(--danger); }
.icon-btn.sm { width: 26px; height: 26px; }

.icon-btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}

.search-mode-select {
    padding: 5px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    outline: none;
    cursor: pointer;
    font-family: var(--font-sans);
    transition: border-color var(--transition);
}

.search-mode-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-lighter);
}

.toast-container {
    position: fixed;
    top: 60px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 10px 18px;
    border-radius: var(--radius-md);
    font-size: var(--text-md);
    font-weight: 500;
    animation: toastIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 220px;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(8px);
}

.toast-success { background: var(--success-light); border: 1px solid var(--success); color: var(--success); }
.toast-error { background: var(--danger-light); border: 1px solid var(--danger); color: var(--danger); }
.toast-info { background: var(--info-light); border: 1px solid var(--info); color: var(--info); }
.toast-warning { background: var(--warning-light); border: 1px solid var(--warning); color: var(--warning); }

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

.loading-dots {
    display: inline-flex;
    gap: 5px;
    padding: 4px 0;
}

.loading-dots span {
    width: 7px;
    height: 7px;
    border-radius: var(--radius-full);
    background: var(--text-muted);
    animation: dotPulse 1.2s infinite;
}

.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotPulse {
    0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
    40% { opacity: 1; transform: scale(1.1); }
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

@media (max-width: 900px) {
    .sidebar { width: 200px; min-width: 160px; }
    .col-right { width: 260px; min-width: 200px; }
}

.center-view-tabs {
    display: flex;
    gap: 2px;
    background: var(--bg-elevated);
    padding: 3px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

.right-view-tabs {
    display: flex;
    gap: 2px;
    background: var(--bg-elevated);
    padding: 3px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

.view-tab {
    padding: 5px 12px;
    border-radius: var(--radius-xs);
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--text-md);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    display: flex;
    align-items: center;
    gap: 5px;
}

.view-tab:hover { color: var(--text-primary); background: var(--bg-hover); }
.view-tab.active { background: var(--primary); color: var(--text-on-primary); box-shadow: var(--shadow-primary); }

.editor-view {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-surface);
    flex-shrink: 0;
}

.editor-filename {
    font-size: var(--text-md);
    color: var(--text-secondary);
    font-weight: 500;
}

.cloud-save-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-left: 8px;
    font-size: var(--text-xs);
    color: var(--text-muted);
    white-space: nowrap;
}

.cloud-save-status::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
}

.cloud-save-status[data-status="dirty"] { color: #b45309; }
.cloud-save-status[data-status="dirty"]::before { background: #f59e0b; }
.cloud-save-status[data-status="saving"] { color: var(--primary); }
.cloud-save-status[data-status="saving"]::before { background: var(--primary); }
.cloud-save-status[data-status="saved"] { color: #059669; }
.cloud-save-status[data-status="saved"]::before { background: #10b981; }
.cloud-save-status[data-status="error"] { color: var(--danger); }
.cloud-save-status[data-status="error"]::before { background: var(--danger); }

.editor-actions { display: flex; gap: 3px; }

.editor-content {
    flex: 1;
    padding: 14px;
    background: var(--bg-input);
    border: none;
    color: var(--text-primary);
    font-size: var(--text-md);
    font-family: var(--font-mono);
    line-height: var(--leading-relaxed);
    resize: none;
    outline: none;
    tab-size: 4;
}

.editor-content::placeholder { color: var(--text-muted); }

.image-preview-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    padding: 16px;
    overflow: auto;
}

.image-preview-img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.pdf-preview-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    min-height: 500px;
    overflow: hidden;
}

/* Native PDF viewers keep their intrinsic width unless the iframe is sized explicitly. */
.pdf-preview-container > iframe,
.kg-pdf-preview iframe {
    flex: 1 1 auto;
    display: block;
    width: 100%;
    min-width: 0;
    height: 100%;
    min-height: 0;
    border: 0;
    background: #f3f4f6;
}

#page-kg .kg-reader.kg-reader-pdf-mode .pdf-preview-container > iframe {
    min-height: 0;
}

.chat-toolbar {
    display: flex;
    gap: 3px;
    padding: 7px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
    flex-shrink: 0;
}

.toolbar-btn {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-sans);
}

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

.toolbar-btn { position: relative; }
.toolbar-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: var(--text-xs);
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity var(--transition);
    z-index: 1000;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
}
.toolbar-btn:hover::after { opacity: 1; }

#page-rag .rag-composer {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 12px 16px 14px;
    padding: 10px 12px;
    min-height: 104px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

#page-rag .rag-composer:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-lighter);
}

#page-rag .rag-composer textarea {
    width: 100%;
    min-height: 50px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    line-height: 1.55;
}

#page-rag .rag-composer textarea:focus {
    border-color: transparent;
    box-shadow: none;
}

.rag-composer-footer {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    min-height: 30px;
}

#page-rag .rag-composer-tools {
    display: flex;
    flex: 1 1 auto;
    min-width: 0;
    gap: 4px;
    padding: 0;
    border-top: 0;
    background: transparent;
}

#page-rag .rag-composer-tools .toolbar-btn {
    width: 28px;
    height: 28px;
    padding: 0;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    justify-content: center;
}

#page-rag .rag-composer-tools .toolbar-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

#page-rag .rag-composer .send-btn {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    align-self: auto;
}

.convert-tab {
    border: 1px solid var(--border-light);
    background: transparent;
}

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

.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(6px);
    animation: overlayIn 0.2s ease;
}

@keyframes overlayIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal {
    width: 560px;
    max-width: 90vw;
    max-height: 80vh;
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.convert-modal {
    width: 680px;
    max-height: 85vh;
}

.convert-modal-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--text-primary);
}

.convert-modal-title svg { color: var(--primary); width: 18px; height: 18px; }

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

.modal-title {
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--text-primary);
}

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

.convert-drop-zone {
    border: 2px dashed var(--border-light);
    border-radius: var(--radius-lg);
    padding: 44px 28px;
    text-align: center;
    cursor: pointer;
    transition: all var(--transition);
    color: var(--text-muted);
    background: var(--bg-elevated);
}

.convert-drop-zone:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary);
}

.convert-drop-zone.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: scale(1.01);
}

.convert-drop-icon {
    margin-bottom: 12px;
    opacity: 0.7;
}

.convert-drop-icon svg {
    width: 36px;
    height: 36px;
}

.convert-drop-zone:hover .convert-drop-icon { opacity: 1; }

.chunk-card .chunk-title svg {
    width: 14px;
    height: 14px;
}

.convert-drop-title {
    font-size: var(--text-lg);
    font-weight: 500;
    margin-bottom: 4px;
    color: var(--text-secondary);
}

.convert-drop-hint {
    font-size: var(--text-sm);
    opacity: 0.6;
    margin-bottom: 16px;
}

.convert-format-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
}

.format-tag {
    display: inline-block;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: var(--text-xs);
    font-weight: 600;
    background: var(--bg-hover);
    color: var(--text-secondary);
    border: 1px solid var(--border-light);
    letter-spacing: 0.3px;
}

.convert-file-info {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    margin-bottom: 20px;
    border: 1px solid var(--border-subtle);
}

.convert-file-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--primary);
}

.convert-file-icon-success {
    background: var(--success-light);
    color: var(--success);
}

.convert-file-detail {
    flex: 1;
    min-width: 0;
}

.convert-file-name {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.convert-file-meta {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 2px;
}

.convert-progress-bar {
    margin-top: 4px;
}

.convert-progress-track {
    position: relative;
    height: 6px;
    background: var(--bg-hover);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.convert-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: var(--radius-full);
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.convert-progress-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    animation: progressShimmer 1.5s infinite;
}

@keyframes progressShimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.convert-progress-glow {
    position: absolute;
    top: -3px;
    width: 12px;
    height: 12px;
    border-radius: var(--radius-full);
    background: var(--secondary);
    box-shadow: 0 0 12px var(--secondary), 0 0 4px var(--primary);
    transition: left 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateX(-50%);
}

.convert-progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
}

.convert-progress-status {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.convert-progress-status::before {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
}

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

.convert-progress-percent {
    font-size: var(--text-md);
    font-weight: 600;
    color: var(--primary);
    font-variant-numeric: tabular-nums;
}

.convert-result-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}

.convert-result-file {
    display: flex;
    align-items: center;
    gap: 12px;
}

.convert-result-name {
    font-size: var(--text-lg);
    font-weight: 600;
    color: var(--text-primary);
}

.convert-result-meta {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 2px;
}

.convert-result-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.btn-sm {
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-light);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: all var(--transition-fast);
    font-weight: 500;
    font-family: var(--font-sans);
}

.btn-sm:hover {
    background: var(--primary);
    color: var(--text-on-primary);
    border-color: var(--primary);
    box-shadow: var(--shadow-primary);
}

.convert-send-actions {
    display: flex;
    gap: 10px;
    margin: 14px 0;
}

.send-action-card {
    cursor: pointer;
    border: 1.5px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    background: var(--bg-elevated);
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    transition: all var(--transition);
}

.send-action-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.send-action-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.send-action-icon svg {
    width: 18px;
    height: 18px;
}

.convert-file-icon svg {
    width: 20px;
    height: 20px;
}

.send-action-icon-kb {
    background: var(--primary);
    color: var(--text-on-primary);
}

.send-action-icon-kg {
    background: #6c5ce7;
    color: var(--text-inverse);
}

.send-action-text { flex: 1; }

.send-action-title {
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--text-primary);
}

.send-action-desc {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 1px;
}

.convert-preview-tabs {
    display: flex;
    gap: 2px;
    background: var(--bg-hover);
    border-radius: var(--radius-sm);
    padding: 3px;
    margin-bottom: 10px;
}

.preview-tab {
    flex: 1;
    padding: 6px 12px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: var(--text-sm);
    font-weight: 500;
    border-radius: var(--radius-xs);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: var(--font-sans);
}

.preview-tab.active {
    background: var(--bg-surface);
    color: var(--text-primary);
    box-shadow: var(--shadow-xs);
}

.preview-tab:hover:not(.active) {
    color: var(--text-secondary);
}

.convert-preview-container {
    position: relative;
}

.convert-preview {
    width: 100%;
    height: 280px;
    padding: 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    line-height: var(--leading-relaxed);
    resize: none;
    outline: none;
    tab-size: 4;
}

.convert-preview-rendered {
    width: 100%;
    height: 280px;
    padding: 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    overflow-y: auto;
    color: var(--text-primary);
    font-size: var(--text-md);
    line-height: 1.7;
}

.convert-preview-rendered h1,
.convert-preview-rendered h2,
.convert-preview-rendered h3 {
    margin: 12px 0 8px;
    color: var(--text-primary);
}

.convert-preview-rendered h1 { font-size: var(--text-2xl); }
.convert-preview-rendered h2 { font-size: var(--text-xl); }
.convert-preview-rendered h3 { font-size: var(--text-lg); }

.convert-preview-rendered p { margin: 6px 0; }

.convert-preview-rendered table {
    border-collapse: collapse;
    width: 100%;
    margin: 8px 0;
    font-size: var(--text-sm);
}

.convert-preview-rendered th,
.convert-preview-rendered td {
    border: 1px solid var(--border-light);
    padding: 6px 10px;
    text-align: left;
}

.convert-preview-rendered th {
    background: var(--bg-hover);
    font-weight: 600;
}

.convert-preview-rendered code {
    background: var(--bg-hover);
    padding: 1px 5px;
    border-radius: var(--radius-xs);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
}

.convert-preview-rendered pre {
    background: var(--bg-hover);
    padding: 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    margin: 8px 0;
}

.convert-preview-rendered pre code {
    background: none;
    padding: 0;
}

.convert-preview-rendered blockquote {
    border-left: 3px solid var(--primary);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-secondary);
}

.convert-preview-rendered ul,
.convert-preview-rendered ol {
    padding-left: 20px;
    margin: 6px 0;
}

.convert-preview-rendered img {
    max-width: 100%;
    border-radius: var(--radius-sm);
}

.convert-drop-zone {
    border-color: var(--border-light);
    background: var(--bg-elevated);
}

.convert-drop-zone:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.convert-preview {
    background: var(--bg-elevated);
    border-color: var(--border);
    color: var(--text-primary);
}

.convert-preview-rendered {
    background: var(--bg-elevated);
    border-color: var(--border);
}

.convert-file-info {
    background: var(--bg-elevated);
}

.send-action-card {
    background: var(--bg-elevated);
    border-color: var(--border);
}

.preview-tab.active {
    background: var(--bg-surface);
    box-shadow: var(--shadow-xs);
}

.convert-modal {
    background: #ffffff;
    box-shadow: var(--shadow-xl);
}

.modal-header {
    border-color: var(--border);
}

.format-tag {
    background: var(--bg-hover);
    border-color: var(--border);
}

.btn-sm {
    background: var(--bg-elevated);
    border-color: var(--border);
}

.floating-progress {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 10000;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px 18px;
    min-width: 300px;
    box-shadow: var(--shadow-xl);
    transition: opacity var(--transition), transform var(--transition);
    animation: floatingProgressIn 0.3s ease;
    backdrop-filter: blur(8px);
}

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

.floating-progress-out {
    opacity: 0 !important;
    transform: translateY(10px) !important;
}

.floating-progress-msg {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.floating-progress-msg::before {
    content: '';
    display: inline-block;
    width: 12px;
    height: 12px;
    border: 2px solid var(--primary);
    border-top-color: transparent;
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
    flex-shrink: 0;
}

.floating-progress-track {
    background: var(--bg-hover);
    border-radius: var(--radius-full);
    height: 6px;
    overflow: hidden;
}

.floating-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    border-radius: var(--radius-full);
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.floating-progress-fill::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
    animation: progressShimmer 1.5s infinite;
}

.floating-progress-percent {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 6px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.floating-progress {
    background: #ffffff;
    border-color: var(--border);
    box-shadow: var(--shadow-lg);
}

.node-info-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
}

.node-info {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.info-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    gap: 12px;
    padding: 24px;
    text-align: center;
}

.info-empty p {
    font-size: var(--text-lg);
    margin: 0;
}

.kg-node-info {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.rag-chunks-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.rag-citations-panel {
    display: flex;
    flex-direction: column;
    gap: 0;
    min-width: 0;
    overflow: hidden;
}

.rag-chunks-list {
    flex: 0 0 42%;
    overflow-y: auto;
    min-width: 0;
    border-bottom: 1px solid var(--border);
}

.rag-chunk-detail {
    display: none;
    flex-direction: column;
    max-height: none;
    min-height: 260px;
    min-width: 0;
    flex: 1 1 58%;
    overflow: hidden;
    background: var(--bg-surface);
}

.rag-citation-card {
    width: 100%;
    display: block;
    padding: 12px 13px;
    border: 0;
    border-left: 3px solid transparent;
    border-bottom: 1px solid var(--border);
    background: #ffffff;
    text-align: left;
    cursor: pointer;
}

.rag-citation-card:hover {
    background: #f8fafc;
}

.rag-citation-card.is-active {
    border-left-color: var(--primary);
    background: #f7faff;
}

.rag-citation-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

.rag-citation-card-title {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    color: var(--text-primary);
    font-size: 13px;
}

.rag-citation-card-title span {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 18px;
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
    font-size: 11px;
    font-weight: 700;
}

.rag-citation-card-title strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 650;
}

.rag-citation-card-head em {
    flex-shrink: 0;
    color: var(--primary);
    font-size: 12px;
    font-style: normal;
    font-weight: 650;
}

.rag-citation-card-preview {
    margin-top: 7px;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.rag-citation-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    margin-top: 8px;
    color: var(--text-muted);
    font-size: 11px;
}

.rag-citation-detail-head {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    min-width: 0;
}

.rag-citation-detail-title-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
    min-width: 0;
}

.rag-citation-detail-title {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    min-width: 0;
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 650;
    line-height: 1.45;
}

.rag-citation-detail-title span:last-child {
    min-width: 0;
    overflow: hidden;
    overflow-wrap: anywhere;
}

.rag-citation-detail-index {
    width: 20px;
    height: 20px;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 20px;
    font-size: 12px;
    font-weight: 700;
}

.rag-citation-detail-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px 10px;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.45;
    min-width: 0;
}

.rag-citation-detail-meta span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rag-citation-detail-meta b {
    margin-right: 5px;
    color: var(--text-secondary);
    font-weight: 600;
}

.rag-citation-detail-body {
    flex: 1;
    overflow-y: auto;
    min-width: 0;
    padding: 12px 14px 16px;
}

.rag-citation-section-title {
    margin-bottom: 8px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 650;
}

.rag-citation-section-title.is-primary {
    color: var(--primary);
}

.rag-citation-detail-content {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.75;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    padding: 10px;
    border: 1px solid #e5e9f0;
    border-radius: 8px;
    background: #ffffff;
}

.rag-citation-detail-content p {
    margin: 0 0 10px;
}

.rag-citation-child-hit {
    margin-top: 14px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg-hover);
}

.rag-citation-child-text {
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.65;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.rag-chunk-dialog {
    width: min(1080px, calc(100vw - 64px)) !important;
    max-height: 86vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 !important;
}

.new-item-dialog .dialog-box.rag-chunk-dialog {
    width: min(1080px, calc(100vw - 64px)) !important;
    padding: 0 !important;
}

.rag-chunk-dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.rag-chunk-dialog-title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.rag-chunk-dialog-title div {
    min-width: 0;
}

.rag-chunk-dialog-title strong {
    display: block;
    color: var(--text-primary);
    font-size: 16px;
    font-weight: 650;
    line-height: 1.35;
}

.rag-chunk-dialog-title span {
    display: block;
    color: var(--text-muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rag-chunk-dialog-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.rag-parent-chunk-list {
    flex: 1;
    min-height: 260px;
    overflow-y: auto;
    padding: 14px;
    background: #fbfcfe;
}

.rag-parent-chunk-empty {
    min-height: 180px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 13px;
}

.rag-parent-chunk-empty.is-error {
    color: var(--danger);
}

.rag-parent-chunk-notice {
    margin-bottom: 10px;
    padding: 9px 11px;
    border: 1px solid #fed7aa;
    border-radius: 8px;
    background: #fff7ed;
    color: #c2410c;
    font-size: 13px;
}

.rag-parent-chunk-card {
    margin-bottom: 10px;
    border: 1px solid #e1e6ef;
    border-radius: 9px;
    overflow: hidden;
    background: #ffffff;
}

.rag-parent-chunk-summary {
    width: 100%;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 14px;
    border: 0;
    background: #ffffff;
    cursor: pointer;
    text-align: left;
}

.rag-parent-chunk-summary:hover {
    background: #f8fafc;
}

.rag-parent-chunk-summary-main {
    display: flex;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.rag-parent-chunk-index {
    width: 24px;
    height: 24px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 24px;
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary);
    font-size: 12px;
    font-weight: 700;
}

.rag-parent-chunk-title-wrap {
    min-width: 0;
}

.rag-parent-chunk-title {
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 650;
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rag-parent-chunk-preview {
    margin-top: 5px;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.55;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.rag-parent-chunk-summary-meta {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 7px;
    color: var(--text-muted);
    font-size: 12px;
    flex: 0 0 280px;
}

.rag-parent-chunk-summary-meta svg {
    transition: transform 0.18s ease;
}

.rag-parent-chunk-detail {
    padding: 14px;
    border-top: 1px solid #e8edf5;
    background: #fbfcfe;
}

.rag-parent-section {
    margin-bottom: 14px;
}

.rag-parent-section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 8px;
}

.rag-parent-section-head strong {
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 700;
}

.rag-parent-section-head span {
    color: var(--text-muted);
    font-size: 12px;
}

.rag-parent-text {
    max-height: 360px;
    overflow-y: auto;
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #ffffff;
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.75;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.rag-child-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.rag-child-item {
    border: 1px solid #e5e9f0;
    border-radius: 8px;
    background: #ffffff;
    overflow: hidden;
}

.rag-child-item-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: #f8fafc;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 650;
}

.rag-child-text {
    padding: 10px;
    color: var(--text-secondary);
    font-size: 13px;
    line-height: 1.7;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.rag-child-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 10px 10px;
    color: var(--text-muted);
    font-size: 11px;
}

.rag-parent-meta-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 7px 10px;
    padding-top: 12px;
    border-top: 1px solid #e5e9f0;
    color: var(--text-muted);
    font-size: 11px;
}

.rag-parent-meta-grid span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rag-parent-meta-grid b {
    margin-right: 5px;
    color: var(--text-secondary);
}

.rag-chunk-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 13px;
    flex-shrink: 0;
}

.rag-chunk-pagination-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.rag-chunk-pagination input {
    width: 56px;
    text-align: center;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 3px 5px;
    font-size: 12px;
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.rag-answer-warning {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 10px;
    font-size: 13px;
    color: #92400e;
}

.rag-inline-citation {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 22px;
    margin: 0 2px;
    padding: 0 7px;
    border: 1px solid rgba(59, 130, 246, 0.18);
    border-radius: 999px;
    background: rgba(59, 130, 246, 0.1);
    color: #2563eb;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    vertical-align: baseline;
}

.rag-inline-citation:hover {
    background: rgba(59, 130, 246, 0.16);
}

.rag-inline-citation.is-disabled {
    cursor: default;
    color: var(--text-muted);
    background: var(--bg-hover);
    border-color: var(--border);
}

.rag-inference-tag {
    display: inline-flex;
    align-items: center;
    padding: 0 8px;
    height: 22px;
    margin: 0 2px;
    border-radius: 999px;
    background: #f3f4f6;
    color: #6b7280;
    font-size: 12px;
    font-weight: 600;
}

.rag-source-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}

.rag-open-citations-btn {
    border: 1px solid var(--border);
    background: var(--bg-hover);
    color: var(--text-secondary);
    border-radius: 999px;
    padding: 3px 10px;
    font-size: 12px;
    cursor: pointer;
}

.rag-open-citations-btn:hover {
    color: var(--text-primary);
    background: var(--bg-active);
}

.rag-source-chip {
    width: 100%;
    border: 0;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
}

.rag-source-chip-index {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    background: var(--bg-active);
    color: var(--primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
}

.rag-source-chip-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.rag-source-chip-score {
    font-size: 11px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.rag-session-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    height: 100%;
    overflow-y: auto;
}

.rag-session-item {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    background: var(--bg-elevated);
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.rag-session-item:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.08);
}

.rag-session-item.is-active {
    border-color: var(--primary);
    background: rgba(59, 130, 246, 0.05);
}

.rag-session-title-row,
.rag-session-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.rag-session-side {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.rag-session-delete-btn {
    width: 24px;
    height: 24px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
}

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

.rag-session-delete-btn:hover {
    background: #fee2e2;
    color: #dc2626;
}

.rag-session-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rag-session-meta,
.rag-session-preview,
.rag-session-footer {
    font-size: 12px;
    color: var(--text-muted);
}

.rag-session-preview {
    margin: 6px 0 8px;
    line-height: 1.5;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.rag-session-badge {
    color: var(--primary);
    font-weight: 600;
}

.chunk-card.is-active {
    border-left: 3px solid var(--primary);
    background: rgba(59, 130, 246, 0.04);
}

.new-item-dialog {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(6px);
}

.new-item-dialog .dialog-box {
    width: 360px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    padding: 22px;
    box-shadow: var(--shadow-xl);
    animation: modalIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.new-item-dialog .dialog-title {
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.new-item-dialog .dialog-target {
    margin-bottom: 14px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    line-height: 1.4;
    word-break: break-all;
}

.new-item-dialog .dialog-input {
    width: 100%;
    padding: 9px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: var(--text-md);
    font-family: var(--font-sans);
    outline: none;
    margin-bottom: 14px;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.new-item-dialog .dialog-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-lighter);
}

.new-item-dialog .dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.new-item-dialog .dialog-btn {
    padding: 7px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text-secondary);
    font-size: var(--text-md);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    font-family: var(--font-sans);
}

.new-item-dialog .dialog-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.new-item-dialog .dialog-btn.primary { background: var(--primary); color: var(--text-on-primary); border-color: var(--primary); box-shadow: var(--shadow-primary); }
.new-item-dialog .dialog-btn.primary:hover { background: var(--primary-hover); }

.toolbar-btn.eval-btn {
    font-size: var(--text-xs);
    padding: 3px 8px;
    opacity: 0.85;
}
.toolbar-btn.eval-btn:hover { opacity: 1; }
.toolbar-btn.eval-btn svg { width: 12px; height: 12px; }

.eval-dialog-box {
    width: 520px !important;
    max-height: 80vh;
    overflow-y: auto;
}

.eval-subtitle {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-bottom: 16px;
}

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

.eval-form-row {
    margin-bottom: 10px;
}
.eval-form-row label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.eval-hint {
    font-weight: 400;
    color: var(--text-muted);
    font-size: var(--text-xs);
}

.eval-select {
    width: 100%;
    padding: 7px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.eval-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-lighter);
}

.eval-textarea {
    width: 100%;
    padding: 7px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: var(--text-sm);
    font-family: var(--font-sans);
    outline: none;
    resize: vertical;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.eval-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-lighter);
}

.eval-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-bottom: 12px;
}

.eval-loading {
    text-align: center;
    padding: 24px;
    color: var(--text-muted);
    font-size: var(--text-sm);
}
.eval-loading::before {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: var(--radius-full);
    animation: eval-spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}
@keyframes eval-spin {
    to { transform: rotate(360deg); }
}

.eval-error {
    text-align: center;
    padding: 16px;
    color: var(--danger);
    font-size: var(--text-sm);
}

.eval-overall {
    text-align: center;
    padding: 16px 0 12px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}
.eval-overall-score {
    font-size: var(--text-3xl);
    font-weight: 700;
    line-height: var(--leading-tight);
}
.eval-overall-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 4px;
}

.eval-category {
    margin-bottom: 12px;
}
.eval-cat-title {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border);
}

.eval-metric-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
    gap: 12px;
}
.eval-metric-row.eval-metric-na { opacity: 0.5; }

.eval-metric-info {
    flex: 1;
    min-width: 0;
}
.eval-metric-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-primary);
}
.eval-metric-desc {
    display: block;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}
.eval-metric-detail {
    display: none;
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 2px;
    line-height: var(--leading-snug);
}
.eval-metric-row:hover .eval-metric-detail { display: block; }

.eval-metric-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.eval-bar-bg {
    width: 80px;
    height: 6px;
    background: var(--bg-input);
    border-radius: var(--radius-full);
    overflow: hidden;
}
.eval-bar-fill {
    height: 100%;
    border-radius: var(--radius-full);
    transition: width 0.6s ease;
}

.eval-metric-value {
    font-size: var(--text-md);
    font-weight: 600;
    min-width: 36px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.eval-metric-value.na {
    color: var(--text-muted);
    font-weight: 400;
}

.dialog-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    backdrop-filter: blur(6px);
}

.dialog-overlay .dialog-box {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-xl);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: modalIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.dialog-header h3 {
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.dialog-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    line-height: 1;
    transition: all var(--transition);
}

.dialog-close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.dialog-body {
    padding: 18px 22px;
    overflow-y: auto;
    flex: 1;
}

.dialog-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.triple-dialog-box {
    width: 560px !important;
    max-height: 80vh;
}

.triple-file-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    margin-bottom: 12px;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.triple-file-size {
    margin-left: auto;
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.triple-flow {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 0;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.triple-flow-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.triple-flow-icon {
    font-size: 20px;
    line-height: 1;
}

.triple-flow-label {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.triple-flow-arrow {
    font-size: var(--text-lg);
    color: var(--text-muted);
    margin: 0 2px;
}

.triple-results {
    max-height: 50vh;
    overflow-y: auto;
}

.triple-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 32px 0;
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.triple-loading-text {
    font-size: var(--text-md);
    font-weight: 500;
    color: var(--text-primary);
}

.triple-loading-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.triple-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: var(--radius-full);
    animation: triple-spin 0.8s linear infinite;
}

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

.triple-success {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--success-light);
    border: 1px solid var(--success);
    border-radius: var(--radius-sm);
    color: var(--success);
    font-size: var(--text-sm);
    margin-bottom: 12px;
}

.triple-error {
    padding: 10px 14px;
    background: var(--danger-light);
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: var(--text-sm);
}

.triple-empty {
    padding: 20px 0;
    text-align: center;
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.triple-table-wrap {
    max-height: 200px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.triple-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-xs);
}

.triple-table th {
    text-align: left;
    padding: 7px 10px;
    background: var(--bg-input);
    color: var(--text-muted);
    font-weight: 500;
    position: sticky;
    top: 0;
}

.triple-table td {
    padding: 6px 10px;
    border-bottom: 1px solid var(--border);
}

.triple-entity {
    display: inline-block;
    padding: 2px 7px;
    border-radius: var(--radius-xs);
    background: var(--primary-light);
    color: var(--primary);
    font-size: var(--text-xs);
    font-weight: 500;
}

.triple-relation {
    display: inline-block;
    padding: 2px 7px;
    border-radius: var(--radius-xs);
    background: var(--success-light);
    color: var(--success);
    font-size: var(--text-xs);
    font-weight: 500;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    font-family: var(--font-sans);
}

.btn-primary {
    background: var(--primary);
    color: var(--text-on-primary);
    border-color: var(--primary);
    box-shadow: var(--shadow-primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text-secondary);
}

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

.triple-goto-btn {
    width: 100%;
    margin-top: 8px;
}

.md-content h1,
.chat-bubble h1 {
    font-size: 1.4em;
    font-weight: 700;
    margin: 0.6em 0 0.3em;
    padding-bottom: 0.2em;
    border-bottom: 1px solid var(--border);
}

.md-content h2,
.chat-bubble h2 {
    font-size: 1.2em;
    font-weight: 700;
    margin: 0.5em 0 0.3em;
    padding-bottom: 0.15em;
    border-bottom: 1px solid var(--border);
}

.md-content h3,
.chat-bubble h3 {
    font-size: 1.1em;
    font-weight: 600;
    margin: 0.4em 0 0.2em;
}

.md-content h4, .md-content h5, .md-content h6,
.chat-bubble h4, .chat-bubble h5, .chat-bubble h6 {
    font-size: 1em;
    font-weight: 600;
    margin: 0.3em 0 0.15em;
}

.md-content p,
.chat-bubble p {
    margin: 0.4em 0;
    line-height: 1.7;
}

.md-content ul, .md-content ol,
.chat-bubble ul, .chat-bubble ol {
    margin: 0.4em 0;
    padding-left: 1.5em;
}

.md-content ol,
.chat-bubble ol {
    list-style-type: decimal;
}

.md-content ol ol,
.chat-bubble ol ol {
    list-style-type: lower-alpha;
}

.md-content li,
.chat-bubble li {
    margin: 0.15em 0;
    line-height: 1.6;
}

.md-content code,
.chat-bubble code {
    background: var(--bg-hover);
    padding: 1px 5px;
    border-radius: var(--radius-xs);
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.md-content pre,
.chat-bubble pre {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 12px 14px;
    margin: 0.5em 0;
    overflow-x: auto;
    font-size: 0.9em;
    line-height: var(--leading-relaxed);
}

.md-content pre code,
.chat-bubble pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: inherit;
}

.md-content blockquote,
.chat-bubble blockquote {
    border-left: 3px solid var(--primary);
    margin: 0.5em 0;
    padding: 0.3em 1em;
    color: var(--text-secondary);
    background: var(--bg-hover);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.md-content table,
.chat-bubble table {
    border-collapse: collapse;
    margin: 0.5em 0;
    font-size: 0.9em;
    width: 100%;
}

.md-content th, .md-content td,
.chat-bubble th, .chat-bubble td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
}

.md-content th,
.chat-bubble th {
    background: var(--bg-input);
    font-weight: 600;
}

.md-content hr,
.chat-bubble hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 0.8em 0;
}

.md-content strong,
.chat-bubble strong {
    font-weight: 700;
}

.md-content em,
.chat-bubble em {
    font-style: italic;
}

.md-content a,
.chat-bubble a {
    color: var(--primary);
    text-decoration: none;
}

.md-content a:hover,
.chat-bubble a:hover {
    text-decoration: underline;
}

.chat-bubble .kg-chat-source-link {
    display: inline-flex;
    max-width: 100%;
    align-items: center;
    color: var(--primary);
    font-weight: 600;
    overflow-wrap: anywhere;
}

/* Obsidian-style light shell */
html,
html[data-theme="dark"] {
    --primary: #6d4aff;
    --primary-hover: #7c5cff;
    --primary-active: #5836dc;
    --primary-light: rgba(109, 74, 255, 0.09);
    --primary-lighter: rgba(109, 74, 255, 0.05);
    --bg-base: #ffffff;
    --bg-surface: #fbfbfc;
    --bg-elevated: #ffffff;
    --bg-hover: #f3f4f7;
    --bg-active: #eeebff;
    --bg-input: #ffffff;
    --border: #e1e4ea;
    --border-light: #eef0f4;
    --text-primary: #1f2328;
    --text-secondary: #4d5562;
    --text-muted: #7a828e;
    --text-inverse: #ffffff;
    --text-on-primary: #ffffff;
    --shadow-xs: none;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
    --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.08);
}

body,
html[data-theme="dark"] body,
.app,
.workspace,
.main-content {
    background: #ffffff;
    color: #1f2328;
}

.header,
html[data-theme="dark"] .header {
    background: #ffffff;
    border-bottom: 1px solid #e1e4ea;
    box-shadow: none;
}

.logo,
.header-status,
.icon-btn,
html[data-theme="dark"] .toolbar button {
    color: #4d5562;
}

.logo span:first-of-type {
    color: #1f2328;
}

.nav-tabs {
    background: #f5f6f8;
    border: 1px solid #e1e4ea;
    box-shadow: none;
}

.nav-tab {
    color: #5c6470;
}

.nav-tab:hover {
    background: #eceef3;
    color: #1f2328;
}

.nav-tab.active {
    background: #eeebff;
    color: #5b3ee4;
    box-shadow: none;
}

.sidebar,
html[data-theme="dark"] .sidebar {
    background: #fbfbfc;
    border-right-color: #e1e4ea;
}

.sidebar-header,
.sidebar-footer,
.panel-header,
.chat-input-box,
html[data-theme="dark"] .toolbar {
    background: #fbfbfc;
    border-color: #e1e4ea;
}

.sidebar-search,
.sidebar-search input,
html[data-theme="dark"] input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] select {
    background: #ffffff;
    color: #1f2328;
    border-color: #dfe3ea;
}

.tree-item:hover {
    background: #f0f1f4;
}

.tree-item.active,
.tree-item.selected {
    background: #eeebff;
    color: #5b3ee4;
}

.col-right,
.panel,
#kg-right-panel,
html[data-theme="dark"] .main-content,
html[data-theme="dark"] .chat-bubble {
    background: #ffffff;
    color: #1f2328;
}

#page-kg .col-right {
    border-left: 1px solid #e1e4ea;
}

#page-kg .panel-header {
    background: #ffffff;
    border-bottom: 1px solid #e1e4ea;
    color: #1f2328;
}

#page-kg .chat-messages,
#page-kg .kg-side-graph {
    background: #ffffff;
}

#page-kg .kg-side-graph-head {
    color: #24272e;
}

#page-kg .kg-side-graph-box,
#page-kg .kg-graph-canvas-wrap,
html[data-theme="dark"] .kg-container canvas {
    background: #ffffff;
    border-color: #dfe3ea;
}

#page-kg canvas {
    background: #ffffff;
}

#page-kg .chat-msg.assistant .chat-bubble {
    background: #f7f7f8;
    border: 1px solid #e1e4ea;
    color: #1f2328;
    box-shadow: none;
}

#page-kg .chat-msg.user .chat-bubble {
    background: #eeeaff;
    color: #35206f;
    border: 1px solid #ddd4ff;
    box-shadow: none;
}

#page-kg .chat-avatar {
    background: #f0f1f4;
    color: #5c6470;
    border: 1px solid #e1e4ea;
}

#page-kg .chat-input-box {
    background: #fbfbfc;
    border-top: 1px solid #e1e4ea;
}

#page-kg .chat-input-box textarea {
    background: #ffffff;
    border: 1px solid #dfe3ea;
    color: #1f2328;
}

#page-kg .send-btn {
    background: #6d4aff;
    color: #ffffff;
    box-shadow: none;
}

.kg-graph-modal {
    background: #ffffff;
}

.kg-graph-modal-body,
.kg-graph-modal-canvas {
    background: #ffffff;
}

body.kg-layout-active .workspace {
    width: min(100%, 1560px);
    max-width: 1560px;
    flex: 1 1 auto;
    align-self: center;
    border-left: 1px solid #edf0f4;
    border-right: 1px solid #edf0f4;
}

body.kg-layout-active .sidebar {
    width: 300px;
    min-width: 260px;
    max-width: 340px;
}

body.kg-layout-active .main-content {
    flex: 1 1 auto;
    min-width: 0;
}

body.kg-layout-active #page-kg .col-center {
    flex: 1 1 820px;
}

body.kg-layout-active #page-kg .col-right {
    width: 340px;
    min-width: 300px;
    max-width: 380px;
}

body.kg-layout-active #page-kg .kg-reader {
    max-width: 720px;
    padding-left: 28px;
    padding-right: 28px;
}

body.kg-layout-active #page-kg .kg-side-graph {
    padding-left: 16px;
    padding-right: 16px;
}

body.kg-layout-active #page-kg .kg-side-graph-box {
    height: 206px;
}

@media (max-width: 1500px) {
    body.kg-layout-active .workspace {
        border-left: 0;
        border-right: 0;
    }
}

body.focused-layout-active .header,
body.focused-layout-active .workspace {
    width: min(100%, 1560px);
    max-width: 1560px;
    align-self: center;
}

body.focused-layout-active .header {
    padding-left: 12px;
    padding-right: 12px;
    border-left: 1px solid #edf0f4;
    border-right: 1px solid #edf0f4;
}

body.focused-layout-active .workspace {
    flex: 1 1 auto;
    border-left: 1px solid #edf0f4;
    border-right: 1px solid #edf0f4;
}

body.focused-layout-active .sidebar {
    width: 300px;
    min-width: 260px;
    max-width: 340px;
}

body.focused-layout-active .main-content {
    flex: 1 1 auto;
    min-width: 0;
}

body.rag-layout-active #page-rag .col-center {
    flex: 1 1 900px;
    border-right: 1px solid #e1e4ea;
}

body.rag-layout-active #page-rag .col-right {
    width: 300px;
    min-width: 280px;
    max-width: 340px;
}

body.rag-layout-active #page-rag .chat-messages {
    padding: 18px 24px;
}

body.rag-layout-active #page-rag .chat-toolbar,
body.rag-layout-active #page-rag .chat-input-box {
    padding-left: 18px;
    padding-right: 18px;
}

body.rag-layout-active #page-rag .chat-bubble {
    max-width: 920px;
}

body.rag-layout-active #page-rag .chat-msg.assistant {
    margin-left: 0;
    max-width: 88%;
}

body.rag-layout-active #page-rag .chat-msg.user {
    max-width: min(760px, 78%);
}

body.rag-layout-active #page-rag .chat-msg.assistant .chat-bubble {
    transform: translateX(0);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

body.rag-layout-active #page-rag .chat-msg.assistant.rag-index-focus .chat-bubble {
    transform: translateX(4px);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.08);
}

.rag-kb-page {
    height: 100%;
    overflow-y: auto;
    padding: 18px 20px 28px;
    background: #ffffff;
}

.rag-kb-page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.rag-kb-page-head h3 {
    margin: 0;
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 650;
    line-height: 1.3;
}

.rag-kb-page-head p {
    margin: 5px 0 0;
    color: var(--text-muted);
    font-size: 13px;
}

.rag-kb-create-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    height: 34px;
    padding: 0 12px;
    border: 1px solid var(--primary);
    border-radius: 7px;
    background: var(--primary);
    color: var(--text-on-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}

.rag-kb-create-btn:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.rag-kb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 14px;
    align-items: start;
}

.rag-kb-empty {
    grid-column: 1 / -1;
    min-height: 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: var(--text-muted);
    border: 1px dashed #d8dde8;
    border-radius: 8px;
    background: #fbfcfe;
}

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

.rag-kb-card {
    min-width: 0;
    overflow: hidden;
    border: 1px solid #e1e4ea;
    border-radius: 8px;
    background: #ffffff;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, transform 0.18s ease;
}

.rag-kb-card:hover {
    border-color: #c8d2e4;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    transform: translateY(-1px);
}

.rag-kb-card-main {
    padding: 14px;
}

.rag-kb-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    min-width: 0;
}

.rag-kb-title-wrap {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: 0;
}

.rag-kb-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--kb-accent) 10%, white);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 34px;
}

.rag-kb-title-text {
    min-width: 0;
}

.rag-kb-title-text h4 {
    margin: 0;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 650;
    line-height: 1.35;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rag-kb-title-text p {
    margin: 3px 0 0;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.rag-kb-fixed-badge {
    display: inline-flex;
    align-items: center;
    height: 18px;
    margin-left: 8px;
    padding: 0 7px;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.10);
    color: var(--primary);
    font-size: 11px;
    font-weight: 700;
    vertical-align: middle;
}

.rag-kb-actions {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 0 0 auto;
}

.rag-kb-actions .icon-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
}

.rag-kb-stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
    margin-top: 14px;
}

.rag-kb-stats div {
    min-width: 0;
    padding: 8px 7px;
    border: 1px solid #edf0f5;
    border-radius: 7px;
    background: #fafbfc;
}

.rag-kb-stats strong {
    display: block;
    color: var(--text-primary);
    font-size: 15px;
    font-weight: 700;
    line-height: 1.1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rag-kb-stats span {
    display: block;
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.1;
    white-space: nowrap;
}

.rag-kb-card-foot {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.rag-kb-inline-action {
    height: 22px;
    padding: 0 9px;
    border: 1px solid #d8e2f0;
    border-radius: 999px;
    background: #ffffff;
    color: var(--primary);
    font-size: 12px;
    font-weight: 650;
    cursor: pointer;
}

.rag-kb-inline-action:hover {
    background: rgba(37, 99, 235, 0.08);
    border-color: rgba(37, 99, 235, 0.28);
}

.icon-btn.primary {
    background: rgba(37, 99, 235, 0.08);
    color: var(--primary);
    border: 1px solid rgba(37, 99, 235, 0.18);
}

.icon-btn.primary:hover {
    background: rgba(37, 99, 235, 0.14);
}

.rag-kb-strategy,
.rag-kb-local-pending {
    display: inline-flex;
    align-items: center;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.rag-kb-strategy {
    color: var(--kb-accent);
    background: color-mix(in srgb, var(--kb-accent) 10%, white);
}

.rag-kb-local-pending {
    color: #b45309;
    background: #fff7ed;
}

.rag-kb-docs {
    max-height: 260px;
    overflow-y: auto;
    border-top: 1px solid #edf0f5;
    background: #fbfcfe;
}

.rag-kb-docs-inner {
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rag-kb-docs-title {
    margin-bottom: 2px;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 650;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.rag-kb-docs-title-main {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-wrap: wrap;
}

.rag-kb-docs-title-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
}

.rag-kb-mini-btn {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text-secondary);
    font-size: 11px;
    line-height: 1;
    padding: 5px 10px;
    border-radius: 999px;
    cursor: pointer;
    transition: all .18s ease;
}

.rag-kb-mini-btn:hover {
    border-color: #c7d2fe;
    color: var(--primary);
    background: #f5f7ff;
}

.rag-kb-docs-local,
.rag-kb-docs-pending {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    line-height: 1.4;
    background: #f8fafc;
    color: var(--text-secondary);
    border: 1px solid #e2e8f0;
}

.rag-kb-docs-pending {
    background: #fff7ed;
    border-color: #fed7aa;
    color: #c2410c;
}

.rag-kb-docs-empty {
    padding: 14px;
    color: var(--text-muted);
    text-align: center;
    font-size: 13px;
}

.rag-kb-docs-empty.is-error {
    color: var(--danger);
}

.rag-kb-import-dialog-box {
    width: min(920px, calc(100vw - 32px)) !important;
    max-height: 88vh;
    display: flex;
    flex-direction: column;
    padding: 0 !important;
    overflow: hidden;
}

.rag-kb-import-head {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 18px 20px 14px;
    border-bottom: 1px solid #e7eaf0;
}

.rag-kb-import-head-icon {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 36px;
    border-radius: 7px;
    color: #245fbd;
    background: #eef4ff;
}

.rag-kb-import-target {
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 12px;
}

.rag-kb-import-pipeline {
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 38px;
    padding: 0 20px;
    color: #596273;
    background: #f8f9fb;
    border-bottom: 1px solid #e7eaf0;
    font-size: 12px;
}

.rag-kb-import-pipeline i {
    color: #a5acb8;
    font-style: normal;
}

.rag-kb-import-pipeline em {
    margin-left: auto;
    color: #4f5968;
    font-style: normal;
}

.rag-kb-import-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 20px 10px;
}

.rag-kb-import-search-wrap {
    flex: 1 1 240px;
    min-width: 0;
    height: 34px;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 10px;
    border: 1px solid #dce1e9;
    border-radius: 6px;
    background: #fff;
    color: #8a93a2;
}

.rag-kb-import-search {
    min-width: 0;
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text-primary);
    font: inherit;
}

.rag-kb-import-format {
    height: 34px;
    max-width: 148px;
    padding: 0 28px 0 10px;
    border: 1px solid #dce1e9;
    border-radius: 6px;
    background: #fff;
    color: #4f5968;
    font-size: 12px;
}

.rag-kb-import-count {
    color: #687284;
    font-size: 12px;
    white-space: nowrap;
}

.rag-kb-import-count strong {
    color: var(--primary);
    font-size: 13px;
}

.rag-kb-import-columns {
    display: grid;
    grid-template-columns: 22px 48px minmax(0, 1fr) 76px;
    gap: 10px;
    align-items: center;
    margin: 0 20px;
    padding: 0 12px 7px;
    color: #8b94a2;
    font-size: 11px;
}

.rag-kb-import-list {
    flex: 1 1 auto;
    min-height: 300px;
    max-height: 52vh;
    overflow-y: auto;
    margin: 0 20px;
    border: 1px solid #dfe3ea;
    border-radius: 6px;
    background: #fff;
    padding: 4px;
}

.rag-kb-import-row {
    display: grid;
    grid-template-columns: 22px 48px minmax(0, 1fr) 76px;
    gap: 10px;
    align-items: center;
    min-width: 0;
    min-height: 48px;
    padding: 6px 8px;
    border-bottom: 1px solid #f0f2f5;
    color: var(--text-primary);
    cursor: pointer;
}

.rag-kb-import-row:last-child { border-bottom: 0; }

.rag-kb-import-row:hover {
    background: #f7f9fc;
}

.rag-kb-import-row input {
    margin: 0;
}

.rag-kb-import-ext {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 24px;
    padding: 0;
    border-radius: 5px;
    background: #eef3fb;
    color: #315f9f;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}

.rag-kb-import-file {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.rag-kb-import-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #222833;
    font-size: 13px;
    font-weight: 650;
}

.rag-kb-import-path {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 11px;
    text-align: left;
}

.rag-kb-import-size {
    color: #7b8595;
    font-size: 11px;
    text-align: right;
    white-space: nowrap;
}

.rag-kb-import-empty {
    min-height: 180px;
    display: grid;
    place-items: center;
    color: var(--text-muted);
    font-size: 13px;
}

.rag-kb-import-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 20px 18px;
    border-top: 1px solid #e7eaf0;
    margin-top: 14px;
}

.rag-kb-import-footer .dialog-actions {
    margin: 0;
}

@media (max-width: 720px) {
    .rag-kb-import-toolbar { flex-wrap: wrap; }
    .rag-kb-import-search-wrap { flex-basis: 100%; }
    .rag-kb-import-columns,
    .rag-kb-import-row { grid-template-columns: 22px 42px minmax(0, 1fr); }
    .rag-kb-import-columns span:last-child,
    .rag-kb-import-size { display: none; }
    .rag-kb-import-pipeline em { display: none; }
}

.rag-kb-doc-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
    padding: 7px 8px;
    border: 1px solid transparent;
    border-radius: 7px;
    background: #ffffff;
}

.rag-kb-doc-row:hover {
    border-color: #dbe2ef;
}

.rag-kb-doc-main {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
    cursor: pointer;
}

.rag-kb-doc-copy {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.rag-kb-doc-ext {
    min-width: 34px;
    max-width: 42px;
    height: 20px;
    padding: 0 5px;
    border-radius: 5px;
    background: color-mix(in srgb, var(--doc-accent) 10%, white);
    color: var(--doc-accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    overflow: hidden;
}

.rag-kb-doc-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-primary);
    font-size: 13px;
}

.rag-kb-doc-subline {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
    flex-wrap: wrap;
    color: var(--text-muted);
    font-size: 11px;
}

.rag-kb-embed-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid transparent;
    font-size: 10px;
    font-weight: 600;
    line-height: 1.3;
}

.rag-kb-embed-badge.complete {
    background: #ecfdf5;
    border-color: #bbf7d0;
    color: #15803d;
}

.rag-kb-embed-badge.partial {
    background: #fff7ed;
    border-color: #fed7aa;
    color: #c2410c;
}

.rag-kb-embed-badge.missing {
    background: #f8fafc;
    border-color: #cbd5e1;
    color: #475569;
}

.rag-kb-embed-badge.empty {
    background: #f1f5f9;
    border-color: #e2e8f0;
    color: #64748b;
}

.rag-kb-doc-count,
.rag-kb-doc-progress {
    font-variant-numeric: tabular-nums;
}

.rag-kb-doc-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    color: var(--text-muted);
    font-size: 12px;
}

.rag-kb-chunks {
    max-height: 520px;
    overflow-y: auto;
    border-top: 1px solid #edf0f5;
    background: #fbfcfe;
    padding: 12px;
}

.rag-kb-inline-chunks-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.rag-kb-inline-chunks-head strong {
    display: block;
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 700;
}

.rag-kb-inline-chunks-head span {
    display: block;
    margin-top: 2px;
    color: var(--text-muted);
    font-size: 12px;
}

.rag-kb-inline-chunks-list .rag-parent-chunk-card {
    margin-bottom: 8px;
}

.rag-kb-inline-chunks-list .rag-parent-chunk-summary {
    padding: 10px 11px;
}

.rag-kb-inline-chunks-list .rag-parent-chunk-summary-meta {
    flex-basis: 230px;
}

.rag-kb-multi-btn {
    cursor: pointer;
    min-width: 132px;
    max-width: 170px;
    text-align: left;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.rag-kb-multi-btn span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rag-kb-multi-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 1200;
    min-width: 190px;
    max-width: 240px;
    max-height: 250px;
    overflow-y: auto;
    padding: 6px;
    border: 1px solid #dce2ec;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 14px 32px rgba(15, 23, 42, 0.14);
}

.rag-kb-multi-option {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    padding: 7px 8px;
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
}

.rag-kb-multi-option:hover {
    background: #f4f7fb;
}

.rag-kb-multi-option input {
    flex-shrink: 0;
}

body.kg-layout-active #page-kg .kg-reader {
    max-width: 720px;
}

body.kg-layout-active #page-kg .kg-reader.kg-reader-pdf-mode {
    max-width: none;
}

body.focused-layout-active .sidebar,
body.focused-layout-active .sidebar-header,
body.focused-layout-active .sidebar-footer,
body.focused-layout-active .sidebar-tree {
    background: #ffffff;
}

body.focused-layout-active .sidebar {
    border-right-color: #edf0f4;
}

body.focused-layout-active .sidebar-search {
    background: #ffffff;
    border-color: #e3e6ec;
}

body.focused-layout-active .tree-item:hover {
    background: #f6f7f9;
}

body.focused-layout-active .tree-item.active,
body.focused-layout-active .tree-item.selected {
    background: #f1efff;
}

#page-kg .kg-side-graph-box {
    border-color: #e8ebf0;
    border-radius: 7px;
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.7);
}

.kg-graph-modal-body {
    box-shadow: none;
}

.kg-graph-modal-canvas {
    border: 0;
}

@media (max-width: 1560px) {
    body.focused-layout-active .header,
    body.focused-layout-active .workspace {
        border-left: 0;
        border-right: 0;
    }
}
.access-role-badge {
    display: inline-flex;
    align-items: center;
    height: 24px;
    padding: 0 9px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-secondary);
    background: var(--bg-surface);
    font-size: 11px;
    white-space: nowrap;
}

.access-role-badge.owner {
    color: #236348;
    border-color: rgba(35, 99, 72, 0.2);
    background: rgba(35, 99, 72, 0.07);
}

.access-role-badge.guest {
    color: #77571b;
    border-color: rgba(119, 87, 27, 0.2);
    background: rgba(119, 87, 27, 0.07);
}

body.access-guest .convert-tab,
body.access-guest .sidebar-actions,
body.access-guest .tree-file-actions,
body.access-guest .rag-kb-create-btn,
body.access-guest .rag-kb-import-toolbar,
body.access-guest .rag-session-delete-btn,
body.access-guest .kg-reader-save-btn {
    display: none !important;
}

body.access-guest .write-access-only {
    display: none !important;
}

body.access-guest .tree-item {
    cursor: default;
}

body.access-guest .tree-item[draggable="true"] {
    -webkit-user-drag: none;
}

.kg-reader-loading {
    min-height: 320px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    color: var(--text-secondary);
    font-size: 13px;
}

.kg-reader-loading strong {
    max-width: min(520px, 80%);
    overflow: hidden;
    color: var(--text-primary);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kg-reader-loading-spinner {
    width: 22px;
    height: 22px;
    border: 2px solid #dfe3ea;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: kg-reader-loading-spin 0.75s linear infinite;
}

.kg-reader-plain-text {
    margin: 0;
    padding: 18px 22px 28px;
    overflow: auto;
    color: #28303d;
    background: #fff;
    font: 13px/1.65 var(--font-mono);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    tab-size: 2;
}

@keyframes kg-reader-loading-spin {
    to { transform: rotate(360deg); }
}

body.rag-layout-active #page-rag .rag-composer,
#page-rag .rag-composer {
    padding: 10px 12px;
}

body.rag-layout-active #page-rag .rag-composer-tools,
#page-rag .rag-composer-tools {
    padding: 0;
    border-top: 0;
    background: transparent;
}
