/* ================================================================
   AgentView — 对话界面样式
   ================================================================ */

:root {
    --bg: #1a1a2e;
    --bg-panel: #16213e;
    --bg-msg-user: #0f3460;
    --bg-msg-assistant: #1a1a2e;
    --bg-toolbox: #1b2a3a;
    --bg-toolbox-nested: #1f3145;
    --bg-thinking: #1c2333;
    --text: #e0e0e0;
    --text-dim: #8899aa;
    --text-bright: #ffffff;
    --accent: #e94560;
    --accent2: #53a8b6;
    --border: #2a3a50;
    --border-active: #e94560;
    --radius: 8px;
    --font-mono: 'Consolas', 'Courier New', monospace;
    --font-sans: 'Segoe UI', system-ui, sans-serif;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    height: 100vh;
    overflow: hidden;
}

/* ---- 容器 ---- */

.container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 900px;
    margin: 0 auto;
}

/* ---- 工具栏 ---- */

.toolbar {
    display: flex; align-items: center; justify-content: flex-end;
    padding: 4px 10px; border-bottom: 1px solid var(--border); flex-shrink: 0;
    gap: 6px; min-height: 30px;
}
.toolbar__btn {
    padding: 2px 10px; font-size: 11px; border: 1px solid var(--border);
    border-radius: 3px; background: transparent; color: var(--text-dim); cursor: pointer;
}
.toolbar__btn:hover { border-color: var(--accent2); color: var(--text-bright); }

/* ---- 工具框参数 ---- */
.tool-box__args { font-size: 11px; color: var(--text-dim); margin-left: 8px; }
.tool-box__arg { display: inline; background: rgba(255,255,255,0.05); padding: 1px 4px; border-radius: 3px; margin-right: 4px; }

/* ---- 消息区 ---- */

.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ---- 消息气泡 ---- */

.msg {
    padding: 10px 14px;
    border-radius: var(--radius);
    line-height: 1.5;
    word-break: break-word;
    animation: fadeIn 0.2s ease;
}

.msg--user {
    max-width: 90%;
    align-self: flex-end;
    background: var(--bg-msg-user);
    border-bottom-right-radius: 2px;
    white-space: pre-wrap;
}

.msg--assistant {
    width: 100%;
    align-self: flex-start;
    background: var(--bg-msg-assistant);
    border: 1px solid var(--border);
    border-bottom-left-radius: 2px;
}

.msg--system {
    align-self: center;
    max-width: 90%;
    background: var(--bg-panel);
    border: 1px dashed var(--border);
    font-size: 0.85em;
    color: var(--text-dim);
}

/* ---- 思考区 ---- */

.thinking {
    margin-bottom: 6px;
    font-size: 0.82em;
    color: var(--text-dim);
    font-style: italic;
    border-left: 2px solid var(--border);
    padding-left: 10px;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s, padding 0.3s;
}

.thinking--open {
    max-height: 300px;
    padding: 4px 0 4px 10px;
}

.thinking__toggle {
    font-size: 0.75em;
    color: var(--accent2);
    cursor: pointer;
    user-select: none;
    margin-bottom: 2px;
}

/* ---- 工具框 ---- */

.tool-box {
    align-self: stretch;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    animation: fadeIn 0.2s ease;
}

.tool-box--running {
    border: 2px solid var(--accent2);
    animation: fadeIn 0.2s ease, toolBoxPulse 1.5s ease-in-out infinite;
}

.tool-box__header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-toolbox);
    font-size: 0.82em;
    font-family: var(--font-mono);
    color: var(--accent2);
    cursor: pointer;
    user-select: none;
}
.tool-box__header:hover { background: rgba(255,255,255,0.03); }

.tool-box__collapse-icon {
    font-size: 0.65em;
    transition: transform 0.2s;
    flex-shrink: 0;
}
.tool-box--collapsed .tool-box__collapse-icon {
    transform: rotate(-90deg);
}

.tool-box__icon {
    font-size: 1em;
}

.tool-box__status {
    margin-left: auto;
    font-size: 0.75em;
    color: var(--text-dim);
}

.tool-box__status--done { color: #4caf50; }
.tool-box__status--running { color: var(--accent2); }

.tool-box__body {
    padding: 10px 14px;
    background: var(--bg-toolbox);
    border-top: 1px solid var(--border);
}

.tool-box__result {
    padding: 8px 14px;
    background: rgba(0,0,0,0.3);
    font-size: 0.85em;
    color: var(--text);
    border-top: 1px solid var(--border);
    max-height: 400px;
    overflow-y: auto;
    line-height: 1.5;
}

/* 折叠状态 */
.tool-box--collapsed .tool-box__body,
.tool-box--collapsed .tool-box__result,
.tool-box--collapsed .tool-box__args-line {
    display: none !important;
}

/* 长参数独立行 */
.tool-box__args-line {
    padding: 4px 14px;
    background: var(--bg-toolbox);
    border-top: 1px solid var(--border);
    font-size: 0.78em;
    color: var(--text-dim);
    font-family: var(--font-mono);
    word-break: break-all;
    line-height: 1.6;
}
.tool-box__arg-line {
    padding: 1px 0;
}

/* 嵌套工具框配色逐层加深 */
.tool-box .tool-box {
    margin-top: 8px;
    border-color: rgba(255,255,255,0.06);
}
.tool-box .tool-box .tool-box__header { background: var(--bg-toolbox-nested); }
.tool-box .tool-box .tool-box__body   { background: var(--bg-toolbox-nested); }

/* ---- 选择面板 ---- */

.choice-panel {
    margin-top: 8px;
    padding: 10px 12px;
    border: 1px solid var(--border-active);
    border-radius: var(--radius);
    background: rgba(233, 69, 96, 0.05);
}

.choice-panel__question {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-bright);
}

.choice-panel__options {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.choice-btn {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-panel);
    color: var(--text);
    cursor: pointer;
    text-align: left;
}
.choice-btn__title { font-weight: 600; display: block; }
.choice-btn__content { display: block; font-size: 0.85em; color: var(--text-dim); margin-top: 3px; }
.choice-panel__actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 4px; }
.choice-confirm-btn {
    padding: 6px 20px; border: none; border-radius: 4px;
    background: var(--accent2); color: #fff; cursor: pointer; font-size: 13px;
}
.choice-confirm-btn:hover { opacity: 0.85; }
.choice-confirm-btn:disabled { opacity: 0.35; cursor: default; }
.choice-panel__custom { margin-top: 8px; }
.choice-custom-input {
    width: 100%; padding: 8px 10px; background: var(--bg-input); border: 1px solid var(--border);
    border-radius: 4px; color: var(--text-bright); font-size: 13px; outline: none; resize: none;
    font-family: inherit; line-height: 1.4; overflow: hidden;
}
.choice-custom-input:focus { border-color: var(--accent); }

.choice-btn:hover {
    border-color: var(--accent2);
    background: rgba(83, 168, 182, 0.1);
}

.choice-btn--chosen {
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.2);
    color: var(--text-bright);
    font-weight: 600;
}

.choice-btn--dimmed {
    opacity: 0.45;
    pointer-events: none;
}
.choice-btn--alt {
    opacity: 0.55;
}

.choice-btn:disabled {
    opacity: 0.4;
    pointer-events: none;
}


/* ---- 输入区 ---- */

.input-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-panel);
}

.input-area textarea {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 0.9em;
    resize: none;
    min-height: 42px;
    max-height: 120px;
    outline: none;
}

.input-area textarea:focus {
    border-color: var(--accent2);
}

.input-area button {
    padding: 0 20px;
    border: none;
    border-radius: var(--radius);
    background: var(--accent2);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9em;
    transition: background 0.15s;
    min-height: 42px;
    white-space: nowrap;
}

.input-area button:hover { background: #4798a6; }
.input-area button:disabled { opacity: 0.5; cursor: default; }
.input-area__send--stop { background: var(--danger, #e74c3c); }

/* ---- 状态栏 ---- */

.status-bar {
    display: flex;
    gap: 16px;
    padding: 6px 16px;
    font-size: 0.75em;
    color: var(--text-dim);
    border-top: 1px solid var(--border);
    background: var(--bg-panel);
}

/* ---- 动画 ---- */

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

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

@keyframes toolBoxPulse {
    0%, 100% { box-shadow: 0 0 4px rgba(83, 168, 182, 0.25); }
    50%      { box-shadow: 0 0 14px rgba(83, 168, 182, 0.55); }
}

.cursor-blink {
    display: inline-block;
    width: 6px;
    height: 14px;
    background: var(--text);
    animation: pulse 0.8s infinite;
    vertical-align: middle;
    margin-left: 1px;
}

/* ---- Markdown 渲染内容 ---- */
.msg--assistant h1, .msg--system h1,
.tool-box__streaming h1, .tool-box__result h1 { font-size: 1.3em; margin: 0.6em 0 0.3em; color: var(--accent2); }

.msg--assistant h2, .msg--system h2,
.tool-box__streaming h2, .tool-box__result h2 { font-size: 1.1em; margin: 0.5em 0 0.25em; border-bottom: 1px solid var(--border); padding-bottom: 3px; }

.msg--assistant h3, .msg--system h3,
.tool-box__streaming h3, .tool-box__result h3 { font-size: 1em; margin: 0.45em 0 0.2em; }

.msg--assistant h4, .msg--system h4,
.tool-box__streaming h4, .tool-box__result h4 { font-size: 0.95em; margin: 0.4em 0 0.15em; color: var(--text-dim); }

.msg--assistant p, .msg--system p,
.tool-box__streaming p, .tool-box__result p { margin: 0.4em 0; }

.msg--assistant strong,
.tool-box__streaming strong, .tool-box__result strong { color: var(--accent); }

.msg--assistant ul, .msg--assistant ol,
.msg--system ul, .msg--system ol,
.tool-box__streaming ul, .tool-box__result ul, .tool-box__streaming ol, .tool-box__result ol { padding-left: 22px; margin: 0.3em 0; }

.msg--assistant li, .msg--system li,
.tool-box__streaming li, .tool-box__result li { margin: 2px 0; }

.msg--assistant blockquote,
.tool-box__streaming blockquote,
.tool-box__result blockquote {
    border-left: 3px solid var(--accent2);
    margin: 0.5em 0;
    padding: 2px 12px;
    color: var(--text-dim);
    background: rgba(83, 168, 182, 0.05);
    border-radius: 0 4px 4px 0;
}

.msg--assistant code, .msg--system code,
.tool-box__streaming code, .tool-box__result code {
    background: rgba(83, 168, 182, 0.15);
    padding: 1px 5px;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.9em;
}

.msg--assistant pre, .msg--system pre,
.tool-box__streaming pre, .tool-box__result pre {
    background: #0f1923;
    border-left: 3px solid var(--accent2);
    padding: 10px 14px;
    border-radius: 0 4px 4px 0;
    overflow-x: auto;
    margin: 6px 0;
}

.msg--assistant pre code, .msg--system pre code,
.tool-box__streaming pre code, .tool-box__result pre code {
    background: none;
    padding: 0;
    font-size: 0.85em;
    line-height: 1.6;
    white-space: pre;
}

.msg--assistant table, .msg--system table,
.tool-box__streaming table, .tool-box__result table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.5em 0;
    font-size: 0.9em;
}

.msg--assistant th, .msg--assistant td,
.msg--system th, .msg--system td,
.tool-box__streaming th, .tool-box__result th, .tool-box__streaming td, .tool-box__result td {
    border: 1px solid var(--border);
    padding: 4px 10px;
    text-align: left;
}

.msg--assistant th, .msg--system th,
.tool-box__streaming th, .tool-box__result th { background: rgba(0,0,0,0.2); }

.msg--assistant hr, .msg--system hr,
.tool-box__streaming hr, .tool-box__result hr { border: none; border-top: 1px solid var(--border); margin: 0.8em 0; }

.msg--assistant a, .msg--system a,
.tool-box__streaming a, .tool-box__result a { color: var(--accent2); text-decoration: underline; }

.msg--assistant img, .msg--system img,
.tool-box__streaming img, .tool-box__result img { max-width: 100%; border-radius: 4px; }

/* 滚动条 */
.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* 思考过程（历史渲染，可折叠） */
.msg--thinking {
    padding: 8px 14px;
    margin: 2px 0;
    border-left: 3px solid var(--border);
    color: var(--text-dim);
    font-size: 0.85em;
    cursor: pointer;
}
.msg--thinking summary {
    color: var(--accent2);
    font-weight: 600;
    margin-bottom: 6px;
}
.msg--thinking .thinking-content {
    white-space: pre-wrap;
    line-height: 1.5;
}
.msg--thinking .thinking-content p { margin: 0.3em 0; }
