/*
 * GNSW Mail — mailbox refinements, layered over workspace.css.
 *
 * Three jobs: text sizes that can be read without leaning in (nothing below
 * 11px, body copy at 15px), a reader that presents a message the way its
 * sender meant it, and a list that shows at a glance what is new.
 */

.mail-view {
  --reader-max: 860px;
  --ok: #10b981;
  --warn: #d99a1e;
  --radius-card: 14px;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
}

/* ── top bar ───────────────────────────────────────────────────────── */

.sync-status {
  font-size: 12px;
  font-weight: 550;
  color: var(--muted);
}

.live-indicator {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 11px 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
}

.live-indicator[data-state="live"] .live-dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
  animation: live-breathe 3.2s ease-in-out infinite;
}

.live-indicator[data-state="polling"] .live-dot {
  background: var(--warn);
}

.live-indicator[data-state="reconnecting"] .live-dot {
  background: var(--faint);
  animation: live-blink 1.2s ease-in-out infinite;
}

@keyframes live-breathe {
  50% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0.06); }
}

@keyframes live-blink {
  50% { opacity: 0.35; }
}

/* ── folders ───────────────────────────────────────────────────────── */

.folder-button,
.folder-list button {
  font-size: 14px;
}

.filter-chips button {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 8px;
}

#message-count {
  font-size: 13px;
}

#selection-status {
  font-size: 12px;
}

/* ── message list ──────────────────────────────────────────────────── */

/* No dark-mode twin: this rule is layout only (see workspace.css). */
.message-row {
  grid-template-columns: 16px 36px minmax(0, 1fr) 24px;
  gap: 10px 12px;
  min-height: 88px;
  padding: 14px 12px 14px 10px;
  border-radius: 12px;
  transition: background-color 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.message-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
}

.message-content {
  gap: 3px;
}

.message-row-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.message-sender {
  font-size: 14px;
  font-weight: 560;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message-subject {
  font-size: 13.5px;
}

.message-preview {
  font-size: 13px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.message-date {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.message-row.unread .message-date {
  color: var(--blue);
  font-weight: 700;
}

.message-clip {
  display: inline-grid;
  place-items: center;
  width: 15px;
  height: 15px;
  color: var(--faint);
}

.message-clip svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.message-star {
  font-size: 18px;
  color: var(--faint);
}

.message-star.active {
  color: #f0a020;
}

.status-chip {
  font-size: 10.5px;
  font-weight: 650;
  padding: 2px 7px;
  border-radius: 999px;
  text-transform: capitalize;
}

.important-dot {
  font-size: 11px;
}

/* A message that has just arrived says so, once, then settles. */
.message-row.arrived {
  animation: row-arrive 2.6s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes row-arrive {
  0% { transform: translateY(-8px); opacity: 0; box-shadow: 0 0 0 2px var(--blue); }
  12% { transform: none; opacity: 1; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ── reader ────────────────────────────────────────────────────────── */

.reader-panel {
  container-type: inline-size;
  container-name: reader;
}

.message-reader {
  max-width: var(--reader-max);
  margin: 0 auto;
  padding: 0 clamp(18px, 3vw, 40px) 56px;
}

.reader-actions {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  overflow: visible;
  gap: 6px 8px;
  margin: 0 calc(-1 * clamp(18px, 3vw, 40px)) 22px;
  padding: 14px clamp(18px, 3vw, 40px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  backdrop-filter: blur(10px);
}

.reader-btn-group,
.reader-btn-group--star {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 4px;
  margin: 0;
  padding: 0;
  border: 0;
}

.reader-btn-group + .reader-btn-group {
  padding-left: 8px;
  border-left: 1px solid var(--line);
}

.reader-btn-group + .reader-btn-group::before,
[data-theme="dark"] .reader-btn-group + .reader-btn-group::before {
  content: none;
  display: none;
}

.reader-btn-group--star {
  margin-left: auto;
  border-left: 0 !important;
}

.reader-btn,
.reader-btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 560;
}

.reader-btn svg {
  width: 15px;
  height: 15px;
}

.reader-btn:hover {
  background: var(--panel-soft);
  border-color: var(--line);
  color: var(--ink);
}

.reader-btn-primary,
[data-theme="dark"] .reader-btn-primary {
  border-color: var(--line-strong);
  background: var(--panel);
  color: var(--ink);
}

#reply-button,
[data-theme="dark"] #reply-button {
  border-color: transparent;
  background: var(--accent-dark);
  color: #fff;
}

#reply-button:hover {
  background: var(--accent);
}

.reader-btn-danger:hover {
  color: #c2362c;
  border-color: rgba(194, 54, 44, 0.3);
  background: rgba(194, 54, 44, 0.06);
}

.reader-btn-group--star .icon-button {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  font-size: 17px;
}

.message-reader h1 {
  margin: 6px 0 0;
  color: var(--ink);
  font-size: clamp(21px, 2vw, 26px);
  font-weight: 700;
  line-height: 1.28;
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

.reader-details {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 10px 0 0;
}

.reader-details:empty {
  display: none;
}

.reader-chip {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
}

.reader-chip.high,
.reader-chip.warn {
  text-transform: none;
}

.reader-chip.high {
  background: rgba(217, 45, 32, 0.1);
  color: #b42318;
}

.reader-chip.warn {
  background: rgba(217, 154, 30, 0.14);
  color: #9a6700;
}

[data-theme="dark"] .reader-chip.high { color: #fca5a5; }
[data-theme="dark"] .reader-chip.warn { color: #f8cf7a; }

.reader-header {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  margin: 22px 0 0;
  padding: 0 0 20px;
  border-bottom: 1px solid var(--line);
}

.reader-avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #fff;
  font-size: 17px;
  font-weight: 700;
}

.reader-sender {
  min-width: 0;
}

.reader-sender-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
  min-width: 0;
}

#reader-from-name {
  color: var(--ink);
  font-size: 15px;
  font-weight: 700;
}

.reader-from-email {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.reader-recipients {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.reader-date {
  align-self: start;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12.5px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* Attachments */
.reader-attachments:empty {
  display: none;
}

.reader-attachments {
  display: block;
  margin: 20px 0 0;
}

.attachments-heading {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* auto-fit lets a lone attachment use up to 360px instead of sitting in
   one narrow track of an otherwise empty row, so its name has room. */
.attachment-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 360px));
  gap: 10px;
}

.attachment-card {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 20px;
  align-items: center;
  gap: 12px;
  min-height: 60px;
  padding: 10px 14px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}

.attachment-card:hover {
  border-color: var(--line-strong);
  box-shadow: var(--workspace-shadow);
  transform: translateY(-1px);
}

.attachment-type {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: #eef1f8;
  color: #4b5570;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.attachment-type[data-kind="pdf"] { background: #fdecea; color: #b42318; }
.attachment-type[data-kind="image"] { background: #e8f4fd; color: #1768ac; }
.attachment-type[data-kind="archive"] { background: #fdf3e2; color: #9a6700; }
.attachment-type[data-kind="sheet"] { background: #e6f6ee; color: #0a7a4c; }
.attachment-type[data-kind="doc"] { background: #ecefff; color: #3b56c4; }

[data-theme="dark"] .attachment-type { background: #1b2640; color: #c4cde2; }
[data-theme="dark"] .attachment-type[data-kind="pdf"] { background: #3a1b20; color: #fca5a5; }
[data-theme="dark"] .attachment-type[data-kind="image"] { background: #12304a; color: #93c5fd; }
[data-theme="dark"] .attachment-type[data-kind="archive"] { background: #3a2c12; color: #f8cf7a; }
[data-theme="dark"] .attachment-type[data-kind="sheet"] { background: #0f3326; color: #7ee2b8; }
[data-theme="dark"] .attachment-type[data-kind="doc"] { background: #1f2a55; color: #9fb4ff; }

.attachment-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.attachment-meta strong {
  overflow: hidden;
  font-size: 13.5px;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* The name is split in two (see attachmentNameHtml): only the head gives
   way, so the extension and the end of the name always stay readable. */
.attachment-meta .attachment-name {
  display: flex;
  min-width: 0;
}

.attachment-name .name-head {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-name .name-tail {
  flex: none;
  white-space: nowrap;
}

.attachment-meta small {
  color: var(--muted);
  font-size: 12px;
}

.attachment-download {
  display: grid;
  place-items: center;
  color: var(--faint);
}

.attachment-download svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.attachment-card:hover .attachment-download {
  color: var(--blue);
}

/* Body */
.reader-body {
  margin: 22px 0 0;
  padding: 0;
  border: 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.7;
}

.reader-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.reader-text a,
.reader-body a {
  color: var(--blue);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.reader-quote {
  margin: 12px 0 0;
  padding: 2px 0 2px 16px;
  border-left: 3px solid var(--line-strong);
  color: var(--muted);
  font-size: 14px;
}

.reader-empty {
  color: var(--muted);
  font-style: italic;
}

/* Sender HTML keeps its own design, on its own paper. */
.reader-paper {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: #ffffff;
}

.reader-body-html {
  display: block;
  width: 100%;
  min-height: 120px;
  border: 0;
  background: #ffffff;
}

[data-theme="dark"] .reader-paper {
  border-color: #2a3654;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03);
}

.quote-toggle {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  height: 20px;
  margin: 12px 0 0;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel-soft);
  cursor: pointer;
}

.quote-toggle span {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--muted);
}

.quote-toggle:hover {
  border-color: var(--blue);
}

.quote-toggle[aria-expanded="true"] {
  background: var(--blue-soft);
}

/* ── responsive ────────────────────────────────────────────────────── */

/* The toolbar answers to the reader's width, not the window's. */
@container reader (max-width: 820px) {
  .reader-btn:not(.reader-btn-primary) {
    width: 34px;
    padding: 0;
    justify-content: center;
    font-size: 0;
    gap: 0;
  }

  .reader-btn svg {
    width: 16px;
    height: 16px;
  }
}

@container reader (max-width: 600px) {
  .reader-btn-primary:not(#reply-button) {
    width: 34px;
    padding: 0;
    justify-content: center;
    font-size: 0;
    gap: 0;
  }

  .reader-actions {
    gap: 4px;
  }

  .reader-btn-group + .reader-btn-group {
    padding-left: 4px;
  }
}

@container reader (max-width: 460px) {
  .reader-actions {
    flex-wrap: wrap;
    row-gap: 8px;
  }

  .reader-btn-group--star {
    margin-left: 0;
  }
}

.reader-back {
  font-size: 13px;
  font-weight: 600;
}

@media (max-width: 760px) {
  .message-row {
    min-height: 80px;
    padding: 12px 10px 12px 8px;
  }

  .reader-header {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .reader-avatar {
    width: 40px;
    height: 40px;
    font-size: 15px;
  }

  .reader-date {
    grid-column: 2;
    margin-top: -6px;
  }

  .live-indicator span:last-child {
    display: none;
  }

  .live-indicator {
    padding: 0 9px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .message-row.arrived,
  .live-indicator .live-dot {
    animation: none !important;
  }
}

/* ── folder badges: only what is waiting ───────────────────────────── */

.folder-count.is-empty,
#sidebar-folder-total.is-empty {
  display: none;
}

.folder-count.is-unread,
.folder-button.active .folder-count.is-unread {
  border-color: transparent;
  background: var(--accent-dark);
  color: #fff;
  font-weight: 700;
}

#sidebar-folder-total {
  color: var(--blue);
  font-weight: 700;
}


/* ── DMARC aggregate report ───────────────────────────────────────────
   Rendered above a report email's body by dmarc-report.js: a verdict, the
   published policy in plain words, and one row per sending server. */
.reader-report:empty {
  display: none;
}

.reader-report {
  margin: 0 0 18px;
}

.dmarc-report {
  container-type: inline-size;
  --good: #0f7a3d;   --good-bg: #e8f6ee;
  --warn: #9a6700;   --warn-bg: #fdf3e2;
  --bad: #b42318;    --bad-bg: #fdecea;
  display: grid;
  gap: 16px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  color: var(--ink);
}

[data-theme="dark"] .dmarc-report {
  --good: #7ee2b8;   --good-bg: #0f2e22;
  --warn: #f8cf7a;   --warn-bg: #33280f;
  --bad: #fca5a5;    --bad-bg: #3a1b20;
}

.dmarc-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 12px;
}

.dmarc-kicker {
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.dmarc-source {
  font-size: 14px;
  font-weight: 650;
}

.dmarc-period {
  margin-left: auto;
  color: var(--muted);
  font-size: 12.5px;
}

.dmarc-verdict {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 14px 16px;
  border-radius: 11px;
  background: var(--good-bg);
}

.dmarc-report[data-state="warn"] .dmarc-verdict { background: var(--warn-bg); }
.dmarc-report[data-state="fail"] .dmarc-verdict { background: var(--bad-bg); }

.dmarc-verdict-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--good);
  color: var(--panel);
  font-size: 17px;
  font-weight: 800;
}

.dmarc-report[data-state="warn"] .dmarc-verdict-icon { background: var(--warn); }
.dmarc-report[data-state="fail"] .dmarc-verdict-icon { background: var(--bad); }

.dmarc-verdict strong {
  display: block;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.35;
}

.dmarc-verdict p {
  margin: 4px 0 0;
  color: var(--ink-soft);
  font-size: 13px;
  line-height: 1.55;
}

.dmarc-verdict code {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.06);
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px;
}

[data-theme="dark"] .dmarc-verdict code {
  background: rgba(255, 255, 255, 0.08);
}

.dmarc-policy {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.dmarc-policy div {
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.dmarc-policy dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.dmarc-policy dd {
  margin: 3px 0 0;
  font-size: 13.5px;
  font-weight: 600;
}

.dmarc-policy dd small {
  color: var(--muted);
  font-weight: 500;
}

.dmarc-table {
  display: grid;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.dmarc-row {
  display: grid;
  /* The result columns take what their chips need and the server and
     volume columns share the rest, so the table fits the reader pane at
     whatever width the three-column layout leaves it. */
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) repeat(3, max-content);
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.dmarc-row:first-child {
  border-top: 0;
}

.dmarc-row-head {
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.dmarc-ip {
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12.5px;
}

.dmarc-count {
  color: var(--ink-soft);
}

/* Column headers carry the SPF/DKIM names on wide screens. */
.dmarc-label {
  display: none;
}

.dmarc-chip {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-transform: lowercase;
}

.dmarc-chip[data-tone="pass"] { background: var(--good-bg); color: var(--good); }
.dmarc-chip[data-tone="fail"] { background: var(--bad-bg); color: var(--bad); }

.dmarc-result {
  font-weight: 700;
  color: var(--good);
}

.dmarc-row[data-pass="false"] .dmarc-result {
  color: var(--bad);
}

.dmarc-foot {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 11.5px;
}

/* Narrow panel — a phone, or a slim reader pane — each server becomes a
   two-line card, with the SPF and DKIM names beside their results since
   there is no header row. Measured on the panel, not the viewport. */
@media (max-width: 600px) {
  .dmarc-report {
    padding: 14px;
  }
}

@container (max-width: 400px) {
  .dmarc-period {
    margin-left: 0;
    width: 100%;
  }

  .dmarc-policy {
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
  }

  .dmarc-policy div {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    padding: 8px 12px;
  }

  .dmarc-policy dd {
    margin: 0;
    text-align: right;
  }

  .dmarc-row-head {
    display: none;
  }

  .dmarc-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-areas:
      "ip ip count"
      "spf dkim result";
    row-gap: 8px;
  }

  .dmarc-row:nth-child(2) {
    border-top: 0;
  }

  .dmarc-ip { grid-area: ip; }
  .dmarc-count { grid-area: count; text-align: right; }
  .dmarc-check:nth-of-type(3) { grid-area: spf; }
  .dmarc-check:nth-of-type(4) { grid-area: dkim; }
  .dmarc-result { grid-area: result; text-align: right; }

  .dmarc-label {
    display: inline;
    margin-right: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
  }
}
