/* ============================================================
   SDI Training — AI Voice Assistant
   Copilot-style frosted-glass panel with mic, TTS, text input.
   Responsive: floats bottom-right on desktop, full-width sheet on mobile.
   ============================================================ */

/* ── Launcher button (floating, bottom-right) ──────────────── */
#sdi-voice-launcher {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  z-index: 2147483646;
  background: linear-gradient(135deg, #C2410C 0%, #EA580C 50%, #F97316 100%);
  box-shadow: 0 8px 24px rgba(194, 65, 12, 0.4), 0 2px 8px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
  animation: sdi-voice-pulse 2.5s ease-in-out infinite;
}
#sdi-voice-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 12px 32px rgba(194, 65, 12, 0.5), 0 4px 12px rgba(0,0,0,0.25);
}
#sdi-voice-launcher svg {
  width: 28px; height: 28px;
  fill: #fff;
}
@keyframes sdi-voice-pulse {
  0%, 100% { box-shadow: 0 8px 24px rgba(194,65,12,0.4), 0 0 0 0 rgba(249,115,22,0.5); }
  50% { box-shadow: 0 8px 24px rgba(194,65,12,0.4), 0 0 0 14px rgba(249,115,22,0); }
}

/* ── Overlay backdrop ──────────────────────────────────────── */
#sdi-voice-backdrop {
  position: fixed; inset: 0;
  background: rgba(11, 28, 44, 0.35);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  z-index: 2147483647;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}
#sdi-voice-backdrop.sdi-voice-open {
  opacity: 1; visibility: visible;
}

/* ── Main panel (frosted glass) ────────────────────────────── */
#sdi-voice-panel {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 400px;
  max-width: calc(100vw - 40px);
  max-height: calc(100vh - 130px);
  z-index: 2147483648;
  border-radius: 24px;
  background: linear-gradient(160deg,
    rgba(255,255,255,0.85) 0%,
    rgba(219,234,254,0.78) 50%,
    rgba(196,181,253,0.72) 100%);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255,255,255,0.6);
  box-shadow:
    0 20px 60px rgba(11,28,44,0.35),
    0 8px 24px rgba(11,28,44,0.2),
    inset 0 1px 0 rgba(255,255,255,0.8);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(20px) scale(0.96);
  opacity: 0;
  visibility: hidden;
  transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease, visibility 0.3s ease;
}
#sdi-voice-panel.sdi-voice-open {
  transform: translateY(0) scale(1);
  opacity: 1; visibility: visible;
}

/* ── Panel header ──────────────────────────────────────────── */
.sdi-voice-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.4);
  flex-shrink: 0;
}
.sdi-voice-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.sdi-voice-brand-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #F97316, #C2410C);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(194,65,12,0.3);
}
.sdi-voice-brand-icon svg { width: 18px; height: 18px; fill: #fff; }
.sdi-voice-brand-text {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  font-weight: 600;
  color: #0B1C2C;
  letter-spacing: -0.01em;
}
.sdi-voice-brand-text span {
  display: block;
  font-size: 11px;
  font-weight: 400;
  color: #4A5A68;
  margin-top: 1px;
}
.sdi-voice-expand {
  width: 32px; height: 32px;
  border-radius: 8px;
  border: none;
  background: rgba(255,255,255,0.5);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s ease;
}
.sdi-voice-expand:hover { background: rgba(255,255,255,0.8); }
.sdi-voice-expand svg { width: 16px; height: 16px; fill: #0B1C2C; }

/* ── Conversation area ─────────────────────────────────────── */
.sdi-voice-conversation {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(11,28,44,0.2) transparent;
}
.sdi-voice-conversation::-webkit-scrollbar { width: 6px; }
.sdi-voice-conversation::-webkit-scrollbar-thumb { background: rgba(11,28,44,0.2); border-radius: 3px; }

.sdi-voice-message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  animation: sdi-voice-msg-in 0.3s ease;
}
@keyframes sdi-voice-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.sdi-voice-message.assistant {
  align-self: flex-start;
  background: rgba(255,255,255,0.7);
  color: #0B1C2C;
  border-bottom-left-radius: 4px;
}
.sdi-voice-message.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #C2410C, #EA580C);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.sdi-voice-message a {
  color: #C2410C;
  text-decoration: underline;
  font-weight: 500;
}
.sdi-voice-message.user a { color: #fff; }
.sdi-voice-message ul { margin: 6px 0 0; padding-left: 18px; }
.sdi-voice-message li { margin: 2px 0; }

/* ── "Collecting context" loader ───────────────────────────── */
.sdi-voice-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  gap: 14px;
}
.sdi-voice-loader.hidden { display: none; }
.sdi-voice-sparkle {
  width: 48px; height: 48px;
  position: relative;
}
.sdi-voice-sparkle::before,
.sdi-voice-sparkle::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, #F97316, #C2410C);
  clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
  animation: sdi-voice-sparkle-spin 2s linear infinite;
}
.sdi-voice-sparkle::after {
  animation-delay: -1s;
  opacity: 0.5;
  transform: scale(0.7);
}
@keyframes sdi-voice-sparkle-spin {
  0% { transform: rotate(0deg) scale(1); }
  50% { transform: rotate(180deg) scale(1.1); }
  100% { transform: rotate(360deg) scale(1); }
}
.sdi-voice-loader-text {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 13px;
  color: #4A5A68;
  letter-spacing: 0.02em;
}

/* ── Voice waveform (when listening) ───────────────────────── */
.sdi-voice-waveform {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: 40px;
  padding: 8px;
}
.sdi-voice-waveform.hidden { display: none; }
.sdi-voice-waveform .bar {
  width: 3px;
  height: 8px;
  background: linear-gradient(180deg, #F97316, #C2410C);
  border-radius: 2px;
  animation: sdi-voice-wave 1s ease-in-out infinite;
}
.sdi-voice-waveform .bar:nth-child(2) { animation-delay: 0.1s; }
.sdi-voice-waveform .bar:nth-child(3) { animation-delay: 0.2s; }
.sdi-voice-waveform .bar:nth-child(4) { animation-delay: 0.3s; }
.sdi-voice-waveform .bar:nth-child(5) { animation-delay: 0.4s; }
.sdi-voice-waveform .bar:nth-child(6) { animation-delay: 0.5s; }
.sdi-voice-waveform .bar:nth-child(7) { animation-delay: 0.4s; }
.sdi-voice-waveform .bar:nth-child(8) { animation-delay: 0.3s; }
.sdi-voice-waveform .bar:nth-child(9) { animation-delay: 0.2s; }
@keyframes sdi-voice-wave {
  0%, 100% { height: 8px; }
  50% { height: 32px; }
}

/* ── Interim transcript (while user speaks) ────────────────── */
.sdi-voice-interim {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  color: #4A5A68;
  font-style: italic;
  text-align: center;
  padding: 0 16px 8px;
  min-height: 20px;
}

/* ── Control bar (bottom) ──────────────────────────────────── */
.sdi-voice-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  background: rgba(255,255,255,0.45);
  border-top: 1px solid rgba(255,255,255,0.5);
  flex-shrink: 0;
}
.sdi-voice-mic,
.sdi-voice-speaker {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
  background: rgba(255,255,255,0.7);
  border: 1px solid rgba(11,28,44,0.1);
}
.sdi-voice-mic:hover,
.sdi-voice-speaker:hover {
  background: rgba(255,255,255,0.95);
  transform: scale(1.05);
}
.sdi-voice-mic svg,
.sdi-voice-speaker svg { width: 18px; height: 18px; fill: #0B1C2C; }
.sdi-voice-mic.active {
  background: linear-gradient(135deg, #C2410C, #EA580C);
  border-color: transparent;
  animation: sdi-voice-mic-pulse 1.5s ease-in-out infinite;
}
.sdi-voice-mic.active svg { fill: #fff; }
@keyframes sdi-voice-mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(249,115,22,0.5); }
  50% { box-shadow: 0 0 0 10px rgba(249,115,22,0); }
}
.sdi-voice-speaker.muted svg .sdi-voice-speaker-x { display: block; }
.sdi-voice-speaker .sdi-voice-speaker-x { display: none; }

.sdi-voice-input {
  flex: 1;
  height: 40px;
  border-radius: 20px;
  border: 1px solid rgba(11,28,44,0.15);
  background: rgba(255,255,255,0.8);
  padding: 0 16px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  color: #0B1C2C;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.sdi-voice-input::placeholder { color: #8A98A6; }
.sdi-voice-input:focus {
  border-color: #F97316;
  box-shadow: 0 0 0 3px rgba(249,115,22,0.15);
}

.sdi-voice-hangup {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #DC2626, #B91C1C);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 2px 8px rgba(220,38,38,0.3);
}
.sdi-voice-hangup:hover {
  transform: scale(1.05) rotate(135deg);
  box-shadow: 0 4px 12px rgba(220,38,38,0.4);
}
.sdi-voice-hangup svg { width: 18px; height: 18px; fill: #fff; }

/* ── Hint row (above controls, first open) ─────────────────── */
.sdi-voice-hints {
  display: flex;
  gap: 6px;
  padding: 8px 14px 0;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.sdi-voice-hints.hidden { display: none; }
.sdi-voice-hint {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px;
  padding: 5px 11px;
  border-radius: 14px;
  background: rgba(255,255,255,0.6);
  border: 1px solid rgba(11,28,44,0.08);
  color: #0B1C2C;
  cursor: pointer;
  transition: all 0.2s ease;
}
.sdi-voice-hint:hover {
  background: rgba(249,115,22,0.15);
  border-color: rgba(249,115,22,0.3);
}

/* ── Permission prompt banner ──────────────────────────────── */
.sdi-voice-permission {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(253,224,71,0.25);
  border-top: 1px solid rgba(253,224,71,0.4);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 12px;
  color: #713F12;
  flex-shrink: 0;
}
.sdi-voice-permission.show { display: flex; }
.sdi-voice-permission svg { width: 16px; height: 16px; flex-shrink: 0; fill: #713F12; }

/* ── Reserve footer space so the floating launcher never
   overlaps the footer's bottom legal-links row. Applies on
   every viewport because the launcher sits bottom-right on all. */
.footer-bottom {
  padding-right: 78px !important;
}
.footer-bottom .legal {
  flex-wrap: wrap;
  row-gap: 4px;
  column-gap: 12px;
}

/* ── Responsive: mobile sheet ──────────────────────────────── */
@media (max-width: 640px) {
  #sdi-voice-launcher {
    bottom: 16px; right: 16px;
    width: 54px; height: 54px;
  }
  #sdi-voice-launcher svg { width: 24px; height: 24px; }
  #sdi-voice-panel {
    bottom: 0; right: 0; left: 0;
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    border-radius: 24px 24px 0 0;
    transform: translateY(100%);
  }
  #sdi-voice-panel.sdi-voice-open {
    transform: translateY(0);
  }
  .sdi-voice-message { max-width: 90%; font-size: 13px; }
  .footer-bottom { padding-right: 72px !important; }
}

/* ── Reduced motion ────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  #sdi-voice-launcher,
  #sdi-voice-panel,
  .sdi-voice-message,
  .sdi-voice-sparkle::before,
  .sdi-voice-sparkle::after,
  .sdi-voice-waveform .bar,
  .sdi-voice-mic.active {
    animation: none !important;
    transition: none !important;
  }
}
