:root {
  --bg: #edf0f4;
  --surface: #ffffff;
  --sunken: #f5f7fa;
  --ink: #18202e;
  --muted: #657085;
  --line: #d3d9e2;
  --accent: #3b3fd8;
  --accent-ink: #ffffff;
  --accent-soft: #e6e7fb;
  --ok: #1c7c53;
  --ok-soft: #e1f2ea;
  --danger: #b33a3a;
  --danger-soft: #f8e4e4;
  --warn: #9a5a12;
  --warn-soft: #f8ecdc;
  --ui: 'Onest', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --quote: 'Literata', Georgia, 'Times New Roman', serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161f;
    --surface: #1a1f2b;
    --sunken: #151a24;
    --ink: #e7ebf2;
    --muted: #93a0b5;
    --line: #2c3444;
    --accent: #7d81ff;
    --accent-ink: #0f1230;
    --accent-soft: #262a52;
    --ok: #5cc195;
    --ok-soft: #173327;
    --danger: #ef7d7d;
    --danger-soft: #3a1d20;
    --warn: #e0a55a;
    --warn-soft: #36291a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--ui);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-underline-offset: 2px; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ── Кнопки ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface);
  padding: 7px 14px; border-radius: 8px; cursor: pointer;
  font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn.quiet:hover { color: var(--ink); background: var(--sunken); }
.btn.danger-text { color: var(--danger); }

/* ── Вход ───────────────────────────────────────────────── */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login form {
  width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px;
}
.login h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
.login p { margin: 0 0 20px; color: var(--muted); }
.login input { width: 100%; margin-bottom: 12px; }
.login .error { color: var(--danger); margin: -4px 0 12px; font-size: 14px; }
.login .btn { width: 100%; justify-content: center; padding: 10px; }

input[type=text], input[type=password], input[type=url], input[type=number], textarea {
  border: 1px solid var(--line); background: var(--sunken); border-radius: 8px; padding: 9px 11px;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); }

/* ── Каркас ─────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.side {
  border-right: 1px solid var(--line); padding: 22px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 22px;
}
.brand { padding: 0 10px; }
.brand strong { display: block; font-size: 17px; letter-spacing: -.01em; }
.brand span { color: var(--muted); font-size: 13px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface); }
.nav a[aria-current=page] { background: var(--surface); box-shadow: inset 3px 0 0 var(--accent); }
.nav .count {
  min-width: 22px; padding: 0 7px; border-radius: 11px; text-align: center;
  background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 600; line-height: 22px;
}
.nav .count:empty { display: none; }
.side .bottom { margin-top: auto; padding: 0 10px; font-size: 13px; color: var(--muted); }

.main { min-width: 0; }
.status {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px 24px;
  padding: 14px 32px; border-bottom: 1px solid var(--line); background: var(--surface);
  position: sticky; top: 0; z-index: 5;
}
.state { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.state .account { font-weight: 400; color: var(--muted); }
.state .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); }
.state.paused .dot { background: var(--warn); }
.state.busy .dot { background: var(--accent); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.meter { display: grid; gap: 4px; min-width: 150px; font-size: 13px; color: var(--muted); }
.meter b { color: var(--ink); font-weight: 600; }
.meter .bar { height: 4px; border-radius: 2px; background: var(--sunken); overflow: hidden; }
.meter .bar i { display: block; height: 100%; background: var(--accent); }
.meter.full .bar i { background: var(--danger); }
.status .next { font-size: 13px; color: var(--muted); }
.status .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.page { padding: 28px 32px 80px; max-width: 980px; }
.page-head { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 26px; letter-spacing: -.02em; margin: 0; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.empty {
  border: 1px dashed var(--line); border-radius: 14px; padding: 36px 28px; color: var(--muted); max-width: 640px;
}
.empty strong { display: block; color: var(--ink); font-size: 17px; margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }

/* ── Очередь: пост и ответ как ветка Threads ───────────── */
.queue { display: grid; gap: 18px; max-width: 760px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
.card.leaving { opacity: .4; transition: opacity .2s; }
.thread { padding: 20px 22px 6px; }
.turn { display: grid; grid-template-columns: 38px 1fr; gap: 0 14px; }
.turn .rail { display: flex; flex-direction: column; align-items: center; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: var(--sunken); border: 1px solid var(--line); font-weight: 600; color: var(--muted); text-transform: uppercase;
}
.avatar.ours { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-size: 13px; }
.turn .rail .line { width: 2px; flex: 1; background: var(--line); margin: 6px 0; min-height: 18px; }
.turn .body { padding-bottom: 18px; min-width: 0; }
.who { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; margin-bottom: 4px; }
.who .name { font-weight: 600; color: var(--ink); text-decoration: none; }
.who a.name:hover { text-decoration: underline; }
.who .src, .who .time { color: var(--muted); font-size: 13px; }
.score {
  font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 10px;
  background: var(--accent-soft); color: var(--accent);
}
.post-text {
  font-family: var(--quote); font-size: 16px; line-height: 1.6; margin: 0;
  white-space: pre-wrap; overflow-wrap: anywhere; max-width: 64ch;
}
.reply textarea {
  width: 100%; min-height: 92px; resize: vertical; line-height: 1.5; background: var(--surface);
  border-color: transparent; padding: 6px 8px; margin-left: -8px;
}
.reply textarea:hover { border-color: var(--line); }
.reply textarea:focus { border-color: var(--accent); }
.link-line { font-size: 14px; color: var(--accent); overflow-wrap: anywhere; margin: 2px 0 6px; }
.reply-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; font-size: 13px; color: var(--muted); }
.reply-tools .over { color: var(--danger); font-weight: 600; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; }
.switch input { appearance: none; width: 30px; height: 18px; border-radius: 9px; background: var(--line); position: relative; cursor: pointer; margin: 0; transition: background .15s; }
.switch input::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(12px); }
.card-foot {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 22px;
  background: var(--sunken); border-top: 1px solid var(--line);
}
.card-foot .why { flex: 1 1 260px; font-size: 13px; color: var(--muted); }
.card-foot .btns { display: flex; gap: 8px; flex-wrap: wrap; }
.tag { font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 10px; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.muted { background: var(--sunken); color: var(--muted); border: 1px solid var(--line); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }

/* ── Лента ──────────────────────────────────────────────── */
.feed { list-style: none; margin: 0; padding: 0; max-width: 820px; }
.feed li {
  display: grid; grid-template-columns: 64px 108px 1fr; gap: 12px; align-items: baseline;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.feed li.fresh { animation: fresh 2s ease-out; }
@keyframes fresh { from { background: var(--accent-soft); } to { background: transparent; } }
.feed time { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.feed .kind { font-size: 13px; font-weight: 600; display: flex; align-items: center; gap: 7px; }
.feed .kind::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.feed .k-sent::before { background: var(--ok); }
.feed .k-draft::before, .feed .k-filter::before, .feed .k-search::before { background: var(--accent); }
.feed .k-error::before { background: var(--danger); }
.feed .k-error { color: var(--danger); }
.feed .k-warn::before, .feed .k-skip::before { background: var(--warn); }
.feed .text { overflow-wrap: anywhere; }
.feed .text a { margin-left: 8px; font-size: 13px; }
.day { padding: 22px 0 6px; font-weight: 600; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); }

/* ── Оценки ─────────────────────────────────────────────── */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 16px; padding: 4px 12px; cursor: pointer; font-size: 14px; }
.chip[aria-pressed=true] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.scored { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; max-width: 900px; }
.scored .row { display: grid; grid-template-columns: 54px 1fr; gap: 16px; padding: 14px 18px; background: var(--surface); }
.scored .num { font-size: 26px; font-weight: 700; letter-spacing: -.03em; color: var(--muted); font-variant-numeric: tabular-nums; line-height: 1.1; }
.scored .num.hi { color: var(--accent); }
.scored .meta { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.scored .meta .name { color: var(--ink); font-weight: 600; text-decoration: none; }
.scored .excerpt { font-family: var(--quote); margin: 0 0 4px; overflow-wrap: anywhere; }
.scored .reason { font-size: 13px; color: var(--muted); margin: 0; }

/* ── Отправленные ───────────────────────────────────────── */
.sent { display: grid; gap: 14px; max-width: 760px; }
.sent .card .thread { padding-bottom: 0; }
.sent .reply-text { white-space: pre-wrap; overflow-wrap: anywhere; margin: 0; }

/* ── Настройки ──────────────────────────────────────────── */
.settings { display: grid; gap: 28px; max-width: 720px; }
.settings fieldset { border: 0; padding: 0; margin: 0; display: grid; gap: 14px; }
.settings legend { font-size: 18px; font-weight: 600; margin-bottom: 4px; padding: 0; }
.field { display: grid; gap: 6px; }
.field label { font-weight: 500; }
.field small { color: var(--muted); }
.field textarea { min-height: 160px; resize: vertical; }
.field textarea.tall { min-height: 280px; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; }
.grid2 input { width: 100%; }
.settings.forget { margin-top: 40px; padding-top: 24px; border-top: 1px solid var(--line); }
.save-bar { display: flex; gap: 12px; align-items: center; position: sticky; bottom: 0; padding: 14px 0; background: var(--bg); border-top: 1px solid var(--line); }

/* ── Уведомления ────────────────────────────────────────── */
#toasts { position: fixed; right: 20px; bottom: 20px; display: grid; gap: 8px; z-index: 50; max-width: min(420px, calc(100vw - 40px)); }
.toast { background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 10px; font-size: 14px; }
.toast.error { background: var(--danger); color: #fff; }

/* ── Мобильная версия ───────────────────────────────────── */
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 14px 12px; gap: 10px; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; }
  .nav a { flex: none; gap: 8px; }
  .nav a[aria-current=page] { box-shadow: inset 0 -2px 0 var(--accent); }
  .side .bottom { display: none; }
  .status { position: static; padding: 12px 16px; }
  .status .actions { margin-left: 0; width: 100%; }
  .status .actions .btn { flex: 1 1 auto; justify-content: center; }
  .meter { min-width: 0; flex: 1 1 140px; }
  .card-foot .btns { width: 100%; }
  .card-foot .btns .btn { flex: 1 1 auto; justify-content: center; }
  .page { padding: 20px 16px 60px; }
  .thread { padding: 16px 14px 4px; }
  .card-foot { padding: 12px 14px; }
  .feed li { grid-template-columns: 52px 1fr; }
  .feed li .text { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
