:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --side: #eef0f4;
  --text: #1c1f24;
  --muted: #6b7280;
  --border: #e3e5ea;
  --hover: #f0f2f6;
  --selected: #e6efff;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --star: #f59e0b;
  --warn-bg: #fff7e6;
  --warn-text: #8a5300;
  --shadow: 0 10px 30px rgba(15, 23, 42, .18);
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317;
    --panel: #181b20;
    --side: #14161a;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --border: #2a2e35;
    --hover: #20242a;
    --selected: #1c2a44;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --danger: #f87171;
    --warn-bg: #2d2412;
    --warn-text: #f5c56b;
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111317; --panel: #181b20; --side: #14161a; --text: #e6e8eb; --muted: #9aa1ab; --border: #2a2e35;
  --hover: #20242a; --selected: #1c2a44; --accent: #3b82f6; --accent-hover: #60a5fa; --danger: #f87171;
  --warn-bg: #2d2412; --warn-text: #f5c56b; --shadow: 0 10px 30px rgba(0, 0, 0, .5); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
#root { height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
.boot { padding: 40px; text-align: center; color: var(--muted); }
[hidden] { display: none !important; }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* 按钮与输入框 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); cursor: pointer; white-space: nowrap; text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px;
  border: 0; border-radius: var(--radius); background: transparent; cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.input, .select, textarea.input {
  width: 100%; height: 36px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--panel); outline: none;
}
textarea.input { height: auto; padding: 10px; resize: vertical; }
.input:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; margin-bottom: 6px; font-size: 13px; color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; cursor: pointer; }
.check input { margin: 0; }
.seg { display: flex; gap: 20px; margin-bottom: 4px; }
.cf-rows { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; align-items: center; font-size: 13px; margin-bottom: 12px; }
.ok { color: #16a34a; font-weight: 600; }
.no { color: var(--danger); font-weight: 600; }
.unknown { color: var(--muted); }
.steps-result { list-style: none; margin: 0; padding: 0; }
.steps-result li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.steps-result li:last-child { border-bottom: 0; }
.steps-result b { display: block; }
.err { color: var(--danger); font-size: 13px; min-height: 20px; }

/* 登录 / 初始化 */
.auth-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 28px 24px; }
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card .sub { margin: 0 0 22px; color: var(--muted); }
.addr-group { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--panel); }
.addr-group:focus-within { border-color: var(--accent); }
.addr-group input { flex: 1; min-width: 0; border: 0; height: 36px; padding: 0 10px; outline: none; background: transparent; }
.addr-group .suffix { display: flex; align-items: center; padding: 0 10px; background: var(--hover); color: var(--muted); }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font-size: 13px; }
.auth-card .btn.primary { width: 100%; height: 40px; margin-top: 4px; }

/* 主框架 */
.app { display: flex; height: 100%; }
.side {
  width: 232px; flex: none; display: flex; flex-direction: column; background: var(--side);
  border-right: 1px solid var(--border); padding: 14px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; font-weight: 600; font-size: 16px; }
.brand img { width: 26px; height: 26px; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side .compose-btn { margin: 0 4px 12px; height: 40px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius);
  color: var(--text); text-decoration: none;
}
.nav a:hover { background: var(--hover); }
.nav a.active { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.nav a.active:hover { background: var(--accent-hover); }
.nav .badge { margin-left: auto; font-size: 12px; color: var(--muted); }
.nav a.active .badge { color: var(--accent-text); }
.nav-domains { max-height: 40vh; overflow-y: auto; }
.nav-domains a { padding: 5px 10px 5px 38px; font-size: 13px; }
.nav-domains a.active, .nav-domains a.active:hover { background: var(--selected); color: var(--accent); }
.nav-domains a.active .badge { color: var(--accent); }
.nav-domains .dn { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav hr { border: 0; border-top: 1px solid var(--border); margin: 10px 4px; }
.side-bottom { margin-top: auto; padding: 10px 4px 0; border-top: 1px solid var(--border); }
.me-addr { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 8px; }
.side-bottom .row { display: flex; gap: 6px; }
.side-bottom .btn { flex: 1; }
.scrim { display: none; }
.viewas {
  height: 40px; display: flex; align-items: center; justify-content: center; gap: 12px; padding: 0 16px;
  background: var(--warn-bg); color: var(--warn-text); font-size: 13px; border-bottom: 1px solid var(--border);
  white-space: nowrap; overflow: hidden;
}
.app.with-viewas { height: calc(100% - 40px); }

.main { flex: 1; min-width: 0; display: flex; }
.list-pane { width: 400px; flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--panel); }
.list-head { display: flex; align-items: center; gap: 6px; padding: 10px; border-bottom: 1px solid var(--border); }
.list-head .input { height: 34px; }
.menu-btn { display: none; }
.bulkbar { display: flex; align-items: center; gap: 4px; padding: 6px 10px; border-bottom: 1px solid var(--border); min-height: 44px; }
.bulkbar .count { font-size: 13px; color: var(--muted); margin-right: auto; padding-left: 6px; }
.list { flex: 1; overflow-y: auto; }
.item { display: flex; align-items: flex-start; gap: 8px; padding: 10px 10px 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.item:hover { background: var(--hover); }
.item.current { background: var(--selected); }
.item input[type=checkbox] { margin: 3px 0 0; flex: none; }
.item-body { flex: 1; min-width: 0; }
.row1 { display: flex; gap: 8px; align-items: baseline; }
.who { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.date { flex: none; font-size: 12px; color: var(--muted); }
.subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 4px; }
.subj svg.i { width: 14px; height: 14px; color: var(--muted); }
.snip { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.unread .who, .item.unread .subj { font-weight: 650; }
.item.unread { box-shadow: inset 3px 0 0 var(--accent); }
.star { border: 0; background: none; padding: 2px; cursor: pointer; color: var(--muted); flex: none; }
.star.on { color: var(--star); }
.star.on svg.i { fill: currentColor; }
.list-empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.more { display: block; margin: 12px auto; }

.reader-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--panel); }
.reader-empty { margin: auto; color: var(--muted); }
.reader-bar { display: flex; align-items: center; gap: 2px; padding: 8px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.reader-bar .spacer { flex: 1; }
.back-btn { display: none; }
.reader-scroll { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }
.reader-head { padding: 16px 20px 8px; }
.reader-head h1 { font-size: 20px; margin: 0 0 12px; word-break: break-word; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; font-size: 13px; color: var(--muted); }
.meta b { font-weight: 500; color: var(--text); }
.meta .v { word-break: break-all; }
.banner { margin: 8px 20px 0; padding: 8px 12px; border-radius: var(--radius); background: var(--warn-bg); color: var(--warn-text); font-size: 13px; display: flex; gap: 10px; align-items: center; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 20px; }
.att { display: inline-flex; align-items: center; gap: 6px; max-width: 260px; padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none; font-size: 13px; }
.att:hover { background: var(--hover); }
.att .n { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att .s { color: var(--muted); flex: none; }
.body-frame { flex: 1; min-height: 420px; width: 100%; border: 0; background: #fff; margin-top: 8px; }
.plain { padding: 8px 20px 24px; white-space: pre-wrap; word-break: break-word; }

/* 弹窗 */
.modal-back { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 440px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); }
.modal.wide { max-width: 720px; }
.modal header { display: flex; align-items: center; padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--border); font-weight: 600; }
.modal header .icon-btn { margin-left: auto; }
.modal .content { padding: 16px 20px; overflow-y: auto; }
.modal footer { display: flex; align-items: center; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--border); }
.modal footer .grow { flex: 1; }
.compose .content { padding: 0; display: flex; flex-direction: column; }
.compose .line { display: flex; align-items: center; border-bottom: 1px solid var(--border); padding: 0 12px 0 20px; }
.compose .line label { flex: none; width: 56px; color: var(--muted); font-size: 13px; }
.compose .line input { flex: 1; min-width: 0; height: 40px; border: 0; outline: none; background: transparent; }
.compose textarea { flex: 1; min-height: 280px; border: 0; outline: none; padding: 14px 20px; resize: none; background: transparent; }
.compose .files { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 20px 10px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: 999px; background: var(--hover); font-size: 12px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0 4px; }
.compose .banner { margin: 10px 20px 0; }

/* 管理后台 */
.admin { flex: 1; overflow-y: auto; padding: 16px 20px 40px; }
.admin-top { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.admin-top h1 { font-size: 20px; margin: 0; }
.admin-top .select { width: auto; min-width: 200px; margin-left: auto; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; }
.card h2 { font-size: 15px; margin: 0 0 12px; display: flex; align-items: center; gap: 8px; }
.card h2 .btn { margin-left: auto; }
.form-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.form-row .field { margin: 0; flex: 1; min-width: 160px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; }
td .btn { margin-right: 4px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--hover); color: var(--muted); }
.tag.blue { background: var(--selected); color: var(--accent); }
.tag.red { color: var(--danger); }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 6px; }
code { background: var(--hover); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1f2937; color: #fff; padding: 10px 16px; border-radius: var(--radius); box-shadow: var(--shadow); z-index: 100; max-width: calc(100vw - 32px); }
.toast.error { background: #b91c1c; }

/* 窄屏 */
@media (max-width: 1100px) {
  .list-pane { width: 340px; }
}
@media (max-width: 820px) {
  .side { position: fixed; z-index: 40; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .2s; }
  .app.nav-open .side { transform: none; box-shadow: var(--shadow); }
  .app.nav-open .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .3); }
  .menu-btn, .back-btn { display: inline-flex; }
  .list-pane { width: 100%; border-right: 0; }
  .reader-pane { display: none; }
  .app.reading .list-pane { display: none; }
  .app.reading .reader-pane { display: flex; }
  .reader-head, .plain, .atts { padding-left: 16px; padding-right: 16px; }
  .banner { margin-left: 16px; margin-right: 16px; }
  .admin { padding: 12px 16px 32px; }
  .admin-top { flex-wrap: wrap; }
  .admin-top .select { margin-left: 0; width: 100%; }
  .modal-back.full { padding: 0; }
  .modal-back.full .modal { max-width: none; max-height: none; height: 100%; border-radius: 0; }
  .compose .line { padding-left: 16px; }
  .compose textarea { padding: 12px 16px; }
}
