/* ── Tokens ── */
:root {
  --brand: #0f4c81;
  --brand-light: #e8f1fb;
  --brand-mid: #2d7dd2;
  --accent: #00c48c;
  --accent-soft: #e0f9f1;
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --surface-3: #eef1f5;
  --border: rgba(0, 0, 0, 0.09);
  --border-strong: rgba(0, 0, 0, 0.18);
  --text: #0d1b2a;
  --text-2: #4a5568;
  --text-3: #8a9ab0;
  --danger: #e53935;
  --danger-soft: #fdecea;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 22px;
  --shadow-sm: 0 2px 12px rgba(0, 0, 0, 0.08);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.18);
  font-family: "DM Sans", ui-sans-serif, system-ui, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
body {
  background: #e8edf2;
  min-height: 100dvh;
  overflow: hidden;
}
button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
}
input {
  font: inherit;
}

/* ══════════════════════════════════════
   LOBBY
══════════════════════════════════════ */
.lobby {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition:
    opacity 0.4s ease,
    transform 0.4s ease;
}
.lobby.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.96);
}

.lobby-bg {
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #0f2340 0%, #1a4a7a 45%, #0e6b55 100%);
}

.lobby-content {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 48px 40px;
  max-width: 480px;
  width: 100%;
}

.lobby-badge {
  display: inline-block;
  background: rgba(255, 255, 255, 0.15);
  color: rgba(255, 255, 255, 0.9);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 6px 16px;
  margin-bottom: 28px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.lobby-title {
  font-family: "DM Serif Display", Georgia, serif;
  font-size: clamp(36px, 6vw, 52px);
  color: #ffffff;
  line-height: 1.1;
  margin-bottom: 16px;
}
.lobby-title em {
  font-style: italic;
  color: #4dd9ac;
}

.lobby-sub {
  color: rgba(255, 255, 255, 0.7);
  font-size: 16px;
  line-height: 1.6;
  margin-bottom: 40px;
}

.lobby-avatar {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 36px;
}

.lobby-ring {
  position: absolute;
  border-radius: 50%;
  border: 2px solid rgba(77, 217, 172, 0.3);
  animation: pulse-ring 2.5s ease-out infinite;
}
.lobby-ring--1 {
  inset: -14px;
  animation-delay: 0s;
}
.lobby-ring--2 {
  inset: -28px;
  animation-delay: 0.7s;
}

@keyframes pulse-ring {
  0% {
    opacity: 0.7;
    transform: scale(0.9);
  }
  70% {
    opacity: 0;
    transform: scale(1.05);
  }
  100% {
    opacity: 0;
  }
}

.lobby-avatar-face {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: linear-gradient(145deg, #1e5fa0, #0e3d6e);
  border: 3px solid rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 600;
  color: #ffffff;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.lobby-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
}

.byok-input {
  width: min(320px, 100%);
  min-height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  outline: none;
  padding: 0 18px;
}

.byok-input::placeholder {
  color: rgba(255, 255, 255, 0.58);
}

.btn-primary {
  background: #00c48c;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  border-radius: 999px;
  padding: 14px 40px;
  transition:
    background 0.2s,
    transform 0.15s,
    box-shadow 0.2s;
  box-shadow: 0 4px 20px rgba(0, 196, 140, 0.4);
  min-width: 220px;
}
.btn-primary:hover {
  background: #00b07d;
  transform: translateY(-1px);
  box-shadow: 0 6px 28px rgba(0, 196, 140, 0.5);
}
.btn-primary:active {
  transform: translateY(0);
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.1);
  color: rgba(255, 255, 255, 0.7);
  font-size: 14px;
  border-radius: 999px;
  padding: 10px 28px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  transition: background 0.2s;
  min-width: 120px;
}
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.18);
}
.btn-ghost:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.lobby-hint {
  color: rgba(255, 255, 255, 0.4);
  font-size: 13px;
}

/* ══════════════════════════════════════
   CALL SCREEN
══════════════════════════════════════ */
.call-screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: #f8fafb;
  z-index: 5;
}
.call-screen[hidden] {
  display: none;
}

/* Top bar */
.call-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.95) 60%,
    rgba(255, 255, 255, 0)
  );
}

.call-agent-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.call-agent-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #ccc;
  transition: background 0.4s;
}
.call-agent-dot.live {
  background: #00c48c;
  box-shadow: 0 0 0 3px rgba(0, 196, 140, 0.2);
}

.call-agent-name {
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
}
.call-agent-title {
  font-size: 12px;
  color: var(--text-3);
}

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

.call-stage-badge {
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 4px 12px;
  border: 1px solid var(--border);
  transition: all 0.3s;
}
.call-stage-badge.active {
  background: var(--accent-soft);
  color: #00825e;
  border-color: rgba(0, 196, 140, 0.25);
}

.btn-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  transition: background 0.2s;
}
.btn-icon:hover {
  background: var(--surface-2);
}

/* Call stage — agent video area */
.call-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding-top: 68px;
  padding-bottom: 200px; /* leaves room for panel + controls */
}

.call-video-wrap {
  position: relative;
  width: min(480px, 90vw);
  aspect-ratio: 9/11;
  border-radius: var(--radius-lg);
  background: #ffffff;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.call-avatar-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
}
.call-avatar-initials {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: linear-gradient(145deg, #1e5fa0, #0e3d6e);
  color: #fff;
  font-size: 36px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 28px rgba(15, 76, 129, 0.3);
}

.call-connecting-dots {
  display: flex;
  gap: 8px;
}
.call-connecting-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: bounce-dot 1.2s infinite ease-in-out;
}
.call-connecting-dots span:nth-child(2) {
  animation-delay: 0.2s;
}
.call-connecting-dots span:nth-child(3) {
  animation-delay: 0.4s;
}
.call-connecting-dots.hidden {
  display: none;
}

@keyframes bounce-dot {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  40% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

.call-video {
  position: absolute;
  inset: 0;
}
.call-video video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* Mic level indicator */
.call-mic-indicator {
  position: absolute;
  bottom: calc(200px + 24px); /* above panel */
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  color: var(--text-2);
  font-size: 12px;
  backdrop-filter: blur(8px);
  z-index: 10;
}
.call-mic-bar {
  width: 80px;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.call-mic-bar span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #f3af3d, #e53935);
  transition: width 100ms linear;
  width: 0%;
}

/* ── Floating chat bubbles ── */
.call-chat {
  position: absolute;
  inset: 0;
  top: 68px;
  bottom: 200px;
  pointer-events: none;
  display: flex;
  align-items: flex-end;
  padding: 0 0 24px;
  overflow: hidden;
}

.call-chat-inner {
  width: 100%;
  max-height: 100%;
  overflow-y: auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: all;
  scrollbar-width: none;
}
.call-chat-inner::-webkit-scrollbar {
  display: none;
}

.bubble {
  max-width: min(360px, 72vw);
  padding: 11px 15px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  box-shadow: var(--shadow-sm);
}
.bubble p {
  margin: 0;
}
.bubble strong {
  display: block;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.6;
}

.bubble--agent {
  background: #ffffff;
  color: var(--text);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 5px;
}
.bubble--agent strong {
  color: var(--brand);
}

.bubble--user {
  background: var(--brand);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 5px;
}
.bubble--user strong {
  color: rgba(255, 255, 255, 0.7);
}

.bubble--tool {
  background: #fffbe6;
  border: 1px solid #f3d55a;
  color: #6b4f00;
  align-self: flex-start;
  border-bottom-left-radius: 5px;
}
.bubble--tool strong {
  color: #8a6500;
}

/* ── Bottom panel (agent-driven) ── */
.call-panel {
  position: absolute;
  bottom: 80px; /* above controls bar */
  left: 0;
  right: 0;
  background: #ffffff;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -4px 40px rgba(0, 0, 0, 0.1);
  z-index: 15;
  overflow: hidden;
  max-height: 60vh;
  display: flex;
  flex-direction: column;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}
.call-panel.collapsed {
  transform: translateY(calc(100% - 52px));
}

.call-panel-handle {
  width: 40px;
  height: 4px;
  background: #d1d9e0;
  border-radius: 999px;
  margin: 12px auto 0;
  cursor: pointer;
  flex-shrink: 0;
}

.call-panel-tabs {
  display: flex;
  gap: 4px;
  padding: 10px 16px 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.panel-tab {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-3);
  border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent;
  transition:
    color 0.2s,
    border-color 0.2s;
}
.panel-tab--active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.panel-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

/* Plan cards */
.plan-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.plan-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 16px;
  color: var(--text-3);
  font-size: 14px;
  text-align: center;
}

.plan-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  transition:
    border-color 0.2s,
    box-shadow 0.2s;
}
.plan-card:hover {
  border-color: var(--brand-mid);
  box-shadow: var(--shadow-sm);
}
.plan-card strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}
.plan-card p {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.5;
}
.plan-card .plan-price {
  font-size: 12px;
  font-weight: 600;
  color: var(--brand);
  margin-top: 6px;
}

/* Live updates */
.live-updates {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.live-updates:empty {
  display: none;
}
.update-pill {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
}
.update-pill strong {
  color: var(--brand);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.update-pill span {
  color: var(--text-2);
  text-align: right;
}

/* Lead form */
.lead-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.field label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.field input {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
  background: var(--surface-2);
  outline: none;
}
.field input:focus {
  border-color: var(--brand-mid);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(45, 125, 210, 0.12);
}

/* Demo controls */
.demo-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  margin-bottom: 10px;
}
.demo-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}
.btn-demo {
  display: flex;
  align-items: center;
  gap: 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  transition:
    background 0.15s,
    border-color 0.15s;
}
.btn-demo:hover {
  background: var(--brand-light);
  border-color: var(--brand-mid);
  color: var(--brand);
}
.btn-demo:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Session info */
.session-info {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.session-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.session-key {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-3);
  width: 80px;
  flex-shrink: 0;
}
.session-val {
  font-size: 12px;
  color: var(--text-2);
  font-family: ui-monospace, Menlo, monospace;
  background: none;
  border: none;
  outline: none;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.state-debug summary {
  font-size: 12px;
  color: var(--text-3);
  cursor: pointer;
  margin-bottom: 8px;
}
.state-debug pre {
  background: #101820;
  border-radius: 8px;
  color: #b8cfe0;
  font-size: 11px;
  padding: 12px;
  max-height: 200px;
  overflow: auto;
  white-space: pre-wrap;
}

/* ── Bottom call controls bar ── */
.call-controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 80px;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 20;
  padding: 0 24px;
}

.ctrl-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
  flex-shrink: 0;
}

.ctrl-btn--mic {
  width: 52px;
  height: 52px;
  background: var(--surface-3);
  color: var(--text);
  border: 1px solid var(--border-strong);
}
.ctrl-btn--mic:hover {
  background: var(--surface-2);
}
.ctrl-btn--mic.muted {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(229, 57, 53, 0.2);
}
.ctrl-btn--mic:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ctrl-btn--join {
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  padding: 0 22px;
  height: 52px;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(15, 76, 129, 0.3);
  display: flex;
  align-items: center;
}
.ctrl-btn--join:hover {
  background: #0d4372;
}
.ctrl-btn--join:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ctrl-btn--end {
  width: 52px;
  height: 52px;
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 16px rgba(229, 57, 53, 0.35);
}
.ctrl-btn--end:hover {
  background: #c62828;
}
.ctrl-btn--end:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.call-status {
  font-size: 12px;
  color: var(--text-3);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 8px;
  white-space: nowrap;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .call-video-wrap {
    width: 92vw;
    aspect-ratio: 3/4;
  }
  .call-panel {
    max-height: 55vh;
  }
  .ctrl-btn--join {
    padding: 0 16px;
    font-size: 13px;
  }
  .bubble {
    max-width: 88vw;
  }
}
