/* ── Markdown Preview ────────────────────────────────── */

.markdown-preview {
  position: relative;
  padding: 24px 32px;
  font-size: inherit;
  line-height: 1.7;
}

.markdown-preview:focus-visible {
  outline: none;
}

.markdown-preview-search {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0;
  width: fit-content;
  max-width: min(100%, 460px);
  margin-left: auto;
  margin-right: -20px;
  margin-bottom: 6px;
  padding: 0 2px 0 4px;
  border: 1px solid var(--border);
  border-radius: 0 0 0 4px;
  background: var(--background);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.16);
}

.markdown-preview-search-field {
  display: flex;
  align-items: center;
  min-width: 0;
  width: 220px;
  border: 1px solid var(--ring);
  background: var(--background);
  flex: 0 1 auto;
}

.markdown-preview-search-status {
  min-width: 0;
  padding: 0 6px;
  font-size: 12px;
  color: var(--muted-foreground);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  line-height: 1;
  flex: 0 0 auto;
}

.markdown-preview-search-divider {
  width: 1px;
  height: 16px;
  margin: 0 2px;
  background: var(--border);
}

.markdown-preview-search-input {
  font-size: 13px;
  line-height: 1;
}

.markdown-preview-search-input::placeholder {
  color: var(--muted-foreground);
}

.markdown-preview-search-button {
  width: 22px;
  height: 22px;
  min-width: 22px;
  padding: 0;
  border-radius: 2px;
  color: var(--muted-foreground);
}

.markdown-preview-search-button:hover:not(:disabled) {
  background: var(--accent);
  color: var(--foreground);
}

.markdown-preview-search-match {
  padding: 0;
  border-radius: 2px;
  background: color-mix(in srgb, #facc15 50%, transparent);
  color: inherit;
}

.markdown-preview-search-match[data-active] {
  background: color-mix(in srgb, #fb923c 60%, transparent);
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4,
.markdown-body h5,
.markdown-body h6 {
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  font-weight: 600;
  line-height: 1.3;
}

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

.markdown-body h1 {
  font-size: 1.85em;
  font-weight: 700;
  letter-spacing: -0.02em;
}

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

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

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

/* Links use a proper blue instead of --primary (which is near-black/white and
   visually indistinguishable from body text). */
.markdown-body a {
  text-decoration: underline;
  text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
  text-underline-offset: 2px;
  transition: text-decoration-color 150ms;
}

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

.markdown-light .markdown-body a {
  color: #0969da;
}

.markdown-dark .markdown-body a {
  color: #58a6ff;
}

.markdown-body code {
  padding: 0.2em 0.4em;
  border-radius: 5px;
  font-size: 0.88em;
  font-family: var(--font-mono, monospace);
}

.markdown-dark .markdown-body code {
  background: rgba(255, 255, 255, 0.1);
}

.markdown-light .markdown-body code {
  background: rgba(0, 0, 0, 0.07);
}

.markdown-body pre {
  margin: 1em 0;
  padding: 14px 18px;
  border-radius: 8px;
  overflow-x: auto;
  line-height: 1.55;
}

.markdown-dark .markdown-body pre {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.markdown-light .markdown-body pre {
  background: #f6f8fa;
  border: 1px solid rgba(0, 0, 0, 0.08);
}

.markdown-body pre code {
  padding: 0;
  background: none;
  border: none;
  font-size: inherit;
  border-radius: 0;
}

/* Code copy button — appears on hover over code blocks in preview mode */
.code-block-wrapper {
  position: relative;
}
.code-block-copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  opacity: 0;
  transition: opacity 0.15s ease;
  background: none;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 4px;
  cursor: pointer;
  color: var(--muted-foreground);
  display: flex;
  align-items: center;
  justify-content: center;
}
.code-block-wrapper:hover .code-block-copy-btn {
  opacity: 1;
}
.code-block-copy-btn:hover {
  background: var(--accent);
  color: var(--foreground);
}
/* Always show on touch devices that lack hover */
@media (hover: none) {
  .code-block-copy-btn {
    opacity: 1;
  }
}

.code-block-copy-label {
  font-size: 11px;
  margin-left: 3px;
  font-family: var(--font-sans, sans-serif);
}

/* Mermaid diagram container */
.mermaid-block svg {
  max-width: 100%;
  height: auto;
}
.mermaid-error {
  color: var(--color-warning, #d29922);
  font-size: 0.85em;
  margin-bottom: 0.5em;
}
/* Full-file mermaid diagram viewer — used when opening .mmd/.mermaid files
   in diagram mode. Centers the rendered SVG and adds padding so diagrams
   don't press against viewport edges. */
.mermaid-viewer {
  background: var(--color-background, transparent);
}
.mermaid-viewer-canvas {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  min-height: 100%;
  padding: 32px 24px;
}
.mermaid-viewer-canvas .mermaid-block {
  width: 100%;
}
.mermaid-viewer-canvas .mermaid-block svg {
  width: 100%;
  height: auto;
}

.markdown-body ul,
.markdown-body ol {
  margin: 0.75em 0;
  padding-left: 1.5em;
}

/* Restore list markers inside markdown preview because the app-wide reset removes
   them for navigation UI. Markdown content needs native list semantics to match
   source documents, so this override should stay scoped to the preview surface. */
.markdown-body ul {
  list-style: disc;
}

.markdown-body ol {
  list-style: decimal;
}

.markdown-body ul ul {
  list-style: circle;
}

.markdown-body ul ul ul {
  list-style: square;
}

/* GFM task lists already render an explicit checkbox input, so keeping the
   browser marker here would show both a bullet and a checkbox for one item. */
.markdown-body ul.contains-task-list,
.markdown-body li.task-list-item {
  list-style: none;
}
.markdown-body li {
  margin: 0.25em 0;
}

.markdown-body li > input[type='checkbox'] {
  margin-right: 0.5em;
}

.markdown-body blockquote {
  margin: 0.75em 0;
  padding: 0.5em 1em;
  border-left: 3px solid var(--border);
  border-radius: 0 6px 6px 0;
}

.markdown-dark .markdown-body blockquote {
  background: rgba(255, 255, 255, 0.025);
  color: rgba(255, 255, 255, 0.72);
}

.markdown-light .markdown-body blockquote {
  background: rgba(0, 0, 0, 0.02);
  color: rgba(0, 0, 0, 0.6);
}

.markdown-body table {
  margin: 1em 0;
  border-collapse: collapse;
  width: 100%;
  font-size: 0.95em;
}

.markdown-body th,
.markdown-body td {
  padding: 8px 14px;
  border: 1px solid var(--border);
  text-align: left;
}

.markdown-body th {
  font-weight: 600;
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.markdown-dark .markdown-body th {
  background: rgba(255, 255, 255, 0.06);
}

.markdown-light .markdown-body th {
  background: rgba(0, 0, 0, 0.04);
}

.markdown-dark .markdown-body tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.02);
}

.markdown-light .markdown-body tr:nth-child(even) td {
  background: rgba(0, 0, 0, 0.015);
}

.markdown-body hr {
  margin: 2em 0;
  border: none;
  border-top: 1px solid var(--border);
}

.markdown-body img {
  max-width: 100%;
  border-radius: 6px;
}

/* ── Syntax Highlighting (GitHub-inspired) ────────── */

.markdown-light .hljs {
  color: #24292f;
}

.markdown-light .hljs-comment,
.markdown-light .hljs-quote {
  color: #6e7781;
  font-style: italic;
}

.markdown-light .hljs-keyword,
.markdown-light .hljs-selector-tag,
.markdown-light .hljs-template-tag {
  color: #cf222e;
}

.markdown-light .hljs-string,
.markdown-light .hljs-doctag,
.markdown-light .hljs-regexp {
  color: #0a3069;
}

.markdown-light .hljs-number,
.markdown-light .hljs-literal {
  color: #0550ae;
}

.markdown-light .hljs-title,
.markdown-light .hljs-section {
  color: #8250df;
}

.markdown-light .hljs-type,
.markdown-light .hljs-built_in {
  color: #0550ae;
}

.markdown-light .hljs-attr,
.markdown-light .hljs-attribute {
  color: #0550ae;
}

.markdown-light .hljs-variable,
.markdown-light .hljs-template-variable {
  color: #953800;
}

.markdown-light .hljs-tag,
.markdown-light .hljs-name {
  color: #116329;
}

.markdown-light .hljs-symbol,
.markdown-light .hljs-bullet,
.markdown-light .hljs-selector-class,
.markdown-light .hljs-selector-id {
  color: #0550ae;
}

.markdown-light .hljs-meta {
  color: #1f7f34;
}

.markdown-light .hljs-addition {
  color: #116329;
  background: rgba(46, 160, 67, 0.1);
}
.markdown-light .hljs-deletion {
  color: #82071e;
  background: rgba(248, 81, 73, 0.1);
}

.markdown-light .hljs-emphasis {
  font-style: italic;
}
.markdown-light .hljs-strong {
  font-weight: 700;
}

.markdown-dark .hljs {
  color: #e6edf3;
}

.markdown-dark .hljs-comment,
.markdown-dark .hljs-quote {
  color: #8b949e;
  font-style: italic;
}

.markdown-dark .hljs-keyword,
.markdown-dark .hljs-selector-tag,
.markdown-dark .hljs-template-tag {
  color: #ff7b72;
}

.markdown-dark .hljs-string,
.markdown-dark .hljs-doctag,
.markdown-dark .hljs-regexp {
  color: #a5d6ff;
}

.markdown-dark .hljs-number,
.markdown-dark .hljs-literal {
  color: #79c0ff;
}

.markdown-dark .hljs-title,
.markdown-dark .hljs-section {
  color: #d2a8ff;
}

.markdown-dark .hljs-type,
.markdown-dark .hljs-built_in {
  color: #ffa657;
}

.markdown-dark .hljs-attr,
.markdown-dark .hljs-attribute {
  color: #79c0ff;
}

.markdown-dark .hljs-variable,
.markdown-dark .hljs-template-variable {
  color: #ffa657;
}

.markdown-dark .hljs-tag,
.markdown-dark .hljs-name {
  color: #7ee787;
}

.markdown-dark .hljs-symbol,
.markdown-dark .hljs-bullet,
.markdown-dark .hljs-selector-class,
.markdown-dark .hljs-selector-id {
  color: #d2a8ff;
}

.markdown-dark .hljs-meta {
  color: #79c0ff;
}

.markdown-dark .hljs-addition {
  color: #aff5b4;
  background: rgba(46, 160, 67, 0.15);
}
.markdown-dark .hljs-deletion {
  color: #ffdcd7;
  background: rgba(248, 81, 73, 0.15);
}

.markdown-dark .hljs-emphasis {
  font-style: italic;
}
.markdown-dark .hljs-strong {
  font-weight: 700;
}
