* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: #fafafa; color: #111;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }

/* header */
.top {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 16px;
  background: rgba(255,255,255,0.92); backdrop-filter: blur(12px);
  border-bottom: 1px solid #eee;
}
.brand { display: flex; align-items: center; gap: 8px; color: #111; font-weight: 600; }
.brand .dot { width: 22px; height: 22px; border-radius: 6px; background: #111; color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; }
.brand .sub { font-weight: 400; font-size: 13px; color: #6b7280; margin-left: 8px; padding-left: 8px; border-left: 1px solid #e5e7eb; }
#nav { display: flex; gap: 12px; align-items: center; font-size: 14px; }
#nav .me { color: #111; font-weight: 500; }
#nav a, #nav button { color: #374151; background: transparent; border: 0; padding: 6px 10px; border-radius: 6px; }
#nav a:hover, #nav button:hover { background: #f3f4f6; }
#nav .nav-badge {
  position: relative; padding: 6px; display: inline-flex; align-items: center; justify-content: center;
}
#nav .nav-badge .bell { width: 18px; height: 18px; color: #6b7280; }
#nav .nav-badge.has .bell { color: #2563eb; }
#nav .nav-badge .dot {
  position: absolute; top: -2px; right: -4px; min-width: 16px; height: 16px; padding: 0 4px;
  background: #dc2626; color: #fff; border-radius: 10px; font-size: 10px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}

/* main */
main { max-width: 1000px; margin: 0 auto; padding: 24px 16px 80px; }

/* card */
.card { background: #fff; border: 1px solid #eee; border-radius: 12px; padding: 18px; margin-bottom: 14px; }
.card h2 { margin: 0 0 12px; font-size: 16px; font-weight: 600; }
.muted { color: #6b7280; font-size: 13px; }

/* auth */
.auth-card { max-width: 360px; margin: 60px auto; }
.auth-card h1 { font-size: 20px; margin: 0 0 6px; }
.auth-tabs { display: flex; border-bottom: 1px solid #eee; margin-bottom: 16px; }
.auth-tabs button {
  flex: 1; background: none; border: 0; padding: 12px;
  border-bottom: 2px solid transparent; color: #6b7280; font-weight: 500;
}
.auth-tabs button.on { color: #111; border-bottom-color: #111; }
.field { display: block; margin: 10px 0; }
.field label { display: block; font-size: 13px; color: #374151; margin-bottom: 4px; }
.field input {
  width: 100%; padding: 10px 12px; border: 1px solid #e5e7eb; border-radius: 8px;
  font-size: 14px; outline: none;
}
.field input:focus { border-color: #111; box-shadow: 0 0 0 3px rgba(17,17,17,.08); }
.btn-primary {
  width: 100%; padding: 11px; margin-top: 8px;
  background: #111; color: #fff; border: 0; border-radius: 8px; font-weight: 500;
}
.btn-primary:hover { background: #2563eb; }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.err { color: #dc2626; font-size: 13px; min-height: 18px; margin-top: 6px; }
.hint { background: #f3f4f6; border-radius: 8px; padding: 10px 12px; font-size: 12px; color: #4b5563; margin-top: 14px; }
.hint code { background: #fff; padding: 1px 4px; border-radius: 3px; }

/* addr card */
.addr-card {
  display: block;
  background: linear-gradient(135deg, #ffffff 0%, #fafbff 100%);
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 8px 24px -8px rgba(79,70,229,0.06);
  margin-bottom: 20px;
  transition: box-shadow 0.2s;
}
.addr-card:hover { box-shadow: 0 1px 3px rgba(0,0,0,0.04), 0 12px 32px -8px rgba(79,70,229,0.10); }

.addr-card-header { margin-bottom: 14px; }
.addr-card-title {
  display: flex; align-items: center; gap: 10px;
}
.addr-card-title svg { width: 22px; height: 22px; color: #4f46e5; flex-shrink: 0; }
.addr-card-title h3 {
  margin: 0; font-size: 16px; font-weight: 600; color: #111; flex: 1;
  letter-spacing: -0.01em;
}
.addr-count {
  font-size: 12px; font-weight: 500; color: #6b7280;
  background: #f3f4f6; padding: 3px 10px; border-radius: 999px;
  font-variant-numeric: tabular-nums;
}
.addr-count.full { background: #fef2f2; color: #dc2626; }
.addr-hint {
  margin-top: 4px; padding-left: 32px;
  font-size: 12px; color: #9ca3af;
}

.addr-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.addr-row {
  display: flex; align-items: center; gap: 12px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  padding: 12px 14px;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 14px;
  transition: all 0.15s ease;
  position: relative;
}
.addr-row:hover {
  border-color: #c7d2fe;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px -4px rgba(79,70,229,0.12);
}
.addr-row.is-primary {
  background: linear-gradient(135deg, #eef2ff 0%, #f5f3ff 100%);
  border-color: #c7d2fe;
}
.addr-row.loading { opacity: 0.5; pointer-events: none; }

.addr-row-main {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 10px;
  overflow: hidden;
}
.addr-full {
  color: #111; font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.addr-row .badge {
  display: inline-flex; align-items: center; gap: 3px;
  font-family: system-ui, sans-serif;
  font-size: 10px; font-weight: 600;
  padding: 3px 8px; border-radius: 999px;
  flex-shrink: 0;
  letter-spacing: 0.02em;
}
.addr-row .badge svg { width: 10px; height: 10px; }
.addr-row .badge.primary {
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: #fff;
}
.addr-row .badge.alias {
  background: #f3f4f6; color: #6b7280;
  border: 1px solid #e5e7eb;
}

.addr-row-actions { display: flex; gap: 6px; flex-shrink: 0; }
.act-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: #f9fafb; color: #374151;
  border: 1px solid #e5e7eb;
  padding: 6px 10px; border-radius: 8px;
  font-size: 12px; font-weight: 500;
  font-family: system-ui, sans-serif;
  cursor: pointer;
  transition: all 0.12s ease;
}
.act-btn svg { width: 13px; height: 13px; }
.act-btn:hover { background: #f3f4f6; border-color: #d1d5db; }
.act-btn.copy:hover { background: #eef2ff; border-color: #c7d2fe; color: #4f46e5; }
.act-btn.setprimary:hover { background: #fef3c7; border-color: #fde68a; color: #b45309; }
.act-btn.deladdr { padding: 6px 8px; }
.act-btn.deladdr:hover { background: #fef2f2; border-color: #fecaca; color: #dc2626; }

.addr-add-row {
  display: flex; gap: 8px; align-items: stretch;
}
.addr-add-box {
  flex: 1; min-width: 0;
  display: flex; align-items: center;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 0 12px;
  transition: all 0.15s;
}
.addr-add-box:focus-within {
  border-color: #4f46e5;
  box-shadow: 0 0 0 3px rgba(79,70,229,0.12);
}
.addr-add-box input {
  flex: 1; min-width: 0;
  border: 0; background: transparent; outline: none;
  padding: 10px 0;
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 14px; color: #111;
}
.addr-add-box input::placeholder { color: #9ca3af; font-family: system-ui, sans-serif; }
.addr-add-box .addr-suffix {
  color: #9ca3af;
  font-family: ui-monospace, monospace;
  font-size: 13px;
  user-select: none;
}
.addr-add-box .addr-check {
  margin-left: 6px; font-size: 12px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 3px;
  font-family: system-ui, sans-serif;
  min-width: 60px;
}
.addr-add-box.pending { border-color: #d1d5db; }
.addr-add-box.pending .addr-check { color: #9ca3af; }
.addr-add-box.ok { border-color: #10b981; box-shadow: 0 0 0 3px rgba(16,185,129,0.12); }
.addr-add-box.ok .addr-check { color: #10b981; }
.addr-add-box.no { border-color: #ef4444; box-shadow: 0 0 0 3px rgba(239,68,68,0.12); }
.addr-add-box.no .addr-check { color: #ef4444; }
.primary-btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
  color: #fff;
  border: 0;
  padding: 0 18px;
  border-radius: 10px;
  font-size: 13px; font-weight: 600;
  font-family: system-ui, sans-serif;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(79,70,229,0.2);
}
.primary-btn svg { width: 14px; height: 14px; }
.primary-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79,70,229,0.3);
}
.primary-btn:active:not(:disabled) { transform: translateY(0); }
.primary-btn:disabled {
  background: #e5e7eb; color: #9ca3af;
  cursor: not-allowed; box-shadow: none;
}
.primary-btn.loading-btn { opacity: 0.7; pointer-events: none; }

.addr-foot {
  display: flex; align-items: center; gap: 6px;
  margin-top: 12px;
  font-size: 11px; color: #9ca3af;
  padding: 0 2px;
}
.addr-foot svg { width: 12px; height: 12px; flex-shrink: 0; }
.addr-foot code {
  background: #f3f4f6; padding: 1px 4px; border-radius: 3px;
  font-size: 10px; color: #6b7280;
}

/* toast */
#toast-host {
  position: fixed; top: 70px; right: 20px; z-index: 999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  min-width: 280px; max-width: 420px;
  padding: 12px 16px;
  border-radius: 10px;
  background: #fff;
  border: 1px solid #e5e7eb;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08), 0 12px 32px -8px rgba(0,0,0,0.12);
  font-size: 13px; color: #111;
  opacity: 0; transform: translateX(20px);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: auto;
}
.toast.show { opacity: 1; transform: translateX(0); }
.toast.success { border-left: 3px solid #10b981; }
.toast.success .toast-icon { color: #10b981; }
.toast.error { border-left: 3px solid #dc2626; }
.toast.error .toast-icon { color: #dc2626; }
.toast.info { border-left: 3px solid #4f46e5; }
.toast.info .toast-icon { color: #4f46e5; }
.toast-icon { display: flex; align-items: center; flex-shrink: 0; }
.toast-icon svg { width: 18px; height: 18px; }
.toast-msg { flex: 1; line-height: 1.45; }

/* responsive */
@media (max-width: 640px) {
  .addr-card { padding: 16px; border-radius: 14px; }
  .addr-row { padding: 10px 12px; flex-wrap: wrap; gap: 10px; }
  .addr-row-actions { width: 100%; justify-content: flex-end; }
  .act-btn span { display: none; }
  .act-btn.copy span,
  .act-btn.setprimary span { display: inline; }
  .act-btn { padding: 6px 8px; }
  .addr-add-row { flex-direction: column; }
  .primary-btn { padding: 10px 18px; justify-content: center; }
  #toast-host { top: auto; bottom: 20px; right: 12px; left: 12px; }
  .toast { min-width: 0; max-width: none; }
}

/* toolbar */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.toolbar .pill {
  background: #fff; border: 1px solid #e5e7eb; border-radius: 999px; padding: 6px 14px;
  font-size: 13px; color: #374151;
}
.toolbar .pill.active { background: #111; color: #fff; border-color: #111; }
.toolbar .pill .ct { font-weight: 700; opacity: .7; font-size: 12px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.search-box {
  position: relative; flex: 1; min-width: 200px; display: flex; align-items: center;
  border: 1px solid #e5e7eb; border-radius: 8px; padding: 0 10px;
}
.search-box input { flex: 1; border: 0; outline: 0; padding: 8px 4px; background: transparent; font-size: 14px; }
.search-box .search-ic { width: 16px; height: 16px; color: #9ca3af; flex-shrink: 0; }
.search-box button {
  background: transparent; border: 0; color: #9ca3af; font-size: 18px; padding: 0 4px; line-height: 1;
}

/* actions row */
.actions-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* buttons */
.btn-sm {
  background: #111; color: #fff; border: 0; border-radius: 6px;
  padding: 5px 12px; font-size: 12px; font-weight: 500;
}
.btn-sm:hover { background: #2563eb; }
.btn-sm.ghost { background: transparent; color: #374151; border: 1px solid #e5e7eb; }
.btn-sm.ghost:hover { background: #f3f4f6; color: #111; }
.btn-sm.danger { background: #dc2626; }
.btn-sm.danger:hover { background: #b91c1c; }
.btn-sm:disabled { opacity: .4; cursor: not-allowed; }

.batch-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* message list */
.list { background: #fff; border: 1px solid #eee; border-radius: 12px; overflow: hidden; }
.item {
  display: grid; grid-template-columns: 24px 28px 36px 1fr 24px; gap: 10px; padding: 12px 14px;
  border-bottom: 1px solid #f1f1f1; cursor: pointer; align-items: center;
}
.item:last-child { border-bottom: 0; }
.item:hover { background: #fafafa; }
.item.selected { background: #eff6ff; }
.item.unread { background: #fff; }
.item.unread .from-name, .item.unread .subj { font-weight: 700; color: #111; }

.item .check {
  width: 16px; height: 16px; cursor: pointer; accent-color: #2563eb;
}
.star-btn {
  background: transparent; border: 0; font-size: 18px; color: #d1d5db; padding: 0; line-height: 1;
  cursor: pointer;
}
.star-btn:hover { color: #f59e0b; }
.star-btn.on { color: #f59e0b; }
.star-btn-lg { background: transparent; border: 0; font-size: 28px; color: #d1d5db; padding: 0; line-height: 1; cursor: pointer; }
.star-btn-lg.on { color: #f59e0b; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #ec4899); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px;
}
.item .meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.item .row1 { display: flex; align-items: baseline; gap: 8px; }
.item .from-name { font-weight: 600; font-size: 14px; color: #111; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 50%; }
.item .from-dom { font-size: 11px; color: #9ca3af; font-family: ui-monospace, monospace; }
.item .time { font-size: 12px; color: #9ca3af; flex-shrink: 0; margin-left: auto; }
.item .subj { font-size: 13px; color: #6b7280; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .badge {
  display: inline-block; width: 18px; text-align: center; font-size: 12px; color: #f59e0b;
}

.empty { text-align: center; padding: 60px 20px; color: #9ca3af; }
.empty h3 { color: #6b7280; font-weight: 500; margin: 0 0 6px; }

/* detail */
.back {
  display: inline-flex; align-items: center; gap: 6px;
  color: #6b7280; font-size: 13px; padding: 6px 10px; border-radius: 6px;
}
.back:hover { background: #f3f4f6; }
.detail-head { padding: 18px; background: #fff; border: 1px solid #eee; border-radius: 12px; margin-bottom: 12px; }
.detail-title-row { display: flex; align-items: flex-start; gap: 12px; }
.detail-head h1 { margin: 0; font-size: 20px; line-height: 1.4; flex: 1; }
.detail-meta { color: #6b7280; font-size: 13px; margin-top: 8px; }
.detail-meta .from-dom { font-family: ui-monospace, monospace; background: #f3f4f6; padding: 1px 6px; border-radius: 4px; margin-left: 6px; }
.detail-actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.body-card { background: #fff; border: 1px solid #eee; border-radius: 12px; padding: 0; overflow: hidden; }
.body-card .body { padding: 20px; font-size: 14px; line-height: 1.65; color: #1f2937; }
.body-card .body img { max-width: 100%; height: auto; }
.body-card pre, .body-card code { font-family: ui-monospace, monospace; }

.translate-card { background: #fffbeb; border: 1px solid #fde68a; border-radius: 12px; margin-bottom: 12px; }
.translate-card.hidden { display: none; }
.translate-head { padding: 10px 14px; font-weight: 600; color: #92400e; border-bottom: 1px solid #fde68a; font-size: 13px; }
.translate-body { margin: 0; padding: 14px; white-space: pre-wrap; font-family: inherit; font-size: 14px; color: #111; }

.atts { padding: 14px 18px; border-top: 1px solid #f1f1f1; background: #fafafa; }
.atts h4 { margin: 0 0 8px; font-size: 13px; color: #6b7280; font-weight: 500; }
.att-item {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 10px; background: #fff; border: 1px solid #eee; border-radius: 6px; margin-bottom: 6px;
}
.att-thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 4px; background: #f3f4f6; flex-shrink: 0; }
.att-info { flex: 1; min-width: 0; }
.att-info .name { font-size: 13px; word-break: break-all; display: block; }
.att-info .size { color: #9ca3af; font-size: 12px; }
.att-actions { display: flex; gap: 6px; flex-shrink: 0; }

.del-btn { background: transparent; border: 1px solid #e5e7eb; color: #dc2626; padding: 6px 12px; border-radius: 6px; font-size: 13px; }
.del-btn:hover { background: #fee2e2; }

/* footer */
.ft { text-align: center; padding: 30px 16px; color: #9ca3af; font-size: 13px; border-top: 1px solid #eee; }
.ft a { color: #6b7280; }

/* responsive */
@media (max-width: 600px) {
  main { padding: 16px 12px 60px; }
  .brand .sub { display: none; }
  .item { grid-template-columns: 20px 24px 32px 1fr 20px; gap: 6px; padding: 10px 8px; }
  .item .from-name { max-width: 40%; }
  .toolbar { gap: 8px; }
}