/* ── AI Chat Bot Widget — self-contained tokens so it looks identical on every
   panel (frontend, tourist, guide, admin) regardless of that page's own theme. ── */
.chatbot-widget {
  --cb-brand: #4f46e5;
  --cb-brand-dark: #4338ca;
  --cb-surface: #ffffff;
  --cb-surface-2: #f8fafc;
  --cb-border: #e5e7eb;
  --cb-text: #1e293b;
  --cb-text-muted: #64748b;
  position: fixed;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  right: 22px;
  z-index: 99990;
  font-family: inherit;
}
[dir="rtl"] .chatbot-widget { right: auto; left: 22px; }

[data-theme="dark"] .chatbot-widget {
  --cb-surface: #1a1c23;
  --cb-surface-2: #20222b;
  --cb-border: #2c2f3a;
  --cb-text: #e2e8f0;
  --cb-text-muted: #94a3b8;
}

.chatbot-toggle-btn {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--cb-brand), #7c3aed);
  color: #fff;
  font-size: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(79,70,229,.35);
  transition: transform .2s, box-shadow .2s;
}
.chatbot-toggle-btn:hover { transform: translateY(-2px); box-shadow: 0 14px 36px rgba(79,70,229,.45); }
.chatbot-toggle-icon-close { display: none; }
.chatbot-widget.open .chatbot-toggle-icon-open { display: none; }
.chatbot-widget.open .chatbot-toggle-icon-close { display: inline-block; }

.chatbot-panel {
  position: absolute;
  bottom: 72px;
  right: 0;
  width: 360px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: 70vh;
  background: var(--cb-surface);
  border: 1px solid var(--cb-border);
  border-radius: 18px;
  box-shadow: 0 24px 64px rgba(0,0,0,.18);
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: chatbotFadeIn .18s ease;
}
[dir="rtl"] .chatbot-panel { right: auto; left: 0; }
.chatbot-widget.open .chatbot-panel { display: flex; }

@keyframes chatbotFadeIn {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 16px;
  background: linear-gradient(135deg, var(--cb-brand), #7c3aed);
  color: #fff;
  flex-shrink: 0;
}
.chatbot-header-info { display: flex; align-items: center; gap: 10px; }
.chatbot-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.chatbot-title { font-size: 14px; font-weight: 700; line-height: 1.2; }
.chatbot-status { font-size: 11px; opacity: .85; display: flex; align-items: center; gap: 5px; }
.chatbot-status-dot { width: 6px; height: 6px; border-radius: 50%; background: #4ade80; flex-shrink: 0; }
.chatbot-close-btn {
  width: 28px; height: 28px;
  border: none; background: rgba(255,255,255,.15);
  border-radius: 8px; color: #fff; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .15s;
}
.chatbot-close-btn:hover { background: rgba(255,255,255,.28); }

.chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--cb-surface-2);
}

.chatbot-msg { display: flex; }
.chatbot-msg-user { justify-content: flex-end; }
.chatbot-msg-bubble {
  max-width: 82%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.chatbot-msg-bot .chatbot-msg-bubble {
  background: var(--cb-surface);
  border: 1px solid var(--cb-border);
  color: var(--cb-text);
  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, var(--cb-brand), #7c3aed);
  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; }
.chatbot-msg-error .chatbot-msg-bubble { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }

.chatbot-msg-bot .chatbot-msg-bubble a { color: var(--cb-brand); font-weight: 600; word-break: break-all; }
.chatbot-msg-bot .chatbot-msg-bubble a:hover { text-decoration: underline; }
.chatbot-msg-user .chatbot-msg-bubble a { color: #fff; font-weight: 600; text-decoration: underline; word-break: break-all; }

.chatbot-typing {
  display: flex;
  gap: 4px;
  padding: 0 16px 8px;
  background: var(--cb-surface-2);
}
.chatbot-typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--cb-text-muted);
  animation: chatbotTypingDot 1s infinite ease-in-out;
}
.chatbot-typing span:nth-child(2) { animation-delay: .15s; }
.chatbot-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes chatbotTypingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chatbot-quota {
  font-size: 11px;
  color: var(--cb-text-muted);
  padding: 0 16px;
  text-align: center;
}
.chatbot-quota.limit-reached { color: #dc2626; font-weight: 600; }

.chatbot-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid var(--cb-border);
  background: var(--cb-surface);
  flex-shrink: 0;
}
.chatbot-input {
  flex: 1;
  border: 1.5px solid var(--cb-border);
  background: var(--cb-surface-2);
  color: var(--cb-text);
  border-radius: 99px;
  padding: 9px 16px;
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
.chatbot-input:focus { border-color: var(--cb-brand); }
.chatbot-input:disabled { opacity: .6; }
.chatbot-send-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--cb-brand);
  color: #fff;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s;
}
.chatbot-send-btn:hover { background: var(--cb-brand-dark); }
.chatbot-send-btn:disabled { opacity: .5; cursor: not-allowed; }

@media (max-width: 480px) {
  .chatbot-widget {
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    right: 16px;
  }
  [dir="rtl"] .chatbot-widget { right: auto; left: 16px; }
  .chatbot-panel { width: calc(100vw - 32px); height: 60vh; }
}
/* Push above mobile booking bar when present (tour show page) */
@media (max-width: 900px) {
  body.td-show-page .chatbot-widget {
    bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  }
}
