/* ============================================================
   preview.css — Polished rendering of parsed markdown.
   Applied to #preview and reused conceptually by the HTML export.
   ============================================================ */

.preview {
  font-size: 0.9375rem;
  line-height: 1.65;
  color: var(--text);
}

.preview > :first-child {
  margin-top: 0;
}

/* RTL blocks emitted by the parser (dir="rtl") align naturally;
   explicit rule for robustness across browsers. */
.preview [dir="rtl"] {
  text-align: right;
}

/* ---------- Headings ---------- */

.preview h1, .preview h2, .preview h3,
.preview h4, .preview h5, .preview h6 {
  margin: 1.1em 0 0.45em;
  font-weight: 650;
  line-height: 1.3;
}

.preview h1 {
  font-size: 1.6em;
  padding-bottom: 0.25em;
  border-bottom: 1px solid var(--border);
}

.preview h2 {
  font-size: 1.35em;
  padding-bottom: 0.2em;
  border-bottom: 1px solid var(--border-soft);
}

.preview h3 { font-size: 1.15em; }
.preview h4 { font-size: 1.02em; }
.preview h5 { font-size: 0.95em; color: var(--text-muted); }
.preview h6 { font-size: 0.9em;  color: var(--text-muted); }

/* ---------- Text blocks ---------- */

.preview p {
  margin: 0 0 0.8em;
}

.preview a {
  color: var(--accent);
  text-decoration: none;
}

.preview a:hover {
  text-decoration: underline;
}

.preview del {
  color: var(--text-muted);
}

.preview img {
  max-width: 100%;
  border-radius: var(--radius);
}

.preview hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.4em 0;
}

/* ---------- Inline code ---------- */

.preview code {
  font-family: var(--font-mono);
  font-size: 0.875em;
  vertical-align: baseline;
  background: #363636;
  border: 1px solid #2a2a2a;
  border-radius: 4px;
  padding: 2px 7px;
  color: #9c9d9e;
  /* Code is always LTR, even inside RTL blocks */
  direction: ltr;
  unicode-bidi: embed;
}

/* ---------- Code blocks ---------- */

.preview .code-block {
  margin: 0 0 1em;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  direction: ltr;
  text-align: left;
}

.preview .code-block .code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 8px 4px 12px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border-soft);
  font: 0.75rem var(--font-mono);
  color: var(--text-faint);
  letter-spacing: 0.03em;
}

.preview .code-copy {
  padding: 2px 9px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font: 0.7rem var(--font-ui);
  cursor: pointer;
  transition: all 0.12s ease;
}

.preview .code-copy:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.preview .code-copy.done {
  border-color: var(--success-border);
  color: var(--success-text);
}

.preview .code-block pre {
  margin: 0;
  padding: 10px 14px;
  background: var(--bg-code);
  overflow: auto;
  /* Modern compact code box: capped height with its own scroll */
  max-height: 200px;
}

.preview .code-block code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1.55;
  color: #d4d4d8;
}

/* ---------- Syntax highlight tokens ---------- */

.preview .tk-kw,  .export .tk-kw  { color: #c678dd; }
.preview .tk-str, .export .tk-str { color: #98c379; }
.preview .tk-num, .export .tk-num { color: #d19a66; }
.preview .tk-cm,  .export .tk-cm  { color: #5c6370; font-style: italic; }
.preview .tk-tag, .export .tk-tag { color: #e06c75; }
.preview .tk-attr,.export .tk-attr{ color: #61afef; }


/* ---------- Blockquotes ---------- */

.preview blockquote {
  margin: 0 0 1em;
  padding: 6px 14px;
  border: 1px solid var(--border-soft);
  background: var(--bg-raised);
  border-radius: var(--radius);
  color: var(--text-muted);
}


.preview blockquote > :last-child {
  margin-bottom: 0;
}

/* ---------- Lists ---------- */

.preview ul, .preview ol {
  margin: 0 0 0.8em;
  padding-inline-start: 1.6em;
}

.preview li {
  margin: 0.15em 0;
}

.preview li::marker {
  color: var(--text-faint);
}

.preview ul ul, .preview ul ol,
.preview ol ul, .preview ol ol {
  margin-bottom: 0;
}

.preview input[type="checkbox"] {
  accent-color: var(--accent);
  margin-inline-end: 0.4em;
  vertical-align: -1px;
}

/* ---------- Tables ---------- */

.preview table {
  border-collapse: collapse;
  margin: 0 0 1em;
  max-width: 100%;
  display: inline-block;
  overflow-x: auto;
  border-radius: var(--radius-lg);
}

.preview th, .preview td {
  border: 1px solid var(--border);
  padding: 6px 14px;
  font-size: 0.9em;
}

.preview th {
  background: var(--bg-raised);
  font-weight: 650;
  color: var(--text);
  cursor: pointer;          /* Phase 26 — click to sort */
  user-select: none;
  white-space: nowrap;
}

.preview th:hover {
  color: var(--accent);
}

/* Three-state sort indicators — ▲ asc, ▼ desc, none = source order */
.preview th.sort-asc::after,
.preview th.sort-desc::after {
  content: ' \25b2';
  color: var(--accent);
  font-size: 0.7em;
}

.preview th.sort-desc::after {
  content: ' \25bc';
}

.preview tbody tr:nth-child(even) td {
  background: #17171b;
}

/* ---------- Inline [[TOC]] block ---------- */

.preview .toc-inline {
  margin: 0 0 1em;
  padding: 12px 18px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
}

.preview .toc-inline-title {
  margin-bottom: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.preview .toc-inline ul {
  margin: 0;
  padding-inline-start: 1.1em;
  list-style: none;
}

.preview .toc-inline > ul {
  padding-inline-start: 0;
}

.preview .toc-inline li {
  margin: 0.25em 0;
}

.preview .toc-inline a {
  color: var(--text-muted);
}

.preview .toc-inline a:hover {
  color: var(--accent);
  text-decoration: none;
}

.preview .toc-inline-empty {
  font-size: 0.84rem;
  color: var(--text-faint);
}

/* Native #slug jumps (exported HTML) land with a little headroom. */
.preview .toc-anchor {
  scroll-margin-top: 10px;
}

/* ---------- Mermaid diagrams (full Mermaid.js) ---------- */

.preview .diagram-block {
  margin: 0 0 1em;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-panel);
  overflow-x: auto;
  text-align: center;
}

.preview .diagram-block svg {
  max-width: 100%;
  height: auto;
  font-family: var(--font-ui, system-ui, sans-serif);
}

.preview .diagram-block .mermaid {
  display: inline-block;
  text-align: left;
}
