:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --ink: #1f2430;
  --ink-2: #6b7280;
  --ink-3: #9aa3b2;
  --line: #e6e9f0;
  --brand: #4f7cf7;
  --brand-2: #eaf0ff;
  --input-bg: #f7f9fc;
  --input-bg-focus: #ffffff;
  --radius: 16px;
  --shadow: 0 2px 12px rgba(31, 36, 48, .06);
}

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

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

body { overflow: hidden; }
.hidden { display: none !important; }

/* ───────── 登录 ───────── */
.login {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background: linear-gradient(170deg, #eef3ff 0%, #f7f8fc 55%, #f3f6fb 100%);
}
.login-card {
  width: 100%; max-width: 340px;
  background: var(--card); border-radius: 22px;
  padding: 32px 24px 26px; text-align: center;
  box-shadow: 0 12px 40px rgba(31, 36, 48, .1);
}
.logo {
  width: 56px; height: 56px; margin: 0 auto 14px;
  border-radius: 18px; background: var(--brand); color: #fff;
  font-size: 26px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.login-card h1 { font-size: 19px; margin: 0 0 6px; font-weight: 600; letter-spacing: .5px; }
.login-card .hint { color: var(--ink-3); font-size: 13px; margin: 0 0 20px; }
.login-card input {
  width: 100%; padding: 13px 16px; font-size: 19px; letter-spacing: 4px;
  text-align: center; border: 1px solid var(--line); border-radius: 12px;
  outline: none; background: var(--input-bg); color: var(--ink);
  font-family: inherit;
}
.login-card input::placeholder { color: var(--ink-3); letter-spacing: 4px; }
.login-card input:focus { border-color: var(--brand); background: var(--input-bg-focus); }
.login-card button {
  width: 100%; margin-top: 14px; padding: 13px;
  border: 0; border-radius: 12px; background: var(--brand); color: #fff;
  font-size: 16px; font-weight: 500; letter-spacing: 2px;
  font-family: inherit;
}
.login-card button:active { transform: scale(.985); opacity: .92; }
.err { color: #e05252; font-size: 13px; min-height: 18px; margin: 10px 0 0; }

/* ───────── 主界面 ───────── */
.app {
  height: 100%; display: flex; flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}
.topbar {
  flex: 0 0 auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: rgba(255, 255, 255, .88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  position: relative; z-index: 10;
}
.title-wrap { flex: 1; min-width: 0; text-align: center; }
.title-wrap > div:first-child {
  font-size: 15px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sub { font-size: 11.5px; color: var(--ink-3); margin-top: 1px; }
.icon-btn {
  flex: 0 0 auto; width: 38px; height: 38px; border: 0; border-radius: 11px;
  background: transparent; color: var(--ink-2); font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit;
}
.icon-btn:active { background: #eef1f7; }
.icon-btn.small { width: 34px; height: 34px; font-size: 16px; }

/* ───────── 消息区 ───────── */
.msgs {
  flex: 1 1 auto; overflow-y: auto; overflow-x: hidden;
  padding: 16px 12px 8px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}
.row { display: flex; margin-bottom: 14px; }
.row.user { justify-content: flex-end; }
.bubble {
  max-width: 82%;
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 15.5px;
  word-break: break-word;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.row.ai .bubble {
  background: var(--card); color: var(--ink);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow);
}
.row.user .bubble {
  background: var(--brand); color: #fff;
  border-bottom-right-radius: 6px;
}
.bubble p { margin: 0 0 8px; }
.bubble p:last-child { margin-bottom: 0; }
.bubble code {
  background: rgba(0, 0, 0, .06); padding: 1px 5px; border-radius: 5px;
  font-size: .92em; font-family: ui-monospace, Consolas, monospace;
}
.row.user .bubble code { background: rgba(255, 255, 255, .22); }
.bubble pre {
  background: #f4f6fa; padding: 10px 12px; border-radius: 10px;
  overflow-x: auto; margin: 8px 0; white-space: pre;
}
.bubble pre code { background: none; padding: 0; }
.bubble ol, .bubble ul { margin: 6px 0; padding-left: 22px; }
.bubble li { margin: 3px 0; }
.bubble strong { font-weight: 600; }
.bubble h1, .bubble h2, .bubble h3 { font-size: 1.05em; margin: 10px 0 6px; font-weight: 600; }

.tools {
  display: flex; gap: 12px; margin: -6px 0 14px 4px;
  font-size: 12px; color: var(--ink-3);
}
.tools button {
  border: 0; background: none; color: var(--ink-3); font-size: 12px;
  padding: 2px 0; font-family: inherit;
}
.tools button:active { color: var(--brand); }

.thinking {
  font-size: 12.5px; color: var(--ink-3);
  background: #eef1f7; border-radius: 10px; padding: 6px 10px;
  margin-bottom: 6px; max-width: 82%; display: none;
  white-space: pre-wrap; max-height: 92px; overflow: hidden;
}
.thinking.on { display: block; }

.dots { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.dots i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ink-3);
  animation: blink 1.3s infinite;
}
.dots i:nth-child(2) { animation-delay: .18s; }
.dots i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

.notice {
  text-align: center; font-size: 12px; color: var(--ink-3);
  margin: 10px 0 16px;
}
.notice b { color: var(--brand); font-weight: 500; }

.empty-hint {
  text-align: center; color: var(--ink-3); font-size: 14px;
  margin-top: 22vh; line-height: 2;
}
.empty-hint .big { font-size: 30px; display: block; margin-bottom: 10px; }

/* ───────── 输入区 ───────── */
.composer {
  flex: 0 0 auto;
  display: flex; flex-direction: column; align-items: stretch; gap: 8px;
  padding: 8px 12px calc(9px + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.composer-row { display: flex; align-items: flex-end; gap: 8px; }

/* 深度思考 / 联网搜索 */
.chips { display: flex; gap: 7px; padding: 0 2px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 15px;
  border: 1px solid var(--line); background: var(--input-bg); color: var(--ink-2);
  font-size: 12.5px; font-family: inherit; line-height: 1.2;
  transition: background .15s, color .15s, border-color .15s;
}
.chip .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ink-3); transition: background .15s;
}
.chip:active { transform: scale(.97); }
.chip.on {
  background: var(--brand-2); border-color: var(--brand);
  color: var(--brand); font-weight: 500;
}
.chip.on .dot { background: var(--brand); box-shadow: 0 0 0 3px rgba(79, 124, 247, .16); }

/* 参考网页 */
.sources {
  margin: -4px 0 16px 4px; padding: 10px 12px;
  background: #f8fafd; border-radius: 12px; max-width: 88%;
}
.sources-head { font-size: 11.5px; color: var(--ink-3); margin-bottom: 6px; }
.src {
  display: flex; gap: 7px; text-decoration: none; padding: 6px 0;
  border-top: 1px solid var(--line);
}
.src:first-of-type { border-top: 0; }
.src-n {
  flex: 0 0 auto; color: var(--ink-3); font-size: 11.5px;
  line-height: 1.6; font-variant-numeric: tabular-nums;
}
.src-t {
  flex: 1; min-width: 0; font-size: 13px; color: var(--brand); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.composer textarea {
  flex: 1 1 auto;
  min-height: 42px; max-height: 140px;
  padding: 10px 14px;
  border: 1px solid var(--line); border-radius: 21px;
  background: var(--input-bg); color: var(--ink);
  font-size: 16px; line-height: 1.5; font-family: inherit;
  resize: none; outline: none;
  overflow-y: auto;
}
.composer textarea::placeholder { color: var(--ink-3); }
.composer textarea:focus { border-color: var(--brand); background: var(--input-bg-focus); }
.send {
  flex: 0 0 auto; height: 42px; padding: 0 18px;
  border: 0; border-radius: 21px; background: var(--brand); color: #fff;
  font-size: 15px; font-weight: 500; font-family: inherit;
}
.send:disabled { background: #c3cff0; }
.send:active:not(:disabled) { opacity: .9; }

/* ───────── 抽屉 ───────── */
.mask {
  position: fixed; inset: 0; background: rgba(20, 24, 34, .32);
  z-index: 40; opacity: 0; transition: opacity .22s;
}
.mask.on { opacity: 1; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 84%; max-width: 360px;
  background: var(--card); z-index: 50;
  display: flex; flex-direction: column;
  transform: translateX(-102%); transition: transform .26s cubic-bezier(.3, .8, .4, 1);
  box-shadow: 4px 0 24px rgba(20, 24, 34, .12);
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  padding: calc(14px + env(safe-area-inset-top)) 14px 12px;
  border-bottom: 1px solid var(--line);
}
.seg { display: flex; gap: 6px; background: #f1f4fa; padding: 4px; border-radius: 11px; }
.seg-btn {
  flex: 1; padding: 7px 0; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink-2); font-size: 13.5px;
  font-family: inherit;
}
.seg-btn.active { background: #fff; color: var(--ink); font-weight: 600; box-shadow: 0 1px 4px rgba(0, 0, 0, .07); }
.drawer-body { flex: 1 1 auto; overflow-y: auto; padding: 14px; }
.drawer-foot {
  padding: 10px 14px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.link-btn { border: 0; background: none; color: var(--ink-3); font-size: 13px; padding: 4px; font-family: inherit; }

.wide-btn {
  width: 100%; padding: 12px; margin-bottom: 14px;
  border: 1px dashed var(--brand); border-radius: 12px;
  background: var(--brand-2); color: var(--brand);
  font-size: 14.5px; font-weight: 500; font-family: inherit;
}
.session-list { display: flex; flex-direction: column; gap: 6px; }
.sess {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-radius: 11px; background: #f8fafd;
  border: 1px solid transparent;
}
.sess.active { background: var(--brand-2); border-color: #cddbff; }
.sess-main { flex: 1; min-width: 0; }
.sess-title {
  font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sess-meta { font-size: 11.5px; color: var(--ink-3); margin-top: 2px; }
.sess-del {
  flex: 0 0 auto; border: 0; background: none; color: var(--ink-3);
  font-size: 15px; padding: 4px 6px; font-family: inherit;
}
.sess-del.arm { color: #e05252; font-size: 12px; }

/* ───────── 用量 ───────── */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.stat { background: #f8fafd; border-radius: 12px; padding: 12px 10px; text-align: center; }
.stat .k { font-size: 11.5px; color: var(--ink-3); }
.stat .v { font-size: 18px; font-weight: 600; margin-top: 3px; letter-spacing: .3px; }
.stat .u { font-size: 10.5px; color: var(--ink-3); }
.chart-wrap { margin-top: 18px; }
.chart-title { font-size: 12.5px; color: var(--ink-2); margin-bottom: 8px; }
.chart { display: flex; align-items: flex-end; gap: 5px; height: 92px; }
.bar { flex: 1 1 0; max-width: 30px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 3px; }
.bar i {
  display: block; width: 100%; min-height: 2px; border-radius: 3px 3px 0 0;
  background: linear-gradient(180deg, #7ba0ff, var(--brand));
}
.bar span { font-size: 8.5px; color: var(--ink-3); white-space: nowrap; }
.usage-sessions { display: flex; flex-direction: column; gap: 6px; }
.us {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font-size: 13px; padding: 8px 10px; background: #f8fafd; border-radius: 9px;
}
.us .n { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.us .t { color: var(--ink-2); font-size: 12px; font-variant-numeric: tabular-nums; }
.tip { font-size: 12px; color: var(--ink-3); line-height: 1.7; margin: 14px 0 0; }

/* ───────── 记忆 ───────── */
.memory-list { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.mem-item {
  display: flex; gap: 8px; align-items: flex-start;
  font-size: 13.5px; background: #f8fafd; border-radius: 9px; padding: 9px 11px;
}
.mem-item .mt { flex: 1; }
.mem-item button { border: 0; background: none; color: var(--ink-3); font-size: 14px; padding: 0 2px; font-family: inherit; }
.mem-add { display: flex; gap: 8px; margin-top: 12px; }
.mem-add input {
  flex: 1; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; font-family: inherit; outline: none;
  background: var(--input-bg); color: var(--ink);
}
.mem-add input::placeholder { color: var(--ink-3); }
.mem-add input:focus { border-color: var(--brand); background: var(--input-bg-focus); }
.mem-add button {
  padding: 0 16px; border: 0; border-radius: 10px; background: var(--brand); color: #fff;
  font-size: 14px; font-family: inherit;
}
.danger-btn {
  width: 100%; margin-top: 16px; padding: 10px;
  border: 1px solid #f3c9c9; border-radius: 10px; background: #fff6f6; color: #d64d4d;
  font-size: 13.5px; font-family: inherit;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161c; --card: #1c1f27; --ink: #e8ebf2; --ink-2: #a3acbd; --ink-3: #6f7888;
    --line: #2a2e39; --brand: #5c88ff; --brand-2: #222b45;
    --input-bg: #22262f; --input-bg-focus: #2c313c;
    --shadow: 0 2px 12px rgba(0, 0, 0, .3);
  }
  .login { background: #101218; }
  .login-card { background: #1c1f27; }
  .topbar, .composer { background: rgba(28, 31, 39, .9); }
  .seg, .stat, .sess, .us, .mem-item, .bubble pre, .sources { background: #22262f; }
  .icon-btn:active { background: #2a2e39; }
  .seg-btn.active { background: #2e333f; }
}