/* elephant-cc 手机端 — 移动优先暗色主题 */
:root {
  --bg: #0f1318;
  --bg-elevated: #171d24;
  --bg-bubble-user: #2b5c8f;
  --bg-bubble-ai: #1c242e;
  --border: #263041;
  --text: #e6ebf2;
  --text-dim: #8b98a9;
  --accent: #3d7dC4;
  --accent-press: #2f66a1;
  --danger: #c0504d;
  --ok: #4caf7d;
  --warn: #d9a441;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}
[v-cloak] { display: none; }
/* 不用 vh/dvh（老内核不认识或比可见区高一截，会导致页面可被拖动、
   头尾不固定、底部内容在屏幕外）。fixed 钉满可视区是全年代内核
   都支持的做法，文档永不滚动，头部/输入框恒定在首尾 */
#app { position: fixed; top: 0; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; }

/* ---------------- 通用 ---------------- */
.btn {
  appearance: none; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text);
  padding: 12px 16px; border-radius: 12px; font-size: 15px;
  cursor: pointer; transition: filter .12s;
}
.btn:active { filter: brightness(1.2); }
.btn:disabled { opacity: .45; }
.btn.primary { background: var(--accent); border-color: var(--accent); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }

.icon-btn {
  appearance: none; border: none; background: var(--bg-elevated);
  color: var(--text); border-radius: 12px; width: 42px; height: 42px;
  font-size: 17px; cursor: pointer; flex: none;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:disabled { opacity: .4; }

.card {
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 16px; margin: 0 16px 14px;
}
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--text-dim); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 12px; font-size: 16px; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
}
.field input:focus { outline: none; border-color: var(--accent); }

/* ---------------- 配对页 ---------------- */
.pair-view {
  flex: 1; display: flex; flex-direction: column; justify-content: center;
  padding: 16px 0 calc(16px + var(--safe-bottom));
}
.brand { text-align: center; margin-bottom: 26px; }
.logo { font-size: 56px; }
.brand h1 { margin: 6px 0 2px; font-size: 26px; letter-spacing: .5px; }
.brand .sub { margin: 0; color: var(--text-dim); font-size: 14px; }
.code-input {
  text-transform: uppercase; letter-spacing: .4em; text-align: center; font-size: 22px !important;
}
.tips { font-size: 13px; color: var(--text-dim); line-height: 1.8; }
.tips p { margin: 0; }
.tips b { color: var(--text); }
.tips .env-line { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); font-size: 12px; opacity: .8; }
.notice { margin: 12px 0 0; font-size: 13px; line-height: 1.6; white-space: pre-wrap; }
.notice.error { color: var(--danger); }
.notice.info { color: var(--text-dim); }

/* ---------------- 聊天页 ---------------- */
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--safe-top)) 14px 10px;
  border-bottom: 1px solid var(--border); background: var(--bg);
  position: sticky; top: 0; z-index: 5;
}
.header-main { flex: 1; min-width: 0; }
.agent-name { font-weight: 600; font-size: 16px; }
/* 权限模式徽标（电脑端 Shift+Tab 切换后同步）：深黄色 */
.mode-badge {
  margin-left: 8px;
  font-size: 12px;
  font-weight: 600;
  color: #d4a017;
  border: 1px solid rgba(212, 160, 23, 0.45);
  border-radius: 8px;
  padding: 1px 8px;
  vertical-align: 1px;
}
.agent-status { font-size: 12px; color: var(--text-dim); }
.agent-status.running { color: var(--ok); }
.agent-status.waiting_permission { color: var(--warn); }
.agent-status.error, .agent-status.stopped { color: var(--danger); }

.banner {
  padding: 8px 14px; font-size: 13px; background: #3a2b2b; color: #e8b0ac;
  border-bottom: 1px solid #5a3a3a;
}

/* 消息滚动区外包一层定位容器：悬浮「回到最新」按钮以其为锚。
   本层仍用 flex:1 占据头部与输入区之间的剩余高度（与旧版 .messages 直接
   挂在 .chat-view 下的机制一致，已在真机验证可用） */
.messages-wrap { position: relative; flex: 1; min-height: 0; }

/* 滚动容器绝对定位钉满外层，不依赖 flex 拉伸/交叉轴 stretch——部分手机
   WebView 的 stretch 会让容器随内容自动长高：内部滚动失效（scroll 事件
   不触发、「↓」按钮永不出现）、内容被顶出屏幕外拉不到底 */
.messages {
  position: absolute; left: 0; right: 0; top: 0; bottom: 0;
  overflow-y: auto; padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  /* 注意不要加 scroll-behavior: smooth——流式输出期间高频跟随滚动会被
     平滑动画拖住、越落越远（手机端「不自动滚到最新」的根因）；跟随必须是瞬时 */
}

.jump-latest {
  position: absolute; right: 14px; bottom: 10px;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg-elevated); border: 1px solid var(--border);
  color: var(--text); font-size: 18px; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .45);
  cursor: pointer;
}

.msg { max-width: 92%; }
.msg.user { align-self: flex-end; }
.msg.assistant, .msg.tool, .msg.thinking, .msg.system { align-self: flex-start; }

.bubble {
  padding: 10px 13px; border-radius: var(--radius);
  font-size: 15px; line-height: 1.55; word-break: break-word; white-space: pre-wrap;
}
.bubble.user { background: var(--bg-bubble-user); border-bottom-right-radius: 4px; }
.bubble.assistant { background: var(--bg-bubble-ai); border-bottom-left-radius: 4px; }
.bubble .text code { background: #0c0f13; padding: 1px 5px; border-radius: 4px; font-size: 13px; }

.cursor {
  display: inline-block; width: 8px; height: 15px; margin-right: 4px;
  background: var(--accent); vertical-align: -2px;
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.thinking {
  font-size: 13px; color: var(--text-dim);
  border: 1px dashed var(--border); border-radius: 10px; padding: 6px 10px;
  width: 100%;
}
.thinking summary { cursor: pointer; user-select: none; }
.thinking pre {
  margin: 8px 0 2px; white-space: pre-wrap; word-break: break-word;
  max-height: 300px; overflow-y: auto; font-size: 12px; line-height: 1.5;
}

.tool-card {
  width: 100%; background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 12px; padding: 10px 12px; font-size: 13px;
}
.tool-card.pending { border-color: var(--warn); }
.tool-head { display: flex; align-items: center; gap: 8px; }
.tool-name { font-weight: 600; font-family: ui-monospace, Consolas, monospace; }
.tool-state { margin-left: auto; color: var(--text-dim); font-size: 12px; }
.tool-card.pending .tool-state { color: var(--warn); }
.tool-summary, .tool-result {
  margin: 8px 0 0; white-space: pre-wrap; word-break: break-word;
  font-family: ui-monospace, Consolas, monospace; font-size: 12px; line-height: 1.5;
  max-height: 220px; overflow-y: auto; color: var(--text-dim);
}
.tool-result { border-top: 1px dashed var(--border); padding-top: 8px; }
.tool-actions { display: flex; gap: 8px; margin-top: 10px; }
.tool-actions .btn { flex: 1; padding: 9px 6px; font-size: 14px; }

.system-line {
  align-self: center; text-align: center; font-size: 12px; color: var(--text-dim);
  background: var(--bg-elevated); border-radius: 999px; padding: 4px 12px;
}

/* ---------------- 输入区 ---------------- */
.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--border); background: var(--bg);
}
.composer textarea {
  flex: 1; resize: none; max-height: 140px;
  background: var(--bg-elevated); color: var(--text);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 11px 12px; font-size: 16px; font-family: inherit; line-height: 1.4;
}
.composer textarea:focus { outline: none; border-color: var(--accent); }
.send-btn { background: var(--accent); color: #fff; }
.stop-btn { background: var(--danger); color: #fff; }
/* 停止图标用 CSS 画方块，不依赖 emoji 字体（手机上 U+23F9 渲染偏移、无法居中） */
.stop-btn::before {
  content: ''; display: block;
  width: 12px; height: 12px; border-radius: 2px; background: #fff;
}

/* ---------------- 历史会话面板 ---------------- */
.history-workdir {
  margin: 0; font-size: 12px; color: var(--text-dim);
  font-family: ui-monospace, Consolas, monospace; word-break: break-all;
}
.history-empty { margin: 8px 0; font-size: 13px; color: var(--text-dim); line-height: 1.6; }
.history-list { display: flex; flex-direction: column; gap: 8px; }
.history-item {
  appearance: none; text-align: left; cursor: pointer;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; color: var(--text);
}
.history-item:active { border-color: var(--accent); }
.history-title {
  display: block; font-size: 14px; line-height: 1.5;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.history-time { display: block; margin-top: 3px; font-size: 12px; color: var(--text-dim); }
.history-hint { margin: 4px 0 0; font-size: 12px; color: var(--text-dim); line-height: 1.6; }

/* ---------------- 设置面板 ---------------- */
.sheet-mask {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: flex-end; z-index: 20;
}
.sheet {
  width: 100%; background: var(--bg-elevated); border-radius: 18px 18px 0 0;
  padding: 20px 16px calc(20px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 10px;
  max-height: 80dvh; overflow-y: auto;
}
.sheet h3 { margin: 0 0 4px; }
.session-info { font-size: 13px; color: var(--text-dim); line-height: 1.8; }
.session-info p { margin: 0; }
