/* pages/mail.css — /mail/ (SPEC §5.2).
 *
 * The page on the foundation's components: the mailbox chips are filter chips
 * (.m3-chip--filter) in the fixed top (.page-top), Inbox / Sent is a
 * connected button group, each message is a three-line list item
 * (.m3-list-item--three), its actions are S standard icon buttons
 * (.m3-icon-btn), and the record head is the shell's sticky head
 * (§4.7). This file holds only what is Mail's own: the row's grid, the unread
 * weight, the overlaid actions and their touch reveal, the gone row, the body
 * frame, and the compose form's measure.
 *
 * MONOCHROME (answer 1): selection is the grey step (the m3 components do
 * that). Blue appears on this page only as the unread COUNT's text (D8), the
 * focus ring and links. 700 marks unread and nothing else (K53).
 *
 * PAGE-SCOPE RULE (§1.1, test_design check 9): every selector starts with a
 * class this file owns — `.tiles`, `.mailtile*`, `.maillist*`, `.boxtab`,
 * `.messages*`, `.message*`, `.msgact`, `.gone__*`, `.mailbody` — or with
 * [data-page="mail"]. All eleven page files load on every page.
 */

/* ═══════════════════════════════════════════════════════ THE FIXED TOP ══
   The mailbox chips ride the .page-top (interim, Q1 answered "on the
   card"). ONE row at every width: it scrolls sideways under the shell's 40px
   SIDEWAYS fade (.tiles is in app.css's list) instead of wrapping into three
   rows on a phone. Its inline padding (16) holds the end chips' 8px insets
   and puts the first chip's visible edge on the same line as Inbox / Sent and
   the list's text below. */
[data-page="mail"] .tiles {          /* scoped: Finance's account cards are a .tiles row too */
  flex: 1 1 100%;
  min-width: 0;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 0 16px;
}
[data-page="mail"] .tiles[hidden] { display: none; }
/* The unread count: accent TEXT, never a fill (D8). The chip's own gap is 8;
   the count sits 4 from its label, as a number after a word does. */
.mailtile__count {
  margin-inline-start: -4px;
  color: var(--app-color-accent);
  font-style: normal;
  font-size: var(--md-sys-typescale-label-large-size);
  line-height: var(--md-sys-typescale-label-large-line-height);
  font-weight: var(--md-sys-typescale-emphasized-label-large-weight);
  font-variation-settings: "ROND" var(--md-sys-typescale-emphasized-rond);
  font-variant-numeric: tabular-nums;
}
/* The head is the fixed top's only content, so it keeps no margin of its own:
   the chips' visible shapes sit 24 from the top and 24 from the top's foot. */
[data-page="mail"] .page-top > .head { margin-bottom: 0; }
/* In reading mode (<=839px) the chips give their room to the record. */
[data-page="mail"] .page-top:is(.content.is-reading *) { display: none; }
[data-page="mail"] .page-top:is(.content.is-reading *) ~ .split { margin-top: 0; }
/* ...but the pane keeps its top padding (§4.6). app.css zeroes the padding of
   a pane that has a .page-top, because the top brings its own. With the top
   gone the pane takes the 16px back, so Back sits where it does on every other
   page (y 80 on a phone, not 64). */
[data-page="mail"]:is(.content.is-reading .pane) { padding-top: var(--app-viewpad); }
/* The same three for a record read in a half of a split (app.css, READING
   MODE), where the state is the PANE's: the other half may be showing Mail's
   list, or another page's fixed top, and must keep it. */
[data-page="mail"]:is(.content.is-split .pane.is-reading) .page-top { display: none; }
[data-page="mail"]:is(.content.is-split .pane.is-reading) .page-top ~ .split { margin-top: 0; }
[data-page="mail"]:is(.content.is-split .pane.is-reading) { padding-top: var(--app-viewpad); }

/* ════════════════════════════════════════════════════════════ THE LIST ══
   ⚠️ .maillist sits BETWEEN .split__list and the scroller, so it is itself
   a flex column that fills — otherwise .messages grows past the column and
   nothing scrolls (§4.7, build-12). */
.maillist { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.maillist[hidden] { display: none; }
/* The list's top row: Inbox / Sent at the start, Compose at the end — the
   edge the record pane opens beside. The row keeps the group's old insets
   (16 in, 8 under); the icon button's 48px box brings its own 4px. */
.maillist__top {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0 4px 8px 16px;
}
.maillist__top[hidden] { display: none; }
/* Inbox / Sent: a connected button group, S (§3.5) — the m3 rules draw it. */
.maillist__boxes { flex: none; }
.maillist__compose { flex: none; }

/* The scroller: a standard list (.m3-list) and a VERTICAL fade scroller (it
   is in app.css's list). */
.messages { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }

/* SEARCH. The bar is the shared .split__search (m3.css, §3.8) on the card at
   the top of the list column (Q1); only the two lines around its results are
   Mail's. The note heads GMAIL's answer, so a short list is not taken for the
   index's — body-small, on-surface-variant, on the rows' 16px text edge. The
   foot holds the text button that asks Gmail: its 12px padding plus 4 puts
   the icon on that same edge. */
.maillist__note {
  padding: 4px 16px 8px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-small-size);
  line-height: var(--md-sys-typescale-body-small-line-height);
  font-weight: var(--md-sys-typescale-body-small-weight);
}
.maillist__more { padding: 8px 4px; }

/* ⚠️ THE ROW IS A POSITIONED <li>, NOT THE OPEN BUTTON BY ITSELF.
   A star nested inside the open <button> would be a button inside a button —
   invalid, and browsers resolve it by dropping the inner one, so the control
   renders and never clicks. The actions are the button's SIBLINGS, laid OVER
   its trailing area (below), so they reserve no width. */
.messages__row { position: relative; }

/* The open control: a three-line list item (88). The time takes the top
   right by grid-area, whatever its place in the DOM (it used to land under
   the snippet). Text colours read the item's own --_head / --_sup, so the
   current-row marker (aria-current, §4.7) recolours them with the shape. */
.message {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "who time" "subject subject" "snippet snippet";
  column-gap: 12px;
  align-items: start;
}
.message__who {
  grid-area: who;
  min-width: 0;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  color: var(--_head);
  font-size: var(--md-sys-typescale-body-large-size);
  line-height: var(--md-sys-typescale-body-large-line-height);
  font-weight: var(--_head-w);
  font-variation-settings: "ROND" var(--_head-rond);
}
.message__subject {
  grid-area: subject;
  min-width: 0;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  color: var(--_head);
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line-height);
  font-weight: var(--md-sys-typescale-body-medium-weight);
}
.message__snippet {
  grid-area: snippet;
  min-width: 0;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
  color: var(--_sup);
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line-height);
  font-weight: var(--md-sys-typescale-body-medium-weight);
}
.message time {
  grid-area: time;
  align-self: start;
  padding-top: 4px;
  white-space: nowrap;
  color: var(--_sup);
  font-size: var(--md-sys-typescale-label-small-size);
  line-height: var(--md-sys-typescale-label-small-line-height);
  font-weight: var(--md-sys-typescale-label-small-weight);
  font-variant-numeric: tabular-nums;
}
/* UNREAD: weight 700 + ROND 100, the one state that weight marks (K53, D8),
   so it never reads as a selection (600) or as <strong>. */
.message.is-unread .message__who {
  font-size: var(--md-sys-typescale-title-medium-size);
  line-height: var(--md-sys-typescale-title-medium-line-height);
  font-weight: var(--md-ref-typeface-weight-bold);
  font-variation-settings: "ROND" var(--md-sys-typescale-emphasized-rond);
}
.message.is-unread .message__subject {
  font-weight: var(--md-ref-typeface-weight-bold);
  font-variation-settings: "ROND" var(--md-sys-typescale-emphasized-rond);
}
.message.is-unread time { color: var(--_head); }

/* The ROW is what is hovered, not just the button: the pointer travelling onto
   the actions (which overlay the button) must not drop the row's layer. */
@media (hover: hover) {
  .messages__row:hover > .message {
    --_state: var(--md-sys-state-hover-state-layer-opacity);
    --_r: var(--md-sys-shape-corner-medium);
  }
}

/* ═════════════════════════════════════════════════════ THE ROW ACTIONS ══
   S standard icon buttons (.m3-icon-btn: 40 visual, 48 box, icon 24, FILL 0
   at rest). They OVERLAY the row's trailing area and reserve no width (they
   used to take 122px of a 320px column at opacity 0, and were still
   hit-testable there). Hidden until the row is hovered or a KEYBOARD focus is
   in it (:has(:focus-visible) — not :focus-within, which a mouse click also
   sets, and which left the clicked row covered after the pointer had gone).

   ⚠️ THE COVER SPANS THE WHOLE ROW HEIGHT. Revealed, the group is painted in
   exactly the row's own colour (its ground and state layer, below) from the
   row's top to its bottom, with a 24px fade in front of it, so it hides the
   ENDS of all three lines. A 48px pill centred in the 88px row cut straight
   through the sender's and the snippet's glyphs — half-letters, read as a
   rendering bug. The date gives way to it (Gmail swaps the date for the
   actions). The star sits LAST (in the DOM, so the keyboard meets it where the
   eye does), so a starred row's star stays put when the others appear. */
.messages__row {
  /* The cover's colour, kept in step with what .message paints: the list's
     ground, plus the row's state layer. */
  --_cover-ground: var(--md-sys-color-surface-container-low);
  --_cover-ink: var(--md-sys-color-on-surface);
  --_cover-state: 0%;
  --_cover-r: var(--md-sys-shape-corner-extra-small);
}
@media (hover: hover) {
  .messages__row:hover {
    --_cover-state: var(--md-sys-state-hover-state-layer-opacity);
    --_cover-r: var(--md-sys-shape-corner-medium);
  }
}
.messages__row:has(> .message:focus-visible) {
  --_cover-state: var(--md-sys-state-focus-state-layer-opacity);
  --_cover-r: var(--md-sys-shape-corner-large);
}
.messages__row:has(> .message[aria-current="true"]) {
  --_cover-ground: var(--md-sys-color-secondary-container);
  --_cover-ink: var(--md-sys-color-on-secondary-container);
  --_cover-r: var(--md-sys-shape-corner-large);
}
/* ⚠️ HIDDEN BY OPACITY, NEVER BY visibility. A visibility:hidden button cannot
   take focus, and after a swap htmx gives focus back by CALLING focus() on the
   new control with the same id — on a hidden one that silently fails and
   focus falls to BODY. So the group is always "visible", the buttons are
   transparent and let the pointer through (the old opacity-0 buttons were
   still hit-testable; pointer-events closes that), and the group itself never
   takes the pointer — a click on the cover's empty part still opens the row. */
.message__actions {
  --_cover: color-mix(in srgb, var(--_cover-ink) var(--_cover-state), var(--_cover-ground));
  position: absolute;
  inset-block: 0;
  inset-inline-end: 0;
  display: flex;
  align-items: center;
  padding-inline: 4px 12px;
  border-radius: 0 var(--_cover-r) var(--_cover-r) 0;
  background-color: transparent;
  pointer-events: none;
}
.message__actions[hidden] { display: none; }
/* The fade in front of the cover: line-ends dissolve instead of stopping at
   a hard edge. */
.message__actions::before {
  content: "";
  position: absolute;
  inset-block: 0;
  inset-inline-end: 100%;
  width: 24px;
  background: linear-gradient(to right, transparent, var(--_cover));
  opacity: 0;
}
.msgact { opacity: 0; pointer-events: none; }
.messages__row:is(:hover, :has(:focus-visible)) .message time { visibility: hidden; }
.messages__row:is(:hover, :has(:focus-visible)) .message__actions { background-color: var(--_cover); }
.messages__row:is(:hover, :has(:focus-visible)) .message__actions::before { opacity: 1; }
.messages__row:is(:hover, :has(:focus-visible)) .msgact { opacity: 1; pointer-events: auto; }
/* A starred message says so whether or not the pointer is near it: the star
   is a toggle (aria-pressed: FILL 1 and on-surface, from .m3-icon-btn), and
   the text of its row keeps clear of it. */
.msgact[aria-pressed="true"] { opacity: 1; pointer-events: auto; }
.messages__row:has(.msgact[aria-pressed="true"]) :is(.message__subject, .message__snippet) { padding-inline-end: 48px; }
@media (prefers-reduced-motion: no-preference) {
  .message__actions {
    transition: background-color var(--md-sys-motion-spring-fast-effects-duration) var(--md-sys-motion-spring-fast-effects);
  }
  .msgact {
    transition-property: border-radius, background-color, color, box-shadow, opacity;
    transition-duration:
      var(--md-sys-motion-spring-default-effects-duration), var(--md-sys-motion-spring-fast-effects-duration),
      var(--md-sys-motion-spring-fast-effects-duration), var(--md-sys-motion-spring-fast-effects-duration),
      var(--md-sys-motion-spring-fast-effects-duration);
    transition-timing-function:
      var(--md-sys-motion-spring-default-effects), var(--md-sys-motion-spring-fast-effects),
      var(--md-sys-motion-spring-fast-effects), var(--md-sys-motion-spring-fast-effects),
      var(--md-sys-motion-spring-fast-effects);
  }
}
/* TOUCH (K16): there is no hover, so Star and Archive are always there, in
   the row's trailing area under the time, with no cover; Move to bin and Mark
   read/unread live in the open record's head (_detail_actions.html). The two
   text lines they sit beside stop short of them (two 40px shapes + insets). */
@media (hover: none), (pointer: coarse) {
  .messages__row .message__actions,
  .messages__row:is(:hover, :has(:focus-visible)) .message__actions {
    inset-block: auto 4px;
    padding-inline: 0 8px;
    background-color: transparent;
  }
  .messages__row .message__actions::before,
  .messages__row:is(:hover, :has(:focus-visible)) .message__actions::before { display: none; }
  .messages__row .msgact { opacity: 1; pointer-events: auto; }
  .messages__row:is(:hover, :has(:focus-visible)) .message time { visibility: visible; }
  .messages__row .msgact:is(:nth-child(2), :nth-child(3)) { display: none; }
  .messages__row :is(.message__subject, .message__snippet),
  .messages__row:has(.msgact[aria-pressed="true"]) :is(.message__subject, .message__snippet) { padding-inline-end: 88px; }
}

/* ═══════════════════════════════════════════════════════ THE GONE ROW ══
   A message just archived or binned, holding its own undo in place (K1:
   a delete never asks). A one-line item (56); Undo is a text button. */
.messages > .messages__row--gone {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--app-list-h-1);
  padding: 4px 8px 4px 16px;
  box-sizing: border-box;
}
.gone__text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.gone__text b {
  color: var(--md-sys-color-on-surface);
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line-height);
  font-weight: var(--md-sys-typescale-emphasized-body-medium-weight);
}
.gone__text em {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--md-sys-color-on-surface-variant);
  font-style: normal;
  font-size: var(--md-sys-typescale-body-small-size);
  line-height: var(--md-sys-typescale-body-small-line-height);
}
.gone__undo { flex: none; }

/* ═══════════════════════════════════════════════════════════ THE RECORD ══
   The head is the shell's sticky head (§4.7); its actions are the last
   row of it (D16: the record's actions sit in its head), so Reply, Archive,
   bin and read/unread stay in reach however long the mail. */
[data-page="mail"] .card-detail__head > .card-detail__actions { margin-top: 8px; gap: 8px; }
/* What an Archive / Move to bin pressed HERE did, beside its Undo — on a
   phone the list (and the gone row) is hidden while the record is read. */
.message__status {
  margin: 0 0 0 8px;
  color: var(--md-sys-color-on-surface-variant);
  font-size: var(--md-sys-typescale-body-medium-size);
  line-height: var(--md-sys-typescale-body-medium-line-height);
  font-weight: var(--md-sys-typescale-body-medium-weight);
}
.message__status[hidden] { display: none; }
/* The body fills what the record leaves of the reading region, so a short
   mail does not float in a 420px box with the region empty below it. A frame
   cannot be measured from here (it is sandboxed, no same-origin), so a long
   mail scrolls inside it. */
[data-page="mail"] .card-detail:has(> .mailbody) { min-height: 100%; }
/* In reading mode the shell's Back (40 + 8) sits above the record. */
@media (max-width: 839px) {
  [data-page="mail"] .reading__back ~ .card-detail:has(> .mailbody) { min-height: calc(100% - 48px); }
}
[data-page="mail"] .reading__back:where(.content.is-split *) ~ .card-detail:has(> .mailbody) { min-height: calc(100% - 48px); }   /* …and in a half of a split */
.mailbody {
  display: block;
  flex: 1 0 auto;
  width: 100%;
  min-height: 420px;
  border: 0;
  border-radius: var(--md-sys-shape-corner-medium);
  margin: 0;
  background: var(--md-sys-color-surface-container-low);
  color-scheme: dark;
}
.mailbody[hidden] { display: none; }
/* With the reading region (>=840px) the detail is padded 24 and the head's
   text sits at 24; the dark sheet insets its text 16 (views._frame), so the
   frame lets out 16 into the padding and its text lines up with the head's.
   (A white sheet then shows 8px of well around its paper.) */
@media (min-width: 840px) {
  .mailbody { width: calc(100% + 32px); margin-inline: -16px; }
}

/* Compose / reply: M3 filled fields (the .fieldgrid__row alias, §3.7) at a
   720px measure; the message field is tall. The head is not capped: as a
   reply it is the record's sticky head and spans the region. */
[data-page="mail"] form.card-detail > :not(.card-detail__head) { max-inline-size: 720px; }
[data-page="mail"] form.card-detail .fieldgrid__row--tall textarea { min-height: 240px; }
/* The confirming press ends the row, as on Calendar and Tasks (§5.5): the
   markup puts Cancel first and Save draft last, and the row aligns to the end
   of the 720 measure. (A direct child of the form, so the record head's own
   action row above is untouched.) */
[data-page="mail"] form.card-detail > .card-detail__actions { justify-content: flex-end; }
