/* === Variables (Dark theme, WorkBuddy-inspired) === */
:root {
    /* === Dark theme (WorkBuddy-inspired) === */
    --bg: #1a1d23;                 /* app background */
    --bg-sidebar: #14171c;         /* sidebar surface */
    --bg-sidebar-2: #1c1f25;       /* raised sidebar element */
    --bg-chat: #1a1d23;            /* chat area background */
    --bg-user-msg: #2a2f3a;        /* user bubble */
    --bg-agent-msg: #1f2329;       /* agent bubble */
    --bg-plan: #1f2329;
    --bg-tool: #2a2419;            /* tool call row */
    --bg-rag: #1a2620;
    --bg-input: #14171c;           /* input area background */
    --text: #e6e8ec;               /* primary text */
    --text-secondary: #9ba1ad;     /* secondary text */
    --text-muted: #6b727d;         /* muted text */
    --border: #2a2f37;             /* default border */
    --border-strong: #3a4048;
    --accent: #5b8def;             /* brand accent */
    --accent-hover: #7ba1ff;
    --accent-light: #243047;       /* accent-tinted background */
    --accent2: #f97316;            /* orange — brand logo color */
    --success: #4ade80;
    --success-dark: #22c55e;
    --success-soft: #1a2a22;       /* success-tinted background */
    --error: #f87171;
    --warning: #fbbf24;
    --radius: 10px;                /* ds-control radius */
    --radius-sm: 8px;
    --radius-pill: 4096px;         /* ds pill buttons */
    --shadow: 0 1px 2px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.5);
    /* inline code / fenced block surface — theme-aware */
    --code-bg: rgba(255,255,255,0.08);
    --code-bg-block: rgba(0,0,0,0.22);
    --code-text: #e599c2;
    /* Chinese: PingFang SC (macOS/iOS) first, Noto Sans CJK SC fallback.
       Latin: SF Pro surfaces via -apple-system/PingFang embedded Latin.
       Explicitly exclude 微软雅黑 (Microsoft YaHei — variable stroke width,
       flared corners) and serif faces (楷体/宋体). */
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Noto Sans CJK SC", "Source Han Sans SC", "Helvetica Neue", Arial, sans-serif;
    /* Code: JetBrains Mono first, SF Mono fallback. Keep out of --font (body). */
    --font-mono: "JetBrains Mono", "SF Mono", "Menlo", "Consolas", "Courier New", monospace;
    --sidebar-w: 300px;
    --topbar-h: 52px;
}

/* === Light theme (toggle via html[data-theme="light"]) === */
:root[data-theme="light"] {
    --bg: #f5f6f8;
    --bg-sidebar: #eceef1;
    --bg-sidebar-2: #e2e5ea;
    --bg-chat: #f5f6f8;
    --bg-user-msg: #d8e3f7;
    --bg-agent-msg: #ffffff;
    --bg-plan: #ffffff;
    --bg-tool: #fff6e6;
    --bg-rag: #e6f4ec;
    --bg-input: #ffffff;
    --text: #1c1f24;
    --text-secondary: #5a616e;
    --text-muted: #8a919d;
    --border: #dde1e7;
    --border-strong: #c6ccd6;
    --accent: #2f6fe0;
    --accent-hover: #1e5cc9;
    --accent-light: #e4ecfc;
    --accent2: #ea6a12;
    --success: #16a34a;
    --success-dark: #15803d;
    --success-soft: #dcf3e5;
    --error: #dc2626;
    --warning: #d97706;
    --shadow: 0 1px 2px rgba(0,0,0,0.08);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.12);
    --code-bg: rgba(0,0,0,0.06);
    --code-bg-block: rgba(0,0,0,0.05);
    --code-text: #b03060;
}

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

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
    overflow: hidden;
    /* 兜底：任何意外溢出都不产生横向滚动条 */
    overflow-x: hidden;
}

/* === Layout === */
#app {
    display: flex;
    height: 100vh;
    height: 100dvh;
    /* 不允许整体出现横向滚动条；子项改用 min-width:0 收缩 */
    overflow-x: hidden;
}

/* === Sidebar === */
#sidebar {
    width: var(--sidebar-w);
    min-width: var(--sidebar-w);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

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

.sidebar-header h2 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

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

/* === Index section === */
.index-section {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-bottom: 1px solid var(--border);
}

/* Row under the path input: Index Files + refresh + config icons */
.index-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.index-actions #index-btn {
    flex: 1;
    white-space: nowrap;
}

#index-path {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font-mono);
    outline: none;
    transition: border-color 0.15s;
}

#index-path:focus {
    border-color: var(--accent);
}

.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s;
}

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

.btn-primary:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

/* === Stats === */
.stats-bar {
    padding: 8px 16px;
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
    border-bottom: 1px solid var(--border);
}

.stat-item span {
    font-weight: 600;
    color: var(--text);
}

.stat-sep {
    color: var(--border);
}

/* === Index progress === */
.index-progress {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
}

.progress-header {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.progress-bar {
    height: 4px;
    background: var(--bg-chat);
    border-radius: 2px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
    width: 0%;
}

/* KB operation feedback (upload/index/delete results) in the sidebar */
.kb-status {
    margin: 8px 16px;
    padding: 8px 10px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--text-secondary);
    background: var(--bg-chat);
    border: 1px solid var(--border);
    border-radius: 6px;
    word-break: break-all;
}
.kb-status.hidden {
    display: none;
}

/* kshare config entry status line */
.kshare-status {
    font-size: 11px;
    color: var(--text-muted);
    align-self: center;
}

/* === Document list === */
.doc-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.doc-card {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 6px;
    transition: border-color 0.15s;
    cursor: default;
}

.doc-card:hover {
    border-color: var(--accent);
}

.doc-card-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 4px;
    word-break: break-word;
}

.doc-card-meta {
    font-size: 11px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.doc-card-type {
    background: var(--accent-light);
    color: var(--accent);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 500;
    font-family: var(--font-mono);
    text-transform: uppercase;
}

.doc-card-chunks {
    color: var(--text-secondary);
}

.doc-card-summary {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 6px;
    line-height: 1.4;
}

.doc-card-category {
    display: inline-block;
    background: var(--bg-rag);
    color: var(--success);
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 500;
    margin-top: 4px;
}

.doc-card-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.15s;
}

.doc-card:hover .doc-card-actions {
    opacity: 1;
}

.doc-action-btn {
    font-size: 11px;
    padding: 3px 8px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg-sidebar);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s;
}

.doc-action-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.doc-action-btn.delete:hover {
    border-color: var(--error);
    color: var(--error);
}

/* --- Category-tree document list (replaces the old doc-card layout) --- */

.doc-cat-root > .doc-cat-head {
    display: none; /* root has no label */
}

.doc-cat {
    margin-bottom: 4px;
}

.doc-cat-children {
    margin-left: 12px;
    border-left: 1px solid var(--border);
    padding-left: 8px;
}

.doc-cat-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: default;
}

.doc-cat-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.doc-cat-count {
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-chat);
    border-radius: 8px;
    padding: 0 6px;
}

.doc-cat-docs {
    margin-top: 1px;
}

/* One compact row per document: [icon] name [type] [size] (actions icons) */
.doc-row {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 4px;
    border-radius: 4px;
    font-size: 12px;
    color: var(--text);
    cursor: default;
    white-space: nowrap;
}

.doc-row:hover {
    background: var(--bg-chat);
}

.doc-row-icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

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

.doc-row-type {
    flex-shrink: 0;
    font-size: 10px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    text-transform: uppercase;
    background: var(--bg-chat);
    padding: 0 4px;
    border-radius: 3px;
}

.doc-row-size {
    flex-shrink: 0;
    font-size: 10px;
    color: var(--text-muted);
}

.doc-row-actions {
    flex-shrink: 0;
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity 0.15s;
}

.doc-row:hover .doc-row-actions {
    opacity: 1;
}

.doc-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}

.doc-icon-btn:hover {
    color: var(--accent);
    background: var(--bg-sidebar);
}

.doc-icon-btn.del:hover {
    color: var(--error);
    background: var(--bg-sidebar);
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    padding: 30px 16px;
    line-height: 1.6;
}

/* === Main area === */
#main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;        /* 新任务态：绝对定位输入相对内容区而非视口 */
    /* 主区内部也不允许横向溢出（内容改为自身滚动/换行） */
    overflow-x: hidden;
}

/* === Topbar === */
#topbar {
    height: var(--topbar-h);
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-left h1 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.connected {
    background: var(--success);
    box-shadow: 0 0 6px rgba(22, 163, 74, 0.4);
}

.status-dot.disconnected {
    background: var(--text-muted);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.topbar-select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 5px 8px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    max-width: 160px;
    height: 28px;
}

/* Task switcher — wider so task names stay readable. */
.task-select {
    max-width: 200px;
    font-weight: 600;
}

.topbar-input {
    width: 120px;
}

.btn-ghost {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 5px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-ghost:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* === Chat === */
.chat {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-width: 0;
}

.welcome-msg {
    text-align: center;
    padding: 7vh 20px 8px;
    color: var(--text-muted);
}

.welcome-icon {
    margin-bottom: 16px;
    opacity: 0.6;
}

.welcome-msg h3 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 8px;
    letter-spacing: -0.01em;
}

.welcome-msg p {
    font-size: 14px;
}

/* === Messages === */
.msg {
    max-width: 85%;
    min-width: 0;
    animation: msgIn 0.2s ease;
}

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

.msg.user {
    align-self: flex-end;
}

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

.msg-bubble {
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.msg.user .msg-bubble {
    background: var(--bg-user-msg);
    color: var(--text);
    border-bottom-right-radius: 2px;
}

.msg.agent .msg-bubble {
    background: var(--bg-agent-msg);
    border: 1px solid var(--border);
    border-bottom-left-radius: 2px;
    box-shadow: var(--shadow);
}

.msg-bubble code {
    font-family: var(--font-mono);
    font-size: 0.86em;
    background: var(--code-bg);
    color: var(--code-text);
    padding: 1px 5px;
    border-radius: 4px;
    border: none;                 /* 规范: 无边框, 极弱浅灰底 */
    white-space: pre-wrap;
    word-break: break-all;
}

.msg-bubble pre {
    background: var(--code-bg-block);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    max-width: 100%;
    margin: 8px 0;
    line-height: 1.55;
}

.msg-bubble pre code {
    background: none;
    color: inherit;
    padding: 0;
    font-size: 12.5px;
}

/* Markdown tables: keep within the bubble, cells wrap instead of overflowing */
.msg-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 8px 0;
    font-size: 13px;
    display: block;
    overflow-x: auto;
}
.msg-bubble th, .msg-bubble td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
    word-break: break-word;
    overflow-wrap: anywhere;
}

/* === Thinking indicator === */
.thinking {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: var(--bg-agent-msg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    color: var(--text-secondary);
}

.thinking-dots {
    display: flex;
    gap: 4px;
}

.thinking-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: bounce 1.2s infinite;
}

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

@keyframes bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* === Plan (task decomposition) === */
.plan-block {
    align-self: flex-start;
    width: 85%;
    background: var(--bg-plan);
    border: 1px solid #e1bee7;
    border-radius: var(--radius);
    padding: 12px 16px;
    animation: msgIn 0.2s ease;
}

.plan-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: #7b1fa2;
    margin-bottom: 8px;
}

.plan-steps {
    list-style: none;
    counter-reset: step;
}

.plan-steps li {
    counter-increment: step;
    padding: 4px 0 4px 28px;
    position: relative;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
}

.plan-steps li::before {
    content: counter(step);
    position: absolute;
    left: 0;
    top: 4px;
    width: 20px;
    height: 20px;
    background: #7b1fa2;
    color: #fff;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
}

/* === Tool call collapsible === */
/* Compact gray line (no card): icon + Chinese label + key info */
.tool-line {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 6px;
    max-width: 92%;
    padding: 2px 12px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-muted);
    background: transparent;
    cursor: default;
    animation: msgIn 0.15s ease;
    user-select: none;
}

.tool-line-icon {
    flex-shrink: 0;
    font-size: 13px;
    opacity: 0.85;
}

.tool-line-name {
    flex-shrink: 0;
    font-weight: 500;
    color: var(--text-secondary);
}

.tool-line-key {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
}

.tool-line-key::before {
    content: '·';
    margin-right: 6px;
    opacity: 0.6;
}

.tool-line-state {
    flex-shrink: 0;
    font-size: 11px;
    color: var(--text-muted);
    opacity: 0.7;
}

.tool-line.running .tool-line-state::after {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-left: 2px;
    border: 1.5px solid var(--text-muted);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    vertical-align: -1px;
}

.tool-line.ok .tool-line-state {
    color: var(--success);
    opacity: 1;
}

.tool-line.err .tool-line-state {
    color: var(--error);
    opacity: 1;
}

.tool-block {
    align-self: flex-start;
    width: 85%;
    background: var(--bg-tool);
    border: 1px solid #ffe082;
    border-radius: var(--radius);
    overflow: hidden;
    animation: msgIn 0.2s ease;
}

.tool-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    cursor: pointer;
    user-select: none;
    font-size: 13px;
}

.tool-header:hover {
    background: rgba(255, 224, 130, 0.3);
}

.tool-icon {
    font-size: 14px;
    flex-shrink: 0;
}

.tool-name {
    font-weight: 500;
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 12px;
}

.tool-status {
    margin-left: auto;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 3px;
    font-weight: 500;
}

.tool-status.running {
    background: var(--accent-light);
    color: var(--accent);
}

.tool-status.success {
    background: #dcfce7;
    color: var(--success);
}

.tool-status.error {
    background: #fee2e2;
    color: var(--error);
}

.tool-chevron {
    color: var(--text-muted);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.tool-block.expanded .tool-chevron {
    transform: rotate(90deg);
}

.tool-body {
    display: none;
    padding: 10px 14px;
    border-top: 1px solid #ffe082;
    font-size: 12px;
}

.tool-block.expanded .tool-body {
    display: block;
}

.tool-section-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.tool-args, .tool-result {
    font-family: var(--font-mono);
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
    line-height: 1.5;
    margin-bottom: 8px;
    padding: 8px;
    background: rgba(0,0,0,0.04);
    border-radius: var(--radius-sm);
}

.tool-result.success-text {
    color: var(--success);
}

.tool-result.error-text {
    color: var(--error);
}

/* === RAG context === */
.rag-block {
    align-self: flex-start;
    width: 85%;
    background: var(--bg-rag);
    border: 1px solid #a5d6a7;
    border-radius: var(--radius);
    padding: 10px 14px;
    animation: msgIn 0.2s ease;
}

.rag-header {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: #2e7d32;
    margin-bottom: 8px;
}

.rag-sources {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rag-source {
    background: rgba(255,255,255,0.6);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 12px;
}

.rag-source-title {
    font-weight: 500;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: 6px;
}

.rag-source-score {
    font-size: 10px;
    color: var(--success);
    font-family: var(--font-mono);
}

.rag-source-snippet {
    color: var(--text-secondary);
    margin-top: 4px;
    font-size: 11px;
    line-height: 1.4;
    max-height: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
}

/* === Error message === */
.error-block {
    align-self: flex-start;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 13px;
    color: var(--error);
    animation: msgIn 0.2s ease;
}

/* === Status message === */
.status-msg {
    align-self: center;
    font-size: 12px;
    color: var(--text-muted);
    padding: 4px 12px;
    background: var(--bg-chat);
    border-radius: 12px;
}

/* === Input area === */
#input-area {
    padding: 12px 24px calc(env(safe-area-inset-bottom, 0px) + 16px);
    background: var(--bg-sidebar);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-input);
    /* No border on the text box area at all; focus highlight uses a soft
       shadow ring so it does not shift layout. */
    border: none;
    border-radius: var(--radius);
    padding: 6px 6px 4px;
    transition: box-shadow 0.15s;
    box-shadow: var(--shadow);
}

/* Focus highlight: soft accent ring instead of a border */
.input-wrapper:focus-within {
    box-shadow: 0 0 0 1.5px var(--accent);
}

#message-input {
    flex: 1;
    border: none;
    outline: none;
    background: none;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    max-height: 240px;
    color: var(--text);
}

#message-input::placeholder {
    color: var(--text-muted);
}

.btn-send {
    background: var(--accent);
    border: none;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

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

.btn-send:disabled {
    background: var(--text-muted);
    cursor: not-allowed;
}

/* === Utility === */
.hidden { display: none !important; }

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c0c0c0; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a0a0a0; }

/* === Sidebar header actions === */
.sidebar-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* === Config modal === */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(2px);
    animation: fadeIn 0.15s ease;
}

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

.modal-dialog {
    position: relative;
    width: 520px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 64px);
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

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

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

.modal-header h3 {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
}

.modal-header .icon-btn {
    font-size: 20px;
    line-height: 1;
    width: 28px;
    height: 28px;
}

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

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

.config-section {
    margin-bottom: 20px;
}

.config-section:last-child {
    margin-bottom: 0;
}

.config-section h4 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
}

.config-hint {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.5;
    margin-bottom: 12px;
}

.config-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

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

.config-path-row {
    display: flex;
    gap: 8px;
}

.config-path-row input {
    flex: 1;
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font-mono);
    outline: none;
    transition: border-color 0.15s;
}

.config-path-row input:focus {
    border-color: var(--accent);
}

.source-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
}

.source-list .empty-state {
    padding: 16px;
}

.source-item {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-chat);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
}

.source-item-path {
    flex: 1;
    min-width: 0;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text);
    word-break: break-all;
    line-height: 1.4;
}

.source-item-remove {
    flex-shrink: 0;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.source-item-remove:hover {
    border-color: var(--error);
    color: var(--error);
}

.toggle-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    line-height: 1.5;
}

.toggle-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin-top: 2px;
    accent-color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
}

/* === Sidebar toggle (mobile) === */
.sidebar-toggle { display: none; }
.sidebar-backdrop { display: none; }

/* Desktop: when the sidebar is collapsed to a thin rail, its header (with the
   collapse button) is hidden — the toggle button surfaces at the LEFTMOST of
   the content top bar instead, so the sidebar can always be reopened. */
@media (min-width: 769px) {
    #app:has(#sidebar.collapsed) #sidebar-toggle {
        display: flex;
    }
}

/* === Responsive === */
/* Medium widths: shrink the fixed sidebar + trim paddings so the chat keeps
   comfortable room and never triggers a horizontal scrollbar before the
   mobile off-canvas layout takes over at 768px. */
@media (max-width: 1100px) {
    :root { --sidebar-w: 260px; }
    .chat { padding: 16px 18px; }
    #topbar { padding: 0 14px; }
    #input-area { padding-left: 18px; padding-right: 18px; }
    .topbar-task-name { max-width: 32vw; }
}

@media (max-width: 900px) {
    :root { --sidebar-w: 230px; }
    .chat { padding: 14px 14px; }
    #input-area { padding-left: 14px; padding-right: 14px; }
    .turn-bubble { padding-left: 36px; }
    .topbar-task-name { max-width: 28vw; }
}

@media (max-width: 768px) {
    :root { --sidebar-w: 240px; }
    .msg, .plan-block, .tool-block, .rag-block { max-width: 95%; width: 95%; }

    /* Sidebar collapses off-canvas by default on phones; open via hamburger */
    #sidebar {
        position: fixed;
        top: 0; left: 0; bottom: 0;
        width: min(82%, 300px);
        z-index: 60;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: var(--shadow-lg);
    }
    #sidebar.open { transform: translateX(0); }
    .sidebar-backdrop:not(.hidden) {
        display: block;
        position: fixed; inset: 0;
        background: rgba(0,0,0,.45);
        z-index: 55;
    }
    .sidebar-toggle { display: flex; }

    /* Keep the input above the browser's bottom navigation bar */
    #input-area {
        padding: 10px 14px calc(env(safe-area-inset-bottom, 0px) + 14px);
    }
}

/* === v0.3: Streaming cursor === */
.cursor-blink {
    display: inline-block;
    animation: blink 0.8s steps(2) infinite;
    color: var(--accent);
    font-weight: bold;
    margin-left: 1px;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

.msg-bubble.streaming {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

/* === v0.3: Reasoning panel === */
.reasoning-block {
    align-self: flex-start;
    width: 85%;
    background: #f8f4ff;
    border: 1px solid #d1c4e9;
    border-radius: var(--radius);
    overflow: hidden;
    animation: msgIn 0.2s ease;
}

.reasoning-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    font-weight: 600;
    color: #6a1b9a;
    background: rgba(106, 27, 154, 0.05);
}

.reasoning-header:hover {
    background: rgba(106, 27, 154, 0.1);
}

.reasoning-chevron {
    margin-left: auto;
    font-size: 10px;
    color: var(--text-muted);
    transition: transform 0.2s;
}

.reasoning-block.expanded .reasoning-chevron {
    transform: rotate(90deg);
}

.reasoning-body {
    display: none;
    padding: 10px 14px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
}

.reasoning-block.expanded .reasoning-body {
    display: block;
}

/* === v0.3: Approval banner === */
.approval-banner {
    align-self: flex-start;
    width: 85%;
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: #fff8e1;
    border: 1px solid #ffcc02;
    border-radius: var(--radius);
    padding: 12px 14px;
    animation: msgIn 0.2s ease;
}

.approval-icon {
    font-size: 18px;
    flex-shrink: 0;
}

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

.approval-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

.approval-args {
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-secondary);
    background: rgba(0,0,0,0.04);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    word-break: break-word;
}

.approval-reason {
    font-size: 11px;
    color: var(--text-muted);
}

.approval-actions {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
}

.approve-btn {
    background: var(--success);
    color: #fff;
    border: none;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    cursor: pointer;
    font-weight: 500;
}

.approve-btn:hover {
    filter: brightness(1.1);
}

.deny-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-size: 12px;
    cursor: pointer;
}

.deny-btn:hover {
    border-color: var(--error);
    color: var(--error);
}

/* === v0.3: Loop warning === */
.loop-warning-block {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: var(--radius);
    padding: 8px 14px;
    font-size: 12px;
    color: #92400e;
    animation: msgIn 0.2s ease;
}

/* === v0.3: Usage display === */
.usage-block {
    align-self: flex-start;
    font-size: 11px;
    color: var(--text-muted);
    padding: 4px 10px;
    background: var(--bg-chat);
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.usage-label {
    font-weight: 600;
}

.usage-val {
    font-family: var(--font-mono);
}

.usage-total {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-secondary);
}

/* === Login overlay (web auth) === */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 17, 21, 0.55);
    backdrop-filter: blur(4px);
}

.login-card {
    width: 320px;
    max-width: calc(100vw - 40px);
    background: var(--bg-agent-msg);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 32px 28px 28px;
    text-align: center;
}

.login-logo {
    font-size: 40px;
    line-height: 1;
}

.login-title {
    margin: 8px 0 2px;
    font-size: 22px;
    font-weight: 700;
}

.login-sub {
    margin-bottom: 20px;
    color: var(--text-secondary);
    font-size: 13px;
}

.login-form,
#login-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.login-input {
    width: 100%;
    padding: 11px 12px;
    font-size: 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text);
    outline: none;
}

.login-input:focus {
    border-color: var(--accent);
}

.login-btn {
    width: 100%;
    padding: 11px 12px;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: var(--accent);
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 0.15s;
}

.login-btn:hover {
    background: var(--accent-hover);
}

.login-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

.login-error {
    margin-top: 12px;
    color: var(--error);
    font-size: 13px;
}

/* === Task step status (P1-5) === */
.steps-block {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 12px;
    margin: 4px 0;
    background: var(--bg-agent-msg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 12.5px;
}
.step-item {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-secondary);
}
.step-item .step-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}
.step-item.running .step-dot {
    background: var(--accent);
    box-shadow: 0 0 6px rgba(79, 140, 255, 0.5);
}
.step-item.done .step-dot {
    background: var(--success);
}
.step-item.error .step-dot {
    background: var(--danger, #ef4444);
}
.step-item .step-status-text {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
}

/* === Skill slash palette (chat "/commands") === */
#input-area {
    position: relative;
}
.skill-palette {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 100%;
    margin-bottom: 8px;
    max-height: 240px;
    overflow-y: auto;
    background: var(--bg-agent-msg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    z-index: 30;
    padding: 4px;
}
.skill-palette.hidden {
    display: none;
}
.skill-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.skill-item:hover,
.skill-item.active {
    background: var(--bg-input);
}
.skill-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
}
.skill-desc {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === Sidebar: no view tabs; full-width success "New task" button === */
.sidebar-tabs {
    display: flex;
    padding: 8px;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

/* "＋ 新任务" — full sidebar width, success green */
.task-new-full {
    width: 100%;
    padding: 8px 0;
    background: var(--success);
    border-color: var(--success);
    color: #fff;
    font-weight: 600;
    border-radius: var(--radius-sm);
}
.task-new-full:hover {
    background: var(--success-dark);
    border-color: var(--success-dark);
    color: #fff;
}

.sidebar-view {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* === Tasks view === */
.tasks-toolbar {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.task-list-items {
    flex: 1;
    overflow-y: auto;
    padding: 6px;
}
/* === Sidebar nav rows (WorkBuddy style: icon + label, no heavy buttons) === */
.side-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 8px 10px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
}
.nav-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text);
    font-family: var(--font);
    font-size: 13.5px;
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}
.nav-row:hover { background: var(--bg-sidebar-2); }
.nav-row .nav-ico { color: var(--text-secondary); flex: none; }

/* Task group header: "任务 (N) ⌄" */
.task-group-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px 4px;
    font-size: 12px;
    color: var(--text-muted);
    user-select: none;
}

.task-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    margin-bottom: 2px;
    border: 1px solid transparent;
    transition: background 0.15s;
}
.task-item:hover { background: var(--bg-sidebar-2); }
/* WorkBuddy-style selected state: soft grey fill, regular text color. */
.task-item.active { background: var(--bg-sidebar-2); }
.task-item-name {
    flex: 1;
    font-size: 13px;
    color: var(--text);
    word-break: break-all;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
}
.task-item-time {
    flex: none;
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}
.task-item-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.task-item.active .task-item-name { color: var(--text); font-weight: 600; }

/* === Chat toolbar (provider / autonomy / clear etc.) === */
.chat-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 20px;
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
}
.chat-task-info {
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 45%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-task-info #chat-task-name { color: var(--text); font-weight: 500; }
.chat-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* === Collapsed sidebar (desktop) === */
@media (min-width: 769px) {
    #sidebar.collapsed { width: 0; min-width: 0; border-right: none; }
}

/* === Question window: input box + toolbar below (DeepSeek-style) === */
/* Toolbar has NO border at all (input-wrapper keeps its own rounded frame) */
#chat-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 8px 10px;
    background: var(--bg-sidebar);
    border: none;
    border-top: none;
    border-radius: 0;
    box-shadow: none;
    flex-shrink: 0;
    flex-wrap: wrap;
}
#chat-toolbar .chat-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* Title bar: current task name (no model) */
.topbar-task-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text);
    max-width: 40vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-left: 1px solid var(--border);
    padding-left: 12px;
    margin-left: 4px;
}

/* === DeepSeek-style refinements === */
/* Borderless selects (provider / autonomy) */
.sel-flat {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 13px;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    outline: none;
    appearance: none;
    -webkit-appearance: none;
}
.sel-flat:hover { background: var(--bg-chat); color: var(--text); }

/* Per-row task "..." menu (rename / delete) + running spinner */
.task-item { display: flex; align-items: center; gap: 6px; }
.task-item .task-item-name { flex: 1; }
.task-item-running {
    flex-shrink: 0;
    color: var(--accent);
    display: flex;
    align-items: center;
}
.task-item-running .spin { animation: taskSpin 0.9s linear infinite; }
@keyframes taskSpin { to { transform: rotate(360deg); } }
.task-item-menu { position: relative; flex-shrink: 0; }
.task-item-more {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    font-size: 16px;
    line-height: 1;
    border-radius: var(--radius-sm);
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.task-item:hover .task-item-more { opacity: 1; }
.task-item-more:hover { color: var(--text); background: var(--bg-chat); }
.task-menu-dropdown {
    display: none;
    position: absolute;
    right: 0;
    top: calc(100% + 2px);
    min-width: 120px;
    max-height: min(320px, 60vh);
    overflow-y: auto;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
    padding: 4px;
    /* Above chat messages / normal content so the menu is never covered;
       modals (z-index 1000) still sit above it. */
    z-index: 900;
}
.task-item-menu.open .task-menu-dropdown { display: block; }
.task-menu-item {
    padding: 7px 10px;
    font-size: 12.5px;
    color: var(--text);
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
}
.task-menu-item:hover { background: var(--bg-chat); }
.task-menu-item.danger { color: #dc2626; }
.task-menu-item.danger:hover { background: rgba(220, 38, 38, 0.08); }

/* Top bar: task name as centered title, no brand logo */
#topbar {
    justify-content: flex-start;
    padding: 0 16px;
    gap: 8px;
}
#topbar .topbar-title {
    flex: 1;
    text-align: center;
    overflow: hidden;
    display: flex;
    justify-content: center;
}
.topbar-task-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    max-width: 60vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    border-left: none;
    padding-left: 0;
    margin-left: 0;
}
#topbar > .status-dot {
    margin-right: 4px;
}

/* Toolbar icon buttons (apply / clear) — tighter, ghost style */
#chat-toolbar .icon-btn {
    padding: 5px;
    border-radius: var(--radius-sm);
}

/* === DeepSeek-style input area (borderless) === */
#input-area {
    padding: 8px 24px calc(env(safe-area-inset-bottom, 0px) + 12px);
    background: transparent;
    border-top: none;
}
#input-area .input-wrapper {
    background: var(--bg-input);
    border: none;
    border-radius: var(--radius);
    box-shadow: none;
    padding: 10px 14px;
    transition: background 0.15s;
}
#input-area .input-wrapper:focus-within {
    border-color: transparent;
    background: var(--bg-input);
}
#chat-toolbar {
    border: none;
    box-shadow: none;
    border-radius: 0;
    padding: 6px 6px 0;
    background: transparent;
}
#chat-toolbar .chat-toolbar-actions {
    gap: 2px;
}
/* Send sits at the far right (after clear-context) */
#chat-toolbar #send-btn {
    margin-left: auto;
}

/* Sidebar brand logo */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
}
.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}
.brand-text h2 { margin: 0; }
.brand-ver {
    font-size: 10.5px;
    color: var(--text-muted);
}
.sidebar-logo {
    flex-shrink: 0;
}

/* Tasks view: tile across the whole sidebar */
.task-list-items {
    padding: 4px;
    display: flex;
    flex-direction: column;
}
.task-item {
    padding: 10px 12px;
    border-radius: 8px;
    width: 100%;
}

/* === DeepSeek component alignment === */
/* Input box: very light inset border (barely visible), brand-blue on focus */
#input-area .input-wrapper {
    background: var(--bg-sidebar);
    box-shadow: inset 0 0 0 1px var(--border);
    border-radius: var(--radius);
    transition: box-shadow 0.15s;
}
#input-area .input-wrapper:focus-within {
    box-shadow: inset 0 0 0 1px var(--accent);
    background: var(--bg-sidebar);
}
#input-area #message-input { caret-color: var(--accent); }

/* Pill buttons (ds-button radius 4096px) */
.btn-primary, .btn-secondary, .btn-ghost, .btn-send {
    border-radius: var(--radius-pill);
}

/* Toolbar icon buttons: circle on hover like ds icon-btn */
#chat-toolbar .icon-btn {
    border-radius: var(--radius-pill);
}

/* Sidebar header: 60px with bottom border (ds sidebar header) */
.sidebar-header {
    min-height: 56px;
    border-bottom: 1px solid var(--border);
}

/* Welcome / brand accents */
.status-dot.connected { background: var(--success); }
.welcome-icon svg rect { stroke: var(--accent); }

/* Chat bubbles slightly softer */
.bubble-agent, .msg-agent { border-radius: var(--radius); }
.bubble-user, .msg-user { border-radius: var(--radius); }

/* === Final: sidebar header one-row layout (logo + tabs + actions) === */
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    flex-wrap: nowrap;
    overflow: hidden;
}
.sidebar-brand {
    flex-shrink: 0;
}
.sidebar-header h2 {
    font-size: 14px;
    white-space: nowrap;
}
/* No sidebar tabs in compact mode (removed) */
.sidebar-header .sidebar-header-actions {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 2px;
}

/* === Final: question window — borderless textarea inside one framed input-area === */
#input-area {
    padding: 8px 24px calc(env(safe-area-inset-bottom, 0px) + 12px);
    background: transparent;
}
#input-area .input-wrapper {
    background: var(--bg-sidebar);
    box-shadow: inset 0 0 0 1px var(--border);
    border-radius: var(--radius);
    padding: 0;
    /* NOT overflow:hidden — it clips the provider/autonomy drop-up menus that
       open upward out of the toolbar (they would render only 2 of N items).
       The border-radius still rounds this wrapper's own background; its
       children (textarea + toolbar) are transparent, so nothing needs clipping. */
    transition: box-shadow 0.15s;
    /* textarea stacked ABOVE the toolbar, never side-by-side */
    flex-direction: column;
    align-items: stretch;
}
#input-area .input-wrapper:focus-within {
    box-shadow: inset 0 0 0 1px var(--accent);
}
#input-area #message-input {
    border: none;
    outline: none;
    background: transparent;
    box-shadow: none;
    width: 100%;
    resize: none;
    flex: 0 0 auto;
    padding: 12px 14px 4px;
    caret-color: var(--accent);
    font-size: 15px;
}
#chat-toolbar {
    border: none;
    border-top: 1px solid var(--border);
    box-shadow: none;
    border-radius: 0;
    padding: 6px 8px;
    background: var(--bg-input);
}
#chat-toolbar .chat-toolbar-actions {
    gap: 2px;
}
/* Send sits at the far right */
#chat-toolbar #send-btn {
    margin-left: auto;
}

/* Sidebar collapse button (right of the settings gear) */
#sidebar-collapse {
    border-radius: var(--radius-sm);
}

/* === Collapsed sidebar → fully hidden (no thin rail, no expand arrow) ===
   The rail expand button is gone; the ONLY way to reopen is the toggle at
   the leftmost of the content top bar (`#app:has(#sidebar.collapsed)
   #sidebar-toggle`), which mirrors the collapse button. */
.sidebar-rail-open {
    display: none;
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    border-radius: var(--radius-sm);
}
@media (min-width: 769px) {
    #sidebar { position: relative; }
    #sidebar.collapsed {
        width: 0;
        min-width: 0;
        border-right: none;
        overflow: hidden;
    }
    #sidebar.collapsed .sidebar-header,
    #sidebar.collapsed .sidebar-view {
        display: none;
    }
}

/* === Input window: height adjustable up to 3× default === */
#message-input {
    resize: vertical;
    min-height: 40px;
    max-height: 120px; /* 3 × min-height */
}

/* === 新任务态（body.mode-newtask）===
   底部完整输入窗(#input-area，含全部工具栏)整体上移至上中上部，作为整页
   唯一输入；欢迎语隐藏，避免重复输入/冗余标题。提交后 mode-newtask 移除，
   #input-area 回到底部原样式。 */
body.mode-newtask .welcome-msg { display: none; }
body.mode-newtask #input-area {
    position: absolute;
    top: 13%;
    left: 50%;
    transform: translateX(-50%);
    width: min(720px, calc(100% - 48px));
    z-index: 30;
    background: var(--bg);
    border-radius: var(--radius);
    box-shadow: 0 10px 34px rgba(0, 0, 0, 0.14);
    padding: 8px 16px calc(env(safe-area-inset-bottom, 0px) + 12px);
}

/* Stop button state (processing) — gray circle with white stop icon */
#send-btn.btn-stop {
    color: #fff;
    background: #9ca3af;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;}

/* Voice button active (recording) — gray circle, white mic icon */
#chat-toolbar #voice-btn.recording {
    color: #fff;
    background: #9ca3af;
    border-radius: 50%;
}

/* Chat toolbar buttons: brand-colored icons instead of gray lines */
#chat-toolbar .icon-btn {
    color: var(--accent);
}

/* === Task finished + generated-file download blocks === */
.task-done {
    align-self: center;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
    font-size: 12.5px;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

/* Task-start pill — opens the timeline right after the user's message. */
.msg.task-started {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 0;
    font-size: 12px;
    color: var(--text-muted);
    background: transparent;
    border: none;
    border-radius: 0;
    box-shadow: none;
}

/* Closing summary prefix（已结束， / 出现异常，） */
.summary-prefix {
    font-weight: 500;
    color: var(--text-secondary);
}

/* Compressed summary body: smaller font, dimmer color, clamped height —
   full text on hover (title attr). */
.summary-body {
    display: inline-block;
    max-width: 100%;
    vertical-align: top;
    font-size: 12px;
    color: var(--text-muted);
    opacity: .85;
    line-height: 1.5;
    max-height: 60px;
    overflow: hidden;
    word-break: break-word;
    white-space: pre-wrap;
}

.msg.task-error-summary .msg-bubble {
    border-color: var(--error, #e5484d);
    color: var(--error, #e5484d);
}

.msg.task-final-summary .msg-bubble {
    border-color: var(--accent, #5b8def);
}

/* Paperclip icon row appended after the closing summary — hidden file list. */
.files-icon-wrap {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
}
.files-icon-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: 999px;
    cursor: pointer;
    user-select: none;
}
.files-icon-btn:hover {
    border-color: var(--accent, #5b8def);
    color: var(--accent, #5b8def);
}

/* Popup modal listing the generated files. */
.files-popup-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.files-popup {
    width: min(520px, 92vw);
    max-height: 75vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}
.files-popup-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    background: var(--bg-sidebar-2);
    border-bottom: 1px solid var(--border);
}
.files-popup-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 15px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
}
.files-popup-close:hover { color: var(--text); background: var(--border); }
.files-popup-list {
    overflow-y: auto;
    padding: 8px 12px;
}
.files-popup-row {
    padding: 8px 4px;
    border-bottom: 1px solid var(--border);
}
.files-popup-row:last-child { border-bottom: none; }

.file-link {
    display: block;
    padding: 5px 0;
    font-size: 13px;
    font-family: var(--font-mono);
    color: var(--accent);
    text-decoration: underline;
    word-break: break-all;
    cursor: pointer;
}

.file-link:hover {
    opacity: 0.85;
}

/* === Markdown rendering (tables, images, headings, lists) === */
.msg-bubble table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
    font-size: 13px;
    display: block;
    overflow-x: auto;
}
.msg-bubble th, .msg-bubble td {
    border: 1px solid var(--border);
    padding: 6px 10px;
    text-align: left;
    white-space: normal;
}
.msg-bubble th { background: var(--bg-sidebar); font-weight: 600; }
/* === 正文排版规范 ===
   · 中文正文: PingFang SC / Noto Sans CJK SC, sans-serif, 无衬线
   · 加粗强调: 字重 600 (段首黑体式强调用 600/700)
   · 列表/标题/链接延续无衬线混排 */
.msg-bubble strong { font-weight: 600; }
.msg-bubble b { font-weight: 600; }
.msg-bubble h1, .msg-bubble h2, .msg-bubble h3, .msg-bubble h4 {
    font-family: var(--font);
    font-weight: 600;
    letter-spacing: -0.01em;
}
.msg-bubble h1 { font-size: 18px; }
.msg-bubble h2 { font-size: 16px; }
.msg-bubble h3 { font-size: 15px; }
.msg-bubble h4 { font-size: 14px; }
.msg-bubble p { margin: 4px 0; line-height: 1.7; }
.msg-bubble ul, .msg-bubble ol { margin: 4px 0; padding-left: 20px; }
.msg-bubble ul li, .msg-bubble ol li { margin: 2px 0; line-height: 1.65; }
.msg-bubble img { max-width: 100%; border-radius: var(--radius-sm); margin: 6px 0; border: 1px solid var(--border); }
.msg-bubble a { color: var(--accent); text-decoration: underline; }
.msg-bubble blockquote {
    margin: 6px 0;
    padding: 2px 12px;
    border-left: 3px solid var(--border-strong);
    color: var(--text-secondary);
    font-style: normal;
}
.msg-bubble hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 10px 0;
}
.file-img {
    display: block;
    max-width: 100%;
    border-radius: var(--radius-sm);
    margin: 6px 0;
    border: 1px solid var(--border);
    cursor: zoom-in;
}

/* === Workspace input (bottom toolbar, left of provider) === */




/* === Workspace picker (folder-name label + browse button) === */
.workspace-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    min-width: 0;
    flex-shrink: 1;
}

.workspace-label {
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    cursor: default;
}

/* === Server directory picker modal === */
.dir-nav {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.dir-nav input {
    flex: 1;
    min-width: 0;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-family: var(--font-mono);
    outline: none;
    box-sizing: border-box;
}

.dir-nav input:focus {
    border-color: var(--accent);
}

.dir-list {
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg);
}

.dir-item {
    padding: 7px 12px;
    cursor: pointer;
    font-size: 13px;
    font-family: var(--font-mono);
    border-bottom: 1px solid var(--border);
}

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

.dir-item:hover {
    background: var(--bg-sidebar);
}

/* Task sidebar: compact uniform-height blocks.
   Long task names / workspace paths are truncated instead of wrapping, so
   every task renders the same single-line shape. Full text via title
   tooltips set in renderTaskList. NOTE: avoid -webkit-line-clamp here — a
   flex item with display:-webkit-box collapses to min-content width in
   Chromium (a CJK name shows only ~2 chars). */
.task-item {
    min-width: 0;
}
.task-item-name {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.task-item-meta {
    min-width: 0;
    flex: 0 1 auto;
    max-width: 55%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

/* Selected item inside toolbar dropdown menus (provider / autonomy) */
.task-menu-item.selected {
    font-weight: 600;
    color: var(--accent, #2563eb);
    background: rgba(37, 99, 235, 0.06);
}
/* Check mark for the selected option — kept left-aligned and aligned across
   items by reserving the width only on selected items (text-align left). */
.task-menu-item.selected::before {
    content: '✓ ';
    font-weight: 700;
    color: var(--accent, #2563eb);
}

/* Toolbar dropdowns (provider / autonomy / workspace) open UPWARD because
   the toolbar sits at the bottom of the screen. */
.task-item-menu.drop-up .task-menu-dropdown {
    top: auto;
    bottom: calc(100% + 2px);
}

/* Nudge toolbar icon buttons 2px down (visual alignment) */
#chat-toolbar .icon-btn {
    transform: translateY(2px);
}

/* Build label at the far LEFT of the chat toolbar (version · build N).
   margin-right:auto pushes it left while the actions stay right. */
.build-label {
    margin-right: auto;
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
    user-select: none;
    padding: 2px 4px;
}

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

/* === run-block: dynamic collapsing execution tracker === */
.run-block {
    align-self: flex-start;
    max-width: 92%;
    margin: 2px 12px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-muted);
    user-select: none;
    animation: msgIn 0.15s ease;
}

.run-block .run-head {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: default;
}

.run-block.live .run-head-label {
    font-weight: 500;
    color: var(--text-secondary);
}

.run-head-spin {
    margin-left: 2px;
    font-size: 11px;
    opacity: 0.8;
    animation: spin 1s linear infinite;
    display: inline-block;
}

.run-body {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.run-reasoning {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 2px 0;
    color: var(--text-secondary);
    font-size: 12px;
    word-break: break-word;
}

.run-reasoning-icon {
    flex-shrink: 0;
    opacity: 0.8;
}

.run-reasoning-text {
    white-space: pre-wrap;
    max-height: 240px;
    overflow-y: auto;
}

/* per-round (iteration) timeline inside the run-block */
.run-iteration {
    border-left: 1px solid var(--border);
    padding-left: 10px;
    margin: 2px 0 6px;
}

.run-iter-head {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-weight: 500;
}

.run-iter-state {
    font-size: 10px;
    opacity: 0.7;
    animation: spin 1s linear infinite;
    display: inline-block;
}

/* Round spinner stopped once the round's tool finished (✓/✗ shown instead). */
.run-iter-state.stopped {
    animation: none;
}

.run-iter-body {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.run-think {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 2px 0;
    color: var(--text-secondary);
    font-size: 13px;
    word-break: break-word;
    min-width: 0;
}

.run-think-toggle {
    flex-shrink: 0;
    cursor: pointer;
    user-select: none;
    color: var(--accent, #5b8def);
    display: flex;
    align-items: center;
}

.run-think.collapsed .run-think-toggle .think-chev {
    transform: rotate(-90deg);
}

.run-think.collapsed .run-think-text {
    display: none;
}

.run-think.collapsed .run-think-icon {
    opacity: 0.5;
}

.run-think-icon {
    flex-shrink: 0;
    opacity: 0.8;
    color: var(--accent, #5b8def);
}

.run-think-label {
    flex-shrink: 0;
    color: var(--accent, #5b8def);
    font-weight: 500;
}

.run-think-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    word-break: break-word;
    max-height: 240px;
    overflow-y: auto;
}

.run-decision {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 2px 0;
    color: var(--text-secondary);
    font-size: 12px;
    word-break: break-word;
    min-width: 0;
}

.run-decision-icon {
    flex-shrink: 0;
    opacity: 0.8;
}

.run-decision-label {
    flex-shrink: 0;
    color: var(--success, #22c55e);
    font-weight: 500;
}

.run-decision-text {
    white-space: pre-wrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
}

.run-tool {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    max-width: 100%;
    min-width: 0;
}

.run-tool-summary {
    margin-left: 6px;
    font-size: 11px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 40%;
}

.run-tool.err {
    color: var(--error, #e5484d);
}

.run-tool.err .tool-line-name,
.run-tool.err .tool-line-key {
    color: var(--error, #e5484d);
}

/* LLM / knowledge-base retry notice inside a round's block */
.run-retry {
    padding: 2px 0;
    font-size: 12px;
    color: #b7791f;
}

.run-tool-summary.err {
    color: var(--error, #e5484d);
}

.run-reasoning.fade-out,
.run-tool.fade-out {
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

/* final (collapsed) state */
.run-block.final .run-head {
    cursor: pointer;
}

.run-block.final .run-head:hover {
    color: var(--text);
}

.run-head-chevron {
    font-size: 9px;
    transition: transform 0.2s;
    color: var(--text-muted);
}

.run-block.final.expanded .run-head-chevron {
    transform: rotate(90deg);
}

.run-block.final .run-body {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding-left: 12px;
    border-left: 1px solid var(--border);
    margin-left: 3px;
}

.run-block.final.collapsed .run-body {
    display: none;
}

.run-final-tool {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
    color: var(--text-secondary);
}

.run-final-summary {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 55%;
    color: var(--text-muted);
}

.run-final-reasoning {
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px dashed var(--border);
}

.run-final-reasoning-head {
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.run-final-reasoning-body {
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 160px;
    overflow-y: auto;
    color: var(--text-muted);
}

.run-final-plan {
    margin-top: 4px;
    color: var(--text-secondary);
}

/* task aborted alert */
.aborted-banner {
    align-self: flex-start;
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 92%;
    margin: 6px 12px;
    padding: 8px 12px;
    font-size: 12.5px;
    color: var(--error, #e5484d);
    background: var(--bg-chat);
    border: 1px solid var(--error, #e5484d);
    border-radius: var(--radius-sm);
}

/* === Sidebar user card (signed-in operator) === */
.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    background: var(--bg-sidebar);
    flex-shrink: 0;
    cursor: default;
}
.user-avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.user-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}
.user-name {
    font-size: 13px;
    color: var(--text);
    font-weight: 500;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-id {
    font-size: 11px;
    color: var(--text-muted);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}
.user-action-btn {
    padding: 5px !important;
    color: var(--text-secondary);
}
.user-action-btn:hover {
    color: var(--text);
    background: var(--bg-sidebar-2);
}

/* === Topbar action buttons (search / notify / copy) === */
.topbar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    margin-left: auto;
}
.topbar-action-btn {
    padding: 6px !important;
    color: var(--text-secondary);
}
.topbar-action-btn:hover {
    background: var(--bg-sidebar-2);
    color: var(--text);
}

/* === Input area access row ("+ 允许完全访问" 风格) === */
#input-access {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 6px;
    font-size: 12px;
    color: var(--text-secondary);
    flex-wrap: wrap;
}
#input-access .access-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    background: var(--bg-sidebar-2);
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    font-size: 12px;
}
#input-access .access-chip:hover {
    background: var(--accent-light);
    color: var(--text);
}
#input-access .access-chip.active {
    background: var(--accent-light);
    color: var(--accent);
}
#input-access .access-chip .access-icon {
    font-weight: 700;
    font-size: 13px;
    line-height: 1;
}

/* === Sidebar adjustments for dark theme === */
.sidebar {
    background: var(--bg-sidebar);
}
.sidebar-header {
    background: var(--bg-sidebar);
    border-bottom: 1px solid var(--border);
}
#task-list-items {
    background: var(--bg-sidebar);
}
.task-item {
    background: transparent;
    color: var(--text);
}
.task-item:hover {
    background: var(--bg-sidebar-2);
}
.task-item.active {
    background: var(--accent-light) !important;
    color: var(--text) !important;
}
.task-item-name {
    color: var(--text);
}
.tasks-toolbar .task-new-full {
    background: var(--success);
    color: #fff;
}
.empty-state {
    color: var(--text-muted);
}

/* === Top-bar toast + search highlight === */
.topbar-toast {
    position: fixed;
    top: 64px;
    left: 50%;
    transform: translateX(-50%) translateY(-8px);
    background: var(--bg-sidebar-2);
    color: var(--text);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 9999;
    max-width: 70vw;
    text-align: center;
}
.topbar-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}
.search-hl {
    background: rgba(251, 191, 36, 0.35);
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}

/* === History timeline replay (switched task) === */
.hist-time {
    flex-shrink: 0;
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-right: 6px;
    align-self: center;
}
.hist-time-row {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 2px;
}
.hist-system {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: var(--text-muted);
    padding: 2px 0;
}
.history-tool {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-secondary);
    padding: 2px 0;
}
.hist-tool-summary {
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 60%;
}

/* === 资料库浏览器 (kshare explorer) === */
.kb-explorer {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--bg-chat);
}
.kb-explorer.hidden { display: none; }
.kb-topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-sidebar);
    flex-wrap: wrap;
}
.kb-title { font-size: 15px; font-weight: 700; color: var(--text); }
.kb-stats { font-size: 12px; color: var(--text-muted); margin-left: 2px; }
.kb-search { margin-left: auto; min-width: 200px; flex: 0 1 320px; }
.kb-search input {
    width: 100%;
    padding: 7px 12px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: var(--bg-input);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
}
.kb-search input:focus { border-color: var(--accent); }
.kb-body {
    flex: 1;
    display: flex;
    min-height: 0;
    gap: 0;
}
.kb-side {
    width: 220px;
    flex: none;
    overflow-y: auto;
    padding: 12px 8px;
    border-right: 1px solid var(--border);
    background: var(--bg-sidebar);
}
.kb-side-head {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-muted);
    padding: 2px 10px 6px;
    text-transform: none;
}
.kb-tree { display: flex; flex-direction: column; gap: 1px; }
.kb-cat, .kb-dom {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    background: none;
    border: none;
    text-align: left;
    width: 100%;
    font-family: var(--font);
}
.kb-cat:hover, .kb-dom:hover { background: var(--bg-sidebar-2); }
.kb-cat.active, .kb-dom.active { background: var(--bg-sidebar-2); font-weight: 600; }
.kb-cat .kb-cat-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-cat .kb-cat-count { font-size: 11px; color: var(--text-muted); }
.kb-cat.depth-1 { padding-left: 22px; }
.kb-cat.depth-2 { padding-left: 34px; font-size: 12.5px; }
.kb-main { flex: 1; overflow-y: auto; padding: 14px 18px; }
.kb-loading { color: var(--text-muted); font-size: 13px; padding: 12px; }
.kb-doc-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    background: var(--bg-agent-msg);
    cursor: pointer;
    transition: border-color .15s;
}
.kb-doc-item:hover { border-color: var(--accent); }
.kb-doc-item.selected { border-color: var(--accent); background: var(--accent-light); }
.kb-doc-body { flex: 1; min-width: 0; }
.kb-doc-title { font-size: 13.5px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-doc-meta { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-doc-snippet { font-size: 12px; color: var(--text-secondary); margin-top: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.kb-empty { color: var(--text-muted); font-size: 13px; padding: 20px; text-align: center; }
.kb-pager { display: flex; align-items: center; justify-content: center; gap: 12px; padding: 10px 0 4px; font-size: 12px; color: var(--text-muted); }
.kb-pager button { background: var(--bg-sidebar-2); border: 1px solid var(--border); color: var(--text); border-radius: var(--radius-sm); padding: 4px 12px; cursor: pointer; font-family: var(--font); }
.kb-pager button:disabled { opacity: .4; cursor: default; }

/* 详情抽屉 */
.kb-drawer-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40;
}
.kb-drawer {
    position: fixed; top: 0; right: 0; bottom: 0; width: min(520px, 94%);
    background: var(--bg-sidebar); z-index: 41; box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column;
}
.kb-drawer-head {
    display: flex; align-items: center; gap: 10px; padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}
.kb-drawer-title { flex: 1; font-size: 15px; font-weight: 700; color: var(--text); word-break: break-all; }
.kb-drawer-body { flex: 1; overflow-y: auto; padding: 14px 16px; font-size: 13px; color: var(--text); line-height: 1.7; }
.kb-drawer-body .kb-doc-sec { margin-top: 12px; }
.kb-drawer-body .kb-sec-label { font-size: 11.5px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.kb-drawer-content { white-space: pre-wrap; word-break: break-word; color: var(--text-secondary); font-size: 12.5px; max-height: 340px; overflow-y: auto; background: var(--code-bg-block); border-radius: var(--radius-sm); padding: 10px; }
.kb-drawer-foot {
    display: flex; align-items: center; gap: 8px; padding: 12px 16px;
    border-top: 1px solid var(--border); background: var(--bg-sidebar);
}
.kb-cat-chip {
    display: inline-block; background: var(--accent-light); color: var(--accent);
    border-radius: var(--radius-pill); padding: 1px 9px; font-size: 11.5px; margin: 2px 4px 2px 0;
}
.kb-config {
    display: flex; align-items: center; gap: 8px;
    padding: 8px 18px; border-bottom: 1px solid var(--border);
    background: var(--bg-tool); font-size: 13px; color: var(--text-secondary);
    flex-wrap: wrap;
}
.kb-config.hidden { display: none; }
.kb-config input { flex: 1; min-width: 240px; padding: 6px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--bg-input); color: var(--text); font-family: var(--font); font-size: 13px; }
.kb-config .btn-primary, .kb-config .btn-secondary { padding: 5px 14px; }

/* === 文档化排版 + 页内折叠（9/6 覆盖）===
   任务过程像文档平铺：去掉卡片/时间线竖线与横线，弱化块感。
   折叠/展开均为页内直接显隐（非 hover/tips）。 */
.run-block .run-head { gap: 5px; }
.run-block.final .run-head-label { font-weight: 600; color: var(--text); }

/* 去掉 run-body/iteration 的竖线边框，纯文档留白分隔 */
.run-block.final .run-body,
.run-body {
    gap: 6px;
    padding-left: 0;
    border-left: none;
    margin-left: 0;
}
.run-iteration {
    border-left: none;
    padding-left: 2px;
    margin: 4px 0 8px;
}
.run-think, .run-decision, .run-reasoning {
    padding: 1px 0;
    align-items: flex-start;
}
.run-think-text, .run-decision-text, .run-reasoning-text {
    flex: 1;
    line-height: 1.7;
}
.run-decision-text {
    -webkit-line-clamp: none;
    overflow: visible;
}
.run-final-reasoning { border-top: none; padding-top: 2px; }
.run-final-plan { border: none; }

/* 工具行：头部一行可点，参数/结果默认折叠在页内显隐 */
.run-tool { display: flex; flex-direction: column; align-items: stretch; padding: 1px 0; }
.run-tool-head {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    max-width: 100%;
    flex-wrap: wrap;
}
.run-tool-head:hover { color: var(--text); }
/* 工具行标题即内容本身（命令/结果摘要）：单行省略，不撑破布局 */
.run-tool-head .tool-line-name {
    min-width: 0;
    flex: 0 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tool-line-chev { font-size: 8px; color: var(--text-muted); transition: transform .15s; flex: none; }
.run-tool.expanded > .run-tool-head .tool-line-chev { transform: rotate(90deg); }
.run-tool-detail { display: none; margin: 2px 0 4px 22px; }
.run-tool.expanded .run-tool-detail { display: flex; flex-direction: column; gap: 6px; }

/* 工具子行（方案X）：命令/输出 单层级 run-tool-head，点击展开详情 */
.tool-sub { display: flex; flex-direction: column; }
.tool-sub > .run-tool-head { padding-left: 22px; }
.tool-sub .run-tool-detail { display: none; margin: 2px 0 4px 22px; }
.tool-sub.expanded .run-tool-detail { display: flex; flex-direction: column; gap: 6px; }
.tool-detail-label { font-size: 11px; color: var(--text-muted); display: block; margin-bottom: 2px; }
.tool-args, .tool-out {
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-all;
    background: var(--code-bg-block);
    border-radius: 6px;
    padding: 8px 10px;
    margin: 0;
    max-height: 260px;
    overflow-y: auto;
    color: var(--text);
}
.run-tool.err .tool-out { color: var(--error); }

.history-tool { max-width: none; }
.history-tool .run-tool-summary { max-width: 60%; }
.hist-tool-summary.err { color: var(--error); }

/* run-tool-summary 在文档流中作为 tool 行尾注 */
.run-tool-summary { margin-left: 2px; color: var(--text-muted); }
/* 工具名后的结果单行（实时）：压缩成一行，超长省略号，点击展开全文 */
.run-tool-head .run-tool-summary {
    flex: 1 1 auto;
    min-width: 0;
    margin-left: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    max-width: none;
}
.run-tool-head .run-tool-summary.line-expanded {
    white-space: pre-wrap;
    overflow: visible;
    text-overflow: clip;
}

/* === 气泡对话（带头像，9/6 09:43）===
   user 消息：右侧 + 用户头像（预置选择）；agent 消息：左侧 MyClaw 图标 + 灰底气泡；
   消息正文字号 16px（原 14 增大）。run-block 内思考/工具/结果仍为文档平铺折叠。 */
.msg {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 100%;
}
.msg.user { flex-direction: row-reverse; }
.msg.user .msg-bubble { align-self: flex-end; }

.msg-avatar {
    flex: none;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    overflow: hidden;
    margin-top: 2px;
    user-select: none;
    background: var(--accent);
}
.msg-avatar.avatar-agent {
    background: transparent;
}
.msg.user .msg-avatar { order: -1; }

.msg-bubble { font-size: 16px; line-height: 1.7; }
.msg.agent .msg-bubble {
    background: var(--bg-agent-msg);
    border: 1px solid var(--border);
    box-shadow: none;
    padding: 10px 14px;
    border-bottom-left-radius: 2px;
    border-radius: var(--radius);
}
.task-final-summary .msg-bubble,
.task-error-summary .msg-bubble {
    background: var(--bg-agent-msg);
    border: 1px solid var(--border);
    padding: 10px 14px;
}
.msg.agent .msg-bubble p { margin: 4px 0; }

/* 设置弹窗 - 头像选择 */
.settings-section { margin-bottom: 18px; }
.settings-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-bottom: 10px; }
.avatar-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.avatar-opt {
    background: none; border: none; cursor: pointer; padding: 4px;
    border-radius: 50%; outline: none;
}
.avatar-opt:hover { background: var(--bg-sidebar-2); }
.avatar-opt.selected { box-shadow: 0 0 0 2px var(--accent); background: var(--accent-light); border-radius: 50%; }
.avatar-preview { width: 42px; height: 42px; font-size: 20px; margin-top: 0; }
.settings-hint { font-size: 12px; color: var(--text-muted); margin-top: 10px; }

/* === agent-turn 单组长回复（9/6 10:20 模型重构）===
   一次用户提问 → 一条 MyClaw 长消息。头像只在组首一次；
   气泡内：状态首行 → 步骤文档流(思考/工具/执行说明) → 结束行 → 正文。
   无 run-head / history-run 折叠分隔条；每行文字前头均带时间戳。 */
.msg.agent-turn {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-width: 100%;
    min-width: 0;
    align-self: flex-start;
}
/* 图标独占行：MyClaw logo + 「开始执行 XX 任务…」 */
.turn-head-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.msg.agent-turn .msg-avatar { margin-top: 0; }
.turn-bubble {
    flex: 1;
    min-width: 0;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    gap: 7px;
    background: transparent;      /* 视觉上无框：文档平铺 */
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 0 0 0 44px;          /* 与图标行对齐（头像 34 + gap 8） */
}
.msg.agent-turn .msg-bubble {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
}
.turn-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13.5px;
    color: var(--text-secondary);
    padding: 0 0 2px;
}
.turn-status .hist-time { align-self: center; margin-left: 6px; margin-right: 0; }
.turn-status-icon { flex: none; }
.turn-status-text {
    font-weight: 600;
    color: var(--text);
}
.turn-status-spin {
    margin-left: 2px;
    font-size: 11px;
    opacity: .75;
    display: inline-block;
    animation: spin 1s linear infinite;
}
/* 顶栏"执行中"转圈动画：任务未完成时出现，停止后消失 */
.exec-spinner {
    display: none;
    align-items: center;
    margin-left: 8px;
    color: var(--accent);
}
.exec-spinner.active { display: inline-flex; }
.exec-spinner .spin { animation: spin 1s linear infinite; }
/* 任务执行中：文字最底部的"MyClaw 正在处理…"转圈指示 */
.busy-indicator {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 4px 2px 2px;
    min-width: 0;
    color: var(--text-muted);
    font-size: 13px;
    align-self: flex-start;
}
.busy-spin {
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    display: inline-block;
    animation: spin 0.9s linear infinite;
    flex: none;
}
.busy-text { color: var(--text-secondary); }
.turn-flow {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}
/* 步骤行文字前头嵌入时间（hist-time 已由 JS 放置于每行 HTML 最前） */
.turn-flow .run-think,
.turn-flow .run-decision,
.turn-flow .run-plan-head,
.turn-flow .run-tool-head,
.turn-flow .run-retry {
    font-size: 13px;
    color: var(--text-secondary);
}
.turn-flow .hist-time { align-self: center; }

/* 任务拆分（plan 即时行） */
.run-plan { display: flex; flex-direction: column; gap: 3px; padding: 1px 0 3px; }
.run-plan-head { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); font-weight: 500; }
.run-plan-icon { flex: none; }
.run-plan-label { color: var(--text-secondary); }
.run-plan-body { padding-left: 30px; display: flex; flex-direction: column; gap: 2px; }
.run-plan-step { font-size: 13px; color: var(--text-secondary); line-height: 1.6; }

/* 结尾行：任务已结束/失败/停止（无横线，仅文字加重） */
.turn-tail { display: flex; flex-direction: column; gap: 7px; }
.turn-end {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13.5px;
    padding: 3px 0 0;
}
.turn-end-text { font-weight: 600; }
.turn-end.done .turn-end-text { color: var(--success); }
.turn-end.err .turn-end-text { color: var(--error); }
.turn-end.stopped .turn-end-text { color: var(--warning); }
.turn-end .hist-time { align-self: center; }

/* 最终正文 / 失败原因：正常字号 16px 文档段落 */
.turn-answer {
    display: flex;
    flex-direction: column;
}
/* 最终正文首句内嵌时间戳（小字 mono 灰） */
.turn-answer-time {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-bottom: 2px;
}
.turn-answer .msg-bubble {
    font-size: 16px;
    line-height: 1.7;
    white-space: normal;
}
.turn-answer.streaming .msg-bubble { font-size: 16px; }
.turn-answer-err .msg-bubble {
    color: var(--error);
    font-size: 14px;
}
.turn-answer-err .msg-bubble p,
.turn-answer-err .msg-bubble li { color: var(--error); }

/* 产出文件行 */
.turn-files {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
}
.turn-files .files-icon-btn {
    background: var(--accent-light);
    border: none;
    color: var(--accent);
    border-radius: var(--radius-pill);
    padding: 3px 12px;
    font-size: 12.5px;
    cursor: pointer;
    font-family: var(--font);
}
.turn-files .hist-time { align-self: center; }

/* 历史长回复组与实时同构 */
.msg.agent-turn.hist-turn .turn-status { display: none; }

/* === 行内时间戳（9/6 10:30 微调）===
   hist-time 作为"行内小尾巴"跟在工具名 / 结束行文字之后，与正文同行，
   但字号更小、颜色更浅（mono 灰）。思考/执行说明等多行文本行仍在行首。 */
.turn-flow .run-tool-head .hist-time,
.turn-end .hist-time {
    margin-left: 6px;
    margin-right: 0;
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    align-self: center;
    flex-shrink: 0;
}

/* 最后输出（模型未给出最终总结时，直接回显最后一步结果） */
.turn-lastout {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.turn-lastout-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: var(--text-muted);
}
.turn-lastout-label .hist-time { margin-left: 6px; margin-right: 0; }
.turn-lastout-title { font-weight: 600; color: var(--text-secondary); }
.turn-lastout-text {
    font-family: var(--font-mono);
    font-size: 12.5px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    color: var(--text-secondary);
    max-height: 320px;
    overflow-y: auto;
}

/* 历史长回复组与实时同构（图标行同样显示"开始执行 XX 任务…"） */
.msg.agent-turn.hist-turn .turn-status { display: flex; }
.turn-lastout.collapsed .turn-lastout-text { display: none; }
.turn-lastout-chev { font-size: 8px; color: var(--text-muted); flex: none; }
.turn-lastout-label { cursor: pointer; }
.turn-lastout-label:hover .turn-lastout-title { color: var(--text); }

/* === WorkBuddy 式步骤块（9/6 10:50）===
   思考 = 「深度思考 ∨」标题 + 文章排版内容（可折叠）；
   工具 = 标题行 + 概括说明(常显正文) + 折叠的 具体命令/原始输出；
   结果概括行正文式常显。 */
.run-think { display: flex; flex-direction: column; gap: 3px; padding: 1px 0; }
.run-think-head {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    user-select: none;
}
.run-think-head:hover { color: var(--text); }
.run-think-toggle { display: flex; align-items: center; color: var(--text-muted); }
.run-think-toggle .think-chev { transition: transform .15s; }
.run-think.collapsed .run-think-toggle .think-chev { transform: rotate(-90deg); }
.run-think.collapsed .run-think-head .hist-time { display: none; }
.run-think-text {
    font-size: 15px;
    line-height: 1.75;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    padding-left: 24px;
}
.run-think.collapsed .run-think-text { display: none; }

/* 工具概括说明 / 结果概括：正文式常显 */
.run-tool { display: flex; flex-direction: column; gap: 3px; }
.run-tool-desc, .run-tool-result {
    font-size: 15px;
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    padding-left: 24px;
    cursor: default;
}
.run-tool-result { color: var(--text); }
.run-tool-result.err { color: var(--error); }
.run-tool-detail { margin-left: 24px; }

/* 历史/实时通用的 hist-system 摘要块（系统图标 + 正文 16px） */
.hist-system-msg {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 100%;
    align-self: flex-start;
}
.hist-system-msg .msg-bubble {
    background: transparent;
    border: none;
    box-shadow: none;
    padding: 0;
    font-size: 16px;
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-wrap;
}
.hist-system { display: none; }

/* === 主流程阶段骨架（9/6 11:20）===
   第一层：接收任务 → 思考与拆解 → 步骤 1..N → 最终结果
   第二层：阶段 body 内为思考(大模型返回)/工具/结果/系统处理，可折叠 */
.proc-stage {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 2px 0;
    min-width: 0;
}
.proc-stage-head {
    display: flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    user-select: none;
}
.proc-stage-head:hover { color: var(--accent); }
.proc-stage-chev { font-size: 9px; color: var(--text-muted); flex: none; }
.proc-stage-icon { flex: none; font-size: 13px; }
.proc-stage-label { flex: none; }
.proc-stage-state {
    font-size: 12px;
    color: var(--text-muted);
    flex: none;
}
.proc-stage-state.ok { color: var(--success); }
.proc-stage-state.err { color: var(--error); }
/* 阶段头行内嵌时间戳（与步骤行同构：小字 mono 灰，推到最右） */
.proc-stage-head .hist-time {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-weight: 400;
    flex-shrink: 0;
}
.proc-stage-body {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding-left: 20px;
    border-left: 2px solid var(--border);
    margin-left: 4px;
    padding-bottom: 2px;
    min-width: 0;
}
.proc-stage.collapsed .proc-stage-body { display: none; }
.stage-think .proc-stage-head { color: var(--text); }

/* === 执行中：动画 + 内部内容展开 === */
/* 执行中的阶段：左侧进度线高亮 + 图标呼吸脉冲（提示正在运行） */
.proc-stage.executing > .proc-stage-body { border-left-color: var(--accent); }
.proc-stage.executing > .proc-stage-head .proc-stage-icon {
    color: var(--accent);
    animation: iconPulse 1.6s ease-in-out infinite;
}
@keyframes iconPulse {
    0%, 100% { opacity: .55; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.15); }
}
/* 执行中：内部思考 / 工具命令输出 / 结果 实时展开，便于观看进度 */
.proc-stage.executing .run-think .run-think-text { display: block; }
.proc-stage.executing .run-think .run-think-toggle .think-chev { transform: rotate(0deg); }
.proc-stage.executing .tool-sub .run-tool-detail {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.proc-stage.executing .tool-sub .tool-line-chev { transform: rotate(90deg); }
/* 思考流式输出末尾闪烁光标（执行中） */
.proc-stage.executing .run-think.streaming .run-think-text::after {
    content: '▍';
    color: var(--accent);
    animation: blink 1s step-end infinite;
}
/* 运行中状态标记：旋转的 ⟳ 作为加载动画 */
.proc-stage-state.running,
.tool-line-state.running {
    display: inline-block;
    color: var(--accent);
    animation: spin 1s linear infinite;
}
/* 运行中的工具行头部轻微呼吸，提示正在执行 */
.run-tool.running > .run-tool-head {
    animation: headBreath 1.6s ease-in-out infinite;
}
@keyframes headBreath {
    0%, 100% { opacity: .72; }
    50% { opacity: 1; }
}

/* 系统处理行（上下文压缩 / 记录文档 / memory） */
.proc-sys {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    padding: 1px 0;
    min-width: 0;
}
.proc-sys-icon { flex: none; font-size: 12px; opacity: .85; }
.proc-sys-text { color: var(--text-secondary); }
.proc-sys .hist-time { margin-left: 6px; margin-right: 0; }

/* 第一层「最终结果」阶段标签 */
.turn-end-tag {
    flex: none;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-sidebar-2);
    border-radius: var(--radius-pill);
    padding: 1px 9px;
}

/* === 单行紧凑 + 展开（9/6 11:50）=== */
/* 阶段标题行内的工具概括：单行截断，换行符已被 JS 替换为空格 */
.proc-stage-desc {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 400;
    color: var(--text-secondary);
}
.proc-stage-head { flex-wrap: nowrap; }
.proc-stage-label { flex: none; }
.proc-stage-state { margin-left: auto; }
.proc-stage-desc:empty { display: none; }

/* 结果概括/描述：默认单行，点击展开全文 */
.run-tool-result {
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: pointer;
    padding-left: 24px;
    max-width: 100%;
}
.run-tool-result.err { color: var(--error); }
.run-tool-result.line-expanded {
    white-space: pre-wrap;
    word-break: break-word;
    overflow: visible;
}

/* 折叠块：默认只显示标签行（一行），点击展开 pre 全文 */
.fold-block { display: flex; flex-direction: column; gap: 3px; }
.fold-block .tool-detail-label {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
}
.fold-block .tool-detail-label:hover { color: var(--text-secondary); }
.fold-chev { font-size: 8px; }
.fold-block > pre { display: none; }
.fold-block.expanded > pre { display: block; }

/* 历史对话摘要行：与"接收任务"同一视觉层级，独立系统图标(📝) */
.hist-digest {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 2px 0;
}
.hist-digest-head {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13.5px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}
.hist-digest-head:hover { color: var(--text); }
.hist-digest-icon { flex: none; }
.hist-digest-title { font-weight: 600; color: var(--text); flex: none; }
.hist-digest-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
}
.hist-digest-head .hist-time { margin-left: 6px; margin-right: 0; flex: none; }
.hist-digest-chev { font-size: 8px; color: var(--text-muted); flex: none; }
.hist-digest-body {
    display: none;
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 320px;
    overflow-y: auto;
    padding-left: 26px;
}
.hist-digest:not(.collapsed) .hist-digest-body { display: block; }

/* === 9/6 12:30 微调：去步骤N / 描述大1号 / 用户时间行内 / 摘要独立层 === */
.proc-stage-label:empty { display: none; }
.proc-stage-state:empty { display: none; }
/* 步骤标题行：去除"步骤 N"后仅留概括描述，字号大 2 号(13px→16px) */
.stage-step .proc-stage-desc {
    font-size: 16px;
    font-weight: 500;
    color: var(--text);
}
/* 第一层摘要状态行：turn-status 样式 + 新图标 🗂️（替代原 proc-stage 📜） */
.hist-digest-status {
    display: flex;
    cursor: pointer;
    user-select: none;
    min-width: 0;
}
.hist-digest-status .turn-status-icon { font-size: 14px; line-height: 1; }
.hist-digest-status:hover .turn-status-text { color: var(--text); }
.hist-digest-status .hist-digest-chev {
    font-size: 8px;
    color: var(--text-muted);
    flex: none;
    margin-left: 2px;
}
.hist-digest-full {
    font-size: 13px;
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
    padding-left: 24px;
}
/* 用户输入：时间嵌入内容行首(小字灰, 行内) */
.inline-time {
    display: inline;
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-right: 6px;
}
