* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif; color: #1f2328; background: #f6f8fa; }
button { font: inherit; cursor: pointer; border: 1px solid #1f6feb; background: #1f6feb; color: #fff; border-radius: 6px; padding: 6px 12px; }
button.ghost { background: transparent; color: #1f6feb; }
input { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid #d0d7de; border-radius: 6px; background: #fff; }
label { display: block; margin: 10px 0; color: #57606a; }
label input { margin-top: 4px; }

/* login */
.login-page { display: flex; align-items: center; justify-content: center; }
.login-box { width: 320px; max-width: 92vw; background: #fff; padding: 24px; border: 1px solid #d0d7de; border-radius: 10px; }
.login-box h1 { margin: 0 0 8px; font-size: 20px; }
.login-box button { width: 100%; margin-top: 8px; padding: 9px; }
.err { background: #ffebe9; color: #cf222e; padding: 8px 10px; border-radius: 6px; margin: 8px 0; }

/* layout */
body:not(.login-page) { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
header { display: flex; align-items: center; gap: 10px; padding: 8px 14px; background: #fff; border-bottom: 1px solid #d0d7de; }
header form { margin: 0; }
.brand { font-weight: 600; font-size: 16px; }
.spacer { flex: 1; }
.who { color: #57606a; }
main { flex: 1; min-height: 0; display: grid; grid-template-columns: 280px 380px 1fr; }
.pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid #d0d7de; background: #fff; }
.pane:last-child { border-right: 0; }
.pane-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-bottom: 1px solid #d0d7de; min-height: 48px; }
.pane-head .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; padding: 4px 8px; }
.list { flex: 1; overflow-y: auto; }
.item { padding: 10px 12px; border-bottom: 1px solid #eaeef2; cursor: pointer; }
.item:hover { background: #f6f8fa; }
.item.active { background: #ddf4ff; }
.row-top { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.meta, .time { color: #6e7781; font-size: 12px; white-space: nowrap; }
.badge { background: #1f6feb; color: #fff; border-radius: 10px; padding: 0 7px; font-size: 12px; }
.item.msg .name { font-weight: 500; }
.item.msg.unread .name, .item.msg.unread .subject { font-weight: 700; }
.subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview { color: #6e7781; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { color: #6e7781; padding: 24px; text-align: center; }
.more { display: block; margin: 10px auto; }

/* verification code chip */
.codechip { display: inline-flex; align-items: center; gap: 8px; margin: 4px 0 2px; padding: 3px 8px;
  border: 1px solid #1a7f37; background: #eafaef; color: #0f5323; border-radius: 6px; cursor: pointer; }
.codechip:hover { background: #d6f5e0; }
.codechip.copied { border-color: #1f6feb; background: #ddf4ff; }
.codecode { font: 600 15px/1.2 ui-monospace, Menlo, Consolas, monospace; letter-spacing: .08em; }
.copyhint { font-size: 11px; opacity: .75; }
.code-row { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; }
.code-label { color: #6e7781; font-size: 12px; }

/* detail */
.detail { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 12px 16px; overflow-y: auto; }
.d-subject { margin: 0 0 8px; font-size: 18px; word-break: break-word; }
.d-meta { background: #f6f8fa; border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; }
.kv { display: flex; gap: 10px; }
.kv .k { color: #6e7781; width: 52px; flex: none; }
.kv .v { word-break: break-all; }
.atts { margin-bottom: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.att { padding: 3px 8px; border: 1px solid #d0d7de; border-radius: 6px; color: #1f6feb; text-decoration: none; }
.tabs { display: flex; gap: 6px; margin-bottom: 6px; }
.tab { padding: 3px 10px; background: transparent; color: #1f6feb; }
.tab.active { background: #1f6feb; color: #fff; }
.d-body { flex: 1; min-height: 420px; display: flex; }
.d-body iframe { flex: 1; width: 100%; border: 1px solid #d0d7de; border-radius: 6px; background: #fff; min-height: 420px; }
.plain { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; width: 100%; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); display: flex; align-items: center; justify-content: center; z-index: 10; }
.modal.hidden { display: none; }
.modal-box { background: #fff; padding: 18px; border-radius: 10px; width: 340px; max-width: 92vw; }
.modal-box h2 { margin: 0 0 6px; font-size: 16px; }
.modal-box .row { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.msg { min-height: 18px; font-size: 13px; }
.msg.ok { color: #1a7f37; }
.msg.bad { color: #cf222e; }

/* mobile: one pane at a time */
@media (max-width: 860px) {
  main { display: block; }
  .pane { display: none; height: 100%; border-right: 0; }
  body.view-boxes #pane-boxes, body.view-list #pane-list, body.view-detail #pane-detail { display: flex; }
  .back { display: inline-block; }
  .who { display: none; }
}
