:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-elevated: #ffffff;
  --subtle: #f1f4f9;
  --subtle-hover: #e8edf5;
  --border: #e5eaf1;
  --border-strong: #d4dce8;
  --text: #0f172a;
  --text-sub: #475569;
  --text-muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: rgba(37, 99, 235, 0.1);
  --success: #059669;
  --success-soft: rgba(16, 185, 129, 0.12);
  --success-grad: linear-gradient(135deg, #10b981, #059669);
  --danger: #dc2626;
  --danger-soft: rgba(239, 68, 68, 0.1);
  --warn: #d97706;
  --warn-soft: rgba(245, 158, 11, 0.13);
  --paper-canvas: #eef2f7;
  --card-shadow: 0 1px 3px rgba(15, 23, 42, 0.05), 0 6px 20px rgba(15, 23, 42, 0.04);
  --msg-active-border: rgba(37, 99, 235, 0.28);
  --msg-active-shadow: 0 2px 8px rgba(37, 99, 235, 0.09);
}

[data-theme="dark"] {
  --bg: #0b101b;
  --surface: #111827;
  --surface-elevated: #172033;
  --subtle: #182234;
  --subtle-hover: #212e45;
  --border: #223047;
  --border-strong: #324461;
  --text: #f1f5f9;
  --text-sub: #cbd5e1;
  --text-muted: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --success: #34d399;
  --success-soft: rgba(16, 185, 129, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --warn: #fbbf24;
  --warn-soft: rgba(245, 158, 11, 0.18);
  --paper-canvas: #0f172a;
  --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.32);
  --msg-active-border: rgba(96, 165, 250, 0.35);
  --msg-active-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: "Segoe UI Variable Text", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

/* 按钮与输入 */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 9px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 550;
  padding: 7.5px 14px;
  cursor: pointer;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--subtle);
}
.btn-emerald {
  background: var(--success-grad);
  color: #ffffff;
}
.btn-emerald:hover:not(:disabled) {
  filter: brightness(1.05);
}
.btn-soft-primary {
  background: var(--primary-soft);
  color: var(--primary);
}
.btn-soft-primary:hover:not(:disabled) {
  filter: brightness(0.95);
}
.btn-sm {
  padding: 6px 11px;
  font-size: 12.5px;
}
.btn-xs {
  padding: 4px 10px;
  font-size: 12px;
  border-radius: 7px;
}
.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
  background: var(--surface);
  color: var(--text-sub);
  border-color: var(--border);
}
.btn-icon:hover {
  background: var(--subtle);
  color: var(--text);
}
.btn-icon .icon {
  width: 16px;
  height: 16px;
}

.input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  font-size: 13.5px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.form-label {
  display: block;
  font-size: 12.5px;
  font-weight: 550;
  color: var(--text-sub);
  margin-bottom: 6px;
}

/* 客户登录屏 */
.portal-auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  background: radial-gradient(circle at top center, var(--primary-soft) 0%, var(--bg) 52%);
}
.auth-theme-btn {
  position: fixed;
  top: 18px;
  right: 18px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 30px 26px 24px;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.1);
}
.auth-head {
  text-align: center;
  margin-bottom: 22px;
}
.auth-logo {
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.28);
}
.auth-head h2 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 6px;
}
.auth-head p {
  font-size: 13px;
  color: var(--text-sub);
}
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.pwd-field {
  position: relative;
}
.pwd-field .input {
  padding-right: 38px;
}
.pwd-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  cursor: pointer;
}
.pwd-toggle:hover {
  background: var(--subtle);
  color: var(--text);
}
.auth-error {
  background: var(--danger-soft);
  border: 1px solid rgba(239, 68, 68, 0.28);
  color: var(--danger);
  font-size: 12.5px;
  padding: 9px 12px;
  border-radius: 9px;
}
.auth-submit {
  width: 100%;
  padding: 10px 16px;
  font-size: 14px;
  margin-top: 4px;
}
.auth-foot {
  text-align: center;
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 18px;
}

/* 主应用 */
.portal-app {
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.portal-topbar {
  height: 54px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}
.portal-brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
}
.portal-brand h1 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
}
.portal-topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.portal-expiry-pill {
  font-size: 11.5px;
  color: var(--text-sub);
  background: var(--subtle);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.portal-main {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1260px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.account-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  flex-shrink: 0;
}
.account-left {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex: 1;
}
.mail-pill-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.18);
  flex-shrink: 0;
}
.cur-email {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cur-email:hover {
  color: var(--primary);
}
.btn-copy-tag {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-sub);
  font-size: 12px;
  font-weight: 500;
  padding: 4px 9px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
}
.btn-copy-tag:hover {
  color: var(--primary);
  border-color: rgba(37, 99, 235, 0.35);
}
.account-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
.is-loading .icon-refresh {
  animation: spin 0.75s linear infinite;
}
.pulse-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
}
.polling .pulse-dot {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.25);
}

.alert-error {
  background: var(--danger-soft);
  border: 1px solid rgba(239, 68, 68, 0.28);
  color: var(--danger);
  padding: 9px 14px;
  border-radius: 10px;
  font-size: 12.5px;
  flex-shrink: 0;
}

.otp-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  flex-shrink: 0;
  box-shadow: var(--card-shadow);
}
.otp-bar.has-code {
  border-color: rgba(16, 185, 129, 0.45);
  background: linear-gradient(90deg, var(--success-soft) 0%, var(--surface) 58%);
}
.latest-badge {
  font-size: 11.5px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary);
  flex-shrink: 0;
}
.otp-bar.has-code .latest-badge {
  background: var(--success-grad);
  color: #ffffff;
}
.otp-bar-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.otp-code {
  font-family: "JetBrains Mono", Consolas, monospace;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 1.5px;
  color: var(--success);
  background: var(--surface);
  border: 1px solid rgba(16, 185, 129, 0.35);
  padding: 2px 11px;
  border-radius: 7px;
  cursor: pointer;
  user-select: all;
}
.otp-bar-main {
  flex: 1;
  min-width: 160px;
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.otp-bar-main .preview-muted {
  color: var(--text-sub);
  margin-left: 6px;
  font-size: 12px;
}
.otp-bar-link {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.latest-time {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  flex-shrink: 0;
}

.mail-card {
  flex: 1;
  min-height: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--card-shadow);
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  overflow: hidden;
}
.mail-list-col {
  min-height: 0;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: rgba(15, 23, 42, 0.02);
}
.list-header {
  height: 48px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.list-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-sub);
}
.list-title em {
  font-style: normal;
  color: var(--text-muted);
  margin-left: 4px;
}
.list-sub {
  font-size: 11px;
  color: var(--text-muted);
}
.messages-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px;
  contain: layout style;
}
.msg-card {
  padding: 10px 11px;
  margin-bottom: 4px;
  border-radius: 10px;
  border: 1px solid transparent;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  cursor: pointer;
  content-visibility: auto;
  contain-intrinsic-size: auto 74px;
  transition: background-color 0.14s ease, border-color 0.14s ease;
}
.msg-card:hover:not(.active) {
  background: var(--subtle);
}
.msg-card.active {
  background: var(--surface-elevated);
  border-color: var(--msg-active-border);
  box-shadow: var(--msg-active-shadow);
}
.msg-avatar {
  width: 29px;
  height: 29px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.av-0 { background: rgba(99, 102, 241, 0.13); color: #6366f1; }
.av-1 { background: rgba(14, 165, 233, 0.13); color: #0ea5e9; }
.av-2 { background: rgba(16, 185, 129, 0.13); color: #10b981; }
.av-3 { background: rgba(245, 158, 11, 0.14); color: #f59e0b; }
.av-4 { background: rgba(168, 85, 247, 0.13); color: #a855f7; }
.av-5 { background: rgba(236, 72, 153, 0.13); color: #ec4899; }

.msg-card-body {
  flex: 1;
  min-width: 0;
}
.msg-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 3px;
}
.msg-sender {
  font-size: 12.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-date {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}
.msg-subject {
  font-size: 12.5px;
  color: var(--text-sub);
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.msg-card.active .msg-subject {
  color: var(--text);
  font-weight: 550;
}
.msg-preview {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.msg-tags {
  display: flex;
  gap: 6px;
  margin-top: 5px;
}
.code-chip {
  background: var(--success-soft);
  border: 1px solid rgba(16, 185, 129, 0.28);
  color: var(--success);
  font-family: "JetBrains Mono", Consolas, monospace;
  font-weight: 700;
  font-size: 11.5px;
  padding: 1.5px 7px;
  border-radius: 6px;
}
.spam-tag {
  font-size: 11px;
  color: var(--warn);
  background: var(--warn-soft);
  padding: 1px 6px;
  border-radius: 5px;
}

.mail-reader-col {
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
}
.reader-header {
  min-height: 48px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.reader-avatar {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.reader-title-wrap {
  min-width: 0;
  flex: 1;
}
.reader-subject {
  font-size: 14.5px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reader-submeta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  white-space: nowrap;
}
.meta-sender {
  overflow: hidden;
  text-overflow: ellipsis;
}
.reader-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.seg-switch {
  display: flex;
  background: var(--subtle);
  padding: 2.5px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.seg-btn {
  border: none;
  background: transparent;
  padding: 3.5px 9px;
  font-size: 11.5px;
  font-weight: 500;
  border-radius: 6px;
  color: var(--text-sub);
  cursor: pointer;
}
.seg-btn.active {
  background: var(--surface-elevated);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.reader-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 22px;
}
.reader-body.html-mode {
  padding: 12px;
  background: var(--paper-canvas);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.html-paper-frame {
  flex: 1;
  min-height: 0;
  background: #ffffff;
  border-radius: 10px;
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.sandbox-iframe {
  width: 100%;
  flex: 1;
  border: none;
  background: #ffffff;
}
.reader-pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.75;
  color: var(--text);
}
.reader-link {
  color: var(--primary);
  text-decoration: underline;
}

.empty-hint {
  height: 100%;
  min-height: 160px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
  padding: 24px;
  text-align: center;
}
.loading-spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2.2px solid var(--border-strong);
  border-top-color: var(--primary);
  animation: spin 0.72s linear infinite;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 400;
  pointer-events: none;
}
.toast {
  background: var(--surface-elevated);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  box-shadow: 0 10px 26px rgba(15, 23, 42, 0.16);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.is-leaving {
  opacity: 0;
  transform: translateY(-6px);
}
.toast-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
}
.toast.success .toast-dot { background: #10b981; }
.toast.error .toast-dot { background: #ef4444; }

/* 移动端自适应 */
@media (max-width: 820px) {
  .portal-app {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  .portal-topbar {
    padding: 0 12px;
  }
  .portal-expiry-pill {
    display: none;
  }
  .portal-main {
    padding: 12px;
    overflow: visible;
  }
  .cur-email {
    font-size: 14.5px;
  }
  .mail-card {
    grid-template-columns: 1fr;
    overflow: visible;
  }
  .mail-list-col {
    border-right: none;
    border-bottom: 1px solid var(--border);
    max-height: 300px;
  }
  .mail-reader-col {
    min-height: 440px;
  }
  .reader-body.html-mode {
    min-height: 420px;
  }
  .sandbox-iframe {
    min-height: 400px;
  }
}
