:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --surface-alt: #f3f0ea;
  --border: #e7e2d6;
  --border-strong: #d8d2c2;
  --ink: #1b1a17;
  --ink-soft: #54514a;
  --muted: #8a857a;
  --accent: #4338ca;
  --accent-hover: #3730a3;
  --accent-soft: #eef1ff;
  --success: #0f7a3c;
  --danger: #b8310f;
  --warn: #b8860b;
  --shadow-sm: 0 1px 2px rgba(27, 26, 23, 0.04);
  --shadow-md: 0 4px 16px rgba(27, 26, 23, 0.06);
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 64px 24px;
}
.container.wide { max-width: 1180px; padding: 28px 28px 64px; }

h1 { font-size: 32px; margin: 0 0 8px; letter-spacing: -0.02em; font-weight: 700; }
h2 { font-size: 18px; margin: 0 0 10px; letter-spacing: -0.01em; font-weight: 600; }
.muted { color: var(--muted); font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  margin-top: 20px;
  box-shadow: var(--shadow-sm);
}

label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: var(--ink-soft); }
input[type="text"], input[type="email"], input[type="password"], textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 16px;
  transition: background 0.12s, transform 0.04s;
  letter-spacing: 0.01em;
}
button:hover { background: var(--accent-hover); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--border-strong);
}
button.ghost:hover { background: var(--surface-alt); }
button.sm { padding: 6px 12px; font-size: 13px; margin-top: 0; }

.error { color: var(--danger); font-size: 14px; margin-top: 10px; }
.success { color: var(--success); font-size: 14px; margin-top: 10px; }

.tabs {
  display: flex;
  gap: 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.tab {
  padding: 10px 0;
  cursor: pointer;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-weight: 500;
  font-size: 14px;
  transition: color 0.12s, border-color 0.12s;
}
.tab:hover { color: var(--ink-soft); }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .brand {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}
.topbar .brand::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 9px;
  vertical-align: middle;
  transform: translateY(-1px);
}
.topbar-right { display: flex; align-items: center; gap: 14px; }
.address-pill {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--accent-hover);
  border-radius: 999px;
  padding: 5px 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 500;
  border: 1px solid rgba(67, 56, 202, 0.15);
}

/* ======= Mail layout ======= */
.mail {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  margin-top: 8px;
  min-height: calc(100vh - 120px);
}
@media (max-width: 860px) {
  .mail { grid-template-columns: 1fr; }
  .mail.has-open .mail-list { display: none; }
  .mail:not(.has-open) .mail-detail { display: none; }
}

.mail-list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  align-self: start;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  display: flex;
  flex-direction: column;
}
.mail-list-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
}
.mail-list-header h2 { margin: 0; }
.mail-list-body { overflow-y: auto; flex: 1; }
.email-list { list-style: none; padding: 0; margin: 0; }
.email-list li {
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
  position: relative;
}
.email-list li:last-child { border-bottom: 0; }
.email-list li:hover { background: var(--surface-alt); }
.email-list li.active {
  background: var(--accent-soft);
}
.email-list li.active::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
}
.email-list .row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.email-list .from { font-weight: 600; font-size: 14px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-list .date { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.email-list .subject {
  font-size: 13.5px;
  color: var(--ink-soft);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.email-list .preview {
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}

.mail-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.mail-detail-header {
  padding: 24px 28px 18px;
  border-bottom: 1px solid var(--border);
}
.mail-detail-header .subject {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 14px;
  line-height: 1.3;
}
.sender {
  display: flex;
  align-items: center;
  gap: 12px;
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
}
.avatar.me { background: var(--ink); }
.sender-meta { flex: 1; min-width: 0; }
.sender-name { font-weight: 600; font-size: 14.5px; }
.sender-email { color: var(--muted); font-size: 13px; }
.sender-date { color: var(--muted); font-size: 13px; white-space: nowrap; }

.mail-body {
  padding: 22px 28px;
  font-size: 15px;
  line-height: 1.6;
  color: var(--ink);
}
.mail-body pre {
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: inherit;
  font-size: 15px;
  margin: 0;
}

.thread-item {
  border-top: 1px solid var(--border);
  padding: 22px 28px;
  background: var(--surface);
}
.thread-item.sent { background: var(--surface-alt); }
.thread-item .sender { margin-bottom: 12px; }

.reply-box {
  border-top: 1px solid var(--border);
  padding: 20px 28px 24px;
  background: var(--bg);
}
.reply-box-collapsed {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 14px 16px;
  cursor: text;
  color: var(--muted);
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.reply-box-collapsed:hover { border-color: var(--accent); color: var(--ink-soft); }
.reply-box-collapsed .icon { color: var(--accent); }
.reply-open {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  overflow: hidden;
}
.reply-to {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--ink-soft);
  background: var(--surface-alt);
}
.reply-to b { color: var(--ink); font-weight: 600; }
.reply-open textarea {
  border: 0;
  border-radius: 0;
  padding: 14px;
  min-height: 140px;
}
.reply-open textarea:focus { box-shadow: none; }
.reply-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.reply-actions button { margin-top: 0; }
.reply-status { font-size: 13px; color: var(--muted); }
.reply-status.err { color: var(--danger); }
.reply-status.ok { color: var(--success); }

.empty {
  text-align: center;
  padding: 72px 24px;
  color: var(--muted);
}
.empty .emoji {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.5;
}
.empty strong { color: var(--ink-soft); display: block; font-weight: 600; margin-bottom: 4px; }

.detail-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: var(--muted);
  font-size: 14px;
  padding: 72px 24px;
  text-align: center;
}

.claim-hero {
  background: linear-gradient(180deg, var(--accent-soft) 0%, var(--surface) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  margin-top: 20px;
}
.claim-hero h2 { font-size: 22px; margin-bottom: 8px; }
.claim-hero .preview-box {
  margin-top: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  color: var(--accent-hover);
  min-height: 20px;
}

.landing-tagline {
  color: var(--ink-soft);
  font-size: 16px;
  margin: 0 0 28px;
  line-height: 1.55;
}
