:root {
  --bg: #eef1f6;
  --surface: #fff;
  --surface-2: #f7f9fc;
  --line: #e4e8ef;
  --line-strong: #d0d7e2;
  --text: #1f2329;
  --muted: #8a9199;
  --accent: #1e6fff;
  --accent-hover: #1558d6;
  --accent-soft: #e8f1ff;
  --accent-border: #b8d4ff;
  --warn: #e6a23c;
  --warn-soft: #fdf6ec;
  --danger: #f56c6c;
  --danger-soft: #fef0f0;
  --success: #67c23a;
  --success-soft: #f0f9eb;
  --shadow: 0 2px 12px rgba(15, 35, 75, 0.08);
  --radius: 6px;
  --sidebar-w: 496px;
  --list-w: 340px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
button, input, textarea { font: inherit; }
.hidden { display: none !important; }

/* ── Login ── */
.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px;
  background: linear-gradient(135deg, #e8f1ff 0%, #f5f7fa 50%, #eef1f6 100%);
}
.login-panel {
  width: min(720px, 100%);
  display: grid;
  grid-template-columns: 1fr 300px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.login-copy, .login-form { padding: 40px 32px; }
.login-copy h1 { margin: 8px 0 12px; font-size: 26px; color: var(--accent); }
.login-form { display: grid; gap: 14px; align-content: center; border-left: 1px solid var(--line); background: var(--surface-2); }
.eyebrow, .section-label, .field-label, .helper-text, .form-note { color: var(--muted); font-size: 12px; }
.muted { color: var(--muted); }

.field, .search-field { display: grid; gap: 6px; }
.field input, .search-field input, .compact-compose input, .compact-compose textarea, .reply-strip textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.field input:focus, .search-field input:focus, .compact-compose input:focus,
.compact-compose textarea:focus, .reply-strip textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(30, 111, 255, .12);
}
.field input, .search-field input, .compact-compose input { min-height: 36px; padding: 0 12px; }
.compact-compose textarea, .reply-strip textarea { min-height: 120px; padding: 12px; resize: vertical; }

.primary-button, .ghost-button, .danger-button, .accent-outline-button {
  min-height: 34px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0 14px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.primary-button { background: var(--accent); color: #fff; }
.primary-button:hover { background: var(--accent-hover); }
.primary-button:disabled { opacity: .55; cursor: not-allowed; }
.ghost-button { background: var(--surface); color: var(--text); border-color: var(--line-strong); }
.ghost-button:hover { background: var(--surface-2); border-color: var(--accent-border); color: var(--accent); }
.accent-outline-button { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-border); }
.accent-outline-button:hover { background: #d6e7ff; }
.danger-button { background: var(--danger-soft); color: var(--danger); border-color: rgba(245, 108, 108, .3); }
.danger-button:hover { background: #fde2e2; }
.tiny-button { min-height: 28px; padding: 0 10px; font-size: 12px; }

/* ── App Shell ── */
.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
}

/* ── Hero Banner ── */
.hero-banner {
  background: linear-gradient(180deg, #1a5fd4 0%, #1e6fff 42%, #f7f9fc 42%, #fff 100%);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.hero-banner-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  color: #fff;
}
.brand-block { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: rgba(255,255,255,.18);
  display: grid; place-items: center;
  font-size: 20px;
}
.brand-block h1 { margin: 0; font-size: 18px; font-weight: 600; color: #fff; }
.hero-banner-tools { display: flex; gap: 8px; align-items: center; }
.hero-banner-tools .search-field input {
  min-height: 36px;
  width: min(320px, 36vw);
  background: rgba(255,255,255,.14);
  border-color: rgba(255,255,255,.28);
  color: #fff;
}
.hero-banner-tools .search-field input::placeholder { color: rgba(255,255,255,.65); }
.hero-banner-tools .search-field input:focus { background: #fff; color: var(--text); border-color: #fff; box-shadow: none; }
.hero-banner-tools .ghost-button { background: rgba(255,255,255,.14); color: #fff; border-color: rgba(255,255,255,.28); }
.hero-banner-tools .ghost-button:hover { background: rgba(255,255,255,.24); color: #fff; }
.hero-banner-tools .primary-button { background: #fff; color: var(--accent); min-height: 36px; font-weight: 600; }
.hero-banner-tools .primary-button:hover { background: #f0f5ff; }

.hero-banner-main {
  text-align: center;
  padding: 8px 24px 20px;
}
.hero-banner-eyebrow {
  margin: 0 0 10px;
  font-size: 13px;
  color: rgba(255,255,255,.88);
  letter-spacing: .5px;
}
.hero-email-box {
  display: inline-block;
  max-width: min(920px, 92vw);
  padding: 14px 28px;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 8px 28px rgba(16, 52, 120, .18);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: clamp(18px, 2.4vw, 28px);
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .5px;
  word-break: break-all;
  line-height: 1.35;
}
.hero-domain-hint {
  margin: 8px 0 14px;
  font-size: 12px;
  color: var(--muted);
}
.hero-email-actions {
  display: flex;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.hero-btn {
  min-height: 44px;
  min-width: 140px;
  padding: 0 24px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
}
.hero-btn:hover { transform: translateY(-1px); }
.hero-btn-generate {
  background: linear-gradient(180deg, #3d8bff 0%, #1e6fff 100%);
  color: #fff;
  box-shadow: 0 6px 18px rgba(30, 111, 255, .35);
}
.hero-btn-copy {
  background: linear-gradient(180deg, #fff7e6 0%, #ffe7ba 100%);
  color: #d48806;
  box-shadow: 0 6px 18px rgba(212, 136, 6, .22);
  border: 1px solid #ffd591;
}
.hero-btn-compose {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line-strong);
  box-shadow: 0 4px 12px rgba(15, 35, 75, .08);
}

.hero-banner-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 10px 24px 14px;
  background: #fff;
  border-top: 1px solid var(--line);
}
.hero-stats {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  justify-content: center;
}
.stat-chip {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
}
.stat-chip-label { font-size: 12px; color: var(--muted); }
.stat-chip-value { font-size: 16px; font-weight: 700; color: var(--text); }
.stat-chip-value.warn { color: var(--warn); }
.stat-chip-value.accent { color: var(--accent); }
.hero-transport {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}
.scan-status {
  font-size: 12px;
  color: var(--accent);
  display: flex;
  align-items: center;
  gap: 6px;
}
.scan-status .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* ── Workspace ── */
.workspace {
  display: grid;
  grid-template-columns: var(--sidebar-w) var(--list-w) minmax(0, 1fr);
  min-height: 0;
  overflow: hidden;
}

.sidebar, .main-panel, .detail-panel {
  min-height: 0;
  overflow: hidden;
  background: var(--surface);
  display: flex;
  flex-direction: column;
}
.sidebar { border-right: 1px solid var(--line); }
.main-panel { border-right: 1px solid var(--line); }

.sidebar-head, .panel-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.sidebar-head h2, .panel-head h2 {
  margin: 2px 0 0;
  font-size: 14px;
  font-weight: 600;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
}
.panel-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.nav-group { padding: 8px; display: grid; gap: 2px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.nav-item {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  border: none;
  border-radius: var(--radius);
  background: transparent;
  cursor: pointer;
  color: var(--text);
  transition: background .12s;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.nav-item strong {
  font-size: 12px;
  min-width: 20px;
  text-align: center;
  padding: 1px 6px;
  border-radius: 10px;
  background: var(--line);
  color: var(--muted);
  font-weight: 600;
}
.nav-item.active strong { background: var(--accent); color: #fff; }

.sidebar-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}
.sidebar-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 12px 4px;
  flex-shrink: 0;
}
.mailbox-list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  flex-shrink: 0;
}
.mailbox-select-all {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}
.mailbox-select-all input { width: 16px; height: 16px; cursor: pointer; }
.mailbox-list-actions { display: flex; gap: 6px; }
.sidebar-panel-header h3 { margin: 2px 0 0; font-size: 13px; font-weight: 600; }
.sidebar-filters {
  display: flex;
  gap: 6px;
  padding: 0 12px 8px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 26px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface-2);
  font-size: 12px;
  cursor: pointer;
  color: var(--muted);
  transition: all .12s;
}
.filter-chip:hover { border-color: var(--accent-border); color: var(--accent); }
.filter-chip.active { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); font-weight: 600; }
.filter-chip input { display: none; }

.sidebar-panel .search-field { padding: 0 12px 8px; flex-shrink: 0; }
.sidebar-list, .content-list, .detail-body { min-height: 0; overflow: auto; flex: 1; }

/* ── Mailbox & List Items ── */
.mailbox-item, .list-item {
  display: grid;
  gap: 4px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--soft, #f0f2f5);
  cursor: pointer;
  transition: background .1s;
  position: relative;
}
.mailbox-item { grid-template-columns: 18px 1fr; align-items: start; }
.mailbox-item:hover, .list-item:hover { background: #f5f8ff; }
.mailbox-item.active, .list-item.active { background: var(--accent-soft); }
.mailbox-item.active::before, .list-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
}
.mailbox-item.has-unread .mailbox-address { font-weight: 700; color: var(--text); }
.list-item.unread .item-title { font-weight: 700; }

.mailbox-mainline, .meta-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mailbox-address {
  font-size: 12px;
  line-height: 1.4;
  word-break: break-all;
  color: var(--muted);
}
.mailbox-item.active .mailbox-address { color: var(--accent); }
.item-title {
  font-size: 14px;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-preview {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.item-subtitle, .meta-row, .mailbox-meta-inline, .thread-line { font-size: 12px; color: var(--muted); }
.pick-box { display: inline-flex; align-items: center; padding-top: 2px; }

.toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  flex-shrink: 0;
}
.wide-field { min-width: 160px; flex: 1; }
.toggle-chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.toggle-chip:has(input:checked) { background: var(--accent-soft); border-color: var(--accent-border); color: var(--accent); }

/* ── Detail Panel ── */
.detail-body { padding: 0; display: flex; flex-direction: column; }
.empty-state {
  flex: 1;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
  padding: 40px 20px;
  font-size: 13px;
}

.thread-stack { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.thread-messages { flex: 1; overflow: auto; padding: 16px 20px; }

.thread-row {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 10px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.thread-row.solo { grid-template-columns: 1fr; }
.thread-content { min-width: 0; }
.thread-line {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.thread-body {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: break-word;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  max-width: 100%;
}
.thread-html-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  max-width: 100%;
}
.thread-html-frame {
  display: block;
  width: 100%;
  min-height: 120px;
  border: 0;
  background: #fff;
}
.thread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}
.thread-badge.inbound { background: #f0f2f5; color: var(--muted); }
.thread-badge.outbound { background: var(--accent-soft); color: var(--accent); }
.thread-code {
  padding: 2px 10px;
  border-radius: 4px;
  background: var(--warn-soft);
  color: #c47a0a;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 2px;
  font-family: Consolas, monospace;
}
.verification-banner {
  margin: 16px 20px 0;
  padding: 18px 20px;
  border: 2px solid #ffc069;
  border-radius: 12px;
  background: linear-gradient(135deg, #fff9e6 0%, #fff1b8 100%);
  box-shadow: 0 8px 24px rgba(212, 136, 6, .15);
  flex-shrink: 0;
}
.verification-banner-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}
.verification-banner-label {
  font-size: 14px;
  color: #ad6800;
  font-weight: 700;
}
.verification-banner-meta {
  font-size: 12px;
  color: #8c6d1f;
}
.verification-banner-code {
  font-size: clamp(32px, 5vw, 42px);
  font-weight: 800;
  letter-spacing: 6px;
  font-family: Consolas, "Cascadia Code", monospace;
  color: #d46b08;
  line-height: 1.2;
  word-break: break-all;
  text-align: center;
  padding: 8px 0 14px;
}
.verification-banner-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.verification-copy-btn {
  min-height: 42px;
  min-width: 160px;
  padding: 0 28px;
  border: none;
  border-radius: 10px;
  background: linear-gradient(180deg, #ffa940 0%, #fa8c16 100%);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(250, 140, 22, .35);
}
.verification-copy-btn:hover { filter: brightness(1.05); }
.verification-copy-btn.secondary {
  background: #fff;
  color: #d46b08;
  border: 1px solid #ffc069;
  box-shadow: none;
  min-width: 120px;
  font-size: 14px;
}
.panel-actions .tiny-button { min-width: 52px; }
.thread-arrow { color: var(--line-strong); }

.reply-strip {
  display: grid;
  gap: 8px;
  padding: 12px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  flex-shrink: 0;
}
.reply-strip textarea { min-height: 80px; background: #fff; }
.compact-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.compact-compose { display: grid; gap: 10px; padding: 16px 20px; }

.status-pill, .pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}
.status-pill.ready, .pill-accent { background: var(--success-soft); color: var(--success); }
.status-pill.error { background: var(--danger-soft); color: var(--danger); }
.pill-neutral { background: #f0f2f5; color: var(--muted); }
.pill-warn { background: var(--warn-soft); color: #c47a0a; }

.toast-stack { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 40; }
.toast {
  min-width: 220px; max-width: 360px;
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.98);
  box-shadow: var(--shadow);
  font-size: 13px;
}
.toast-error { background: var(--danger-soft); border-color: rgba(245,108,108,.3); color: var(--danger); }

.html-dialog {
  width: min(1000px, calc(100vw - 32px));
  height: min(82vh, 920px);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0;
  overflow: hidden;
}
.html-dialog::backdrop { background: rgba(9,20,31,.45); }
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
#htmlFrame { width: 100%; height: calc(100% - 52px); border: 0; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
  .detail-panel { display: none; }
  .main-panel.detail-open + .detail-panel,
  .workspace.show-detail .detail-panel { display: flex; position: fixed; inset: 0; z-index: 30; }
}

@media (max-width: 768px) {
  .login-panel { grid-template-columns: 1fr; }
  .workspace { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .hero-banner-tools .search-field input { width: 140px; }
  .hero-btn { min-width: 110px; padding: 0 16px; }
}
