/* Features: Speech-to-Ticket stage (#speech-to-ticket in features.dc.html).
   One call in four movements: Record (the browser sends the agent's audio to
   the server five seconds at a time), Write up (the speech engine turns the
   recording into text), Draft (the AI provider fills the form, every value
   tied by a thread to the words that prove it) and Review (the agent checks
   it and presses Create Ticket; the transcript is kept, the audio deleted).
   js/features-speech.js drives the states below and draws the links, packets,
   waveform, engine and threads on the canvas. Without the script, or before
   it mounts, the markup is the finished picture. Colours come from the page's
   --stage-* variables, so it follows the theme. */

.stx-block { margin-top: 72px; padding-top: 64px; border-top: 1px solid var(--line); scroll-margin-top: 96px; }
.stx-head { margin-bottom: 28px; display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 18px 48px; }
.stx-head h3 { flex: 1 1 380px; min-width: 0; margin: 0; }
.stx-head h3 span { color: var(--muted); }
.stx-head p { flex: 0 1 460px; margin: 0; font: 400 15px/1.6 var(--f-sans); color: var(--muted); text-wrap: pretty; }
.stx-tag { margin-right: 8px; padding: 4px 7px; border-radius: 999px; background: var(--teal-wash); font: 500 11px/1 var(--f-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }

.stx { --stx-rec: 255, 107, 97; container: stx / inline-size; position: relative; margin: 0 0 24px; min-width: 0; border: 1px solid rgba(var(--stage-ink), .1); border-radius: 14px; background: var(--stage-bg); color: var(--stage-text); overflow: hidden; isolation: isolate; -webkit-tap-highlight-color: transparent; }
[data-theme='light'] .stx { --stx-rec: 190, 50, 44; }
.stx::before { content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none; background-image: radial-gradient(circle at 1px 1px, rgba(var(--stage-ink), .1) 1px, transparent 0); background-size: 22px 22px; -webkit-mask-image: radial-gradient(70% 62% at 50% 46%, #000 0%, transparent 82%); mask-image: radial-gradient(70% 62% at 50% 46%, #000 0%, transparent 82%); }
/* Above the words: packets enter the nodes and threads cross the text. `color` hands the script the teal. */
.stx__canvas { position: absolute; inset: 0; z-index: 2; display: block; width: 100%; height: 100%; pointer-events: none; color: var(--stage-teal); }

/* Caption and the recorder */
.stx__top { position: relative; z-index: 1; display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 14px 32px; padding: 24px 28px 0; }
.stx__captions { flex: 1 1 300px; min-width: 0; display: grid; }
.stx__caption { grid-area: 1 / 1; margin: 0; max-width: 38ch; font: 400 15px/1.5 var(--f-sans); letter-spacing: -.005em; color: rgba(var(--stage-ink), .86); text-wrap: pretty; transition: opacity .8s ease, transform 1s cubic-bezier(.2, .7, .2, 1); }
.stx__caption:not(:first-child) { opacity: 0; }
.stx.is-live .stx__caption { opacity: 0; transform: translateY(8px); transition-delay: 0s; }
.stx.is-live .stx__caption.is-on { opacity: 1; transform: none; transition-delay: .3s; }

.stx__dock { flex: none; display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 12px; box-sizing: border-box; border: 1px solid rgba(var(--stage-ink), .14); border-radius: 9px; background: var(--stage-bg); font: 500 13px/1 var(--f-sans); letter-spacing: -.005em; }
.stx__dock i { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--stage-teal); }
.stx__time { min-width: 4ch; font: 400 11px/1 var(--f-mono); text-align: right; color: var(--stage-faint); font-variant-numeric: tabular-nums; }
.stx[data-phase='idle'] .stx__dock i { background: none; box-shadow: inset 0 0 0 1.5px var(--stage-faint); }
.stx[data-phase='rec'] .stx__dock i { background: rgb(var(--stx-rec)); animation: stx-rec 1.1s ease-in-out infinite; }
.stx[data-phase='write'] .stx__dock i, .stx[data-phase='draft'] .stx__dock i { animation: stx-work .7s ease-in-out infinite alternate; }
@keyframes stx-rec { 0%, 100% { box-shadow: 0 0 0 0 rgba(var(--stx-rec), .45); } 60% { box-shadow: 0 0 0 6px rgba(var(--stx-rec), 0); } }
@keyframes stx-work { from { opacity: .35; } to { opacity: 1; } }

/* The path a call takes */
.stx__path { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 56px; padding: 26px 28px 0; }
.stx-node { min-width: 0; display: flex; flex-direction: column; gap: 9px; padding: 12px 14px 13px; box-sizing: border-box; border: 1px solid rgba(var(--stage-ink), .1); border-radius: 9px; background: linear-gradient(rgba(var(--stage-ink), .025), rgba(var(--stage-ink), .025)), var(--stage-bg); transition: border-color .4s ease; }
.stx-node.is-on { border-color: color-mix(in srgb, var(--stage-teal) 48%, transparent); }
.stx-node__name { margin: 0; font: 500 13px/1.2 var(--f-sans); letter-spacing: -.005em; }
.stx-node__slot { height: 34px; }
.stx-node__meta { margin: 0; font: 400 12px/1.35 var(--f-sans); color: var(--stage-faint); }
/* The two places a call can be read: one is picked, the other is the opt-in. */
.stx-opt { display: flex; align-items: baseline; gap: 7px; }
.stx-opt + .stx-opt { margin-top: -5px; }
.stx-opt::before { content: ''; flex: none; width: 7px; height: 7px; box-sizing: border-box; border: 1px solid rgba(var(--stage-ink), .3); border-radius: 50%; }
.stx-opt.is-picked { color: var(--stage-text); }
.stx-opt.is-picked::before { border-color: var(--stage-teal); background: var(--stage-teal); box-shadow: inset 0 0 0 1.5px var(--stage-bg); }
/* Audio the server holds: dashed when it holds none. */
.stx-segs { display: grid; grid-template-columns: repeat(10, minmax(0, 1fr)); align-items: center; gap: 4px; }
.stx-segs i { height: 18px; box-sizing: border-box; border: 1px dashed rgba(var(--stage-ink), .2); border-radius: 3px; transition: background-color .3s ease, border-color .3s ease; }
.stx-segs i.is-in { border: 1px solid transparent; background: rgba(var(--stage-ink), .42); }
.stx-segs i.is-in.is-read { background: color-mix(in srgb, var(--stage-teal) 58%, transparent); }

/* Transcript and form */
.stx__body { position: relative; z-index: 1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 48px; padding: 40px 28px 24px; }
.stx-label { margin: 0 0 10px; font: 500 11px/1.4 var(--f-mono); letter-spacing: .06em; text-transform: uppercase; color: var(--stage-faint); }
.stx-label:not(:first-child) { margin-top: 20px; }
.stx-text { margin: 0; max-width: 52ch; font: 400 14px/1.65 var(--f-sans); color: rgba(var(--stage-ink), .62); }
.stx-text mark { background: none; color: var(--stage-text); white-space: nowrap; box-shadow: inset 0 -1px 0 color-mix(in srgb, var(--stage-teal) 75%, transparent); }
.stx-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 8px; }
.stx-chips li { display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px; border: 1px solid rgba(var(--stage-ink), .14); border-radius: 999px; font: 400 12px/1.2 var(--f-sans); color: var(--stage-text); transition: color .4s ease, border-color .4s ease; }
.stx-chips li::before { content: ''; flex: none; width: 5px; height: 5px; border-radius: 50%; background: var(--stage-teal); transition: background-color .4s ease; }
.stx-chips li b { font-weight: 400; color: var(--stage-faint); transition: opacity .4s ease; }
.stx-chips li.is-none { border-style: dashed; }
.stx-chips li.is-none::before { background: none; box-shadow: inset 0 0 0 1px rgba(var(--stage-ink), .4); }

.stx-rows { margin: 0; }
.stx-row { position: relative; display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 10px; align-items: baseline; padding: 9px 0 9px 16px; border-top: 1px solid rgba(var(--stage-ink), .1); font: 400 13px/1.35 var(--f-sans); }
.stx-row::before { content: ''; position: absolute; left: 0; top: 50%; width: 5px; height: 5px; margin-top: -2.5px; border-radius: 50%; background: var(--stage-teal); transition: background-color .3s ease, box-shadow .3s ease; }
.stx-row dt { color: var(--stage-faint); }
.stx-row dd { min-width: 0; margin: 0; color: var(--stage-text); }
.stx-row dd > span { display: inline-block; transition: clip-path .45s cubic-bezier(.3, .6, .2, 1), opacity .3s ease; }
.stx-row--none::before { background: none; box-shadow: inset 0 0 0 1px rgba(var(--stage-ink), .3); }
.stx-none { padding: 2px 8px; border: 1px dashed rgba(var(--stage-ink), .22); border-radius: 999px; font-size: 12px; color: rgba(var(--stage-ink), .62); }
.stx-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; margin: 14px 0 0; font: 400 12px/1.3 var(--f-sans); color: var(--stage-faint); }
.stx-create { position: relative; overflow: hidden; padding: 9px 14px; border-radius: 6px; background: color-mix(in srgb, var(--stage-teal) 16%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--stage-teal) 40%, transparent); font: 500 13px/1 var(--f-sans); color: var(--stage-teal); transition: transform .16s ease, background-color .35s ease, color .35s ease, box-shadow .35s ease; }

/* Replay states: the rules above are the end of the call; .is-live hides what has not happened yet. */
.stx.is-live .stx-w { opacity: 0; filter: blur(3px); transition: opacity .4s ease, filter .4s ease, color .5s ease, box-shadow .5s ease; }
.stx.is-live .stx-w.is-in { opacity: 1; filter: none; }
.stx.is-live mark.stx-w:not(.is-lit) { color: inherit; box-shadow: inset 0 -1px 0 transparent; }
.stx.is-live mark.stx-w.is-lit { animation: stx-lit .9s ease; }
@keyframes stx-lit { 0% { background-color: color-mix(in srgb, var(--stage-teal) 28%, transparent); } 100% { background-color: transparent; } }
.stx.is-live .stx-row:not(.is-filled)::before { background: rgba(var(--stage-ink), .22); box-shadow: none; }
.stx.is-live .stx-row:not(.is-filled) dd > span { clip-path: inset(0 100% 0 0); opacity: 0; }
.stx.is-live .stx-row.is-filled dd > span { clip-path: inset(0 -2px 0 0); }
.stx.is-live .stx-row.is-checked::before { box-shadow: 0 0 0 3px color-mix(in srgb, var(--stage-teal) 22%, transparent); }
.stx.is-live .stx-row--none.is-checked::before { box-shadow: inset 0 0 0 1px rgba(var(--stage-ink), .3), 0 0 0 3px rgba(var(--stage-ink), .1); }
.stx.is-live .stx-chips li:not(.is-set) { border-color: rgba(var(--stage-ink), .1); border-style: solid; color: var(--stage-faint); }
.stx.is-live .stx-chips li:not(.is-set)::before { background: rgba(var(--stage-ink), .22); box-shadow: none; }
.stx.is-live .stx-chips li:not(.is-set) b { opacity: 0; }
.stx.is-live .stx-create:not(.is-ready) { background: transparent; color: var(--stage-faint); box-shadow: inset 0 0 0 1px rgba(var(--stage-ink), .16); }
.stx.is-live .stx-create.is-ready:not(.is-done) { background: var(--stage-teal); color: var(--stage-bg); box-shadow: none; }
.stx.is-live .stx-create.is-pressed { transform: scale(.94); }

/* Movements */
.stx__rail { position: relative; z-index: 3; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0 16px; margin: 0 28px; }
.stx__tab { all: unset; --h: var(--stage-teal); box-sizing: border-box; position: relative; min-width: 0; display: flex; align-items: baseline; gap: 9px; padding: 15px 0 19px; cursor: pointer; color: var(--stage-faint); transition: color .3s ease; }
.stx__tab:nth-child(3) { --h: var(--stage-blue); }
.stx__tab:nth-child(4) { --h: var(--stage-violet); }
.stx__tab[aria-pressed='true'], .stx__tab:hover { color: var(--stage-text); }
.stx__tab:focus-visible { outline: 1px solid var(--h); outline-offset: -2px; }
.stx__track { position: absolute; top: 0; left: 0; right: 0; height: 1px; overflow: hidden; background: rgba(var(--stage-ink), .18); }
.stx__bar { display: block; height: 100%; background: var(--h); transform: scaleX(0); transform-origin: left; }
.stx__idx { font: 400 11px/1 var(--f-mono); color: var(--h); }
.stx__tab > span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font: 500 13px/1 var(--f-sans); letter-spacing: -.005em; }

.stx.is-still *, .stx.is-still *::before, .stx.is-still *::after { animation: none !important; transition: none !important; }

/* What an administrator sets, under the stage */
.stx-facts { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; border: 1px solid var(--line); border-radius: 14px; background: var(--line); overflow: hidden; }
.stx-facts li { padding: 20px 22px 22px; background: var(--bg); }
.stx-facts b { display: block; margin-bottom: 8px; font: 500 14px/1.35 var(--f-sans); color: var(--text); }
.stx-facts span { font: 400 13px/1.55 var(--f-sans); color: var(--muted); }
.stx-note { margin: 14px 0 0; font: 400 12px/1.5 var(--f-sans); color: var(--faint); }

@container stx (max-width: 760px) {
  .stx__top { padding: 18px 18px 0; }
  .stx__path { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 26px 26px; padding: 20px 18px 0; }
  /* Stacked: the form follows the transcript, so each thread is a short drop; the chips come last. */
  .stx__body { display: flex; flex-direction: column; padding: 30px 18px 20px; }
  .stx-col { display: contents; }
  .stx-col--form > * { order: 2; }
  .stx-col--form > .stx-label { margin-top: 22px; }
  .stx-after { order: 3; }
  .stx-label.stx-after { margin-top: 22px; }
  .stx__rail { gap: 0 10px; margin: 0 18px; }
}
@container stx (max-width: 420px) {
  /* Equal quarters were narrower than "01 Record" or "02 Write up" on a phone, so every name ended
     in an ellipsis. Each chapter is now at least as wide as its name; the spare width is shared. */
  .stx__rail { grid-template-columns: repeat(4, minmax(max-content, 1fr)); gap: 0 4px; margin: 0 14px; }
  .stx__tab { gap: 5px; }
  .stx-node { padding: 10px 10px 11px; }
  .stx-segs { gap: 2px; }
  .stx-row { grid-template-columns: 92px minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .stx-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stx-block { margin-top: 56px; padding-top: 48px; }
}
@media (max-width: 560px) {
  .stx-facts { grid-template-columns: minmax(0, 1fr); }
}
