:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f0f3f9;
  --text: #182032;
  --muted: #5d6b82;
  --border: #e3e8f2;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #e11d48;
  --danger-hover: #be123c;
  --success: #059669;
  --warn: #d97706;
  --user-bubble: #2563eb;
  --ai-bubble: #ffffff;
  --shadow: 0 8px 28px rgba(24, 32, 50, 0.07);
  --radius: 18px;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* Banners */
.top-banner {
  background: #fff7ed;
  color: #9a3412;
  border-bottom: 1px solid #fed7aa;
  padding: 10px 16px;
  font-size: 13px;
  text-align: center;
}
.top-banner.error {
  background: #fff1f2;
  color: #9f1239;
  border-bottom-color: #fecdd3;
}

/* Login Screen */
.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 32px 26px;
  box-shadow: var(--shadow);
  text-align: center;
}
.logo-circle {
  width: 60px;
  height: 60px;
  margin: 0 auto 14px;
  border-radius: 18px;
  background: linear-gradient(135deg, #2563eb, #06b6d4);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  box-shadow: 0 10px 20px rgba(37, 99, 235, 0.25);
}
.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}
.login-card p {
  margin: 0 0 22px;
  color: var(--muted);
  font-size: 14px;
}
.input-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.text-input, .select-input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.text-input:focus, .select-input:focus {
  border-color: var(--primary);
}
.btn {
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .1s, background .15s, opacity .15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
}
.btn-ghost:hover:not(:disabled) { background: #e4eaf5; }
.btn-icon {
  padding: 8px 12px;
  font-size: 13px;
  border-radius: 10px;
}
.err-text {
  color: var(--danger);
  font-size: 13px;
  min-height: 20px;
  margin-top: 8px;
}

/* Main App Layout */
.app-shell {
  height: 100dvh;
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #94a3b8;
  flex-shrink: 0;
  transition: background .2s, box-shadow .2s;
}
.brand-dot.connecting { background: var(--warn); box-shadow: 0 0 0 4px rgba(217,119,6,0.18); }
.brand-dot.live { background: var(--success); box-shadow: 0 0 0 4px rgba(5,150,105,0.2); }
.brand-title {
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.stat-pill {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* Preset Strip */
.preset-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.preset-bar::-webkit-scrollbar { display: none; }
.chip {
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 7px 13px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all .15s;
}
.chip.active {
  background: #eff6ff;
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}
.chip:disabled { opacity: 0.5; cursor: not-allowed; }

/* Transcript Area */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.empty-state {
  margin: auto;
  text-align: center;
  max-width: 360px;
  color: var(--muted);
  padding: 20px 12px;
}
.empty-state h2 {
  margin: 0 0 8px;
  font-size: 18px;
  color: var(--text);
}
.empty-state p {
  margin: 0 0 12px;
  font-size: 14px;
}
.tip-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 13px;
  text-align: left;
  color: var(--muted);
}

.msg {
  max-width: 84%;
  padding: 11px 14px;
  border-radius: 16px;
  font-size: 15px;
  word-break: break-word;
  box-shadow: 0 2px 8px rgba(24, 32, 50, 0.04);
}
.msg.user {
  align-self: flex-end;
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--ai-bubble);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.system {
  align-self: center;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
  font-size: 12.5px;
  padding: 4px 10px;
  text-align: center;
}
.msg-role {
  font-size: 11px;
  opacity: 0.72;
  margin-bottom: 3px;
  font-weight: 600;
}
.blind-mode .msg.assistant .msg-text {
  filter: blur(6px);
  user-select: none;
  cursor: pointer;
  transition: filter .2s;
}
.blind-mode .msg.assistant.revealed .msg-text {
  filter: none;
  user-select: text;
}

/* Bottom Dock */
.dock {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.status-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  color: var(--muted);
}
.meter-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 18px;
}
.bar {
  width: 3.5px;
  height: 4px;
  border-radius: 99px;
  background: var(--primary);
  transition: height 60ms linear;
}
.bar.ai { background: var(--success); }

.controls-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
}
.call-btn {
  height: 52px;
  border-radius: 999px;
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.22);
}
.call-btn.danger {
  box-shadow: 0 8px 20px rgba(225, 29, 72, 0.22);
}
.sub-btn {
  height: 46px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 13px;
}
.sub-btn.active {
  background: #fee2e2;
  color: #b91c1c;
}
.sub-btn.blind-on {
  background: #e0e7ff;
  color: #3730a3;
}

/* Settings Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  padding: 0;
}
@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: 20px; }
}
.modal {
  width: 100%;
  max-width: 460px;
  max-height: 88dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 22px 22px 0 0;
  padding: 20px 20px calc(22px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 30px rgba(0,0,0,0.15);
}
@media (min-width: 640px) {
  .modal { border-radius: 22px; padding: 24px; }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-head h3 { margin: 0; font-size: 17px; }
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.field-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 5px;
}
.modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 18px;
}
