:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #1d4ed8;
  --accent-soft: #dbe5ff;
  --talk: #dc2626;
  --rx: #059669;
  --mine: #e8efff;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --panel: #111827; --ink: #e5e7eb; --muted: #94a3b8; --line: #1f2937;
    --accent: #6d8dff; --accent-soft: #1e2a4d; --mine: #1b2540;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-tap-highlight-color: transparent; }
#app { height: 100%; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.pad { padding: 16px; }
.link { color: var(--accent); text-decoration: none; display: inline-block; margin-top: 8px; }
.view { height: 100%; }

/* login */
#view-login, #view-start { display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 28px 22px; }
.login-card.center { text-align: center; }
.brand { font-size: 26px; font-weight: 700; display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.login-card.center .brand { justify-content: center; }
.brand-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--talk); box-shadow: 0 0 0 5px rgba(220,38,38,.18); }
.field { display: block; margin: 16px 0 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input { width: 100%; font: inherit; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); outline: none; }
input:focus { border-color: var(--accent); }
.row { display: flex; gap: 8px; }
.row input { flex: 1; min-width: 0; }
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 10px 14px; border-radius: 10px; cursor: pointer; white-space: nowrap; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; margin-top: 20px; padding: 13px; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.msg { min-height: 20px; color: var(--talk); font-size: 13px; margin: 10px 0 0; }
.msg.ok { color: var(--rx); }

/* main */
#view-main { display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me-name { font-weight: 600; }
.me-code { font-size: 13px; color: var(--muted); }
.me-code b { color: var(--ink); letter-spacing: 1px; }
.chip { font: inherit; font-size: 12px; border: 1px solid var(--line); background: transparent; color: var(--accent);
  border-radius: 999px; padding: 1px 8px; margin-left: 4px; cursor: pointer; }
.icon-btn { font: inherit; font-size: 22px; background: none; border: none; color: var(--ink); cursor: pointer; padding: 4px 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; background: #94a3b8; }
.dot.on { background: #10b981; }
.dot.off { background: #94a3b8; }
.dot.wait { background: #f59e0b; }

.layout { flex: 1; display: flex; min-height: 0; }
.pane { background: var(--panel); }
#pane-list { width: 320px; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.pane-actions { display: flex; gap: 6px; padding: 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.contact-list { overflow-y: auto; flex: 1; }
.contact { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--line); }
.contact:hover { background: var(--bg); }
.contact.active { background: var(--accent-soft); }
.avatar { width: 40px; height: 40px; border-radius: 12px; background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; position: relative; }
.avatar.group { border-radius: 50%; }
.avatar .dot { position: absolute; right: -2px; bottom: -2px; border: 2px solid var(--panel); width: 12px; height: 12px; }
.contact-main { flex: 1; min-width: 0; }
.contact-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-sub { font-size: 12px; color: var(--muted); }
.badge { background: var(--talk); color: #fff; border-radius: 999px; font-size: 12px; padding: 0 7px; min-width: 20px; text-align: center; }
.speaking { color: var(--rx); font-weight: 600; }

.conv { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.conv-head { display: flex; align-items: center; gap: 6px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.conv-title { font-weight: 700; }
.back { display: none; }
.history { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.item { max-width: 78%; align-self: flex-start; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 8px 12px; display: flex; align-items: center; gap: 10px; cursor: pointer; }
.item.mine { align-self: flex-end; background: var(--mine); }
.item .play { width: 30px; height: 30px; border-radius: 50%; border: none; background: var(--accent); color: #fff; font-size: 12px; flex: none; }
.item.playing .play { background: var(--rx); }
.item .meta { font-size: 12px; color: var(--muted); }
.item .who { font-size: 13px; font-weight: 600; }
.item.unheard .who::after { content: " ●"; color: var(--talk); }
.item.live { border-color: var(--rx); }

.ptt-wrap { padding: 14px 16px calc(18px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 10px;
  background: var(--panel); border-top: 1px solid var(--line); }
.ptt-status { font-size: 14px; color: var(--muted); min-height: 21px; text-align: center; }
.ptt-status.talk { color: var(--talk); font-weight: 600; }
.ptt-status.rx { color: var(--rx); font-weight: 600; }
.ptt { position: relative; width: 132px; height: 132px; border-radius: 50%; border: none; background: var(--accent); color: #fff;
  font: 600 17px/1 inherit; cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none;
  box-shadow: 0 8px 24px rgba(29,78,216,.25); transition: transform .08s, background .15s; }
.ptt:disabled { background: #94a3b8; box-shadow: none; cursor: default; }
.ptt.down { transform: scale(.94); background: var(--talk); box-shadow: 0 8px 28px rgba(220,38,38,.35); }
.ptt.busy { background: #f59e0b; }
.ptt-ring { position: absolute; inset: -8px; border-radius: 50%; border: 3px solid transparent; }
.ptt.down .ptt-ring { border-color: rgba(220,38,38,.35); animation: pulse 1s infinite; }
@keyframes pulse { 0% { transform: scale(1); opacity: 1; } 100% { transform: scale(1.15); opacity: 0; } }
.level { width: 160px; height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; }
#level-bar { height: 100%; width: 0; background: var(--talk); transition: width .05s; }

/* modal & toast */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.modal-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: var(--radius); padding: 20px; }
.modal-card h3 { margin: 0 0 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.setting { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.setting:last-child { border-bottom: none; }
.toast { position: fixed; left: 50%; bottom: 210px; transform: translateX(-50%); background: rgba(15,23,42,.92); color: #fff;
  padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 20; max-width: 86%; text-align: center; }
.big-code { font-size: 28px; font-weight: 700; letter-spacing: 3px; text-align: center; margin: 10px 0; }

@media (max-width: 720px) {
  #pane-list { width: 100%; border-right: none; }
  .layout.in-conv #pane-list { display: none; }
  .layout:not(.in-conv) #pane-conv { display: none; }
  .back { display: inline-block; }
}
