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

.ai-chatbot-host {
  --cb-primary:      #2271b1;
  --cb-primary-dark: #1a5a96;
  --cb-bg:           #ffffff;
  --cb-surface:      #f6f7f8;
  --cb-border:       #e2e8f0;
  --cb-text:         #1d2327;
  --cb-text-muted:   #6b7280;
  --cb-radius:       18px;
  --cb-shadow:       0 8px 32px rgba(0,0,0,0.16);
  --cb-z:            999999;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--cb-text);
  box-sizing: border-box;
}

.ai-chatbot-host *,
.ai-chatbot-host *::before,
.ai-chatbot-host *::after {
  box-sizing: inherit;
}

/* ── Toggle button ─────────────────────────────────────────────────────── */

.ai-chatbot-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--cb-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  z-index: var(--cb-z);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.25s cubic-bezier(.34,1.56,.64,1),
              box-shadow 0.2s;
  outline: none;
}

.ai-chatbot-toggle:hover {
  transform: scale(1.12);
  box-shadow: 0 6px 24px rgba(0,0,0,0.3);
}

.ai-chatbot-toggle.left {
  right: auto;
  left: 24px;
}

.ai-chatbot-toggle svg { pointer-events: none; }

/* Notification badge */
.ai-chatbot-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 12px;
  height: 12px;
  background: #ef4444;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
}

.ai-chatbot-badge.visible { display: block; }

/* ── Chat panel ────────────────────────────────────────────────────────── */

.ai-chatbot-panel {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  height: 560px;
  max-height: calc(100svh - 120px);
  background: var(--cb-bg);
  border-radius: var(--cb-radius);
  box-shadow: var(--cb-shadow);
  z-index: var(--cb-z);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform-origin: bottom right;
  transition: transform 0.28s cubic-bezier(.34,1.56,.64,1),
              opacity   0.2s;
}

.ai-chatbot-panel.left {
  right: auto;
  left: 24px;
  transform-origin: bottom left;
}

.ai-chatbot-panel.ai-hidden {
  transform: scale(0.78) translateY(8px);
  opacity: 0;
  pointer-events: none;
}

/* ── Header ────────────────────────────────────────────────────────────── */

.ai-chatbot-header {
  background: var(--cb-primary);
  color: #fff;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  user-select: none;
}

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

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

.ai-chatbot-header-name {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ai-chatbot-header-status {
  font-size: 12px;
  opacity: 0.82;
}

.ai-chatbot-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
  opacity: 0.75;
  transition: opacity 0.15s, background 0.15s;
  display: flex;
  align-items: center;
}

.ai-chatbot-close:hover {
  opacity: 1;
  background: rgba(255,255,255,0.15);
}

/* ── Messages area ─────────────────────────────────────────────────────── */

.ai-chatbot-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

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

/* Message bubbles */
.ai-msg {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  animation: ai-msg-in 0.22s ease;
}

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

.ai-msg.bot {
  background: var(--cb-surface);
  color: var(--cb-text);
  align-self: flex-start;
  border-bottom-left-radius: 5px;
}

.ai-msg.user {
  background: var(--cb-primary);
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 5px;
}

/* Streaming cursor */
.ai-msg.bot.streaming::after {
  content: '▍';
  display: inline-block;
  animation: ai-blink 0.7s step-end infinite;
  opacity: 0.7;
  font-size: 13px;
}

@keyframes ai-blink {
  0%, 100% { opacity: 0.7; }
  50%       { opacity: 0; }
}

/* Typing indicator (3 dots) */
.ai-typing-indicator {
  display: flex;
  gap: 5px;
  padding: 12px 14px;
  background: var(--cb-surface);
  border-radius: 18px;
  border-bottom-left-radius: 5px;
  align-self: flex-start;
}

.ai-typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--cb-text-muted);
  animation: ai-dot-bounce 1.2s infinite;
}

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

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

/* Error message */
.ai-msg-error {
  align-self: center;
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fca5a5;
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 13px;
  max-width: 90%;
  text-align: center;
}

/* ── Input area ────────────────────────────────────────────────────────── */

.ai-chatbot-input-area {
  padding: 12px 14px;
  border-top: 1px solid var(--cb-border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  background: var(--cb-bg);
}

.ai-chatbot-input {
  flex: 1;
  border: 1.5px solid var(--cb-border);
  border-radius: 22px;
  padding: 9px 16px;
  font-size: 14px;
  font-family: inherit;
  color: var(--cb-text);
  background: var(--cb-surface);
  resize: none;
  outline: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.45;
  transition: border-color 0.15s;
}

.ai-chatbot-input:focus { border-color: var(--cb-primary); }
.ai-chatbot-input::placeholder { color: var(--cb-text-muted); }

.ai-chatbot-send {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--cb-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s;
  outline: none;
}

.ai-chatbot-send:hover:not(:disabled) {
  background: var(--cb-primary-dark);
  transform: scale(1.08);
}

.ai-chatbot-send:disabled {
  opacity: 0.45;
  cursor: default;
}

/* ── Powered-by footer ─────────────────────────────────────────────────── */

.ai-chatbot-footer {
  text-align: center;
  font-size: 11px;
  color: var(--cb-text-muted);
  padding: 4px 0 8px;
  flex-shrink: 0;
}

/* ── Mobile ─────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
  .ai-chatbot-panel {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: 80svh;
    border-radius: var(--cb-radius) var(--cb-radius) 0 0;
  }

  .ai-chatbot-panel.left {
    left: 0;
    right: 0;
  }

  .ai-chatbot-panel.ai-hidden {
    transform: translateY(100%);
    opacity: 0;
  }
}
