/* ============================================================
   VerveLink · 主题与视觉
   - 跟随系统 / 手动浅色 / 手动深色
   - 三种蓝色主调（深海 / 天蓝 / 雾蓝）
   - 分层：bg → surface → surface-2，边框极淡，阴影很短
   ============================================================ */

:root {
  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 16px;
  --r-lg: 22px;
  --r-pill: 999px;
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 28px; --s7: 40px;
  --dur: .18s;
  --ease: cubic-bezier(.2,.7,.3,1);

  --accent: #3b6ff5;
  --accent-2: #7a9dff;
  --accent-ink: #ffffff;
  --accent-soft: rgba(59,111,245,.12);

  --bg: #f4f6fa;
  --bg-grain: radial-gradient(1200px 620px at 50% -12%, #ffffff 0%, #f4f6fa 46%, #eef1f7 100%);
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --surface-3: #e8edf6;
  --line: rgba(16,26,48,.085);
  --line-strong: rgba(16,26,48,.14);
  --text: #141b2b;
  --muted: rgba(20,27,43,.56);
  --muted-2: rgba(20,27,43,.38);
  --bubble-me: linear-gradient(160deg, var(--accent) 0%, var(--accent-2) 120%);
  --bubble-me-text: #ffffff;
  --bubble-her: #ffffff;
  --shadow-1: 0 1px 2px rgba(16,26,48,.05);
  --shadow-2: 0 6px 20px rgba(16,26,48,.07);
  --shadow-3: 0 18px 48px rgba(16,26,48,.13);
  --scrim: rgba(12,18,32,.34);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0b0f16;
  --bg-grain: radial-gradient(1100px 600px at 50% -10%, #17202e 0%, #0d121b 48%, #080b11 100%);
  --surface: #121823;
  --surface-2: #18202d;
  --surface-3: #1f2836;
  --line: rgba(255,255,255,.075);
  --line-strong: rgba(255,255,255,.13);
  --text: #e9eef7;
  --muted: rgba(233,238,247,.56);
  --muted-2: rgba(233,238,247,.34);
  --bubble-her: #18202d;
  --shadow-1: 0 1px 2px rgba(0,0,0,.3);
  --shadow-2: 0 8px 24px rgba(0,0,0,.36);
  --shadow-3: 0 20px 56px rgba(0,0,0,.5);
  --scrim: rgba(0,0,0,.5);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0f16;
    --bg-grain: radial-gradient(1100px 600px at 50% -10%, #17202e 0%, #0d121b 48%, #080b11 100%);
    --surface: #121823;
    --surface-2: #18202d;
    --surface-3: #1f2836;
    --line: rgba(255,255,255,.075);
    --line-strong: rgba(255,255,255,.13);
    --text: #e9eef7;
    --muted: rgba(233,238,247,.56);
    --muted-2: rgba(233,238,247,.34);
    --bubble-her: #18202d;
    --shadow-1: 0 1px 2px rgba(0,0,0,.3);
    --shadow-2: 0 8px 24px rgba(0,0,0,.36);
    --shadow-3: 0 20px 56px rgba(0,0,0,.5);
    --scrim: rgba(0,0,0,.5);
    color-scheme: dark;
  }
}

[data-accent="sky"]  { --accent: #2b9cf0; --accent-2: #6fd0ff; --accent-soft: rgba(43,156,240,.13); }
[data-accent="slate"]{ --accent: #5b7aa8; --accent-2: #93aecd; --accent-soft: rgba(91,122,168,.14); }
[data-theme="dark"][data-accent="sky"]   { --accent: #37a9f5; --accent-2: #86d8ff; }
[data-theme="dark"][data-accent="slate"] { --accent: #6d8cb8; --accent-2: #a8c0dc; }

* { box-sizing: border-box; }
html, body { height: 100%; max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  background: var(--bg-grain);
  color: var(--text);
  font-family: "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
button, input, textarea { font: inherit; color: inherit; }
button { background: none; border: none; cursor: pointer; }
.hidden { display: none !important; }
::selection { background: var(--accent-soft); }

@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes dim  { from { opacity: 0; } to { opacity: 1; } }

/* ---------- 登录 ---------- */
#login {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: var(--s6); padding: var(--s6) var(--s4);
  animation: dim .35s var(--ease);
}
.logo { text-align: center; }
.logo h1 { margin: var(--s4) 0 var(--s1); font-size: 27px; font-weight: 650; letter-spacing: .14em; }
.logo .sub { margin: 0; font-size: 13px; color: var(--muted); letter-spacing: .08em; }
.blob {
  width: 76px; height: 62px; margin: 0 auto; position: relative;
  border-radius: 52% 52% 46% 46% / 60% 60% 42% 42%;
  background: linear-gradient(155deg, var(--accent-2), var(--accent) 62%);
  box-shadow: 0 14px 40px -12px var(--accent);
}
.blob::after {
  content: ""; position: absolute; right: -15px; top: 26px;
  width: 26px; height: 17px; border-radius: 60% 40% 50% 50%;
  background: linear-gradient(155deg, var(--accent-2), var(--accent));
  transform: rotate(-20deg);
}

.card {
  width: min(372px, 92vw);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: var(--s5);
  box-shadow: var(--shadow-2);
  animation: rise .3s var(--ease);
}
.tabs { display: flex; gap: var(--s1); padding: var(--s1); background: var(--surface-2); border-radius: var(--r-sm); margin-bottom: var(--s4); }
.tabs button { flex: 1; padding: 9px; border-radius: var(--r-xs); color: var(--muted); font-size: 14px; transition: all var(--dur) var(--ease); }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); font-weight: 600; }
.form { display: flex; flex-direction: column; gap: var(--s3); }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.form input {
  background: var(--surface-2); border: 1px solid transparent;
  border-radius: var(--r-sm); padding: 12px 13px; font-size: 15px; outline: none;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.form input:focus { border-color: var(--accent); background: var(--surface); }
.primary {
  background: linear-gradient(150deg, var(--accent), var(--accent-2));
  color: var(--accent-ink); font-weight: 650; letter-spacing: .06em;
  border-radius: var(--r-sm); padding: 12px; margin-top: var(--s1);
  box-shadow: 0 8px 20px -10px var(--accent);
  transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease);
}
.primary:hover { filter: brightness(1.04); }
.primary:active { transform: scale(.985); }
.err { min-height: 18px; margin-top: var(--s2); font-size: 12px; color: #e0596b; text-align: center; }

/* ---------- 主界面 ---------- */
#main { display: grid; grid-template-columns: 268px 1fr; height: 100vh; }
#side {
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.me { display: flex; align-items: center; gap: var(--s3); padding: var(--s4) var(--s4) var(--s3); }
.avatar {
  width: 38px; height: 38px; border-radius: 13px; flex: none;
  background: linear-gradient(140deg, var(--accent-2), var(--accent));
  box-shadow: var(--shadow-1);
}
.me-info { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.me-info b { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-info span { font-size: 11px; color: var(--muted-2); }
.me button { margin-left: auto; color: var(--muted-2); font-size: 15px; padding: 6px; border-radius: var(--r-xs); }
.me button:hover { color: var(--text); background: var(--surface-2); }

.search-row { padding: 0 var(--s3) var(--s2); }
.search-row input {
  width: 100%; background: var(--surface-2); border: 1px solid transparent;
  border-radius: var(--r-pill); padding: 9px 14px; font-size: 13px; outline: none;
  transition: border-color var(--dur) var(--ease);
}
.search-row input:focus { border-color: var(--accent); }

#convs { list-style: none; margin: 0; padding: 0 var(--s2); overflow: auto; flex: 1; min-height: 0; }
#convs li {
  display: flex; gap: var(--s3); align-items: center;
  padding: 11px var(--s3); border-radius: var(--r-sm); cursor: pointer;
  transition: background var(--dur) var(--ease);
}
#convs li:hover { background: var(--surface-2); }
#convs li.on { background: var(--accent-soft); }
#convs .c-av {
  width: 40px; height: 40px; border-radius: 14px; flex: none;
  display: grid; place-items: center;
  font-size: 15px; font-weight: 650; color: #fff;
  background: linear-gradient(140deg, hsl(var(--h, 220) 68% 62%), hsl(calc(var(--h, 220) + 34) 62% 48%));
  box-shadow: var(--shadow-1);
}
#convs .c-body { min-width: 0; flex: 1; }
#convs .c-top { display: flex; align-items: baseline; gap: var(--s2); }
#convs .c-name { font-size: 14.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#convs .c-time { margin-left: auto; font-size: 11px; color: var(--muted-2); flex: none; }
#convs .c-last { font-size: 12.5px; color: var(--muted); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#convs .badge {
  background: var(--accent); color: var(--accent-ink);
  font-size: 10px; font-weight: 600; line-height: 1;
  border-radius: var(--r-pill); padding: 3px 6px; flex: none;
}

.side-foot { padding: var(--s2) var(--s3) var(--s3); border-top: 1px solid var(--line); }
.ghost {
  width: 100%; border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 9px 12px; font-size: 12.5px; color: var(--muted);
  transition: all var(--dur) var(--ease); background: transparent;
}
.ghost:hover { color: var(--text); border-color: var(--line-strong); background: var(--surface-2); }

/* ---------- 聊天 ---------- */
#chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
#chat-head {
  display: flex; align-items: center; gap: var(--s2);
  padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line);
  background: var(--surface);
}
#chat-head .title { display: flex; flex-direction: column; line-height: 1.35; min-width: 0; }
#chat-head b { font-size: 15px; font-weight: 620; }
#chat-head span { font-size: 11px; color: var(--muted-2); }
#chat-head .ghost { width: auto; padding: 7px 12px; }
.head-actions { margin-left: auto; display: flex; gap: 6px; }
#back { display: none; width: 32px; padding: 0; border: none; font-size: 22px; line-height: 1; color: var(--muted); }

#stream {
  flex: 1; overflow: auto; padding: var(--s4) var(--s4) var(--s2);
  display: flex; flex-direction: column; gap: 7px; min-height: 0;
}
.bubble {
  max-width: min(540px, 76%);
  padding: 9px 13px;
  border-radius: var(--r-md);
  font-size: 14.5px; line-height: 1.62;
  white-space: pre-wrap; word-break: break-word;
  animation: rise .18s var(--ease);
}
.bubble.me {
  align-self: flex-end;
  background: var(--bubble-me); color: var(--bubble-me-text);
  border-bottom-right-radius: 6px;
  box-shadow: 0 6px 18px -12px var(--accent);
}
.bubble.her {
  align-self: flex-start;
  background: var(--bubble-her); color: var(--text);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
  box-shadow: var(--shadow-1);
}
.bubble .t { display: block; font-size: 10px; margin-top: 4px; opacity: .55; }
.bubble.me .t { color: var(--bubble-me-text); }
.bubble .recalled { font-size: 12.5px; font-style: italic; color: var(--muted); }
.bubble .img { display: block; max-width: min(280px, 60vw); max-height: 320px; border-radius: var(--r-sm); }
.bubble .sticker { display: block; width: 118px; height: 118px; object-fit: contain; }
.bubble .audio { width: 200px; height: 34px; }

.empty { align-self: center; margin: auto; text-align: center; color: var(--muted-2); font-size: 13px; line-height: 1.9; }
.empty .big { font-size: 30px; display: block; margin-bottom: var(--s2); opacity: .5; }

/* ---------- 输入 ---------- */
#composer {
  display: flex; gap: var(--s2); align-items: flex-end;
  padding: var(--s3) var(--s4) calc(var(--s3) + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--surface);
}
#input {
  flex: 1; min-width: 0; resize: none; max-height: 116px;
  background: var(--surface-2); border: 1px solid transparent;
  border-radius: var(--r-md); padding: 11px 14px; font-size: 15px; outline: none;
  line-height: 1.5; transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
#input:focus { border-color: var(--accent); background: var(--surface); }
#send {
  width: 62px; flex: none; padding: 11px 0;
  background: linear-gradient(150deg, var(--accent), var(--accent-2));
  color: var(--accent-ink); font-weight: 600; border-radius: var(--r-md);
  box-shadow: 0 8px 18px -12px var(--accent);
}
#send:active { transform: scale(.97); }
#composer .ghost { width: 42px; height: 40px; flex: none; padding: 0; display: grid; place-items: center; font-size: 13px; }

/* ---------- 右侧面板 ---------- */
#panel {
  width: 344px; position: relative; overflow: auto;
  padding: var(--s5) var(--s4);
  border-left: 1px solid var(--line);
  background: var(--surface);
  animation: dim .2s var(--ease);
}
#panel h3 { font-size: 11px; letter-spacing: .12em; color: var(--muted-2); margin: var(--s5) 0 var(--s2); font-weight: 600; }
#panel h3:first-of-type { margin-top: var(--s2); }
#close-panel { position: absolute; right: 10px; top: 10px; width: 30px; border: none; font-size: 16px; }
.state-box { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s3); }
.meter { display: flex; align-items: center; gap: var(--s2); font-size: 12px; color: var(--muted); }
.meter .bar { flex: 1; height: 6px; border-radius: var(--r-pill); background: var(--surface-3); overflow: hidden; }
.meter .bar i {
  display: block; height: 100%; width: 0; border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .45s var(--ease);
}
.meter b { color: var(--text); font-size: 12px; width: 36px; text-align: right; }
.kv { display: flex; justify-content: space-between; margin-top: var(--s3); font-size: 13px; color: var(--muted); }
.kv b { color: var(--text); font-weight: 600; }
#usage-chart { width: 100%; height: auto; border-radius: var(--r-sm); background: var(--surface-2); }
.usage-sum { font-size: 12px; color: var(--muted); margin-top: var(--s2); line-height: 1.8; }
.usage-sum b { color: var(--text); }
#events { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
#events li { padding: 7px 0 7px 10px; border-left: 2px solid var(--line-strong); line-height: 1.5; }
#events li b { color: var(--text); font-weight: 500; }

/* ---------- 表情面板 ---------- */
#picker {
  position: fixed; left: 0; right: 0; bottom: 0; max-height: 54vh; z-index: 20;
  display: flex; flex-direction: column;
  background: var(--surface); border-top: 1px solid var(--line);
  box-shadow: var(--shadow-3); border-radius: var(--r-lg) var(--r-lg) 0 0;
  animation: rise .2s var(--ease);
}
#picker.hidden { display: none; }
.picker-head { display: flex; gap: var(--s2); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.picker-head input { flex: 1; background: var(--surface-2); border: 1px solid transparent; border-radius: var(--r-pill); padding: 8px 14px; outline: none; font-size: 13px; }
.picker-head input:focus { border-color: var(--accent); }
.picker-head .ghost { width: 34px; border: none; }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(82px, 1fr)); gap: 6px; padding: var(--s3); overflow: auto; }
.picker-grid img {
  width: 100%; aspect-ratio: 1; object-fit: contain; cursor: pointer;
  border-radius: var(--r-sm); background: var(--surface-2);
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.picker-grid img:hover { background: var(--accent-soft); transform: translateY(-1px); }
.picker-tip { grid-column: 1/-1; text-align: center; color: var(--muted-2); font-size: 12px; padding: var(--s5); }

/* ---------- 设置面板 ---------- */
#settings {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  background: var(--scrim); animation: dim .16s var(--ease);
}
#settings.hidden { display: none; }
.sheet {
  width: min(360px, 90vw); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s5); box-shadow: var(--shadow-3); animation: rise .2s var(--ease);
}
.sheet h3 { margin: 0 0 var(--s4); font-size: 15px; font-weight: 620; }
.sheet .row { margin-bottom: var(--s4); }
.sheet .row > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: var(--s2); }
.seg { display: flex; gap: var(--s1); padding: var(--s1); background: var(--surface-2); border-radius: var(--r-sm); }
.seg button { flex: 1; padding: 8px; border-radius: var(--r-xs); font-size: 13px; color: var(--muted); transition: all var(--dur) var(--ease); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-1); font-weight: 600; }
.swatches { display: flex; gap: var(--s3); }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; transition: all var(--dur) var(--ease); }
.swatch.on { border-color: var(--text); transform: scale(1.06); }
.sheet .close { width: 100%; margin-top: var(--s2); }

/* ---------- 手机 ---------- */
@media (max-width: 820px) {
  #main { grid-template-columns: 1fr; }
  #side { display: flex; }
  #chat { display: none; }
  #main.show-chat #side { display: none; }
  #main.show-chat #chat { display: flex; }
  #back { display: inline-flex; align-items: center; justify-content: center; }
  #chat-head { padding: var(--s2) var(--s3); padding-right: 46px; }
  #side .me { padding-right: 46px; }
  #stream { padding: var(--s3) var(--s3) var(--s2); gap: 6px; }
  .bubble { max-width: 84%; }
  #composer { padding: var(--s2) var(--s3) calc(var(--s2) + env(safe-area-inset-bottom)); gap: 6px; }
  #composer .ghost { width: 40px; height: 38px; font-size: 11px; }
  #input { font-size: 16px; padding: 10px 12px; }
  #send { width: 54px; padding: 10px 0; }
  #panel { position: fixed; right: 0; top: 0; bottom: 0; width: min(92vw, 360px); z-index: 30; }
  .picker-grid { grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
