/* ================================================================
 * agent.css — 系统频道样式 (整页重写版 · 纯 CSS 布局)
 *
 *   设计约束(本次重写的三条硬要求):
 *   1. 【键盘不再遮挡输入框】布局骨架换成纯 CSS:
 *      100dvh + flex 三段(顶栏 / 消息流 / 输入栏)。
 *      index.html 的 <meta viewport> 已带 interactive-widget=resizes-content,
 *      键盘弹出时浏览器会把布局视口整体缩到键盘上沿 → 100dvh 自动变矮 →
 *      贴底的输入栏天然浮在键盘正上方。不再依赖 JS 写 --agent-vvh / --agent-vvt
 *      去顶布局(那套在部分内核下反而和原生 resizes-content 打架,才会"被遮一半")。
 *      ★ agent.js 里那套 visualViewport 逻辑【原样保留、照常运行】,只是本文件
 *        不再读它算出来的变量 —— JS 功能一行没动,布局改由 CSS 独立完成。
 *   2. 【输入框高度纯 CSS 自增】textarea 用 field-sizing: content,
 *      内容几行就长几行,到 max-height 后内部滚动。不写一行 JS 改高度。
 *      (老内核不支持 field-sizing 时优雅退化为单行 + 内部滚动,行为不比以前差。)
 *   3. 【白胶囊输入区】中间一颗白色药丸,发送键内置在药丸右侧,
 *      药丸带极淡阴影;聚焦时药丸边缘轻微提亮。
 *
 *   ★ 兼容性:agent.js / agent-template.js 用到的每一个 class 钩子都完整保留
 *     (消息 / 思考流 / 各类卡片 / 锁定态 / 首页入口卡),渲染逻辑无缝对接。
 *   只依赖 base.css 的设计令牌(--accent-blue 等)。删掉本文件 + 对应 <link> 即可完全回退。
 * ============================================================== */

/* ---------- 本页局部设计令牌 ---------- */
:root {
    --agent-pulse:        #10b981;                    /* 呼吸灯核心: 翡翠绿 */
    --agent-pulse-soft:   rgba(16, 185, 129, 0.40);   /* 光圈起始透明度 */
    --agent-fail:         #f43f5e;                    /* 失败态: 玫红, 比正红柔和 */
    --agent-grad-a:       #3b82f6;                    /* 主渐变起点 (沿用全局蓝) */
    --agent-grad-b:       #6366f1;                    /* 主渐变终点 (靛蓝) */
    --agent-hairline:     rgba(28, 28, 30, 0.07);     /* 发丝线 */
    --agent-capsule-bg:   #ffffff;                    /* 输入胶囊: 纯白 */
    --agent-bar-bg:       var(--bg-page);             /* 输入栏底衬: 和页面同色, 干净不抢戏 */
}

/* ================================================================
 * 一、页面骨架 — 纯 CSS 三段式(顶栏 / 消息流 / 输入栏)
 *   高度用 100dvh:配合 viewport 的 resizes-content,键盘弹起自动变矮。
 *   overflow:hidden + 内部只有 .agent-feed 自己滚 → 外层文档纹丝不动。
 * ============================================================== */
#page-agent.active {
    display: flex !important;
    flex-direction: column;
    height: 100vh;             /* 旧内核兜底 */
    height: 100dvh;            /* 现代内核: 键盘弹出时随布局视口一起变矮 */
    padding: 0 !important;     /* 盖掉 .page 默认的 padding-bottom:30px */
    overflow: hidden;
    position: relative;
    background: var(--bg-page);
}

/* 系统频道本身用 relative + flex 做全屏对话布局，但返回动画期间必须像其它页面
   一样脱离文档流。ID 选择器优先级高于 layout.css 的通用滑动规则，因此需要在
   这里显式覆盖，否则 WebView 会边 translate 边重新计算 #page-main 高度而抖动。 */
.app.swiping #page-agent.active.swipe-current {
    position: absolute;
    inset: 0;
    width: 100%;
    margin: 0;
    will-change: transform;
}

/* 对话页专用外层滚动锁(由 agent.js 给 html/body/#page-main 挂 .agent-kbd-lock;
   离开对话页会摘掉)。纯高度锁 + overflow:hidden,不依赖任何 JS 变量。 */
html.agent-kbd-lock,
body.agent-kbd-lock {
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
}
body.agent-kbd-lock #page-main {
    height: 100dvh;
    overflow: hidden;
}

/* ---------- 顶栏(仅在对话页内做视觉微调, 不影响其它页面的 .nav-bar) ---------- */
#page-agent .nav-bar {
    flex-shrink: 0;
    position: relative;   /* 对话页是 flex 段, 不需要 sticky */
    top: auto;
}
#page-agent .nav-title { letter-spacing: 0.2px; }

/* ---------- 消息流(中间那段, 自己滚动) ---------- */
.agent-feed {
    flex: 1 1 auto;
    min-height: 0;   /* flex 子项要滚动必须显式清零, 否则被内容撑高而不出滚动条 */
    overflow-y: auto;
    padding: 16px 16px 12px;
    -webkit-overflow-scrolling: touch;   /* iOS 惯性滚动 */
    overscroll-behavior: contain;        /* 滚到头也不把动量传给外层文档 */
}

/* ================================================================
 * 二、智能体消息行(无头像, 用呼吸灯代替)
 * ============================================================== */
.agent-msg-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 18px;
    animation: agentMsgIn 0.25s ease;
}
@keyframes agentMsgIn {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0); }
}
.agent-msg-body { flex: 1; min-width: 0; }
.agent-msg-meta {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 5px;
}
.agent-msg-time {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}
.agent-msg-content {
    font-size: 13.5px;
    line-height: 1.65;
    color: var(--text-primary);   /* 实时对话消息: 主文字色, 最清晰、最靠前 */
    word-break: break-word;
    white-space: pre-wrap;
}
.agent-msg-content.auto {
    color: #5b7691;   /* 自动执行插入的消息: 降饱和灰蓝色, 主动退居二线 */
}

/* ---------- 正文里的 Markdown 渲染(agent 消息专用) ---------- */
.agent-md.agent-msg-content { white-space: normal; }
.agent-md > *:first-child { margin-top: 0; }
.agent-md > *:last-child  { margin-bottom: 0; }

.agent-md-p { margin: 0 0 8px; }
.agent-md-h {
    font-weight: 700;
    line-height: 1.35;
    margin: 14px 0 6px;
    color: var(--text-primary);
}
.agent-md-h1 { font-size: 17px; }
.agent-md-h2 { font-size: 15px; }
.agent-md-h3 { font-size: 14px; }
.agent-md-h4, .agent-md-h5, .agent-md-h6 { font-size: 13px; }

.agent-md-list { margin: 4px 0 8px; padding-left: 20px; }
.agent-md-list li { margin: 3px 0; }

.agent-md-hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

.agent-md a { color: var(--accent-blue); word-break: break-all; }

.agent-md-quote {
    margin: 8px 0;
    padding: 6px 12px;
    border-left: 3px solid rgba(59, 130, 246, 0.35);
    background: rgba(59, 130, 246, 0.05);
    border-radius: 0 8px 8px 0;
    color: var(--text-secondary);
}
.agent-md-quote > *:last-child { margin-bottom: 0; }

.agent-md-code {
    font-family: var(--font-mono);
    font-size: 12px;
    background: var(--bg-hover);
    padding: 1px 5px;
    border-radius: 4px;
    word-break: break-all;
}

.agent-md-pre {
    margin: 8px 0;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: #f7f8fa;
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
}
.agent-md-pre code {
    font-family: var(--font-mono);
    font-size: 12px;
    line-height: 1.55;
    white-space: pre;
    color: var(--text-primary);
}

/* 表格: 限宽 + 横向滚动 */
.agent-md-tablewrap {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 8px 0;
    border: 1px solid var(--border);
    border-radius: 10px;
}
.agent-md-table {
    border-collapse: collapse;
    width: 100%;
    font-size: 12px;
    font-family: var(--font-mono);
}
.agent-md-table th,
.agent-md-table td {
    padding: 7px 10px;
    text-align: left;
    white-space: nowrap;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
}
.agent-md-table th:last-child,
.agent-md-table td:last-child { border-right: none; }
.agent-md-table tbody tr:last-child td,
.agent-md-table tr:last-child td { border-bottom: none; }
.agent-md-table thead th {
    background: #f7f8fa;
    color: var(--text-secondary);
    font-weight: 700;
    position: sticky;
    top: 0;
}

/* ================================================================
 * 三、状态呼吸灯 — 本页签名元素
 * ============================================================== */
.agent-dot {
    width: 9px; height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 6px;
}
.agent-dot.idle   { background: #788deb; }
.agent-dot.done   { background: var(--agent-pulse); }
.agent-dot.failed { background: var(--agent-fail); }
.agent-dot.active {
    background: var(--agent-pulse);
    box-shadow: 0 0 0 0 var(--agent-pulse-soft);
    animation: agentPulseRing 1.8s cubic-bezier(0.35, 0, 0.25, 1) infinite;
}
@keyframes agentPulseRing {
    0%   { box-shadow: 0 0 0 0   var(--agent-pulse-soft); }
    70%  { box-shadow: 0 0 0 8px rgba(16, 185, 129, 0); }
    100% { box-shadow: 0 0 0 0   rgba(16, 185, 129, 0); }
}

/* ---------- 消息类型标签 ---------- */
.agent-tag {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 5px;
    font-family: var(--font-mono);
    flex-shrink: 0;
}
.agent-tag.scan    { background: rgba(59,130,246,0.10);  color: var(--accent-blue); }
.agent-tag.open    { background: rgba(16,185,129,0.10);  color: #059669; }
.agent-tag.close   { background: rgba(239,68,68,0.10);   color: var(--accent-red); }
.agent-tag.summary { background: rgba(139,92,246,0.10);  color: var(--accent-purple); }
.agent-tag.config  { background: rgba(245,158,11,0.10);  color: #d97706; }
.agent-tag.error   { background: rgba(107,114,128,0.12); color: var(--text-secondary); }
.agent-tag.pick    { background: rgba(6,182,212,0.10);   color: #0891b2; }
.agent-tag.delegate{ background: rgba(99,102,241,0.10);  color: #6366f1; }
.agent-tag.quote   { background: rgba(13,148,136,0.10);  color: #0d9488; }

/* ================================================================
 * 四、结构化卡片(行情 / 委托 / 通用 / 持仓)
 * ============================================================== */

/* ---------- 行情卡 ---------- */
.agent-quote-card {
    background: var(--bg-card);
    border: 1px solid var(--agent-hairline);
    border-radius: 14px;
    padding: 12px 14px 8px;
    margin-top: 8px;
    cursor: pointer;
    transition: background 0.15s, transform 0.12s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.agent-quote-card:active { background: var(--bg-hover); transform: scale(0.99); }
.agent-quote-top {
    display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
    margin-bottom: 6px;
}
.agent-quote-symbol {
    font-size: 13px; font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text-primary);
}
.agent-quote-price {
    font-size: 15px; font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text-primary);
}
.agent-quote-change {
    font-size: 11px; font-weight: 600;
    padding: 2px 7px; border-radius: 5px;
    font-family: var(--font-mono);
    margin-left: auto;
}
.agent-quote-change.up   { background: rgba(16,185,129,0.10); color: #059669; }
.agent-quote-change.down { background: rgba(239,68,68,0.10);  color: var(--accent-red); }
.agent-quote-spark { width: 100%; height: 40px; display: block; }
.agent-quote-hint {
    font-size: 10px;
    color: var(--text-muted);
    text-align: right;
    margin-top: 2px;
}

/* ---------- 委托任务卡 ---------- */
.agent-delegate-card {
    background: var(--bg-card);
    border: 1px solid var(--agent-hairline);
    border-radius: 14px;
    padding: 12px 14px;
    margin-top: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.agent-delegate-top {
    display: flex; align-items: center; gap: 7px; flex-wrap: wrap;
    margin-bottom: 5px;
}
.agent-delegate-symbol {
    font-size: 13px; font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text-primary);
}
.agent-delegate-auto {
    font-size: 9px; font-weight: 700;
    padding: 2px 6px; border-radius: 4px;
    font-family: var(--font-mono);
    background: rgba(107,114,128,0.12); color: var(--text-secondary);
}
.agent-delegate-status {
    font-size: 9px; font-weight: 700;
    padding: 2px 6px; border-radius: 4px;
    font-family: var(--font-mono);
    margin-left: auto;
}
.agent-delegate-status.pending  { background: rgba(245,158,11,0.10); color: #d97706; }
.agent-delegate-status.watching { background: rgba(59,130,246,0.10); color: var(--accent-blue); }
.agent-delegate-status.done     { background: rgba(16,185,129,0.10); color: #059669; }
.agent-delegate-status.expired,
.agent-delegate-status.canceled { background: rgba(107,114,128,0.12); color: var(--text-secondary); }
.agent-delegate-meta {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
}
.agent-delegate-cancel {
    display: block;
    margin-top: 9px;
    padding: 6px 12px;
    font-size: 11px;
    font-weight: 600;
    border: none;
    border-radius: 7px;
    background: rgba(244,63,94,0.10);
    color: var(--agent-fail);
    cursor: pointer;
}
.agent-delegate-cancel:active { background: rgba(244,63,94,0.22); }

/* ---------- 委托列表卡 ---------- */
.agent-card-row.agent-delegate-row { cursor: default; }
.agent-card-row.agent-delegate-row:active { background: transparent; }
.agent-delegate-row.inactive { opacity: 0.55; }
.agent-delegate-cancel-sm {
    flex-shrink: 0;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border: none;
    border-radius: 6px;
    background: rgba(244,63,94,0.10);
    color: var(--agent-fail);
    cursor: pointer;
}
.agent-delegate-cancel-sm:active { background: rgba(244,63,94,0.22); }

/* ---------- 通用结构化卡片(选币 / 持仓等复用) ---------- */
.agent-card {
    background: var(--bg-card);
    border: 1px solid var(--agent-hairline);
    border-radius: 14px;
    overflow: hidden;
    margin-top: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.03);
}
.agent-card-row {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 13px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}
.agent-card-row:last-child { border-bottom: none; }
.agent-card-row:active { background: var(--bg-hover); }
.agent-card-main { flex: 1; min-width: 0; }
.agent-card-title {
    font-size: 13px;
    font-weight: 700;
    font-family: var(--font-mono);
    color: var(--text-primary);
    display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
}
.agent-card-dirtag {
    font-size: 9px; font-weight: 700;
    padding: 2px 6px; border-radius: 4px;
    font-family: var(--font-mono); letter-spacing: 0.3px;
}
.agent-card-dirtag.long  { background: rgba(16,185,129,0.10); color: #059669; }
.agent-card-dirtag.short { background: rgba(239,68,68,0.10);  color: var(--accent-red); }
.agent-card-target { font-size: 11px; }
.agent-card-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 3px;
    font-family: var(--font-mono);
    display: flex; gap: 8px; flex-wrap: wrap;
}
.agent-card-meta .pass { color: var(--accent-blue);  font-weight: 600; }
.agent-card-meta .peak { color: #d97706; font-weight: 600; }
.agent-card-arrow { color: var(--text-muted); font-size: 16px; flex-shrink: 0; }

/* 多卡片: 一条消息里问了多个币/多件事时, 卡片竖着叠 */
.agent-card-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ================================================================
 * 五、用户自己发的消息(右侧渐变气泡)
 * ============================================================== */
.agent-msg-user-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-bottom: 18px;
    animation: agentMsgIn 0.25s ease;
}
.agent-msg-user-bubble {
    background: linear-gradient(135deg, var(--agent-grad-a) 0%, var(--agent-grad-b) 100%);
    color: #fff;
    border-radius: 18px 18px 5px 18px;
    padding: 10px 14px;
    font-size: 13.5px;
    line-height: 1.55;
    max-width: 78%;
    word-break: break-word;
    box-shadow: 0 2px 10px rgba(80, 100, 246, 0.20);
}
.agent-msg-user-time {
    font-size: 11px;
    color: var(--text-muted);
    font-family: var(--font-mono);
    margin-top: 4px;
}

/* ================================================================
 * 六、思考过程 · 一个块 / 一行摘要 / 按需展开(时间线)
 * ============================================================== */
.agent-think-flow { margin: 2px 0 8px; }

.agent-think-flow-head {
    display: flex; align-items: center; gap: 7px;
    padding: 3px 0;
    cursor: pointer; user-select: none;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
}
.agent-think-flow-head:active { opacity: .6; }

.agent-think-dot {
    width: 5px; height: 5px; border-radius: 50%;
    background: var(--text-muted); opacity: .55;
    flex: 0 0 auto;
}
.agent-think-dot.failed { background: var(--agent-fail); opacity: 1; }

.agent-think-summary { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent-think-live {
    flex: 1; min-width: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    color: var(--text-secondary);
    animation: agentThinkLiveIn .22s ease;
}
.agent-think-count { flex: 0 0 auto; font-family: var(--font-mono); opacity: .7; }
.agent-think-flow.failed .agent-think-summary { color: var(--agent-fail); }

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

.agent-think-chev {
    display: flex; flex: 0 0 auto;
    color: var(--text-muted); opacity: .55;
    transition: transform .18s ease;
}
.agent-think-flow.expanded .agent-think-chev { transform: rotate(180deg); }

.agent-think-spin {
    width: 11px; height: 11px; flex: 0 0 auto; border-radius: 50%;
    border: 1.5px solid var(--border);
    border-top-color: var(--agent-pulse);
    animation: agentThinkSpin .7s linear infinite;
}
@keyframes agentThinkSpin { to { transform: rotate(360deg); } }

/* 展开后的时间线: grid 0fr→1fr 做高度动画 */
.agent-think-flow-body {
    display: grid;
    grid-template-rows: 0fr;
    transition: grid-template-rows .22s ease;
}
.agent-think-flow.expanded .agent-think-flow-body { grid-template-rows: 1fr; }
.agent-think-flow-inner { overflow: hidden; }
.agent-think-flow.expanded .agent-think-flow-inner { padding: 6px 0 2px 2px; }

.agent-think-node {
    position: relative;
    padding: 0 0 9px 15px;
    border-left: 1px solid var(--border);
    margin-left: 2px;
}
.agent-think-node:last-child { border-left-color: transparent; padding-bottom: 2px; }
.agent-think-node-dot {
    position: absolute; left: -3px; top: 6px;
    width: 5px; height: 5px; border-radius: 50%;
    background: var(--border);
    box-shadow: 0 0 0 2px var(--bg-page);
}
.agent-think-node.running .agent-think-node-dot { background: var(--agent-pulse); }
.agent-think-node.failed  .agent-think-node-dot { background: var(--agent-fail); }
.agent-think-node-main { min-width: 0; }
.agent-think-node-title {
    font-size: 13px; line-height: 1.45;
    color: var(--text-secondary);
    overflow: hidden; text-overflow: ellipsis;
}
.agent-think-node.failed .agent-think-node-title { color: var(--agent-fail); }

.agent-think-node-steps { margin-top: 3px; }
.agent-think-step {
    display: flex; align-items: flex-start; gap: 6px;
    padding: 2px 0;
}
.agent-think-icon {
    width: 12px; height: 12px; flex: 0 0 auto;
    display: flex; align-items: center; justify-content: center;
    margin-top: 2px;
}
.agent-think-icon svg { width: 10px; height: 10px; }
.agent-think-icon.thought { color: var(--text-muted); }
.agent-think-icon.action  { color: var(--accent-blue); }
.agent-think-step-body { flex: 1; min-width: 0; }
.agent-think-step-text {
    font-size: 12px; line-height: 1.5;
    color: var(--text-muted);
}
.agent-think-step-text.muted { opacity: .5; }
.agent-think-badge {
    display: inline-block;
    margin-left: 5px;
    font-size: 10px;
    font-weight: 700;
    padding: 0 5px;
    border-radius: 4px;
    font-family: var(--font-mono);
    vertical-align: 1px;
}
.agent-think-badge.scan     { background: rgba(59,130,246,0.10);  color: var(--accent-blue); }
.agent-think-badge.quote    { background: rgba(13,148,136,0.10);  color: #0d9488; }
.agent-think-badge.delegate { background: rgba(99,102,241,0.10);  color: #6366f1; }
.agent-think-badge.config   { background: rgba(245,158,11,0.10);  color: #d97706; }
.agent-think-badge.pick     { background: rgba(6,182,212,0.10);   color: #0891b2; }

/* ================================================================
 * 七、底部输入栏 — 白胶囊 + 内置发送键(纯 CSS 自动增高)
 *   结构(见 agent-template.js):
 *     .agent-input-bar               ← flex 段, 贴底, 垫手势条安全区
 *       └ .agent-input-capsule       ← 白色药丸, 极淡阴影, 聚焦时轻微提亮
 *            ├ textarea.agent-input  ← 透明底, field-sizing 自增高, 无边框
 *            └ button.agent-send-btn ← 内置在药丸右侧的圆形发送键
 * ============================================================== */
.agent-input-bar {
    flex-shrink: 0;
    padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
    background: var(--agent-bar-bg);
    border-top: 1px solid var(--agent-hairline);
    transition: padding-bottom 0.15s ease;
}
/* 键盘弹起时(agent.js 侦测后给 #page-agent 挂 .kbd-open):
   手势条被键盘挡住, 收掉底部安全区留白, 不浪费一像素。 */
#page-agent.kbd-open .agent-input-bar {
    padding-bottom: 8px;
}

/* 白胶囊本体 */
.agent-input-capsule {
    display: flex;
    align-items: flex-end;   /* 发送键始终贴底: textarea 长高时它不跟着变大 */
    gap: 6px;
    background: var(--agent-capsule-bg);
    border: 1px solid rgba(28, 28, 30, 0.06);
    border-radius: 23px;
    padding: 5px 5px 5px 16px;   /* 左边给文字留白, 右边留 5px 让圆键内嵌 */
    /* 极淡、几乎看不出来的阴影:近处一层描边感 + 远处一层柔化 */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 14px rgba(0, 0, 0, 0.04);
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
/* 聚焦时药丸边缘轻微提亮(仍很克制) */
.agent-input-capsule:focus-within {
    border-color: rgba(59, 130, 246, 0.30);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05), 0 4px 16px rgba(59, 130, 246, 0.10);
}

/* textarea:无边框、透明底,靠 field-sizing 纯 CSS 自增高 */
.agent-input {
    flex: 1 1 auto;
    min-width: 0;
    border: none;
    outline: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 16px;        /* ≥16px: 彻底避开 iOS 聚焦自动放大 */
    line-height: 1.4;
    color: var(--text-primary);
    padding: 6px 0;
    word-break: break-word;

    /* ★ 纯 CSS 自动增高:内容几行就长几行,不写一行 JS。
       到 max-height 后自身内部滚动。老内核不支持 field-sizing 时,
       退化为固定单行 + 内部滚动(rows=1),行为不比以前差,且零 JS。 */
    field-sizing: content;
    min-height: 22px;       /* 约一行 */
    max-height: 116px;      /* 约五行,超出内部滚 */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.agent-input::placeholder { color: var(--text-muted); }

/* 圆形发送键:内嵌在药丸右侧,贴底对齐 */
.agent-send-btn {
    width: 34px; height: 34px;
    flex: 0 0 auto;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--agent-grad-a), var(--agent-grad-b));
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    box-shadow: 0 1px 5px rgba(80, 100, 246, 0.28);
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.15s, opacity 0.15s;
    touch-action: manipulation;   /* 消灭 300ms 点击延迟与双击缩放 */
}
.agent-send-btn:active {
    transform: scale(0.90);
    box-shadow: 0 1px 3px rgba(80, 100, 246, 0.22);
}
.agent-send-btn svg { width: 16px; height: 16px; margin: 1px 1px 0 0; }

/* ---------- 发送锁定态: AI 回复期间输入只读、发送键禁用 ---------- */
.agent-input.agent-input-locked {
    color: var(--text-muted);
    cursor: not-allowed;
}
.agent-input.agent-input-locked::placeholder { color: var(--text-muted); }

.agent-send-btn.agent-send-locked,
.agent-send-btn:disabled {
    background: var(--border-strong);   /* 收掉蓝紫渐变, 变安静灰底 */
    color: #fff;
    box-shadow: none;
    cursor: not-allowed;
    opacity: 0.65;
    pointer-events: none;               /* 连 :active 缩放都不触发, 彻底点不动 */
}
.agent-send-btn:disabled:active { transform: none; }

/* ================================================================
 * 八、首页入口卡片(运行时由 agent.js 插到搜索框上方)
 * ============================================================== */
.agent-entry-card {
    background: var(--bg-card);
    margin: 0 16px 16px;
    padding: 14px 16px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-card);
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    cursor: pointer;
    transition: background 0.15s;
}
.agent-entry-card:active { background: var(--bg-hover); }
.agent-entry-left { flex: 1; min-width: 0; }
.agent-entry-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
}
.agent-entry-value {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    display: flex; align-items: center; gap: 8px;
}
.agent-entry-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #80dd70;
    flex-shrink: 0;
}
.agent-entry-dot.active {
    background: var(--agent-pulse);
    box-shadow: 0 0 0 0 var(--agent-pulse-soft);
    animation: agentPulseRing 1.8s cubic-bezier(0.35, 0, 0.25, 1) infinite;
}
.agent-entry-dot.done   { background: var(--agent-pulse); }
.agent-entry-dot.failed { background: var(--agent-fail); }
.agent-entry-arrow { color: var(--text-muted); font-size: 18px; flex-shrink: 0; }

/* ================================================================
 * 九、无障碍: 用户系统开了"减弱动态效果"时, 停掉持续动画
 * ============================================================== */
@media (prefers-reduced-motion: reduce) {
    .agent-dot.active,
    .agent-entry-dot.active { animation: none; box-shadow: 0 0 0 3px var(--agent-pulse-soft); }
    .agent-msg-row,
    .agent-msg-user-wrap { animation: none; }
}
