:root {
  --bg: #eef0f5;
  --bar: #ffffff;
  --line: #e6e6ea;
  --text: #1a1a1a;
  --muted: #9b9ba3;
  --purple: #6c5ce7;
  --bubble-self: #e9e3fb;
  --danger: #e5483c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: #ffffff;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

button {
  font-family: inherit;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

input,
select {
  font-family: inherit;
}

/* ---------------- 通用头像 ---------------- */

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  font-size: 15px;
  line-height: 1;
  color: #ffffff;
  overflow: hidden;
  user-select: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

.avatar.small {
  width: 34px;
  height: 34px;
  font-size: 14px;
}

.avatar.large {
  width: 96px;
  height: 96px;
  font-size: 34px;
}

.av-muzi {
  background: linear-gradient(145deg, #f7ddc2 0%, #eab793 52%, #cf9475 100%);
}

.av-c {
  background: linear-gradient(145deg, #f9d3e0 0%, #eb9fba 52%, #d4779a 100%);
}

/* 头像照片：铺满圆形，渐变作为加载失败时的兜底 */
.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

/* ---------------- 登录页 ---------------- */

.page-login {
  background: #f2f2f3;
  overflow: hidden;
}

.qr-stage {
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  -webkit-touch-callout: none;
  user-select: none;
}

.qr {
  width: 232px;
  height: 232px;
}

.qr svg {
  display: block;
  width: 100%;
  height: 100%;
}

.pw-layer {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: #f2f2f3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pw-input {
  width: 232px;
  height: 48px;
  border: 1px solid #e0e0e4;
  border-radius: 8px;
  background: #ffffff;
  text-align: center;
  font-size: 17px;
  letter-spacing: 3px;
  color: var(--text);
  outline: none;
  padding: 0 8px;
  box-sizing: border-box;
}

/* ---------------- 错误页 ---------------- */

.page-blocked {
  background: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.blocked-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 24px;
}

.blocked-icon {
  width: 126px;
  height: 86px;
  color: #c0c0c4;
}

.blocked-text {
  margin: 0;
  color: #9a9a9a;
  font-size: 15px;
}

/* ---------------- 聊天页 ---------------- */

.page-chat {
  background: var(--bg);
  overflow: hidden;
}

.chat-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  height: 56px;
  height: calc(56px + env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  padding-top: env(safe-area-inset-top);
  background: var(--bar);
  border-bottom: 1px solid var(--line);
}

.chat-title {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 17px;
  font-weight: 500;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
}

.title-name {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.title-dots {
  flex: 0 0 auto;
  color: #9a9aa2;
  font-weight: 400;
  letter-spacing: 1px;
}

.top-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 7px;
}

.top-btn {
  height: 30px;
  padding: 0 10px;
  border: 1px solid #d9d9df;
  border-radius: 6px;
  background: #ffffff;
  color: #333333;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
}

.top-btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 6px 12px 16px;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  -webkit-overflow-scrolling: touch;
}

.time-label {
  align-self: center;
  margin: 10px 0 8px;
  font-size: 12px;
  line-height: 1;
  color: #9b9ba3;
  font-variant-numeric: tabular-nums;
}

.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
  max-width: 100%;
}

.msg-row.self {
  justify-content: flex-end;
}

.msg-wrap {
  display: flex;
  flex-direction: column;
  max-width: calc(72%);
  min-width: 0;
}

.msg-row.self .msg-wrap {
  align-items: flex-end;
}

.msg-bubble {
  padding: 9px 12px;
  border-radius: 8px;
  background: #ffffff;
  font-size: 15px;
  line-height: 1.5;
  color: #222222;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
}

.msg-row.self .msg-bubble {
  background: var(--bubble-self);
}

.msg-bubble.img {
  padding: 0;
  background: transparent;
  line-height: 0;
}

.msg-bubble.img img {
  display: block;
  max-width: 180px;
  max-height: 250px;
  width: auto;
  height: auto;
  border-radius: 8px;
  object-fit: cover;
  cursor: pointer;
}

.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
  background: #f7f7f9;
  border-top: 1px solid var(--line);
}

.composer-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: #f2f2f5;
  padding: 0 14px;
  font-size: 15px;
  color: #333333;
  outline: none;
}

.composer-input::placeholder {
  color: #b3b3bb;
}

.send-btn {
  flex: 0 0 auto;
  width: 62px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: var(--purple);
  color: #ffffff;
  font-size: 15px;
  line-height: 1;
}

/* ---------------- 头像菜单 ---------------- */

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

.me-menu {
  position: fixed;
  top: 62px;
  left: 8px;
  z-index: 41;
  width: 186px;
  padding: 12px;
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
}

.menu-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 10px;
  margin-bottom: 6px;
  border-bottom: 1px solid #f0f0f2;
}

.menu-name {
  font-size: 16px;
  line-height: 1;
  color: #1a1a1a;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-row {
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.menu-label {
  font-size: 14px;
  color: #333333;
}

.toggle {
  width: 42px;
  height: 24px;
  border: none;
  border-radius: 12px;
  padding: 2px;
  background: #d7d7dd;
  display: flex;
  align-items: center;
  transition: background 0.15s ease;
}

.toggle i {
  display: block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.15s ease;
}

.toggle[aria-pressed="true"] {
  background: var(--purple);
}

.toggle[aria-pressed="true"] i {
  transform: translateX(18px);
}

.menu-note {
  margin: 6px 0 8px;
  font-size: 11px;
  line-height: 1.4;
  color: #a2a2aa;
}

.menu-btn {
  width: 100%;
  height: 38px;
  margin-top: 8px;
  border: 1px solid #e3e3e8;
  border-radius: 6px;
  background: #ffffff;
  font-size: 14px;
  color: #5b6fa8;
}

.menu-btn.danger {
  color: #d9534f;
}

/* ---------------- 退出页 ---------------- */

/* ---------------- 聊天记录 ---------------- */

.history {
  position: fixed;
  inset: 0;
  z-index: 65;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.history-head {
  flex: 0 0 auto;
  height: 52px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.history-close {
  width: 48px;
  border: none;
  background: transparent;
  padding: 0;
  font-size: 14px;
  color: #666666;
  text-align: left;
}

.history-title {
  flex: 1 1 auto;
  text-align: center;
  font-size: 16px;
  font-weight: 500;
}

.history-holder {
  width: 48px;
}

.history-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 12px 16px;
  display: flex;
  flex-direction: column;
}

/* ---------------- 大图预览 ---------------- */

.viewer {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: #000000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.viewer-save {
  position: absolute;
  top: 18px;
  right: 18px;
  z-index: 71;
  padding: 6px 10px;
  color: #ffffff;
  font-size: 14px;
  text-decoration: none;
}

/* ---------------- 视频通话 ---------------- */

.call {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: #000000;
  color: #ffffff;
  overflow: hidden;
}

.call-outgoing,
.call-incoming {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 18vh;
  gap: 10px;
}

.call-name {
  font-size: 18px;
  font-weight: 500;
}

.call-tip {
  font-size: 14px;
  color: rgba(255, 255, 255, 0.66);
}

.call-round {
  width: 66px;
  height: 66px;
  border: none;
  border-radius: 50%;
  color: #ffffff;
  font-size: 14px;
  line-height: 1.2;
}

.call-round.hangup,
.call-round.reject {
  background: var(--danger);
}

.call-round.accept {
  background: #07c160;
}

.call-center-btn {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.call-btns {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 64px;
}

.call-incall {
  position: absolute;
  inset: 0;
  background: #111111;
}

.remote-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #111111;
  pointer-events: none;
}

.remote-fallback {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #1c1c1c;
}

.local-video {
  position: absolute;
  top: 76px;
  right: 12px;
  width: 100px;
  height: 140px;
  object-fit: cover;
  border-radius: 8px;
  background: #2a2a2a;
  z-index: 5;
  pointer-events: auto;
  touch-action: none;
  cursor: grab;
}

.local-video:active {
  cursor: grabbing;
}

.call-timer {
  position: absolute;
  top: 16px;
  left: 0;
  right: 0;
  z-index: 4;
  text-align: center;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.9);
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}

.call-tap-area {
  position: absolute;
  inset: 0;
  z-index: 3;
}

.call-bottom-btn {
  position: absolute;
  bottom: 56px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 4;
}

.call-toast {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 5;
  padding: 12px 18px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.16);
  font-size: 15px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ---------------- 提示条 ---------------- */

.chat-tip {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  z-index: 90;
  padding: 8px 14px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.72);
  color: #ffffff;
  font-size: 13px;
  white-space: nowrap;
}

/* ---------------- 管理后台 ---------------- */

.page-admin {
  background: #f5f6f8;
}

.admin-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
}

.admin-pw {
  width: 220px;
  height: 42px;
  border: 1px solid #dddddd;
  border-radius: 6px;
  background: #ffffff;
  padding: 0 12px;
  font-size: 18px;
  letter-spacing: 6px;
  outline: none;
}

.admin-pw.small {
  width: 160px;
  height: 36px;
  font-size: 16px;
  letter-spacing: 4px;
}

.admin-login-btn,
.admin-btn {
  height: 42px;
  padding: 0 18px;
  border: none;
  border-radius: 6px;
  background: var(--purple);
  color: #ffffff;
  font-size: 15px;
}

.admin-btn {
  height: 36px;
}

.admin-panel {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 20px 48px;
}

.admin-head h1 {
  margin: 0 0 18px;
  font-size: 22px;
  font-weight: 600;
}

.admin-card {
  background: #ffffff;
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.admin-card h2 {
  margin: 0 0 12px;
  font-size: 16px;
  font-weight: 600;
}

.admin-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.admin-label {
  font-size: 15px;
}

.admin-value {
  font-size: 14px;
  color: var(--muted);
  min-width: 24px;
}

.switch {
  width: 46px;
  height: 26px;
  border: none;
  border-radius: 13px;
  padding: 2px;
  background: #cfcfd4;
  display: flex;
  align-items: center;
  transition: background 0.15s ease;
}

.switch span {
  display: block;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  transition: transform 0.15s ease;
}

.switch[aria-pressed="true"] {
  background: var(--purple);
}

.switch[aria-pressed="true"] span {
  transform: translateX(20px);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.devices-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  white-space: nowrap;
}

.devices-table th,
.devices-table td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid #f0f0f2;
}

.devices-table th {
  color: var(--muted);
  font-weight: 500;
}

.devices-table td.time {
  font-variant-numeric: tabular-nums;
}

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  line-height: 1.5;
}

.tag.on {
  background: #eae6fd;
  color: #5a49cf;
}

.tag.off {
  background: #f2f2f4;
  color: #8a8a92;
}

.tag.bad {
  background: #fdecec;
  color: #d33b38;
}

.row-btn {
  height: 28px;
  padding: 0 10px;
  margin-right: 6px;
  border: 1px solid #d9d9df;
  border-radius: 4px;
  background: #ffffff;
  font-size: 12px;
  color: #333333;
}

.pw-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.admin-select {
  height: 36px;
  border: 1px solid #dddddd;
  border-radius: 6px;
  background: #ffffff;
  padding: 0 8px;
  font-size: 14px;
  outline: none;
}

.admin-msg {
  font-size: 13px;
  color: var(--purple);
}
