.voice-widget {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 3000;
  font-family: inherit;
}

.voice-widget__fab {
  width: 56px;
  height: 56px;
  border: 0;
  border-radius: 50%;
  background: #2f5bd8;
  color: #fff;
  box-shadow: 0 14px 35px rgba(15, 35, 75, 0.25);
  cursor: pointer;
  font-size: 24px;
}

.voice-widget__panel {
  position: absolute;
  right: 0;
  bottom: 70px;
  width: min(380px, calc(100vw - 32px));
  border: 1px solid #dbe3f2;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 50px rgba(15, 35, 75, 0.22);
  overflow: hidden;
  /* The panel grows upward from the button, and with a transcript plus a parsed
     command it reaches ~500px. On a phone in landscape that put the confirm and
     reject buttons above the top of the screen, with no way to reach them. */
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 96px);
}
.voice-widget__panel[hidden] {
  display: none !important;
}

.voice-widget__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: #132642;
  color: #fff;
}

.voice-widget__close {
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 24px;
  cursor: pointer;
  /* Explicit size: the phone rule that makes form buttons full width used to
     catch this one too and push the heading off the panel. */
  width: 44px;
  min-width: 44px;
  height: 44px;
  min-height: 44px;
  flex-shrink: 0;
  padding: 0;
}

.voice-widget__header { flex-shrink: 0; }

.voice-widget__body {
  padding: 16px;
  overflow-y: auto;
}

.voice-widget__state,
.voice-widget__message {
  margin: 0 0 12px;
  color: #63708a;
}

.voice-widget__timer {
  margin-bottom: 14px;
  font-size: 28px;
  font-weight: 800;
  color: #0c1b33;
}

.voice-widget__actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* While the countdown runs the confirm button becomes the ring: it drains over
   the three seconds and carries the number of seconds left. Still a button -
   pressing it runs the command straight away instead of waiting out the ring. */
.voice-widget__go {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.voice-widget__ringwrap {
  position: relative;
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  display: inline-grid;
  place-items: center;
}

.voice-widget__ringwrap[hidden] { display: none; }

.voice-widget__ringwrap svg {
  width: 34px;
  height: 34px;
  transform: rotate(-90deg);
}

.voice-widget__ring-track,
.voice-widget__ring-fill {
  fill: none;
  stroke-width: 5;
}

.voice-widget__ring-track { stroke: rgba(255, 255, 255, 0.28); }

.voice-widget__ring-fill {
  stroke: #fff;
  stroke-linecap: round;
  /* 2 * pi * r, r = 21 */
  stroke-dasharray: 131.95;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.1s linear;
}

.voice-widget__ringwrap b {
  position: absolute;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

@media (prefers-reduced-motion: reduce) {
  .voice-widget__ring-fill { transition: none; }
}

.voice-widget .btn {
  min-height: 42px;
  border-radius: 8px;
  border: 1px solid #cfd8ea;
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
}

.voice-widget .btn.primary {
  background: #2f5bd8;
  color: #fff;
  border-color: #2f5bd8;
}

.voice-widget .btn.secondary {
  background: #fff;
  color: #132642;
}

.voice-widget__result {
  margin-top: 16px;
}

.voice-widget__text {
  margin: 6px 0 12px;
  padding: 10px;
  border-radius: 8px;
  background: #f4f7fb;
  color: #132642;
}

.voice-widget dl {
  margin: 0 0 12px;
}

.voice-widget dl div {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 8px;
  padding: 5px 0;
  border-bottom: 1px solid #eef2f8;
}

.voice-widget dt {
  color: #63708a;
}

.voice-widget dd {
  margin: 0;
  color: #0c1b33;
  font-weight: 700;
}

.voice-widget__warning {
  color: #9a5b00;
  background: #fff6df;
  border: 1px solid #ffe2a6;
  padding: 8px;
  border-radius: 8px;
}

@media (max-width: 640px) {
  .voice-widget {
    right: 12px;
    bottom: 12px;
  }
}

/* ---- push-to-talk ------------------------------------------------------ */
/* The button is the whole interaction, so it has to say what it is doing at a
   glance: idle, listening, thinking. Colour alone is not enough on a factory
   screen, hence the ring animation and the level meter. */

.voice-widget__fab {
  position: relative;
  touch-action: none;          /* a hold must not scroll the page */
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.12s ease, background 0.15s ease;
}
.voice-widget__fab:active { transform: scale(0.94); }
.voice-widget__fab-icon { position: relative; z-index: 1; }

.voice-widget__ring {
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 3px solid transparent;
  pointer-events: none;
}

[data-voice-mode="recording"] .voice-widget__fab { background: #d92f3c; }
[data-voice-mode="recording"] .voice-widget__ring {
  border-color: rgba(217, 47, 60, 0.55);
  animation: voice-pulse 1.1s ease-out infinite;
}
[data-voice-mode="requesting"] .voice-widget__fab,
[data-voice-mode="sending"] .voice-widget__fab,
[data-voice-mode="recognizing"] .voice-widget__fab { background: #7a6bd8; }
[data-voice-mode="recognizing"] .voice-widget__ring {
  border-top-color: #7a6bd8;
  animation: voice-spin 0.9s linear infinite;
}
[data-voice-mode="result"] .voice-widget__fab { background: #c58b12; }
[data-voice-mode="done"] .voice-widget__fab { background: #1f9254; }
[data-voice-mode="error"] .voice-widget__fab { background: #8b1f2b; }

@keyframes voice-pulse {
  0%   { transform: scale(1);    opacity: 0.9; }
  100% { transform: scale(1.45); opacity: 0; }
}
@keyframes voice-spin { to { transform: rotate(360deg); } }

.voice-widget__live {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.voice-widget__meter {
  flex: 1;
  height: 8px;
  border-radius: 4px;
  background: #e7ecf7;
  overflow: hidden;
}
.voice-widget__meter > i {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 4px;
  background: linear-gradient(90deg, #2f9e55, #d9a72f 70%, #d92f3c);
  transition: width 0.06s linear;
}
.voice-widget__timer {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  color: #5a6b8c;
  min-width: 52px;
  text-align: right;
}

.voice-widget__hint {
  margin: 0 0 10px;
  font-size: 12.5px;
  line-height: 1.45;
  color: #5a6b8c;
}
.voice-widget__hint kbd {
  padding: 1px 6px;
  border: 1px solid #cfd8ea;
  border-bottom-width: 2px;
  border-radius: 4px;
  background: #f6f8fc;
  font-size: 11.5px;
  font-family: inherit;
}
[data-voice-mode="recording"] .voice-widget__hint,
[data-voice-mode="result"] .voice-widget__hint { display: none; }

@media (prefers-reduced-motion: reduce) {
  .voice-widget__ring { animation: none !important; }
}
