/* ================================================================
   全人知识库智能体 · Design System v2
   "Quiet Luxury" — 温暖、克制、呼吸感
   ================================================================ */

/* ===== Design Tokens ===== */
:root {
  /* Surfaces */
  --bg: #F3F2EE;
  --bg-2: #EDEBE6;
  --surface: #FFFFFF;
  --surface-2: #FAF9F7;
  --header-bg: rgba(243, 242, 238, 0.78);

  /* Ink */
  --ink: #2A2D33;
  --ink-2: #6E737C;
  --ink-3: #A5AAB3;
  --ink-4: #C8CCD3;

  /* Accent — sage teal */
  --accent: #5B8A82;
  --accent-deep: #47706A;
  --accent-tint: rgba(91, 138, 130, 0.07);
  --accent-tint-2: rgba(91, 138, 130, 0.13);

  /* Bubbles */
  --user-bubble: #5B8A82;
  --user-ink: #FFFFFF;
  --ai-bubble: #FFFFFF;

  /* Semantic */
  --danger: #B5563F;
  --danger-tint: rgba(181, 86, 63, 0.09);
  --warn: #C29A4E;

  /* Lines */
  --line: rgba(0, 0, 0, 0.05);
  --line-2: rgba(0, 0, 0, 0.08);

  /* Shadows — layered, soft */
  --shadow-xs: 0 1px 2px rgba(20, 25, 30, 0.04);
  --shadow-sm: 0 2px 10px rgba(20, 25, 30, 0.05);
  --shadow-md: 0 6px 24px rgba(20, 25, 30, 0.07);
  --shadow-lg: 0 14px 48px rgba(20, 25, 30, 0.11);
  --shadow-accent: 0 4px 16px rgba(91, 138, 130, 0.22);

  /* Radii */
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 24px;
  --r-pill: 22px;

  /* Safe areas */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);

  /* Easing */
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1, "liga" 1;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

button, input, textarea { font: inherit; color: inherit; }
button { border: none; background: none; cursor: pointer; }

/* ===== Header ===== */
.app-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(8px + var(--safe-top)) 14px 8px;
  background: var(--header-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-logo {
  width: 32px; height: 32px; border-radius: 50%; flex: 0 0 auto;
  object-fit: contain;
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}
.brand-text { min-width: 0; }
.brand-title {
  font-size: 15.5px; font-weight: 600; letter-spacing: -0.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 50vw;
  line-height: 1.25;
}
.brand-sub {
  font-size: 10.5px; color: var(--ink-3); white-space: nowrap;
  letter-spacing: 0.02em; margin-top: 1px;
}
.header-actions { display: flex; gap: 2px; flex: 0 0 auto; }
.icon-btn {
  width: 38px; height: 38px; border-radius: var(--r-sm);
  display: grid; place-items: center;
  color: var(--ink-2);
  transition: background 0.18s var(--ease-out), color 0.18s;
}
.icon-btn:active { background: var(--accent-tint-2); color: var(--accent-deep); }

/* ===== Sidebar ===== */
.sidebar-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 20, 25, 0.32);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 40;
  animation: fade 0.25s var(--ease-out);
}
.sidebar-overlay.hidden { display: none; }
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: 84%; max-width: 340px;
  background: var(--bg); z-index: 45;
  transform: translateX(-100%);
  transition: transform 0.32s var(--ease-out);
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.sidebar.open { transform: translateX(0); }
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + var(--safe-top)) 16px 14px;
}
.sidebar-title { font-size: 17px; font-weight: 600; letter-spacing: -0.01em; }
.conversation-list { flex: 1 1 auto; overflow-y: auto; padding: 4px 10px; }
.sidebar-empty {
  color: var(--ink-3); text-align: center; padding: 48px 16px;
  font-size: 14px; line-height: 1.6;
}
.conv-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 12px;
  border-radius: var(--r-md);
  transition: background 0.15s;
  margin-bottom: 2px;
}
.conv-item:active { background: var(--accent-tint); }
.conv-item.active { background: var(--accent-tint-2); }
.conv-main { flex: 1 1 auto; min-width: 0; }
.conv-title {
  font-size: 14.5px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  color: var(--ink);
}
.conv-time { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.conv-del {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 8px;
  color: var(--ink-3); display: grid; place-items: center;
  opacity: 0; transition: opacity 0.15s, background 0.15s, color 0.15s;
}
.conv-item:active .conv-del { opacity: 1; }
.conv-del:active { background: var(--danger-tint); color: var(--danger); }
.sidebar-new {
  margin: 8px 12px calc(14px + var(--safe-bottom));
  padding: 13px; border-radius: var(--r-md);
  background: var(--surface); color: var(--accent-deep);
  font-weight: 600; font-size: 15px;
  box-shadow: var(--shadow-xs);
  transition: transform 0.12s var(--ease-out), background 0.15s;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.sidebar-new:active { transform: scale(0.97); background: var(--accent-tint); }

/* ===== Messages ===== */
.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 20px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  position: relative;
}
.msg {
  display: flex; max-width: 100%;
  flex-direction: column;
  animation: msgIn 0.34s var(--ease-out) both;
}
.msg.user { align-items: flex-end; }
.msg.ai { align-items: flex-start; }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.bubble {
  max-width: 85%;
  padding: 12px 16px;
  font-size: 15.5px;
  line-height: 1.62;
  word-wrap: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  letter-spacing: 0.005em;
}
.msg.user .bubble {
  background: var(--user-bubble);
  color: var(--user-ink);
  border-radius: var(--r-lg) var(--r-lg) 6px var(--r-lg);
  box-shadow: var(--shadow-accent);
}
.msg.ai .bubble {
  background: var(--ai-bubble);
  color: var(--ink);
  border-radius: var(--r-lg) var(--r-lg) var(--r-lg) 6px;
  box-shadow: var(--shadow-sm);
}
.bubble-img {
  max-width: 100%; border-radius: var(--r-sm);
  margin-top: 8px; display: block;
}

/* AI 气泡 markdown 排版 — 全面支持 */
.bubble p { margin: 0 0 0.6em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 {
  margin: 0.7em 0 0.35em; line-height: 1.3; font-weight: 600;
  letter-spacing: -0.005em;
}
.bubble h1 { font-size: 1.3em; }
.bubble h2 { font-size: 1.18em; }
.bubble h3 { font-size: 1.06em; }
.bubble h4 { font-size: 1em; color: var(--ink-2); }
.bubble h1:first-child, .bubble h2:first-child, .bubble h3:first-child { margin-top: 0; }

/* 列表 */
.bubble ul, .bubble ol { margin: 0.4em 0; padding-left: 1.4em; }
.bubble li { margin: 0.22em 0; }
.bubble ul li::marker { color: var(--accent); }
.bubble ol li::marker { color: var(--ink-2); font-weight: 600; }
.bubble ul ul, .bubble ol ol, .bubble ul ol, .bubble ol ul { margin: 0.15em 0; }

/* 任务列表 */
.bubble li input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 16px; height: 16px; border-radius: 4px;
  border: 1.5px solid var(--ink-3); background: transparent;
  vertical-align: -3px; margin: 0 6px 0 -1.3em;
  cursor: pointer; position: relative;
  transition: border-color 0.15s, background 0.15s;
}
.bubble li input[type="checkbox"]:checked {
  background: var(--accent); border-color: var(--accent);
}
.bubble li input[type="checkbox"]:checked::after {
  content: ""; position: absolute; left: 4px; top: 1px;
  width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.bubble li:has(> input[type="checkbox"]) { list-style: none; margin-left: -0.3em; }

/* 强调 */
.bubble strong, .bubble b { font-weight: 600; }
.bubble em, .bubble i { font-style: italic; }
.bubble del { color: var(--ink-3); }
.bubble mark { background: rgba(194, 154, 78, 0.2); padding: 1px 3px; border-radius: 3px; }

/* 行内代码 */
.bubble code {
  background: var(--bg-2); padding: 2px 6px; border-radius: 5px;
  font-size: 0.86em; font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  color: var(--accent-deep);
}

/* 代码块 */
.bubble pre {
  position: relative;
  background: #1B1D21; color: #E2E0DB; padding: 14px 16px; border-radius: var(--r-sm);
  overflow-x: auto; margin: 0.7em 0; font-size: 13px; line-height: 1.55;
  -webkit-overflow-scrolling: touch;
}
.bubble pre code {
  background: transparent; padding: 0; color: inherit; font-size: inherit;
  font-family: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
}
.code-copy {
  position: absolute; top: 7px; right: 7px;
  padding: 3px 9px; border-radius: 6px;
  background: rgba(255,255,255,0.08); color: #888;
  font-size: 11px; cursor: pointer;
  transition: background 0.15s, color 0.15s; user-select: none;
}
.code-copy:active { background: rgba(255,255,255,0.18); color: #fff; }

/* 引用块 */
.bubble blockquote {
  margin: 0.6em 0; padding: 4px 14px;
  border-left: 3px solid var(--accent); color: var(--ink-2);
  background: var(--accent-tint); border-radius: 0 var(--r-sm) var(--r-sm) 0;
}
.bubble blockquote p { margin: 0.2em 0; }

/* 链接 */
.bubble a {
  color: var(--accent); text-decoration: none;
  border-bottom: 1px solid var(--accent-tint-2);
  transition: border-color 0.15s;
}
.bubble a:active { border-bottom-color: var(--accent); }

/* 分隔线 */
.bubble hr {
  border: none; height: 1px; margin: 1em 0;
  background: var(--line-2);
}

/* 表格 */
.bubble .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0.6em 0; }
.bubble table {
  border-collapse: collapse; font-size: 0.9em; width: 100%; min-width: 280px;
}
.bubble th, .bubble td { border: 1px solid var(--line-2); padding: 7px 11px; text-align: left; }
.bubble th { background: var(--bg-2); font-weight: 600; color: var(--ink); white-space: nowrap; }
.bubble tbody tr:nth-child(even) { background: var(--surface-2); }

/* 图片 */
.bubble img:not(.bubble-img) { max-width: 100%; border-radius: var(--r-sm); margin: 0.4em 0; }

.cite-link {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 4px;
  background: var(--accent-tint-2); color: var(--accent-deep);
  border-radius: 5px; font-size: 11px; font-weight: 600;
  text-decoration: none; vertical-align: super; line-height: 1;
  transition: background 0.15s;
}
.cite-link:active { background: var(--accent); color: #fff; }
.err { color: var(--danger); }

/* ===== Thinking (breathing pulse) ===== */
.thinking {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 3px 2px;
}
.thinking .pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  animation: breathe 2.2s ease-in-out infinite;
}
@keyframes breathe {
  0%, 100% { opacity: 0.25; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}
.think-label { font-size: 13px; color: var(--ink-3); }

/* Stream cursor */
.stream-cursor {
  display: inline-block; width: 2px; height: 1em;
  background: var(--accent); margin-left: 2px;
  vertical-align: text-bottom; border-radius: 1px;
  animation: caret 0.9s step-end infinite;
}
@keyframes caret { 0%, 50% { opacity: 1; } 51%, 100% { opacity: 0; } }

/* ===== Quotes ===== */
.quotes {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.quotes-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12.5px; color: var(--ink-2); font-weight: 500;
}
.quotes-head:active { color: var(--accent-deep); }
.quotes-toggle {
  font-size: 11.5px; color: var(--ink-3); font-weight: 400;
  display: flex; align-items: center; gap: 2px;
}
.quotes-toggle svg { transition: transform 0.25s var(--ease-out); }
.quotes.open .quotes-toggle svg { transform: rotate(180deg); }
.quotes-list {
  max-height: 0; overflow: hidden;
  transition: max-height 0.3s var(--ease-out);
}
.quotes.open .quotes-list { max-height: 1200px; }
.quotes-list-inner { padding-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.quote-item {
  background: var(--surface-2); border-radius: var(--r-sm);
  padding: 10px 12px; scroll-margin-top: 80px;
  border: 1px solid var(--line);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.quote-item.highlight {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint-2);
}
.quote-src {
  font-size: 12px; font-weight: 600; color: var(--ink);
  display: flex; align-items: center; gap: 5px;
}
.quote-src .src-icon { color: var(--accent); flex: 0 0 auto; }
.quote-q { font-size: 12.5px; color: var(--ink-2); margin-top: 4px; line-height: 1.55; }

/* ===== Message Tools — 已移除（改用长按上下文菜单）===== */

/* 编辑弹窗 textarea */
.edit-textarea {
  width: 100%; border: 1.5px solid var(--line-2); border-radius: var(--r-md);
  padding: 12px 14px; font-size: 15px; line-height: 1.6; resize: vertical;
  min-height: 100px; max-height: 240px; outline: none;
  background: var(--surface-2); color: var(--ink);
  transition: border-color 0.2s, background 0.2s; margin-bottom: 16px;
}
.edit-textarea:focus { border-color: var(--accent); background: var(--surface); }

/* ===== Empty State ===== */
.empty {
  margin: auto; text-align: center;
  max-width: 300px; padding: 24px;
  animation: fadeUp 0.5s var(--ease-out) both;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
.empty .glyph {
  width: 72px; height: 72px; margin: 0 auto 20px;
  border-radius: 50%; object-fit: contain;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  animation: float 4s ease-in-out infinite;
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}
.empty h2 {
  font-size: 18px; color: var(--ink); margin: 0 0 8px;
  font-weight: 600; letter-spacing: -0.01em;
}
.empty p {
  font-size: 14px; margin: 0; line-height: 1.7;
  color: var(--ink-2);
}

/* ===== Guide / 猜你想问 ===== */
.guide {
  flex: 0 0 auto;
  padding: 6px 16px calc(8px + var(--safe-bottom));
}
.guide.hidden { display: none; }
.guide-label {
  display: flex; align-items: center; gap: 5px;
  font-size: 12.5px; color: var(--ink-2); margin-bottom: 9px;
  font-weight: 500; letter-spacing: 0.01em;
}
.guide-label svg { color: var(--accent); }

/* 空状态：卡片网格 */
.guide-cards {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.guide-card {
  background: var(--surface); color: var(--ink);
  font-size: 13.5px; line-height: 1.45;
  padding: 13px 14px; border-radius: var(--r-md);
  box-shadow: var(--shadow-xs);
  text-align: left;
  display: flex; align-items: flex-start; gap: 8px;
  transition: transform 0.12s var(--ease-out), background 0.15s, box-shadow 0.15s;
  animation: cardIn 0.35s var(--ease-out) both;
}
.guide-card:nth-child(2) { animation-delay: 0.05s; }
.guide-card:nth-child(3) { animation-delay: 0.1s; }
.guide-card:nth-child(4) { animation-delay: 0.15s; }
@keyframes cardIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.guide-card .card-icon {
  color: var(--accent); flex: 0 0 auto; margin-top: 1px;
  opacity: 0.8;
}
.guide-card .card-text {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.guide-card:active {
  transform: scale(0.96);
  background: var(--accent-tint); box-shadow: var(--shadow-sm);
}

/* 对话后：横滑 chips */
.guide-chips {
  display: flex; gap: 8px; overflow-x: auto;
  padding-bottom: 2px; scroll-snap-type: x proximity;
}
.guide-chips::-webkit-scrollbar { height: 0; }
.guide-chip {
  flex: 0 0 auto;
  background: var(--surface); color: var(--ink);
  font-size: 13.5px; padding: 8px 14px 8px 11px;
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-xs);
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
  transition: transform 0.12s var(--ease-out), background 0.15s, color 0.15s;
  scroll-snap-align: start;
}
.guide-chip .chip-icon { color: var(--accent); flex: 0 0 auto; opacity: 0.8; }
.guide-chip:active {
  transform: scale(0.96);
  background: var(--accent-tint-2); color: var(--accent-deep);
}

/* ===== Input Bar ===== */
.input-bar {
  flex: 0 0 auto;
  padding: 8px 14px calc(10px + var(--safe-bottom));
  background: var(--header-bg);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--line);
}
.img-preview {
  display: flex; gap: 8px; padding: 0 4px 8px;
  overflow-x: auto;
}
.img-preview::-webkit-scrollbar { height: 0; }
.img-preview.hidden { display: none; }
.img-thumb {
  position: relative; flex: 0 0 auto;
  width: 52px; height: 52px; border-radius: var(--r-sm);
  overflow: hidden; box-shadow: var(--shadow-xs);
  animation: thumbIn 0.25s var(--ease-spring) both;
}
@keyframes thumbIn {
  from { opacity: 0; transform: scale(0.6); }
  to { opacity: 1; transform: scale(1); }
}
.img-thumb img { width: 100%; height: 100%; object-fit: cover; }
.img-thumb .img-remove {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.55); color: #fff;
  display: grid; place-items: center;
  font-size: 11px; line-height: 1;
}
.input-wrap {
  display: flex; align-items: flex-end; gap: 2px;
  background: var(--surface);
  border-radius: var(--r-pill);
  padding: 6px 6px 6px 8px;
  box-shadow: var(--shadow-sm);
  border: 1.5px solid transparent;
  transition: border-color 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out);
}
.input-wrap:focus-within {
  border-color: var(--accent-tint-2);
  box-shadow: var(--shadow-sm), 0 0 0 3px var(--accent-tint);
}
.attach-btn {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--ink-3);
  transition: background 0.15s, color 0.15s, transform 0.12s;
}
.attach-btn:active { background: var(--accent-tint); color: var(--accent-deep); transform: scale(0.92); }
.attach-btn.has-img { color: var(--accent); background: var(--accent-tint-2); }
.attach-btn:disabled { opacity: 0.3; }
.attach-btn.hidden { display: none; }
.input {
  flex: 1 1 auto; border: none; outline: none; resize: none;
  background: transparent; color: var(--ink);
  line-height: 1.5; max-height: 140px; padding: 8px 6px;
}
.input::placeholder { color: var(--ink-3); }
.send-btn {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  transition: transform 0.15s var(--ease-spring), opacity 0.2s, background 0.2s;
  box-shadow: var(--shadow-accent);
}
.send-btn:disabled {
  background: var(--ink-4); box-shadow: none; cursor: not-allowed; opacity: 0.4;
}
.send-btn:not(:disabled):active { transform: scale(0.86); }
.send-btn.stop { background: var(--ink); box-shadow: var(--shadow-sm); }
.send-btn.stop:active { transform: scale(0.86); }
.send-btn.hidden { display: none; }

/* ===== Scroll to Bottom ===== */
.scroll-bottom {
  position: fixed; right: 18px;
  bottom: calc(84px + var(--safe-bottom));
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-md);
  display: grid; place-items: center;
  color: var(--ink-2);
  z-index: 15;
  opacity: 0; transform: translateY(8px) scale(0.85);
  pointer-events: none;
  transition: all 0.25s var(--ease-out);
}
.scroll-bottom.visible {
  opacity: 1; transform: translateY(0) scale(1);
  pointer-events: auto;
}
.scroll-bottom:active { transform: scale(0.9); }

/* ===== Modal / Bottom Sheet ===== */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 20, 25, 0.4);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade 0.25s var(--ease-out);
}
.modal-card {
  position: relative; width: 100%; max-width: 520px;
  background: var(--surface); border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 0 20px calc(20px + var(--safe-bottom));
  animation: slideup 0.32s var(--ease-spring);
}
.sheet-handle {
  width: 36px; height: 4px; border-radius: 2px;
  background: var(--ink-4); margin: 8px auto 0;
}
.modal-title {
  font-size: 17px; font-weight: 600; letter-spacing: -0.01em;
  margin: 16px 0 18px;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.field input {
  border: 1.5px solid var(--line-2); border-radius: var(--r-md);
  padding: 12px 14px; outline: none;
  background: var(--surface-2); color: var(--ink);
  transition: border-color 0.2s, background 0.2s;
}
.field input:focus { border-color: var(--accent); background: var(--surface); }
.hint {
  font-size: 12px; color: var(--ink-3); line-height: 1.6;
  margin: 4px 0 16px;
}
.modal-actions { display: flex; gap: 10px; }
.btn-ghost, .btn-primary {
  flex: 1; padding: 13px; border-radius: var(--r-md);
  font-weight: 600; font-size: 15px;
  transition: transform 0.12s var(--ease-out), background 0.15s;
}
.btn-ghost { background: var(--bg-2); color: var(--ink); }
.btn-ghost:active { transform: scale(0.97); background: var(--line-2); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: var(--shadow-accent); }
.btn-primary:active { transform: scale(0.97); background: var(--accent-deep); }

/* ===== Action Sheet (custom confirm) ===== */
.action-sheet { position: fixed; inset: 0; z-index: 55; display: flex; align-items: flex-end; justify-content: center; }
.action-sheet.hidden { display: none; }
.as-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 20, 25, 0.4);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  animation: fade 0.2s var(--ease-out);
}
.as-card {
  position: relative; width: 100%; max-width: 520px;
  background: var(--surface); border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 0 20px calc(20px + var(--safe-bottom));
  animation: slideup 0.28s var(--ease-spring);
}
.as-title { font-size: 16px; font-weight: 600; margin: 18px 0 6px; text-align: center; }
.as-desc { font-size: 14px; color: var(--ink-2); text-align: center; margin-bottom: 18px; line-height: 1.6; }
.as-actions { display: flex; flex-direction: column; gap: 8px; }
.as-btn {
  width: 100%; padding: 13px; border-radius: var(--r-md);
  font-weight: 600; font-size: 15px; text-align: center;
  transition: transform 0.12s var(--ease-out), background 0.15s;
}
.as-btn:active { transform: scale(0.97); }
.as-btn.danger { background: var(--danger-tint); color: var(--danger); }
.as-btn.cancel { background: var(--bg-2); color: var(--ink-2); margin-top: 4px; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom));
  transform: translateX(-50%);
  background: rgba(20, 25, 30, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  color: #fff; padding: 10px 18px; border-radius: var(--r-pill);
  font-size: 13.5px; z-index: 60; max-width: 86%; text-align: center;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.3s var(--ease-spring) both;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}
.toast.hidden { display: none; }

/* ===== Scrollbar ===== */
.messages::-webkit-scrollbar { width: 0; height: 0; }
.conversation-list::-webkit-scrollbar { width: 0; }

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== 键盘适配 ===== */
body { height: var(--app-height, 100dvh); }

/* ===== 上下文菜单项 ===== */
.cm-items { display: flex; flex-direction: column; gap: 2px; margin-bottom: 8px; }
.cm-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 13px 16px; border-radius: var(--r-md);
  font-size: 15px; font-weight: 500; color: var(--ink);
  text-align: left; transition: background 0.12s;
}
.cm-item:active { background: var(--accent-tint); }
.cm-item.danger { color: var(--danger); }
.cm-item.active { color: var(--accent-deep); background: var(--accent-tint-2); }
.cm-item svg { flex: 0 0 auto; }
.cm-desc { font-size: 13px; color: var(--ink-2); text-align: center; padding: 0 16px 12px; line-height: 1.5; }

/* ===== 图片全屏查看器 ===== */
.image-viewer {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  animation: fade 0.25s var(--ease-out);
}
.image-viewer.hidden { display: none; }
.iv-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.92); }
.iv-img { position: relative; max-width: 92%; max-height: 85vh; border-radius: var(--r-sm); z-index: 1; }

/* ===== 连接状态横幅 ===== */
.conn-banner {
  flex: 0 0 auto; padding: 8px 16px;
  background: var(--danger); color: #fff;
  font-size: 13px; text-align: center; font-weight: 500;
  animation: fade 0.2s var(--ease-out);
}
.conn-banner.hidden { display: none; }

/* ===== 侧栏搜索 ===== */
.sidebar-search {
  display: flex; align-items: center; gap: 7px;
  margin: 0 10px 4px; padding: 8px 11px;
  background: var(--accent-tint);
  border-radius: var(--r-sm);
  border: 1.5px solid transparent;
  transition: border-color 0.2s var(--ease-out), background 0.2s;
}
.sidebar-search:focus-within {
  border-color: var(--accent-tint-2);
  background: var(--surface);
}
.sidebar-search svg { color: var(--ink-3); flex: 0 0 auto; }
.sidebar-search input {
  flex: 1 1 auto; border: none; outline: none; background: transparent;
  font-size: 14px; color: var(--ink);
}
.sidebar-search input::placeholder { color: var(--ink-3); }

/* ===== 会话分组标题 ===== */
.conv-group-head {
  font-size: 11px; font-weight: 600; color: var(--ink-3);
  letter-spacing: 0.05em; text-transform: uppercase;
  padding: 12px 12px 4px;
}
.conv-pin {
  flex: 0 0 auto; color: var(--accent); display: grid; place-items: center;
  opacity: 0.7;
}
.conv-pin svg { transform: rotate(45deg); }

/* ===== 消息时间戳 ===== */
.msg-time {
  text-align: center; font-size: 11px; color: var(--ink-3);
  padding: 8px 0 2px; letter-spacing: 0.02em;
}

/* ===== 语音按钮录制态 ===== */
.attach-btn.recording {
  color: var(--danger); background: var(--danger-tint);
  animation: pulseRec 1s ease-in-out infinite;
}
@keyframes pulseRec {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ===== 登录页 ===== */
.login-screen {
  position: fixed; inset: 0; z-index: 100;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  animation: fade 0.3s var(--ease-out);
}
.login-screen.hidden { display: none; }
.login-card { text-align: center; padding: 32px; max-width: 320px; width: 100%; }
.login-logo {
  width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 16px;
  display: block; box-shadow: var(--shadow-md); background: var(--surface);
  animation: float 4s ease-in-out infinite;
}
.login-title { font-size: 18px; font-weight: 600; color: var(--ink); margin-bottom: 4px; }
.login-sub { font-size: 13px; color: var(--ink-3); margin-bottom: 28px; }
.login-input {
  width: 100%; padding: 13px 16px; border: 1.5px solid var(--line-2);
  border-radius: var(--r-pill); font-size: 15px; outline: none;
  background: var(--surface); color: var(--ink); text-align: center;
  margin-bottom: 12px; transition: border-color 0.2s, box-shadow 0.2s;
}
.login-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.login-btn { width: 100%; padding: 13px; border-radius: var(--r-pill); border: none; }
.login-btn:disabled { opacity: 0.6; }
.login-err { color: var(--danger); font-size: 13px; margin-top: 10px; }
.login-err.hidden { display: none; }

/* ===== 骨架屏 ===== */
.skeleton-wrap { display: flex; flex-direction: column; gap: 12px; padding: 8px 0; }
.skeleton-bubble {
  height: 48px; border-radius: var(--r-lg) var(--r-lg) var(--r-lg) 6px;
  background: linear-gradient(90deg, var(--surface) 0%, var(--bg-2) 50%, var(--surface) 100%);
  background-size: 200% 100%; animation: shimmer 1.3s infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ===== 禁用原生选择 ===== */
body { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
input, textarea { -webkit-user-select: text; user-select: text; }

/* ===== 深色模式 ===== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181C;
    --bg-2: #1E2025;
    --surface: #232529;
    --surface-2: #1A1C20;
    --header-bg: rgba(22, 24, 28, 0.82);
    --ink: #E4E2DD;
    --ink-2: #969BA5;
    --ink-3: #62666E;
    --ink-4: #3F4248;
    --accent: #6BAAA0;
    --accent-deep: #5B9A90;
    --accent-tint: rgba(107, 170, 160, 0.1);
    --accent-tint-2: rgba(107, 170, 160, 0.18);
    --user-bubble: #4A7C74;
    --ai-bubble: #232529;
    --line: rgba(255, 255, 255, 0.06);
    --line-2: rgba(255, 255, 255, 0.1);
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 6px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 14px 48px rgba(0, 0, 0, 0.45);
    --shadow-accent: 0 4px 16px rgba(107, 170, 160, 0.25);
  }
  .bubble pre { background: #0E0F12; }
  .bubble code { background: var(--bg-2); }
  .brand-logo { background: var(--surface); }
  .empty .glyph { background: var(--surface); }
}
