/* 信鸽的全部样式：深色、手机优先。颜色都在 :root 里。 */
:root {
  --bg: #0f1115;
  --panel: #171a21;
  --border: #262b36;
  --text: #e6e8ee;
  --muted: #8b93a7;
  --accent: #f2994a;
  --accent-text: #1a1206;
  --bubble-ai: #1f2430;
  --danger: #e5484d;
  --tool: #4c8dff;
  --ok: #46a758;
  --radius: 16px;
  --font: -apple-system, "PingFang SC", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --app-h: 100dvh;
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
body { font: 15px/1.5 var(--font); -webkit-text-size-adjust: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- 主框架 ---------- */
.app { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h); display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px; flex: none;
  padding: calc(env(safe-area-inset-top) + 6px) 12px 8px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.icon-btn { width: 40px; height: 40px; border-radius: 12px; font-size: 20px; flex: none; }
.icon-btn:active { background: var(--border); }
.title-wrap { flex: 1; min-width: 0; text-align: center; }
.title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 10px; height: 10px; border-radius: 50%; margin: 0 15px; flex: none; background: var(--muted); }
.dot.thinking { background: var(--accent); animation: breathe 1.4s ease-in-out infinite; }
.dot.running_tool { background: var(--tool); animation: breathe 1.4s ease-in-out infinite; }
.dot.asking { background: var(--accent); animation: blink .6s steps(2) infinite; }
@keyframes breathe { 50% { opacity: .35; transform: scale(.8); } }
@keyframes blink { 50% { opacity: .15; } }
.files-btn { font-size: 18px; }
.files-btn + .dot { margin-left: 2px; }
.conn-bar { flex: none; font-size: 12px; text-align: center; padding: 3px; background: #3a2a14; color: var(--accent); }

.messages { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 12px 12px 4px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.empty { text-align: center; color: var(--muted); margin-top: 22vh; }
.empty img { width: 64px; height: 64px; border-radius: 16px; opacity: .85; }

/* ---------- 消息气泡 ---------- */
.msg { display: flex; margin: 8px 0; }
.msg.user { justify-content: flex-end; }
.bubble { max-width: 88%; min-width: 0; padding: 9px 13px; border-radius: var(--radius); overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--accent); color: var(--accent-text); border-bottom-right-radius: 6px; }
.utext { white-space: pre-wrap; }

/* 用户气泡里的附件：图片缩略图、文件小卡片 */
.atts { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 6px; }
.atts:last-child { margin-bottom: 2px; }
.att-img img { display: block; max-width: 200px; max-height: 200px; border-radius: 10px; object-fit: cover; }
.att-file { display: flex; align-items: center; gap: 6px; max-width: 100%; padding: 6px 10px; border-radius: 10px; background: #0000001f; color: inherit; text-decoration: none; font-size: 13px; }
.att-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { flex: none; opacity: .7; font-size: 12px; }

/* Claude 回复里的文件卡片和图片 */
.fchip { display: inline-block; max-width: 100%; padding: 0 7px; border-radius: 7px; background: #ffffff14; color: var(--accent); text-decoration: none; vertical-align: bottom; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.md code .fchip { background: none; padding: 0; }
.img-link { display: block; margin-top: 6px; }
.inline-img { display: block; max-width: 100%; max-height: 320px; object-fit: contain; border-radius: 10px; background: #0003; }
.msg.assistant .bubble { background: var(--bubble-ai); border-bottom-left-radius: 6px; width: 100%; max-width: 100%; }
.meta { font-size: 11px; color: var(--muted); margin: 2px 4px 0; }
.msg.assistant { flex-direction: column; align-items: flex-start; }
.typing::after { content: "▍"; color: var(--accent); animation: blink 1s steps(2) infinite; }

/* Markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol { margin: 6px 0; }
.md ul, .md ol { padding-left: 22px; }
.md h3, .md h4 { margin: 10px 0 4px; font-size: 15px; }
.md a { color: var(--accent); }
.md code { font: 13px var(--mono); background: #0003; padding: 1px 5px; border-radius: 5px; }
.code { position: relative; margin: 8px 0; background: #0b0d11; border: 1px solid var(--border); border-radius: 10px; }
.code pre { margin: 0; padding: 10px 12px; overflow-x: auto; font: 12.5px/1.45 var(--mono); }
.code pre code { background: none; padding: 0; }
.copy { position: absolute; top: 4px; right: 4px; font-size: 11px; color: var(--muted); background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; }
.part + .part { margin-top: 6px; }
.tbl { overflow-x: auto; margin: 8px 0; }
.tbl table { border-collapse: collapse; font-size: 13.5px; }
.tbl th, .tbl td { border: 1px solid var(--border); padding: 5px 9px; text-align: left; white-space: nowrap; }
.tbl th { background: #0003; font-weight: 600; }

/* 思考中：三个跳动的小圆点 */
.thinking { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: hop 1.2s ease-in-out infinite; }
.dots i:nth-child(2) { animation-delay: .15s; }
.dots i:nth-child(3) { animation-delay: .3s; }
@keyframes hop { 0%, 60%, 100% { transform: translateY(0); opacity: .5; } 30% { transform: translateY(-5px); opacity: 1; } }

/* 反问的记录 */
.qa { font-size: 13px; color: var(--muted); border-left: 2px solid var(--tool); padding-left: 8px; }
.qa-cap { margin-bottom: 2px; }
.qa-line { color: var(--text); }

/* 工具活动条 */
.tools { border-left: 2px solid var(--border); padding-left: 8px; margin: 4px 0; }
.tools-head { font-size: 12px; color: var(--muted); display: block; padding: 2px 0; }
.tools.folded .tool { display: none; }
.tool { font-size: 13px; color: var(--muted); }
.tool-row { display: flex; align-items: center; gap: 6px; padding: 2px 0; width: 100%; text-align: left; min-width: 0; }
.tool-row .lbl { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-ico { width: 14px; height: 14px; flex: none; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; }
.tool.running .tool-ico { border: 2px solid var(--tool); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; }
.tool.ok .tool-ico::before { content: "✓"; color: var(--ok); }
.tool.fail .tool-ico::before { content: "✕"; color: var(--danger); }
@keyframes spin { to { transform: rotate(360deg); } }
.tool-detail { margin: 2px 0 6px; }
.tool-cap { font-size: 11px; color: var(--muted); margin: 6px 0 2px; }
.tool pre { margin: 0; padding: 8px; background: #0b0d11; border-radius: 8px; font: 12px/1.4 var(--mono); white-space: pre-wrap; max-height: 220px; overflow: auto; color: var(--text); }

/* 确认卡片 */
.ask { margin: 10px 0; padding: 12px; border: 1.5px solid var(--accent); border-radius: var(--radius); background: var(--panel); }
.ask h4 { margin: 0 0 8px; font-size: 15px; }
.ask pre { margin: 0 0 10px; padding: 8px 10px; background: #0b0d11; border-radius: 8px; font: 12.5px/1.45 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 180px; overflow-y: auto; }
.ask-btns { display: flex; gap: 10px; }
.ask-btns .btn { flex: 1; }
.ask.question { border-color: var(--tool); }
.q-sec { margin: 0 0 12px; }
.q-head { font-size: 12px; color: var(--tool); font-weight: 600; margin-bottom: 2px; }
.q-text { margin-bottom: 8px; }
.q-opt { display: grid; grid-template-columns: 18px 1fr; column-gap: 8px; width: 100%; text-align: left; padding: 8px 10px; margin-bottom: 6px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.q-opt small { grid-column: 2; color: var(--muted); font-size: 12px; }
.q-mark { width: 16px; height: 16px; margin-top: 3px; border: 1.5px solid var(--muted); border-radius: 50%; }
.q-opt.multi .q-mark { border-radius: 4px; }
.q-opt.on { border-color: var(--tool); }
.q-opt.on .q-mark { border-color: var(--tool); background: var(--tool); box-shadow: inset 0 0 0 3px var(--bg); }
.q-other { width: 100%; height: 40px; font-size: 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--text); padding: 0 12px; outline: none; }
.ask .always { display: block; margin: 10px auto 0; font-size: 12px; color: var(--muted); text-decoration: underline; }

/* ---------- 输入栏 ---------- */
.composer {
  position: relative; flex: none; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--border);
}
.plus-btn { width: 40px; height: 40px; border-radius: 50%; flex: none; font-size: 22px; color: var(--muted); border: 1px solid var(--border); background: var(--bg); }
.plus-menu { position: absolute; left: 10px; bottom: calc(100% + 6px); z-index: 5; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 4px 16px #0009; overflow: hidden; }
.plus-menu button { display: block; width: 100%; padding: 11px 18px; text-align: left; }
.plus-menu button + button { border-top: 1px solid var(--border); }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

/* 待发送横条 */
.att-bar { flex: 0 0 100%; display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0; }
.att-item { position: relative; height: 56px; border-radius: 10px; background: var(--bg); border: 1px solid var(--border); }
.att-item.image { width: 56px; }
.att-item.image img { width: 100%; height: 100%; object-fit: cover; border-radius: 9px; }
.att-item.file { display: flex; align-items: center; gap: 6px; max-width: 70%; padding: 0 22px 0 10px; font-size: 12px; }
.att-item .att-size { color: var(--muted); }
.att-x { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; background: #000c; color: #fff; font-size: 11px; line-height: 20px; text-align: center; }
.att-status { flex: 0 0 100%; font-size: 12px; color: var(--muted); }
.composer textarea {
  flex: 1; min-width: 0; resize: none; max-height: calc(6 * 1.5em + 18px);
  font: 16px/1.5 var(--font); color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 20px; padding: 8px 14px; outline: none;
}
.composer textarea:focus { border-color: #3a4152; }
.send-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); flex: none; display: flex; align-items: center; justify-content: center; }
.send-btn:disabled { opacity: .4; cursor: default; }
.to-bottom { position: absolute; right: 14px; bottom: calc(100% + 10px); width: 38px; height: 38px; border-radius: 50%; background: var(--panel); border: 1px solid var(--border); font-size: 18px; box-shadow: 0 2px 10px #0008; }
.to-bottom.unseen::after { content: ""; position: absolute; top: 1px; right: 1px; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.ico-send { width: 20px; height: 20px; fill: none; stroke: var(--accent-text); stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.ico-stop { display: none; width: 14px; height: 14px; border-radius: 3px; background: #fff; }
.send-btn.stop { background: var(--danger); }
.send-btn.stop .ico-send { display: none; }
.send-btn.stop .ico-stop { display: block; }

/* ---------- 通用按钮 ---------- */
.btn { height: 42px; padding: 0 16px; border-radius: 12px; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger-outline { border: 1.5px solid var(--danger); color: var(--danger); }
.btn.outline { border: 1.5px solid var(--border); color: var(--muted); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.link-btn { color: var(--accent); font-size: 14px; padding: 6px 4px; }
.link-btn.danger { color: var(--danger); }
.link-btn.strong { font-weight: 600; }
.link-btn.small, .small { font-size: 12px; }
.muted { color: var(--muted); }

/* 首次进入对话时的“开启通知”提示条 */
.tip { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 8px; margin: 0 0 10px; padding: 8px 10px 8px 12px; font-size: 13px; border-radius: 12px; background: #2a2f3b; color: var(--text); }
.tip span { flex: 1 1 180px; }
.tip-x { color: var(--muted); padding: 2px 6px; }

/* ---------- 抽屉 ---------- */
.mask { position: fixed; inset: 0; background: #0009; z-index: 10; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: min(82vw, 330px); z-index: 11;
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; transform: translateX(-105%); transition: transform .22s ease;
  padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom);
}
.drawer.open { transform: none; }
.drawer-head { padding: 12px; }
.drawer-tools { display: flex; justify-content: space-between; align-items: center; padding: 0 14px; color: var(--muted); font-size: 13px; }
.conv-list { list-style: none; margin: 0; padding: 4px 8px; flex: 1; overflow-y: auto; }
.conv-item { display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 12px; }
.conv-item.active { background: var(--bubble-ai); }
.conv-main { flex: 1; min-width: 0; }
.conv-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-run { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.conv-del { display: none; color: var(--danger); font-size: 13px; border: 1px solid var(--danger); border-radius: 8px; padding: 2px 8px; flex: none; }
.conv-list.editing .conv-del { display: block; }
.conv-list.editing .conv-title { text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }
.always-row { display: flex; align-items: center; gap: 8px; margin: 6px 14px 0; padding: 6px 10px; font-size: 12px; color: var(--muted); background: var(--bg); border-radius: 10px; }
.always-row span { flex: 1; min-width: 0; }
.notify-row { font-size: 14px; margin-bottom: 8px; }
.drawer-foot { padding: 10px 14px; border-top: 1px solid var(--border); }

/* ---------- 新对话弹层 ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; background: #0009; display: flex; align-items: flex-end; }
.sheet {
  width: 100%; max-height: 88%; display: flex; flex-direction: column; background: var(--panel);
  border-radius: 18px 18px 0 0; padding: 8px 14px calc(14px + env(safe-area-inset-bottom));
}
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 0 10px; }
.sheet-label { font-size: 12px; color: var(--muted); margin: 8px 2px 6px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 2px; font-size: 13px; }
.crumbs button { color: var(--accent); padding: 2px 4px; }
.crumbs span { color: var(--muted); }
.dir-list { list-style: none; margin: 6px 0 0; padding: 0; overflow-y: auto; min-height: 120px; max-height: 40vh; border: 1px solid var(--border); border-radius: 12px; }
.dir-list li button { display: flex; width: 100%; padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; gap: 8px; }
.dir-list li:last-child button { border-bottom: 0; }
.dir-list .up { color: var(--muted); }
.dir-list .none { padding: 12px; color: var(--muted); font-size: 13px; }
/* 文件面板 */
.file-list { max-height: 60vh; }
.file-row { position: relative; display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.file-list li:last-child { border-bottom: 0; }
.file-open { flex: 1; min-width: 0; display: flex; gap: 8px; padding: 10px 4px 10px 12px; color: inherit; text-decoration: none; }
.file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { flex: none; color: var(--muted); font-size: 12px; }
.file-list .file-more { flex: none; width: 40px; height: 40px; padding: 0; border-bottom: 0; justify-content: center; align-items: center; color: var(--muted); font-size: 18px; }
.file-menu { display: none; position: absolute; right: 8px; top: 38px; z-index: 2; background: var(--bubble-ai); border: 1px solid var(--border); border-radius: 10px; }
.file-menu a { display: block; padding: 8px 18px; color: var(--text); text-decoration: none; }
.file-row.menu-open .file-menu { display: block; }
.seg { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 7px 0; border-radius: 9px; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--bubble-ai); color: var(--text); font-weight: 600; }

.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; background: #000c; padding: 8px 14px; border-radius: 10px; font-size: 13px; max-width: 90vw; }

/* ---------- 登录页 ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 16px; }
.login-card { width: min(340px, 100%); background: var(--panel); border: 1px solid var(--border); border-radius: 20px; padding: 28px 22px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-logo { width: 72px; height: 72px; border-radius: 18px; margin: 0 auto; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.login-card input { height: 44px; font-size: 16px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); color: var(--text); padding: 0 14px; outline: none; }
.login-err { margin: 0; min-height: 1.5em; color: var(--danger); font-size: 13px; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
