:root {
  --bg: #0a0e14;
  --bg2: #11161f;
  --bg3: #18202c;
  --bg4: #223045;
  --bd: #263140;
  --t1: #e6edf3;
  --t2: #8b98a9;
  --t3: #5a6673;
  --ac: #4a9eff;
  --grn: #4aff8a;
  --red: #ff5c5c;
  --yel: #ffc35c;
  --deep: #04101f;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { background: var(--bg); color: var(--t1); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; min-height: 100vh; }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 22px; background: var(--bg2); border-bottom: 1px solid var(--bd); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; }
.logo { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; display: block; }
.brand-text h1 { font-size: 18px; font-weight: 700; }
.brand-text h1 span { color: var(--ac); }
.brand-text p { font-size: 12px; color: var(--t2); margin-top: 2px; }
.actions { display: flex; gap: 8px; }

/* Buttons */
.btn { padding: 9px 16px; border-radius: 8px; border: 1px solid var(--bd); background: var(--bg3); color: var(--t1); font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s; }
.btn:hover { border-color: var(--ac); }
.btn.primary { background: var(--ac); color: var(--deep); border-color: var(--ac); }
.btn.primary:hover { filter: brightness(1.12); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 12px; font-size: 12px; }
.btn.block { width: 100%; margin-top: 14px; }
.btn.danger { color: var(--red); }
.btn.danger:hover { border-color: var(--red); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Layout */
.layout { display: grid; grid-template-columns: 260px 1fr 1fr; gap: 0; height: calc(100vh - 69px); }
.sidebar { border-right: 1px solid var(--bd); background: var(--bg2); overflow-y: auto; padding: 16px 0; }
.col { overflow-y: auto; display: flex; flex-direction: column; min-width: 0; }
.col-list { border-right: 1px solid var(--bd); }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 0 16px 12px; }
.side-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 1px; color: var(--t2); }
.pill { background: var(--bg4, #223045); border: 1px solid var(--bd); color: var(--t2); font-size: 11px; padding: 2px 8px; border-radius: 12px; }

/* Mailbox list */
.mb-item { display: flex; align-items: center; gap: 8px; padding: 10px 16px; cursor: pointer; border-left: 3px solid transparent; }
.mb-item:hover { background: var(--bg3); }
.mb-item.active { background: var(--bg3); border-left-color: var(--ac); }
.mb-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--bg4, #223045); border: 1px solid var(--bd); display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--ac); flex-shrink: 0; }
.mb-meta { flex: 1; min-width: 0; }
.mb-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mb-addr { font-size: 11px; color: var(--t3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mb-count { font-size: 11px; color: var(--t2); background: var(--bg3); border: 1px solid var(--bd); padding: 1px 7px; border-radius: 10px; }
.mb-del { background: none; border: none; color: var(--t3); cursor: pointer; font-size: 14px; padding: 2px 4px; }
.mb-del:hover { color: var(--red); }
.mb-actions { display: none; flex-direction: column; gap: 4px; align-items: center; }
.mb-item:hover .mb-actions { display: flex; }
.mb-copy { background: none; border: none; color: var(--t3); cursor: pointer; font-size: 12px; padding: 2px 4px; }
.mb-copy:hover { color: var(--ac); }

/* Message list tools */
.list-tools { display: flex; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--bd); position: sticky; top: 0; background: var(--bg); z-index: 5; }
.list-tools input, .list-tools select { background: var(--bg3); border: 1px solid var(--bd); color: var(--t1); border-radius: 8px; padding: 8px 10px; font-size: 13px; outline: none; }
.list-tools input { flex: 1; }
.list-tools input:focus, .list-tools select:focus { border-color: var(--ac); }

.msg-list { flex: 1; overflow-y: auto; }
.msg-item { padding: 12px 14px; border-bottom: 1px solid var(--bd); cursor: pointer; transition: background .1s; }
.msg-item:hover { background: var(--bg3); }
.msg-item.active { background: var(--bg3); border-left: 3px solid var(--ac); }
.msg-item.unread { background: rgba(74,158,255,.06); }
.msg-top { display: flex; justify-content: space-between; gap: 8px; }
.msg-sender { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-subject { font-size: 14px; color: var(--t2); margin: 3px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-time { font-size: 11px; color: var(--t3); white-space: nowrap; }
.msg-rcpt { font-size: 11px; color: var(--t3); margin-top: 4px; }
.unread-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ac); display: inline-block; margin-right: 6px; }
.att-chip { display: inline-block; font-size: 11px; color: var(--yel); background: var(--bg3); border: 1px solid var(--bd); padding: 1px 6px; border-radius: 4px; margin-top: 6px; }

.empty { padding: 30px; text-align: center; color: var(--t3); font-size: 13px; }

/* Pager */
.pager { padding: 10px 14px; border-top: 1px solid var(--bd); display: flex; align-items: center; justify-content: space-between; }
.pager span { font-size: 12px; color: var(--t2); }
.hidden { display: none !important; }

/* Message view */
.msg-view { padding: 22px; max-width: 760px; }
.view-head h3 { font-size: 20px; margin-bottom: 6px; }
.view-meta { font-size: 13px; color: var(--t2); margin: 2px 0; }
.view-meta b { color: var(--t1); font-weight: 600; }
.view-code { margin: 16px 0; padding: 14px 18px; background: var(--bg3); border: 1px solid var(--ac); border-radius: 10px; display: inline-block; }
.view-code .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--t2); margin-bottom: 4px; }
.view-code .code { font-size: 36px; font-weight: 800; letter-spacing: 8px; color: var(--ac); font-family: 'SF Mono', Consolas, monospace; }
.view-code .copy { margin-left: 12px; }
.view-actions { display: flex; gap: 8px; margin: 16px 0; }
.view-body { background: var(--bg2); border: 1px solid var(--bd); border-radius: 10px; padding: 20px; font-size: 14px; line-height: 1.7; overflow-wrap: break-word; margin-top: 12px; }
.view-body a { color: var(--ac); }
.view-att { margin-top: 16px; }
.view-att h4 { font-size: 13px; color: var(--t2); margin-bottom: 8px; }
.att-item { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--bg3); border: 1px solid var(--bd); border-radius: 8px; margin-bottom: 8px; }
.att-item .fi { width: 32px; height: 32px; border-radius: 6px; background: var(--bg4, #223045); display: grid; place-items: center; font-weight: 700; color: var(--ac); }
.att-item .fm { flex: 1; }
.att-item .fm .fn { font-size: 13px; font-weight: 600; }
.att-item .fm .fs { font-size: 11px; color: var(--t3); }
.att-dl { color: var(--ac); text-decoration: none; font-size: 13px; font-weight: 600; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal-card { background: var(--bg2); border: 1px solid var(--bd); border-radius: 12px; padding: 26px; width: 420px; max-width: 92vw; position: relative; }
.modal-card h2 { font-size: 17px; margin-bottom: 14px; }
.modal-close { position: absolute; top: 12px; right: 14px; background: none; border: none; color: var(--t3); font-size: 22px; cursor: pointer; }
.modal-card label { display: block; font-size: 12px; color: var(--t2); margin: 12px 0 4px; }
.modal-card input { width: 100%; background: var(--bg3); border: 1px solid var(--bd); color: var(--t1); border-radius: 8px; padding: 10px 12px; font-size: 14px; outline: none; }
.modal-card input:focus { border-color: var(--ac); }
#modal-result { margin-top: 14px; background: var(--bg3); border: 1px solid var(--bd); border-radius: 8px; padding: 12px; font-size: 12px; overflow: auto; max-height: 200px; }

/* Toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--bg3); border: 1px solid var(--ac); color: var(--t1); padding: 10px 18px; border-radius: 8px; font-size: 13px; z-index: 60; box-shadow: 0 4px 20px rgba(0,0,0,.4); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--bd); max-height: 180px; }
  .col { min-height: 300px; }
}