:root {
  --bg: #f8fafc; --surface: #fff; --surface-2: #f1f5f9; --text: #0f172a; --muted: #64748b;
  --border: #e2e8f0; --primary: #2563eb; --primary-text: #fff; --danger: #dc2626; --ok: #16a34a;
  --bubble: #fff; --highlight: #fef3c7; --radius: 12px; --shadow: 0 1px 2px rgb(0 0 0 / .08);
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120; --surface: #111a2e; --surface-2: #1b2640; --text: #e5e9f2; --muted: #94a3b8;
    --border: #25314d; --primary: #3b82f6; --danger: #f87171; --ok: #4ade80; --bubble: #16213a;
    --highlight: #4a3b0f; --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); overscroll-behavior-y: none;
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-text-size-adjust: 100%;
}
#app { height: 100%; display: flex; flex-direction: column; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Каркас экранов */
.topbar {
  display: flex; align-items: center; gap: 8px; padding: calc(8px + var(--safe-t)) 12px 8px;
  background: var(--surface); border-bottom: 1px solid var(--border); min-height: 52px; flex: none;
}
.topbar h1 { font-size: 1.1rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scroll { flex: 1; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.page { max-width: 720px; margin: 0 auto; padding: 16px 12px calc(24px + var(--safe-b)); }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; word-break: break-all; }
.hidden { display: none !important; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card > h2 { font-size: 1rem; margin-bottom: 10px; }

/* Кнопки и поля */
.btn, .iconbtn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; text-decoration: none;
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 8px 14px; min-height: 40px;
}
.btn:hover, .iconbtn:hover { filter: brightness(.97); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn[disabled], .iconbtn[disabled] { opacity: .55; cursor: default; }
.iconbtn { padding: 0; width: 40px; background: transparent; border-color: transparent; font-size: 1.25rem; }
input[type=text], input[type=password], input[type=number], input[type=url] {
  width: 100%; padding: 9px 12px; min-height: 40px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 4px; }
.field + .field { margin-top: 12px; }
.err { color: var(--danger); font-size: .9rem; }
.badge {
  display: inline-block; min-width: 22px; padding: 1px 7px; border-radius: 999px; background: var(--primary);
  color: var(--primary-text); font-size: .78rem; text-align: center; font-weight: 600;
}
.badge.mutedb { background: var(--muted); }
.tag { font-size: .72rem; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }

/* Вход */
.login { margin: auto; width: min(380px, 100%); padding: 24px 16px; }
.login h1 { text-align: center; margin-bottom: 16px; }
.login .logo { width: 72px; height: 72px; display: block; margin: 0 auto 12px; }

/* Список каналов */
.list { list-style: none; margin: 0; padding: 0; }
.list > li > a.item, .list > li > .item {
  display: flex; gap: 12px; align-items: center; padding: 12px; color: inherit; text-decoration: none; border-bottom: 1px solid var(--border);
}
.list a.item:hover { background: var(--surface-2); }
.avatar {
  flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  font-weight: 700; background: var(--primary);
}
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .preview { color: var(--muted); font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { text-align: right; font-size: .78rem; color: var(--muted); display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.tabs { display: flex; border-top: 1px solid var(--border); background: var(--surface); padding-bottom: var(--safe-b); flex: none; }
.tabs a { flex: 1; text-align: center; padding: 10px 4px; color: var(--muted); text-decoration: none; font-size: .85rem; }
.tabs a[aria-current=page] { color: var(--primary); font-weight: 600; }

/* Лента */
.feed { max-width: 720px; margin: 0 auto; padding: 8px 10px 16px; display: flex; flex-direction: column; gap: 8px; }
.msg {
  background: var(--bubble); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px;
  content-visibility: auto; contain-intrinsic-size: auto 120px; box-shadow: var(--shadow); overflow-wrap: anywhere;
}
.msg.hl { animation: hl 2.4s ease-out; }
@keyframes hl { 0%, 60% { background: var(--highlight); } 100% { background: var(--bubble); } }
@media (prefers-reduced-motion: reduce) { .msg.hl { animation: none; background: var(--highlight); } * { scroll-behavior: auto !important; } }
.msg .mtitle { font-weight: 700; margin-bottom: 4px; }
.msg .mbody :first-child { margin-top: 0; }
.msg .mbody :last-child { margin-bottom: 0; }
.msg .mbody img, .msg .mbody video { max-width: 100%; height: auto; border-radius: 8px; display: block; }
.msg .mbody pre { background: var(--surface-2); padding: 8px; border-radius: 8px; overflow-x: auto; }
.msg .mbody code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; font-size: .9em; }
.msg .mbody pre code { padding: 0; background: none; }
.msg .mbody table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; }
.msg .mbody td, .msg .mbody th { border: 1px solid var(--border); padding: 4px 8px; }
.msg .mfoot { margin-top: 6px; font-size: .75rem; color: var(--muted); display: flex; gap: 8px; }
.mbtns { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.mbtns .brow { display: flex; gap: 6px; }
.mbtns .btn { flex: 1; min-height: 38px; padding: 6px 10px; background: var(--surface-2); }
.mbtns .btn.busy::after { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.sentinel { height: 1px; }
.loadmore { text-align: center; color: var(--muted); font-size: .85rem; padding: 6px; }
.jump {
  position: absolute; right: 12px; bottom: calc(12px + var(--safe-b)); box-shadow: 0 2px 8px rgb(0 0 0 / .25);
  background: var(--primary); color: var(--primary-text); border: 0; border-radius: 999px; padding: 10px 16px; cursor: pointer;
}
.viewwrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Диалоги и тосты */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 18px; width: min(400px, calc(100vw - 24px)); }
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { font-size: 1.05rem; margin-bottom: 10px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
#toasts { position: fixed; left: 0; right: 0; bottom: calc(16px + var(--safe-b)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; z-index: 50; padding: 0 12px; }
.toast { background: #1e293b; color: #fff; padding: 10px 16px; border-radius: 10px; max-width: 520px; box-shadow: 0 4px 16px rgb(0 0 0 / .3); }
.toast.error { background: #b91c1c; }
.banner { background: var(--highlight); padding: 10px 12px; border-radius: 10px; font-size: .9rem; }
table.users { width: 100%; border-collapse: collapse; }
table.users td { padding: 8px 4px; border-bottom: 1px solid var(--border); vertical-align: middle; }
