/* ═══════════════════════════════════════
   IGY Apps AI Chatbot Widget
   ═══════════════════════════════════════ */

/* ── Floating Button ────────────────── */
.chatbot-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9998;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
}

[dir="rtl"] .chatbot-fab {
  right: auto;
  left: 24px;
}

.chatbot-fab:hover {
  transform: scale(1.1);
  box-shadow: 0 6px 28px rgba(99, 102, 241, 0.55);
}

.chatbot-fab svg {
  width: 26px;
  height: 26px;
  transition: transform 0.3s ease;
}

.chatbot-fab.active svg {
  transform: rotate(90deg);
}

/* Pulse animation */
.chatbot-fab::after {
  content: '';
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(99, 102, 241, 0.5);
  animation: chatbot-pulse 2.5s ease-in-out infinite;
  pointer-events: none;
}

.chatbot-fab.active::after {
  display: none;
}

@keyframes chatbot-pulse {
  0%, 100% { transform: scale(1); opacity: 0.6; }
  50% { transform: scale(1.2); opacity: 0; }
}

/* ── Chat Window ────────────────────── */
.chatbot-window {
  position: fixed;
  bottom: 92px;
  right: 24px;
  z-index: 9999;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 120px);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  opacity: 0;
  transform: translateY(20px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  background: var(--chatbot-bg, #ffffff);
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.18);
  border: 1px solid var(--chatbot-border, rgba(0, 0, 0, 0.08));
}

[dir="rtl"] .chatbot-window {
  right: auto;
  left: 24px;
}

.chatbot-window.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(135deg, #6366f1, #8b5cf6);
  color: #fff;
  flex-shrink: 0;
}

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

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

.chatbot-header-info {
  flex: 1;
  min-width: 0;
}

.chatbot-header-title {
  font-weight: 600;
  font-size: 0.95rem;
  line-height: 1.3;
}

.chatbot-header-status {
  font-size: 0.75rem;
  opacity: 0.85;
}

.chatbot-close-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  transition: background 0.2s;
  flex-shrink: 0;
}

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

/* ── Messages ───────────────────────── */
.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--chatbot-messages-bg, #f8fafc);
}

.chatbot-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: chatbot-msg-in 0.3s ease;
}

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

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

[dir="rtl"] .chatbot-msg.user {
  flex-direction: row;
}

.chatbot-msg-bubble {
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.875rem;
  line-height: 1.55;
  word-break: break-word;
}

.chatbot-msg.bot .chatbot-msg-bubble {
  background: var(--chatbot-bot-bg, #ffffff);
  color: var(--chatbot-bot-text, #334155);
  border: 1px solid var(--chatbot-border, rgba(0, 0, 0, 0.06));
  border-bottom-left-radius: 4px;
}

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

.chatbot-msg.user .chatbot-msg-bubble {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  border-bottom-right-radius: 4px;
}

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

/* Markdown inside bot messages */
.chatbot-msg-bubble h1, .chatbot-msg-bubble h2, .chatbot-msg-bubble h3 {
  font-size: 0.95rem;
  font-weight: 600;
  margin: 8px 0 4px;
}

.chatbot-msg-bubble h1:first-child, .chatbot-msg-bubble h2:first-child, .chatbot-msg-bubble h3:first-child {
  margin-top: 0;
}

.chatbot-msg-bubble p { margin: 4px 0; }
.chatbot-msg-bubble ul, .chatbot-msg-bubble ol { margin: 4px 0; padding-left: 1.2em; }
[dir="rtl"] .chatbot-msg-bubble ul, [dir="rtl"] .chatbot-msg-bubble ol { padding-left: 0; padding-right: 1.2em; }
.chatbot-msg-bubble li { margin: 2px 0; }
.chatbot-msg-bubble code { background: rgba(99,102,241,0.1); padding: 1px 4px; border-radius: 4px; font-size: 0.82em; }
.chatbot-msg-bubble a { color: #6366f1; text-decoration: underline; }
.chatbot-msg.user .chatbot-msg-bubble a { color: #e0e7ff; }
.chatbot-msg-bubble strong { font-weight: 600; }

/* Typing indicator */
.chatbot-typing {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  align-items: center;
}

.chatbot-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #a5b4fc;
  animation: chatbot-bounce 1.2s ease-in-out infinite;
}

.chatbot-typing span:nth-child(2) { animation-delay: 0.15s; }
.chatbot-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes chatbot-bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ── Suggestions ────────────────────── */
.chatbot-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 16px 12px;
  background: var(--chatbot-messages-bg, #f8fafc);
}

.chatbot-suggestion-btn {
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--chatbot-border, rgba(99, 102, 241, 0.3));
  background: var(--chatbot-bg, #ffffff);
  color: #6366f1;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.chatbot-suggestion-btn:hover {
  background: #6366f1;
  color: #fff;
  border-color: #6366f1;
}

/* ── Input ──────────────────────────── */
.chatbot-input-area {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--chatbot-border, rgba(0, 0, 0, 0.06));
  background: var(--chatbot-bg, #ffffff);
  flex-shrink: 0;
}

.chatbot-input {
  flex: 1;
  border: 1px solid var(--chatbot-border, rgba(0, 0, 0, 0.12));
  border-radius: 22px;
  padding: 9px 16px;
  font-size: 0.875rem;
  outline: none;
  background: var(--chatbot-input-bg, #f8fafc);
  color: var(--chatbot-bot-text, #334155);
  transition: border-color 0.2s;
  font-family: inherit;
}

.chatbot-input:focus {
  border-color: #6366f1;
}

.chatbot-input::placeholder {
  color: var(--chatbot-placeholder, #94a3b8);
}

.chatbot-send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s, opacity 0.2s;
}

.chatbot-send-btn:hover {
  transform: scale(1.08);
}

.chatbot-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

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

[dir="rtl"] .chatbot-send-btn svg {
  transform: scaleX(-1);
}

/* ── Dark Mode ──────────────────────── */
[data-theme="dark"] .chatbot-window {
  --chatbot-bg: #1e1e2e;
  --chatbot-messages-bg: #151521;
  --chatbot-border: rgba(255, 255, 255, 0.08);
  --chatbot-bot-bg: #252536;
  --chatbot-bot-text: #e2e8f0;
  --chatbot-input-bg: #252536;
  --chatbot-placeholder: #64748b;
}

[data-theme="dark"] .chatbot-fab {
  box-shadow: 0 4px 20px rgba(99, 102, 241, 0.3);
}

/* ── Mobile ─────────────────────────── */
@media (max-width: 480px) {
  .chatbot-window {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    max-height: 100%;
    border-radius: 0;
  }

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

  .chatbot-fab {
    bottom: 16px;
    right: 16px;
  }

  [dir="rtl"] .chatbot-fab {
    right: auto;
    left: 16px;
  }
}
