:root {
  --bg: #f0f4f8;
  --sidebar: #1e293b;
  --sidebar-text: #e2e8f0;
  --card: #ffffff;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --inbound: #0ea5e9;
  --outbound: #8b5cf6;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
  padding: 0 8px;
}

.brand-icon {
  font-size: 28px;
  background: var(--primary);
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand h1 { font-size: 18px; font-weight: 700; color: #fff; }
.subtitle { font-size: 12px; color: #94a3b8; }

.nav { display: flex; flex-direction: column; gap: 6px; flex: 1; }

.nav-btn {
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  text-align: left;
  padding: 12px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}

.nav-btn:hover { background: rgba(255,255,255,0.08); }
.nav-btn.active { background: var(--primary); color: #fff; font-weight: 600; }

.sidebar-footer { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,0.1); }
.active-account { font-size: 12px; color: #94a3b8; margin-bottom: 10px; word-break: break-all; }

.main { display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.topbar h2 { font-size: 20px; }

.status-badge {
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 20px;
  background: #f1f5f9;
  color: var(--muted);
}

.status-badge.ok { background: #dcfce7; color: #166534; }
.status-badge.warn { background: #fef3c7; color: #92400e; }
.status-badge.err { background: #fee2e2; color: #991b1b; }

.view { display: none; flex: 1; overflow: auto; padding: 20px 24px; }
.view.active { display: block; }

.toast {
  position: fixed;
  top: 20px;
  right: 24px;
  background: #1e293b;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  z-index: 1000;
  box-shadow: var(--shadow);
  max-width: 360px;
}
.toast.hidden { display: none; }
.toast.error { background: var(--danger); }
.toast.success { background: #16a34a; }

.inbox-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 16px;
  height: calc(100vh - 100px);
}

.thread-list-panel, .thread-detail-panel {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.panel-header {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.panel-header input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
}

.thread-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
}

.thread-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.thread-item:hover { background: #f8fafc; }
.thread-item.active { background: #eff6ff; border-left: 3px solid var(--primary); }

.thread-item .subject {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-item .meta {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
}

.badge.inbound { background: #e0f2fe; color: var(--inbound); }
.badge.outbound { background: #ede9fe; color: var(--outbound); }

.thread-detail {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.thread-detail.empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
}

.message-block {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
  background: #fafafa;
}

.message-block .msg-header {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px dashed var(--border);
}

.message-block .msg-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.6;
}

.reply-box {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 2px solid var(--border);
}

.reply-box h4 { margin-bottom: 12px; }

.form label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.form input, .form select, .form textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
}

.form textarea { min-height: 120px; resize: vertical; }

.form textarea.textarea-auto-grow,
textarea.textarea-auto-grow.bulk-textarea {
  resize: none;
  overflow-y: hidden;
}

.inline-form { display: flex; gap: 10px; align-items: flex-end; }
.inline-form input { flex: 1; }

.btn {
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  font-weight: 600;
  transition: background 0.15s;
}

.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover { background: #cbd5e1; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card h3 { margin-bottom: 12px; font-size: 16px; }

.info-card {
  background: linear-gradient(135deg, #f0fdf4 0%, #eff6ff 100%);
  border: 1px solid #86efac;
}

.info-card h3 { color: #166534; }

.compose-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.compose-tab {
  padding: 10px 16px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
}

.compose-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.compose-panel { display: none; }
.compose-panel.active { display: block; }

.account-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.account-tab {
  padding: 10px 16px;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.account-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.account-panel { display: none; }
.account-panel.active { display: block; }

.tab-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}

.account-tab.active .tab-badge {
  background: #fff;
  color: #ef4444;
}

.tab-badge.hidden {
  display: none;
}

.bulk-textarea { min-height: 160px; font-family: Consolas, monospace; font-size: 13px; }

.bulk-progress { margin: 12px 0; }
.bulk-progress.hidden { display: none; }

.send-progress-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.send-stat {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 8px;
  text-align: center;
}

.send-stat strong {
  display: block;
  font-size: 22px;
  margin-top: 4px;
  color: var(--text);
}

.send-stat.ok strong { color: #16a34a; }
.send-stat.fail strong { color: #dc2626; }

.send-stat-label {
  font-size: 12px;
  color: var(--muted);
}

.send-progress-pct {
  text-align: center;
  margin-top: 6px;
  font-weight: 600;
  color: var(--primary);
}

.send-progress-panel {
  margin: 0 24px 16px;
  padding: 16px 18px;
  background: #fff;
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.send-progress-panel.hidden { display: none; }

.send-progress-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.send-progress-panel-head h3 {
  font-size: 16px;
  margin: 0;
}

.send-result-inline {
  margin-top: 12px;
  padding: 12px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
  max-height: 420px;
  overflow: auto;
}

.send-result-summary {
  margin-bottom: 10px;
}

.send-result-note {
  margin: 0 0 10px;
}

.send-result-section {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.send-result-section.hidden {
  display: none;
}

.send-result-section-title {
  font-weight: 600;
  margin-bottom: 8px;
}

.send-result-list {
  margin: 0 0 8px;
  padding-left: 22px;
}

.send-result-plain-list {
  margin: 0;
  padding-left: 20px;
}

.resend-profile-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.resend-profile-list {
  list-style: none;
  margin: 0 0 14px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.resend-profile-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
}

.resend-profile-item.active {
  border-color: var(--primary);
  background: #f0f7ff;
}

.resend-profile-item-main {
  min-width: 0;
  flex: 1;
}

.resend-profile-item-title {
  font-weight: 600;
  font-size: 14px;
  word-break: break-all;
}

.resend-profile-item-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.resend-profile-badge {
  display: inline-block;
  padding: 6px 12px;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
}

.send-result-inline.hidden { display: none; }

.btn-sm {
  padding: 6px 12px;
  font-size: 13px;
}

.progress-bar {
  height: 8px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
  margin-top: 8px;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.3s;
}

.hint { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.hint code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: 12px; }

.account-list { list-style: none; }
.account-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.account-list li:last-child { border-bottom: none; }

.account-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.account-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

#invalid-accounts-card {
  border-left: 4px solid #dc2626;
}

#invalid-accounts-card.hidden-section,
.hidden-section {
  display: none;
}
  display: none;
}

.account-status {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 8px;
  font-weight: 600;
}

.account-status.ok {
  background: #dcfce7;
  color: #166534;
}

.account-status.invalid,
.account-status.missing {
  background: #fee2e2;
  color: #b91c1c;
}

.account-status.error {
  background: #fef3c7;
  color: #b45309;
}

.account-status.unknown {
  background: #f1f5f9;
  color: #64748b;
}

.account-pagination {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.account-pagination.hidden {
  display: none;
}

.account-pagination-inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.account-page-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.account-page-btn {
  min-width: 36px;
  padding: 6px 10px;
}

.account-page-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.pager-ellipsis {
  display: inline-flex;
  align-items: center;
  padding: 0 4px;
  color: var(--muted);
  user-select: none;
}

.pager-nav-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.recipient-preview-panel {
  margin: 8px 0 12px;
  padding: 12px 14px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.recipient-preview-panel.hidden {
  display: none;
}

.recipient-preview-title {
  margin-bottom: 8px;
  font-weight: 600;
}

.recipient-preview-list {
  margin: 0 0 10px;
  padding-left: 22px;
  font-size: 13px;
  line-height: 1.7;
  max-height: 220px;
  overflow-y: auto;
}

.recipient-preview-error {
  color: #dc2626;
  margin-bottom: 8px;
}

.recipient-preview-error.hidden {
  display: none;
}

.empty-hint {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
}

.help-list { padding-left: 20px; font-size: 14px; color: var(--muted); }
.help-list li { margin-bottom: 8px; }

.code-block {
  background: #1e293b;
  color: #e2e8f0;
  padding: 16px;
  border-radius: 8px;
  font-size: 13px;
  overflow-x: auto;
  line-height: 1.7;
}

.detail-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  max-width: 480px;
  width: 90%;
  margin: auto;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
}

.dialog-form { padding: 24px; }
.dialog-form h3 { margin-bottom: 8px; }
.send-preview {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin: 16px 0;
  font-size: 13px;
  white-space: pre-wrap;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }

.setup-banner {
  margin: 0 24px 16px;
  padding: 20px 24px;
  background: linear-gradient(135deg, #eff6ff 0%, #fef3c7 100%);
  border: 1px solid #93c5fd;
  border-radius: var(--radius);
  font-size: 14px;
  line-height: 1.7;
}

.setup-banner h3 { margin-bottom: 10px; color: #1e40af; }
.setup-banner ol { margin: 10px 0 14px 20px; }
.setup-banner li { margin-bottom: 6px; }
.setup-banner .setup-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

.setup-panel {
  grid-column: 1 / -1;
  padding: 40px;
  text-align: center;
  color: var(--muted);
}

.setup-panel h3 { color: var(--text); margin-bottom: 12px; font-size: 18px; }
.setup-panel .steps { text-align: left; max-width: 520px; margin: 20px auto; }
.setup-panel .steps li { margin-bottom: 8px; }

.domain-status {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  line-height: 1.7;
}

.domain-status code { font-size: 13px; word-break: break-all; }

#domain-apply-result {
  margin-top: 16px;
  padding: 12px 14px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
}

#domain-apply-result.hidden { display: none; }

.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.form-actions-inline {
  align-items: center;
  margin-top: -4px;
  margin-bottom: 8px;
}

.guide-card h4 {
  margin: 24px 0 12px;
  font-size: 17px;
  color: var(--text);
}

.guide-card h4:first-of-type {
  margin-top: 8px;
}

.guide-card h5 {
  margin: 16px 0 8px;
  font-size: 15px;
  color: var(--text);
}

.guide-section + .guide-section {
  border-top: 1px solid var(--border);
  padding-top: 4px;
}

.guide-list {
  margin: 0 0 12px;
  padding-left: 22px;
  line-height: 1.7;
}

.guide-list li {
  margin-bottom: 6px;
}

.guide-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0 16px;
  font-size: 14px;
}

.guide-table th,
.guide-table td {
  border: 1px solid var(--border);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

.guide-table th {
  background: #f8fafc;
  font-weight: 600;
}

.guide-table code {
  word-break: break-all;
}

.guide-panel { display: none; }
.guide-panel.active { display: block; }

.resend-panel { display: none; }
.resend-panel.active { display: block; }

.resend-tabs {
  margin-bottom: 16px;
}

.guide-code {
  margin: 10px 0 14px;
  padding: 12px 14px;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 14px;
  cursor: pointer;
}

.checkbox-label input {
  width: auto;
}

.form label.optional { color: var(--muted); font-size: 14px; }

.ok-text { color: #16a34a; font-weight: 600; }
.warn-text { color: #d97706; font-weight: 600; }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; padding: 12px; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { width: 100%; }
  .inbox-layout { grid-template-columns: 1fr; height: auto; }
}

.auth-page {
  min-height: 100vh;
  background: linear-gradient(135deg, #eff6ff 0%, #f8fafc 50%, #f0fdf4 100%);
}

.hidden {
  display: none !important;
}

.auth-shell,
.admin-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.admin-shell {
  display: block;
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}

.auth-brand h1 {
  margin: 0;
  font-size: 22px;
}

.auth-hint {
  margin-top: 16px;
}

.auth-error {
  margin-top: 12px;
  color: #dc2626;
}

.admin-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
}

.admin-topbar h1 {
  margin: 0 0 4px;
}

.admin-topbar-actions {
  display: flex;
  gap: 8px;
}

.admin-create-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto auto;
  gap: 10px;
  align-items: end;
}

.web-user-info {
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.web-user-name {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.85);
  margin-bottom: 6px;
}

.sidebar-link {
  display: inline-block;
  font-size: 12px;
  color: #93c5fd;
  text-decoration: none;
}

.sidebar-link:hover {
  color: #fff;
}

@media (max-width: 720px) {
  .admin-create-form {
    grid-template-columns: 1fr;
  }
}
