/* Светлый интерфейс по мотивам референса: карточки, сайдбар, пилюли. */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f2f3f5;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #8a8a90;
  --line: #e7e7ea;
  --field: #f0f0f2;
  --accent: #cbA168;
  --accent-dark: #b98f55;
  --ok: #3d9a63;
  --err: #c2504a;
  --radius: 22px;
}

body {
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

a { color: inherit; }

.layout { display: flex; min-height: 100vh; }

/* Сайдбар */
.sidebar {
  width: 250px;
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  flex-shrink: 0;
}
.logo { font-weight: 800; letter-spacing: .12em; font-size: 17px; padding: 4px 12px 12px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; border-radius: 12px;
  text-decoration: none; color: var(--text); font-weight: 500;
}
.nav-item:hover { background: #f4f4f6; }
.nav-item.active { background: #ededf0; }
.nav-icon { width: 18px; text-align: center; color: var(--muted); }
.sidebar-bottom { margin-top: auto; }

/* Шапка и контент */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 32px; background: var(--card); border-bottom: 1px solid var(--line);
}
.page-title { font-size: 24px; font-weight: 700; }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.badge {
  font-size: 12.5px; padding: 5px 12px; border-radius: 999px; font-weight: 600;
  white-space: nowrap;
}
.badge-ok { background: #e4f3e9; color: var(--ok); }
.badge-off { background: #fdeceb; color: var(--err); }
.badge-warn { background: #fcf3e2; color: #a8792a; }
.tg-hint {
  margin: 16px 32px 0; padding: 12px 16px; border-radius: 14px;
  background: #fcf3e2; color: #7a5a22; font-size: 14px;
}
.tg-hint code { background: #fff; padding: 2px 8px; border-radius: 6px; }
.content { padding: 24px 32px 120px; max-width: 980px; width: 100%; margin: 0 auto; }

/* Карточки */
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 24px 28px; margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(20, 20, 40, .05);
}
.card h2 { font-size: 19px; margin-bottom: 12px; }
.cards-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .cards-row { grid-template-columns: 1fr; } }
.form-card p.muted { margin-bottom: 12px; }

/* Поля */
.input {
  width: 100%; border: 1px solid transparent; background: var(--field);
  border-radius: 12px; padding: 11px 14px; font-size: 15px; color: var(--text);
  font-family: inherit;
}
.input:focus { outline: none; border-color: var(--accent); background: #fff; }
.textarea { min-height: 84px; resize: vertical; }
.input-wrap { position: relative; }
.input-counter {
  position: absolute; right: 14px; top: 50%; transform: translateY(-50%);
  font-size: 13px; color: var(--muted); pointer-events: none;
}
.input-wrap .input { padding-right: 84px; }
.field-row { display: flex; gap: 10px; }
.field-row .input { flex: 1; }
.input-short { max-width: 120px; }
.input-compact { padding: 7px 10px; font-size: 14px; width: auto; max-width: 220px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.period-row { display: flex; align-items: center; gap: 12px; }
.period-arrow { color: var(--muted); }

/* Кнопки */
.btn {
  display: inline-block; border: none; cursor: pointer; text-decoration: none;
  font-size: 15px; font-weight: 600; font-family: inherit;
  padding: 11px 22px; border-radius: 999px; text-align: center;
  transition: background .15s;
}
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-dark); }
.btn-light { background: #fff; color: var(--text); border: 1px solid var(--line); }
.btn-light:hover { background: #f6f6f8; }
.btn-soft { background: var(--field); color: var(--text); }
.btn-soft:hover { background: #e6e6ea; }
.btn-danger { background: #fdeceb; color: var(--err); }
.btn-danger:hover { background: #f9dbd9; }
.btn-small { padding: 7px 14px; font-size: 13.5px; }
.btn-wide { width: 100%; }
.page-actions { margin-bottom: 20px; display: flex; justify-content: flex-end; }

/* Переключатель-пилюля «Точное/Частичное совпадение» */
.pill-toggle {
  display: flex; background: var(--field); border-radius: 999px;
  padding: 3px; margin-bottom: 14px;
}
.pill-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.pill-toggle label {
  flex: 1; text-align: center; padding: 9px 12px; border-radius: 999px;
  cursor: pointer; font-weight: 500; color: var(--muted); font-size: 14.5px;
}
.pill-toggle input:checked + label {
  background: #fff; color: var(--text);
  box-shadow: 0 1px 4px rgba(20, 20, 40, .10);
}

/* Группы слов */
.groups { display: flex; flex-direction: column; gap: 10px; margin-bottom: 12px; }
.group-row { display: flex; gap: 10px; align-items: center; }
.group-row .input:first-child { max-width: 260px; }
.group-remove {
  border: none; background: var(--field); color: var(--muted);
  width: 34px; height: 34px; border-radius: 50%; cursor: pointer; font-size: 17px;
  flex-shrink: 0;
}
.group-remove:hover { background: #fdeceb; color: var(--err); }

/* Выбор каналов: категории с «топ-N» + поиск отдельных каналов */
.check-line { display: flex; align-items: center; gap: 9px; padding: 4px 0; cursor: pointer; }
.empty-inline { background: var(--field); border-radius: 14px; padding: 16px 20px; }
.cat-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.cat-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--line); border-radius: 14px; padding: 8px 16px;
}
.cat-top { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.top-input { width: 84px; max-width: 84px; text-align: center; }

/* Панель ручного выбора каналов внутри категории: поиск, список с галочками, страницы */
.pick-panel {
  margin: -2px 0 10px; padding: 14px 16px 12px;
  border: 1px solid var(--line); border-radius: 14px; background: #fafafb;
}
.pick-panel .search-wrap { margin-bottom: 8px; }
.pick-counter { margin: 4px 0 6px; }
.pick-list {
  max-height: 320px; overflow-y: auto; padding: 4px 12px;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}
.pick-list .check-line { padding: 7px 0; border-bottom: 1px solid var(--line); }
.pick-list .check-line:last-child { border-bottom: none; }
.pick-list .check-line > span:first-of-type { flex: 1; min-width: 0; }
.pick-list .check-line > span.muted { white-space: nowrap; }
.pick-panel .pick-pager { padding-top: 10px; }
.pick-pager .pager-num { min-width: 56px; }

.channel-search { margin-bottom: 14px; }
.channel-search > label { display: block; margin-bottom: 6px; }
.search-wrap { position: relative; }
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 10;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 6px 20px rgba(20, 20, 40, .10); overflow: hidden auto; max-height: 280px;
}
.search-item {
  display: block; width: 100%; text-align: left; border: none; background: none;
  padding: 10px 16px; font: inherit; font-size: 14.5px; cursor: pointer; color: var(--text);
}
.search-item:hover { background: var(--field); }
.picked-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--field); border-radius: 999px; padding: 5px 8px 5px 14px; font-size: 14px;
}
.chip-remove {
  border: none; background: none; color: var(--muted); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 0 4px;
}
.chip-remove:hover { color: var(--err); }
.selection-summary { margin-top: 4px; }

/* Список каналов: панель поиска и страницы */
.list-toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.list-toolbar .input[type="search"] { flex: 1; min-width: 220px; }
.list-toolbar .input-compact { max-width: 240px; }
.list-counter { margin: 10px 0 4px; }
.pager { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-top: 16px; }
.pager-num {
  display: inline-block; min-width: 34px; text-align: center; padding: 6px 10px;
  border-radius: 10px; text-decoration: none; font-size: 14px; color: var(--text);
}
.pager-num:hover { background: var(--field); }
.pager-num.current { background: var(--accent); color: #fff; font-weight: 600; }
.pager-gap { color: var(--muted); }

/* Низ формы проекта */
.form-footer {
  position: fixed; left: 250px; right: 0; bottom: 0;
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 32px; background: var(--card); border-top: 1px solid var(--line);
  z-index: 5;
}
@media (max-width: 700px) { .form-footer { left: 0; } }

/* Таблицы */
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 13px; color: var(--muted); font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em;
  padding: 8px 12px; border-bottom: 1px solid var(--line);
}
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.inline-form { display: inline-block; }

/* Статусы */
.status {
  display: inline-block; padding: 4px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
}
.status-draft { background: #ededf0; color: #55555c; }
.status-running { background: #e3edfa; color: #3568a8; }
.status-done { background: #e4f3e9; color: var(--ok); }
.status-error, .status-interrupted { background: #fdeceb; color: var(--err); }
.status-partial { background: #fcf3e2; color: #a8792a; }
.status-error-text { color: var(--err); }

/* Сообщения */
.alert { border-radius: 14px; padding: 12px 16px; margin-bottom: 14px; font-size: 14.5px; }
.alert-error { background: #fdeceb; color: #8f322d; }
.alert-warn { background: #fcf3e2; color: #7a5a22; }
.alert-ok { background: #e4f3e9; color: #2b6e46; }
.alert-link { margin-left: 8px; font-weight: 600; color: inherit; white-space: nowrap; }

/* Страница проекта */
.status-row { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.progress-line { font-size: 16px; font-weight: 600; margin-bottom: 8px; }
.detail-line { margin-bottom: 4px; }
.actions-row { display: flex; gap: 12px; margin-top: 18px; align-items: center; flex-wrap: wrap; }
/* Счётчики каналов проекта по статусам (ожидает / собран / ошибка / недоступен) */
.counters { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 10px; }
.counter {
  background: var(--field); border-radius: 999px; padding: 4px 12px;
  font-size: 13.5px; color: var(--muted);
}
.counter b { color: var(--text); }
.counter-done b { color: var(--ok); }
.counter-error b { color: var(--err); }
/* Кнопка запуска с галочкой «Пересчитать средние за месяц» */
.run-form { display: inline-flex; align-items: center; gap: 12px; }
.run-form .check-line { padding: 0; color: var(--muted); }
/* История прогонов: таблица шире карточки прокручивается сама */
.table-wrap { overflow-x: auto; }
.runs-table td { font-size: 14px; vertical-align: top; }
.runs-table .status { white-space: nowrap; }
.run-reason { margin-top: 4px; max-width: 260px; }
.run-warnings summary { cursor: pointer; color: #a8792a; font-weight: 600; font-size: 13.5px; }
.run-warnings ul { margin: 6px 0 0 18px; font-size: 13.5px; color: #7a5a22; }

/* Пустые состояния */
.empty-state { text-align: center; padding: 48px 28px; }
.empty-state h2 { margin-bottom: 8px; }
.empty-state p { margin-bottom: 18px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* Вход */
.login-body { background: var(--bg); }
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { width: 360px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
