/* The voice: the microphone of the top bar, the panel of the router (home-voice.js,
   voice-view.js) and dictation into the text fields. The parts the voice of a row can use
   again: .mic, .wave, .v-confirm, .v-tap. Colours and sizes are the tokens of home.css. */

/* The microphone: a round button in the accent; it pulses while a line is open. */
.mic { flex: none; width: 34px; height: 34px; padding: 0; border-radius: 50%; border: 1px solid var(--accent); background: var(--accent-soft); color: var(--accent); display: inline-grid; place-items: center; cursor: pointer; }
.mic .ic { width: 16px; height: 16px; }
.mic:hover { filter: brightness(1.08); }
.mic:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.mic.on { background: var(--accent); color: var(--on-accent); box-shadow: 0 0 0 5px var(--accent-soft); animation: mic-pulse 1.4s infinite; }
.mic.on.muted { background: var(--sunk); color: var(--muted); border-color: var(--muted); box-shadow: none; animation: none; }
@keyframes mic-pulse { 50% { box-shadow: 0 0 0 10px transparent; } }
@media (prefers-reduced-motion: reduce) { .mic.on { animation: none; } }

.mic:disabled { opacity: .55; cursor: default; animation: none; }

/* Dictation into a text field (voice-view.js dictateButton, dictatePartial): the microphone
   beside Send of the answer box and under the prompt of New session, and the grey line of the
   words the recognizer is not sure of yet. */
.mic.dictate { width: 32px; height: 32px; }
.dictate-partial { margin: 4px 2px 0; font-size: .8rem; font-style: italic; color: var(--muted); overflow-wrap: anywhere; }
.dictate-partial[hidden] { display: none; }
.np-dictate { display: flex; align-items: center; gap: 8px; }
.np-dictate .dictate-partial { margin: 0; flex: 1; min-width: 0; }

/* The level of the microphone: the wiring sets each bar's height. */
.wave { display: inline-flex; gap: 3px; align-items: center; height: 22px; }
.wave i { width: 3px; height: 4px; background: var(--accent); border-radius: 2px; transition: height .12s; }

/* The panel: above the page at the right on the desk, at the foot of the screen on the phone.
   It is a popover, so it stays above a dialog the voice opened. */
.voice-panel { position: fixed; inset: 64px 16px auto auto; margin: 0; padding: 0; width: min(380px, calc(100vw - 32px)); max-height: calc(100dvh - 96px);
  background: var(--surface); color: var(--ink); border: 1px solid var(--accent); border-radius: 12px; box-shadow: 0 16px 48px rgba(0, 0, 0, .35); overflow: hidden; }
.voice-panel:popover-open, .voice-panel:not([popover]):not([hidden]) { display: flex; flex-direction: column; }
.voice-panel .v-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.voice-panel .v-head b { font-size: .9rem; }
.voice-panel .v-state { margin-left: auto; font-size: .76rem; color: var(--muted); text-align: right; min-width: 0; overflow-wrap: anywhere; }
.voice-panel .v-state.bad { color: var(--bad); }
.voice-panel .v-log { flex: 1 1 auto; min-height: 60px; max-height: 52vh; overflow: auto; padding: 10px 12px; display: grid; gap: 8px; align-content: start; }
.voice-panel .v-msg { padding: 7px 10px; border-radius: 10px; font-size: .86rem; max-width: 92%; overflow-wrap: anywhere; }
.voice-panel .v-msg.me { justify-self: end; background: var(--sunk); }
.voice-panel .v-msg.ai { justify-self: start; border: 1px solid var(--line); }
.voice-panel .v-tool { justify-self: start; font-family: var(--f-mono); font-size: .72rem; color: var(--muted); border-left: 2px solid var(--line); padding-left: 8px; overflow-wrap: anywhere; }
.voice-panel .v-note { margin: 0; font-size: .78rem; color: var(--muted); }
.v-confirm { border: 1px solid var(--warn); background: var(--warn-soft); border-radius: 10px; padding: 9px 10px; font-size: .86rem; display: grid; gap: 8px; }
.v-confirm .what { font-family: var(--f-mono); font-size: .8rem; background: var(--bg); border-radius: 6px; padding: 6px 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.v-confirm .btns { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.v-confirm small { color: var(--muted); }
.v-tap { border: 1px dashed var(--bad); border-radius: 10px; padding: 8px 10px; font-size: .82rem; color: var(--bad); }
.voice-panel .v-foot { display: flex; gap: 6px; padding: 8px 12px; border-top: 1px solid var(--line); flex-wrap: wrap; align-items: center; }
.voice-panel .v-foot .act[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.voice-panel .v-hint { font-size: .74rem; color: var(--muted); }
/* Push to talk: the pad to hold. touch-action and user-select keep a long press on a phone from
   scrolling or selecting; the pressed pad takes the accent. */
.voice-panel .v-hold { display: grid; justify-items: center; gap: 2px; margin: 8px 12px 0; padding: 12px; border: 1px dashed var(--line); border-radius: 10px; background: var(--sunk); color: var(--ink); cursor: pointer; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.voice-panel .v-hold svg { width: 22px; height: 22px; }
.voice-panel .v-hold small { color: var(--muted); font-size: .74rem; text-align: center; }
.voice-panel .v-hold[aria-pressed="true"] { border-style: solid; border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.mic[data-voice] { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }

/* The voice of one row (home-row-voice.js): a pop-up next to the speech icon of its row. The
   wiring sets --rv-top or --rv-bottom and --rv-left from the place of the icon (the CSSOM);
   without them it sits at the bottom right. In the session dialog it is a box of the dialog
   (a modal dialog makes the page behind it inert), at the bottom right of the dialog. */
.act.rv:hover { color: var(--accent); border-color: var(--accent); }
.rvpop { position: fixed; z-index: 40; top: var(--rv-top, auto); bottom: var(--rv-bottom, 16px); left: var(--rv-left, auto); right: var(--rv-right, 16px);
  width: min(380px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto;
  background: var(--surface); color: var(--ink); border: 1px solid var(--accent); border-radius: 12px; box-shadow: 0 16px 48px rgba(0, 0, 0, .4); }
.rvpop[hidden] { display: none; }
.dlg > .rvpop { position: absolute; top: auto; left: auto; bottom: 12px; right: 12px; max-height: calc(100% - 24px); }
.rvpop .rv-h { display: flex; gap: 8px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: .86rem; }
.rvpop .rv-h > .ic { color: var(--accent); flex: none; }
.rvpop .rv-h b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rvpop .rv-ctx { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 12px 0; }
.rvpop .rv-ctx:empty { display: none; }
.rvpop .rv-ctx span { font-size: .7rem; border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; color: var(--muted); overflow-wrap: anywhere; }
.rvpop .rv-rec { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.rvpop .rv-dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.rvpop .rv-dot.on { background: var(--bad); animation: rv-blink 1.2s infinite; }
.rvpop .rv-dot.paused { background: var(--muted); }
@keyframes rv-blink { 50% { opacity: .35; } }
/* The browser's recognition gives no level: the bars move on their own while it records. */
.rvpop .rv-dot.on ~ .rv-wave i { animation: rv-wave 1s ease-in-out infinite; }
.rvpop .rv-dot.on ~ .rv-wave i:nth-child(2n) { animation-delay: .25s; }
.rvpop .rv-dot.on ~ .rv-wave i:nth-child(3n) { animation-delay: .5s; }
@keyframes rv-wave { 50% { height: 14px; } }
@media (prefers-reduced-motion: reduce) { .rvpop .rv-dot.on, .rvpop .rv-dot.on ~ .rv-wave i { animation: none; } }
.rvpop .rv-time { font-family: var(--f-mono); font-size: .8rem; color: var(--muted); }
.rvpop .rv-state { margin-left: auto; font-size: .76rem; color: var(--muted); }
.rvpop .rv-said { margin: 0 12px; padding: 7px 9px; background: var(--sunk); border-radius: 8px; font-size: .86rem; min-height: 34px; max-height: 140px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
.rvpop .rv-partial { margin: 4px 12px 0; }
.rvpop .rv-note { margin: 6px 12px 0; font-size: .78rem; color: var(--muted); }
.rvpop .rv-note[hidden] { display: none; }
.rvpop textarea { display: block; box-sizing: border-box; margin: 8px 12px 0; width: calc(100% - 24px); min-height: 54px; max-height: 160px; resize: vertical;
  background: var(--bg); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; font: inherit; font-size: .82rem; }
/* Talk to this session: the line of the recording, the bar of the pause that ends a message,
   the target line above the box (amber when it changed), the listen line, the last send. */
.rvpop .rv-line { margin: 0 12px 6px; font-size: .78rem; color: var(--muted); }
.rvpop .rv-line:empty { display: none; }
.rvpop .rv-sil { margin: 0 12px 6px; height: 3px; border-radius: 2px; background: var(--line); overflow: hidden; }
.rvpop .rv-sil i { display: block; width: 0; height: 100%; background: var(--accent); transition: width .2s linear; }
.rvpop .rv-target { margin: 8px 12px 0; padding: 6px 9px; border-radius: 8px; border: 1px solid var(--line); font-size: .8rem; }
.rvpop .rv-target.warn { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.rvpop .rv-target[hidden], .rvpop .rv-yes[hidden], .rvpop .rv-sent[hidden], .rvpop textarea[hidden] { display: none; }
.rvpop .rv-yes { margin: 6px 12px 0; font-size: .78rem; color: var(--muted); }
.rvpop .rv-sent { margin: 6px 12px 0; font-size: .78rem; color: var(--ok); }
.rvpop .rv-hint { font-size: .74rem; color: var(--muted); align-self: center; }
.rvpop .rv-hold { touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.rvpop .rv-rb { margin: 8px 12px 0; }
.rvpop .rv-rb:empty { display: none; }
.rvpop .rv-rb .what { max-height: 160px; overflow: auto; }
.rvpop .rv-warn { margin: 6px 0 0; font-size: .78rem; color: var(--warn); }
.rvpop .rv-result { margin: 0; padding: 7px 9px; border-radius: 8px; font-size: .84rem; border: 1px solid var(--line); }
.rvpop .rv-result.ok { border-color: var(--ok); background: var(--ok-soft); }
.rvpop .rv-result.bad { border-color: var(--bad); background: var(--bad-soft); }
.rvpop .rv-btns { display: flex; gap: 6px; padding: 10px 12px; flex-wrap: wrap; }
.rvpop .rv-btns:empty { padding: 6px 0 0; }
.rvpop .act[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

/* "Talk to this session" above the answer box of the session dialog. */
.c-talk { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.c-talk span { font-size: .76rem; color: var(--muted); }

@media (max-width: 559px) {
  .voice-panel { inset: auto 8px 8px 8px; width: auto; max-height: 70dvh; }
  .voice-panel .v-log { max-height: 40dvh; }
  /* The pop-up of a row on the phone: at the foot of the screen, the whole width. */
  .rvpop, .dlg > .rvpop { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 75dvh; }
}
