/* Writing together: the shared drafts components (packs/editing/app/components/editing/; docs/editing_plan/09-every-screen.md). One stylesheet for the pack,
   in the order the page reads: a person's face and their caret, the offer to write together, the live form's header (who is here, the connection, the
   mode), the form and its panel, the suggestions (in the list and as marks in the text), the comments, the people, the versions and their comparison, and
   the two sheets (restore, submit). The classes inside an editor are the shared editor code's (editing/shared/: `editing-caret`, `editing-caret-label`,
   `editing-selection`, `editing-person-<n>`, `editing-insertion`, `editing-deletion`); a comment's highlight and a suggested break are drawn by
   18-editing-comments.css (SD6), from the comment-mark and insertion tokens.

   A person's color is one of eight tokens (`--editing-person-1` to `-8`, each with a light and a dark value and a `-tint`; 10-globals.css and their pairs in
   config/contrast_pairs.yml), chosen by `data-color` (Editing::PersonColor). It is never the only signal: a face is decoration beside the person's name, a
   suggestion is <ins> or <del> with its author in words, and a state is a word before it is a dot (WCAG 1.4.1).

   Tokens only and logical properties only, both enforced (test/styles/tokens_test.rb, test/styles/components_test.rb), so it reads on the light shell and the
   console, in light and in dark, and mirrors in a right-to-left language. Nothing pinned to an edge (the header sticks only on a wide screen in a browser),
   no height in vh, and everything that holds words may shrink and wrap, so a language 40% longer never widens the page (WCAG 1.4.10). */

/* ── A person's face, and their caret ────────────────────────────────────
   Their initials on their color, the same small round mark wherever a person is drawn. `aria-hidden`: the name is beside it in words. In the text, their
   caret is a line in their color with their name on it (3:1 against the page, the name 4.5:1 on the color), and what they have selected is their tint
   under the page's own text. The color comes from `data-color` on a face and from `editing-person-<n>` on a caret or a selection. */
.editing-face {
  --editing-person: var(--editing-person-1);
  display: inline-grid;
  place-items: center;
  flex: none;
  inline-size: 1.75rem;
  block-size: 1.75rem;
  border-radius: 50%;
  background: var(--editing-person);
  color: var(--fg-invert);
  font-size: var(--text-xs);
  font-weight: 700;
  line-height: 1;
  letter-spacing: 0.02em;
}
.editing-face[data-color="1"],
.editing-person-1 {
  --editing-person: var(--editing-person-1);
  --editing-person-tint: var(--editing-person-1-tint);
}
.editing-face[data-color="2"],
.editing-person-2 {
  --editing-person: var(--editing-person-2);
  --editing-person-tint: var(--editing-person-2-tint);
}
.editing-face[data-color="3"],
.editing-person-3 {
  --editing-person: var(--editing-person-3);
  --editing-person-tint: var(--editing-person-3-tint);
}
.editing-face[data-color="4"],
.editing-person-4 {
  --editing-person: var(--editing-person-4);
  --editing-person-tint: var(--editing-person-4-tint);
}
.editing-face[data-color="5"],
.editing-person-5 {
  --editing-person: var(--editing-person-5);
  --editing-person-tint: var(--editing-person-5-tint);
}
.editing-face[data-color="6"],
.editing-person-6 {
  --editing-person: var(--editing-person-6);
  --editing-person-tint: var(--editing-person-6-tint);
}
.editing-face[data-color="7"],
.editing-person-7 {
  --editing-person: var(--editing-person-7);
  --editing-person-tint: var(--editing-person-7-tint);
}
.editing-face[data-color="8"],
.editing-person-8 {
  --editing-person: var(--editing-person-8);
  --editing-person-tint: var(--editing-person-8-tint);
}

.editing-caret {
  position: relative;
  margin-inline: -1px;
  border-inline-start: 2px solid var(--editing-person, var(--editing-person-1));
  word-break: normal;
  pointer-events: none;
}

.editing-caret-label {
  position: absolute;
  inset-block-end: 100%;
  inset-inline-start: -2px;
  max-inline-size: 12rem;
  overflow: hidden;
  padding: 0.05rem 0.35rem;
  border-start-start-radius: var(--radius-sm);
  border-start-end-radius: var(--radius-sm);
  border-end-end-radius: var(--radius-sm);
  background: var(--editing-person, var(--editing-person-1));
  color: var(--fg-invert);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-style: normal;
  font-weight: 600;
  line-height: 1.3;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: none;
}

.editing-selection {
  background: var(--editing-person-tint, var(--editing-person-1-tint));
}

/* A caret near the end of a line carries its name past the line's end. In a shared form the editor's box cuts it there rather than scrolling sideways
   (the box already scrolls up and down, 58-rich-text.css, so `clip` is not available on the other axis); the name is in the presence list in full. */
.editing-form .rich-editor-content {
  overflow-x: hidden;
}

/* ── Write together ──────────────────────────────────────────────────────
   On a form with a profile, beside the form a person fills alone: a raised card with a title, a sentence, who is in the open draft, and one button. */
.editing-offer {
  display: grid;
  gap: var(--density-block);
  min-inline-size: 0;
  padding: var(--space-4);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}

.editing-offer__title,
.editing-offer__lede,
.editing-offer__people-title {
  margin-block: 0;
  overflow-wrap: anywhere;
}

.editing-offer__lede {
  color: var(--fg2);
  font-size: var(--text-sm);
  max-inline-size: 66ch;
}

.editing-offer__people-title {
  font-size: var(--text-sm);
  font-weight: 600;
}

.editing-offer__people {
  display: flex;
  flex-wrap: wrap;
  gap: var(--density-gap) var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
}

.editing-offer__person {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-inline-size: 0;
}

.editing-offer__name {
  min-inline-size: 0;
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

.editing-offer__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.editing-offer--compact { gap: var(--space-2); padding: var(--space-3); scroll-margin-block-start: var(--space-4); }
.editing-offer--compact .editing-offer__title { font-size: var(--text-lg); }
.editing-offer--compact:focus-visible { outline: 2px solid var(--focus); outline-offset: var(--space-1); }

/* Folded to one row, so the form beside it starts on a phone's first screen: the title, then the button at the row's end; an open draft's people wrap within it. */
.editing-offer--inline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-2) var(--space-3);
}
.editing-offer--inline .editing-offer__title { margin-inline-end: auto; font-size: var(--text-base); }

/* ── Who is here ─────────────────────────────────────────────────────────
   The faces in a row, then "3 here", a native disclosure that opens the list of names and roles in the flow of the header (not over it), so it covers
   nothing and reads the same by keyboard, by touch and to a screen reader. */
.editing-presence {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-inline-size: 0;
}

.editing-presence__faces {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.editing-presence__all {
  min-inline-size: 0;
}

/* Open, the list takes the header's whole row, so the names have room to wrap at 320 px; closed, it takes no room at all (a closed disclosure's content
   is still laid out at the width of its summary in some browsers, which is a box the names spill out of). */
.editing-presence__all[open] {
  flex: 1 1 100%;
}

.editing-presence__all:not([open]) > .editing-presence__list {
  display: none;
}

.editing-presence__count {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--density-chip);
  padding-inline: var(--space-2);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

.editing-presence__list {
  display: grid;
  gap: var(--density-gap);
  margin: var(--space-2) 0 0;
  padding: var(--space-3);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
  list-style: none;
}

.editing-presence__person {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-inline-size: 0;
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

.editing-presence__person > [data-slot="words"] {
  flex: 1 1 auto;
  min-inline-size: 0;
}

/* ── The connection ──────────────────────────────────────────────────────
   The state in words, a dot in its tone before it (decoration: the word says it), and what to do under the three states that need it. */
.editing-connection {
  display: grid;
  gap: var(--space-1);
  min-inline-size: 0;
  font-size: var(--text-sm);
}

.editing-connection__state {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-weight: 600;
}

.editing-connection__dot {
  flex: none;
  inline-size: 0.6rem;
  block-size: 0.6rem;
  border-radius: 50%;
  background: var(--editing-connection-tone, var(--fg3));
}
.editing-connection[data-tone="good"] { --editing-connection-tone: var(--tone-good-fg); }
.editing-connection[data-tone="warn"] { --editing-connection-tone: var(--tone-warn-fg); }
.editing-connection[data-tone="bad"] { --editing-connection-tone: var(--tone-bad-fg); }
.editing-connection[data-tone="info"] { --editing-connection-tone: var(--tone-info-fg); }

.editing-connection__detail {
  margin: 0;
  color: var(--fg2);
  max-inline-size: 60ch;
  overflow-wrap: anywhere;
}

/* ── Editing, Suggesting, Viewing ────────────────────────────────────────
   A native radio group (Forms::RadioGroupComponent, as chips); a role with one mode has a sentence instead. */
.editing-mode {
  min-inline-size: 0;
}

.editing-mode .field {
  margin: 0;
}

.editing-mode__only {
  margin: 0;
  color: var(--fg2);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

/* ── The live form ───────────────────────────────────────────────────────
   The header (presence, the connection, the mode, then the draft's own tools), the fields on their sheet, the panel beside them on a wide screen and
   under them on a phone, and the submit bar. On a wide screen in a browser the header sticks to the top, and the page's scroll padding keeps whatever has
   the focus clear of it (WCAG 2.4.11); in the native shells and on a phone it scrolls with the page. */
.editing-form {
  display: grid;
  gap: var(--space-4);
  min-inline-size: 0;
}

.editing-form__header {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  background: var(--surface-raised);
  box-shadow: var(--shadow-soft);
  min-inline-size: 0;
}

.editing-form__status {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--space-3) var(--space-5);
  min-inline-size: 0;
}

.editing-form__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
  min-inline-size: 0;
}

.editing-form__waiting,
.editing-form__full {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  font-size: var(--text-sm);
}

/* A change that would make the draft more than it can hold was not kept: the page's copy stays, read-only, until the person goes back (SD10). */
.editing-form__full > span {
  min-inline-size: 0;
  overflow-wrap: anywhere;
}

.editing-form__links ul {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: var(--text-sm);
}

.editing-form__links a {
  display: inline-flex;
  align-items: center;
  min-block-size: var(--density-chip);
}

.editing-form__body {
  display: grid;
  gap: var(--space-4);
  min-inline-size: 0;
}

.editing-form__fields {
  min-inline-size: 0;
}

.editing-form__panel {
  display: grid;
  align-content: start;
  gap: var(--space-4);
  min-inline-size: 0;
}

.editing-form__panel:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.editing-form__owner-only {
  margin: var(--space-1) 0 0;
  color: var(--fg2);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

.editing-form__submit {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* The submit sheet's frame (SD5): a block under the bar, and nothing at all until the sheet is in it. */
.editing-form__sheet {
  display: block;
  margin-block-start: var(--space-4);
}

.editing-form__sheet:empty {
  display: none;
}

@media screen and (min-width: 64rem) {
  .editing-form--with-panel .editing-form__body {
    grid-template-columns: minmax(0, 1fr) minmax(16rem, 22rem);
    align-items: start;
  }
}

@media screen and (min-width: 1080px) {
  body:not([data-native]) .editing-form__header {
    position: sticky;
    inset-block-start: var(--space-2);
    z-index: 20;
    background: color-mix(in srgb, var(--surface-raised) 94%, transparent);
    -webkit-backdrop-filter: saturate(1.2) blur(8px);
    backdrop-filter: saturate(1.2) blur(8px);
  }

  html:has(body:not([data-native]) .editing-form__header) {
    scroll-padding-block-start: 9rem;
  }
}

/* ── Words that are suggested, and words that changed ────────────────────
   An insertion is underlined and a deletion struck through, each in its own line color over its own fill, and each is <ins> or <del> with its meaning in
   words beside it, so neither is color alone. The text on them is the page's own (4.5:1 on both fills, in both modes). */
.editing-insertion,
.editing-deletion,
.editing-suggestion__words,
.editing-diff__added,
.editing-diff__removed {
  color: var(--fg1);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.2em;
  border-radius: var(--radius-sm);
  -webkit-box-decoration-break: clone;
  box-decoration-break: clone;
}

.editing-insertion,
ins.editing-suggestion__words,
.editing-diff__added {
  background: var(--editing-insertion-bg);
  text-decoration-line: underline;
  text-decoration-color: var(--editing-insertion-line);
}

.editing-deletion,
del.editing-suggestion__words,
.editing-diff__removed {
  background: var(--editing-deletion-bg);
  text-decoration-line: line-through;
  text-decoration-color: var(--editing-deletion-line);
}

/* ── Suggestions ─────────────────────────────────────────────────────────
   The list in the panel: who suggested what, in which question, and the buttons. Accept all, Reject all and the filter by author wait for the script. */
.editing-suggestions,
.editing-comments,
.editing-people,
.editing-versions,
.editing-compare {
  display: grid;
  gap: var(--density-block);
  min-inline-size: 0;
}

.editing-suggestions__head,
.editing-comments__head,
.editing-people__head,
.editing-versions__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-1) var(--space-3);
}

.editing-suggestions__title,
.editing-comments__title,
.editing-people__title,
.editing-versions__title,
.editing-compare__title,
.editing-restore__title,
.editing-submit__title {
  margin: 0;
  overflow-wrap: anywhere;
}

/* In the live form's panel the two lists are a column beside the fields, so their titles are a size down from a page's section. */
.editing-form__panel :is(.editing-suggestions__title, .editing-comments__title) {
  font-size: var(--text-lg);
}

.editing-suggestions__count,
.editing-comments__count,
.editing-people__count,
.editing-versions__count {
  margin: 0;
  color: var(--fg2);
  font-size: var(--text-sm);
}

.editing-suggestions__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--space-2) var(--space-4);
}

.editing-suggestions__filter {
  display: grid;
  gap: var(--space-1);
  min-inline-size: 0;
}

.editing-suggestions__all,
.editing-comments__nav,
.editing-suggestion__actions,
.editing-version__actions,
.editing-person__actions,
.editing-comments__new-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.editing-suggestions__none {
  margin: 0;
  color: var(--fg2);
  font-size: var(--text-sm);
}

.editing-suggestions__list,
.editing-comments__open,
.editing-versions__list,
.editing-people__list {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.editing-suggestion,
.editing-thread,
.editing-version > article {
  display: grid;
  gap: var(--space-2);
  min-inline-size: 0;
  padding: var(--space-3);
  border: 1px solid var(--rule);
  border-radius: var(--radius-md);
  background: var(--surface-raised);
}

.editing-suggestion__summary,
.editing-suggestion__text,
.editing-suggestion__field {
  margin: 0;
  overflow-wrap: anywhere;
}

.editing-suggestion__summary {
  font-size: var(--text-sm);
  font-weight: 600;
}

.editing-suggestion__field {
  color: var(--fg2);
  font-size: var(--text-sm);
}

/* ── Comments ────────────────────────────────────────────────────────────
   One thread: what it is on, the comment and its replies (one level deep, set in from the start), a reply box and Resolve. A resolved thread is quieter. */
.editing-thread[data-state="resolved"] {
  background: var(--surface-sunken);
}

.editing-thread__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
}

.editing-thread__title {
  margin: 0;
  font-size: var(--text-sm);
  font-weight: 600;
  overflow-wrap: anywhere;
}

.editing-thread__comments {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.editing-comment {
  display: grid;
  gap: var(--space-1);
  min-inline-size: 0;
}

.editing-comment--reply {
  padding-inline-start: var(--space-3);
  border-inline-start: 2px solid var(--rule-strong);
}

.editing-comment__by,
.editing-comment__body {
  margin: 0;
  overflow-wrap: anywhere;
}

.editing-comment__by {
  color: var(--fg2);
  font-size: var(--text-xs);
}

.editing-comment__body {
  white-space: pre-line;
}

.editing-thread__reply,
.editing-comments__new {
  display: grid;
  gap: var(--space-2);
  min-inline-size: 0;
}

.editing-thread__reply .field,
.editing-comments__new .field {
  margin: 0;
}

.editing-thread__reply > .btn {
  justify-self: start;
}

/* A reply is a line or two: its box starts smaller than a form's text box (7.5rem, 36-form-fields.css, which is linked after this file, so this rule says .field too) and grows by hand as any does. */
.editing-thread__reply .field textarea.field-control {
  min-block-size: 4rem;
}

.editing-thread__resolve {
  display: flex;
}

.editing-comments__detached,
.editing-comments__resolved {
  display: grid;
  gap: var(--space-2);
  min-inline-size: 0;
}

.editing-comments__subtitle {
  margin: 0;
  font-size: var(--text-base);
}

.editing-comments__lede,
.editing-comments__quote {
  margin: 0;
  color: var(--fg2);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

.editing-comments__resolved > summary {
  min-block-size: var(--density-chip);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

/* ── The people in a draft ───────────────────────────────────────────────
   Each person's face, name and role, and, for whoever may invite, a change of role and Remove; the invitation under them. */
.editing-person {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  min-inline-size: 0;
  padding-block: var(--space-2);
  border-block-end: 1px solid var(--rule);
}

.editing-person__words {
  flex: 1 1 12rem;
  min-inline-size: 0;
}

.editing-person__name,
.editing-person__role {
  margin: 0;
  overflow-wrap: anywhere;
}

.editing-person__name {
  font-weight: 600;
}

.editing-person__role {
  color: var(--fg2);
  font-size: var(--text-sm);
}

.editing-person__actions {
  align-items: end;
}

.editing-person__role-form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--space-2);
}

.editing-person__role-form .field {
  margin: 0;
}

.editing-people__invite {
  display: grid;
  gap: var(--space-3);
  min-inline-size: 0;
}

.editing-people__subtitle {
  margin: 0;
}

.editing-people__lede,
.editing-versions__lede,
.editing-compare__lede,
.editing-submit__lede,
.editing-submit__paused {
  margin: 0;
  color: var(--fg2);
  font-size: var(--text-sm);
  max-inline-size: 66ch;
  overflow-wrap: anywhere;
}

/* ── Versions ────────────────────────────────────────────────────────────
   The history, newest first: each version's title, when and by whom, who wrote since the one before, and Open, Compare and Restore. */
.editing-version__head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
}

.editing-version__title {
  margin: 0;
  font-size: var(--text-base);
  overflow-wrap: anywhere;
}

.editing-version__made,
.editing-version__by,
.editing-version__pending {
  margin: 0;
  color: var(--fg2);
  font-size: var(--text-sm);
  overflow-wrap: anywhere;
}

/* ── Comparing two versions ──────────────────────────────────────────────
   Each question that changed, with its words compared (the <ins> and <del> above) or what it was and what it is now; the rest folded into one line. */
.editing-compare__legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-3);
  margin: 0;
  font-size: var(--text-sm);
}

.editing-compare__fields {
  display: grid;
  gap: var(--space-3);
}

.editing-compare__field {
  display: grid;
  gap: var(--space-2);
  min-inline-size: 0;
  padding-block-end: var(--space-3);
  border-block-end: 1px solid var(--rule);
}

.editing-compare__question {
  margin: 0;
  font-size: var(--text-base);
  overflow-wrap: anywhere;
}

.editing-diff,
.editing-compare__formatting {
  margin: 0;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

.editing-compare__was-now {
  display: grid;
  gap: var(--space-2) var(--space-4);
  margin: 0;
  min-inline-size: 0;
}

@media (min-width: 40rem) {
  .editing-compare__was-now {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.editing-compare__was-now dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.editing-compare__label {
  margin: 0;
  color: var(--fg2);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.editing-compare__none {
  color: var(--fg2);
  font-style: italic;
}

.editing-compare__terms {
  margin: 0;
  padding-inline-start: var(--space-4);
}

.editing-compare__both,
.editing-compare__unchanged {
  display: grid;
  gap: var(--space-2);
}

.editing-compare__both > summary,
.editing-compare__unchanged > summary {
  min-block-size: var(--density-chip);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
}

/* ── The two sheets ──────────────────────────────────────────────────────
   Restoring a version, and the last look before submitting: what will happen, in a list of sentences, then the form. */
.editing-restore,
.editing-submit {
  display: grid;
  gap: var(--space-4);
  min-inline-size: 0;
}

.editing-restore__what {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding-inline-start: var(--space-5);
  max-inline-size: 66ch;
  overflow-wrap: anywhere;
}

.editing-restore__discarded {
  font-weight: 600;
}

.editing-submit__answers {
  display: grid;
  gap: var(--space-3);
  min-inline-size: 0;
}

.editing-submit__subtitle {
  margin: 0;
}

.editing-submit__cancel {
  display: flex;
}

/* The browser's `hidden` holds, whatever display a rule above gives these parts: they wait for the script. */
:is(.editing-form, .editing-suggestions, .editing-comments, .editing-connection, .editing-thread) [hidden] {
  display: none !important;
}
