:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --sidebar: #f3f2ee;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-wash: rgba(42, 120, 214, 0.10);

  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  --good: #0ca30c;
  --good-ink: #006300;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-wash: rgba(208, 59, 59, 0.08);

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222220;
    --sidebar: #141413;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --accent: #3987e5;
    --accent-wash: rgba(57, 135, 229, 0.16);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;
    --good-ink: #0ca30c;
    --critical-wash: rgba(208, 59, 59, 0.16);
    --shadow: none;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --sidebar: #141413;
  --text: #ffffff;
  --text-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --accent: #3987e5;
  --accent-wash: rgba(57, 135, 229, 0.16);
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;
  --good-ink: #0ca30c;
  --critical-wash: rgba(208, 59, 59, 0.16);
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--page);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0; }
code { font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.secondary { color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.small { font-size: 12px; }

/* ---------- Кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn-danger { color: var(--critical); }
.btn-danger:hover { background: var(--critical-wash); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-icon { width: 32px; padding: 0; }
.btn-block { width: 100%; }

input[type=text], input[type=password], input[type=number], input[type=search], input[type=tel], select, textarea {
  width: 100%; height: 34px; padding: 0 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit;
}
textarea { height: auto; padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.form-error { color: var(--critical); font-size: 13px; }

/* ---------- Экран входа ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card {
  width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 28px; box-shadow: var(--shadow);
}

/* ---------- Каркас ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 20px;
  padding: 18px 12px; background: var(--sidebar); border-right: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; padding: 0 8px; }
a.brand { color: var(--text); }
a.brand:hover { text-decoration: none; opacity: .85; }
.brand-lg { font-size: 18px; padding: 0; }
.brand-mark {
  width: 24px; height: 24px; border-radius: 7px; background: var(--accent); flex: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M7 22l6-7 4 4 8-10' stroke='white' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-size: cover;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: var(--radius-sm); color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-wash); color: var(--text); }
.nav-badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px;
  background: var(--critical); color: #fff; font-size: 11px; font-weight: 600;
  display: inline-grid; place-items: center;
}
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.sidebar-actions { display: flex; justify-content: space-between; }
.status-line { font-size: 12px; color: var(--muted); padding: 0 8px; line-height: 1.5; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 16px 28px; border-bottom: 1px solid var(--border); background: var(--page);
  position: sticky; top: 0; z-index: 5;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.content { padding: 24px 28px 48px; display: flex; flex-direction: column; gap: 20px; max-width: 1400px; width: 100%; }

.pill {
  display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 14px; font-size: 13px; color: var(--text-2);
  background: var(--surface);
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; background: var(--muted); }
.dot-good { background: var(--good); }
.dot-warning { background: var(--warning); }
.dot-critical { background: var(--critical); }

/* ---------- Карточки ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); min-width: 0;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.card-head .sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.card-body { padding: 16px 18px; }
.card-body.flush { padding: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-head .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.section-head select { width: auto; min-width: 160px; max-width: 280px; height: 28px; font-size: 13px; }
.act-total { font-size: 15px; font-weight: 600; white-space: nowrap; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row-end { justify-content: flex-end; }
.spacer { flex: 1; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; box-shadow: var(--shadow);
}
.tile-label { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 7px; }
.tile-value { font-size: 26px; font-weight: 600; line-height: 1.2; }
.tile-sub { font-size: 12px; color: var(--muted); }
/* Плитка-кнопка: фильтр ленты событий по типу */
.tile-btn { font: inherit; text-align: left; cursor: pointer; color: inherit; }
.tile-btn:hover { background: var(--surface-2); }
.tile-btn.on { border-color: var(--accent); background: var(--accent-wash); }
.tile-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface);
}
.banner-warn { border-color: color-mix(in srgb, var(--warning) 60%, transparent); }
.banner-error { border-color: color-mix(in srgb, var(--critical) 50%, transparent); background: var(--critical-wash); }
.banner .spacer { flex: 1; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 14px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
th { font-size: 12px; font-weight: 500; color: var(--muted); white-space: nowrap; background: var(--surface); position: sticky; top: 0; }
tbody tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
tr.is-deleted td { background: var(--critical-wash); }
td.right, th.right { text-align: right; }
.cell-text { color: var(--text-2); overflow-wrap: break-word; }
/* Колонка текста забирает свободное место и не сжимается: в узком окне таблица прокручивается */
td.col-text, th.col-text { width: 100%; min-width: 260px; }
td.col-text .tags { margin-top: 6px; }
td.col-channel { min-width: 130px; }
#posts-table th, #posts-table td { padding-left: 10px; padding-right: 10px; }
#posts-table th:first-child, #posts-table td:first-child { padding-left: 18px; }
.cell-title { font-weight: 500; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.empty { padding: 32px 18px; text-align: center; color: var(--muted); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters select, .filters input:not([type=checkbox]) { width: auto; min-width: 150px; }
.filters input[type=search] { min-width: 220px; flex: 1; max-width: 360px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 18px; border-top: 1px solid var(--border); }

/* ---------- Метки ---------- */
.tag {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border-radius: 11px; font-size: 12px; font-weight: 500; white-space: nowrap;
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.tag .dot { width: 7px; height: 7px; }
.tag-critical { color: var(--critical); background: var(--critical-wash); border-color: transparent; }
.tag-pending { color: var(--text); background: var(--accent-wash); border-color: var(--accent); }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
/* Список «Мои каналы»: строка целиком — подпись галочки */
.pick-table td { vertical-align: middle; }
.pick-table .check { gap: 12px; }
.pick-table .check input { flex: none; }
.rx { display: inline-flex; gap: 8px; flex-wrap: nowrap; font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 8px; white-space: nowrap;
  border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); font-size: 13px;
}
.chip b { font-weight: 600; font-variant-numeric: tabular-nums; }
.chip i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
/* Чип-переключатель канала в сравнении */
.chip-check { cursor: pointer; user-select: none; }
.chip-check input { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); }
.chip-check.off { opacity: .6; }
.chip-check:has(input:disabled) { opacity: .35; cursor: default; }
.sel-sm { height: 28px; font-size: 13px; width: auto; padding: 0 6px; }
.log-wrap { max-height: 460px; overflow-y: auto; }
.log-table td { padding: 8px 14px; vertical-align: middle; }
.rx span { white-space: nowrap; }
.growth-up { color: var(--good-ink); font-weight: 500; }
.growth-down { color: var(--critical); font-weight: 500; }

/* ---------- Лента событий ---------- */
.feed { display: flex; flex-direction: column; }
.feed-item {
  display: grid; grid-template-columns: 12px 1fr auto; gap: 4px 12px; align-items: start;
  padding: 12px 18px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.feed-item:last-child { border-bottom: none; }
.feed-item:hover { background: var(--surface-2); }
.feed-item.unread { background: var(--accent-wash); }
.feed-item .dot { margin-top: 6px; }
.feed-title { font-weight: 500; }
.feed-meta { font-size: 12px; color: var(--muted); white-space: nowrap; text-align: right; }
.feed-detail { grid-column: 2 / 4; color: var(--text-2); font-size: 13px; overflow-wrap: anywhere; }
.quote {
  margin-top: 6px; padding: 8px 12px; border-left: 3px solid var(--axis); background: var(--surface-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0; white-space: pre-wrap; color: var(--text-2); font-size: 13px;
}

/* Цитата поста, на который отвечает публикация */
.reply {
  display: block; margin-bottom: 4px; padding: 2px 8px; border-left: 2px solid var(--axis); color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.reply b { color: var(--text-2); font-weight: 500; }
.reply[data-open-post] { cursor: pointer; }
.reply[data-open-post]:hover { color: var(--text-2); border-color: var(--accent); }
.post-text + .reply, .modal-body .reply { white-space: normal; margin-bottom: 10px; }

/* ---------- Графики ---------- */
.chart-box { position: relative; height: 240px; }
.chart-box.tall { height: 280px; }
.chart-box.short { height: 170px; }
.chart-fallback { display: grid; place-items: center; height: 100%; color: var(--muted); font-size: 13px; text-align: center; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; }
.seg button {
  height: 28px; padding: 0 10px; border: 0; background: var(--surface); color: var(--text-2);
  font: inherit; font-size: 12px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--border-strong); }
.seg button.on { background: var(--accent-wash); color: var(--text); font-weight: 500; }

.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: grid; grid-template-columns: 34px 1fr 64px 44px; gap: 10px; align-items: center; font-size: 13px; }
.bar-row .emoji { font-size: 16px; text-align: center; }
.bar-track { height: 10px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar-fill { height: 100%; background: var(--series-1); border-radius: 0 4px 4px 0; }

/* ---------- Модальное окно ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; justify-content: flex-end; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); }
.modal-panel {
  position: relative; width: min(1000px, 100%); height: 100%; overflow-y: auto;
  background: var(--page); border-left: 1px solid var(--border); display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 24px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--page); z-index: 2;
}
.modal-body { padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 18px; }
.post-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 14px; }
/* Сравнение версий: смысл несёт начертание (зачёркнуто / подчёркнуто), цвет только помогает */
.diff { overflow-wrap: anywhere; }
.diff-del {
  text-decoration: line-through; background: var(--critical-wash); color: var(--text-2);
  border-radius: 3px; padding: 0 2px;
}
.diff-ins {
  text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px;
  background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--text);
  border-radius: 3px; padding: 0 2px;
}
.versions { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Вложения ---------- */
.media-grid { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; }
.media-item { display: block; max-width: 100%; }
.media-item img { display: block; max-height: 320px; max-width: min(100%, 480px); border-radius: var(--radius-sm); border: 1px solid var(--border); }
video.media-item { max-height: 360px; max-width: min(100%, 560px); border-radius: var(--radius-sm); background: #000; }
.media-audio { width: min(100%, 420px); }
.media-note { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
a.media-note:hover { text-decoration: none; background: var(--accent-wash); }

/* ---------- Настройки ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 16px; }
.login-steps { display: flex; flex-direction: column; gap: 14px; max-width: 460px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.help { font-size: 13px; color: var(--text-2); display: flex; flex-direction: column; gap: 6px; }
.help ol { margin: 0; padding-left: 20px; }

/* ---------- Группы сбора и параметры канала ---------- */
.ovr-section { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0 14px; }
.ovr-section > summary { cursor: pointer; padding: 10px 0; font-weight: 500; font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 8px; }
.ovr-section[open] > summary { border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.ovr-section .settings-grid { padding-bottom: 14px; }
.field.is-own input, .field.is-own select { border-color: var(--accent); background: var(--accent-wash); }
.help table td { padding: 3px 10px 3px 0; vertical-align: top; }
.help pre { margin: 0; padding: 10px 12px; background: var(--surface-2); border-radius: var(--radius-sm); overflow-x: auto; white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---------- Уведомления ---------- */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  padding: 10px 14px; border-radius: var(--radius-sm); background: var(--text); color: var(--page);
  font-size: 13px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}
.toast-error { background: var(--critical); color: #fff; }

/* ---------- Адаптивность ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--border); }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin-top: 0; flex-direction: row; align-items: center; width: 100%; }
  .status-line { display: none; }
  .topbar { padding: 12px 16px; position: static; }
  .content { padding: 16px 16px 40px; }
  .grid-2 { grid-template-columns: 1fr; }
  .modal-head, .modal-body { padding-left: 16px; padding-right: 16px; }
}
