:root {
  --bg: #0b1220;
  --panel: #131c31;
  --panel-2: #1a2540;
  --line: #243152;
  --text: #e8edf7;
  --muted: #8ea0bf;
  --accent: #2f7bff;
  --ok: #34c98e;
  --ok-bg: rgba(52, 201, 142, .14);
  --warn: #f0a13c;
  --err: #e5605d;
  --err-bg: rgba(229, 96, 93, .12);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body.center {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

a { color: #6ab2f2; text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }

/* ===== Лэйаут с сайдбаром ===== */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px;
  flex: 0 0 250px;
  background: #0e1628;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  gap: 18px;
}
.logo { display: flex; gap: 10px; align-items: center; padding: 0 6px; }
.logo-ic {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 18px;
}
.logo b { display: block; font-size: 14px; }
.logo small, .logo span small { display: block; color: var(--muted); font-size: 11px; font-weight: 400; }
.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.side-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px;
  color: var(--muted); font-size: 14px;
}
.side-nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.side-nav a.active { background: rgba(47, 123, 255, .18); color: var(--text); }
.side-nav .badge { margin-left: auto; }
.side-user {
  display: flex; gap: 10px; align-items: center;
  border-top: 1px solid var(--line); padding-top: 14px; font-size: 13px;
}
.side-user b { display: block; }
.side-user form { margin-left: auto; }

.main { flex: 1; min-width: 0; }
.page-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 14px;
  padding: 22px 28px 0; flex-wrap: wrap;
}
.page-head h1 { margin: 0; font-size: 22px; }
.page-head p { margin: 2px 0 0; }
.page-actions { display: flex; gap: 10px; align-items: center; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 20px 28px 30px; }
.wrap.narrow { max-width: 760px; }

/* Верхняя полоса standalone-страниц (setup, login используют свой header) */
.topbar {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 22px; background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10; flex-wrap: wrap;
}
.brand { font-weight: 700; letter-spacing: .2px; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); }
.topbar nav a:hover { background: var(--panel-2); color: var(--text); text-decoration: none; }
.topbar nav a.active { background: var(--panel-2); color: var(--text); }

.badge {
  background: var(--line); border-radius: 20px;
  padding: 1px 8px; font-size: 12px; color: var(--text);
}
.badge.warn { background: var(--warn); color: #1b1206; }

/* ===== Карточки, таблицы ===== */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  margin-bottom: 18px;
}
.card h1, .card h2 { margin: 0 0 12px; font-size: 17px; }
.card h3 { margin: 16px 0 6px; font-size: 14px; }
.card h3:first-of-type { margin-top: 12px; }
.card p { margin: 6px 0; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.login { width: 340px; }
.login h1 { font-size: 20px; }
.login button { width: 100%; margin-top: 12px; }
.section-title { font-size: 17px; margin: 22px 0 12px; }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; color: var(--muted); font-weight: 500; font-size: 12px;
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tr:hover td { background: rgba(47, 123, 255, .05); }
.cell-main { display: flex; gap: 10px; align-items: center; min-width: 180px; }
.cell-main b { display: block; }
.cell-sub { color: var(--muted); font-size: 12px; }
.tbl .actions { white-space: nowrap; text-align: right; }
.tbl .actions form { display: inline; }
.btn.sm, button.sm { padding: 5px 10px; font-size: 13px; }

/* ===== Формы, кнопки ===== */
label { display: block; color: var(--muted); font-size: 13px; }
label input, label select, label textarea {
  display: block; width: 100%; margin-top: 5px;
  padding: 9px 11px; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px; font: inherit;
}
label textarea { resize: vertical; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; margin: 0; }

input, select, textarea {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 11px; font: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(47, 123, 255, .35); border-color: var(--accent); }

button, .btn {
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 9px 14px; font: inherit; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
}
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--err); border-color: rgba(229, 96, 93, .4); }
button.big, .btn.big { padding: 12px 20px; font-weight: 600; }
button.linklike { background: none; border: none; color: var(--muted); padding: 0; text-decoration: underline; }

.inline-form { display: flex; gap: 10px; align-items: flex-end; }
.inline-form input { flex: 1; }
.wrap-form { flex-wrap: wrap; }
.wrap-form input, .wrap-form select { flex: 1 1 180px; }

.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.grid-form .wide, .sep.wide { grid-column: 1 / -1; }
@media (max-width: 760px) { .grid-form { grid-template-columns: 1fr; } }
.sep { border-top: 1px dashed var(--line); padding-top: 12px; color: var(--muted); font-size: 13px; }

.row { display: flex; gap: 10px; align-items: center; margin: 14px 0; flex-wrap: wrap; }
.row form { display: inline; }

.filters-bar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.filters-bar label { min-width: 140px; }
.filters-bar .grow { flex: 1 1 200px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }

.meta { display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 13px; margin-top: 8px; }

/* ===== Теги, бейджи ===== */
.tag {
  display: inline-block; padding: 2px 10px; border-radius: 20px;
  background: var(--line); font-size: 12px; color: var(--text); white-space: nowrap;
}
.tag.telegram { background: #2b5278; }
.tag.rss { background: #b06a1f; }
.tag.web { background: #2f6b4f; }
.tag-telegram_web { background: #2b5278; }
.tag.ok, .tag.on { background: var(--ok-bg); color: var(--ok); }
.tag.off { background: var(--line); color: var(--muted); }
.tag.pub { background: rgba(47, 123, 255, .16); color: #6ab2f2; }
.tag.priv { background: rgba(240, 161, 60, .14); color: var(--warn); }

.flash { padding: 11px 14px; border-radius: 10px; margin-bottom: 14px; }
.flash.ok { background: rgba(52, 201, 142, .12); border: 1px solid rgba(52, 201, 142, .4); }
.flash.err { background: var(--err-bg); border: 1px solid rgba(229, 96, 93, .4); }
.flash.small { font-size: 13px; }
.err-text { color: var(--err); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ===== Статистика ===== */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 860px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; }
.stat-card .lbl { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.stat-card .num { font-size: 26px; font-weight: 700; }
.stat-card .num.warn { color: var(--warn); }
.stat-card .delta { font-size: 12px; color: var(--ok); }

.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 18px; }
@media (max-width: 960px) { .cols { grid-template-columns: 1fr; } }

.chart { width: 100%; height: auto; display: block; }
.ch-grid { stroke: var(--line); stroke-width: 1; }
.ch-lbl { fill: var(--muted); font-size: 11px; }
.ch-area { fill: rgba(47, 123, 255, .18); }
.ch-line-f { fill: none; stroke: var(--accent); stroke-width: 2; }
.ch-line-p { fill: none; stroke: var(--ok); stroke-width: 2; }
.chart-legend { display: flex; gap: 16px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.chart-legend i { display: inline-block; width: 18px; height: 3px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }

.donut-wrap { display: flex; gap: 18px; align-items: center; flex-wrap: wrap; }
.donut { width: 170px; height: 170px; }
.donut-num { fill: var(--text); font-size: 24px; font-weight: 700; }
.donut-lbl { fill: var(--muted); font-size: 10px; }
.donut-legend { display: flex; flex-direction: column; gap: 8px; font-size: 13px; flex: 1; }
.donut-row { display: flex; gap: 8px; align-items: center; }
.donut-row .dot { width: 10px; height: 10px; border-radius: 3px; }
.donut-row b { margin-left: auto; }

/* Совместимость со старыми шаблонами */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
@media (max-width: 700px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 16px; text-align: center;
}
.stat .num { font-size: 28px; font-weight: 700; }
.stat .num.warn { color: var(--warn); }
.stat .lbl { color: var(--muted); font-size: 13px; }

/* ===== Шаги мастера, подсказки ===== */
.steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 16px; }
@media (max-width: 860px) { .steps { grid-template-columns: repeat(2, 1fr); } }
.step {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; font-size: 13px;
}
.step.done { border-color: var(--ok); }
.step-num {
  flex: 0 0 22px; height: 22px; border-radius: 50%;
  background: var(--line); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.step.done .step-num { background: var(--ok); color: #06210f; }

.wizard { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 16px; }
@media (max-width: 860px) { .wizard { grid-template-columns: repeat(2, 1fr); } }
.wstep {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px; font-size: 13px; color: var(--text);
}
.wstep:hover { text-decoration: none; border-color: var(--accent); }
.wstep.done { border-color: var(--ok); }
.wstep.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.wstep-num {
  flex: 0 0 22px; height: 22px; border-radius: 50%;
  background: var(--line); color: var(--muted);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
}
.wstep.done .wstep-num { background: var(--ok); color: #06210f; }
.wstep.current .wstep-num { background: var(--accent); color: #fff; }
.wizard.mini { grid-template-columns: repeat(2, 1fr); max-width: 420px; }

.hint-list { margin: 8px 0 12px 18px; padding: 0; color: var(--text); font-size: 14px; }
.hint-list li { margin-bottom: 6px; }
.hint-list code { background: var(--panel-2); padding: 1px 6px; border-radius: 6px; }

/* ===== Плитки выбора ===== */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin: 14px 0; }
.tile {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 8px;
  background: var(--panel-2); border: 2px solid var(--line);
  border-radius: 16px; padding: 14px 10px; cursor: pointer; text-align: center;
}
.tile:hover { border-color: var(--accent); }
.tile input[type="checkbox"] { position: absolute; opacity: 0; pointer-events: none; }
.tile-check {
  position: absolute; top: 8px; right: 8px;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--line); color: transparent;
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.tile:has(input:checked) { border-color: var(--ok); }
.tile:has(input:checked) .tile-check { background: var(--ok); color: #06210f; }
.tile-avatar {
  width: 72px; height: 72px; border-radius: 50%; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px; font-weight: 700; color: #fff; flex: 0 0 72px;
}
.tile-avatar.sm { width: 32px; height: 32px; font-size: 14px; flex-basis: 32px; }
.tile-avatar img { width: 100%; height: 100%; object-fit: cover; }
.tile-name { font-weight: 600; overflow-wrap: anywhere; }

/* ===== Превью поста «как в Telegram» ===== */
.tg-post { background: #182533; border-radius: 12px; padding: 12px 12px 8px; max-width: 520px; }
.tg-head { display: flex; gap: 10px; align-items: center; margin-bottom: 8px; }
.tg-avatar {
  flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%;
  background: #4c8dff; color: #fff; font-weight: 700; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.tg-channel { color: #6ab2f2; font-weight: 700; }
.tg-sub { color: var(--muted); font-size: 12px; }
.tg-photo { width: 100%; border-radius: 8px; display: block; margin: 4px 0 8px; }
.tg-text { color: #fff; white-space: pre-wrap; overflow-wrap: anywhere; }
.tg-text a { color: #6ab2f2; }
.tg-text blockquote { border-left: 2px solid #6ab2f2; margin: 6px 0; padding-left: 8px; color: #d7e3f0; }
.tg-text pre, .tg-text code { background: rgba(0, 0, 0, .35); border-radius: 6px; padding: 1px 5px; }
.tg-text pre { padding: 8px; overflow-x: auto; }
.tg-foot { margin-top: 8px; font-size: 13px; }
.tg-link { border-left: 2px solid #6ab2f2; padding-left: 8px; margin: 8px 0 4px; }
.tg-link-site { color: #6ab2f2; font-size: 13px; }
.tg-link-title { color: #fff; font-weight: 700; }
.tg-link-desc {
  color: var(--muted); font-size: 13px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

/* ===== Прочее ===== */
.list { list-style: none; padding: 0; margin: 0 0 10px; }
.list li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: none; }

.preview { white-space: pre-wrap; color: var(--text); }
.raw { background: var(--panel-2); padding: 12px; border-radius: 10px; overflow-x: auto; white-space: pre-wrap; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.status-line { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.card[id] { scroll-margin-top: 12px; }
.tabs a { padding: 8px 14px; border-radius: 9px; background: var(--panel); border: 1px solid var(--line); color: var(--muted); }
.tabs a.active { color: var(--text); border-color: var(--accent); }

.pagination { display: flex; gap: 6px; align-items: center; margin-top: 14px; flex-wrap: wrap; }
.pagination a, .pagination span.cur {
  padding: 6px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font-size: 13px;
}
.pagination span.cur { background: var(--accent); border-color: var(--accent); color: #fff; }
.pagination a:hover { border-color: var(--accent); text-decoration: none; }

details { margin-top: 10px; }
summary { cursor: pointer; color: var(--muted); }
details[open] summary { margin-bottom: 10px; }

.avatar {
  width: 48px; height: 48px; border-radius: 50%; overflow: hidden; flex: 0 0 48px;
  display: inline-flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 18px; background: #3a7bd5;
}
.avatar.lg { width: 64px; height: 64px; flex-basis: 64px; font-size: 24px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.who { display: inline-flex; align-items: center; gap: 10px; min-width: 0; color: var(--text); text-decoration: none; }
.who-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.who-text b { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.who-text small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 240px; }
.picked-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
a.tile { color: inherit; text-decoration: none; }
a.tile.on { border-color: var(--accent); }
.tile-avatar.word { font-size: 16px; letter-spacing: .02em; }

.feed { display: flex; flex-direction: column; gap: 10px; }
.feed-card {
  display: block; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px 16px; color: inherit; text-decoration: none;
}
.feed-card:hover { border-color: var(--accent); text-decoration: none; }
.feed-top { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.feed-arrow { color: var(--muted); }
.feed-time { margin-left: auto; color: var(--muted); font-size: 12px; }
.feed-text { margin: 10px 0 8px; white-space: pre-wrap; }
.feed-foot { display: flex; gap: 8px; align-items: center; }
.feed-open { margin-left: auto; color: #6ab2f2; font-size: 13px; }

.editor-layout { display: grid; grid-template-columns: minmax(0, 520px) minmax(240px, 1fr); gap: 16px; align-items: start; }
.composer { max-width: none; }
.composer .tile-avatar { width: 42px; height: 42px; flex-basis: 42px; font-size: 18px; }
.tg-editor { min-height: 120px; outline: none; }
.tg-editor:empty:before { content: attr(data-placeholder); color: #7d8da3; }
.tg-editor tg-spoiler, .tg-text tg-spoiler { background: #6d7a8a; color: transparent; border-radius: 4px; }
.tg-editor tg-spoiler:hover, .tg-text tg-spoiler:hover { color: #fff; }
.tg-sign { margin-top: 8px; color: #9eb0c6; font-size: 14px; white-space: pre-wrap; }
.tg-album { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 8px; }
.tg-album.single { grid-template-columns: 1fr; }
.tg-album[hidden] { display: none; }
.tg-thumb { position: relative; background: #0e1621; border-radius: 8px; overflow: hidden; min-height: 72px; }
.tg-thumb img, .tg-thumb video { width: 100%; height: 180px; object-fit: cover; display: block; }
.tg-album.single .tg-thumb img, .tg-album.single .tg-thumb video { height: auto; max-height: 360px; object-fit: contain; background: #0e1621; }
.tg-file { padding: 16px 12px; color: #d5e2f2; font-size: 13px; word-break: break-all; }
.tg-remove {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .55); color: #fff; cursor: pointer; font-size: 16px;
}
.tg-toolbar { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 10px; padding-top: 8px; border-top: 1px solid rgba(255,255,255,.08); }
.tg-toolbar button {
  background: transparent; color: #d5e2f2; border: 0; border-radius: 8px;
  padding: 6px 8px; cursor: pointer; font: inherit;
}
.tg-toolbar button:hover { background: rgba(255,255,255,.08); }
.composer-meta { display: flex; justify-content: space-between; gap: 8px; margin-top: 6px; color: #8ea0bf; font-size: 12px; }
.composer-meta .over { color: var(--err); }
.media-add { display: flex; gap: 8px; margin: 10px 0; }
.media-add input { flex: 1; }
.composer-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.side-who { margin: 8px 0; }
.period-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pill {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--panel); color: var(--muted); text-decoration: none; font-size: 13px;
}
.pill.active, .pill:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }
.pick-row { margin-bottom: 16px; }
.emotion-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 14px; }
.bar { display: inline-block; width: 72px; height: 6px; border-radius: 99px; background: var(--line); vertical-align: middle; margin-right: 6px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--ok); }
.donut-row { text-decoration: none; color: inherit; }
.donut-row:hover { text-decoration: none; }

.hover-tip {
  position: fixed;
  z-index: 80;
  max-width: 260px;
  padding: 6px 9px;
  background: #172033;
  color: #e7eef8;
  border: 1px solid #3c5270;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.35;
  pointer-events: none;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .35);
}
.hover-tip[hidden] { display: none; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; padding: 12px; }
  .side-nav { flex-direction: row; overflow-x: auto; }
  .side-nav a { white-space: nowrap; }
  .side-user { border: none; padding: 0; }
  .page-head, .wrap { padding-left: 16px; padding-right: 16px; }
  .editor-layout { grid-template-columns: 1fr; }
}
