:root {
    --sidebar-w: 232px;
    --brand: #6366f1;
    --brand-2: #8b5cf6;
    --surface: #f5f6fa;
    --pane-border: rgba(0, 0, 0, .07);
}
[data-bs-theme="dark"] {
    --surface: #0f1115;
    --pane-border: rgba(255, 255, 255, .08);
}
[data-bs-theme="dark"] .card, [data-bs-theme="dark"] .pane { background: #171a21; }
[data-bs-theme="dark"] .table-light { --bs-table-bg: #1d2129; --bs-table-color: #cfd3dc; }

body { background: var(--surface); font-feature-settings: "tnum"; }
.btn-primary { --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-hover-bg: #4f46e5; --bs-btn-hover-border-color: #4f46e5; --bs-btn-active-bg: #4338ca; }
.min-w-0 { min-width: 0; }

/* вход */
.login-bg { background: radial-gradient(1200px 600px at 10% 0%, rgba(99, 102, 241, .25), transparent), radial-gradient(900px 500px at 100% 100%, rgba(139, 92, 246, .22), transparent), var(--surface); }
.login-card { width: 100%; max-width: 400px; border-radius: 1rem; }
.brand-mark { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; color: #fff; font-size: 1.6rem; background: linear-gradient(135deg, var(--brand), var(--brand-2)); box-shadow: 0 8px 24px rgba(99, 102, 241, .35); }
.brand-mark.sm { width: 34px; height: 34px; border-radius: 10px; font-size: 1rem; box-shadow: none; }

/* сайдбар */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); padding: 1rem .75rem; background: #111827; color: #cbd5e1; z-index: 1030; }
.sidebar-brand { color: #fff; padding: .25rem .5rem; }
.sidebar .nav-link { color: #cbd5e1; display: flex; align-items: center; gap: .7rem; border-radius: .6rem; padding: .55rem .75rem; background: none; border: 0; width: 100%; }
.sidebar .nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sidebar .nav-link.active { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; }
.sidebar .nav-link i { font-size: 1.1rem; }
.main { margin-left: var(--sidebar-w); min-height: 100vh; }
.view { display: none; }
.view.active { display: block; }

/* почта: три панели */
.mail-layout { display: grid; grid-template-columns: 300px 380px 1fr; height: 100vh; gap: 0; }
.pane { background: var(--bs-body-bg); border-right: 1px solid var(--pane-border); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: .9rem 1rem; border-bottom: 1px solid var(--pane-border); }
.pane-boxes .pane-head { border-bottom: 0; }
.pane-body { overflow-y: auto; flex: 1; min-height: 0; }

.box-item, .msg-item { display: block; width: 100%; text-align: left; border: 0; background: none; color: inherit; padding: .7rem 1rem; border-left: 3px solid transparent; }
.box-item:hover, .msg-item:hover { background: var(--bs-tertiary-bg); }
.box-item.active, .msg-item.active { background: rgba(99, 102, 241, .1); border-left-color: var(--brand); }
.box-item .addr { font-weight: 500; font-size: .92rem; word-break: break-all; }
.box-item .meta { font-size: .75rem; color: var(--bs-secondary-color); }
.msg-item { border-bottom: 1px solid var(--pane-border); }
.box-item .note { font-size: .78rem; color: var(--bs-secondary-color); font-style: italic; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.box-comment { padding: .6rem 1rem; border-bottom: 1px solid var(--pane-border); background: var(--bs-tertiary-bg); }
#box-comment-text { white-space: pre-wrap; }
#box-comment-text.empty { color: var(--bs-secondary-color); font-style: italic; }
.msg-item .from { font-size: .9rem; }
.msg-item .subj { font-size: .88rem; }
.msg-item .snip { font-size: .8rem; color: var(--bs-secondary-color); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.msg-item.unread .from, .msg-item.unread .subj { font-weight: 600; }
.msg-item.unread .dot { display: inline-block; }
.dot { display: none; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); flex-shrink: 0; }
.msg-time { font-size: .75rem; color: var(--bs-secondary-color); white-space: nowrap; }

.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem; color: var(--bs-secondary-color); padding: 2rem; text-align: center; }
.empty-state i { font-size: 2.5rem; opacity: .5; }

#reader:not(.d-none) { display: flex; }
#r-body { display: flex; flex-direction: column; }
#r-body iframe { width: 100%; flex: 1; border: 0; background: #fff; border-radius: .5rem; min-height: 420px; }
#r-body pre { white-space: pre-wrap; word-break: break-word; font-size: .88rem; }
.att-chip { display: inline-flex; align-items: center; gap: .4rem; padding: .3rem .6rem; border: 1px solid var(--pane-border); border-radius: .5rem; font-size: .82rem; margin: 0 .4rem .4rem 0; text-decoration: none; color: inherit; }
.att-chip:hover { background: var(--bs-tertiary-bg); }

#sync-progress { position: fixed; left: calc(var(--sidebar-w) + 16px); bottom: 16px; width: min(440px, calc(100vw - var(--sidebar-w) - 32px)); z-index: 1060; }
.stat-icon { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: #fff; font-size: 1.1rem; flex-shrink: 0; }
.stat-icon.bg-warning { color: #212529; }
.acc-domains { min-width: 220px; }
.acc-domains summary { cursor: pointer; white-space: nowrap; }
.acc-domains ul { max-height: 240px; overflow-y: auto; }
.step { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-size: .8rem; font-weight: 600; color: #fff; background: linear-gradient(135deg, var(--brand), var(--brand-2)); }
.card { border-radius: .9rem; }

/* адаптив */
@media (max-width: 1199.98px) {
    .mail-layout { grid-template-columns: 260px 1fr; }
    .pane-reader { display: none; }
    .mail-layout.reading .pane-messages { display: none; }
    .mail-layout.reading .pane-reader { display: flex; }
}
@media (max-width: 767.98px) {
    :root { --sidebar-w: 64px; }
    .sidebar { padding: 1rem .5rem; }
    .sidebar span:not(.brand-mark):not(.badge) { display: none; }
    .sidebar .nav-link { justify-content: center; position: relative; }
    .sidebar .badge { position: absolute; top: 2px; right: 2px; }
    .mail-layout { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
    .mail-layout .pane { min-height: 50vh; }
    .mail-layout.has-box .pane-boxes { display: none; }
    .mail-layout:not(.has-box) .pane-messages { display: none; }
}
