/* REONE Live Voice: layout, call controls and ambience.
   Presentation only. Provider, VAD, lead capture, tools and conversation
   behaviour live in 17-live-voice.js and are not touched here.

   Three zones, so the controls can never scroll out of reach:
     header (badge, minimize)
     body   (hero, orb, status, captions, suggestions); the only part that scrolls
     dock   (session timer + call controls), always visible
   Every colour derives from the published theme tokens, so a Control Center
   palette (e.g. violet + lime) carries through without a code change. */

/* A closed native dialog stays out of layout on every browser; iOS Safari can
   otherwise let an authored display value beat the UA's. */
dialog#voice-dialog:not([open]) { display: none !important; }

/* One visible dialogue surface: finalized turns go to the shared chat thread,
   the live captions are the voice surface. */
#voice-dialog .voice-transcript-feed { display: none !important; }

.voice-dialog {
  --vd-card: color-mix(in srgb, var(--on-contrast) 7%, transparent);
  --vd-card-strong: color-mix(in srgb, var(--on-contrast) 13%, transparent);
  --vd-line: color-mix(in srgb, var(--on-contrast) 14%, transparent);
  --vd-glow: color-mix(in srgb, var(--brand) 30%, transparent);
  --vd-glow-soft: color-mix(in srgb, var(--brand) 14%, transparent);
  --vd-hangup: #e0373f;
  --vd-hangup-hover: #c42a33;
  position: fixed;
  isolation: isolate;
  width: min(520px, calc(100% - 32px));
  min-height: 0;
  max-height: min(840px, calc(100vh - 32px));
  max-height: min(840px, calc(100dvh - 32px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--vd-line);
  border-radius: 28px;
  background:
    radial-gradient(120% 58% at 50% -6%, var(--vd-glow), transparent 64%),
    radial-gradient(90% 46% at 100% 104%, var(--vd-glow-soft), transparent 72%),
    linear-gradient(180deg, var(--contrast) 0%, var(--contrast-2) 70%);
  color: var(--on-contrast);
  font-family: var(--font-body), "Inter", system-ui, sans-serif;
  text-align: center;
  box-shadow: 0 40px 120px -20px rgba(0, 0, 0, .6), var(--shadow-pop);
}
.voice-dialog[open] { display: flex; flex-direction: column; }
.voice-dialog::backdrop {
  background: color-mix(in srgb, var(--contrast-2) 66%, transparent);
  backdrop-filter: blur(10px);
}
#voice-dialog button { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }

/* --- Ambient background -------------------------------------------------
   Three soft light fields drift slowly behind the content and brighten with
   the conversation: steady while listening, strongest while REONE speaks,
   greyed when muted or failed. Motion only when the visitor allows it. */
.voice-ambient { position: absolute; inset: 0; z-index: -1; overflow: hidden; border-radius: inherit; pointer-events: none; }
.voice-ambient span {
  position: absolute;
  width: 78%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle, color-mix(in srgb, var(--brand) 34%, transparent), transparent 66%);
  opacity: .42;
  transition: opacity .6s var(--ease), filter .6s var(--ease);
}
.voice-ambient span:nth-child(1) { top: -30%; left: -26%; }
.voice-ambient span:nth-child(2) { top: 24%; right: -38%; width: 66%; background: radial-gradient(circle, color-mix(in srgb, var(--on-contrast-brand) 22%, transparent), transparent 68%); opacity: .34; }
.voice-ambient span:nth-child(3) { bottom: -40%; left: 4%; width: 92%; opacity: .3; }
.voice-dialog[data-voice-state="listening"] .voice-ambient span,
.voice-dialog[data-voice-state="user_speaking"] .voice-ambient span { opacity: .55; }
.voice-dialog[data-voice-state="assistant_speaking"] .voice-ambient span { opacity: .8; }
.voice-dialog[data-voice-state="muted"] .voice-ambient span,
.voice-dialog[data-voice-state="error"] .voice-ambient span { opacity: .22; filter: grayscale(1); }
@media (prefers-reduced-motion: no-preference) {
  .voice-ambient span { will-change: transform; }
  .voice-ambient span:nth-child(1) { animation: vd-drift-a 17s ease-in-out infinite alternate; }
  .voice-ambient span:nth-child(2) { animation: vd-drift-b 21s ease-in-out infinite alternate; }
  .voice-ambient span:nth-child(3) { animation: vd-drift-c 25s ease-in-out infinite alternate; }
  .voice-dialog[data-voice-state="assistant_speaking"] .voice-ambient span { animation-duration: 7s, 9s, 11s; }
}
@keyframes vd-drift-a { to { transform: translate(22%, 16%) scale(1.14); } }
@keyframes vd-drift-b { to { transform: translate(-20%, 12%) scale(.88); } }
@keyframes vd-drift-c { to { transform: translate(12%, -14%) scale(1.1); } }

/* --- Header --------------------------------------------------------------- */
.voice-dialog .voice-dialog-top {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  width: auto;
  margin: 0;
  padding: 14px 14px 4px 22px;
}
.voice-dialog .voice-badge-group { display: flex; align-items: center; gap: 10px; min-width: 0; }
.voice-dialog .voice-badge-group .eyebrow { margin: 0; white-space: nowrap; }
.voice-dialog .voice-model-pill { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-dialog .voice-model-pill::before {
  content: "";
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--on-contrast-faint);
  transition: background .3s, box-shadow .3s;
}
.voice-dialog:not([data-voice-state="idle"], [data-voice-state="ended"], [data-voice-state="error"]) .voice-model-pill::before {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 28%, transparent);
}
.voice-dialog .voice-minimize {
  flex: 0 0 40px;
  width: 40px;
  height: 40px;
  margin-inline-start: auto;
  border: 1px solid var(--vd-line);
  border-radius: 50%;
  background: var(--vd-card);
  color: var(--on-contrast);
}
.voice-dialog .voice-minimize:hover { background: var(--vd-card-strong); }

/* --- Body (the only scrolling zone) --------------------------------------- */
.voice-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 6px 26px 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--vd-card-strong) transparent;
}
/* Idle: the group sits in the middle when there is room to spare. Auto
   margins, not justify-content, so a short screen still scrolls from the top. */
.voice-body > .voice-hero { margin-top: auto; }
.voice-body > #voice-knowledge-status { margin-bottom: auto; }

.voice-dialog .voice-hero h2 {
  margin: 6px 0 14px;
  font-family: var(--font-heading), "Space Grotesk", "Inter", system-ui, sans-serif;
  font-size: clamp(28px, 3.4vw, 36px);
  line-height: 1.04;
  letter-spacing: -.025em;
}

/* In a call the heading leaves the layout but keeps naming the dialog. */
.voice-dialog:not([data-voice-state="idle"], [data-voice-state="ended"], [data-voice-state="error"]) .voice-hero {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.voice-dialog .voice-stage { flex: 0 0 auto; width: 100%; }
.voice-dialog .voice-orb { width: 132px; height: 132px; margin: 4px auto 8px; }
.voice-dialog .voice-orb span { inset: 14px; }
.voice-dialog .voice-orb span:nth-child(2) { inset: 28px; }
.voice-dialog:not([data-voice-state="idle"], [data-voice-state="ended"], [data-voice-state="error"]) .voice-orb { width: 92px; height: 92px; margin: 10px auto 4px; }
.voice-dialog:not([data-voice-state="idle"], [data-voice-state="ended"], [data-voice-state="error"]) .voice-orb span { inset: 7px; }
.voice-dialog:not([data-voice-state="idle"], [data-voice-state="ended"], [data-voice-state="error"]) .voice-orb span:nth-child(2) { inset: 17px; }
.voice-dialog .voice-visualizer { height: 22px; margin: 2px auto 6px; }

.voice-dialog #voice-status { margin: 0 0 4px; font-size: 17px; font-weight: 700; line-height: 1.3; }
.voice-dialog #voice-detail {
  display: block;
  max-width: 380px;
  margin: 0 auto;
  color: var(--on-contrast-soft);
  font-size: 13px;
  line-height: 1.5;
}
.voice-dialog .voice-tool-indicator { margin: 10px auto 0; border-color: var(--vd-line); background: var(--vd-card); }
.voice-dialog .voice-tool-pulse { flex: 0 0 auto; width: 7px; height: 7px; border-radius: 50%; }
@media (prefers-reduced-motion: no-preference) {
  .voice-dialog .voice-tool-pulse { animation: pulse 1.2s ease-in-out infinite; }
}

/* --- Captions: live subtitles, newest text always in view ----------------- */
.voice-dialog .voice-captions { display: flex; flex-direction: column; gap: 10px; margin: 18px 0 0; text-align: start; }
.voice-dialog:not([data-voice-state="idle"], [data-voice-state="ended"], [data-voice-state="error"]) .voice-captions { flex: 1 0 auto; }
.voice-dialog .voice-captions p {
  margin: 0;
  padding: 12px 14px;
  border: 1px solid var(--vd-line);
  border-radius: 18px;
  background: var(--vd-card);
  line-height: 1.4;
}
.voice-dialog .voice-captions p[hidden] { display: none; }
.voice-dialog #voice-assistant-caption {
  border-color: color-mix(in srgb, var(--brand) 34%, var(--vd-line));
  background: linear-gradient(180deg, color-mix(in srgb, var(--brand) 9%, transparent), var(--vd-card));
}
.voice-dialog #voice-user-caption { margin-inline-start: 14%; background: transparent; }
.voice-dialog .voice-captions b { margin-bottom: 4px; font-size: 10.5px; letter-spacing: .09em; color: var(--on-contrast-brand); }
.voice-dialog #voice-user-caption b { color: var(--on-contrast-faint); }
.voice-dialog .voice-captions span {
  max-height: clamp(4.8em, 26vh, 11em);
  font-size: 15.5px;
  line-height: 1.55;
  color: var(--on-contrast);
  scrollbar-width: none;
}
.voice-dialog .voice-captions span::-webkit-scrollbar { display: none; }
.voice-dialog #voice-user-caption span { max-height: 4.8em; font-size: 14px; color: var(--on-contrast-soft); }
@media (prefers-reduced-motion: no-preference) {
  .voice-dialog .voice-captions p { animation: vd-rise .28s var(--ease) both; }
}
@keyframes vd-rise { from { opacity: 0; transform: translateY(6px); } }

/* Transcript off: captions leave the screen only. The conversation is still
   committed to the shared chat thread. */
.voice-dialog[data-transcript="off"] .voice-captions { display: none; }
.voice-transcript-note { display: none; max-width: 320px; margin: 16px auto 0; color: var(--on-contrast-faint); font-size: 12.5px; line-height: 1.5; }
.voice-dialog[data-transcript="off"]:not([data-voice-state="idle"], [data-voice-state="ended"], [data-voice-state="error"]) .voice-transcript-note { display: block; }
/* With nothing to read, the call screen centres on the orb. */
.voice-dialog[data-transcript="off"]:not([data-voice-state="idle"], [data-voice-state="ended"], [data-voice-state="error"]) .voice-stage { margin-top: auto; }
.voice-dialog[data-transcript="off"]:not([data-voice-state="idle"], [data-voice-state="ended"], [data-voice-state="error"]) .voice-transcript-note { margin-bottom: auto; }
#voice-bubble[data-transcript="off"] #voice-bubble-caption { display: none; }

/* --- Suggestions, knowledge line, diagnostics ------------------------------ */
.voice-dialog .voice-suggestions { flex: 0 0 auto; display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 18px 0 0; }
.voice-dialog .voice-chip {
  min-height: 38px;
  padding: 8px 14px;
  border: 1px solid var(--vd-line);
  border-radius: 999px;
  background: var(--vd-card);
  color: var(--on-contrast-soft);
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.25;
}
.voice-dialog .voice-chip:hover {
  border-color: color-mix(in srgb, var(--brand) 60%, transparent);
  background: color-mix(in srgb, var(--brand) 14%, transparent);
  color: var(--on-contrast);
}
.voice-dialog .voice-chip:focus-visible,
.voice-dialog .voice-minimize:focus-visible,
.voice-dialog .voice-demo:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }
.voice-dialog #voice-knowledge-status {
  display: block;
  max-width: 380px;
  margin: 14px auto 0;
  color: var(--on-contrast-faint);
  font-size: 11.5px;
  line-height: 1.45;
}
.voice-dialog .voice-sources { margin-top: 10px; border-radius: 14px; background: var(--vd-card); }
.voice-dialog .voice-diagnostics { margin: 10px auto 0; width: 100%; font-size: 11px; }
.voice-dialog .voice-diagnostics summary { min-height: 36px; justify-content: center; color: var(--on-contrast-faint); }

/* --- Dock: timer + call controls ------------------------------------------ */
.voice-dock {
  flex: 0 0 auto;
  padding: 14px 20px 20px;
  border-top: 1px solid var(--vd-line);
  background: color-mix(in srgb, var(--contrast-2) 70%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}
.voice-dialog .voice-session-timer { width: min(100%, 380px); margin: 0 auto 14px; }

.voice-dialog .voice-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: center;
  gap: 10px 14px;
  margin: 0;
}
.voice-dialog .voice-actions [hidden] { display: none !important; }

/* Before a call: one clear primary action. */
.voice-dialog .voice-actions .voice-demo {
  flex: 1 1 220px;
  max-width: 380px;
  min-height: 56px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 24px;
  border: 0;
  border-radius: 999px;
  background: var(--brand);
  color: var(--on-brand);
  font-size: 16px;
  font-weight: 800;
  box-shadow: 0 12px 32px -6px color-mix(in srgb, var(--brand) 55%, transparent);
  transition: transform .18s var(--ease), box-shadow .18s var(--ease), background .18s;
}
.voice-dialog .voice-actions .voice-demo svg { width: 20px; height: 20px; margin: 0; }
.voice-dialog .voice-actions .voice-demo:hover { background: var(--brand-fill-hover, var(--brand)); transform: translateY(-1px); }
.voice-dialog .voice-actions .voice-demo:active { transform: scale(.98); }
.voice-dialog .voice-actions .voice-demo:disabled { opacity: .62; cursor: progress; transform: none; box-shadow: none; }

/* In a call: round controls with a visible label, the phone-call pattern.
   The whole column is the hit target (72 x ~80px). */
.voice-dialog .voice-actions .voice-ctl {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 7px;
  width: 72px;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--on-contrast-soft);
  font: 600 11.5px/1.25 var(--font-body), "Inter", system-ui, sans-serif;
  cursor: pointer;
}
.voice-dialog .voice-ctl-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border: 1px solid var(--vd-line);
  border-radius: 50%;
  background: var(--vd-card-strong);
  color: var(--on-contrast);
  transition: background .18s, border-color .18s, color .18s, transform .18s var(--ease), box-shadow .18s;
}
.voice-dialog .voice-ctl-icon svg { width: 22px; height: 22px; margin: 0; }
.voice-dialog .voice-ctl-label { max-width: 100%; overflow-wrap: anywhere; }
.voice-dialog .voice-actions .voice-ctl:hover { color: var(--on-contrast); }
.voice-dialog .voice-actions .voice-ctl:hover .voice-ctl-icon { background: color-mix(in srgb, var(--on-contrast) 20%, transparent); }
.voice-dialog .voice-actions .voice-ctl:active .voice-ctl-icon { transform: scale(.93); }
.voice-dialog .voice-actions .voice-ctl:focus-visible { outline: none; }
.voice-dialog .voice-actions .voice-ctl:focus-visible .voice-ctl-icon { outline: 2px solid var(--focus); outline-offset: 3px; }
.voice-dialog .voice-actions .voice-ctl:disabled { opacity: .5; cursor: default; }
.voice-dialog .voice-actions .voice-ctl:disabled .voice-ctl-icon { transform: none; }

.voice-dialog .voice-mute[aria-pressed="true"] { color: var(--on-contrast); }
.voice-dialog .voice-mute[aria-pressed="true"] .voice-ctl-icon { border-color: transparent; background: var(--on-contrast); color: var(--contrast-2); }
.voice-dialog .voice-transcript-toggle[aria-pressed="true"] .voice-ctl-icon {
  border-color: color-mix(in srgb, var(--on-contrast-brand) 60%, transparent);
  background: color-mix(in srgb, var(--brand) 18%, transparent);
  color: var(--on-contrast-brand);
}
.voice-dialog .voice-actions .voice-end .voice-ctl-icon {
  border-color: transparent;
  background: var(--vd-hangup);
  color: #fff;
  box-shadow: 0 10px 26px -6px color-mix(in srgb, var(--vd-hangup) 70%, transparent);
}
.voice-dialog .voice-actions .voice-end:hover .voice-ctl-icon { background: var(--vd-hangup-hover); }

/* --- Phone, and any short landscape screen: full screen ------------------- */
@media (max-width: 720px), (max-height: 520px) {
  dialog.voice-dialog[open] {
    inset: 0;
    width: 100%;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border: 0;
    border-radius: 0;
  }
  .voice-dialog .voice-dialog-top { padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) 4px max(18px, env(safe-area-inset-left)); }
  .voice-body { padding: 4px max(18px, env(safe-area-inset-right)) 12px max(18px, env(safe-area-inset-left)); }
  .voice-dock { padding: 12px 14px max(16px, env(safe-area-inset-bottom)); }
  .voice-dialog .voice-hero h2 { font-size: clamp(26px, 7.6vw, 32px); }
  .voice-dialog .voice-orb { width: 116px; height: 116px; }
  .voice-dialog .voice-orb span { inset: 12px; }
  .voice-dialog .voice-orb span:nth-child(2) { inset: 25px; }
  .voice-dialog .voice-captions span { font-size: 15px; }
  /* In a call, suggestions take one swipeable row instead of three. */
  .voice-dialog:not([data-voice-state="idle"], [data-voice-state="ended"], [data-voice-state="error"]) .voice-suggestions {
    flex-wrap: nowrap;
    justify-content: flex-start;
    margin-inline: -18px;
    padding: 2px 18px 4px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
    -webkit-mask-image: linear-gradient(90deg, transparent, #000 18px, #000 calc(100% - 18px), transparent);
    mask-image: linear-gradient(90deg, transparent, #000 18px, #000 calc(100% - 18px), transparent);
  }
  .voice-dialog .voice-suggestions::-webkit-scrollbar { display: none; }
  .voice-dialog:not([data-voice-state="idle"], [data-voice-state="ended"], [data-voice-state="error"]) .voice-chip { flex: 0 0 auto; white-space: nowrap; scroll-snap-align: start; }
}
@media (max-width: 380px) {
  .voice-dialog .voice-actions { gap: 10px 8px; }
  .voice-dialog .voice-actions .voice-ctl { width: 64px; font-size: 11px; }
  .voice-dialog .voice-ctl-icon { width: 52px; height: 52px; }
  .voice-dialog .voice-model-pill { max-width: 130px; }
}
@media (max-height: 520px) {
  .voice-dialog .voice-dock { padding-top: 8px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .voice-dialog .voice-session-timer { margin-bottom: 8px; }
  .voice-dialog .voice-ctl-icon { width: 46px; height: 46px; }
  .voice-dialog .voice-actions .voice-demo { min-height: 48px; }
  .voice-dialog .voice-orb { width: 88px; height: 88px; }
}

/* Phone landscape: orb and status on the left, words and suggestions on
   the right, so the transcript is not squeezed under the orb. */
@media (max-height: 520px) and (min-width: 600px) {
  .voice-body {
    display: grid;
    grid-template-columns: minmax(200px, 36%) minmax(0, 1fr);
    grid-template-rows: repeat(8, min-content) 1fr;
    column-gap: 28px;
    align-content: start;
  }
  .voice-body > * { grid-column: 2; }
  .voice-body > .voice-hero, .voice-body > #voice-knowledge-status { margin-top: 0; margin-bottom: 0; }
  .voice-dialog .voice-body > .voice-stage { position: sticky; top: 0; grid-column: 1; grid-row: 1 / -1; align-self: start; margin: 0; }
  .voice-dialog .voice-body > .voice-captions,
  .voice-dialog .voice-body > .voice-transcript-note { margin-top: 6px; }
  .voice-dialog .voice-hero h2 { font-size: 24px; text-align: start; margin: 6px 0 4px; }
  .voice-dialog .voice-suggestions { justify-content: flex-start; margin-top: 12px; }
  .voice-dialog #voice-knowledge-status { margin-inline: 0; text-align: start; }
}

/* The minimized call pill picks up the same palette. */
.voice-bubble { border-color: var(--vd-line, var(--contrast-line)); background: linear-gradient(135deg, var(--contrast), var(--contrast-2)); }
.voice-bubble-dot { background: var(--brand); box-shadow: 0 0 0 7px color-mix(in srgb, var(--brand) 26%, transparent); }
