/* Syntax highlighting — light theme (hljs); dark overrides below match `html.dark` app theme */
@import 'highlight.js/styles/github.css';

/* Markdown body — tokens aligned with `web` @theme + design system */

.markdown-body {
  font-size: 0.9375rem;
  line-height: 1.5;
  letter-spacing: -0.011em;
  color: inherit;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: 1.35em;
  margin-bottom: 0.45em;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.022em;
  color: var(--color-fg);
}

.markdown-body h1 {
  font-size: 1.5em;
  border-bottom: 1px solid var(--color-edge);
  padding-bottom: 0.3em;
}

.markdown-body h2 {
  font-size: 1.3em;
  border-bottom: 1px solid var(--color-edge);
  padding-bottom: 0.3em;
}

.markdown-body h3 {
  font-size: 1.1em;
}

.markdown-body ul,
.markdown-body ol {
  margin-bottom: 1em;
  padding-left: 2em;
}

.markdown-body li {
  margin-bottom: 0.35em;
}

.markdown-body code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  background: var(--color-surface-hover);
  padding: 0.15em 0.4em;
  border-radius: var(--radius-sm);
  color: var(--color-accent-fg);
}

.markdown-body pre {
  background: var(--color-surface-hover);
  border-radius: var(--radius-xl);
  padding: 1em;
  overflow-x: auto;
  margin-bottom: 1em;
  border: 1px solid var(--color-edge);
}

/* Fenced blocks: toolbar + body (injected by MarkdownView) */
.markdown-code-block {
  margin: 0 0 1em;
  border: 1px solid var(--color-edge);
  border-radius: var(--radius-xl);
  /* `overflow: hidden` prevents `position: sticky` on the header from reaching the chat scrollport */
  overflow: visible;
  background: var(--color-surface-hover);
}

.markdown-code-block-header {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  min-height: 2.25rem;
  padding: 0.35rem 0.65rem 0.35rem 0.85rem;
  border-bottom: 1px solid var(--color-edge);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  /* Darker than code pane (`surface-hover`) — opaque toolbar strip */
  background: var(--color-surface-active);
}

.markdown-code-block-lang {
  flex: 1 1 auto;
  min-width: 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0.02em;
  color: var(--color-fg-muted);
  text-transform: lowercase;
  user-select: none;
}

.markdown-code-copy-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.25rem 0.45rem;
  margin: 0;
  border: none;
  border-radius: var(--radius-md);
  background: var(--color-surface-active);
  color: var(--color-fg-muted);
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.25;
  cursor: pointer;
  transition:
    color 0.15s ease,
    background-color 0.15s ease,
    transform 0.12s ease;
}

.markdown-code-copy-btn:hover {
  color: var(--color-fg);
  background: var(--color-surface-panel);
}

.markdown-code-copy-btn:active {
  transform: scale(0.97);
}

.markdown-code-copy-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.markdown-code-copy-inner {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
}

.markdown-code-copy-btn svg {
  pointer-events: none;
}

.markdown-code-copy-label {
  white-space: nowrap;
}

.markdown-body .markdown-code-block > pre {
  margin: 0;
  border: none;
  border-radius: 0 0 var(--radius-xl) var(--radius-xl);
  background: var(--color-surface-hover);
}

html.dark .markdown-code-block {
  border-color: var(--color-edge);
  background: #0d1117;
}

html.dark .markdown-code-block-header {
  /* Opaque, darker than `#0d1117` code pane */
  background: #06080b;
  border-bottom-color: var(--color-edge);
}

html.dark .markdown-code-block-lang {
  color: var(--color-fg-muted);
}

html.dark .markdown-body .markdown-code-block > pre {
  background: #0d1117;
}

html.dark .markdown-code-copy-btn {
  color: var(--color-fg-subtle);
  background: #06080b;
}

html.dark .markdown-code-copy-btn:hover {
  color: var(--color-fg);
  background: #121820;
}

/**
 * Chat scroll container (`.chat-messages`) uses top padding (`py-4` / `pt-5` in `chat-page.tsx`).
 * Without offset, `position: sticky; top: 0` aligns to the content box below that padding, leaving a gap.
 */
.chat-messages .markdown-code-block-header {
  top: -1rem;
}

.chat-messages.chat-messages--compact-welcome .markdown-code-block-header {
  top: -1.25rem;
}

.markdown-body pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: 0.8125rem;
}

.markdown-body blockquote {
  margin: 0 0 1em;
  padding: 0.75em 1em;
  border-left: 3px solid var(--color-accent);
  color: var(--color-fg-muted);
  background: var(--color-surface-hover);
  border-radius: 0 var(--radius-lg) var(--radius-lg) 0;
}

.markdown-body a {
  color: var(--color-accent-fg);
  text-decoration: none;
}

.markdown-body a:hover {
  text-decoration: underline;
}

.markdown-body hr {
  height: 1px;
  background: var(--color-edge);
  border: none;
  margin: 1.5em 0;
}

.markdown-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 1em;
  font-size: 0.875rem;
  line-height: 1.5;
  border: 1px solid var(--color-edge);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--color-edge-subtle);
  padding: 0.5rem 0.75rem;
  text-align: left;
  vertical-align: top;
}

.markdown-body th {
  background: var(--color-surface-hover);
  font-weight: 600;
  color: var(--color-fg);
}

.markdown-body tbody tr:hover td {
  background: var(--color-surface-hover);
}

.markdown-body p {
  margin: 0 0 0.75em;
}

.markdown-body strong {
  font-weight: 600;
}

.markdown-body em {
  font-style: italic;
}

/* Compact — chat bubbles */
.markdown-body.markdown-compact h1,
.markdown-body.markdown-compact h2,
.markdown-body.markdown-compact h3 {
  margin-top: 0.75em;
  margin-bottom: 0.25em;
}

.markdown-body.markdown-compact p {
  margin: 0 0 0.5em;
}

.markdown-body.markdown-compact pre {
  margin-bottom: 0.75em;
}

.markdown-body.markdown-compact .markdown-code-block {
  margin-bottom: 0.75em;
}

.markdown-body.markdown-compact .markdown-code-block > pre {
  margin-bottom: 0;
}

/* GitHub Dark hljs when app shell is dark (`html.dark`), scoped to markdown preview */
html.dark .markdown-body pre code.hljs {
  display: block;
  overflow-x: auto;
  padding: 1em;
}

html.dark .markdown-body code.hljs {
  padding: 3px 5px;
}

html.dark .markdown-body .hljs {
  color: #c9d1d9;
  background: #0d1117;
}

html.dark .markdown-body .hljs-doctag,
html.dark .markdown-body .hljs-keyword,
html.dark .markdown-body .hljs-meta .hljs-keyword,
html.dark .markdown-body .hljs-template-tag,
html.dark .markdown-body .hljs-template-variable,
html.dark .markdown-body .hljs-type,
html.dark .markdown-body .hljs-variable.language_ {
  color: #ff7b72;
}

html.dark .markdown-body .hljs-title,
html.dark .markdown-body .hljs-title.class_,
html.dark .markdown-body .hljs-title.class_.inherited__,
html.dark .markdown-body .hljs-title.function_ {
  color: #d2a8ff;
}

html.dark .markdown-body .hljs-attr,
html.dark .markdown-body .hljs-attribute,
html.dark .markdown-body .hljs-literal,
html.dark .markdown-body .hljs-meta,
html.dark .markdown-body .hljs-number,
html.dark .markdown-body .hljs-operator,
html.dark .markdown-body .hljs-variable,
html.dark .markdown-body .hljs-selector-attr,
html.dark .markdown-body .hljs-selector-class,
html.dark .markdown-body .hljs-selector-id {
  color: #79c0ff;
}

html.dark .markdown-body .hljs-regexp,
html.dark .markdown-body .hljs-string,
html.dark .markdown-body .hljs-meta .hljs-string {
  color: #a5d6ff;
}

html.dark .markdown-body .hljs-built_in,
html.dark .markdown-body .hljs-symbol {
  color: #ffa657;
}

html.dark .markdown-body .hljs-comment,
html.dark .markdown-body .hljs-code,
html.dark .markdown-body .hljs-formula {
  color: #8b949e;
}

html.dark .markdown-body .hljs-name,
html.dark .markdown-body .hljs-quote,
html.dark .markdown-body .hljs-selector-tag,
html.dark .markdown-body .hljs-selector-pseudo {
  color: #7ee787;
}

html.dark .markdown-body .hljs-subst {
  color: #c9d1d9;
}

html.dark .markdown-body .hljs-section {
  color: #1f6feb;
  font-weight: bold;
}

html.dark .markdown-body .hljs-bullet {
  color: #f2cc60;
}

html.dark .markdown-body .hljs-emphasis {
  color: #c9d1d9;
  font-style: italic;
}

html.dark .markdown-body .hljs-strong {
  color: #c9d1d9;
  font-weight: bold;
}

html.dark .markdown-body .hljs-addition {
  color: #aff5b4;
  background-color: #033a16;
}

html.dark .markdown-body .hljs-deletion {
  color: #ffdcd7;
  background-color: #67060c;
}
