:root {
  --bg: #f9f8f6; --panel: #f2f0eb; --surface: #fff; --text: #1f1e1c; --muted: #6f6d68; --faint: #a3a09a;
  --line: #e6e3dc; --chip: #ebe8e1; --bubble: #efebe4; --code: #f4f2ee; --accent: #c6613f; --accent-soft: rgba(198, 97, 63, .1);
  --ok: #2f8a58; --err: #c2413b; --warn: #c47f17;
  --shadow: 0 1px 2px rgba(31, 30, 28, .04), 0 6px 24px rgba(31, 30, 28, .07);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Georgia, "Songti SC", "Noto Serif CJK SC", serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --col: 780px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1b1a; --panel: #161615; --surface: #252523; --text: #ecebe6; --muted: #a3a19b; --faint: #706e69;
    --line: #33322f; --chip: #2d2c29; --bubble: #2f2e2b; --code: #151514; --accent: #d97757; --accent-soft: rgba(217, 119, 87, .14);
    --ok: #5fb487; --err: #e5675f; --warn: #e0a440;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 28px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: 15px/1.65 var(--sans); -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
::selection { background: var(--accent-soft); }

/* ---------- buttons & controls ---------- */
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 7px 15px; font-size: 14px; cursor: pointer; transition: background .15s, border-color .15s, opacity .15s; }
.btn:hover { border-color: var(--faint); }
.btn.pri { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.pri:hover { filter: brightness(1.05); }
.btn.danger { color: var(--err); }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 0; background: none; border-radius: 9px; color: var(--muted); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--chip); color: var(--text); }
.icon-btn.sm { width: 30px; height: 30px; }
.link { border: 0; background: none; padding: 0; color: var(--muted); font-size: 13px; cursor: pointer; }
.link:hover { color: var(--text); }
.chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 5px 12px; font: 13px var(--mono); cursor: pointer; max-width: 100%; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip svg { width: 15px; height: 15px; }
.chip:hover { color: var(--text); border-color: var(--faint); }
select.pill {
  appearance: none; -webkit-appearance: none; border: 0; border-radius: 999px; background-color: transparent; color: var(--muted);
  font: 13px var(--sans); padding: 5px 22px 5px 10px; cursor: pointer; flex: none; max-width: 150px; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23999' stroke-width='1.4' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; background-size: 9px;
}
select.pill:hover, select.pill:focus { background-color: var(--chip); color: var(--text); outline: none; }
select.pill.hot { color: var(--accent); }

/* ---------- login ---------- */
#login { position: fixed; inset: 0; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(340px, 100%); display: flex; flex-direction: column; gap: 14px; text-align: center; }
.login-card .mark { font-size: 40px; color: var(--accent); line-height: 1; }
.login-card h1 { font: 500 26px var(--serif); margin: 0 0 8px; }
.login-card input { font: 16px var(--sans); padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); outline: none; }
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card .btn { padding: 10px; font-size: 15px; }
.login-err { color: var(--err); font-size: 13px; min-height: 1.4em; margin: 0; }

/* ---------- layout ---------- */
#app { position: fixed; top: 0; left: 0; right: 0; height: var(--app-h, 100dvh); display: flex; overflow: hidden; }
#side { width: 272px; flex: none; background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom) env(safe-area-inset-left); }
main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
#scrim { display: none; }

.side-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 10px 6px 16px; }
.brand { font-weight: 600; font-size: 15px; display: flex; gap: 8px; align-items: center; }
.brand i { color: var(--accent); font-style: normal; font-size: 18px; }
#list { flex: 1; overflow-y: auto; padding: 2px 8px 12px; overscroll-behavior: contain; }
.space-btn { display: flex; align-items: center; gap: 8px; margin: 2px 10px 4px; padding: 7px 10px; border: 1px solid var(--line); background: var(--surface); border-radius: 11px; cursor: pointer; text-align: left; transition: border-color .15s; }
.space-btn:hover { border-color: var(--faint); }
.space-btn span { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.space-btn svg { width: 16px; height: 16px; color: var(--muted); }
.row.on { background: var(--accent-soft); }
.row.on .rt { font-weight: 600; }
.row.on svg { color: var(--accent); }
.newsp { display: flex; gap: 8px; align-items: center; }
.newsp input.txt { margin-top: 0; flex: 1; min-width: 0; }
.grp { font-size: 12px; color: var(--faint); padding: 14px 8px 4px; }
.item { display: block; padding: 7px 10px; border-radius: 9px; color: inherit; text-decoration: none; position: relative; }
.item:hover { background: var(--chip); }
.item.on { background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, .06); }
.item .t { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 14px; }
.item .m { font-size: 12px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .dot { position: absolute; right: 9px; top: 14px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: pulse 1.3s ease-in-out infinite; }
.item .dot.perm { background: var(--warn); animation: none; box-shadow: 0 0 0 3px rgba(196, 127, 23, .18); }
.item .act { position: absolute; right: 5px; top: 50%; transform: translateY(-50%); width: 28px; height: 28px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; display: none; place-items: center; }
.item .act svg { width: 17px; height: 17px; }
.item .act:hover { background: var(--line); color: var(--text); }
.item:hover .act, .item.on .act { display: grid; }
.item:hover .t, .item:hover .m, .item.on .t, .item.on .m { padding-right: 26px; }
.item:hover .dot, .item.on .dot { right: 38px; }
@media (hover: none) {
  .item .act { display: grid; }
  .item .t, .item .m { padding-right: 26px; }
  .item .dot { right: 38px; }
}
.item.editing .act, .item.editing .dot { display: none; }
.item .rn { width: 100%; font: inherit; font-size: 14px; color: var(--text); background: var(--surface); border: 1px solid var(--accent); border-radius: 6px; padding: 1px 6px; margin: -2px 0 -2px -7px; outline: none; }
.pop { position: fixed; z-index: 40; min-width: 132px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 4px; animation: rise .12s ease-out; }
.pop button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 8px 10px; border: 0; border-radius: 8px; background: none; color: var(--text); font: inherit; font-size: 14px; cursor: pointer; text-align: left; }
.pop button:hover { background: var(--chip); }
.pop button.danger { color: var(--err); }
.pop svg { width: 16px; height: 16px; }
/* skills & MCP dialog */
.caps-wait { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 22px 4px; font-size: 14px; }
.caps-wait .spark { color: var(--accent); display: inline-block; animation: spin 2.4s linear infinite; }
.seg { display: flex; gap: 4px; padding: 3px; background: var(--chip); border-radius: 11px; margin-bottom: 6px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 8px; padding: 6px 10px; font-size: 13.5px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .08); font-weight: 600; }
.seg em { font-style: normal; color: var(--faint); font-weight: 400; margin-left: 2px; }
.cap { border-radius: 10px; }
.cap summary { display: flex; align-items: center; gap: 8px; padding: 8px 6px; cursor: pointer; list-style: none; border-radius: 9px; font-size: 14px; }
.cap summary::-webkit-details-marker { display: none; }
.cap summary:hover { background: var(--chip); }
.cap summary b { font-weight: 500; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cap[open] summary b { font-weight: 600; }
.cap.off summary b { color: var(--faint); }
.cap-m { font-size: 12px; color: var(--faint); flex: none; }
.cap .tag { font-size: 11px; color: var(--muted); background: var(--chip); border-radius: 5px; padding: 0 6px; }
.cap-b { padding: 0 6px 10px; font-size: 13px; color: var(--muted); line-height: 1.6; }
.cap-b p { margin: 2px 0 8px; }
.cap-b .btn { font-size: 13px; padding: 5px 12px; }
.cap-kv { color: var(--faint); font-size: 12px; }
.cap-err { color: var(--err); }
.cap-tools { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.cap-tools li { display: flex; flex-direction: column; }
.cap-tools code { font: 12.5px var(--mono); color: var(--text); }
.cap-tools span { font-size: 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.st-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.st-dot.ok { background: var(--ok); }
.st-dot.err { background: var(--err); }
.st-dot.warn { background: var(--warn); }
.caps-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); font-size: 12px; color: var(--faint); }
.caps-foot code { font: 11.5px var(--mono); }
.foot-links a.link { text-decoration: none; }
.list-empty { color: var(--faint); font-size: 13px; padding: 16px 10px; }

.side-foot { border-top: 1px solid var(--line); padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.usage { display: flex; flex-direction: column; gap: 8px; border: 0; background: none; padding: 4px 2px; text-align: left; cursor: pointer; border-radius: 8px; }
.u-row { display: flex; flex-direction: column; gap: 3px; }
.u-top { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }
.u-top b { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.u-bar { height: 4px; border-radius: 4px; background: var(--chip); overflow: hidden; }
.u-bar i { display: block; height: 100%; border-radius: 4px; background: var(--ok); transition: width .4s; }
.u-bar i.mid { background: var(--warn); }
.u-bar i.hi { background: var(--err); }
.u-reset { font-size: 11px; color: var(--faint); }
.u-note { font-size: 12px; color: var(--faint); }
.foot-links { display: flex; justify-content: space-between; padding: 0 2px; }

#top { display: flex; align-items: center; gap: 8px; min-height: 54px; padding: env(safe-area-inset-top) 12px 0 18px; border-bottom: 1px solid transparent; transition: border-color .2s; }
#top.edge { border-bottom-color: var(--line); }
.head-text { flex: 1; min-width: 0; }
#title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#sub { font-size: 12px; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-family: var(--mono); }
.ctx { font-size: 12px; color: var(--muted); background: var(--chip); border-radius: 999px; padding: 2px 9px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ctx.warn { color: var(--warn); }

#feed { flex: 1; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
#msgs { max-width: var(--col); margin: 0 auto; padding: 18px 20px 4px; }
#composer { padding: 6px 14px calc(12px + env(safe-area-inset-bottom)); }
.box { position: relative; max-width: var(--col); margin: 0 auto; background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); padding: 10px 10px 8px 16px; transition: border-color .15s; }
.box:focus-within { border-color: var(--faint); }
#input { display: block; width: 100%; border: 0; outline: 0; resize: none; background: transparent; color: inherit; font: 16px/1.5 var(--sans); max-height: 38vh; min-height: 26px; padding: 3px 0; }
#input::placeholder { color: var(--faint); }
.bar { display: flex; align-items: center; gap: 2px; margin: 6px -2px 0 -8px; overflow-x: auto; scrollbar-width: none; }
.bar::-webkit-scrollbar { display: none; }
.grow { flex: 1; }
.send { width: 34px; height: 34px; flex: none; border: 0; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; transition: opacity .15s, transform .1s; }
.send:active { transform: scale(.94); }
.send:disabled { opacity: .3; cursor: default; }
.send svg { stroke-width: 2.2; }
.send .i-stop { display: none; fill: currentColor; stroke: none; }
.send.stop { background: var(--text); color: var(--bg); }
.send.stop .i-send { display: none; }
.send.stop .i-stop { display: block; }

/* ---------- empty state ---------- */
#empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; min-height: 100%; padding: 32px 20px 80px; text-align: center; }
#empty .mark { font-size: 38px; color: var(--accent); line-height: 1; animation: spin 14s linear infinite; }
#empty h2 { font: 400 28px/1.3 var(--serif); margin: 0; letter-spacing: .01em; }

/* ---------- messages ---------- */
.msg { margin: 0 0 16px; }
.msg.user { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.bubble { background: var(--bubble); padding: 9px 15px; border-radius: 20px 20px 6px 20px; max-width: min(85%, 640px); white-space: pre-wrap; word-break: break-word; }
.bubble img { display: block; max-width: 220px; max-height: 220px; border-radius: 12px; margin: 2px 0 6px; }
.img-ph { display: inline-block; font-size: 13px; color: var(--muted); margin-right: 6px; }
.cmd { font: 13px var(--mono); color: var(--accent); background: var(--accent-soft); border-radius: 8px; padding: 3px 10px; }
.cmdout { font: 12.5px/1.55 var(--mono); color: var(--muted); white-space: pre-wrap; word-break: break-word; margin: -6px 0 16px; padding-left: 12px; border-left: 2px solid var(--line); }
.note { text-align: center; font-size: 12.5px; color: var(--faint); margin: 4px 0 16px; display: flex; align-items: center; gap: 12px; }
.note::before, .note::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.note.err { color: var(--err); white-space: pre-wrap; text-align: left; display: block; background: rgba(194, 65, 59, .07); border-radius: 10px; padding: 9px 12px; font-family: var(--mono); font-size: 12.5px; }
.note.err::before, .note.err::after { display: none; }
.foot { font-size: 12px; color: var(--faint); margin: -8px 0 18px; font-variant-numeric: tabular-nums; }

.md { word-wrap: break-word; overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 .75em; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 1.2em 0 .5em; line-height: 1.35; font-weight: 600; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.2em; } .md h3 { font-size: 1.07em; } .md h4, .md h5, .md h6 { font-size: 1em; }
.md ul, .md ol { margin: 0 0 .75em; padding-left: 1.5em; }
.md li { margin: .2em 0; }
.md li > ul, .md li > ol { margin: .2em 0; }
.md a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-soft); }
.md a:hover { border-bottom-color: var(--accent); }
.md blockquote { margin: 0 0 .75em; padding: 2px 0 2px 14px; border-left: 3px solid var(--line); color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1.2em 0; }
.md code { font: .88em var(--mono); background: var(--code); border: 1px solid var(--line); padding: .05em .35em; border-radius: 5px; }
.md strong { font-weight: 600; }
.tbl { overflow-x: auto; margin: 0 0 .9em; border: 1px solid var(--line); border-radius: 10px; }
.md table { border-collapse: collapse; width: 100%; font-size: 14px; }
.md th, .md td { padding: 6px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.md th { background: var(--code); font-weight: 600; white-space: nowrap; }
.md tr:last-child td { border-bottom: 0; }
.md .center { text-align: center; } .md .right { text-align: right; }
.code { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin: 0 0 .9em; background: var(--code); }
.code .ch { display: flex; justify-content: space-between; align-items: center; padding: 4px 8px 4px 12px; font: 12px var(--mono); color: var(--faint); border-bottom: 1px solid var(--line); }
.code .cp { border: 0; background: none; color: var(--faint); font-size: 12px; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.code .cp:hover { color: var(--text); background: var(--chip); }
.code pre { margin: 0; padding: 10px 14px; overflow-x: auto; font: 13px/1.6 var(--mono); }
.code pre code { background: none; border: 0; padding: 0; font-size: inherit; }

.think { margin: 0 0 12px; color: var(--muted); font-size: 14px; }
.think > summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: 6px; color: var(--faint); font-size: 13px; }
.think > summary::-webkit-details-marker { display: none; }
.think > summary::before { content: "›"; transition: transform .15s; display: inline-block; }
.think[open] > summary::before { transform: rotate(90deg); }
.think .md { margin-top: 6px; padding-left: 12px; border-left: 2px solid var(--line); }
.think.live { display: flex; gap: 8px; align-items: baseline; font-size: 13px; color: var(--faint); }
.think.live .tt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }

/* tool calls */
.tool { margin: 0 0 6px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); font-size: 13.5px; }
.tool + :not(.tool) { margin-top: 14px; }
.tool > summary { list-style: none; display: flex; align-items: center; gap: 9px; padding: 7px 11px; cursor: pointer; min-width: 0; }
.tool > summary::-webkit-details-marker { display: none; }
.tool .st { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--faint); }
.tool.run .st { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.tool.ok .st { background: var(--ok); }
.tool.err .st { background: var(--err); }
.tool .tn { font-weight: 600; flex: none; }
.tool .ts { color: var(--muted); font: 12.5px var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tool .tb { border-top: 1px solid var(--line); padding: 9px 11px; max-height: 440px; overflow: auto; }
.tool .tb:empty { display: none; }
.ico { display: inline-grid; place-items: center; flex: none; }
.ico svg { width: 16px; height: 16px; }
a.rt { color: inherit; text-decoration: none; }
.tb pre, .card pre { margin: 0 0 8px; white-space: pre-wrap; word-break: break-word; font: 12.5px/1.55 var(--mono); }
.tb pre:last-child { margin-bottom: 0; }
.tb .lbl { font-size: 11.5px; color: var(--faint); margin: 0 0 3px; text-transform: uppercase; letter-spacing: .04em; }
.tb .out { color: var(--muted); }
.tb .out.e { color: var(--err); }
.diff { border-radius: 8px; overflow: hidden; }
.diff span { display: block; padding: 0 8px; }
.diff .add { color: var(--ok); background: rgba(47, 138, 88, .09); }
.diff .del { color: var(--err); background: rgba(194, 65, 59, .08); }
.diff .ctxl { color: var(--faint); }
.todos { list-style: none; margin: 0; padding: 0; }
.todos li { padding: 2px 0; }
.todos .done { color: var(--faint); text-decoration: line-through; }
.todos .doing { color: var(--accent); font-weight: 500; }

/* live / working */
.live-caret::after { content: ""; display: inline-block; width: 7px; height: 1em; background: var(--accent); vertical-align: -2px; margin-left: 2px; border-radius: 1px; animation: blink 1s steps(2) infinite; }
/* status row: always visible just above the input */
#working { max-width: var(--col); margin: 0 auto 7px; padding: 0 10px; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13.5px; min-width: 0; }
#working .spark { color: var(--accent); display: inline-block; animation: spin 2.4s linear infinite; font-size: 15px; flex: none; }
#wtext { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: linear-gradient(90deg, var(--muted) 0%, var(--text) 50%, var(--muted) 100%); background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent; animation: shimmer 2.2s linear infinite; }
#wlive { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--faint); flex: none; white-space: nowrap; }
#wlive i { width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
#wlive.on i { background: var(--ok); box-shadow: 0 0 0 3px rgba(47, 138, 88, .18); animation: pulse 1.2s ease-in-out infinite; }
#wlive.warn { color: var(--warn); white-space: normal; flex: 0 1 auto; }
#wlive.warn i { background: var(--warn); }
#wlive.bad { color: var(--err); }
#wlive.bad i { background: var(--err); }
#wtime { color: var(--faint); font-variant-numeric: tabular-nums; font-size: 12px; flex: none; }
#working.stalled .spark { animation-duration: 6s; color: var(--warn); }
/* thin progress sweep under the header while Claude is working */
#top { position: relative; }
#app.is-busy #top::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; pointer-events: none;
  background: linear-gradient(90deg, transparent, var(--accent), transparent) no-repeat; background-size: 35% 100%; animation: sweep 1.6s ease-in-out infinite; }
@keyframes sweep { from { background-position: -50% 0; } to { background-position: 150% 0; } }
.to-bottom { position: absolute; left: 50%; transform: translateX(-50%); bottom: 150px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--muted); box-shadow: var(--shadow); display: grid; place-items: center; cursor: pointer; z-index: 5; }

/* dock: permission / question / plan cards */
#dock { max-width: var(--col); margin: 0 auto; display: flex; flex-direction: column; gap: 8px; max-height: 55vh; overflow-y: auto; }
#dock:not(:empty) { margin-bottom: 8px; }
.card { background: var(--surface); border: 1px solid var(--accent); border-radius: 16px; padding: 12px 14px; box-shadow: var(--shadow); font-size: 14px; animation: rise .18s ease-out; }
.card.done { opacity: .5; pointer-events: none; }
.card .ph { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.card .ph b { color: var(--text); font-weight: 600; font-size: 14px; }
.card .ph .dotw { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.card .pd { margin-bottom: 6px; }
.card .pb { max-height: 26vh; overflow: auto; background: var(--code); border-radius: 10px; padding: 8px 10px; }
.card .pb pre:last-child { margin: 0; }
.card .md { max-height: 34vh; overflow: auto; background: var(--code); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.acts { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; flex-wrap: wrap; }
.q { margin-bottom: 10px; }
.q .qh { font-size: 12px; color: var(--faint); }
.q .qt { font-weight: 500; margin: 2px 0 8px; }
.opts { display: flex; flex-direction: column; gap: 6px; }
.opt { text-align: left; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 8px 12px; cursor: pointer; }
.opt small { display: block; color: var(--muted); font-size: 12.5px; }
.opt.on { border-color: var(--accent); background: var(--accent-soft); }
.card input.txt, .dlg input.txt { width: 100%; font: 15px var(--sans); padding: 8px 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--text); outline: none; margin-top: 6px; }
.card input.txt:focus, .dlg input.txt:focus { border-color: var(--accent); }

/* slash command popup & thumbnails */
#slash { position: absolute; left: 8px; right: 8px; bottom: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 4px; max-height: 260px; overflow-y: auto; z-index: 6; }
#slash button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 7px 10px; border-radius: 9px; font: 13.5px var(--mono); cursor: pointer; }
#slash button:hover, #slash button.sel { background: var(--chip); }
#thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
#thumbs:not(:empty) { margin-bottom: 8px; }
.att-chip { position: relative; display: flex; align-items: center; height: 56px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); overflow: hidden; }
.att-chip.pic { width: 56px; }
.att-chip.pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att-chip .fi { display: flex; align-items: center; gap: 8px; padding: 0 30px 0 10px; max-width: 230px; min-width: 0; }
.att-chip .fi svg { width: 20px; height: 20px; color: var(--accent); }
.att-chip .fm { display: flex; flex-direction: column; min-width: 0; }
.att-chip .fn { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-chip .fs { font-size: 11.5px; color: var(--faint); }
.att-chip .bar { position: absolute; left: 0; bottom: 0; height: 3px; width: 0; background: var(--accent); transition: width .2s; }
.att-chip.up img, .att-chip.up .fi { opacity: .5; }
.att-chip.err { border-color: var(--err); }
.att-chip.err .fs::after { content: " · 上传失败"; color: var(--err); }
.att-chip button { position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: var(--text); color: var(--bg); font-size: 12px; line-height: 20px; padding: 0; cursor: pointer; opacity: .85; }
.atts { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: min(85%, 640px); }
.att-img img { display: block; max-width: 220px; max-height: 220px; border-radius: 12px; border: 1px solid var(--line); }
.att-file { display: inline-flex; align-items: center; gap: 7px; max-width: 260px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--text); text-decoration: none; font-size: 13.5px; }
.att-file:hover { border-color: var(--faint); }
.att-file svg { width: 17px; height: 17px; color: var(--accent); }
.att-file span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-file.gone { opacity: .55; }
.att-file.gone span { text-decoration: line-through; }

/* dialog & toast */
dialog { border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--text); padding: 0; width: min(460px, calc(100vw - 28px)); max-height: min(78vh, 680px); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(0, 0, 0, .32); backdrop-filter: blur(2px); }
.dlg { display: flex; flex-direction: column; max-height: min(78vh, 680px); }
.dlg-h { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 8px 18px; font-weight: 600; }
.dlg-b { padding: 4px 18px 12px; overflow-y: auto; flex: 1; }
.dlg-f { padding: 10px 16px 16px; display: flex; gap: 8px; justify-content: flex-end; border-top: 1px solid var(--line); }
.rows { display: flex; flex-direction: column; }
.row { display: flex; align-items: center; gap: 10px; padding: 9px 6px; border-radius: 9px; cursor: pointer; text-decoration: none; color: inherit; border: 0; background: none; text-align: left; width: 100%; font-size: 14px; }
.row:hover { background: var(--chip); }
.row .rt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .rm { font-size: 12px; color: var(--faint); flex: none; }
.row svg { color: var(--faint); width: 16px; height: 16px; }
.sec { font-size: 12px; color: var(--faint); margin: 10px 6px 4px; }
.hint { font-size: 13px; color: var(--muted); line-height: 1.6; }
.hint code { font: 12.5px var(--mono); background: var(--code); padding: 1px 5px; border-radius: 5px; }
.kv { font: 12.5px var(--mono); background: var(--code); border-radius: 10px; padding: 8px 10px; word-break: break-all; margin: 4px 0 10px; display: flex; gap: 8px; align-items: center; }
.kv span { flex: 1; }
#toast { position: fixed; left: 50%; bottom: calc(110px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 13.5px; z-index: 50; box-shadow: var(--shadow); max-width: calc(100vw - 40px); animation: rise .18s ease-out; }

@keyframes pulse { 50% { opacity: .35; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes blink { to { visibility: hidden; } }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.only-mobile { display: none; }

@media (max-width: 760px) {
  .only-mobile { display: inline-grid; }
  #side { position: fixed; z-index: 30; top: 0; bottom: 0; left: 0; width: min(300px, 84vw); transform: translateX(-102%); transition: transform .24s cubic-bezier(.2, .8, .2, 1); box-shadow: var(--shadow); }
  #side.open { transform: none; }
  #scrim { display: block; position: fixed; inset: 0; z-index: 25; background: rgba(0, 0, 0, .3); opacity: 0; pointer-events: none; transition: opacity .2s; }
  #scrim.show { opacity: 1; pointer-events: auto; }
  #top { padding-left: 6px; }
  #msgs { padding: 12px 16px 4px; }
  #working { padding: 0 8px; margin-bottom: 6px; }
  #composer { padding: 4px 8px calc(8px + env(safe-area-inset-bottom)); }
  .box { border-radius: 20px; padding: 8px 8px 6px 14px; }
  select.pill { max-width: 112px; padding-left: 8px; }
  .bubble { max-width: 90%; }
  #empty h2 { font-size: 24px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
