:root {
  --bg: #f4f1ec;
  --panel: #fffdf9;
  --text: #1a1a1a;
  --muted: #6b6560;
  --border: #e4ddd4;
  --accent: #2f5d50;
  --accent-soft: #e8f2ee;
  --danger: #b42318;
  --shadow: 0 10px 30px rgba(26, 26, 26, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "PingFang SC", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, #efe8df 0, transparent 40%),
    var(--bg);
  min-height: 100vh;
}

.hidden { display: none !important; }

.view { min-height: 100vh; }

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

.error { color: var(--danger); margin-top: 0.75rem; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.login-card {
  width: min(420px, 92vw);
  margin: 12vh auto;
  padding: 2rem;
}

.login-card h1 { margin: 0 0 0.25rem; }

.login-card form {
  display: grid;
  gap: 1rem;
  margin-top: 1.5rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
}

input {
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: #fff;
}

button {
  border: none;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  background: var(--accent);
  color: #fff;
  font-size: 0.95rem;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--border);
}

button.small { padding: 0.35rem 0.65rem; font-size: 0.85rem; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: rgba(255, 253, 249, 0.85);
  backdrop-filter: blur(8px);
}

.topbar h1 { margin: 0; font-size: 1.25rem; }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 240px) minmax(0, 320px) 1fr;
  min-height: calc(100vh - 76px);
}

.mailbox-panel {
  border-right: 1px solid var(--border);
  background: #f8f5f0;
  padding: 0.75rem;
  min-width: 0;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.5rem 0.25rem 0.75rem;
  font-weight: 600;
}

.small { font-size: 0.82rem; }

#mailbox-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.mailbox-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
}

.mailbox-item:hover { background: var(--accent-soft); }

.mailbox-item.active {
  background: var(--accent-soft);
  border-color: #cfe0d8;
}

.mailbox-item .addr {
  font-size: 0.88rem;
  word-break: break-all;
}

.mailbox-item button {
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.add-mailbox {
  margin-top: 0.75rem;
  padding: 0.85rem;
  display: grid;
  gap: 0.5rem;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 2px 8px rgba(26, 26, 26, 0.04);
}

.add-mailbox-label {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.prefix-input {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.92rem;
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.prefix-input:focus {
  border-color: #8fb8aa;
  box-shadow: 0 0 0 3px rgba(47, 93, 80, 0.14);
}

.prefix-input::placeholder {
  color: #b5aea6;
}

.prefix-preview {
  margin: 0;
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--muted);
  word-break: break-all;
}

.prefix-preview span {
  color: var(--accent);
  font-weight: 600;
}

.add-mailbox-btn {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  padding: 0.62rem 0.85rem;
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: 10px;
}

.add-mailbox .error {
  margin-top: 0;
  font-size: 0.82rem;
}

.data-tools {
  margin-top: 0.75rem;
  padding: 0.75rem;
  display: grid;
  gap: 0.45rem;
  border: 1px dashed var(--border);
  border-radius: 12px;
  background: rgba(255, 253, 249, 0.6);
}

.data-tools-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.data-tool-btn {
  width: 100%;
  box-sizing: border-box;
  padding: 0.45rem 0.65rem;
  font-size: 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.data-tool-btn:hover {
  background: #faf7f2;
  border-color: #d8d0c6;
}

.data-tool-btn.danger {
  color: var(--danger);
  border-color: #f0c4c0;
  background: #fef8f7;
}

.data-tool-btn.danger:hover {
  background: #fdeeed;
  border-color: #e8a8a0;
}

.account-form {
  display: grid;
  gap: 0.75rem;
}

.account-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.account-form input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text);
  background: #fff;
}

.account-form-hint {
  margin: 0;
}

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

.sidebar-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1rem 0.5rem;
  font-weight: 600;
  gap: 0.5rem;
}

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.btn-danger-text {
  color: var(--danger) !important;
  border-color: #f0c4c0 !important;
}

.btn-danger-text:hover {
  background: #fef3f2 !important;
}

#email-list {
  list-style: none;
  margin: 0;
  padding: 0.5rem;
}

.email-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.35rem;
  padding: 0.85rem 0.9rem;
  border-radius: 12px;
  cursor: pointer;
  border: 1px solid transparent;
  margin-bottom: 0.35rem;
}

.email-item-body {
  flex: 1;
  min-width: 0;
}

.email-item .email-del-btn {
  flex-shrink: 0;
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.email-item .email-del-btn:hover {
  color: var(--danger);
  border-color: #f0c4c0;
  background: #fef8f7;
}

.email-item:hover { background: var(--accent-soft); }

.email-item.active {
  background: var(--accent-soft);
  border-color: #cfe0d8;
}

.email-item.unread .subject { font-weight: 700; }

.email-item .subject {
  margin: 0 0 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.email-item .line {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.detail {
  padding: 1rem 1.25rem 1.5rem;
  background: linear-gradient(180deg, #f0ebe4 0%, var(--bg) 120px);
  overflow-y: auto;
}

.detail-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 120px);
  padding: 2rem;
  text-align: center;
}

.empty-icon {
  width: 72px;
  height: 72px;
  margin-bottom: 1rem;
  color: #c4bbb0;
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.empty-icon svg {
  width: 40px;
  height: 40px;
}

.empty-title {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.empty-hint {
  margin: 0;
  font-size: 0.88rem;
  color: var(--muted);
  max-width: 240px;
  line-height: 1.5;
}

.detail-card {
  max-width: 820px;
  margin: 0 auto;
  display: grid;
  gap: 1rem;
}

.detail-header {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.35rem 1.5rem;
  box-shadow: var(--shadow);
}

.detail-title-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1.15rem;
}

.detail-title-row .detail-subject {
  margin: 0;
  flex: 1;
  min-width: 0;
}

.detail-actions {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
}

.detail-subject {
  font-size: 1.35rem;
  font-weight: 650;
  line-height: 1.4;
  letter-spacing: -0.02em;
  color: var(--text);
}

.detail-meta {
  margin: 0;
  display: grid;
  gap: 0.55rem;
}

.meta-row {
  display: grid;
  grid-template-columns: 4.5rem 1fr;
  gap: 0.75rem;
  align-items: baseline;
  font-size: 0.9rem;
}

.meta-row dt {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: 0.04em;
}

.meta-row dd {
  margin: 0;
  color: var(--text);
  line-height: 1.45;
  word-break: break-word;
}

.extract-meta {
  margin: 0;
}

.extract-link a {
  color: var(--accent);
  text-decoration: underline;
  word-break: break-all;
}

.extract-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.05rem;
  letter-spacing: 0.06em;
}

.detail-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1rem 1.25rem 1.25rem;
  box-shadow: 0 4px 16px rgba(26, 26, 26, 0.04);
}

.section-label {
  margin: 0 0 0.75rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.85rem 0.5rem 0.65rem;
  border-radius: 10px;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--accent);
  text-decoration: none;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  max-width: 100%;
}

.attachment-chip:hover {
  background: var(--accent-soft);
  border-color: #cfe0d8;
}

.attachment-chip:active {
  transform: scale(0.98);
}

.chip-icon {
  flex-shrink: 0;
  font-size: 0.9rem;
  opacity: 0.85;
}

.chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 200px;
}

.chip-size {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--muted);
  padding-left: 0.25rem;
}

.body-section .body {
  margin: 0;
}

.body {
  background: #fff;
  border: 1px solid #ebe4db;
  border-radius: 12px;
  padding: 1.25rem 1.35rem;
  line-height: 1.75;
  font-size: 0.95rem;
  color: #2a2a2a;
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 120px;
}

.body.html-body {
  white-space: normal;
}

.body.html-body img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.body.html-body a {
  color: var(--accent);
}

.empty-state, .empty {
  padding: 2rem;
  text-align: center;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .mailbox-panel { border-right: none; border-bottom: 1px solid var(--border); }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
}

/* —— 弹窗 & Toast —— */
body.modal-open {
  overflow: hidden;
}

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(26, 26, 26, 0.35);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

.modal-dialog {
  position: relative;
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 1.35rem 1.4rem 1.2rem;
  box-shadow: 0 20px 50px rgba(26, 26, 26, 0.18);
  animation: slideUp 0.22s ease;
}

.modal-dialog-wide {
  width: min(720px, 100%);
}

.headers-pre {
  margin: 0 0 1.1rem;
  max-height: min(70vh, 560px);
  overflow: auto;
  padding: 0.85rem 1rem;
  background: #1e1e1e;
  color: #e8e8e8;
  border-radius: 10px;
  font-family: Consolas, "Cascadia Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  border: 1px solid #333;
}

.modal-title {
  margin: 0 0 0.6rem;
  font-size: 1.1rem;
  font-weight: 650;
  color: var(--text);
}

.modal-message {
  margin: 0 0 1.25rem;
  font-size: 0.92rem;
  line-height: 1.55;
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

.modal-btn {
  border: none;
  border-radius: 10px;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
}

.modal-btn:active {
  transform: scale(0.98);
}

.modal-btn.btn-ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.modal-btn.btn-ghost:hover {
  background: #f5f2ec;
}

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

.modal-btn.btn-primary:hover {
  background: #264a40;
}

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

.modal-btn.btn-danger:hover {
  background: #9a1d14;
}

.toast-root {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: min(360px, calc(100vw - 2rem));
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  font-size: 0.88rem;
  line-height: 1.45;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 8px 24px rgba(26, 26, 26, 0.12);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.25s ease, transform 0.25s ease;
  cursor: pointer;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast-success {
  border-color: #cfe0d8;
  background: #f0faf6;
  color: #1a4d3e;
}

.toast-error {
  border-color: #f5c4c0;
  background: #fef3f2;
  color: var(--danger);
}

.toast-info {
  border-color: var(--border);
  background: var(--panel);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}
