/* Xava voice agent. Scoped to #xva-root so it never touches the rest of the site. */
#xva-root {
  --xva-bg: #0a0a0a;
  --xva-elev: #111111;
  --xva-line: rgba(255, 255, 255, 0.1);
  --xva-text: #f5f5f5;
  --xva-muted: #9a9a9a;
  --xva-orange: #ff6a00;
  --xva-orange-2: #ff8a1f;
  --xva-orange-3: #ffb15c;
  --xva-user: rgba(255, 106, 0, 0.14);
  font-family: 'Inter', system-ui, sans-serif;
  color: var(--xva-text);
}
html.light #xva-root {
  --xva-bg: #ffffff;
  --xva-elev: #efeae4;
  --xva-line: rgba(0, 0, 0, 0.12);
  --xva-text: #151515;
  --xva-muted: #5b5b5b;
  --xva-user: rgba(255, 106, 0, 0.12);
}

#xva-root *,
#xva-root *::before,
#xva-root *::after { box-sizing: border-box; }
#xva-root [hidden] { display: none !important; }

/* ---------- Launcher (sits above the WhatsApp button) ---------- */
#xva-root .xva-launch {
  position: fixed;
  right: 20px;
  bottom: calc(92px + env(safe-area-inset-bottom, 0px));
  width: 58px;
  height: 58px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--xva-orange), var(--xva-orange-2));
  box-shadow: 0 8px 24px rgba(255, 106, 0, 0.45), inset 0 1px 1px rgba(255, 255, 255, 0.35);
  z-index: 41;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#xva-root .xva-launch:hover { transform: scale(1.08); box-shadow: 0 10px 30px rgba(255, 106, 0, 0.6); }
#xva-root .xva-launch:focus-visible,
#xva-root button:focus-visible,
#xva-root input:focus-visible { outline: 2px solid var(--xva-orange-3); outline-offset: 2px; }
#xva-root .xva-launch svg { width: 26px; height: 26px; }

#xva-root .xva-hint {
  position: fixed;
  right: 88px;
  bottom: calc(104px + env(safe-area-inset-bottom, 0px));
  max-width: 220px;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 12.5px;
  line-height: 1.35;
  background: var(--xva-bg);
  color: var(--xva-text);
  border: 1px solid var(--xva-line);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  z-index: 41;
  opacity: 0;
  transform: translateX(6px);
  transition: opacity 0.35s ease, transform 0.35s ease;
  pointer-events: none;
}
#xva-root .xva-hint.is-on { opacity: 1; transform: none; }

/* ---------- Panel ---------- */
#xva-root .xva-panel {
  position: fixed;
  right: 20px;
  bottom: calc(162px + env(safe-area-inset-bottom, 0px));
  width: 380px;
  height: min(640px, calc(100dvh - 182px - env(safe-area-inset-bottom, 0px)));
  display: flex;
  flex-direction: column;
  background: var(--xva-bg);
  border: 1px solid var(--xva-line);
  border-radius: 20px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 106, 0, 0.08);
  overflow: hidden;
  z-index: 80;
  animation: xva-in 0.22s ease-out;
}
@keyframes xva-in { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: none; } }

#xva-root .xva-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--xva-line);
}
#xva-root .xva-id { display: flex; flex-direction: column; min-width: 0; flex: 1; }
#xva-root .xva-name { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 16px; letter-spacing: 0.02em; }
#xva-root .xva-status {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  color: var(--xva-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
#xva-root .xva-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--xva-muted);
}
#xva-root[data-state='listening'] .xva-status::before { background: #34d399; }
#xva-root[data-state='thinking'] .xva-status::before { background: var(--xva-orange-3); }
#xva-root[data-state='speaking'] .xva-status::before { background: var(--xva-orange); }

#xva-root .xva-lang {
  display: inline-flex;
  border: 1px solid var(--xva-line);
  border-radius: 999px;
  padding: 2px;
}
#xva-root .xva-lang button {
  border: 0;
  background: transparent;
  color: var(--xva-muted);
  font: 600 12px 'Inter', sans-serif;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
}
#xva-root .xva-lang button[aria-pressed='true'] { background: var(--xva-orange); color: #fff; }

#xva-root .xva-close {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--xva-muted);
  cursor: pointer;
}
#xva-root .xva-close:hover { background: var(--xva-elev); color: var(--xva-text); }
#xva-root .xva-close svg { width: 18px; height: 18px; }

/* ---------- Orb: ring of bars around the mic button ---------- */
#xva-root .xva-stage {
  position: relative;
  flex: none;
  height: 188px;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 55%, rgba(255, 106, 0, 0.1), transparent 62%);
}
#xva-root .xva-orb { position: absolute; inset: 0; width: 100%; height: 100%; }
#xva-root .xva-mic {
  position: relative;
  width: 74px;
  height: 74px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, var(--xva-orange), var(--xva-orange-2));
  box-shadow: 0 6px 22px rgba(255, 106, 0, 0.5), inset 0 1px 1px rgba(255, 255, 255, 0.35);
  transition: transform 0.15s ease;
}
#xva-root .xva-mic:active { transform: scale(0.95); }
#xva-root .xva-mic svg { width: 30px; height: 30px; }
#xva-root .xva-mic .xva-ico-stop { display: none; }
#xva-root[data-state='listening'] .xva-mic .xva-ico-mic,
#xva-root[data-state='speaking'] .xva-mic .xva-ico-mic { display: none; }
#xva-root[data-state='listening'] .xva-mic .xva-ico-stop,
#xva-root[data-state='speaking'] .xva-mic .xva-ico-stop { display: block; }

#xva-root .xva-live {
  min-height: 22px;
  padding: 0 16px;
  text-align: center;
  font-size: 13px;
  font-style: italic;
  color: var(--xva-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Conversation ---------- */
#xva-root .xva-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
}
#xva-root .xva-msg {
  max-width: 88%;
  padding: 9px 12px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
#xva-root .xva-msg--agent { align-self: flex-start; background: var(--xva-elev); border-bottom-left-radius: 4px; }
#xva-root .xva-msg--user { align-self: flex-end; background: var(--xva-user); border: 1px solid rgba(255, 106, 0, 0.3); border-bottom-right-radius: 4px; }
#xva-root .xva-msg--note { align-self: center; max-width: 100%; background: transparent; color: var(--xva-muted); font-size: 12px; text-align: center; padding: 2px 8px; }
#xva-root .xva-act {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 11px;
  border-radius: 8px;
  border: 1px solid rgba(255, 106, 0, 0.45);
  color: var(--xva-orange-3);
  font: 600 12px 'Inter', sans-serif;
  text-decoration: none;
  background: transparent;
  cursor: pointer;
}
html.light #xva-root .xva-act { color: #b84800; }
#xva-root .xva-act:hover { background: rgba(255, 106, 0, 0.12); }

#xva-root .xva-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 10px; }
#xva-root .xva-chips button {
  border: 1px solid var(--xva-line);
  background: transparent;
  color: var(--xva-text);
  font: 500 12px 'Inter', sans-serif;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}
#xva-root .xva-chips button:hover { border-color: var(--xva-orange); color: var(--xva-orange-3); }
html.light #xva-root .xva-chips button:hover { color: #b84800; }

/* ---------- Input + footer ---------- */
#xva-root .xva-form { display: flex; gap: 8px; padding: 0 14px 10px; }
#xva-root .xva-form input {
  flex: 1;
  min-width: 0;
  background: var(--xva-elev);
  border: 1px solid var(--xva-line);
  color: var(--xva-text);
  border-radius: 10px;
  padding: 9px 12px;
  font: 400 16px 'Inter', sans-serif; /* 16px stops iOS zooming on focus */
}
#xva-root .xva-form input::placeholder { color: var(--xva-muted); }
#xva-root .xva-form button {
  width: 40px;
  border: 0;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--xva-orange);
  color: #fff;
  cursor: pointer;
}
#xva-root .xva-form button svg { width: 18px; height: 18px; }

#xva-root .xva-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px 12px;
  border-top: 1px solid var(--xva-line);
  font-size: 12px;
  color: var(--xva-muted);
}
#xva-root .xva-foot label { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
#xva-root .xva-foot input { accent-color: var(--xva-orange); }
#xva-root .xva-mute {
  border: 1px solid var(--xva-line);
  background: transparent;
  color: var(--xva-muted);
  font: 500 12px 'Inter', sans-serif;
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
}
#xva-root .xva-mute[aria-pressed='true'] { color: var(--xva-orange-3); border-color: rgba(255, 106, 0, 0.5); }

/* ---------- Small screens: bottom sheet ---------- */
@media (max-width: 520px) {
  #xva-root .xva-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: min(86dvh, 720px);
    border-radius: 20px 20px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  #xva-root.is-open .xva-launch,
  #xva-root.is-open .xva-hint { display: none; }
  #xva-root .xva-hint { max-width: 170px; right: 84px; }
}
@media (max-height: 700px) and (min-width: 521px) {
  #xva-root .xva-stage { height: 150px; }
  #xva-root .xva-mic { width: 62px; height: 62px; }
}

@media (prefers-reduced-motion: reduce) {
  #xva-root .xva-panel { animation: none; }
  #xva-root .xva-hint,
  #xva-root .xva-launch { transition: none; }
}
