/* 泠依手机端 · 极简黑白（跟随系统深浅色）
   纯色面、细边框、无阴影噪点，只留一点圆角和顺手的动效。
   配色通过 CSS 变量切换：系统 prefers-color-scheme，或原生侧注入 data-theme。 */

:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f1f1f2;
  --ink: #111111;
  --ink-soft: #4a4a4c;
  --muted: #8e8e93;
  --line: #e5e5e7;
  --line-strong: #d4d4d6;
  --mine-bg: #111111;
  --mine-ink: #ffffff;
  --peer-bg: #ffffff;
  --peer-ink: #111111;
  --peer-border: #e5e5e7;
  --accent: #111111;
  --accent-ink: #ffffff;
  --danger: #c0392b;
  --overlay: rgba(0, 0, 0, 0.28);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  --radius: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  color-scheme: light dark;
}

/* 系统深色（除非页面被原生侧指定为 light） */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0c;
    --surface: #171718;
    --surface-2: #202022;
    --ink: #f2f2f3;
    --ink-soft: #c9c9cc;
    --muted: #8c8c90;
    --line: #2a2a2c;
    --line-strong: #3a3a3d;
    --mine-bg: #f2f2f3;
    --mine-ink: #0b0b0c;
    --peer-bg: #1a1a1c;
    --peer-ink: #f2f2f3;
    --peer-border: #2c2c2f;
    --accent: #f2f2f3;
    --accent-ink: #0b0b0c;
    --danger: #ff6b5e;
    --overlay: rgba(0, 0, 0, 0.5);
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

/* 原生侧注入的显式主题优先 */
html[data-theme="dark"] {
  --bg: #0b0b0c;
  --surface: #171718;
  --surface-2: #202022;
  --ink: #f2f2f3;
  --ink-soft: #c9c9cc;
  --muted: #8c8c90;
  --line: #2a2a2c;
  --line-strong: #3a3a3d;
  --mine-bg: #f2f2f3;
  --mine-ink: #0b0b0c;
  --peer-bg: #1a1a1c;
  --peer-ink: #f2f2f3;
  --peer-border: #2c2c2f;
  --accent: #f2f2f3;
  --accent-ink: #0b0b0c;
  --danger: #ff6b5e;
  --overlay: rgba(0, 0, 0, 0.5);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  transition: background-color .2s ease, color .2s ease;
}
.hidden { display: none !important; }
button { font-family: inherit; color: inherit; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }

/* ── 登录 ───────────────────────────────────────────── */
#login { align-items: center; justify-content: center; padding: 32px 24px; background: var(--bg); }
.login-card {
  width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; text-align: center;
}
.login-avatar {
  width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 4px;
  display: flex; align-items: center; justify-content: center;
  background: var(--ink); color: var(--bg);
  font-size: 30px; font-weight: 500; letter-spacing: 1px;
  border: 1px solid var(--line);
}
.login-card h1 { margin: 0; font-size: 22px; letter-spacing: 8px; font-weight: 600; color: var(--ink); }
.muted { color: var(--muted); font-size: 14px; margin: 0; }
#login input, .field input {
  width: 100%; padding: 13px 16px; border-radius: 14px;
  border: 1px solid var(--line-strong); background: var(--surface);
  font-size: 16px; color: var(--ink); outline: none; transition: border-color .15s ease;
}
#login input::placeholder, .field input::placeholder { color: var(--muted); }
#login input:focus, .field input:focus { border-color: var(--ink); }
.primary {
  padding: 13px 18px; border-radius: 14px; border: 1px solid var(--accent);
  background: var(--accent); color: var(--accent-ink);
  font-size: 16px; font-weight: 600; cursor: pointer;
  transition: opacity .15s ease, transform .12s ease;
}
.primary:active { transform: scale(.985); opacity: .86; }
.primary.small, .ghost.small { padding: 9px 18px; font-size: 14px; width: auto; align-self: flex-start; }
.ghost {
  background: transparent; border: 1px solid var(--line-strong); color: var(--ink-soft);
  border-radius: 12px; cursor: pointer; transition: border-color .15s ease, color .15s ease;
}
.ghost:active { border-color: var(--ink); color: var(--ink); }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 0; }

/* ── 顶栏 ───────────────────────────────────────────── */
.topbar {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + var(--safe-top)) 16px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}
.peer { display: flex; align-items: center; gap: 11px; min-width: 0; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; object-fit: cover; flex: none;
  border: 1px solid var(--line-strong); background: var(--surface-2);
}
.avatar.big { width: 64px; height: 64px; }
.peer-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.peer-name { font-size: 17px; font-weight: 600; letter-spacing: .5px; }
.peer-status { font-size: 12px; color: var(--muted); white-space: nowrap; }
.peer-status.busy { color: var(--ink-soft); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid transparent; background: transparent; color: var(--ink-soft);
  cursor: pointer; transition: background .15s ease, transform .12s ease;
}
.icon-btn:active { background: var(--surface-2); transform: scale(.95); }

.banner {
  flex: none; padding: 9px 16px; font-size: 13px; text-align: center;
  color: var(--ink-soft); background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}

/* ── 消息区 ─────────────────────────────────────────── */
.messages {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 18px 16px;
  display: flex; flex-direction: column; gap: 14px;
  background: var(--bg);
  scrollbar-width: none;
}
.messages::-webkit-scrollbar { display: none; }

.empty-state { margin: auto; text-align: center; color: var(--muted); display: flex; flex-direction: column; gap: 14px; align-items: center; }
.empty-avatar {
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: var(--ink-soft);
  border: 1px solid var(--line-strong); background: transparent;
}

.msg { display: flex; gap: 9px; align-items: flex-end; max-width: 100%; animation: msg-in .22s ease-out; }
@keyframes msg-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg.peer { align-self: flex-start; }
.msg.mine { align-self: flex-end; flex-direction: row-reverse; }
.msg .avatar { width: 30px; height: 30px; }
.bubble-wrap { display: flex; flex-direction: column; gap: 4px; max-width: min(80vw, 560px); }
.msg.mine .bubble-wrap { align-items: flex-end; }

.bubble {
  position: relative;
  padding: 8px 13px; border-radius: 17px;
  font-size: 16px; line-height: 1.48;
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
}
.msg.peer .bubble {
  background: var(--peer-bg); color: var(--peer-ink);
  border: 1px solid var(--peer-border);
  border-bottom-left-radius: 6px;
}
.msg.mine .bubble {
  background: var(--mine-bg); color: var(--mine-ink);
  border: 1px solid var(--mine-bg);
  border-bottom-right-radius: 6px;
}

.bubble.md p { margin: 0 0 .5em; }
.bubble.md p:last-child { margin-bottom: 0; }
.bubble.md code {
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 6px; font-size: 14px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
.msg.mine .md code { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.18); }
.bubble.md pre {
  margin: 8px 0; padding: 10px 12px; border-radius: 12px; overflow-x: auto; font-size: 13.5px;
  background: var(--surface-2); border: 1px solid var(--line);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; line-height: 1.55;
}
.msg.mine .md pre { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.18); }
.bubble.md pre code { background: transparent; border: 0; padding: 0; }
.bubble.md a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.bubble.md ul { margin: .3em 0; padding-left: 1.2em; }
.bubble.md li { margin: .15em 0; }
.bubble.md blockquote { margin: .4em 0; padding-left: 10px; border-left: 2px solid var(--line-strong); color: var(--ink-soft); }
.bubble.md h1, .bubble.md h2, .bubble.md h3 { margin: .5em 0 .3em; font-size: 1.05em; }
.bubble.md hr { border: 0; border-top: 1px solid var(--line); margin: .6em 0; }
.msg img.photo {
  max-width: 100%; border-radius: 12px; display: block; margin: 2px 0;
  border: 1px solid var(--line);
}
.msg .bubble.imgs { padding: 6px; }

.files { display: flex; flex-direction: column; gap: 6px; }
.meta-line { font-size: 11.5px; color: var(--muted); padding: 0 4px; }

.typing { display: inline-flex; gap: 4px; align-items: center; padding: 3px 2px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-2px); } }

/* 回到底部：相对屏幕固定（不再相对聊天容器），右下角、拇指能够到、面积够大 */
.jump-btn {
  position: fixed; right: 14px; left: auto;
  bottom: calc(74px + var(--safe-bottom));
  min-width: 48px; height: 42px; padding: 0 15px;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
  border-radius: 21px; font-size: 13px; font-weight: 500;
  border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  cursor: pointer; z-index: 30;
  transition: opacity .15s ease, transform .12s ease;
}
.jump-btn:active { transform: scale(.94); }
.jump-btn svg { display: block; }

/* ── 输入区（贴边、无圆角、无空隙）─────────────────── */
.composer {
  flex: none;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
#input {
  flex: 1; resize: none; max-height: 128px; min-height: 42px; padding: 9px 15px;
  border-radius: 21px; border: 1px solid var(--line-strong);
  background: var(--surface); color: var(--ink);
  font-size: 16px; line-height: 1.5; outline: none; font-family: inherit;
  transition: border-color .15s ease;
}
#input::placeholder { color: var(--muted); }
#input:focus { border-color: var(--ink); }
.send-btn {
  position: relative; width: 42px; height: 42px; border-radius: 50%; flex: none;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: transform .14s ease, opacity .15s ease;
}
.send-btn:active { transform: scale(.92); opacity: .85; }
.send-btn.busy { opacity: .55; }
.steer-hint { font-size: 12px; color: var(--muted); text-align: center; padding-top: 5px; }

/* 附件条 */
.attachment-bar { display: flex; gap: 8px; padding: 4px 0 8px; overflow-x: auto; scrollbar-width: none; }
.attachment-bar::-webkit-scrollbar { display: none; }
.chip {
  position: relative; flex: none; border-radius: 12px; padding: 5px 9px;
  font-size: 12.5px; color: var(--ink-soft); display: flex; align-items: center; gap: 6px; max-width: 210px;
  border: 1px solid var(--line-strong); background: var(--surface);
}
.chip img { width: 36px; height: 36px; border-radius: 8px; object-fit: cover; }
.chip .chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip.uploading { opacity: .55; }
.chip .chip-x {
  border: 1px solid var(--line); color: var(--ink-soft); width: 18px; height: 18px; border-radius: 50%;
  font-size: 11px; background: var(--surface-2); cursor: pointer; display: flex; align-items: center; justify-content: center; flex: none;
}

/* 附件菜单（图片 / 文件） */
.attach-menu {
  position: absolute; left: 12px; bottom: calc(66px + var(--safe-bottom));
  display: flex; flex-direction: column; min-width: 148px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 16px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.16); overflow: hidden; z-index: 9;
  animation: menu-in .16s ease-out;
}
@keyframes menu-in { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
.attach-menu button {
  border: 0; background: transparent; color: var(--ink);
  padding: 13px 18px; font-size: 15px; text-align: left; cursor: pointer;
}
.attach-menu button + button { border-top: 1px solid var(--line); }
.attach-menu button:active { background: var(--surface-2); }

/* ── 设置面板 ───────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: var(--overlay); z-index: 20; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--bg); border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -18px 50px rgba(0, 0, 0, 0.18);
  animation: sheet-up .24s cubic-bezier(.22, 1.2, .36, 1);
}
@keyframes sheet-up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet::before {
  content: ""; position: absolute; top: 8px; left: 50%; width: 40px; height: 4px; border-radius: 2px;
  transform: translateX(-50%); background: var(--line-strong);
}
.sheet-head {
  flex: none; display: flex; align-items: center; justify-content: space-between;
  padding: 22px 16px 8px; font-weight: 600; font-size: 17px;
}
.sheet-body {
  overflow-y: auto; padding: 4px 16px calc(22px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 14px; scrollbar-width: none;
}
.sheet-body::-webkit-scrollbar { display: none; }
.setting-block {
  border: 1px solid var(--line); border-radius: 16px; padding: 15px;
  display: flex; flex-direction: column; gap: 11px; background: var(--surface);
}
.setting-title { font-size: 12.5px; color: var(--muted); letter-spacing: 1px; }
.avatars-row { display: flex; gap: 26px; }
.avatar-edit { display: flex; flex-direction: column; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-soft); cursor: pointer; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; color: var(--ink-soft); }
.field input { flex: 1; max-width: 62%; padding: 9px 13px; border-radius: 11px; font-size: 15px; }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13.5px; color: var(--ink-soft); }
.kv code {
  font-size: 12px; color: var(--muted); padding: 2px 7px; border-radius: 6px; max-width: 58%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--line);
}
.sheet-foot { text-align: center; font-size: 12px; color: var(--muted); margin: 0; }

/* ── 图片预览 / toast ───────────────────────────────── */
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.92); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 18px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 10px; }
.toast {
  position: fixed; left: 50%; bottom: calc(104px + var(--safe-bottom)); transform: translateX(-50%);
  max-width: 80vw; padding: 9px 16px; border-radius: 12px; z-index: 50;
  font-size: 13.5px; color: var(--bg); background: var(--ink);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}

@media (min-width: 720px) {
  .messages { padding-left: max(16px, calc(50vw - 430px)); padding-right: max(16px, calc(50vw - 430px)); }
  .composer { padding-left: max(12px, calc(50vw - 440px)); padding-right: max(12px, calc(50vw - 440px)); }
  .topbar { padding-left: max(16px, calc(50vw - 430px)); padding-right: max(16px, calc(50vw - 430px)); }
}
