/* ─── Chatbot Widget ─────────────────────────────────────────────────────── */

#chatbot-toggle {
  position: fixed;
  bottom: 32px; right: 32px;
  width: 60px; height: 60px;
  border-radius: 50%;
  background: var(--gradient);
  color: #fff; font-size: 1.4rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 24px rgba(59, 130, 246, 0.45);
  z-index: 1000;
  transition: transform var(--transition), box-shadow var(--transition);
}

#chatbot-toggle:hover { transform: translateY(-4px); box-shadow: 0 8px 30px rgba(59, 130, 246, 0.55); }

[dir="rtl"] #chatbot-toggle { right: auto; left: 32px; }

#chatbot-toggle .icon-close { display: none; }
#chatbot-toggle.open .icon-chat { display: none; }
#chatbot-toggle.open .icon-close { display: block; }

#chatbot-teaser {
  position: fixed;
  bottom: 104px; right: 32px;
  max-width: 240px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px 34px 12px 14px;
  font-size: 0.82rem;
  line-height: 1.4;
  color: var(--text-primary);
  z-index: 999;
  cursor: pointer;
  opacity: 0; visibility: hidden; pointer-events: none;
  transform: translateY(10px);
  transition: opacity var(--transition), transform var(--transition), visibility var(--transition);
}

#chatbot-teaser::after {
  content: '';
  position: absolute;
  bottom: -7px; right: 26px;
  width: 14px; height: 14px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  transform: rotate(45deg);
}

#chatbot-teaser.show { opacity: 1; visibility: visible; pointer-events: all; transform: translateY(0); }

.chatbot-teaser-icon { color: var(--accent-bright); margin-right: 6px; }
[dir="rtl"] .chatbot-teaser-icon { margin-right: 0; margin-left: 6px; }

[dir="rtl"] #chatbot-teaser { right: auto; left: 32px; padding: 12px 14px 12px 34px; }
[dir="rtl"] #chatbot-teaser::after { right: auto; left: 26px; }

#chatbot-teaser-close {
  position: absolute;
  top: 8px; right: 8px;
  width: 22px; height: 22px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  font-size: 0.72rem;
  transition: all var(--transition);
}

#chatbot-teaser-close:hover { background: var(--accent-glow); color: var(--accent-bright); }

[dir="rtl"] #chatbot-teaser-close { right: auto; left: 8px; }

@media (max-width: 600px) {
  #chatbot-teaser {
    bottom: 76px; right: 14px;
    max-width: calc(100vw - 80px);
  }
  [dir="rtl"] #chatbot-teaser { right: auto; left: 14px; }
}

#chatbot-panel {
  position: fixed;
  bottom: 106px; right: 32px;
  width: 380px; max-width: calc(100vw - 32px);
  height: 560px; max-height: calc(100vh - 140px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow), var(--shadow-accent);
  display: flex; flex-direction: column;
  overflow: hidden;
  z-index: 1000;
  opacity: 0; visibility: hidden; pointer-events: none;
  transform: translateY(16px) scale(0.97);
  transform-origin: bottom right;
  transition: opacity var(--transition), transform var(--transition), visibility var(--transition);
}

[dir="rtl"] #chatbot-panel { right: auto; left: 32px; transform-origin: bottom left; }

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

.chatbot-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
  flex-shrink: 0;
}

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

.chatbot-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--gradient);
  color: #fff; font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.chatbot-title { font-size: 0.95rem; font-weight: 700; color: var(--text-primary); }

.chatbot-status {
  display: flex; align-items: center; gap: 6px;
  font-size: 0.78rem; color: var(--text-muted);
}

.chatbot-status .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #34d399;
  animation: pulse-dot 1.5s ease-in-out infinite;
}

#chatbot-close {
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition);
  flex-shrink: 0;
}

#chatbot-close:hover { background: var(--accent-glow); color: var(--accent-bright); }

.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex; flex-direction: column; gap: 12px;
}

.chatbot-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: break-word;
}

.chatbot-msg strong { color: inherit; font-weight: 700; }

.chatbot-msg p { margin: 0 0 8px; }
.chatbot-msg p:last-child { margin-bottom: 0; }

.chatbot-msg ul, .chatbot-msg ol {
  margin: 0 0 8px;
  padding-left: 20px;
}
[dir="rtl"] .chatbot-msg ul, [dir="rtl"] .chatbot-msg ol { padding-left: 0; padding-right: 20px; }
.chatbot-msg li { margin-bottom: 3px; }

.chatbot-msg h1, .chatbot-msg h2, .chatbot-msg h3, .chatbot-msg h4 {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 10px 0 6px;
  color: var(--text-primary);
}
.chatbot-msg h1:first-child, .chatbot-msg h2:first-child,
.chatbot-msg h3:first-child, .chatbot-msg h4:first-child { margin-top: 0; }

.chatbot-msg a {
  color: var(--accent-bright);
  text-decoration: underline;
  word-break: break-all;
}
.chatbot-msg-user a { color: #fff; }

.chatbot-msg code {
  background: rgba(0, 0, 0, 0.18);
  padding: 2px 5px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.82em;
}

.chatbot-msg pre {
  background: rgba(0, 0, 0, 0.22);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0 0 8px;
}
.chatbot-msg pre code { background: none; padding: 0; }

.chatbot-msg table {
  display: block;
  overflow-x: auto;
  border-collapse: collapse;
  width: max-content;
  max-width: 100%;
  margin: 0 0 8px;
  font-size: 0.82rem;
}
.chatbot-msg th, .chatbot-msg td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
  word-break: normal;
  overflow-wrap: normal;
  white-space: nowrap;
}
[dir="rtl"] .chatbot-msg th, [dir="rtl"] .chatbot-msg td { text-align: right; }
.chatbot-msg th { background: rgba(0, 0, 0, 0.15); font-weight: 700; }

.chatbot-msg blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  margin: 0 0 8px;
  color: inherit;
  opacity: 0.85;
}
[dir="rtl"] .chatbot-msg blockquote { border-left: none; border-right: 3px solid var(--accent); padding-left: 0; padding-right: 10px; }

.chatbot-msg hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }

.chatbot-msg-user {
  align-self: flex-end;
  background: var(--gradient);
  color: #fff;
  border-bottom-right-radius: 4px;
}

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

.chatbot-msg-assistant {
  align-self: flex-start;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

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

.chatbot-typing {
  display: flex; align-items: center; gap: 4px;
  padding: 14px 16px;
}

.chatbot-typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}

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

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.chatbot-input-row {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#chatbot-input {
  flex: 1;
  resize: none;
  max-height: 120px;
  min-height: 40px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.4;
  transition: border-color var(--transition);
  overflow-y: auto;
  scrollbar-width: none; /* Firefox */
}

#chatbot-input::-webkit-scrollbar { display: none; } /* Chrome/Edge/Safari */
#chatbot-input::-webkit-resizer { display: none; }

#chatbot-input:focus { outline: none; border-color: var(--accent); }
#chatbot-input:disabled { opacity: 0.6; }

#chatbot-send {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: var(--gradient);
  color: #fff; font-size: 0.95rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}

#chatbot-send:hover:not(:disabled) { transform: translateY(-2px); }
#chatbot-send:disabled { opacity: 0.5; cursor: default; }

[dir="rtl"] #chatbot-send { transform: scaleX(-1); }
[dir="rtl"] #chatbot-send:hover:not(:disabled) { transform: scaleX(-1) translateY(-2px); }

.chatbot-disclaimer {
  padding: 0 16px 14px;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-align: center;
  flex-shrink: 0;
}

/* ─── Mobile: full-width bottom sheet ────────────────────────────────────── */
@media (max-width: 600px) {
  #chatbot-toggle {
    bottom: 16px; right: 14px;
    width: 52px; height: 52px; font-size: 1.2rem;
  }
  [dir="rtl"] #chatbot-toggle { right: auto; left: 14px; }

  #chatbot-panel {
    bottom: 0; right: 0; left: 0;
    width: 100%; max-width: 100%;
    height: 78vh; max-height: 78vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
  }
  [dir="rtl"] #chatbot-panel { left: 0; }
  #chatbot-panel.open { transform: translateY(0); }
}
