:root {
    --bg: #f6f7f9; --fg: #1f2328; --muted: #6b7280; --line: #e5e7eb;
    --accent: #2563eb; --accent-fg: #fff; --danger: #dc2626; --warn: #f59e0b;
    --card: #fff; --hover: #f3f4f6;
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --bg: #0f1115; --fg: #e6e8eb; --muted: #9aa4b2; --line: #242a33;
      --accent: #3b82f6; --danger: #ef4444; --card: #171a20; --hover: #1e222a;
    }
  }
  * { box-sizing: border-box; }
  body {
    margin: 0; background: var(--bg); color: var(--fg);
    font: 14px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
          "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  }
  button, input, select { font: inherit; }
  .hidden { display: none !important; }

  /* 登录页 */
  #login {
    max-width: 360px; margin: 12vh auto; padding: 28px;
    background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  }
  #login h1 { font-size: 20px; margin: 0 0 4px; }
  #login p.sub { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
  .field { margin-bottom: 14px; }
  .field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
  .field input {
    width: 100%; padding: 9px 11px; border: 1px solid var(--line);
    border-radius: 8px; background: var(--bg); color: var(--fg);
  }
  .field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
  .btn {
    padding: 9px 16px; border-radius: 8px; border: 1px solid var(--line);
    background: var(--card); color: var(--fg); cursor: pointer;
  }
  .btn:hover { background: var(--hover); }
  .btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
  .btn.primary:hover { filter: brightness(1.08); }
  .btn.danger { color: var(--danger); }
  .btn:disabled { opacity: .55; cursor: not-allowed; }
  .btn.block { width: 100%; }

  /* 主界面 */
  #app { display: none; height: 100vh; flex-direction: column; }
  #app.on { display: flex; }
  header {
    display: flex; align-items: center; gap: 12px; padding: 10px 16px;
    border-bottom: 1px solid var(--line); background: var(--card); flex-wrap: wrap;
  }
  header .title { font-weight: 600; }
  header .spacer { flex: 1; }
  .addr-box { position: relative; }
  .addr-input {
    width: 260px; padding: 7px 10px; border: 1px solid var(--line);
    border-radius: 8px; background: var(--bg); color: var(--fg);
  }
  .addr-list {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20;
    max-height: 320px; overflow: auto; background: var(--card);
    border: 1px solid var(--line); border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,.12);
  }
  .addr-item {
    padding: 8px 12px; cursor: pointer; display: flex; gap: 8px;
    justify-content: space-between; align-items: center;
  }
  .addr-item:hover, .addr-item.active { background: var(--hover); }
  .addr-item .badge {
    font-size: 12px; color: var(--muted); white-space: nowrap;
  }

  main { flex: 1; display: flex; min-height: 0; }
  #listPane { width: 420px; border-right: 1px solid var(--line); display: flex; flex-direction: column; }
  #listTools {
    padding: 8px 12px; border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted);
  }
  #list { flex: 1; overflow: auto; }
  .mail {
    padding: 10px 14px; border-bottom: 1px solid var(--line); cursor: pointer;
    display: flex; flex-direction: column; gap: 3px;
  }
  .mail:hover { background: var(--hover); }
  .mail.selected { background: var(--hover); box-shadow: inset 3px 0 0 var(--accent); }
  .mail .row1 { display: flex; gap: 8px; align-items: baseline; }
  .mail .from { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mail .time { margin-left: auto; font-size: 12px; color: var(--muted); white-space: nowrap; }
  .mail .subject { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .mail .meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; }
  .empty { padding: 32px 16px; text-align: center; color: var(--muted); }

  #readPane { flex: 1; display: flex; flex-direction: column; min-width: 0; }
  #readHead { padding: 12px 18px; border-bottom: 1px solid var(--line); }
  #readHead h2 { margin: 0 0 6px; font-size: 16px; word-break: break-word; }
  #readHead .meta { font-size: 12px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }
  #readBody {
    flex: 1; overflow: auto; padding: 16px 18px; white-space: pre-wrap;
    word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 13px; line-height: 1.7;
  }
  #readActions { padding: 10px 18px; border-top: 1px solid var(--line); display: flex; gap: 8px; }
  .placeholder { margin: auto; color: var(--muted); text-align: center; padding: 24px; }

  #toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    background: #111827; color: #fff; padding: 10px 18px; border-radius: 8px;
    font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s;
    max-width: 80vw; z-index: 100;
  }
  #toast.show { opacity: .95; }
  #toast.err { background: var(--danger); }

  @media (max-width: 900px) {
    #listPane { width: 100%; }
    #readPane { display: none; }
    #readPane.on { display: flex; position: absolute; inset: 0; background: var(--bg); z-index: 10; }
    main { position: relative; }
  }