/* ===== AI Chatbot Widget ===== */

.chatbot-container {
  position: fixed;
  bottom: 0;
  right: 0;
  z-index: 9990;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* Toggle Button — right side (WhatsApp moves to left) */
.chatbot-toggle {
  position: fixed;
  bottom: var(--spacing-lg, 2rem);
  right: var(--spacing-lg, 2rem);
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2px solid var(--color-accent, #b8894a);
  background: var(--color-accent, #b8894a);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25);
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 9995;
  padding: 0;
  overflow: hidden;
}

.chatbot-toggle:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 25px rgba(184, 137, 74, 0.4);
}

.chatbot-toggle-photo {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  transition: opacity 0.3s ease;
}

.chatbot-toggle .chatbot-icon-close {
  display: none;
  width: 28px;
  height: 28px;
}

.chatbot-toggle.chatbot-active .chatbot-toggle-photo {
  display: none;
}

.chatbot-toggle.chatbot-active .chatbot-icon-close {
  display: block;
}

.chatbot-toggle.chatbot-active {
  background: var(--color-accent, #b8894a);
}

/* Toggle label */
.chatbot-toggle-label {
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--color-cream, #f0e4cf);
  white-space: nowrap;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.chatbot-toggle.chatbot-active .chatbot-toggle-label {
  display: none;
}

/* Phase 1: Slide-up entrance */
.chatbot-toggle.chatbot-entrance {
  animation: chatbot-slide-up 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes chatbot-slide-up {
  0%   { opacity: 0; transform: translateY(40px) scale(0.8); }
  100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* Phase 2: Pulse ring — repeats 3 times */
.chatbot-toggle.chatbot-pulse {
  animation: chatbot-pulse-ring 2s ease-out 3;
}

@keyframes chatbot-pulse-ring {
  0%   { box-shadow: 0 0 0 0 rgba(184, 137, 74, 0.5); }
  50%  { box-shadow: 0 0 0 16px rgba(184, 137, 74, 0); }
  100% { box-shadow: 0 0 0 0 rgba(184, 137, 74, 0); }
}

/* Phase 3: Teaser chat bubble */
.chatbot-teaser {
  position: fixed;
  bottom: calc(var(--spacing-lg, 2rem) + 70px);
  right: var(--spacing-lg, 2rem);
  background: #0f1a2e;
  border: 1px solid rgba(184, 137, 74, 0.3);
  border-radius: 12px 12px 4px 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  z-index: 9994;
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px) scale(0.95);
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 260px;
}

/* Triangle pointer toward toggle button */
.chatbot-teaser::after {
  content: "";
  position: absolute;
  bottom: -7px;
  right: 18px;
  width: 14px;
  height: 14px;
  background: #0f1a2e;
  border-right: 1px solid rgba(184, 137, 74, 0.3);
  border-bottom: 1px solid rgba(184, 137, 74, 0.3);
  transform: rotate(45deg);
}

.chatbot-teaser.chatbot-teaser-visible {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.chatbot-teaser.chatbot-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px) scale(0.95);
}

.chatbot-teaser-text {
  color: #f0e4cf;
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.3;
}

.chatbot-teaser-close {
  background: none;
  border: none;
  color: #6c7b95;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.2s ease;
}

.chatbot-teaser-close:hover {
  color: #aebcd1;
}

/* Chat Window */
.chatbot-window {
  position: fixed;
  bottom: 6rem;
  right: 2rem;
  width: 380px;
  height: min(600px, calc(100vh - 8rem));
  background: #0c1524;
  border: 1px solid rgba(184, 137, 74, 0.15);
  border-radius: 16px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 9999;
}

.chatbot-window.chatbot-hidden {
  transform: scale(0.9);
  opacity: 0;
  pointer-events: none;
}

/* Header */
.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: #060c17;
  border-bottom: 1px solid rgba(184, 137, 74, 0.2);
  flex-shrink: 0;
}

.chatbot-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chatbot-avatar-img {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--color-accent, #b8894a);
}

.chatbot-header-title {
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: #f0e4cf;
}

.chatbot-header-subtitle {
  font-size: 0.7rem;
  color: #6c7b95;
  margin-top: 1px;
}

.chatbot-header-actions {
  display: flex;
  gap: 4px;
}

.chatbot-header-actions button {
  background: none;
  border: none;
  color: #6c7b95;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.chatbot-header-actions button:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #aebcd1;
}

.chatbot-header-actions button svg {
  width: 16px;
  height: 16px;
}

/* Messages Area */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scrollbar-width: thin;
  scrollbar-color: rgba(184, 137, 74, 0.2) transparent;
}

.chatbot-messages::-webkit-scrollbar {
  width: 4px;
}

.chatbot-messages::-webkit-scrollbar-thumb {
  background: rgba(184, 137, 74, 0.2);
  border-radius: 2px;
}

/* Message Bubbles */
.chatbot-msg {
  display: flex;
  max-width: 85%;
  gap: 8px;
  align-items: flex-end;
}

.chatbot-msg-assistant {
  align-self: flex-start;
}

.chatbot-msg-user {
  align-self: flex-end;
}

.chatbot-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid rgba(184, 137, 74, 0.3);
}

.chatbot-msg-bubble {
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.chatbot-msg-assistant .chatbot-msg-bubble {
  background: #0f1a2e;
  color: #aebcd1;
  border-bottom-left-radius: 4px;
}

.chatbot-msg-user .chatbot-msg-bubble {
  background: rgba(184, 137, 74, 0.18);
  color: #f0e4cf;
  border-bottom-right-radius: 4px;
}

/* Photo Grid in Messages */
.chatbot-photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px;
  margin-top: 8px;
}

.chatbot-photo {
  width: 100%;
  height: 90px;
  object-fit: cover;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.2s;
}

.chatbot-photo:hover {
  opacity: 0.8;
}

/* Typing/Status Indicator */
.chatbot-status {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.chatbot-status.chatbot-hidden {
  display: none;
}

.chatbot-typing-dots {
  display: flex;
  gap: 4px;
}

.chatbot-typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-accent, #b8894a);
  animation: chatbot-bounce 1.4s infinite ease-in-out both;
}

.chatbot-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.chatbot-typing-dots span:nth-child(2) { animation-delay: -0.16s; }
.chatbot-typing-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes chatbot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.chatbot-status-text {
  font-size: 0.75rem;
  color: #6c7b95;
}

/* Quick Actions */
.chatbot-quick-actions {
  padding: 8px 16px 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex-shrink: 0;
}

.chatbot-quick-actions.chatbot-hidden {
  display: none;
}

.chatbot-quick-actions button {
  background: none;
  border: 1px solid rgba(184, 137, 74, 0.35);
  color: var(--color-accent, #b8894a);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.chatbot-quick-actions button:hover {
  background: rgba(184, 137, 74, 0.12);
  border-color: var(--color-accent, #b8894a);
}

/* Input Area */
.chatbot-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px 16px;
  background: #060c17;
  border-top: 1px solid rgba(184, 137, 74, 0.12);
  flex-shrink: 0;
}

.chatbot-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: #f0e4cf;
  font-size: 0.875rem;
  font-family: inherit;
  resize: none;
  line-height: 1.4;
  max-height: 72px;
  padding: 6px 0;
}

.chatbot-input::placeholder {
  color: #6c7b95;
}

.chatbot-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--color-accent, #b8894a);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.chatbot-send:disabled {
  opacity: 0.3;
  cursor: default;
}

.chatbot-send:not(:disabled):hover {
  background: #d4a96a;
  transform: scale(1.05);
}

.chatbot-send svg {
  width: 18px;
  height: 18px;
}

/* Powered-by footer */
.chatbot-powered {
  text-align: center;
  padding: 4px 0 8px;
  font-size: 0.6rem;
  color: #4a5568;
  background: #060c17;
}

/* WhatsApp — move to LEFT side */
.whatsapp-float {
  right: auto !important;
  left: var(--spacing-lg, 2rem) !important;
}

/* Persistent label below WhatsApp button */
.whatsapp-float-label {
  position: absolute;
  bottom: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  font-weight: 600;
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--color-cream, #f0e4cf);
  white-space: nowrap;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

/* Mobile */
@media (max-width: 768px) {
  .chatbot-toggle {
    bottom: 1.5rem;
    right: 1.5rem;
    width: 54px;
    height: 54px;
  }

  .chatbot-window {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    border-radius: 0;
    border: none;
    z-index: 10002;
    padding-top: env(safe-area-inset-top, 0);
  }

  .chatbot-window.chatbot-hidden {
    transform: translateY(100%);
    opacity: 0;
  }

  /* Bigger header on mobile fullscreen */
  .chatbot-header {
    padding: 16px 16px;
    padding-top: calc(12px + env(safe-area-inset-top, 0));
  }

  .chatbot-avatar-img {
    width: 44px;
    height: 44px;
  }

  .chatbot-header-title {
    font-size: 1.1rem;
  }

  .chatbot-header-subtitle {
    font-size: 0.75rem;
  }

  /* Larger close/clear buttons for touch */
  .chatbot-header-actions button {
    width: 38px;
    height: 38px;
  }

  .chatbot-header-actions button svg {
    width: 18px;
    height: 18px;
  }

  /* Input area — safe area for home bar */
  .chatbot-input-area {
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
  }

  /* Bigger input on mobile */
  .chatbot-input {
    font-size: 1rem;
    padding: 8px 0;
  }

  /* Bigger send button for thumb */
  .chatbot-send {
    width: 42px;
    height: 42px;
  }

  /* Quick actions — bigger tap targets */
  .chatbot-quick-actions button {
    padding: 10px 16px;
    font-size: 0.85rem;
  }

  .whatsapp-float {
    left: 1.5rem !important;
    right: auto !important;
  }

  .chatbot-toggle-label,
  .whatsapp-float-label {
    font-size: 0.6rem;
    bottom: -20px;
  }
}

/* Hide WhatsApp & navbar when chat is fullscreen on mobile */
@media (max-width: 768px) {
  body.chatbot-open .whatsapp-float {
    display: none !important;
  }

  body.chatbot-open .navbar {
    display: none !important;
  }

  /* Hide toggle label and teaser when chat is open */
  body.chatbot-open .chatbot-toggle-label,
  body.chatbot-open .chatbot-teaser {
    display: none !important;
  }

  /* Teaser: adjust position for mobile */
  .chatbot-teaser {
    bottom: calc(1.5rem + 64px);
    right: 1.5rem;
    max-width: 220px;
  }
}

/* RTL */
[dir="rtl"] .chatbot-toggle {
  right: auto;
  left: var(--spacing-lg, 2rem);
}

[dir="rtl"] .chatbot-teaser {
  right: auto;
  left: var(--spacing-lg, 2rem);
  border-radius: 12px 12px 12px 4px;
}

[dir="rtl"] .chatbot-teaser::after {
  right: auto;
  left: 18px;
  border-right: none;
  border-left: 1px solid rgba(184, 137, 74, 0.3);
}

[dir="rtl"] .chatbot-window {
  right: auto;
  left: 2rem;
  transform-origin: bottom left;
}

[dir="rtl"] .chatbot-msg-assistant {
  align-self: flex-end;
  flex-direction: row-reverse;
}

[dir="rtl"] .chatbot-msg-user {
  align-self: flex-start;
}

[dir="rtl"] .chatbot-msg-assistant .chatbot-msg-bubble {
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 4px;
}

[dir="rtl"] .chatbot-msg-user .chatbot-msg-bubble {
  border-bottom-right-radius: 12px;
  border-bottom-left-radius: 4px;
}

[dir="rtl"] .chatbot-input {
  text-align: right;
}

[dir="rtl"] .whatsapp-float {
  left: auto !important;
  right: var(--spacing-lg, 2rem) !important;
}


@media (max-width: 768px) {
  [dir="rtl"] .chatbot-toggle {
    left: 1.5rem;
  }

  [dir="rtl"] .chatbot-window {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }

  [dir="rtl"] .whatsapp-float {
    right: 1.5rem !important;
    left: auto !important;
  }

  [dir="rtl"] .chatbot-teaser {
    right: auto;
    left: 1.5rem;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .chatbot-window,
  .chatbot-toggle,
  .chatbot-teaser {
    transition: none;
    animation: none;
  }

  .chatbot-typing-dots span {
    animation: none;
    opacity: 0.6;
  }

  .chatbot-toggle.chatbot-entrance {
    animation: none;
    opacity: 1;
    transform: none;
  }

  .chatbot-toggle.chatbot-pulse {
    animation: none;
  }
}

/* Print */
@media print {
  .chatbot-container {
    display: none;
  }
}
