/* ===========================================================
   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);
}

/* -----------------------------------------------------------
   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, 70vh, 720px);
  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-rows: auto 1fr auto;
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  scroll-padding-bottom: 28px;
}
#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;
  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;
}
#wordai-chat-window .assistant-name {
  display: flex; align-items: center; gap: 10px; overflow: hidden;
}
#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: 80%;
}

/* -----------------------------------------------------------
   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: 15px;
  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;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  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;
}

.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 {
  flex: 1 1 auto;
  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 .chat-send {
  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: 60vh;
    border-radius: 12px;
    overflow: auto !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: 16px !important;
  line-height: 1.65;
}

/* Input text + placeholder match messages visually */
#wordai-chat-window .chat-input {
  font-size: 16px;
  line-height: 1.5;
}
#wordai-chat-window .chat-input::placeholder {
  font-size: 15px;
  opacity: 0.8;
}

/* Mobile — slightly larger for comfort */
@media (max-width: 600px) {
  #wordai-chat-window .ai-msg,
  #wordai-chat-window .user-msg {
    font-size: 18px !important;
    line-height: 1.7;
  }
  #wordai-chat-window .chat-input {
    font-size: 17px;
    line-height: 1.55;
  }
  #wordai-chat-window .chat-input::placeholder {
    font-size: 16px;
    opacity: 0.85;
  }
}
