/* ===================== 基础 ===================== */
:root {
  --brand: #12b7f5;
  --brand-dark: #0a9fd8;
  --bg: #f2f4f7;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --line: #e3e6eb;
  --text: #1f2329;
  --text-dim: #8a919c;
  --bubble-me: linear-gradient(135deg, #12b7f5, #0a9fd8);
  --bubble-other: #ffffff;
  --danger: #f5483b;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(17, 30, 60, .08);
}

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

html, body {
  height: 100%;
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior: none;
  overflow-x: hidden;
  max-width: 100vw;
}

button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ===================== 登录页 ===================== */
.auth-wrap {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(1000px 500px at 10% 0%, #d9f1ff 0%, transparent 60%),
    radial-gradient(800px 400px at 100% 100%, #e6e9ff 0%, transparent 55%),
    #f4f7fb;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border-radius: 18px;
  padding: 28px 26px 22px;
  box-shadow: 0 18px 50px rgba(20, 40, 80, .12);
}

.auth-logo { text-align: center; margin-bottom: 18px; }

.auth-back {
  display: inline-block;
  margin-bottom: 8px;
  padding: 4px 6px;
  font-size: 12px;
  color: var(--text-dim);
  border-radius: 6px;
}
.auth-back:hover { color: var(--brand); background: var(--panel-2); }
.auth-logo h1 { margin: 8px 0 2px; font-size: 22px; letter-spacing: 2px; }
.auth-logo p { margin: 0; color: var(--text-dim); font-size: 12px; }

.auth-tabs {
  display: flex;
  gap: 6px;
  background: var(--panel-2);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 18px;
}
.auth-tabs button {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  color: var(--text-dim);
  font-weight: 500;
}
.auth-tabs button.active {
  background: #fff;
  color: var(--brand);
  box-shadow: var(--shadow);
}

.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
}
.auth-form input {
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
  outline: none;
  transition: .15s;
  font-size: 15px;
}
.auth-form input:focus { border-color: var(--brand); background: #fff; }

button.primary {
  padding: 11px 16px;
  border-radius: 10px;
  background: var(--brand);
  color: #fff;
  font-weight: 600;
  transition: .15s;
}
button.primary:hover { background: var(--brand-dark); }
button.primary:disabled { opacity: .55; cursor: not-allowed; }

.auth-msg { min-height: 18px; margin: 2px 0 0; font-size: 12px; color: var(--danger); text-align: center; }

/* ===================== 主框架 ===================== */
.app {
  height: 100%;
  width: 100%;
  max-width: 100vw;
  display: flex;
  overflow: hidden;
}

#sidebar {
  width: 300px;
  min-width: 0;
  max-width: 100%;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.side-top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 10px;
}
.me { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.me-info { min-width: 0; }
.me-name {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.me-status { font-size: 11px; color: var(--text-dim); }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 15px;
  flex: none;
  background: linear-gradient(135deg, #12b7f5, #6a8dff);
  overflow: hidden;
  user-select: none;
}
.avatar.small { width: 34px; height: 34px; border-radius: 10px; font-size: 13px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  font-size: 16px;
  transition: .15s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--brand); }

.search-box { display: flex; gap: 8px; padding: 0 14px 10px; }
.search-box input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  outline: none;
  font-size: 13px;
}
.search-box input:focus { border-color: var(--brand); background: #fff; }
.mini-btn {
  padding: 0 12px;
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 13px;
}
.mini-btn:hover { color: var(--brand); }

.tabs { display: flex; padding: 0 10px; border-bottom: 1px solid var(--line); }
.tabs button {
  position: relative;
  flex: 1;
  padding: 9px 4px;
  font-size: 13px;
  color: var(--text-dim);
  border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

.dot-badge {
  display: inline-grid;
  place-items: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin-left: 4px;
  border-radius: 8px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  vertical-align: 1px;
}

.list { flex: 1; overflow-y: auto; padding: 6px; }

.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s;
}
.list-item:hover { background: var(--panel-2); }
.list-item.active { background: #e8f6fe; }

.list-item .body { flex: 1; min-width: 0; }
.list-item .top { display: flex; align-items: baseline; gap: 6px; }
.list-item .name {
  font-weight: 500;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.list-item .time { font-size: 11px; color: var(--text-dim); flex: none; }
.list-item .preview {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.list-item .badge {
  flex: none;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  display: grid;
  place-items: center;
}

.side-actions { padding: 10px 14px 14px; border-top: 1px solid var(--line); }
.ghost-btn {
  width: 100%;
  padding: 9px;
  border-radius: 9px;
  background: var(--panel-2);
  color: var(--text-dim);
  font-size: 13px;
  transition: .15s;
}
.ghost-btn:hover { color: var(--brand); background: #e8f6fe; }
.ghost-btn.small { width: auto; padding: 5px 12px; font-size: 12px; }

.list-empty {
  padding: 30px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.8;
}

/* ===================== 聊天区 ===================== */
#chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.chat-empty {
  flex: 1;
  display: grid;
  place-content: center;
  text-align: center;
  color: var(--text-dim);
  gap: 4px;
}
.empty-art { font-size: 44px; opacity: .5; }
.chat-empty p { margin: 0; }
.chat-empty .hint { font-size: 12px; opacity: .75; }

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

.chat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.chat-title-wrap { flex: 1; min-width: 0; }
.chat-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { font-size: 11px; color: var(--text-dim); }
.back-btn { display: none; font-size: 24px; line-height: 1; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
}
.load-more-wrap { text-align: center; padding: 4px 0 12px; }

.msg-row { display: flex; gap: 8px; margin: 8px 0; align-items: flex-start; }
.msg-row.mine { flex-direction: row-reverse; }

.msg-col { max-width: min(76%, 560px); display: flex; flex-direction: column; }
.msg-row.mine .msg-col { align-items: flex-end; }

.msg-sender { font-size: 11px; color: var(--text-dim); margin: 0 4px 3px; }
.msg-sender.mine { text-align: right; }
.msg-row.mine .msg-sender { text-align: right; }

.bot-form .avatar-edit { margin-bottom: 14px; }
.bot-form details {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 8px 10px;
  background: var(--panel-2);
}
.bot-form details summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--text-dim);
  outline: none;
}
.bot-form details textarea {
  width: 100%;
  margin-top: 8px;
  min-height: 120px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
  font-size: 13px;
  line-height: 1.6;
  resize: vertical;
  outline: none;
}

.bubble {
  padding: 9px 13px;
  border-radius: 12px;
  background: var(--bubble-other);
  box-shadow: var(--shadow);
  word-break: break-word;
  white-space: pre-wrap;
  font-size: 14.5px;
  line-height: 1.55;
  position: relative;
}
.msg-row.mine .bubble {
  background: var(--bubble-me);
  color: #fff;
  box-shadow: 0 2px 10px rgba(18, 183, 245, .3);
}
/* 乐观更新中的气泡（还没被服务器确认） */
.msg-row.pending .bubble { opacity: .7; }
.msg-row.pending .msg-sender::after { content: ' · 发送中'; opacity: .7; }
.bubble.recalled {
  background: transparent !important;
  box-shadow: none;
  color: var(--text-dim);
  font-size: 12px;
  font-style: italic;
}
.bubble.image { padding: 4px; background: #fff; }
.bubble.image img {
  display: block;
  max-width: 240px;
  max-height: 240px;
  border-radius: 9px;
  cursor: zoom-in;
}
.msg-row.mine .bubble.image { background: #fff; }

.time-divider {
  text-align: center;
  font-size: 11px;
  color: var(--text-dim);
  margin: 14px 0 6px;
}

.msg-tools {
  opacity: 0;
  transition: opacity .12s;
  font-size: 11px;
  color: var(--text-dim);
  padding: 2px 4px;
  cursor: pointer;
}
.msg-row:hover .msg-tools { opacity: 1; }
.msg-tools:hover { color: var(--danger); }

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

.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
}
.composer .img-pick {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: var(--text-dim);
  cursor: pointer;
  flex: none;
  -webkit-tap-highlight-color: transparent;
}
.composer .img-pick:hover { background: var(--panel-2); color: var(--brand); }
.composer .img-pick:active { background: #e8f6fe; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.composer textarea {
  flex: 1;
  min-height: 38px;
  max-height: 140px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  outline: none;
  resize: none;
  line-height: 1.45;
}
.composer textarea:focus { border-color: var(--brand); background: #fff; }
.send-btn { padding: 9px 18px; flex: none; }

/* ===================== 弹窗 / 提示 ===================== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 25, 45, .45);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}
.modal-card {
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(10, 20, 40, .3);
}
.modal-card header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}
.modal-card header h3 { margin: 0; font-size: 15px; flex: 1; }
.modal-body { padding: 14px; overflow-y: auto; }
.modal-card footer {
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--panel-2);
  outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--brand); background: #fff; }

.check-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: 9px; }
.check-list label {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 11px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  font-size: 13px;
}
.check-list label:last-child { border-bottom: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 40px;
  transform: translateX(-50%);
  background: rgba(30, 40, 60, .92);
  color: #fff;
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 90;
  pointer-events: none;
}

.img-preview {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .85);
  display: grid;
  place-items: center;
  z-index: 80;
  cursor: zoom-out;
}
.img-preview img { max-width: 94vw; max-height: 92vh; border-radius: 8px; }

/* ===================== 账号菜单 / 头像编辑 ===================== */
.side-top { position: relative; }

.user-menu {
  position: absolute;
  top: 58px;
  left: 14px;
  width: 190px;
  padding: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 12px 34px rgba(20, 40, 80, .16);
  z-index: 30;
}
.user-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 10px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--text);
}
.user-menu button:hover { background: var(--panel-2); }
.user-menu button.danger { color: var(--danger); }

.chat-actions { display: flex; align-items: center; gap: 6px; }

.avatar-edit {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}
.avatar-edit .avatar {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  font-size: 22px;
  cursor: pointer;
}
.avatar-edit .hint { font-size: 12px; color: var(--text-dim); line-height: 1.6; }

/* ===================== 安装横幅 ===================== */
.install-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 12px 10px;
  padding: 9px 10px;
  border-radius: 10px;
  background: linear-gradient(135deg, #e8f6fe, #eef4ff);
  border: 1px solid #cfe9fb;
  font-size: 12px;
  color: #1b6f9c;
}
.install-banner .ib-ico { font-size: 15px; }
.install-banner .ib-text { flex: 1; min-width: 0; }
.install-banner .ib-btn {
  padding: 4px 12px;
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}
.install-banner .ib-btn:hover { background: var(--brand-dark); }
.install-banner .ib-close {
  color: #7aa8bf;
  font-size: 12px;
  padding: 2px 4px;
}
.install-banner .ib-close:hover { color: var(--danger); }

.dl-box {
  margin-top: 14px;
  padding: 12px;
  border-radius: 10px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}
.dl-box .dl-title { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.dl-link {
  display: inline-block;
  margin-top: 8px;
  padding: 8px 14px;
  border-radius: 9px;
  background: var(--brand);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
}
.dl-link:hover { background: var(--brand-dark); }
.dl-note { font-size: 11px; color: var(--text-dim); margin-top: 8px; line-height: 1.7; }

/* ===================== 设置面板 ===================== */
.set-group {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 12px;
  background: var(--panel-2);
}
.set-group > h4 {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.set-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
}
.set-row .set-label {
  flex: 1;
  font-size: 13px;
  color: var(--text);
}
.set-row .set-hint {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 1px;
}
.set-row input[type="number"],
.set-row input[type="text"] {
  width: 92px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  text-align: right;
  outline: none;
}
.set-row input[type="text"] { width: 160px; text-align: left; }
.set-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--brand);
  flex: none;
}
.set-row .unit { font-size: 12px; color: var(--text-dim); }
.set-row.disabled { opacity: .45; }

/* ===================== 手机端 ===================== */
@media (max-width: 820px) {
  #sidebar { width: 100%; max-width: 100vw; border-right: none; }
  #chat { display: none; }
  .app.chat-open #sidebar { display: none; }
  .app.chat-open #chat { display: flex; }
  .back-btn { display: grid; }
  .msg-col { max-width: 82%; }
  .bubble.image img { max-width: 200px; max-height: 200px; }
  .search-box { padding: 0 12px 10px; }
  .tabs button { font-size: 12.5px; padding: 9px 2px; }
  .list-item { padding: 9px 8px; }
}
