/* Rich text: editor (.rte) and the shared read-only renderer (.rich-content). Syntax colours: light + dark tokens. */
:root {
  --hl-bg: #f6f8fa; --hl-head: #eceff3; --hl-fg: #24292f; --hl-comment: #6a737d; --hl-keyword: #cf222e; --hl-string: #0a3069; --hl-number: #0550ae;
  --hl-title: #6639ba; --hl-attr: #116329; --hl-built: #953800; --hl-meta: #8250df;
}
:root[data-theme="dark"] {
  --hl-bg: #161b22; --hl-head: #1f2630; --hl-fg: #e6edf3; --hl-comment: #8b949e; --hl-keyword: #ff7b72; --hl-string: #a5d6ff; --hl-number: #79c0ff;
  --hl-title: #d2a8ff; --hl-attr: #7ee787; --hl-built: #ffa657; --hl-meta: #d2a8ff;
}
html.rte-lock { overflow: hidden; }

/* ---- content (editor surface + renderer share these rules) ---- */
.rich-content { font-size: var(--fs-body); line-height: 1.65; color: var(--text); overflow-wrap: anywhere; min-width: 0; }
.rich-content > :first-child { margin-top: 0; }
.rich-content > :last-child { margin-bottom: 0; }
.rich-content p { margin: 0 0 .65em; }
.rich-content h1, .rich-content h2, .rich-content h3 { font-weight: var(--fw-semibold); line-height: 1.3; margin: 1.1em 0 .4em; }
.rich-content h1 { font-size: 1.45em; } .rich-content h2 { font-size: 1.22em; } .rich-content h3 { font-size: 1.07em; }
.rich-content ul, .rich-content ol { margin: 0 0 .65em; padding-inline-start: 1.5em; }
.rich-content li > p { margin-bottom: .2em; }
.rich-content blockquote { margin: 0 0 .8em; padding: .15em .9em; border-inline-start: 3px solid var(--border-strong); color: var(--text-muted); }
.rich-content hr { border: 0; border-top: 1px solid var(--border); margin: 1.1em 0; opacity: 1; }
.rich-content a { color: var(--accent-text); text-decoration: none; }
.rich-content a:hover { text-decoration: underline; }
.rich-content :not(pre) > code { font-family: var(--font-mono); font-size: .88em; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: .05em .35em; direction: ltr; unicode-bidi: isolate; }
.rich-content table { border-collapse: collapse; margin: 0 0 .9em; max-width: 100%; display: block; overflow-x: auto; }
.rich-content th, .rich-content td { border: 1px solid var(--border); padding: 5px 9px; vertical-align: top; min-width: 70px; text-align: start; }
.rich-content th { background: var(--surface-2); font-weight: var(--fw-semibold); }
.rich-content--box { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--sp-3); }
/* checklists */
.rich-content ul[data-type="taskList"] { list-style: none; padding-inline-start: .2em; }
.rich-content li[data-type="taskItem"] { display: flex; gap: .55em; align-items: flex-start; }
.rich-content li[data-type="taskItem"]::before { content: ''; flex: none; inline-size: 1em; block-size: 1em; margin-block-start: .38em; border: 1.5px solid var(--border-strong); border-radius: 4px; background: var(--surface); }
.rich-content li[data-type="taskItem"][data-checked="true"]::before { background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round' d='M3.5 8.5l3 3 6-7'/%3E%3C/svg%3E") center/100% no-repeat; border-color: var(--accent); }
.rich-content li[data-type="taskItem"][data-checked="true"] > * { color: var(--text-muted); text-decoration: line-through; }
.rich-content li[data-type="taskItem"] > div, .rich-content li[data-type="taskItem"] > p { flex: 1; min-width: 0; margin: 0; }

/* ---- code blocks: always LTR, monospace, horizontal scroll, light + dark ---- */
.rich-content pre, .rte-content pre { margin: 0; padding: var(--sp-3); background: var(--hl-bg); color: var(--hl-fg); font-family: var(--font-mono); font-size: 12.5px; line-height: 1.6;
  white-space: pre; overflow: auto; tab-size: 4; direction: ltr; text-align: left; unicode-bidi: isolate; max-block-size: 520px; border-radius: 0 0 var(--r-md) var(--r-md); }
.rich-content pre code, .rte-content pre code { font: inherit; background: none; border: 0; padding: 0; color: inherit; white-space: inherit; direction: ltr; }
.rc-code, .rte-code { margin: 0 0 .9em; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; direction: ltr; text-align: left; background: var(--hl-bg); }
.rc-code__head, .rte-code__head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-2); padding: 3px 6px 3px 10px; background: var(--hl-head); border-bottom: 1px solid var(--border); font-size: var(--fs-xs); color: var(--text-muted); user-select: none; }
.rc-code__lang { font-family: var(--font-mono); letter-spacing: .02em; }
.rc-code__copy, .rte-code__copy { display: inline-flex; align-items: center; gap: 5px; border: 0; background: transparent; color: var(--text-muted); font-size: var(--fs-xs); padding: 2px 8px; border-radius: var(--r-sm); cursor: pointer; }
.rc-code__copy:hover, .rte-code__copy:hover { background: var(--surface-hover); color: var(--text); }
.rc-code__copy.is-done, .rte-code__copy.is-done { color: var(--success); }
.rte-code__lang { font: inherit; font-family: var(--font-mono); font-size: var(--fs-xs); color: var(--text-muted); background: transparent; border: 0; padding: 2px 4px; border-radius: var(--r-sm); cursor: pointer; max-inline-size: 140px; }
.rte-code__lang:hover { background: var(--surface-hover); color: var(--text); }
.rte-code__lang:disabled { cursor: default; appearance: none; }
.rte-code pre { border-radius: 0; }
.hljs-comment, .hljs-quote { color: var(--hl-comment); font-style: italic; }
.hljs-keyword, .hljs-selector-tag, .hljs-doctag, .hljs-literal, .hljs-type { color: var(--hl-keyword); }
.hljs-string, .hljs-regexp, .hljs-addition, .hljs-meta .hljs-string { color: var(--hl-string); }
.hljs-number, .hljs-symbol, .hljs-bullet { color: var(--hl-number); }
.hljs-title, .hljs-section, .hljs-title.function_, .hljs-title.class_ { color: var(--hl-title); }
.hljs-attr, .hljs-attribute, .hljs-name, .hljs-selector-class, .hljs-selector-id, .hljs-tag { color: var(--hl-attr); }
.hljs-built_in, .hljs-variable, .hljs-template-variable, .hljs-params { color: var(--hl-built); }
.hljs-meta, .hljs-link, .hljs-deletion { color: var(--hl-meta); }
.hljs-emphasis { font-style: italic; } .hljs-strong { font-weight: 700; }

/* ---- editor shell ---- */
.rte { position: relative; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); transition: border-color var(--t-fast), box-shadow var(--t-fast); }
.rte:hover { border-color: var(--text-faint); }
.rte.is-focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
.rte:has(textarea.is-invalid) { border-color: var(--danger); }
.rte:not(.is-ready) .rte-mount { display: none; }
.rte:not(.is-ready) textarea.rte-source { display: block; border: 0; min-height: var(--rte-min, 140px); }
.rte-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 4px 6px; border-bottom: 1px solid var(--border); background: var(--surface-2); border-radius: var(--r-md) var(--r-md) 0 0; position: relative; z-index: 3; }
.rte-tail { display: inline-flex; gap: 2px; margin-inline-start: auto; }
.rte-sep { inline-size: 1px; block-size: 18px; background: var(--border); margin-inline: 4px; }
.rte-btn { inline-size: 28px; block-size: 28px; display: inline-flex; align-items: center; justify-content: center; border: 0; background: transparent; color: var(--text-muted); border-radius: var(--r-sm); font-size: 15px; cursor: pointer; padding: 0; }
.rte-btn:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }
.rte-btn:focus-visible, .rte-menu__item:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
.rte-btn.is-on { background: var(--accent-soft); color: var(--accent-text); }
.rte-btn:disabled { opacity: .35; cursor: default; }
.rte-btn--text { inline-size: auto; padding-inline: 8px; gap: 5px; font-size: var(--fs-xs); }
.rte-menuwrap { position: relative; display: inline-flex; }
.rte-menu { display: none; position: absolute; inset-block-start: calc(100% + 4px); inset-inline-start: 0; min-inline-size: 190px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--sh-menu); padding: 4px; z-index: 20; }
.rte-menu.is-open { display: block; }
.rte-menu__item { display: flex; align-items: center; gap: 9px; inline-size: 100%; border: 0; background: transparent; color: var(--text); padding: 6px 9px; border-radius: var(--r-sm); font-size: var(--fs-sm); text-align: start; cursor: pointer; }
.rte-menu__item:hover { background: var(--surface-hover); }
.rte-menu__item i { color: var(--text-muted); }
.rte-link { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px; border-bottom: 1px solid var(--border); background: var(--surface); }
.rte-link[hidden], .rte-tablebar[hidden] { display: none; }
.rte-link .m-input { flex: 1 1 200px; min-inline-size: 0; }
.rte-link__err { flex-basis: 100%; color: var(--danger); font-size: var(--fs-xs); }
.rte-link__err:empty { display: none; }
.rte-tablebar { display: flex; flex-wrap: wrap; gap: 2px; padding: 3px 6px; border-bottom: 1px solid var(--border); background: var(--accent-soft); }
.rte-mount { padding: var(--sp-3); }
.rte-content { min-block-size: var(--rte-min, 140px); max-block-size: min(70vh, 640px); overflow-y: auto; outline: none; caret-color: var(--accent); }
.rte-content:focus { outline: none; }
.rte-content p.is-editor-empty:first-child::before { content: attr(data-placeholder); color: var(--text-faint); float: inline-start; block-size: 0; pointer-events: none; }
.rte-content .selectedCell { background: var(--accent-soft); }
.rte-content table { display: table; table-layout: auto; }
.rte-content .rte-code { margin-block: .4em .9em; }
/* in the editor TipTap renders a real (keyboard-accessible) checkbox per item */
.rte-content ul[data-type="taskList"] { list-style: none; padding-inline-start: .2em; }
.rte-content ul[data-type="taskList"] li { display: flex; gap: .55em; align-items: flex-start; }
.rte-content ul[data-type="taskList"] li > label { flex: none; margin-block-start: .38em; user-select: none; line-height: 1; }
.rte-content ul[data-type="taskList"] li > label input { inline-size: 1em; block-size: 1em; margin: 0; accent-color: var(--accent); cursor: pointer; }
.rte-content ul[data-type="taskList"] li > div { flex: 1; min-width: 0; }
.rte-content ul[data-type="taskList"] li > div > p { margin: 0 0 .2em; }
.rte-content ul[data-type="taskList"] li[data-checked="true"] > div { color: var(--text-muted); text-decoration: line-through; }
.rte-content .ProseMirror-selectednode { outline: 2px solid var(--accent); }
.rte-slash { position: absolute; z-index: 30; inline-size: 240px; max-block-size: 280px; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--sh-menu); padding: 4px; }
.rte-slash__item { display: flex; align-items: center; gap: 9px; inline-size: 100%; border: 0; background: transparent; color: var(--text); padding: 6px 9px; border-radius: var(--r-sm); font-size: var(--fs-sm); text-align: start; cursor: pointer; }
.rte-slash__item.is-active, .rte-slash__item:hover { background: var(--accent-soft); }
.rte-slash__item i { color: var(--text-muted); inline-size: 1.1em; }
.rte-slash__empty { padding: 8px 10px; color: var(--text-faint); font-size: var(--fs-sm); }

/* focus mode / fullscreen */
.rte.is-full { position: fixed; inset: 0; z-index: var(--z-lightbox); border-radius: 0; display: flex; flex-direction: column; background: var(--bg); border: 0; }
.rte.is-full .rte-toolbar { border-radius: 0; }
.rte.is-full .rte-mount { flex: 1; overflow: auto; padding: var(--sp-5) var(--sp-4); }
.rte.is-full .rte-content { max-inline-size: 820px; margin-inline: auto; max-block-size: none; min-block-size: 100%; font-size: calc(var(--fs-body) + 1px); }

@media (max-width: 575.98px) {
  .rte-toolbar { padding: 3px; gap: 1px; }
  .rte-btn { inline-size: 32px; block-size: 32px; }
  .rte-sep { margin-inline: 2px; }
  .rte-mount { padding: var(--sp-2) var(--sp-3); }
  .rte-content { max-block-size: 60vh; }
}
@media (prefers-reduced-motion: reduce) { .rte { transition: none; } }

/* ---- compact comment editor (Linear / GitLab style): one quiet line until focused, toolbar + actions on focus ---- */
.cm-form { display: grid; gap: var(--sp-2); }
.cm-form .m-field { margin: 0; }
.cm-form .m-field__error:empty { display: none; }
.rte--compact .rte-toolbar { display: none; border-bottom: 1px solid var(--border); }
.rte--compact.is-open .rte-toolbar { display: flex; }
.rte--compact .rte-mount { padding: 8px 12px; }
.rte--compact .rte-content { min-block-size: var(--rte-min, 40px); max-block-size: 240px; font-size: var(--fs-body); }
.rte--compact.is-expanded .rte-content { min-block-size: 190px; max-block-size: min(60vh, 520px); }
.rte--compact .rte-code { margin-block: .3em .6em; }
.cm-actions { display: none; align-items: center; justify-content: flex-end; gap: var(--sp-2); }
.cm-form:focus-within .cm-actions, .cm-form.has-content .cm-actions, .cm-form--edit .cm-actions { display: flex; }
.cm-hint { margin-inline-end: auto; color: var(--text-faint); font-size: var(--fs-xs); }
@media (max-width: 575.98px) { .cm-hint { display: none; } .cm-actions .m-btn { flex: 1; } }

/* ---- comments in timelines ---- */
.ct-activity__main { min-width: 0; }
.cm__meta { color: var(--text-muted); }
.cm__edited { color: var(--text-faint); cursor: help; }
.cm__body { margin-block-start: 4px; font-size: var(--fs-body); }
.cm__body.is-clamp:not(.is-expanded) { max-block-size: 18em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 72%, transparent); mask-image: linear-gradient(#000 72%, transparent); }
.cm__more { display: inline-block; border: 0; background: none; padding: 2px 0; color: var(--accent-text); font-size: var(--fs-sm); cursor: pointer; }
.cm__more:hover { text-decoration: underline; }
.cm__history { margin-block-start: 6px; font-size: var(--fs-sm); color: var(--text-muted); }
.cm__history summary { cursor: pointer; }
.cm__old { margin-block-start: 6px; padding-inline-start: 10px; border-inline-start: 2px solid var(--border); opacity: .85; }
.cm.is-editing .ct-activity__actions { display: none; }
.cm__edit { margin-block-start: 6px; }
.ct-activity__main .rich-content p { margin: 0 0 .65em; color: inherit; white-space: normal; }
.ct-activity__main .rich-content > :last-child { margin-bottom: 0; }
.rc-code__lang, .rc-code__copy, .rte-code__copy { white-space: nowrap; }
@media (max-width: 575.98px) {
  .cm { position: relative; padding-inline: var(--sp-3); }
  .cm .ct-activity__icon { display: none; }
  .cm .ct-activity__actions { position: absolute; inset-block-start: 2px; inset-inline-end: var(--sp-2); }
  .cm .cm__meta { padding-inline-end: 64px; }
}

/* ---- code blocks, one-line header: the language label and Copy sit at the end of the FIRST code line (not in a bar of their own) ---- */
.rc-code, .rte-code { position: relative; }
.rc-code__head, .rte-code__head { position: absolute; inset-block-start: 0; inset-inline-end: 0; z-index: 1; gap: 2px; padding: 2px 4px 2px 8px; border: 0; background: var(--hl-bg); border-end-start-radius: var(--r-sm); }
.rc-code pre, .rte-code pre { border-radius: 0; padding-inline-end: calc(var(--sp-3) + 150px); min-block-size: 38px; }
.rc-code pre, .rte-code pre { padding-block: 8px; }

/* Pasted / dropped images */
.rich-content img { max-width: 100%; height: auto; border-radius: var(--r-md); vertical-align: middle; }
.rte-content img.ProseMirror-selectednode { outline: 2px solid var(--accent); outline-offset: 2px; }
/* image options: size (small / medium / large / full width) and alignment, set from the bar over a selected image */
.rich-content img[data-size="sm"] { width: min(100%, 220px); }
.rich-content img[data-size="md"] { width: min(100%, 440px); }
.rich-content img[data-size="lg"] { width: min(100%, 680px); }
.rich-content img[data-size="full"] { width: 100%; }
.rich-content img[data-align] { display: block; }
.rich-content img[data-align="left"] { margin-inline: 0 auto; }
.rich-content img[data-align="center"] { margin-inline: auto; }
.rich-content img[data-align="right"] { margin-inline: auto 0; }
.rte-imgbar { padding: 3px 4px; }
.rte-imgbar__txt { width: auto; min-width: 26px; padding-inline: 6px; font-size: var(--fs-xs); font-weight: var(--fw-semibold); }
.rte-imgbar .is-on { background: var(--accent-soft); color: var(--accent-text); }
.rte-imgbar__sep { width: 1px; align-self: stretch; margin: 2px 3px; background: var(--border); }
.rte.is-uploading { position: relative; }
.rte.is-uploading::after { content: ""; position: absolute; inset-inline: 0; inset-block-end: 0; height: 2px; background: linear-gradient(90deg, transparent, var(--accent), transparent); background-size: 40% 100%; background-repeat: no-repeat; animation: rte-upload 1s linear infinite; }
@keyframes rte-upload { from { background-position: -40% 0; } to { background-position: 140% 0; } }
.rich-content img[src^="/rich-images/"] { cursor: zoom-in; }
.rte-content img[src^="/rich-images/"] { cursor: default; }
.m-lightbox { position: fixed; inset: 0; z-index: var(--z-modal); display: flex; align-items: center; justify-content: center; padding: 3vh 3vw; background: rgb(0 0 0 / .82); cursor: zoom-out; }
.m-lightbox > img { max-width: 94vw; max-height: 92vh; width: auto; height: auto; object-fit: contain; border-radius: var(--r-md); background: #fff; box-shadow: 0 10px 40px rgb(0 0 0 / .5); cursor: default; }
.m-lightbox__close, .m-lightbox__open { position: fixed; inset-block-start: 12px; background: rgb(0 0 0 / .55); color: #fff; border-radius: var(--r-pill); }
.m-lightbox__close { inset-inline-end: 12px; }
.m-lightbox__open { inset-inline-end: 56px; text-decoration: none; }
.m-lightbox__close:hover, .m-lightbox__open:hover { background: rgb(0 0 0 / .8); color: #fff; }

/* Link bar: open in a new tab / copy / edit, under the link the cursor is on */
.rte-linktip { position: absolute; z-index: 5; display: flex; align-items: center; gap: 2px; max-width: calc(100% - 8px); padding: 3px 4px 3px 10px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-md); box-shadow: 0 4px 14px rgb(0 0 0 / .22); }
.rte-linktip[hidden] { display: none; }
.rte-linktip__url { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--fs-xs); color: var(--text-muted); margin-inline-end: 4px; }
.rte-linktip__btn { display: inline-grid; place-items: center; width: 26px; height: 26px; padding: 0; border: 0; border-radius: var(--r-sm); background: none; color: var(--text-muted); cursor: pointer; text-decoration: none; }
.rte-linktip__btn:hover { background: var(--surface-hover); color: var(--text); }

/* Every editor: the toolbar floats above the selected text (placed by mosta.js); the full-screen editor keeps its fixed toolbar. "/" opens the command menu. */
.rte:not(.is-full) .rte-toolbar { display: none; position: fixed; z-index: 1080; inset: auto; padding: 3px 4px; border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--sh-menu); }
.rte:not(.is-full) .rte-toolbar.is-bubble { display: flex; }
.rte:not(.is-full) .rte-link, .rte:not(.is-full) .rte-tablebar { border-radius: var(--r-md); }
