:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --text: #1b1b1b;
  --muted: #5c5c5c;
  --line: #dcdcd8;
  --accent: #1f5fbf;
  --danger: #b3261e;
  --site: #5c5c5c;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141414;
    --surface: #1e1e1e;
    --text: #ececec;
    --muted: #a8a8a8;
    --line: #333333;
    --accent: #8ab4f8;
    --danger: #f2b8b5;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 15px/1.45 system-ui, sans-serif; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; color: inherit; }
button {
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 12px; cursor: pointer;
}
button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button[disabled] { opacity: 0.6; cursor: progress; }
a { color: var(--accent); }
.error { color: var(--danger); margin: 0; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
kbd {
  display: inline-block; font: 0.75rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  padding: 2px 5px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px;
  background: var(--bg); color: var(--muted); vertical-align: middle;
}

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(360px, 100%); display: grid; gap: 8px; padding: 24px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
}
.login-card h1 { margin: 0 0 8px; font-size: 1.4rem; }
.login-card input { padding: 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.login-card button { margin-top: 8px; background: var(--accent); color: var(--surface); border-color: var(--accent); }

/* app shell */
.app { height: 100vh; display: flex; flex-direction: column; }
.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.bar h1 { font-size: 1.1rem; margin: 0 8px 0 0; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }
.filters button[aria-pressed="true"] { border-color: var(--site); box-shadow: inset 0 -3px 0 var(--site); }
.queue { display: inline-flex; align-items: center; gap: 6px; }
.queue[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }
.count {
  min-width: 1.5em; padding: 0 6px; border-radius: 999px; font-size: 0.75rem; line-height: 1.5em; text-align: center;
  background: var(--accent); color: var(--surface);
}
.icon { width: 32px; padding: 6px 0; border-radius: 50%; color: var(--muted); }
#inbox-errors:not(:empty) { padding: 6px 16px; }

.panes { flex: 1; display: grid; grid-template-columns: minmax(280px, 380px) 1fr; min-height: 0; }
.list-pane { overflow-y: auto; border-right: 1px solid var(--line); }
.list { list-style: none; margin: 0; padding: 0; }
.list .empty { padding: 16px; color: var(--muted); }

.item {
  width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); border-radius: 0;
  border-left: 4px solid var(--site);
  display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 10px 12px;
}
.item[aria-current="true"] { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.item .site { grid-column: 1 / -1; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.item .from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .date { color: var(--muted); font-size: 0.85rem; }
.item .subject { grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.item.unread .from, .item.unread .subject { font-weight: 650; color: var(--text); }
.item.answered .subject { color: var(--muted); }

/* reader */
.reader { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.reader-nav { display: flex; justify-content: space-between; gap: 8px; }
.reader-nav:empty { display: none; }
.back { display: none; }
.jump { margin-left: auto; color: var(--muted); }
.reader-head h2 { margin: 0 0 8px; font-size: 1.25rem; overflow-wrap: anywhere; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 12px; margin: 0; color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.notice { display: flex; gap: 8px; align-items: center; margin: 8px 0 0; color: var(--muted); }
.reader-body { width: 100%; min-height: 360px; flex: 1; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.reader-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; font: inherit; }
.attachments { margin: 0; padding-left: 20px; }
.attachments:empty { display: none; }

/* the reply box */
.reply {
  display: grid; gap: 10px; min-width: 0;
  padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  border-top: 3px solid var(--site);
}
.reply-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 12px; }
.reply-as { margin: 0; font-size: 1rem; font-weight: 500; overflow-wrap: anywhere; }
.reply-as .dot { display: inline-block; width: 10px; height: 10px; margin-right: 8px; border-radius: 50%; background: var(--site); vertical-align: -1px; }
.hint { font-size: 0.8rem; color: var(--muted); white-space: nowrap; }

.templates { display: grid; gap: 8px; min-width: 0; }
.templates-bar { display: flex; align-items: center; gap: 10px; }
.templates-label { font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.templates-bar input {
  flex: 1; min-width: 0; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg);
}
.templates-bar input::placeholder { color: var(--muted); opacity: 0.8; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; min-width: 0; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  padding: 5px 12px 5px 6px; border-radius: 999px; font-size: 0.9rem; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chip:hover { border-color: var(--site); }
.chip[aria-pressed="true"] { border-color: var(--site); background: color-mix(in srgb, var(--site) 14%, var(--surface)); }
.chip-n {
  width: 1.5em; height: 1.5em; border-radius: 50%; font-size: 0.7rem; line-height: 1.5em; text-align: center;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line);
}
.chip[aria-pressed="true"] .chip-n { background: var(--site); color: var(--surface); border-color: var(--site); }
.chips-empty { font-size: 0.85rem; color: var(--muted); padding: 5px 0; }

.reply textarea {
  width: 100%; min-height: 9em; padding: 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); resize: vertical; line-height: 1.5; overflow: hidden;
}
.reply textarea::placeholder { color: var(--muted); opacity: 0.8; }
.reply textarea::selection { background: color-mix(in srgb, var(--site) 30%, var(--surface)); }
.signature {
  margin: -2px 0 0; padding: 4px 0 4px 12px; border-left: 2px solid var(--site);
  font: inherit; line-height: 1.5; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere;
}
.signature-edit { padding: 3px 10px; font-size: 0.85rem; color: var(--muted); }
.signature-editor { display: grid; gap: 6px; min-width: 0; padding-left: 12px; border-left: 2px solid var(--site); }
.signature-editor label { font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.reply .signature-editor textarea { min-height: 5.5em; overflow: auto; }
.signature-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.signature-save { border-color: var(--accent); color: var(--accent); }
.reply-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.reply .check { display: flex; gap: 6px; align-items: center; color: var(--muted); }
.preview-toggle[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }
.send-group { margin-left: auto; display: flex; gap: 6px; }
.reply .send {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--accent); color: var(--surface); border-color: var(--accent);
}
.reply .send-next { border-color: var(--accent); color: var(--accent); white-space: nowrap; }
.reply .send kbd { border-color: color-mix(in srgb, var(--surface) 40%, transparent); background: color-mix(in srgb, var(--surface) 18%, transparent); color: var(--surface); }
.reply-status-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0; min-height: 1.5em; }
.reply-status-row:has(#reply-status:empty, #next-unanswered[hidden]) { min-height: 0; }
#reply-status:empty { display: none; }

/* the reply as it will arrive */
.preview { display: grid; gap: 10px; padding: 12px; border: 1px dashed var(--line); border-radius: 8px; background: var(--bg); }
.preview.is-stale { opacity: 0.6; transition: opacity 0.2s; }
.preview-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: start; gap: 8px 16px; }
.preview-head .meta { font-size: 0.9rem; min-width: 0; }
.preview-modes { display: flex; gap: 4px; }
.preview-modes button { padding: 4px 10px; font-size: 0.85rem; }
.preview-modes button[aria-pressed="true"] { border-color: var(--accent); box-shadow: inset 0 -3px 0 var(--accent); }
.preview-note { margin: 0; color: var(--muted); }
.preview-html { width: 100%; height: 360px; border: 1px solid var(--line); border-radius: 6px; background: #fff; resize: vertical; }
.preview-text {
  margin: 0; padding: 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
  white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; line-height: 1.5;
}

/* a line at the bottom: a note, or an undo */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 2;
  display: flex; align-items: center; gap: 12px; max-width: calc(100% - 32px); margin: 0;
  padding: 10px 14px; border-radius: 8px; background: var(--text); color: var(--bg); box-shadow: var(--shadow);
}
.toast button { padding: 4px 10px; background: transparent; color: inherit; border-color: color-mix(in srgb, var(--bg) 40%, transparent); }

/* shortcuts */
.help {
  width: min(420px, calc(100% - 32px)); padding: 20px 24px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.help::backdrop { background: rgba(0, 0, 0, 0.35); }
.help h2 { margin: 0 0 12px; font-size: 1.1rem; }
.help dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0 0 16px; align-items: center; }
.help dt { white-space: nowrap; }
.help dd { margin: 0; color: var(--muted); }
.help form { display: flex; justify-content: flex-end; margin: 0; }

/* one column on a phone: the list, or the open message */
@media (max-width: 760px) {
  .panes { grid-template-columns: 1fr; }
  .list-pane { border-right: 0; }
  body.reading .list-pane { display: none; }
  .back { display: inline-block; }
  .bar h1 { margin-right: auto; }
  .filters { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .filters button { flex: none; }
  .hint { display: none; }
  .reply { padding: 12px; }
  .chips { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; margin: 0 -12px; padding-left: 12px; padding-right: 12px; }
  .chip { flex: none; }
  .templates-bar { flex-wrap: wrap; }
  .templates-bar input { flex-basis: 100%; }
  .send-group { flex: 1 0 100%; margin-left: 0; }
  .send-group button { flex: 1; justify-content: center; }
  .send-group kbd, .preview-toggle kbd { display: none; }
  .preview-html { height: 300px; }
}

@media (max-width: 400px) {
  .bar { padding: 8px 12px; }
  .reader { padding: 12px; }
}
