/* ====================================================
   CHATBOT WIDGET — Floating chat assistant
   z-index: 1100 → above WhatsApp (1000), below Gate (9999)
   Animation: transform + opacity only (no display toggle for perf)
==================================================== */

/* ── Root container — anchors both toggle & window ── */
#chatbot-widget {
  position: fixed;
  bottom: 100px;          /* 28px bottom + 58px WA btn + 14px gap */
  left: 28px;             /* LTR: left side, same column as WA */
  z-index: 1100;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}
[dir="rtl"] #chatbot-widget {
  left: auto;
  right: 28px;
  align-items: flex-end;
}

/* ── Chat window ── */
.chatbot-window {
  width: 320px;
  max-height: 440px;
  display: flex;
  flex-direction: column;
  background: linear-gradient(
    160deg,
    rgba(14, 14, 26, 0.98) 0%,
    rgba(10, 10, 18, 0.99) 100%
  );
  border: 1px solid rgba(200, 169, 106, 0.16);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow:
    0 8px 32px rgba(0, 0, 0, 0.55),
    0 20px 60px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(200, 169, 106, 0.06);

  /* Closed state */
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition:
    opacity 0.32s cubic-bezier(0.25, 0.8, 0.25, 1),
    transform 0.32s cubic-bezier(0.25, 0.8, 0.25, 1);
}
.chatbot-window.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header ── */
.chatbot-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(
    100deg,
    rgba(18, 18, 32, 1) 0%,
    rgba(24, 20, 36, 1) 100%
  );
  border-bottom: 1px solid rgba(200, 169, 106, 0.12);
  flex-shrink: 0;
}
.chatbot-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--primary);
  flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(200, 169, 106, 0.25);
}
.chatbot-header-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chatbot-header-name {
  font-family: var(--font-ar);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--accent-light);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chatbot-header-status {
  font-family: var(--font-ar);
  font-size: 0.7rem;
  color: #4ade80;           /* online green — intentional, not a brand color */
  display: flex;
  align-items: center;
  gap: 4px;
}
.chatbot-header-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #4ade80;
  animation: statusPulse 2s ease infinite;
}
@keyframes statusPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}
.chatbot-close-btn {
  background: none;
  border: none;
  color: var(--text-light);
  font-size: 1rem;
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: color var(--speed) var(--ease), background var(--speed) var(--ease);
  line-height: 1;
  flex-shrink: 0;
}
.chatbot-close-btn:hover {
  color: var(--accent);
  background: rgba(200, 169, 106, 0.08);
}

/* ── Messages area ── */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
.chatbot-messages::-webkit-scrollbar { width: 3px; }
.chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.chatbot-messages::-webkit-scrollbar-thumb {
  background: rgba(200, 169, 106, 0.25);
  border-radius: 2px;
}

/* Message bubbles */
.chat-msg {
  max-width: 88%;
  padding: 9px 13px;
  border-radius: 14px;
  font-family: var(--font-ar);
  font-size: 0.82rem;
  line-height: 1.6;
  animation: msgFadeIn 0.28s cubic-bezier(0.25, 0.8, 0.25, 1) both;
}
@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.chat-msg.bot {
  align-self: flex-start;
  background: rgba(30, 28, 48, 0.9);
  border: 1px solid rgba(200, 169, 106, 0.10);
  color: rgba(250, 249, 247, 0.92);
  border-bottom-left-radius: 4px;
}
[dir="rtl"] .chat-msg.bot { border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }

.chat-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent-dark), var(--accent));
  color: var(--primary);
  font-weight: 600;
  border-bottom-right-radius: 4px;
}
[dir="rtl"] .chat-msg.user { border-bottom-right-radius: 14px; border-bottom-left-radius: 4px; }

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 11px 16px;
  background: rgba(30, 28, 48, 0.9);
  border: 1px solid rgba(200, 169, 106, 0.10);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  animation: msgFadeIn 0.2s ease both;
}
[dir="rtl"] .chat-typing { border-bottom-left-radius: 14px; border-bottom-right-radius: 4px; }
.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.5;
  animation: typingDot 1.2s ease infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.chat-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingDot {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40%           { opacity: 1;   transform: translateY(-4px); }
}

/* ── Quick reply buttons ── */
.chatbot-quickreplies {
  padding: 8px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  border-top: 1px solid rgba(200, 169, 106, 0.08);
  background: rgba(10, 10, 18, 0.6);
  flex-shrink: 0;
}
.qr-btn {
  background: rgba(200, 169, 106, 0.07);
  border: 1px solid rgba(200, 169, 106, 0.20);
  border-radius: 20px;
  color: rgba(232, 201, 138, 0.92);
  font-family: var(--font-ar);
  font-size: 0.79rem;
  font-weight: 600;
  padding: 7px 14px;
  cursor: pointer;
  text-align: center;
  transition:
    background var(--speed) var(--ease),
    border-color var(--speed) var(--ease),
    color var(--speed) var(--ease),
    transform 0.18s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.qr-btn:hover {
  background: rgba(200, 169, 106, 0.15);
  border-color: var(--accent);
  color: var(--accent-light);
  transform: translateY(-1px);
}
.qr-btn:active {
  transform: translateY(0);
}
.qr-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ── Toggle button ── */
.chatbot-toggle {
  position: relative;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent-dark) 0%, var(--accent) 60%, var(--accent-light) 100%);
  color: var(--primary);
  font-size: 1.3rem;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow:
    0 4px 20px rgba(200, 169, 106, 0.45),
    0 8px 32px rgba(0, 0, 0, 0.35),
    0 2px 6px rgba(0, 0, 0, 0.2);
  transition:
    transform var(--speed) var(--ease),
    box-shadow var(--speed) var(--ease);
  flex-shrink: 0;
}
.chatbot-toggle:hover {
  transform: scale(1.08);
  box-shadow:
    0 6px 28px rgba(200, 169, 106, 0.6),
    0 12px 40px rgba(0, 0, 0, 0.4);
}
.chatbot-toggle:active { transform: scale(0.96); }

/* Icon cross-fade */
.chatbot-toggle .icon-chat,
.chatbot-toggle .icon-close {
  position: absolute;
  transition: opacity 0.22s ease, transform 0.22s ease;
}
.chatbot-toggle .icon-chat  { opacity: 1; transform: rotate(0deg) scale(1); }
.chatbot-toggle .icon-close { opacity: 0; transform: rotate(-90deg) scale(0.6); }

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

/* Notification badge */
.chatbot-badge {
  position: absolute;
  top: -3px;
  right: -3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-family: var(--font-en);
  font-size: 0.65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--primary);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.chatbot-badge.hidden {
  opacity: 0;
  transform: scale(0);
  pointer-events: none;
}

/* ── Mobile ── */
@media (max-width: 480px) {
  .chatbot-window {
    width: calc(100vw - 24px);
    max-height: 380px;
  }
  #chatbot-widget {
    left: 12px;
    bottom: 96px;
  }
  [dir="rtl"] #chatbot-widget {
    left: auto;
    right: 12px;
  }
}
