/* ======================================================
   MedTech Voice - Chatbot Widget Styles
   Glassmorphism + MTV brand dark palette
   ====================================================== */

/* --- Chatbot Launcher (Floating Bubble) --- */
.chatbot-launcher {
  position: fixed;
  bottom: 28px;
  right: 28px;
  z-index: 9998;
  width: 60px;
  height: 60px;
  border-radius: var(--radius-full);
  border: none;
  cursor: pointer;
  background: var(--color-gradient-accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 4px 20px rgba(249, 115, 22, 0.35),
    0 0 40px rgba(249, 115, 22, 0.12);
  transition:
    transform var(--transition-base),
    box-shadow var(--transition-base);
  animation: chatbot-pulse 3s ease-in-out infinite;
}

.chatbot-launcher:hover {
  transform: scale(1.08);
  box-shadow:
    0 6px 30px rgba(249, 115, 22, 0.45),
    0 0 60px rgba(249, 115, 22, 0.18);
}

.chatbot-launcher:active {
  transform: scale(0.95);
}

.chatbot-launcher svg {
  width: 28px;
  height: 28px;
  transition: transform var(--transition-base);
}

.chatbot-launcher[aria-expanded="true"] svg {
  transform: rotate(90deg) scale(0);
  opacity: 0;
}

.chatbot-launcher__close {
  position: absolute;
  width: 28px;
  height: 28px;
  opacity: 0;
  transform: rotate(-90deg) scale(0);
  transition:
    opacity var(--transition-base),
    transform var(--transition-base);
}

.chatbot-launcher[aria-expanded="true"] .chatbot-launcher__close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

@keyframes chatbot-pulse {
  0%, 100% { box-shadow: 0 4px 20px rgba(249, 115, 22, 0.35), 0 0 40px rgba(249, 115, 22, 0.12); }
  50% { box-shadow: 0 4px 20px rgba(249, 115, 22, 0.45), 0 0 60px rgba(249, 115, 22, 0.20); }
}

.chatbot-launcher[aria-expanded="true"] {
  animation: none;
}

/* --- Notification Badge --- */
.chatbot-launcher__badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  background: var(--color-accent-secondary);
  border-radius: var(--radius-full);
  border: 2px solid var(--color-bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 700;
  font-family: var(--font-primary);
  color: #fff;
  opacity: 1;
  transition: opacity var(--transition-fast);
}

.chatbot-launcher[aria-expanded="true"] .chatbot-launcher__badge {
  opacity: 0;
}

/* --- Chat Panel --- */
.chatbot-panel {
  position: fixed;
  bottom: 100px;
  right: 28px;
  z-index: 9997;
  width: 400px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100vh - 140px);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: rgba(10, 10, 10, 0.92);
  backdrop-filter: blur(24px) saturate(1.5);
  -webkit-backdrop-filter: blur(24px) saturate(1.5);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 24px 80px rgba(0, 0, 0, 0.6),
    0 0 1px rgba(255, 255, 255, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);

  /* Animation */
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition:
    opacity 350ms cubic-bezier(0.16, 1, 0.3, 1),
    transform 350ms cubic-bezier(0.16, 1, 0.3, 1);
}

.chatbot-panel[data-open="true"] {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* --- Panel Header --- */
.chatbot-header {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  background: linear-gradient(180deg, rgba(249, 115, 22, 0.06) 0%, transparent 100%);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
}

.chatbot-header__avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--color-gradient-accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  position: relative;
}

.chatbot-header__avatar svg {
  width: 22px;
  height: 22px;
  color: #fff;
}

.chatbot-header__status {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 10px;
  height: 10px;
  background: #22c55e;
  border-radius: var(--radius-full);
  border: 2px solid var(--color-bg-secondary);
}

.chatbot-header__info {
  flex: 1;
  min-width: 0;
}

.chatbot-header__name {
  font-family: var(--font-heading);
  font-size: var(--font-size-base);
  font-weight: var(--font-weight-semibold);
  color: var(--color-text-primary);
  letter-spacing: var(--letter-spacing-wide);
  text-transform: uppercase;
  line-height: 1.2;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* AI Badge - persistent transparency indicator (EU AI Act Article 50) */
.chatbot-ai-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 1px 6px;
  font-family: var(--font-primary);
  font-size: 9px;
  font-weight: var(--font-weight-bold);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #fff;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  border-radius: var(--radius-full);
  line-height: 1.4;
}

.chatbot-header__subtitle {
  font-family: var(--font-primary);
  font-size: var(--font-size-xs);
  color: var(--color-text-secondary);
  line-height: 1.4;
}

.chatbot-header__close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}

.chatbot-header__close:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text-primary);
}

/* --- Speaker Toggle --- */
.chatbot-header__speaker {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast), color var(--transition-fast);
  flex-shrink: 0;
}

.chatbot-header__speaker:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text-primary);
}

.chatbot-header__speaker .speaker-off {
  display: none;
}

.chatbot-header__speaker[data-enabled="false"] .speaker-on {
  display: none;
}

.chatbot-header__speaker[data-enabled="false"] .speaker-off {
  display: block;
}

.chatbot-header__speaker[data-enabled="true"] {
  color: var(--color-accent-light);
}

/* --- Speaking State (avatar pulses while bot talks) --- */
.chatbot-panel[data-speaking="true"] .chatbot-header__avatar {
  animation: chatbot-speaking-pulse 1.2s ease-in-out infinite;
}

.chatbot-panel[data-speaking="true"] .chatbot-header__status {
  background: var(--color-accent-primary);
  animation: chatbot-speaking-dot 1.2s ease-in-out infinite;
}

@keyframes chatbot-speaking-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(249, 115, 22, 0.25); }
  50% { box-shadow: 0 0 0 8px rgba(249, 115, 22, 0); }
}

@keyframes chatbot-speaking-dot {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.4); }
}

/* --- Messages Area --- */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4) var(--space-4) var(--space-2);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar {
  width: 4px;
}

.chatbot-messages::-webkit-scrollbar-track {
  background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius-full);
}

/* --- Message Bubbles --- */
.chatbot-msg {
  max-width: 85%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-family: var(--font-primary);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  animation: chatbot-msg-in 400ms cubic-bezier(0.16, 1, 0.3, 1) both;
  word-wrap: break-word;
}

.chatbot-msg--bot {
  align-self: flex-start;
  background: var(--color-bg-card);
  color: var(--color-text-primary);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--color-border);
}

.chatbot-msg--user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(249, 115, 22, 0.18) 0%, rgba(249, 115, 22, 0.12) 100%);
  color: var(--color-text-primary);
  border-bottom-right-radius: 4px;
  border: 1px solid rgba(249, 115, 22, 0.18);
}

/* AI disclosure system message */
.chatbot-msg--system {
  align-self: stretch;
  max-width: 100%;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.2);
  color: var(--color-text-secondary);
  font-size: 11px;
  line-height: 1.5;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
}

.chatbot-msg--system a {
  color: var(--color-accent-light);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chatbot-msg--bot a {
  color: var(--color-accent-light);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chatbot-msg--bot strong {
  color: var(--color-accent-light);
  font-weight: var(--font-weight-semibold);
}

/* Typing indicator */
.chatbot-msg--typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: var(--space-3) var(--space-4);
  min-width: 60px;
}

.chatbot-msg--typing .dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--color-text-muted);
  animation: chatbot-typing 1.4s ease-in-out infinite;
}

.chatbot-msg--typing .dot:nth-child(2) { animation-delay: 0.2s; }
.chatbot-msg--typing .dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatbot-typing {
  0%, 60%, 100% { opacity: 0.3; transform: scale(0.8); }
  30% { opacity: 1; transform: scale(1); }
}

@keyframes chatbot-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* --- Quick Actions / Chips --- */
.chatbot-chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  margin-bottom: var(--space-2);
  animation: chatbot-msg-in 400ms cubic-bezier(0.16, 1, 0.3, 1) 200ms both;
}

.chatbot-chip {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-full);
  border: 1px solid rgba(249, 115, 22, 0.20);
  background: rgba(249, 115, 22, 0.05);
  color: var(--color-accent-light);
  font-family: var(--font-primary);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    transform var(--transition-fast);
  white-space: nowrap;
}

.chatbot-chip:hover {
  background: rgba(249, 115, 22, 0.10);
  border-color: rgba(249, 115, 22, 0.35);
  transform: translateY(-1px);
}

.chatbot-chip:active {
  transform: scale(0.97);
}

/* --- Input Area --- */
.chatbot-input {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--color-border);
  background: rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

.chatbot-input__field {
  flex: 1;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--color-text-primary);
  font-family: var(--font-primary);
  font-size: var(--font-size-sm);
  line-height: var(--line-height-normal);
  resize: none;
  outline: none;
  min-height: 40px;
  max-height: 100px;
  transition:
    border-color var(--transition-fast),
    background var(--transition-fast);
}

.chatbot-input__field::placeholder {
  color: var(--color-text-muted);
}

.chatbot-input__field:focus {
  border-color: rgba(249, 115, 22, 0.35);
  background: rgba(255, 255, 255, 0.06);
}

.chatbot-input__btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background var(--transition-fast),
    transform var(--transition-fast),
    opacity var(--transition-fast);
  flex-shrink: 0;
}

/* Send button */
.chatbot-input__send {
  background: var(--color-accent-primary);
  color: #fff;
}

.chatbot-input__send:hover {
  background: var(--color-accent-light);
  transform: scale(1.05);
}

.chatbot-input__send:disabled {
  opacity: 0.4;
  cursor: default;
  transform: none;
}

/* Voice button */
.chatbot-input__voice {
  background: rgba(255, 255, 255, 0.06);
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
}

.chatbot-input__voice:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--color-text-primary);
}

.chatbot-input__voice[data-listening="true"] {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #ef4444;
  animation: chatbot-voice-pulse 1.5s ease-in-out infinite;
}

@keyframes chatbot-voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* Active conversation mode (persistent glow) */
.chatbot-input__voice--active {
  background: rgba(249, 115, 22, 0.10) !important;
  border-color: rgba(249, 115, 22, 0.35) !important;
  color: var(--color-accent-light) !important;
  box-shadow: 0 0 12px rgba(249, 115, 22, 0.18);
}

/* --- Voice Waveform Visualizer --- */
.chatbot-voice-indicator {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: var(--space-2) 0;
}

.chatbot-voice-indicator[data-active="true"] {
  display: flex;
}

.chatbot-voice-indicator__bar {
  width: 3px;
  height: 16px;
  background: var(--color-accent-primary);
  border-radius: var(--radius-full);
  animation: chatbot-wave 1s ease-in-out infinite;
}

.chatbot-voice-indicator__bar:nth-child(1) { animation-delay: 0s; height: 10px; }
.chatbot-voice-indicator__bar:nth-child(2) { animation-delay: 0.1s; height: 16px; }
.chatbot-voice-indicator__bar:nth-child(3) { animation-delay: 0.2s; height: 12px; }
.chatbot-voice-indicator__bar:nth-child(4) { animation-delay: 0.3s; height: 18px; }
.chatbot-voice-indicator__bar:nth-child(5) { animation-delay: 0.4s; height: 10px; }

@keyframes chatbot-wave {
  0%, 100% { transform: scaleY(0.5); opacity: 0.5; }
  50% { transform: scaleY(1); opacity: 1; }
}

/* --- Calendar Embed --- */
.chatbot-calendar {
  padding: var(--space-3);
  animation: chatbot-msg-in 400ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

.chatbot-calendar iframe {
  width: 100%;
  height: 360px;
  border: none;
  border-radius: var(--radius-md);
  background: var(--color-bg-card);
}

/* --- Powered By --- */
.chatbot-footer {
  text-align: center;
  padding: var(--space-1) var(--space-4) var(--space-2);
  font-family: var(--font-primary);
  font-size: 10px;
  color: var(--color-text-muted);
  letter-spacing: var(--letter-spacing-wide);
  flex-shrink: 0;
}

/* --- Mobile Responsive --- */
@media (max-width: 480px) {
  .chatbot-launcher {
    bottom: 20px;
    right: 20px;
    width: 54px;
    height: 54px;
  }

  .chatbot-panel {
    bottom: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    height: 100vh; /* fallback for older browsers */
    max-height: 100dvh;
    max-height: -webkit-fill-available;
    border-radius: 0;
  }

  @supports (height: 100dvh) {
    .chatbot-panel {
      height: 100dvh;
      max-height: 100dvh;
    }
  }

  .chatbot-panel[data-open="true"] {
    transform: translateY(0);
  }

  .chatbot-header {
    padding: var(--space-4) var(--space-4);
    padding-top: calc(var(--space-4) + env(safe-area-inset-top, 0px));
  }

  .chatbot-footer {
    padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom, 0px));
  }
}

@media (min-width: 481px) and (max-width: 768px) {
  .chatbot-panel {
    width: 360px;
    height: 500px;
  }
}
