.chatbot-root {
  --bot-accent: #2563eb;
  --bot-bg: #ffffff;
  --bot-fg: #111827;
  --bot-muted: #4b5563;
  --bot-border: #e5e7eb;
  --bot-radius: 14px;
  --bot-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial,
    sans-serif;
  color: var(--bot-fg);
}
/* Defensive scope: don't let parent-site CSS leak weird sizing, margins,
 * min-heights, or fonts into the widget. The site uses dark themes with
 * generous paragraph spacing and min-heights, which would otherwise stretch
 * the chat bubbles and push citations outside the bubble. */
.chatbot-root, .chatbot-root * {
  box-sizing: border-box;
  font-family: inherit;
  min-height: 0;
  min-width: 0;
}
.chatbot-root p,
.chatbot-root ul,
.chatbot-root li,
.chatbot-root span,
.chatbot-root a {
  margin: 0;
  padding: 0;
  text-indent: 0;
  font-size: inherit;
  line-height: inherit;
  font-weight: inherit;
}

/* Force the [hidden] attribute to actually hide. The parent site's CSS
 * sometimes sets display: flex / display: block on these classes via
 * higher-specificity rules, which would otherwise override the user-agent
 * default and leave the panel visible after pressing close. */
.chatbot-panel[hidden],
.chatbot-bubble[hidden] {
  display: none !important;
}

.chatbot-bubble {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--bot-accent);
  color: white;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: var(--bot-shadow);
  z-index: 999998;
  transition: transform 0.15s ease;
}
.chatbot-bubble:hover { transform: scale(1.05); }

.chatbot-panel {
  position: fixed;
  right: 20px;
  bottom: 20px;
  width: 560px;
  height: 720px;
  background: var(--bot-bg);
  color: var(--bot-fg);
  border-radius: var(--bot-radius);
  box-shadow: var(--bot-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 999999;
}

.chatbot-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bot-accent);
  color: white;
  font-weight: 600;
}
.chatbot-header-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}
.chatbot-reset {
  background: transparent;
  color: white;
  border: none;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 6px;
  opacity: 0.8;
}
.chatbot-reset:hover { opacity: 1; }
.chatbot-close {
  background: transparent;
  color: white;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 0 4px;
}

.chatbot-thread {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bot-bg);
  color: var(--bot-fg);
}
.chatbot-msg {
  max-width: 90%;
  padding: 10px 12px;
  border-radius: 10px;
  line-height: 1.45;
  font-size: 14px;
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  flex-shrink: 0;
}
.chatbot-user {
  align-self: flex-end;
  background: var(--bot-accent);
  color: white;
  border-bottom-right-radius: 2px;
}
.chatbot-assistant {
  align-self: flex-start;
  background: #f3f4f6;
  color: var(--bot-fg);
  border-bottom-left-radius: 2px;
}
.chatbot-pending {
  color: var(--bot-muted);
  display: inline-flex;
  gap: 4px;
  align-items: center;
  min-height: 18px;
}
.chatbot-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--bot-muted);
  display: inline-block;
  animation: chatbot-bounce 1.2s infinite ease-in-out both;
}
.chatbot-dot:nth-child(2) { animation-delay: 0.15s; }
.chatbot-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatbot-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

.chatbot-msg-divider {
  height: 0;
  border-top: 2px solid var(--bot-border);
  margin: 4px 0 0 0;
  align-self: stretch;
  opacity: 0.6;
}

.chatbot-busy .chatbot-input,
.chatbot-busy .chatbot-send {
  opacity: 0.55;
  cursor: not-allowed;
}
.chatbot-msg-body {
  all: revert;
  display: block;
  margin: 0;
  padding: 0;
  font: inherit;
  color: inherit;
  line-height: inherit;
  white-space: pre-wrap;
  background: none;
  border: 0;
}

.chatbot-citations {
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.chatbot-citations li {
  padding: 2px 0 2px 10px;
  border-left: 2px solid var(--bot-border);
  color: var(--bot-fg);
  background: none;
  border-radius: 0;
  border-top: 0;
  border-right: 0;
  border-bottom: 0;
  min-width: 0;
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.chatbot-cite {
  all: revert;
  font: inherit;
  font-weight: 600;
  color: var(--bot-accent);
  text-decoration: none;
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 0;
  background: none;
  border: 0;
  line-height: inherit;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.chatbot-cite:hover { text-decoration: underline; }
.chatbot-relation {
  all: revert;
  display: block;
  margin: 2px 0 0 0;
  padding: 0;
  font: inherit;
  font-size: 13px;
  color: var(--bot-muted);
  line-height: 1.4;
  background: none;
  border: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.chatbot-kind-image::before { content: "img - "; opacity: 0.7; }
.chatbot-kind-animation::before { content: "anim - "; opacity: 0.7; }

.chatbot-form {
  display: flex;
  gap: 8px;
  padding: 10px;
  border-top: 1px solid var(--bot-border);
  background: var(--bot-bg);
}
.chatbot-input {
  flex: 1;
  border: 1px solid var(--bot-border);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  color: var(--bot-fg);
  background: var(--bot-bg);
  outline: none;
}
.chatbot-input:focus { border-color: var(--bot-accent); }
.chatbot-send {
  background: var(--bot-accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 600;
}

@media (max-width: 600px) {
  .chatbot-panel {
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 80vh;
    border-radius: var(--bot-radius) var(--bot-radius) 0 0;
  }
}
