/* ===== Chatbot widget ===== */
.chatbot {
  --chat-w: 380px;
  --chat-h: 520px;
  --chat-radius: 20px;
  --chat-user: #3b82f6;
  --chat-user-hover: #2563eb;
  --chat-bot: #1e1e28;
  --chat-panel: #12121a;
  --chat-border: rgba(255, 255, 255, 0.08);
  --chat-fab-size: 56px;
  position: fixed;
  right: max(1rem, env(safe-area-inset-right, 0px));
  bottom: max(5.75rem, calc(5.75rem + env(safe-area-inset-bottom, 0px)));
  z-index: 200;
  font-family: var(--sans);
}

.chatbot__fab {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--chat-fab-size);
  height: var(--chat-fab-size);
  border: none;
  border-radius: 50%;
  background: linear-gradient(135deg, #7c3aed 0%, #3b82f6 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 28px rgba(59, 130, 246, 0.45);
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.chatbot__fab:hover {
  transform: scale(1.06);
  box-shadow: 0 10px 32px rgba(59, 130, 246, 0.55);
}

.chatbot__fab svg {
  width: 26px;
  height: 26px;
}

.chatbot__fab-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #22c55e;
  border: 2px solid #12121a;
}

.chatbot.is-open .chatbot__fab {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.8);
}

.chatbot__panel {
  position: absolute;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: var(--chat-w);
  height: var(--chat-h);
  max-height: calc(100dvh - var(--header-h) - 2rem);
  background: var(--chat-panel);
  border: 1px solid var(--chat-border);
  border-radius: var(--chat-radius);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity 0.28s ease, transform 0.28s ease, visibility 0.28s;
}

.chatbot.is-open .chatbot__panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.chatbot__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.15rem 0.9rem;
  border-bottom: 1px solid var(--chat-border);
  background: rgba(255, 255, 255, 0.02);
}

.chatbot__title-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.chatbot__ai-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
  background: linear-gradient(135deg, #7c3aed 0%, #3b82f6 100%);
  color: #fff;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  line-height: 1;
}

.chatbot__title {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}

.chatbot__status {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.68rem;
  font-weight: 500;
  color: #4ade80;
}

.chatbot__close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.chatbot__close:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.chatbot__messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  -webkit-overflow-scrolling: touch;
}

.chatbot__msg {
  max-width: 88%;
  padding: 0.75rem 0.95rem;
  border-radius: 16px;
  font-size: 0.82rem;
  line-height: 1.55;
  word-break: break-word;
  animation: chatbot-msg-in 0.3s ease;
}

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

.chatbot__msg--bot {
  align-self: flex-start;
  background: var(--chat-bot);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chatbot__msg--bot a {
  color: #93c5fd;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.chatbot__msg--bot a:hover {
  color: #bfdbfe;
}

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

.chatbot__msg--fallback {
  align-self: stretch;
  max-width: 100%;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: var(--text);
  border-radius: 14px;
}

.chatbot__fallback-text {
  margin-bottom: 0.85rem;
  font-size: 0.8rem;
  line-height: 1.5;
}

.chatbot__fallback-btn {
  display: block;
  width: 100%;
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 999px;
  background: var(--chat-user);
  color: #fff;
  font-size: 0.78rem;
  font-weight: 600;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s;
}

.chatbot__fallback-btn:hover {
  background: var(--chat-user-hover);
}

.chatbot__typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 0.85rem 1rem;
  background: var(--chat-bot);
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}

.chatbot__typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-dim);
  animation: chatbot-typing 1.2s infinite;
}

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

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

.chatbot__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.5rem 1rem 0.75rem;
  border-top: 1px solid var(--chat-border);
  background: rgba(0, 0, 0, 0.15);
  flex-shrink: 0;
}

.chatbot__chip {
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--chat-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.chatbot__chip:hover {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.35);
  color: var(--text);
}

.chatbot__form {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.85rem 1rem calc(0.85rem + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--chat-border);
  background: rgba(0, 0, 0, 0.2);
}

.chatbot__input {
  flex: 1;
  min-width: 0;
  padding: 0.7rem 1rem;
  border: 1px solid var(--chat-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.2s;
}

.chatbot__input::placeholder {
  color: var(--text-dim);
}

.chatbot__input:focus {
  border-color: rgba(59, 130, 246, 0.5);
}

.chatbot__send {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--chat-user);
  color: #fff;
  cursor: pointer;
  transition: background 0.2s, transform 0.15s;
}

.chatbot__send:hover {
  background: var(--chat-user-hover);
}

.chatbot__send:active {
  transform: scale(0.94);
}

.chatbot__send svg {
  width: 18px;
  height: 18px;
}

@media (max-width: 480px) {
  .chatbot {
    right: max(0.85rem, env(safe-area-inset-right, 0px));
    bottom: max(4.5rem, calc(4.5rem + env(safe-area-inset-bottom, 0px)));
    --chat-fab-size: 50px;
  }

  .chatbot__panel {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    height: min(85dvh, 560px);
    max-height: 85dvh;
    border-radius: var(--chat-radius) var(--chat-radius) 0 0;
    border-bottom: none;
    transform: translateY(100%);
  }

  .chatbot.is-open .chatbot__panel {
    transform: translateY(0);
  }
}
