/* =========================================================================
   Decision 041: the live voice demo (templates/partials/voice-demo.php,
   js/voice-demo.js). Colours follow the surrounding text, so it sits on the
   light page and on the dark AI receptionist band alike; light-dark() picks
   the error and focus colours from the colour scheme it is in. Motion stops
   with reduced motion (chairday.css) and the bars then stay still.
   ========================================================================= */
.cd-voice {
  --cd-voice-accent: var(--cd-accent, #FF9548);
  --cd-voice-on-accent: var(--cd-on-accent, #0B3341);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  min-width: 0; text-align: center; color: inherit;
}
.cd-voice__stage { display: flex; flex-direction: column; align-items: center; gap: 18px; padding-top: 8px; }

.cd-voice__mic {
  position: relative; display: grid; place-items: center;
  width: 96px; height: 96px; padding: 0; border: 0; border-radius: 50%;
  background: var(--cd-voice-accent); color: var(--cd-voice-on-accent);
  box-shadow: var(--cd-shadow-sun, 0 10px 28px -10px rgba(255, 149, 72, 0.65));
  cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
  transition: transform 0.18s ease, background-color 0.18s ease;
}
.cd-voice__mic:hover { transform: scale(1.04); }
.cd-voice__mic:active { transform: scale(0.97); }
.cd-voice__mic:focus-visible { outline: 3px solid #0B3341; outline: 3px solid light-dark(#0B3341, #FF9548); outline-offset: 6px; }
.cd-voice__icon { width: 38px; height: 38px; }
.cd-voice__icon--stop { display: none; width: 30px; height: 30px; }
.cd-voice[data-voice="connecting"] .cd-voice__icon--mic,
.cd-voice[data-voice="listening"] .cd-voice__icon--mic,
.cd-voice[data-voice="speaking"] .cd-voice__icon--mic { display: none; }
.cd-voice[data-voice="connecting"] .cd-voice__icon--stop,
.cd-voice[data-voice="listening"] .cd-voice__icon--stop,
.cd-voice[data-voice="speaking"] .cd-voice__icon--stop { display: block; }

/* The ring: an invitation when idle, a spinner while connecting, a live halo on a call */
.cd-voice__ring {
  position: absolute; inset: -9px; border-radius: 50%; pointer-events: none;
  border: 2px solid var(--cd-voice-accent); opacity: 0.45;
}
.cd-voice[data-voice="connecting"] .cd-voice__ring { border-color: transparent; border-top-color: var(--cd-voice-accent); opacity: 1; }
.cd-voice[data-voice="listening"] .cd-voice__ring,
.cd-voice[data-voice="speaking"] .cd-voice__ring { opacity: 0.8; }
.cd-voice[data-voice="error"] .cd-voice__mic { background: transparent; color: inherit; box-shadow: inset 0 0 0 2px currentColor; }
.cd-voice[data-voice="error"] .cd-voice__ring { opacity: 0; }

/* The bars: script-driven levels (--cd-voice-level, 0 to 1) on a call, a gentle wave otherwise */
.cd-voice__wave { display: flex; align-items: center; justify-content: center; gap: 4px; height: 44px; width: min(100%, 220px); }
.cd-voice__wave span {
  --f: 1;
  flex: 0 0 4px; height: 100%; border-radius: 3px; background: currentColor; opacity: 0.38;
  transform: scaleY(0.12); transform-origin: center;
  transition: transform 0.12s ease-out, opacity 0.2s ease;
}
.cd-voice__wave span:nth-child(3n + 1) { --f: 0.55; }
.cd-voice__wave span:nth-child(4n + 2) { --f: 0.85; }
.cd-voice__wave span:nth-child(5n + 3) { --f: 0.7; }
.cd-voice[data-voice="listening"] .cd-voice__wave span,
.cd-voice[data-voice="speaking"] .cd-voice__wave span {
  opacity: 0.8; transform: scaleY(calc(0.12 + var(--cd-voice-level, 0) * 0.88 * var(--f)));
}
.cd-voice[data-voice="speaking"] .cd-voice__wave span { background: var(--cd-voice-accent); }

.cd-voice__label { margin: 0; max-width: 36ch; font-weight: 700; font-size: 1.0625rem; line-height: 1.35; text-wrap: balance; }
.cd-voice[data-voice="error"] .cd-voice__label { color: #B8352A; color: light-dark(#B8352A, #FFB4A2); }
.cd-voice__time { margin: 0; font: 600 0.875rem/1 var(--cd-font-ui, system-ui, sans-serif); font-variant-numeric: tabular-nums; opacity: 0.75; }
.cd-voice__note { margin: 4px 0 0; max-width: 52ch; font-size: 0.8125rem; line-height: 1.45; opacity: 0.78; }
.cd-voice__note a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.cd-voice__note a:focus-visible { outline: 2px solid #0B3341; outline: 2px solid light-dark(#0B3341, #FF9548); outline-offset: 2px; }

@media (prefers-reduced-motion: no-preference) {
  .cd-voice[data-voice="idle"] .cd-voice__ring { animation: cd-voice-invite 2.4s ease-out infinite; }
  .cd-voice[data-voice="connecting"] .cd-voice__ring { animation: cd-voice-spin 0.9s linear infinite; }
  .cd-voice[data-voice="connecting"] .cd-voice__wave span { animation: cd-voice-wait 1.2s ease-in-out infinite; }
  .cd-voice[data-voice="connecting"] .cd-voice__wave span:nth-child(2n) { animation-delay: 0.15s; }
  .cd-voice[data-voice="connecting"] .cd-voice__wave span:nth-child(3n) { animation-delay: 0.3s; }
}
@keyframes cd-voice-invite { 0% { transform: scale(0.94); opacity: 0.55; } 75%, 100% { transform: scale(1.28); opacity: 0; } }
@keyframes cd-voice-spin { to { transform: rotate(360deg); } }
@keyframes cd-voice-wait { 0%, 100% { transform: scaleY(0.12); } 50% { transform: scaleY(0.4); } }

@media (forced-colors: active) {
  .cd-voice__mic { border: 2px solid ButtonText; }
  .cd-voice__wave span { background: CanvasText; forced-color-adjust: none; }
}
