/* Voice I/O (STT dictation + TTS playback) UI.
   Scoped, additive styles. Nothing here renders unless voice.js injects the
   controls, so pages without voice are visually unchanged. */

.voice-mic-wrap { display: inline-flex; align-items: center; gap: .4rem; vertical-align: middle; }

.voice-edit-actions {
  display: inline-flex; align-items: center; gap: .2rem;
  padding: .15rem; border: 1px solid var(--border, #33415a);
  border-radius: .55rem; background: color-mix(in srgb, var(--panel, #182236) 86%, transparent);
}
.voice-edit-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.8rem; height: 1.8rem; padding: 0 .25rem; border: 0;
  border-radius: .35rem; background: transparent; color: var(--muted, #93a4bd);
  cursor: pointer; font-size: .95rem; line-height: 1;
  transition: background .15s ease, color .15s ease;
}
.voice-edit-btn:hover { background: var(--border, #33415a); color: inherit; }
.voice-edit-btn:focus-visible { outline: 2px solid #64a9ff; outline-offset: 1px; }

.voice-mic-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 4.5rem; min-height: 44px; padding: .4rem .65rem; gap: .35rem; border-radius: 999px;
  border: 1px solid var(--border, #33415a); background: var(--panel, #182236);
  color: inherit; cursor: pointer; line-height: 1; font-size: 1rem;
  transition: background .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.voice-mic-btn:hover { border-color: #64a9ff; }
.voice-mic-btn:focus-visible { outline: 2px solid #64a9ff; outline-offset: 2px; }
.voice-mic-btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

.voice-mic-btn[data-state="listening"] {
  background: #7f1d1d; border-color: #ef4444; color: #fff;
  box-shadow: 0 0 0 0 rgba(239,68,68,.6); animation: voice-pulse 1.4s infinite;
}
.voice-mic-btn[data-state="processing"] { background: #1e3a8a; border-color: #3b82f6; }
.voice-mic-btn[data-state="connecting"] { opacity: .7; }
.voice-mic-btn[data-state="error"] { border-color: #f59e0b; }

@keyframes voice-pulse {
  0% { box-shadow: 0 0 0 0 rgba(239,68,68,.55); }
  70% { box-shadow: 0 0 0 .5rem rgba(239,68,68,0); }
  100% { box-shadow: 0 0 0 0 rgba(239,68,68,0); }
}

.voice-mic-status {
  font-size: .72rem; color: var(--muted, #93a4bd); min-width: 0;
  display: inline-flex; align-items: center; gap: .35rem;
}
.voice-mic-timer { font-variant-numeric: tabular-nums; }
.voice-level { width: 2.4rem; height: .35rem; border-radius: 999px; background: #33415a; overflow: hidden; }
.voice-level > span { display: block; height: 100%; width: 0%; background: #22c55e; transition: width .08s linear; }

/* Partial (interim) hypothesis caption — visually distinct from the draft and
   never written into the field until finalized. */
.voice-partial {
  margin-top: .3rem; font-size: .8rem; color: #93a4bd; font-style: italic;
  border-left: 2px solid #3b82f6; padding-left: .5rem; white-space: pre-wrap;
}
.voice-partial:empty { display: none; }

.voice-convert-preview {
  display: flex; align-items: center; gap: .45rem; margin-top: .35rem;
  padding: .35rem .5rem; border: 1px solid #3b82f6; border-radius: .45rem;
  background: color-mix(in srgb, #172554 78%, var(--panel, #182236));
  color: #dbeafe; font-size: .78rem; max-width: min(42rem, 100%);
}
.voice-convert-preview[hidden] { display: none; }
.voice-convert-preview > span:first-child { flex: 1 1 auto; white-space: pre-wrap; }
.voice-countdown { flex: 0 0 4rem; height: .3rem; border-radius: 999px; overflow: hidden; background: #33415a; }
.voice-countdown-bar { display: block; height: 100%; width: 100%; background: #60a5fa; transition: width .08s linear; }
.voice-convert-cancel {
  width: 1.5rem; height: 1.5rem; border: 1px solid #64748b; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; background: transparent; color: inherit; cursor: pointer;
  line-height: 1; font-size: 1rem;
}
.voice-convert-cancel:hover { background: #7f1d1d; border-color: #f87171; }

/* TTS speak controls */
.voice-speak-controls { display: inline-flex; gap: .35rem; align-items: center; margin-left: .4rem; }
.voice-speak-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .15rem .5rem; border-radius: 6px; border: 1px solid var(--border, #33415a);
  background: var(--panel, #182236); color: inherit; cursor: pointer; font-size: .78rem;
}
.voice-speak-btn:hover { border-color: #64a9ff; }
.voice-speak-btn:focus-visible { outline: 2px solid #64a9ff; outline-offset: 2px; }

/* Settings panel */
.voice-settings { display: grid; gap: 1rem; max-width: 760px; }
.voice-settings fieldset { border: 1px solid var(--border, #33415a); border-radius: 10px; padding: 1rem; }
.voice-settings legend { font-weight: 600; padding: 0 .4rem; }
.voice-settings label { display: block; margin: .5rem 0 .2rem; font-size: .85rem; }
.voice-settings .voice-row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.voice-settings .voice-row > div { flex: 1 1 200px; }
.voice-settings select, .voice-settings input[type="range"] { width: 100%; }
.voice-settings .voice-check { display: flex; align-items: center; gap: .5rem; margin: .4rem 0; }
.voice-settings .voice-check input { width: auto; }
.voice-test-out {
  margin-top: .5rem; font-size: .82rem; padding: .5rem .7rem; border-radius: 8px;
  background: #0f1830; border: 1px solid #33415a; white-space: pre-wrap; min-height: 1.2rem;
}
.voice-test-out[data-ok="true"] { border-color: #22c55e; }
.voice-test-out[data-ok="false"] { border-color: #f59e0b; }
.voice-badge {
  display: inline-block; font-size: .7rem; padding: .05rem .4rem; border-radius: 999px;
  border: 1px solid #33415a; color: #93a4bd; margin-left: .35rem;
}
.voice-badge.local-only { border-color: #22c55e; color: #86efac; }
.voice-badge.remote { border-color: #f59e0b; color: #fcd34d; }
.voice-muted { color: var(--muted, #93a4bd); font-size: .82rem; }

/* Voice Conversation operational dashboard */
.voice-pane-title { display:grid; grid-template-columns:minmax(0,1fr); gap:.45rem; font-size:1.05rem; font-weight:700; margin:.2rem 0 .55rem; }
.voice-pane-heading { min-width:0; }
.voice-title-actions { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); align-items:center; gap:.4rem; min-width:0; }
.voice-title-actions > * { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; text-align:center; }
.voice-connection-badge { color:#a9b9d2; font-size:.78rem; padding:.25rem .55rem; border:1px solid #33415a; border-radius:999px; }
.voice-connection-badge[data-state="error"] { color:#fecaca; border-color:#dc2626; }
.voice-state-badge { font-size:.68rem; font-weight:600; padding:.2rem .55rem; border-radius:999px; border:1px solid #475569; color:#cbd5e1; background:#172033; }
.voice-state-badge[data-state="listening"] { border-color:#22c55e; color:#86efac; background:#052e1a; }
.voice-state-badge[data-state="thinking"], .voice-state-badge[data-state="speaking"] { border-color:#60a5fa; color:#bfdbfe; background:#172554; }
.voice-state-badge[data-state="error"] { border-color:#f59e0b; color:#fde68a; background:#451a03; }
.voice-pipeline { display:flex; align-items:center; gap:.35rem; margin-bottom:.55rem; font-size:.68rem; }
.voice-pipeline-step { flex:1; text-align:center; padding:.28rem .2rem; border:1px solid var(--border,#33415a); border-radius:.4rem; color:#cbd5e1; background:color-mix(in srgb,var(--panel,#182236) 88%,transparent); }
.voice-pipeline-arrow { color:var(--muted,#93a4bd); }
.voice-model-card { display:flex; justify-content:space-between; gap:.5rem; padding:.45rem .6rem; border:1px solid var(--border,#33415a); border-radius:.5rem; font-size:.72rem; margin-bottom:.5rem; }
.voice-model-label { color:var(--muted,#93a4bd); }
.voice-model-value { text-align:right; font-weight:600; max-width:70%; overflow-wrap:anywhere; }
.voice-meter { display:flex; align-items:center; gap:.5rem; margin:.35rem 0 .55rem; height:.55rem; border-radius:999px; background:#1e293b; overflow:visible; }
.voice-meter-bar { display:block; height:100%; width:0%; border-radius:inherit; background:linear-gradient(90deg,#22c55e,#eab308,#ef4444); transition:width .08s linear; }
.voice-meter-text { margin-left:auto; transform:translateY(1.05rem); font-size:.66rem; color:var(--muted,#93a4bd); white-space:nowrap; }
.voice-pending { padding:.35rem .55rem; margin:.25rem 0 .5rem; border-left:3px solid #60a5fa; background:#172554; color:#bfdbfe; font-size:.74rem; }
.voice-pending[hidden] { display:none; }
.voice-metrics { font-size:.68rem; color:var(--muted,#93a4bd); padding:.25rem .45rem; border:1px dashed var(--border,#33415a); border-radius:.4rem; margin:.25rem 0 .5rem; font-variant-numeric:tabular-nums; }

/* Right sidebar: independent, closed-by-default settings and touch controls. */
.voice-conversation-pane { display:flex; flex-direction:column; gap:.65rem; width:100%; height:100%; min-width:0; min-height:0; overflow:hidden; }
.voice-conversation-pane > * { flex-shrink:0; min-width:0; max-width:100%; box-sizing:border-box; }
.voice-pane-tabs { display:grid; grid-template-columns:1fr 1fr; gap:.25rem; padding:.25rem; border:1px solid var(--border,#33415a); border-radius:.6rem; background:#0f1728; }
.voice-pane-tab { min-height:42px; border:1px solid transparent; border-radius:.45rem; background:transparent; color:var(--muted,#93a4bd); cursor:pointer; font:inherit; }
.voice-pane-tab[aria-selected="true"] { color:var(--text,#e7ecf5); background:#1d4ed833; border-color:#3b82f6; }
.voice-pane-section { display:flex; flex-direction:column; gap:.65rem; min-height:0; min-width:0; }
.voice-pane-section[hidden] { display:none; }
.voice-pane-section:not(.voice-pane-config) { flex:1 1 0; overflow:hidden; }
.voice-pane-section:not(.voice-pane-config) > .rs-chat-log { flex:1 1 12rem; min-height:8rem; max-height:none; }
.voice-pane-config { overflow:auto; }
.voice-pane-help { display:block; color:var(--muted,#93a4bd); font-size:.7rem; line-height:1.35; overflow-wrap:anywhere; }
.voice-conversation-pane .voice-pane-title { flex-wrap:wrap; gap:.5rem; margin:0; }
.voice-conversation-pane .rs-muted { margin:0; overflow-wrap:anywhere; }
.voice-pane-controls, .voice-pane-session-actions { min-width:0; }
.voice-pane-session-actions { display:flex; flex-wrap:wrap; gap:.5rem; }
.voice-pane-controls { display:grid; gap:.65rem; padding:.65rem; border:1px solid var(--border,#33415a); border-radius:.75rem; background:#0f1728; }
.voice-control-status { display:grid; grid-template-columns:auto minmax(0,1fr); align-items:center; gap:.35rem .6rem; min-width:0; }
.voice-control-status > .rs-muted { min-width:0; text-align:right; }
.voice-control-status > .voice-meter { grid-column:1 / -1; width:100%; }
.voice-control-actions { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:.5rem; min-width:0; }
.voice-control-actions > .rs-chip { width:100%; min-width:0; padding:.4rem .65rem; white-space:normal; line-height:1.2; }
.voice-control-actions > .voice-runtime-stop:not([hidden]) { grid-column:1 / -1; }
.voice-pane-controls .rs-chip { min-height:44px; }
.voice-end-btn, .voice-interrupt-btn { border-color:#c084fc; }
.voice-jobs-link { text-decoration:none; }
.voice-pane-controls .voice-pane-icon { display:inline-flex; align-items:center; justify-content:center; flex:0 0 44px; width:44px; min-width:44px; min-height:44px; padding:0; font-size:1.2rem; }
.voice-pane-control-symbol { display:block; line-height:1; pointer-events:none; }
.voice-pane-icon:first-child { color:#86efac; }
.voice-pane-icon:focus-visible, .voice-pane-group > summary:focus-visible { outline:2px solid #64a9ff; outline-offset:2px; }
.voice-pane-settings { display:grid; gap:.5rem; }
.voice-pane-group { border:1px solid var(--border,#33415a); border-radius:.6rem; overflow:hidden; }
.voice-pane-group > summary { padding:.7rem; min-height:44px; box-sizing:border-box; cursor:pointer; font-weight:600; font-size:.82rem; overflow-wrap:anywhere; }
.voice-pane-group[open] > summary { border-bottom:1px solid var(--border,#33415a); }
.voice-pane-group-body { display:grid; gap:.65rem; padding:.7rem; min-width:0; }
.voice-pane-field { display:grid; gap:.35rem; min-width:0; font-size:.78rem; color:var(--muted,#93a4bd); }
.voice-pane-field select { box-sizing:border-box; width:100%; min-width:0; max-width:100%; min-height:44px; font-size:16px; color:var(--text,#e7ecf5); background:var(--panel,#182236); border:1px solid var(--border,#33415a); border-radius:.4rem; padding:.4rem; }
.voice-pane-group-body .voice-model-card, .voice-pane-group-body .voice-metrics, .voice-pane-group-body .voice-pipeline { margin:0; overflow-wrap:anywhere; }
.voice-conversation-pane .voice-meter { margin:0 0 1rem; }
.voice-conversation-pane .rs-chat-log { min-height:8rem; max-height:none; overflow:auto; align-content:start; align-items:start; padding:.65rem; border:1px solid var(--border,#33415a); border-radius:.75rem; background:#0c1424; overscroll-behavior:contain; }
.voice-conversation-pane .rs-chat-msg { min-width:0; white-space:pre-wrap; overflow-wrap:anywhere; box-sizing:border-box; }
.voice-pane-composer { display:grid; gap:.5rem; }
.voice-pane-composer { padding:.5rem .65rem; border:1px solid var(--border,#33415a); border-radius:.65rem; background:#0f1728; }
.voice-composer-body { display:flex; align-items:flex-end; gap:.5rem; }
.voice-composer-body[hidden] { display:none; }
.voice-control-status > .voice-meter { margin-bottom:1rem; }
.voice-pane-controls .voice-end-btn { color:#fca5a5; }
.voice-pending .rs-chip { margin:.4rem .5rem 0 0; min-height:44px; }
.voice-pane-composer textarea {
  width:100%;
  min-width:0;
  max-width:100%;
  box-sizing:border-box;
  min-height:88px;
  resize:vertical;
  font-size:16px;
  border:1px solid var(--border,#33415a);
  outline:none;
}
.voice-pane-composer textarea:focus-visible {
  border-color:#3b82f6;
  outline:2px solid #3b82f6;
  outline-offset:-2px;
}
.voice-pane-composer button, .voice-pane-session-actions button { min-height:44px; }
.voice-pane-composer button { justify-self:end; }

@media (max-width: 639px) {
  .voice-conversation-pane { gap:.45rem; }
  .voice-pane-section { gap:.45rem; }
  .voice-title-actions { gap:.35rem; }
  .voice-title-actions .rs-chip { min-width:44px; padding:.35rem .55rem; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
  .voice-pane-controls { gap:.5rem; padding:.55rem; }
  .voice-control-actions { gap:.4rem; }
  .voice-pane-controls .voice-pane-icon { flex-basis:44px; }
  .voice-pane-session-actions > button { flex:1 1 9rem; min-width:0; }
  .voice-pane-composer { padding:.45rem .55rem; }
}

@media (prefers-reduced-motion: reduce) {
  .voice-mic-btn[data-state="listening"] { animation: none; }
}
