:root {
  --bg: #f2f3f5;
  --surface: #ffffff;
  --ink: #151a26;
  --muted: #5d6676;
  --faint: #8d96a5;
  --line: #e4e6eb;
  --line-strong: #cfd4dc;
  --accent: #1f4fd8;
  --code-ink: #14307f;
  --code-bg: #eef2ff;
  --code-line: #c9d5fb;
  --bar: 57px;
  --nav: 248px;
  --cols: 112px minmax(160px, 1.1fr) minmax(120px, 0.8fr) minmax(200px, 2fr) 150px;
  color: var(--ink);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, p { margin: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.mono, .code-chip b, .reader-code b {
  font-family: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
}

/* ---------- top bar ---------- */
.bar {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: var(--bar);
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line-strong);
}
.bar h1 { font-size: 18px; font-weight: 650; letter-spacing: -0.01em; }

.tools { display: flex; align-items: center; gap: 12px; }
.tools form { margin: 0; }
.status { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.status.bad { color: #b42318; }

.btn {
  height: 32px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  font-weight: 500;
  transition: background 0.12s, border-color 0.12s;
}
.btn:hover { background: #f6f7f9; }
.btn:active { background: #eceef2; }
.btn-quiet { border-color: transparent; color: var(--muted); }
.btn-primary { background: var(--ink); border-color: var(--ink); color: #fff; height: 38px; }
.btn-primary:hover { background: #2a3142; }
.btn.busy { color: var(--muted); pointer-events: none; }
.btn.busy::before {
  content: "";
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 7px;
  vertical-align: -1px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; color: var(--muted); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.track {
  position: relative;
  width: 32px;
  height: 18px;
  border-radius: 9px;
  background: var(--line-strong);
  transition: background 0.15s;
}
.track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); }
.switch input:checked ~ span:last-child { color: var(--ink); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- layout: recipients on the left, mail on the right ---------- */
.shell { display: grid; grid-template-columns: var(--nav) minmax(0, 1fr); align-items: start; }

.nav {
  position: sticky;
  top: var(--bar);
  height: calc(100vh - var(--bar));
  overflow-y: auto;
  padding: 16px 12px 24px;
  background: var(--surface);
  border-right: 1px solid var(--line-strong);
}
.nav-title { padding: 0 10px 8px; color: var(--faint); font-size: 12px; font-weight: 600; letter-spacing: 0.06em; }
.nav-list { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 6px 10px 6px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  text-align: left;
}
.nav-item:hover { background: #f3f4f7; color: var(--ink); }
.nav-item[aria-pressed="true"] { background: var(--code-bg); color: var(--ink); font-weight: 600; }
.nav-item[aria-pressed="true"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 2px;
  background: var(--accent);
}
.nav-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item small { flex: none; color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.nav-item[aria-pressed="true"] small { color: var(--accent); }

.pane { min-width: 0; padding-bottom: 56px; }
.pane-head {
  position: sticky;
  top: var(--bar);
  z-index: 4;
  background: var(--surface);
  border-bottom: 1px solid var(--line-strong);
}
.filters {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--line);
  background: #fafbfc;
}
.filters h2 { min-width: 0; max-width: 40%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 15px; font-weight: 650; }
.filters input[type="search"] {
  width: 240px;
  height: 32px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  padding: 0 10px;
}
.count { margin-left: auto; color: var(--faint); font-size: 13px; font-variant-numeric: tabular-nums; }

/* Inside one recipient the recipient column is redundant. */
.pane.scoped { --cols: 112px minmax(120px, 0.8fr) minmax(220px, 2.2fr) 150px; }
.pane.scoped .account { display: none; }

/* ---------- table ---------- */
.row {
  display: grid;
  grid-template-columns: var(--cols);
  column-gap: 14px;
  align-items: center;
  padding: 0 24px;
}
.head {
  height: 34px;
  background: #f6f7f9;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

#rows { background: var(--surface); }

.item {
  position: relative;
  min-height: 46px;
  padding-top: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.item:hover { background: #f8f9fb; }
.item.fresh { animation: fresh 2.4s ease-out; }

.cell { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { color: var(--muted); font-variant-numeric: tabular-nums; }
.account { color: var(--ink); }
.from { color: var(--muted); }
.subject { font-weight: 500; }
.preview { color: var(--faint); font-weight: 400; margin-left: 8px; }

.code-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
  padding: 2px 4px 2px 10px;
  border: 1px solid var(--code-line);
  border-radius: 6px;
  background: var(--code-bg);
}
.code-chip b { color: var(--code-ink); font-size: 15px; font-weight: 700; letter-spacing: 0.1em; }
.code-chip button, .reader-code button {
  height: 22px;
  padding: 0 8px;
  border: 0;
  border-radius: 4px;
  background: #fff;
  color: var(--code-ink);
  font-size: 12px;
  font-weight: 600;
}
.code-chip button:hover, .reader-code button:hover { background: #dfe7ff; }
.code-chip button.done, .reader-code button.done { background: #d7f3e5; color: #0b6b43; }

.more { display: flex; justify-content: center; padding: 20px; }
.banner {
  margin: 16px 24px 0;
  padding: 10px 14px;
  border: 1px solid #f2c4bf;
  border-radius: 6px;
  background: #fff1f0;
  color: #912018;
}
.empty { padding: 56px 24px; text-align: center; color: var(--muted); }
.empty .btn { margin-top: 12px; }

/* ---------- reader ---------- */
.scrim { position: fixed; inset: 0; background: rgba(21, 26, 38, 0.32); z-index: 9; }
.reader {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  width: min(640px, 100%);
  padding: 18px 24px 28px;
  overflow: auto;
  background: var(--surface);
  border-left: 1px solid var(--line-strong);
  box-shadow: -12px 0 32px rgba(21, 26, 38, 0.12);
  animation: slide 0.18s ease-out;
}
.scrim[hidden], .reader[hidden] { display: none; }
.reader-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.reader-meta { color: var(--muted); font-size: 13px; }
.reader h2 { margin: 12px 0 14px; font-size: 20px; line-height: 1.3; letter-spacing: -0.01em; }
.reader-code {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding: 12px 14px;
  border: 1px solid var(--code-line);
  border-radius: 8px;
  background: var(--code-bg);
}
.reader-code[hidden] { display: none; }
.reader-code b { color: var(--code-ink); font-size: 28px; letter-spacing: 0.14em; }
.reader-code button { height: 28px; margin-left: auto; padding: 0 12px; font-size: 13px; }
#reader-body {
  margin: 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  white-space: pre-wrap;
  word-break: break-word;
  font: inherit;
  line-height: 1.6;
}

/* ---------- login ---------- */
.gate { display: grid; place-items: center; padding: 24px 16px; }
.gate-card {
  width: min(380px, 100%);
  padding: 28px 26px 26px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgba(21, 26, 38, 0.06);
}
.gate-card h1 { font-size: 22px; letter-spacing: -0.01em; }
.gate-note { margin: 4px 0 18px; color: var(--muted); }
.gate-card form { display: flex; flex-direction: column; gap: 6px; }
.gate-card label { margin-top: 8px; color: var(--muted); font-size: 13px; font-weight: 500; }
.gate-card input {
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
}
.gate-card .btn-primary { margin-top: 18px; }
.gate-foot { margin: 16px 0 0; font-size: 13px; }
.gate-foot a, .prose a { color: var(--accent); }
.prose { width: min(560px, 100%); }
.prose h2 { margin: 18px 0 6px; font-size: 15px; }
.prose p { margin: 0 0 10px; }
.error { margin: 0 0 6px; padding: 8px 10px; border-radius: 6px; background: #fff1f0; color: #912018; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes slide { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes fresh { from { background: #fff7d6; } to { background: transparent; } }

@media (max-width: 1100px) {
  :root { --nav: 210px; --cols: 100px minmax(130px, 1fr) minmax(90px, 0.7fr) minmax(140px, 1.6fr) 140px; }
  .pane.scoped { --cols: 100px minmax(90px, 0.7fr) minmax(160px, 1.8fr) 140px; }
  .row { padding: 0 16px; column-gap: 10px; }
  .bar, .filters { padding-left: 16px; padding-right: 16px; }
}

@media (max-width: 860px) {
  :root { --bar: 0px; }
  .bar { position: static; height: auto; flex-wrap: wrap; align-content: center; padding-top: 8px; padding-bottom: 8px; row-gap: 6px; }
  .tools { flex-wrap: wrap; gap: 8px 12px; }
  .shell { display: block; }
  .nav {
    position: sticky;
    top: var(--bar);
    z-index: 4;
    height: auto;
    padding: 8px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--line-strong);
  }
  .nav-title { display: none; }
  .nav-list { flex-direction: row; gap: 6px; }
  .nav-item { width: auto; max-width: 240px; min-height: 32px; border: 1px solid var(--line-strong); }
  .nav-item[aria-pressed="true"] { border-color: var(--accent); }
  .nav-item[aria-pressed="true"]::before { display: none; }
  .pane-head { position: static; }
  .head { display: none; }
  .filters { flex-wrap: wrap; padding-left: 16px; padding-right: 16px; }
  .filters h2 { max-width: 100%; flex: 1 1 100%; }
  .filters input[type="search"] { flex: 1 1 100%; width: 100%; }
  .count { margin-left: 0; }
  .item {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "subject when" "from account" "code code";
    row-gap: 3px;
    padding-top: 10px;
    padding-bottom: 10px;
  }
  .item .when { grid-area: when; text-align: right; }
  .item .subject { grid-area: subject; }
  .item .from { grid-area: from; }
  .item .account { grid-area: account; color: var(--faint); font-size: 13px; text-align: right; }
  .item .codecell { grid-area: code; }
  .item .codecell:empty { display: none; }
  .preview { display: none; }
}

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