.markdown {
  font-size: 0.9375rem;
  line-height: 1.72;
  color: var(--color-text);
  /* Prevent content overflow on mobile */
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.markdown > :first-child {
  margin-top: 0;
}

.markdown > :last-child {
  margin-bottom: 0;
}

/* Headings */
.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4,
.markdown h5,
.markdown h6 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-weight: 600;
  line-height: 1.3;
  color: var(--color-text);
}

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

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

.markdown h3 {
  font-size: 1.25em;
}

.markdown h4 {
  font-size: 1.1em;
}

.markdown h5,
.markdown h6 {
  font-size: 1em;
}

/* Paragraphs */
.markdown p {
  margin-top: 0;
  margin-bottom: 0.95em;
}

/* Lists */
.markdown ul,
.markdown ol {
  margin-top: 0;
  margin-bottom: 1em;
  padding-left: 2em;
}

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

.markdown li > p {
  margin-bottom: 0.5em;
}

.markdown li > :last-child {
  margin-bottom: 0;
}

/* Code blocks */
.codeBlock {
  position: relative;
  margin: 1em 0;
  background-color: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.codeHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background-color: var(--color-bg-secondary);
  border-bottom: 1px solid var(--color-border);
  min-height: 2rem;
}

.codeLanguage {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--color-text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-family: var(--font-mono);
}

.copyButton {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background-color: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--color-text-tertiary, #6b7280);
  cursor: pointer;
  transition: all var(--transition-fast);
  margin-left: auto;
}

.copyButton:hover {
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--color-text-secondary, #9ca3af);
}

.copyButton:active {
  transform: scale(0.92);
}

.copyButton svg {
  display: block;
  width: 18px;
  height: 18px;
  stroke-width: 1.5;
}

.codeBlock code {
  display: block;
  padding: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.5;
  background-color: transparent;
}

/* Inline code */
.inlineCode {
  padding: 0.2em 0.4em;
  margin: 0;
  font-size: 0.875em;
  background-color: var(--color-bg-tertiary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
}

/* Blockquotes */
.markdown blockquote {
  margin: 1em 0;
  padding: 0.5em 1em;
  border-left: 4px solid var(--color-primary);
  background-color: var(--color-bg-tertiary);
  color: var(--color-text-secondary);
}

.markdown blockquote p {
  margin: 0;
}

/* Links */
.markdown a {
  color: var(--color-primary);
  text-decoration: none;
  transition: opacity var(--transition-fast);
}

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

.citationLink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 0.125rem;
  padding: 0.1rem 0.3rem;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.12);
  color: #7dd3fc;
  font-size: 0.72em;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  vertical-align: super;
}

.citationLink:hover {
  background: rgba(59, 130, 246, 0.22);
  color: #bae6fd;
  text-decoration: none;
  opacity: 1;
}

/* Horizontal rules */
.markdown hr {
  margin: 2em 0;
  border: 0;
  border-top: 1px solid var(--color-border);
}

/* Tables */
.tableWrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1em 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  max-width: 100%;
}

.markdown table {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.markdown th,
.markdown td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

.markdown th {
  background-color: var(--color-bg-secondary);
  font-weight: 600;
  color: var(--color-text);
}

.markdown tr:last-child td {
  border-bottom: none;
}

.markdown tr:hover {
  background-color: var(--color-bg-tertiary);
}

/* Images */
.markdown img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-md);
  margin: 1em 0;
}

/* Task lists */
.markdown input[type="checkbox"] {
  margin-right: 0.5em;
}

/* Strikethrough */
.markdown del {
  color: var(--color-text-secondary);
  text-decoration: line-through;
}

/* Strong and emphasis */
.markdown strong {
  font-weight: 600;
}

.markdown em {
  font-style: italic;
}

/* Override highlight.js styles to match theme */
.codeBlock code.hljs {
  background-color: transparent;
  padding: 0;
}

/* Dark theme only */
.codeBlock {
  background-color: #0d1117;
}

.codeBlock code {
  color: #c9d1d9;
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .markdown {
    font-size: 0.875rem;
  }

  .markdown h1 {
    font-size: 1.5em;
  }

  .markdown h2 {
    font-size: 1.25em;
  }

  .markdown h3 {
    font-size: 1.125em;
  }

  .markdown ul,
  .markdown ol {
    padding-left: 1.5em;
  }

  .codeBlock {
    margin: 0.75em 0;
  }

  .codeHeader {
    padding: 0.375rem 0.75rem;
  }

  .codeLanguage {
    font-size: 0.6875rem;
  }

  .codeBlock code {
    padding: 0.75rem;
    font-size: 0.8125rem;
  }

  .tableWrapper {
    margin: 0.75em 0;
    /* Visual indicator that table is scrollable */
    position: relative;
  }

  .markdown table {
    font-size: 0.8125rem;
  }

  .markdown th,
  .markdown td {
    padding: 0.5rem 0.75rem;
  }

  .markdown blockquote {
    margin: 0.75em 0;
    padding: 0.375em 0.75em;
  }
}

@media (max-width: 480px) {
  .markdown {
    font-size: 0.8125rem;
  }

  .codeBlock code {
    padding: 0.625rem;
    font-size: 0.75rem;
  }

  .markdown table {
    font-size: 0.75rem;
  }

  .markdown th,
  .markdown td {
    padding: 0.375rem 0.5rem;
  }
}
