* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", "Microsoft YaHei", "PingFang SC", sans-serif;
  font-size: 16px;
  color: #0d0d0d;
  background: #fff;
  overflow: hidden;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, textarea { font: inherit; color: inherit; }

/* ---------- auth ---------- */
.auth-view {
  position: fixed; inset: 0; z-index: 10;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1100px 600px at 50% -10%, #2a2a35 0%, #0d0d0d 60%);
}
.auth-card {
  width: 380px; max-width: calc(100vw - 32px);
  background: #fff; border-radius: 18px; padding: 34px 30px 30px;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.auth-logo { font-size: 26px; font-weight: 700; text-align: center; letter-spacing: -.5px; }
.auth-sub { font-size: 13px; color: #8e8e8e; text-align: center; margin: 6px 0 22px; }
.auth-tabs { display: flex; background: #f0f0f0; border-radius: 10px; padding: 4px; margin-bottom: 18px; }
.auth-tabs button { flex: 1; padding: 8px 0; border-radius: 8px; font-size: 14px; color: #555; }
.auth-tabs button.active { background: #fff; color: #0d0d0d; font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.auth-card input {
  width: 100%; border: 1px solid #d9d9d9; border-radius: 10px;
  padding: 11px 13px; outline: none; margin-bottom: 12px; font-size: 14px;
}
.auth-card input:focus { border-color: #0d0d0d; }
.form-error { color: #d93025; font-size: 13px; min-height: 18px; margin: -4px 0 8px; }
.btn-primary { width: 100%; background: #0d0d0d; color: #fff; border-radius: 10px; padding: 12px 0; font-weight: 600; }
.btn-primary:hover { background: #2a2a2a; }

/* ---------- layout ---------- */
.app { display: flex; height: 100vh; height: 100dvh; }

/* sidebar */
#sidebar {
  width: 260px; flex: none;
  background: #171717; color: #e3e3e3;
  display: flex; flex-direction: column; padding: 12px 10px;
}
.brand { font-weight: 700; font-size: 15px; padding: 6px 8px 14px; color: #fff; letter-spacing: -.3px; }
.side-btn {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px; border-radius: 10px; font-size: 14px; color: #e3e3e3; text-align: left;
}
.side-btn:hover { background: #2a2a2a; }
.side-btn .icon { width: 18px; text-align: center; color: #bbb; }
#convList { flex: 1; overflow-y: auto; margin-top: 14px; }
.conv-item {
  display: block; width: 100%; text-align: left;
  padding: 10px; border-radius: 10px;
  font-size: 14px; color: #dcdcdc;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 2px;
}
.conv-item:hover { background: #2a2a2a; }
.conv-item.active { background: #303030; }
.conv-empty { color: #777; font-size: 13px; padding: 8px 10px; }
.side-foot { border-top: 1px solid #2a2a2a; padding-top: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 6px 8px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: #19c37d; color: #064e35;
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; flex: none;
}
.uname { flex: 1; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#btnLogout { color: #999; font-size: 13px; padding: 4px 8px; border-radius: 8px; }
#btnLogout:hover { background: #2a2a2a; color: #fff; }
.side-mask { display: none; }

/* main */
.chat-main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #fff; }
.chat-head {
  display: flex; align-items: center; gap: 8px;
  height: 52px; padding: 0 16px;
  border-bottom: 1px solid #ececec; flex: none;
}
.chat-title { flex: 1; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.invite-btn { border: 1px solid #d9d9d9; border-radius: 18px; padding: 5px 14px; font-size: 13px; color: #333; }
.invite-btn:hover { background: #f5f5f5; }
.icon-btn { font-size: 18px; padding: 4px 8px; border-radius: 8px; }
.icon-btn:hover { background: #f2f2f2; }
.mobile-only { display: none; }

/* messages */
.msg-scroll { flex: 1; overflow-y: auto; }
.msg-col { max-width: 768px; margin: 0 auto; padding: 28px 20px 10px; }
.welcome { text-align: center; padding-top: 18vh; }
.welcome h1 { font-size: 30px; font-weight: 650; letter-spacing: -.5px; }
.welcome p { color: #8e8e8e; margin-top: 10px; font-size: 14px; }
.msg-own { display: flex; justify-content: flex-end; margin: 0 0 14px; }
.msg-own .bubble {
  background: #f1f1f3; border-radius: 22px; padding: 10px 18px; max-width: 72%;
  white-space: pre-wrap; word-break: break-word; line-height: 1.65; font-size: 15.5px;
}
.msg-ai { margin: 0 0 26px; }
.ai-label { font-size: 12.5px; font-weight: 600; color: #8e8e8e; margin-bottom: 3px; }
.ai-body { white-space: pre-wrap; word-break: break-word; line-height: 1.75; font-size: 15.5px; }
.cursor {
  display: inline-block; width: 9px; height: 17px; margin-left: 2px; vertical-align: -3px;
  background: #0d0d0d; border-radius: 1px; animation: blink 1.05s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* typing indicator */
.typing-bar {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: #8e8e8e;
  max-width: 768px; margin: 0 auto 6px; padding: 0 6px;
}
.typing-bar b { font-weight: 600; }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: #b4b4b4; animation: dot 1.2s infinite; }
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes dot {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30% { transform: translateY(-3px); opacity: 1; }
}

/* composer */
.composer-wrap { flex: none; padding: 6px 16px 14px; background: linear-gradient(transparent, #fff 30%); }
.composer {
  display: flex; align-items: flex-end; gap: 10px;
  max-width: 768px; margin: 0 auto;
  border: 1px solid #e3e3e3; border-radius: 28px;
  padding: 10px 10px 10px 18px;
  box-shadow: 0 2px 14px rgba(0,0,0,.05); background: #fff;
}
.composer:focus-within { border-color: #c7c7c7; }
#input {
  flex: 1; border: 0; outline: none; resize: none;
  max-height: 180px; line-height: 1.6; padding: 6px 0; background: transparent;
}
#input:disabled { color: #999; }
#btnSend {
  width: 36px; height: 36px; border-radius: 50%;
  background: #0d0d0d; color: #fff;
  display: flex; align-items: center; justify-content: center; flex: none;
  transition: background .15s;
}
#btnSend:disabled { background: #d9d9d9; cursor: default; }
#btnSend:not(:disabled):hover { background: #333; }
.composer-hint { text-align: center; font-size: 12px; color: #a4a4a4; margin-top: 8px; }

/* modal */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
}
.modal {
  width: 400px; max-width: calc(100vw - 32px);
  background: #fff; border-radius: 16px; padding: 24px;
  box-shadow: 0 18px 50px rgba(0,0,0,.35);
}
.modal h3 { font-size: 17px; margin-bottom: 4px; }
.modal .modal-sub { font-size: 13px; color: #8e8e8e; margin-bottom: 16px; }
.modal input {
  width: 100%; border: 1px solid #d9d9d9; border-radius: 10px;
  padding: 11px 13px; outline: none; margin-bottom: 12px; font-size: 14px;
}
.modal input:focus { border-color: #0d0d0d; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions button { flex: 1; padding: 11px 0; border-radius: 10px; font-weight: 600; }
.btn-cancel { background: #f0f0f0; color: #333; }
.btn-cancel:hover { background: #e4e4e4; }
.btn-ok { background: #0d0d0d; color: #fff; }
.btn-ok:hover { background: #2a2a2a; }
.code-box {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 26px; letter-spacing: 3px;
  background: #f5f5f5; border: 1px dashed #cfcfcf; border-radius: 12px;
  text-align: center; padding: 16px 0; margin: 6px 0 14px;
  user-select: all;
}
.member-list { max-height: 150px; overflow-y: auto; margin: 4px 0 0; }
.member-item { display: flex; align-items: center; gap: 8px; padding: 6px 4px; font-size: 14px; }
.member-item .avatar { width: 24px; height: 24px; font-size: 12px; }

/* toast */
#toast {
  position: fixed; left: 50%; bottom: 90px;
  transform: translateX(-50%) translateY(20px);
  background: #1c1c1c; color: #fff; font-size: 14px;
  border-radius: 10px; padding: 10px 18px;
  opacity: 0; pointer-events: none; transition: .25s;
  z-index: 99; max-width: 80vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* scrollbar */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); }

@media (max-width: 768px) {
  .mobile-only { display: inline-flex; }
  #sidebar {
    position: fixed; z-index: 40; top: 0; left: 0; bottom: 0;
    transform: translateX(-100%); transition: transform .25s;
    box-shadow: 8px 0 30px rgba(0,0,0,.3);
  }
  #sidebar.open { transform: translateX(0); }
  .side-mask.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 39; }
  .msg-col { padding: 20px 14px 10px; }
}
