/* 云聊 CloudChat —— 界面样式（移动优先） */

:root {
  --brand: #5b5bd6;
  --brand-strong: #4a44c6;
  --brand-soft: #ecebff;
  --bg: #f5f6fb;
  --panel: #ffffff;
  --line: #e4e6f0;
  --text: #1c1d2b;
  --muted: #6b6f85;
  --danger: #c0392b;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 28px rgba(28, 29, 43, .10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "PingFang SC", "Noto Sans SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100dvh;
  max-width: 100%;
}

/* ---------- 顶栏 ---------- */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 20;
}

.icon-btn {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 12px;
  color: var(--muted);
  transition: background .18s ease, color .18s ease, transform .12s ease;
}
.icon-btn:hover { background: var(--brand-soft); color: var(--brand); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.small { width: 32px; height: 32px; }
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn.small svg { width: 18px; height: 18px; }

.topbar-title { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.app-name { font-size: 12px; color: var(--muted); letter-spacing: .06em; }
.channel-name {
  font-size: 16px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.topbar-actions { display: flex; align-items: center; gap: 2px; }

.online-chip {
  font-size: 12px; color: var(--brand);
  background: var(--brand-soft);
  padding: 5px 10px; border-radius: 999px;
  white-space: nowrap;
}

/* ---------- 侧栏 ---------- */
.sidebar {
  display: flex; flex-direction: column;
  gap: 4px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 10px 10px 20px;
  overflow-y: auto;
}

.side-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 6px 2px;
}
.side-title { font-size: 12px; color: var(--muted); letter-spacing: .08em; }

.channel-list { display: flex; flex-direction: column; gap: 2px; }

.channel-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--muted);
  text-align: left;
  width: 100%;
  transition: background .18s ease, color .18s ease;
}
.channel-item:hover { background: #f2f3fa; }
.channel-item.active { background: var(--brand-soft); color: var(--brand-strong); font-weight: 600; }
.channel-item svg { width: 18px; height: 18px; flex: none; }
.channel-item .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.member-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 6px; }
.member-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f4f5fb; border-radius: 999px;
  padding: 5px 10px 5px 5px; font-size: 13px; color: var(--muted);
  transition: background .18s ease;
}
.member-chip:hover { background: var(--brand-soft); color: var(--brand-strong); }
.member-chip img, .member-chip .avatar { width: 22px; height: 22px; border-radius: 50%; object-fit: cover; }

.drawer-mask {
  position: fixed; inset: 0; background: rgba(20, 21, 33, .38);
  opacity: 0; pointer-events: none; transition: opacity .22s ease;
  z-index: 30;
}

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

.messages {
  flex: 1; overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}

.empty {
  margin: auto; text-align: center; color: var(--muted);
  display: flex; flex-direction: column; gap: 8px; align-items: center; padding: 40px 20px;
}
.empty svg { width: 54px; height: 54px; opacity: .35; }
.empty h3 { margin: 0; font-size: 16px; color: var(--text); font-weight: 600; }
.empty p { margin: 0; font-size: 13px; max-width: 260px; line-height: 1.6; }

.msg-row { display: flex; gap: 8px; align-items: flex-end; animation: pop .22s ease both; }
.msg-row.mine { flex-direction: row-reverse; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  flex: none; object-fit: cover;
  display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, #7b7bf0, #4a44c6);
  overflow: hidden;
  user-select: none;
}
.avatar.lg { width: 56px; height: 56px; font-size: 20px; }

.bubble-wrap { max-width: 76%; display: flex; flex-direction: column; gap: 4px; }
.msg-row.mine .bubble-wrap { align-items: flex-end; }
.meta { font-size: 11px; color: var(--muted); padding: 0 4px; }
.meta .who { color: var(--brand); font-weight: 600; margin-right: 6px; }

.bubble {
  padding: 10px 14px;
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 2px 8px rgba(28, 29, 43, .06);
  font-size: 15px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.msg-row.mine .bubble {
  background: linear-gradient(135deg, #6b66e0, var(--brand-strong));
  color: #fff;
}

/* ---------- 输入栏 ---------- */
.composer {
  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 textarea {
  flex: 1; resize: none;
  max-height: 120px;
  padding: 12px 14px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: #f7f8fc;
  color: var(--text);
  font: inherit; font-size: 15px; line-height: 1.4;
  outline: none;
  transition: border-color .18s ease, background .18s ease;
}
.composer textarea:focus { border-color: var(--brand); background: #fff; }

.send-btn {
  width: 46px; height: 46px; flex: none;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff;
  background: linear-gradient(135deg, #6b66e0, var(--brand-strong));
  box-shadow: 0 6px 16px rgba(74, 68, 198, .32);
  transition: transform .12s ease, box-shadow .18s ease, opacity .18s ease;
}
.send-btn:active { transform: scale(.92); }
.send-btn svg { width: 22px; height: 22px; }
.send-btn:disabled { opacity: .5; box-shadow: none; }

/* ---------- 弹层 ---------- */
.modal-mask {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(20, 21, 33, .45);
  display: grid; place-items: center;
  padding: 20px;
  animation: fade .2s ease both;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }
.modal-mask.hidden { display: none; }

.modal {
  width: min(420px, 100%);
  max-height: 88dvh; overflow-y: auto;
  background: var(--panel);
  border-radius: var(--radius-lg);
  padding: 22px 20px 18px;
  box-shadow: var(--shadow);
  animation: rise .26s cubic-bezier(.2, .8, .2, 1) both;
  display: flex; flex-direction: column; gap: 12px;
}
@keyframes rise { from { opacity: 0; transform: translateY(14px) } to { opacity: 1; transform: none } }

.modal h2 { margin: 0; font-size: 20px; font-weight: 700; }
.modal-sub { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.5; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: 13px; color: var(--muted); }
.field input, .field textarea {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: #f7f8fc;
  color: var(--text);
  font: inherit; font-size: 15px;
  outline: none;
  transition: border-color .18s ease, background .18s ease;
}
.field input:focus { border-color: var(--brand); background: #fff; }

.avatar-preview { display: flex; align-items: center; gap: 12px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.5; }

.field-error { color: var(--danger); font-size: 13px; min-height: 18px; }

.primary-btn {
  padding: 14px 18px;
  border-radius: 999px;
  background: linear-gradient(135deg, #6b66e0, var(--brand-strong));
  color: #fff; font-weight: 600; font-size: 15px;
  box-shadow: 0 8px 20px rgba(74, 68, 198, .28);
  transition: transform .12s ease, box-shadow .18s ease;
}
.primary-btn:active { transform: scale(.98); }

.ghost-btn {
  padding: 14px 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 15px;
  transition: background .18s ease;
}
.ghost-btn:hover { background: #f2f3fa; }

.text-btn { padding: 10px; font-size: 13px; color: var(--muted); border-radius: var(--radius-sm); }
.text-btn.danger { color: var(--danger); }

.modal-actions { display: flex; gap: 10px; }
.modal-actions > * { flex: 1; }

.member-picker { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.member-option {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-md);
  text-align: left; width: 100%;
  transition: background .18s ease;
}
.member-option:hover { background: #f2f3fa; }
.member-option.selected { background: var(--brand-soft); color: var(--brand-strong); }

.toast {
  position: fixed; left: 50%; bottom: 92px;
  transform: translate(-50%, 16px);
  background: rgba(28, 29, 43, .92);
  color: #fff; font-size: 13px;
  padding: 10px 16px; border-radius: 999px;
  opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 60; max-width: 84vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 响应式 ---------- */
@media (min-width: 760px) {
  .app { grid-template-columns: 268px 1fr; grid-template-rows: auto 1fr; }
  .sidebar { grid-row: 2; grid-column: 1; }
  .chat { grid-row: 2; grid-column: 2; }
  #btnMenu { display: none; }
  .drawer-mask { display: none !important; }
}

@media (max-width: 759px) {
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: min(300px, 82vw);
    transform: translateX(-104%);
    transition: transform .26s cubic-bezier(.2, .8, .2, 1);
    z-index: 35;
    padding-top: calc(14px + env(safe-area-inset-top));
  }
  .sidebar.open { transform: none; }
  .bubble-wrap { max-width: 82%; }
}
