:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --ink: #1a1d29;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #4f46e5;
  --brand-soft: #eef2ff;
  --danger: #dc2626;
  --ok: #059669;
  --shadow: 0 8px 24px rgba(17, 24, 39, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  line-height: 1.55;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 28px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--brand); color: white;
  display: grid; place-items: center;
  font-size: 22px; font-weight: 700;
}
.brand h1 { margin: 0; font-size: 18px; }
.brand p { margin: 0; color: var(--muted); font-size: 12px; }

.tabs { display: flex; gap: 6px; background: var(--bg); padding: 4px; border-radius: 10px; }
.tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 8px 16px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.tab.active { background: var(--panel); color: var(--brand); font-weight: 600; box-shadow: var(--shadow); }

main { padding: 24px 28px 48px; max-width: 1440px; margin: 0 auto; }
.view { display: none; }
.view.active { display: block; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px;
}

#view-inbox { display: none; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
#view-inbox.active { display: grid; }

h2 { margin: 0 0 8px; font-size: 16px; }
h3 { margin: 24px 0 8px; font-size: 14px; }
.section-title { margin-top: 28px; }
.hint { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.error { color: var(--danger); font-size: 12px; min-height: 18px; margin: 8px 0; }

.input-group { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.input-group input { flex: 1; min-width: 0; }
.at { color: var(--muted); font-weight: 600; }
.domain-suffix { color: var(--muted); font-size: 12px; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

input[type="text"], input[type="password"] {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 9px; font: inherit; background: #fff; color: var(--ink);
}
input:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }

button { font: inherit; cursor: pointer; }
button.primary {
  width: 100%; border: 0; border-radius: 9px;
  background: var(--brand); color: white; padding: 10px 14px; font-weight: 600;
}
button.primary:hover { background: #4338ca; }
button.ghost {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 8px; padding: 7px 12px;
}
button.ghost:hover { border-color: var(--brand); color: var(--brand); }

.created-box {
  margin-top: 16px; padding: 14px; border-radius: 10px;
  background: var(--brand-soft); border: 1px solid #c7d2fe;
}
.created-title { font-weight: 700; color: var(--brand); margin-bottom: 6px; }
.created-address { font-weight: 700; font-size: 15px; word-break: break-all; }
.token-row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.token-row code {
  flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: 11px;
  background: #fff; padding: 8px; border-radius: 6px; border: 1px solid #c7d2fe;
}

.address-list { display: flex; flex-direction: column; gap: 6px; }
.address-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; cursor: pointer;
}
.address-item:hover { border-color: #c7d2fe; }
.address-item.active { border-color: var(--brand); background: var(--brand-soft); }
.address-item span { overflow-wrap: anywhere; font-size: 13px; }
.address-item button { border: 0; background: transparent; color: var(--muted); padding: 2px 4px; }
.address-item button:hover { color: var(--danger); }

.content-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.mail-layout { display: grid; grid-template-columns: minmax(240px, 0.9fr) minmax(0, 1.3fr); gap: 16px; }
.mail-list { border-right: 1px solid var(--line); padding-right: 12px; max-height: 68vh; overflow: auto; }
.mail-item {
  border: 1px solid transparent; border-radius: 9px; padding: 10px 12px; cursor: pointer; margin-bottom: 4px;
}
.mail-item:hover { background: var(--bg); }
.mail-item.active { background: var(--brand-soft); border-color: #c7d2fe; }
.mail-item .subject { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item .meta { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item .snippet { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-detail { padding-left: 4px; max-height: 68vh; overflow: auto; }
.mail-detail h3 { margin: 0 0 4px; font-size: 17px; overflow-wrap: anywhere; }
.mail-meta { color: var(--muted); font-size: 12px; display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.mail-body {
  margin-top: 12px; padding: 14px; border: 1px solid var(--line);
  border-radius: 9px; background: #fbfbfd; white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: 46vh; overflow: auto;
}
.attachment-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.attachment {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; text-decoration: none; color: var(--ink); font-size: 12px;
}
.attachment:hover { border-color: var(--brand); color: var(--brand); }

.empty { color: var(--muted); padding: 28px 8px; text-align: center; }
.hidden { display: none !important; }

.settings-panel { max-width: 900px; }
.domain-form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: center; }
.domain-form button { grid-column: 1 / -1; }
.domain-form label { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.notice { color: var(--muted); font-size: 12px; background: var(--bg); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; }
.domain-list { display: flex; flex-direction: column; gap: 6px; }
.domain-item { display: flex; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; }
.badge { font-size: 11px; border-radius: 999px; padding: 2px 8px; background: var(--bg); color: var(--muted); }
.badge.ok { background: #ecfdf5; color: var(--ok); }
.dns-list { padding-left: 20px; color: var(--muted); }
.dns-list li { margin-bottom: 6px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #111827; color: white; padding: 10px 18px; border-radius: 9px;
  box-shadow: 0 8px 28px rgba(0,0,0,.2); z-index: 50;
}

@media (max-width: 900px) {
  main { padding: 16px; }
  #view-inbox.active { grid-template-columns: 1fr; }
  .mail-layout { grid-template-columns: 1fr; }
  .mail-list { border-right: 0; border-bottom: 1px solid var(--line); padding: 0 0 10px; max-height: 240px; }
  .mail-detail { max-height: none; }
  .domain-form { grid-template-columns: 1fr; }
}
