/* ==========================================================================
   CHATBOT.CSS - AI Assistant Widget Styles
   Uses design tokens from base.css
   ========================================================================== */

/* ==========================================================================
   1. WIDGET LAUNCHER BUTTON
   ========================================================================== */

.chatbot-launcher {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--navy);
  color: var(--white);
  border: none;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    transform 0.2s ease,
    box-shadow 0.2s ease,
    background-color 0.2s ease;
}

.chatbot-launcher:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
  background: var(--navy-light);
}

.chatbot-launcher:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.chatbot-launcher svg {
  width: 28px;
  height: 28px;
}

.chatbot-launcher-close {
  display: none;
}

.chatbot-launcher.active .chatbot-launcher-icon {
  display: none;
}

.chatbot-launcher.active .chatbot-launcher-close {
  display: block;
}

/* Notification dot */
.chatbot-launcher-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 16px;
  height: 16px;
  background: var(--gold);
  border-radius: 50%;
  border: 2px solid var(--white);
  display: none;
}

.chatbot-launcher.has-notification .chatbot-launcher-badge {
  display: block;
}

/* ==========================================================================
   2. CHAT WINDOW
   ========================================================================== */

.chatbot-window {
  position: fixed;
  bottom: calc(var(--space-lg) + 72px);
  right: var(--space-lg);
  width: 380px;
  height: 520px;
  max-height: calc(100vh - 120px);
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition:
    opacity 0.25s ease,
    visibility 0.25s ease,
    transform 0.25s ease;
}

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

/* ==========================================================================
   3. CHAT HEADER
   ========================================================================== */

.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-md) var(--space-lg);
  background: var(--navy);
  color: var(--white);
  flex-shrink: 0;
}

.chatbot-header-info {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

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

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

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

.chatbot-header-title {
  font-size: 0.9375rem;
  font-weight: 600;
  line-height: 1.2;
}

.chatbot-header-status {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
  display: flex;
  align-items: center;
  gap: 4px;
}

.chatbot-status-dot {
  width: 6px;
  height: 6px;
  background: var(--green);
  border-radius: 50%;
}

.chatbot-header-actions {
  display: flex;
  gap: var(--space-xs);
}

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

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

.chatbot-header-btn:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: -2px;
}

.chatbot-header-btn svg {
  width: 16px;
  height: 16px;
}

/* ==========================================================================
   4. MESSAGES AREA
   ========================================================================== */

.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-md);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  scroll-behavior: smooth;
}

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

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

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

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

/* Message bubbles */
.chatbot-message {
  max-width: 85%;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.chatbot-message-user {
  align-self: flex-end;
}

.chatbot-message-assistant {
  align-self: flex-start;
}

.chatbot-message-content {
  padding: var(--space-sm) var(--space-md);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  line-height: 1.5;
  word-wrap: break-word;
}

.chatbot-message-user .chatbot-message-content {
  background: var(--navy);
  color: var(--white);
  border-bottom-right-radius: 4px;
}

.chatbot-message-assistant .chatbot-message-content {
  background: var(--off-white);
  color: var(--charcoal);
  border-bottom-left-radius: 4px;
}

/* Links in messages */
.chatbot-message-content a {
  color: var(--blue-accent);
  text-decoration: underline;
}

.chatbot-message-user .chatbot-message-content a {
  color: var(--gold-light);
}

/* Message timestamp */
.chatbot-message-time {
  font-size: 0.6875rem;
  color: var(--gray);
  padding: 0 var(--space-xs);
}

.chatbot-message-user .chatbot-message-time {
  text-align: right;
}

/* ==========================================================================
   5. TYPING INDICATOR
   ========================================================================== */

.chatbot-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: var(--space-sm) var(--space-md);
  background: var(--off-white);
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  align-self: flex-start;
}

.chatbot-typing-dot {
  width: 6px;
  height: 6px;
  background: var(--gray);
  border-radius: 50%;
  animation: chatbot-typing-bounce 1.2s infinite ease-in-out;
}

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

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

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

@keyframes chatbot-typing-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-4px);
  }
}

/* ==========================================================================
   6. QUICK REPLIES
   ========================================================================== */

.chatbot-quick-replies {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  padding: 0 var(--space-md);
  margin-bottom: var(--space-sm);
}

.chatbot-quick-reply {
  padding: var(--space-xs) var(--space-md);
  background: var(--white);
  border: 1px solid var(--navy);
  border-radius: 20px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--navy);
  cursor: pointer;
  transition:
    background-color 0.2s ease,
    color 0.2s ease;
}

.chatbot-quick-reply:hover {
  background: var(--navy);
  color: var(--white);
}

.chatbot-quick-reply:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* ==========================================================================
   7. INPUT AREA
   ========================================================================== */

.chatbot-input-area {
  display: flex;
  align-items: flex-end;
  gap: var(--space-sm);
  padding: var(--space-md);
  border-top: 1px solid rgba(0, 0, 0, 0.08);
  background: var(--white);
  flex-shrink: 0;
}

.chatbot-input-wrapper {
  flex: 1;
  display: flex;
  align-items: flex-end;
  background: var(--off-white);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: border-color 0.2s ease;
}

.chatbot-input-wrapper:focus-within {
  border-color: var(--navy);
}

.chatbot-input {
  flex: 1;
  border: none;
  background: transparent;
  padding: var(--space-sm) var(--space-md);
  font-family: var(--font-main);
  font-size: 0.9375rem;
  line-height: 1.4;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  overflow-y: auto;
}

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

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

.chatbot-send-btn {
  width: 40px;
  height: 40px;
  background: var(--gold);
  border: none;
  border-radius: var(--radius-md);
  color: var(--navy);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition:
    background-color 0.2s ease,
    transform 0.2s ease;
}

.chatbot-send-btn:hover:not(:disabled) {
  background: var(--gold-light);
  transform: scale(1.05);
}

.chatbot-send-btn:focus-visible {
  outline: 2px solid var(--navy);
  outline-offset: 2px;
}

.chatbot-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

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

/* ==========================================================================
   8. WELCOME MESSAGE
   ========================================================================== */

.chatbot-welcome {
  text-align: center;
  padding: var(--space-xl) var(--space-md);
}

.chatbot-welcome-icon {
  width: 48px;
  height: 48px;
  background: var(--off-white);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto var(--space-md);
}

.chatbot-welcome-icon svg {
  width: 24px;
  height: 24px;
  color: var(--navy);
}

.chatbot-welcome h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: var(--space-sm);
}

.chatbot-welcome p {
  font-size: 0.875rem;
  color: var(--gray);
  margin-bottom: 0;
}

/* ==========================================================================
   9. ERROR STATE
   ========================================================================== */

.chatbot-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: var(--red-light);
  border-radius: var(--radius-md);
  margin: var(--space-md);
  text-align: center;
}

.chatbot-error-message {
  font-size: 0.875rem;
  color: var(--charcoal);
}

.chatbot-error-retry {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--navy);
  background: var(--white);
  border: 1px solid var(--navy);
  border-radius: var(--radius-sm);
  padding: var(--space-xs) var(--space-md);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

.chatbot-error-retry:hover {
  background: var(--off-white);
}

/* ==========================================================================
   10. MINIMIZED STATE
   ========================================================================== */

.chatbot-window.minimized {
  height: auto;
}

.chatbot-window.minimized .chatbot-messages,
.chatbot-window.minimized .chatbot-quick-replies,
.chatbot-window.minimized .chatbot-input-area {
  display: none;
}

/* ==========================================================================
   11. RESPONSIVE - TABLET
   ========================================================================== */

@media (max-width: 1023px) {
  .chatbot-window {
    width: 360px;
    height: 480px;
  }
}

/* ==========================================================================
   12. RESPONSIVE - MOBILE (Full Screen)
   ========================================================================== */

@media (max-width: 639px) {
  .chatbot-launcher {
    bottom: var(--space-md);
    right: var(--space-md);
    width: 56px;
    height: 56px;
  }

  .chatbot-launcher svg {
    width: 24px;
    height: 24px;
  }

  .chatbot-window {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border-radius: 0;
    transform: translateY(100%);
  }

  .chatbot-window.open {
    transform: translateY(0);
  }

  .chatbot-header {
    padding: var(--space-md);
    /* Safe area for notched phones */
    padding-top: max(var(--space-md), env(safe-area-inset-top));
  }

  .chatbot-messages {
    padding: var(--space-md);
  }

  .chatbot-input-area {
    padding: var(--space-md);
    /* Safe area for home indicator */
    padding-bottom: max(var(--space-md), env(safe-area-inset-bottom));
  }

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

  /* Hide launcher when chat is open on mobile */
  .chatbot-launcher.active {
    display: none;
  }
}

/* ==========================================================================
   13. FOLLOW-UP SUGGESTION CHIPS (AI-generated)
   ========================================================================== */

.chatbot-suggestions {
  padding: var(--space-sm) 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-sm);
  align-self: flex-start;
  max-width: 85%;
}

.chatbot-suggestion {
  display: inline-block;
  padding: 6px 12px;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #b8923f;
  background: rgba(214, 158, 46, 0.08);
  border: 1px solid rgba(214, 158, 46, 0.25);
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
  font-family: inherit;
  line-height: 1.3;
}

.chatbot-suggestion:hover {
  background: rgba(214, 158, 46, 0.15);
  border-color: rgba(214, 158, 46, 0.5);
}

.chatbot-suggestion:active {
  transform: scale(0.96);
}

.chatbot-suggestion:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

/* Entrance animation */
.chatbot-message + .chatbot-suggestions {
  animation: chatbot-chip-in 0.25s ease-out;
}

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

/* ==========================================================================
   14. LEAD CONFIRMATION CARD
   ========================================================================== */

.chatbot-lead-confirm {
  display: flex;
  align-items: flex-start;
  gap: var(--space-sm);
  padding: var(--space-md);
  background: var(--green-light);
  border-radius: var(--radius-md);
  align-self: flex-start;
  max-width: 85%;
  animation: chatbot-chip-in 0.25s ease-out;
}

.chatbot-lead-confirm-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: var(--green);
}

.chatbot-lead-confirm-icon svg {
  width: 24px;
  height: 24px;
  stroke: var(--green);
}

.chatbot-lead-confirm-title {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--charcoal);
  margin-bottom: 2px;
}

.chatbot-lead-confirm-detail {
  font-size: 0.8125rem;
  color: var(--charcoal);
  margin-bottom: 4px;
}

.chatbot-lead-confirm-note {
  font-size: 0.75rem;
  color: var(--gray);
}

/* ==========================================================================
   15. REDUCED MOTION
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  .chatbot-window {
    transition: none;
  }

  .chatbot-launcher {
    transition: none;
  }

  .chatbot-typing-dot {
    animation: none;
  }

  .chatbot-quick-reply,
  .chatbot-suggestion,
  .chatbot-send-btn,
  .chatbot-header-btn {
    transition: none;
  }

  .chatbot-message + .chatbot-suggestions {
    animation: none;
  }
}

/* ==========================================================================
   16. PRINT
   ========================================================================== */

@media print {
  .chatbot-launcher,
  .chatbot-window {
    display: none !important;
  }
}
