: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; }

.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; }

.bulk-textarea { min-height: 160px; font-family: Consolas, monospace; font-size: 13px; }

.bulk-progress { margin: 12px 0; }
.bulk-progress.hidden { display: none; }

.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; }

.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%;
}

.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; }

@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; }
}
