/* ============ 全局 ============ */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #1e2028;
  --bg2: #262933;
  --panel: #2b2f3a;
  --panel2: #333844;
  --border: #3a3f4d;
  --text: #e6e8ee;
  --text-dim: #9aa0ae;
  --accent: #5865f2;
  --accent-h: #6a74ff;
  --danger: #ed4245;
  --ok: #3ba55d;
  --speak: #43b581;
}
html, body { height: 100%; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
a { color: var(--accent-h); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ 通用组件 ============ */
.btn-primary {
  background: var(--accent);
  color: #fff; border: none; border-radius: 6px;
  padding: 8px 16px; cursor: pointer; font-size: 14px;
  transition: background .15s;
}
.btn-primary:hover { background: var(--accent-h); }
.btn-primary.btn-block { width: 100%; padding: 11px; }
.btn-primary.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-ghost {
  background: transparent; color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 14px; cursor: pointer; font-size: 13px;
}
.btn-ghost:hover { background: var(--panel2); }
.btn-danger { background: var(--danger); color: #fff; border: none; border-radius: 6px; padding: 8px 14px; cursor: pointer; }
.btn-danger:hover { filter: brightness(1.1); }

.badge { display: inline-block; padding: 2px 9px; border-radius: 10px; font-size: 12px; }
.badge-admin { background: rgba(88,101,242,.18); color: #9aa5ff; }
.badge-member { background: var(--panel2); color: var(--text-dim); }
.badge-muted { background: var(--panel2); color: var(--text-dim); }

.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 18px 20px; margin-bottom: 16px; }
.card h2 { font-size: 16px; margin-bottom: 12px; }
.empty { color: var(--text-dim); }

.alert {
  background: rgba(237,66,69,.12); border: 1px solid rgba(237,66,69,.4);
  color: #ff9aa0; padding: 10px 12px; border-radius: 6px; margin-bottom: 14px;
}

/* ============ 进入页 ============ */
.auth-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-card {
  width: 360px; background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 30px 32px;
}
.auth-card h1 { font-size: 20px; margin-bottom: 16px; text-align: center; }
.auth-card label { display: block; font-size: 13px; color: var(--text-dim); margin: 12px 0 6px; }
.auth-card input {
  width: 100%; padding: 10px 12px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--bg2); color: var(--text);
  font-size: 14px; outline: none;
}
.auth-card input:focus { border-color: var(--accent); }
.auth-card .btn-primary { margin-top: 18px; }
.hint { font-size: 12px; color: var(--text-dim); margin-bottom: 8px; }
.hint b { color: #9aa5ff; }
.switch { text-align: center; margin-top: 16px; font-size: 13px; color: var(--text-dim); }

/* ============ 首页顶部栏 ============ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand { font-size: 17px; font-weight: 700; }
.userbox { display: flex; align-items: center; gap: 10px; }
.userbox .nick { font-weight: 600; }

.container { max-width: 760px; margin: 26px auto; padding: 0 16px; }

.inline-form { display: flex; gap: 10px; align-items: center; }
.inline-form input[type=text] { flex: 1; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); outline: none; }
.inline-form input[type=text]:focus { border-color: var(--accent); }
.inline-form input[type=number] { width: 80px; padding: 10px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); }

.room-table { width: 100%; border-collapse: collapse; }
.room-table th, .room-table td { text-align: left; padding: 11px 8px; border-bottom: 1px solid var(--border); }
.room-table th { color: var(--text-dim); font-size: 13px; font-weight: 500; }

/* ============ 语音房间页 ============ */
.room-body { height: 100vh; display: flex; flex-direction: column; }
.room-wrap { flex: 1; display: flex; flex-direction: column; }

.room-topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.room-topbar .room-title { font-size: 16px; font-weight: 700; margin: 0 12px; }
.room-status { color: var(--text-dim); font-size: 13px; }

.room-main { flex: 1; display: flex; min-height: 0; }

.members-panel {
  width: 260px; background: var(--bg2); border-right: 1px solid var(--border);
  padding: 16px; display: flex; flex-direction: column; gap: 12px;
}
.members-panel h3 { font-size: 14px; color: var(--text-dim); }
.member-list { list-style: none; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.member-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; border-radius: 8px; background: var(--panel); border: 1px solid var(--border);
}
.member-item.self { border-color: var(--accent); }
.member-item .m-name { font-weight: 500; }
.m-voice { color: var(--panel2); transition: color .1s, text-shadow .1s; font-size: 12px; }
.member-item.speaking { border-color: var(--speak); background: rgba(67,181,129,.08); }
.member-item.speaking .m-voice { color: var(--speak); text-shadow: 0 0 8px var(--speak); }

.self-actions { display: flex; gap: 8px; }
.self-actions button { flex: 1; }

.chat-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-log { flex: 1; overflow-y: auto; padding: 16px 20px; }
.chat-line { margin-bottom: 8px; line-height: 1.5; }
.chat-line.system { color: var(--text-dim); font-size: 13px; }
.chat-line.mine { color: #b9c1ff; }
.chat-line.from { color: var(--text); }

.chat-input { display: flex; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); background: var(--panel); }
.chat-input input {
  flex: 1; padding: 10px 12px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg2); color: var(--text); outline: none;
}
.chat-input input:focus { border-color: var(--accent); }

.conn-tip {
  position: fixed; bottom: 70px; left: 50%; transform: translateX(-50%);
  background: rgba(237,66,69,.95); color: #fff; padding: 9px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.3); z-index: 10;
}
.hidden { display: none !important; }

/* 移动端适配 */
@media (max-width: 768px) {
  /* 进入页 */
  .auth-card { width: 92%; max-width: 360px; padding: 24px 20px; }

  /* 大厅 */
  .topbar { padding: 10px 12px; }
  .brand { font-size: 15px; }
  .container { max-width: 100%; margin: 16px auto; padding: 0 12px; overflow-x: auto; }
  .inline-form { flex-wrap: wrap; }
  .inline-form input[type=text] { flex: 1 1 100%; }
  .inline-form input[type=number] { width: 100%; flex: 1; }
  .room-table { min-width: 0; }
  .room-table th, .room-table td { padding: 10px 6px; }
  .room-table td:first-child { max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .room-table .btn-primary { white-space: nowrap; padding: 6px 10px; }
  .card { padding: 14px 14px; }

  /* 房间页：上下布局（成员在上，聊天在下） */
  .room-topbar { padding: 10px 12px; flex-wrap: wrap; }
  .room-status { flex-basis: 100%; order: 3; margin-top: 4px; }
  .room-main { flex-direction: column; }

  .members-panel {
    width: 100%; max-height: 44%;
    border-right: none; border-bottom: 1px solid var(--border);
    padding: 10px 12px; flex-direction: column; gap: 8px; overflow: hidden;
  }
  .members-panel h3 { white-space: nowrap; }
  .member-list { flex-direction: row; overflow-x: auto; flex: 0 0 auto; gap: 8px; padding-bottom: 2px; }
  .member-item { flex: 0 0 auto; min-width: 104px; }
  .self-actions { margin-left: 0; }
  .self-actions button { flex: 1; padding: 10px 0; }

  .chat-panel { flex: 1; min-height: 0; }
  .chat-log { padding: 12px 12px; }
  .chat-input { padding: 10px 12px; }
  .chat-input input { padding: 10px 10px; }
}

/* 超窄屏微调 */
@media (max-width: 400px) {
  .members-panel { max-height: 50%; }
  .member-item { min-width: 92px; }
  .auth-card h1 { font-size: 18px; }
}

/* ============ 管理后台 ============ */
.admin-wrap { max-width: 960px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.admin-wrap .card { margin-bottom: 18px; }
.admin-wrap h2 { font-size: 16px; margin-bottom: 14px; }
.admin-create { gap: 10px; flex-wrap: wrap; }
.admin-create input[type=text] { flex: 1 1 220px; }

/* 表格横向滚动（手机端不挤压） */
.table-scroll { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.admin-table { min-width: 520px; font-size: 14px; }
.admin-table td { vertical-align: middle; }
.room-edit-form { display: flex; gap: 8px; flex-wrap: nowrap; align-items: center; margin: 0; padding: 8px 0; }
.room-edit-form input[type=text] { flex: 1 1 auto; min-width: 120px; }

/* 状态徽章 */
.badge-muted { background: #fdecea; color: #c0392b; border: 1px solid #f5c6c0; }
.alert-ok { background: #eafaf1; color: #1e7e45; border: 1px solid #b7e4c7; }

/* 房间成员禁言标记 */
.m-muted {
  margin-left: auto; font-size: 11px; color: #c0392b;
  background: #fdecea; border-radius: 6px; padding: 2px 7px; white-space: nowrap;
}
.member-item.is-muted { opacity: .72; }
.member-item.is-muted .m-name { color: #999; }

/* 被禁用的输入/按钮 */
button:disabled, input:disabled { opacity: .55; cursor: not-allowed; }
.chat-input input:disabled { background: #f4f5f7; }

@media (max-width: 768px) {
  .admin-table { min-width: 480px; }
  .room-edit-form { flex-wrap: wrap; }
  .room-edit-form input[type=text] { flex: 1 1 100%; }
}
