/* A thread's mails (emails/_email, docs/planning/email-and-meetings.md and
   email-ux.md): each folded to a line — who, the first words, when — or open
   to its words, with the team's comments and a few lines between them
   (email_threads/_entries). The fold is an accordion (accordions.css): the
   <details> element's own state, its words swapped by it. */
@layer components {
  /* Hairlines between the thread's rows — a mail, a line, the fold that
     holds its middle. A comment stands apart in its tint, and the New line
     draws its own rule (dividers.css). */
  :is(.mails, .mails__fold) > :is(.mail, .mails__line, .mails__fold) + :is(.mail, .mails__line, .mails__fold) {
    border-block-start: var(--border);
  }

  .mail__head {
    display: flex;
    align-items: start;
    gap: var(--inline-space);
    padding-block: var(--block-space);
  }

  /* The head's words — who and to whom, and when — stand on the face's
     line: each set down by half of what its own line lacks of the face's
     height, the comment composer's seat (comments.css). Top-aligned alone,
     the time's smaller line stood above the name, and both above the
     levers. */
  .mail__line {
    padding-block-start: calc((var(--avatar-size, 1.75rem) - 1lh) / 2);
  }

  .mail__body {
    padding-block-end: var(--block-space);
  }

  /* An open mail's ⋯ (emails/_email): drawn inside the <summary>, every
     click on its menu would fold the mail, so it stands after it, on the
     seat the head keeps. */
  .mail__seat {
    inline-size: var(--btn-size, 1.75rem);
    block-size: var(--btn-size, 1.75rem);
  }

  .mail__menu {
    position: absolute;
    position-area: center;
  }

  /* A line between the mails — who joined, an invitation — and the row of
     the folded middle: the glyph stands in the faces' column. */
  .mails__line > .icon {
    inline-size: var(--avatar-size, 1.75rem);
  }

  /* The folded middle's row goes once it is open (email_threads/show). */
  .mails__fold[open] > summary {
    display: none;
  }

  /* A comment of the team's between the mails: the internal note's straw,
     every ink in it the tint's own (HANSHI, Comments). Its face in the
     mails' column (comments.css hangs it in the gutter), the tint reaching
     a space past the mails' edge. */
  :is(.mails, .mails__fold) > .comment {
    --thread-indent: calc(var(--avatar-size, 1.75rem) + var(--inline-space));
    --color-ink: var(--color-warning-ink);
    --color-ink-subtle: var(--color-warning-ink);
    --color-ink-faint: var(--color-warning-ink);
    --lexxy-color-ink: var(--color-warning-ink);
    --lexxy-color-link: var(--color-warning-ink);

    margin: var(--block-space-half) calc(-1 * var(--inline-space));
    padding: var(--block-space-half) var(--inline-space) var(--block-space-half) calc(var(--inline-space) + var(--thread-indent));
    border-radius: var(--border-radius);
    background-color: var(--color-highlight);
    color: var(--color-ink);

    & + .comment {
      border-block-start: none;
    }
  }

  /* A mail on its way (emails/_on_its_way): its words faded until it has
     gone; its head, which says when it goes, keeps full ink. */
  .mail--on-its-way .mail__body {
    opacity: 0.5;
  }

  /* An HTML mail, as its sender laid it out, in a frame of its own: as tall
     as its words once mail_frame_controller has measured them, a screenful
     until then. It paints its own light paper (EmailsHelper::FRAME_STYLE),
     as mail is drawn for light — or, a plain one, the page's. */
  .mail__frame {
    display: block;
    inline-size: 100%;
    block-size: 16rem;
    border: 0;
    border-radius: var(--border-radius);
  }

  /* A plain mail keeps its lines; its quoted history folds as the HTML's
     does, a fold like every other (accordions.css lists its summary). */
  .mail__text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;

    summary { color: var(--color-ink-faint); letter-spacing: .2em; }
  }

  .mail__files {
    display: flex;
    flex-wrap: wrap;
    gap: var(--inline-space-half);
    padding-block-end: var(--block-space);
  }

  /* Folded on a phone, a mail's line is its sender and its first words. */
  @container main (width < 35rem) {
    .mail__to {
      display: none;
    }
  }
}
