/* 远程控制台查看端。手机优先；≥ 900px 变成左侧导航 + 对话列表 + 对话三栏。 */
:root {
  --bg: #f5f6f8; --panel: #ffffff; --panel-2: #f0f2f5; --fg: #1b2029; --muted: #6a7280; --line: #e2e5ea;
  --accent: #2f6fe4; --accent-fg: #ffffff; --accent-soft: #e8f0fe;
  --ok: #1f9d55; --run: #2f6fe4; --wait: #d97706; --err: #d0342c; --warn: #b45309;
  --add: #e6f6ea; --add-fg: #176a35; --del: #fdecea; --del-fg: #a22a22; --hunk: #eef2ff;
  --code-bg: #f3f4f6; --shadow: 0 8px 30px rgba(15, 23, 42, .12);
  --radius: 12px; --tabs-h: 58px; --top-h: 52px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418; --panel: #191d23; --panel-2: #20252c; --fg: #e5e8ec; --muted: #98a1ad; --line: #2b313a;
    --accent: #5b93ff; --accent-fg: #0b1220; --accent-soft: #1d2b45;
    --ok: #3ccf7a; --run: #5b93ff; --wait: #f0a93b; --err: #ff6b62; --warn: #f0b451;
    --add: #13301f; --add-fg: #7ee2a3; --del: #3a1614; --del-fg: #ff9d95; --hunk: #1d2336;
    --code-bg: #14181d; --shadow: 0 8px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111418; --panel: #191d23; --panel-2: #20252c; --fg: #e5e8ec; --muted: #98a1ad; --line: #2b313a;
  --accent: #5b93ff; --accent-fg: #0b1220; --accent-soft: #1d2b45;
  --ok: #3ccf7a; --run: #5b93ff; --wait: #f0a93b; --err: #ff6b62; --warn: #f0b451;
  --add: #13301f; --add-fg: #7ee2a3; --del: #3a1614; --del-fg: #ff9d95; --hunk: #1d2336;
  --code-bg: #14181d; --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg); }
body { font: 15px/1.55 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif; -webkit-text-size-adjust: 100%; overflow: hidden; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
button:disabled { opacity: .45; cursor: default; }
code, .mono, pre { font-family: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", monospace; }
code { font-size: .9em; background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
h2 { font-size: 20px; margin: 4px 0 12px; }
h3 { font-size: 16px; margin: 0 0 10px; }
.icon { flex: none; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.big { font-size: 22px; letter-spacing: 2px; }
.warn { color: var(--warn); }
.error, .errtext { color: var(--err); }
.pre { white-space: pre-wrap; word-break: break-word; }
.clip { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; }
.row.between { justify-content: space-between; gap: 8px; }
.row.end { justify-content: flex-end; }
.row.gap { gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.end-align { align-items: flex-end; }
.block { display: block; width: 100%; }
.pad { padding: 16px; }
.center { display: grid; place-items: center; min-height: 60vh; }

/* ── 按钮与输入 ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); font-size: 14px; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.danger-ghost { background: transparent; color: var(--err); border-color: color-mix(in srgb, var(--err) 40%, var(--line)); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { justify-content: center; width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px; flex: none; }
.icon-btn:hover { background: var(--panel-2); }
.icon-btn.send { background: var(--accent); color: var(--accent-fg); }
.icon-btn.stop { background: var(--err); color: #fff; }
.field { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); color: var(--fg); font: inherit; outline: none; }
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field.inline { width: auto; min-width: 140px; }
textarea.field { resize: none; line-height: 1.5; }
select.field { appearance: auto; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
label .field { color: var(--fg); font-size: 15px; }
.label { font-size: 13px; color: var(--muted); margin-top: 4px; }
.form { display: grid; gap: 12px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; white-space: nowrap; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip button { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.seg { display: inline-flex; background: var(--panel-2); border-radius: 10px; padding: 3px; border: 1px solid var(--line); }
.seg button { padding: 5px 12px; border-radius: 8px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.choices.four { grid-template-columns: repeat(2, 1fr); }
.choice { text-align: left; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); display: grid; gap: 2px; }
.choice span { font-size: 12px; color: var(--muted); }
.choice.on { border-color: var(--accent); background: var(--accent-soft); }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--err); color: #fff; font-size: 12px; font-weight: 700; }

/* ── 状态点 ── */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.st-run { background: var(--run); box-shadow: 0 0 0 3px color-mix(in srgb, var(--run) 25%, transparent); }
.dot.st-wait { background: var(--wait); animation: pulse 1.4s infinite; }
.dot.st-err { background: var(--err); }
.dot.st-ok { background: var(--ok); }
.dot.st-idle { background: color-mix(in srgb, var(--muted) 60%, transparent); }
@keyframes pulse { 50% { box-shadow: 0 0 0 5px color-mix(in srgb, var(--wait) 30%, transparent); } }

/* ── 外壳 ── */
.app { display: flex; flex-direction: column; height: 100dvh; }
.topbar { height: var(--top-h); flex: none; display: flex; align-items: center; gap: 8px; padding: 0 12px; padding-top: env(safe-area-inset-top); background: var(--panel); border-bottom: 1px solid var(--line); position: relative; z-index: 5; }
.hostswitch { position: relative; min-width: 0; }
.hostbtn { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 10px; max-width: 52vw; }
.hostbtn:hover { background: var(--panel-2); }
.dropdown { position: absolute; top: 44px; left: 0; min-width: 240px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: grid; }
.dropdown button { display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 8px; text-align: left; }
.dropdown button .muted { margin-left: auto; }
.dropdown button:hover, .dropdown button.on { background: var(--panel-2); }
.conn { color: var(--warn); }
.quotamini { display: flex; gap: 8px; font-size: 12px; color: var(--muted); padding: 4px 8px; border-radius: 8px; background: var(--panel-2); font-variant-numeric: tabular-nums; }
.quotamini.hot { color: var(--err); }
.bell { position: relative; display: grid; place-items: center; width: 40px; height: 40px; color: var(--muted); border-radius: 10px; }
.bell.on { color: var(--wait); }
.bell .badge { position: absolute; top: 2px; right: 0; transform: scale(.85); }
.main { flex: 1; display: flex; min-height: 0; }
.content { flex: 1; min-width: 0; min-height: 0; overflow: auto; padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom)); }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabs-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--panel); border-top: 1px solid var(--line); z-index: 4; }
.tabs a { flex: 1; display: grid; place-items: center; align-content: center; gap: 2px; font-size: 11px; color: var(--muted); }
.tabs a.on { color: var(--accent); }
.app.in-chat .tabs { display: none; }
.app.in-chat .content { padding-bottom: 0; overflow: hidden; }
.page { padding: 16px; max-width: 900px; margin: 0 auto; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; display: grid; gap: 8px; }
.card.note { background: var(--accent-soft); border-color: transparent; }
.card.narrow { max-width: 460px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.steps { padding-left: 20px; margin: 0; display: grid; gap: 6px; }

/* ── 列表 ── */
.list { display: grid; grid-template-columns: minmax(0, 1fr); align-content: start; }
.item { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; width: 100%; color: inherit; }
.item.link:hover { background: var(--panel-2); }
.item.active { background: var(--accent-soft); }
.pane-list { display: flex; flex-direction: column; height: 100%; background: var(--panel); }
.pane-list .list { overflow: auto; flex: 1; }
.list-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; gap: 8px; }
.search { display: flex; align-items: center; gap: 8px; margin: 0 12px 8px; padding: 7px 10px; border-radius: 10px; background: var(--panel-2); color: var(--muted); }
.search input { border: 0; outline: 0; background: none; color: var(--fg); font: inherit; width: 100%; }
.split { display: flex; height: 100%; }
.split > .pane-list { width: 100%; }
.split > .chat, .split > .chat-empty { display: none; }
.split.has-chat > .pane-list { display: none; }
.split.has-chat > .chat { display: flex; }
.chat-empty { flex: 1; place-items: center; }

/* ── 对话 ── */
.chat { flex-direction: column; flex: 1; min-width: 0; height: 100%; background: var(--bg); }
.chat-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; background: var(--panel); border-bottom: 1px solid var(--line); }
.timeline { flex: 1; overflow: auto; padding: 14px 12px 20px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.timeline.static { max-height: 60vh; }
/* flex 列里的子元素默认 min-width: auto，长路径会把整列撑出屏幕 */
.timeline > *, .approval > *, .tool-body > *, .card > *, .sheet > * { min-width: 0; }
.mono.small, .muted.mono { overflow-wrap: anywhere; }
.approval .row.between > .muted { text-align: right; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble { max-width: 85%; background: var(--accent); color: var(--accent-fg); padding: 9px 13px; border-radius: 16px 16px 4px 16px; white-space: pre-wrap; word-break: break-word; }
.msg.ai { max-width: 100%; }
.msg.ai.streaming { opacity: .92; }
.sysnote { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel-2); padding: 3px 10px; border-radius: 999px; text-align: center; max-width: 92%; }
.errbox { border: 1px solid color-mix(in srgb, var(--err) 40%, var(--line)); background: color-mix(in srgb, var(--err) 8%, var(--panel)); color: var(--err); padding: 10px 12px; border-radius: 10px; white-space: pre-wrap; font-size: 14px; }
.turnend { font-size: 12px; color: var(--muted); padding-left: 2px; }
.thinking { font-size: 13px; color: var(--muted); }
.thinking summary { cursor: pointer; }
.tool { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; overflow: hidden; }
.tool.err { border-color: color-mix(in srgb, var(--err) 45%, var(--line)); }
.tool.pending .tool-head { color: var(--muted); }
.tool-head { display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; text-align: left; font-size: 14px; }
.tool-head .ti { width: 18px; text-align: center; }
.tool-body { padding: 0 10px 10px; display: grid; gap: 6px; }
.kids { border-left: 2px solid var(--line); padding-left: 8px; display: grid; gap: 6px; }
.kidtext { color: var(--muted); }
.todos { background: var(--panel); border-bottom: 1px solid var(--line); padding: 6px 14px; font-size: 13px; }
.todos ul { margin: 6px 0; padding-left: 4px; list-style: none; display: grid; gap: 3px; }
.todos li.completed { color: var(--muted); text-decoration: line-through; }
.todos li.in_progress { color: var(--accent); font-weight: 600; }
.typing { display: flex; gap: 4px; padding: 6px 2px; }
.typing span { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 50% { opacity: .25; } }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); display: grid; gap: 8px; }
.composer textarea { max-height: 220px; }
.quick { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }

/* ── 审批 ── */
.approval { border: 1.5px solid var(--wait); background: color-mix(in srgb, var(--wait) 7%, var(--panel)); border-radius: 12px; padding: 12px; display: grid; gap: 8px; }
.approval.danger { border-color: var(--err); background: color-mix(in srgb, var(--err) 6%, var(--panel)); }
.warnline { color: var(--err); font-size: 13px; font-weight: 600; }
.ctx { border-left: 2px solid var(--line); padding-left: 8px; }
.rules { display: grid; gap: 6px; justify-items: start; }

/* ── Markdown / 代码 / diff ── */
.md { word-break: break-word; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: .5em 0; }
.md h1, .md h2, .md h3, .md h4 { margin: 1em 0 .4em; line-height: 1.3; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3 { font-size: 1.07em; }
.md ul, .md ol { padding-left: 1.4em; margin: .4em 0; }
.md pre { background: var(--code-bg); padding: 10px 12px; border-radius: 8px; overflow: auto; font-size: 13px; }
.md pre code { background: none; padding: 0; }
.md table { border-collapse: collapse; display: block; overflow: auto; max-width: 100%; font-size: 14px; margin: .6em 0; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; vertical-align: top; }
.md th { background: var(--panel-2); }
.md blockquote { margin: .6em 0; padding: 2px 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md img { max-width: 100%; }
.md a.path { background: var(--accent-soft); border-radius: 5px; padding: 0 4px; font-family: ui-monospace, Consolas, monospace; font-size: .9em; word-break: break-all; }
.md.doc { font-size: 15px; }
pre.code { background: var(--code-bg); padding: 8px 10px; border-radius: 8px; overflow: auto; margin: 0; white-space: pre-wrap; word-break: break-word; font-size: 13px; max-height: 50vh; }
pre.code.log { max-height: 70vh; }
pre.diff { background: var(--code-bg); border-radius: 8px; overflow: auto; margin: 0; font-size: 12.5px; line-height: 1.45; padding: 6px 0; max-height: 60vh; }
pre.diff span { display: block; padding: 0 10px; white-space: pre; }
.d-add { background: var(--add); color: var(--add-fg); }
.d-del { background: var(--del); color: var(--del-fg); }
.d-hunk { background: var(--hunk); color: var(--muted); }
.d-head, .d-file { font-weight: 700; }
.docimg { max-width: 100%; border-radius: 8px; }

/* ── 弹层 ── */
.scrim { position: fixed; inset: 0; background: rgba(8, 12, 20, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--panel); width: 100%; max-height: 90dvh; overflow: auto; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 12px; align-content: start; box-shadow: var(--shadow); }
.sheet h3 { margin: 0; }
.menu { display: grid; gap: 2px; }
.menu > button { display: flex; align-items: center; gap: 10px; padding: 12px 10px; border-radius: 10px; text-align: left; }
.menu > button:hover { background: var(--panel-2); }
.menu > button.danger { color: var(--err); }
.menu-group { display: grid; gap: 8px; padding: 10px; font-size: 13px; color: var(--muted); }
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabs-h) + 16px + env(safe-area-inset-bottom)); z-index: 60; display: grid; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; }
.toast.error { background: var(--err); color: #fff; }
.scanner { width: 100%; max-height: 60vh; border-radius: 12px; background: #000; object-fit: cover; }

/* ── 文档树 ── */
.tree { display: grid; margin-top: 10px; }
.tree-dir, .tree-file { display: flex; align-items: center; gap: 6px; padding: 7px 8px; text-align: left; border-radius: 8px; font-size: 14px; }
.tree-dir { font-weight: 600; }
.tree-dir:hover, .tree-file:hover { background: var(--panel-2); }

/* ── 额度 ── */
.win { display: grid; gap: 4px; }
.bar { height: 8px; border-radius: 999px; background: var(--panel-2); overflow: hidden; }
.bar .fill { height: 100%; background: var(--ok); border-radius: 999px; }
.bar .fill.warm { background: var(--wait); }
.bar .fill.hot { background: var(--err); }
.chart { width: 100%; height: 120px; }
.chart .grid { stroke: var(--line); stroke-dasharray: 3 3; }
.chart .line { fill: none; stroke-width: 2; }
.chart .l0, .legend .sw.l0 { stroke: var(--accent); background: var(--accent); }
.chart .l1, .legend .sw.l1 { stroke: var(--wait); background: var(--wait); }
.chart .l2, .legend .sw.l2 { stroke: var(--ok); background: var(--ok); }
.legend { display: flex; gap: 12px; color: var(--muted); }
.legend .sw { display: inline-block; width: 10px; height: 3px; margin-right: 4px; vertical-align: middle; }

/* ── 登录 ── */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; overflow: auto; }
.login .card { width: min(100%, 380px); gap: 14px; padding: 22px; }
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 4px; }
.brand b { font-size: 18px; }

/* ── 宽屏：左侧导航 + 列表 + 对话 ── */
@media (min-width: 900px) {
  .tabs { position: static; flex-direction: column; width: 76px; height: auto; border-top: 0; border-right: 1px solid var(--line); padding: 8px 0; gap: 4px; justify-content: flex-start; }
  .tabs a { flex: none; height: 60px; }
  .app.in-chat .tabs { display: flex; }
  .content { padding-bottom: 0; }
  .split > .pane-list { width: 340px; flex: none; border-right: 1px solid var(--line); display: flex; }
  .split > .chat, .split.has-chat > .chat { display: flex; }
  .split > .chat-empty { display: grid; }
  .split.has-chat > .pane-list { display: flex; }
  .chat-head .back { display: none; }
  .scrim { align-items: center; }
  .sheet { width: min(560px, 92vw); border-radius: 16px; max-height: 86dvh; }
  .sheet.wide { width: min(980px, 94vw); }
  .toasts { bottom: 24px; }
  .choices.four { grid-template-columns: repeat(4, 1fr); }
  .timeline { padding: 18px 28px 24px; }
}
