/* ===========================================
   AI CHATBOT WIDGET - Souq al'Ard Assistant
   =========================================== */

/* ── Floating Trigger Button ─────────────────────────────────── */
.chatbot-trigger {
  position: fixed;
  bottom: 100px;          /* above the WhatsApp button */
  right: 24px;
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
  color: var(--white);
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  box-shadow: var(--shadow-xl), 0 0 0 0 rgba(26, 54, 93, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  z-index: var(--z-chatbot);
  transition: transform var(--transition-spring), box-shadow var(--transition-fast);
  animation: chatbot-pulse 3s ease-in-out infinite;
}

.chatbot-trigger:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-xl), 0 0 0 6px rgba(26, 54, 93, 0.15);
  animation: none;
}

.chatbot-trigger.open {
  background: linear-gradient(135deg, #374151, #1f2937);
  animation: none;
}

.chatbot-trigger .chatbot-trigger-icon { display: block; }
.chatbot-trigger .chatbot-trigger-close { display: none; }
.chatbot-trigger.open .chatbot-trigger-icon { display: none; }
.chatbot-trigger.open .chatbot-trigger-close { display: block; }

@keyframes chatbot-pulse {
  0%, 100% { box-shadow: var(--shadow-xl), 0 0 0 0 rgba(26, 54, 93, 0.3); }
  50%       { box-shadow: var(--shadow-xl), 0 0 0 10px rgba(26, 54, 93, 0); }
}

/* Unread badge */
.chatbot-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 18px;
  height: 18px;
  background: #ef4444;
  color: var(--white);
  border-radius: var(--radius-full);
  font-size: 0.65rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--white);
  transition: opacity var(--transition-fast);
}

.chatbot-badge.hidden { opacity: 0; pointer-events: none; }

/* Tooltip label */
.chatbot-tooltip {
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--text-dark);
  color: var(--white);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.chatbot-tooltip::after {
  content: '';
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  border: 5px solid transparent;
  border-left-color: var(--text-dark);
}

.chatbot-trigger:hover .chatbot-tooltip { opacity: 1; }

/* ── Chat Panel ──────────────────────────────────────────────── */
.chatbot-panel {
  position: fixed;
  bottom: 168px;
  right: 24px;
  width: 370px;
  max-width: calc(100vw - 32px);
  height: 540px;
  max-height: calc(100vh - 200px);
  background: var(--white);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl), 0 0 0 1px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: var(--z-chatbot);
  transform-origin: bottom right;
  transform: scale(0.85) translateY(20px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
              opacity 0.25s ease;
}

.chatbot-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Chat Header ─────────────────────────────────────────────── */
.chatbot-header {
  background: linear-gradient(135deg, var(--primary-color) 0%, var(--primary-light) 100%);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--white);
  flex-shrink: 0;
}

.chatbot-avatar {
  width: 42px;
  height: 42px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.3);
}

.chatbot-header-info {
  flex: 1;
}

.chatbot-header-name {
  font-weight: 600;
  font-size: 0.95rem;
  margin: 0;
}

.chatbot-header-status {
  font-size: 0.75rem;
  opacity: 0.85;
  display: flex;
  align-items: center;
  gap: 5px;
}

.chatbot-status-dot {
  width: 7px;
  height: 7px;
  background: #4ade80;
  border-radius: var(--radius-full);
  animation: status-blink 2s ease-in-out infinite;
}

@keyframes status-blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

.chatbot-header-close {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: var(--white);
  width: 30px;
  height: 30px;
  border-radius: var(--radius-full);
  cursor: pointer;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color var(--transition-fast);
}

.chatbot-header-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ── Chat Messages Area ─────────────────────────────────────── */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
  background: var(--light-bg);
}

.chatbot-messages::-webkit-scrollbar { width: 4px; }
.chatbot-messages::-webkit-scrollbar-track { background: transparent; }
.chatbot-messages::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--radius-pill);
}

/* Message bubbles */
.chat-message {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  animation: message-in 0.3s ease;
}

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

.chat-message.user {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  flex-shrink: 0;
}

.msg-avatar.user-avatar {
  background: linear-gradient(135deg, var(--accent-dark), var(--accent-hover));
}

.msg-bubble {
  max-width: 76%;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--text-dark);
  background: var(--white);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
  word-break: break-word;
}

.chat-message.user .msg-bubble {
  background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
  color: var(--white);
  border: none;
  box-shadow: var(--shadow-md);
  border-bottom-left-radius: var(--radius-lg);
  border-bottom-right-radius: 4px;
}

.msg-time {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 3px;
  text-align: right;
}

.chat-message.user .msg-time {
  text-align: left;
}

/* Typing indicator */
.chatbot-typing {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.typing-bubble {
  background: var(--white);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  padding: 12px 16px;
  display: flex;
  gap: 4px;
  box-shadow: var(--shadow-sm);
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: var(--radius-full);
  animation: typing 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40%            { transform: translateY(-5px); opacity: 1; }
}

/* Quick reply chips */
.chatbot-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 8px;
  background: var(--light-bg);
}

.chip {
  background: var(--white);
  border: 1px solid var(--border-color);
  color: var(--primary-color);
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color var(--transition-fast),
              border-color var(--transition-fast),
              transform var(--transition-fast);
  white-space: nowrap;
}

.chip:hover {
  background: var(--section-alt);
  border-color: var(--primary-color);
  transform: translateY(-1px);
}

/* ── Chat Input Area ──────────────────────────────────────────── */
.chatbot-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  background: var(--white);
  flex-shrink: 0;
}

.chatbot-input {
  flex: 1;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 0.875rem;
  line-height: 1.5;
  resize: none;
  outline: none;
  max-height: 100px;
  min-height: 40px;
  overflow-y: auto;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  color: var(--text-dark);
  background: var(--light-bg);
}

.chatbot-input:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(26, 54, 93, 0.08);
  background: var(--white);
}

.chatbot-input::placeholder {
  color: var(--text-muted);
}

.chatbot-send {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
  color: var(--white);
  border: none;
  border-radius: var(--radius-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: transform var(--transition-fast),
              filter var(--transition-fast);
  flex-shrink: 0;
}

.chatbot-send:hover {
  filter: brightness(1.15);
  transform: scale(1.08);
}

.chatbot-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
  filter: none;
}

/* Powered by line */
.chatbot-footer {
  text-align: center;
  font-size: 0.65rem;
  color: var(--text-muted);
  padding: 4px 0 8px;
  background: var(--white);
  letter-spacing: 0.2px;
}

/* ── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .chatbot-trigger {
    bottom: 88px;
    right: 16px;
    width: 50px;
    height: 50px;
  }

  .chatbot-panel {
    bottom: 152px;
    right: 8px;
    left: 8px;
    width: auto;
    max-width: none;
    height: 70vh;
    border-radius: var(--radius-xl);
  }
}
