:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --border: #e3e8f0;
  --text: #1f2733;
  --text-sub: #7a8598;
  --primary: #2f6fed;
  --primary-dark: #245bd0;
  --danger: #e5484d;
  --ok: #2f9e6e;
  --bubble-me: #2f6fed;
  --bubble-other: #ffffff;
  --radius: 10px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ---------- 登录 ---------- */
.login-wrap {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e8effc 0%, #f4f6fa 60%, #e6f2ee 100%);
}
.login-card {
  width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  box-shadow: 0 12px 40px rgba(31, 49, 82, 0.08);
  text-align: center;
}

.field { text-align: left; margin-bottom: 16px; }
.field label { display: block; font-size: 13px; color: var(--text-sub); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: #fafbfd;
  outline: none;
}
.field input:focus, .field textarea:focus, .field select:focus {
  border-color: var(--primary);
  background: #fff;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text-sub); }
.btn-ghost:hover { background: #eef1f6; color: var(--text); }
.btn-outline { background: #eaf1ff; color: var(--primary); }
.btn-outline:hover { background: #dce7ff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c93a3f; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; padding: 11px; font-size: 15px; }
.btn-mini {
  padding: 3px 8px; font-size: 12px; border-radius: 6px;
  background: #f0f3f8; color: var(--text-sub); margin-right: 6px;
}
.btn-mini:hover { background: #e4e9f2; color: var(--text); }
.btn-mini.danger { color: var(--danger); }
.btn-mini.danger:hover { background: #fdecec; }

.form-error {
  background: #fdecec;
  color: var(--danger);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  text-align: left;
}
.form-msg {
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  margin-top: 10px;
  text-align: left;
}
.form-msg.ok { background: #e8f6ef; color: var(--ok); }
.form-msg.err { background: #fdecec; color: var(--danger); }

/* ---------- 主布局 ---------- */
.app { display: flex; height: 100vh; }

.sidebar {
  width: 280px;
  background: #1f2733;
  color: #d7dde7;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.side-header { padding: 18px 18px 12px; }
.side-title { font-size: 16px; font-weight: 600; color: #fff; }
.side-user { margin-top: 10px; display: flex; align-items: center; gap: 8px; }
.side-user-name { font-size: 14px; }
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 20px;
  background: rgba(255, 152, 0, 0.9);
  color: #fff;
}
.badge.admin { background: rgba(47, 111, 237, 0.9); }
.badge.member { background: rgba(255, 255, 255, 0.18); color: #cfd6e2; }
.badge.disabled { background: rgba(229, 72, 77, 0.85); }

.side-actions {
  display: flex;
  gap: 6px;
  padding: 0 14px 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-wrap: wrap;
}
.side-actions .btn-ghost { color: #aeb8c8; }
.side-actions .btn-ghost:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.side-actions .btn-outline { background: rgba(47, 111, 237, 0.25); color: #9db9f7; }
.side-actions .btn-outline:hover { background: rgba(47, 111, 237, 0.4); }

.conv-scroll { flex: 1; overflow-y: auto; padding: 10px; }
.conv-search { padding: 0 0 8px; }
.conv-search input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 12px;
  border: 1px solid var(--border, #dfe3ea);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  background: #f7f8fa;
}
.conv-search input:focus { border-color: var(--primary, #4a7dff); background: #fff; }
.admin-search { margin: 8px 0 12px; }
.admin-search input {
  width: 100%;
  max-width: 360px;
  box-sizing: border-box;
  padding: 8px 12px;
  border: 1px solid var(--border, #dfe3ea);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  background: #f7f8fa;
}
.admin-search input:focus { border-color: var(--primary, #4a7dff); background: #fff; }
.conv-group-label {
  font-size: 11px;
  color: #8a94a6;
  padding: 10px 8px 6px;
  letter-spacing: 1px;
}
.conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.12s;
}
.conv-item:hover { background: rgba(255, 255, 255, 0.07); }
.conv-item.active { background: var(--primary); color: #fff; }
.conv-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: #3a4656;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}
.conv-item.active .conv-avatar { background: rgba(255,255,255,0.25); }
.conv-info { flex: 1; min-width: 0; }
.conv-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-last {
  font-size: 12px; color: #8a94a6;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px;
}
.conv-item.active .conv-last { color: rgba(255,255,255,0.8); }
.conv-tag {
  font-size: 10px; padding: 1px 6px; border-radius: 10px;
  background: rgba(255,255,255,0.14); color: #b8c2d2; margin-left: 4px;
}
.conv-item.active .conv-tag { background: rgba(255,255,255,0.25); color: #fff; }

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

.chat-empty {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-sub);
}
.chat-empty-icon { font-size: 52px; margin-bottom: 12px; }
.chat-empty-tip { font-size: 12px; margin-top: 6px; opacity: 0.8; }

.chat-main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 14px 22px;
  display: flex; align-items: center; justify-content: space-between;
}
.chat-title { font-size: 16px; font-weight: 600; }
.chat-sub { font-size: 12px; color: var(--text-sub); margin-top: 2px; }

.msg-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px 26px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg-row { display: flex; gap: 10px; max-width: 78%; }
.msg-row.me { align-self: flex-end; flex-direction: row-reverse; }
.msg-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: #c8d2e4; color: #4a5568;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0; margin-top: 18px;
}
.msg-body { display: flex; flex-direction: column; }
.msg-meta { font-size: 11px; color: var(--text-sub); margin: 0 4px 4px; display: flex; gap: 8px; align-items: center; }
.msg-row.me .msg-meta { justify-content: flex-end; }
.msg-del {
  color: var(--danger); cursor: pointer; font-size: 11px;
  visibility: hidden;
}
.msg-row:hover .msg-del { visibility: visible; }
.msg-bubble {
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  background: var(--bubble-other);
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(31, 49, 82, 0.04);
}
.msg-row.me .msg-bubble {
  background: var(--bubble-me);
  border-color: var(--bubble-me);
  color: #fff;
}
.msg-bubble.image-bubble { padding: 5px; }
.msg-img {
  max-width: 280px;
  max-height: 220px;
  border-radius: 8px;
  display: block;
  cursor: zoom-in;
}
.msg-img-loading {
  width: 160px; height: 100px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; color: var(--text-sub);
}
.msg-file {
  display: flex; align-items: center; gap: 10px;
  min-width: 180px;
}
.msg-file-icon { font-size: 26px; }
.msg-file-info { flex: 1; min-width: 0; }
.msg-file-name {
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.msg-file-size { font-size: 11px; opacity: 0.75; margin-top: 2px; }
.msg-file-dl {
  border: none; cursor: pointer;
  background: rgba(255,255,255,0.2); color: inherit;
  border-radius: 6px; padding: 4px 10px; font-size: 12px; flex-shrink: 0;
}
.msg-row:not(.me) .msg-file-dl { background: #eaf1ff; color: var(--primary); }
.msg-file-dl:hover { filter: brightness(0.95); }

.attach-btn { font-size: 18px; padding: 6px 10px; }
.msg-day {
  align-self: center;
  font-size: 11px;
  color: var(--text-sub);
  background: #e9edf4;
  border-radius: 12px;
  padding: 3px 12px;
}

.chat-input {
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 12px 18px;
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.chat-input textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: #fafbfd;
}
.chat-input textarea:focus { border-color: var(--primary); background: #fff; }

/* ---------- 管理面板 ---------- */
.admin-panel { flex: 1; overflow-y: auto; padding: 0 26px 30px; }
.admin-header {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  margin: 0 -26px 18px;
  padding: 14px 22px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 5;
}
.admin-tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.admin-tab {
  border: none; background: #e9edf4; color: var(--text-sub);
  padding: 8px 20px; border-radius: 8px; font-size: 14px; cursor: pointer;
}
.admin-tab.active { background: var(--primary); color: #fff; }
.admin-tab-body { max-width: 860px; }
.admin-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 22px;
  margin-bottom: 18px;
}
.admin-card h3 { font-size: 15px; margin-bottom: 14px; }

.create-user-form { display: flex; flex-wrap: wrap; gap: 10px; }
.create-user-form input, .create-user-form select {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  background: #fafbfd;
}
.create-user-form input { flex: 1 1 180px; }
.create-user-form input:focus, .create-user-form select:focus { border-color: var(--primary); background: #fff; }
.create-user-form select { flex: 0 0 110px; }

.table-wrap { overflow-x: auto; }
.admin-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.admin-table th, .admin-table td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.admin-table th { color: var(--text-sub); font-weight: 500; font-size: 12px; }
.status-pill { font-size: 11px; padding: 2px 10px; border-radius: 12px; }
.status-pill.active { background: #e8f6ef; color: var(--ok); }
.status-pill.disabled { background: #fdecec; color: var(--danger); }
.role-pill { font-size: 11px; padding: 2px 10px; border-radius: 12px; }
.role-pill.superadmin { background: #fff3e0; color: #d97a06; }
.role-pill.admin { background: #eaf1ff; color: var(--primary); }
.role-pill.member { background: #f0f3f8; color: var(--text-sub); }

.create-group-form input[type="text"] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  background: #fafbfd;
  margin-bottom: 10px;
}
.create-group-form input[type="text"]:focus { border-color: var(--primary); background: #fff; }

.member-pick {
  display: flex; flex-wrap: wrap; gap: 8px;
  max-height: 180px; overflow-y: auto;
  padding: 4px 0 12px;
}
.member-pick label {
  display: flex; align-items: center; gap: 5px;
  background: #f0f3f8;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
}
.member-pick label:has(input:checked) { background: #eaf1ff; border-color: var(--primary); color: var(--primary); }
.member-pick input { accent-color: var(--primary); }

.admin-group-list { display: flex; flex-direction: column; gap: 10px; }
.admin-group-item {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.admin-group-info { flex: 1; min-width: 0; }
.admin-group-name { font-size: 14px; font-weight: 600; }
.admin-group-members { font-size: 12px; color: var(--text-sub); margin-top: 4px; }
.admin-group-ops { display: flex; gap: 6px; flex-shrink: 0; }

.admin-tip { font-size: 13px; color: var(--text-sub); line-height: 1.7; margin-bottom: 16px; }
.admin-section { font-size: 17px; margin: 6px 0 14px; }
.retention-label { font-size: 14px; font-weight: 500; }
.retention-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.retention-form select, .retention-form input {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  background: #fafbfd;
}
.retention-form select:focus, .retention-form input:focus { border-color: var(--primary); background: #fff; }
.retention-form input { width: 120px; }
.perm-check {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 4px; font-size: 14px; cursor: pointer; user-select: none;
}
.perm-check input { accent-color: var(--primary); width: 16px; height: 16px; }

/* ---------- 弹窗 ---------- */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(20, 28, 40, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal {
  width: 380px;
  background: #fff;
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.18);
}
.modal-wide { width: 460px; }
.modal h3 { font-size: 16px; margin-bottom: 16px; }
.confirm-text { font-size: 14px; color: var(--text); line-height: 1.6; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  top: 26px; left: 50%;
  transform: translateX(-50%);
  background: #1f2733;
  color: #fff;
  font-size: 13px;
  padding: 10px 20px;
  border-radius: 10px;
  z-index: 99;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
}
.toast.err { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* ---------- 语音消息 ---------- */
.msg-bubble.voice-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 140px;
  padding: 8px 14px;
}
.voice-play {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: rgba(255,255,255,0.25);
  color: inherit;
  font-size: 13px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.msg-row:not(.me) .voice-play { background: #eaf1ff; color: var(--primary); }
.voice-wave {
  flex: 1;
  height: 18px;
  min-width: 44px;
  background-image: repeating-linear-gradient(90deg, currentColor 0 2px, transparent 2px 6px);
  opacity: 0.45;
}
.voice-dur { font-size: 12px; opacity: 0.85; flex-shrink: 0; }

/* 录音提示条 */
.voice-rec-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px;
  background: #fff7e8;
  border-top: 1px solid #f2e2bd;
  font-size: 13px;
  color: #8a6116;
}
.voice-rec-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--danger);
  animation: blink 1s infinite;
}
@keyframes blink { 50% { opacity: 0.2; } }

/* ---------- 通话 ---------- */
.menu-btn { display: none; }
.call-btn { font-size: 16px; }
.chat-header-main { flex: 1; min-width: 0; }
.chat-header-ops { display: flex; gap: 4px; flex-shrink: 0; }

.call-overlay {
  position: fixed; inset: 0;
  background: rgba(18, 24, 34, 0.92);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.call-panel {
  position: relative;
  width: 100%; height: 100%;
  max-width: 560px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: #fff;
  padding: 24px;
}
.call-peer { text-align: center; margin-bottom: 26px; }
.call-avatar {
  width: 84px; height: 84px;
  border-radius: 50%;
  background: linear-gradient(135deg, #2f6fed, #6ea0ff);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 34px;
  margin: 0 auto 14px;
}
.call-avatar.big { width: 96px; height: 96px; font-size: 40px; }
.call-peer-name { font-size: 20px; font-weight: 600; }
.call-status { font-size: 13px; opacity: 0.75; margin-top: 8px; }
.call-video {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  background: #000;
  z-index: -1;
}
.call-video-local {
  position: absolute;
  right: 16px; top: 16px;
  width: 110px;
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  z-index: 2;
  background: #000;
}
.call-ops {
  display: flex;
  gap: 14px;
  margin-top: 30px;
  flex-wrap: wrap;
  justify-content: center;
  z-index: 3;
}
.call-op-btn {
  border: none;
  cursor: pointer;
  background: rgba(255,255,255,0.16);
  color: #fff;
  font-size: 14px;
  padding: 12px 20px;
  border-radius: 26px;
  transition: background 0.15s;
}
.call-op-btn:hover { background: rgba(255,255,255,0.28); }
.call-op-btn.hangup { background: var(--danger); }
.call-op-btn.hangup:hover { background: #c93a3f; }
.call-op-btn.accept { background: var(--ok); }
.call-op-btn.accept:hover { background: #27855c; }

.call-incoming { text-align: center; width: 320px; }
.call-incoming-ops {
  display: flex;
  gap: 16px;
  justify-content: center;
  margin-top: 24px;
}

.drawer-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
}

/* ---------- 响应式（手机适配） ---------- */
@media (max-width: 720px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 78%;
    max-width: 320px;
    z-index: 45;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-block; }
  .chat-area, .chat-main { width: 100%; }
  .chat-header { padding: 10px 12px; gap: 8px; }
  .chat-title { font-size: 15px; }
  .chat-sub { display: none; }
  .msg-list { padding: 14px 10px; }
  .msg-row { max-width: 88%; }
  .msg-avatar { display: none; }
  .msg-img { max-width: 200px; max-height: 170px; }
  .chat-input { padding: 8px 10px; gap: 6px; }
  .chat-input textarea { font-size: 15px; padding: 8px 10px; }
  .attach-btn { font-size: 17px; padding: 6px 7px; }
  #sendBtn { padding: 8px 13px; }
  .login-card { width: 92%; max-width: 380px; padding: 30px 24px; }
  .modal { width: 92%; max-width: 420px; padding: 20px; }
  .modal-wide { width: 92%; }
  .admin-panel { padding: 0 12px 24px; }
  .admin-tabs { flex-wrap: wrap; }
  .admin-tab { padding: 7px 12px; font-size: 13px; }
  .create-user-form, .create-group-form { flex-direction: column; align-items: stretch; }
  .retention-form { flex-wrap: wrap; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .admin-table { min-width: 560px; }
  .toast { top: 12px; width: max-content; max-width: 92%; }
  .call-video-local { width: 88px; }
  .voice-rec-bar { padding: 8px 12px; }
}
