.agent-markdown {
  display: block;
  white-space: normal;
  word-break: break-word;
  line-height: 1.7;
}

.agent-markdown p {
  margin: 0;
}

.agent-markdown p + p,
.agent-markdown ul,
.agent-markdown ol,
.agent-markdown pre,
.agent-markdown blockquote,
.agent-markdown table {
  margin-top: 1rem;
}

.agent-markdown h1,
.agent-markdown h2,
.agent-markdown h3,
.agent-markdown h4,
.agent-markdown h5,
.agent-markdown h6 {
  margin: 1.1rem 0 0.5rem 0;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.agent-markdown :is(h1, h2, h3, h4, h5, h6):first-child {
  margin-top: 0;
}

.agent-markdown h1 + p,
.agent-markdown h2 + p,
.agent-markdown h3 + p,
.agent-markdown h4 + p,
.agent-markdown h5 + p,
.agent-markdown h6 + p,
.agent-markdown h1 + ul,
.agent-markdown h2 + ul,
.agent-markdown h3 + ul,
.agent-markdown h4 + ul,
.agent-markdown h5 + ul,
.agent-markdown h6 + ul,
.agent-markdown h1 + ol,
.agent-markdown h2 + ol,
.agent-markdown h3 + ol,
.agent-markdown h4 + ol,
.agent-markdown h5 + ol,
.agent-markdown h6 + ol {
  margin-top: 0.25rem;
}

.agent-markdown ul,
.agent-markdown ol {
  padding-left: 1.1rem;
}

.agent-markdown ul {
  list-style-type: disc;
}

.agent-markdown ol {
  list-style-type: decimal;
}

.agent-markdown ul ul {
  list-style-type: circle;
  padding-left: 1.2rem;
}

.agent-markdown ul ul ul {
  list-style-type: square;
}

.agent-markdown ol ol {
  list-style-type: lower-alpha;
  padding-left: 1.3rem;
}

.agent-markdown ol ol ol {
  list-style-type: lower-roman;
}

.agent-markdown ul ol {
  list-style-type: decimal;
  padding-left: 1.3rem;
}

.agent-markdown ol ul {
  list-style-type: disc;
  padding-left: 1.2rem;
}

.agent-markdown li {
  margin-top: 0.25rem;
}

.agent-markdown li > p {
  margin: 0;
}

.agent-markdown code {
  font-family: var(--font-mono), ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas,
    "Liberation Mono", "Courier New", monospace;
  font-size: 0.82em;
  overflow-wrap: anywhere;
  word-break: break-word;
  background: color-mix(in oklch, var(--surface-3) 92%, transparent);
  padding: 0.14rem 0.28rem;
  border-radius: 0.3125rem;
  border: 1px solid color-mix(in oklch, var(--surface-selected-border) 88%, transparent);
}

.agent-markdown pre {
  background: color-mix(in oklch, var(--surface-2) 94%, transparent);
  border-radius: 0.4rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid color-mix(in oklch, var(--surface-selected-border) 82%, transparent);
  overflow-x: auto;
  line-height: 1.64;
}

.agent-markdown pre code {
  background: transparent;
  padding: 0;
  font-size: 0.85em;
  border: 0;
  border-radius: 0;
}

.agent-tool-markdown pre {
  max-height: 70px;
  overflow: auto;
  padding: 0.5rem 0.6rem;
}

.agent-markdown blockquote {
  border-left: 3px solid var(--surface-selected-border);
  padding-left: 0.7rem;
  color: var(--muted-foreground);
}

.agent-markdown table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85em;
}

.agent-markdown th,
.agent-markdown td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.65rem;
  text-align: left;
}

.agent-markdown a {
  color: color-mix(in oklch, var(--action-bg) 68%, var(--foreground));
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.agent-markdown img {
  max-width: 100%;
  height: auto;
  display: block;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
}

.dark .agent-markdown code {
  background: color-mix(in oklch, var(--surface-1) 80%, var(--surface-0));
  border-color: color-mix(in oklch, var(--chat-assistant-border) 88%, var(--surface-selected-border));
}

.dark .agent-markdown pre {
  background: color-mix(in oklch, var(--surface-0) 82%, var(--surface-1));
  border-color: color-mix(in oklch, var(--chat-assistant-border) 86%, transparent);
  box-shadow: inset 0 1px 0 var(--elev-overlay-1);
}

.dark .ui-chat-assistant-card .agent-markdown :is(p + p, ul, ol, pre, blockquote, table) {
  margin-top: 1.35rem;
}

.dark .ui-chat-assistant-card .agent-markdown :is(h1, h2, h3, h4, h5, h6) {
  margin: 1.35rem 0 0.68rem 0;
}

.dark .ui-chat-assistant-card .agent-markdown li + li {
  margin-top: 0.42rem;
}
