/* ============================================================
   微信对讲 - 全局样式
   适配范围：375px（手机 / 微信浏览器）~ 1920px（桌面浏览器）
   识别微信 UA 时通过 body 上的 .wechat 类隐藏非必要元素
   ============================================================ */

/* ---------- 设计变量 ---------- */
:root {
  --wx-green: #07c160;            /* 微信品牌绿 */
  --wx-green-dark: #06ad56;
  --wx-green-light: #e8f8ef;
  --bg: #f5f6f7;
  --panel-bg: #ffffff;
  --text-main: #1f2329;
  --text-sub: #8a919f;
  --border: #e5e6eb;
  --danger: #fa5151;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --radius: 12px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text-main);
  font-size: 15px;
}

body { line-height: 1.5; }

button, input { font-family: inherit; }

/* ---------- 顶部栏 ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--wx-green);
  color: #fff;
  padding-top: var(--safe-top);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}
.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 600; }
.brand-icon { font-size: 20px; }
.header-user { display: flex; align-items: center; gap: 8px; }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; border: 2px solid rgba(255, 255, 255, 0.6); }
.user-nickname { font-size: 14px; max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- 布局 ---------- */
.app-main { max-width: 960px; margin: 0 auto; padding: 16px; }
.view { width: 100%; }

/* ---------- 通用组件 ---------- */
.panel { background: var(--panel-bg); border-radius: var(--radius); padding: 20px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05); }
.panel-title { font-size: 18px; margin-bottom: 16px; }
.section-title { font-size: 15px; margin: 20px 0 10px; color: var(--text-sub); font-weight: 500; }
.auto-refresh-hint { font-size: 11px; color: var(--text-sub); margin: -6px 0 8px; }
.hidden { display: none !important; }

.btn {
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 15px;
  transition: opacity 0.15s, transform 0.05s;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--wx-green); color: #fff; padding: 10px 18px; }
.btn-primary:active { background: var(--wx-green-dark); }
.btn-secondary { background: #f2f3f5; color: var(--text-main); padding: 10px 18px; }
.btn-danger { background: var(--danger); color: #fff; padding: 10px 18px; }
.btn-ghost { background: transparent; border: 1px solid rgba(255, 255, 255, 0.6); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-lg { padding: 14px 20px; font-size: 17px; }
.btn-block { width: 100%; }

/* 触控最小尺寸：不小于 44px（微信触控友好） */
.btn { min-height: 44px; }
.btn-sm { min-height: 32px; }

.input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  min-height: 44px;
  background: #fff;
}
.input:focus { border-color: var(--wx-green); }

/* ---------- 登录视图 ---------- */
.login-panel { max-width: 420px; margin: 40px auto; text-align: center; }
.login-hero { margin-bottom: 24px; }
.login-logo { font-size: 56px; }
.login-hero h1 { font-size: 24px; margin: 8px 0 4px; }
.login-sub { color: var(--text-sub); font-size: 13px; }
.wx-login-box { margin-bottom: 8px; }
.login-tip { font-size: 12px; color: var(--text-sub); margin-top: 10px; }
.guest-form { display: flex; flex-direction: column; gap: 10px; }
.divider { display: flex; align-items: center; color: var(--text-sub); font-size: 13px; margin: 18px 0 14px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.divider span { padding: 0 12px; }

/* ---------- 房间视图 ---------- */
.create-room { display: flex; gap: 10px; }
.create-room .input { flex: 1; }
.room-tips { margin-top: 12px; font-size: 13px; color: var(--text-sub); }
.mic-status { margin-top: 10px; padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.mic-status.ok { background: var(--wx-green-light); color: var(--wx-green-dark); }
.mic-status.err { background: #fdecec; color: var(--danger); }

.room-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: #fafbfc;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.room-item-info { min-width: 0; }
.room-item-name { font-size: 16px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-item-meta { font-size: 12px; color: var(--text-sub); margin-top: 2px; }
.room-item .btn { flex-shrink: 0; }

/* ---------- 对讲视图 ---------- */
.talk-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.talk-header > div:first-child { flex: 1; min-width: 0; }
.talk-header > div:first-child h2,
.talk-header > div:first-child > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.talk-room-name { font-size: 20px; }
.talk-room-meta { font-size: 13px; color: var(--text-sub); }
.talk-header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.conn-status { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap; }
.conn-status.ok { color: var(--wx-green); border-color: var(--wx-green); background: var(--wx-green-light); }
.conn-status.warn { color: #b88230; border-color: #f0c98a; background: #fdf6ec; }
.conn-status.err { color: var(--danger); border-color: #f3b6b6; background: #fef0f0; }
.conn-status.neutral { color: var(--text-sub); border-color: var(--border); background: #f5f5f5; }

.member-list { list-style: none; display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.member-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.15s, background 0.15s;
}
.member-item.me { border-color: var(--wx-green); background: var(--wx-green-light); }
.member-item.speaking { border-color: var(--wx-green); background: #d6f5e3; }
.member-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--border);
  flex-shrink: 0;
}
.member-avatar.fallback { display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600; }
.member-info { flex: 1; min-width: 0; }
.member-name { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-tag { font-size: 12px; color: var(--text-sub); }
.member-status { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--text-sub); flex-shrink: 0; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #c0c4cc; }
.status-dot.speaking { background: var(--wx-green); box-shadow: 0 0 6px var(--wx-green); animation: pulse 0.8s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.member-kick { color: var(--danger); background: #fdecec; border: none; cursor: pointer; font-size: 12px; min-height: 32px; padding: 4px 10px; border-radius: 6px; }
.member-kick:active { opacity: 0.7; }

/* 按住说话按钮 */
.talk-controls { position: sticky; bottom: var(--safe-bottom); padding: 4px 0 8px; background: var(--bg); }
.push-to-talk-wrap { text-align: center; }
.btn-push-to-talk {
  width: 100%;
  max-width: 420px;
  height: 88px;
  border: none;
  border-radius: 16px;
  background: var(--wx-green);
  color: #fff;
  font-size: 18px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
  transition: background 0.1s, transform 0.05s;
}
.btn-push-to-talk.pressed { background: var(--danger); transform: scale(0.98); }
.btn-push-to-talk:disabled { background: #c0c4cc; cursor: not-allowed; }
.ptt-icon { font-size: 28px; }
.ptt-hint { font-size: 12px; color: var(--text-sub); margin-top: 8px; }
.broadcast-hint { margin-top: 8px; font-size: 12px; color: #e6a23c; }

/* ---------- Toast 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  top: 20%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 999;
  max-width: 80vw;
  text-align: center;
}

/* ---------- 权限引导弹窗 ---------- */
.modal-mask {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal {
  background: #fff;
  border-radius: var(--radius);
  width: 100%;
  max-width: 420px;
  padding: 20px;
  max-height: 80vh;
  overflow-y: auto;
}
.modal h3 { font-size: 17px; margin-bottom: 12px; }
.modal-body { font-size: 14px; color: var(--text-main); }
.modal-body ol { padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }
.modal-body li { line-height: 1.6; }
.modal-body code { background: #f2f3f5; padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.modal-actions { margin-top: 16px; text-align: right; }

/* ============================================================
   微信 UA 特化样式（body.wechat 时生效）
   ============================================================ */
body.wechat .room-tips,
body.wechat .login-tip { display: none; }   /* 微信内隐藏非必要说明 */
body.wechat .btn,
body.wechat .input,
body.wechat .btn-push-to-talk { border-radius: 22px; }   /* 微信更圆润的风格 */
body.wechat .btn-push-to-talk { border-radius: 24px; }
body.wechat .app-header { padding-bottom: 2px; }

/* ============================================================
   响应式：桌面端（≥ 768px）
   ============================================================ */
@media (min-width: 768px) {
  .app-main { padding: 24px; }
  .member-list { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .member-item { padding: 14px 16px; }
  .login-panel { margin-top: 80px; }
  .btn-push-to-talk { height: 96px; font-size: 20px; }
}

/* 桌面端大屏（≥ 1440px）自动加宽容器，利用更多横向空间 */
@media (min-width: 1440px) {
  .app-main { max-width: 1200px; }
}

/* ============================================================
   新功能样式：偏好工具条 / 最近访问 / 网络质量 / 听筒扬声器 / 夜间模式
   ============================================================ */

/* ---------- 偏好工具条（房间列表页） ---------- */
.room-tools { display: flex; align-items: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.room-tools-label { font-size: 12px; color: var(--text-sub); }
.btn-plain { background: #f2f3f5; color: var(--text-main); min-height: 32px; padding: 4px 12px; font-size: 13px; }
.btn-plain:active { opacity: 0.7; }

/* ---------- 最近访问房间 ---------- */
.recent-rooms { display: flex; flex-direction: column; gap: 8px; }
.recent-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: var(--wx-green-light);
  border: 1px solid rgba(7, 193, 96, 0.35);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
  min-height: 44px;
}
.recent-chip:active { opacity: 0.75; }
.recent-chip-name { font-size: 14px; font-weight: 500; color: var(--wx-green-dark); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recent-chip-time { font-size: 12px; color: var(--text-sub); flex-shrink: 0; }

/* ---------- 网络质量徽标（对讲页顶栏） ---------- */
.net-status { font-size: 11px; padding: 2px 8px; border-radius: 999px; border: 1px solid transparent; white-space: nowrap; }
.net-status.ok { color: var(--wx-green); border-color: var(--wx-green); background: var(--wx-green-light); }
.net-status.warn { color: #b88230; border-color: #f0c98a; background: #fdf6ec; }
.net-status.err { color: var(--danger); border-color: #f3b6b6; background: #fef0f0; }
.net-status.neutral { color: var(--text-sub); border-color: var(--border); background: #f5f5f5; }

/* ---------- 成员最后活跃文本 ---------- */
.member-tag .active-now { color: var(--wx-green); font-weight: 500; }

/* ============================================================
   夜间模式（html[data-theme="dark"] 时生效）
   ============================================================ */
html[data-theme="dark"] {
  --bg: #111418;
  --panel-bg: #1b2129;
  --text-main: #e6e9ee;
  --text-sub: #8b96a5;
  --border: #2b333e;
  --wx-green-light: #1d3a2c;
  --wx-green-dark: #19c87c;
}
html[data-theme="dark"] .app-header { background: #0e8c52; }
html[data-theme="dark"] .room-item,
html[data-theme="dark"] .member-item,
html[data-theme="dark"] .modal { background: #1b2129; }
html[data-theme="dark"] .member-item.speaking { background: #1d3a2c; }
html[data-theme="dark"] .member-item.me { background: #16301f; }
html[data-theme="dark"] .btn-secondary,
html[data-theme="dark"] .btn-plain,
html[data-theme="dark"] .modal-body code,
html[data-theme="dark"] .input { background: #2b333e; color: var(--text-main); }
html[data-theme="dark"] .input { border-color: #3a4553; }
html[data-theme="dark"] .conn-status.neutral,
html[data-theme="dark"] .net-status.neutral { background: #2b333e; border-color: #3a4553; }
html[data-theme="dark"] .divider::before,
html[data-theme="dark"] .divider::after { background: #2b333e; }
html[data-theme="dark"] .recent-chip { background: #16301f; }
html[data-theme="dark"] .mic-status.ok,
html[data-theme="dark"] .conn-status.ok,
html[data-theme="dark"] .net-status.ok { color: #19c87c; border-color: #19c87c; background: #1d3a2c; }

/* ===== 优化：按房号加入 / 复制房间号 / 可点击重连 / 等待中 ===== */
.join-room { display: flex; gap: 8px; margin-top: 10px; }
.join-room .input { flex: 1; min-width: 0; }
.conn-status.clickable { cursor: pointer; text-decoration: underline dotted; }
.conn-status.clickable:hover { opacity: .8; }
.tag-waiting { font-style: normal; opacity: .7; }
