/* ── Chatbot Widget ── */

.chatbot-widget {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}

/* Toggle Button */

.chatbot-toggle {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--gradient-primary);
  color: var(--color-text-inverse);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg), 0 0 0 0 rgba(31, 60, 245, 0.3);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  flex-shrink: 0;
}

.chatbot-toggle:hover {
  transform: scale(1.06);
  box-shadow: var(--shadow-lg), 0 0 0 8px rgba(31, 60, 245, 0.10);
}

.chatbot-toggle:focus-visible {
  outline: 2px solid var(--color-primary);
  outline-offset: 3px;
}

.chatbot-toggle-icon {
  position: absolute;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.chatbot-toggle-icon--chat  { opacity: 1; transform: scale(1) rotate(0deg); }
.chatbot-toggle-icon--close { opacity: 0; transform: scale(0.5) rotate(-90deg); }

.chatbot-widget.is-open .chatbot-toggle-icon--chat  { opacity: 0; transform: scale(0.5) rotate(90deg); }
.chatbot-widget.is-open .chatbot-toggle-icon--close { opacity: 1; transform: scale(1) rotate(0deg); }

/* Panel */

.chatbot-panel {
  width: 360px;
  max-height: 540px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(14px) scale(0.97);
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  transform-origin: bottom right;
}

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

/* Header */

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

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

.chatbot-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chatbot-header-name {
  font-family: 'Syne', sans-serif;
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-text-primary);
  line-height: 1.2;
}

.chatbot-header-status {
  font-size: 0.71rem;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 1px;
}

.chatbot-status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}

.chatbot-close {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.chatbot-close:hover { background: var(--color-surface-alt); color: var(--color-text-primary); }
.chatbot-close:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* Messages */

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

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

.chatbot-msg {
  display: flex;
  flex-direction: column;
  max-width: 84%;
  animation: chatMsgIn 0.18s ease forwards;
}

@keyframes chatMsgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chatbot-msg--bot  { align-self: flex-start; }
.chatbot-msg--user { align-self: flex-end; }

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

.chatbot-msg--bot .chatbot-msg-bubble {
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-bottom-left-radius: 4px;
  color: var(--color-text-primary);
}

.chatbot-msg--user .chatbot-msg-bubble {
  background: var(--gradient-primary);
  color: var(--color-text-inverse);
  border-bottom-right-radius: 4px;
}

.chatbot-msg-bubble a {
  color: var(--color-primary);
  text-decoration: underline;
  word-break: break-all;
}

.chatbot-msg--user .chatbot-msg-bubble a {
  color: rgba(255, 255, 255, 0.9);
}

.chatbot-msg--error .chatbot-msg-bubble {
  background: rgba(220, 38, 38, 0.06);
  border: 1px solid rgba(220, 38, 38, 0.2);
  color: #991b1b;
}

/* Typing indicator */

.chatbot-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-light);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  width: fit-content;
  align-self: flex-start;
}

.chatbot-typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: chatTyping 1.2s ease infinite;
}

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

@keyframes chatTyping {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%            { opacity: 1;   transform: translateY(-3px); }
}

/* Input area */

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

.chatbot-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 9px 12px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.875rem;
  color: var(--color-text-primary);
  background: var(--color-surface);
  line-height: 1.5;
  max-height: 100px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

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

.chatbot-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}

.chatbot-send {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: none;
  background: var(--gradient-primary);
  color: var(--color-text-inverse);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

.chatbot-send:hover:not(:disabled) { opacity: 0.88; transform: scale(1.05); }
.chatbot-send:disabled { opacity: 0.35; cursor: not-allowed; }
.chatbot-send:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

/* Responsive */

@media (max-width: 640px) {
  .chatbot-widget { bottom: 16px; right: 16px; }
  .chatbot-panel  { width: calc(100vw - 32px); max-height: 72vh; }
}

@media (prefers-reduced-motion: reduce) {
  .chatbot-panel,
  .chatbot-toggle-icon,
  .chatbot-msg          { transition: none; animation: none; }
  .chatbot-typing-dot   { animation: none; opacity: 0.5; }
}
