:root {
  --bg: #0f1319;
  --bg-soft: #161b23;
  --card: #1a2029;
  --card-2: #212936;
  --line: #2a3441;
  --text: #e6ebf2;
  --muted: #8d9bad;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, .14);
  --ok: #37c17a;
  --ok-soft: rgba(55, 193, 122, .14);
  --warn: #e0a336;
  --err: #e5645f;
  --err-soft: rgba(229, 100, 95, .14);
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 28px rgba(0, 0, 0, .28);
  --maxw: 1180px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa;
    --bg-soft: #eceff5;
    --card: #ffffff;
    --card-2: #f7f9fc;
    --line: #dfe4ec;
    --text: #161d28;
    --muted: #6b7889;
    --accent: #2f6fe4;
    --accent-soft: rgba(47, 111, 228, .1);
    --ok: #1d9c58;
    --ok-soft: rgba(29, 156, 88, .12);
    --warn: #b9791b;
    --err: #cf3b36;
    --err-soft: rgba(207, 59, 54, .12);
    --shadow: 0 6px 22px rgba(21, 32, 51, .08);
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: env(safe-area-inset-bottom);
  overflow-x: clip;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .4em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.08rem; }

code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }

/* --- Шапка --- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.topbar__inner {
  max-width: var(--maxw); margin: 0 auto; padding: 10px 14px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand__mark {
  width: 34px; height: 34px; flex: none; border-radius: 10px;
  display: grid; place-items: center; font-weight: 700; font-size: 1.05rem;
  background: linear-gradient(140deg, var(--accent), #7b5cff); color: #fff;
}
.brand__mark--big { width: 52px; height: 52px; font-size: 1.5rem; border-radius: 14px; margin: 0 auto 10px; }
.brand__text { display: flex; flex-direction: column; line-height: 1.2; }
.brand__text strong { font-size: .95rem; }
.brand__text small { color: var(--muted); font-size: .75rem; }

.nav { display: none; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.nav a {
  padding: 7px 11px; border-radius: var(--radius-sm); color: var(--muted);
  font-size: .9rem; text-decoration: none;
}
.nav a:hover { background: var(--card-2); color: var(--text); text-decoration: none; }

@media (max-width: 859px) {
  .nav--open {
    display: flex; flex-direction: column; width: 100%; order: 3;
    margin-left: 0; padding-top: 6px; border-top: 1px solid var(--line);
  }
}

.burger {
  margin-left: auto; width: 40px; height: 38px; display: grid; place-content: center; gap: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer;
}
.burger span { display: block; width: 18px; height: 2px; background: var(--text); border-radius: 2px; }

@media (min-width: 860px) {
  .burger { display: none; }
  .nav { display: flex; }
}

/* --- Страница --- */
.page { max-width: var(--maxw); margin: 0 auto; padding: 18px 14px 40px; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap; margin-bottom: 14px;
}
.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow);
  min-width: 0;
}
.card__head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 12px;
}
.card__actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px; }

.columns { display: grid; gap: 16px; }
.columns > * { min-width: 0; }
@media (min-width: 900px) { .columns { grid-template-columns: 1.15fr .85fr; } }

/* --- Кнопки --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 15px; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--card-2); color: var(--text); font-size: .9rem; font-weight: 500;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn--primary { background: var(--accent); color: #fff; }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--muted); }
.btn--ghost:hover { color: var(--text); }
.btn--ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.btn--danger { background: var(--err-soft); color: var(--err); border-color: transparent; }
.btn--sm { padding: 6px 11px; font-size: .82rem; }
.btn--tiny { padding: 4px 9px; font-size: .76rem; border-radius: 7px; }
.btn--block { width: 100%; }

/* --- Формы --- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-size: .82rem; color: var(--muted); }
.field--wide { grid-column: 1 / -1; }

input[type="text"], input[type="search"], input[type="password"], input[type="datetime-local"],
select, textarea {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--text);
  font: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; }
.textarea--code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88rem; }

.grid-form { display: grid; gap: 0 14px; }
@media (min-width: 760px) { .grid-form { grid-template-columns: 1fr 1fr; } }

.filters {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px;
}
.filters select, .filters input[type="search"] { width: auto; min-width: 150px; flex: 1 1 150px; }

.radio { display: inline-flex; align-items: center; gap: 6px; font-size: .9rem; color: var(--muted); }
.radio input { width: auto; }

/* --- Статистика --- */
.stats {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px;
}
.stat__value { font-size: 1.5rem; font-weight: 650; }
.stat__label { font-size: .78rem; color: var(--muted); }
.stat--accent .stat__value { color: var(--accent); }
.stat--ok .stat__value { color: var(--ok); }

/* --- Темы --- */
.topic { border-left: 3px solid var(--accent); padding-left: 12px; }
.topic__date { font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
.topic__text { margin: 0 0 6px; font-size: 1rem; overflow-wrap: anywhere; }
.topic__extra { margin: 0; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }

.topic-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
@media (min-width: 860px) { .topic-list { grid-template-columns: 1fr 1fr; } }
.topic-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow);
}
.topic-card__date { display: flex; gap: 8px; align-items: baseline; margin-bottom: 6px; }
.topic-card__text { margin: 0 0 8px; }
.topic-card__extra { margin: 0 0 10px; color: var(--muted); font-size: .87rem; }
.generate-status { margin-left: 8px; }

/* --- Новости --- */
.news-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; min-width: 0; }
.news-list > li { min-width: 0; }
.news-item { background: var(--card-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 13px; min-width: 0; overflow-wrap: anywhere; }
.news-item--full { display: flex; gap: 12px; align-items: flex-start; }
.news-item__img { width: 92px; height: 70px; object-fit: cover; border-radius: 8px; flex: none; }
.news-item__body { flex: 1; min-width: 0; }
.news-item__meta { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 5px; }
.news-item__title { display: block; font-weight: 550; color: var(--text); overflow-wrap: anywhere; word-break: break-word; }
.news-item__title:hover { color: var(--accent); }
.news-item__summary { margin: 6px 0 0; color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; word-break: break-word; }
.news-item__actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 9px; }
.news-item__file { display: none; }
.news-item__pick { cursor: pointer; user-select: none; }
.news-item__pick.is-busy { opacity: .6; pointer-events: none; }

.tag {
  font-size: .72rem; padding: 2px 7px; border-radius: 999px;
  background: var(--bg-soft); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.tag--ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag--error { background: var(--err-soft); color: var(--err); border-color: transparent; }
.tag--new { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tag--approved { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.tag--rejected { background: var(--err-soft); color: var(--err); border-color: transparent; }
.tag--score { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
.tag--ai { background: rgba(123, 92, 255, .16); color: #a58cff; border-color: transparent; }
@media (prefers-color-scheme: light) { .tag--ai { color: #6d4aff; } }

/* --- Счётчик символов и воронка сбора --- */
.chars { display: flex; align-items: center; gap: 10px; margin: 4px 0 10px; }
.chars__bar { flex: 1; height: 6px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; }
.chars__fill { display: block; height: 100%; width: 0; background: var(--ok); transition: width .2s ease; }
.chars__fill--warn { background: var(--warn); }
.chars__fill--over { background: var(--err); }

.funnel { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.funnel__step {
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 10px 14px; display: flex; flex-direction: column; min-width: 110px;
}
.funnel__step--ok { border-color: var(--ok); }
.funnel__value { font-size: 1.25rem; font-weight: 650; }
.funnel__label { font-size: .76rem; color: var(--muted); }
.funnel__arrow { color: var(--muted); }

.news-item__ai { margin: 5px 0 0; font-size: .82rem; color: var(--muted); font-style: italic; }

/* --- Пост под новостью --- */
.news-post {
  margin-top: 12px; padding: 12px; border-radius: var(--radius-sm);
  background: var(--bg-soft); border: 1px solid var(--line);
}
.news-post__head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.news-post .post-block { background: transparent; }

/* --- Компактный редактор поста --- */
.post-block .edit-tabs { margin-bottom: 8px; }
.post-block .textarea { font-size: .92rem; line-height: 1.5; padding: 9px 11px; }
.post-block .chars { margin: 6px 0 0; }
.post-block .card__actions { margin-top: 8px; }
.post-block .preview { padding: 11px; }

/* --- Таблица тем --- */
.topics-table-wrap {
  max-height: 460px; overflow-y: auto; border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.topics-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.topics-table thead th {
  position: sticky; top: 0; z-index: 1; background: var(--card-2);
  text-align: left; padding: 9px 12px; font-size: .76rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--line);
}
.topics-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.topics-table tr:last-child td { border-bottom: none; }
.topics-table__date { width: 190px; color: var(--muted); font-size: .84rem; }
.topics-table__row--today { background: var(--accent-soft); }
.topics-table__row--today .topics-table__date { color: var(--accent); font-weight: 600; }
.topic-link {
  background: none; border: none; padding: 0; font: inherit; color: var(--text);
  text-align: left; cursor: pointer; overflow-wrap: anywhere;
}
.topic-link:hover { color: var(--accent); }

.page-check__net {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--accent); min-width: 62px;
}

/* --- Мастер постов --- */
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input[type="text"] { flex: 1 1 320px; min-width: 0; }

.topics-grid {
  display: grid; gap: 8px; max-height: 460px; overflow-y: auto; padding-right: 4px;
  scroll-behavior: smooth;
}
@media (min-width: 860px) { .topics-grid { grid-template-columns: 1fr 1fr; } }
.topic-chip {
  text-align: left; background: var(--bg-soft); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; color: var(--text);
  display: flex; flex-direction: column; gap: 3px; font: inherit;
}
.topic-chip:hover { border-color: var(--accent); background: var(--card); }
.topic-chip__date { font-size: .75rem; color: var(--accent); }
.topic-chip__text { font-size: .9rem; overflow-wrap: anywhere; }
.topic-chip--today {
  border-color: var(--accent); background: var(--accent-soft);
  box-shadow: inset 3px 0 0 var(--accent);
}
.topic-chip--today .topic-chip__date { font-weight: 600; }

.post-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }

.edit-tabs { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.edit-tabs__btn {
  padding: 6px 13px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg-soft); color: var(--muted); font: inherit; font-size: .85rem; cursor: pointer;
}
.edit-tabs__btn:hover { color: var(--text); }
.edit-tabs__btn--active {
  background: var(--accent-soft); color: var(--accent);
  border-color: transparent; font-weight: 600;
}
.edit-tabs__btn + .muted { margin-left: 4px; }

/* Публикация свёрнута, чтобы окно поста оставалось компактным */
.publish-block { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.publish-block > summary {
  display: flex; align-items: baseline; gap: 8px; cursor: pointer;
  font-size: .92rem; font-weight: 600; list-style: none;
}
.publish-block > summary::-webkit-details-marker { display: none; }
.publish-block > summary::after { content: "▾"; color: var(--muted); font-weight: 400; }
.publish-block:not([open]) > summary::after { content: "▸"; }
.publish-block__body { margin-top: 10px; }
.editor-form { margin-top: 4px; }

/* --- Под-вкладки и отчёт прогона --- */
.subnav {
  display: flex; gap: 4px; margin-bottom: 16px;
  border-bottom: 1px solid var(--line); padding-bottom: 0;
}
.subnav__item {
  padding: 8px 14px; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  color: var(--muted); font-size: .92rem; text-decoration: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.subnav__item:hover { color: var(--text); background: var(--card-2); text-decoration: none; }
.subnav__item--active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 550; }

.run-report {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 14px; margin-bottom: 14px;
}
.run-report summary { cursor: pointer; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.run-report summary > span:first-child { font-weight: 550; }
.run-report__body { padding-top: 10px; margin-top: 8px; border-top: 1px solid var(--line); }
.run-report__body p { margin: 3px 0; }

.pager { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; margin-top: 18px; }
.pager__item {
  padding: 7px 12px; border-radius: var(--radius-sm); background: var(--card);
  border: 1px solid var(--line); color: var(--muted); font-size: .86rem;
}
.pager__item--active { background: var(--accent); color: #fff; border-color: transparent; }

/* --- Черновики --- */
.draft-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.draft-list li { display: flex; align-items: center; gap: 10px; }
.draft-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.draft-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 15px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.draft-card__title { font-weight: 550; color: var(--text); display: block; margin-bottom: 4px; }

.preview { background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; }
.preview p { margin: 0 0 .7em; }
.preview p:last-child { margin-bottom: 0; }

.publish-row { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.input--date { width: auto; min-width: 190px; }
.pages-list { display: grid; gap: 6px; max-height: 260px; overflow-y: auto; }
.page-check { display: flex; align-items: center; gap: 9px; padding: 7px 10px; background: var(--bg-soft); border-radius: var(--radius-sm); }
.page-check input { width: auto; }
.page-check__name { font-size: .9rem; }

/* --- Таблица источников --- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { color: var(--muted); font-weight: 500; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
.cell-url { max-width: 320px; }
.cell-url a { word-break: break-all; }
.cell-actions { white-space: nowrap; }
.cell-actions .btn { margin-right: 4px; }

/* --- Прочее --- */
.flash {
  background: var(--ok-soft); color: var(--ok); border: 1px solid transparent;
  padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: .9rem;
}
.flash--error { background: var(--err-soft); color: var(--err); }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.block { display: block; }
.error-text { color: var(--err); font-size: .85rem; margin: 6px 0 0; }
.ellipsis { display: block; max-width: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ellipsis-block { overflow-wrap: anywhere; }
.code-block {
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px; white-space: pre-wrap; margin: 0 0 10px;
}

.checklist { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.checklist li { display: flex; align-items: center; gap: 9px; font-size: .9rem; min-width: 0; }
.checklist li > span:not(.dot) { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
/* Длинные ссылки переносим, чтобы не распирали карточку */
.checklist li .ellipsis { white-space: normal; overflow-wrap: anywhere; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.checklist li.ok .dot { background: var(--ok); }
.checklist li.warn .dot { background: var(--warn); }

.footer {
  max-width: var(--maxw); margin: 0 auto; padding: 18px 14px 30px;
  color: var(--muted); font-size: .8rem; display: flex; gap: 8px; align-items: center;
}
.footer__dot { opacity: .5; }

/* --- Вход --- */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 26px; width: 100%; max-width: 380px; box-shadow: var(--shadow); text-align: center;
}
.login-card h1 { font-size: 1.15rem; }
.login-card input { margin: 14px 0 12px; text-align: left; }
/* Экран входа: одно поле «Пароль» + переключатель видимости */
.login-form { text-align: left; }
.login-label { display: block; margin: 16px 0 6px; font-size: .82rem; color: var(--muted); }
.login-password { position: relative; }
.login-card .login-password input { margin: 0; padding-right: 92px; }
.login-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--accent); font: inherit;
  font-size: .8rem; padding: 6px 8px; border-radius: 6px; cursor: pointer;
}
.login-toggle:hover { background: var(--accent-soft); }
.login-form .btn--block { margin-top: 14px; }
.login-hint { margin: 14px 0 0; font-size: .78rem; color: var(--muted); text-align: center; }

@media (max-width: 520px) {
  .news-item--full { flex-direction: column; }
  .news-item__img { width: 100%; height: 150px; }
  .stat__value { font-size: 1.3rem; }
}
