/**
 * Signal Pilot Chatbot - Enhanced Design
 * Based on the superior docs chatbot design
 * 400px × 600px optimal dimensions | Purple gradient | Smooth animations
 */

/* ========================================
   CHATBOT TOGGLE BUTTON
   ======================================== */

.sp-chatbot-toggle,
.sp-assist-btn {
  position: fixed !important;
  bottom: 2rem !important;
  right: 2rem !important;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.14);
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000; /* Above cookie banner (9999) */
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  top: auto !important;
  left: auto !important;
  transform: none !important;
}

.sp-chatbot-toggle:hover,
.sp-assist-btn:hover {
  transform: scale(1.1);
  background: rgba(255,255,255,.1);
  box-shadow: 0 6px 20px rgba(0,0,0,.4);
}

.sp-chatbot-toggle:active,
.sp-assist-btn:active {
  transform: scale(0.95);
}

.sp-chatbot-toggle svg,
.sp-assist-btn svg {
  width: 28px !important;
  height: 28px !important;
  stroke: #9fdcff !important;
  fill: none !important;
  stroke-width: 2 !important;
}

/* Light mode support */
html[data-theme="light"] .sp-chatbot-toggle,
.sp-assist-btn {
  background: #f6f8fc;
  border-color: #d7def0;
  box-shadow: 0 4px 12px rgba(0,0,0,.1);
}

html[data-theme="light"] .sp-chatbot-toggle:hover,
.sp-assist-btn:hover {
  background: #eef1f9;
  box-shadow: 0 6px 20px rgba(0,0,0,.15);
}

html[data-theme="light"] .sp-chatbot-toggle svg,
.sp-assist-btn svg {
  stroke: #0f1524 !important;
  fill: none !important;
  stroke-width: 2 !important;
}

/* Mobile: Smaller button to not cover content, with safe area */
@media (max-width: 768px) {
  .sp-chatbot-toggle,
.sp-assist-btn {
    width: 48px !important;
    height: 48px !important;
    bottom: max(1rem, calc(1rem + env(safe-area-inset-bottom))) !important;
    right: 1rem !important;
    position: fixed !important; /* Ensure sticky on mobile */
    top: auto !important;
    left: auto !important;
    transform: none !important;
    -webkit-tap-highlight-color: transparent;
  }

  .sp-chatbot-toggle svg,
.sp-assist-btn svg {
    width: 24px;
    height: 24px;
  }
}

/* ========================================
   CHAT WINDOW
   ======================================== */

.sp-chatbot-window {
  position: fixed;
  bottom: 6rem;
  right: 2rem;
  width: 400px;
  max-width: calc(100vw - 40px);
  height: 600px;
  max-height: calc(100vh - 120px);
  background: #ffffff;
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 10001; /* Above toggle button and cookie banner */
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sp-chatbot-window.active {
  display: flex;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
  .sp-chatbot-window {
    background: #1a202c;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
  }
}

/* ========================================
   HEADER
   ======================================== */

.sp-chatbot-header {
  padding: 1rem 1.25rem;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sp-chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sp-chatbot-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sp-chatbot-avatar svg {
  width: 20px;
  height: 20px;
  fill: white;
}

.sp-chatbot-title {
  font-weight: 700;
  font-size: 1rem;
  color: white;
}

.sp-chatbot-status {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.sp-chatbot-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #3ed598;
  box-shadow: 0 0 8px rgba(62, 213, 152, 0.6);
}

.sp-chatbot-close {
  background: transparent;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: all 0.2s ease;
}

.sp-chatbot-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* ========================================
   MESSAGES CONTAINER
   ======================================== */

.sp-chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(102, 126, 234, 0.3) transparent;
}

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

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

.sp-chatbot-messages::-webkit-scrollbar-thumb {
  background: rgba(102, 126, 234, 0.3);
  border-radius: 3px;
}

.sp-chatbot-messages::-webkit-scrollbar-thumb:hover {
  background: rgba(102, 126, 234, 0.5);
}

@media (prefers-color-scheme: dark) {
  .sp-chatbot-messages {
    background: #1a202c;
  }
}

/* ========================================
   MESSAGE BUBBLES
   ======================================== */

.sp-chatbot-message {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  animation: messageSlide 0.3s ease;
}

@keyframes messageSlide {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.sp-chatbot-message.user {
  flex-direction: row-reverse;
}

.sp-chatbot-message .sp-chatbot-avatar {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
}

.sp-chatbot-bubble {
  padding: 0.75rem 1rem;
  border-radius: 12px;
  line-height: 1.5;
  max-width: 80%;
  word-wrap: break-word;
  font-size: 14px;
}

.sp-chatbot-bot-message .sp-chatbot-bubble {
  background: #f5f7fb;
  color: #1a202c;
  border-radius: 12px 12px 12px 4px;
  margin-left: 40px;
}

.sp-chatbot-user-message .sp-chatbot-bubble {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-radius: 12px 12px 4px 12px;
  margin-left: auto;
}

@media (prefers-color-scheme: dark) {
  .sp-chatbot-bot-message .sp-chatbot-bubble {
    background: #2d3748;
    color: #e2e8f0;
  }
}

/* Markdown support in bubbles */
.sp-chatbot-bubble strong {
  font-weight: 700;
  color: inherit;
}

.sp-chatbot-bubble em {
  font-style: italic;
}

.sp-chatbot-bubble a {
  color: #667eea;
  text-decoration: underline;
  transition: color 0.2s ease;
}

.sp-chatbot-bubble a:hover {
  color: #764ba2;
}

.sp-chatbot-user-message .sp-chatbot-bubble a {
  color: rgba(255, 255, 255, 0.9);
}

.sp-chatbot-bubble ul,
.sp-chatbot-bubble ol {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

.sp-chatbot-bubble li {
  margin: 0.25rem 0;
}

.sp-chatbot-bubble code {
  background: rgba(0, 0, 0, 0.1);
  padding: 0.125rem 0.375rem;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.9em;
}

.sp-chatbot-user-message .sp-chatbot-bubble code {
  background: rgba(255, 255, 255, 0.2);
}

/* ========================================
   TYPING INDICATOR
   ======================================== */

.sp-chatbot-typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.75rem 1rem;
}

.sp-chatbot-typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #cbd5e0;
  animation: typing 1.4s infinite;
}

.sp-chatbot-typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.sp-chatbot-typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.6;
  }
  30% {
    transform: translateY(-10px);
    opacity: 1;
  }
}

/* ========================================
   QUICK ACTION BUTTONS
   ======================================== */

.sp-chatbot-quick-actions {
  padding: 0.75rem 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  border-top: 1px solid #e2e8f0;
  background: #f9fafb;
}

@media (prefers-color-scheme: dark) {
  .sp-chatbot-quick-actions {
    background: #2d3748;
    border-top-color: #4a5568;
  }
}

.sp-chatbot-quick-btn {
  padding: 8px 16px;
  background: #edf2f7;
  border: 1px solid #e2e8f0;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.sp-chatbot-quick-btn:hover {
  background: #e2e8f0;
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

@media (prefers-color-scheme: dark) {
  .sp-chatbot-quick-btn {
    background: #4a5568;
    border-color: #718096;
    color: #e2e8f0;
  }

  .sp-chatbot-quick-btn:hover {
    background: #718096;
  }
}

/* ========================================
   INPUT AREA
   ======================================== */

.sp-chatbot-input-area {
  padding: 1rem 1.25rem;
  border-top: 1px solid #e2e8f0;
  background: white;
  display: flex;
  gap: 0.75rem;
  align-items: flex-end;
}

@media (prefers-color-scheme: dark) {
  .sp-chatbot-input-area {
    background: #2d3748;
    border-top-color: #4a5568;
  }
}

.sp-chatbot-input {
  flex: 1;
  padding: 0.625rem 0.875rem;
  background: #f5f7fb;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  color: #1a202c;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  line-height: 1.5;
  transition: all 0.2s ease;
}

.sp-chatbot-input:focus {
  border-color: #667eea;
  background: white;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.sp-chatbot-input::placeholder {
  color: #a0aec0;
}

@media (prefers-color-scheme: dark) {
  .sp-chatbot-input {
    background: #1a202c;
    border-color: #4a5568;
    color: #e2e8f0;
  }

  .sp-chatbot-input:focus {
    background: #2d3748;
    border-color: #667eea;
  }

  .sp-chatbot-input::placeholder {
    color: #718096;
  }
}

.sp-chatbot-send {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s ease;
}

.sp-chatbot-send:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.sp-chatbot-send:active {
  transform: translateY(0);
}

.sp-chatbot-send svg {
  width: 18px;
  height: 18px;
  fill: white;
}

.sp-chatbot-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

/* ========================================
   FOOTER
   ======================================== */

.sp-chatbot-footer {
  padding: 0.75rem 1.25rem;
  background: #f9fafb;
  border-top: 1px solid #e2e8f0;
  text-align: center;
}

@media (prefers-color-scheme: dark) {
  .sp-chatbot-footer {
    background: #2d3748;
    border-top-color: #4a5568;
  }
}

.sp-chatbot-footer-text {
  font-size: 0.75rem;
  color: #718096;
}

.sp-chatbot-footer-text a {
  color: #667eea;
  text-decoration: none;
  transition: color 0.2s ease;
}

.sp-chatbot-footer-text a:hover {
  color: #764ba2;
}

/* ========================================
   MOBILE RESPONSIVE
   ======================================== */

/* Tablet - align with theme toggle */
@media (max-width: 768px) {
  .sp-chatbot-toggle,
.sp-assist-btn {
    width: 60px;
    height: 60px;
    bottom: 1rem;
    right: 1rem;
    position: fixed; /* Ensure sticky on mobile */
  }

  .sp-chatbot-toggle svg,
.sp-assist-btn svg {
    width: 26px;
    height: 26px;
  }
}

/* Small mobile screens - make smaller to save space */
@media (max-width: 480px) {
  .sp-chatbot-toggle,
.sp-assist-btn {
    width: 48px;
    height: 48px;
    bottom: 1rem;
    right: 1rem;
    position: fixed; /* Ensure sticky on mobile */
  }

  .sp-chatbot-toggle svg,
.sp-assist-btn svg {
    width: 20px;
    height: 20px;
  }
}

/* Small mobile screens - adjust chatbot window */
@media (max-width: 480px) {
  .sp-chatbot-window {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 85vh; /* Don't take full screen - leave room for top */
    max-width: none;
    max-height: 85vh;
    border-radius: 16px 16px 0 0; /* Rounded top corners only */
  }

  .sp-chatbot-header {
    padding: 0.75rem 1rem;
  }

  .sp-chatbot-messages {
    padding: 1rem;
  }

  .sp-chatbot-bubble {
    max-width: 85%;
    font-size: 14px;
  }

  .sp-chatbot-quick-actions {
    padding: 0.5rem 1rem;
  }

  .sp-chatbot-quick-btn {
    font-size: 12px;
    padding: 6px 12px;
  }

  .sp-chatbot-input-area {
    padding: 0.75rem 1rem;
  }

  .sp-chatbot-input {
    font-size: 16px; /* Prevent iOS zoom on focus */
  }
}

/* Ultra-small screens - even smaller buttons */
@media (max-width: 380px) {
  .sp-chatbot-toggle,
.sp-assist-btn {
    width: 44px;
    height: 44px;
    bottom: 1rem;
    right: 1rem;
    position: fixed; /* Ensure sticky on mobile */
  }

  .sp-chatbot-toggle svg,
.sp-assist-btn svg {
    width: 18px;
    height: 18px;
  }
}

/* ========================================
   ACCESSIBILITY
   ======================================== */

.sp-chatbot-toggle:focus-visible,
.sp-chatbot-close:focus-visible,
.sp-chatbot-send:focus-visible,
.sp-chatbot-quick-btn:focus-visible {
  outline: 2px solid #667eea;
  outline-offset: 2px;
}

.sp-chatbot-input:focus-visible {
  outline: none;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  .sp-chatbot-window,
  .sp-chatbot-message,
  .sp-chatbot-toggle,
  .sp-chatbot-typing-indicator span {
    animation: none;
  }

  .sp-chatbot-toggle:hover,
.sp-assist-btn:hover,
  .sp-chatbot-send:hover,
  .sp-chatbot-quick-btn:hover {
    transform: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .sp-chatbot-window {
    border: 2px solid currentColor;
  }

  .sp-chatbot-bubble {
    border: 1px solid currentColor;
  }
}
