:root {
  color-scheme: light;
  --sidebar: #ececf2;
  --sidebar-line: rgba(0, 0, 0, 0.08);
  --list: #ffffff;
  --viewer: #ffffff;
  --text: #1d1d1f;
  --muted: #8a8a8e;
  --line: #e6e6eb;
  --hover: rgba(0, 0, 0, 0.05);
  --selected: rgba(0, 0, 0, 0.08);
  --accent: #0a84ff;
  --accent-ink: #ffffff;
  --toolbar: rgba(246, 246, 248, 0.86);
  --danger: #ff3b30;
  --flag: #ff9f0a;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  --mono: "SF Mono", ui-monospace, Menlo, monospace;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --sidebar: #1c1c1e;
  --sidebar-line: rgba(255, 255, 255, 0.08);
  --list: #161618;
  --viewer: #1c1c1e;
  --text: #f5f5f7;
  --muted: #98989d;
  --line: rgba(255, 255, 255, 0.08);
  --hover: rgba(255, 255, 255, 0.06);
  --selected: rgba(255, 255, 255, 0.1);
  --toolbar: rgba(28, 28, 30, 0.86);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--text);
  background: var(--sidebar);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(900px 420px at 50% -10%, rgba(10, 132, 255, 0.18), transparent 60%),
    var(--sidebar);
}
.login-card {
  width: min(420px, calc(100% - 32px));
  background: var(--viewer);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 36px 32px 28px;
  text-align: center;
}
.mark {
  width: 64px; height: 64px; margin: 0 auto 14px;
  border-radius: 16px; background: var(--accent); color: white;
  display: grid; place-items: center;
}
.login h1 { font-size: 28px; font-weight: 650; margin: 0 0 6px; letter-spacing: -0.03em; }
.login p { margin: 0 0 22px; color: var(--muted); }
.field { text-align: left; margin-bottom: 12px; }
.field span { display: block; font-size: 12px; color: var(--muted); margin: 0 0 6px; }
.field input, .search input, .compose input, .settings input, .settings textarea {
  width: 100%; border: 1px solid var(--line); background: var(--list);
  border-radius: 10px; padding: 11px 12px; outline: none;
}
.field input:focus, .compose input:focus, .settings textarea:focus, .settings input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.18);
}
.primary, .send {
  background: var(--accent); color: white; border: 0; border-radius: 10px;
  padding: 11px 16px; font-weight: 600;
}
.primary { width: 100%; margin-top: 6px; }
.primary:disabled, .send:disabled { opacity: 0.55; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 8px 0 0; }

.shell { height: 100%; display: grid; grid-template-columns: 228px 360px minmax(0, 1fr); }
.sidebar, .list, .viewer { min-height: 0; }
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-line);
  display: flex; flex-direction: column;
  padding: 14px 10px 10px;
}
.account {
  display: flex; gap: 10px; align-items: center;
  padding: 4px 8px 14px;
}
.avatar, .msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; color: white; font-weight: 650; font-size: 13px; flex: none;
}
.account strong { display: block; font-size: 13px; }
.account small, .muted { color: var(--muted); }
.account small { font-size: 11px; }
.nav { overflow: auto; flex: 1; padding-right: 2px; }
.nav h2 {
  margin: 14px 8px 6px; font-size: 11px; font-weight: 650;
  letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted);
}
.box, .icon-btn, .text-btn {
  border: 0; background: transparent; color: inherit;
}
.box {
  width: 100%; display: flex; align-items: center; gap: 8px;
  height: 30px; border-radius: 8px; padding: 0 8px; font-size: 13px; text-align: left;
}
.box svg { width: 16px; height: 16px; flex: none; opacity: 0.9; }
.box .count { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.box.active { background: var(--selected); font-weight: 600; }
.box:hover { background: var(--hover); }
.box.active:hover { background: var(--selected); }
.sidebar-foot { display: flex; gap: 6px; padding-top: 8px; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center;
}
.icon-btn:hover, .text-btn:hover { background: var(--hover); }
.icon-btn[aria-pressed="true"] { color: var(--accent); }

.list { background: var(--list); border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.list-head, .viewer-head {
  height: 54px; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: color-mix(in srgb, var(--list) 88%, transparent);
  backdrop-filter: blur(16px);
}
.list-head h1, .viewer-title { font-size: 17px; margin: 0; font-weight: 680; letter-spacing: -0.02em; }
.list-head .spacer, .viewer-head .spacer { flex: 1; }
.rows { overflow: auto; flex: 1; }
.row {
  width: 100%; border: 0; background: transparent; text-align: left; color: inherit;
  display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 8px;
  padding: 11px 14px 12px; border-bottom: 1px solid var(--line);
}
.row:hover { background: var(--hover); }
.row.selected { background: var(--accent); color: white; }
.row.selected .muted, .row.selected .snippet, .row.selected .when { color: rgba(255,255,255,0.82); }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; background: transparent; }
.row.unread .dot { background: var(--accent); }
.row.selected .dot { background: white; }
.who { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row.unread .who, .row.unread .subject { font-weight: 680; }
.subject, .snippet { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subject { font-size: 13px; }
.snippet { font-size: 12px; color: var(--muted); margin-top: 2px; }
.when { font-size: 12px; color: var(--muted); }
.flag { color: var(--flag); font-size: 12px; }
.clip { color: var(--muted); margin-right: 4px; }
.empty {
  height: 100%; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 24px;
}
.empty strong { display: block; color: var(--text); font-size: 20px; font-weight: 620; margin-bottom: 6px; }

.viewer { background: var(--viewer); display: flex; flex-direction: column; min-width: 0; }
.viewer-head { background: color-mix(in srgb, var(--viewer) 88%, transparent); }
.letter { overflow: auto; padding: 28px 36px 48px; }
.letter h2 { font-size: 28px; letter-spacing: -0.03em; margin: 0 0 18px; font-weight: 680; }
.meta { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 22px; }
.meta .msg-avatar { width: 40px; height: 40px; font-size: 16px; }
.meta .who { font-size: 15px; }
.meta .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.body { font-size: 15px; line-height: 1.5; overflow-wrap: anywhere; }
.body pre.plain { white-space: pre-wrap; font-family: var(--font); margin: 0; }
.body img { max-width: 100%; height: auto; }
.files { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }
.file {
  display: flex; align-items: center; gap: 8px; text-decoration: none; color: inherit;
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: var(--hover);
}
.banner {
  margin: 0 36px; padding: 8px 12px; border-radius: 10px; background: var(--hover);
  display: flex; justify-content: space-between; align-items: center; font-size: 13px;
}
.text-btn { border-radius: 8px; padding: 6px 8px; color: var(--accent); background: transparent; }

.search {
  width: min(420px, 40vw); margin: 0 auto;
}
.search input {
  height: 32px; border-radius: 8px; border: 0; background: var(--hover); padding: 0 12px;
}

.compose, .sheet-back {
  position: fixed; inset: 0; z-index: 20;
}
.sheet-back { background: rgba(0,0,0,0.28); }
.compose {
  width: min(760px, calc(100% - 40px));
  height: min(680px, calc(100% - 48px));
  margin: auto; background: var(--viewer); color: var(--text);
  border-radius: 14px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
  top: 24px; bottom: 24px; left: 0; right: 0;
}
.compose header, .settings header {
  height: 48px; display: flex; align-items: center; gap: 8px;
  padding: 0 12px; background: var(--toolbar); border-bottom: 1px solid var(--line);
}
.compose header strong { font-size: 13px; }
.compose header .spacer { flex: 1; }
.send { border-radius: 999px; padding: 6px 14px; }
.compose-fields { padding: 4px 16px 0; }
.line { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--line); min-height: 40px; }
.line label { width: 54px; color: var(--muted); font-size: 13px; }
.line input { border: 0; background: transparent; padding: 8px 0; border-radius: 0; }
.line input:focus { box-shadow: none; }
.editor {
  flex: 1; overflow: auto; padding: 16px; outline: none; font-size: 15px; line-height: 1.5;
}
.format { display: flex; gap: 4px; padding: 8px 12px; border-top: 1px solid var(--line); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 16px 8px; }
.chip { font-size: 12px; background: var(--hover); border-radius: 999px; padding: 4px 8px; }

.settings {
  position: fixed; z-index: 30; right: 18px; bottom: 18px; width: min(420px, calc(100% - 24px));
  background: var(--viewer); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden;
}
.settings textarea { min-height: 120px; resize: vertical; }
.settings .pad { padding: 14px; display: grid; gap: 10px; }
.toast {
  position: fixed; z-index: 40; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: #1d1d1f; color: white; border-radius: 999px; padding: 8px 14px; font-size: 13px;
}
html[data-theme="dark"] .toast { background: #f5f5f7; color: #1d1d1f; }
.suggest {
  position: absolute; z-index: 5; background: var(--viewer); border: 1px solid var(--line);
  border-radius: 10px; box-shadow: var(--shadow); min-width: 220px;
}
.suggest button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 10px; }
.suggest button:hover { background: var(--hover); }

@media (max-width: 980px) {
  .shell { grid-template-columns: 72px minmax(0, 1fr); }
  .shell.reading { grid-template-columns: 1fr; }
  .shell.reading .sidebar, .shell.reading .list { display: none; }
  .shell:not(.reading) .viewer { display: none; }
  .box span.label, .account div, .nav h2, .box .count { display: none; }
  .sidebar { padding-inline: 6px; }
  .search { display: none; }
}
