/* ---------- tokens ---------- */
:root {
    --bg: #f3f4f8;
    --panel: #ffffff;
    --panel-2: #f7f8fb;
    --text: #161a2b;
    --text-2: #4a5068;
    --muted: #8a90a6;
    --line: #e6e8f0;
    --hover: #f4f5fa;
    --active: #eef0ff;
    --accent: #5b5bf7;
    --accent-2: #7c5cf6;
    --accent-soft: #ecebff;
    --accent-text: #ffffff;
    --success: #12a150;
    --success-soft: #e6f7ee;
    --danger: #e5484d;
    --danger-soft: #fdecec;
    --shadow-sm: 0 1px 2px rgba(20, 22, 40, .06);
    --shadow-lg: 0 18px 44px -12px rgba(30, 30, 80, .25);
    --frame-bg: #ffffff;
    color-scheme: light;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0c0e17;
        --panel: #131624;
        --panel-2: #191d2e;
        --text: #eceef7;
        --text-2: #b4b9cf;
        --muted: #7a809a;
        --line: #242941;
        --hover: #1a1e31;
        --active: #21264b;
        --accent: #7c7cff;
        --accent-2: #9f7cff;
        --accent-soft: #252955;
        --success: #3ecf7f;
        --success-soft: #12301f;
        --danger: #ff6b6f;
        --danger-soft: #3a1a1d;
        --shadow-sm: none;
        --shadow-lg: 0 24px 60px -16px rgba(0, 0, 0, .7);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #0c0e17;
    --panel: #131624;
    --panel-2: #191d2e;
    --text: #eceef7;
    --text-2: #b4b9cf;
    --muted: #7a809a;
    --line: #242941;
    --hover: #1a1e31;
    --active: #21264b;
    --accent: #7c7cff;
    --accent-2: #9f7cff;
    --accent-soft: #252955;
    --success: #3ecf7f;
    --success-soft: #12301f;
    --danger: #ff6b6f;
    --danger-soft: #3a1a1d;
    --shadow-sm: none;
    --shadow-lg: 0 24px 60px -16px rgba(0, 0, 0, .7);
    color-scheme: dark;
}

/* ---------- base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 "Be Vietnam Pro", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.i {
    width: 18px; height: 18px; flex: none;
    fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.shell { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }

/* ---------- top bar ---------- */
.topbar {
    display: flex; align-items: center; gap: 24px;
    padding: 12px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
    position: relative; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-mark {
    display: grid; place-items: center; width: 36px; height: 36px; border-radius: 11px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff;
    box-shadow: 0 6px 14px -4px rgba(91, 91, 247, .55);
}
.brand-name { font-size: 17px; font-weight: 500; letter-spacing: -.01em; }
.brand-name b { font-weight: 700; }

.addr { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.addr-input {
    display: flex; align-items: center; gap: 8px; flex: 0 1 440px; min-width: 0; height: 42px;
    padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-2);
    cursor: text; transition: border-color .15s, box-shadow .15s, background .15s;
}
.addr-input:hover { border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); }
.addr-input:focus-within { border-color: var(--accent); background: var(--panel); box-shadow: 0 0 0 4px var(--accent-soft); }
.addr-input > .i { color: var(--muted); width: 17px; height: 17px; }
.addr-input input { flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent; font-weight: 600; font-size: 15px; }
.addr-input input::placeholder { color: var(--muted); font-weight: 400; }
.addr-sep { color: var(--muted); }
.addr-domain { color: var(--muted); font-weight: 500; white-space: nowrap; }
select.addr-domain { border: 0; background: transparent; cursor: pointer; outline: 0; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    height: 42px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
    background: var(--panel); color: var(--text-2); font-weight: 600; white-space: nowrap; flex: none;
    transition: background .15s, color .15s, border-color .15s, transform .1s, filter .15s;
}
.btn:hover { background: var(--hover); color: var(--text); }
.btn:active { transform: scale(.97); }
.btn .i { width: 17px; height: 17px; }
.btn-icon { width: 42px; padding: 0; }
.btn-primary {
    border: 0; color: var(--accent-text); padding: 0 22px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 6px 16px -6px rgba(91, 91, 247, .7);
}
.btn-primary:hover { color: var(--accent-text); background: linear-gradient(135deg, var(--accent), var(--accent-2)); filter: brightness(1.08); }
.btn.done { color: var(--success); border-color: color-mix(in srgb, var(--success) 40%, var(--line)); background: var(--success-soft); }
.btn-primary.done { color: #fff; background: var(--success); }
.btn-sm { height: 34px; padding: 0 12px; border-radius: 10px; font-size: 13px; }

.icon-btn {
    display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; flex: none;
    border: 0; background: transparent; color: var(--text-2); text-decoration: none;
    transition: background .15s, color .15s, transform .1s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:active { transform: scale(.94); }
.icon-btn.danger:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn.spin .i { animation: spin .7s linear; }
.theme-btn { margin-left: auto; }

.menu-wrap { position: relative; }
.menu {
    position: absolute; top: calc(100% + 8px); right: 0; z-index: 30;
    width: 300px; max-width: calc(100vw - 32px); padding: 6px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow-lg);
    animation: pop .14s ease-out;
}
.menu-title { padding: 8px 10px 6px; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.menu-item {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 10px; border: 0; border-radius: 9px;
    background: transparent; text-align: left; font-size: 14px;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); outline: none; }
.menu-item.current { color: var(--accent); font-weight: 600; }
.menu-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-item .i { width: 16px; height: 16px; color: var(--muted); }
.menu-item.current .i { color: var(--accent); }
.menu-sep { height: 1px; margin: 6px 4px; background: var(--line); }
.menu-empty { padding: 12px 10px; color: var(--muted); }

/* ---------- layout ---------- */
.layout { flex: 1; min-height: 0; display: grid; grid-template-columns: 400px 1fr; }

/* sidebar */
.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--line); }
.side-head {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 16px 12px 14px 20px; border-bottom: 1px solid var(--line);
}
.side-info { min-width: 0; }
.side-addr { font-size: 15px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-status { display: flex; align-items: center; gap: 7px; margin-top: 2px; font-size: 12px; color: var(--muted); }
.live { position: relative; width: 7px; height: 7px; border-radius: 50%; background: var(--success); flex: none; }
.live::after {
    content: ""; position: absolute; inset: 0; border-radius: 50%; background: inherit;
    animation: ping 1.8s cubic-bezier(0, 0, .2, 1) infinite;
}
.live.error { background: var(--danger); }
.live.error::after { animation: none; }

.list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.list:empty { display: none; }
.item {
    position: relative; display: grid; grid-template-columns: 38px 1fr; gap: 12px;
    padding: 12px; border-radius: 12px; cursor: pointer; transition: background .12s;
}
.item + .item { margin-top: 2px; }
.item:hover { background: var(--hover); }
.item.active { background: var(--active); }
.item.active::before {
    content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 3px; border-radius: 0 3px 3px 0;
    background: var(--accent);
}
.item.fresh { animation: slideIn .4s ease-out; }
.item-main { min-width: 0; }
.item-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.item-from { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-time { flex: none; font-size: 12px; color: var(--muted); }
.item-subj { font-size: 13.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-prev { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-tags { display: flex; gap: 6px; margin-top: 6px; }
.item.unread .item-from, .item.unread .item-subj { font-weight: 700; color: var(--text); }
.item.unread .item-time { color: var(--accent); font-weight: 600; }
.item.unread .item-time::after {
    content: ""; display: inline-block; width: 7px; height: 7px; margin-left: 6px; border-radius: 50%;
    background: var(--accent); vertical-align: 1px;
}

.tag {
    display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 6px;
    font-size: 12px; font-weight: 600; background: var(--panel-2); color: var(--text-2); border: 1px solid var(--line);
}
.tag .i { width: 13px; height: 13px; }
.tag-code { background: var(--accent-soft); color: var(--accent); border-color: transparent; letter-spacing: .04em; font-variant-numeric: tabular-nums; }

.avatar {
    --h: 240;
    display: grid; place-items: center; width: 38px; height: 38px; border-radius: 11px; flex: none;
    background: hsl(var(--h) 85% 94%); color: hsl(var(--h) 55% 38%); font-weight: 700; font-size: 14px;
}
:root[data-theme="dark"] .avatar { background: hsl(var(--h) 40% 22%); color: hsl(var(--h) 80% 80%); }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .avatar { background: hsl(var(--h) 40% 22%); color: hsl(var(--h) 80% 80%); }
}
.avatar.lg { width: 44px; height: 44px; border-radius: 13px; font-size: 16px; }

.skel { pointer-events: none; }
.skel .bar, .skel .avatar {
    background: linear-gradient(90deg, var(--hover) 25%, var(--panel-2) 50%, var(--hover) 75%);
    background-size: 200% 100%; animation: shimmer 1.2s infinite linear; color: transparent;
}
.skel .bar { height: 10px; border-radius: 6px; margin: 6px 0; }

.empty { margin: auto; padding: 32px 28px; text-align: center; }
.empty h3 { margin: 18px 0 6px; font-size: 16px; }
.empty p { margin: 0; color: var(--muted); }
.empty-art {
    position: relative; display: grid; place-items: center; width: 76px; height: 76px; margin: 0 auto;
    border-radius: 24px; background: var(--accent-soft); color: var(--accent);
}
.empty-art .i { width: 32px; height: 32px; stroke-width: 1.6; }
.ring { position: absolute; inset: -9px; border-radius: 30px; border: 2px solid var(--accent); opacity: 0; animation: ripple 2.4s ease-out infinite; }
.ring.r2 { animation-delay: 1.2s; }

.side-note { margin: 0; padding: 10px 20px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

/* reader */
.reader { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.reader-empty { margin: auto; text-align: center; color: var(--muted); padding: 40px; }
.reader-empty .ill {
    display: grid; place-items: center; width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 22px;
    background: var(--panel); border: 1px solid var(--line); color: var(--muted);
}
.reader-empty .ill .i { width: 30px; height: 30px; stroke-width: 1.5; }
.reader-empty p { margin: 0; }

.msg-head { padding: 16px 28px 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.msg-bar { display: flex; align-items: center; gap: 6px; margin: 0 -8px 8px 0; }
.msg-bar .spacer { flex: 1; }
.back { display: none; }
.msg-subject { margin: 0 0 14px; font-size: 21px; line-height: 1.35; font-weight: 700; letter-spacing: -.01em; word-break: break-word; }
.msg-meta { display: flex; align-items: center; gap: 12px; min-width: 0; }
.msg-who { min-width: 0; flex: 1; }
.msg-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-name span { font-weight: 400; color: var(--muted); font-size: 13px; }
.msg-addr { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-time { flex: none; text-align: right; font-size: 12.5px; color: var(--muted); line-height: 1.6; }

.seg { display: inline-flex; padding: 3px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); }
.seg button { height: 28px; padding: 0 12px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; }
.seg button[aria-selected="true"] { background: var(--panel); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--line); }

.extras { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px 28px; background: var(--panel); border-bottom: 1px solid var(--line); }
.extras:empty { display: none; }
.otp {
    display: flex; align-items: center; gap: 14px; padding: 10px 10px 10px 12px; border-radius: 14px;
    background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent) 22%, transparent);
}
.otp-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 10px; background: var(--panel); color: var(--accent); }
.otp-label { font-size: 11px; font-weight: 700; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em; }
.otp-code { font-size: 22px; font-weight: 700; letter-spacing: .12em; line-height: 1.15; font-variant-numeric: tabular-nums; }
.att {
    display: flex; align-items: center; gap: 10px; max-width: 280px; padding: 8px 12px 8px 8px;
    border: 1px solid var(--line); border-radius: 12px; color: var(--text); text-decoration: none; background: var(--panel);
    transition: border-color .15s, background .15s;
}
.att:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); background: var(--hover); }
.att-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); flex: none; }
.att > div { min-width: 0; }
.att-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-size { font-size: 12px; color: var(--muted); }
.att .dl { color: var(--muted); width: 16px; height: 16px; }

.msg-body { flex: 1; min-height: 0; display: flex; }
.mail-frame { flex: 1; width: 100%; border: 0; background: var(--frame-bg); }
.mail-text {
    flex: 1; margin: 0; padding: 24px 28px; overflow: auto; white-space: pre-wrap; word-break: break-word;
    background: var(--panel); font: 14px/1.7 ui-monospace, SFMono-Regular, Consolas, monospace;
}

/* toast */
.toast {
    position: fixed; left: 50%; bottom: 24px; z-index: 50;
    display: flex; align-items: center; gap: 8px; padding: 11px 16px; border-radius: 12px;
    background: var(--text); color: var(--bg); font-size: 14px; font-weight: 500; box-shadow: var(--shadow-lg);
    opacity: 0; transform: translate(-50%, 12px); pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast .i { width: 16px; height: 16px; }

/* animations */
@keyframes ping { 75%, 100% { transform: scale(2.6); opacity: 0; } }
@keyframes ripple { 0% { transform: scale(.85); opacity: .35; } 100% { transform: scale(1.25); opacity: 0; } }
@keyframes shimmer { to { background-position: -200% 0; } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } }
@keyframes slideIn { from { opacity: 0; transform: translateY(-6px); background: var(--accent-soft); } }
@keyframes sheet { from { transform: translateY(16px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
    .btn .lbl { display: none; }
    #btn-random, #btn-copy { width: 42px; padding: 0; }
    .layout { grid-template-columns: 340px 1fr; }
}
@media (max-width: 820px) {
    .shell { height: auto; min-height: 100vh; }
    .topbar { flex-wrap: wrap; gap: 12px; padding: 12px 16px; }
    .addr { order: 3; flex: 1 1 100%; flex-wrap: wrap; }
    .addr-input { flex: 1 1 100%; }
    .addr .btn-primary { flex: 1; }
    .layout { grid-template-columns: 1fr; }
    .sidebar { border-right: 0; min-height: calc(100vh - 130px); }
    .reader { display: none; }
    body.reading { overflow: hidden; }
    body.reading .reader { display: flex; position: fixed; inset: 0; z-index: 40; animation: sheet .22s ease-out; }
    .back { display: inline-grid; }
    .msg-head { padding: 10px 16px 14px; }
    .extras { padding: 12px 16px; }
    .mail-text { padding: 18px 16px; }
    .msg-time { display: none; }
}
@media (max-width: 480px) {
    .brand-name { font-size: 15px; }
    .addr-domain { font-size: 13px; }
    .btn-primary { padding: 0 16px; }
    .otp { flex: 1 1 100%; }
    .otp .btn { margin-left: auto; }
}
