/* Voice call (packages/ask panel/voice/voice.js), from the Control Plane's app.css: a call sheet with an orb, cards confirmed by a tap, captions; minimized to a
   call bar (phone, top) or a pill (desktop). The app's own Talk buttons are its own CSS. Uses the host's design tokens,
   like term.css, and its .primary, .small, .danger and .muted classes. */
.voice-audio { display: none; }

.voice-sheet { position: fixed; z-index: 75; right: 1rem; bottom: 1rem; width: min(27rem, calc(100vw - 2rem)); max-height: min(86dvh, 48rem);
  display: flex; flex-direction: column; gap: .6rem; padding: .7rem .8rem .8rem; border-radius: var(--radius-xl); background: var(--surface-raised);
  border: 1px solid var(--border-default); box-shadow: var(--shadow-xl); animation: ns-scale-in var(--duration-base) var(--ease-out) backwards; }
.voice-sheet[hidden] { display: none; }
.voice-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto auto; align-items: center; gap: .4rem; }
.voice-who-head { display: flex; align-items: center; gap: .55rem; min-width: 0; }
.voice-avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--surface-sunken); display: grid; place-items: center; overflow: hidden; }
.voice-titles { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.voice-titles small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .78rem; }
.voice-clock { font: 500 .82rem/1 var(--font-mono); color: var(--text-secondary); }
.voice-stage { display: flex; flex-direction: column; align-items: center; gap: .55rem; padding: .4rem 0 .2rem; }
.voice-phase { margin: 0; font-size: .92rem; color: var(--text-secondary); text-align: center; min-height: 1.3em; }

/* the orb: --lvl (0..1) is the mic level while listening, the speech level while speaking */
.voice-orb { --lvl: 0; --c: var(--olive-600); position: relative; width: 108px; height: 108px; min-height: 0; padding: 0; border-radius: 50%; border: 0;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--c) 55%, var(--surface-sunken)), var(--surface-sunken) 72%); box-shadow: none; }
.voice-orb::before { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 3px solid var(--c);
  transform: scale(calc(1 + var(--lvl) * .22)); opacity: calc(.45 + var(--lvl) * .55); transition: transform 80ms linear, opacity 80ms linear; }
.voice-orb-core { position: absolute; inset: 30%; border-radius: 50%; background: var(--c); transform: scale(calc(.85 + var(--lvl) * .35)); transition: transform 80ms linear; }
.voice-orb[data-phase="hearing"] { --c: var(--clay-400); }
.voice-orb[data-phase="speaking"] { --c: var(--clay-500); }
.voice-orb[data-phase="thinking"], .voice-orb[data-phase="working"], .voice-orb[data-phase="connecting"] { --c: var(--taupe-300); }
.voice-orb[data-phase="thinking"]::before, .voice-orb[data-phase="working"]::before, .voice-orb[data-phase="connecting"]::before { border-style: dashed; animation: voice-spin 2.4s linear infinite; }
.voice-orb[data-phase="muted"] { --c: var(--warn-text); --lvl: 0; }
.voice-orb[data-phase="confirm"] { --c: var(--clay-500); --lvl: .25; }
.voice-orb[data-phase="reconnecting"]::before { border-style: dashed; opacity: .5; }
.voice-orb[data-phase="ended"] { --c: var(--border-control); --lvl: 0; }
@keyframes voice-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .voice-orb::before, .voice-orb-core { transition: none; animation: none !important; } }

/* background tasks: a row each while a tool runs or an agent session answers */
.voice-tasks { display: flex; flex-direction: column; gap: .3rem; }
.voice-tasks:empty { display: none; }
.voice-task { display: grid; grid-template-columns: 1.4rem minmax(0, 1fr) auto; align-items: center; gap: .5rem; padding: .45rem .6rem; border-radius: var(--radius-md); background: var(--surface-sunken); border: 1px solid var(--border-subtle); }
.voice-task[data-state="done"] { border-color: color-mix(in srgb, var(--pos-text) 45%, transparent); }
.voice-task[data-state="done"] .voice-task-icon { color: var(--pos-text); }
.voice-task[data-state="failed"] .voice-task-icon { color: var(--warn-text); }
.voice-task-icon { display: grid; place-items: center; }
.voice-task-icon .icon { width: 1rem; height: 1rem; }
.voice-spin { width: 1rem; height: 1rem; border-radius: 50%; border: 2px solid var(--border-default); border-top-color: var(--clay-500); animation: voice-spin .9s linear infinite; }
.voice-task-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.voice-task-label { font-size: .88rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-task-detail { font: .76rem/1.3 var(--font-mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-task-detail:empty { display: none; }
.voice-task-time { font: .78rem/1 var(--font-mono); color: var(--text-secondary); }
@media (prefers-reduced-motion: reduce) { .voice-spin { animation: none; border-top-color: var(--clay-500); } }
.voice-cards { display: flex; flex-direction: column; gap: .45rem; }
.voice-cards:empty { display: none; }
.voice-card { padding: .65rem .75rem; border-radius: var(--radius-md); border: 1px solid var(--border-accent); background: var(--surface-accent-soft); display: flex; flex-direction: column; gap: .3rem; }
.voice-card.done { border-color: var(--pos-text); background: transparent; } .voice-card.failed { border-color: var(--border-default); background: transparent; }
.voice-card-what { margin: 0; font-size: .92rem; }
.voice-card-text { margin: .15rem 0 0; padding: .5rem .6rem; border-radius: var(--radius-sm); background: var(--surface-sunken); font: .88rem/1.35 var(--font-mono); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 8rem; overflow: auto; }
.voice-card-time { display: flex; align-items: center; gap: .5rem; }
.voice-card-bar { --left: 1; flex: 1; height: 4px; border-radius: var(--radius-pill); background: linear-gradient(90deg, var(--clay-500) calc(var(--left) * 100%), var(--border-subtle) 0); }
.voice-left { font-family: var(--font-mono); white-space: nowrap; }
.voice-card-actions { display: flex; align-items: center; justify-content: flex-end; gap: .45rem; margin-top: .15rem; }
.voice-card-actions button { min-height: 40px; padding: .3rem 1rem; }
.voice-ok { color: var(--pos-text); } .voice-no { color: var(--text-muted); }

.voice-captions { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.voice-sheet.no-captions .voice-captions { display: none; }
.voice-captions-toggle { align-self: flex-start; min-height: 28px; padding: 0 .2rem; gap: .25rem; background: transparent; border: 0; color: var(--text-muted); font-size: .72rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.voice-captions-toggle .icon { width: .9rem; height: .9rem; }
.voice-sheet.captions-short .voice-captions-toggle .icon { transform: rotate(-90deg); }
.voice-log { min-height: 4rem; max-height: 30dvh; overflow-y: auto; display: flex; flex-direction: column; gap: .35rem; padding: .2rem .1rem; }
.voice-sheet.captions-short .voice-log { min-height: 0; max-height: 1.6rem; overflow: hidden; }
.voice-line { margin: 0; display: grid; grid-template-columns: 3.4rem minmax(0, 1fr); gap: .4rem; font-size: .9rem; line-height: 1.35; }
.voice-who { color: var(--text-muted); font-size: .75rem; font-weight: 600; padding-top: .1rem; overflow: hidden; text-overflow: ellipsis; }
.voice-line.agent .voice-who { color: var(--text-accent); }
.voice-line.tool, .voice-line.error { color: var(--text-muted); font-size: .8rem; }
.voice-line.tool .voice-text { display: inline-flex; gap: .35rem; align-items: center; }
.voice-line.tool .icon { width: .85rem; height: .85rem; }
.voice-line.error { color: var(--neg-text); }
.voice-type { display: flex; gap: .35rem; }
.voice-type[hidden] { display: none; }
.voice-type input { flex: 1 1 auto; min-width: 0; min-height: 42px; }
.voice-foot { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .5rem; }
.voice-foot .voice-summary { grid-column: 1 / -1; margin: 0; text-align: center; font-size: .88rem; }
.voice-talk { min-height: 50px; border-radius: var(--radius-pill); font-weight: 600; }
.voice-talk[aria-pressed="true"], .voice-talk.on { background: var(--surface-accent-soft); border-color: var(--border-accent); color: var(--text-accent); }
.voice-talk.hold { touch-action: none; user-select: none; -webkit-user-select: none; }
.voice-end { min-height: 50px; border-radius: var(--radius-pill); padding: 0 1.1rem; }

/* minimized: a call bar under the top edge (phone) or a pill (desktop) */
.voice-bar { position: fixed; z-index: 74; left: 50%; transform: translateX(-50%); bottom: 1rem; display: flex; align-items: center; gap: .3rem; padding: .3rem .4rem .3rem .5rem;
  border-radius: var(--radius-pill); background: var(--surface-raised); border: 1px solid var(--border-accent); box-shadow: var(--shadow-lg); }
.voice-bar-main { display: flex; align-items: center; gap: .6rem; min-height: 40px; padding: 0 .4rem; background: transparent; border: 0; }
.voice-bar .voice-orb { width: 30px; height: 30px; pointer-events: none; }
.voice-bar .voice-orb::before { inset: -3px; border-width: 2px; }
.voice-bar-text { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; font-size: .85rem; }
.voice-bar-phase { color: var(--text-secondary); font-size: .76rem; white-space: nowrap; }
.voice-bar-end { color: var(--neg-text); }

@media (max-width: 700px), (pointer: coarse) {
  .voice-sheet { left: 0; right: 0; bottom: 0; width: auto; max-height: 92dvh; border-radius: var(--radius-xl) var(--radius-xl) 0 0; border-bottom: 0;
    padding-bottom: calc(.8rem + var(--safe-bottom)); animation: ns-sheet-up var(--duration-slow) var(--ease-out) backwards; }
  .voice-bar { left: .5rem; right: .5rem; transform: none; top: calc(var(--safe-top) + .35rem); bottom: auto; border-radius: var(--radius-lg); }
  .voice-bar-main { flex: 1; }
  .voice-bar .voice-clock { margin-left: auto; }
  body.voice-bar-on:not(.voice-bar-mounted) main { padding-top: 3.4rem; } /* a floating bar sits over the page top */
}
/* the sheet's icon buttons (the app's own button styles apply to the rest) */
.voice-icon-btn { width: 40px; height: 40px; min-height: 0; padding: 0; border-radius: var(--radius-pill); background: transparent; border-color: transparent; color: var(--text-secondary); }
.voice-icon-btn:hover:not(:disabled) { background: var(--surface-hover); color: var(--text-primary); }
.voice-icon-btn .icon { width: 1.3rem; height: 1.3rem; }
/* a call bar mounted in the app's own layout (createVoiceCall {mount}) instead of floating */
.voice-bar.mounted { position: static; transform: none; left: auto; right: auto; top: auto; bottom: auto; width: 100%; }
