/*
 * FAQ Chatbot Widget -- chatbot.css
 * Include this in any page that embeds chatbot.js
 *
 * Scoped to #chat-fab and #chat-wrapper so it won't bleed
 * into the rest of your page styles.
 */

/* -- FAB toggle button ---------------------------------------- */
#chat-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(30,64,175,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  z-index: 9998;
  transition: transform 0.2s, box-shadow 0.2s;
  outline: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
}

#chat-fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(30,64,175,0.55);
}

#chat-fab:active { transform: scale(0.95); }

/* Icon swap: chat bubble vs X */
#chat-fab .icon-open  { display: block; }
#chat-fab .icon-close { display: none; }
#chat-fab.is-open .icon-open  { display: none; }
#chat-fab.is-open .icon-close { display: block; }

/* Unread badge */
#chat-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: #ef4444;
  border-radius: 50%;
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  pointer-events: none;
  animation: faq-pop 0.3s ease;
}

#chat-badge.hidden { display: none; }

@keyframes faq-pop {
  0%   { transform: scale(0); }
  70%  { transform: scale(1.2); }
  100% { transform: scale(1); }
}

/* -- Chat Window --------------------------------------------- */
/* Force consistent font across all widget children regardless of host page */
#chat-wrapper,
#chat-wrapper *,
#chat-fab,
#chat-fab * {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
}

#chat-wrapper {
  position: fixed;
  bottom: 100px;
  right: 28px;
  width: 400px;
  height: 580px;
  max-height: calc(100vh - 120px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 12px 50px rgba(0,0,0,0.18);
  overflow: hidden;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: #1e293b;
  /* Hidden state */
  opacity: 0;
  transform: translateY(20px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#chat-wrapper.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* -- Header -------------------------------------------------- */
#chat-header {
  background: linear-gradient(135deg, #1e40af 0%, #3b82f6 100%);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

#chat-header .faq-avatar {
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,0.2);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

#chat-header .faq-info h2 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
}

#chat-header .faq-info p {
  font-size: 0.75rem;
  opacity: 0.8;
  margin: 2px 0 0;
}

#chat-header .faq-status-dot {
  width: 8px;
  height: 8px;
  background: #4ade80;
  border-radius: 50%;
  margin-left: auto;
  box-shadow: 0 0 6px #4ade80;
  flex-shrink: 0;
}

#chat-close {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: 10px;
  flex-shrink: 0;
  transition: background 0.15s;
}

#chat-close:hover { background: rgba(255,255,255,0.3); }

/* -- Quick-action chips -------------------------------------- */
#faq-quick-actions {
  padding: 10px 16px;
  background: #f8fafc;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  flex-shrink: 0;
}

#chat-wrapper .faq-chip {
  background: #fff;
  border: 1px solid #cbd5e1;
  border-radius: 20px;
  padding: 5px 14px;
  font-size: 0.78rem;
  color: #1e40af;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
}

#chat-wrapper .faq-chip:hover {
  background: #1e40af;
  color: #fff;
  border-color: #1e40af;
}

/* -- Messages Area ------------------------------------------ */
#faq-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* -- Individual Messages ------------------------------------ */
#chat-wrapper .faq-msg {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: faq-fadeUp 0.25s ease;
}

@keyframes faq-fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

#chat-wrapper .faq-msg.user { flex-direction: row-reverse; }

#chat-wrapper .faq-msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}

#chat-wrapper .faq-msg.bot  .faq-msg-avatar { background: #dbeafe; }
#chat-wrapper .faq-msg.user .faq-msg-avatar { background: #e0e7ff; }

#chat-wrapper .faq-bubble {
  max-width: 80%;
  padding: 11px 15px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.55;
  word-break: break-word;
}

#chat-wrapper .faq-msg.bot  .faq-bubble {
  background: #f1f5f9;
  color: #1e293b;
  border-bottom-left-radius: 4px;
}

#chat-wrapper .faq-msg.user .faq-bubble {
  background: linear-gradient(135deg, #1e40af, #3b82f6);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* -- FAQ Result Cards --------------------------------------- */
#chat-wrapper .faq-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  margin-top: 6px;
  overflow: hidden;
  transition: box-shadow 0.15s;
}

#chat-wrapper .faq-card:hover { box-shadow: 0 2px 12px rgba(0,0,0,0.08); }

#chat-wrapper .faq-question {
  padding: 11px 14px;
  font-weight: 600;
  font-size: 0.875rem;
  color: #1e40af;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  user-select: none;
}

#chat-wrapper .faq-question:hover { background: #f8fafc; }

#chat-wrapper .faq-toggle {
  font-size: 0.75rem;
  color: #94a3b8;
  flex-shrink: 0;
  transition: transform 0.2s;
}

#chat-wrapper .faq-question.open .faq-toggle { transform: rotate(180deg); }

#chat-wrapper .faq-answer {
  display: none;
  padding: 10px 14px 14px;
  font-size: 0.865rem;
  color: #374151;
  border-top: 1px solid #f1f5f9;
  line-height: 1.6;
}

#chat-wrapper .faq-answer a { color: #1e40af; }

#chat-wrapper .faq-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

#chat-wrapper .faq-tag {
  background: #e0e7ff;
  color: #3730a3;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 600;
}

#chat-wrapper .faq-tag.featured { background: #fef3c7; color: #92400e; }

/* -- Category List ------------------------------------------ */
#chat-wrapper .faq-category-list { margin-top: 6px; display: flex; flex-direction: column; gap: 6px; }

#chat-wrapper .faq-category-item {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 0.875rem;
  font-weight: 600;
  color: #1e40af;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}

#chat-wrapper .faq-category-item:hover {
  background: #1e40af;
  color: #fff;
  border-color: #1e40af;
}

#chat-wrapper .faq-sub-categories {
  margin-top: 4px;
  padding-left: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#chat-wrapper .faq-sub-category-item {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 0.82rem;
  color: #475569;
  cursor: pointer;
  transition: all 0.15s;
}

#chat-wrapper .faq-sub-category-item:hover {
  background: #e0e7ff;
  color: #1e40af;
  border-color: #a5b4fc;
}

/* -- Typing Indicator --------------------------------------- */
#faq-typing-indicator { display: none; }

#chat-wrapper .faq-typing-dots {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: #f1f5f9;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

#chat-wrapper .faq-typing-dots span {
  width: 7px;
  height: 7px;
  background: #94a3b8;
  border-radius: 50%;
  animation: faq-bounce 1.2s infinite;
}

#chat-wrapper .faq-typing-dots span:nth-child(2) { animation-delay: 0.2s; }
#chat-wrapper .faq-typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes faq-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-5px); }
}

/* -- Input hint bar ----------------------------------------- */
#faq-input-hint {
  display: none;
  background: #fffbeb;
  border-top: 1px solid #fde68a;
  color: #92400e;
  font-size: 0.8rem;
  padding: 7px 18px;
  flex-shrink: 0;
}

/* -- Input Area --------------------------------------------- */
#faq-input-area {
  padding: 14px 16px;
  background: #fff;
  border-top: 1px solid #e2e8f0;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
}

#faq-user-input {
  flex: 1;
  border: 1px solid #cbd5e1;
  border-radius: 22px;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  resize: none;
  outline: none;
  max-height: 100px;
  overflow-y: auto;
  line-height: 1.4;
  transition: border-color 0.15s;
}

#faq-user-input:focus { border-color: #3b82f6; }

#faq-send-btn {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #1e40af, #3b82f6);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.15s, opacity 0.15s;
}

#faq-send-btn:hover  { transform: scale(1.05); }
#faq-send-btn:active { transform: scale(0.95); }
#faq-send-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* -- Misc --------------------------------------------------- */
#chat-wrapper .faq-no-results {
  color: #64748b;
  font-style: italic;
  font-size: 0.875rem;
  margin-top: 4px;
}

#chat-wrapper .faq-result-header {
  font-size: 0.78rem;
  color: #64748b;
  margin-bottom: 6px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

#chat-wrapper .faq-refine-hint {
  font-size: 0.78rem;
  color: #64748b;
  font-style: italic;
  margin-top: 8px;
  padding: 6px 10px;
  background: #f8fafc;
  border-radius: 6px;
  border-left: 3px solid #cbd5e1;
}

/* -- Scrollbar ---------------------------------------------- */
#faq-messages::-webkit-scrollbar { width: 5px; }
#faq-messages::-webkit-scrollbar-track { background: transparent; }
#faq-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* -- Responsive --------------------------------------------- */
@media (max-width: 480px) {
  #chat-wrapper {
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    bottom: 0;
    right: 0;
    border-radius: 0;
  }
  #chat-fab {
    bottom: 18px;
    right: 18px;
  }
}

/* -- Yes / No response buttons ------------------------------------- */
#chat-wrapper .faq-yn-btn {
  display: inline-block;
  padding: 5px 14px;
  border-radius: 20px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #1e40af;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

#chat-wrapper .faq-yn-btn:hover {
  background: #1e40af;
  color: #fff;
  border-color: #1e40af;
}

/* -- Export button (header) ---------------------------------------- */
#chat-export {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-left: auto;
  flex-shrink: 0;
  transition: background 0.15s;
}

#chat-export:hover { background: rgba(255,255,255,0.3); }

/* -- Source selector buttons ---------------------------------------- */
#chat-wrapper .faq-source-btn {
  display: inline-block;
  padding: 10px 20px;
  border-radius: 10px;
  border: 2px solid #1e40af;
  background: #fff;
  color: #1e40af;
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

#chat-wrapper .faq-source-btn:hover {
  background: #1e40af;
  color: #fff;
}

/* -- Chooser list (multiple choosers) -------------------------------- */
#chat-wrapper .faq-chooser-item {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid #1e40af;
  background: #fff;
  color: #1e40af;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

#chat-wrapper .faq-chooser-item:hover {
  background: #1e40af;
  color: #fff;
}

/* -- Chooser answer buttons ------------------------------------------ */
#chat-wrapper .faq-chooser-answer {
  display: inline-block;
  padding: 7px 16px;
  margin: 3px 2px;
  border-radius: 20px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  color: #1e293b;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

#chat-wrapper .faq-chooser-answer:hover {
  background: #1e40af;
  color: #fff;
  border-color: #1e40af;
}

/* -- Chooser question text ------------------------------------------- */
#chat-wrapper .chooser-question {
  font-weight: 600;
  font-size: 0.9rem;
  color: #1e293b;
  margin-bottom: 4px;
}

/* -- Chooser product result card ------------------------------------ */
#chat-wrapper .chooser-product {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 8px;
}

#chat-wrapper .chooser-product-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #0369a1;
  margin-bottom: 6px;
}

#chat-wrapper .chooser-product-name {
  font-size: 1rem;
  font-weight: 700;
  color: #0c4a6e;
  margin-bottom: 8px;
}

#chat-wrapper .chooser-product-text {
  font-size: 0.85rem;
  color: #1e293b;
  line-height: 1.6;
}

/* -- Switch source chip --------------------------------------------- */
#chat-wrapper #faq-switch-source {
  background: #f1f5f9;
  border-color: #94a3b8;
  color: #475569;
}

#chat-wrapper #faq-switch-source:hover {
  background: #475569;
  color: #fff;
  border-color: #475569;
}

/* -- Switch source bar (sits below FAQ chips) ----------------------- */
#chat-wrapper #faq-switch-bar {
  padding: 4px 12px 0;
  text-align: right;
}