:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e3e8f0;
  --text: #1f2937;
  --text-2: #6b7280;
  --primary: #4f6ef7;
  --primary-2: #3b5bdb;
  --accent: #10b981;
  --danger: #ef4444;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(31, 41, 55, .06);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- 顶栏 ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #6c8bff, #4f6ef7);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 10px rgba(79, 110, 247, .3);
}
.brand h1 { font-size: 17px; font-weight: 700; letter-spacing: .2px; }
.sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }

.topbar-right { display: flex; align-items: center; gap: 14px; }

.conn-state {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; color: var(--text-2);
  background: var(--bg);
  padding: 7px 14px;
  border-radius: 20px;
}
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: #9ca3af;
  transition: background .25s;
}
.dot.on { background: var(--accent); box-shadow: 0 0 0 4px rgba(16, 185, 129, .15); }
.dot.err { background: var(--danger); box-shadow: 0 0 0 4px rgba(239, 68, 68, .15); }
.dot.busy { background: #f59e0b; box-shadow: 0 0 0 4px rgba(245, 158, 11, .15); }

/* ---------- 按钮 ---------- */
.btn {
  border: none; cursor: pointer;
  font-size: 13.5px; font-weight: 600;
  padding: 10px 20px;
  border-radius: 10px;
  transition: all .18s;
  font-family: inherit;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-connect {
  background: linear-gradient(135deg, #6c8bff, #4f6ef7);
  color: #fff;
  box-shadow: 0 4px 12px rgba(79, 110, 247, .3);
}
.btn-connect:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(79,110,247,.4); }
.btn-primary {
  background: linear-gradient(135deg, #6c8bff, #4f6ef7);
  color: #fff;
  box-shadow: 0 3px 10px rgba(79, 110, 247, .3);
}
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); }
.btn-stop {
  background: #fff; color: var(--danger);
  border: 1.5px solid #fecaca;
}
.btn-stop:hover:not(:disabled) { background: #fef2f2; }

/* ---------- 布局 ---------- */
.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  padding: 16px 24px;
  min-height: 0;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

/* ---------- 设置面板 ---------- */
.settings-panel { padding: 18px; overflow-y: auto; }
.panel-title { font-size: 14px; font-weight: 700; margin-bottom: 16px; }

.field { margin-bottom: 15px; }
.field label {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12.5px; color: var(--text-2);
  margin-bottom: 6px; font-weight: 500;
}
.val { color: var(--primary); font-weight: 700; font-variant-numeric: tabular-nums; }

select, textarea, input[type="range"] {
  width: 100%; font-family: inherit;
}
select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 13px;
  background: #fafbfe;
  color: var(--text);
  outline: none;
  cursor: pointer;
}
select:focus { border-color: var(--primary); }
textarea {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  font-size: 12.5px;
  resize: vertical;
  background: #fafbfe;
  outline: none;
  line-height: 1.6;
  color: var(--text);
}
textarea:focus { border-color: var(--primary); }

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 5px;
  border-radius: 3px;
  background: #e2e8f0;
  outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2.5px solid #fff;
  box-shadow: 0 1px 5px rgba(79, 110, 247, .4);
}

/* 预置脚本 */
.script-list { display: flex; flex-direction: column; gap: 7px; }
.script-btn {
  text-align: left;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #fafbfe;
  font-size: 12.5px;
  cursor: pointer;
  color: var(--text);
  transition: all .15s;
  font-family: inherit;
  display: flex; align-items: center; gap: 8px;
}
.script-btn:hover { border-color: var(--primary); background: #f3f6ff; }
.script-btn .icon { font-size: 15px; }
.script-btn .desc { color: var(--text-2); font-size: 11.5px; }

/* 知识库卡片 */
.kb-card {
  background: #f6f8ff;
  border: 1px solid #dbe3ff;
  border-radius: 10px;
  padding: 11px 13px;
}
.kb-name { font-size: 13px; font-weight: 700; color: var(--primary-2); margin-bottom: 5px; }
.kb-desc { font-size: 11.5px; color: var(--text-2); line-height: 1.7; }

/* ---------- 通话区 ---------- */
.call-panel {
  display: flex; flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.call-head {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.call-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #6c8bff, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
  box-shadow: 0 4px 10px rgba(139, 92, 246, .3);
}
.call-name { font-size: 15.5px; font-weight: 700; }
.call-meta { font-size: 12px; color: var(--text-2); margin-top: 3px; }

.call-metrics {
  margin-left: auto;
  display: flex; gap: 26px;
}
.metric { text-align: right; }
.metric-label { display: block; font-size: 11px; color: var(--text-2); margin-bottom: 3px; }
.metric-value {
  font-size: 16px; font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--primary);
}

/* 波形 */
.wave-wrap {
  padding: 10px 20px 4px;
  background: #fafbfe;
  border-bottom: 1px solid var(--border);
}
#wave { width: 100%; height: 56px; display: block; }

/* VAD 语音活动指示 */
.vad-row {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 6px;
}
.vad-label { font-size: 11px; color: var(--text-2); white-space: nowrap; font-weight: 600; }
.vad-bar {
  flex: 1; height: 7px;
  background: #e8ecf4;
  border-radius: 4px;
  overflow: hidden;
}
.vad-fill {
  height: 100%; width: 0;
  background: #d5dce8;
  border-radius: 4px;
  transition: width .12s ease-out, background .2s;
}
.vad-state { font-size: 11.5px; color: var(--primary); white-space: nowrap; min-width: 120px; text-align: right; }

/* 对话气泡 */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 200px;
}
.chat::-webkit-scrollbar { width: 6px; }
.chat::-webkit-scrollbar-thumb { background: #d5dce8; border-radius: 3px; }

.bubble { display: flex; flex-direction: column; max-width: 78%; }
.bubble.user { align-self: flex-end; align-items: flex-end; }
.bubble.bot { align-self: flex-start; align-items: flex-start; }

.bubble .who { font-size: 11px; color: var(--text-2); margin-bottom: 4px; }
.bubble .txt {
  padding: 10px 14px;
  border-radius: 13px;
  font-size: 13.5px;
  line-height: 1.65;
  word-break: break-word;
  white-space: pre-wrap;
}
.bubble.user .txt {
  background: linear-gradient(135deg, #6c8bff, #4f6ef7);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble.bot .txt {
  background: #f1f4fa;
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.bubble .foot { font-size: 10.5px; color: #9ca3af; margin-top: 4px; }

.empty-hint {
  margin: auto;
  text-align: center;
  color: #b3bccb;
  font-size: 13px;
  line-height: 2;
}
.empty-hint .big { font-size: 34px; display: block; margin-bottom: 6px; }

/* 输入区 */
.input-bar {
  border-top: 1px solid var(--border);
  padding: 14px 20px 16px;
  background: #fff;
}
.input-bar textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 11px 13px;
  font-size: 13.5px;
  resize: none;
  outline: none;
  background: #fafbfe;
  line-height: 1.6;
}
.input-bar textarea:focus { border-color: var(--primary); background: #fff; }
.input-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 10px;
}

/* ---------- 日志栏 ---------- */
.log-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 24px 14px;
}
.log-label { font-size: 12px; color: var(--text-2); font-weight: 600; white-space: nowrap; }
.log {
  flex: 1;
  font-size: 12.5px;
  line-height: 1.75;
  color: #4b5563;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 10px 14px;
  height: 170px;
  overflow-y: auto;
  font-family: "SF Mono", Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-all;
}
.log .ok { color: var(--accent); }
.log .err { color: var(--danger); }
.log .info { color: var(--primary); }

/* 响应式 */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .settings-panel { max-height: none; }
  .call-metrics { display: none; }
}
