/* ============================================================
   webclient2 — 设计系统（亮色主题，index.html 与 phone.html 共用）
   ============================================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #f4f6fb;
  --bg2: #eef1f8;
  --card: rgba(255, 255, 255, .92);
  --card-solid: #ffffff;
  --line: #e2e8f2;
  --line-soft: rgba(15, 23, 42, .08);
  --text: #1a2438;
  --muted: #64748b;
  --accent: #2f6bff;
  --accent2: #7c5cff;
  --green: #0f9d6e;
  --red: #e5484d;
  --amber: #d97706;
  --radius: 14px;
  --shadow: 0 10px 30px rgba(15, 23, 42, .08);
}
html, body {
  height: 100%;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(110% 80% at 15% -10%, rgba(47, 107, 255, .10) 0%, transparent 55%),
    radial-gradient(110% 80% at 90% 0%, rgba(124, 92, 255, .08) 0%, transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #c7d2e0; border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- 通用控件 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  cursor: pointer; border: 1px solid transparent; border-radius: 10px;
  font-size: 13px; font-weight: 500; padding: 9px 16px; color: #fff;
  background: var(--accent); transition: opacity .15s, transform .06s, box-shadow .15s;
  user-select: none; white-space: nowrap;
}
.btn:hover { opacity: .92; box-shadow: 0 4px 12px rgba(47,107,255,.22); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }
.btn.primary { background: linear-gradient(135deg, var(--accent), #2b56c9); box-shadow: 0 4px 14px rgba(47,107,255,.25); }
.btn.ghost { background: #eef1f7; color: var(--text); border-color: var(--line); }
.btn.danger { background: linear-gradient(135deg, #ef5350, #d32f2f); }
.btn.sm { padding: 6px 11px; font-size: 12px; border-radius: 8px; }
.btn.round { border-radius: 999px; }

input, select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; color: var(--text); font-size: 13px; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,107,255,.14); }
textarea { resize: vertical; font-family: "SF Mono", Consolas, Menlo, monospace; font-size: 12px; }
label { font-size: 11px; color: var(--muted); display: block; margin: 10px 0 4px; letter-spacing: .4px; font-weight: 500; }

.badge {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px;
  border-radius: 999px; font-size: 12px; background: #eef1f7; color: var(--muted); font-weight: 500;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.on { background: rgba(15,157,110,.12); color: var(--green); }
.badge.speaking { background: rgba(229,72,77,.1); color: var(--red); }
.badge.listening { background: rgba(124,92,255,.12); color: #6d3ff0; }

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex; align-items: center; gap: 14px; padding: 14px 22px;
  position: sticky; top: 0; z-index: 20;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; font-weight: 700; letter-spacing: .3px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 17px; background: linear-gradient(135deg, var(--accent), var(--accent2));
  box-shadow: 0 4px 12px rgba(47,107,255,.3);
}
.brand small { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 2px; }
.topbar .spacer { flex: 1; }
.topbar .status-pill { font-size: 13px; color: var(--muted); padding: 6px 14px; border-radius: 999px; background: #eef1f7; }
.topbar .actions { display: flex; gap: 8px; }

/* ---------- Device-ID 冲突提示 ---------- */
.kick-warn {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  max-width: 1280px; margin: 14px auto 0; padding: 12px 18px;
  background: rgba(229, 72, 77, .07); border: 1px solid rgba(229, 72, 77, .28);
  border-left: 4px solid var(--red); border-radius: var(--radius);
}
.kick-warn[hidden] { display: none; }
.kick-warn-text { flex: 1; min-width: 260px; font-size: 13px; line-height: 1.7; color: var(--text); }
.kick-warn-text b { color: var(--red); }
.kick-warn-text code {
  font-family: ui-monospace, monospace; font-size: 12px;
  background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 1px 6px;
}
.kick-warn-actions { display: flex; gap: 8px; }

/* ---------- 主布局 ---------- */
.app { max-width: 1280px; margin: 0 auto; padding: 18px 22px 26px; }
.grid-main { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .grid-main { grid-template-columns: 1fr; } }

/* ---------- 卡片 ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); backdrop-filter: blur(6px);
}
.card + .card { margin-top: 14px; }
.card-title {
  display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600;
  color: #3d4b66; margin-bottom: 4px; letter-spacing: .3px;
}
.card-title .ico { opacity: .8; }

/* ---------- 设备卡 ---------- */
.device-name { font-size: 20px; font-weight: 700; margin-bottom: 2px; }
.device-id { font-size: 12px; color: var(--muted); font-family: monospace; margin-bottom: 14px; word-break: break-all; }
.kv { font-size: 12px; color: var(--muted); line-height: 1.9; }
.kv b { color: #2a3752; font-weight: 600; }

/* 麦克风 */
.mic-wrap { display: flex; flex-direction: column; align-items: center; padding: 6px 0 12px; }
.mic-btn {
  width: 92px; height: 92px; border-radius: 50%; border: none; cursor: pointer; user-select: none;
  display: flex; align-items: center; justify-content: center; font-size: 34px;
  background: linear-gradient(145deg, #eef2f9, #dbe3f0); color: #1a2438;
  box-shadow: 0 8px 24px rgba(30, 41, 59, .14), inset 0 1px 0 rgba(255,255,255,.9);
  transition: transform .08s, box-shadow .2s, background .2s; position: relative;
}
.mic-btn:active { transform: scale(.94); }
.mic-btn.recording { background: linear-gradient(145deg, #ef5350, #dc2626); color: #fff; box-shadow: 0 0 34px rgba(229,72,77,.45); animation: pulse-red 1.4s ease-out infinite; }
.mic-btn.listening { background: linear-gradient(145deg, #8b5cf6, #6d28d9); color: #fff; box-shadow: 0 0 34px rgba(124,92,255,.45); animation: pulse-violet 1.4s ease-out infinite; }
@keyframes pulse-red { 0% { box-shadow: 0 0 22px rgba(229,72,77,.4); } 50% { box-shadow: 0 0 42px rgba(229,72,77,.65); } 100% { box-shadow: 0 0 22px rgba(229,72,77,.4); } }
@keyframes pulse-violet { 0% { box-shadow: 0 0 22px rgba(124,92,255,.4); } 50% { box-shadow: 0 0 42px rgba(124,92,255,.65); } 100% { box-shadow: 0 0 22px rgba(124,92,255,.4); } }
.mic-hint { font-size: 11px; color: var(--muted); text-align: center; line-height: 1.7; }
#level { height: 5px; background: #e2e8f2; border-radius: 3px; overflow: hidden; margin: 10px 0 4px; }
#levelBar { height: 100%; width: 0%; background: linear-gradient(90deg, #10b981, #eab308, #ef4444); transition: width .06s linear; }

/* 快捷操作 */
.op-row { display: flex; gap: 8px; margin-top: 10px; }
.op-row .btn { flex: 1; }

/* ---------- 对话区 ---------- */
.chat-card { display: flex; flex-direction: column; min-height: 520px; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding-bottom: 12px;
  border-bottom: 1px solid var(--line-soft);
}
.chat-area { flex: 1; overflow-y: auto; padding: 16px 4px; display: flex; flex-direction: column; gap: 10px; }
.bubble {
  max-width: 82%; padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.6;
  white-space: pre-wrap; word-break: break-word; animation: fadeIn .22s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; } }
.bubble.user { align-self: flex-end; background: linear-gradient(135deg, #2f6bff, #2552c8); color: #fff; border-bottom-right-radius: 5px; }
.bubble.ai { align-self: flex-start; background: #eef2f9; border-bottom-left-radius: 5px; }
.bubble.sys { align-self: center; background: none; color: var(--muted); font-size: 12px; }
.chat-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 60px 20px; }
.chat-empty .big { font-size: 40px; display: block; margin-bottom: 12px; opacity: .6; }

/* ---------- 调试面板 ---------- */
.debug-panel {
  margin-top: 16px; background: var(--card-solid); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.debug-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px;
  cursor: pointer; user-select: none; background: #f6f8fc;
}
.debug-head:hover { background: #f0f3f9; }
.debug-title { font-size: 13px; font-weight: 600; color: #3d4b66; display: flex; align-items: center; gap: 8px; }
.debug-title .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.debug-tabs { display: flex; gap: 4px; margin-left: 8px; }
.debug-tab {
  padding: 4px 11px; border-radius: 999px; font-size: 11px; color: var(--muted);
  background: #e9edf5; cursor: pointer; border: none; transition: background .15s, color .15s; font-weight: 500;
}
.debug-tab:hover { color: var(--text); }
.debug-tab.active { background: var(--accent); color: #fff; }
.debug-count { margin-left: auto; font-size: 11px; color: var(--muted); }
.debug-toggle { transform: rotate(0deg); transition: transform .2s; }
.debug-panel.collapsed .debug-toggle { transform: rotate(-90deg); }
.debug-body { border-top: 1px solid var(--line-soft); }
.debug-panel.collapsed .debug-body { display: none; }
.debug-log {
  height: 240px; overflow-y: auto; padding: 10px 14px; font-family: "SF Mono", Consolas, Menlo, monospace; font-size: 12px;
  background: #fbfcfe;
}
.log-line { margin-bottom: 3px; line-height: 1.55; word-break: break-all; white-space: pre-wrap; }
.log-line .ts { color: #a3aec2; margin-right: 8px; user-select: none; }
.t-up { color: #1d4ed8; }   /* 上行 */
.t-down { color: #047857; } /* 下行 */
.t-sys { color: #64748b; }
.t-err { color: #dc2626; }
.debug-raw { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line-soft); }
.debug-raw input { font-family: "SF Mono", Consolas, Menlo, monospace; font-size: 12px; }
.debug-raw .btn { flex: none; }

/* ============================================================
   phone.html — 通话页（亮色）
   ============================================================ */
.phone { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.phone-back { width: auto; position: absolute; left: 14px; top: 14px; z-index: 5; }
.phone-head { position: relative; text-align: center; padding: 46px 20px 6px; }
.phone-avatar {
  width: 104px; height: 104px; border-radius: 50%; margin: 0 auto;
  background: linear-gradient(145deg, var(--accent), var(--accent2));
  display: flex; align-items: center; justify-content: center; font-size: 50px;
  box-shadow: 0 10px 44px rgba(47,107,255,.3), inset 0 1px 0 rgba(255,255,255,.25);
  position: relative;
}
.phone-avatar.small { width: 70px; height: 70px; font-size: 34px; }
.phone-avatar.ring::before, .phone-avatar.ring::after {
  content: ""; position: absolute; inset: -14px; border-radius: 50%;
  border: 2px solid rgba(15,157,110,.5); animation: ring 1.6s ease-out infinite;
}
.phone-avatar.ring::after { animation-delay: .8s; }
@keyframes ring { from { transform: scale(.9); opacity: .9; } to { transform: scale(1.3); opacity: 0; } }
.phone-name { font-size: 22px; font-weight: 700; margin-top: 14px; letter-spacing: 1px; }
.phone-state { font-size: 13px; color: var(--muted); margin-top: 6px; min-height: 20px; font-variant-numeric: tabular-nums; }
.phone-state.live { color: var(--green); }
.phone-captions {
  flex: 1; width: 100%; max-width: 520px; margin: 10px auto; padding: 8px 20px;
  overflow-y: auto; display: flex; flex-direction: column; gap: 6px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.phone-captions::-webkit-scrollbar { display: none; }
.cap {
  max-width: 88%; padding: 8px 13px; border-radius: 14px; font-size: 14px; line-height: 1.55;
  word-break: break-word; animation: fadeIn .22s ease;
}
.cap.user { align-self: flex-end; background: linear-gradient(135deg, #2f6bff, #2552c8); color: #fff; border-bottom-right-radius: 5px; }
.cap.ai { align-self: flex-start; background: #eef2f9; color: var(--text); border-bottom-left-radius: 5px; }
.cap.sys { align-self: center; background: none; color: var(--muted); font-size: 12px; }
.phone-controls {
  display: flex; gap: 34px; align-items: center; justify-content: center;
  padding: 22px 20px calc(26px + env(safe-area-inset-bottom)); margin-top: auto;
}
.ctrl-btn {
  width: 66px; height: 66px; border-radius: 50%; border: none; cursor: pointer; font-size: 26px;
  background: linear-gradient(145deg, #eef2f9, #dbe3f0); color: #1a2438;
  box-shadow: 0 6px 20px rgba(30, 41, 59, .12), inset 0 1px 0 rgba(255,255,255,.9);
  display: flex; align-items: center; justify-content: center; transition: transform .08s, box-shadow .2s;
}
.ctrl-btn:active { transform: scale(.92); }
.ctrl-btn.end { width: 74px; height: 74px; font-size: 30px; background: linear-gradient(145deg, #ef5350, #dc2626); color: #fff; }
.ctrl-btn.recording { background: linear-gradient(145deg, #ef5350, #dc2626); color: #fff; box-shadow: 0 0 30px rgba(229,72,77,.45); animation: pulse-red 1.4s ease-out infinite; }
.ctrl-btn.listening { background: linear-gradient(145deg, #8b5cf6, #6d28d9); color: #fff; box-shadow: 0 0 30px rgba(124,92,255,.45); animation: pulse-violet 1.4s ease-out infinite; }

/* ---------- 响应式 ---------- */
@media (max-width: 640px) {
  .app { padding: 10px; }
  .topbar { padding: 10px 12px; }
  .topbar .status-pill { display: none; }
  .brand small { display: none; }
  .chat-card { min-height: 420px; }
}