/* ---------------------------------------------------------------------
   WhatsIQ — email reads like mail, not like chat
   ---------------------------------------------------------------------
   Scope: EVERY rule here is behind [data-wiq-mail], an attribute that
   wiq-tweaks.js puts on the chat pane only while an email conversation is
   open and takes off the moment a WhatsApp one is clicked. Nothing in this
   file can reach another channel.

   The rows are addressed through [data-wiq-mailrow], which the behaviour
   layer sets from the message records. The vendor tells inbound from
   outbound with an emotion class hash, and those move on a MUI bump; the
   data attribute does not.

   WHY THE SELECTORS ARE SO LONG
   whatsiq-theme.css section 9.4 styles the chat bubbles through

     main > .MuiBox-root > section:nth-of-type(2)
       > .MuiBox-root:nth-child(2) .MuiPaper-root.MuiPaper-rounded

   with !important on every declaration — max-width: min(70%, 460px)
   among them. A short selector like [data-wiq-mail] [data-wiq-mailrow] >
   .MuiPaper-root carries three class-column points against that rule's
   six, so !important does nothing and the card stays a 70% chat bubble.
   The rules below therefore repeat the theme's own path and add the mail
   attribute to it, which outranks it on the one pane that has it. Keep
   that shape if you add a rule; a short one will silently lose.
   --------------------------------------------------------------------- */

/* The reading pane. */
main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] > .MuiBox-root:nth-child(2) {
  background: var(--wiq-frame) !important;
}

/* A message is a full-width card, not a bubble parked on one side. */
main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(2) [data-wiq-mailrow] {
  justify-content: stretch !important;
  width: 100% !important;
  margin: 0 0 10px !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(2) [data-wiq-mailrow] > .MuiPaper-root.MuiPaper-rounded {
  max-width: none !important;
  width: 100% !important;
  box-sizing: border-box !important;
  background: var(--wiq-sheet) !important;
  border: 1px solid var(--wiq-border) !important;
  border-radius: var(--wiq-r-card) !important;
  box-shadow: none !important;
  padding: 13px 16px 9px !important;
}

/* Theirs carries the accent edge; ours is the quieter one. Colour is doing
   the job the left/right alignment used to do, at a tenth the noise. */
main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(2) [data-wiq-mailrow="in"] > .MuiPaper-root.MuiPaper-rounded {
  border-left: 3px solid var(--wiq-accent) !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(2) [data-wiq-mailrow="out"] > .MuiPaper-root.MuiPaper-rounded {
  background: var(--wiq-raised) !important;
  border-left: 3px solid var(--wiq-control) !important;
}

/* Mail is written in paragraphs. Keep them. */
main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(2) [data-wiq-mailrow] > .MuiPaper-root.MuiPaper-rounded
  > p.MuiTypography-root {
  font-family: var(--wiq-font) !important;
  font-size: 14px !important;
  line-height: 1.62 !important;
  color: var(--wiq-text) !important;
  white-space: pre-wrap !important;
  word-break: break-word !important;
}

/* A subject the vendor prints inside the card, when it is not a repeat of
   the thread header above it. */
main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(2) [data-wiq-mailrow] > .MuiPaper-root.MuiPaper-rounded
  > p.MuiTypography-root:first-of-type:not(:last-of-type) {
  font-family: var(--wiq-head) !important;
  font-size: 14.5px !important;
  font-weight: 600 !important;
  margin-bottom: 6px !important;
}

/* Who it is from, and when. */
main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(2) [data-wiq="mailhdr"] {
  font-family: var(--wiq-font) !important;
  font-size: 12.5px !important;
  font-weight: 600 !important;
  color: var(--wiq-text) !important;
  letter-spacing: 0.01em !important;
  padding-bottom: 8px !important;
  margin-bottom: 10px !important;
  border-bottom: 1px solid var(--wiq-rule) !important;
  white-space: pre-wrap !important;
}

/* A new subject starts a new thread. This is the ticket boundary. */
main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(2) [data-wiq="mailsubj"] {
  font-family: var(--wiq-head) !important;
  font-size: 12.5px !important;
  font-weight: 600 !important;
  color: var(--wiq-faint) !important;
  text-transform: uppercase !important;
  letter-spacing: 0.07em !important;
  margin: 20px 0 11px !important;
  padding-bottom: 7px !important;
  border-bottom: 1px solid var(--wiq-edge) !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(2) [data-wiq="mailsubj"]:first-child {
  margin-top: 2px !important;
}

/* The quoted history the vendor cuts off. */
main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(2) [data-wiq="mailmore"] {
  appearance: none !important;
  display: inline-block !important;
  margin: 11px 0 2px !important;
  padding: 4px 10px !important;
  font-family: var(--wiq-font) !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  color: var(--wiq-accent) !important;
  background: var(--wiq-accent-soft) !important;
  border: 0 !important;
  border-radius: var(--wiq-r-chip) !important;
  cursor: pointer !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(2) [data-wiq="mailmore"]:hover {
  filter: brightness(0.97) !important;
}

/* The time and the delivery tick become a footer, not a chat timestamp
   tucked under the last word. */
main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(2) [data-wiq-mailrow] > .MuiPaper-root.MuiPaper-rounded
  .MuiStack-root {
  justify-content: flex-start !important;
  margin-top: 11px !important;
  padding-top: 8px !important;
  border-top: 1px solid var(--wiq-rule) !important;
  opacity: 0.8 !important;
}

/* Composing: mail needs room, and the hint has to say what Enter does. */
main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(3) textarea {
  min-height: 104px !important;
  line-height: 1.6 !important;
}

/* --- the formatted composer (section 6c in wiq-tweaks.js) ------------
   The editor sits in the vendor's own send row, so the row has to stop
   centring its children or the send arrow floats beside a tall box. */
main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(3) .MuiBox-root:has(> [data-wiq="mailed"]) {
  align-items: flex-end !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailed"] {
  flex: 1 1 auto !important;
  min-width: 0 !important;
  border: 1px solid var(--wiq-control) !important;
  border-radius: var(--wiq-r-ctl) !important;
  background: var(--wiq-sheet) !important;
  overflow: hidden !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailed"]:focus-within {
  border-color: var(--wiq-accent) !important;
  box-shadow: 0 0 0 1px var(--wiq-accent) !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailbar"] {
  display: flex !important;
  align-items: center !important;
  gap: 2px !important;
  padding: 5px 6px !important;
  border-bottom: 1px solid var(--wiq-rule) !important;
  background: var(--wiq-raised) !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailbar"] button {
  appearance: none !important;
  min-width: 28px !important;
  height: 26px !important;
  padding: 0 7px !important;
  font-family: var(--wiq-font) !important;
  font-size: 12.5px !important;
  color: var(--wiq-nav-ink) !important;
  background: transparent !important;
  border: 0 !important;
  border-radius: var(--wiq-r-chip) !important;
  cursor: pointer !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailbar"] button:hover {
  background: var(--wiq-hover) !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailrt"] {
  min-height: 104px !important;
  max-height: 320px !important;
  overflow-y: auto !important;
  padding: 10px 12px !important;
  font-family: var(--wiq-font) !important;
  font-size: 14px !important;
  line-height: 1.6 !important;
  color: var(--wiq-text) !important;
  outline: none !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailrt"]:empty::before {
  content: attr(data-ph);
  color: var(--wiq-faint);
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailrt"] a {
  color: var(--wiq-accent) !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailrt"] ul,
main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailrt"] ol {
  margin: 6px 0 !important;
  padding-left: 22px !important;
}

/* --- Cc (section 6d in wiq-tweaks.js) --------------------------------
   Two separate things, both about recipients the vendor used to discard.

   In the card: who else was on the mail that arrived.
   Above the composer: who the reply will go to, which is editable,
   because a reply-all that happens silently is worse than none. */

/* the header gives up its rule when a Cc line follows it */
main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(2) [data-wiq="mailhdr"]:has(+ [data-wiq="mailcc"]) {
  padding-bottom: 2px !important;
  margin-bottom: 0 !important;
  border-bottom: 0 !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail]
  > .MuiBox-root:nth-child(2) [data-wiq="mailcc"] {
  font-family: var(--wiq-font) !important;
  font-size: 11.5px !important;
  font-weight: 500 !important;
  color: var(--wiq-faint) !important;
  padding-bottom: 8px !important;
  margin-bottom: 10px !important;
  border-bottom: 1px solid var(--wiq-rule) !important;
  word-break: break-word !important;
}

/* the editable row above the composer */
main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailccbar"] {
  display: flex !important;
  flex-wrap: wrap !important;
  align-items: center !important;
  gap: 6px !important;
  padding: 0 2px 8px !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailcclabel"] {
  font-family: var(--wiq-font) !important;
  font-size: 11.5px !important;
  font-weight: 600 !important;
  color: var(--wiq-faint) !important;
  letter-spacing: 0.04em !important;
  text-transform: uppercase !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailccchip"] {
  display: inline-flex !important;
  align-items: center !important;
  gap: 4px !important;
  max-width: 100% !important;
  padding: 2px 4px 2px 9px !important;
  border: 1px solid var(--wiq-rule) !important;
  border-radius: 999px !important;
  background: var(--wiq-frame) !important;
  font-family: var(--wiq-font) !important;
  font-size: 12px !important;
  color: var(--wiq-text) !important;
  word-break: break-all !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailccchip"] button {
  all: unset !important;
  cursor: pointer !important;
  width: 16px !important;
  height: 16px !important;
  display: grid !important;
  place-items: center !important;
  border-radius: 50% !important;
  color: var(--wiq-faint) !important;
  font-size: 14px !important;
  line-height: 1 !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailccchip"] button:hover {
  background: var(--wiq-rule) !important;
  color: var(--wiq-text) !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailccadd"] {
  flex: 1 1 140px !important;
  min-width: 120px !important;
  border: 0 !important;
  outline: none !important;
  background: transparent !important;
  font-family: var(--wiq-font) !important;
  font-size: 12px !important;
  color: var(--wiq-text) !important;
  padding: 3px 2px !important;
}

main > .MuiBox-root > section:nth-of-type(2)[data-wiq-mail] [data-wiq="mailccadd"]::placeholder {
  color: var(--wiq-faint) !important;
}
