/* 茶马古道AI 手机端聊天 —— 参考 Claude 手机端，简洁、以对话为主 */
:root {
  --paper: #f7f3ea;
  --paper-2: #efe9da;
  --ink: #28251f;
  --ink-soft: #575246;
  --muted: #8a8373;
  --line: #e3dccd;
  --cinnabar: #c0392b;
  --cinnabar-2: #a12d22;
  --brand: #324a4d;
  --bubble-user: #324a4d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; width: 100%; max-width: 100%;
  font-family: -apple-system, "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  background: var(--paper); color: var(--ink);
  overscroll-behavior: none; overflow-x: hidden;
}
body { display: flex; flex-direction: column; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.err { color: var(--cinnabar); font-size: 13px; margin-top: 6px; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* —— 登录 —— */
.setup { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; padding-top: calc(24px + var(--safe-top)); }
.setup-card { width: 100%; max-width: 360px; text-align: center; }
.seal { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 18px; background: var(--cinnabar);
  color: var(--paper); display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: 700;
  font-family: "Noto Serif SC", serif; box-shadow: 0 8px 24px rgba(192,57,43,.25); }
.setup-card h1 { font-family: "Noto Serif SC", serif; font-size: 1.5rem; margin: 0 0 4px; }
.setup-card .muted { margin: 0 0 22px; font-size: 14px; }
#key-input { width: 100%; padding: 13px 15px; border: 1px solid var(--line); border-radius: 14px; background: #fff;
  font-size: 15px; color: var(--ink); outline: none; }
#key-input:focus { border-color: var(--cinnabar); }
.btn-primary { width: 100%; margin-top: 12px; padding: 13px; border: 0; border-radius: 14px; background: var(--cinnabar);
  color: #fff; font-size: 15px; font-weight: 600; cursor: pointer; }
.btn-primary:active { background: var(--cinnabar-2); }
.btn-ghost { width: 100%; margin-top: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 14px;
  background: #fff; color: var(--ink-soft); font-size: 14px; }
.link { display: inline-block; margin-top: 16px; color: var(--cinnabar-2); font-size: 13px; text-decoration: none; }
.link2 { display: inline-block; margin-top: 12px; border: 0; background: transparent; color: var(--cinnabar-2); font-size: 13px; }
/* 登录方式分段 */
.seg { display: flex; gap: 4px; background: var(--paper-2); border-radius: 12px; padding: 4px; margin: 18px 0 16px; }
.seg-btn { flex: 1; padding: 9px 0; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 14px; font-weight: 600; }
.seg-btn.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.pane { display: flex; flex-direction: column; }
.pane input { width: 100%; margin-bottom: 10px; padding: 13px 15px; border: 1px solid var(--line); border-radius: 14px; background: #fff; font-size: 15px; color: var(--ink); outline: none; }
.pane input:focus { border-color: var(--cinnabar); }
.pane .btn-primary { margin-top: 2px; }

/* —— 主界面 —— */
.app { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between;
  padding: calc(8px + var(--safe-top)) 14px 8px; background: rgba(247,243,234,.85);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: 8px; }
.brand-seal { width: 28px; height: 28px; border-radius: 8px; background: var(--cinnabar); color: var(--paper);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-family: "Noto Serif SC", serif; font-size: 15px; }
.brand-name { font-family: "Noto Serif SC", serif; font-weight: 700; font-size: 16px; }
.top-actions { display: flex; gap: 4px; }
.icon-btn { position: relative; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center;
  border: 0; background: transparent; color: var(--ink-soft); border-radius: 10px; }
.icon-btn:active { background: var(--paper-2); }
.update-dot { position: absolute; top: 6px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--cinnabar); border: 1.5px solid var(--paper); }

/* 设置里的行 */
.row-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 14px 0 4px; }
.row-title { font-size: 15px; color: var(--ink); }
.row-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.mini-btn { flex-shrink: 0; padding: 8px 16px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--cinnabar-2); font-size: 13px; font-weight: 600; }
.mini-btn.has-update { background: var(--cinnabar); color: #fff; border-color: var(--cinnabar); }
.update-msg { font-size: 13px; color: var(--ink-soft); margin: 2px 0 8px; line-height: 1.5; }

/* 消息区 */
.msgs { flex: 1; overflow-y: auto; padding: 18px 14px 8px; display: flex; flex-direction: column; gap: 18px; -webkit-overflow-scrolling: touch; }
.welcome { margin: auto; text-align: center; color: var(--muted); max-width: 280px; }
.welcome .seal { width: 56px; height: 56px; font-size: 1.7rem; margin-bottom: 12px; }
.welcome h2 { font-family: "Noto Serif SC", serif; color: var(--ink); font-size: 1.2rem; margin: 0 0 6px; }
.welcome p { font-size: 14px; line-height: 1.6; margin: 0; }

.row { display: flex; }
.row.user { justify-content: flex-end; }
.bubble { max-width: 86%; font-size: 15.5px; line-height: 1.62; word-wrap: break-word; }
.row.user .bubble { background: var(--bubble-user); color: #fff; padding: 10px 14px; border-radius: 18px 18px 4px 18px; }
.row.ai .bubble { color: var(--ink); padding: 2px 2px; }
.row.ai .bubble.thinking { color: var(--muted); }

/* 轻量 markdown */
.bubble p { margin: 0 0 .55em; } .bubble > :last-child { margin-bottom: 0; }
.bubble strong { font-weight: 700; }
.bubble em { font-style: italic; }
.bubble a { color: var(--cinnabar-2); word-break: break-all; }
.bubble .h { font-weight: 700; margin: .6em 0 .35em; }
.bubble ul, .bubble ol { margin: .3em 0 .6em; padding-left: 1.3em; }
.bubble li { margin: .18em 0; }
.bubble code { background: rgba(40,53,56,.08); border-radius: 4px; padding: 1px 5px; font-size: .9em;
  font-family: ui-monospace, Menlo, monospace; }
.bubble pre { background: #1f2a2c; color: #e8e6e1; border-radius: 12px; padding: 12px 14px; margin: .5em 0; overflow-x: auto; }
.bubble pre code { background: none; padding: 0; font-size: .85em; line-height: 1.5; white-space: pre; }

.typing { display: inline-flex; gap: 4px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); opacity: .5; animation: blink 1.1s infinite; }
.typing i:nth-child(2) { animation-delay: .18s; } .typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%,100% { transform: translateY(0); opacity: .35; } 50% { transform: translateY(-4px); opacity: .9; } }

/* 输入区 */
.composer-wrap { padding: 8px 12px calc(8px + var(--safe-bottom)); background: var(--paper); border-top: 1px solid var(--line); }
.composer { display: flex; align-items: flex-end; gap: 8px; background: #fff; border: 1px solid var(--line);
  border-radius: 24px; padding: 6px 6px 6px 8px; }
#input { flex: 1; border: 0; outline: none; resize: none; background: transparent; font-size: 16px; line-height: 1.4;
  color: var(--ink); max-height: 140px; padding: 8px 2px; font-family: inherit; }
.mic-btn, .send-btn { flex-shrink: 0; width: 40px; height: 40px; border-radius: 50%; border: 0;
  display: flex; align-items: center; justify-content: center; }
.mic-btn { background: var(--paper-2); color: var(--ink-soft); }
.mic-btn.active { background: var(--cinnabar); color: #fff; animation: pulse 1.3s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(192,57,43,.4); } 50% { box-shadow: 0 0 0 8px rgba(192,57,43,0); } }
.send-btn { background: var(--cinnabar); color: #fff; }
.send-btn:disabled { background: var(--paper-2); color: var(--muted); }
.voice-hint { text-align: center; font-size: 12px; color: var(--cinnabar-2); padding: 6px 0 0; }
/* 图片附件 */
.file-hidden { display: none; }
.attach { display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 4px 8px; }
.attach .chip { position: relative; }
.attach .chip img { width: 54px; height: 54px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); display: block; }
.attach .chip .rm { position: absolute; top: -7px; right: -7px; width: 20px; height: 20px; border-radius: 50%; border: 0; background: var(--ink, #28251f); color: #fff; font-size: 12px; line-height: 20px; padding: 0; }
.bubble .imgs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.bubble .imgs img { width: 130px; max-width: 62vw; border-radius: 10px; display: block; }

/* 设置面板 */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; }
.sheet-bg { position: absolute; inset: 0; background: rgba(26,24,20,.35); }
.sheet-card { position: relative; width: 100%; background: var(--paper); border-radius: 20px 20px 0 0;
  padding: 10px 20px calc(24px + var(--safe-bottom)); animation: up .25s ease; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
.sheet-handle { width: 40px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 14px; }
.sheet-card h3 { font-family: "Noto Serif SC", serif; margin: 0 0 16px; }
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
#model-select { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff;
  font-size: 15px; color: var(--ink); margin-bottom: 8px; }

/* 账号 / 余额 / 充值 视图 */
.view { position: fixed; inset: 0; z-index: 40; background: var(--paper); display: flex; flex-direction: column; }
.acc-scroll { flex: 1; overflow-y: auto; padding: 14px 14px calc(24px + var(--safe-bottom)); -webkit-overflow-scrolling: touch; }
.acc-card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin-bottom: 14px; }
.acc-h { font-family: "Noto Serif SC", serif; font-weight: 700; font-size: 15px; color: var(--ink); margin-bottom: 12px; }
.acc-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-top: 1px solid var(--paper-2); font-size: 14px; color: var(--ink-soft); }
.acc-row:first-of-type { border-top: 0; }
.acc-row b { color: var(--ink); font-weight: 600; }
.acc-det { margin-top: 8px; border-top: 1px solid var(--paper-2); padding-top: 10px; }
.acc-det summary { font-size: 14px; color: var(--cinnabar-2); cursor: pointer; list-style: none; }
.acc-det summary::-webkit-details-marker { display: none; }
.acc-det input { width: 100%; margin-top: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; font-size: 15px; color: var(--ink); outline: none; }
.acc-det input:focus { border-color: var(--cinnabar); }
.acc-det .btn-primary { margin-top: 12px; }
.acc-bal { display: flex; gap: 10px; text-align: center; }
.acc-bal > div { flex: 1; background: var(--paper); border-radius: 12px; padding: 12px 6px; }
.acc-bal-num { font-size: 18px; font-weight: 700; color: var(--cinnabar-2); }
.acc-bal-lbl { font-size: 11px; color: var(--muted); margin-top: 3px; }
.acc-card .mini-btn { margin-top: 12px; }
.acc-sub { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.acc-inline { display: flex; gap: 8px; }
.acc-inline input { flex: 1; min-width: 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; font-size: 15px; color: var(--ink); outline: none; background: #fff; }
.acc-inline input:focus { border-color: var(--cinnabar); }
.acc-btn-sm { width: auto; flex-shrink: 0; padding-left: 18px; padding-right: 18px; }
.acc-msg { font-size: 13px; margin-top: 8px; color: var(--ink-soft); }
.acc-msg.ok { color: var(--brand); } .acc-msg.err { color: var(--cinnabar-2); }
.acc-qr { margin-top: 14px; text-align: center; }
.acc-qr img { width: 220px; height: 220px; max-width: 70vw; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
.acc-qr-amt { font-size: 18px; font-weight: 700; color: var(--cinnabar-2); margin-top: 8px; }
.acc-qr-tip { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* 快捷提示词 */
.chips { display: flex; gap: 7px; overflow-x: auto; padding: 0 2px 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; padding: 7px 13px; border: 1px solid var(--line); border-radius: 999px; background: #fff;
  color: var(--ink-soft); font-size: 13px; white-space: nowrap; }
.chip:active { background: var(--paper-2); }

/* 发送按钮的「停止」态 */
.send-btn.stop { background: var(--ink-700, #46423a); }
.send-btn.stop svg { display: none; }
.send-btn.stop::after { content: ''; width: 12px; height: 12px; background: #fff; border-radius: 3px; }

/* 会话抽屉（新旧对话窗口） */
.drawer { position: fixed; inset: 0; z-index: 50; display: flex; }
.drawer-bg { position: absolute; inset: 0; background: rgba(26,24,20,.4); }
.drawer-panel { position: relative; width: 82%; max-width: 330px; height: 100%; background: var(--paper);
  display: flex; flex-direction: column; box-shadow: 2px 0 16px rgba(0,0,0,.12); animation: dwIn .22s ease; }
@keyframes dwIn { from { transform: translateX(-100%); } to { transform: none; } }
.drawer-top { display: flex; align-items: center; justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 12px; border-bottom: 1px solid var(--line); }
.drawer-title { font-family: "Noto Serif SC", serif; font-weight: 700; font-size: 16px; }
.dw-list { flex: 1; overflow-y: auto; padding: 8px; }
.dw-item { display: flex; align-items: center; gap: 6px; padding: 11px 12px; border-radius: 12px; margin-bottom: 2px; }
.dw-item.on { background: var(--paper-2); }
.dw-item:active { background: var(--paper-2); }
.dw-it-main { flex: 1; min-width: 0; }
.dw-it-title { font-size: 14.5px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dw-it-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.dw-del { flex-shrink: 0; width: 28px; height: 28px; border: 0; background: transparent; color: var(--ink-300); font-size: 13px; border-radius: 8px; }
.dw-del:active { background: var(--cinnabar-50, #fdf4f2); color: var(--cinnabar-2); }
