/* Веб-почта idb.lv. Светлая и тёмная тема — по настройке системы. */
:root {
    --bg: #f3f4f6;
    --surface: #ffffff;
    --surface-2: #f1f2f5;
    --hover: #eef0f3;
    --text: #1d2025;
    --muted: #6a717d;
    --border: #e1e4e9;
    --accent: #e0661f;
    --accent-hover: #c95814;
    --accent-ink: #ffffff;
    --accent-soft: rgba(224, 102, 31, .12);
    --select: rgba(224, 102, 31, .09);
    --danger: #cf3030;
    --danger-soft: rgba(207, 48, 48, .1);
    --ok: #1f8a4c;
    --star: #f2a900;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16);
    --radius: 10px;
    --top: 60px;
    --side: 264px;
    color-scheme: light;
}
/* Тёмная тема: по системе (если не выбрана светлая) или выбранная явно — data-theme на <html> */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #16181b;
        --surface: #1e2125;
        --surface-2: #25292e;
        --hover: #2a2e34;
        --text: #e6e8eb;
        --muted: #99a0aa;
        --border: #30353b;
        --accent: #f07a33;
        --accent-hover: #ff8c47;
        --accent-ink: #1a1a1a;
        --accent-soft: rgba(240, 122, 51, .16);
        --select: rgba(240, 122, 51, .12);
        --danger: #f26b6b;
        --danger-soft: rgba(242, 107, 107, .14);
        --shadow: 0 1px 2px rgba(0, 0, 0, .4);
        --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
        color-scheme: dark;
    }
}
:root[data-theme="dark"] {
    --bg: #16181b;
    --surface: #1e2125;
    --surface-2: #25292e;
    --hover: #2a2e34;
    --text: #e6e8eb;
    --muted: #99a0aa;
    --border: #30353b;
    --accent: #f07a33;
    --accent-hover: #ff8c47;
    --accent-ink: #1a1a1a;
    --accent-soft: rgba(240, 122, 51, .16);
    --select: rgba(240, 122, 51, .12);
    --danger: #f26b6b;
    --danger-soft: rgba(242, 107, 107, .14);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
}
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2 { margin: 0; font-weight: 600; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }

.ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.ic-xs { width: 15px; height: 15px; }
.ic-xl { width: 48px; height: 48px; stroke-width: 1.4; opacity: .5; }

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid transparent;
    background: var(--surface-2); cursor: pointer; font-weight: 500; white-space: nowrap;
    transition: background .15s, box-shadow .15s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--hover); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 14px; }
.btn-block { width: 100%; }
.btn[disabled], .btn.busy { opacity: .6; pointer-events: none; }
.icon-btn {
    display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
    border: 0; background: transparent; cursor: pointer; color: var(--text); flex: none;
    transition: background .15s;
}
.icon-btn:hover { background: var(--hover); }
.icon-btn.disabled { opacity: .35; pointer-events: none; }
.icon-btn.danger:hover { color: var(--danger); background: var(--danger-soft); }
.link-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 14px; }
.link-btn:hover { color: var(--text); background: var(--hover); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Каркас ---------- */
.app {
    display: grid;
    grid-template-columns: var(--side) minmax(0, 1fr);
    grid-template-rows: var(--top) minmax(0, 1fr);
    height: 100vh; height: 100dvh;
}
.topbar {
    grid-column: 1 / -1; display: flex; align-items: center; gap: 12px;
    padding: 0 16px 0 12px; background: var(--bg);
}
.brand { display: flex; align-items: center; gap: 10px; width: calc(var(--side) - 24px); font-weight: 650; font-size: 17px; letter-spacing: -.01em; }
.brand-mark { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(135deg, #f08a3c, #d4541a); color: #fff; }
.brand-mark .ic { stroke-width: 2.1; }
.brand-mark.big { width: 56px; height: 56px; border-radius: 16px; }
.brand-mark.big .ic { width: 30px; height: 30px; }
.topbar-spacer { flex: 1; }

.search {
    flex: 1; max-width: 720px; display: flex; align-items: center; gap: 4px;
    background: var(--surface-2); border-radius: 999px; padding: 0 6px 0 14px; height: 44px;
    border: 1px solid transparent; transition: background .15s, border-color .15s, box-shadow .15s;
}
.search:focus-within { background: var(--surface); border-color: var(--border); box-shadow: var(--shadow); }
.search .search-ic { color: var(--muted); }
.search input { flex: 1; min-width: 0; border: 0; background: none; outline: none; height: 100%; padding: 0 6px; }
.search select { border: 0; background: transparent; color: var(--muted); max-width: 140px; cursor: pointer; padding: 6px; border-radius: 999px; }
.search select:hover { background: var(--hover); }

.avatar {
    --h: 210;
    display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; flex: none;
    background: hsl(var(--h) 55% 88%); color: hsl(var(--h) 45% 28%);
    font-size: 14px; font-weight: 600; letter-spacing: .02em; user-select: none;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .avatar { background: hsl(var(--h) 30% 30%); color: hsl(var(--h) 60% 88%); }
}
:root[data-theme="dark"] .avatar { background: hsl(var(--h) 30% 30%); color: hsl(var(--h) 60% 88%); }
.avatar.sm { width: 32px; height: 32px; font-size: 12px; }

.usermenu { position: relative; margin-left: auto; }
.usermenu > summary { list-style: none; cursor: pointer; }
.usermenu > summary::-webkit-details-marker, .dropdown > summary::-webkit-details-marker { display: none; }

.dropdown { position: relative; }
.dropdown > summary { list-style: none; }
.menu {
    position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; min-width: 220px; max-height: min(70vh, 480px); overflow: auto;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px;
}
.menu-right { left: auto; right: 0; }
.menu a, .menu button {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 9px 12px; padding-left: calc(12px + var(--depth, 0) * 14px);
    border: 0; background: none; border-radius: 8px; cursor: pointer; text-align: left; white-space: nowrap;
}
.menu a:hover, .menu button:hover { background: var(--hover); }
.menu form { margin: 0; }
.menu-head { padding: 8px 12px 10px; display: grid; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.menu-head span { color: var(--muted); font-size: 13px; }
.menu-form { padding: 12px; min-width: 280px; }

/* ---------- Боковая панель ---------- */
.sidebar { display: flex; flex-direction: column; gap: 4px; padding: 4px 12px 12px; overflow: auto; background: var(--bg); }
.btn-compose { height: 52px; border-radius: 16px; justify-content: flex-start; padding: 0 22px; margin: 4px 0 12px; box-shadow: var(--shadow); font-size: 15px; width: fit-content; min-width: 150px; }
.folders { display: grid; gap: 1px; }
.folder {
    display: flex; align-items: center; gap: 14px; height: 38px; padding: 0 14px; padding-left: calc(14px + var(--depth, 0) * 16px);
    border-radius: 999px; color: var(--text); transition: background .12s;
}
.folder:hover { background: var(--hover); }
.folder.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.folder.active .badge { background: var(--accent); color: var(--accent-ink); }
.folder.disabled { color: var(--muted); }
.folder-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { min-width: 22px; height: 20px; padding: 0 7px; border-radius: 999px; background: var(--surface-2); font-size: 12px; font-weight: 600; display: grid; place-items: center; }
.sidebar-foot { margin-top: auto; padding-top: 16px; display: grid; gap: 2px; font-size: 14px; color: var(--muted); }
.sidebar-foot a { display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-radius: 999px; }
.sidebar-foot a:hover { background: var(--hover); color: var(--text); }
.sidebar-foot .ic { width: 18px; height: 18px; }

/* ---------- Основная область ---------- */
.main {
    position: relative; overflow: auto; background: var(--surface);
    border-radius: 16px 0 0 0; box-shadow: var(--shadow);
}
.toolbar {
    position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 6px;
    min-height: 56px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.toolbar-title { display: flex; align-items: baseline; gap: 10px; min-width: 0; flex: 1; }
.toolbar-title h1, h1.toolbar-title { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar-title .muted { font-size: 13px; white-space: nowrap; }
.toolbar-actions { display: flex; align-items: center; gap: 2px; margin-left: auto; }
.sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }
.sel-count { font-weight: 600; margin-right: 8px; color: var(--accent); }
.list-page [data-when-selected] { display: none; }
.list-page.has-selection [data-when-selected] { display: flex; }
.list-page.has-selection [data-when-none] { display: none; }
.list-page.has-selection .toolbar-title { display: none; }

.chk { display: inline-grid; place-items: center; width: 36px; height: 36px; flex: none; cursor: pointer; border-radius: 50%; }
.chk:hover { background: var(--hover); }
.chk input { width: 17px; height: 17px; margin: 0; accent-color: var(--accent); cursor: pointer; }

.filters { display: flex; gap: 8px; align-items: center; padding: 10px 16px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--border); }
.filters::-webkit-scrollbar { display: none; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border); font-size: 14px; white-space: nowrap; }
.chip:hover { background: var(--hover); }
.chip.active { background: var(--accent-soft); border-color: transparent; color: var(--accent); font-weight: 600; }
.chip-clear .ic { width: 14px; height: 14px; }
.filter-search { margin-left: auto; height: 34px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); padding: 0 14px; min-width: 180px; }

/* ---------- Список писем ---------- */
.msg-list { display: block; }
.msg-row {
    display: grid; grid-template-columns: 44px 32px minmax(0, 1fr); align-items: center;
    padding: 0 8px 0 4px; border-bottom: 1px solid var(--border); min-height: 52px; position: relative;
    transition: background .1s;
}
.msg-row:hover { background: var(--hover); box-shadow: inset 3px 0 0 var(--border); }
.msg-row.selected { background: var(--select); }
.msg-row .chk { justify-self: center; }
.msg-link { display: grid; grid-template-columns: 32px minmax(120px, 220px) minmax(0, 1fr) auto; align-items: center; gap: 14px; padding: 10px 8px 10px 4px; min-width: 0; }
.msg-from, .msg-subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-subject { color: var(--muted); }
.msg-meta { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.msg-row.unread { background: color-mix(in srgb, var(--accent) 3%, var(--surface)); }
.msg-row.unread .msg-from, .msg-row.unread .msg-subject, .msg-row.unread time { font-weight: 650; color: var(--text); }
.msg-row.unread::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.star { display: inline-grid; place-items: center; width: 32px; height: 32px; border: 0; background: none; border-radius: 50%; cursor: pointer; color: var(--muted); padding: 0; }
.star:hover { background: var(--hover); }
.star .ic { width: 18px; height: 18px; }
.flagged .star .ic, .star.on .ic, .star[data-star="1"] .ic { fill: var(--star); stroke: var(--star); }

.empty { display: grid; place-items: center; gap: 8px; text-align: center; padding: 72px 24px; color: var(--muted); }
.empty p { margin: 0; }

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; font-size: 14px; flex-wrap: wrap; }
.pager-links { display: flex; align-items: center; gap: 2px; }
.pg { display: inline-grid; place-items: center; min-width: 34px; height: 34px; padding: 0 6px; border-radius: 999px; }
a.pg:hover { background: var(--hover); }
.pg.current { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.page-dots { padding: 0 4px; color: var(--muted); }

/* ---------- Чтение ---------- */
.reader { max-width: 1100px; }
.reader-toolbar .toolbar-actions { margin-left: 0; }
.reader-nav { margin-left: auto; display: flex; gap: 2px; }
.reader-head { padding: 20px 24px 8px; }
.reader-subject { font-size: 22px; line-height: 1.3; font-weight: 500; display: flex; align-items: flex-start; gap: 8px; overflow-wrap: anywhere; }
.reader-subject .star { margin-top: -2px; }
.sender { display: flex; align-items: flex-start; gap: 12px; margin-top: 18px; }
.sender-info { flex: 1; min-width: 0; }
.sender-line { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.sender-line .muted { font-size: 13px; }
.sender-date { font-size: 13px; white-space: nowrap; }
.recipients { font-size: 13px; color: var(--muted); }
.recipients summary { cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: fit-content; max-width: 100%; }
.recipients summary:hover { color: var(--text); }
.recipients dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 8px 0 0; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); width: fit-content; max-width: 100%; }
.recipients dt { text-align: right; }
.recipients dd { margin: 0; color: var(--text); overflow-wrap: anywhere; }
.notice { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin: 8px 24px 0; padding: 10px 14px; background: var(--surface-2); border-radius: var(--radius); font-size: 14px; }
.mail-body { display: block; width: 100%; height: 300px; border: 0; margin-top: 8px; background: #fff; color-scheme: light; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .mail-body { border-radius: 10px; margin: 8px 16px 0; width: calc(100% - 32px); }
}
:root[data-theme="dark"] .mail-body { border-radius: 10px; margin: 8px 16px 0; width: calc(100% - 32px); }
.attachments { padding: 16px 24px 4px; border-top: 1px solid var(--border); margin-top: 12px; }
.attachments h2 { font-size: 14px; color: var(--muted); font-weight: 500; margin-bottom: 10px; }
.attachments ul, .att-list { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.att { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius); min-width: 0; background: var(--surface); }
.att-thumb { width: 48px; height: 48px; border-radius: 8px; overflow: hidden; flex: none; display: grid; place-items: center; background: var(--surface-2); }
.att-thumb img { width: 100%; height: 100%; object-fit: cover; }
.att-type { font-size: 11px; font-weight: 700; color: var(--accent); letter-spacing: .03em; }
.att-info { display: grid; min-width: 0; flex: 1; font-size: 14px; }
.att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-info .muted { font-size: 12px; }
.att-actions { display: flex; }
.att.uploading { opacity: .7; }
.att progress { width: 100%; height: 4px; accent-color: var(--accent); }
.reply-bar { display: flex; gap: 10px; flex-wrap: wrap; padding: 20px 24px 40px; }

/* ---------- Написание ---------- */
.composing .main { display: flex; flex-direction: column; }
.compose { display: flex; flex-direction: column; min-height: 100%; }
.compose .toolbar-title { font-size: 18px; }
.save-state { font-size: 13px; margin-right: 8px; }
.compose-fields { padding: 0 16px; }
.cfield { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); min-height: 48px; position: relative; }
.cfield label { width: 72px; flex: none; color: var(--muted); font-size: 14px; }
.cfield input { flex: 1; min-width: 0; border: 0; background: none; outline: none; height: 46px; }
.cfield-toggles { display: flex; gap: 2px; }
.suggest {
    position: absolute; z-index: 40; top: 100%; left: 72px; right: 0; max-width: 520px; margin: 0; padding: 6px; list-style: none;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.suggest li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.suggest li.active, .suggest li:hover { background: var(--hover); }
.suggest .muted { font-size: 13px; }
.editor { flex: 1; display: flex; flex-direction: column; padding: 8px 16px; min-height: 320px; }
.editor-bar { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; padding: 4px; border-radius: 10px; background: var(--surface-2); position: sticky; top: 56px; z-index: 5; }
.editor-bar button { display: inline-grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 8px; background: none; cursor: pointer; }
.editor-bar button:hover { background: var(--hover); }
.editor-bar .ic { width: 18px; height: 18px; }
.editor-html-tools { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.editor-spacer { flex: 1; }
.editor-bar .editor-mode { width: auto; padding: 0 10px; gap: 6px; display: inline-flex; font-size: 13px; color: var(--muted); }
.editor-area, .editor-text {
    flex: 1; min-height: 280px; padding: 14px 4px; outline: none; overflow-wrap: anywhere; border: 0; background: none; resize: vertical;
}
.editor-text { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; width: 100%; }
.editor-area blockquote { margin: 0 0 0 .8ex; border-left: 2px solid var(--border); padding-left: 1ex; color: var(--muted); }
.editor-area img { max-width: 100%; height: auto; }
.editor-area .signature { color: var(--muted); }
.compose-attachments { padding: 8px 16px 24px; display: grid; gap: 10px; }
.drop-zone { width: fit-content; cursor: pointer; }
.drop-zone .muted { font-weight: 400; font-size: 13px; }
.compose.dragover .editor { outline: 2px dashed var(--accent); outline-offset: -4px; border-radius: 12px; }

/* ---------- Страницы: папки, контакты, настройки ---------- */
.page { max-width: 900px; padding: 20px 24px 48px; display: grid; gap: 16px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.page-head h1 { font-size: 22px; font-weight: 600; flex: 1; }
.page-head-actions { display: flex; gap: 8px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }
.card h2 { font-size: 16px; margin-bottom: 12px; }
.card-summary { cursor: pointer; display: flex; align-items: center; gap: 8px; font-weight: 600; list-style: none; }
details[open] > .card-summary { margin-bottom: 12px; }
.list-card { padding: 0; overflow: hidden; }
.form { display: grid; gap: 14px; }
.form-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); align-items: end; margin-top: 10px; }
.form-inline { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.form-actions { display: flex; gap: 10px; }
.sticky-actions { position: sticky; bottom: 0; padding: 12px 0; background: linear-gradient(transparent, var(--surface) 40%); }
.field { display: grid; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend { font-size: 13px; color: var(--muted); font-weight: 500; padding: 0; }
.field small { font-size: 12px; }
input[type=text], input[type=email], input[type=password], input[type=search], select, textarea {
    height: 42px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); outline: none; width: 100%;
    transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cfield input:focus, .search input:focus, .search select:focus { box-shadow: none; }
.cfield input, .search input, .search select { height: auto; border: 0; width: auto; background: transparent; border-radius: 0; }
.search input { padding: 0 6px; height: 100%; }
.search input::-webkit-search-decoration { -webkit-appearance: none; }
.radio { display: flex; align-items: center; gap: 10px; padding: 4px 0; cursor: pointer; }
.radio input { accent-color: var(--accent); width: 17px; height: 17px; margin: 0; }
.settings .card { display: grid; gap: 14px; }
.settings .card h2 { margin: 0; }
.alert { padding: 10px 14px; border-radius: 10px; font-size: 14px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.compose > .alert { margin: 12px 16px 0; }
.tag { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-left: 6px; }

.folder-row, .contact-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; padding-left: calc(14px + var(--depth, 0) * 22px); border-bottom: 1px solid var(--border); }
.folder-row:last-child, .contact-row:last-child { border-bottom: 0; }
.folder-row-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.folder-row-main .muted { font-size: 13px; }
.folder-row-actions { display: flex; gap: 6px; align-items: center; }
.folder-row-actions form, .contact-row form { margin: 0; }
.inline-edit > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.inline-edit > summary::-webkit-details-marker { display: none; }
.inline-edit[open] > summary { margin-bottom: 8px; }
.inline-edit .form-inline input { max-width: 280px; height: 36px; }

/* ---------- Сообщения ---------- */
.toast-host { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; }
.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 100;
    background: #23262b; color: #fff; padding: 12px 20px; border-radius: 12px; box-shadow: var(--shadow-lg); font-size: 14px;
    animation: toast-in .2s ease-out; max-width: calc(100vw - 32px);
}
.toast-host .toast { position: static; transform: none; }
.toast-error { background: var(--danger); }
.toast.hide { opacity: 0; transition: opacity .4s; }
@keyframes toast-in { from { opacity: 0; translate: 0 8px; } to { opacity: 1; translate: 0 0; } }

.fab { display: none; }
.scrim { display: none; }
.only-mobile { display: none; }

/* ---------- Вход ---------- */
.guest { min-height: 100vh; min-height: 100dvh; display: grid; }
.login { display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1200px 600px at 20% -10%, var(--accent-soft), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 32px 28px 20px; box-shadow: var(--shadow-lg); display: grid; gap: 24px; }
.login-brand { display: grid; justify-items: center; gap: 8px; text-align: center; }
.login-brand h1 { font-size: 22px; }
.login-brand p { margin: 0; color: var(--muted); font-size: 14px; }
.btn-block { height: 46px; }
.langs { display: flex; justify-content: center; gap: 4px; font-size: 13px; }
.langs a { padding: 6px 10px; border-radius: 999px; color: var(--muted); }
.langs a:hover { background: var(--hover); color: var(--text); }
.langs a[aria-current] { color: var(--accent); font-weight: 600; }
.guest .page { margin: auto; }

/* ---------- Планшет ---------- */
@media (max-width: 1100px) {
    .msg-link { grid-template-columns: 32px minmax(110px, 170px) minmax(0, 1fr) auto; gap: 10px; }
    .search select { display: none; }
}

/* ---------- Телефон и узкий планшет ---------- */
@media (max-width: 900px) {
    :root { --top: 56px; }
    .app { grid-template-columns: minmax(0, 1fr); }
    .only-mobile { display: inline-grid; }
    .hide-mobile { display: none !important; }
    .topbar { padding: 0 8px; gap: 6px; }
    .brand { width: auto; }
    .brand-name { display: none; }
    .search { height: 42px; }
    .sidebar {
        position: fixed; z-index: 50; top: 0; bottom: 0; left: 0; width: min(300px, 86vw);
        padding-top: 16px; background: var(--surface); box-shadow: var(--shadow-lg);
        transform: translateX(-102%); transition: transform .22s ease;
    }
    .drawer-open .sidebar { transform: none; }
    .drawer-open .scrim { display: block; position: fixed; inset: 0; z-index: 45; background: rgba(0, 0, 0, .35); }
    .main { border-radius: 0; box-shadow: none; grid-column: 1; }
    .btn-compose { display: none; }
    .fab {
        display: inline-grid; place-items: center; position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 40;
        width: 56px; height: 56px; border-radius: 18px; background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-lg);
    }
    .fab .ic { width: 24px; height: 24px; }

    .msg-row { grid-template-columns: 40px minmax(0, 1fr); padding: 0 4px 0 0; }
    .msg-row .star { display: none; }
    .msg-link { grid-template-columns: 40px minmax(0, 1fr) auto; grid-template-areas: "av from meta" "av subj subj"; gap: 2px 10px; padding: 10px 8px 10px 0; }
    .msg-link .avatar { grid-area: av; width: 40px; height: 40px; font-size: 14px; }
    .msg-from { grid-area: from; }
    .msg-subject { grid-area: subj; }
    .msg-meta { grid-area: meta; }
    .flagged .msg-meta::before { content: "★"; color: var(--star); }

    .toolbar { padding: 6px 8px; min-height: 52px; }
    .toolbar-title h1 { font-size: 17px; }
    .filters { padding: 8px 12px; }
    .filter-search { min-width: 140px; }
    .reader-head { padding: 16px 16px 4px; }
    .reader-subject { font-size: 19px; }
    .notice { margin: 8px 16px 0; }
    .attachments { padding: 14px 16px 4px; }
    .attachments ul, .att-list { grid-template-columns: minmax(0, 1fr); }
    .reply-bar { padding: 16px 16px 96px; }
    .reply-bar .btn { flex: 1 1 140px; padding: 0 10px; }
    .compose-fields { padding: 0 12px; }
    .cfield label { width: 58px; }
    .suggest { left: 0; }
    .editor { padding: 8px 12px; }
    .editor-bar { top: 52px; }
    .page { padding: 16px 12px 96px; }
    .menu { position: fixed; z-index: 60; left: 8px !important; right: 8px !important; top: auto; bottom: 8px; min-width: 0; max-height: 70vh; }
    .usermenu .menu { top: 60px; bottom: auto; }
}

@media (max-width: 420px) {
    .search { padding-left: 10px; }
    .toolbar-title .muted { display: none; }
    .reader-toolbar .icon-btn { width: 36px; height: 36px; }
}

@media print {
    .topbar, .sidebar, .toolbar, .reply-bar, .fab, .notice, .att-actions { display: none !important; }
    .app { display: block; height: auto; }
    .main { box-shadow: none; overflow: visible; }
    .mail-body { margin: 0; width: 100%; }
}

/* Во время написания письма кнопка «Написать» не нужна */
.composing .fab { display: none !important; }

/* Токены MCP */
.token-box { display: grid; gap: 8px; padding: 14px; border-radius: 12px; background: var(--accent-soft); }
.token { font: 14px ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; padding: 8px 10px; border-radius: 8px; background: var(--surface); overflow-wrap: anywhere; user-select: all; }
.token-config { margin: 0; padding: 10px; border-radius: 8px; background: var(--surface); font-size: 12px; overflow-x: auto; }
.small { font-size: 12px; }
small.alert-error { background: none; padding: 0; }

/* ---------- Панель управления почтой /admin ---------- */
.page-wide { max-width: 1100px; }
input[type=number] {
    height: 42px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); outline: none; width: 100%;
}
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table code { font-size: 12px; }
.nowrap { white-space: nowrap; }
.strong-link { font-weight: 600; }
.strong-link:hover { color: var(--accent); }
.tag-ok { background: rgba(31, 138, 76, .12); color: var(--ok); }
.tag-off { background: var(--danger-soft); color: var(--danger); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.card > h2 .muted { font-weight: 400; font-size: 14px; }
.subcard { border: 1px dashed var(--border); border-radius: 12px; padding: 10px 14px; margin-bottom: 8px; }
.subcard[open] { border-style: solid; }
.rows { margin: 0 -16px; }
.rows > .muted { padding: 0 16px; }
.row-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.row-actions form { margin: 0; }
.addr-input { display: flex; align-items: center; gap: 6px; }
.addr-input input { flex: 1; min-width: 0; }
.check-list { display: flex; flex-wrap: wrap; gap: 0 18px; }
.radio input[type=checkbox] { accent-color: var(--accent); width: 17px; height: 17px; margin: 0; }
.admin .card .form-grid { margin-top: 4px; }
@media (max-width: 760px) {
    .table th:nth-child(2), .table td:nth-child(2) { display: none; }
}
.admin .list-card { overflow-x: auto; }

/* Переключатель темы */
.theme-switch { display: inline-flex; gap: 2px; padding: 3px; border-radius: 999px; background: var(--surface-2); }
.theme-switch button { display: inline-grid; place-items: center; width: 32px; height: 28px; border: 0; border-radius: 999px; background: none; color: var(--muted); cursor: pointer; }
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-pressed="true"] { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.theme-switch .ic { width: 16px; height: 16px; }
.menu-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 6px 6px 12px; }
.menu-row > span { color: var(--muted); font-size: 14px; }
.login-theme { display: flex; justify-content: center; margin-bottom: -12px; }
/* Кнопка темы у профиля: прижимает себя и профиль к правому краю */
.theme-btn { margin-left: auto; color: var(--muted); }
.theme-btn:hover { color: var(--text); }
.theme-btn + .usermenu { margin-left: 4px; }
/* Кнопка звука стоит перед кнопкой темы — к правому краю прижимает она */
.sound-btn + .theme-btn { margin-left: 0; }
.sound-btn[aria-pressed="false"] { opacity: .6; }
/* Письмо, только что появившееся в списке без перезагрузки */
.msg-row.fresh { animation: fresh-row 2.5s ease-out; }
@keyframes fresh-row { from { background: var(--accent-soft); } to { background: transparent; } }

/* ---------- /admin: проверка DNS домена ---------- */
.dns-summary { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-radius: 12px; font-weight: 600; }
.dns-summary.is-ok { background: rgba(31, 138, 76, .12); color: var(--ok); }
.dns-summary.is-bad { background: var(--danger-soft); color: var(--danger); }
.dns-list { display: grid; gap: 10px; }
.dns-check { display: grid; gap: 8px; border-left: 4px solid var(--border); }
.dns-check.dns-ok { border-left-color: var(--ok); }
.dns-check.dns-warning { border-left-color: var(--star); }
.dns-check.dns-error { border-left-color: var(--danger); }
.dns-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.dns-head h2 { margin: 0; font-size: 15px; }
.dns-head code { font-size: 12px; overflow-wrap: anywhere; }
.dns-badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.dns-ok .dns-badge { background: rgba(31, 138, 76, .12); color: var(--ok); }
.dns-warning .dns-badge { background: rgba(242, 169, 0, .16); color: var(--text); }
.dns-error .dns-badge { background: var(--danger-soft); color: var(--danger); }
.dns-msg { margin: 0; font-size: 14px; }
.dns-values { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 4px 12px; margin: 0; font-size: 13px; }
.dns-values dt { color: var(--muted); }
.dns-values dd { margin: 0; display: grid; gap: 4px; }
.dns-values code { font-size: 12px; overflow-wrap: anywhere; word-break: break-all; }
