:root {
  --bg: #101114;
  --bg-soft: #17191d;
  --line: rgba(255, 255, 255, 0.09);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #e8eaee;
  --text-dim: rgba(232, 234, 238, 0.56);
  --accent: #4d8dff;
  --bubble: rgba(255, 255, 255, 0.06);
  --bubble-me: rgba(77, 141, 255, 0.20);
  --danger: #ff6b61;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
}

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

#app { height: 100%; display: flex; min-height: 0; }

/* ---------------- 布局：手机单列 */

.shell { flex: 1; display: flex; min-height: 0; min-width: 0; }

.side { display: none; }
.side.is-open { display: flex; }

.main { flex: 1; display: flex; flex-direction: column; min-height: 0; min-width: 0; }

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

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-top)) 12px 10px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; z-index: 5;
}
.title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.badge { font-size: 11px; color: var(--text-dim); border: 1px solid var(--line-strong); padding: 1px 7px; border-radius: 999px; white-space: nowrap; }
.iconbtn {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  color: var(--text-dim); font-size: 17px; flex: 0 0 auto;
}
.iconbtn:active { background: var(--bubble); }
.chip {
  border: 1px solid var(--line-strong); border-radius: 999px; padding: 5px 11px;
  font-size: 12px; color: var(--text-dim); white-space: nowrap;
}
.chip.is-on { background: var(--bubble); color: var(--text); border-color: transparent; }

/* ---------------- 消息 */

.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 14px 12px 8px; display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; }
.row.me { justify-content: flex-end; }
.bubble {
  max-width: 84%; padding: 9px 13px; border-radius: 16px; white-space: pre-wrap; word-break: break-word;
  background: var(--bubble);
}
.row.me .bubble { background: var(--bubble-me); border-bottom-right-radius: 6px; }
.row.bot .bubble { border-bottom-left-radius: 6px; }
.bubble.streaming::after { content: "▍"; opacity: .5; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0 } }

.welcome { margin: auto; text-align: center; color: var(--text-dim); padding: 20px; }
.welcome h2 { font-size: 15px; margin: 0 0 6px; color: var(--text); font-weight: 600; }
.welcome p { margin: 0; font-size: 13px; }

.notice { margin: 0 12px 6px; font-size: 12px; color: var(--danger); }

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

.composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 8px 12px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
}
.input {
  flex: 1; resize: none; max-height: 132px; min-height: 40px;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 14px;
  padding: 10px 12px; font-size: 15px; line-height: 1.4; outline: none;
}
.input:focus { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.send {
  flex: 0 0 auto; width: 56px; height: 40px; border-radius: 14px;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;
}
.send:disabled { opacity: .35; }

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

.drawer {
  position: fixed; inset: 0; z-index: 20;
  background: var(--bg); display: flex; flex-direction: column;
  padding-top: var(--safe-top);
}
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.drawer-title { flex: 1; font-weight: 600; font-size: 15px; }
.drawer-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.group-title { font-size: 11px; letter-spacing: .06em; color: var(--text-dim); margin: 6px 0 2px; }

.memrow { display: flex; gap: 8px; align-items: flex-start; padding: 9px 10px; background: var(--bg-soft); border-radius: 12px; }
.memtext { flex: 1; font-size: 14px; }
.memdel { color: var(--text-dim); font-size: 16px; padding: 0 2px; }

.addrow { display: flex; gap: 8px; }
.addrow .input { min-height: 38px; }

.recall { background: color-mix(in srgb, var(--accent) 12%, var(--bg-soft)); border-radius: 12px; padding: 10px 12px; font-size: 12px; color: var(--text-dim); }
.recall b { color: var(--text); display: block; margin-bottom: 4px; font-weight: 500; }
.recall p { margin: 0; }

.persona-text { flex: 1; min-height: 40vh; background: var(--bg-soft); border: 1px solid var(--line); border-radius: 12px; padding: 12px; resize: none; outline: none; }
.persona-files { display: flex; flex-wrap: wrap; gap: 8px; }

.empty { color: var(--text-dim); font-size: 13px; padding: 6px 2px; }

.login { margin: auto; max-width: 340px; padding: 24px; text-align: center; }
.login h2 { font-size: 16px; margin: 0 0 8px; }
.login p { color: var(--text-dim); font-size: 13px; margin: 0 0 16px; }
.login .input { width: 100%; margin-bottom: 10px; }
.login .send { width: 100%; }

/* 列表（手机抽屉内复用） */
.chatlist { display: flex; flex-direction: column; gap: 2px; }
.chatitem { display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 12px; }
.chatitem.is-active { background: var(--bg-soft); }
.chatitem span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- 桌面：三栏 */

@media (min-width: 900px) {
  .side {
    display: flex; flex-direction: column; width: 240px; flex: 0 0 240px;
    border-right: 1px solid var(--line); min-height: 0;
    padding-top: var(--safe-top);
  }
  .side-head { display: flex; align-items: center; gap: 8px; padding: 12px 12px 8px; }
  .side-head .title { font-size: 13px; color: var(--text-dim); }
  .chatlist { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
  .drawer { position: static; inset: auto; width: 340px; flex: 0 0 340px; border-left: 1px solid var(--line); background: var(--bg); }
  .drawer.panel { display: flex; }
  .bubble { max-width: 76%; }
  .mobileonly { display: none; }
}
