:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #15171a;
  --muted: #5d6470;
  --border: #e2e5ea;
  --accent: #2f6fed;
  --accent-hover: #2459c9;
  --accent-soft: #e8effd;
  --danger: #c4372f;
  --danger-soft: #fdecea;
  --success: #198754;
  --warning-soft: #fff6e0;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.05), 0 4px 16px rgb(16 24 40 / 0.04);
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1014;
    --surface: #16191f;
    --surface-2: #1d2128;
    --text: #e8eaed;
    --muted: #9ba2ad;
    --border: #2a2f38;
    --accent: #6b9bff;
    --accent-hover: #8db2ff;
    --accent-soft: #1c2a47;
    --danger: #ff7b72;
    --danger-soft: #3a1d1c;
    --success: #4cc38a;
    --warning-soft: #2e2716;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }

[hidden] { display: none !important; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.container {
  width: 100%;
  max-width: 1120px;
  margin-inline: auto;
  padding-inline: 20px;
}

/* Top bar */
.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 60px;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 650;
  font-size: 17px;
  text-decoration: none;
}
.brand-mark {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}
.status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}
.status[data-state="live"]::before { background: var(--success); }
.status[data-state="offline"]::before { background: var(--danger); }

/* Address card */
.address-card {
  margin-block: 28px 20px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.eyebrow {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
}
.address-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.address {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font: 600 clamp(16px, 3.2vw, 22px)/1.3 var(--mono);
  overflow-wrap: anywhere;
  user-select: all;
}
.address-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}
.retention {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-weight: 550;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
@media (prefers-color-scheme: dark) {
  .btn-primary { color: #0b1220; }
}
.btn-quiet-danger { color: var(--danger); }
.btn-quiet-danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
.btn-small { min-height: 34px; padding: 6px 12px; font-size: 13px; }

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn.spinning svg { animation: spin 700ms linear; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Custom name form */
.custom-form {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.custom-form label {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
}
.custom-fields {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.custom-input {
  flex: 1 1 320px;
  display: flex;
  align-items: center;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}
.custom-input:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.custom-input input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border: 0;
  background: transparent;
  font-family: var(--mono);
  font-size: 16px; /* 16px keeps iOS from zooming in */
  outline: none;
}
.custom-input .at {
  padding-inline: 2px 6px;
  color: var(--muted);
  font-family: var(--mono);
}
.custom-input select {
  max-width: 55%;
  align-self: stretch;
  padding: 0 12px;
  border: 0;
  border-left: 1px solid var(--border);
  background: var(--surface-2);
  font-family: var(--mono);
  font-size: 15px;
  outline: none;
}
.custom-input select:disabled { opacity: 1; appearance: none; }
.hint {
  margin: 8px 0 0;
  font-size: 13px;
  color: var(--muted);
}
.form-error {
  margin: 6px 0 0;
  font-size: 13px;
  font-weight: 550;
  color: var(--danger);
}
.form-error:empty { display: none; }

/* Mail area */
.mail {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  margin-bottom: 40px;
  min-height: 560px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.inbox-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--border);
}
.pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 12px 18px;
  border-bottom: 1px solid var(--border);
}
.pane-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
}
.count {
  margin-left: 4px;
  color: var(--muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.message-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
}
.message-list:empty { display: none; }
.message-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 10px;
  width: 100%;
  padding: 12px 18px 12px 26px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  text-align: left;
  cursor: pointer;
  position: relative;
}
.message-item:hover { background: var(--surface-2); }
.message-item[aria-current="true"] { background: var(--accent-soft); }
.message-item.unread::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 19px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
}
.message-item .from,
.message-item .subject,
.message-item .preview {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  min-width: 0;
}
.message-item .from { font-weight: 550; }
.message-item.unread .from,
.message-item.unread .subject { font-weight: 700; }
.message-item .time {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.message-item .subject { grid-column: 1 / -1; font-size: 14px; }
.message-item .preview { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.message-item .clip { color: var(--muted); }

.empty {
  display: grid;
  justify-items: center;
  gap: 4px;
  margin: auto;
  padding: 48px 24px;
  text-align: center;
}
.empty-title { margin: 12px 0 0; font-weight: 650; }
.empty-text { margin: 0; max-width: 260px; font-size: 14px; color: var(--muted); }
/* Pulses only while the inbox is really being checked; static and grey when offline. */
.empty-pulse {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--muted);
}
body[data-connection="live"] .empty-pulse {
  background: var(--accent);
  animation: pulse 1.8s ease-out infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); }
  100% { box-shadow: 0 0 0 18px transparent; }
}

/* Reader */
.reader-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.reader-placeholder {
  display: grid;
  place-items: center;
  flex: 1;
  color: var(--muted);
  font-size: 14px;
}
.reader-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding: 16px 22px 22px;
}
.reader-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.back-btn { visibility: hidden; }
.msg-subject {
  margin: 0 0 10px;
  font-size: 20px;
  line-height: 1.3;
  font-weight: 650;
  overflow-wrap: anywhere;
}
.msg-meta {
  display: grid;
  gap: 2px;
  margin: 0 0 14px;
  font-size: 13px;
}
.msg-meta div { display: flex; gap: 8px; min-width: 0; }
.msg-meta dt { flex: 0 0 64px; color: var(--muted); }
.msg-meta dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
  padding: 0;
  list-style: none;
}
.attachments:empty { display: none; }
.attachment {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  font-size: 13px;
  cursor: pointer;
}
.attachment:hover { border-color: var(--accent); }
.attachment .name { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.attachment .size { color: var(--muted); font-variant-numeric: tabular-nums; }

.images-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 8px 8px 8px 14px;
  border-radius: var(--radius-sm);
  background: var(--warning-soft);
  font-size: 13px;
}
.msg-body {
  flex: 1;
  display: flex;
  min-height: 420px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.msg-body iframe {
  flex: 1;
  width: 100%;
  min-height: 420px;
  border: 0;
  background: #fff; /* emails are designed for a white page */
}
.msg-body .text-body {
  flex: 1;
  margin: 0;
  padding: 16px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 14px/1.6 var(--font);
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 16px);
  max-width: calc(100% - 40px);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 550;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Small screens: list and reader take turns */
@media (max-width: 820px) {
  .container { padding-inline: 14px; }
  .address-card { margin-top: 16px; padding: 18px; }
  .address-row { flex-direction: column; }
  .address-actions .btn { flex: 1 1 auto; }
  .mail { grid-template-columns: 1fr; min-height: 420px; }
  .inbox-pane { border-right: 0; }
  .mail[data-view="list"] .reader-pane { display: none; }
  .mail[data-view="reader"] .inbox-pane { display: none; }
  .back-btn { visibility: visible; }
  .reader-content { padding: 14px; }
  .msg-body, .msg-body iframe { min-height: 60vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
