/* Web Claude — 深色主题 */
:root {
  color-scheme: dark;
  --bg: #1a1917;
  --bg2: #22201d;
  --bg3: #2b2825;
  --line: #383430;
  --text: #e8e4dd;
  --text-dim: #948e83;
  --accent: #d97757;
  --accent-dim: #a45a41;
  --ok: #7fb069;
  --err: #e5695c;
  --files-w: 380px;
  --radius: 10px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; } /* 防止自定义 display 覆盖 hidden 属性 */
html, body { height: 100%; }
body {
  font-family: system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; flex-direction: column; overflow: hidden;
  font-size: 14px;
}
button { font: inherit; color: inherit; cursor: pointer; }

/* ===== 顶栏 ===== */
#topbar {
  min-height: 48px; flex: none; display: flex; align-items: center; flex-wrap: wrap; gap: 4px 10px;
  padding: 4px 12px; background: var(--bg2); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 6px; }
.brand .logo { color: var(--accent); }
.badge {
  font-size: 12px; color: var(--accent); border: 1px solid var(--accent-dim);
  padding: 2px 8px; border-radius: 99px; white-space: nowrap;
}
.pill {
  font-size: 12px; padding: 2px 10px; border-radius: 99px;
  background: var(--bg3); color: var(--text-dim); white-space: nowrap;
}
.pill[data-state="working"] { color: #f0b45c; background: rgba(240,180,92,.12); }
.pill[data-state="idle"] { color: var(--ok); background: rgba(127,176,105,.12); }
.pill[data-state="crashed"], .pill[data-state="offline"] { color: var(--err); background: rgba(229,105,92,.12); }
.pill.queue-pill { color: #f0b45c; background: rgba(240,180,92,.12); }
.ghost {
  background: none; border: 1px solid var(--line); border-radius: 8px;
  padding: 5px 12px; color: var(--text-dim); white-space: nowrap;
}
.ghost:hover { color: var(--text); border-color: var(--text-dim); }
.ghost.on { color: var(--accent); border-color: var(--accent-dim); } /* 全屏中 */
#btnFullscreen { margin-left: auto; } /* ⛶/new/用户名 整组推到顶栏右缘，其前空隙自动填满 */
/* 用户名 = 退出入口：点击弹出菜单（复用右键菜单样式）；▾ 提示可点 */
.who { color: var(--text-dim); font-size: 13px; cursor: pointer; white-space: nowrap; user-select: none; }
.who:hover { color: var(--text); }
.who::after { content: ' ▾'; font-size: 10px; }
/* 顶栏系统状态条（GLM 额度/存储/温度/CPU） */
#sysStatus { color: var(--text-dim); border-color: var(--line); display: inline-flex; align-items: center; gap: 9px; padding: 2px 6px; }
#sysStatus[hidden] { display: none; }
#sysStatus i { font-style: normal; font-size: 11px; opacity: .65; }
#sysStatus b { font-weight: 600; }
#sysStatus b.ok { color: var(--ok); }
#sysStatus b.warn { color: #f0b45c; }
#sysStatus b.bad { color: var(--err); }
.tabs { display: none; gap: 4px; }
.tabs button {
  background: none; border: 1px solid transparent; border-radius: 8px;
  padding: 5px 12px; color: var(--text-dim);
}
.tabs button.active { color: var(--text); border-color: var(--line); background: var(--bg3); }

/* ===== 主区布局 ===== */
main { flex: 1; display: flex; min-height: 0; }

/* 左侧文件面板 */
#filePanel {
  width: var(--files-w); min-width: 220px; flex: none;
  display: flex; flex-direction: column; background: var(--bg2);
  border-right: 1px solid var(--line);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 10px; border-bottom: 1px solid var(--line); flex: none;
}
.fs-root { font-size: 13px; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-actions { display: flex; gap: 4px; flex: none; }
button.icon {
  background: none; border: 0; border-radius: 6px; padding: 4px 7px;
  color: var(--text-dim); font-size: 14px; line-height: 1;
}
button.icon:hover { background: var(--bg3); color: var(--text); }

.file-tree { flex: 1; overflow: auto; padding: 6px 4px 20px; user-select: none; }
.row {
  display: flex; align-items: center; gap: 6px; padding: 4px 8px;
  border-radius: 6px; cursor: pointer; white-space: nowrap;
}
.row:hover { background: var(--bg3); }
.row.selected { background: rgba(217,119,87,.16); }
.row .arrow { width: 14px; flex: none; color: var(--text-dim); font-size: 10px; text-align: center; transition: transform .12s; }
.row.open .arrow { transform: rotate(90deg); }
.row .name { overflow: hidden; text-overflow: ellipsis; }
.row .size { margin-left: auto; font-size: 11px; color: var(--text-dim); flex: none; }
.children { margin-left: 14px; }
.empty-tip { color: var(--text-dim); text-align: center; padding: 24px 10px; font-size: 13px; }

/* 左侧页签：文件 / 对话历史 */
.side-tabs {
  display: flex; gap: 4px; padding: 6px 8px 0; flex: none;
  border-bottom: 1px solid var(--line);
}
.side-tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--text-dim); font-size: 13px; padding: 6px 10px; border-radius: 6px 6px 0 0;
}
.side-tabs button.active { color: var(--text); border-bottom-color: var(--accent); }
.side-tabs button { flex: none; }
/* 模型切换下拉：左侧页签行右端（modelSettingsDir 下有可选配置时才显示）；窄面板自动收缩截断 */
.model-select {
  font: inherit; font-size: 12px; color: var(--text);
  background: var(--bg3); border: 1px solid var(--line); border-radius: 99px;
  padding: 3px 6px; white-space: nowrap;
  margin: 0 2px 4px auto; align-self: center;
  min-width: 0; max-width: 150px; flex: 0 1 150px;
  overflow: hidden; text-overflow: ellipsis;
}
.model-select:focus { outline: none; border-color: var(--accent-dim); }
.side-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.conv-list { flex: 1; overflow: auto; padding: 6px 8px 20px; user-select: none; }
.conv-item { position: relative; padding: 8px 28px 8px 10px; border-radius: 6px; cursor: pointer; }
.conv-item:hover { background: var(--bg3); }
.conv-item.active { background: rgba(217,119,87,.16); }
.conv-item .c-title { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .c-meta { font-size: 11px; color: var(--text-dim); margin-top: 2px; display: flex; gap: 8px; min-width: 0; }
.conv-item .c-cwd { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* 删除按钮：悬停浮现（触屏无 hover，始终显示）；右侧留白防标题压到按钮下 */
.conv-item .c-del {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  background: none; border: 0; border-radius: 6px; padding: 5px 6px;
  color: var(--text-dim); font-size: 12px; line-height: 1; visibility: hidden;
}
.conv-item:hover .c-del, .conv-item .c-del:focus-visible { visibility: visible; }
.conv-item .c-del:hover { color: var(--err); background: rgba(229,72,77,.12); }
@media (hover: none) { .conv-item .c-del { visibility: visible; } }

#splitter { width: 5px; flex: none; cursor: col-resize; background: transparent; }
#splitter:hover, #splitter.dragging { background: var(--accent-dim); }

/* 右侧对话面板 */
#chatPanel { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--bg); }
#messages { flex: 1; overflow-y: auto; padding: 18px 16px 8px; scroll-behavior: smooth; }
#messages .inner { max-width: 860px; margin: 0 auto; }

.msg { margin-bottom: 14px; line-height: 1.65; }
.msg.user .bubble {
  background: var(--bg3); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 14px; white-space: pre-wrap; word-break: break-word;
}
.msg.user.queued .bubble { opacity: .6; border-style: dashed; } /* 排队中：本轮结束才发出 */
.msg .role {
  font-size: 12px; color: var(--text-dim); margin-bottom: 4px; display: flex; align-items: center; gap: 6px;
}
.msg .role .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.msg.assistant .role .dot { animation: pulse 1.2s ease-in-out infinite; }
.msg .role .time { font-size: 11px; } /* Claude 消息时间（跟在 role 行） */
.msg.user .time { font-size: 11px; color: var(--text-dim); text-align: right; margin-top: 3px; } /* 用户消息时间（气泡下方） */
@keyframes pulse { 50% { opacity: .3; } }

.md { word-break: break-word; }
.md pre {
  background: #141312; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; overflow-x: auto; margin: 8px 0; font-size: 13px; line-height: 1.5;
}
.md code { font-family: ui-monospace, "JetBrains Mono", Consolas, monospace; }
.md :not(pre) > code { background: var(--bg3); border-radius: 4px; padding: 1px 5px; font-size: .92em; }
.md h1, .md h2, .md h3, .md h4 { margin: 12px 0 6px; line-height: 1.4; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.25em; } .md h3 { font-size: 1.12em; } .md h4 { font-size: 1em; }
.md ul, .md ol { padding-left: 1.5em; margin: 6px 0; }
.md a { color: var(--accent); }
.md blockquote { border-left: 3px solid var(--line); padding-left: 10px; color: var(--text-dim); margin: 8px 0; }
.md table { border-collapse: collapse; margin: 8px 0; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 4px 10px; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

/* 工具调用卡片 */
.tool {
  border: 1px solid var(--line); border-radius: 8px; margin: 8px 0;
  background: var(--bg2); font-size: 13px; overflow: hidden;
}
.tool > summary {
  list-style: none; cursor: pointer; padding: 7px 12px;
  display: flex; align-items: center; gap: 8px; color: var(--text-dim);
}
.tool > summary::-webkit-details-marker { display: none; }
.tool > summary:hover { color: var(--text); }
.tool > summary .t-name { color: var(--accent); font-weight: 600; }
.tool > summary .t-brief { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tool > summary .t-state { flex: none; font-size: 12px; }
.tool > summary .t-state.run { color: #f0b45c; }
.tool > summary .t-state.ok { color: var(--ok); }
.tool > summary .t-state.fail { color: var(--err); }
.tool .t-body { border-top: 1px solid var(--line); padding: 8px 12px; max-height: 320px; overflow: auto; }
.tool .t-body pre { white-space: pre-wrap; word-break: break-all; font-size: 12px; color: var(--text-dim); }

.turn-info {
  flex: none; text-align: center; font-size: 12px; color: var(--text-dim);
  padding: 0 12px 4px; min-height: 18px;
}

/* 输入区 */
#composer {
  flex: none; display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg2);
  max-width: 884px; margin: 0 auto; width: 100%;
}
#input {
  flex: 1; resize: none; max-height: 180px; padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
  color: var(--text); font: inherit; line-height: 1.5; outline: none;
}
#input:focus { border-color: var(--accent-dim); }
#btnSend {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px;
  padding: 10px 18px; font-weight: 600;
}
#btnSend:disabled { opacity: .4; cursor: default; }
/* 语音输入（内联 SVG 话筒）：按住说话、松开识别；录音中变红呼吸闪烁；识别请求期间禁用显省略号。
   touch-action:none 防按住时页面滚动抢手势；后两行防长按选中文本/弹系统菜单。
   横向 padding 18px 加宽触控目标（≈54px，[92] 用户反馈窄了易误触） */
#btnMic {
  flex: none; border: 1px solid var(--line); border-radius: 10px; background: var(--bg);
  padding: 11px 18px; line-height: 0; cursor: pointer; color: var(--text-dim);
  display: flex; align-items: center; justify-content: center;
  touch-action: none; user-select: none; -webkit-touch-callout: none;
}
#btnMic:hover { color: var(--text); border-color: var(--text-dim); }
#btnMic.rec { color: var(--err); border-color: var(--err); animation: micPulse 1.2s ease-in-out infinite; }
#btnMic:disabled { opacity: .5; cursor: default; }
@keyframes micPulse { 50% { opacity: .35; } }
button.stop {
  background: var(--err); color: #fff; border: 0; border-radius: 10px;
  width: 44px; height: 42px; font-size: 15px; flex: none;
}

/* ===== 右键菜单 / 弹窗 / 提示 ===== */
.ctx-menu {
  position: fixed; z-index: 60; background: var(--bg3); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px; min-width: 140px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.ctx-menu button {
  display: block; width: 100%; text-align: left; background: none; border: 0;
  padding: 7px 12px; border-radius: 6px; color: var(--text);
}
.ctx-menu button:hover { background: var(--bg2); }
.ctx-menu button.danger { color: var(--err); }

.modal-mask {
  position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 14px;
  width: 100%; max-width: 720px; max-height: 88dvh; display: flex; flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.modal .m-head {
  display: flex; align-items: center; gap: 8px; padding: 12px 16px;
  border-bottom: 1px solid var(--line); font-size: 13px; color: var(--text-dim);
}
.modal .m-head .m-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal .m-body { padding: 12px 16px; overflow: auto; flex: 1; min-height: 0; }
.modal .m-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--line); }
.modal textarea {
  width: 100%; height: 100%; min-height: 50vh; resize: none; border: 0; outline: none;
  background: transparent; color: var(--text); font: 13px/1.6 ui-monospace, "JetBrains Mono", Consolas, monospace;
}
.modal textarea.editor { min-height: 46dvh; }
.modal input[type="text"] {
  width: 100%; padding: 9px 12px; border-radius: 8px; font-size: 14px;
  border: 1px solid var(--line); background: var(--bg); color: var(--text); outline: none;
}
.modal input[type="text"]:focus { border-color: var(--accent); }
.modal img.preview, .modal video.preview { max-width: 100%; max-height: 70dvh; display: block; margin: 0 auto; border-radius: 8px; }
.modal .btn {
  border: 0; border-radius: 8px; padding: 8px 16px; font-weight: 600;
  background: var(--accent); color: #fff;
}
.modal .btn.plain { background: var(--bg3); color: var(--text-dim); border: 1px solid var(--line); }
.modal .btn.danger { background: var(--err); }
.modal p.confirm { line-height: 1.7; }

/* 工作目录选择器 */
.cwd-path {
  font-size: 12px; color: var(--text-dim); background: var(--bg2);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; margin-bottom: 10px; word-break: break-all;
}
.cwd-list { max-height: 46dvh; overflow: auto; }
.cwd-row {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
.cwd-row:hover { background: var(--bg3); }
.cwd-row .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cwd-row.up { color: var(--text-dim); }
.cwd-tip { color: var(--text-dim); font-size: 13px; text-align: center; padding: 16px 0; }

.toast {
  position: fixed; z-index: 90; bottom: 70px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--line); color: var(--text);
  padding: 9px 18px; border-radius: 99px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.4);
  max-width: 86vw; white-space: pre-wrap;
}
.toast.err { border-color: var(--err); color: var(--err); }

/* ===== 移动端 ===== */
@media (max-width: 820px) {
  .tabs { display: flex; }
  #sysStatus { font-size: 11px; gap: 5px; }
  #sysStatus .wide { display: none; } /* 手机上隐藏磁盘/CPU占用，其余常显 */
  #filePanel, #splitter { display: none; }
  body[data-tab="files"] #filePanel { display: flex; width: 100%; border-right: 0; }
  body[data-tab="files"] #splitter { display: none; }
  body[data-tab="files"] #chatPanel { display: none; }
  body[data-tab="chat"] #chatPanel { display: flex; }
  #messages { padding: 12px 10px 6px; }
  #btnNewChat, #btnFullscreen { padding: 5px 8px; }
}
