/**
 * FAQ Bot Chat Widget Styles
 *
 * Provides layout and positioning for the floating help button and chat modal.
 * Uses SilverCloud's existing button and form classes for consistent styling.
 */

/* ============================================================================
   Floating Help Button
   ============================================================================ */

.faq-help-button {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;

  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 50px;
}

.faq-help-button i {
  font-size: 20px;
}

/* Hide button when chat is open */
.faq-help-button[aria-expanded="true"] {
  display: none;
}

/* Mobile adjustments */
@media (max-width: 600px) {
  .faq-help-button {
    bottom: 16px;
    right: 16px;
    padding: 10px 16px;
    font-size: 14px;
  }

  .faq-help-button__text {
    display: none;
  }

  .faq-help-button i {
    font-size: 24px;
  }
}

/* ============================================================================
   Chat Modal
   ============================================================================ */

.faq-chat-modal {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1001;

  width: 380px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 48px);

  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);

  display: flex;
  flex-direction: column;
  overflow: hidden;

  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: all 0.25s ease;
}

.faq-chat-modal[aria-hidden="false"] {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Mobile: Full screen modal */
@media (max-width: 600px) {
  .faq-chat-modal {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
    /* Prevent iOS/Firefox mobile scrolling issues */
    display: flex;
    flex-direction: column;
    position: fixed;
  }
}

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

.faq-chat-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--primary-color, #14025d);
  color: #fff;
}

.faq-chat-modal__title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #fff;
}

.faq-chat-modal__title i {
  font-size: 22px;
}

.faq-chat-modal__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;

  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border: none;
  border-radius: 50%;

  font-size: 18px;
  cursor: pointer;
  transition: background 0.2s ease;
}

.faq-chat-modal__close:hover {
  background: rgba(255, 255, 255, 0.25);
}

.faq-chat-modal__close:focus {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

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

.faq-chat-modal__messages {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overflow-scrolling: touch;
  /* Critical for Firefox mobile flex scrolling */
  min-height: 0;
  max-height: 400px;
  background: #f8f9fa;
}

@media (max-width: 600px) {
  .faq-chat-modal__messages {
    max-height: none;
    min-height: 0;
    /* Prevent body scroll when modal is open on mobile */
    position: relative;
  }
}

/* Individual message */
.faq-chat-message {
  margin-bottom: 12px;
  animation: fadeInUp 0.3s ease;
}

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

.faq-chat-message__content {
  display: inline-block;
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.6;
  font-size: 14px;
  word-wrap: break-word;
}

/* Bot message content formatting */
.faq-chat-message--bot .faq-chat-message__content {
  background: #fff;
  color: #333;
  border: 1px solid #e0e0e0;
  border-bottom-left-radius: 4px;
}

/* Markdown formatting within bot messages */
.faq-chat-message--bot .faq-chat-message__content p {
  margin: 0;
  display: block;
}

.faq-chat-message--bot .faq-chat-message__content p + p {
  margin-top: 12px;
}

.faq-chat-message--bot .faq-chat-message__content strong {
  color: #14025d;
  font-weight: 600;
}

.faq-chat-message--bot .faq-chat-message__content div[style*="margin-left"] {
  display: block;
  margin-left: 16px;
  margin-bottom: 6px;
}

.faq-chat-message--bot .faq-chat-message__content br {
  line-height: 1.5;
}

/* User messages (right aligned) */
.faq-chat-message--user {
  text-align: right;
}

.faq-chat-message--user .faq-chat-message__content {
  background: var(--primary-color, #14025d);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Loading indicator */
.faq-chat-message--loading .faq-chat-message__content {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 16px 20px;
}

.faq-loading-dot {
  width: 8px;
  height: 8px;
  background: #999;
  border-radius: 50%;
  animation: loadingPulse 1.4s infinite ease-in-out both;
}

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

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

@keyframes loadingPulse {
  0%, 80%, 100% {
    transform: scale(0.6);
    opacity: 0.5;
  }
  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Error message */
.faq-chat-message--error .faq-chat-message__content {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

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

.faq-chat-modal__input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: #fff;
  border-top: 1px solid #e0e0e0;
}

.faq-chat-modal__suggestions-toggle {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  min-width: 36px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.faq-chat-modal__suggestions-toggle[aria-expanded="true"] {
  background: var(--primary-color, #14025d);
  color: #fff;
  border-color: var(--primary-color, #14025d);
}

.faq-chat-modal__input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #e0e0e0;
  border-radius: 24px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.faq-chat-modal__input:focus {
  border-color: var(--primary-color, #14025d);
  box-shadow: 0 0 0 3px rgba(20, 2, 93, 0.15);
}

.faq-chat-modal__input::placeholder {
  color: #999;
}

.faq-chat-modal__send {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  min-width: 44px;
  padding: 0;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.faq-chat-modal__send:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* ============================================================================
   Suggestions
   ============================================================================ */

.faq-chat-modal__suggestions {
  padding: 0 16px;
  background: #f8f9fa;
  border-top: 1px solid #e0e0e0;

  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.3s ease, padding 0.3s ease;
}

.faq-chat-modal__suggestions[aria-hidden="false"] {
  max-height: 200px;
  opacity: 1;
  padding: 12px 16px;
}

.faq-chat-modal__suggestions-label {
  font-size: 12px;
  font-weight: 600;
  color: #666;
  margin-bottom: 8px;
}

.faq-chat-modal__suggestions-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.faq-suggestion-chip {
  text-align: left;
  font-size: 13px;
}

/* ============================================================================
   Disclaimer
   ============================================================================ */

.faq-chat-modal__disclaimer {
  padding: 8px 16px 12px;
  background: #f8f9fa;
  text-align: center;
}

.faq-chat-modal__disclaimer small {
  color: #666;
  font-size: 11px;
  line-height: 1.4;
}

/* ============================================================================
   High Contrast / Accessibility
   ============================================================================ */

@media (prefers-reduced-motion: reduce) {
  .faq-chat-modal,
  .faq-help-button,
  .faq-chat-message {
    transition: none;
    animation: none;
  }
}

/* Prevent body scroll when modal is open on mobile */
body.faq-modal-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}
