:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e3e5e9;
  --text: #1f2329;
  --text-dim: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --unread-dot: #2563eb;
  --hover: #f0f4ff;
  --active: #e3ecff;
}

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

/* 确保 hidden 属性不被下方的 display 规则覆盖 */
[hidden] { display: none !important; }

body {
  font-family: -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

button { font-family: inherit; cursor: pointer; }
input, textarea, select { font-family: inherit; font-size: 14px; }

/* ---------- 通用按钮 ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  transition: background .15s;
}
.btn:hover { background: var(--hover); }
.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: #fee2e2; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--hover); color: var(--text); }
.btn-block { display: block; width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  border: none; background: transparent; font-size: 16px;
  color: var(--text-dim); border-radius: 6px; padding: 4px 8px;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }

/* ---------- 登录页 ---------- */
#login-view {
  display: flex; align-items: center; justify-content: center; height: 100vh;
}
#login-form {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 16px; padding: 40px 36px; width: 340px; text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,.06);
}
.login-logo { font-size: 44px; }
#login-form h1 { font-size: 22px; margin: 8px 0 4px; }
.login-sub { color: var(--text-dim); font-size: 13px; margin-bottom: 24px; }
#login-password {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 12px; outline: none;
}
#login-password:focus { border-color: var(--primary); }
.login-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- 主布局 ---------- */
#app-view {
  display: grid;
  grid-template-columns: 230px 360px 1fr;
  grid-template-rows: minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

/* 侧栏 */
#sidebar {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; gap: 12px;
  min-height: 0;
}
.brand { font-size: 18px; font-weight: 700; padding: 4px 8px 8px; }
#account-list { flex: 1; overflow-y: auto; min-height: 0; }
.account-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; border-radius: 8px; font-size: 13px;
  cursor: pointer; color: var(--text); margin-bottom: 2px;
  position: relative;
}
.account-item:hover { background: var(--hover); }
.account-item.active { background: var(--active); font-weight: 600; }
.account-item .acct-name {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.account-item .acct-remove {
  display: none; border: none; background: none; color: var(--text-dim);
  font-size: 12px; padding: 2px 4px; border-radius: 4px;
}
.account-item:hover .acct-remove { display: block; }
.account-item .acct-remove:hover { color: var(--danger); background: #fee2e2; }
.sidebar-footer { border-top: 1px solid var(--border); padding-top: 10px; }
.sidebar-footer .btn { text-align: left; font-size: 13px; margin-bottom: 2px; }

/* 邮件列表 */
#list-pane {
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-width: 0; min-height: 0;
}
.pane-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 15px;
}
#message-list { flex: 1; overflow-y: auto; }
.msg-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; position: relative;
}
.msg-item:hover { background: var(--hover); }
.msg-item.selected { background: var(--active); }
.msg-item.unread .msg-subject { font-weight: 700; }
.msg-item.unread::before {
  content: ''; position: absolute; left: 5px; top: 50%;
  transform: translateY(-50%);
  width: 6px; height: 6px; border-radius: 50%; background: var(--unread-dot);
}
.msg-top { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 3px; }
.msg-from {
  font-size: 13px; font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.msg-date { font-size: 12px; color: var(--text-dim); flex-shrink: 0; }
.msg-subject {
  font-size: 13px; margin-bottom: 3px; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.msg-preview {
  font-size: 12px; color: var(--text-dim); overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.msg-account {
  display: inline-block; font-size: 11px; color: var(--primary);
  background: var(--active); border-radius: 4px; padding: 1px 6px; margin-top: 4px;
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-junk {
  display: inline-block; font-size: 11px; color: var(--danger);
  background: #fee2e2; border-radius: 4px; padding: 0 5px;
  font-weight: 600; vertical-align: middle;
}
.msg-error { padding: 12px 16px; color: var(--danger); font-size: 12px; border-bottom: 1px solid var(--border); }
.list-hint { padding: 32px 16px; text-align: center; color: var(--text-dim); font-size: 13px; }

/* 阅读窗格 */
#read-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.reader-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: var(--text-dim);
}
.reader-empty-icon { font-size: 48px; margin-bottom: 12px; opacity: .5; }
#reader { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.reader-header {
  padding: 18px 24px 14px; border-bottom: 1px solid var(--border); background: var(--panel);
}
#reader-subject { font-size: 18px; margin-bottom: 10px; word-break: break-word; }
.reader-meta { font-size: 13px; color: var(--text-dim); line-height: 1.7; }
.account-badge {
  display: inline-block; font-size: 12px; color: var(--primary);
  background: var(--active); border-radius: 4px; padding: 1px 8px; margin-top: 4px;
}
.reader-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
#body-frame { flex: 1; border: none; background: #fff; width: 100%; }

/* 回复框 */
#reply-box { padding: 12px 24px; border-bottom: 1px solid var(--border); background: var(--panel); }
#reply-text {
  width: 100%; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; resize: vertical; outline: none;
}
#reply-text:focus { border-color: var(--primary); }
.reply-actions { display: flex; gap: 8px; margin-top: 8px; }

/* 写邮件弹窗 */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal {
  background: var(--panel); border-radius: 14px; width: 560px; max-width: 92vw;
  max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.modal-body { padding: 16px 20px; overflow-y: auto; }
.modal-body label {
  display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 12px;
}
.modal-body input, .modal-body select, .modal-body textarea {
  display: block; width: 100%; margin-top: 4px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 8px; outline: none;
  color: var(--text); background: var(--panel); resize: vertical;
}
.modal-body input:focus, .modal-body textarea:focus { border-color: var(--primary); }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); text-align: right; }

/* 账号台账 */
.modal-lg { width: 920px; max-width: 96vw; }
.ledger-hint {
  font-size: 12px; color: var(--text-dim); line-height: 1.6; margin-bottom: 14px;
}
.ledger-table-wrap { overflow-x: auto; }
#ledger-table { width: 100%; border-collapse: collapse; font-size: 13px; }
#ledger-table th, #ledger-table td {
  padding: 7px 8px; border-bottom: 1px solid var(--border);
  text-align: left; vertical-align: middle;
}
#ledger-table th { color: var(--text-dim); font-weight: 600; white-space: nowrap; }
#ledger-table td:first-child {
  max-width: 170px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; font-size: 12px; color: var(--text-dim);
}
#ledger-table input {
  width: 100%; min-width: 92px; padding: 6px 8px;
  border: 1px solid var(--border); border-radius: 6px; outline: none;
  color: var(--text); background: var(--panel);
}
#ledger-table input:focus { border-color: var(--primary); }
.ledger-save { padding: 5px 12px; font-size: 12px; white-space: nowrap; }

/* Toast */
#toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: #1f2329; color: #fff; font-size: 13px;
  padding: 10px 20px; border-radius: 8px; z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
#toast.error { background: var(--danger); }

/* 窄屏简单适配 */
@media (max-width: 900px) {
  #app-view { grid-template-columns: 200px 1fr; }
  #read-pane {
    position: fixed; inset: 0; background: var(--bg); z-index: 50;
    display: none;
  }
  #read-pane.mobile-open { display: flex; }
}
