/* ─── Chatbot Widget ─────────────────────────────────────── */
:root {
  --chat-primary: #7c3aed;
  --chat-primary-hover: #6d28d9;
  --chat-primary-light: #ede9fe;
  --chat-text: #1a1a2e;
  --chat-text-muted: #5a6478;
  --chat-bg: #ffffff;
  --chat-bg-secondary: #f8f6f1;
  --chat-border: rgba(26, 26, 46, 0.10);
  --chat-radius: 16px;
  --chat-radius-sm: 10px;
  --chat-shadow: 0 8px 32px rgba(26, 26, 46, 0.14);
  --chat-fab-size: 60px;
}

/* Floating action button */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  width: var(--chat-fab-size);
  height: var(--chat-fab-size);
  border-radius: 50%;
  background: var(--chat-primary);
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(124, 58, 237, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
  outline: none;
}
.chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(124, 58, 237, 0.45);
  background: var(--chat-primary-hover);
}
.chat-fab:focus-visible {
  outline: 3px solid var(--chat-primary);
  outline-offset: 3px;
}
.chat-fab svg { transition: transform 0.25s ease, opacity 0.2s ease; }
.chat-fab-icon-close { display: none; }
.chat-fab.open .chat-fab-icon-close { display: block; }
.chat-fab.open .chat-fab-icon-open { display: none; }

/* Badge dot on FAB when there are unread/pending messages */
.chat-fab-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
}
.chat-fab.has-badge .chat-fab-badge { display: block; }

/* Chat window */
.chat-window {
  position: fixed;
  bottom: 100px;
  right: 24px;
  z-index: 9998;
  width: 380px;
  max-width: calc(100vw - 48px);
  max-height: 560px;
  background: var(--chat-bg);
  border-radius: var(--chat-radius);
  box-shadow: var(--chat-shadow);
  border: 1px solid var(--chat-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Sticky: always visible regardless of scroll */
  will-change: transform, opacity;
  /* Hidden state: translateY + scale down */
  transform: translateY(24px) scale(0.94);
  opacity: 0;
  pointer-events: none;
  transition:
    transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 0.25s ease;
}
.chat-window.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

/* Chat header */
.chat-header {
  padding: 16px 20px;
  background: var(--chat-primary);
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: default;
}
.chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.chat-header-info { flex: 1; }
.chat-header-name {
  font-family: 'Syne', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  color: #fff;
}
.chat-header-status {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.75);
  display: flex;
  align-items: center;
  gap: 5px;
}
.chat-header-status::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
}
.chat-close {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.7);
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
  flex-shrink: 0;
}
.chat-close:hover { background: rgba(255,255,255,0.15); color: #fff; }
.chat-close:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

/* Mode indicator pill in header */
.chat-mode-pill {
  font-size: 0.7rem;
  font-weight: 600;
  background: rgba(255,255,255,0.2);
  color: #fff;
  border-radius: 20px;
  padding: 3px 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Message area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--chat-border);
  border-radius: 3px;
}

/* Message bubbles */
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  animation: msgIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.chat-msg--bot { align-self: flex-start; }
.chat-msg--user { align-self: flex-end; align-items: flex-end; }

.chat-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.9rem;
  line-height: 1.55;
  color: var(--chat-text);
}
.chat-msg--bot .chat-bubble {
  background: var(--chat-bg-secondary);
  border-bottom-left-radius: 4px;
}
.chat-msg--user .chat-bubble {
  background: var(--chat-primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg-time {
  font-size: 0.68rem;
  color: var(--chat-text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

/* Quick reply buttons */
.chat-replies {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
}
.chat-reply-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: 1.5px solid var(--chat-primary);
  background: #fff;
  color: var(--chat-primary);
  font-family: 'DM Sans', sans-serif;
  transition: background 0.18s, color 0.18s, border-color 0.18s;
  white-space: nowrap;
}
.chat-reply-btn:hover { background: var(--chat-primary); color: #fff; }
.chat-reply-btn:focus-visible { outline: 2px solid var(--chat-primary); outline-offset: 2px; }

/* Contact form in chat */
.chat-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}
.chat-form label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--chat-text-muted);
}
.chat-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--chat-border);
  border-radius: var(--chat-radius-sm);
  font-size: 0.9rem;
  font-family: 'DM Sans', sans-serif;
  color: var(--chat-text);
  background: #fff;
  outline: none;
  transition: border-color 0.2s;
}
.chat-input:focus { border-color: var(--chat-primary); }
.chat-form-submit {
  padding: 10px;
  border-radius: var(--chat-radius-sm);
  font-size: 0.88rem;
  font-weight: 700;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  border: none;
  background: var(--chat-primary);
  color: #fff;
  transition: background 0.2s;
  width: 100%;
}
.chat-form-submit:hover { background: var(--chat-primary-hover); }

/* Typing indicator */
.chat-typing {
  display: flex;
  gap: 5px;
  padding: 10px 14px;
  background: var(--chat-bg-secondary);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  align-self: flex-start;
  animation: msgIn 0.25s ease;
}
.chat-typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--chat-text-muted);
  animation: typingBounce 1.2s ease-in-out infinite;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* Chat input area */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid var(--chat-border);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  background: #fff;
}
.chat-text-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--chat-border);
  border-radius: 24px;
  font-size: 0.9rem;
  font-family: 'DM Sans', sans-serif;
  color: var(--chat-text);
  background: var(--chat-bg-secondary);
  outline: none;
  resize: none;
  max-height: 100px;
  line-height: 1.4;
  transition: border-color 0.2s, background 0.2s;
}
.chat-text-input:focus { border-color: var(--chat-primary); background: #fff; }
.chat-text-input::placeholder { color: var(--chat-text-muted); }
.chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--chat-primary);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
}
.chat-send-btn:hover { background: var(--chat-primary-hover); transform: scale(1.05); }
.chat-send-btn:focus-visible { outline: 2px solid var(--chat-primary); outline-offset: 2px; }
.chat-send-btn:disabled { background: var(--chat-border); cursor: not-allowed; transform: none; }

/* FAQ welcome card */
.chat-faq-card {
  background: var(--chat-primary-light);
  border: 1px solid rgba(124, 58, 237, 0.15);
  border-radius: var(--chat-radius-sm);
  padding: 12px 16px;
  font-size: 0.82rem;
  color: var(--chat-text-muted);
  line-height: 1.5;
}
.chat-faq-card strong { color: var(--chat-primary); }

/* Success feedback after contact capture */
.chat-success {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--chat-radius-sm);
  padding: 12px 16px;
  font-size: 0.88rem;
  color: #166534;
  text-align: center;
  animation: msgIn 0.3s ease;
}

/* Closing the chat hides FAB badge */
.chat-fab.has-unread .chat-fab-badge { display: block; }

/* Mobile: full-width bottom-sheet on small screens */
@media (max-width: 480px) {
  .chat-window {
    bottom: 0;
    right: 0;
    width: 100vw;
    max-width: 100vw;
    max-height: 85vh;
    border-radius: 16px 16px 0 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    /* Bottom-sheet: slide up from off-screen */
    transform: translateY(100%);
    transition:
      transform 0.35s cubic-bezier(0.32, 0.72, 0, 1),
      opacity 0.25s ease;
  }
  .chat-window.open {
    transform: translateY(0);
  }
  .chat-fab {
    bottom: 16px;
    right: 16px;
  }
}