: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 {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 16px;
}

/* 品牌图标:直接复用站点自己的应用图标(与 favicon 同一个文件)。
   源图 256×256,缩到 20px 显示;圆角让它的视觉重量与旁边的按钮接近一些。
   宽高属性写在 HTML 上,图片加载前也不会引起顶栏跳动。 */
.brand-icon {
  flex: none;
  width: 20px;
  height: 20px;
  border-radius: 4px;
  object-fit: contain;
}
header input[type="search"] { flex: 1; max-width: 420px; }
nav { margin-left: auto; display: flex; gap: 4px; }

/* 用户菜单:右边一排按钮的最后一个,下拉挂在它下面 */
.user-menu { position: relative; }
#btn-user { display: inline-flex; align-items: center; gap: 4px; }
.user-caret { font-size: 10px; color: var(--muted); }

#user-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 132px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .28);
  z-index: 150;
}
/* 下拉项不带边框和底色,否则会跟上方那排按钮长得一样 */
#user-dropdown > button {
  border: none;
  background: none;
  text-align: left;
  padding: 7px 10px;
  border-radius: 4px;
}
#user-dropdown > button:hover { background: var(--hover); }
/* 分隔线:不用 --border,它和 --panel 只差一点点,暗底上几乎看不见;
   半透明白在任何面板色上都稳定可见。
   flex:none 是防御——父级是 column flex,1px 高的元素在空间紧张时
   会被压成 0,那看起来就跟没画一样。 */
#user-dropdown .menu-separator {
  flex: none;
  height: 1px;
  margin: 5px 8px;
  background: rgba(255, 255, 255, .16);
}

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); }

/* 同步中的转圈。用「边框上边透明 + 旋转」画,不依赖图片或图标字体 */
@keyframes mmail-spin { to { transform: rotate(360deg); } }

/* 顶部「立即同步」:用伪元素而不是往按钮里塞节点,
   这样按钮宽度和点击区域都不受影响 */
#btn-sync.loading::before {
  content: '';
  display: inline-block;
  width: 11px; height: 11px;
  margin-right: 6px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  vertical-align: -1px;
  animation: mmail-spin .7s linear infinite;
}

/* 侧栏文件夹上的转圈。文件夹行是 block、徽标靠 float:right 顶到最右,
   这里跟着右浮;margin-top 用来在 18px 高的行里与徽标对齐 */
#sidebar .folder .folder-spinner {
  float: right;
  width: 11px; height: 11px;
  margin: 4px 0 0 6px;
  border: 2px solid var(--muted);
  border-top-color: transparent;
  border-radius: 50%;
  animation: mmail-spin .7s linear infinite;
}

/* 「其他文件夹」子分组头:复用 .account 的 flex 布局但整体弱化——
   它是目录索引不是账户名,不能在视觉上跟账户平级 */
#sidebar .account.other-group {
  font-weight: 500;
  font-size: 12px;
  margin: 6px 0 2px;
  color: var(--muted);
}
/* 组内文件夹比顶层多缩进一级,层次才看得出来 */
#sidebar .subfolder-group .folder { padding-left: 36px; }

/* 未读徽标:蓝色小圆牌。
   账户行是 flex,用 margin-left:auto 顶到最右;文件夹行是 block,只能 float 右浮。
   分成两条是为了不去改动上面已有的 display 属性。 */
.unread-badge {
  flex: none;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px; font-weight: 600;
  line-height: 18px; text-align: center;
}
#sidebar .account .unread-badge { margin-left: auto; }
#sidebar .folder .unread-badge { float: right; }

/* 顶层「未读邮件」:不属于任何账户,低一级缩进 + 底部分隔,
   否则它和上一个账户最后的文件夹连成一片,看不出是另一层 */
#sidebar .folder.unread-root {
  padding-left: 12px;
  margin-bottom: 6px;
  font-weight: 600;
}

/* 文件夹图标。给固定宽度而不是只留 margin:emoji 在不同平台的字宽
   差别不小(有的按全角算),不固定的话每行文件夹名的起点会参差不齐。
   字号略小于正文,免得图标比文字还抢眼。 */
#sidebar .folder .folder-icon {
  display: inline-block;
  width: 18px;
  margin-right: 2px;
  text-align: center;
  font-size: 13px;
}

/* 右键菜单:fixed 定位,坐标由 JS 按视口收边后写入 */
#context-menu {
  position: fixed;
  z-index: 200;
  min-width: 168px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}
#context-menu .menu-item {
  display: block; width: 100%;
  text-align: left; font: inherit; color: inherit;
  border: none; background: none;
  padding: 7px 10px; border-radius: 4px;
}
#context-menu .menu-item:hover { background: var(--hover); }
#context-menu .menu-separator {
  height: 1px; margin: 4px 6px; background: var(--border);
}

/* 拖动分隔条调整列宽 */
.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 .auth-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 14px; height: 14px;
  margin-right: 5px;
  border-radius: 50%;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  vertical-align: -1px;
  cursor: help;   /* 提示这里可以悬停看原因 */
}
#message-list .auth-verified   { background: #1e4d34; color: #7ee2a8; }
#message-list .auth-suspicious { background: #57430f; color: #e8c266; }
#message-list .auth-failed     { background: #5c1f1c; color: #f0a09b; }
#message-list .auth-unverified { background: #2b3038; color: #8b939f; }

#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; }
/* 阅读区标题行:主题在左、右上角按钮在右(收件箱是「回复」,草稿箱是「编辑」)。
   主题用 flex:1 + min-width:0,长主题才会正常换行而不是把按钮挤出去 */
#detail .detail-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 6px;
}
#detail .detail-head h2 { flex: 1; min-width: 0; margin: 0; }
#detail .detail-head .btn-reply,
#detail .detail-head .btn-edit { flex: none; }
#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; }

/* 「显示远程图片」不用 link-button:这是个有后果的动作,得长成正经按钮,
   而不是一行让人不敢点的下划线链接。全局 button 样式自带边框与悬停色,
   这里只补与下方正文的间距 */
#show-images { margin-bottom: 10px; }

/* 正文 iframe:宽度铺满,高度由 JS 按内容撑起 */
.mail-frame {
  display: block;
  width: 100%;
  min-height: 120px;
  border: 0;
}

.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;
}

/* 设置页顶部、版本条上方那一行占用量。不给分隔线:
   它和版本条是一个信息块,中间再切一刀就碎了 */
.storage-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 6px;
}

/* 设置页顶部的版本条。下面留一条分隔线,
   否则「当前版本 + 检查更新」会看起来像另一个设置项 */
.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; }

/* 账号列表跟随页面宽度铺开。原先与 contact-list 共用 560px 上限,
   宽屏下那行「邮箱 · 认证方式 · 上次同步」被硬挤成两三行,右侧还空着
   一大片——列表项本来就是 flex 行,宽度给足就不会折。
   contact-list 保留原上限:联系人条目短,铺满全宽反而把姓名和按钮拉开。 */
#contact-list { 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; }

/* 发送中的状态提示:跟在「发送 / 取消」后面,与按钮同一行垂直居中 */
#compose-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

/* 不可用的按钮统一置灰:发送中、以及内容不完整时的「存入草稿箱」。
   不只是禁用行为,视觉上也要一眼看出点不了 */
#compose-form button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

/* 通用转圈。同步按钮用伪元素画、文件夹行要浮动,各有专用写法;
   这里是常规行内场景,直接给个类复用同一套动画 */
.spinner {
  flex: none;
  width: 11px; height: 11px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: mmail-spin .7s linear infinite;
}

#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);
}

/* ---------- 移动端 / 平板适配 ----------
   原则:桌面样式零改动。下面只有两类东西——
   1. 桌面上 display:none 的新元素(手机专用按钮、FAB、返回键);
   2. 一个 @media (max-width: 768px) 块,断点与 app.js 的 mobileQuery 一致。
   手机上「哪个窗格可见」由 body[data-pane](list / folders / detail)决定,
   该属性由 app.js 的 showMobilePane 写入;桌面端媒体查询不匹配,属性留着也无碍。 */

/* 手机端专用元素:桌面一概不渲染 */
.mobile-only, .mobile-fab { display: none; }
/* 详情页的返回按钮:桌面有完整三栏,永远用不上 */
.btn-back { display: none; }

@media (max-width: 768px) {
  /* 双击缩放对邮件客户端没有意义,点按应即时响应 */
  html { touch-action: manipulation; }

  /* 用 flex 列让 main 自动填满 header 之外的空间:
     header 在手机上可能是一行也可能两行(搜索展开时),
     写死 calc(100vh - 53px) 会错位。dvh 随地址栏收起而收缩,是真实视口 */
  body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
  }
  main { flex: 1; height: auto; min-height: 0; display: flex; }
  .view { height: 100%; }

  /* 单栏化的根基:同一时刻只显示一个窗格 */
  body[data-pane="folders"] #mail-view { display: none; }
  body[data-pane="list"] #detail-pane { display: none; }
  body[data-pane="detail"] #list-pane { display: none; }
  .splitter { display: none !important; }

  /* 文件夹全屏页。侧栏在列表/详情窗格下不出现——
     三栏里的常驻列在单栏模式下没有位置 */
  #sidebar { display: none; }
  body[data-pane="folders"] #sidebar {
    display: block;
    width: auto;
    height: 100%;
    flex: 1;
  }
  /* 列表与详情各占满一行 */
  #list-pane, #detail-pane { width: auto; flex: 1; }
  #detail-pane { padding: 12px; padding-top: max(12px, env(safe-area-inset-top)); }

  /* 列表/详情/侧栏内部的滚动不再外溢带动整页(iOS 橡皮筋连锁) */
  #list-pane, #detail-pane, #sidebar, .panel, #compose {
    overscroll-behavior: contain;
  }

  /* ---- 顶栏 ---- */
  header {
    flex-wrap: wrap;
    padding: 8px max(10px, env(safe-area-inset-right)) 8px max(10px, env(safe-area-inset-left));
  }
  .mobile-only { display: inline-flex; align-items: center; justify-content: center; min-width: 38px; }
  .brand-text { display: none; }
  /* 搜索框默认收起;点放大镜展开成独占一整行 */
  header input[type="search"] { display: none; flex: 1 1 100%; max-width: none; order: 9; }
  header.search-open input[type="search"] { display: block; }
  /* 顶栏放不下的动作:同步走文件夹长按菜单,写信走 FAB,导航走用户菜单 */
  nav, #btn-sync, #btn-compose { display: none; }
  #btn-search { margin-left: auto; }
  /* iOS 聚焦输入框会自动放大页面,16px 是它认定的「不需要放大」门槛 */
  input, select, textarea { font-size: 16px; }

  /* ---- 邮件列表:卡片压矮一点,一屏多看几封 ---- */
  #message-list li { padding: 10px; }
  #message-list .preview { -webkit-line-clamp: 1; }

  /* ---- 详情页 ---- */
  .btn-back { display: inline-flex; }
  #detail .detail-head { flex-wrap: wrap; }
  #detail .detail-head h2 { font-size: 17px; }

  /* ---- 写信:浮窗改全屏,动作按钮吸底不被键盘顶没 ---- */
  #compose {
    inset: 0;
    width: 100%;
    max-height: none;
    border-radius: 0;
    padding: 12px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  #compose .row {
    position: sticky;
    bottom: 0;
    background: var(--panel);
    padding: 8px 0 4px;
    flex-wrap: wrap;
  }

  /* ---- 写信悬浮球 ---- */
  .mobile-fab {
    display: flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    width: 52px;
    height: 52px;
    border-radius: 50%;
    font-size: 22px;
    line-height: 1;
    z-index: 60;
    box-shadow: 0 4px 14px rgba(0, 0, 0, .45);
  }
  /* 写信页盖着的时候 FAB 没必要露出 */
  body:has(#compose:not(.hidden)) .mobile-fab { display: none; }

  /* 登录 / 改密遮罩:固定 340px 在窄屏上会贴边 */
  .overlay form { width: min(340px, calc(100vw - 32px)); }

  #toast { max-width: calc(100vw - 32px); text-align: center; }
}