:root {
  color-scheme: light dark;
  --bg: #f6f6f3;
  --surface: #ffffff;
  --text: #1c1d1a;
  --muted: #6a6c64;
  --line: #e2e2dc;
  --hover: #efefea;
  --selected: #e4ebdf;
  --accent: #2f6b3f;
  --on-accent: #ffffff;
  --danger: #a93226;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161714;
    --surface: #1e1f1b;
    --text: #e9e9e3;
    --muted: #9b9d93;
    --line: #30322c;
    --hover: #272922;
    --selected: #2a3627;
    --accent: #84c493;
    --on-accent: #10210f;
    --danger: #ec8b7f;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); }

h1, h2, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }

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

input {
  width: 100%;
  min-height: 36px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.primary {
  min-height: 38px;
  padding: 0 14px;
  background: var(--accent);
  color: var(--on-accent);
  border: 0;
  border-radius: 6px;
  font-weight: 600;
}

.quiet {
  min-height: 30px;
  padding: 0 8px;
  background: none;
  border: 1px solid transparent;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  white-space: nowrap;
}
.quiet:hover { background: var(--hover); color: var(--text); }
.quiet.danger:hover { color: var(--danger); }

.error { color: var(--danger); }

/* Sign in */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(340px, 100%);
  display: grid;
  gap: 10px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.login-card h1 { font-size: 18px; margin-bottom: 6px; }
.login-card label { color: var(--muted); }

/* Layout */
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(300px, 400px) minmax(0, 1fr);
}

.list-pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-right: 1px solid var(--line);
}

.list-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  gap: 8px;
  padding: 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.brand h1 { font: 600 13px var(--mono); overflow-wrap: anywhere; }

/* Message list */
.message {
  display: grid;
  gap: 1px;
  width: 100%;
  padding: 10px 12px;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--line);
}
.message:hover { background: var(--hover); }
.message[aria-current="true"] { background: var(--selected); }
.message.fresh { animation: arrive 1.6s ease-out; }

@keyframes arrive {
  from { background: var(--selected); }
}

.message-top { display: flex; justify-content: space-between; gap: 10px; min-width: 0; }
.message-recipient { font: 12px var(--mono); overflow-wrap: anywhere; min-width: 0; }
.message-time { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.message-subject { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-meta { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list-state { padding: 24px 16px; color: var(--muted); text-align: center; overflow-wrap: anywhere; }
.list-state:empty { display: none; }
.list-state code { font: 12.5px var(--mono); color: var(--text); }

.more { margin: 12px; min-height: 36px; background: none; border: 1px solid var(--line); border-radius: 6px; }
.more:hover { background: var(--hover); }

/* Message detail */
.detail-pane { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--surface); }
.placeholder { margin: auto; color: var(--muted); padding: 16px; text-align: center; }

.detail-header { padding: 14px 16px 0; border-bottom: 1px solid var(--line); }
.detail-actions { display: flex; align-items: center; gap: 2px; margin: -4px -8px 6px; flex-wrap: wrap; }
.detail-actions .spacer { flex: 1; }
.back { display: none; }

.detail-subject { font-size: 18px; line-height: 1.3; font-weight: 600; overflow-wrap: anywhere; margin-bottom: 8px; }

.fields { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 12px; margin: 0; }
.fields dt { color: var(--muted); }
.fields dd { margin: 0; overflow-wrap: anywhere; }
.recipient-link {
  padding: 0;
  background: none;
  border: 0;
  font: 12.5px var(--mono);
  color: var(--accent);
  text-align: left;
  overflow-wrap: anywhere;
}
.recipient-link:hover { text-decoration: underline; }

.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.attachment {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: inherit;
  text-decoration: none;
  font-size: 12.5px;
  overflow-wrap: anywhere;
}
.attachment:hover { background: var(--hover); }
.attachment span { color: var(--muted); }

.tabs { display: flex; gap: 4px; margin-top: 10px; }
.tab {
  min-height: 34px;
  padding: 0 10px;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.detail-body { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; }
/* Emails are written for a white page, whatever this UI's theme is. */
.email-frame { flex: 1; width: 100%; min-height: 0; border: 0; background: #fff; color-scheme: light; }
.text-body {
  margin: 0;
  padding: 16px;
  font: 13px/1.55 var(--mono);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.empty-body { padding: 16px; color: var(--muted); }

.headers-table { width: 100%; border-collapse: collapse; font: 12.5px/1.5 var(--mono); }
.headers-table th, .headers-table td { padding: 5px 16px; vertical-align: top; text-align: left; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.headers-table th { width: 30%; color: var(--muted); font-weight: 400; }

/* Phone: one pane at a time */
@media (max-width: 720px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .list-pane { border-right: 0; }
  .app.viewing .list-pane { display: none; }
  .app:not(.viewing) .detail-pane { display: none; }
  .back { display: inline-flex; }
  .quiet, .tab { min-height: 44px; }
  input { font-size: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .message.fresh { animation: none; }
}
