:root {
  --bg: #17121a;
  --bg-soft: #201925;
  --card: #2a2130;
  --line: #3a2f42;
  --text: #f2e9f2;
  --muted: #a99bb0;
  --accent: #e78fb3;
  --accent-soft: #4a2f3f;
  --mine: #3c2b46;
  --radius: 18px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

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

/* hidden 属性必须真的隐藏——否则 .sheet{display:flex} 会把抽屉撑出来 */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Noto Sans CJK SC", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
}

#app { display: flex; flex-direction: column; height: 100dvh; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(8px + var(--safe-t)) 12px 8px;
  background: rgba(23, 18, 26, 0.92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  position: relative; z-index: 5;
}
.icon-btn {
  background: none; border: 0; color: var(--muted);
  font-size: 20px; line-height: 1; padding: 8px; border-radius: 12px;
}
.icon-btn:active { background: var(--card); color: var(--text); }
.who { flex: 1; display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
  background-image: url('/icons/avatar.png');
  background-size: cover; background-position: center 30%;
  color: transparent; font-weight: 600; font-size: 15px; flex: none;
  box-shadow: 0 2px 10px rgba(231, 143, 179, .25);
}
.avatar.large { width: 64px; height: 64px; font-size: 22px; margin: 0 auto 6px; }
.who-text { min-width: 0; }
.name { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 5px; margin-top: 2px; }
.dot { width: 6px; height: 6px; border-radius: 50%; background: #59c07a; display: inline-block; }
.status.busy .dot { background: var(--accent); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1 } 50% { opacity: .3 } }

/* ---------- 消息区 ---------- */
.thread {
  flex: 1; overflow-y: auto; padding: 14px 12px 6px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.daymark {
  text-align: center; font-size: 12px; color: var(--muted);
  margin: 4px 0 8px;
}
.row { display: flex; gap: 8px; max-width: 100%; }
.row.me { flex-direction: row-reverse; }
.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--card);
  border-bottom-left-radius: 6px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
  font-size: 15.5px;
  animation: pop .18s ease-out;
}
.row.me .bubble {
  background: var(--mine);
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: 6px;
}
@keyframes pop { from { transform: translateY(4px); opacity: 0 } to { transform: none; opacity: 1 } }
.typing { display: inline-flex; gap: 4px; align-items: center; height: 20px; }
.typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: bounce 1.1s infinite;
}
.typing i:nth-child(2) { animation-delay: .15s }
.typing i:nth-child(3) { animation-delay: .3s }
@keyframes bounce { 0%,60%,100% { transform: none; opacity: .45 } 30% { transform: translateY(-4px); opacity: 1 } }
.recall-chip {
  align-self: center; font-size: 11.5px; color: var(--muted);
  background: var(--bg-soft); border: 1px solid var(--line);
  padding: 3px 10px; border-radius: 999px;
}

/* ---------- 输入 ---------- */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(8px + var(--safe-b));
  background: rgba(23, 18, 26, .96);
  border-top: 1px solid var(--line);
}
#input {
  flex: 1; resize: none; max-height: 132px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 22px;
  padding: 10px 16px; font: inherit; font-size: 16px;
  line-height: 1.4; outline: none;
}
#input:focus { border-color: #5a4462; }
.send {
  width: 42px; height: 42px; flex: none; border-radius: 50%;
  border: 0; background: var(--accent); color: #2a121d;
  display: grid; place-items: center;
  transition: transform .1s ease, opacity .2s;
}
.send:active { transform: scale(.94); }
.send[disabled] { opacity: .4; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + var(--safe-b));
  transform: translateX(-50%);
  background: var(--accent-soft); color: #ffd9e6;
  border: 1px solid #6d4457;
  padding: 8px 16px; border-radius: 999px; font-size: 13px;
  max-width: 86vw; z-index: 40;
  animation: pop .2s ease-out;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- 抽屉 ---------- */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  max-height: 82dvh; display: flex; flex-direction: column;
  background: #1e1722;
  border-top-left-radius: 22px; border-top-right-radius: 22px;
  border-top: 1px solid var(--line);
  animation: slideup .22s ease-out;
  padding-bottom: var(--safe-b);
}
@keyframes slideup { from { transform: translateY(100%) } to { transform: none } }
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 8px;
}
.sheet-head h2 { margin: 0; font-size: 16px; font-weight: 600; }
.sheet-body { overflow-y: auto; padding: 0 16px 20px; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 20; }

.thread::-webkit-scrollbar, .sheet-body::-webkit-scrollbar { width: 0 }

/* ---------- 记忆 ---------- */
.mem-form { display: flex; gap: 8px; margin-bottom: 12px; }
.mem-form input {
  flex: 1; background: var(--card); border: 1px solid var(--line);
  color: var(--text); border-radius: 12px; padding: 9px 12px; font: inherit; font-size: 14px; outline: none;
}
.mem-form select {
  background: var(--card); border: 1px solid var(--line); color: var(--muted);
  border-radius: 12px; padding: 0 8px; font-size: 13px; outline: none;
}
.mem-list { display: flex; flex-direction: column; gap: 8px; }
.mem-item {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 12px;
}
.mem-item .k {
  font-size: 11px; color: var(--accent); border: 1px solid var(--accent-soft);
  padding: 2px 7px; border-radius: 999px; flex: none; margin-top: 1px;
}
.mem-item .c { flex: 1; font-size: 14px; line-height: 1.45; color: #e4d9e6; }
.mem-item button { background: none; border: 0; color: #7c6a84; font-size: 15px; padding: 2px 4px; }

/* ---------- 会话 ---------- */
.session-list { display: flex; flex-direction: column; gap: 8px; margin: 14px 0; }
.session-item {
  text-align: left; background: var(--bg-soft); border: 1px solid var(--line);
  color: var(--text); border-radius: 14px; padding: 12px 14px; font: inherit;
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
}
.session-item.active { border-color: #6d4a5d; background: var(--accent-soft); }
.session-item .t { font-size: 14.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-item .n { font-size: 11.5px; color: var(--muted); flex: none; }

.btn {
  background: var(--accent); color: #2a121d; border: 0;
  border-radius: 14px; padding: 11px 18px; font: inherit; font-weight: 600; font-size: 15px;
}
.btn.wide { width: 100%; display: block; margin: 6px 0; }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); font-weight: 500; }
.btn.danger { color: #e08a8a; }
.btn:active { opacity: .8; }

label {
  display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px;
}
label input, label textarea {
  width: 100%; margin-top: 6px;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 10px 12px; font: inherit; font-size: 15px; outline: none;
  resize: vertical;
}
label input:focus, label textarea:focus { border-color: #5a4462; }

.hint { font-size: 12.5px; color: var(--muted); text-align: center; margin: 14px 0 4px; }

/* ---------- 登录 ---------- */
.login-body {
  display: grid; place-items: center; min-height: 100dvh; padding: 24px;
  background: radial-gradient(circle at 50% 0%, #2c1e2a 0%, var(--bg) 60%);
}
.login-card {
  width: 100%; max-width: 340px; text-align: center;
  background: rgba(32, 25, 37, .8); border: 1px solid var(--line);
  border-radius: 24px; padding: 28px 22px;
}
.login-card h1 { font-size: 20px; margin: 8px 0 18px; font-weight: 600; }
.login-card input {
  width: 100%; background: var(--card); border: 1px solid var(--line);
  color: var(--text); border-radius: 14px; padding: 12px 14px; font: inherit; font-size: 16px;
  outline: none; margin-bottom: 12px; text-align: center;
}

/* ---------- 导入预览 ---------- */
.import-preview { margin: 10px 0 4px; }
.import-card {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 16px; padding: 14px;
}
.import-title { font-size: 13px; color: var(--muted); margin-bottom: 6px; word-break: break-all; }
.import-nums { font-size: 15px; margin-bottom: 10px; }
.import-nums b { color: var(--accent); font-weight: 600; }
.import-sample { font-size: 13px; color: #cdbfd2; line-height: 1.6; }
.import-sample.mem { color: var(--muted); }
.import-sample .who { color: var(--accent); margin-right: 6px; }
.import-actions { display: flex; gap: 8px; margin-top: 12px; }
.import-actions .btn { flex: 1; }

.search-input {
  width: 100%; margin: 14px 0 10px;
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 14px; padding: 10px 14px; font: inherit; font-size: 15px; outline: none;
}

/* ---------- 她的日记 ---------- */
.diary-list { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.diary-item {
  background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: 16px; padding: 14px 16px;
}
.diary-time { font-size: 12px; color: var(--muted); margin-bottom: 8px; letter-spacing: .3px; }
.diary-text {
  font-size: 15px; line-height: 1.75; color: #eadfe8;
  white-space: pre-wrap; font-family: "Songti SC", "Noto Serif CJK SC", Georgia, serif;
}

/* ---------- 消息时间 ---------- */
.msg-time {
  align-self: center;
  font-size: 11.5px;
  color: var(--muted);
  opacity: .75;
  margin: 6px 0 2px;
  letter-spacing: .3px;
}

/* ---------- 自我整理 ---------- */
.evo-block { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.evo-head { font-size: 14px; color: var(--accent); margin-bottom: 6px; }
.evo-traits { font-size: 12.5px; color: var(--muted); margin: 8px 0; }
.evo-item {
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; margin-top: 8px; font-size: 13.5px; line-height: 1.5;
}
.evo-time { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.evo-reason { color: var(--muted); font-size: 12.5px; }

/* ---------- 发图 ---------- */
.attach-btn { font-size: 22px; color: var(--muted); }
.attach-preview {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--bg-soft); border-top: 1px solid var(--line);
}
.attach-preview img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; }
.attach-remove {
  background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 50%; width: 26px; height: 26px; font-size: 13px;
}
.bubble-img { display: block; max-width: 100%; border-radius: 12px; margin-bottom: 6px; }

/* ---------- 记忆分组 ---------- */
.mem-group {
  margin: 18px 0 6px; padding-bottom: 6px;
  font-size: 13px; color: var(--muted);
  border-bottom: 1px solid var(--line);
  letter-spacing: .5px;
}
.mem-sub {
  margin: 10px 0 4px; font-size: 12px; color: var(--muted); opacity: .8;
}

/* ---------- 语音 ---------- */
.speak-btn {
  margin-left: 8px; padding: 0 4px; background: none; border: none;
  font-size: 13px; opacity: .45; cursor: pointer; vertical-align: middle;
}
.speak-btn:active { opacity: .9; }

/* ---------- 引用回复 ---------- */
.quote-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--bg-soft);
  border-top: 1px solid var(--line);
}
.quote-text { flex: 1; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-cancel {
  background: none; border: 1px solid var(--line); color: var(--muted);
  border-radius: 50%; width: 24px; height: 24px; font-size: 12px;
}
.quote-in {
  font-size: 12px; color: var(--muted);
  border-left: 2px solid var(--line);
  padding-left: 6px; margin-bottom: 4px;
  opacity: .8;
}

/* 左滑引用：允许横向手势，纵向仍可滚 */
.bubble { touch-action: pan-y; }

/* ---------- 时间线 ---------- */
.tl-row { font-size: 13px; color: var(--fg); padding: 2px 0 2px 8px; line-height: 1.5; }
.tl-mem { color: var(--muted); }
