:root {
  --bg: #070c1c; --bg2: #0c1428; --panel: #0f1932; --panel2: #15213f; --hover: rgba(79, 140, 255, .08); --sel: rgba(79, 140, 255, .16);
  --line: rgba(120, 160, 255, .13); --line2: rgba(120, 160, 255, .26);
  --text: #e8eeff; --dim: #a4b2d6; --faint: #6b7aa3; --accent: #4f8cff; --accent2: #a9c8ff; --on-accent: #04102c;
  --ok: #3ddc97; --bad: #ff6b81; --star: #f5c451; --shadow: 0 12px 40px rgba(0, 6, 30, .55);
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f4f6fb; --bg2: #ffffff; --panel: #ffffff; --panel2: #eef2fb; --hover: rgba(0, 56, 184, .05); --sel: rgba(0, 56, 184, .1);
  --line: rgba(0, 40, 120, .1); --line2: rgba(0, 40, 120, .2);
  --text: #0d1a36; --dim: #4a5a7e; --faint: #8592b0; --accent: #1f5fe0; --accent2: #1f5fe0; --on-accent: #ffffff;
  --ok: #0f9d68; --bad: #d1345b; --star: #e0a400; --shadow: 0 12px 34px rgba(0, 30, 90, .14);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif; -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent2); }
.ico { display: inline-flex; flex: none; }
.ico svg { display: block; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line2); border-top-color: var(--accent); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.boot { height: 100vh; display: grid; place-items: center; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line2); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
* { scrollbar-width: thin; scrollbar-color: var(--line2) transparent; }

/* buttons + inputs */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; height: 34px; padding: 0 14px; border-radius: 9px; border: 1px solid var(--line2); background: var(--panel2); cursor: pointer; font-weight: 600; white-space: nowrap; transition: background .12s, border-color .12s, transform .1s; }
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--dim); }
.btn.ghost:hover { background: var(--hover); color: var(--text); }
.btn.danger { color: var(--bad); }
.btn[disabled] { opacity: .5; pointer-events: none; }
.iconbtn { width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 50%; border: 0; background: transparent; color: var(--dim); cursor: pointer; transition: background .12s, color .12s; }
.iconbtn:hover { background: var(--hover); color: var(--text); }
.iconbtn.on { color: var(--star); }
.input, .select, .textarea { width: 100%; height: 38px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line2); background: var(--bg); outline: none; transition: border-color .12s, box-shadow .12s; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--dim); }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--dim); cursor: pointer; user-select: none; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }
.err { color: var(--bad); font-size: 13px; min-height: 18px; }
.hint { color: var(--faint); font-size: 12.5px; }
.row { display: flex; align-items: center; gap: 8px; }
.spacer { flex: 1; }

/* auth */
.auth { height: 100vh; overflow: auto; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1000px 600px at 50% -10%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 70%), var(--bg); }
.auth-card { width: 100%; max-width: 400px; padding: 28px 26px; border-radius: 18px; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.auth-logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: .02em; }
.auth-logo .ico { color: var(--accent); }
.auth-sub { color: var(--dim); margin: 6px 0 18px; }
.tabs2 { display: flex; gap: 4px; padding: 4px; border-radius: 11px; background: var(--bg); border: 1px solid var(--line); margin-bottom: 18px; }
.tabs2 button { flex: 1; height: 32px; border: 0; border-radius: 8px; background: transparent; color: var(--dim); font-weight: 650; cursor: pointer; }
.tabs2 button.on { background: var(--panel2); color: var(--text); box-shadow: 0 1px 6px rgba(0, 0, 0, .2); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.suffix { position: relative; }
.suffix .input { padding-right: 140px; }
.suffix span { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--faint); pointer-events: none; }
.code6 { text-align: center; font-size: 22px; letter-spacing: .4em; height: 46px; }

/* shell */
.shell { height: 100vh; display: grid; grid-template-columns: 244px 1fr; grid-template-rows: 58px 1fr; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; padding: 0 14px 0 10px; border-bottom: 1px solid var(--line); background: var(--bg2); }
.brand { display: flex; align-items: center; gap: 9px; width: 222px; font-weight: 800; letter-spacing: .02em; }
.brand .ico { color: var(--accent); }
.brand small { color: var(--faint); font-weight: 600; }
.search { flex: 1; max-width: 680px; display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: 12px; background: var(--panel2); border: 1px solid transparent; transition: border-color .12s, background .12s; }
.search:focus-within { border-color: var(--line2); background: var(--panel); }
.search input { flex: 1; border: 0; outline: 0; background: transparent; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; background: linear-gradient(160deg, #2c5bd8, #10265e); border: 0; cursor: pointer; flex: none; }
.menu-btn { display: none; }

.side { overflow: auto; padding: 12px 10px; border-right: 1px solid var(--line); background: var(--bg2); }
.compose-btn { width: 100%; height: 46px; border-radius: 14px; font-size: 15px; margin-bottom: 12px; box-shadow: 0 6px 20px color-mix(in srgb, var(--accent) 35%, transparent); }
.nav-item { display: flex; align-items: center; gap: 12px; height: 36px; padding: 0 12px; border-radius: 0 18px 18px 0; margin-left: -10px; padding-left: 22px; color: var(--dim); cursor: pointer; user-select: none; border: 0; background: transparent; width: calc(100% + 10px); text-align: left; }
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.on { background: var(--sel); color: var(--text); font-weight: 700; }
.nav-item .n { margin-left: auto; font-size: 12px; font-weight: 700; color: var(--text); }
.nav-item .addr { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.side h4 { margin: 18px 0 6px 12px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--faint); }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }

.main { min-width: 0; min-height: 0; display: flex; }
.listpane { flex: 1; min-width: 0; display: flex; flex-direction: column; border-right: 1px solid var(--line); }
.main.split .listpane { flex: 0 0 440px; }
.toolbar { display: flex; align-items: center; gap: 4px; height: 48px; padding: 0 10px; border-bottom: 1px solid var(--line); flex: none; }
.toolbar .title { font-weight: 700; margin-left: 6px; }
.toolbar .count { color: var(--faint); font-size: 12.5px; margin-left: 8px; }
.list { flex: 1; overflow: auto; }
.item { display: grid; grid-template-columns: 28px 28px minmax(0, 190px) 1fr auto; align-items: center; gap: 6px; height: 46px; padding: 0 14px 0 8px; border-bottom: 1px solid var(--line); cursor: pointer; color: var(--dim); }
.main.split .item { grid-template-columns: 28px 28px 1fr auto; grid-template-rows: auto auto; height: auto; padding: 9px 14px 9px 8px; row-gap: 2px; }
.main.split .item .subj { grid-column: 3 / 5; grid-row: 2; }
.main.split .item .date { grid-column: 4; grid-row: 1; }
.main.split .item input[type=checkbox], .main.split .item .star { grid-row: 1 / 3; }
.item:hover { background: var(--hover); }
.item.sel { background: var(--sel); }
.item.unread { color: var(--text); background: color-mix(in srgb, var(--panel) 60%, transparent); }
.item.unread .from, .item.unread .subj b { font-weight: 750; }
.item .from { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .subj { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .subj b { font-weight: 500; color: var(--text); }
.item .subj span { color: var(--faint); }
.item .date { font-size: 12px; white-space: nowrap; text-align: right; }
.item .clip { color: var(--faint); margin-right: 4px; }
.item input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; justify-self: center; }
.item .star { width: 28px; height: 28px; }
.empty { padding: 60px 20px; text-align: center; color: var(--faint); }
.empty b { display: block; color: var(--dim); font-size: 16px; margin-bottom: 4px; }
.more { padding: 14px; text-align: center; }

.reader { flex: 1; min-width: 0; overflow: auto; background: var(--bg); }
.reader-empty { height: 100%; display: grid; place-items: center; color: var(--faint); }
.rd { max-width: 920px; margin: 0 auto; padding: 18px 26px 60px; }
.rd-actions { display: flex; align-items: center; gap: 2px; margin-bottom: 8px; }
.rd h1 { font-size: 21px; font-weight: 650; margin: 6px 0 16px; word-break: break-word; }
.rd-head { display: flex; gap: 12px; align-items: flex-start; }
.rd-head .avatar { width: 40px; height: 40px; cursor: default; }
.rd-from b { font-weight: 700; }
.rd-from span { color: var(--faint); }
.rd-meta { color: var(--faint); font-size: 12.5px; margin-top: 2px; word-break: break-word; }
.rd-date { margin-left: auto; color: var(--faint); font-size: 12.5px; white-space: nowrap; }
.rd-body { margin-top: 18px; }
.rd-text { white-space: pre-wrap; word-break: break-word; line-height: 1.6; }
.rd-frame { width: 100%; border: 0; border-radius: 12px; background: #fff; min-height: 120px; display: block; }
.banner { display: flex; align-items: center; gap: 10px; padding: 9px 12px; margin-top: 14px; border-radius: 10px; border: 1px solid var(--line2); background: var(--panel2); color: var(--dim); font-size: 13px; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.att { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line2); background: var(--panel); cursor: pointer; max-width: 280px; }
.att:hover { border-color: var(--accent); }
.att span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att small { color: var(--faint); }
.rd-reply { display: flex; gap: 8px; margin-top: 24px; }

/* compose */
.compose { position: fixed; right: 20px; bottom: 0; width: min(560px, calc(100vw - 24px)); height: min(600px, calc(100vh - 70px)); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line2); border-bottom: 0; border-radius: 14px 14px 0 0; box-shadow: var(--shadow); z-index: 40; animation: rise .18s ease both; }
.compose.min { height: 44px; overflow: hidden; }
.compose.max { right: 50%; transform: translateX(50%); width: min(900px, calc(100vw - 24px)); height: calc(100vh - 80px); }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } }
.compose.max { animation: none; }
.c-head { display: flex; align-items: center; gap: 4px; height: 44px; padding: 0 6px 0 16px; border-bottom: 1px solid var(--line); font-weight: 700; cursor: pointer; flex: none; }
.c-head .iconbtn { width: 30px; height: 30px; }
.c-row { display: flex; align-items: center; gap: 8px; padding: 0 14px; border-bottom: 1px solid var(--line); min-height: 40px; flex: none; }
.c-row label { color: var(--faint); width: 44px; font-size: 13px; flex: none; }
.c-row input, .c-row select { flex: 1; border: 0; outline: 0; background: transparent; height: 38px; min-width: 0; }
.c-row select option { background: var(--panel); }
.c-body { flex: 1; border: 0; outline: 0; resize: none; padding: 14px; background: transparent; line-height: 1.55; min-height: 0; }
.c-foot { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); flex: none; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 6px 0 10px; border-radius: 8px; background: var(--panel2); border: 1px solid var(--line); font-size: 12.5px; max-width: 220px; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* menus, modals, toasts */
.pop { position: fixed; z-index: 60; min-width: 220px; padding: 6px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line2); box-shadow: var(--shadow); animation: fade .12s ease both; }
.pop button { display: flex; align-items: center; gap: 10px; width: 100%; height: 36px; padding: 0 10px; border: 0; border-radius: 8px; background: transparent; cursor: pointer; text-align: left; }
.pop button:hover { background: var(--hover); }
.pop .who { padding: 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.pop .who small { display: block; color: var(--faint); }
@keyframes fade { from { opacity: 0; transform: translateY(-4px); } }
.modal-bg { position: fixed; inset: 0; z-index: 70; background: rgba(2, 6, 20, .55); display: grid; place-items: center; padding: 16px; animation: fade .12s ease both; }
.modal { width: min(640px, 100%); max-height: calc(100vh - 32px); overflow: auto; border-radius: 16px; background: var(--panel); border: 1px solid var(--line2); box-shadow: var(--shadow); }
.modal-head { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--line); font-weight: 750; font-size: 16px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 22px; }
.modal-body h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); }
.addr-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.addr-row b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.addr-row .input { width: 160px; height: 32px; }
.sess { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--dim); }
.sess b { color: var(--text); font-weight: 600; }
#toasts { position: fixed; left: 20px; bottom: 20px; z-index: 90; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 11px 16px; border-radius: 10px; background: #1c2a4f; color: #fff; box-shadow: var(--shadow); font-size: 13.5px; max-width: 420px; display: flex; gap: 14px; align-items: center; opacity: 0; transform: translateY(8px); transition: all .2s ease; }
.toast.in { opacity: 1; transform: none; }
.toast.bad { background: #5a1a2b; }
.toast button { background: transparent; border: 0; color: var(--accent2); font-weight: 700; cursor: pointer; padding: 0; }

/* responsive */
@media (max-width: 1100px) { .main.split .listpane { flex: 0 0 360px; } }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; top: 58px; bottom: 0; left: 0; width: 270px; z-index: 50; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .side.open { transform: none; }
  .menu-btn { display: inline-grid; }
  .brand { width: auto; }
  .brand small { display: none; }
  .main.split .listpane { display: none; }
  .main:not(.split) .reader { display: none; }
  .top { gap: 6px; padding: 0 8px; }
  .top > .spacer { display: none; }
  .banner { flex-wrap: wrap; }
  .banner > .spacer { display: none; }
  .rd-head { flex-wrap: wrap; }
  .rd-head > div:nth-child(2) { flex: 1; }
  .rd-date { margin-left: 52px; width: 100%; white-space: normal; }
  .search, .search input { min-width: 0; }
  .shell { grid-template-columns: minmax(0, 1fr); }
  .item { grid-template-columns: 28px 1fr auto; grid-template-rows: auto auto; height: auto; padding: 9px 14px 9px 8px; row-gap: 2px; }
  .item .star { display: none; }
  .item .subj { grid-column: 2 / 4; grid-row: 2; }
  .item .date { grid-column: 3; grid-row: 1; }
  .item input[type=checkbox] { grid-row: 1 / 3; }
  .rd { padding: 14px 14px 60px; }
  .compose { right: 0; width: 100vw; height: calc(100vh - 58px); border-radius: 0; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
