/* Rich text (task descriptions): the formatted view and the WYSIWYG editor (public/js/richtext.js).
   The six text colours and the highlighter are tokens with light and dark values; every colour keeps at least 4.5:1 (WCAG AA)
   on the page surfaces and on the highlighter in both themes. */
:root {
  --rt-red: #c0262d; --rt-orange: #a84f06; --rt-green: #1e7a3e; --rt-blue: #1f5fbf; --rt-purple: #7a3cc0; --rt-gray: #5d6675;
  --rt-mark: #fff0a6;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --rt-red: #ff8d8d; --rt-orange: #ffaa5c; --rt-green: #6cd492; --rt-blue: #8ab4ff; --rt-purple: #c4a2ff; --rt-gray: #a3acba;
    --rt-mark: #4d3d0e;
  }
}
:root[data-theme="dark"] {
  --rt-red: #ff8d8d; --rt-orange: #ffaa5c; --rt-green: #6cd492; --rt-blue: #8ab4ff; --rt-purple: #c4a2ff; --rt-gray: #a3acba;
  --rt-mark: #4d3d0e;
}

/* ---------- formatted text (view and editor share it) */
.rt { line-height: 1.55; overflow-wrap: anywhere; color: var(--fg); }
.rt > :first-child { margin-top: 0; }
.rt > :last-child { margin-bottom: 0; }
.rt p { margin: 0 0 0.5rem; }
.rt .rt-h, .rt h2, .rt h3 { margin: 0.75rem 0 0.375rem; font-weight: 600; letter-spacing: -.005em; line-height: 1.3; text-transform: none; color: var(--fg); }
.rt h2 { font-size: 1rem; }
.rt h3 { font-size: 0.9063rem; }
.rt ul, .rt ol { margin: 0.25rem 0 0.5rem; padding-left: 1.375rem; }
.rt li { margin: 0.125rem 0; }
.rt li > ul, .rt li > ol, .rt ul > ul, .rt ol > ol, .rt ul > ol, .rt ol > ul { margin: 0.125rem 0; }
.rt blockquote { margin: 0.5rem 0; padding: 0.125rem 0 0.125rem 0.75rem; border-left: 3px solid var(--line); color: var(--muted); }
.rt hr { border: 0; border-top: 1px solid var(--line); margin: 0.75rem 0; }
.rt code, .rt .rt-code { font-family: var(--font-mono); font-size: 0.8em; background: var(--chip); padding: 1px 0.3125rem; border-radius: 0.25rem; }
.rt pre { margin: 0.5rem 0; padding: 0.625rem 0.75rem; background: var(--surface-3); border: 1px solid var(--line-soft); border-radius: var(--radius); overflow-x: auto; white-space: pre; }
.rt pre code { background: none; padding: 0; font-size: 0.75rem; }
.rt a.rt-link { color: var(--info); text-decoration: underline; text-underline-offset: 2px; }
.rt a.rt-tasklink { font-family: var(--font-mono); font-size: 0.78em; color: var(--accent-ink); background: var(--accent-soft); padding: 1px 0.3125rem; border-radius: 0.25rem; text-decoration: none; white-space: nowrap; }
.rt a.rt-tasklink:hover { text-decoration: underline; }
.rt-c-red { color: var(--rt-red); } .rt-c-orange { color: var(--rt-orange); } .rt-c-green { color: var(--rt-green); }
.rt-c-blue { color: var(--rt-blue); } .rt-c-purple { color: var(--rt-purple); } .rt-c-gray { color: var(--rt-gray); }
.rt-mark { background: var(--rt-mark); border-radius: 0.1875rem; padding: 0 0.125rem; box-decoration-break: clone; -webkit-box-decoration-break: clone; }

/* checklists: a box instead of the bullet */
.rt li.rt-task { list-style: none; position: relative; }
.rt-box, .rt-area li.rt-task::before {
  position: absolute; left: -1.375rem; top: 0.2rem; width: 0.95rem; height: 0.95rem; box-sizing: border-box;
  border: 1.5px solid var(--ctl-line); border-radius: 0.25rem; background: var(--surface);
}
.rt-box { display: inline-block; }
.rt-box[tabindex] { cursor: pointer; }
.rt-box[tabindex]:hover { border-color: var(--accent); }
.rt-box:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rt-box[aria-checked="true"], .rt-area li.rt-task[data-checked="true"]::before { background: var(--accent); border-color: var(--accent); }
.rt-box[aria-checked="true"]::after, .rt-area li.rt-task[data-checked="true"]::after {
  content: ""; position: absolute; width: 0.28rem; height: 0.52rem; border: solid var(--accent-fg); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.rt-box[aria-checked="true"]::after { left: 0.27rem; top: 0.08rem; }
.rt-area li.rt-task[data-checked="true"]::after { left: calc(-1.375rem + 0.33rem); top: 0.28rem; pointer-events: none; }
.rt-area li.rt-task::before { content: ""; cursor: pointer; }
.rt li.rt-task[data-checked="true"] > .rt-li-text { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }

/* ---------- view (task panel): grows with the text up to a screen-relative ceiling, then scrolls */
.rt-view { max-height: min(60vh, 40rem); overflow-y: auto; overscroll-behavior: contain; padding: 0.5rem 0.625rem; margin: 0 -0.625rem; border-radius: var(--radius); scrollbar-gutter: auto; }
.rt-view.rt-clickable { cursor: text; transition: background .12s; }
.rt-view.rt-clickable:hover { background: var(--hover); }
.rt-view a, .rt-view .rt-box { cursor: pointer; }
.rt-empty { display: block; width: 100%; text-align: left; border: 1px dashed var(--line); background: transparent; color: var(--muted); border-radius: var(--radius); padding: 0.625rem 0.75rem; font: inherit; }
.rt-empty:hover { border-color: var(--ctl-line); color: var(--fg); background: var(--hover); }

/* ---------- editor */
.rt-editor { position: relative; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); transition: border-color .12s, box-shadow .12s; }
.rt-editor:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.rt-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 1px; padding: 0.25rem; border-bottom: 1px solid var(--line-soft); background: var(--surface-2); border-radius: var(--radius) var(--radius) 0 0; position: sticky; top: 0; z-index: 2; }
.rt-tb-btn { width: 1.875rem; height: 1.75rem; display: inline-grid; place-items: center; border: 0; padding: 0; background: transparent; color: var(--muted); border-radius: 0.375rem; }
.rt-tb-btn:hover { background: var(--chip); color: var(--fg); }
.rt-tb-btn[aria-pressed="true"], .rt-tb-btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent-ink); }
.rt-tb-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
.rt-ico { width: 1rem; height: 1rem; }
.rt-sep { width: 1px; height: 1.125rem; background: var(--line); margin: 0 0.25rem; }
/* the text area grows with its content; past the ceiling it scrolls and the toolbar above stays in view */
.rt-area { min-height: 5.5rem; max-height: min(55vh, 34rem); overflow-y: auto; overscroll-behavior: contain; padding: 0.5rem 0.75rem; outline: none; white-space: pre-wrap; position: relative; }
.rt-editor.compact .rt-area { min-height: 4rem; max-height: min(35vh, 16rem); }
.rt-area.is-empty::before { content: attr(data-placeholder); position: absolute; left: 0.75rem; top: 0.5rem; right: 0.75rem; color: var(--faint); pointer-events: none; white-space: normal; }
.rt-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; padding: 0.375rem 0.5rem; border-top: 1px solid var(--line-soft); }
.rt-hint { margin-left: auto; }

/* popovers (colour, emoji, link) */
.rt-pop { position: absolute; z-index: 5; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 0.5rem; max-width: calc(100% - 0.25rem); }
.rt-pop-colors { display: flex; flex-direction: column; gap: 0.25rem; min-width: 12rem; }
.rt-sw-grid { display: grid; grid-template-columns: repeat(6, 1.875rem); gap: 0.25rem; margin-bottom: 0.25rem; }
.rt-sw { width: 1.875rem; height: 1.875rem; border: 1px solid var(--line); border-radius: 0.375rem; background: var(--surface); display: grid; place-items: center; padding: 0; }
.rt-sw:hover { border-color: var(--ctl-line); background: var(--hover); }
.rt-sw-dot { font-weight: 700; font-size: 0.9375rem; line-height: 1; }
.rt-sw-text { border: 0; background: transparent; text-align: left; padding: 0.3125rem 0.375rem; border-radius: 0.375rem; color: var(--fg); }
.rt-sw-text:hover { background: var(--hover); }
.rt-emoji-grid { display: grid; grid-template-columns: repeat(8, 2rem); gap: 0.125rem; max-width: 100%; }
.rt-emo { width: 2rem; height: 2rem; border: 0; background: transparent; border-radius: 0.375rem; font-size: 1.125rem; line-height: 1; padding: 0; }
.rt-emo:hover { background: var(--chip); }
.rt-pop-link { display: flex; flex-direction: column; gap: 0.375rem; width: min(20rem, calc(100% - 0.25rem)); }
.rt-pop-row { display: flex; gap: 0.375rem; }
.rt-pop-err { color: var(--crit); font-size: 0.75rem; }
.rt-pop button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- documents: all heading levels (# ## ### split a document into sections) */
.rt h1 { font-size: 1.1875rem; margin: 1rem 0 0.5rem; font-weight: 600; letter-spacing: -.01em; line-height: 1.25; }
.rt h4, .rt h5, .rt h6 { font-size: 0.8438rem; margin: 0.625rem 0 0.25rem; font-weight: 600; color: var(--fg); }

/* ---------- any colour: exact value kept in --rt-c / --rt-bg; the drawn ink is computed for each theme (see readableInk in richtext.js) */
.rt-cx { color: var(--rt-c-l, var(--rt-c)); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .rt-cx { color: var(--rt-c-d, var(--rt-c)); } }
:root[data-theme="dark"] .rt-cx { color: var(--rt-c-d, var(--rt-c)); }
.rt-bgx { background: var(--rt-bg); color: var(--rt-bg-ink, inherit); border-radius: 0.1875rem; padding: 0 0.125rem; box-decoration-break: clone; -webkit-box-decoration-break: clone; }

/* ---------- tables (GFM; a copied Google Sheet is one big table) */
.rt .rt-table { overflow-x: auto; margin: 0.5rem 0 0.75rem; border: 1px solid var(--line); border-radius: var(--radius); max-width: 100%; }
.rt .rt-table table { border-collapse: collapse; width: max-content; min-width: 100%; font-size: 0.8125rem; }
.rt .rt-table th, .rt .rt-table td { border-bottom: 1px solid var(--line-soft); border-right: 1px solid var(--line-soft); padding: 0.3125rem 0.5rem; text-align: left; vertical-align: top; white-space: pre-wrap; }
.rt .rt-table th { background: var(--surface-2); font-weight: 600; position: sticky; top: 0; }
.rt .rt-table tr:last-child td { border-bottom: 0; }
.rt .rt-table th:last-child, .rt .rt-table td:last-child { border-right: 0; }
.rt .rt-al-c { text-align: center !important; } .rt .rt-al-r { text-align: right !important; }
.rt-area .rt-table { cursor: default; user-select: none; outline: 1px dashed transparent; }
.rt-area .rt-table:hover { outline-color: var(--ctl-line); }

/* ---------- images and videos attached to the task, inside the text */
.rt-att { display: inline-block; vertical-align: top; max-width: 100%; margin: 0.25rem 0; }
.rt-att img, .rt-att video { display: block; max-width: min(100%, 32rem); max-height: 22rem; border-radius: var(--radius); border: 1px solid var(--line); background: var(--surface-3); }
.rt-att-img { padding: 0; border: 0; background: none; cursor: zoom-in; border-radius: var(--radius); }
.rt-att-img:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.rt-att-missing, .rt-att-ref, .rt-att-uploading { font-size: 0.8125rem; color: var(--muted); background: var(--chip); border-radius: 0.375rem; padding: 0.125rem 0.5rem; }
.rt-att-uploading { color: var(--fg); background: var(--accent-soft); }
.rt-area .rt-att { cursor: default; }
.rt-area .rt-att:hover img, .rt-area .rt-att:hover video { border-color: var(--ctl-line); }
.rt-editor.is-busy .rt-save { opacity: .6; }
.rt-err { margin: 0; padding: 0.375rem 0.75rem; color: var(--crit); background: var(--crit-soft); font-size: 0.8125rem; border-top: 1px solid var(--line-soft); }

/* ---------- colour palettes */
.rt-pop-label { margin: 0.25rem 0 0.125rem; font-size: 0.6875rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.rt-palette { display: grid; grid-template-columns: repeat(10, 1.375rem); gap: 0.1875rem; }
.rt-pal { width: 1.375rem; height: 1.375rem; padding: 0; border: 1px solid var(--line); border-radius: 0.25rem; background: var(--surface); display: grid; place-items: stretch; }
.rt-pal-sw { display: block; border-radius: 0.1875rem; background: var(--sw); }
.rt-pal:hover, .rt-pal:focus-visible { transform: scale(1.15); border-color: var(--fg); }
.rt-custom { display: flex; align-items: center; gap: 0.5rem; margin-top: 0.375rem; font-size: 0.8125rem; color: var(--fg); cursor: pointer; }
.rt-custom-input { width: 2rem; height: 1.5rem; padding: 0; border: 1px solid var(--line); border-radius: 0.25rem; background: var(--surface); cursor: pointer; }

/* ---------- emoji picker */
.rt-pop-emoji { width: min(22rem, calc(100% - 0.25rem)); }
.rt-emoji-top { display: flex; gap: 0.375rem; align-items: center; margin-bottom: 0.375rem; }
.rt-emoji-search { flex: 1; min-width: 0; height: 1.875rem; padding: 0.25rem 0.5rem; }
.rt-tones { display: flex; gap: 2px; flex: none; }
.rt-tone { width: 1.125rem; height: 1.125rem; border-radius: 50%; border: 2px solid transparent; padding: 0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .15); }
.rt-tone[aria-pressed="true"] { border-color: var(--accent); }
.rt-tone-0 { background: #ffc83d; } .rt-tone-1 { background: #f7d7c4; } .rt-tone-2 { background: #d8b094; }
.rt-tone-3 { background: #bb9167; } .rt-tone-4 { background: #8e562e; } .rt-tone-5 { background: #613d30; }
.rt-emoji-tabs { display: flex; gap: 1px; overflow-x: auto; border-bottom: 1px solid var(--line-soft); padding-bottom: 0.25rem; scrollbar-width: thin; }
.rt-emoji-tab { flex: none; width: 1.875rem; height: 1.875rem; border: 0; background: transparent; border-radius: 0.375rem; font-size: 1.0625rem; padding: 0; opacity: .7; }
.rt-emoji-tab:hover { background: var(--chip); opacity: 1; }
.rt-emoji-tab[aria-selected="true"] { background: var(--accent-soft); opacity: 1; box-shadow: inset 0 -2px 0 var(--accent); }
.rt-emoji .rt-emoji-grid { grid-template-columns: repeat(auto-fill, 2rem); max-height: 13.5rem; overflow-y: auto; overscroll-behavior: contain; padding: 2px; content-visibility: auto; }
.rt-emoji-none, .rt-emoji-loading { grid-column: 1 / -1; padding: 0.5rem; margin: 0; }
.rt-emoji-hint { margin: 0.375rem 0 0; }
.rt-emoji-label { margin-top: 0.375rem; }
.rt-emo, .rt-emoji-tab { font-family: "Twemoji Country Flags", "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", var(--font-body); } /* (the flag font first: Windows draws country flags as letters) */
.rt-emo:focus-visible, .rt-emoji-tab:focus-visible, .rt-tone:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }

/* ---------- document editor (Markdown source toggle) */
.doc-editor-bar { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.3125rem; }
.doc-src { font-family: var(--font-mono); font-size: 0.8125rem; min-height: 16rem; max-height: min(55vh, 34rem); }
.doc-links-kept { margin-top: 0.625rem; padding: 0.5rem 0.75rem; border: 1px dashed var(--line); border-radius: var(--radius); background: var(--surface-2); }
.doc-links-kept .rt { font-size: 0.8125rem; }

@media (max-width: 480px) {
  .rt-emoji-grid { grid-template-columns: repeat(6, 2rem); }
  .rt-hint { display: none; }
  .rt-area { max-height: 45vh; }
  .rt-palette { grid-template-columns: repeat(10, 1.125rem); }
  .rt-pal { width: 1.125rem; height: 1.125rem; }
}
