/*
 * Reading pane and conversation view (js/mail-reader-thread.js, js/mail-reader-extras.js, js/mail-attachments.js).
 *
 * Linked from mail.html right after mail-enterprise-final.css. Several later sheets carry rules written with
 * !important and long selectors (gmail-parity-final.css, mail-gmail-enterprise-closeout.css), and the Mail frame
 * is narrow enough in the app shell to trigger their phone layouts. Every rule below therefore starts from
 * `html body.mail-body:not(#mail-ux-reader)`: the :not(#id) adds an id's worth of specificity, so these rules win
 * over those sheets by specificity without !important wherever the other side has none, and with !important
 * only where the other side uses it. Light theme only: the dark theme inverts the finished page.
 */

html body.mail-body.mail-simple-mode:not(#mail-ux-reader) {
  /* The body text of a message starts this far from the card edge (gmail-parity-final.css, .mail-message-body).
   * Attachments and the reply row use the same inset, so they line up with the text above them. */
  --mail-reader-inset: 64px;
  --mail-reader-end-space: 32px;
}

@media (max-width: 900px) {
  html body.mail-body.mail-simple-mode:not(#mail-ux-reader) {
    --mail-reader-inset: 14px;
  }
}

/* ---- The reading pane is its own scroll area, with room below the last message ----------------------------- */

html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-view-panel {
  overflow-y: auto;
  overscroll-behavior: contain;
  scroll-padding-block: 56px var(--mail-reader-end-space);
}

html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-thread-detail {
  padding-bottom: calc(var(--mail-reader-end-space) + env(safe-area-inset-bottom, 0px)) !important;
}

/* ---- Reply / Reply all / Forward after the last message ----------------------------------------------------- */

html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-thread-reply-row {
  display: flex !important;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 8px;
  padding: 0 var(--mail-reader-inset) !important;
}

html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-thread-reply-row > button {
  flex: 0 0 auto !important;
  width: auto !important;
  min-width: 96px;
  min-height: 36px;
  padding: 0 20px;
  border: 1px solid #dadce0;
  border-radius: 18px;
  background: #fff;
  box-shadow: none !important;
  color: #3c4043;
  font: 500 14px/1 Roboto, "Helvetica Neue", Arial, sans-serif;
  cursor: pointer;
}

html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-thread-reply-row > button:hover {
  background: #f6f8fc;
  border-color: #c4c7c5;
}

html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-thread-reply-row > button:focus-visible {
  outline: 2px solid #0b57d0;
  outline-offset: 2px;
}

@media (pointer: coarse) {
  html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-thread-reply-row > button {
    min-height: 44px;
  }
}

/* ---- One-line message header: sender, snippet, then date, star, reply and the menu --------------------------- */

@media (min-width: 480px) {
  html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-message-head {
    display: flex !important;
    flex-wrap: nowrap;
    align-items: center !important;
    gap: 12px !important;
  }

  html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-message-persona {
    flex: 1 1 0 !important;
    min-width: 0 !important;
  }

  html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-message-copy {
    flex: 1 1 0 !important;
    min-width: 0 !important;
  }

  html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-message-status {
    flex: 0 0 auto !important;
    display: flex !important;
    flex-wrap: nowrap !important;
    align-items: center !important;
    justify-content: flex-end !important;
    gap: 2px !important;
    width: auto !important;
    min-width: 0 !important;
    margin: 0 0 0 auto !important;
    padding: 0 !important;
    white-space: nowrap;
  }

  html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-message-status > .meta {
    margin-right: 6px;
    font-size: 12px;
    white-space: nowrap;
  }

  /* A collapsed message keeps the same actions as an open one. */
  html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-message-card:has(> [data-message-content-email-id][hidden]) .mail-message-quick-actions {
    display: flex !important;
  }

  html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-message-quick-actions {
    flex: 0 0 auto !important;
    flex-wrap: nowrap !important;
    gap: 0 !important;
    margin: 0 !important;
  }

  html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-message-status :is(.mail-message-quick-actions > button, .mail-message-more-actions > summary, .mail-message-collapse) {
    width: 32px !important;
    min-width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
    padding: 0 !important;
  }
}

@media (min-width: 480px) and (pointer: coarse) {
  html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-message-status :is(.mail-message-quick-actions > button, .mail-message-more-actions > summary, .mail-message-collapse) {
    width: 44px !important;
    min-width: 44px !important;
    height: 44px !important;
    min-height: 44px !important;
  }
}

/* ---- Attachments line up with the message text --------------------------------------------------------------- */

html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-message-card .mail-attachments {
  padding-inline: var(--mail-reader-inset) !important;
  box-sizing: border-box;
}

/* ---- Attachment thumbnails: a file-type placeholder until the picture is there, and after it fails ----------- */

html body.mail-body:not(#mail-ux-reader) .mail-attachments .mail-attachment-thumb {
  position: relative;
  overflow: hidden;
  background: #f1f3f4;
}

html body.mail-body:not(#mail-ux-reader) .mail-attachments .mail-attachment-thumb img {
  position: absolute;
  inset: 0;
  z-index: 1;
}

html body.mail-body:not(#mail-ux-reader) .mail-attachments .mail-attachment-placeholder {
  position: absolute;
  inset: 0;
  margin: auto;
}

html body.mail-body:not(#mail-ux-reader) .mail-attachments .mail-attachment-thumb.is-loaded .mail-attachment-placeholder,
html body.mail-body:not(#mail-ux-reader) .mail-attachments .mail-attachment-thumb.is-failed img {
  visibility: hidden;
}

/* A PDF has no picture to draw in the browser, so its tile shows a page: white sheet, ruled lines, type badge. */
html body.mail-body:not(#mail-ux-reader) .mail-attachments .mail-attachment-glyph.is-pdf {
  width: 52px;
  height: 64px;
  border: 1px solid #dadce0;
  border-radius: 3px;
  background:
    linear-gradient(#fff, #fff) padding-box,
    repeating-linear-gradient(#fff 0 5px, #e8eaed 5px 6px);
  box-shadow: 0 1px 2px rgba(60, 64, 67, .2);
}

html body.mail-body:not(#mail-ux-reader) .mail-attachments .mail-attachment-glyph.is-pdf svg {
  opacity: 0;
}

html body.mail-body:not(#mail-ux-reader) .mail-attachments .mail-attachment-glyph.is-pdf::before {
  content: "";
  position: absolute;
  inset: 8px 8px 22px;
  background: repeating-linear-gradient(#bdc1c6 0 2px, transparent 2px 6px);
}

html body.mail-body:not(#mail-ux-reader) .mail-attachments .mail-attachment-glyph.is-pdf b {
  bottom: 5px;
  padding: 2px 5px;
  font-size: 10px;
}

/* The hover layer shades the tile instead of hiding it, so the thumbnail stays readable. */
html body.mail-body:not(#mail-ux-reader) .mail-attachments .mail-attachment-hover {
  z-index: 2;
  background: linear-gradient(rgba(32, 33, 36, .72), rgba(32, 33, 36, .12) 70%, rgba(32, 33, 36, .32));
}

html body.mail-body:not(#mail-ux-reader) .mail-attachments .attachment-card-actions.mail-attachment-tile-actions {
  z-index: 3;
}

/* ---- Thread toolbar: the same icon buttons as the list's bulk toolbar, plus Snooze, Move to, Labels and "n of N" - */

html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-reader-action-group > :nth-child(1) { order: 1; }
html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-reader-action-group > :nth-child(2) { order: 2; }
html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-reader-action-group > :nth-child(3) { order: 3; }
html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-reader-action-group > .mail-reader-action-divider { order: 4; }
html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-reader-action-group > [data-mark-unread-email-id] { order: 5; }
html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-reader-action-group > .mail-reader-toolbar-snooze { order: 6; }
html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-reader-action-group > .mail-reader-move-shell { order: 7; }
html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-reader-action-group > .mail-reader-toolbar-labels { order: 8; }
html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-reader-action-group > .mail-reader-more-menu { order: 9; }

html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-reader-shell:not(.is-split-companion) .mail-reader-primary-actions .mail-reader-move-shell {
  display: inline-flex !important;
}

/* Move to is as large as the buttons beside it when they are the touch-sized ones. */
@media (min-width: 560px) and (max-width: 900px) {
  html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-reader-shell:not(.is-split-companion) .mail-reader-primary-actions .mail-reader-move-shell {
    width: 44px !important;
    height: 44px !important;
  }
}

html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-reader-shell:not(.is-split-companion) .mail-reader-primary-actions .mail-reader-position {
  display: inline-block !important;
  margin-right: 6px;
  color: #5f6368;
  font-size: 12px !important;
  white-space: nowrap;
}

/* Snooze and Labels go when the toolbar itself is too narrow for them (a window, or the reading pane beside the
 * list); the more menu has both in every width. The toolbar's own width decides, not the window's. */
html body.mail-body.mail-simple-mode:not(#mail-ux-reader) #mail-reader-primary-actions-slot {
  container: mail-reader-toolbar / inline-size;
}

@container mail-reader-toolbar (max-width: 559px) {
  html body.mail-body.mail-simple-mode:not(#mail-ux-reader) .mail-reader-action-group > :is(.mail-reader-toolbar-snooze, .mail-reader-toolbar-labels) {
    display: none !important;
  }
}
