* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, sans-serif;
  background: #0d141d;
  color: #e8eef6;
  overflow: hidden;
}
#app { display: flex; height: 100dvh; }

/* ---------- 侧栏 ---------- */
#sidebar {
  width: 280px; flex: none; display: flex; flex-direction: column;
  background: #101a26; border-right: 1px solid #1c2b3d;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 14px 10px; }
.side-title { font-weight: 700; font-size: 16px; letter-spacing: .5px; }
.session-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.session-item {
  padding: 11px 12px; border-radius: 12px; cursor: pointer; margin-bottom: 4px;
  display: flex; align-items: center; gap: 8px; color: #b9c8d9; font-size: 14px;
}
.session-item:hover { background: #17263a; }
.session-item.active { background: #1d3a55; color: #fff; }
.session-item .avatars { font-size: 16px; letter-spacing: -2px; }
.session-item .sname { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot { padding: 10px; border-top: 1px solid #1c2b3d; }

/* ---------- 聊天区 ---------- */
#chat { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-head {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid #1c2b3d; background: #101a26;
}
.chat-title { flex: 1; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 16px 14px 8px; scroll-behavior: smooth; }
.empty-hint { color: #5d7288; text-align: center; margin-top: 30%; font-size: 14px; line-height: 1.8; padding: 0 30px; }

.msg { display: flex; gap: 9px; margin-bottom: 16px; align-items: flex-start; }
.msg.user { flex-direction: row-reverse; }
.avatar {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-size: 19px;
  background: #1b2c40; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.bubble-wrap { max-width: 78%; min-width: 0; display: flex; flex-direction: column; }
.msg.user .bubble-wrap { align-items: flex-end; }
.bubble-name { font-size: 11.5px; color: #7f93a8; margin: 0 4px 4px; }
.bubble {
  padding: 10px 13px; border-radius: 14px; font-size: 15px; line-height: 1.6;
  background: #17263a; white-space: pre-wrap; word-break: break-word;
  border-top-left-radius: 4px;
}
.msg.user .bubble { background: #24506e; border-top-left-radius: 14px; border-top-right-radius: 4px; }
.bubble.typing::after { content: "…"; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.msg .err { font-size: 12px; color: #e2795f; margin: 4px; }

/* ---------- 输入框 ---------- */
.composer {
  display: flex; gap: 10px; padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid #1c2b3d; background: #101a26;
}
.composer textarea {
  flex: 1; resize: none; max-height: 120px; padding: 10px 13px;
  background: #17263a; color: #e8eef6; border: 1px solid #24384f;
  border-radius: 12px; font: inherit; font-size: 15px; line-height: 1.4; outline: none;
}
.composer textarea:focus { border-color: #35719c; }
.composer button {
  border: 0; border-radius: 12px; padding: 0 18px; font-size: 15px; font-weight: 600;
  background: #2f7ab0; color: #fff; cursor: pointer;
}
.composer button:disabled { opacity: .45; }

/* ---------- 按钮 ---------- */
.icon-btn { background: transparent; border: 0; color: #9fb3c7; font-size: 20px; width: 36px; height: 36px; border-radius: 10px; cursor: pointer; }
.icon-btn:hover { background: #17263a; }
.ghost-btn, .primary-btn {
  border-radius: 10px; padding: 9px 14px; font-size: 14px; cursor: pointer; border: 1px solid #2a4159;
  background: transparent; color: #c8d6e5;
}
.primary-btn { background: #2f7ab0; border-color: #2f7ab0; color: #fff; font-weight: 600; }
.ghost-btn.danger { color: #e2795f; border-color: #62372c; }
.hidden { display: none !important; }

/* ---------- 弹窗 ---------- */
.modal { position: fixed; inset: 0; background: rgba(4, 8, 13, .7); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal-card {
  width: 100%; max-width: 420px; max-height: 88dvh; overflow-y: auto;
  background: #101a26; border: 1px solid #22354a; border-radius: 18px; padding: 20px;
}
.modal-card.wide { max-width: 560px; }
.modal-card h3 { margin: 0 0 6px; font-size: 17px; }
.muted { color: #7f93a8; font-size: 13px; margin: 0 0 14px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.text-input, .text-area {
  width: 100%; margin-top: 10px; padding: 10px 12px; border-radius: 10px;
  background: #17263a; color: #e8eef6; border: 1px solid #24384f; font: inherit; font-size: 14px; outline: none;
}
.text-input:focus, .text-area:focus { border-color: #35719c; }
.text-area { resize: vertical; line-height: 1.5; }
.text-input.short { width: 120px; }
.temp-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 13px; color: #9fb3c7; }
.temp-row input { flex: 1; }

.char-picker { display: flex; flex-direction: column; gap: 8px; max-height: 40dvh; overflow-y: auto; }
.pick-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border: 1px solid #24384f; border-radius: 12px; cursor: pointer; font-size: 14px;
}
.pick-item.sel { border-color: #2f7ab0; background: #16283a; }
.pick-item .avatar { width: 30px; height: 30px; font-size: 16px; }
.pick-item .pname { flex: 1; }

.char-list { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.char-chip {
  display: flex; align-items: center; gap: 6px; padding: 7px 11px; border-radius: 20px;
  background: #17263a; border: 1px solid #24384f; cursor: pointer; font-size: 13px;
}
.char-chip.sel { border-color: #2f7ab0; }
.chip-del { color: #7f93a8; margin-left: 2px; }
.chip-del:hover { color: #e2795f; }

/* ---------- 手机 ---------- */
@media (max-width: 720px) {
  #sidebar { position: fixed; inset: 0; width: 100%; z-index: 10; }
  #app.chat-open #sidebar { display: none; }
  #app:not(.chat-open) #chat { display: none; }
  .back { display: block; }
  .bubble-wrap { max-width: 84%; }
}
@media (min-width: 721px) { #btnBack { display: none; } }
