/* ===========================================================
   WordAI Chat Widget — Stable Premium R8.7 Final
   -----------------------------------------------------------
   - Bubble always visible (toggle)
   - Chat window opens above bubble (no overlap)
   - Mobile: 60–70vh height, 92% width (not fullscreen)
   - Footer fully visible with fade shadow
   - Typing dots animation, avatar glow, smooth scroll
   =========================================================== */

:root {
  --wordai-bubble-bg: #0073aa;
  --wordai-bubble-fg: #ffffff;
  --wordai-avatar-fg: #ffffff;
  --wordai-bg: #ffffff;
  --wordai-text: #1e1e1e;
  --wordai-ai-bg: #f5f7fa;
  --wordai-user-bg: linear-gradient(135deg, #e0f3ff, #bde2ff);
  --wordai-chat-conversation-font-size: 16px;
  --wordai-chat-input-font-size: 15px;
}

/* -----------------------------------------------------------
   Chat Bubble
   ----------------------------------------------------------- */
#wordai-chat-bubble.wordai-chat-bubble {
  position: fixed;
  right: 22px;
  bottom: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-width: 56px;
  height: 46px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--wordai-bubble-bg);
  color: var(--wordai-bubble-fg);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  z-index: 2147483640;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#wordai-chat-bubble.wordai-pos-left { left: 22px; right: auto; }
#wordai-chat-bubble .wordai-bubble-label {
  color: var(--wordai-bubble-fg) !important;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
}

/* -----------------------------------------------------------
   Avatar (Bubble + Header)
   ----------------------------------------------------------- */
.wordai-avatar {
  width: 30px;
  height: 30px;
  min-width: 30px;
  border-radius: 50%;
  display: flex !important;
  align-items: center;
  justify-content: center;
  background: var(--wordai-avatar-fg);
  overflow: hidden;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}
.wordai-avatar:hover {
  transform: scale(1.08) translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}
.wordai-avatar svg { width: 100%; height: 100%; display: block; }
.wordai-avatar-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
}

/* Avatar pulse glow when AI typing */
@keyframes wordaiPulseGlow {
  0%,100% { box-shadow: 0 0 0 rgba(0,0,0,0); transform: scale(1); }
  50% { box-shadow: 0 0 14px var(--wordai-bubble-bg); transform: scale(1.1); }
}
.wordai-avatar.pulsing { animation: wordaiPulseGlow 1.6s ease-in-out infinite; }

/* -----------------------------------------------------------
   Chat Window
   ----------------------------------------------------------- */
#wordai-chat-window.wordai-chat-window {
  position: fixed;
  right: 20px;
  bottom: 80px; /* above bubble */
  width: 360px;
  height: clamp(440px, 80vh, 760px);
  max-height: 85vh;
  background: var(--wordai-bg);
  color: var(--wordai-text);
  display: none;
  z-index: 2147483639;
  border-radius: 16px;
  box-shadow: 0 10px 32px rgba(0,0,0,.35);
  /* overflow: auto; */
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr auto;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  scroll-padding-bottom: 28px;
  box-sizing: border-box;
}
#wordai-chat-window > * {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
#wordai-chat-window.wordai-pos-left { left: 20px; right: auto; }
#wordai-chat-window.is-open { display: grid !important; opacity: 1; transform: none; }

#wordai-chat-window[data-theme="dark"] {
  --wordai-bg: #181818;
  --wordai-text: #f4f4f4;
  --wordai-ai-bg: #232323;
  --wordai-user-bg: linear-gradient(135deg, #0073aa, #3198ff);
  color-scheme: dark;
}
/* .wordai-chat-body { overflow: auto; } */
/* -----------------------------------------------------------
   Smooth Scrolling & Scrollbar Enhancement (R8.7.3)
   ----------------------------------------------------------- */
.wordai-chat-body {
  overflow-y: auto;
  scroll-behavior: smooth;             /* ✅ makes native scrolls soft */
  -webkit-overflow-scrolling: touch;   /* ✅ natural momentum on iOS */
  overscroll-behavior: contain;        /* ✅ prevents page bounce */
  scrollbar-width: thin;               /* ✅ thin scrollbar (Firefox) */
  scrollbar-color: rgba(0,0,0,0.25) transparent;
}

/* ✅ Pretty scrollbars for Chrome/Safari/Edge */
.wordai-chat-body::-webkit-scrollbar {
  width: 6px;
}
.wordai-chat-body::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.25);
  border-radius: 10px;
}
.wordai-chat-body::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.35);
}


/* -----------------------------------------------------------
   Header
   ----------------------------------------------------------- */
#wordai-chat-window .wordai-chat-header {
  grid-row: 1;
  width: 100%;
  max-width: 100%;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(135deg, var(--wordai-bubble-bg), color-mix(in srgb, var(--wordai-bubble-bg) 55%, #19a3ff));
  color: var(--wordai-bubble-fg);
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  box-sizing: border-box;
}
#wordai-chat-window .assistant-name {
  display: flex; align-items: center; gap: 10px; overflow: hidden; flex: 1 1 auto; min-width: 0;
}
#wordai-chat-window .assistant-name .wordai-avatar {
  background: var(--wordai-avatar-fg);
  width: 30px; height: 30px; flex: 0 0 30px; border-radius: 50%;
}
#wordai-chat-window .assistant-name .title-text {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: none; flex: 1 1 auto; min-width: 0;
}

#wordai-chat-window .chat-close {
  flex: 0 0 auto;
  min-width: 30px;
  margin-left: 8px;
}

/* -----------------------------------------------------------
   Messages Section
   ----------------------------------------------------------- */
#wordai-chat-window .chat-messages {
  grid-row: 2;
  overflow-y: auto !important;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
#wordai-chat-window .chat-messages p { margin: .25em 0; }

#wordai-chat-window .ai-msg,
#wordai-chat-window .user-msg {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: var(--wordai-chat-conversation-font-size);
  line-height: 1.6;
  animation: fadeIn 0.18s ease;
}
#wordai-chat-window .ai-msg { align-self: flex-start; background: var(--wordai-ai-bg); }
#wordai-chat-window .user-msg { align-self: flex-end; background: var(--wordai-user-bg); }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* Typing dots (instead of “Typing...”) */
.typing-dots {
  display: inline-flex;
  gap: 4px;
  padding: 10px 14px;
}
.typing-dots span {
  width: 6px;
  height: 6px;
  background: #999;
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(1){animation-delay:0s;}
.typing-dots span:nth-child(2){animation-delay:0.2s;}
.typing-dots span:nth-child(3){animation-delay:0.4s;}
@keyframes bounce {
  0%,80%,100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
}

/* -----------------------------------------------------------
   Footer
   ----------------------------------------------------------- */
#wordai-chat-window .wordai-chat-footer {
  grid-row: 3;
  width: 100%;
  max-width: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  column-gap: 8px;
  row-gap: 6px;
  padding: 10px;
  border-top: 1px solid rgba(0,0,0,0.08);
  background: var(--wordai-bg);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.05);
  z-index: 3;
  position: relative;
  box-sizing: border-box;
}

.footer-fade {
  position: absolute;
  top: -10px;
  left: 0;
  width: 100%;
  height: 18px;
  pointer-events: none;
  background: linear-gradient(to top, rgba(255,255,255,0.96), rgba(255,255,255,0));
  z-index: 2;
}

#wordai-chat-window .chat-input {
  grid-column: 1;
  grid-row: 1;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  min-height: 42px;
  resize: none;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  scroll-margin-block-end: 24px;
}

#wordai-chat-window .wordai-chat-sources {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
  font-size: 11px;
  line-height: 1.4;
}
#wordai-chat-window .wordai-chat-sources span {
  flex-basis: 100%;
  color: #667085;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .02em;
}
#wordai-chat-window .wordai-chat-sources a {
  max-width: 100%;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(0, 115, 170, .09);
  color: var(--wordai-bubble-bg);
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#wordai-chat-window .wordai-chat-feedback {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 12px;
  color: #667085;
}
#wordai-chat-window .wordai-feedback-btn {
  width: 28px;
  height: 26px;
  padding: 0;
  border: 1px solid rgba(0, 0, 0, .12);
  border-radius: 7px;
  background: #fff;
  cursor: pointer;
}
#wordai-chat-window .wordai-feedback-btn:hover,
#wordai-chat-window .wordai-feedback-btn:focus {
  border-color: var(--wordai-bubble-bg);
  box-shadow: 0 0 0 2px rgba(0, 115, 170, .12);
}
#wordai-chat-window .wordai-chat-feedback.is-submitted {
  color: #16803c;
}
#wordai-chat-window .wordai-chat-feedback em {
  font-style: normal;
  font-weight: 700;
}
#wordai-chat-window .wordai-chat-lead-card {
  max-width: 94%;
  padding: 12px;
}
#wordai-chat-window .wordai-chat-lead-form {
  display: grid;
  gap: 10px;
}
#wordai-chat-window .wordai-chat-lead-form p {
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: #344054;
}
#wordai-chat-window .wordai-chat-lead-error {
  padding: 8px 10px;
  border-radius: 8px;
  background: #fef2f2;
  color: #b42318;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.35;
}
#wordai-chat-window .wordai-chat-lead-fields {
  display: grid;
  gap: 8px;
}
#wordai-chat-window .wordai-chat-lead-fields label,
#wordai-chat-window .wordai-chat-lead-consent {
  display: grid;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  color: #475467;
}
#wordai-chat-window .wordai-chat-lead-fields input,
#wordai-chat-window .wordai-chat-lead-fields textarea {
  width: 100%;
  min-height: 34px;
  box-sizing: border-box;
  border: 1px solid #d0d5dd;
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 13px;
  line-height: 1.35;
  background: #fff;
}
#wordai-chat-window .wordai-chat-lead-fields textarea {
  min-height: 58px;
  resize: vertical;
}
#wordai-chat-window .wordai-chat-lead-consent {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-weight: 500;
  line-height: 1.35;
}
#wordai-chat-window .wordai-chat-lead-consent input {
  margin-top: 2px;
}
#wordai-chat-window .wordai-chat-lead-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
#wordai-chat-window .wordai-chat-lead-submit,
#wordai-chat-window .wordai-chat-lead-skip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--wordai-bubble-bg);
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}
#wordai-chat-window .wordai-chat-lead-submit {
  background: var(--wordai-bubble-bg);
  color: #fff;
}
#wordai-chat-window .wordai-chat-lead-skip {
  background: #fff;
  color: var(--wordai-bubble-bg);
}
#wordai-chat-window .wordai-chat-lead-form.has-error {
  border-left: 3px solid #d63638;
  padding-left: 8px;
}
#wordai-chat-window.wordai-lead-required-blocked .chat-input {
  background: #f8fafc;
}
#wordai-chat-window .wordai-chat-lead-saved p {
  color: #16803c;
  font-weight: 700;
}
#wordai-chat-window .wordai-chat-handoff {
  display: flex;
  margin-top: 9px;
}
#wordai-chat-window .wordai-chat-handoff-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 7px 11px;
  border-radius: 8px;
  background: var(--wordai-bubble-bg);
  color: #fff !important;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  text-decoration: none;
  box-shadow: 0 6px 14px rgba(0, 115, 170, .18);
}
#wordai-chat-window .wordai-chat-handoff-btn:hover,
#wordai-chat-window .wordai-chat-handoff-btn:focus {
  filter: brightness(1.04);
  text-decoration: none;
}
#wordai-chat-window .wordai-chat-branding {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
  margin-top: -2px;
  text-align: center;
  font-size: 11px;
  color: #667085;
  line-height: 1.25;
  overflow-wrap: anywhere;
}
#wordai-chat-window .wordai-chat-branding a {
  color: var(--wordai-bubble-bg);
  font-weight: 800;
  text-decoration: none;
}

#wordai-chat-window .chat-send {
  grid-column: 2;
  grid-row: 1;
  align-self: end;
  height: 42px;
  padding: 0 16px;
  border-radius: 10px;
  border: none;
  background: var(--wordai-bubble-bg);
  color: var(--wordai-bubble-fg);
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
#wordai-chat-window .chat-send:hover { transform: translateY(-1px); box-shadow: 0 2px 6px rgba(0,0,0,0.2); }
#wordai-chat-window .chat-send .arrow {
  display: inline-block;
  margin-right: 3px;
  font-weight: bold;
  transform: translateY(1px);
}
#wordai-chat-window .chat-send.is-sending {
  opacity: 0.65;
  cursor: not-allowed;
}

/* -----------------------------------------------------------
   Mobile Polished Width (R8.7.1)
   ----------------------------------------------------------- */
@media (max-width:600px) {
  #wordai-chat-window {
    position: fixed;
    width: 96%;
    left: 2%;
    right: 2%;
    bottom: calc(72px + 10px) !important; /* stays above bubble */
    height: min(82vh, calc(100vh - 96px));
    border-radius: 12px;
    overflow: hidden !important;
  }
  #wordai-chat-window.wordai-pos-left {
    left: 2%;
    right: 2%;
  }
}

/* ===========================================================
   Responsive Font Sizes — Messages + Input (R8.7.2 Final)
   -----------------------------------------------------------
   - 16px desktop (standard readability)
   - 18px mobile (matches WhatsApp / Messenger)
   - Input font + placeholder scaled proportionally
   =========================================================== */

/* Desktop / default */
#wordai-chat-window .ai-msg,
#wordai-chat-window .user-msg {
  font-size: var(--wordai-chat-conversation-font-size) !important;
  line-height: 1.65;
}

/* Input text + placeholder match messages visually */
#wordai-chat-window .chat-input {
  font-size: var(--wordai-chat-input-font-size);
  line-height: 1.5;
}
#wordai-chat-window .chat-input::placeholder {
  font-size: var(--wordai-chat-input-font-size);
  opacity: 0.8;
}

/* Mobile — slightly larger for comfort */
@media (max-width: 600px) {
  #wordai-chat-window .ai-msg,
  #wordai-chat-window .user-msg {
    font-size: var(--wordai-chat-conversation-font-size) !important;
    line-height: 1.7;
  }
  #wordai-chat-window .chat-input {
    font-size: var(--wordai-chat-input-font-size);
    line-height: 1.55;
  }
  #wordai-chat-window .chat-input::placeholder {
    font-size: var(--wordai-chat-input-font-size);
    opacity: 0.85;
  }
}
