/* =========================================================================
   summit-prose — the one stylesheet for Summit Docs content.
   Loaded AFTER ui-theme.css. See docs/plans/SUMMIT_DOCS_PLAN.md §6.

   It dresses BOTH the editor content area and the published page. The editor
   is the page with a cursor in it: that is what makes WYSIWYG true rather
   than approximate, and it is the reason this file must never gain an
   `.summit-prose--editing` rule that changes layout, spacing or type.
   Editing-only rules are allowed for *affordances* alone — placeholder text,
   the table resize grip, selection outlines.

   Colours come from --ht-* tokens so light and dark both work with no second
   theme. Never hardcode a colour here.
   ========================================================================= */

.summit-prose {
  /* ── Type scale ──────────────────────────────────────────────────────
     Defined once, as tokens. Per-element sizes below only ever reference
     these, so the whole document rescales from one place. */
  --prose-size:      1rem;        /* 16px body */
  --prose-lh:        1.7;
  --prose-h1:        1.875rem;    /* 30px */
  --prose-h2:        1.4375rem;   /* 23px */
  --prose-h3:        1.1875rem;   /* 19px */
  --prose-h4:        1.0625rem;   /* 17px */
  --prose-small:     0.875rem;
  --prose-code:      0.875em;

  /* Vertical rhythm — one gap, used everywhere, so blocks line up. */
  --prose-gap:       1.15em;
  --prose-gap-tight: 0.45em;

  /* Measure. ~72 characters at 16px Inter. Full-width body text is the
     single biggest giveaway of an amateur document. */
  --prose-measure:   68ch;

  --prose-mono: ui-monospace, "Cascadia Code", "JetBrains Mono",
                "SF Mono", Consolas, "Liberation Mono", monospace;

  font-family: var(--ht-font);
  font-size: var(--prose-size);
  line-height: var(--prose-lh);
  color: var(--ht-ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-variant-numeric: tabular-nums lining-nums;
  overflow-wrap: break-word;
}

/* The measure is applied to the BLOCKS, not to the container.
   Capping the container instead is the obvious thing to do and it is wrong:
   an eight-column table then has to live inside 68 characters and crushes
   its own headers to one syllable per line. So text caps, and the blocks
   that legitimately need room — tables, figures, code — use the whole
   content column. Everything still starts at the same left edge.
   The host page sets that column's width; this file does not. */
.summit-prose > * { max-width: var(--prose-measure); }
.summit-prose > :is(table, .tableWrapper, figure, pre, .prose-wide) {
  max-width: none;
}

/* ── Vertical rhythm ────────────────────────────────────────────────────
   Applied to blocks NESTED in a container as well as to top-level ones.
   Without the second rule a paragraph inside a callout, a quote or a table
   cell keeps the browser's default 1em margins, which pushes it below the
   callout's icon and makes every table cell taller than it needs to be. */
.summit-prose > * { margin: 0 0 var(--prose-gap); }
.summit-prose > :last-child { margin-bottom: 0; }

.summit-prose :is(blockquote, .callout, li, td, th, [data-type='taskItem'] > div) > * {
  margin: 0 0 var(--prose-gap);
}
.summit-prose :is(blockquote, .callout, li, td, th, [data-type='taskItem'] > div) > :last-child {
  margin-bottom: 0;
}
/* ProseMirror appends the column-resize grip inside the cell when you reach
   for a column border. That stopped the cell's last paragraph being
   :last-child, handed its bottom margin back, and grew every row in the
   table — the grip itself is out of flow and was never the culprit. It is
   not content, so it must not count as a sibling. */
.summit-prose :is(td, th) > :has(+ .column-resize-handle) {
  margin-bottom: 0;
}

/* ── Headings ─────────────────────────────────────────────────────────── */
.summit-prose :is(h1, h2, h3, h4) {
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: -0.011em;
  color: var(--ht-ink);
  /* Keep a heading with the text it introduces. */
  break-after: avoid;
  page-break-after: avoid;
}

.summit-prose h1 { font-size: var(--prose-h1); margin-top: 0; }
.summit-prose h2 {
  font-size: var(--prose-h2);
  margin-top: 2em;
  padding-bottom: 0.3em;
  border-bottom: 1px solid var(--ht-line);
}
.summit-prose h3 { font-size: var(--prose-h3); margin-top: 1.8em; }
.summit-prose h4 {
  font-size: var(--prose-h4);
  margin-top: 1.6em;
  color: var(--ht-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: var(--prose-small);
}

/* First heading after another heading shouldn't get the big top margin. */
.summit-prose :is(h1, h2, h3, h4) + :is(h2, h3, h4) { margin-top: var(--prose-gap); }

/* ── Inline ───────────────────────────────────────────────────────────── */
.summit-prose strong { font-weight: 600; color: var(--ht-ink); }
.summit-prose a {
  color: var(--ht-accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.summit-prose a:hover { text-decoration-thickness: 2px; }

.summit-prose :not(pre) > code {
  font-family: var(--prose-mono);
  font-size: var(--prose-code);
  background: var(--ht-chip-bg);
  border: 1px solid var(--ht-line);
  border-radius: 4px;
  padding: 0.12em 0.34em;
  white-space: break-spaces;
}

.summit-prose mark {
  background: color-mix(in srgb, var(--ht-accent) 18%, transparent);
  color: inherit;
  border-radius: 3px;
  padding: 0 0.15em;
}

/* ── Lists ────────────────────────────────────────────────────────────── */
.summit-prose :is(ul, ol) { padding-left: 1.5em; }
.summit-prose li { margin-bottom: var(--prose-gap-tight); }
.summit-prose li > :is(ul, ol) { margin: var(--prose-gap-tight) 0 0; }
.summit-prose li > p { margin-bottom: var(--prose-gap-tight); }
.summit-prose li::marker { color: var(--ht-faint); }

/* ── Blockquote ───────────────────────────────────────────────────────── */
.summit-prose blockquote {
  margin-left: 0;
  padding: 0.2em 0 0.2em 1.1em;
  border-left: 3px solid var(--ht-line);
  color: var(--ht-muted);
  font-style: normal;
}
.summit-prose blockquote > :last-child { margin-bottom: 0; }

/* ── Code blocks ──────────────────────────────────────────────────────── */
.summit-prose pre {
  font-family: var(--prose-mono);
  font-size: var(--prose-small);
  line-height: 1.6;
  background: var(--ht-surface-2);
  border: 1px solid var(--ht-line);
  border-radius: 8px;
  padding: 0.9em 1.1em;
  overflow-x: auto;
  break-inside: avoid;
}
.summit-prose pre code {
  background: none;
  border: 0;
  padding: 0;
  font-size: inherit;
  color: inherit;
}

/* ── Rule ─────────────────────────────────────────────────────────────── */
.summit-prose hr {
  border: 0;
  border-top: 1px solid var(--ht-line);
  margin: 2.2em 0;
}

/* ── Tables ───────────────────────────────────────────────────────────────
   Tiptap's defaults are raw: no borders, no header treatment. This is most
   of what makes a page read as a document rather than a web form. */
/* ProseMirror wraps every table in this. In the read view there is no
   wrapper, so the same rules have to reach a bare table too. */
.summit-prose .tableWrapper { overflow-x: auto; }

.summit-prose table {
  border-collapse: collapse;
  font-size: var(--prose-small);
  line-height: 1.55;
  width: 100%;
  /* ProseMirror's table plugin writes inline colgroup widths; fixed layout
     is what makes column resizing behave. */
  table-layout: fixed;
  break-inside: avoid;
}

.summit-prose :is(th, td) {
  border: 1px solid var(--ht-line);
  padding: 0.5em 0.7em;
  text-align: left;
  vertical-align: top;
  position: relative;   /* ProseMirror anchors the resize grip to this */
  /* Long tokens still have to break, or one URL widens the whole table —
     but a cell narrow enough to split an ordinary word is a sign the table
     needed the full column, not that the word needed hyphenating. */
  overflow-wrap: break-word;
}

/* Headers never break mid-word: "Refere / nce" reads as a mistake even when
   the cell genuinely is too narrow. */
.summit-prose th { overflow-wrap: normal; hyphens: none; }

.summit-prose th {
  background: var(--ht-surface-2);
  font-weight: 600;
  color: var(--ht-ink);
  /* Repeat the header when a long table breaks across printed pages. Only
     real <th> rows carry this — a stray flag on a body row makes some
     renderers apply first-row formatting to it. */
}
.summit-prose thead { display: table-header-group; }

/* Numeric columns right-align; authors tag the cell, not every row. */
.summit-prose :is(th, td).num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Images and figures ───────────────────────────────────────────────── */
.summit-prose img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--ht-line);
  display: block;
}

.summit-prose figure { margin: var(--prose-gap) 0; break-inside: avoid; }
.summit-prose figcaption {
  margin-top: 0.55em;
  font-size: var(--prose-small);
  color: var(--ht-muted);
  text-align: center;
}

/* ── Callouts ─────────────────────────────────────────────────────────────
   Highest perceived quality per unit of work. The node is `callout` with a
   `tone` attribute; everything below is one rule plus a colour per tone. */
.summit-prose .callout {
  --callout-tone: var(--ht-accent);
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.75em;
  padding: 0.85em 1em;
  border: 1px solid var(--ht-line);
  border-left: 3px solid var(--callout-tone);
  border-radius: 8px;
  background: color-mix(in srgb, var(--callout-tone) 6%, var(--ht-surface));
  break-inside: avoid;
}
.summit-prose .callout > :last-child { margin-bottom: 0; }
.summit-prose .callout::before {
  content: attr(data-icon);
  line-height: var(--prose-lh);
  color: var(--callout-tone);
}
.summit-prose .callout[data-tone='warning'] { --callout-tone: #d97706; }
.summit-prose .callout[data-tone='danger']  { --callout-tone: #dc2626; }
.summit-prose .callout[data-tone='success'] { --callout-tone: #16a34a; }

/* The glyph sits in a circle so it reads as a marker rather than a stray
   character, and so the four tones are distinguishable without relying on
   colour alone — which is also what makes them work in print. */
.summit-prose .callout::before {
  display: grid;
  place-items: center;
  width: 1.3em;
  height: 1.3em;
  margin-top: 0.18em;
  border-radius: 50%;
  background: var(--callout-tone);
  color: var(--ht-surface);
  font-size: 0.8em;
  font-weight: 700;
  line-height: 1;
}

/* ── Task lists ───────────────────────────────────────────────────────── */
.summit-prose ul[data-type='taskList'] {
  list-style: none;
  padding-left: 0.1em;
}
.summit-prose ul[data-type='taskList'] li {
  display: flex;
  align-items: flex-start;
  gap: 0.6em;
}
.summit-prose ul[data-type='taskList'] li > label {
  flex: 0 0 auto;
  /* Margins explicitly zero. "li > *" above hands every child a --prose-gap
     bottom margin and only the LAST child has it taken back — the label is
     the first, so every checklist item carried 18px of empty space under
     its checkbox and the list read as double-spaced.
     One text line tall with the box centred in it, rather than nudged down
     by a top margin: a margin would align the checkbox and make the row
     taller at the same time, which is why a checklist did not sit on the
     same rhythm as a bullet list. */
  display: flex;
  align-items: center;
  height: calc(var(--prose-size) * var(--prose-lh));
  margin: 0;
  user-select: none;
}
.summit-prose ul[data-type='taskList'] li > div { flex: 1 1 auto; min-width: 0; }
.summit-prose ul[data-type='taskList'] li > div > p { margin-bottom: 0; }
.summit-prose ul[data-type='taskList'] input[type='checkbox'] {
  accent-color: var(--ht-accent);
  width: 1em;
  height: 1em;
}
/* The read view's checkboxes are disabled — the state is part of the
   published page and changing it means editing. Browsers grey a disabled
   checkbox, which would make the read view differ from the editor for no
   good reason, so the greying is undone. */
.summit-prose ul[data-type='taskList'] input[type='checkbox']:disabled {
  opacity: 1;
  cursor: default;
}
/* A done item is struck through and faded, so the remaining work is what
   the eye lands on. */
.summit-prose ul[data-type='taskList'] li[data-checked='true'] > div {
  color: var(--ht-faint);
  text-decoration: line-through;
}

/* ── Code colours ─────────────────────────────────────────────────────────
   Highlighting happens on the server (DocCodeHighlighter), which emits
   ColorCode's class names. Defining the palette here rather than letting it
   write inline styles is what makes code blocks work in dark mode. */
.summit-prose pre code {
  --code-keyword: #0b6bcb;
  --code-string:  #0a7d4f;
  --code-comment: var(--ht-faint);
  --code-number:  #a4561d;
  --code-type:    #6f42c1;
}
:root[data-theme='dark'] .summit-prose pre code {
  --code-keyword: #7aa2ff;
  --code-string:  #6cc39a;
  --code-comment: var(--ht-faint);
  --code-number:  #e0a075;
  --code-type:    #c3a0ff;
}

.summit-prose pre code .keyword      { color: var(--code-keyword); font-weight: 600; }
.summit-prose pre code .string       { color: var(--code-string); }
.summit-prose pre code .comment      { color: var(--code-comment); font-style: italic; }
.summit-prose pre code .number       { color: var(--code-number); }
.summit-prose pre code .preprocessor,
.summit-prose pre code .typeName,
.summit-prose pre code .className    { color: var(--code-type); }
.summit-prose pre code .htmlTagDelimiter,
.summit-prose pre code .htmlElementName { color: var(--code-keyword); }
.summit-prose pre code .htmlAttributeName { color: var(--code-type); }
.summit-prose pre code .htmlAttributeValue,
.summit-prose pre code .htmlComment  { color: var(--code-string); }

/* Language label, from the attribute the converter writes. Costs no markup
   and disappears by itself on a block with no language. */
.summit-prose pre { position: relative; }
.summit-prose pre[data-language]::before {
  content: attr(data-language);
  position: absolute;
  top: 0.4em;
  right: 0.6em;
  font-size: 0.75em;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--ht-faint);
  pointer-events: none;
}

/* ── Editing affordances only ─────────────────────────────────────────────
   Nothing here may change layout, spacing or type — otherwise the editor
   stops being the page. */
.summit-prose--editing {
  outline: none;

  /* The editor is a document, so the whole area has to be the document.
     Sized to its content, an empty page is one line tall and clicking
     anywhere below it does nothing — which reads as "the editor is
     broken", not as "you missed". Every editor worth using does this. */
  min-height: 60vh;
}

.summit-prose--editing p.is-editor-empty:first-child::before {
  content: attr(data-placeholder);
  color: var(--ht-faint);
  float: left;
  height: 0;
  pointer-events: none;
}

/* ProseMirror's own selected-node and resize-grip classes. */
.summit-prose--editing .ProseMirror-selectednode {
  outline: 2px solid var(--ht-accent);
  outline-offset: 2px;
}
/* prosemirror-tables ships its own stylesheet, which editor.css imports and
   which already lays these two out. We only recolour them — but the two
   files carry equal specificity, so plain .summit-prose--editing rules won
   or lost by load order alone. The extra class pins ours on top, and
   repeating the geometry keeps this file correct on its own. */
.summit-prose.summit-prose--editing .selectedCell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: color-mix(in srgb, var(--ht-accent) 14%, transparent);
}
.summit-prose.summit-prose--editing .column-resize-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  right: -1px;
  width: 2px;
  z-index: 20;
  pointer-events: none;
  background: var(--ht-accent);
}
.summit-prose--editing.resize-cursor { cursor: col-resize; }

/* ── Table grips ──────────────────────────────────────────────────────────
   The add-row / add-column buttons on a table's edges. Editor chrome, so
   they sit beside the ProseMirror element rather than in it — anything
   inside is content, and content gets saved. */
.summit-grips {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.summit-grips--on { opacity: 1; }

.summit-grips__add {
  position: absolute;
  display: flex;
  align-items: center;
  /* Explicit, because Chrome's user-agent sheet centres button content and
     nothing here should depend on that either way. */
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--ht-line);
  border-radius: 50%;
  background: var(--ht-surface);
  color: var(--ht-muted);
  font: 600 13px/1 var(--ht-font);
  cursor: pointer;
  pointer-events: auto;
  z-index: 30;
  box-shadow: 0 1px 2px rgb(0 0 0 / 12%);
}

.summit-grips__add:hover {
  background: var(--ht-accent);
  border-color: var(--ht-accent);
  color: var(--ht-surface);
}

/* ── Embedded task query ──────────────────────────────────────────────────
   The result of a `summit-tasks` code block, substituted when the page is
   read. Styled as part of the document rather than as a widget dropped into
   it: the point is that live work reads like the rest of the page. */

.summit-prose .summit-tasks {
  margin: 0 0 var(--prose-gap);
}

.summit-prose .summit-tasks__table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--prose-small);
  table-layout: auto;
}

.summit-prose .summit-tasks__table :is(th, td) {
  border: 1px solid var(--ht-line);
  padding: 0.4em 0.7em;
  text-align: left;
  vertical-align: top;
}

.summit-prose .summit-tasks__table th {
  background: var(--ht-surface-2);
  font-weight: 600;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ht-muted);
}

.summit-prose .summit-tasks__table td:first-child {
  white-space: nowrap;
  font-weight: 600;
}

.summit-prose .summit-tasks__note,
.summit-prose .summit-tasks__empty {
  margin: 0.375rem 0 0;
  font-size: 0.8125rem;
  color: var(--ht-muted);
}

/* A query is live, so it must not print as if it were part of the document
   on the day it was printed. summit-print.css keeps the table; this is the
   line that says when it was true. */
@media print {
  .summit-prose .summit-tasks::after {
    content: "Live task results, as at the time of printing.";
    display: block;
    margin-top: 0.25rem;
    font-size: 8pt;
    color: #666;
  }
}

/* ── Slash menu ───────────────────────────────────────────────────────────
   Drawn at the caret, against the editor's own box. Absolute rather than
   fixed, so it scrolls with the document instead of hovering over it. */

.summit-slash {
  position: absolute;
  z-index: 40;
  min-width: 11rem;
  max-height: 17rem;
  overflow-y: auto;
  padding: 0.25rem;
  border: 1px solid var(--ht-line);
  border-radius: 8px;
  background: var(--ht-surface);
  box-shadow: 0 6px 20px rgb(0 0 0 / 12%);
}

.summit-slash__item {
  display: flex;
  align-items: center;
  /* Explicit: Chrome's user-agent sheet centres button content, and a menu
     of centred labels reads as a toolbar rather than as a list. */
  justify-content: flex-start;
  width: 100%;
  padding: 0.3125rem 0.625rem;
  border: 0;
  border-radius: 5px;
  background: none;
  text-align: left;
  color: var(--ht-ink);
  font: 400 0.875rem/1.3 var(--ht-font);
  cursor: pointer;
  white-space: nowrap;
}

.summit-slash__item:hover,
.summit-slash__item:focus-visible {
  background: var(--ht-surface-2);
  color: var(--ht-accent);
}
