:root {
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-alt: #f1f4f9;
  --border: #e3e8f0;
  --text: #111827;
  --text-muted: #64748b;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-soft: #eff6ff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --success: #059669;
  --success-soft: #ecfdf5;
  --code-bg: #1e293b;
  --code-text: #f8fafc;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
  --radius: 10px;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-alt: #1e293b;
  --border: #263143;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-soft: rgba(59, 130, 246, 0.16);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --success: #34d399;
  --success-soft: rgba(52, 211, 153, 0.14);
  --code-bg: #020617;
  --code-text: #e2e8f0;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--text-muted);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.9em;
  background: var(--surface-alt);
  padding: 2px 6px;
  border-radius: 5px;
}

/* Buttons & Inputs */
input[type="text"],
input[type="password"],
input[type="search"] {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 11px;
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-alt);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-alt);
  color: var(--text);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
}

.btn-danger-ghost:hover:not(:disabled) {
  background: var(--danger-soft);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 13px;
}

.btn-xs {
  padding: 4px 8px;
  font-size: 12px;
}

.btn-block {
  width: 100%;
}

.icon-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

.icon-btn:hover {
  background: var(--surface-alt);
}

/* Login */
.login-screen {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}

.brand-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.login-brand h1 {
  margin: 0;
  font-size: 20px;
}

.login-brand p {
  margin: 2px 0 0;
  font-size: 13px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.login-form label {
  font-size: 13px;
  font-weight: 500;
}

.form-error {
  color: var(--danger);
  background: var(--danger-soft);
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
}

/* App Shell */
.app-shell {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.topbar-left,
.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  margin-right: 6px;
  white-space: nowrap;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
}

.generator-bar {
  display: flex;
  align-items: center;
  gap: 6px;
}

.generator-bar input {
  width: 170px;
}

.search-box input {
  width: 230px;
}

.auto-refresh-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

/* 3-Column Workspace */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 245px 340px 1fr;
  min-height: 0;
  overflow: hidden;
}

.sidebar,
.mail-list-pane,
.reader-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.sidebar-header,
.pane-header {
  height: 46px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.sidebar-header {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.badge-subtle {
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-weight: 500;
}

.mailbox-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.mailbox-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.12s;
}

.mailbox-item:hover {
  background: var(--surface-alt);
}

.mailbox-item.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.mailbox-main {
  min-width: 0;
  flex: 1;
}

.mailbox-addr {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mailbox-note {
  font-size: 11.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mailbox-badges {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.unread-pill {
  background: var(--primary);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 999px;
}

.count-pill {
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 11.5px;
  padding: 1px 7px;
  border-radius: 999px;
}

/* Middle Mail List */
.mail-list-pane {
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.pane-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.pane-title-wrap h2 {
  margin: 0;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pane-actions {
  display: flex;
  align-items: center;
  gap: 2px;
}

.mail-list {
  flex: 1;
  overflow-y: auto;
}

.mail-card {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.mail-card:hover {
  background: var(--surface-alt);
}

.mail-card.active {
  background: var(--primary-soft);
}

.mail-card.unread .mail-subject {
  font-weight: 700;
}

.mail-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
}

.mail-sender {
  font-size: 12.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.unread-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--primary);
  flex-shrink: 0;
}

.mail-time {
  font-size: 11.5px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.mail-subject {
  font-size: 13.5px;
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-preview {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}

.recipient-chip {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--surface-alt);
  padding: 1px 6px;
  border-radius: 5px;
  max-width: 170px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.otp-chip {
  border: 1px solid var(--success);
  background: var(--success-soft);
  color: var(--success);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 6px;
  cursor: pointer;
}

.otp-chip:hover {
  filter: brightness(0.95);
}

/* Reader Pane */
.reader-pane {
  background: var(--bg);
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 10px;
  opacity: 0.45;
}

.empty-state h3 {
  margin: 0 0 6px;
  color: var(--text);
}

.reader-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
}

.reader-toolbar {
  height: 46px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.reader-view-tabs {
  display: flex;
  background: var(--surface-alt);
  padding: 3px;
  border-radius: 8px;
  gap: 2px;
}

.tab-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12.5px;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.reader-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.detail-subject {
  margin: 0 0 10px;
  font-size: 18px;
  line-height: 1.35;
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  font-size: 12.5px;
}

.meta-label {
  color: var(--text-muted);
}

.clickable-copy {
  cursor: pointer;
  color: var(--primary);
}

.clickable-copy:hover {
  text-decoration: underline;
}

.extract-banner {
  padding: 12px 20px;
  background: var(--success-soft);
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.code-box {
  display: flex;
  align-items: center;
  gap: 10px;
}

.code-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--success);
}

.code-value {
  border: 1px solid var(--success);
  background: var(--surface);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2px;
  padding: 4px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.links-box {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.verify-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  padding: 5px 11px;
  border-radius: 7px;
  font-size: 12.5px;
  font-weight: 500;
}

.verify-link-btn:hover {
  background: var(--primary-hover);
}

.attachments-box {
  padding: 8px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.reader-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.html-frame {
  width: 100%;
  flex: 1;
  border: none;
  background: #ffffff;
}

.text-view {
  margin: 0;
  padding: 20px;
  flex: 1;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.65;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-sm {
  max-width: 400px;
}

.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  margin: 0;
  font-size: 16px;
}

.modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.modal-body h4 {
  margin: 8px 0 0;
  font-size: 13.5px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.code-snippet {
  margin: 0;
  padding: 12px;
  border-radius: 8px;
  background: var(--code-bg);
  color: var(--code-text);
  font-size: 12px;
  overflow-x: auto;
}

.api-list {
  margin: 4px 0 0;
  padding-left: 18px;
  font-size: 12.5px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 9px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: fadeIn 0.18s ease-out;
}

[data-theme="dark"] .toast {
  background: #f8fafc;
  color: #0f172a;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.mobile-only {
  display: none;
}

@media (max-width: 980px) {
  .generator-bar input,
  .search-box input {
    width: 130px;
  }

  .workspace {
    grid-template-columns: 210px 280px 1fr;
  }
}

@media (max-width: 760px) {
  .mobile-only {
    display: inline-flex;
  }

  .generator-bar input,
  #use-prefix-btn,
  .auto-refresh-toggle {
    display: none;
  }

  .search-box input {
    width: 120px;
  }

  .workspace {
    grid-template-columns: 1fr;
    position: relative;
  }

  .sidebar {
    position: absolute;
    inset: 0 auto 0 0;
    width: 260px;
    z-index: 20;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .reader-pane {
    position: absolute;
    inset: 0;
    z-index: 15;
    display: none;
  }

  .reader-pane.mobile-open {
    display: flex;
  }
}
