/* Rich text: read-only view (.rt-view) and editor (.rt-editor) */
.rt-view { overflow-wrap: anywhere; }
.rt-view.rt-plain { white-space: pre-wrap; }
.rt-view > :first-child, .rt-area > :first-child { margin-top: 0; }
.rt-view > :last-child, .rt-area > :last-child { margin-bottom: 0; }
.rt-view p, .rt-area p { margin: 0 0 .5em; }
.rt-view h1, .rt-area h1 { font-size: 1.45em; margin: .4em 0; }
.rt-view h2, .rt-area h2 { font-size: 1.3em; margin: .4em 0; }
.rt-view h3, .rt-area h3 { font-size: 1.15em; margin: .4em 0; }
.rt-view h4, .rt-area h4 { font-size: 1.05em; margin: .4em 0; }
.rt-view ul, .rt-view ol, .rt-area ul, .rt-area ol { margin: .3em 0 .5em; padding-left: 1.6em; }
.rt-view blockquote, .rt-area blockquote { margin: .4em 0; padding: 2px 12px; border-left: 3px solid var(--border-strong); color: var(--text-2); }
.rt-view pre, .rt-area pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 6px 10px; font: 12px var(--mono); white-space: pre-wrap; margin: .4em 0; }
.rt-view code, .rt-area code { background: var(--surface-2); border-radius: 3px; padding: 0 3px; font: .92em var(--mono); }
.rt-view mark, .rt-area mark { background: color-mix(in srgb, var(--amber) 40%, var(--surface)); color: var(--text); }
.rt-view table, .rt-area table { border-collapse: collapse; margin: .4em 0; max-width: 100%; font-size: .95em; }
.rt-view td, .rt-view th, .rt-area td, .rt-area th { border: 1px solid var(--border-strong); padding: 3px 7px; vertical-align: top; min-width: 40px; }
.rt-view th, .rt-area th, .rt-view thead td { background: var(--surface-2); font-weight: 600; text-align: left; }
.rt-view caption, .rt-area caption { caption-side: top; font-size: .9em; color: var(--muted); text-align: left; padding: 2px 0; }
.rt-view img, .rt-area img { max-width: 100%; height: auto; border-radius: 3px; }
.rt-view figure, .rt-area figure { margin: .5em 0; }
.rt-view figcaption, .rt-area figcaption { font-size: .88em; color: var(--muted); font-style: italic; }
.rt-view hr, .rt-area hr { border: 0; border-top: 1px solid var(--line); margin: .6em 0; }
.rt-view a, .rt-area a { color: var(--accent); }
a.embedded-link { background: var(--sel-bg); border-radius: 3px; padding: 0 4px; }
a.embedded-link::before { content: "🔗 "; font-size: .85em; }
a.rt-file { display: inline-flex; gap: 4px; align-items: center; border: 1px solid var(--line); border-radius: 4px; padding: 1px 8px; background: var(--surface-2); text-decoration: none; }
figure.rt-diagram { border: 1px solid var(--line); border-radius: 4px; padding: 6px; display: inline-block; background: var(--canvas-bg); }
inno { display: inline; background: var(--info-bg); color: var(--info); border-radius: var(--r-sm); padding: 0 3px; border-bottom: 1px dotted var(--info); white-space: nowrap; cursor: default; }
inno.rt-missing { background: var(--danger-bg); color: var(--danger); }
table.rt-qtable { outline: 1px dashed var(--border-strong); outline-offset: 2px; }
.rt-view.is-empty::before, .rt-area.is-empty::before { content: attr(data-ph); color: var(--text-3); font-style: italic; }
.rt-area.is-empty::before { position: absolute; pointer-events: none; }
.rt-field { cursor: text; border-radius: 3px; min-height: 1.4em; }
.rt-field:hover > .rt-view { background: var(--hover-bg); box-shadow: 0 0 0 1px var(--line); border-radius: 3px; }
.rt-diff del { background: var(--danger-bg); color: var(--danger); text-decoration: line-through; }
.rt-diff ins { background: var(--ok-bg); color: var(--ok); text-decoration: none; }

/* editor */
.rt-editor { border: 1px solid var(--focus); border-radius: var(--r-sm); background: var(--input-bg); box-shadow: 0 0 0 2px var(--focus-halo); margin: 2px 0; font-weight: 400; font-size: 14px; color: var(--text); cursor: auto; }
.rt-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 1px; padding: 3px 4px; border-bottom: 1px solid var(--border); background: var(--surface-2); position: sticky; top: 0; z-index: 2; border-radius: 4px 4px 0 0; }
.rt-btn { min-width: 26px; height: 26px; padding: 0 5px; border: 1px solid transparent; background: none; border-radius: 3px; font-size: 13px; color: var(--text); cursor: pointer; line-height: 1; }
.rt-btn:hover { background: var(--hover-bg); border-color: var(--line); }
.rt-btn.rt-ai { color: var(--ai-line); font-weight: 700; }
.rt-btn.rt-add { font-weight: 700; font-size: 16px; }
.rt-btn.rt-color { text-decoration: underline; text-decoration-color: var(--danger); text-decoration-thickness: 3px; font-weight: 700; }
.rt-btn.rt-save { color: var(--ok); font-weight: 700; }
.rt-sep { width: 1px; height: 18px; background: var(--line); margin: 0 3px; }
.rt-area { position: relative; min-height: 64px; max-height: 60vh; overflow: auto; padding: 8px 10px; outline: none; line-height: 1.5; cursor: text; }
.rt-source { width: 100%; min-height: 120px; border: 0; padding: 8px 10px; font: 12px var(--mono); outline: none; resize: vertical; }
.rt-status { display: flex; gap: 8px; padding: 2px 8px; border-top: 1px solid var(--line-2); font-size: 11px; color: var(--muted); }
.rt-editor.rt-full { position: fixed; inset: 40px 6vw; z-index: 70; display: flex; flex-direction: column; box-shadow: var(--shadow); }
.rt-editor.rt-full .rt-area { flex: 1; max-height: none; }
.rt-swatches { display: flex; gap: 4px; padding: 4px 10px 8px; flex-wrap: wrap; max-width: 190px; }
.rt-swatch { width: 18px; height: 18px; border-radius: 3px; border: 1px solid var(--border-strong); cursor: pointer; padding: 0; }
.rt-chars { display: grid; grid-template-columns: repeat(10, 34px); gap: 4px; }
.rt-char { height: 32px; border: 1px solid var(--border); background: var(--surface); border-radius: 4px; font-size: 16px; cursor: pointer; }
.rt-char:hover { background: var(--sel-bg); }
.rt-attr-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.rt-attr-chips button { border: 0; background: none; cursor: pointer; margin-left: 2px; }
.rt-qprev { max-height: 220px; overflow: auto; border: 1px solid var(--line); padding: 4px; }
.rt-qprev table { border-collapse: collapse; font-size: 12px; width: 100%; }
.rt-qprev td, .rt-qprev th { border: 1px solid var(--line); padding: 2px 6px; text-align: left; }
.rt-preview-val { padding: 6px 8px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; }
.rt-offscreen { position: fixed; left: -20000px; top: 0; width: 1200px; height: 800px; visibility: hidden; pointer-events: none; }
@media print { .rt-toolbar, .rt-status { display: none !important; } inno { background: none; border: 0; color: inherit; } }
[data-theme=dark] .rt-toolbar { background: var(--panel-2); }
[data-theme=dark] .rt-btn { color: var(--text); }
[data-theme=dark] .rt-btn:hover { background: var(--hover); }
[data-theme=dark] .rt-source { background: var(--input-bg); color: var(--text); }
[data-theme=dark] .rt-view th, [data-theme=dark] .rt-area th, [data-theme=dark] .rt-view thead td { background: var(--panel-2); }
[data-theme=dark] .rt-view td, [data-theme=dark] .rt-view th, [data-theme=dark] .rt-area td, [data-theme=dark] .rt-area th { border-color: var(--line-strong); }
[data-theme=dark] .rt-view pre, [data-theme=dark] .rt-area pre, [data-theme=dark] .rt-view code, [data-theme=dark] .rt-area code { background: var(--panel-2); }
[data-theme=dark] .rt-view blockquote, [data-theme=dark] .rt-area blockquote { color: var(--text-2); border-color: var(--line-strong); }
[data-theme=dark] a.embedded-link { background: var(--accent-2); }
[data-theme=dark] a.rt-file, [data-theme=dark] figure.rt-diagram, [data-theme=dark] .rt-char, [data-theme=dark] .rt-preview-val { background: var(--panel-2); }
