:root {
  /* color-scheme 让滚动条、原生表单控件也跟着走暗色 */
  color-scheme: dark;

  --bg: #15181d;
  --panel: #1c2027;
  --hover: #262c34;
  --border: #2f353e;
  --text: #e2e6eb;
  --muted: #99a1ad;
  --accent: #5aa2ff;

  /* 未读行底色，比 hover 更冷一点，避免两者混淆 */
  --unread: #1f2836;

  /* 报错色，与 toast 的错误底色同源 */
  --danger: #d9736e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.5 -apple-system, "Segoe UI", "Noto Sans CJK SC", sans-serif;
  color: var(--text);
  background: var(--bg);
}

header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.brand { font-weight: 700; font-size: 16px; }
header input[type="search"] { flex: 1; max-width: 420px; }
nav { margin-left: auto; display: flex; gap: 4px; }

button, input, select, textarea {
  font: inherit;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
}

button { cursor: pointer; }
button:hover { border-color: var(--accent); }
/* 暗底上用浅蓝底配白字对比度不足，改深色字 */
.tab.active { background: var(--accent); color: #10151c; border-color: var(--accent); }

main { display: flex; height: calc(100vh - 53px); }

#sidebar {
  width: 220px;
  flex: none;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 10px;
}

/* 账户行可点击折叠：> 表示已折叠，∨ 表示已展开 */
#sidebar .account {
  display: flex; align-items: center; gap: 6px;
  width: 100%; text-align: left; font-weight: 600;
  border: none; background: none; padding: 6px 8px; border-radius: 5px;
  /* 账户之间 12px，文件夹之间 8px，分组才看得出层次 */
  margin: 12px 0 4px;
}
/* 第一个账户不再额外下压：侧栏本身已有 10px 内边距 */
#sidebar .account:first-child { margin-top: 0; }
#sidebar .account:hover { background: var(--hover); }

/* 定宽：> 与 ∨ 宽度不同，不定宽的话切换时账户名会左右跳 */
#sidebar .twisty { flex: none; width: 12px; text-align: center; color: var(--muted); }

#sidebar .folder {
  display: block; width: 100%; text-align: left;
  border: none; background: none; padding: 4px 8px 4px 22px; border-radius: 5px;
}
#sidebar .folder:hover { background: var(--hover); }
#sidebar .folder.active { background: var(--unread); color: var(--accent); }

/* 拖动分隔条调整列宽 */
.splitter {
  flex: none;
  width: 5px;
  background: var(--border);
  cursor: col-resize;
  transition: background .12s;
}
.splitter:hover, .splitter.dragging { background: var(--accent); }

/* 拖动时禁止选中文字，否则会把列表文本一起刷蓝 */
body.resizing { user-select: none; cursor: col-resize; }

.view { flex: 1; display: flex; min-width: 0; }
.view.hidden, .hidden { display: none !important; }

#list-pane {
  width: 400px; flex: none; overflow-y: auto;
  background: var(--panel);
}

#message-list {
  list-style: none; margin: 0;
  /* 卡片化：列表外缘留白、卡片内边距、卡片之间一律 8px */
  padding: 8px;
  display: flex; flex-direction: column; gap: 8px;
}
#message-list li {
  /* 四边等距。取 8px 与侧栏文件夹项、分页栏的横向留白一致 */
  padding: 8px;
  /* 圆角与按钮、搜索框同为 6px，否则方块列表和圆角控件摆在一起会割裂 */
  border: 1px solid var(--border);
  border-radius: 6px;
  /* 比所在面板深一档，卡片才立得起来；hover / 未读再往上提亮 */
  background: var(--bg);
  cursor: pointer;

  /* 紧凑三行：标题+时间 / 发件人 / 预览 */
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1px 8px;
  line-height: 1.35;
}
/* 与按钮一致：hover 时边框转强调色，光靠底色变化在卡片上不够明显 */
#message-list li:hover { background: var(--hover); border-color: var(--accent); }
#message-list li.unread { background: var(--unread); box-shadow: inset 3px 0 0 var(--accent); }
#message-list li.active { outline: 2px solid var(--accent); outline-offset: -2px; }

#message-list .subject {
  font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
#message-list li.unread .subject { font-weight: 700; }

#message-list .time {
  color: var(--muted); font-size: 12px; white-space: nowrap;
}

#message-list .meta,
#message-list .preview {
  grid-column: 1 / -1;
  color: var(--muted); font-size: 12.5px;
}
#message-list .meta {
  font-size: 12px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* 姓名用正文色、地址用淡色，一眼能扫出是谁发的 */
#message-list .who { color: var(--text); }
#message-list .addr { color: var(--muted); }
/* 预览最多两行，短的自然只占一行，行高不会忽高忽低 */
#message-list .preview {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* 上边留 0：列表本身已有 8px 下留白，再叠加就变成 16px 了 */
#pager { padding: 0 8px 8px; display: flex; gap: 6px; align-items: center; justify-content: center; }

#detail-pane { flex: 1; overflow-y: auto; padding: 16px; background: var(--panel); min-width: 0; }
#detail h2 { margin: 0 0 6px; }
#detail .meta { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
#detail .auth {
  font-size: 12px; color: var(--muted); border: 1px dashed var(--border);
  padding: 6px 8px; border-radius: 5px; margin-bottom: 12px; word-break: break-all;
}
#detail .body { border-top: 1px solid var(--border); padding-top: 12px; }
#detail .body img { max-width: 100%; }

.attachments { margin: 12px 0; }
.attachments a { display: inline-block; margin-right: 8px; color: var(--accent); }

.empty { color: var(--muted); padding: 16px; }

.panel { flex: 1; padding: 16px; overflow-y: auto; }
.stack { display: flex; flex-direction: column; gap: 8px; max-width: 560px; }
.row { display: flex; gap: 8px; align-items: center; }
.hint { color: var(--muted); font-size: 13px; }

/* 向导里的失败原因：整段都要能一眼看出是错误，不是普通提示 */
.hint.error {
  color: var(--danger);
}

/* 账号列表里的异常状态（令牌失效、未登记凭据等） */
.meta.warning {
  color: var(--danger);
}

/* 小字号的行内文字按钮，用于「改用应用专用密码」这类次要操作 */
.link-button {
  background: none;
  border: none;
  padding: 0;
  font-size: inherit;
  color: var(--accent);
  text-decoration: underline;
}

.link-button:disabled {
  color: var(--muted);
  text-decoration: none;
}

/* 设置页顶部的版本条。下面留一条分隔线，
   否则「当前版本 + 检查更新」会看起来像另一个设置项 */
.version-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.version-label {
  color: var(--muted);
  font-size: 13px;
}

.version-bar code {
  font-size: 13px;
  color: var(--text);
}

a { color: var(--accent); }

/* 设置页：每个服务商一张卡片 */
.setting-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin: 12px 0;
  max-width: 680px;
}
.setting-card h3 { margin: 0 0 6px; font-size: 15px; }
.setting-card code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 12.5px;
  word-break: break-all;
}

#account-list, #contact-list { list-style: none; padding: 0; margin-top: 16px; max-width: 560px; }
#account-list li, #contact-list li {
  display: flex; align-items: center; gap: 8px;
  padding: 8px; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px;
}
#account-list .spacer, #contact-list .spacer { margin-left: auto; }
/* 就地改名的输入框：默认输入框内边距会把这一行撑高，收一点 */
#account-list input.account-name { padding: 3px 8px; max-width: 260px; }

#compose {
  position: fixed; right: 24px; bottom: 24px; width: 520px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px; box-shadow: 0 8px 28px rgba(0,0,0,.55);
  max-height: 80vh; overflow-y: auto;
}
#compose h2 { margin: 0 0 8px; font-size: 16px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--panel); color: var(--text); padding: 10px 16px; border-radius: 6px;
  border: 1px solid var(--border); box-shadow: 0 4px 16px rgba(0,0,0,.5);
}

/* ---------- 登录 / 强制改密码 ----------
   用固定的全屏遮罩而不是单独的 login 页面：
   邮件数据只在通过 API 校验之后才会被取回来，登录前后渲染的是同一个 SPA，
   所以即便遮罩意外失效，底下也只是一层空壳，不会漏出任何邮件内容。 */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.overlay form {
  width: 340px; padding: 24px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,.55);
}
.overlay h2 { margin: 0 0 4px; font-size: 18px; }
.overlay .hint { margin-top: 0; }

#current-user { color: var(--muted); white-space: nowrap; }

code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: .92em;
  padding: 1px 5px; border-radius: 4px;
  background: var(--hover); border: 1px solid var(--border);
}
