/* ==========================================================================
   Makhija Quantum AI - FAQ Support Chatbot Styles
   ========================================================================== */

/* CSS Custom Properties - Inherit from site when available, fallback gracefully */
:root {
  --chatbot-font: 'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Try to inherit from site CSS variables, fallback to brand values */
  --chatbot-accent: var(--brand-accent, #6366F1);
  --chatbot-secondary: var(--brand-secondary, #0EA5E9);
  --chatbot-bg-light: var(--brand-soft, #F8FAFC);
  --chatbot-bg-dark: var(--brand-950, #020617);
  --chatbot-surface-dark: var(--brand-surface, #1E293B);
  --chatbot-text-primary: var(--brand-900, #0C4A6E);
  --chatbot-text-light: #FFFFFF;
  --chatbot-text-muted: #64748B;
  --chatbot-border-light: #E2E8F0;
  --chatbot-border-dark: #334155;

  /* Layout */
  --chatbot-launcher-size: 56px;
  --chatbot-offset: 24px;
  --chatbot-panel-width: 360px;
  --chatbot-panel-height: 600px;
  --chatbot-radius: 16px;
  --chatbot-radius-sm: 12px;
  --chatbot-radius-button: 10px;

  /* Shadows */
  --chatbot-shadow: 0 10px 40px -10px rgba(0, 0, 0, 0.15);
  --chatbot-shadow-dark: 0 10px 40px -10px rgba(0, 0, 0, 0.5);

  /* Transitions */
  --chatbot-transition: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   Container
   ========================================================================== */

.chatbot-container {
  position: fixed;
  bottom: var(--chatbot-offset);
  right: var(--chatbot-offset);
  z-index: 9999;
  font-family: var(--chatbot-font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   Launcher Button
   ========================================================================== */

.chatbot-launcher {
  width: var(--chatbot-launcher-size);
  height: var(--chatbot-launcher-size);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--chatbot-accent), var(--chatbot-secondary));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--chatbot-shadow);
  transition: transform 0.2s var(--chatbot-transition),
    box-shadow 0.2s var(--chatbot-transition);
  position: relative;
}

.chatbot-launcher:hover {
  transform: scale(1.05);
  box-shadow: 0 14px 45px -10px rgba(99, 102, 241, 0.4);
}

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

.chatbot-launcher:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3), var(--chatbot-shadow);
}

.chatbot-launcher svg {
  width: 24px;
  height: 24px;
  color: var(--chatbot-text-light);
  transition: transform 0.2s var(--chatbot-transition);
}

.chatbot-launcher.is-open svg {
  transform: rotate(90deg);
}

/* Tooltip - Desktop only */
.chatbot-launcher-tooltip {
  position: absolute;
  right: calc(100% + 12px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--chatbot-surface-dark);
  color: var(--chatbot-text-light);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s var(--chatbot-transition),
    visibility 0.2s var(--chatbot-transition);
  pointer-events: none;
}

.chatbot-launcher-tooltip::after {
  content: '';
  position: absolute;
  right: -6px;
  top: 50%;
  transform: translateY(-50%);
  border: 6px solid transparent;
  border-left-color: var(--chatbot-surface-dark);
}

/* Show tooltip only on desktop hover */
@media (hover: hover) and (pointer: fine) {
  .chatbot-launcher:hover .chatbot-launcher-tooltip {
    opacity: 1;
    visibility: visible;
  }
}

/* Hide launcher when panel is open */
.chatbot-container.is-open .chatbot-launcher {
  opacity: 0;
  visibility: hidden;
  transform: scale(0.8);
}

/* ==========================================================================
   Panel
   ========================================================================== */

.chatbot-panel {
  position: absolute;
  bottom: 0;
  right: 0;
  width: var(--chatbot-panel-width);
  height: var(--chatbot-panel-height);
  background: var(--chatbot-bg-light);
  border-radius: var(--chatbot-radius);
  box-shadow: var(--chatbot-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: opacity 0.25s var(--chatbot-transition),
    visibility 0.25s var(--chatbot-transition),
    transform 0.25s var(--chatbot-transition);
}

.chatbot-container.is-open .chatbot-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Dark mode */
.dark .chatbot-panel {
  background: var(--chatbot-surface-dark);
  box-shadow: var(--chatbot-shadow-dark);
}

/* ==========================================================================
   Header
   ========================================================================== */

.chatbot-header {
  padding: 16px 20px;
  background: linear-gradient(135deg, var(--chatbot-accent), var(--chatbot-secondary));
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.chatbot-header-info {
  display: flex;
  flex-direction: column;
}

.chatbot-header-title {
  color: var(--chatbot-text-light);
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  line-height: 1.3;
}

.chatbot-header-subtitle {
  color: rgba(255, 255, 255, 0.8);
  font-size: 12px;
  font-weight: 400;
  margin: 2px 0 0 0;
}

.chatbot-header-controls {
  display: flex;
  gap: 4px;
}

.chatbot-header-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s var(--chatbot-transition);
}

.chatbot-header-btn:hover {
  background: rgba(255, 255, 255, 0.25);
}

.chatbot-header-btn:focus {
  outline: none;
  background: rgba(255, 255, 255, 0.3);
}

.chatbot-header-btn svg {
  width: 16px;
  height: 16px;
  color: var(--chatbot-text-light);
}

/* ==========================================================================
   Messages Area
   ========================================================================== */

.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: stretch;
}

/* Custom scrollbar */
.chatbot-messages::-webkit-scrollbar {
  width: 6px;
}

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

.chatbot-messages::-webkit-scrollbar-thumb {
  background: var(--chatbot-border-light);
  border-radius: 3px;
}

.chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: var(--chatbot-text-muted);
}

.dark .chatbot-messages::-webkit-scrollbar-thumb {
  background: var(--chatbot-border-dark);
}

/* ==========================================================================
   Message Bubble
   ========================================================================== */

.chatbot-message {
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: chatbot-fade-in 0.3s var(--chatbot-transition);
  max-width: 85%;
  align-self: flex-start;
}

/* Bot messages align to left */
.chatbot-message:not(.chatbot-message--user) {
  align-self: flex-start;
}

/* User messages align to right */
.chatbot-message--user {
  align-self: flex-end;
  max-width: 85%;
}

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

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chatbot-message-text {
  background: #FFFFFF;
  border: 1px solid var(--chatbot-border-light);
  border-radius: var(--chatbot-radius-sm);
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--chatbot-text-primary);
  white-space: pre-wrap;
  margin: 0;
}

/* Bot message text styling (left side) */
.chatbot-message:not(.chatbot-message--user) .chatbot-message-text {
  background: #F8FAFC;
  border-color: var(--chatbot-border-light);
  border-radius: var(--chatbot-radius-sm) var(--chatbot-radius-sm) var(--chatbot-radius-sm) 4px;
}

/* User message text styling (right side) */
.chatbot-message--user .chatbot-message-text {
  background: linear-gradient(135deg, var(--chatbot-accent), var(--chatbot-secondary));
  border: none;
  color: var(--chatbot-text-light);
  border-radius: var(--chatbot-radius-sm) var(--chatbot-radius-sm) 4px var(--chatbot-radius-sm);
}

.dark .chatbot-message-text {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--chatbot-border-dark);
  color: var(--chatbot-text-light);
}

.dark .chatbot-message:not(.chatbot-message--user) .chatbot-message-text {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--chatbot-border-dark);
}

.dark .chatbot-message--user .chatbot-message-text {
  background: linear-gradient(135deg, var(--chatbot-accent), var(--chatbot-secondary));
  border: none;
  color: var(--chatbot-text-light);
}

/* ==========================================================================
   Action Buttons
   ========================================================================== */

.chatbot-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
  width: 100%;
}

.chatbot-btn {
  width: auto;
  max-width: 100%;
  padding: 12px 16px;
  background: #FFFFFF;
  border: 1px solid var(--chatbot-border-light);
  border-radius: var(--chatbot-radius-button);
  font-family: var(--chatbot-font);
  font-size: 14px;
  font-weight: 500;
  color: var(--chatbot-text-primary);
  cursor: pointer;
  text-align: left;
  transition: all 0.15s var(--chatbot-transition);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.chatbot-btn:hover {
  background: var(--chatbot-bg-light);
  border-color: var(--chatbot-accent);
  color: var(--chatbot-accent);
}

.chatbot-btn:focus {
  outline: none;
  border-color: var(--chatbot-accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.chatbot-btn:active {
  transform: scale(0.98);
}

.chatbot-btn svg {
  width: 16px;
  height: 16px;
  opacity: 0.5;
  flex-shrink: 0;
}

.chatbot-btn:hover svg {
  opacity: 1;
}

/* Back button variant */
.chatbot-btn--back {
  background: transparent;
  border-color: transparent;
  color: var(--chatbot-text-muted);
  font-weight: 400;
}

.chatbot-btn--back:hover {
  background: var(--chatbot-bg-light);
  border-color: transparent;
  color: var(--chatbot-text-primary);
}

/* Dark mode buttons */
.dark .chatbot-btn {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--chatbot-border-dark);
  color: var(--chatbot-text-light);
}

.dark .chatbot-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: var(--chatbot-accent);
  color: var(--chatbot-text-light);
}

.dark .chatbot-btn--back {
  background: transparent;
  border-color: transparent;
  color: var(--chatbot-text-muted);
}

.dark .chatbot-btn--back:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--chatbot-text-light);
}

/* ==========================================================================
   Mobile Styles - Bottom Sheet
   ========================================================================== */

@media (max-width: 480px) {
  .chatbot-container {
    bottom: 16px;
    right: 16px;
  }

  .chatbot-panel {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 90vh;
    max-height: 90vh;
    border-radius: var(--chatbot-radius) var(--chatbot-radius) 0 0;
    transform: translateY(100%);
  }

  .chatbot-container.is-open .chatbot-panel {
    transform: translateY(0);
  }

  .chatbot-message,
  .chatbot-message--user {
    max-width: 90%;
  }

  .chatbot-user-selection {
    max-width: 90%;
  }

  .chatbot-container.is-open .chatbot-launcher {
    opacity: 0;
    visibility: hidden;
  }

  /* Mobile handle indicator */
  .chatbot-header::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
  }

  .chatbot-header {
    position: relative;
    padding-top: 24px;
  }

  .chatbot-btn {
    padding: 14px 16px;
    min-height: 48px;
  }

  /* Hide tooltip on mobile completely */
  .chatbot-launcher-tooltip {
    display: none;
  }
}

/* ==========================================================================
   Accessibility
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {

  .chatbot-launcher,
  .chatbot-panel,
  .chatbot-message,
  .chatbot-btn {
    transition: none;
    animation: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .chatbot-btn {
    border-width: 2px;
  }

  .chatbot-message-text {
    border-width: 2px;
  }
}

/* ==========================================================================
   Print - Hide chatbot
   ========================================================================== */

@media print {
  .chatbot-container {
    display: none !important;
  }
}

/* ==========================================================================
   Text Input Area
   ========================================================================== */

.chatbot-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #FFFFFF;
  border-top: 1px solid var(--chatbot-border-light);
  flex-shrink: 0;
}

.dark .chatbot-input-area {
  background: var(--chatbot-surface-dark);
  border-top-color: var(--chatbot-border-dark);
}

.chatbot-text-input {
  flex: 1;
  padding: 10px 14px;
  background: var(--chatbot-bg-light);
  border: 1px solid var(--chatbot-border-light);
  border-radius: var(--chatbot-radius-button);
  font-family: var(--chatbot-font);
  font-size: 14px;
  color: var(--chatbot-text-primary);
  outline: none;
  transition: border-color 0.15s var(--chatbot-transition),
    box-shadow 0.15s var(--chatbot-transition);
}

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

.chatbot-text-input:focus {
  border-color: var(--chatbot-accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.dark .chatbot-text-input {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--chatbot-border-dark);
  color: var(--chatbot-text-light);
}

.dark .chatbot-text-input:focus {
  border-color: var(--chatbot-accent);
}

.chatbot-send-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--chatbot-radius-button);
  background: linear-gradient(135deg, var(--chatbot-accent), var(--chatbot-secondary));
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s var(--chatbot-transition),
    opacity 0.15s var(--chatbot-transition);
  flex-shrink: 0;
}

.chatbot-send-btn:hover {
  transform: scale(1.05);
}

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

.chatbot-send-btn:focus {
  outline: none;
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.3);
}

.chatbot-send-btn svg {
  width: 18px;
  height: 18px;
  color: var(--chatbot-text-light);
}

/* ==========================================================================
   Typing Indicator
   ========================================================================== */

.chatbot-typing {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 14px 16px;
  background: #F8FAFC;
  border: 1px solid var(--chatbot-border-light);
  border-radius: var(--chatbot-radius-sm) var(--chatbot-radius-sm) var(--chatbot-radius-sm) 4px;
  width: fit-content;
  max-width: 85%;
  align-self: flex-start;
  animation: chatbot-fade-in 0.3s var(--chatbot-transition);
}

.dark .chatbot-typing {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--chatbot-border-dark);
}

.chatbot-typing-dot {
  width: 8px;
  height: 8px;
  background: var(--chatbot-accent);
  border-radius: 50%;
  animation: chatbot-typing-bounce 1.4s infinite ease-in-out both;
}

.chatbot-typing-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.chatbot-typing-dot:nth-child(2) {
  animation-delay: -0.16s;
}

.chatbot-typing-dot:nth-child(3) {
  animation-delay: 0s;
}

@keyframes chatbot-typing-bounce {

  0%,
  80%,
  100% {
    transform: scale(0.6);
    opacity: 0.5;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ==========================================================================
   Message Variants
   ========================================================================== */

/* User selection chips (right side) */
.chatbot-user-selection {
  align-self: flex-end;
  max-width: 85%;
  margin-left: auto;
  padding: 10px 16px;
  background: linear-gradient(135deg, var(--chatbot-accent), var(--chatbot-secondary));
  border: none;
  border-radius: var(--chatbot-radius-sm) var(--chatbot-radius-sm) 4px var(--chatbot-radius-sm);
  color: var(--chatbot-text-light);
  font-size: 14px;
  font-weight: 500;
  animation: chatbot-fade-in 0.3s var(--chatbot-transition);
}

.chatbot-message--ai .chatbot-message-text {
  background: #F0F9FF;
  border-color: #BAE6FD;
  position: relative;
}

.chatbot-message--ai .chatbot-message-text::before {
  content: 'AI';
  position: absolute;
  top: -8px;
  left: 10px;
  background: var(--chatbot-secondary);
  color: var(--chatbot-text-light);
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.dark .chatbot-message--ai .chatbot-message-text {
  background: rgba(14, 165, 233, 0.1);
  border-color: rgba(14, 165, 233, 0.3);
  color: var(--chatbot-text-light);
}

/* ==========================================================================
   Mobile Input Adjustments
   ========================================================================== */

@media (max-width: 480px) {
  .chatbot-input-area {
    padding: 10px 12px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .chatbot-text-input {
    padding: 12px 14px;
    font-size: 16px;
    /* Prevents iOS zoom */
  }

  .chatbot-send-btn {
    width: 44px;
    height: 44px;
  }
}