/* ========== SNORPLE SLEEP ADVISOR CHATBOT ========== */

.chat-bubble {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--accent, #e07a3d);
  color: #fff;
  border: none;
  cursor: pointer;
  z-index: 10000;
  box-shadow: 0 4px 16px rgba(224, 122, 61, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.chat-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(224, 122, 61, 0.55);
}
.chat-bubble svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chat-bubble .chat-bubble-close {
  display: none;
  font-size: 1.5rem;
  line-height: 1;
}
.chat-bubble.open .chat-bubble-icon { display: none; }
.chat-bubble.open .chat-bubble-close { display: block; }

/* Pulse animation to draw attention */
.chat-bubble::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--accent, #e07a3d);
  animation: chatPulse 2.5s ease-out infinite;
  pointer-events: none;
}
.chat-bubble.open::after { display: none; }

@keyframes chatPulse {
  0% { opacity: 0.7; transform: scale(1); }
  100% { opacity: 0; transform: scale(1.5); }
}

/* Unread badge */
.chat-bubble-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #dc2626;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}
.chat-bubble-badge.hidden { display: none; }

/* ========== CHAT WINDOW ========== */

.chat-window {
  position: fixed;
  bottom: 96px;
  right: 24px;
  width: 380px;
  height: 520px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
  z-index: 10001;
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #e5e7eb;
}
.chat-window.open {
  display: flex;
  animation: chatSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes chatSlideUp {
  from { opacity: 0; transform: translateY(16px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0)   scale(1);    }
}

/* Header */
.chat-header {
  background: var(--primary, #1a2744);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.chat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent, #e07a3d);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}
.chat-header-info {
  flex: 1;
}
.chat-header-name {
  font-size: 0.9rem;
  font-weight: 700;
  color: #fff;
}
.chat-header-status {
  font-size: 0.7rem;
  color: #86efac;
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 2px;
}
.chat-header-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  display: inline-block;
  flex-shrink: 0;
}
.chat-header-close {
  background: none;
  border: none;
  cursor: pointer;
  color: rgba(255,255,255,0.6);
  font-size: 1.2rem;
  padding: 4px;
  line-height: 1;
  transition: color 0.2s;
}
.chat-header-close:hover {
  color: #fff;
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  background: #f9fafb;
}

/* Message bubbles */
.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.85rem;
  line-height: 1.55;
  word-wrap: break-word;
}
.chat-msg-bot {
  align-self: flex-start;
  background: #fff;
  color: #1a2744;
  border: 1px solid #e5e7eb;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.chat-msg-user {
  align-self: flex-end;
  background: var(--accent, #e07a3d);
  color: #fff;
  border-bottom-right-radius: 4px;
}

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  padding: 12px 18px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
  display: none;
  gap: 4px;
  align-items: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.chat-typing.visible { display: flex; }
.chat-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9ca3af;
  animation: chatTypingBounce 1.4s ease-in-out infinite;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }
.chat-typing-label {
  font-size: 0.7rem;
  color: #9ca3af;
  margin-left: 4px;
  font-style: italic;
}

@keyframes chatTypingBounce {
  0%, 60%, 100% { transform: translateY(0);    opacity: 0.4; }
  30%            { transform: translateY(-4px); opacity: 1;   }
}

/* Input area */
.chat-input-area {
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
  background: #fff;
}
.chat-input {
  flex: 1;
  border: 1px solid #e5e7eb;
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 0.85rem;
  font-family: 'Inter', sans-serif;
  color: #1a2744;
  background: #f9fafb;
  outline: none;
  transition: border-color 0.2s;
}
.chat-input:focus {
  border-color: var(--accent, #e07a3d);
  background: #fff;
}
.chat-input::placeholder {
  color: #9ca3af;
}
.chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary, #1a2744);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s;
}
.chat-send:hover {
  background: var(--accent, #e07a3d);
}
.chat-send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.chat-send svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* Disclaimer */
.chat-disclaimer {
  padding: 6px 16px 8px;
  text-align: center;
  font-size: 0.6rem;
  color: #9ca3af;
  line-height: 1.5;
  background: #fff;
  border-top: 1px solid #f3f4f6;
  flex-shrink: 0;
}

/* ========== DID YOU KNOW PREVIEW ========== */

.chat-dyk {
  position: fixed;
  bottom: 96px;
  right: 24px;
  max-width: 300px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  border-bottom-right-radius: 4px;
  padding: 12px 16px;
  font-size: 13px;
  line-height: 1.55;
  color: #1a2744;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.13);
  z-index: 9999;
  cursor: pointer;
  pointer-events: none;
  opacity: 0;
  transform: translateY(10px) scale(0.97);
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.chat-dyk::after {
  content: 'Tap to chat →';
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: #e07a3d;
  margin-top: 6px;
  letter-spacing: 0.02em;
}
.chat-dyk.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.chat-dyk:hover {
  border-color: #e07a3d;
  box-shadow: 0 10px 32px rgba(224, 122, 61, 0.18);
}

/* ========== MOBILE ========== */

@media (max-width: 480px) {
  .chat-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
    max-height: 100dvh;
  }
  .chat-bubble {
    bottom: 16px;
    right: 16px;
    width: 54px;
    height: 54px;
  }
  .chat-bubble svg {
    width: 24px;
    height: 24px;
  }
}

/* ========== STICKY BAR AVOIDANCE ========== */
/* Lift chat bubble above the sticky buy bar when it's visible */
body.sticky-visible .chat-bubble {
  bottom: 88px; /* sticky bar ~60px + 28px gap */
  transition: bottom 0.3s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

@media (max-width: 480px) {
  body.sticky-visible .chat-bubble {
    bottom: 80px; /* slightly tighter on mobile */
  }
}
