.ai-chatbot {
  --ai-spacing: 1em;
  --ai-border-opacity: color-mix(in srgb, currentColor, transparent 85%);
  --ai-bg-opacity: color-mix(in srgb, currentColor, transparent 96%);

  border: 1px solid var(--ai-border-opacity);

  font-family: inherit;
  color: inherit;
  line-height: inherit;

  display: flex;
  flex-direction: column;
  height: 90dvh;
}

/* Resetting nested buttons and inputs to inherit host styles */
.ai-chatbot button,
.ai-chatbot textarea {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--ai-border-opacity);
  padding: 0.5em 1em;
  border-radius: 0.25em;
  cursor: pointer;
}

.ai-chatbot__launcher {
  border: 2px solid currentColor;
  font-weight: bold;
  display: flex;
  align-items: center;
  gap: 0.5em;
}

.ai-chatbot__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75em var(--ai-spacing);
  border-bottom: 1px solid var(--ai-border-opacity);
  background: var(--ai-bg-opacity);
}

.ai-chatbot__title {
  font-size: 1.1em;
  margin: 0;
}
.ai-chatbot__messages {
  flex: 1;
  overflow-y: auto;
  padding: var(--ai-spacing);
  display: flex;
  flex-direction: column;
  gap: 0.75em;
  min-height: 200px;
}

.ai-chatbot__intro-text {
  font-size: 0.9em;
  opacity: 0.8;
  margin-bottom: 0.5em;
}

.ai-chatbot__suggestion-btn {
  display: block;
  width: 100%;
  text-align: left;
  font-size: 0.85em;
  margin-bottom: 0.25em;
  background: var(--ai-bg-opacity);
}

.ai-chatbot__footer {
  padding: var(--ai-spacing);
  border-top: 1px solid var(--ai-border-opacity);
}

.ai-chatbot__input-wrapper {
  display: flex;
  gap: 0.5em;
  align-items: flex-end;
}

.ai-chatbot__input {
  flex: 1;
  resize: none;
  min-height: 1.5em;
  max-height: 5em;
  border-color: var(--ai-border-opacity);
}

.ai-chatbot__send {
  aspect-ratio: 1/1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.5em;
}

.ai-chatbot__send:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.ai-chatbot__clear {
  border: none;
  font-size: 0.75em;
  opacity: 0.6;
  padding: 0;
  margin-top: 0.5em;
  text-decoration: underline;
}

.ai-chatbot__message-content {
  margin-inline-start: 0;
}

.ai-chatbot__message-content--user {
  padding-block: 0.25em;
  padding-inline: 0.5em;
  background-color: var(--ai-bg-opacity);
}

.ai-chatbot__message--user {
  width: fit-content;
  min-width: 30%;
  max-width: 60%;
  margin-inline-start: auto;
}

/*
 * Bot messages hug their content too, so a bubble holding only the typing
 * indicator is dot-sized rather than panel-wide. fit-content resolves to the
 * available width once the text is long enough to wrap, so real answers are
 * unaffected. No min-width here, unlike user messages, or the indicator would
 * be padded back out.
 */
.ai-chatbot__message:not(.ai-chatbot__message--user) {
  width: fit-content;
  max-width: 90%;
}

.ai-chatbot__actions--footer {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.75em;
}

.ai-chatbot__disclaimer {
  margin: 0;
  font-size: 0.7em;
  line-height: 1.4;
  opacity: 0.8;
}

/* Typing indicator: three bouncing dots. */
.ai-chatbot__thinking {
  display: flex;
  align-items: center;
  gap: 0.3em;
  padding: 0.35em 0;
}

/*
 * An author display value beats the UA rule for [hidden], so without this the
 * dots would stay on screen after the answer has finished streaming.
 */
.ai-chatbot__thinking[hidden] {
  display: none;
}

.ai-chatbot__thinking-dot {
  width: 0.5em;
  height: 0.5em;
  border-radius: 50%;
  background-color: currentColor;
  animation: ai-chatbot-thinking 1.4s ease-in-out infinite both;
}

/*
 * Negative delays so all three are already mid-cycle on the first frame,
 * rather than the row sitting still until the stagger catches up.
 */
.ai-chatbot__thinking-dot:nth-child(1) {
  animation-delay: -0.32s;
}

.ai-chatbot__thinking-dot:nth-child(2) {
  animation-delay: -0.16s;
}

.ai-chatbot__thinking-dot:nth-child(3) {
  animation-delay: 0s;
}

@keyframes ai-chatbot-thinking {
  0%,
  80%,
  100% {
    transform: translateY(0);
  }
  40% {
    transform: translateY(-0.45em);
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-chatbot__thinking-dot {
    animation: none;
    opacity: 0.55;
  }
}

/*
 * Tables in assistant answers.
 *
 * `display: block` on the table is what makes overflow-x work without a
 * wrapper element - the markup comes straight from the Markdown converter, so
 * there is nowhere to hang a scroll container. It costs the automatic table
 * layout, hence the explicit min-width on the cells to stop columns from
 * collapsing onto one word per line.
 */
.ai-chatbot__message-content table {
  display: block;
  overflow-x: auto;
  max-width: 100%;
  border-collapse: collapse;
  margin-block: 0.75em;
  font-size: 0.9em;
}

.ai-chatbot__message-content th,
.ai-chatbot__message-content td {
  border: 1px solid var(--ai-border-color, currentColor);
  padding: 0.35em 0.6em;
  text-align: start;
  vertical-align: top;
  min-width: 6em;
}

.ai-chatbot__message-content th {
  font-weight: 700;
  background-color: var(--ai-bg-opacity);
}
/*
 * Copy button.
 *
 * Sits in the bot bubble only, revealed on hover and on keyboard focus. It
 * stays in the flow rather than being absolutely positioned, so it can never
 * cover the last line of a long answer - which is exactly the case it exists
 * for.
 *
 * Deliberately NOT revealed via :focus-within on the message: clicking the
 * button focuses it, so the message stayed in that state after the pointer
 * left and the button only faded once the window lost focus. :focus-visible
 * on the button covers keyboard users without the mouse-click side effect,
 * because a click does not set it.
 */
.ai-chatbot__message-actions {
  display: flex;
  justify-content: flex-end;
  margin-block-start: 0.25em;
}

.ai-chatbot__copy {
  display: inline-flex;
  align-items: center;
  gap: 0.3em;
  border: none;
  background: none;
  padding: 0.1em 0.25em;
  font-size: 0.65em;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease-in-out;
}

/*
 * Sized in em rather than by the width/height attributes in the template, so
 * the icon tracks the label instead of dwarfing it.
 */
.ai-chatbot__copy svg {
  width: 1.2em;
  height: 1.2em;
  flex: none;
}

.ai-chatbot__message:hover .ai-chatbot__copy {
  opacity: 0.7;
}

/*
 * is-copied holds the button visible while it shows its confirmation, so the
 * "Kopiert" feedback is not thrown away by a pointer that has already moved
 * on. The behaviour drops the class when it restores the label.
 */
.ai-chatbot__copy:hover,
.ai-chatbot__copy:focus-visible,
.ai-chatbot__copy.is-copied {
  opacity: 1;
}

/* Touch devices never hover, so the button would otherwise be unreachable. */
@media (hover: none) {
  .ai-chatbot__copy {
    opacity: 0.7;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-chatbot__copy {
    transition: none;
  }
}
