/* ═══════════════════════════════════════════════════════════════
   全局
   ═══════════════════════════════════════════════════════════════ */

:root {
  --bg:      #f5f6f7;
  --bg-2:    #ffffff;
  --bg-3:    #eef0f2;
  --bg-4:    #e5e7ea;
  --fg:      #333333;
  --fg-dim:  #666666;
  --fg-mute: #999999;
  --accent:  #12b7f5;
  --accent-2:#0ba5e0;
  --success: #07c160;
  --warn:    #f5a623;
  --error:   #ff3b30;
  --border:  #e6e6e6;
  --radius:  8px;
  --sidebar-w: 300px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 14px; line-height: 1.5;
  background: var(--bg); color: var(--fg);
  -webkit-font-smoothing: antialiased;
}

input, button, textarea { font: inherit; }

button { cursor: pointer; }

.dim { color: var(--fg-dim); }

/* ═══════════════════════════════════════════════════════════════
   认证页
   ═══════════════════════════════════════════════════════════════ */

.auth-page {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(180deg, #e8f7ff 0%, #f5f6f7 60%, #eef0f2 100%);
}
.auth-page[hidden] { display: none; }

.auth-card {
  width: 380px; max-width: 92vw; padding: 32px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}

.auth-logo { text-align: center; margin-bottom: 24px; }
.logo-mark {
  display: inline-block;
  padding: 4px 12px; border-radius: 6px;
  background: var(--accent); color: #fff;
  font-weight: 700; font-size: 14px; letter-spacing: 1px;
}
.logo-text { margin-top: 8px; color: var(--fg-dim); font-size: 13px; }

.auth-tabs {
  display: flex; gap: 4px; padding: 3px;
  background: var(--bg-3); border-radius: var(--radius);
  margin-bottom: 20px;
}
.auth-tabs .tab {
  flex: 1; padding: 8px;
  background: transparent; border: none;
  color: var(--fg-dim); border-radius: 6px;
  transition: background .15s, color .15s;
}
.auth-tabs .tab.active {
  background: var(--bg-4); color: var(--fg);
}

.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form[hidden] { display: none; }
.auth-form label { display: flex; flex-direction: column; gap: 6px; }
.auth-form label span { font-size: 12px; color: var(--fg-dim); }

.auth-form input {
  padding: 10px 12px;
  background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius);
  outline: none;
  transition: border-color .15s;
}
.auth-form input:focus { border-color: var(--accent); }

.captcha-row {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
}
.captcha-q {
  flex: 1; font-size: 16px; letter-spacing: 1px;
  font-family: "SF Mono", Menlo, monospace; color: var(--fg);
}

button.primary {
  padding: 10px 16px;
  background: var(--accent); color: #fff;
  border: 1px solid var(--accent); border-radius: var(--radius);
  transition: background .15s;
}
button.primary:hover { background: var(--accent-2); }
button.primary:disabled { opacity: .5; cursor: not-allowed; }
button.primary.full { width: 100%; padding: 11px; }

button.ghost {
  padding: 6px 10px;
  background: transparent; color: var(--fg-dim);
  border: 1px solid var(--border); border-radius: 6px;
  transition: all .15s;
}
button.ghost:hover { color: var(--fg); border-color: var(--fg-dim); }

button.mini {
  padding: 3px 8px; font-size: 12px;
  background: var(--accent); color: #fff;
  border: 1px solid var(--accent); border-radius: 4px;
}

.auth-error {
  min-height: 18px; margin-top: 12px;
  color: var(--error); font-size: 12px; text-align: center;
}

/* ═══════════════════════════════════════════════════════════════
   主应用
   ═══════════════════════════════════════════════════════════════ */

.app { display: flex; height: 100vh; }
.app[hidden] { display: none; }

/* ── 侧栏 ── */

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: relative;
}

.me-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.me-info { flex: 1; min-width: 0; }
.me-nick {
  font-weight: 600; font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.me-sign {
  font-size: 11px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.me-actions { display: flex; gap: 2px; }

.icon-btn {
  padding: 6px 9px;
  background: transparent; color: var(--fg-dim);
  border: 1px solid transparent; border-radius: 6px;
  font-size: 15px; line-height: 1;
  transition: all .15s;
}
.icon-btn:hover { background: var(--bg-3); color: var(--fg); }

.avatar {
  display: block;
  width: 36px; height: 36px;
  border-radius: 50%; object-fit: cover;
  background: var(--bg-3);
  flex-shrink: 0;
}
.avatar-lg { width: 40px; height: 40px; }

.search-bar { padding: 10px 14px 4px; }
.search-bar input {
  width: 100%; padding: 8px 12px;
  background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px;
  outline: none;
}
.search-bar input:focus { border-color: var(--accent); }

.list-tabs {
  display: flex; gap: 2px;
  padding: 8px 14px 0;
}
.list-tab {
  flex: 1; padding: 7px 0;
  background: transparent; border: none;
  color: var(--fg-dim); font-size: 13px;
  border-bottom: 2px solid transparent;
  transition: all .15s;
}
.list-tab:hover { color: var(--fg); }
.list-tab.active { color: var(--fg); border-bottom-color: var(--accent); }

.list-body { flex: 1; overflow-y: auto; padding: 6px 0 20px; }
.list-body::-webkit-scrollbar { width: 6px; }
.list-body::-webkit-scrollbar-thumb { background: #d5d8dc; border-radius: 3px; }
.list-body::-webkit-scrollbar-track { background: transparent; }

.item-list {
  list-style: none; margin: 0; padding: 0;
}
.item-list[hidden] { display: none; }

.item-list .item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; cursor: pointer;
  transition: background .12s;
  position: relative;
}
.item-list .item:hover { background: var(--bg-3); }
.item-list .item.active { background: var(--bg-4); }

.item-list .item .info { flex: 1; min-width: 0; }
.item-list .item .name {
  font-size: 13px; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.item-list .item .preview {
  font-size: 11px; color: var(--fg-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-top: 2px;
}
.item-list .item .meta {
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
  flex-shrink: 0;
}
.item-list .item .time { font-size: 11px; color: var(--fg-mute); }

.item-list .item .badge {
  background: var(--error); color: #fff;
  font-size: 10px; font-weight: 600;
  border-radius: 10px; padding: 1px 6px;
  min-width: 18px; text-align: center;
}

.item-list .item .dot {
  position: absolute; left: 38px; top: 30px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--fg-mute); border: 2px solid var(--bg-2);
}
.item-list .item .dot.on { background: var(--success); }

.item-list .empty-item {
  padding: 24px 16px; text-align: center;
  color: var(--fg-mute); font-size: 12px;
}

.request-banner {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px;
  background: var(--accent); color: #fff;
  font-size: 12px;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.3);
  animation: banner-in .25s ease;
}
.request-banner[hidden] { display: none; }
.request-banner span { flex: 1; }
.request-banner button {
  background: rgba(255,255,255,.2); color: #fff;
  border: none; border-radius: 4px;
  padding: 4px 10px; cursor: pointer;
}
@keyframes banner-in { from { transform: translateY(100%); } }

/* ── 聊天区 ── */

.chat-pane {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  background: var(--bg);
}

.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-name { font-size: 15px; font-weight: 600; }
.chat-sub  { font-size: 12px; margin-top: 2px; }

.messages {
  flex: 1; overflow-y: auto; padding: 20px 24px;
  display: flex; flex-direction: column; gap: 14px;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: #d5d8dc; border-radius: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--fg-mute); gap: 12px;
}
.empty-icon { font-size: 48px; opacity: .3; }
.empty-text { font-size: 13px; }

.msg {
  display: flex; gap: 10px; max-width: 100%;
  animation: msg-in .18s ease;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(4px); } }

.msg .msg-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  flex-shrink: 0; object-fit: cover;
  background: var(--bg-3);
}
.msg .msg-body { min-width: 0; flex: 1; max-width: min(680px, 78%); }
.msg .msg-head {
  display: flex; align-items: baseline; gap: 8px;
  font-size: 12px; color: var(--fg-dim); margin-bottom: 3px;
}
.msg .msg-name { color: var(--fg); font-weight: 500; }
.msg .msg-time { font-size: 11px; opacity: .6; }

.msg .bubble {
  display: inline-block;
  padding: 8px 12px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 2px 10px 10px 10px;
  word-wrap: break-word; white-space: pre-wrap; word-break: break-word;
  line-height: 1.55;
}

.msg.mine { flex-direction: row-reverse; }
.msg.mine .msg-body { display: flex; flex-direction: column; align-items: flex-end; }
.msg.mine .msg-head { flex-direction: row-reverse; }
.msg.mine .bubble {
  background: var(--accent); color: #fff; border-color: var(--accent);
  border-radius: 10px 2px 10px 10px;
}

.msg.system {
  justify-content: center; max-width: 100%;
}
.msg.system .bubble {
  background: transparent; border: none;
  color: var(--fg-mute); font-size: 11px;
  padding: 2px 10px;
}

.msg .file-attach {
  display: flex; align-items: center; gap: 10px;
  margin-top: 6px; padding: 10px 12px;
  background: rgba(91,141,239,.08);
  border: 1px solid rgba(91,141,239,.25);
  border-radius: 8px;
  color: var(--fg); text-decoration: none;
  font-size: 13px;
  max-width: 320px;
  transition: background .15s;
}
.msg .file-attach:hover { background: rgba(91,141,239,.16); }
.msg .file-attach .icon { font-size: 20px; flex-shrink: 0; }
.msg .file-attach .fname {
  flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg .file-attach .fsize { color: var(--fg-dim); font-size: 11px; flex-shrink: 0; }
.msg .file-attach img {
  display: block; margin-top: 6px;
  max-width: 260px; max-height: 200px; border-radius: 6px;
}
.msg.mine .file-attach {
  background: rgba(255,255,255,.12);
  border-color: rgba(255,255,255,.2);
  color: #fff;
}
.msg.mine .file-attach:hover { background: rgba(255,255,255,.2); }

.chat-input {
  display: flex; gap: 8px; align-items: center;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-input[hidden] { display: none; }
.chat-input #msg-input {
  flex: 1; padding: 10px 14px;
  background: var(--bg-2); color: var(--fg);
  border: 1px solid var(--border); border-radius: 22px;
  outline: none;
  transition: border-color .15s;
}
.chat-input #msg-input:focus { border-color: var(--accent); }
.chat-input #btn-send { border-radius: 22px; padding: 10px 22px; }

/* ═══════════════════════════════════════════════════════════════
   弹窗
   ═══════════════════════════════════════════════════════════════ */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  animation: fade-in .15s;
}
@keyframes fade-in { from { opacity: 0; } }

.modal {
  width: 400px; max-width: 92vw; max-height: 80vh;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.6);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.modal-header button {
  background: none; border: none; color: var(--fg-dim);
  font-size: 18px; padding: 0; line-height: 1;
}
.modal-body { padding: 18px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 12px 18px; border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}

.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-row span { font-size: 12px; color: var(--fg-dim); }
.form-row input, .form-row textarea {
  padding: 9px 12px;
  background: var(--bg-3); color: var(--fg);
  border: 1px solid var(--border); border-radius: 6px;
  outline: none; resize: none;
}
.form-row input:focus, .form-row textarea:focus { border-color: var(--accent); }

.user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 0;
}
.user-row .info { flex: 1; min-width: 0; }
.user-row .name { font-size: 13px; font-weight: 500; }
.user-row .sub  { font-size: 11px; color: var(--fg-dim); }

.avatar-upload {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 18px;
}
.avatar-upload img {
  width: 64px; height: 64px; border-radius: 50%;
  object-fit: cover; background: var(--bg-3);
}

/* ═══════════════════════════════════════════════════════════════
   响应式
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 720px) {
  :root { --sidebar-w: 100vw; }
  .app { flex-direction: column; }
  .chat-pane { position: absolute; inset: 0; z-index: 10; }
  .app.show-chat .sidebar { display: none; }
  .app:not(.show-chat) .chat-pane { display: none; }
  .chat-header::before {
    content: '←'; display: inline-block;
    margin-right: 12px; cursor: pointer; font-size: 18px;
  }
}
/* ═══════════════════════════════════════════════════════════════
   语音消息
   ═══════════════════════════════════════════════════════════════ */

/* 按住说话按钮：录音中红色脉冲 */
.chat-input #btn-voice.recording {
  background: var(--error); color: #fff; border-color: var(--error);
  animation: voice-pulse .8s ease-in-out infinite;
}
@keyframes voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.5); }
  50%      { box-shadow: 0 0 0 8px rgba(239,68,68,0); }
}

/* 语音消息播放器 */
.msg .voice-attach {
  display: flex; flex-direction: column; gap: 4px;
  margin-top: 6px; max-width: 320px;
}
.msg .voice-attach audio {
  width: 240px; max-width: 100%; height: 40px; outline: none;
  border-radius: 18px; background: var(--bg-3);
}
.msg .voice-attach .fname {
  font-size: 11px; color: var(--fg-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg.mine .voice-attach .fname { color: rgba(255,255,255,.75); }

/* 公告横幅 */
.announce-bar {
  display: flex; align-items: center; gap: 8px;
  margin: 10px 14px 0; padding: 8px 12px;
  background: rgba(91,141,239,.12);
  border: 1px solid rgba(91,141,239,.3);
  border-radius: 8px; cursor: pointer;
}
.announce-bar[hidden] { display: none; }
.announce-bar .ann-text {
  flex: 1; font-size: 12px; color: var(--fg);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.announce-bar .ann-more {
  background: none; border: none; color: var(--accent);
  font-size: 12px; cursor: pointer; padding: 0;
}

/* ═══════════════════════════════════════════════════════════════
   表情面板
   ═══════════════════════════════════════════════════════════════ */
.emoji-panel {
  position: fixed; z-index: 300;
  display: grid; grid-template-columns: repeat(8, 1fr);
  gap: 4px; padding: 10px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,0.12);
  width: 320px; max-width: 90vw;
}
.emoji-item {
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; padding: 4px; cursor: pointer;
  border-radius: 6px; transition: background .12s;
}
.emoji-item:hover { background: var(--bg-3); }

/* 图片消息：内嵌缩略图 */
.msg .msg-image {
  display: block; margin-top: 6px;
  border-radius: 8px; overflow: hidden;
  max-width: 320px; cursor: zoom-in;
}
.msg .msg-image img {
  display: block; width: 100%; max-width: 320px; max-height: 240px;
  object-fit: cover; border-radius: 8px;
  transition: transform .15s;
}
.msg .msg-image:hover img { transform: scale(1.02); }
