:root {
  --bg: #0b0f19;
  --card: #141a28;
  --elev: #1c2433;
  --hover: #222c3e;
  --border: rgba(255, 255, 255, .08);
  --border-strong: rgba(255, 255, 255, .18);
  --text: #f3f4f6;
  --muted: #9ca3af;
  --dim: #6b7280;
  --accent: #8b7bff;
  --accent-light: #b3a8ff;
  --on-accent: #0f0b24;
  --danger: #fb7185;
  --ok: #34d399;
  --radius: 12px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--accent-light); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--elev); cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s;
}
a.btn { text-decoration: none; color: var(--text); }
.btn:hover { background: var(--hover); border-color: var(--border-strong); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn.primary:hover { background: var(--accent-light); }
.btn.danger { color: var(--danger); }
.btn.small { height: 30px; padding: 0 10px; font-size: 13px; }
.btn.icon { width: 36px; padding: 0; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--hover); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > span { color: var(--muted); font-size: 12px; }
.input, textarea.input, select.input {
  width: 100%; min-height: 40px; padding: 9px 12px; border-radius: 10px;
  background: var(--elev); border: 1px solid var(--border); outline: none;
}
.input:focus { border-color: var(--accent); }
textarea.input { resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: 12px; }
.error-text { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- логотип ---------- */
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.logo svg { width: 28px; height: 28px; }
.logo b { color: var(--accent); }

/* ---------- экран входа ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 28px; }
.auth-card h1 { font-size: 22px; margin: 18px 0 6px; }
.auth-card p { margin: 0 0 18px; color: var(--muted); }
.addr-input { display: flex; align-items: stretch; }
.addr-input .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.addr-input .suffix { display: flex; align-items: center; padding: 0 12px; background: var(--card); border: 1px solid var(--border); border-left: 0; border-radius: 0 10px 10px 0; color: var(--muted); white-space: nowrap; }

/* ---------- основной макет ---------- */
.layout { display: grid; grid-template-columns: 232px minmax(300px, 400px) 1fr; height: 100vh; height: 100dvh; }
.sidebar { background: var(--card); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 12px; gap: 12px; min-height: 0; }
.sidebar .compose-btn { width: 100%; height: 42px; }
.nav { display: flex; flex-direction: column; gap: 2px; overflow: auto; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px;
  color: var(--text); text-decoration: none;
}
.nav a:hover { background: var(--hover); }
.nav a.active { background: rgba(139, 123, 255, .16); color: var(--accent-light); }
.nav a .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.nav a.unread .count { color: var(--accent-light); font-weight: 700; }
.nav a.install-link { color: var(--accent-light); border: 1px dashed rgba(139, 123, 255, .4); margin-top: 6px; }
.nav .sep { height: 1px; background: var(--border); margin: 8px 4px; }
.sidebar .me { margin-top: auto; padding: 10px 4px 4px; border-top: 1px solid var(--border); font-size: 12px; }
.me-btn { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; text-align: left; }
.me-btn:hover { background: var(--hover); }
.avatar.lg { width: 72px; height: 72px; font-size: 30px; }
.acc-btn { border: 2px solid transparent; border-radius: 50%; padding: 0; background: none; cursor: pointer; flex: none; }
.acc-btn:hover { border-color: var(--accent); }
.acc-pop-bg { position: fixed; inset: 0; z-index: 60; }
.acc-pop { position: absolute; top: 12px; right: 12px; width: 360px; max-width: calc(100vw - 24px); max-height: calc(100vh - 24px); overflow: auto; background: var(--card); border: 1px solid var(--border-strong); border-radius: 24px; box-shadow: 0 16px 48px rgba(0, 0, 0, .55); padding: 8px; }
.acc-head { display: flex; align-items: center; justify-content: center; position: relative; padding: 8px 40px; }
.acc-head .btn { position: absolute; right: 4px; top: 4px; }
.acc-addr { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-me { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 8px 16px 18px; }
.acc-hello { font-size: 20px; font-weight: 500; text-align: center; }
.acc-list { background: var(--bg); border-radius: 16px; overflow: hidden; }
.acc-row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 16px; border: 0; border-bottom: 1px solid var(--border); background: transparent; cursor: pointer; text-align: left; color: var(--text); text-decoration: none; }
.acc-row:last-child { border-bottom: 0; }
.acc-row:hover { background: var(--hover); }
.acc-row.loading { opacity: .5; }
.acc-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-mail { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-unread { background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 12px; border-radius: 999px; padding: 1px 8px; }
.acc-plus { width: 38px; height: 38px; border-radius: 50%; border: 1px dashed var(--border-strong); display: grid; place-items: center; font-size: 20px; color: var(--accent-light); flex: none; }
.acc-foot { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; padding: 14px 8px 8px; }
.quota { height: 4px; background: var(--elev); border-radius: 4px; overflow: hidden; margin-top: 6px; }
.quota > div { height: 100%; background: var(--accent); }

.list-pane { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.list-head { padding: 12px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.list-head h2 { margin: 0; font-size: 18px; }
.bulk-bar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.list { overflow: auto; flex: 1; }
.item {
  display: grid; grid-template-columns: 22px 1fr auto; gap: 4px 8px; padding: 10px 12px;
  border-bottom: 1px solid var(--border); cursor: pointer; position: relative;
}
.item:hover { background: var(--hover); }
.item.active { background: rgba(139, 123, 255, .12); }
.item.unread::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: var(--accent); }
.item .who { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item.unread .who, .item.unread .subj { font-weight: 700; }
.item .date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.item .subj, .item .snip { grid-column: 2 / 4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .snip { color: var(--dim); font-size: 13px; }
.item input[type=checkbox] { margin: 3px 0 0; accent-color: var(--accent); }
.item .star { grid-row: 2; grid-column: 1; background: none; border: 0; padding: 0; cursor: pointer; color: var(--dim); font-size: 15px; line-height: 1; }
.item .star.on { color: #fbbf24; }
.list-empty { padding: 40px 16px; text-align: center; color: var(--muted); }
.more { padding: 12px; text-align: center; }

.reader { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow-y: auto; }
.reader-empty { margin: auto; color: var(--dim); text-align: center; padding: 16px; }
.reader-bar { display: flex; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; align-items: center; position: sticky; top: 0; z-index: 5; background: var(--bg); }
.reader-title { padding: 16px 20px 4px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.reader-title h1 { font-size: 20px; margin: 0; word-break: break-word; }
.thread { display: flex; flex-direction: column; gap: 8px; padding: 10px 16px 24px; }
.tcard { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); }
.tcard.expanded { padding: 14px 16px 6px; }
.tcard.current { border-color: rgba(139, 123, 255, .35); }
.tcard.collapsed { display: grid; grid-template-columns: 28px minmax(80px, 180px) 1fr auto; gap: 10px; align-items: center; padding: 9px 14px; cursor: pointer; }
.tcard.collapsed:hover { border-color: var(--border-strong); background: var(--hover); }
.tcard.collapsed.unread .tc-who { font-weight: 700; color: var(--text); }
.tcard.loading { opacity: .6; }
.tc-who { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tc-snip { color: var(--dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tc-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.tc-actions { display: flex; gap: 2px; }
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }
.from-line.clickable { cursor: pointer; }
.thread-more { align-self: center; background: var(--elev); border: 1px dashed var(--border-strong); color: var(--accent-light); border-radius: 999px; padding: 6px 16px; cursor: pointer; font-size: 13px; }
.thread-more:hover { background: var(--hover); }
.quote-box { margin: 6px 0; white-space: normal; }
.quote-box > summary { display: inline-block; cursor: pointer; list-style: none; padding: 2px 10px; border-radius: 8px; font-size: 12px; color: var(--muted); background: var(--elev); border: 1px solid var(--border); user-select: none; }
.quote-box > summary::-webkit-details-marker { display: none; }
.quote-box > summary:hover { border-color: var(--border-strong); color: var(--text); }
.quote-box[open] > summary { margin-bottom: 6px; }
.quote-box[open] > summary .c, .quote-box:not([open]) > summary .o { display: none; }
.quote-box > .quote { white-space: pre-wrap; }
.reader-head { padding: 16px 20px 8px; }
.reader-head h1 { font-size: 20px; margin: 0 0 12px; word-break: break-word; }
.from-line { display: flex; gap: 10px; align-items: flex-start; }
.avatar { width: 38px; height: 38px; border-radius: 50%; background: var(--elev); display: grid; place-items: center; font-weight: 700; color: var(--accent-light); flex: none; }
.addr-list { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.tc-when { white-space: nowrap; }
.notice { margin: 10px 0 0; padding: 8px 12px; background: var(--elev); border: 1px solid var(--border); border-radius: 10px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 13px; }
.body-wrap { padding: 10px 0 10px; }
.body-frame { display: block; width: 100%; height: 80px; border: 0; border-radius: 10px; background: #fff; opacity: 0; transition: opacity .12s; }
.body-frame.dark { background: transparent; }
.body-frame.ready { opacity: 1; }
.body-text { white-space: pre-wrap; word-break: break-word; font-size: 14px; line-height: 1.55; }
.body-text blockquote, .body-text .quote { color: var(--muted); border-left: 2px solid var(--border-strong); margin: 0; padding-left: 10px; }
.atts { display: flex; flex-wrap: wrap; gap: 8px; padding: 10px 0 0; }
.att { display: flex; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--card); text-decoration: none; color: var(--text); max-width: 260px; }
.att:hover { border-color: var(--border-strong); }
.att .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- окна ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--card); border: 1px solid var(--border); border-radius: 16px; width: 100%; max-width: 720px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; overflow: hidden; }
.modal-head { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); gap: 8px; }
.modal-head h3 { margin: 0; font-size: 16px; flex: 1; }
.modal-body { padding: 16px; overflow: auto; }
.modal-foot { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.compose .line { display: flex; align-items: center; gap: 8px; border-bottom: 1px solid var(--border); padding: 4px 0; }
.compose .line > label { width: 64px; color: var(--muted); font-size: 13px; flex: none; }
.compose .line .input { background: transparent; border: 0; padding: 8px 0; min-height: 36px; }
.compose textarea.input { background: transparent; border: 0; min-height: 280px; padding: 12px 0; line-height: 1.55; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; background: var(--elev); border: 1px solid var(--border); border-radius: 8px; font-size: 12px; max-width: 100%; }
.chip button { background: none; border: 0; cursor: pointer; color: var(--muted); padding: 0; }

/* ---------- страницы настроек/админки ---------- */
.page { grid-column: 2 / 4; overflow: auto; padding: 20px; }
.page h1 { font-size: 22px; margin: 0 0 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; max-width: 900px; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; }
.table-wrap { overflow-x: auto; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 6px; font-size: 11px; background: var(--elev); color: var(--muted); }
.badge.accent { background: rgba(139, 123, 255, .18); color: var(--accent-light); }
.badge.bad { background: rgba(251, 113, 133, .15); color: var(--danger); }
.copy-box { display: flex; gap: 8px; margin-top: 10px; }

#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; width: min(420px, calc(100vw - 32px)); }
.toast { background: var(--elev); border: 1px solid var(--border-strong); border-radius: 10px; padding: 10px 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .4); }
.toast.err { border-color: rgba(251, 113, 133, .5); }

.mobile-only { display: none; }

/* ---------- телефон ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .layout.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .5); }
  .list-pane, .reader, .page { grid-column: 1; grid-row: 1; height: 100dvh; }
  .layout.reading .list-pane { display: none; }
  .layout:not(.reading) .reader { display: none; }
  .mobile-only { display: inline-flex; }
  .modal-bg { padding: 0; }
  .modal { max-width: none; height: 100dvh; max-height: none; border-radius: 0; }
  .reader-title { padding: 12px 12px 2px; }
  .thread { padding: 8px 8px 20px; }
  .tcard.expanded { padding: 12px 10px 4px; }
  .tcard.collapsed { grid-template-columns: 28px 1fr auto; }
  .tcard.collapsed .tc-snip { grid-column: 2 / 4; grid-row: 2; }
  .tcard .from-line { flex-wrap: wrap; }
  .tcard .tc-when { order: 3; flex-basis: 100%; padding-left: 48px; margin-top: -4px; }
}
