/* ============================================================
   Companion Ever Memory — PWA 样式
   移动端优先，深色暖调
   ============================================================ */

:root {
  /* 明亮主题（小红书那一挂的：白底 + 一点红 + 柔和的粉彩色块） */
  /* 底色不用纯白 —— 纯白在大屏上很刺眼。
     微信/小红书那类都是「柔和浅灰底 + 纯白卡片」 */
  --bg:          #f2f3f6;
  --bg-soft:     #ffffff;
  --surface:     #ffffff;
  --surface-2:   #e8eaee;
  --text:        #16181c;
  --text-dim:    #565c66;
  --text-muted:  #9aa0aa;
  --accent:      #ff2442;   /* 小红书红 */
  --accent-soft: #ff6b81;
  --accent-dim:  #ffdde3;   /* 浅粉底（开关选中 / 标签 / 提示条） */
  --bubble-me:   #3a7dff;   /* 我的气泡：蓝底白字（红底看久了刺眼） */
  --bubble-me-tx:#ffffff;
  --line:        #ecedf0;
  --radius:      16px;
  --radius-sm:   12px;
  --topbar-h:    56px;

  /* 头像的粉彩配色（小红书那种柔和色块） */
  --ava-1-bg:    #dceaff; --ava-1-fg: #2f6fed;
  --ava-2-bg:    #d8f5e7; --ava-2-fg: #0f9d6e;
  --ava-3-bg:    #ffe8cc; --ava-3-fg: #dd7b16;

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

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

:root { color-scheme: light; }

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 16px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.msg.history-message { animation: none; }
.chat-sync { display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 6px 16px; color: var(--text-muted); font-size: 12px; flex-shrink: 0; }
.chat-sync button { border: 0; background: none; color: var(--accent); font: inherit; padding: 4px 8px; }
.chat-skeleton { display: flex; flex-direction: column; gap: 22px; padding: 20px 0; }
.chat-skeleton i { display: block; width: 64%; height: 60px; border-radius: 16px;
  background: linear-gradient(90deg,var(--surface) 25%,var(--surface-2) 50%,var(--surface) 75%);
  background-size: 200% 100%; animation: usage-shimmer 1.4s ease-in-out infinite; }
.chat-skeleton i:nth-child(2) { align-self: flex-end; width: 48%; height: 42px; }
@media (prefers-reduced-motion: reduce) { .chat-skeleton i { animation: none; } }
.msg { -webkit-touch-callout: none; }
.msg .body { -webkit-user-select: none; user-select: none; }
.msg:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.message-sender { font-size: 11px; color: var(--text-dim); margin-bottom: 5px; }
.message-quote {
  display: block; flex-shrink: 0;
  width: 100%; margin-top: 9px; padding: 7px 9px; border: 0; border-left: 2px solid currentColor;
  border-radius: 4px; background: #0000000b; color: inherit; font: inherit; font-size: 12px;
  text-align: left; white-space: pre-wrap; cursor: pointer; opacity: .8;
}
.message-quote-text, .composer-quote span {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45;
}
.composer-quote { display: flex; align-items: center; gap: 8px; padding: 8px 10px; margin-bottom: 8px; background: var(--surface-2); border-radius: 8px; color: var(--text-dim); font-size: 12px; }
.composer-quote span { flex: 1; min-width: 0; }
.composer-quote button { border: 0; background: transparent; color: var(--text-dim); font-size: 22px; padding: 0 5px; }
.message-actions { position: fixed; z-index: 1300; display: flex; background: #303238; border-radius: 10px; box-shadow: 0 4px 24px #0003; padding: 5px; }
.message-actions button { background: transparent; border: 0; color: #fff; font: inherit; padding: 10px 18px; border-radius: 6px; }
.message-actions button:focus-visible { outline: 2px solid #fff; }
.mention-overlay { position: fixed; z-index: 1200; top: var(--vv-top,0px); left: 0; right: 0; height: var(--app-h,100dvh); background: #0005; display: flex; align-items: flex-end; justify-content: center; }
.mention-panel { width: 100%; max-width: 720px; max-height: 85%; display: flex; flex-direction: column; background: var(--surface); border-radius: 24px 24px 0 0; padding: 12px calc(20px + var(--safe-r)) max(16px,var(--safe-b)) calc(20px + var(--safe-l)); animation: sheet-up .18s ease-out; }
.mention-heading { display: grid; grid-template-columns: 40px 1fr 40px; align-items: center; text-align: center; padding-bottom: 15px; }
.mention-heading button { border: 0; background: var(--bg); border-radius: 50%; font-size: 26px; height: 36px; width: 36px; color: var(--text); }
#mention-search { flex: 0 0 auto; width: 100%; border: 0; background: var(--bg); border-radius: 10px; padding: 12px; font: inherit; font-size: 16px; color: var(--text); }
.mention-members { overflow-y: auto; min-height: 80px; overscroll-behavior: contain; }
.mention-member { display: block; width: 100%; text-align: left; background: transparent; border: 0; border-bottom: 1px solid var(--line); padding: 19px 8px; font: inherit; color: var(--text); }
.member-option { display: flex; align-items: center; gap: 12px; padding: 13px 0; }
.member-option input { accent-color: var(--accent); width: 19px; height: 19px; }
#dialog-group, #dialog-group-settings { top: var(--vv-top,0px); bottom: auto; height: var(--app-h,100dvh); }
#dialog-group .dlg-card, #dialog-group-settings .dlg-card { max-height: 90%; }
@keyframes sheet-up { from { transform: translateY(24px); } to { transform: translateY(0); } }
@media (prefers-reduced-motion: reduce) { .mention-panel { animation: none; } }
.muted  { color: var(--text-muted); font-weight: 400; }

/* ---------- 骨架 ---------- */

.app {
  display: flex; flex-direction: column;
  /* 固定定位 + 跟随 visualViewport 的上边边边：
     - 固定定位把 app 拿出文档流 → 不会在底部留下空白
     - top/height 跟随可见视口 → 键盘弹起时输入栏不会被顶出屏幕
  */
  position: fixed;
  top: var(--vv-top, 0px);
  left: 0; right: 0;
  height: var(--app-h, 100dvh);
  max-width: 720px; margin: 0 auto;
  overflow: hidden;
}

/* ---------- 顶栏 ---------- */

.topbar {
  flex: 0 0 auto;
  height: calc(var(--topbar-h) + var(--safe-t));
  padding: var(--safe-t) calc(12px + var(--safe-r)) 0 calc(12px + var(--safe-l));
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  /* 不透明：浏览器自带的工具栏和半透明背景叠在一起，会出现一条“高斯模糊”的带状感，很难看 */
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-meta { min-width: 0; }
.topbar-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-sub { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-sub.online  { color: #12a150; }
.topbar-sub.offline { color: #e5484d; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 700; color: var(--accent);
  background: var(--accent-dim);
  flex: 0 0 auto; user-select: none;
}

.icon-btn {
  background: none; border: none; color: var(--text-dim);
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; flex: 0 0 auto;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--surface); color: var(--text); }
.icon-btn:active { transform: scale(.94); }

/* ---------- 对话区 ---------- */

.chat {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 16px calc(14px + var(--safe-r)) 8px calc(14px + var(--safe-l));
  display: flex; flex-direction: column; gap: 12px;
  /* 注意：这里不要加 scroll-behavior: smooth
     CSS 里一旦声明 smooth，JS 的 scrollTo({behavior:'auto'}) 也会走平滑动画
     （规范里 auto = 由元素的 scroll-behavior 决定，不是"立即"）。
     页面刚打开时"跳到底部"会变成一段很长的动画，还会被 iOS 中途打断，
     结果停在中间而不是底部。需要动画的地方在 JS 里显式写 behavior:'smooth'。 */
}

.msg {
  max-width: 82%; padding: 9px 14px; border-radius: var(--radius);
  font-size: 15.5px; white-space: pre-wrap;
  word-break: break-word; overflow-wrap: anywhere;
  animation: pop .22s ease-out; position: relative;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.msg.them {
  align-self: flex-start; background: var(--surface);
  border-bottom-left-radius: 6px;
}
.msg.me {
  align-self: flex-end; background: var(--bubble-me); color: var(--bubble-me-tx);
  border-bottom-right-radius: 6px;
}
.msg .cursor {
  display: inline-block; width: 7px; height: 15px;
  vertical-align: -2px; margin-left: 2px;
  background: var(--accent); border-radius: 2px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }

/* 思考过程（可展开） */
.think {
  margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 7px;
}
.think > summary {
  list-style: none; cursor: pointer;
  font-size: 12px; color: var(--text-muted);
  display: flex; align-items: center; gap: 5px;
  user-select: none;
}
.think > summary::-webkit-details-marker { display: none; }
.think > summary::before {
  content: "▸"; font-size: 9px; transition: transform .2s;
}
.think[open] > summary::before { transform: rotate(90deg); }
.think .think-body {
  font-size: 12.5px; line-height: 1.5; color: var(--text-dim);
  margin-top: 6px; white-space: pre-wrap;
  max-height: 240px; overflow-y: auto;
  padding-left: 12px; border-left: 2px solid var(--surface-2);
}

/* ---------- 正在输入 ---------- */

.typing {
  align-self: flex-start; display: flex; gap: 4px;
  padding: 11px 15px; background: var(--surface);
  border-radius: var(--radius); border-bottom-left-radius: 6px;
}
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted); animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .18s; }
.typing span:nth-child(3) { animation-delay: .36s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ---------- 输入区 ---------- */

.composer {
  position: relative;   /* 悬浮按钮（回到最新）的定位参照 */
  flex: 0 0 auto;
  padding: 8px calc(12px + var(--safe-r)) calc(8px + var(--safe-b)) calc(12px + var(--safe-l));
  background: var(--bg);
  border-top: 1px solid var(--line);
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.group-continue {
  display: block; margin: 0 0 7px auto; padding: 5px 12px; border: 1px solid var(--line);
  border-radius: 999px; background: var(--surface); color: var(--text-dim); font: inherit; font-size: 12px;
}
.group-continue:disabled { opacity: .45; }

#input {
  flex: 1 1 auto; resize: none;
  background: var(--surface); border: 1px solid transparent; border-radius: 22px;
  box-shadow: 0 1px 2px rgba(20,22,28,.05);
  color: var(--text); font: inherit; font-size: 16px; line-height: 1.45;
  padding: 10px 16px; max-height: 140px; overflow-y: auto;
  transition: border-color .15s;
}
#input:focus { outline: none; border-color: var(--accent-dim); }
#input::placeholder { color: var(--text-muted); }

.send-btn {
  flex: 0 0 auto; width: 42px; height: 42px; border-radius: 50%;
  border: none; background: var(--bubble-me);
  color: #fff; display: grid; place-items: center; cursor: pointer;
  transition: transform .12s, opacity .15s;
}
.send-btn:active { transform: scale(.9); }
.send-btn:disabled { opacity: .35; cursor: default; }

.session-btn {
  width: 100%; margin-top: 5px; padding: 5px;
  font: inherit; font-size: 12.5px; color: var(--text-muted);
  background: none; border: 1px dashed var(--line); border-radius: var(--radius-sm);
  cursor: pointer; transition: color .15s, border-color .15s;
}
.session-btn:hover { color: var(--accent-soft); border-color: var(--accent-dim); }

/* 抽屉里的版本（更明显，因为不占聊天区的高度） */
.drawer-session {
  margin: 10px 0 0;
  padding: 10px;
  font-size: 13.5px;
  color: var(--accent-soft);
  border-color: var(--accent-dim);
  background: var(--accent-dim);
}
.drawer-session:hover { color: var(--accent-soft); border-color: var(--accent); }
.session-btn:active { transform: scale(.985); }
.session-btn:disabled { opacity: .4; cursor: default; }

/* ---------- 抽屉 ---------- */

.scrim { position: fixed; inset: 0; background: #0009; z-index: 40; animation: fade .2s; }
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(420px, 88vw);
  background: var(--bg-soft); border-left: 1px solid var(--line);
  z-index: 50; transform: translateX(100%);
  transition: transform .26s cubic-bezier(.32,.72,0,1);
  display: flex; flex-direction: column;
  padding-top: var(--safe-t); padding-bottom: var(--safe-b);
}
.drawer.open { transform: translateX(0); }

.drawer-head {
  flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.drawer-head h3 { margin: 0; font-size: 16px; font-weight: 600; }
.drawer-scroll { flex: 1 1 auto; overflow-y: auto; padding: 0 16px 20px; }

.drawer-section { margin-top: 18px; }
.drawer-label {
  font-size: 12px; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .06em; margin: 0 0 8px;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid transparent;
  color: var(--text-dim); cursor: pointer; font-family: inherit;
}
.chip.active { background: var(--accent-dim); color: var(--accent); border-color: var(--accent-dim); }

.note-list { display: flex; flex-direction: column; gap: 8px; }
#view-memory .note-list { padding: 0 14px 20px; }
.note {
  padding: 9px 12px; background: var(--surface);
  border-radius: var(--radius-sm); font-size: 14px; line-height: 1.5;
  border-left: 3px solid var(--surface-2);
}
.note .note-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 3px;
}
.note .note-type { font-size: 10.5px; color: var(--text-muted); letter-spacing: .03em; }
.note .note-imp  { font-size: 10.5px; color: var(--text-muted); }
.note-content { white-space: pre-wrap; overflow-wrap: anywhere; }
.note-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 10px; }
.note-actions button { border: 0; border-radius: 8px; background: var(--surface-2); color: var(--text-dim); padding: 7px 13px; font: inherit; font-size: 13px; cursor: pointer; }
.note-actions .note-save { background: var(--accent); color: white; }
.note-actions .note-delete, .note-actions .danger { color: #bd253d; background: var(--accent-dim); }
.note-actions button:disabled { opacity: .5; cursor: default; }
.note-editor { width: 100%; min-height: 120px; max-height: 40vh; resize: vertical; margin-top: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg-soft); color: var(--text); font: inherit; font-size: 16px; line-height: 1.6; }
.note-confirm { margin-top: 12px; color: var(--text-dim); }
.note-error { color: #bd253d; font-size: 13px; margin-top: 8px; }

.empty { text-align: center; color: var(--text-muted); font-size: 13px; padding: 28px 10px; }

/* 开关 */
.switch-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; background: var(--surface);
  border-radius: var(--radius-sm); font-size: 14px; cursor: pointer;
}
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  width: 42px; height: 24px; border-radius: 999px; background: var(--surface-2);
  position: relative; flex: 0 0 auto; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px #0002;
  transition: transform .2s, background .2s;
}
.switch-row input:checked ~ .switch { background: var(--accent); }
.switch-row input:checked ~ .switch::after { transform: translateX(18px); background: #fff; }
.switch-row input:disabled ~ .switch { opacity: .45; cursor: default; }
.switch-row input:focus-visible ~ .switch { outline: 2px solid var(--accent); outline-offset: 3px; }

.stat-line { margin-top: 10px; font-size: 12px; color: var(--text-muted); line-height: 1.7; }

/* ---------- 账号登录 ---------- */

.gate { position: fixed; inset: 0; background: var(--bg); z-index: 100;
  display: grid; place-items: center; padding: 24px; }
.gate-card { width: 100%; max-width: 300px; text-align: center; }
.gate-avatar {
  width: 68px; height: 68px; border-radius: 18px; margin: 0 auto 16px; overflow: hidden;
  display: grid; place-items: center; font-size: 26px; font-weight: 700; color: var(--accent);
  background: var(--accent-dim);
}
.gate-card h2 { margin: 0 0 4px; font-size: 18px; font-weight: 600; }
.gate-avatar img { width: 100%; height: 100%; object-fit: cover; }
.gate-hint { margin: 0 0 18px; font-size: 13px; color: var(--text-muted); }
.account-input {
  width: 100%; padding: 12px 16px; font: inherit; font-size: 16px;
  text-align: left;
  background: var(--surface); border: 1px solid transparent;
  border-radius: var(--radius-sm); color: var(--text); margin-bottom: 12px;
}
.account-input:focus { outline: none; border-color: var(--accent-dim); }
.btn-primary {
  width: 100%; padding: 12px; font: inherit; font-weight: 600;
  background: var(--accent);
  color: #fff; border: none; border-radius: var(--radius-sm); cursor: pointer;
}
.btn-primary:active { transform: scale(.98); }
.gate-error { color: #e08a8a; font-size: 13px; min-height: 20px; margin: 10px 0 0; }

/* ---------- Toast ---------- */

.toast {
  position: fixed; left: 50%; bottom: calc(28px + var(--safe-b));
  transform: translateX(-50%);
  background: #2b2e34; color: #fff;
  padding: 10px 18px; border-radius: 999px; font-size: 13.5px; z-index: 100;
  box-shadow: 0 8px 28px #0000001f;
  animation: toast-in .24s cubic-bezier(.32,.72,0,1);
  max-width: 88vw; text-align: center;
}
/* 对话框打开时提示挪到顶部——否则被面板挡在下面，根本看不见 */
.toast.toast-top { bottom: auto; top: calc(14px + var(--safe-t)); animation: toast-in-top .24s cubic-bezier(.32,.72,0,1); }
@keyframes toast-in-top { from { opacity: 0; transform: translate(-50%, -14px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- 桌面端 ---------- */

@media (min-width: 720px) {
  .chat { padding-left: 24px; padding-right: 24px; }
  .msg { max-width: 68%; }
  .composer { padding-left: 24px; padding-right: 24px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .chat { scroll-behavior: auto; }
}

/* ============================================================
   历史记录浏览（微信式）
   ============================================================ */

/* 消息流里的日期分隔条 */
/* 时间分隔条：只有"隔了很久"才插一条（微信那套） */
.time-sep {
  align-self: center;
  font-size: 11.5px;
  color: var(--text-muted);
  padding: 10px 0 4px;
  margin: 0;
}

/* 正在查看历史时的提示条 */
.history-bar {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 7px calc(14px + var(--safe-r)) 7px calc(14px + var(--safe-l));
  background: var(--accent-dim);
  color: var(--accent);
  font-size: 12.5px;
  border-bottom: 1px solid var(--line);
}
.history-bar button {
  font: inherit; font-size: 12.5px; font-weight: 600;
  color: var(--accent); background: none;
  border: 1px solid var(--accent); border-radius: 999px;
  padding: 3px 12px; cursor: pointer;
}
.history-bar button:active { transform: scale(.96); }

/* 上滑加载提示 */
.chat-location-loading {
  position: absolute; inset: calc(var(--topbar-h) + var(--safe-t)) 0 0;
  z-index: 10; display: grid; place-content: center;
  background: var(--bg-soft); color: var(--text-dim); font-size: 14px;
}
.load-more-hint {
  position: absolute;
  top: calc(var(--topbar-h) + var(--safe-t) + 6px);
  left: 50%; transform: translateX(-50%);
  font-size: 11.5px; color: var(--text-muted);
  background: var(--surface-2);
  padding: 3px 12px; border-radius: 999px;
  z-index: 6; pointer-events: none;
}

/* ---------- 搜索面板 ---------- */

.search-panel {
  position: fixed; inset: 0; z-index: 70;
  background: var(--bg-soft);
  display: flex; flex-direction: column;
  padding-top: var(--safe-t);
  padding-bottom: var(--safe-b);
}

.search-head {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 10px calc(12px + var(--safe-r)) 10px calc(12px + var(--safe-l));
  border-bottom: 1px solid var(--line);
}
#search-input {
  flex: 1 1 auto;
  background: var(--surface); border: 1px solid transparent;
  border-radius: 20px; color: var(--text);
  font: inherit; font-size: 16px; padding: 9px 16px;
}
#search-input:focus { outline: none; border-color: var(--accent-dim); }
#search-input::-webkit-search-cancel-button { opacity: .45; }

.search-tabs {
  flex: 0 0 auto;
  display: flex; gap: 6px;
  padding: 10px calc(14px + var(--safe-r)) 4px calc(14px + var(--safe-l));
}

.search-results {
  flex: 1 1 auto; overflow-y: auto;
  padding: 6px calc(14px + var(--safe-r)) 20px calc(14px + var(--safe-l));
}

.hit {
  padding: 10px 12px; margin-bottom: 8px;
  background: var(--surface); border-radius: var(--radius-sm);
  font-size: 14px; line-height: 1.5;
  border-left: 3px solid var(--surface-2);
  cursor: pointer;
}
.hit:active { background: var(--surface-2); }
.hit[data-kind="memory"] { border-left-color: #9b7fd4; }
.hit[data-kind="message"] { border-left-color: #4a90d9; }
.hit .hit-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 8px; margin-bottom: 3px;
}
.hit .hit-meta { font-size: 10.5px; color: var(--text-muted); }
.hit .hit-text { white-space: pre-wrap; word-break: break-word; }
.hit mark { background: var(--accent-dim); color: var(--accent-soft); border-radius: 3px; padding: 0 1px; }

/* 抽屉里的日期列表 */
.date-list { display: flex; flex-direction: column; gap: 6px; }
.date-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 9px 12px; background: var(--surface);
  border-radius: var(--radius-sm); font-size: 14px; cursor: pointer;
}
.date-row:active { background: var(--surface-2); }
.date-row .n { font-size: 12px; color: var(--text-muted); }

/* ---------- debug 面板（?debug=1） ---------- */
#debug-panel {
  position: fixed;
  white-space: pre;
  left: 6px;
  bottom: calc(6px + var(--safe-b));
  z-index: 999;
  background: #000c;
  color: #9fe;
  font: 10px/1.45 ui-monospace, Menlo, Consolas, monospace;
  padding: 6px 8px;
  border-radius: 6px;
  white-space: pre;
  pointer-events: none;
}

/* ============================================================
   回到最新（微信式悬浮按钮）
   用户往上翻历史时出现；有新消息时显示"N 条新消息"
   ============================================================ */
.jump-latest {
  position: absolute;
  right: 14px;
  bottom: calc(100% + 10px);
  z-index: 8;
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
  box-shadow: 0 4px 16px rgba(20,22,28,.16);
  font-family: inherit; font-size: 12.5px; line-height: 1.4;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  animation: jump-in .18s ease-out;
}
.jump-latest:active { transform: scale(.96); }
@keyframes jump-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ============================================================
   Markdown 渲染（模型输出里的 **粗体**、列表等）
   ============================================================ */
.msg .body strong { font-weight: 700; }
.msg .body em { font-style: italic; }
.msg .body del { opacity: .6; }
.msg .body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: .9em;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
}
.msg .body ul, .msg .body ol { margin: 4px 0; padding-left: 20px; }
.msg .body li { margin: 2px 0; }
.msg .body a { color: var(--accent); }

/* ============================================================
   多视图结构（消息 / 通讯录 / 我 / 会话 / 角色资料 / TA 的记忆）
   多页面布局
   ============================================================ */

.views { flex: 1 1 auto; position: relative; overflow: hidden; }
.view  { position: absolute; inset: 0; display: none; flex-direction: column; }
.view.active { display: flex; }
.scroll { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ---------- 导航栏 ---------- */
.nav {
  flex: 0 0 auto;
  height: calc(var(--topbar-h) + var(--safe-t));
  padding: var(--safe-t) calc(12px + var(--safe-r)) 0 calc(12px + var(--safe-l));
  display: flex; align-items: center; gap: 10px;
  background: var(--bg); border-bottom: 1px solid var(--line); z-index: 20;
}
.nav-title { font-size: 17px; font-weight: 700; white-space: nowrap; }
.nav-btn {
  width: 34px; height: 34px; border-radius: 50%; border: none;
  background: var(--surface-2); color: var(--text);
  display: grid; place-items: center; font-size: 19px; line-height: 1;
  cursor: pointer; flex: 0 0 auto;
}
.nav-actions { position: relative; flex: 0 0 auto; }
.create-menu {
  position: absolute; top: calc(100% + 13px); right: 0; z-index: 25;
  width: 166px; padding: 4px 0; border-radius: 9px; background: #4b4b4b;
  box-shadow: 0 6px 24px #0002; color: #fff;
}
.create-menu::before {
  content: ''; position: absolute; top: -7px; right: 10px;
  width: 14px; height: 14px; transform: rotate(45deg); background: inherit;
}
.create-menu button {
  position: relative; width: 100%; display: flex; align-items: center; gap: 13px;
  padding: 14px 18px; border: 0; background: transparent; color: inherit;
  font: inherit; font-size: 15px; text-align: left; cursor: pointer;
}
.create-menu button + button { border-top: 1px solid #ffffff1c; }
.create-menu button:active, .create-menu button:focus-visible { background: #ffffff18; outline: none; }
.create-menu svg { flex: 0 0 auto; }
.spacer { margin-left: auto; }
/* 会话页顶栏：左返回 + 中间名字 + 右搜索/头像，用 flex-start 而不是 space-between */
.topbar-nav { justify-content: flex-start; }

/* ---------- 列表行（微信式） ---------- */
.list { flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.cell { display: flex; align-items: center; gap: 12px; padding: 11px 14px; position: relative; }
.cell + .cell::before {
  content: ''; position: absolute; left: 72px; right: 0; top: 0;
  height: 1px; background: var(--line);
}
.ava {
  width: 46px; height: 46px; flex: 0 0 auto; border-radius: 12px;
  background: var(--accent-dim); color: var(--accent);
  font-weight: 700; font-size: 19px;
  display: grid; place-items: center; user-select: none;
  border: none; cursor: pointer; font-family: inherit;
}
.ava-s1 { background: var(--ava-1-bg); color: var(--ava-1-fg); }
.ava-s2 { background: var(--ava-2-bg); color: var(--ava-2-fg); }
.ava-s3 { background: var(--ava-3-bg); color: var(--ava-3-fg); }
.ava-sm { width: 32px; height: 32px; border-radius: 9px; font-size: 14px; }
.ava-lg { width: 56px; height: 56px; border-radius: 14px; font-size: 23px; }
.ava-xl { width: 72px; height: 72px; border-radius: 20px; font-size: 30px; }
.cell-body { flex: 1 1 auto; min-width: 0; }
.cell-title { font-size: 16px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.cell-sub { font-size: 13px; color: var(--text-muted); overflow: hidden;
            text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.cell-meta { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.cell-time { font-size: 11.5px; color: var(--text-muted); }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
         background: #e5484d; color: #fff; font-size: 11px; font-weight: 600;
         display: grid; place-items: center; }
.pin { font-size: 10px; color: var(--accent); border: 1px solid var(--accent);
       border-radius: 4px; padding: 0 4px; line-height: 15px; font-weight: 500; }
.group-label { font-size: 12px; color: var(--text-muted); padding: 14px 18px 7px; }

/* ---------- 分组设置行 ---------- */
.group {
  background: var(--bg-soft); margin: 10px 0 0;
  border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; position: relative; font-size: 15.5px;
}
.row + .row::before, .notification-hint.hidden + .row::before { content: ''; position: absolute; left: 16px; right: 0; top: 0;
                       height: 1px; background: var(--line); }
.row-val { color: var(--text-muted); font-size: 14px; display: flex; align-items: center; gap: 6px; }
.row-val.col { flex-direction: column; align-items: flex-end; gap: 2px; }
.dim-sm { font-size: 11.5px; color: var(--text-dim); }
.chev { color: var(--text-muted); font-size: 16px; line-height: 1; }
.switch-inline { padding: 0; background: none; border-radius: 0; }
.btn-mini { background: var(--accent); color: #fff; border-radius: 999px;
            padding: 4px 13px; font-size: 12.5px; font-weight: 600; }
.btn-mini.is-busy { opacity: .55; }

/* ---------- 底部 Tab ---------- */
.tabbar {
  flex: 0 0 auto;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--bg-soft); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--text-muted); font-size: 10.5px;
  background: none; border: none; font-family: inherit; cursor: pointer;
  padding: 7px 0 6px;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); }

/* ---------- 统计条 ---------- */
.stats { display: flex; margin: 10px 14px 12px; background: var(--bg-soft);
         border-radius: 14px; padding: 14px 0; }
.stats > div { flex: 1; text-align: center; position: relative; }
.stats > div + div::before { content: ''; position: absolute; left: 0; top: 4px;
                              bottom: 4px; width: 1px; background: var(--line); }
.stat-num { font-size: 22px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

/* ---------- 我 ---------- */
.me-card { display: flex; align-items: center; gap: 14px; padding: 20px 16px; background: var(--bg-soft); }
.me-name { font-size: 18px; font-weight: 600; }
.me-details { min-width: 0; }
.me-sub { font-size: 12.5px; color: var(--text-muted); margin-top: 4px; line-height: 1.6; }
.usage-skeleton { width: 76px; height: 10px; border-radius: 5px;
  background: linear-gradient(90deg,var(--surface-2) 25%,var(--line) 50%,var(--surface-2) 75%);
  background-size: 200% 100%; animation: usage-shimmer 1.4s ease-in-out infinite; }
.usage-notes { padding: 12px 16px 16px; margin: 0; color: var(--text-muted); font-size: 11.5px; line-height: 1.7; }
.usage-notes p { margin: 0; }
.usage-notes p + p { margin-top: 4px; }
#usage-refresh.is-loading::before { content: ''; display: inline-block; vertical-align: -1px; margin-right: 6px;
  width: 10px; height: 10px; border: 1.5px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: usage-spin .8s linear infinite; }
@keyframes usage-shimmer { to { background-position: -200% 0; } }
@keyframes usage-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .usage-skeleton, #usage-refresh.is-loading::before { animation: none; }
}
.hint { font-size: 11.5px; color: var(--text-muted); text-align: center;
        padding: 14px 20px 20px; line-height: 1.6; }

/* ---------- 角色资料 ---------- */
.profile-hero { display: flex; flex-direction: column; align-items: center; gap: 8px;
                padding: 18px 0 22px; }
.profile-name { font-size: 20px; font-weight: 700; }
.profile-sub { font-size: 13px; color: var(--text-muted); }
.chips { padding: 0 14px 8px; margin-bottom: 0; }
.note-bar { height: 3px; background: var(--surface-2); border-radius: 2px; margin-top: 9px; }
.note-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

/* ============================================================
   日历（按日期回溯）
   有聊天记录的日期可点；没有的置灰
   ============================================================ */
.cal-panel {
  position: fixed; inset: 0; z-index: 70;
  background: var(--bg-soft);
  display: flex; flex-direction: column;
  padding-top: var(--safe-t);
  animation: cal-in .18s ease-out;
}
@keyframes cal-in { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: none; } }
.cal-head {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  background: var(--bg-soft);
}
.cal-title { font-size: 17px; font-weight: 700; }
.cal-today-btn {
  font: inherit; font-size: 13px; font-weight: 600;
  color: var(--accent); background: var(--accent-dim);
  border: none; border-radius: 999px; padding: 5px 14px; cursor: pointer;
}
.cal-today-btn:active { transform: scale(.96); }
/* 月份连着排，可以一直往上滑（像 iOS 日历） */
.cal-scroll {
  flex: 1 1 auto; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  position: relative;   /* "本月"按钮靠 offsetTop 定位 */
  /* 底部留白：否则最后一个月（本月）滚不上去，滑不动就没法加载更早的月份 */
  padding-bottom: 20vh;
}
.cal-month { padding-bottom: 6px; }
.cal-month-title {
  font-size: 14px; font-weight: 600; color: var(--text-muted);
  padding: 12px 14px 4px;
}
.cal-week {
  display: grid; grid-template-columns: repeat(7, 1fr);
  padding: 0 6px;
}
.cal-week span { min-width: 0; }
.cal-week span { text-align: center; font-size: 12px; color: var(--text-muted); }
/* 日期格子：固定行高（微信/iOS 日历那样紧凑），
   不能用 aspect-ratio —— 那会让网格列被内容撑大、横向溢出。 */
.cal-days {
  display: grid; grid-template-columns: repeat(7, 1fr);
  grid-auto-rows: 44px;
  padding: 2px 6px;
}
.cal-day {
  min-width: 0;
  display: grid; place-items: center;
  font-size: 15px; color: var(--text); position: relative;
}
.cal-day.empty { color: #d2d6dd; }
.cal-day.has { cursor: pointer; }
.cal-day.has:active { opacity: .55; }
/* 有记录的日期：下面一个小圆点 */
.cal-day.has::after {
  content: ''; position: absolute; bottom: 7px; left: 50%;
  transform: translateX(-50%);
  width: 4px; height: 4px; border-radius: 50%; background: var(--accent);
}
/* 今天：实心圆（数字包一层 span，避免被网格拉伸变形） */
.cal-day.today { color: var(--accent); font-weight: 700; }
.cal-day.today > span {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
}
.cal-day.today::after { display: none; }
.cal-foot {
  padding: 10px 16px calc(16px + var(--safe-b));
  font-size: 12px; color: var(--text-muted); text-align: center;
  border-top: 1px solid var(--line); background: var(--bg-soft);
}

/* ---------- 底部 Tab 角标（未读总数） ---------- */
.tab { position: relative; }
.tab-ico { position: relative; display: block; line-height: 0; }
.tab-badge {
  position: absolute; top: -6px; left: 14px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 8px; background: #e5484d; color: #fff;
  font-size: 10px; font-weight: 600; line-height: 16px;
  text-align: center; box-sizing: border-box;
}

/* ============================================================
   顶栏居中 + "对方正在输入"（微信那套）
   ============================================================ */
.topbar-nav { position: relative; justify-content: flex-start; }
.nav-center {
  position: absolute; left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center;
  pointer-events: none;
}
.topbar-sub:empty { display: none; }
.nav-btn-ico svg { display: block; }

/* 正在输入的三个点 */
.dots {
  display: inline-flex; gap: 3px; margin-left: 3px;
  vertical-align: middle;
}
.dots i {
  width: 4px; height: 4px; border-radius: 50%;
  background: var(--accent); display: inline-block;
  animation: dot-bounce 1.2s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: .16s; }
.dots i:nth-child(3) { animation-delay: .32s; }
@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .35; }
  30% { transform: translateY(-3px); opacity: 1; }
}

.note[data-kind="fact"] { border-left-color: #4a90d9; }
.note[data-kind="episode"] { border-left-color: #d4a03f; }
.reply-status { margin: 12px auto; padding: 10px 12px; max-width: 90%; color: var(--text-dim); font-size: 13px; text-align: center; }
.reply-status .btn-mini { margin-left: 10px; }

/* ---------- 新建角色对话框 ---------- */
.dlg {
  position: fixed; inset: 0; z-index: 90;
  background: #16181c66;
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 560px) { .dlg { align-items: center; } }

.dlg-card {
  width: 100%; max-width: 460px; max-height: 92vh;
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -8px 40px #00000026;
  padding-bottom: var(--safe-b);
}
@media (min-width: 560px) {
  .dlg-card { border-radius: var(--radius); max-height: 86vh; }
}

.dlg-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px 10px; border-bottom: 1px solid var(--line);
}
.dlg-title { font-size: 16px; font-weight: 600; flex: 1; }

.dlg-body { overflow-y: auto; padding: 14px 16px; -webkit-overflow-scrolling: touch; }
.dlg-label { font-size: 13px; font-weight: 600; color: var(--text-dim); margin: 14px 0 6px; }
.dlg-label:first-child { margin-top: 0; }
.dlg-hint { font-size: 12px; color: var(--text-muted); margin: -2px 0 8px; }

.dlg-input, .dlg-textarea {
  width: 100%; font: inherit; font-size: 14px; color: var(--text);
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 11px; margin-bottom: 8px;
}
.dlg-input:focus, .dlg-textarea:focus {
  outline: none; border-color: var(--accent-soft); background: var(--surface);
}
/* 背景、说话风格这类长文本：随内容自动长高，不出内部滚动条 */
.dlg-textarea { min-height: 40px; max-height: 34vh; resize: none; line-height: 1.5; overflow-y: auto; }
.dlg-field-label { font-size: 12.5px; color: var(--text-dim); margin: 0 0 4px; display: block; }

/* 角色设定里的列表字段（性格/价值观/习惯…）：一条一个标签，可换行 */
.chip-input {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 7px 9px; margin-bottom: 8px;
}
.chip-input:focus-within { border-color: var(--accent-soft); background: var(--surface); }
.chip-item {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--accent-dim); color: var(--text);
  border-radius: 999px; padding: 3px 5px 3px 10px; font-size: 13px; line-height: 1.4;
}
.chip-x {
  border: none; background: none; cursor: pointer;
  color: var(--text-dim); font-size: 15px; line-height: 1; padding: 0 4px;
}
.chip-entry {
  flex: 1 1 96px; min-width: 96px; border: none; background: none;
  font: inherit; font-size: 14px; color: var(--text); padding: 3px 0;
}
.chip-entry:focus { outline: none; }
.chip-entry::placeholder { color: var(--text-muted); }

.tpl-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.tpl-card {
  text-align: left; font: inherit; cursor: pointer;
  background: var(--bg-soft); border: 1.5px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 11px;
}
.tpl-card.is-active { border-color: var(--accent); background: var(--accent-dim); }
.tpl-name { font-size: 14px; font-weight: 600; color: var(--text); }
.tpl-id { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.dlg-foot {
  display: flex; gap: 10px; padding: 12px 16px;
  border-top: 1px solid var(--line);
}
.dlg-btn {
  flex: 1; font: inherit; font-size: 15px; cursor: pointer;
  background: var(--surface-2); color: var(--text);
  border: none; border-radius: var(--radius-sm); padding: 11px 12px;
}
.dlg-btn-primary { background: var(--accent); color: #fff; }
#dialog-group .dlg-btn { min-height: 44px; min-width: 0; font-weight: 600; white-space: nowrap; }
#group-save { flex: 2; }
#group-title:focus { outline: none; }

.notification-action { border: 0; background: transparent; color: var(--accent); font: inherit; cursor: pointer; padding: 8px 0 8px 12px; }
.notification-action:disabled { opacity: .5; cursor: default; }
.notification-hint { padding: 0 16px 12px; color: var(--text-muted); font-size: 12px; line-height: 1.6; }

.dlg-danger {
  margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line);
}
.dlg-danger-btn {
  font: inherit; font-size: 13.5px; cursor: pointer;
  background: none; border: 1px solid var(--line); color: var(--text-dim);
  border-radius: var(--radius-sm); padding: 8px 14px;
}

.account-input { display: block; margin: 12px 0; width: 100%; box-sizing: border-box; }
.account-row { width: 100%; text-align: left; font: inherit; background: transparent; border: 0; color: inherit; cursor: pointer; }
.account-link { display: block; margin: 16px auto; border: 0; background: transparent; color: var(--accent); font: inherit; }
