/* ============================================================
   style.css — WhatsApp-inspired Chatbot UI
   ============================================================ */

/* ── CSS Custom Properties ───────────────────────────────────── */
:root {
  --brand-green:     #25d366;
  --brand-green-dk:  #128c7e;
  --brand-teal:      #075e54;
  --user-bubble:     #dcf8c6;
  --bot-bubble:      #ffffff;
  --bg-chat:         #ece5dd;
  --bg-window:       #f0f2f5;
  --text-primary:    #111b21;
  --text-secondary:  #667781;
  --border:          #e9edef;
  --shadow:          0 4px 24px rgba(0,0,0,.18);
  --radius-bubble:   8px;
  --radius-window:   16px;
  --font:            -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition:      .25s cubic-bezier(.4,0,.2,1);
}

/* ── Reset & base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--text-primary);
  background: #e5ddd5;
  min-height: 100vh;
}

/* ── Floating Action Button ──────────────────────────────────── */
.chat-fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--brand-green);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 20px rgba(37,211,102,.45);
  transition: transform var(--transition), background var(--transition);
  z-index: 1000;
}

.chat-fab:hover  { background: var(--brand-green-dk); transform: scale(1.08); }
.chat-fab:active { transform: scale(.96); }

.fab-icon {
  width: 28px;
  height: 28px;
  position: absolute;
  transition: opacity var(--transition), transform var(--transition);
}

.fab-icon--close { opacity: 0; transform: rotate(-90deg); }

.chat-fab.is-open .fab-icon--chat  { opacity: 0; transform: rotate(90deg); }
.chat-fab.is-open .fab-icon--close { opacity: 1; transform: rotate(0deg);  }

/* Notification badge */
.fab-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 20px;
  height: 20px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
  transition: opacity var(--transition), transform var(--transition);
}

.fab-badge.hidden { opacity: 0; transform: scale(0); }

/* ── Chat Window ─────────────────────────────────────────────── */
.chat-window {
  position: fixed;
  bottom: 100px;
  right: 28px;
  width: 380px;
  max-height: 620px;
  border-radius: var(--radius-window);
  background: var(--bg-window);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999;

  overscroll-behavior: contain;

  /* Hidden by default */
  opacity: 0;
  transform: translateY(20px) scale(.97);
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
}

.chat-window.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header ──────────────────────────────────────────────────── */
.chat-header {
  background: var(--brand-teal);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-avatar svg { width: 22px; height: 22px; }

.header-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.header-name   { font-weight: 600; font-size: 15px; }
.header-status { font-size: 12px; opacity: .85; display: flex; align-items: center; gap: 5px; }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand-green);
  box-shadow: 0 0 6px var(--brand-green);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .5; }
}

.header-close {
  background: none;
  border: none;
  color: rgba(255,255,255,.7);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  line-height: 1;
  border-radius: 4px;
  transition: color var(--transition);
}
.header-close:hover { color: #fff; }

/* ── Message list ────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px 12px;
  background: var(--bg-chat);
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.2); border-radius: 2px; }

/* ── Message bubbles ─────────────────────────────────────────── */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  animation: slideIn .2s ease;
}

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

.msg-row--bot  { justify-content: flex-start; }
.msg-row--user { justify-content: flex-end;   }

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--brand-teal);
  color: #fff;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
}

.msg-bubble {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: 12px;
  line-height: 1.5;
  font-size: 14px;
  position: relative;
  word-break: break-word;
}

/* Bot bubble — left tail */
.msg-row--bot .msg-bubble {
  background: var(--bot-bubble);
  border-bottom-left-radius: var(--radius-bubble);
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
  color: var(--text-primary);
}

/* User bubble — right tail */
.msg-row--user .msg-bubble {
  background: var(--user-bubble);
  border-bottom-right-radius: var(--radius-bubble);
  box-shadow: 0 1px 2px rgba(0,0,0,.12);
  color: var(--text-primary);
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 4px;
}

.msg-time {
  font-size: 11px;
  color: var(--text-secondary);
}

/* Double tick for user messages */
.msg-tick { font-size: 12px; color: #4fc3f7; }

/* Support CTA inside bot messages */
.support-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding: 7px 14px;
  background: var(--brand-green);
  color: #fff;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: background var(--transition);
  white-space: nowrap;
}
.support-cta:hover { background: var(--brand-green-dk); }

/* Source attribution */
.msg-sources {
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-secondary);
}

/* ── Typing indicator ────────────────────────────────────────── */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 14px;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-secondary);
  animation: typing 1.2s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }

@keyframes typing {
  0%, 60%, 100% { transform: translateY(0); opacity: .5; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

/* ── Suggested question chips ────────────────────────────────── */
.suggestions {
  background: var(--bg-window);
  padding: 8px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.suggestion-chip {
  padding: 6px 12px;
  border: 1.5px solid var(--brand-teal);
  border-radius: 16px;
  background: transparent;
  color: var(--brand-teal);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  font-family: var(--font);
}

.suggestion-chip:hover {
  background: var(--brand-teal);
  color: #fff;
}

/* Hide suggestions once user types / sends first message */
.suggestions.hidden { display: none; }

/* ── Input area ──────────────────────────────────────────────── */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  background: #fff;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 24px;
  padding: 10px 16px;
  font-size: 14px;
  font-family: var(--font);
  resize: none;
  outline: none;
  color: var(--text-primary);
  line-height: 1.4;
  max-height: 120px;
  overflow-y: auto;
  transition: border-color var(--transition);
}

.chat-input:focus { border-color: var(--brand-teal); }
.chat-input::placeholder { color: var(--text-secondary); }

.send-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  background: var(--brand-green);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition);
  flex-shrink: 0;
}

.send-btn svg { width: 20px; height: 20px; }
.send-btn:hover  { background: var(--brand-green-dk); }
.send-btn:active { transform: scale(.92); }
.send-btn:disabled { background: #ccc; cursor: not-allowed; }

/* ── Welcome message formatting ──────────────────────────────── */
.welcome-text { white-space: pre-line; }

/* ── Date divider ────────────────────────────────────────────── */
.date-divider {
  text-align: center;
  font-size: 12px;
  color: var(--text-secondary);
  background: rgba(0,0,0,.06);
  border-radius: 8px;
  padding: 3px 10px;
  align-self: center;
  margin: 6px 0;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 480px) {
  .chat-window {
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    border-radius: 16px 16px 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .chat-fab {
    bottom: 20px;
    bottom: calc(20px + env(safe-area-inset-bottom));
    right: 20px;
  }
}

/* ── Voice: Mic button ───────────────────────────────────────── */
.mic-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  background: var(--bg-window);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.mic-btn:hover { background: var(--border); color: var(--text-primary); }

/* Voice mode ON — mic stays brand-green between replies */
.mic-btn.voice-mode {
  background: var(--brand-green);
  color: #fff;
  border-color: var(--brand-green);
}
.mic-btn.voice-mode:hover { background: var(--brand-green-dk); border-color: var(--brand-green-dk); }

.mic-btn.listening {
  background: #fee2e2;
  color: #dc2626;
  border-color: #dc2626;
  animation: mic-pulse 1s ease-in-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,.4); }
  50%       { box-shadow: 0 0 0 8px rgba(220,38,38,0); }
}

/* ── Voice: Speaker toggle (in header) ───────────────────────── */
.speaker-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,.55);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  flex-shrink: 0;
}
.speaker-btn:hover  { color: rgba(255,255,255,.85); }
.speaker-btn.tts-active { color: #fff; }

/* Show/hide the right icon based on active state */
.speaker-btn .spk-on  { display: none; }
.speaker-btn .spk-off { display: block; }
.speaker-btn.tts-active .spk-on  { display: block; }
.speaker-btn.tts-active .spk-off { display: none; }

/* ── iOS tap highlight removal ───────────────────────────────── */
.chat-fab,
.header-close,
.send-btn,
.suggestion-chip {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
