/* JMail design system — tokens are the single source of truth (design.md §4) */
:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --surface-2: #f1f3f5;
    --text: #1a1d21;
    --text-2: #5c6470;
    --text-3: #9aa1ab;
    --line: #e4e7eb;
    --line-2: #d4d9df;
    --accent: #3b5bdb;
    --accent-weak: #edf1fd;
    --danger: #d64545;
    --success: #2f9e63;
    --warning: #d9930d;
    --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    --shadow-pop: 0 4px 16px rgba(20, 22, 26, .12);
    --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang PingFang SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
#app { height: 100%; }
a { color: var(--accent); text-decoration: none; }
.mono { font-family: var(--mono); }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- layout ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: 24px; display: flex; flex-direction: column; gap: 24px; }
.page-title { font-size: 15px; font-weight: 600; margin: 0; }
.section-title { font-size: 13px; font-weight: 600; margin: 0 0 12px; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-pad { padding: 16px; }

/* ---------- shell ---------- */
.shell { display: flex; height: 100%; }
.nav {
    width: 220px; flex: none; background: var(--surface); border-right: 1px solid var(--line);
    display: flex; flex-direction: column; padding: 16px 0;
}
.nav-brand { display: flex; align-items: center; gap: 10px; padding: 4px 20px 20px; }
.nav-brand-logo { width: 26px; height: 26px; border-radius: 6px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px; flex: none; }
.nav-brand-name { font-size: 15px; font-weight: 600; }
.nav-items { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.nav-item {
    display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px;
    color: var(--text-2); cursor: pointer; border: none; background: none; text-align: left; width: 100%;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.nav-item svg { flex: none; }
.nav-foot { padding: 12px 10px 0; border-top: 1px solid var(--line); }
.nav-user { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; }
.nav-user-mail { font-size: 12px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.icon-btn {
    display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px;
    border: none; background: none; border-radius: 6px; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: #fdf1f1; color: var(--danger); }
.main { flex: 1; min-width: 0; overflow: auto; }

/* ---------- stats ---------- */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat { padding: 16px; }
.stat .stat-label { font-size: 12px; color: var(--text-3); }
.stat .stat-value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 4px; }
.stat .stat-value.alert { color: var(--danger); }

/* ---------- table ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
    text-align: left; font-size: 12px; font-weight: 600; color: var(--text-3);
    padding: 0 12px; height: 36px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; background: var(--surface);
}
.table td { padding: 0 12px; height: 40px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { font-variant-numeric: tabular-nums; }
.table-actions { display: flex; gap: 4px; justify-content: flex-end; }
.table-scroll { overflow: auto; max-height: 640px; }
.table-empty { padding: 40px; text-align: center; color: var(--text-3); }
.cell-clip { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- status & tags ---------- */
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.dot.ok { background: var(--success); }
.dot.err { background: var(--danger); }
.dot.off { background: var(--text-3); }
.tag {
    display: inline-block; font-size: 12px; line-height: 18px; padding: 0 7px;
    border: 1px solid var(--line-2); border-radius: 4px; color: var(--text-2); white-space: nowrap;
}
.tag.err { color: var(--danger); border-color: var(--danger); }
.tag.ok { color: var(--success); border-color: var(--success); }

/* ---------- buttons & inputs ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px;
    border-radius: 6px; border: 1px solid var(--line-2); background: var(--surface);
    color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: #3450c2; }
.btn--danger { border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: #fdf1f1; }
.btn--sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn--block { width: 100%; justify-content: center; }

.input, .select, textarea.input {
    height: 36px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 6px;
    background: var(--surface); color: var(--text); font: inherit; width: 100%;
}
textarea.input { height: auto; padding: 10px; line-height: 1.5; }
.select { appearance: auto; }
.input:focus, .select:focus, textarea.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(59, 91, 219, .25); }
.input:disabled, .select:disabled { background: var(--surface-2); color: var(--text-3); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label { font-size: 12px; color: var(--text-2); font-weight: 600; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span2 { grid-column: span 2; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar .search { position: relative; flex: 1; min-width: 220px; max-width: 360px; }
.toolbar .search .input { padding-left: 32px; }
.toolbar .search svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.toolbar-right { margin-left: auto; display: flex; gap: 8px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 400px; }
.login-head { text-align: center; margin-bottom: 24px; }
.login-head h1 { font-size: 20px; font-weight: 600; margin: 12px 0 4px; }
.login-head p { margin: 0; color: var(--text-3); font-size: 12px; }
.login-logo { width: 44px; height: 44px; border-radius: 10px; background: var(--accent); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 22px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.form-error {
    border: 1px solid var(--danger); color: var(--danger); background: #fdf3f3;
    border-radius: 6px; padding: 8px 12px; font-size: 12px;
}

/* ---------- inbox ---------- */
.inbox { display: flex; height: 100%; min-height: 0; }
.inbox-side { width: 240px; flex: none; border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.inbox-filters { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; border-bottom: 1px solid var(--line); }
.filter-item {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
    padding: 7px 10px; border-radius: 6px; border: none; background: none; cursor: pointer;
    color: var(--text-2); width: 100%; text-align: left; font-size: 13px;
}
.filter-item:hover { background: var(--surface-2); color: var(--text); }
.filter-item.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.filter-item .count { font-size: 12px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.inbox-accounts { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 10px; gap: 8px; }
.inbox-accounts-head { display: flex; gap: 4px; align-items: center; }
.mini-tab {
    border: 1px solid var(--line-2); background: none; border-radius: 4px; cursor: pointer;
    font-size: 12px; line-height: 20px; padding: 0 8px; color: var(--text-2);
}
.mini-tab.on { background: var(--accent-weak); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.account-list { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 1px; }
.account-item {
    display: flex; align-items: center; justify-content: space-between; gap: 6px;
    padding: 6px 8px; border-radius: 6px; cursor: pointer; border: none; background: none;
    text-align: left; color: var(--text-2); font-size: 12px; min-width: 0;
}
.account-item:hover { background: var(--surface-2); }
.account-item.active { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.account-item .a-mail { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account-item .a-n { color: var(--text-3); font-variant-numeric: tabular-nums; flex: none; }
.account-item.active .a-n { color: var(--accent); }
.account-item .a-dot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--danger); opacity: .5; }

.inbox-list { width: 400px; flex: none; min-width: 340px; border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.inbox-list-tools { padding: 10px 12px; border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; }
.inbox-list-tools .search { position: relative; flex: 1; }
.inbox-list-tools .search .input { height: 32px; padding-left: 30px; }
.inbox-list-tools .search svg { position: absolute; left: 8px; top: 50%; transform: translateY(-50%); color: var(--text-3); }
.mail-rows { flex: 1; overflow: auto; }
.mail-row {
    display: block; width: 100%; text-align: left; border: none; background: none; cursor: pointer;
    padding: 10px 14px 10px 11px; border-bottom: 1px solid var(--line); position: relative;
}
.mail-row:hover { background: var(--surface-2); }
.mail-row.active { background: var(--accent-weak); }
.mail-row.unread { box-shadow: inset 3px 0 0 var(--accent); }
.mail-row-top { display: flex; align-items: baseline; gap: 8px; }
.mail-from { font-size: 13px; color: var(--text-2); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-row.unread .mail-from { color: var(--text); font-weight: 600; }
.mail-time { font-size: 12px; color: var(--text-3); flex: none; font-variant-numeric: tabular-nums; }
.mail-subject { font-size: 13px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.mail-row.unread .mail-subject { font-weight: 600; }
.mail-preview { font-size: 12px; color: var(--text-3); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-box-tag { font-size: 11px; color: var(--text-3); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; line-height: 16px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-more { padding: 10px; display: flex; justify-content: center; }
.list-status { padding: 32px; text-align: center; color: var(--text-3); }
.list-status.error { color: var(--danger); }

.inbox-reader { flex: 1; min-width: 0; background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.reader-head { padding: 14px 20px 12px; border-bottom: 1px solid var(--line); }
.reader-topline { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.reader-subject { font-size: 15px; font-weight: 600; margin: 8px 0; line-height: 1.4; overflow-wrap: anywhere; }
.reader-meta { font-size: 12px; color: var(--text-3); display: flex; flex-direction: column; gap: 2px; }
.reader-meta b { color: var(--text-2); font-weight: 600; }
.reader-actions { display: flex; gap: 4px; }
.reader-body { flex: 1; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.reader-body iframe { flex: 1; border: none; background: #fff; }
.reader-text { flex: 1; overflow: auto; padding: 20px; white-space: pre-wrap; font-size: 13px; line-height: 1.7; overflow-wrap: anywhere; }
.reader-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-3); }

/* ---------- skeleton / toast / modal ---------- */
.skel-row { padding: 12px 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.skel { border-radius: 6px; background: var(--surface-2); height: 12px; }
.skel.w60 { width: 60%; } .skel.w80 { width: 80%; } .skel.w40 { width: 40%; }
.toasts { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
    background: var(--surface); border: 1px solid var(--line-2); border-left: 3px solid var(--accent);
    border-radius: 6px; box-shadow: var(--shadow-pop); padding: 10px 14px; min-width: 240px; max-width: 380px;
    font-size: 13px;
}
.toast.err { border-left-color: var(--danger); }
.toast.ok { border-left-color: var(--success); }

.modal-mask { position: fixed; inset: 0; background: rgba(20, 22, 26, .4); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 8vh 16px 16px; }
.modal { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-pop); width: 100%; max-width: 560px; max-height: 84vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 600; }
.modal-body { padding: 16px; overflow: auto; display: flex; flex-direction: column; gap: 12px; }

/* ---------- pager ---------- */
.pager { display: flex; align-items: center; gap: 8px; justify-content: flex-end; padding: 10px 4px 0; font-size: 12px; color: var(--text-3); }

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
    .nav { width: 56px; }
    .nav-brand-name, .nav-item span, .nav-user-mail { display: none; }
    .nav-brand, .nav-item { justify-content: center; }
    .inbox-list { width: 340px; min-width: 300px; }
}
@media (max-width: 960px) {
    .stat-row { grid-template-columns: repeat(2, 1fr); }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .span2 { grid-column: span 1; }
    .inbox-side { display: none; }
    .inbox { position: relative; }
    .inbox-list { width: 100%; flex: 1; min-width: 0; border-right: none; }
    .inbox-reader { position: absolute; inset: 0; z-index: 10; }
}
@media (prefers-reduced-motion: reduce) {
    * { transition: none !important; animation: none !important; }
}
