:root {
  --paper: #f7f8fb;
  --card: #ffffff;
  --ink: #23262d;
  --ink-2: #565c68;
  --ink-3: #868c98;
  --line: #e2e5ec;
  --line-2: #cfd4de;
  --accent: #2b59c3;
  --accent-2: #234aa6;
  --accent-soft: #e7edfb;
  --ok: #1f8a5b;
  --ok-soft: #e2f4ea;
  --warn: #a8690f;
  --warn-soft: #fcf1de;
  --bad: #c0392b;
  --bad-soft: #fbe8e6;
  --busy: #6f47c2;
  --busy-soft: #efe9fa;
  --tg: #e7f0fa;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 60, 0.05), 0 2px 8px rgba(20, 30, 60, 0.04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--paper); font-size: 15px; line-height: 1.5; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 23px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
[hidden] { display: none !important; }
code { font-family: ui-monospace, Consolas, monospace; font-size: 0.92em; background: #f1f3f7; padding: 0 4px; border-radius: 4px; }

/* Шапка */
.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 18px; padding: 10px 24px; background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; font-size: 18px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.brand span { font-weight: 400; color: var(--ink-3); }
.top nav { display: flex; gap: 2px; flex: 1; flex-wrap: wrap; }
.top nav a { padding: 6px 11px; border-radius: 8px; color: var(--ink-2); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.top nav a.active, .top nav a:hover { background: #eef1f6; color: var(--ink); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 99px; font-size: 12px; font-weight: 700; line-height: 18px; text-align: center; background: var(--accent); color: #fff; }
.badge.muted { background: #e3e7ef; color: var(--ink-2); }
main { max-width: 1240px; margin: 0 auto; padding: 22px 24px 60px; }

/* Кнопки и поля */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 13px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font: inherit; font-weight: 500; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--line-2); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.small { padding: 3px 9px; font-size: 13px; }
label { display: block; font-weight: 600; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
input[type=text], input[type=search], input[type=password], input[type=url], input[type=number], input[type=datetime-local], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; font: inherit; color: var(--ink);
}
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field { margin-bottom: 14px; }
.hint { font-size: 13px; color: var(--ink-3); margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; color: var(--ink); font-size: 14px; cursor: pointer; margin: 0; }
.check input { width: 16px; height: 16px; margin: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.sp { flex: 1; }

/* Заголовок страницы, вкладки, фильтры */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar h1 { margin-right: auto; }
.toolbar input[type=search] { max-width: 240px; }
.toolbar select { width: auto; max-width: 220px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 12px; color: var(--ink-2); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; display: inline-flex; gap: 6px; align-items: center; }
.tabs a.on { color: var(--ink); border-bottom-color: var(--accent); font-weight: 600; }
.tabs a .badge { background: #e3e7ef; color: var(--ink-2); }
.tabs a.on .badge { background: var(--accent); color: #fff; }
.meta { font-size: 13px; color: var(--ink-3); }
.empty { text-align: center; padding: 50px 20px; color: var(--ink-2); background: var(--card); border: 1px dashed var(--line-2); border-radius: var(--radius); }
.empty h2 { margin-bottom: 6px; }

/* Карточки постов */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; text-decoration: none; color: inherit; display: flex; flex-direction: column; transition: transform 0.1s, box-shadow 0.1s; }
.card:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(20, 30, 60, 0.09); }
.thumb { aspect-ratio: 16 / 9; background: linear-gradient(135deg, #eef1f7, #e3e8f2) center / cover no-repeat; display: flex; align-items: center; justify-content: center; color: var(--ink-3); font-size: 13px; position: relative; }
.thumb .score { position: absolute; left: 8px; top: 8px; }
.card .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card .title { font-weight: 650; line-height: 1.35; }
.card .ex { font-size: 14px; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card .foot { margin-top: auto; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

/* Статусы и метки */
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 99px; background: #eef1f6; color: var(--ink-2); width: fit-content; white-space: nowrap; }
.chip.incoming, .chip.skipped { background: #eef1f6; color: var(--ink-2); }
.chip.processing, .chip.sending { background: var(--busy-soft); color: var(--busy); }
.chip.review { background: var(--warn-soft); color: var(--warn); }
.chip.approved { background: var(--accent-soft); color: var(--accent); }
.chip.published { background: var(--ok-soft); color: var(--ok); }
.chip.error, .chip.rejected { background: var(--bad-soft); color: var(--bad); }
.chip.processing::before, .chip.sending::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.2s infinite; }
.chip.topic { background: #f1f3f8; color: var(--ink-2); font-weight: 500; }
@keyframes pulse { 50% { opacity: 0.3; } }
.score { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 22px; padding: 0 6px; border-radius: 6px; font-size: 12px; font-weight: 700; background: #e9ecf2; color: var(--ink-2); }
.score.hi { background: #d8f0e2; color: #17704a; }
.score.mid { background: #fbefd5; color: #8a5a0b; }
.score.lo { background: #eceef3; color: #8b909b; }

/* Входящие */
.inbox { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.irow { display: grid; grid-template-columns: 28px 36px minmax(0, 1fr) auto; gap: 10px; align-items: start; padding: 11px 14px; border-top: 1px solid var(--line); }
.irow:first-child { border-top: 0; }
.irow:hover { background: #fafbfd; }
.irow .t { font-weight: 600; line-height: 1.35; }
.irow .t a { color: var(--ink); text-decoration: none; }
.irow .t a:hover { color: var(--accent); text-decoration: underline; }
.irow .why { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.irow .acts { display: flex; gap: 6px; }
.irow input[type=checkbox] { width: 16px; height: 16px; margin-top: 3px; }
.bulkbar { position: sticky; bottom: 12px; margin-top: 12px; background: var(--ink); color: #fff; border-radius: var(--radius); padding: 10px 14px; display: flex; gap: 10px; align-items: center; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18); }
.bulkbar .btn { border-color: transparent; }
.lastrun { font-size: 13px; color: var(--ink-2); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 14px; display: flex; gap: 14px; flex-wrap: wrap; }

/* Страница поста */
.back { display: inline-block; margin-bottom: 10px; color: var(--ink-2); text-decoration: none; font-size: 14px; }
.head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 16px; }
.head .titles { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.panel > h2 { margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.panel > h2 .sp { flex: 1; }
.notice { border-radius: var(--radius); padding: 11px 15px; margin-bottom: 16px; border: 1px solid; }
.notice.busy { background: var(--busy-soft); border-color: #dccdf3; }
.notice.bad { background: var(--bad-soft); border-color: #f2c9c3; }
.notice.warn { background: var(--warn-soft); border-color: #f0dcb4; }
.notice.ok { background: var(--ok-soft); border-color: #bfe5cf; }
.notice.info { background: var(--accent-soft); border-color: #cbd8f5; }
.notice b { display: block; margin-bottom: 2px; }
.cols { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.tgwrap { background: #d6e4f0 url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='4' cy='4' r='1.2' fill='%23b9cde0'/%3E%3C/svg%3E"); border-radius: var(--radius); padding: 18px; }
.tg { max-width: 460px; margin: 0 auto; background: #fff; border-radius: 12px 12px 12px 4px; overflow: hidden; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.tg img { width: 100%; display: block; aspect-ratio: 16 / 9; object-fit: cover; background: #e9eef4; }
.tg .noimg { aspect-ratio: 16 / 9; display: flex; align-items: center; justify-content: center; background: #eef2f7; color: var(--ink-3); font-size: 13px; }
.tg .cap { padding: 9px 12px 8px; white-space: pre-wrap; word-wrap: break-word; font-size: 15px; line-height: 1.42; }
.tg .cap a { color: #2a7cc7; text-decoration: none; }
.tg .cap code { background: #f0f3f6; }
.tg .time { text-align: right; font-size: 12px; color: #9aa4ae; padding: 0 10px 6px; }
.counter { font-size: 13px; color: var(--ink-3); margin-top: 8px; text-align: center; }
.counter.over { color: var(--bad); font-weight: 600; }
.mk { font-size: 12px; color: var(--ink-3); margin-top: 4px; }
.stickybar { position: sticky; bottom: 0; background: rgba(247, 248, 251, 0.96); border-top: 1px solid var(--line); padding: 10px 0; margin-top: 4px; display: flex; gap: 8px; align-items: center; z-index: 5; }
.stickybar .sp { font-size: 13px; color: var(--ink-3); }
.chatlist { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.chatlist .check { padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; }
.chatlist .check small { color: var(--ink-3); font-weight: 400; margin-left: auto; }
.when { display: flex; gap: 14px; margin-bottom: 10px; }
.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 12px; font-size: 14px; margin: 0; }
.facts dt { color: var(--ink-3); }
.facts dd { margin: 0; word-break: break-word; }
.article { white-space: pre-wrap; font-size: 14px; color: var(--ink-2); max-height: 420px; overflow: auto; background: #fafbfd; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-top: 8px; }
details > summary { cursor: pointer; color: var(--accent); font-size: 14px; margin-top: 8px; }
.history { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.history li { padding: 7px 0; border-top: 1px solid var(--line); }
.history li:first-child { border-top: 0; }
.history time { display: block; font-size: 12px; color: var(--ink-3); }
.links { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }

/* Таблицы */
.tablewrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; font-size: 12px; color: var(--ink-3); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t td.act { text-align: right; white-space: nowrap; }
table.t tr.off td { color: var(--ink-3); }
table.t tr.editing td { background: #f8f9fc; }
table.t td.c, table.t th.c { text-align: center; }
table.t input[type=checkbox] { width: 16px; height: 16px; }
.err { color: var(--bad); font-size: 13px; }
.okc { color: var(--ok); font-size: 13px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 13px; word-break: break-all; }
.toggle { position: relative; display: inline-block; width: 36px; height: 20px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle span { position: absolute; inset: 0; background: #cfd4de; border-radius: 99px; transition: 0.15s; cursor: pointer; }
.toggle span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: 0.15s; }
.toggle input:checked + span { background: var(--ok); }
.toggle input:checked + span::before { transform: translateX(16px); }
.toggle input:disabled + span { cursor: default; opacity: 0.6; }
.pick { display: flex; gap: 6px; flex-wrap: wrap; }
.pick label { display: inline-flex; align-items: center; gap: 5px; margin: 0; padding: 3px 10px; border: 1px solid var(--line); border-radius: 99px; font-weight: 500; font-size: 13px; color: var(--ink-2); cursor: pointer; background: #fff; }
.pick label:has(input:checked) { background: var(--accent-soft); border-color: #b9c9f0; color: var(--accent-2); }
.pick input { width: 14px; height: 14px; margin: 0; }
.matrix th.p { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; height: 130px; vertical-align: bottom; text-align: left; font-weight: 500; color: var(--ink-2); }
.help { font-size: 14px; color: var(--ink-2); }
.help ol { margin: 6px 0 0; padding-left: 20px; }

/* Вход и меню пользователя */
body.anon .authed { display: none !important; }
.usermenu { position: relative; }
.usermenu .drop { position: absolute; right: 0; top: calc(100% + 6px); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.1); min-width: 220px; padding: 6px; display: flex; flex-direction: column; z-index: 20; }
.usermenu .drop a, .usermenu .drop button { text-align: left; padding: 8px 10px; border-radius: 6px; color: var(--ink); text-decoration: none; background: none; border: 0; font: inherit; cursor: pointer; }
.usermenu .drop a:hover, .usermenu .drop button:hover { background: #f2f4f8; }
.usermenu .who { padding: 6px 10px 8px; font-size: 13px; color: var(--ink-3); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.login { max-width: 380px; margin: 9vh auto 0; }
.login h1 { margin-bottom: 4px; }
.login .meta { margin-bottom: 18px; }
.login .btn { width: 100%; padding: 10px; }
.form-error { color: var(--bad); font-size: 14px; margin: -4px 0 12px; min-height: 20px; }
.narrow { max-width: 620px; }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: 0.2s; max-width: min(90vw, 600px); z-index: 50; }
#toast.on { opacity: 1; transform: translateX(-50%); }
#toast.bad { background: var(--bad); }

@media (max-width: 980px) {
  .cols { grid-template-columns: 1fr; }
  .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 700px) {
  .top { padding: 8px 16px 0; gap: 8px; flex-wrap: wrap; }
  .brand { flex: 1; }
  .top nav { order: 3; flex: 0 0 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 4px 12px 8px; }
  .top nav::-webkit-scrollbar { display: none; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs a { white-space: nowrap; }
  .toolbar select { max-width: none; flex: 1; }
  .cols > div, .panel { min-width: 0; }
  .tgwrap { padding: 10px; }
  main { padding: 16px 16px 60px; }
  .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  .irow { grid-template-columns: 24px minmax(0, 1fr); }
  .irow .score { display: none; }
  .irow .acts { grid-column: 2; }
  .hide-m { display: none; }
  .toolbar input[type=search] { max-width: none; }
}
