/* ============================================================
   Cake Classmate — 自研移动端界面
   视口策略（经真机问题反馈修正）：
     1. 根容器 position:fixed + 四边锚定，铺满可用区域
     2. 不使用 viewport-fit=cover，也不使用 env(safe-area-inset-*)：
        让系统状态栏/导航栏自行占位，避免顶部与底部出现空白带
     3. 键盘弹起时用 visualViewport 收缩布局并收起多余栏
   ============================================================ */

:root {
  --accent: #d97706;
  --accent-soft: #fef3c7;
  --accent-text: #ffffff;
  --bg: #faf8f5;
  --surface: #ffffff;
  --surface-2: #f4f1ec;
  --text: #1f2937;
  --text-soft: #4b5563;
  --muted: #8a8175;
  --border: #e8e3dc;
  --bubble-user: #d97706;
  --bubble-user-text: #ffffff;
  --bubble-ai: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --radius: 16px;
}

html[data-theme="dark"] {
  --accent: #f59e0b;
  --accent-soft: #3a2a10;
  --accent-text: #1a1206;
  --bg: #14110f;
  --surface: #1c1917;
  --surface-2: #232020;
  --text: #f5f5f4;
  --text-soft: #d6d3d1;
  --muted: #a8a29e;
  --border: #302b28;
  --bubble-user: #b45309;
  --bubble-user-text: #ffffff;
  --bubble-ai: #1c1917;
  --danger: #f87171;
  --ok: #4ade80;
}

@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) {
    --accent: #f59e0b;
    --accent-soft: #3a2a10;
    --accent-text: #1a1206;
    --bg: #14110f;
    --surface: #1c1917;
    --surface-2: #232020;
    --text: #f5f5f4;
    --text-soft: #d6d3d1;
    --muted: #a8a29e;
    --border: #302b28;
    --bubble-user: #b45309;
    --bubble-ai: #1c1917;
    --danger: #f87171;
    --ok: #4ade80;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--surface);   /* 兜底色与底栏一致，任何缝隙都不会出现色带 */
  color: var(--text);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea { font: inherit; color: inherit; }
button { border: 0; background: none; cursor: pointer; }
.hidden-input { display: none; }

svg { width: 22px; height: 22px; fill: none; stroke: currentColor;
      stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ================= 登录层 ================= */
.login {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.login[hidden] { display: none; }

.login-card {
  width: 100%; max-width: 380px; text-align: center;
}
.login-logo {
  width: 84px; height: 84px; border-radius: 22px;
  box-shadow: 0 10px 30px rgba(217,119,6,.22);
}
.login-card h1 { margin: 18px 0 4px; font-size: 24px; letter-spacing: .3px; }
.login-sub { margin: 0 0 26px; color: var(--muted); font-size: 14px; }

.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card input {
  padding: 15px 16px; border-radius: 14px;
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 16px; outline: none; text-align: center;
  transition: border-color .16s;
}
.login-card input:focus { border-color: var(--accent); }
.login-card button {
  padding: 15px; border-radius: 14px; font-weight: 600; font-size: 16px;
  background: var(--accent); color: var(--accent-text);
  transition: transform .12s, opacity .16s;
}
.login-card button:active { transform: scale(.985); }
.login-card button:disabled { opacity: .55; }
.login-error { min-height: 20px; margin: 12px 0 0; color: var(--danger); font-size: 13.5px; }
.login-hint { margin: 6px 0 0; color: var(--muted); font-size: 12.5px; }

/* ================= 主应用骨架 ================= */
/* 用 top/bottom/left/right 全部锚定，比 100dvh 更可靠：
   全屏(添加到主屏幕)模式下也不会在底部露出背景色带 */
.app {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
}
.app[hidden] { display: none; }

/* 键盘弹起：收缩到可视区，并把多余栏收起，保证输入框紧贴键盘 */
html.kb-open .app {
  bottom: auto;
  height: var(--kb-h, 100%);
  transform: translateY(var(--kb-top, 0px));
}
html.kb-open .chips,
html.kb-open .tabbar { display: none; }
html.kb-open .messages { padding-bottom: 4px; }

/* 顶栏 */
.topbar {
  flex: none;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 8px 6px;
  background: var(--surface);   /* 纯色，避免全屏模式下的毛玻璃条带 */
  border-bottom: 1px solid var(--border);
  z-index: 20;
}
.icon-btn {
  width: 44px; height: 44px; flex: none;
  display: flex; align-items: center; justify-content: center;
  border-radius: 12px; color: var(--text-soft);
  transition: background .16s;
}
.icon-btn:active { background: var(--surface-2); }

.topbar-title { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-logo { width: 32px; height: 32px; border-radius: 10px; flex: none; }
.title-main { font-size: 15.5px; font-weight: 650; line-height: 1.25; }
.title-sub {
  display: flex; align-items: center; gap: 5px;
  font-size: 11.5px; color: var(--muted); line-height: 1.3;
}
.dot {
  width: 6px; height: 6px; border-radius: 50%; flex: none;
  background: var(--muted); transition: background .3s;
}
.dot.ok { background: var(--ok); }
.dot.err { background: var(--danger); }

/* 页面容器 */
.pages { flex: 1; position: relative; overflow: hidden; min-height: 0; }
.page {
  position: absolute; inset: 0;
  display: none; flex-direction: column;
  min-height: 0;
}
.page.active { display: flex; }

/* ================= 消息区 ================= */
.messages {
  flex: 1; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
}

.msg { display: flex; gap: 9px; max-width: 100%; animation: pop .22s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 30px; height: 30px; border-radius: 9px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; background: var(--accent-soft); color: var(--accent);
  overflow: hidden;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg.user .msg-avatar { background: var(--surface-2); color: var(--muted); }

.bubble {
  max-width: 82%;
  padding: 11px 14px;
  border-radius: var(--radius);
  background: var(--bubble-ai);
  border: 1px solid var(--border);
  word-break: break-word; overflow-wrap: anywhere;
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.msg.user .bubble {
  background: var(--bubble-user); color: var(--bubble-user-text);
  border-color: transparent;
}
.msg.system .bubble {
  background: var(--surface-2); color: var(--muted);
  font-size: 13px; border-style: dashed; text-align: center; margin: 0 auto;
}

/* 流式光标 */
.typing-cursor::after {
  content: ""; display: inline-block; width: 2px; height: 1em;
  background: var(--accent); margin-left: 2px; vertical-align: -2px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* 状态行 */
.status-line {
  display: flex; align-items: center; gap: 7px;
  font-size: 12.5px; color: var(--muted); padding: 2px 4px;
}
.spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--border); border-top-color: var(--accent);
  animation: spin .8s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Markdown 渲染 ---- */
.bubble > *:first-child { margin-top: 0; }
.bubble > *:last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 9px; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  margin: 14px 0 7px; line-height: 1.35; font-weight: 650;
}
.bubble h1 { font-size: 19px; } .bubble h2 { font-size: 17.5px; }
.bubble h3 { font-size: 16.5px; } .bubble h4 { font-size: 15.5px; }
.bubble ul, .bubble ol { margin: 0 0 9px; padding-left: 21px; }
.bubble li { margin: 4px 0; }
.bubble a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; }
.bubble code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13.5px; padding: 2px 5px; border-radius: 6px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.bubble pre {
  margin: 9px 0; padding: 12px; border-radius: 12px; overflow-x: auto;
  background: var(--surface-2); border: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}
.bubble pre code { padding: 0; border: 0; background: none; font-size: 13px; line-height: 1.55; }
.bubble blockquote {
  margin: 9px 0; padding: 3px 0 3px 12px;
  border-left: 3px solid var(--accent); color: var(--text-soft);
}
.bubble hr { border: 0; border-top: 1px solid var(--border); margin: 13px 0; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 9px 0; }
.bubble table { border-collapse: collapse; font-size: 13.5px; min-width: 100%; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 6px 9px; text-align: left; white-space: nowrap; }
.bubble th { background: var(--surface-2); font-weight: 620; }

/* ================= 快捷指令 ================= */
.chips {
  flex: none; display: flex; gap: 7px; padding: 4px 12px 3px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: flex; align-items: center;
  min-height: 44px; padding: 0 15px; border-radius: 999px;
  font-size: 13px; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-soft);
  transition: transform .12s, background .16s;
}
.chip:active { transform: scale(.95); background: var(--accent-soft); }

/* ================= 输入区 ================= */
.composer {
  flex: none; display: flex; align-items: flex-end; gap: 8px;
  /* 底部安全区由下方 tabbar 统一承担，这里不再重复加，避免多余空白 */
  padding: 7px 10px;
  background: var(--surface);
  /* 默认不画上边框：下方 tabbar 已有分隔线，避免出现两条平行线 */
}
/* 键盘弹起时 tabbar 收起，这里补一条分隔线 */
html.kb-open .composer { border-top: 1px solid var(--border); }
.composer-btn {
  position: relative;
  width: 38px; height: 38px; flex: none; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-soft); background: var(--surface-2);
  transition: background .16s;
}
.composer-btn:active { background: var(--border); }

#input {
  flex: 1; min-height: 38px; max-height: 132px;
  padding: 8px 13px; border-radius: 19px;
  border: 1.5px solid var(--border); background: var(--surface);
  font-size: 16px; line-height: 1.45; resize: none; outline: none;
  transition: border-color .16s;
  overflow-y: auto;
}
#input:focus { border-color: var(--accent); }
#input::placeholder { color: var(--muted); }

.send-btn {
  position: relative;
  width: 38px; height: 38px; flex: none; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--accent-text);
  transition: transform .12s, opacity .16s;
}
/* 输入区按钮视觉 38px，用透明伪元素把命中区向外扩 4px（共 46px），满足触控友好 */
.composer-btn::after, .send-btn::after {
  content: ""; position: absolute; inset: -4px; border-radius: 50%;
}
.send-btn:active { transform: scale(.92); }
.send-btn[disabled] { opacity: .4; }
.send-btn.stop { background: var(--danger); }
.send-btn[hidden] { display: none; }

/* ================= 文件页（自研原生界面，无 iframe） =================
   数据来源：同源 /files/ 的 copyparty JSON API
     · 列目录  GET  /files/<vpath>/?ls=.   + Accept: application/json
     · 上传    PUT  /files/<vpath>/<name>  Content-Type: application/octet-stream
     · 下载    GET  /files/<vpath>/<name>
   鉴权：cookie cake_files_t（Path=/files/），与对话页共用同一 UI Token。
   附件预览与文件页共用 --surface-2 / --border / --accent 等设计令牌，
   深浅两种主题都会自动跟随。
   ================================================================ */
.files-page {
  flex: 1; min-height: 0; min-width: 0;
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* ---- 顶部：面包屑 + 刷新 ---- */
.files-toolbar {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: 8px 8px 4px 12px;
}
.files-crumbs {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 2px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.files-crumbs::-webkit-scrollbar { display: none; }
.crumb {
  flex: none; display: flex; align-items: center; gap: 2px;
  min-height: 44px; min-width: 44px; justify-content: center;
  padding: 0 6px; border-radius: 10px;
  font-size: 13.5px; color: var(--muted); white-space: nowrap;
  transition: background .14s, color .14s;
}
.crumb:active { background: var(--surface-2); }
.crumb.cur { color: var(--text); font-weight: 620; }
.crumb-sep { flex: none; color: var(--border); font-size: 12px; }
.files-refresh { width: 44px; height: 44px; }
.files-refresh svg { width: 19px; height: 19px; }
.files-refresh.spin svg { animation: spin .8s linear infinite; }

/* ---- 空间分段控件（与对话页 chips 同风格） ---- */
.files-seg {
  flex: none; display: flex; gap: 7px;
  padding: 2px 12px 6px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.files-seg::-webkit-scrollbar { display: none; }
.seg-btn {
  flex: 1 0 auto; min-height: 44px; padding: 0 14px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 999px; font-size: 13px; white-space: nowrap;
  background: var(--surface); border: 1px solid var(--border); color: var(--text-soft);
  transition: transform .12s, background .16s, color .16s, border-color .16s;
}
.seg-btn:active { transform: scale(.96); }
.seg-btn.active {
  background: var(--accent); border-color: var(--accent);
  color: var(--accent-text); font-weight: 620;
}

/* ---- 列表 ---- */
.files-list-wrap { flex: 1; min-height: 0; position: relative; overflow: hidden; }
.files-list {
  position: absolute; inset: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 0 12px 12px;
  display: flex; flex-direction: column; gap: 8px;
  max-width: 100%;
}
.files-hint {
  position: absolute; left: 0; right: 0; top: 0;
  height: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--muted);
  pointer-events: none;
  transition: height .18s;
}
.files-hint.pulling { height: 40px; }

/* 列表行：图标 + 文本 + 下载；点击区域 ≥44px */
.file-row {
  flex: none; width: 100%;
  display: flex; align-items: center; gap: 11px;
  min-height: 60px; padding: 9px 12px;
  border-radius: 14px;
  background: var(--surface); border: 1px solid var(--border);
  text-align: left; color: var(--text);
  transition: background .14s, transform .12s;
}
.file-row:active { background: var(--surface-2); transform: scale(.994); }
.file-ico {
  width: 38px; height: 38px; flex: none; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px; background: var(--accent-soft); color: var(--accent);
}
.file-ico.dir { background: var(--surface-2); color: var(--text-soft); }
.file-main { flex: 1; min-width: 0; }
.file-name {
  font-size: 14.5px; font-weight: 560; line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-meta {
  margin-top: 2px; display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; color: var(--muted);
  overflow: hidden; white-space: nowrap;
}
.file-meta .dotsep { color: var(--border); }
.file-dl {
  width: 44px; height: 44px; flex: none; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent); background: var(--surface-2);
}
.file-dl:active { background: var(--accent-soft); }
.file-dl svg { width: 19px; height: 19px; }
.file-chev { flex: none; color: var(--muted); font-size: 17px; padding-right: 4px; }

/* 骨架屏 */
.file-row.skel { pointer-events: none; }
.sk {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
  border-radius: 8px;
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
.sk-ico { width: 38px; height: 38px; border-radius: 11px; flex: none; }
.sk-line { height: 11px; }
.sk-line.w1 { width: 62%; }
.sk-line.w2 { width: 38%; margin-top: 7px; }

/* 空态 / 错误态 */
.files-state {
  flex: 1; min-height: 200px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 28px 20px; text-align: center;
}
.files-state .fs-emoji { font-size: 42px; line-height: 1; }
.files-state h3 { margin: 6px 0 0; font-size: 16.5px; font-weight: 620; }
.files-state p {
  margin: 0; max-width: 300px;
  color: var(--muted); font-size: 13.5px; line-height: 1.6;
}
.files-state .fs-btn {
  margin-top: 14px; min-height: 44px; padding: 11px 22px; border-radius: 12px;
  background: var(--accent); color: var(--accent-text);
  font-weight: 620; font-size: 14.5px;
  transition: transform .12s;
}
.files-state .fs-btn:active { transform: scale(.97); }

/* ---- 上传队列 ---- */
.files-queue {
  flex: none; max-height: 34vh; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 12px 4px;
  display: flex; flex-direction: column; gap: 7px;
}
.files-queue[hidden] { display: none; }
.q-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 11.5px; color: var(--muted); letter-spacing: .3px;
}
.q-clear { font-size: 12px; color: var(--accent); padding: 4px 6px; border-radius: 8px; min-height: 28px; }
.q-item {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 12px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.q-main { flex: 1; min-width: 0; }
.q-name {
  font-size: 13px; line-height: 1.35;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.q-sub {
  margin-top: 1px; font-size: 11px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.q-sub.err { color: var(--danger); }
.q-sub.ok { color: var(--ok); }
.q-bar {
  margin-top: 6px; height: 4px; border-radius: 999px;
  background: var(--border); overflow: hidden;
}
.q-bar > i {
  display: block; height: 100%; width: 0%;
  background: var(--accent); border-radius: 999px;
  transition: width .18s linear;
}
.q-item.done .q-bar > i { background: var(--ok); }
.q-item.fail .q-bar > i { background: var(--danger); }
.q-act {
  flex: none; min-width: 44px; min-height: 44px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 11px; font-size: 12.5px; color: var(--accent);
}
.q-act:active { background: var(--border); }
.q-act.cancel { color: var(--muted); }

/* ---- 主操作 ---- */
.files-actions {
  flex: none; padding: 8px 12px 10px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.files-cta {
  width: 100%; min-height: 50px;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  padding: 13px 18px; border-radius: 14px;
  background: var(--accent); color: var(--accent-text);
  font-size: 15.5px; font-weight: 650;
  transition: transform .12s, opacity .16s, box-shadow .16s;
}
.files-cta svg { width: 20px; height: 20px; }
.files-cta:active { transform: scale(.985); }
.files-cta[disabled] { opacity: .5; }
.files-cta.drop {
  box-shadow: 0 0 0 3px var(--accent-soft) inset;
  opacity: .92;
}
.files-cta-hint {
  margin-top: 7px; text-align: center;
  font-size: 11.5px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 文件页在键盘弹起时收起主操作区，避免和列表抢空间 */
html.kb-open .files-actions { display: none; }

/* ================= 对话附件（预览区 + 气泡） ================= */
.attach-preview {
  flex: none; display: flex; gap: 8px;
  padding: 4px 12px 2px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.attach-preview::-webkit-scrollbar { display: none; }
.attach-preview[hidden] { display: none; }

/* 有附件待发送时，让出空间：收起快捷指令条（附件预览更相关） */
.page:has(.attach-preview:not([hidden])) .chips { display: none; }

.attach-item {
  position: relative; flex: none;
  display: flex; align-items: center; gap: 9px;
  max-width: 220px; padding: 6px 30px 6px 7px;
  border-radius: 13px;
  background: var(--surface); border: 1px solid var(--border);
}
.attach-thumb {
  width: 42px; height: 42px; flex: none; border-radius: 10px;
  object-fit: cover; background: var(--surface-2); display: block;
}
.attach-fileico {
  width: 42px; height: 42px; flex: none; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; background: var(--accent-soft); color: var(--accent);
}
.attach-meta { min-width: 0; }
.attach-name {
  font-size: 12.5px; font-weight: 560; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.attach-size { font-size: 11px; color: var(--muted); margin-top: 1px; }
.attach-x {
  position: absolute; top: -8px; right: -8px;
  width: 30px; height: 30px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1;
  background: var(--surface-2); color: var(--text-soft);
  border: 1.5px solid var(--bg);
  box-shadow: 0 1px 4px rgba(0,0,0,.14);
}
/* 视觉 30px、实际可点 46px：向外扩一圈透明命中区，满足触控友好 */
.attach-x::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; }
.attach-x:active { background: var(--danger); color: #fff; }
.attach-item.bad { border-color: var(--danger); }
.attach-item.bad .attach-size { color: var(--danger); }

/* 气泡里的图片与文件卡 */
.bubble-media {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 6px;
}
.bubble-media:last-child { margin-bottom: 0; }
.bubble-media img {
  width: 128px; height: 128px; object-fit: cover;
  border-radius: 12px; display: block; cursor: zoom-in;
  background: var(--surface-2);
}
.msg.user .bubble-media img { border: 1px solid rgba(255,255,255,.35); }
.bubble-media img.loading { opacity: .45; }
.bubble-media img.broken {
  width: auto; height: auto; min-width: 128px; padding: 14px;
  font-size: 12px; color: var(--muted); text-align: center;
}
.bubble-file {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 11px; border-radius: 11px;
  background: var(--surface-2); border: 1px solid var(--border);
  max-width: 100%;
}
.msg.user .bubble-file {
  background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.3);
  color: var(--bubble-user-text);
}
.bubble-file .bf-ico { font-size: 18px; flex: none; }
.bubble-file .bf-main { min-width: 0; }
.bubble-file .bf-name {
  font-size: 13px; font-weight: 560;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.bubble-file .bf-size { font-size: 11px; opacity: .82; }

/* ---- 图片灯箱 ---- */
.lightbox {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  padding: 18px;
  background: rgba(0,0,0,.88);
}
.lightbox[hidden] { display: none; }
.lightbox img {
  max-width: 100%; max-height: 100%;
  border-radius: 10px; object-fit: contain;
}
.lightbox-x {
  position: absolute; top: 14px; right: 14px;
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: #fff; background: rgba(255,255,255,.16);
}

/* ---- 附件来源选择（底部弹层） ---- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 60;
  padding: 8px 10px 14px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0;
  transform: translateY(102%);
  transition: transform .24s cubic-bezier(.22,.61,.36,1);
  box-shadow: 0 -8px 28px rgba(0,0,0,.16);
}
.sheet.show { transform: none; }
.sheet[hidden] { display: none; }
.sheet-grip {
  width: 38px; height: 4px; border-radius: 999px;
  background: var(--border); margin: 4px auto 10px;
}
.sheet-item {
  width: 100%; min-height: 50px;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 12px; border-radius: 12px;
  font-size: 15px; color: var(--text); text-align: left;
}
.sheet-item:active { background: var(--surface-2); }
.sheet-item .si-emoji { font-size: 19px; width: 24px; text-align: center; }
.sheet-item .si-sub { display: block; font-size: 11.5px; color: var(--muted); }

/* ================= 底部标签 ================= */
.tabbar {
  flex: none; display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: 3px;   /* 只留极小余量，不再用 safe-area，避免底部空白带 */
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 0 6px; color: var(--muted); font-size: 11px;
  transition: color .16s;
}
.tab.active { color: var(--accent); }
.tab svg { width: 21px; height: 21px; }

/* ================= 侧滑面板 ================= */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(0,0,0,.4);
  opacity: 0; transition: opacity .24s;
  -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px);
}
.overlay.show { opacity: 1; }
.overlay[hidden] { display: none; }

.panel {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
  width: min(82vw, 320px);
  display: flex; flex-direction: column;
  background: var(--surface);
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  transition: transform .26s cubic-bezier(.22,.61,.36,1);
  overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.panel.show { transform: none; }
.panel[hidden] { display: none; }

.panel-head {
  display: flex; align-items: center; gap: 11px;
  padding: 18px 16px 14px; border-bottom: 1px solid var(--border);
}
.panel-logo { width: 42px; height: 42px; border-radius: 13px; }
.panel-name { font-weight: 650; font-size: 16px; }
.panel-sub { font-size: 12px; color: var(--muted); }

.panel-section { padding: 12px 8px 4px; }
.panel-label {
  padding: 0 10px 6px; font-size: 11.5px; font-weight: 600;
  color: var(--muted); letter-spacing: .4px;
}
.panel-item {
  width: 100%; display: flex; align-items: center; gap: 11px;
  padding: 11px 12px; border-radius: 11px; font-size: 14.5px;
  color: var(--text); text-align: left;
  transition: background .14s;
}
.panel-item:active { background: var(--surface-2); }
.pi-emoji { font-size: 17px; width: 22px; text-align: center; }

.panel-foot {
  margin-top: auto; padding: 14px 16px;
  border-top: 1px solid var(--border);
  font-size: 11.5px; color: var(--muted); line-height: 1.6;
}

/* 横屏/大屏微调 */
@media (min-width: 620px) {
  .messages { padding: 20px max(16px, calc(50vw - 340px)); }
  .chips { padding-left: max(12px, calc(50vw - 340px)); }
  .composer { padding-left: max(10px, calc(50vw - 340px)); padding-right: max(10px, calc(50vw - 340px)); }
  .attach-preview { padding-left: max(12px, calc(50vw - 340px)); padding-right: max(12px, calc(50vw - 340px)); }
  .bubble { max-width: 78%; }

  /* 文件页：大屏居中，不铺满整行 */
  .files-toolbar, .files-seg, .files-list, .files-queue, .files-actions {
    padding-left: max(12px, calc(50vw - 340px));
    padding-right: max(12px, calc(50vw - 340px));
  }
}
