/*
 * An objective's Comments section (023): the form for a new comment, then
 * the comments newest first. Looks like the activity feed below it (an
 * author line, a hairline between entries) so the two read as one column;
 * the empty-state item hides itself as soon as a comment exists, including
 * one a turbo_stream prepends. Text is plain with its line breaks kept.
 */
@layer components {
  /*
   * A new comment, or the author's correction: the field and its button on
   * one line, as the task field above. The field grows with its text; an
   * error message takes a line of its own below.
   */
  .comment-form {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: var(--space-2);
    margin-block-end: var(--space-2);

    & textarea {
      flex: 1;
      max-inline-size: none;
      min-block-size: var(--control-height);
      padding: var(--space-2) var(--space-3);
      field-sizing: content;
      resize: none;
    }

    & .field_with_errors {
      display: contents;
    }

    & .field-error {
      flex-basis: 100%;
      order: 1;
    }
  }

  .comment-list {
    list-style: none;
    padding: 0;

    & > li {
      max-inline-size: none;
    }

    & > li + li {
      margin-block-start: 0;
    }
  }

  .comment-list__empty {
    color: var(--color-muted);

    &:not(:only-child) {
      display: none;
    }
  }

  .comment {
    padding-block: var(--space-3);
    border-block-end: var(--border);

    & > turbo-frame {
      display: grid;
      gap: var(--space-1);
    }

    & turbo-frame > * {
      margin: 0;
      max-inline-size: var(--width-reading);
    }
  }

  .comment__meta {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font: var(--text-small);
    color: var(--color-subtle);

    & > * + * {
      margin: 0;
    }

    & strong {
      color: var(--color-text);
    }
  }

  .comment__body {
    white-space: pre-line;
    overflow-wrap: anywhere;
  }

  /* Edit and Delete, at the end of the author line. */
  .comment__actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin-inline-start: auto;

    & form {
      margin: 0;
    }
  }

  /*
   * While its author edits it, the frame holds only the form. A colleague's
   * refresh may add the comment's lines back beside a form the author is
   * typing in (autosave#guard keeps the form); hide them until it is saved
   * or cancelled.
   */
  .comment turbo-frame:has(> .comment-form) > :not(.comment-form) {
    display: none;
  }
}
