:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; color: var(--text); background: var(--bg); }
body { min-width: 320px; }
button, input { font: inherit; }
button { cursor: pointer; }

.page { max-width: 720px; min-height: 100vh; margin: 0 auto; padding-bottom: 76px; }
.page.no-tabs { padding-bottom: 0; }
.topbar { height: 60px; display: flex; align-items: center; justify-content: space-between; padding: 0 18px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar h1 { font-size: 20px; margin: 0; }
.content { padding: 16px; }

.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(100%, 420px); background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; box-shadow: 0 10px 30px rgba(31, 41, 55, .06); }
.auth-card h1 { margin: 0 0 8px; font-size: 26px; }
.auth-card .subtitle { margin: 0 0 24px; color: var(--muted); }
.form-row { margin-bottom: 16px; }
.form-row label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 7px; }
.form-row input { width: 100%; height: 42px; border: 1px solid #d1d5db; border-radius: 8px; padding: 0 12px; outline: none; }
.form-row input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }
.form-actions { display: flex; gap: 10px; align-items: center; }

button.primary, button.secondary, button.text-button, button.danger { border: 0; border-radius: 8px; min-height: 40px; padding: 0 15px; }
button.primary { flex: 1; background: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.secondary { background: #eef2ff; color: #1e40af; }
button.text-button { background: transparent; color: var(--primary); padding: 4px 7px; }
button.danger { background: #fee2e2; color: var(--danger); }
.auth-links { display: flex; justify-content: center; gap: 22px; margin-top: 18px; }
.message { min-height: 20px; color: var(--danger); font-size: 14px; margin: 8px 0; }
.message.success { color: #15803d; }

.session-list { background: var(--panel); border-top: 1px solid var(--line); }
.session-item { width: 100%; display: flex; align-items: center; gap: 12px; min-height: 72px; padding: 12px 16px; border: 0; border-bottom: 1px solid var(--line); background: var(--panel); text-align: left; }
.session-item:hover { background: #f8fafc; }
.avatar { width: 42px; height: 42px; border-radius: 50%; background: #dbeafe; color: #1d4ed8; display: grid; place-items: center; font-weight: 700; flex: 0 0 auto; }
.session-main { min-width: 0; flex: 1; }
.session-name { display: block; font-weight: 600; margin-bottom: 4px; }
.session-preview { display: block; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }

.tabbar { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: min(100%, 720px); height: 64px; display: grid; grid-template-columns: repeat(3, 1fr); background: rgba(255,255,255,.97); border-top: 1px solid var(--line); z-index: 10; }
.tabbar button { border: 0; background: transparent; color: var(--muted); font-size: 13px; }
.tabbar button.active { color: var(--primary); font-weight: 600; }

.chat-list { padding-bottom: 88px; }
.chat-message { display: flex; margin: 10px 0; }
.chat-message.mine { justify-content: flex-end; }
.bubble { max-width: 78%; padding: 10px 12px; border-radius: 12px; background: #fff; border: 1px solid var(--line); white-space: pre-wrap; word-break: break-word; }
.mine .bubble { background: #dbeafe; border-color: #bfdbfe; }
.chat-input { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: min(100%, 720px); display: flex; gap: 8px; padding: 10px 12px; background: var(--panel); border-top: 1px solid var(--line); }
.chat-input input { flex: 1; height: 42px; border: 1px solid #d1d5db; border-radius: 8px; padding: 0 10px; }

@media (max-width: 480px) { .auth-card { padding: 22px; } .content { padding: 12px; } }

/* 底部栏红点 */
.tabbar button { position: relative; }
.tabbar-badge {
  position: absolute; top: 8px; right: calc(50% - 26px);
  min-width: 18px; height: 18px; border-radius: 9px;
  background: #ef4444; color: #fff; font-size: 11px;
  align-items: center; justify-content: center; padding: 0 4px;
}

/* 消息头 */
.msg-head { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; font-size: 12px; }
.msg-head .nick-btn { background: none; border: 0; color: var(--primary); font-weight: 600; padding: 0; font-size: 12px; }
.msg-head .nick-btn:disabled { color: var(--muted); cursor: default; }
.msg-head .msg-time { color: var(--muted); }
.msg-body { white-space: pre-wrap; word-break: break-word; }
.long-link { color: var(--primary); text-decoration: underline; cursor: pointer; }

/* Markdown 渲染样式（聊天消息） */
.md-body { white-space: normal; line-height: 1.6; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4, .md-body h5, .md-body h6 { margin: 8px 0 4px; font-size: 1.1em; }
.md-body p { margin: 0 0 4px; }
.md-body code { background: rgba(31,41,55,.08); border-radius: 4px; padding: 1px 4px; font-size: .92em; font-family: ui-monospace, monospace; }
.md-body pre { background: rgba(31,41,55,.08); border-radius: 8px; padding: 10px; overflow-x: auto; margin: 6px 0; }
.md-body pre code { background: transparent; padding: 0; }
.md-body blockquote { border-left: 3px solid var(--primary); margin: 6px 0; padding: 2px 10px; color: var(--muted); }
.md-body ul, .md-body ol { margin: 4px 0; padding-left: 22px; }
.md-body a { color: var(--primary); text-decoration: underline; word-break: break-all; }
.md-body strong { font-weight: 700; }
.md-body em { font-style: italic; }
.md-body del { color: var(--muted); }

/* 更多按钮与下拉面板 */
.more-wrap { position: relative; display: inline-flex; }
.more-dropdown { position: absolute; right: 0; bottom: calc(100% + 6px); display: none; flex-direction: column; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 20px rgba(31,41,55,.12); min-width: 130px; z-index: 30; overflow: hidden; }
.more-dropdown button { border: 0; background: transparent; text-align: left; padding: 11px 14px; font-size: 13px; }
.more-dropdown button:hover { background: #f3f4f6; }

/* 消息内媒体 */
.md-body audio { width: 100%; max-width: 280px; height: 40px; }
.md-body video { max-width: 100%; border-radius: 8px; margin: 4px 0; }


/* 屏幕阅读器专用通知区域：视觉隐藏，但 aria-live 可被朗读 */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
