/* ═══════════════════════════════════════════════════════════════
   Metona Ollama — Warm Light Theme
   暖色调 · 圆润柔和 · 珊瑚橙主色 · 奶白背景
   ═══════════════════════════════════════════════════════════════ */

/* ── CSS 变量 ── */
:root {
    /* 暖色调色板 */
    --bg-solid: #FAF7F2;
    --bg-card: #FFFFFF;
    --bg-card-hover: #FFF8F0;
    --bg-layer: #F5F0E8;
    --bg-layer-alt: #FBF6EE;
    --bg-smoke: rgba(0, 0, 0, 0.12);
    --bg-mica: rgba(250, 247, 242, 0.85);
    --bg-acrylic: rgba(250, 247, 242, 0.9);

    --border-subtle: rgba(0, 0, 0, 0.06);
    --border-default: rgba(0, 0, 0, 0.1);
    --border-strong: rgba(0, 0, 0, 0.15);
    --border-focus: #E8734A;

    --text-primary: #2D2016;
    --text-secondary: #7A6E5D;
    --text-tertiary: #B0A594;
    --text-disabled: #CCC5B8;

    /* 珊瑚橙主色 */
    --accent: #E8734A;
    --accent-hover: #D4623A;
    --accent-subtle: rgba(232, 115, 74, 0.08);
    --accent-subtle-hover: rgba(232, 115, 74, 0.14);
    --primary: #E8734A;
    --primary-bg: rgba(232, 115, 74, 0.08);
    --bg-hover: #FFF8F0;

    --critical: #D94F5C;
    --critical-bg: rgba(217, 79, 92, 0.08);
    --success: #4AAE6B;
    --success-bg: rgba(74, 174, 107, 0.08);
    --caution: #D4A03C;
    --caution-bg: rgba(212, 160, 60, 0.08);

    /* 圆角 — 温暖圆润 */
    --radius-control: 8px;
    --radius-sm: 10px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    /* 阴影 — 柔和温暖 */
    --shadow-flyout: 0 4px 24px rgba(45, 32, 22, 0.08);
    --shadow-dialog: 0 12px 48px rgba(45, 32, 22, 0.12);
    --shadow-tooltip: 0 2px 12px rgba(45, 32, 22, 0.1);
    --shadow-card: 0 1px 4px rgba(45, 32, 22, 0.04), 0 4px 16px rgba(45, 32, 22, 0.06);

    /* 字体 */
    --font: 'Inter', 'SF Pro Display', -apple-system, 'PingFang SC', 'Noto Sans SC', system-ui, sans-serif;
    --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;

    --transition: 200ms cubic-bezier(0.25, 0.1, 0.25, 1);
    --transition-fast: 100ms cubic-bezier(0.25, 0.1, 0.25, 1);
}

/* ── 全局重置 ── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
    background: var(--bg-solid);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    display: flex;
    flex-direction: row;
    height: 100vh;
    position: relative;
}

/* ═══ 日志面板 ═══ */
.log-panel {
    width: 300px;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border-right: 1px solid var(--border-subtle);
    z-index: 5;
    flex-shrink: 0;
}

.log-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.log-panel-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.log-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 6px 0;
    font-family: var(--font-mono);
    font-size: 11.5px;
    line-height: 1.5;
}

.log-panel-body::-webkit-scrollbar { width: 6px; }
.log-panel-body::-webkit-scrollbar-track { background: transparent; }
.log-panel-body::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 3px; }

.log-entry {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    padding: 3px 10px;
    gap: 6px;
    border-bottom: 1px solid rgba(0,0,0,0.02);
}

.log-entry:hover {
    background: rgba(0,0,0,0.02);
}

.log-time {
    color: var(--text-tertiary);
    font-size: 10px;
    flex-shrink: 0;
    min-width: 56px;
}

.log-icon {
    flex-shrink: 0;
    font-size: 11px;
}

.log-msg {
    flex: 1;
    min-width: 0;
    word-break: break-all;
}

.log-detail {
    width: 100%;
    margin: 2px 0 0;
    padding: 4px 8px;
    background: var(--bg-layer);
    border-radius: 6px;
    font-size: 10.5px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 120px;
    overflow-y: auto;
    color: var(--text-secondary);
}

/* 日志级别颜色 */
.log-info .log-msg { color: var(--text-secondary); }
.log-success .log-msg { color: var(--success); }
.log-warn .log-msg { color: var(--caution); }
.log-error .log-msg { color: var(--critical); }
.log-debug .log-msg { color: var(--text-tertiary); }
.log-tool .log-msg { color: var(--caution); }
.log-think .log-msg { color: #9B7ED8; }
.log-stream .log-msg { color: var(--accent); }

/* 主内容区 */
.main-wrap {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
    height: 100vh;
}

/* ═══ 顶部导航 ═══ */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: var(--bg-mica);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    z-index: 50;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    flex: 1;
}

.logo {
    font-size: 22px;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    object-fit: contain;
    vertical-align: middle;
}

.app-title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    letter-spacing: -0.3px;
}

.app-version {
    font-size: 10px;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-subtle);
    border: 1px solid rgba(232, 115, 74, 0.15);
    border-radius: 20px;
    padding: 2px 10px;
    white-space: nowrap;
    user-select: none;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* ── 连接状态 ── */
.conn-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: var(--radius-control);
    font-size: 12px;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: var(--transition);
}

.status-label {
    white-space: nowrap;
}

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

.conn-status.disconnected .status-dot {
    background: var(--critical);
}

.conn-status.pending .status-dot {
    background: var(--caution);
    animation: blink 1s ease-in-out infinite;
}

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

/* ── 图标按钮 ── */
.icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    border-radius: var(--radius-control);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.icon-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-control);
    background: currentColor;
    opacity: 0;
    transition: var(--transition);
}

.icon-btn:hover::before {
    opacity: 0.08;
}

.icon-btn:active::before {
    opacity: 0.05;
}

.icon-btn:hover {
    color: var(--text-primary);
}

.icon-btn:active {
    transform: scale(0.96);
}

.icon-btn svg {
    width: 18px;
    height: 18px;
    position: relative;
    z-index: 1;
}

.icon-btn.disabled,
.icon-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

#btnAttachImg.disabled {
    pointer-events: auto;
}

#btnAttachImg.disabled:hover {
    opacity: 0.3;
    background: var(--critical-bg);
}

#btnAttachVideo.disabled {
    pointer-events: auto;
}

#btnAttachVideo.disabled:hover {
    opacity: 0.3;
    background: var(--critical-bg);
}

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

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

.icon-btn.danger:hover {
    color: var(--critical);
}

.help-btn {
    margin-left: 2px;
    opacity: 0.4;
}

.help-btn:hover {
    opacity: 1;
}


/* ═══ 模型选择栏 ═══ */
.model-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 20px;
    background: var(--bg-layer-alt);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    z-index: 40;
    position: relative;
}

.model-bar-icon {
    width: 28px;
    height: 28px;
    border-radius: var(--radius-control);
    background: var(--accent-subtle);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.model-bar-icon svg {
    width: 14px;
    height: 14px;
    color: var(--accent);
}

.model-select-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
}

.model-select {
    width: 100%;
    padding: 7px 32px 7px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-control);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font);
    outline: none;
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    -webkit-appearance: none;
}

.model-select:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(232, 115, 74, 0.1);
}

.model-select:hover {
    border-color: var(--border-strong);
}

.model-select option {
    background: var(--bg-card);
    color: var(--text-primary);
}

.model-select-arrow {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
    color: var(--text-tertiary);
}

.model-select-arrow svg {
    width: 14px;
    height: 14px;
}

.model-badges {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.model-badge {
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    padding: 3px 10px;
    border-radius: 20px;
    border: 1px solid;
}

.think-badge {
    color: #9B7ED8;
    background: rgba(155, 126, 216, 0.08);
    border-color: rgba(155, 126, 216, 0.15);
}

.vision-badge {
    color: var(--success);
    background: var(--success-bg);
    border-color: rgba(74, 174, 107, 0.15);
}

.tools-badge {
    color: var(--caution);
    background: var(--caution-bg);
    border-color: rgba(212, 160, 60, 0.15);
}

/* ── 温度滑块 ── */
.temp-slider {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    border-radius: 2px;
    background: var(--bg-layer);
    outline: none;
    margin: 8px 0;
}

.temp-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(232, 115, 74, 0.3);
    transition: box-shadow var(--transition);
}

.temp-slider::-webkit-slider-thumb:hover {
    box-shadow: 0 2px 12px rgba(232, 115, 74, 0.45);
}

.temp-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 8px rgba(232, 115, 74, 0.3);
}

.modal-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
}

/* ── Think 按钮 ── */
.think-toggle {
    display: flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
    user-select: none;
}

.think-toggle input { display: none; }

.think-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-control);
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    color: var(--text-tertiary);
}

.think-btn svg {
    width: 18px;
    height: 18px;
}

.think-toggle:not(.unavailable):hover .think-btn {
    border-color: var(--border-strong);
    color: var(--text-secondary);
}

.think-toggle input:checked + .think-btn {
    background: rgba(155, 126, 216, 0.1);
    border-color: #9B7ED8;
    color: #9B7ED8;
    box-shadow: 0 0 16px rgba(155, 126, 216, 0.2);
}

.think-toggle input:checked + .think-btn:hover {
    background: rgba(155, 126, 216, 0.15);
    box-shadow: 0 0 20px rgba(155, 126, 216, 0.3);
}

.think-toggle.unavailable .think-btn {
    opacity: 0.3;
    cursor: not-allowed;
}

.think-toggle.unavailable:hover .think-btn {
    opacity: 0.25;
    background: var(--critical-bg);
}

/* ── Plan 按钮 ── */
.plan-toggle {
    display: flex;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
    user-select: none;
}

.plan-toggle input { display: none; }

.plan-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-control);
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    color: var(--text-tertiary);
}

.plan-btn svg {
    width: 18px;
    height: 18px;
}

.plan-toggle:hover .plan-btn {
    border-color: var(--border-strong);
    color: var(--text-secondary);
}

.plan-toggle input:checked + .plan-btn {
    background: rgba(71, 132, 143, 0.1);
    border-color: #47848F;
    color: #47848F;
    box-shadow: 0 0 16px rgba(71, 132, 143, 0.2);
}

.plan-toggle input:checked + .plan-btn:hover {
    background: rgba(71, 132, 143, 0.15);
    box-shadow: 0 0 20px rgba(71, 132, 143, 0.3);
}

/* ── 开关控件 ── */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.toggle-label input { display: none; }

.toggle-slider {
    position: relative;
    width: 40px;
    height: 22px;
    background: var(--bg-layer);
    border: 1px solid var(--border-default);
    border-radius: 11px;
    transition: var(--transition);
}

.toggle-slider::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.toggle-label input:checked + .toggle-slider {
    background: var(--accent);
    border-color: var(--accent);
}

.toggle-label input:checked + .toggle-slider::after {
    transform: translateX(18px);
}

/* ═══ 聊天区域 ═══ */
.chat-area {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    scroll-behavior: smooth;
}

.chat-area::-webkit-scrollbar {
    width: 6px;
}

.chat-area::-webkit-scrollbar-track {
    background: transparent;
}

.chat-area::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 3px;
}

.chat-area::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

/* ── 回到底部按钮 ── */
.scroll-to-bottom {
    position: sticky;
    bottom: 16px;
    float: right;
    margin-right: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 16px;
    border: 1px solid var(--border-default);
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    font-size: 12px;
    font-family: var(--font);
    cursor: pointer;
    z-index: 5;
    box-shadow: var(--shadow-card);
    transition: var(--transition);
    animation: fadeSlideUp 200ms ease;
}

.scroll-to-bottom:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-strong);
    color: var(--text-primary);
    box-shadow: var(--shadow-flyout);
}

.scroll-to-bottom:active {
    transform: scale(0.97);
}

.scroll-to-bottom svg {
    width: 14px;
    height: 14px;
}

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

/* ── 空状态 ── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 14px;
    color: var(--text-tertiary);
}

.empty-icon svg {
    width: 80px;
    height: 80px;
    opacity: 0.25;
    color: var(--accent);
}

.empty-state h2 {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.empty-state p {
    font-size: 14px;
    color: var(--text-tertiary);
}

/* ── 消息气泡 ── */
.messages {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: 780px;
    margin: 0 auto;
}

.message {
    display: flex;
    gap: 12px;
    animation: fadeSlideUp 200ms ease;
}

.msg-avatar {
    flex-shrink: 0;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    border-radius: var(--radius-md);
    background: var(--bg-layer);
    border: 1px solid var(--border-subtle);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.msg-body {
    flex: 1;
    min-width: 0;
}

.msg-role {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-tertiary);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.model-tag {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-subtle);
    border: 1px solid rgba(232, 115, 74, 0.15);
    border-radius: 20px;
    padding: 1px 10px;
    line-height: 1.5;
    white-space: nowrap;
}

.message.user .msg-body {
    background: var(--bg-layer);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
}

.message.assistant .msg-body {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 12px 16px;
    box-shadow: var(--shadow-card);
}

.tool-calls-container + .msg-stats + .msg-content,
.tool-calls-container + .msg-content {
    margin-top: 4px;
}

.msg-content {
    font-size: 14px;
    line-height: 1.7;
    word-break: break-word;
}

.msg-content pre {
    background: #2D2016;
    border: none;
    border-radius: var(--radius-md);
    padding: 14px 16px;
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 13px;
    margin: 10px 0;
    color: #F5F0E8;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

.msg-content code {
    background: var(--bg-layer);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.88em;
    color: var(--accent);
}

.msg-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.msg-content p { margin-bottom: 10px; }
.msg-content p:last-child { margin-bottom: 0; }

/* 思考块 */
.think-block {
    margin-bottom: 10px;
    border: 1px solid rgba(155, 126, 216, 0.15);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.think-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    background: rgba(155, 126, 216, 0.06);
    color: #9B7ED8;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}

.think-header .chevron {
    margin-left: auto;
    transition: transform var(--transition);
}

.think-header .chevron.expanded {
    transform: rotate(180deg);
}

.think-content {
    padding: 10px 14px;
    background: rgba(155, 126, 216, 0.02);
}

.think-content pre {
    font-size: 12px;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
    background: none;
    border: none;
    padding: 0;
    box-shadow: none;
}

/* ── 系统提示词折叠卡片 ── */
.system-prompt-card {
    margin-bottom: 10px;
    border: 1px solid rgba(155, 126, 216, 0.12);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: rgba(155, 126, 216, 0.03);
}

.system-prompt-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    color: var(--text-tertiary);
    transition: background 0.15s;
}
.system-prompt-header:hover {
    background: rgba(155, 126, 216, 0.06);
}

.sp-icon { font-size: 14px; flex-shrink: 0; }
.sp-title { font-weight: 600; color: #9B7ED8; white-space: nowrap; }
.sp-tokens {
    font-size: 10px;
    color: var(--text-tertiary);
    background: var(--bg-layer);
    padding: 1px 6px;
    border-radius: 10px;
    white-space: nowrap;
}
.sp-preview {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 11px;
    color: var(--text-tertiary);
}
.sp-chevron {
    flex-shrink: 0;
    transition: transform 0.2s;
    color: var(--text-tertiary);
}
.sp-chevron.sp-expanded { transform: rotate(180deg); }

.system-prompt-body {
    border-top: 1px solid rgba(155, 126, 216, 0.08);
    max-height: 300px;
    overflow-y: auto;
}
.system-prompt-body pre {
    margin: 0;
    padding: 10px 14px;
    font-size: 11px;
    line-height: 1.5;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    background: none;
    border: none;
    box-shadow: none;
    font-family: var(--font);
}

/* 打字光标 */
.typing-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--accent);
    animation: caretBlink 1s step-end infinite;
    vertical-align: text-bottom;
    margin-left: 1px;
    border-radius: 1px;
}

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

/* ═══ Loading 动画 ═══ */
.loading-dots {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 0;
}

.loading-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    animation: dotPulse 1.4s ease-in-out infinite;
}

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

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

.loading-text {
    font-size: 12px;
    color: var(--text-tertiary);
    animation: loadingFade 1.5s ease-in-out infinite;
}

@keyframes loadingFade {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

/* 消息图片 */
.msg-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.msg-img {
    max-width: 200px;
    max-height: 200px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    object-fit: cover;
    box-shadow: var(--shadow-card);
}

.msg-img[data-lightbox] {
    cursor: zoom-in;
    transition: var(--transition);
}

.msg-img[data-lightbox]:hover {
    opacity: 0.85;
    transform: scale(1.02);
}

/* 文件 chip */
.msg-files {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.msg-files .file-chip {
    background: var(--accent-subtle);
    border-color: rgba(232, 115, 74, 0.12);
}

/* 统计信息 */
.msg-stats {
    display: flex;
    gap: 12px;
    margin-top: 8px;
    font-size: 11px;
    color: var(--text-tertiary);
}

/* ═══ 输入区域 ═══ */
.input-area {
    flex-shrink: 0;
    padding: 12px 20px 16px;
    background: var(--bg-mica);
    backdrop-filter: saturate(180%) blur(16px);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    border-top: 1px solid var(--border-subtle);
    z-index: 30;
    position: relative;
    pointer-events: auto;
}

.image-preview {
    display: flex;
    gap: 8px;
    padding: 8px 0;
    flex-wrap: wrap;
}

.preview-thumb {
    position: relative;
    width: 56px;
    height: 56px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--border-default);
    box-shadow: var(--shadow-card);
}

.preview-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-img {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border: none;
    background: var(--critical);
    color: white;
    border-radius: 50%;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* 文件预览 */
.file-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 0;
}

.file-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    background: var(--accent-subtle);
    border: 1px solid rgba(232, 115, 74, 0.12);
    font-size: 12px;
    line-height: 1;
    transition: var(--transition);
    animation: fadeSlideUp 200ms ease;
}

.file-chip:hover {
    background: var(--accent-subtle-hover);
    border-color: rgba(232, 115, 74, 0.2);
}

.file-icon {
    font-size: 13px;
    flex-shrink: 0;
}

.file-name {
    font-weight: 600;
    color: var(--text-primary);
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-size {
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.remove-file {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0 2px;
    border-radius: 3px;
    transition: var(--transition);
}

.remove-file:hover {
    color: var(--critical);
    background: var(--critical-bg);
}

/* ── 视频预览 ── */

.video-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 0;
}

.video-chip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 20px;
    background: rgba(212, 160, 60, 0.1);
    border: 1px solid rgba(212, 160, 60, 0.2);
    font-size: 12px;
    line-height: 1;
    animation: fadeSlideUp 200ms ease;
}

.video-chip .video-icon { font-size: 16px; flex-shrink: 0; }

.video-chip .video-name {
    font-weight: 600;
    color: var(--text-primary);
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.video-chip .video-meta {
    color: #D4A03C;
    flex-shrink: 0;
}

.remove-video {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    border-radius: 3px;
    transition: var(--transition);
}

.remove-video:hover {
    color: var(--critical);
    background: var(--critical-bg);
}

.input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.attach-btn {
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-card);
    border: 1.5px solid var(--border-default);
    border-radius: var(--radius-lg);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    resize: none;
    outline: none;
    min-height: 40px;
    max-height: 120px;
    line-height: 1.5;
    transition: var(--transition);
    pointer-events: auto;
    user-select: text;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}

.chat-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(232, 115, 74, 0.08), 0 1px 3px rgba(0, 0, 0, 0.03);
}

.chat-input::placeholder {
    color: var(--text-disabled);
}

.send-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: var(--radius-lg);
    background: var(--accent);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    box-shadow: 0 2px 8px rgba(232, 115, 74, 0.3);
}

.send-btn:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 16px rgba(232, 115, 74, 0.35);
    transform: translateY(-1px);
}

.send-btn:active {
    transform: translateY(0) scale(0.97);
}

.send-btn.disabled {
    opacity: 0.3;
    cursor: not-allowed;
    pointer-events: none;
    box-shadow: none;
}

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

.send-btn.stop-btn {
    background: var(--critical);
    box-shadow: 0 2px 8px rgba(217, 79, 92, 0.3);
}

.send-btn.stop-btn:hover {
    opacity: 0.9;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ═══ 历史只读提示栏 ═══ */
.history-view-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 20px;
    background: rgba(232, 115, 74, 0.04);
    border-top: 1px solid rgba(232, 115, 74, 0.1);
    font-size: 13px;
    color: var(--accent);
    flex-shrink: 0;
}

/* ═══ 模态框 ═══ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(45, 32, 22, 0.25);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: overlayIn 200ms ease;
    padding: 20px;
}

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

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-dialog);
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    animation: dialogIn 250ms cubic-bezier(0.25, 0.1, 0.25, 1);
    overflow: hidden;
}

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

.modal-lg {
    max-width: 860px;
    width: 96vw;
    max-height: 85vh;
}

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

.modal-header h3 {
    font-size: 17px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.3px;
}

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

/* ── 设置项 ── */
.setting-group {
    margin-bottom: 18px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--border-subtle);
}

.setting-group:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

/* v4.2 人格按钮 */
.personality-btn {
    transition: all 0.15s ease;
    color: var(--text-primary);
}
.personality-btn:hover {
    background: var(--bg-hover) !important;
    border-color: var(--primary) !important;
}
.personality-btn.active {
    background: var(--primary-bg) !important;
    border-color: var(--primary) !important;
    color: var(--primary);
    font-weight: 600;
}

.setting-label {
    display: flex;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.setting-input {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-layer);
    border: 1.5px solid var(--border-default);
    border-radius: var(--radius-control);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font);
    outline: none;
    margin-bottom: 6px;
    transition: var(--transition);
}

.setting-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(232, 115, 74, 0.08);
}

.setting-input::placeholder {
    color: var(--text-disabled);
}

/* ── 按钮 ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 18px;
    border: 1.5px solid transparent;
    border-radius: var(--radius-control);
    font-size: 13px;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: var(--transition);
    gap: 6px;
    position: relative;
    outline: none;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: var(--accent);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(232, 115, 74, 0.25);
}

.btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 12px rgba(232, 115, 74, 0.3);
}

.btn-outline {
    background: var(--bg-card);
    border: 1.5px solid var(--border-default);
    color: var(--text-secondary);
}

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

.btn-danger {
    background: var(--critical-bg);
    border: 1.5px solid rgba(217, 79, 92, 0.15);
    color: var(--critical);
}

.btn-danger:hover {
    background: rgba(217, 79, 92, 0.12);
}

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

/* ── 连接信息 ── */
.connection-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.status-badge {
    padding: 3px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(74, 174, 107, 0.15);
}

.status-badge.error {
    background: var(--critical-bg);
    color: var(--critical);
    border: 1px solid rgba(217, 79, 92, 0.15);
}

.status-badge.warning {
    background: var(--caution-bg);
    color: var(--caution);
    border: 1px solid rgba(212, 160, 60, 0.15);
}

.server-version {
    font-size: 12px;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
}

.cors-hint {
    padding: 12px;
    background: var(--caution-bg);
    border: 1px solid rgba(212, 160, 60, 0.12);
    border-radius: var(--radius-control);
    margin-top: 10px;
}

.cors-hint p {
    font-size: 12px;
    color: var(--caution);
    margin-bottom: 6px;
}

.cors-hint code {
    display: block;
    padding: 8px;
    background: var(--bg-card);
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--accent);
    user-select: all;
    box-shadow: var(--shadow-card);
}

/* ── 运行中的模型 ── */
.running-models {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.running-model {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-layer);
    border-radius: var(--radius-control);
    border: 1px solid var(--border-subtle);
}

.running-model .model-name {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
}

.running-model .model-vram {
    font-size: 12px;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
}

.text-muted {
    color: var(--text-tertiary);
    font-size: 13px;
}

/* ── 历史记录模态框 ── */
#historyModal .modal {
    max-width: 800px;
    max-height: 88vh;
}

#settingsModal .modal {
    max-width: 640px;
}

/* ── 历史记录 ── */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-search-wrap {
    position: relative;
    margin-bottom: 12px;
}

.history-search-input {
    width: 100%;
    padding: 9px 36px 9px 14px;
    background: var(--bg-layer);
    border: 1.5px solid var(--border-default);
    border-radius: var(--radius-control);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font);
    outline: none;
    transition: var(--transition);
}

.history-search-input::placeholder {
    color: var(--text-disabled);
}

.history-search-input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(232, 115, 74, 0.08);
}

.history-search-clear {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
    line-height: 1;
}

.history-search-clear:hover {
    color: var(--text-primary);
}

.history-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-control);
    transition: var(--transition);
}

.history-item:hover {
    background: var(--bg-layer);
}

.history-info {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.history-title {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-meta {
    display: flex;
    gap: 10px;
    font-size: 11px;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.history-actions {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
}

/* ── 历史分页 ── */
.history-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0 4px;
    border-top: 1px solid var(--border-subtle);
    margin-top: 8px;
}

.page-info {
    font-size: 12px;
    color: var(--text-tertiary);
}

.page-buttons {
    display: flex;
    align-items: center;
    gap: 4px;
}

.page-btn {
    min-width: 30px;
    height: 30px;
    border: 1px solid var(--border-default);
    background: var(--bg-card);
    color: var(--text-secondary);
    border-radius: var(--radius-control);
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.page-btn:hover:not(.disabled):not(.active) {
    border-color: var(--border-strong);
    color: var(--text-primary);
}

.page-btn.active {
    background: var(--accent-subtle);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

.page-btn.disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.page-ellipsis {
    color: var(--text-disabled);
    font-size: 12px;
    padding: 0 2px;
}

/* ═══ Lightbox ═══ */
.lightbox-overlay {
    position: fixed;
    inset: 0;
    background: rgba(45, 32, 22, 0.6);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    cursor: zoom-out;
    animation: overlayIn 200ms ease;
}

.lightbox-img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-dialog);
    object-fit: contain;
    cursor: default;
}

.lightbox-close {
    position: fixed;
    top: 16px;
    right: 20px;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-default);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 16px;
    border-radius: var(--radius-control);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    z-index: 301;
    box-shadow: var(--shadow-card);
}

.lightbox-close:hover {
    background: var(--bg-layer);
}

/* ═══ 帮助弹框 ═══ */
#helpModal .modal {
    max-width: 760px;
    max-height: 85vh;
}

.help-section {
    margin-bottom: 14px;
    padding: 14px 16px;
    background: var(--bg-layer);
    border-radius: var(--radius-md);
    border-left: 3px solid var(--border-default);
    transition: border-color var(--transition);
}

.help-section:hover {
    border-left-color: var(--accent);
}

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

.help-section h4 {
    font-size: 14px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.help-section ul,
.help-section ol {
    padding-left: 18px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.7;
}

.help-section li {
    margin-bottom: 3px;
}

.help-section code {
    background: var(--accent-subtle);
    color: var(--accent);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 12px;
}

.help-section kbd {
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-bottom-width: 2px;
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 12px;
    font-family: inherit;
    color: var(--text-primary);
}

.help-shortcuts {
    width: 100%;
    font-size: 13px;
    border-collapse: collapse;
    border-radius: var(--radius-control);
    overflow: hidden;
    border: 1px solid var(--border-default);
}

.help-shortcuts td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border-subtle);
}

.help-shortcuts tr:last-child td {
    border-bottom: none;
}

.help-shortcuts td:first-child {
    width: 140px;
    text-align: center;
    background: var(--bg-layer);
}

.help-shortcuts tr:hover td {
    background: var(--bg-layer-alt);
}

/* ═══ Toast 通知 ═══ */
.toast-container {
    position: fixed;
    top: 56px;
    right: 16px;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    box-shadow: var(--shadow-flyout);
    font-size: 13px;
    color: var(--text-primary);
    pointer-events: auto;
    animation: toastIn 200ms ease;
    max-width: 320px;
}

.toast.removing {
    animation: toastOut 200ms ease forwards;
}

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

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--critical); }
.toast.warning { border-left: 3px solid var(--caution); }
.toast.info { border-left: 3px solid var(--accent); }

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

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to { opacity: 0; transform: translateX(24px); }
}

/* ═══ 响应式 ═══ */
@media (min-width: 768px) {
    .app-header { padding: 10px 28px; }
    .model-bar { padding: 8px 28px; }
    .chat-area { padding: 24px 28px; }
    .messages { max-width: 820px; }
    .input-area { padding: 12px 28px 18px; }
    .modal { max-width: 500px; }
}

@media (min-width: 1024px) {
    .messages { max-width: 900px; }
}

/* ═══ SearXNG 搜索配置 ═══ */
.searxng-btn {
    position: relative;
}

.searxng-icon-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-disabled);
    transition: var(--transition);
    z-index: 2;
}

.searxng-icon-dot.enabled {
    background: var(--success);
    box-shadow: 0 0 6px rgba(74, 174, 107, 0.5);
}

.searxng-badge {
    display: inline-flex;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-tertiary);
    transition: var(--transition);
}

.searxng-badge.enabled {
    color: var(--success);
}

/* ── 选中文本 ── */
::selection {
    background: rgba(232, 115, 74, 0.2);
}

/* ── 链接 ── */
.msg-content a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 500;
}

.msg-content a:hover {
    text-decoration: underline;
}

.msg-content .blocked-link {
    color: var(--critical);
    text-decoration: line-through;
    cursor: not-allowed;
    opacity: 0.7;
}

/* ── 列表 ── */
.msg-content ul, .msg-content ol {
    padding-left: 20px;
    margin: 8px 0;
}

.msg-content li { margin-bottom: 4px; }

/* ── 表格 ── */
.msg-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 13px;
    border-radius: var(--radius-control);
    overflow: hidden;
    border: 1px solid var(--border-default);
}

.msg-content th, .msg-content td {
    padding: 7px 12px;
    border: 1px solid var(--border-subtle);
    text-align: left;
}

.msg-content th {
    background: var(--bg-layer);
    font-weight: 600;
}

/* ── 引用块 ── */
.msg-content blockquote {
    border-left: 3px solid var(--accent);
    padding-left: 14px;
    margin: 10px 0;
    color: var(--text-secondary);
    font-style: italic;
}

/* ═══════════════════════════════════════════════════════════════
   Tool Calling 工具调用卡片
   ═══════════════════════════════════════════════════════════════ */

.tool-calls-container {
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px dashed var(--border-subtle);
}

.tool-call-card {
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    margin: 8px 0;
    overflow: hidden;
    background: var(--bg-layer);
    font-size: 13px;
}

.tool-call-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-layer-alt);
}

.tool-call-icon {
    font-size: 15px;
}

.tool-call-name {
    font-weight: 600;
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 12px;
}

.tool-call-status {
    margin-left: auto;
    font-size: 12px;
    color: var(--text-tertiary);
}

.tool-call-params {
    padding: 6px 14px;
    font-size: 12px;
    color: var(--text-secondary);
}

.tool-call-params code {
    background: var(--bg-card);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--accent);
}

.tool-param {
    margin: 2px 0;
}

.tool-call-result {
    padding: 8px 14px;
    border-top: 1px solid var(--border-subtle);
    max-height: 300px;
    overflow-y: auto;
}

.tool-result-content {
    background: var(--bg-card);
    padding: 10px 12px;
    border-radius: var(--radius-control);
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
    color: var(--text-primary);
    max-height: 200px;
    overflow-y: auto;
    box-shadow: var(--shadow-card);
}

.tool-result-stderr {
    color: var(--critical);
    border-left: 3px solid var(--critical);
}

.tool-result-entry {
    padding: 2px 0;
    font-size: 12px;
    color: var(--text-secondary);
}

.tool-result-entry code {
    background: var(--bg-card);
    padding: 1px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 11px;
}

.tool-result-meta {
    margin-top: 6px;
    font-size: 11px;
    color: var(--text-tertiary);
}

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

.tool-call-error {
    padding: 6px 14px;
    font-size: 12px;
    color: var(--critical);
    border-top: 1px solid var(--border-subtle);
    background: rgba(220, 53, 69, 0.04);
    word-break: break-all;
}

/* ── 聊天区域工具调用历史（可折叠）── */
.tool-calls-history {
    margin: 8px 0;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-layer);
}

.tool-calls-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    color: var(--text-secondary);
    transition: background 0.15s;
}

.tool-calls-toggle:hover {
    background: var(--bg-hover);
}

.tool-calls-chevron {
    font-size: 10px;
    transition: transform 0.2s;
    color: var(--text-tertiary);
}

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

.tool-calls-summary {
    font-family: var(--font);
    font-weight: 500;
}

.tool-calls-list {
    display: none;
    padding: 0 8px 8px;
}

.tool-calls-history.expanded .tool-calls-list {
    display: block;
}

.tool-calls-list .tool-call-card {
    margin: 6px 0;
    font-size: 12px;
}

.tool-calls-list .tool-call-header {
    padding: 6px 10px;
}

.tool-calls-list .tool-call-params {
    padding: 4px 10px;
}

.tool-calls-list .tool-call-result {
    padding: 6px 10px;
    max-height: 200px;
}

.tool-calls-list .tool-result-content {
    font-size: 11px;
    max-height: 150px;
}

/* 状态颜色 */
.tool-call-pending {
    border-color: rgba(212, 160, 60, 0.3);
}

.tool-call-running {
    border-color: rgba(232, 115, 74, 0.3);
}

.tool-call-success {
    border-color: rgba(74, 174, 107, 0.25);
}

.tool-call-error {
    border-color: rgba(217, 79, 92, 0.3);
}

.tool-call-cancelled {
    border-color: var(--border-default);
}

/* 执行中 spinner */
.tool-call-running .tool-call-header::after {
    content: '';
    width: 14px;
    height: 14px;
    border: 2px solid rgba(232, 115, 74, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: tool-spin 0.8s linear infinite;
    margin-left: auto;
}

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

/* ── 工具调用设置 ── */

.tool-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.tool-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 5px 10px;
    border-radius: var(--radius-control);
    background: var(--bg-layer);
    font-size: 12px;
}

.tool-item span:first-child {
    color: var(--text-primary);
}

/* ── 工具确认对话框 ── */

.tool-confirm-info {
    font-size: 13px;
}

.tool-confirm-row {
    display: flex;
    gap: 8px;
    margin: 6px 0;
    align-items: baseline;
}

.tool-confirm-label {
    color: var(--text-secondary);
    white-space: nowrap;
    min-width: 60px;
}

.tool-confirm-row code {
    background: var(--bg-layer);
    padding: 2px 8px;
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--accent);
    word-break: break-all;
}

.tool-confirm-preview {
    background: var(--bg-card);
    padding: 10px 12px;
    border-radius: var(--radius-control);
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 4px 0 0;
    max-height: 150px;
    overflow-y: auto;
    color: var(--text-primary);
    box-shadow: var(--shadow-card);
}

/* ═══════════════════════════════════════════════════════════════
   工作空间面板
   ═══════════════════════════════════════════════════════════════ */

.workspace-panel {
    width: 400px;
    min-width: 400px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border-left: 1px solid var(--border-subtle);
    z-index: 10;
    flex-shrink: 0;
    font-family: var(--font-mono);
}

.ws-header {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-layer-alt);
    min-height: 46px;
    gap: 8px;
}

.ws-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    font-family: var(--font);
}

.ws-tabs {
    display: flex;
    gap: 2px;
    margin-left: auto;
}

.ws-header-tab {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-tertiary);
    padding: 5px 12px;
    border-radius: var(--radius-control);
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font);
    font-weight: 500;
    transition: var(--transition);
}

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

.ws-header-tab.active {
    background: var(--bg-card);
    color: var(--accent);
    border-color: var(--border-default);
    box-shadow: var(--shadow-card);
}

/* ── 终端内容区 ── */

.ws-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.ws-term-tab-bar {
    display: flex;
    gap: 1px;
    padding: 4px 8px 0;
    background: var(--bg-layer-alt);
    border-bottom: 1px solid var(--border-subtle);
    overflow-x: auto;
    min-height: 30px;
}

.ws-term-tab-bar .ws-tab {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-tertiary);
    font-size: 11px;
    padding: 3px 10px;
    border-radius: var(--radius-control) var(--radius-control) 0 0;
    border-bottom: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    transition: var(--transition);
    font-family: var(--font);
}

.ws-term-tab-bar .ws-tab:hover {
    background: var(--bg-layer);
    color: var(--text-primary);
}

.ws-term-tab-bar .ws-tab.active {
    background: var(--bg-card);
    color: var(--accent);
    border-color: var(--border-default);
    border-bottom: 1px solid var(--bg-card);
}

.ws-tab-title {
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ws-tab-close {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 10px;
    padding: 0 2px;
    line-height: 1;
    border-radius: 2px;
}

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

.ws-term-output {
    flex: 1;
    position: relative;
    overflow-y: auto;
    padding: 10px 14px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-primary);
    background: #2D2016;
    word-break: break-all;
    white-space: pre-wrap;
}

.ws-term-placeholder {
    color: rgba(245, 240, 232, 0.4);
    text-align: center;
    padding: 40px 20px;
    font-family: var(--font);
}

/* ── 终端空闲状态 ── */
.ws-idle-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: absolute;
    inset: 0;
    padding: 20px 16px;
    gap: 16px;
}

.ws-idle-logo {
    text-align: center;
}

.ws-idle-ascii {
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.4;
    color: rgba(232, 115, 74, 0.65);
    margin: 0;
    white-space: pre;
    text-shadow: 0 0 20px rgba(232, 115, 74, 0.15);
    animation: idle-glow 3s ease-in-out infinite;
}

@keyframes idle-glow {
    0%, 100% { text-shadow: 0 0 20px rgba(232, 115, 74, 0.1); }
    50% { text-shadow: 0 0 25px rgba(232, 115, 74, 0.25); }
}

.ws-idle-info {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    max-width: 260px;
}

.ws-idle-info-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 11px;
}

.ws-idle-label {
    color: rgba(245, 240, 232, 0.35);
    font-family: var(--font);
    flex-shrink: 0;
}

.ws-idle-value {
    color: rgba(245, 240, 232, 0.6);
    font-family: var(--font-mono);
    font-size: 10px;
    text-align: right;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ws-idle-divider {
    width: 60px;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(232, 115, 74, 0.3), transparent);
}

.ws-idle-tip {
    font-size: 11px;
    color: rgba(245, 240, 232, 0.45);
    font-family: var(--font);
    text-align: center;
    line-height: 1.5;
    max-width: 240px;
    transition: opacity 0.3s ease;
}

.ws-idle-tip.fading {
    opacity: 0;
}

/* ── 工具页签空闲 ── */
.ws-idle-icon-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    max-width: 240px;
}

.ws-idle-icon-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 8px 4px;
    border-radius: 8px;
    background: rgba(245, 240, 232, 0.04);
    border: 1px solid rgba(245, 240, 232, 0.06);
    transition: background 0.2s;
}

.ws-idle-icon-item span {
    font-size: 18px;
}

.ws-idle-icon-item small {
    font-size: 9px;
    color: rgba(245, 240, 232, 0.4);
    font-family: var(--font);
}

/* ── 文件页签空闲 ── */
.ws-idle-icon {
    font-size: 28px;
    opacity: 0.6;
}

.ws-idle-icon-lg {
    font-size: 36px;
}

.ws-idle-desc {
    font-size: 12px;
    color: rgba(245, 240, 232, 0.55);
    font-family: var(--font-mono);
    text-align: center;
}

.ws-idle-hint {
    font-size: 10px;
    color: rgba(245, 240, 232, 0.3);
    font-family: var(--font);
    text-align: center;
}

/* 工具调用 Tab */
.ws-tools-output {
    flex: 1;
    position: relative;
    overflow-y: auto;
    padding: 10px 14px;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text-primary);
    background: #2D2016;
}

.ws-tools-placeholder {
    color: rgba(245, 240, 232, 0.4);
    text-align: center;
    padding: 40px 20px;
}

.ws-tools-output .tool-call-card {
    background: rgba(245, 240, 232, 0.06);
    border: 1px solid rgba(245, 240, 232, 0.1);
    border-radius: 8px;
    margin-bottom: 8px;
    padding: 10px 12px;
    font-family: var(--font);
}

.ws-tools-output .tool-call-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    padding: 0;
    background: none;
    border-bottom: none;
}

.ws-tools-output .tool-call-icon {
    font-size: 14px;
}

.ws-tools-output .tool-call-name {
    font-size: 13px;
    font-weight: 600;
    color: #FAF7F2;
    flex: 1;
}

.ws-tools-output .tool-call-status {
    font-size: 11px;
    color: rgba(245, 240, 232, 0.6);
}

.ws-tools-output .tool-call-params {
    margin-bottom: 6px;
    padding-left: 20px;
}

.ws-tools-output .tool-param {
    font-size: 11px;
    color: rgba(245, 240, 232, 0.7);
    margin-bottom: 2px;
}

.ws-tools-output .tool-param code {
    color: #D4A03C;
    background: rgba(212, 160, 60, 0.15);
    padding: 1px 4px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 11px;
}

.ws-tools-output .tool-call-result {
    border-top: 1px solid rgba(245, 240, 232, 0.08);
    padding-top: 6px;
}

.ws-tools-output .tool-result-content {
    font-family: var(--font-mono);
    font-size: 11px;
    line-height: 1.5;
    color: rgba(245, 240, 232, 0.8);
    background: rgba(0, 0, 0, 0.2);
    padding: 6px 8px;
    border-radius: 4px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}

.ws-tools-output .tool-result-stderr {
    color: #ff8a8a;
}

.ws-tools-output .tool-result-entry {
    font-size: 11px;
    color: rgba(245, 240, 232, 0.75);
    padding: 2px 0;
}

.ws-tools-output .tool-result-entry code {
    color: #6db5f5;
    font-family: var(--font-mono);
    font-size: 10px;
}

.ws-tools-output .tool-result-meta {
    font-size: 10px;
    color: rgba(245, 240, 232, 0.4);
    margin-top: 4px;
}

.ws-tools-output .tool-result-error {
    color: #ff8a8a;
    font-size: 12px;
}

.ws-tools-output .tool-call-running {
    border-color: rgba(232, 115, 74, 0.4);
}

.ws-tools-output .tool-call-error {
    border-color: rgba(255, 138, 138, 0.3);
}

.ws-tools-hint {
    font-size: 11px;
    color: var(--text-tertiary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ws-tools-hint.running {
    color: #E8734A;
}

.ws-term-line {
    min-height: 1.6em;
}

.ws-term-stdout {
    color: rgba(245, 240, 232, 0.85);
}

.ws-term-stderr {
    color: #FF8A8A;
}

.ws-term-system {
    color: #FFB88C;
    font-weight: 500;
    opacity: 0.9;
}

.ws-term-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
    padding: 6px 10px;
    border-top: 1px solid var(--border-default);
    background: var(--bg-layer-alt);
}

.ws-term-hint {
    flex: 1;
    font-size: 11px;
    color: var(--text-tertiary);
    font-family: var(--font);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 4px;
}

.ws-term-hint.running {
    color: var(--accent);
    animation: hint-pulse 1.5s ease-in-out infinite;
}

@keyframes hint-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

.ws-term-toolbar-btns {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.ws-toolbar-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 5px 7px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

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

.ws-toolbar-btn:hover:not(:disabled) {
    background: var(--bg-layer);
    color: var(--text-primary);
}

.ws-toolbar-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.ws-stop-btn.active {
    color: var(--critical);
}

.ws-stop-btn.active:hover {
    background: var(--critical-bg);
}

/* ── 文件浏览器 ── */

.ws-file-toolbar {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border-bottom: 1px solid var(--border-default);
    background: var(--bg-layer-alt);
    min-height: 36px;
}

.ws-file-toolbar .ws-toolbar-btn {
    flex-shrink: 0;
}

.ws-file-path {
    flex: 1;
    font-size: 11px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ws-file-list {
    flex: 1;
    position: relative;
    overflow-y: auto;
    padding: 4px 0;
}

.ws-file-empty {
    color: var(--text-tertiary);
    text-align: center;
    padding: 40px 20px;
    font-size: 13px;
    font-family: var(--font);
}

.ws-file-item {
    display: flex;
    align-items: center;
    padding: 5px 14px;
    cursor: pointer;
    transition: background var(--transition-fast);
    gap: 8px;
}

.ws-file-item:hover {
    background: var(--bg-layer);
}

.ws-file-icon {
    font-size: 14px;
    flex-shrink: 0;
    width: 20px;
    text-align: center;
}

.ws-file-name {
    flex: 1;
    font-size: 12px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ws-file-size {
    font-size: 11px;
    color: var(--text-tertiary);
    flex-shrink: 0;
}

/* ── 文件预览 ── */

.ws-preview {
    border-top: 1px solid var(--border-default);
    display: flex;
    flex-direction: column;
    max-height: 50%;
}

.ws-preview-header {
    display: flex;
    align-items: center;
    padding: 6px 14px;
    background: var(--bg-layer-alt);
    gap: 8px;
}

.ws-preview-title {
    flex: 1;
    font-size: 12px;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ws-preview-content {
    flex: 1;
    overflow-y: auto;
    padding: 0;
    background: #2D2016;
}

.ws-preview-pre {
    margin: 0;
    padding: 8px 0;
    font-size: 11px;
    line-height: 1.6;
    font-family: var(--font-mono);
    color: rgba(245, 240, 232, 0.85);
}

.ws-preview-line {
    display: block;
    padding: 0 14px;
}

.ws-preview-line:hover {
    background: rgba(245, 240, 232, 0.04);
}

.ws-line-num {
    display: inline-block;
    width: 40px;
    text-align: right;
    padding-right: 12px;
    color: rgba(245, 240, 232, 0.25);
    user-select: none;
    border-right: 1px solid rgba(245, 240, 232, 0.08);
    margin-right: 8px;
}

/* ── 滚动条 ── */

.ws-term-output::-webkit-scrollbar,
.ws-tools-output::-webkit-scrollbar,
.ws-file-list::-webkit-scrollbar,
.ws-preview-content::-webkit-scrollbar,
.ws-term-tab-bar::-webkit-scrollbar {
    width: 6px;
}

.ws-term-output::-webkit-scrollbar-track,
.ws-tools-output::-webkit-scrollbar-track,
.ws-file-list::-webkit-scrollbar-track,
.ws-preview-content::-webkit-scrollbar-track {
    background: transparent;
}

.ws-term-output::-webkit-scrollbar-thumb,
.ws-tools-output::-webkit-scrollbar-thumb {
    background: rgba(245, 240, 232, 0.15);
    border-radius: 3px;
}

.ws-file-list::-webkit-scrollbar-thumb,
.ws-preview-content::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: 3px;
}

.ws-term-output::-webkit-scrollbar-thumb:hover,
.ws-tools-output::-webkit-scrollbar-thumb:hover {
    background: rgba(245, 240, 232, 0.25);
}

.ws-file-list::-webkit-scrollbar-thumb:hover,
.ws-preview-content::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

/* ═══════════════════════════════════════════════════════════════
   记忆管理模态框
   ═══════════════════════════════════════════════════════════════ */

#memoryModal .modal {
    max-width: 95vw;
    width: 1000px;
    max-height: 88vh;
}

#memoryModal .modal-body {
    padding: 18px 22px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.memory-layout {
    display: flex;
    gap: 18px;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.memory-sidebar {
    width: 200px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
    overflow: hidden;
    padding-right: 18px;
    border-right: 1px solid var(--border-subtle);
}

.memory-stats {
    padding: 12px;
    background: var(--bg-layer);
    border-radius: var(--radius-control);
    border: 1px solid var(--border-subtle);
    font-size: 12px;
}

.memory-stats-item {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    color: var(--text-secondary);
}

.memory-stats-count {
    color: var(--accent);
    font-weight: 700;
}

.memory-categories {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.memory-category-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: var(--radius-control);
    cursor: pointer;
    transition: var(--transition);
    font-size: 13px;
    color: var(--text-secondary);
    border: 1px solid transparent;
}

.memory-category-item:hover {
    background: var(--bg-layer);
    color: var(--text-primary);
}

.memory-category-item.active {
    background: var(--accent-subtle);
    color: var(--accent);
    border-color: rgba(232, 115, 74, 0.12);
}

.memory-category-icon {
    font-size: 14px;
}

.memory-category-count {
    margin-left: auto;
    font-size: 11px;
    color: var(--text-tertiary);
}

.memory-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.memory-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.memory-search-wrap {
    flex: 1;
    position: relative;
}

.memory-search-input-lg {
    width: 100%;
    padding: 9px 14px;
    background: var(--bg-layer);
    border: 1.5px solid var(--border-default);
    border-radius: var(--radius-control);
    color: var(--text-primary);
    font-size: 13px;
    font-family: var(--font);
    outline: none;
    transition: var(--transition);
}

.memory-search-input-lg:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(232, 115, 74, 0.08);
}

.memory-vector-badge {
    font-size: 11px;
    padding: 3px 10px;
    border-radius: 20px;
    white-space: nowrap;
    font-weight: 500;
}

.memory-vector-badge.enabled {
    color: var(--success);
    background: var(--success-bg);
    border: 1px solid rgba(74, 174, 107, 0.15);
}

.memory-vector-badge.disabled {
    color: var(--text-tertiary);
    background: var(--bg-layer);
    border: 1px solid var(--border-subtle);
}

.memory-list-lg {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
}

.memory-item-lg {
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-control);
    padding: 12px 16px;
    background: var(--bg-layer);
    transition: var(--transition);
}

.memory-item-lg:hover {
    border-color: var(--border-strong);
    background: var(--bg-layer-alt);
    box-shadow: var(--shadow-card);
}

.memory-item-lg-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.memory-item-lg-type {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
}

.memory-item-lg-importance {
    font-size: 8px;
    color: var(--accent);
    letter-spacing: 1px;
    margin-left: auto;
}

.memory-item-lg-delete {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
    line-height: 1;
    transition: color 0.2s;
}

.memory-item-lg-delete:hover {
    color: var(--critical);
}

.memory-item-lg-content {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.5;
    cursor: default;
}

.memory-item-lg-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.memory-item-lg-tags {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.memory-tag-lg {
    background: var(--accent-subtle);
    color: var(--accent);
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 500;
}

.memory-item-lg-time {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-left: auto;
}

.memory-empty-lg {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-tertiary);
    font-size: 13px;
}

/* 记忆面板 toggle */
.memory-toggle {
    display: flex;
    align-items: center;
    cursor: pointer;
    user-select: none;
}

.memory-toggle input {
    display: none;
}

/* btn-danger-outline */
.btn-danger-outline {
    background: none;
    border: 1.5px solid rgba(217, 79, 92, 0.2);
    color: var(--critical);
    border-radius: var(--radius-control);
    padding: 5px 12px;
    cursor: pointer;
    font-size: 12px;
    font-family: var(--font);
    font-weight: 500;
    transition: var(--transition);
}

.btn-danger-outline:hover {
    background: var(--critical-bg);
    border-color: rgba(217, 79, 92, 0.4);
}

/* 记忆注入状态 */
.memory-status {
    text-align: center;
    padding: 4px;
    font-size: 11px;
    color: var(--accent);
    opacity: 0.7;
}

/* 响应式 */
@media (max-width: 640px) {
    .memory-layout {
        flex-direction: column;
    }
    .memory-sidebar {
        width: 100%;
        max-height: 120px;
        border-right: none;
        padding-right: 0;
        padding-bottom: 10px;
        border-bottom: 1px solid var(--border-subtle);
    }
    .memory-categories {
        flex-direction: row;
        flex-wrap: wrap;
    }
}

/* ═══════════════ 工具面板模态框 ═══════════════ */

#toolsModal .modal {
    max-width: 900px;
    width: 95vw;
    max-height: 85vh;
}

.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 8px;
}

.tool-card {
    padding: 10px 14px;
    background: var(--bg-layer);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-control);
    transition: var(--transition);
}

.tool-card:hover {
    border-color: var(--border-strong);
    background: var(--bg-layer-alt);
    box-shadow: var(--shadow-card);
}

.tool-card-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 4px;
}

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

.tool-card-name {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    color: var(--accent);
}

.tool-card-badge {
    margin-left: auto;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    white-space: nowrap;
}

.tool-card-badge.auto {
    color: var(--success);
    background: var(--success-bg);
    border: 1px solid rgba(74, 174, 107, 0.15);
}

.tool-card-badge.confirm {
    color: var(--caution);
    background: var(--caution-bg);
    border: 1px solid rgba(212, 160, 60, 0.15);
}

.tool-card-badge.disabled {
    color: var(--critical);
    background: var(--critical-bg);
    border: 1px solid rgba(217, 79, 92, 0.15);
}

.tool-card-badge.plan-mode {
    color: var(--accent);
    background: rgba(232, 115, 74, 0.08);
    border: 1px solid rgba(232, 115, 74, 0.2);
}

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

/* ══════════════════════════════════════════════
   v4.0 ReAct 执行面板样式
   ══════════════════════════════════════════════ */

/* ReAct 思考过程卡片 */
.react-thought-card {
    background: rgba(155, 126, 216, 0.06);
    border: 1px solid rgba(155, 126, 216, 0.12);
    border-radius: var(--radius-md);
    margin: 8px 0;
    overflow: hidden;
    transition: border-color var(--transition);
}
.react-thought-card:hover {
    border-color: rgba(155, 126, 216, 0.25);
}

.react-thought-header {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 12px;
    color: #9B7ED8;
    font-weight: 600;
    user-select: none;
}
.react-thought-header:hover {
    background: rgba(155, 126, 216, 0.06);
}

.react-thought-content {
    padding: 0 14px 12px;
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
}
.react-thought-content pre {
    margin: 0;
    font-family: inherit;
    white-space: pre-wrap;
    background: none;
    border: none;
    padding: 0;
    box-shadow: none;
    color: inherit;
}

/* ReAct 步骤时间线 */
.react-timeline {
    position: relative;
    padding-left: 20px;
    margin: 12px 0;
}
.react-timeline::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: rgba(155, 126, 216, 0.2);
    border-radius: 1px;
}

.react-step {
    position: relative;
    margin-bottom: 12px;
}
.react-step::before {
    content: '';
    position: absolute;
    left: -18px;
    top: 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #9B7ED8;
    border: 2px solid var(--bg-card);
}

.react-step-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}
.react-step-label.thought { color: #9B7ED8; }
.react-step-label.action { color: var(--accent); }
.react-step-label.observation { color: var(--success); }

.react-step-content {
    font-size: 12px;
    color: var(--text-secondary);
    line-height: 1.5;
    padding: 8px 10px;
    background: var(--bg-layer);
    border-radius: var(--radius-control);
    white-space: pre-wrap;
    word-break: break-word;
}

/* 工具调用卡片增强（v4.0 耗时显示） */
.tool-call-duration {
    font-size: 11px;
    color: var(--text-tertiary);
    margin-left: auto;
}

/* ReAct 执行摘要 */
.react-summary {
    background: rgba(74, 174, 107, 0.06);
    border: 1px solid rgba(74, 174, 107, 0.12);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    margin: 10px 0;
    font-size: 13px;
    line-height: 1.5;
}
.react-summary-title {
    font-weight: 700;
    color: var(--success);
    margin-bottom: 6px;
    font-size: 12px;
}

/* ═══════════════════════════════════════════════════════
   Token 监控仪表盘
   ═══════════════════════════════════════════════════════ */

/* 概览卡片组 */
.td-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.td-stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 16px 14px;
    text-align: center;
    box-shadow: var(--shadow-card);
    transition: var(--transition);
}

.td-stat-card:hover {
    box-shadow: var(--shadow-flyout);
    transform: translateY(-1px);
}

.td-stat-icon {
    font-size: 22px;
    margin-bottom: 6px;
}

.td-stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
    font-family: var(--font-mono);
    line-height: 1.2;
}

.td-stat-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 500;
}

.td-stat-detail {
    font-size: 10px;
    color: var(--text-tertiary);
    margin-top: 2px;
    font-family: var(--font-mono);
}

/* 视图切换按钮 */
.td-view-toggle {
    display: flex;
    gap: 6px;
    margin-bottom: 16px;
    justify-content: center;
}

.td-view-btn {
    padding: 6px 18px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition);
    font-weight: 500;
}

.td-view-btn:hover {
    background: var(--bg-hover, var(--bg-card));
    border-color: var(--accent);
    color: var(--text-primary);
}

.td-view-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* 概览行布局 */
.td-stat-row {
    display: grid;
    gap: 12px;
    margin-bottom: 12px;
}

.td-stat-row-global {
    grid-template-columns: repeat(4, 1fr);
}

.td-stat-row-session {
    grid-template-columns: 1fr;
}

.td-stat-card-small {
    padding: 10px 14px;
}

.td-stat-card-small .td-stat-value {
    font-size: 18px;
}

/* 图例备注 */
.td-legend-note {
    font-size: 11px;
    color: var(--text-tertiary);
    font-style: italic;
}

/* 区块标题 */
.td-section {
    margin-bottom: 20px;
}

.td-section-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-subtle);
}

/* 柱状图 */
.td-chart {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-card);
    min-height: 200px;
}

.td-chart-grid {
    position: relative;
    height: 200px;
    border-left: 1px solid var(--border-subtle);
    border-bottom: 1px solid var(--border-subtle);
    margin-left: 40px;
    margin-bottom: 4px;
}

/* 网格线 */
.td-gridline {
    position: absolute;
    left: 0;
    right: 0;
    border-top: 1px dashed var(--border-subtle);
    pointer-events: none;
    opacity: 0.5;
}

.td-gridline:first-child {
    border-top: none;
}

.td-gridline-label {
    position: absolute;
    right: calc(100% + 6px);
    transform: translateY(-50%);
    font-size: 9px;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    white-space: nowrap;
}

.td-chart-bars {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: stretch;
    gap: 4px;
    padding: 0 8px;
    overflow-x: auto;
    scroll-behavior: smooth;
}

.td-bar-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 0 0 auto;
    width: 40px;
    height: 100%;
    cursor: default;
}

.td-bar-area {
    flex: 1;
    width: 100%;
    display: flex;
    align-items: flex-end;
}

.td-bar-stack {
    width: 100%;
    border-radius: 3px 3px 0 0;
    overflow: hidden;
    display: flex;
    flex-direction: column-reverse;
    transition: height 0.3s ease;
}

.td-bar-segment {
    width: 100%;
    transition: height 0.2s ease;
}

.td-bar-output {
    background: linear-gradient(180deg, #E8734A 0%, #F0976E 100%);
}

.td-bar-input-seg {
    background: linear-gradient(180deg, #9B7ED8 0%, #B99BE5 100%);
}

.td-bar-labels {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    margin-top: 3px;
    font-size: 9px;
    font-family: var(--font-mono);
    white-space: nowrap;
    flex-shrink: 0;
}

.td-bar-label {
    font-size: 10px;
    color: var(--text-tertiary);
    margin-top: 2px;
    font-family: var(--font-mono);
}

.td-bar-col:hover .td-bar-stack {
    filter: brightness(1.1);
}

/* 图例 */
.td-chart-legend {
    display: flex;
    gap: 16px;
    margin-bottom: 10px;
    font-size: 11px;
    color: var(--text-secondary);
}

.td-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.td-legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.td-legend-output {
    background: #E8734A;
}

.td-legend-input {
    background: #9B7ED8;
}

/* 柱子数值标签颜色 */
.td-val-output {
    color: #E8734A;
}

.td-val-input {
    color: #9B7ED8;
}

/* 空状态 */
.td-empty {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-tertiary);
    font-size: 13px;
}

/* 明细表格 */
.td-table-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-card);
    max-height: 260px;
    overflow-y: auto;
}

.td-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.td-table thead {
    position: sticky;
    top: 0;
    z-index: 1;
}

.td-table th {
    background: var(--bg-layer);
    color: var(--text-secondary);
    font-weight: 600;
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.td-table td {
    padding: 7px 12px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
}

.td-table tr:last-child td {
    border-bottom: none;
}

.td-table tr:hover td {
    background: var(--bg-card-hover);
}

.td-num {
    font-family: var(--font-mono);
    font-weight: 500;
    text-align: right;
}

.td-num-total {
    font-weight: 700;
    color: var(--accent);
}

.td-time {
    font-size: 11px;
    color: var(--text-secondary);
}

.td-role-badge {
    font-size: 11px;
}

.td-model-tag {
    font-size: 10px;
    color: var(--text-tertiary);
    background: var(--bg-layer);
    padding: 1px 5px;
    border-radius: 4px;
}

.td-empty-row {
    text-align: center;
    color: var(--text-tertiary);
    padding: 24px !important;
}

/* 响应式：超窄屏幕强制 2 列 */
@media (max-width: 600px) {
    .td-overview {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* ═══════════════════════════════════════════════════════
   上下文使用率环形图
   ═══════════════════════════════════════════════════════ */
.td-ctx-ring-section {
    margin-bottom: 20px;
}

.td-ctx-ring-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 20px;
    box-shadow: var(--shadow-card);
}

.td-ctx-ring-container {
    display: flex;
    align-items: center;
    gap: 28px;
    flex-wrap: wrap;
    justify-content: center;
}

.td-ctx-ring-svg {
    flex-shrink: 0;
}

.td-ctx-ring-details {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-width: 200px;
}

.td-ctx-ring-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.td-ctx-ring-dot {
    width: 10px;
    height: 10px;
    border-radius: 2px;
    flex-shrink: 0;
}

.td-ctx-dot-used {
    background: #9B7ED8;
}

.td-ctx-dot-remain {
    background: var(--border-subtle);
}

.td-ctx-ring-label-text {
    color: var(--text-secondary);
    flex: 1;
}

.td-ctx-ring-val {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-primary);
}

.td-ctx-ring-total {
    border-top: 1px solid var(--border-subtle);
    padding-top: 8px;
    margin-top: 2px;
}

.td-ctx-ring-total .td-ctx-ring-val {
    color: var(--accent);
    font-weight: 700;
}

.td-ctx-ring-note {
    font-size: 11px;
    color: var(--text-tertiary);
    font-style: italic;
    margin-top: 2px;
}

.td-ctx-ring-source {
    font-size: 10px;
    color: var(--text-tertiary);
    margin-top: 2px;
    opacity: 0.8;
}

.td-ctx-ring-streaming {
    font-size: 11px;
    color: #F0A040;
    margin-top: 4px;
    font-weight: 500;
}

/* ═══ R31-R40: UI/UX 增强 ═══ */

/* R38: 代码块复制按钮 */
.code-copy-btn {
    font-family: inherit;
    color: var(--text-secondary);
    transition: opacity 0.2s, background 0.2s;
}
.code-copy-btn:hover {
    background: var(--bg-tertiary, rgba(128, 128, 128, 0.15)) !important;
    color: var(--text-primary);
}

/* R40: 消息操作按钮 */
.msg-actions {
    z-index: 5;
}
.msg-action-btn {
    font-family: inherit;
    color: var(--text-secondary);
    transition: background 0.2s, transform 0.1s;
}
.msg-action-btn:hover {
    background: var(--bg-tertiary, rgba(128, 128, 128, 0.2)) !important;
    transform: scale(1.1);
}
.msg-action-btn:active {
    transform: scale(0.95);
}

/* R31: 消息截断提示 */
.msg-truncated-notice {
    border-top: 1px dashed var(--border-color);
    border-bottom: 1px dashed var(--border-color);
    margin: 8px 0;
    background: var(--bg-secondary, rgba(128, 128, 128, 0.05));
}

/* R34: 加载提示文本动画 */
.loading-text {
    display: inline-block;
    margin-left: 8px;
    color: var(--text-muted);
    font-size: 13px;
    transition: opacity 0.3s;
}
