/*
 * commsite-ai.css: optional base styles for answers rendered by commsite-ai.js.
 *
 * Served at https://apps.<domain>/commsite/commsite-ai.css. Every selector is wrapped in :where(), so the rules
 * have zero specificity and any rule of the host page wins. They restore what CSS resets (Tailwind preflight and
 * the like) strip from answers: list markers, heading sizes, link underlines, code and table looks. Colors are
 * neutral greys that work on light and dark backgrounds; text color and font are inherited from the page.
 * Written for the default classPrefix "commsite-ai".
 */

:where(.commsite-ai) {
  line-height: 1.6;
  overflow-wrap: break-word;
}

/* Blocks */
:where(
  .commsite-ai-p,
  .commsite-ai-h,
  .commsite-ai-ul,
  .commsite-ai-ol,
  .commsite-ai-blockquote,
  .commsite-ai-pre,
  .commsite-ai-table,
  .commsite-ai-html
) {
  margin: 0 0 0.75em;
}
:where(.commsite-ai-body) > :where(:last-child) {
  margin-bottom: 0;
}
:where(.commsite-ai-h) {
  font-weight: 600;
  line-height: 1.3;
}
:where(.commsite-ai-h1) {
  font-size: 1.4em;
}
:where(.commsite-ai-h2) {
  font-size: 1.25em;
}
:where(.commsite-ai-h3) {
  font-size: 1.1em;
}
:where(.commsite-ai-h4, .commsite-ai-h5, .commsite-ai-h6) {
  font-size: 1em;
}

/* Lists */
:where(.commsite-ai-ul, .commsite-ai-ol) {
  padding-inline-start: 1.5em;
}
:where(.commsite-ai-ul) {
  list-style: disc;
}
:where(.commsite-ai-ol) {
  list-style: decimal;
}
:where(.commsite-ai-li .commsite-ai-ul) {
  list-style: circle;
}
:where(.commsite-ai-li)
  > :where(.commsite-ai-ul, .commsite-ai-ol, .commsite-ai-p) {
  margin: 0.25em 0 0;
}
:where(.commsite-ai-li + .commsite-ai-li) {
  margin-top: 0.25em;
}

/* Inline */
:where(.commsite-ai-strong) {
  font-weight: 600;
}
:where(.commsite-ai-em) {
  font-style: italic;
}
:where(.commsite-ai-del) {
  text-decoration: line-through;
}
:where(.commsite-ai-link, .commsite-ai-source-link) {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 0.15em;
}
:where(.commsite-ai-link:hover, .commsite-ai-source-link:hover) {
  text-decoration-thickness: 2px;
}
:where(.commsite-ai-code, .commsite-ai-code-block) {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
}
:where(.commsite-ai-code) {
  padding: 0.1em 0.3em;
  border-radius: 4px;
  background: rgba(127, 127, 127, 0.15);
}

/* Code blocks, quotes, rules */
:where(.commsite-ai-pre) {
  padding: 0.75em 1em;
  overflow-x: auto;
  border-radius: 6px;
  background: rgba(127, 127, 127, 0.12);
}
:where(.commsite-ai-code-block) {
  white-space: pre;
}
:where(.commsite-ai-blockquote) {
  padding-inline-start: 0.75em;
  border-inline-start: 3px solid rgba(127, 127, 127, 0.4);
  opacity: 0.85;
}
:where(.commsite-ai-hr) {
  margin: 1em 0;
  border: 0;
  border-top: 1px solid rgba(127, 127, 127, 0.3);
}

/* Tables scroll inside narrow containers instead of overflowing them. */
:where(.commsite-ai-table) {
  display: block;
  width: max-content;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
}
/* A table with its own direction (a right-to-left table in a left-to-right target, or the reverse) sits at its
   own start edge, like the paragraphs around it. */
:where(.commsite-ai-table[dir]) {
  margin-inline-end: auto;
}
:where(.commsite-ai-th, .commsite-ai-td) {
  padding: 0.35em 0.6em;
  border: 1px solid rgba(127, 127, 127, 0.3);
  text-align: start;
}
:where(.commsite-ai-th) {
  font-weight: 600;
  background: rgba(127, 127, 127, 0.08);
}
:where(.commsite-ai-align-left) {
  text-align: left;
}
:where(.commsite-ai-align-center) {
  text-align: center;
}
:where(.commsite-ai-align-right) {
  text-align: right;
}

/* The streaming caret: an empty span, visible only with a style like this one. */
:where(.commsite-ai-caret) {
  display: inline-block;
  width: 0.5em;
  height: 1em;
  margin-inline-start: 0.1em;
  vertical-align: text-bottom;
  background: currentColor;
  opacity: 0.6;
  animation: commsite-ai-blink 1s steps(2, start) infinite;
}
@keyframes commsite-ai-blink {
  to {
    visibility: hidden;
  }
}
@media (prefers-reduced-motion: reduce) {
  :where(.commsite-ai-caret) {
    animation: none;
  }
}

/* Sources (renderSources: true) as chips. */
:where(.commsite-ai-sources) {
  margin-top: 0.75em;
}
:where(.commsite-ai-sources-list) {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5em;
  margin: 0;
  padding: 0;
  list-style: none;
}
:where(.commsite-ai-source-link) {
  display: inline-block;
  padding: 0.15em 0.7em;
  border: 1px solid rgba(127, 127, 127, 0.35);
  border-radius: 999px;
  font-size: 0.875em;
  text-decoration: none;
}

/* keepPrevious: the previous answer dims while the next one loads. */
:where([data-commsite-ai-state="loading"] > .commsite-ai) {
  opacity: 0.5;
  transition: opacity 0.2s;
}
