/*
 * The inbox (AB#314): the conversation list, the thread, the composer and notes. Loaded after maluce-pages.css, tokens
 * only, no color literals (a test enforces it). Two panes on a desktop; on a phone one at a time.
 *
 * Text colors here are ink (primary) and ink-secondary. ink-muted is not used: the guide verified it against the
 * page surfaces, not against surface-hover, which a selected row and an outbound bubble sit on.
 * The one hand-tuned radius is the message bubble's 11px, which the brand book allows "only on the bubble".
 */

.ml-inbox {
  display: flex;
  height: 100%;
  min-height: 0;
  background: var(--surface-page);
}

/* ---- Conversation list ---- */
.ml-inbox__list {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: 22rem;
  min-height: 0;
  border-right: 1px solid var(--border);
}

.ml-inbox__list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.ml-inbox__list-header h2,
.ml-thread-header h2,
.ml-inbox__compose h2 {
  margin: 0;
  color: var(--ink);
}

.ml-inbox__filters {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.ml-inbox__filters .ml-field {
  max-width: none;
}

.ml-inbox__filters button {
  align-self: flex-start;
}

.ml-inbox__pills {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

/* Selected is a fill AND heavier text, never color alone. Control edge uses border-strong (the guide's rule). */
.ml-inbox__pill {
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: var(--space-1) var(--space-3);
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--ink-secondary);
  cursor: pointer;
}

.ml-inbox__pill:hover {
  background: var(--surface-hover);
}

.ml-inbox__pill[aria-pressed="true"] {
  background: var(--brand-fill);
  border-color: var(--brand-fill);
  color: var(--on-brand);
  font-weight: 700;
}

.ml-inbox__notice {
  padding: var(--space-3) var(--space-4) 0;
}

.ml-inbox__list-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.ml-inbox__loading {
  margin: 0;
  padding: var(--space-4);
  color: var(--ink-secondary);
}

/* The guide's empty state pads for a full page; in a narrow pane it would push everything off screen. */
.ml-inbox__list .ml-empty {
  padding: var(--space-8) var(--space-4);
}

.ml-conversation {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3) var(--space-4);
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.ml-conversation:hover {
  background: var(--surface-100);
}

/* The open conversation: a lighter fill, a heavier name and aria-current, so it is never marked by color alone. */
.ml-conversation[aria-current="true"] {
  background: var(--surface-hover);
}

.ml-conversation[aria-current="true"] .ml-conversation__name {
  font-weight: 700;
}

.ml-conversation__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-1);
  min-width: 0;
}

.ml-conversation__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ml-conversation__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  color: var(--ink-secondary);
}

/* ---- Main pane ---- */
.ml-inbox__main {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.ml-inbox__empty {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: center;
}

.ml-inbox__compose {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  max-width: 36rem;
  padding: var(--space-6);
  overflow-y: auto;
}

.ml-inbox__compose .ml-field {
  max-width: none;
}

/* Only shown on a phone, where the list and the pane are never visible together. */
.ml-inbox__back {
  display: none;
  align-self: flex-start;
}

.ml-thread-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3) var(--space-6);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.ml-thread-header__who {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.ml-thread-header__name {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ml-thread-header__name .mono-md {
  color: var(--ink-secondary);
}

.ml-thread-header__controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: var(--space-3);
}

.ml-thread-header__controls .ml-field {
  max-width: none;
  gap: var(--space-1);
}

/* ---- Notes ---- */
.ml-notes {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  max-height: 16rem;
  padding: var(--space-3) var(--space-4);
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
  background: var(--surface-100);
}

.ml-notes .ml-empty {
  padding: var(--space-4);
}

.ml-notes .ml-field {
  max-width: none;
}

.ml-notes__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.ml-notes__meta {
  color: var(--ink-secondary);
}

.ml-notes__body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.ml-participant {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

/* ---- Thread ---- */
.ml-messages {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-4);
  min-height: 0;
  padding: var(--space-4) var(--space-6);
  overflow-y: auto;
}

.ml-message {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-1);
  max-width: 70%;
}

.ml-message--outbound {
  align-self: flex-end;
  align-items: flex-end;
}

/* Which side a message is on, who it is from (the meta line) and its delivery state are three separate signals. */
.ml-bubble {
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-100);
  color: var(--ink);
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.ml-message--outbound .ml-bubble {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.ml-bubble--locked {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  white-space: normal;
}

.ml-message__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-1) var(--space-2);
  color: var(--ink-secondary);
}

/* ---- Composer ---- */
.ml-composer {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
  background: var(--surface-header);
}

.ml-composer .ml-field {
  max-width: none;
}

/* ---- Attachment control (shared by both composers) ---- */
.ml-attachment {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
}

.ml-attachment .ml-banner {
  flex-basis: 100%;
}

.ml-attach:focus-within {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.ml-attachment__status {
  color: var(--ink-secondary);
}

.ml-attachment__chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

/* Feedback banners inside the panes sit flush with the pane's edges. */
.ml-inbox .ml-banner {
  align-items: center;
}

.ml-inbox .ml-feedback-content {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-4);
}

/* ---- Phone: one pane at a time ---- */
@media (max-width: 767px) {
  .ml-inbox__list {
    width: 100%;
    border-right: 0;
  }

  .ml-inbox__main {
    display: none;
  }

  .ml-inbox--detail .ml-inbox__list {
    display: none;
  }

  .ml-inbox--detail .ml-inbox__main {
    display: flex;
  }

  .ml-inbox__back {
    display: inline-flex;
    margin: var(--space-3) var(--space-4) 0;
  }

  .ml-thread-header {
    padding-top: 0;
  }

  .ml-inbox__compose {
    padding: var(--space-4);
  }

  .ml-message {
    max-width: 88%;
  }

  .ml-messages {
    padding: var(--space-4);
  }
}

/* ---- Saved reply picker (AB#276) ---- */
.ml-saved-replies {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.ml-saved-replies > .ml-btn {
  align-self: flex-start;
}

.ml-saved-replies__panel {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  max-height: 16rem;
  padding: var(--space-3);
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-100);
}

.ml-saved-replies__panel .ml-field {
  max-width: none;
}

.ml-saved-replies__list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin: 0;
  padding: 0;
  list-style: none;
}

.ml-saved-reply {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.ml-saved-reply:hover {
  background: var(--surface-hover);
}

.ml-saved-reply:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* Matching contacts under the New message "To" field. Each row reuses the saved reply row's look. */
.ml-contact-suggest {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  max-width: 360px;
  margin: 0;
  padding: var(--space-2);
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-100);
}

.ml-saved-reply__text {
  color: var(--ink-secondary);
  overflow-wrap: anywhere;
}

/* ---- System lines in a thread (AB#266, AB#302): who did what, between the messages ---- */
.ml-system-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  margin: var(--space-2) 0;
  padding: var(--space-1) var(--space-3);
  color: var(--ink-secondary);
  text-align: center;
}

/* AB#342: the "send later" panel under the composer. Tokens only. */
.ml-schedule {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

/* AB#261: an unread conversation is heavier text AND a dot AND hidden "(unread)" text for a screen reader, never color alone. */
.ml-conversation--unread .ml-conversation__name {
  font-weight: 700;
}

.ml-conversation__unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
  flex: none;
}

/* AB#264: the @ picker under the note box. A plain list of real buttons, so the keyboard reaches every name. */
.ml-mentions {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: var(--space-1);
  list-style: none;
  background: var(--surface-100);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}

.ml-mentions__option {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.ml-mentions__option:hover,
.ml-mentions__option:focus-visible {
  background: var(--surface-hover);
}

/* AB#260: the inbox switcher above the search box. */
.ml-inbox__switcher {
  padding: 0 var(--space-4) var(--space-2);
}

/* AB#340, AB#341: the thread body is the positioned parent of the flyout; the composer row, the "+" menu and the saved-reply popover. Tokens only. */
.ml-thread-body {
  position: relative;
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}

.ml-flyout {
  position: absolute;
  inset: 0 0 0 auto;
  z-index: 20;
  display: flex;
  flex-direction: column;
  width: min(26rem, 100%);
  border-left: 1px solid var(--border-strong);
  background: var(--surface-100);
  box-shadow: var(--shadow);
  animation: ml-flyout-in 160ms ease-out;
}

.ml-flyout:focus {
  outline: none;
}

.ml-flyout__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
}

.ml-flyout__body {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
}

/* The People and Notes sections were inline panels; inside the flyout they lose their own frame and height cap. */
.ml-flyout .ml-notes {
  max-height: none;
  border-bottom: 0;
  background: transparent;
  overflow-y: visible;
}

@keyframes ml-flyout-in {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .ml-flyout { animation: none; }
}

/* The composer: [+] [message box] [Send] on one row, a caption underneath. The box starts two rows tall and grows as you type. */
.ml-composer {
  position: relative;
  gap: var(--space-2);
}

.ml-composer__row {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
}

.ml-composer__row .ml-field {
  flex: 1;
  min-width: 0;
}

.ml-composer__row textarea {
  field-sizing: content;
  min-height: 3.5rem;
  max-height: 10rem;
  resize: none;
}

.ml-composer__caption {
  margin: 0;
  color: var(--ink-secondary);
}

.ml-menu {
  position: relative;
  flex: none;
}

.ml-menu__backdrop {
  position: fixed;
  inset: 0;
  z-index: 29;
}

.ml-menu__list {
  position: absolute;
  bottom: calc(100% + var(--space-2));
  left: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  min-width: 12rem;
  padding: var(--space-1);
  background: var(--surface-100);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}

.ml-menu__item {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: transparent;
  border: 0;
  border-radius: var(--radius-sm);
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.ml-menu__item:hover,
.ml-menu__item:focus-visible {
  background: var(--surface-hover);
}

.ml-menu__item:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: -2px;
}

/* The picker has no button of its own here; its panel floats over the thread, above the composer, and never pushes the layout. */
.ml-saved-replies--popover {
  display: contents;
}

.ml-saved-replies--popover .ml-saved-replies__panel {
  position: absolute;
  right: var(--space-4);
  bottom: 100%;
  left: var(--space-4);
  z-index: 30;
  max-height: 18rem;
  margin-bottom: var(--space-2);
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}

@media (max-width: 767px) {
  .ml-flyout { width: 100%; }
}

/* AB#364: how long the customer has waited. Real text in full-strength ink and heavier weight, so it reads without any colour. */
.ml-conversation__waiting {
  color: var(--ink);
  font-weight: 600;
}
