.mail-page {
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 0;
  flex: 1;
  container: mail-page / inline-size;
}
/* Settings → Mail: the tab's content, in the rhythm of every settings page. */
.mail-settings {
  display: grid;
  gap: 28px;
}
/* The administrator hint folds away under the mailbox list. */
.mail-consent summary {
  font-size: 13px;
}
.mail-consent-message {
  width: 100%;
  resize: vertical;
  font-size: 12px;
}
.mail-model .row {
  flex-wrap: wrap;
}
.mail-toolbar,
.mail-search {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.mail-toolbar .input {
  width: auto;
  max-width: 340px;
}
.mail-search input {
  flex: 1;
  min-width: 200px;
}

/* One column: the list, or the open conversation in its place (Back returns). From 1200 px the drafting panel
   stands beside the conversation. */
.mail-layout {
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  flex: 1;
  min-height: 480px;
}
.mail-list {
  overflow-y: auto;
  max-height: 75vh;
}
.mail-detail {
  display: none;
  min-width: 0;
  max-height: 75vh;
  overflow-y: auto;
}
.mail-detail-open .mail-list {
  display: none;
}
.mail-detail-open .mail-detail {
  display: block;
}

/* A conversation is one line: unread mark, sender, subject — preview, date. */
.mail-row {
  position: relative;
  border-bottom: 1px solid var(--border);
}
.mail-row:hover,
.mail-row[aria-current="true"],
.mail-row.mail-focused {
  background: var(--muted);
}
.mail-row.mail-focused {
  box-shadow: inset 2px 0 0 var(--accent-text);
}
.mail-row-main {
  display: grid;
  grid-template-columns: 7px minmax(120px, 200px) minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 40px;
  padding: 0 16px 0 12px;
  background: transparent;
  border: 0;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
  font-size: 13px;
}
.mail-row-main:focus-visible {
  outline: 2px solid var(--accent-text);
  outline-offset: -2px;
}
.mail-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}
.mail-unread .mail-dot {
  background: var(--accent-brand);
}
.mail-from {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}
.mail-from-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mail-count {
  flex: none;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted-foreground);
}
.mail-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}
.mail-subject {
  flex: none;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mail-preview {
  flex: 1 1 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--muted-foreground);
}
.mail-preview::before {
  content: "— ";
}
.mail-unread .mail-from-name,
.mail-unread .mail-subject {
  font-weight: 600;
}
/* The priority's slot, filled or not, so every subject starts at the same place. */
.mail-tag {
  flex: none;
  width: 40px;
  display: flex;
}
.mail-tag .badge {
  height: 18px;
  padding: 0 6px;
  font-size: 11px;
}
/* Which mailbox the mail came in to: its address with the mailbox's colour. */
.mail-row-main:has(.mail-mailbox) {
  grid-template-columns: 7px minmax(120px, 200px) minmax(0, 1fr) auto auto;
}
.mail-mailbox {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  max-width: 180px;
  font-size: 12px;
  color: var(--muted-foreground);
}
.mail-mailbox-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 2px;
  background: var(--mailbox-color);
}
.mail-mailbox-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mail-mailbox[data-mailbox="0"] {
  --mailbox-color: oklch(0.62 0.17 255);
}
.mail-mailbox[data-mailbox="1"] {
  --mailbox-color: oklch(0.66 0.14 165);
}
.mail-mailbox[data-mailbox="2"] {
  --mailbox-color: oklch(0.62 0.17 305);
}
.mail-mailbox[data-mailbox="3"] {
  --mailbox-color: oklch(0.72 0.15 70);
}
.mail-mailbox[data-mailbox="4"] {
  --mailbox-color: oklch(0.62 0.19 25);
}
.mail-mailbox[data-mailbox="5"] {
  --mailbox-color: oklch(0.6 0.03 255);
}
.mail-date {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  color: var(--muted-foreground);
}
.mail-unread .mail-date {
  color: var(--foreground);
  font-weight: 600;
}
/* Archive and the read toggle take the date's place while the pointer or the focus is on the row. */
.mail-row-actions {
  position: absolute;
  top: 0;
  right: 8px;
  bottom: 0;
  display: none;
  align-items: center;
  gap: 2px;
  padding-left: 16px;
  background: linear-gradient(to right, transparent, var(--muted) 16px);
}
.mail-row:hover .mail-row-actions,
.mail-row:focus-within .mail-row-actions {
  display: flex;
}
.mail-row:hover .mail-date,
.mail-row:focus-within .mail-date {
  visibility: hidden;
}
.mail-icon-btn .icon {
  width: 16px;
  height: 16px;
}
/* A narrow page: sender and date on the first line, subject and preview under it. */
@container mail-page (max-width: 640px) {
  .mail-row-main,
  .mail-row-main:has(.mail-mailbox) {
    grid-template-columns: 7px minmax(0, 1fr) auto auto;
    grid-template-areas:
      "dot from box date"
      ". line line line";
    row-gap: 2px;
    height: auto;
    padding: 10px 14px 10px 10px;
  }
  .mail-dot {
    grid-area: dot;
  }
  .mail-from {
    grid-area: from;
  }
  .mail-date {
    grid-area: date;
  }
  .mail-row-main .mail-mailbox {
    grid-area: box;
    max-width: 120px;
  }
  .mail-line {
    grid-area: line;
    flex-wrap: wrap;
    row-gap: 2px;
  }
  .mail-preview {
    flex-basis: 100%;
  }
  .mail-preview::before {
    content: none;
  }
}

/* The open conversation: a bar (back, archive, mark unread, priority), the subject, then every message in full. */
.mail-detail-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 44px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--background);
}
.mail-detail-bar .spacer {
  flex: 1;
}
.mail-bar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.mail-bar-sep {
  width: 1px;
  height: 16px;
  margin: 0 6px;
  background: var(--border);
}
.mail-detail-head {
  padding: 22px 24px 18px 72px;
}
.mail-detail-head h2 {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 4px;
  overflow-wrap: anywhere;
  font-size: 20px;
  font-weight: 500;
}
.mail-detail-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 12px;
}
.mail-detail-meta .mail-mailbox {
  max-width: none;
}
/* Too narrow for one bar: it wraps, the priority on the second line. */
@container mail-page (max-width: 640px) {
  .mail-detail-bar {
    flex-wrap: wrap;
    height: auto;
    min-height: 44px;
    padding: 6px 12px;
    row-gap: 6px;
  }
}
.mail-loading {
  padding: 24px;
}
.mail-messages {
  padding: 0 24px 24px;
}
.mail-message {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  column-gap: 16px;
  padding: 20px 0;
  border-top: 1px solid var(--border);
}
.mail-message > :not(.mail-avatar) {
  grid-column: 2;
}
.mail-avatar {
  grid-row: 1;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--muted);
  color: var(--muted-foreground);
  font-size: 13px;
  font-weight: 600;
}
.mail-message-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 12px;
  align-items: baseline;
  min-height: 32px;
}
.mail-sender {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0 6px;
  min-width: 0;
  overflow-wrap: anywhere;
}
.mail-sender-address,
.mail-message-date,
.mail-recipients {
  font-size: 12px;
  color: var(--muted-foreground);
}
.mail-message-date {
  white-space: nowrap;
}
.mail-recipients {
  grid-column: 1 / -1;
  margin: 2px 0 0;
  overflow-wrap: anywhere;
}
.mail-message .hint {
  overflow-wrap: anywhere;
}
.mail-empty {
  padding: 64px 24px;
  text-align: center;
}
.mail-empty > svg {
  width: 30px;
  height: 30px;
  opacity: 0.4;
}
.mail-empty h2 {
  font-size: 18px;
}
.mail-body {
  overflow-wrap: anywhere;
  line-height: 1.65;
  font-size: 14px;
  margin: 16px 0;
  max-width: 80ch;
}
.mail-body p {
  margin: 0 0 12px;
}
.mail-body a {
  overflow-wrap: anywhere;
}
.mail-table {
  overflow-x: auto;
  margin: 0 0 12px;
}
.mail-table table {
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
.mail-table th,
.mail-table td {
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  overflow-wrap: normal;
}
.mail-table th {
  font-weight: 500;
}
.mail-table .align-right {
  text-align: right;
}
.mail-table .align-center {
  text-align: center;
}
.mail-quoted summary {
  cursor: pointer;
  font-size: 12px;
  color: var(--muted-foreground);
}
.mail-quoted blockquote {
  margin: 8px 0 0;
  padding-left: 12px;
  border-left: 2px solid var(--border);
  color: var(--muted-foreground);
}
.mail-attachments,
.mail-message-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 12px;
}
.mail-attachments:empty {
  display: none;
}
.mail-reply {
  width: 100%;
  resize: vertical;
  min-height: 170px;
}
@media (max-width: 800px) {
  .mail-page {
    padding: 14px;
  }
  .mail-detail-head {
    padding: 18px 16px 14px;
  }
  .mail-messages {
    padding: 0 16px 16px;
  }
  .mail-message {
    grid-template-columns: 28px minmax(0, 1fr);
    column-gap: 12px;
  }
  .mail-avatar {
    width: 28px;
    height: 28px;
  }
}
/* The main inbox: toolbar with the search box, status chips, row actions, the keyboard hint. */
.mail-toolbar .mail-search {
  flex: 1;
  flex-wrap: nowrap;
  min-width: 320px;
}
.mail-toolbar .mail-search .input {
  max-width: none;
}
.mail-sync {
  width: 32px;
  padding: 0;
  flex: none;
  margin-left: auto; /* stays at the right edge when the search is gone */
}
/* Too narrow for one row (the sidebar still open on a small window, a phone): the search goes, the selects
   and the sync stay. Measured on the page, not the window, as the sidebar takes 256 px of it. */
@container mail-page (max-width: 720px) {
  .mail-toolbar .mail-search {
    display: none;
  }
}
.mail-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.mail-chip {
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  background: var(--background);
}
.mail-chip-name {
  font-weight: 550;
}
.mail-chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted-foreground);
}
.mail-chip[data-tone="ok"] .mail-chip-dot {
  background: var(--ok-text);
}
.mail-chip[data-tone="warn"] .mail-chip-dot {
  background: var(--warn-text);
}
.mail-chip[data-tone="danger"] .mail-chip-dot {
  background: var(--destructive-text);
}
.mail-chip[data-tone="accent"] .mail-chip-dot {
  background: var(--accent-text);
}
.mail-chip-text,
.mail-chip-detail {
  color: var(--muted-foreground);
}
.mail-chip-detail {
  flex-basis: 100%;
  font-size: 11px;
}
.mail-chip .btn[data-size="sm"] {
  height: 22px;
  padding: 0 8px;
  font-size: 12px;
}
.mail-more {
  margin: 12px 16px;
}
.mail-search-failure {
  margin: 8px 18px;
}
.mail-keys {
  font-size: 12px;
  color: var(--muted-foreground);
}
.mail-keys summary {
  cursor: pointer;
}
.mail-keys dl {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  margin: 8px 0 0;
}
.mail-keys dd {
  margin: 0;
}
.mail-keys kbd {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 5px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--muted);
}

/* The "Draft with agent" panel (web/mail-drafting.js): a third column from 1200 px, a slide-over that covers
   the conversation between 801 and 1199 px, a full screen with "Back to conversation" under 800 px. */
.mail-panel {
  display: none;
  border-left: 1px solid var(--border);
  min-width: 0;
  max-height: 75vh;
  overflow-y: auto;
  padding: 16px;
  flex-direction: column;
  gap: 16px;
  font-size: 13px;
}
.mail-panel-open .mail-panel {
  display: flex;
}
.mail-panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  min-height: 0;
}
.mail-panel-head:empty {
  display: none;
}
.mail-panel-close {
  font-size: 18px;
  line-height: 1;
  padding: 0 8px;
}
/* Who the reply goes to, in three rows that line up: the mailbox it leaves from, the people, how it answers. */
.mail-panel-target {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 10px 12px;
  align-items: center;
  font-size: 13px;
  margin: 0;
}
.mail-panel-target dt {
  color: var(--muted-foreground);
  font-size: 12px;
  line-height: 28px;
}
.mail-panel-target dd {
  margin: 0;
  min-height: 28px;
  display: flex;
  align-items: center;
  overflow-wrap: anywhere;
}
.mail-panel-status[hidden] {
  display: none;
}
.mail-panel-replies[hidden] {
  display: none;
}
.mail-panel-pane {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.mail-panel-mode {
  width: auto;
  height: 28px;
  font-size: 13px;
  padding: 0 28px 0 8px;
}
.mail-panel-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.mail-panel-actions .spacer {
  flex: 1;
}
.mail-panel-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.mail-panel-replies {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.mail-panel-replies-list {
  display: contents;
}
.mail-panel-reply-chip {
  font: inherit;
  font-size: 12px;
  color: inherit;
  padding: 2px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--background);
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mail-panel-reply-chip[aria-current="true"] {
  background: var(--muted);
  font-weight: 550;
  cursor: default;
}
.mail-panel-status {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  min-height: 22px;
}
.mail-panel-state[data-tone="warn"] {
  color: var(--warn-text);
}
.mail-panel-state[data-tone="ok"] {
  color: var(--ok-text);
}
.mail-panel-candidates {
  flex-basis: 100%;
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.mail-panel-candidate {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-wrap: anywhere;
}
.mail-panel-candidate-line {
  margin: 2px 0 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 48ch;
}
.mail-panel-back {
  display: none;
}
@media (min-width: 1200px) {
  .mail-layout.mail-detail-open.mail-panel-open {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
  }
}
@media (max-width: 1199px) {
  .mail-panel-back {
    display: inline-flex;
  }
  .mail-panel-close {
    display: none;
  }
  /* The panel takes the conversation's column. */
  .mail-panel-open .mail-detail {
    display: none;
  }
  .mail-panel {
    border-left: 0;
  }
}
@media (max-width: 800px) {
  .mail-panel-open .mail-list,
  .mail-panel-open .mail-detail {
    display: none;
  }
  .mail-panel-open .mail-panel {
    display: flex;
    padding: 14px;
    max-height: none;
  }
}
/* Priority: a badge after the subject (High and Low) and the conversation's own choice in the head. */
.mail-priority {
  flex: none;
}
.mail-detail-bar .mail-priority-choice {
  width: auto;
  height: 28px;
  font-size: 13px;
}

/* Settings → Mail: "Share with the CRM" and its visibility (ADR 0024). */
.mail-crm-share {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.mail-crm-visibility {
  width: auto;
  height: 28px;
  padding: 0 8px;
  font-size: 13px;
}
