:root {
  --bg: #0a0e14;
  --surface: #10161f;
  --surface-2: #141b26;
  --surface-3: #1c2534;
  --line: #1e2836;
  --text: #e8edf5;
  --muted: #8a97ab;
  --primary: #6c9cff;
  --accent: #3ddcab;
  --danger: #e05c5c;
  --sidebar-w: 264px;
  --list-w: 372px;
}

* { box-sizing: border-box; }

/* hidden 属性必须压过 .mail 的 display:flex */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; color: inherit; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) var(--list-w) minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

/* ---------------- 左栏 ---------------- */

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.side-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 14px 12px;
}

.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }

.logo {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: linear-gradient(135deg, #7fb0ff, #3ddcab);
  color: #06121f;
  font-size: 15px;
}

.brand-name { font-weight: 700; letter-spacing: .3px; font-size: 15px; }

.side-head .icon-btn { margin-left: auto; }

.side-label {
  padding: 6px 18px;
  font-size: 11.5px;
  color: var(--muted);
  letter-spacing: .6px;
  display: flex; gap: 6px; align-items: center;
}

.side-label span {
  background: var(--surface-3);
  border-radius: 6px;
  padding: 0 6px;
  font-size: 11px;
}

.box-list { flex: 1; overflow: auto; padding: 4px 10px 10px; }

.box-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--text);
  border: 1px solid transparent;
}

.box-item + .box-item { margin-top: 4px; }

.box-item:hover { background: var(--surface-2); }

.box-item.active {
  background: rgba(108, 156, 255, .12);
  border-color: rgba(108, 156, 255, .35);
}

.box-item .addr-txt {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.box-item .badge {
  background: var(--primary);
  color: #08111f;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
}

.box-item .del {
  opacity: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 6px;
}

.box-item:hover .del { opacity: 1; }
.box-item .del:hover { color: var(--danger); background: rgba(224, 92, 92, .12); }

.side-foot {
  padding: 12px 18px 16px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.side-foot .sep { margin: 0 8px; color: #33405a; }

/* ---------------- 中栏 ---------------- */

.listpane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  border-right: 1px solid var(--line);
}

.pane-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }

.addr-row { display: flex; align-items: center; gap: 6px; }

.addr {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.meta-row {
  display: flex; align-items: center; gap: 8px;
  margin-top: 10px; flex-wrap: wrap;
}

.pill {
  font-size: 11.5px;
  color: var(--accent);
  background: rgba(61, 220, 171, .1);
  border-radius: 7px;
  padding: 2px 8px;
}
.pill.dim { color: var(--muted); background: var(--surface-3); }

.grow { flex: 1; }

.auto { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); cursor: pointer; }
.auto input { accent-color: var(--primary); }

.search {
  width: 100%;
  margin-top: 10px;
  background: var(--surface-2);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 8px 11px;
  outline: none;
  font-size: 13px;
}
.search::placeholder { color: #5d6b82; }
.search:focus { border-color: rgba(108, 156, 255, .45); }

.msgs { flex: 1; overflow: auto; }

.msg {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 12px 16px;
  cursor: pointer;
  color: var(--text);
}
.msg:hover { background: var(--surface); }
.msg.active { background: rgba(108, 156, 255, .09); }

.msg-top { display: flex; align-items: center; gap: 8px; }
.msg-from { font-size: 13px; font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-time { font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.msg-subject { margin-top: 3px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-intro { margin-top: 3px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); flex: none; }
.dot.read { background: transparent; }

.clip { color: var(--muted); font-size: 12px; }

.empty-list { padding: 48px 22px; text-align: center; color: var(--muted); }
.empty-list .big { font-size: 30px; opacity: .35; margin-bottom: 10px; }

.pane-foot {
  border-top: 1px solid var(--line);
  padding: 8px 16px;
  font-size: 11.5px;
  color: var(--muted);
  min-height: 32px;
}

/* ---------------- 右栏 ---------------- */

.reader { min-width: 0; min-height: 0; display: flex; flex-direction: column; background: var(--bg); overflow: hidden; }

.reader-empty {
  margin: auto;
  text-align: center;
  color: var(--muted);
}
.reader-empty .big { font-size: 42px; opacity: .25; }
.reader-empty p { margin: 8px 0 0; }
.reader-empty .hint { font-size: 12px; opacity: .7; }

.mail { display: flex; flex-direction: column; min-height: 0; height: 100%; }

.mail-head { padding: 20px 26px 12px; border-bottom: 1px solid var(--line); }

.mail-head h1 {
  margin: 0 0 14px;
  font-size: 19px;
  line-height: 1.35;
  font-weight: 650;
  word-break: break-word;
}

.mail-meta { display: flex; align-items: center; gap: 10px; }

.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-3);
  color: var(--primary);
  font-weight: 700;
  font-size: 14px;
  flex: none;
}

.who { flex: 1; min-width: 0; }
.who .from { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .to { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.when { font-size: 11.5px; color: var(--muted); white-space: nowrap; }

.codes { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.codes:empty { display: none; }

.code-chip {
  border: 1px solid rgba(61, 220, 171, .45);
  background: rgba(61, 220, 171, .08);
  color: var(--accent);
  border-radius: 9px;
  padding: 6px 11px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 1.5px;
  cursor: pointer;
}
.code-chip:hover { background: rgba(61, 220, 171, .16); }
.code-chip small { display: block; font-size: 10px; letter-spacing: 0; font-weight: 500; color: var(--muted); }

.mail-body { flex: 1; min-height: 0; overflow: auto; padding: 8px 26px 20px; }

#mailFrame {
  width: 100%;
  min-height: 420px;
  border: 0;
  background: #fff;
  border-radius: 10px;
  margin-top: 12px;
}

.mail-text {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 14px 0 0;
  font: inherit;
  font-size: 13.5px;
  line-height: 1.75;
  color: #cfd8e6;
}

.attachments {
  border-top: 1px solid var(--line);
  padding: 12px 26px 18px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.att {
  display: flex; align-items: center; gap: 9px;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 8px 12px;
  color: var(--text);
  font-size: 12.5px;
}
.att:hover { border-color: rgba(108, 156, 255, .5); text-decoration: none; }
.att .size { color: var(--muted); font-size: 11px; }

/* ---------------- 控件 ---------------- */

.icon-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 8px;
  width: 28px; height: 28px;
  display: inline-grid; place-items: center;
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }

.btn {
  border: 0;
  border-radius: 10px;
  padding: 9px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
}
.btn.primary { background: var(--primary); color: #08111f; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--surface-3); color: var(--text); }
.btn[disabled] { opacity: .5; cursor: default; }

.modal {
  position: fixed; inset: 0;
  background: rgba(4, 8, 13, .72);
  display: grid; place-items: center;
  z-index: 20;
  padding: 20px;
}
.modal[hidden] { display: none; }

.modal-card {
  width: min(420px, 100%);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
}
.modal-card h2 { margin: 0 0 16px; font-size: 17px; }

.modal-card label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.modal-card input, .modal-card select {
  display: block;
  width: 100%;
  margin-top: 6px;
  background: var(--surface-3);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 9px 12px;
  outline: none;
  font-size: 13.5px;
}
.modal-card input:focus, .modal-card select:focus { border-color: rgba(108, 156, 255, .5); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.err { color: var(--danger); font-size: 12px; margin: 0 0 4px; }

.toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translateX(-50%);
  background: var(--surface-3);
  border: 1px solid var(--line);
  color: var(--text);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 30;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.toast[hidden] { display: none; }

.only-narrow { display: none !important; }

/* ---------------- 响应式 ---------------- */

@media (max-width: 1180px) {
  :root { --sidebar-w: 232px; --list-w: 330px; }
}

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0;
    width: 264px; z-index: 15;
    transform: translateX(-100%);
    transition: transform .18s ease;
  }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .6); }
  .listpane { border-right: 0; }
  .reader {
    position: fixed; inset: 0; z-index: 14;
    background: var(--bg);
    transform: translateX(100%);
    transition: transform .2s ease;
  }
  .reader.open { transform: none; }
  .only-narrow { display: inline-grid !important; }
  .mail-head { padding: 16px 18px 10px; }
  .mail-body { padding: 8px 18px 20px; }
  .attachments { padding: 12px 18px 18px; }
}
