/* 系统频道布局与交互样式；公共外观参数见 theme-tokens.css。 */

/* ================================================================
 * 一、页面骨架 — 纯 CSS 三段式(顶栏 / 消息流 / 输入栏)
 *   高度用 100dvh:配合 viewport 的 resizes-content,键盘弹起自动变矮。
 *   overflow:hidden + 内部只有 .agent-feed 自己滚 → 外层文档纹丝不动。
 * ============================================================== */
#page-agent.active {
    display: flex !important;
    flex-direction: column;
    height: 100vh;             /* 旧内核兜底 */
    height: var(--viewport-height);            /* 现代内核: 键盘弹出时随布局视口一起变矮 */
    padding: 0 !important;     /* 窄屏底部留白由输入栏承担，避免与页面重复。 */
    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;
    top:0; right:0; bottom:0; left:0;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: var(--viewport-height);
    overflow: hidden;
    overscroll-behavior: none;
}
body.agent-kbd-lock #page-main {
    height: var(--viewport-height);
    overflow: hidden;
}

/* ---------- 顶栏(仅在对话页内做视觉微调, 不影响其它页面的 .nav-bar) ---------- */
#page-agent .nav-bar {
    flex-shrink: 0;
    position: relative;   /* 对话页是 flex 段, 不需要 sticky */
    top: auto;
}

/* Chat typography, bubbles and scroll area are shared with AI Studio. */
.agent-chat-scroll { display: contents; }
.agent-msg-body { min-width: 0; }
#agent-messages.is-empty { height: 100%; }
.agent-input-capsule .chat-input { margin-left: 8px; }
.agent-msg-time { font: inherit; }
#agent-session-state { margin-left: 8px; }
.agent-sr-only { position:absolute; width:1px; height:1px; overflow:hidden; clip:rect(0,0,0,0); }

/* ---------- 正文里的 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: var(--font-weight-700);
    line-height: 1.35;
    margin: 14px 0 6px;
    color: var(--text-primary);
}
.agent-md-h1 { font-size: var(--font-size-17); }
.agent-md-h2 { font-size: var(--font-size-15); }
.agent-md-h3 { font-size: var(--font-size-14); }
.agent-md-h4, .agent-md-h5, .agent-md-h6 { font-size: var(--font-size-13); }

.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(--text-brand); word-break: break-all; }

.agent-md-quote {
    margin: 8px 0;
    padding: 6px 12px;
    border-left: 3px solid rgba(var(--accent-sky-rgb), 0.35);
    background: rgba(var(--accent-sky-rgb), 0.05);
    border-radius: 0 var(--radius-8) var(--radius-8) 0;
    color: var(--text-secondary);
}
.agent-md-quote > *:last-child { margin-bottom: 0; }

.agent-md-code {
    font-family: var(--font-mono);
    font-size: var(--font-size-12);
    background: var(--bg-hover);
    padding: 1px 5px;
    border-radius: var(--radius-4);
    word-break: break-all;
}

.agent-md-pre {
    margin: 8px 0;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--bg-subtle);
    border: 1px solid var(--border);
    border-radius: var(--control-radius);
    padding: 10px 12px;
}
.agent-md-pre code {
    font-family: var(--font-mono);
    font-size: var(--font-size-12);
    line-height: 1.55;
    white-space: pre;
    color: var(--text-primary);
}

/* Markdown tables share AI Studio sizing and wrapping to avoid overlapping cells. */
.agent-md-tablewrap { -webkit-overflow-scrolling: touch; }

/* ================================================================
 * 三、状态呼吸灯 — 本页签名元素
 * ============================================================== */
.agent-dot {
    width: 9px; height: 9px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 6px;
}
.agent-dot.idle   { background: var(--gradient-blue-soft); }
.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(var(--agent-pulse-rgb), 0); }
    100% { box-shadow: 0 0 0 0   rgba(var(--agent-pulse-rgb), 0); }
}

/* ---------- 消息类型标签 ---------- */










/* ================================================================
 * 四、结构化卡片(行情 / 委托 / 通用 / 持仓)
 * ============================================================== *//* ---------- 行情卡 ---------- */
.agent-quote-card {
    padding: 12px 14px 8px;
    margin-top: 8px;
    cursor: pointer;
    transition: background 0.15s, transform 0.12s;
}

.agent-quote-card:active { transform: scale(0.99); }

.agent-quote-top {
    display: flex; align-items: baseline; grid-gap:8px;gap: 8px; flex-wrap: wrap;
    margin-bottom: 6px;
}
.agent-quote-symbol {
    font-size: var(--font-size-13); font-weight: var(--font-weight-700);
    font-family: var(--font-mono);
    color: var(--text-primary);
}
.agent-quote-price {
    font-size: var(--font-size-15); font-weight: var(--font-weight-700);
    font-family: var(--font-mono);
    color: var(--text-primary);
}
.agent-quote-change {
    font-size: var(--caption-font-size); font-weight: var(--font-weight-600);
    padding: 2px 7px; border-radius: var(--radius-5);
    font-family: var(--font-mono);
    margin-left: auto;
}
.agent-quote-change.up   { background: rgba(var(--agent-pulse-rgb), 0.1); color: var(--text-positive); }
.agent-quote-change.down { background: rgba(var(--accent-danger-rgb), 0.1);  color: var(--text-negative); }
.agent-quote-spark { width: 100%; height: 40px; display: block; }
.agent-quote-hint {
    font-size: var(--meta-font-size);
    color: var(--text-secondary);
    text-align: right;
    margin-top: 2px;
}
/* ---------- 委托任务卡 ---------- */
.agent-delegate-card {
    padding: 12px 14px;
    margin-top: 8px;
}

.agent-delegate-top {
    display: flex; align-items: center; grid-gap:7px;gap: 7px; flex-wrap: wrap;
    margin-bottom: 5px;
}
.agent-delegate-symbol {
    font-size: var(--font-size-13); font-weight: var(--font-weight-700);
    font-family: var(--font-mono);
    color: var(--text-primary);
}

.agent-delegate-status {margin-left:auto;}




.agent-delegate-meta {
    font-size: var(--caption-font-size);
    color: var(--text-secondary);
    font-family: var(--font-mono);
}
.agent-delegate-cancel {display:block;margin-top:9px;}


/* ---------- 委托列表卡 ---------- */
.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;}

/* ---------- 通用结构化卡片(选币 / 持仓等复用) ---------- */
.agent-card {
    overflow: hidden;
    margin-top: 8px;
}

.agent-card-row {
    display: flex; align-items: center; grid-gap:10px;gap: 10px;
    padding: var(--list-row-padding);
    border-bottom: 0;
    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: var(--list-title-font-size);
    font-weight: var(--list-title-font-weight);
    line-height: var(--list-title-line-height);
    font-family: var(--site-font);
    color: var(--text-primary);
    display: flex; align-items: center; grid-gap:6px;gap: 6px; flex-wrap: wrap;
}

.agent-card-target { font-size: var(--caption-font-size); }
.agent-card-meta {
    font-size: var(--caption-font-size);
    color: var(--text-secondary);
    margin-top: 3px;
    font-family: var(--font-mono);
    display: flex; grid-gap:8px;gap: 8px; flex-wrap: wrap;
}
.agent-card-meta .pass { color: var(--text-brand);  font-weight: var(--font-weight-600); }
.agent-card-meta .peak { color: var(--text-warning); font-weight: var(--font-weight-600); }
.agent-card-arrow { color: var(--text-secondary); font-size: var(--font-size-16); flex-shrink: 0; }

/* 多卡片: 一条消息里问了多个币/多件事时, 卡片竖着叠 */
.agent-card-stack {
    display: flex;
    flex-direction: column;
    grid-gap:8px;gap: 8px;
}

/* ================================================================
 * 六、思考过程 · 一个块 / 一行摘要 / 按需展开(时间线)
 * ============================================================== */
.agent-think-flow { margin: 2px 0 8px; }

.agent-think-flow-head {
    display: flex; align-items: center; grid-gap:7px;gap: 7px;
    min-height: 36px;
    padding: 6px 0;
    cursor: pointer; user-select: none;
    font-size: var(--body-font-size);
    color: var(--text-secondary);
    line-height: 1.5;
}
.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(--text-negative); }

@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-secondary); 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: var(--font-size-13); line-height: 1.45;
    color: var(--text-secondary);
    overflow: hidden; text-overflow: ellipsis;
}
.agent-think-node.failed .agent-think-node-title { color: var(--text-negative); }

.agent-think-node-steps { margin-top: 3px; }
.agent-think-step {
    display: flex; align-items: flex-start; grid-gap:6px;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-secondary); }
.agent-think-icon.action  { color: var(--text-brand); }
.agent-think-step-body { flex: 1; min-width: 0; }
.agent-think-step-text {
    font-size: var(--font-size-12); line-height: 1.5;
    color: var(--text-secondary);
}
.agent-think-step-text.muted { opacity: .5; }
.agent-think-badge {margin-left:5px;}






/* Composer shares AI Studio sizing; existing send lock and keyboard handling remain. */
.agent-input { field-sizing: fixed; overflow-y: auto; }
.agent-send-btn { touch-action: manipulation; }

/* ---------- 发送锁定态: AI 回复期间输入只读、发送键禁用 ---------- */
.agent-input.agent-input-locked {
    color: var(--text-secondary);
    cursor: not-allowed;
}
.agent-input.agent-input-locked::placeholder { color: var(--text-secondary); }
.agent-send-btn.agent-send-locked {
    pointer-events: none;               /* 连 :active 缩放都不触发, 彻底点不动 */
}
.agent-send-btn:disabled {
    pointer-events: none;               /* 连 :active 缩放都不触发, 彻底点不动 */
}

/* ================================================================
 * 八、首页入口卡片(运行时由 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;
    grid-gap:12px;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: var(--meta-font-size);
    font-weight: var(--font-weight-700);
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    text-transform: uppercase;
    margin-bottom: 4px;
}
.agent-entry-value {
    font-size: var(--font-size-15);
    font-weight: var(--font-weight-600);
    color: var(--text-primary);
    display: flex; align-items: center; grid-gap:8px;gap: 8px;
}
.agent-entry-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--gradient-green-light);
    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-secondary); font-size: var(--font-size-18); 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; }
}
