:root {
  --bg: #ededed; --bar: #f7f7f7; --line: #dcdcdc; --text: #111; --muted: #888;
  --me: #95ec69; --me-text: #111; --them: #fff; --them-text: #111;
  --accent: #07c160; --accent-fg: #fff; --bad: #fa5151; --warn: #ff9900; --ok: #07c160;
  --card: #fff; --sheet: #f7f7f7;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111; --bar: #191919; --line: #2c2c2c; --text: #e6e6e6; --muted: #8a8a8a;
    --me: #3eb575; --me-text: #06180d; --them: #2c2c2c; --them-text: #e6e6e6;
    --card: #1f1f1f; --sheet: #191919;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
}
#app { height: 100vh; height: 100dvh; max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; background: var(--bg); }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
.bar {
  flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 12px; min-height: 52px;
  background: var(--bar); border-bottom: 1px solid var(--line);
}
.bar .title { flex: 1; min-width: 0; text-align: center; }
.bar .title b { display: block; font-size: 17px; font-weight: 600; line-height: 1.2; }
.bar .title small { display: block; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .title small.live { color: var(--ok); }
.icon-btn { width: 40px; height: 40px; border-radius: 8px; font-size: 22px; line-height: 40px; text-align: center; }
.icon-btn:active { background: var(--line); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 4px; vertical-align: 1px; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--bad); }

/* 会话列表 */
.list { flex: 1; overflow-y: auto; background: var(--card); }
.row { display: flex; gap: 12px; align-items: center; padding: 12px 16px; width: 100%; text-align: left; border-bottom: 1px solid var(--line); }
.row:active { background: var(--bg); }
.row .meta { flex: 1; min-width: 0; }
.row .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.row .top b { font-size: 17px; font-weight: 500; }
.row .top span { font-size: 12px; color: var(--muted); }
.row .prev { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar { flex: none; width: 44px; height: 44px; border-radius: 6px; background: #1f6feb center/70% no-repeat; }
.avatar.codex { background-color: #10a37f; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 40 40'%3E%3Crect x='9' y='12' width='22' height='17' rx='5' fill='none' stroke='%23fff' stroke-width='2.4'/%3E%3Ccircle cx='16' cy='20' r='2.2' fill='%23fff'/%3E%3Ccircle cx='24' cy='20' r='2.2' fill='%23fff'/%3E%3Cpath d='M20 12V8' stroke='%23fff' stroke-width='2.4' stroke-linecap='round'/%3E%3Ccircle cx='20' cy='7' r='1.8' fill='%23fff'/%3E%3C/svg%3E"); }
.avatar.me { background-color: #576b95; color: #fff; text-align: center; line-height: 44px; font-size: 16px; }
.badge { background: var(--bad); color: #fff; border-radius: 10px; font-size: 12px; min-width: 20px; padding: 0 6px; text-align: center; line-height: 20px; display: inline-block; }
.badge.q { background: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 60px 16px; }

/* 聊天 */
.chat { flex: 1; overflow-y: auto; padding: 12px 12px 8px; overscroll-behavior: contain; }
.stamp { text-align: center; font-size: 12px; color: var(--muted); margin: 14px 0 8px; }
.note { text-align: center; font-size: 12px; color: var(--muted); margin: 4px auto; max-width: 86%; word-break: break-word; }
.note.prog { text-align: left; background: none; margin: 3px 0 3px 52px; max-width: calc(100% - 64px); }
.msg { display: flex; gap: 8px; margin: 10px 0; align-items: flex-start; }
.msg.me { flex-direction: row-reverse; }
.bubble {
  position: relative; max-width: 74%; padding: 9px 12px; border-radius: 6px; word-break: break-word; white-space: pre-wrap;
  background: var(--them); color: var(--them-text);
}
.msg.me .bubble { background: var(--me); color: var(--me-text); }
.bubble::before { content: ""; position: absolute; top: 14px; width: 10px; height: 10px; background: inherit; transform: rotate(45deg); }
.msg:not(.me) .bubble::before { left: -4px; }
.msg.me .bubble::before { right: -4px; }
.bubble.bad { background: #fde7e7; color: #7a1f1f; }
.bubble.warn { background: #fff4e0; color: #5c3b00; }
@media (prefers-color-scheme: dark) { .bubble.bad { background: #3a1f1f; color: #ffd6d6; } .bubble.warn { background: #3a2c14; color: #ffe2b3; } }
.bubble.pic { padding: 4px; background: var(--them); }
.msg.me .bubble.pic { background: var(--me); }
.pic img { display: block; max-width: 100%; max-height: 320px; border-radius: 4px; }
.bubble .cap { margin-top: 6px; }
.bubble .def { margin-top: 6px; padding-top: 6px; border-top: 1px dashed rgba(128,128,128,.4); font-size: 13px; opacity: .8; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.opts button { background: var(--accent); color: var(--accent-fg); border-radius: 6px; padding: 7px 14px; font-size: 15px; }
.opts button.alt { background: rgba(128,128,128,.25); color: inherit; }
.tag { display: inline-block; font-size: 11px; border-radius: 4px; padding: 0 6px; margin-left: 6px; background: rgba(128,128,128,.25); vertical-align: 1px; }
.tag.done { background: var(--ok); color: #fff; }
.new-pill { position: absolute; left: 50%; bottom: 76px; transform: translateX(-50%); background: var(--accent); color: #fff; border-radius: 16px; padding: 5px 14px; font-size: 13px; box-shadow: 0 2px 8px rgba(0,0,0,.25); }
.new-pill[hidden] { display: none; }

/* 输入区 */
.composer { flex: none; background: var(--bar); border-top: 1px solid var(--line); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
.composer .line { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea {
  flex: 1; font: inherit; color: var(--text); background: var(--card); border: 0; border-radius: 6px; padding: 9px 10px;
  resize: none; max-height: 112px; min-height: 40px; line-height: 1.4;
}
.composer textarea:focus { outline: none; }
.plus { flex: none; width: 40px; height: 40px; border: 1.5px solid var(--text); border-radius: 50%; font-size: 24px; line-height: 36px; text-align: center; opacity: .85; }
.send { flex: none; height: 40px; padding: 0 16px; border-radius: 6px; background: var(--accent); color: var(--accent-fg); }
.send[hidden], .plus[hidden] { display: none; }
.panel { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px 6px; padding: 14px 4px 6px; }
.panel[hidden] { display: none; }
.panel button { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.panel .ic { width: 56px; height: 56px; border-radius: 12px; background: var(--card); font-size: 26px; line-height: 56px; text-align: center; color: var(--text); }
.panel button:active .ic { background: var(--line); }

/* 弹层 */
.mask { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; padding: 24px; z-index: 20; }
.mask[hidden] { display: none; }
.dialog { background: var(--card); border-radius: 12px; width: 100%; max-width: 340px; padding: 20px 18px 14px; }
.dialog h3 { margin: 0 0 6px; font-size: 17px; }
.dialog p { margin: 0 0 12px; font-size: 13px; color: var(--muted); }
.dialog input { width: 100%; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.dialog .err { color: var(--bad); font-size: 13px; min-height: 18px; margin-top: 6px; }
.dialog .btns { display: flex; gap: 10px; margin-top: 10px; }
.dialog .btns button { flex: 1; height: 42px; border-radius: 8px; background: var(--bg); }
.dialog .btns button.ok { background: var(--accent); color: #fff; }
.viewer { position: fixed; inset: 0; background: #000; z-index: 30; display: flex; align-items: center; justify-content: center; }
.viewer[hidden] { display: none; }
.viewer img { max-width: 100%; max-height: 100%; }
.toast { position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); background: rgba(0,0,0,.78); color: #fff; padding: 9px 16px; border-radius: 8px; font-size: 14px; max-width: 86%; text-align: center; z-index: 25; }
.toast[hidden] { display: none; }
form.login { display: flex; flex-direction: column; gap: 12px; padding: 16vh 24px 0; }
form.login h1 { margin: 0 0 8px; font-size: 26px; }
form.login input { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
form.login button { height: 46px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 17px; }
.err { color: var(--bad); font-size: 14px; min-height: 20px; }
