/* ============================================================
   Семантика MaDiS — визуал на дизайн-системе MaDiS
   Светлая + тёмная тема через семантические токены.
   ============================================================ */

:root {
  /* Палитра дизайн-системы */
  --ink: #28323f;
  --steel: #567daa;
  --steel-hover: #456a94;
  --sky: #8ab0e0;
  --carbon: #0e0f12;
  --muted-base: #6b7280;

  --grey-100: #f4f4f5;
  --grey-150: #f1f1f2;
  --grey-tint: #e6e6e9;
  --grey-200: #ececef;
  --grey-250: #e2e4e8;
  --grey-300: #b7bcc4;
  --grey-400: #9ca1aa;
  --slate: #3f4854;

  --green: #2f9e6e;
  --amber: #c98a17;
  --red: #d8584f;

  --font-head: 'Inter Tight', system-ui, sans-serif;
  --font-body: 'Manrope', system-ui, sans-serif;

  --r-control: 8px;
  --r-tile: 16px;
  --r-card: 24px;
  --r-pill: 999px;

  /* Семантические токены (светлая тема) */
  --bg: var(--grey-100);
  --surface: #ffffff;
  --surface-2: var(--grey-150);
  --border: var(--grey-200);
  --border-strong: var(--grey-250);
  --text: var(--ink);
  --text-muted: var(--muted-base);
  --text-faint: var(--grey-400);
  --accent: var(--steel);
  --accent-hover: var(--steel-hover);
  --accent-tint: #eef3fa;
  --accent-tint-strong: #e3ecf6;
  --header-bg: rgba(255, 255, 255, 0.82);
  --shadow: rgba(16, 24, 40, 0.12);
  --ghost-bg: #eef0f2;
  --ghost-bg-hover: #e4e6e9;
}

/* Тёмная тема */
[data-theme='dark'] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1c2027;
  --border: #262a32;
  --border-strong: #2f343d;
  --text: #e7e9ed;
  --text-muted: #9aa0aa;
  --text-faint: #6f7681;
  --accent: #6f9bd0;
  --accent-hover: #8ab0e0;
  --accent-tint: rgba(111, 155, 208, 0.16);
  --accent-tint-strong: rgba(111, 155, 208, 0.24);
  --header-bg: rgba(20, 23, 29, 0.85);
  --shadow: rgba(0, 0, 0, 0.5);
  --ghost-bg: #232730;
  --ghost-bg-hover: #2b303a;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background .2s ease, color .2s ease;
}
h1, h2, h3, h4 { font-family: var(--font-head); }
::selection { background: var(--accent); color: #fff; }

.hidden { display: none !important; }
.muted { color: var(--text-faint); font-size: 14px; }

/* ── Шапка ── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 20px; padding: 12px 28px;
  background: var(--header-bg);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 11px; text-decoration: none; color: inherit; }
.logo {
  width: 32px; height: 32px; display: grid; place-items: center;
  background: var(--accent); border-radius: 9px;
  font-family: var(--font-head); font-weight: 800; font-size: 18px; color: #fff;
}
.brand-name { font-family: var(--font-head); font-weight: 800; font-size: 19px; letter-spacing: -0.01em; }

.topnav { display: flex; align-items: center; gap: 2px; flex: 1; flex-wrap: wrap; }
.navlink {
  background: transparent; border: none; color: var(--text-muted);
  font-family: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
  padding: 9px 14px; border-radius: var(--r-control); transition: all .15s;
  text-decoration: none; display: inline-block;
}
.navlink:hover { color: var(--text); background: var(--surface-2); }
.navlink.active { color: var(--accent); background: var(--accent-tint); }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.theme-toggle {
  width: 38px; height: 38px; border-radius: var(--r-control);
  background: var(--surface-2); border: 1px solid var(--border);
  cursor: pointer; font-size: 16px; display: grid; place-items: center;
  transition: all .15s; color: var(--text);
}
.theme-toggle:hover { border-color: var(--accent); }

.auth-status { display: inline-flex; align-items: center; gap: 8px; color: var(--green); font-size: 14px; font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }

/* ── Кнопки (скругление как у полей — r-control) ── */
.btn {
  font-family: var(--font-body); font-size: 14px; font-weight: 600;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  padding: 11px 18px; border-radius: var(--r-control);
  cursor: pointer; transition: all .16s ease; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 8px;
}
.btn:hover { border-color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-yandex { background: #fc3f1d; border-color: #fc3f1d; color: #fff; }
.btn-yandex:hover { background: #e63415; border-color: #e63415; }
.btn-ghost { background: var(--ghost-bg); border-color: transparent; }
.btn-ghost:hover { background: var(--ghost-bg-hover); border-color: transparent; }
.btn-sm { padding: 8px 14px; font-size: 13px; }
.btn-danger { color: var(--red); border-color: rgba(216, 88, 79, .35); background: var(--surface); }
.btn-danger:hover { background: rgba(216, 88, 79, .1); border-color: var(--red); }

/* ── Контейнер / виды ── */
.container { max-width: none; margin: 0 auto; padding: 36px 28px 90px; }

/* Фирменная сетка-фон (мотив из генераторов скриптов) — позади всего контента */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 44px 44px;
  opacity: 0.4;
}
.view { display: none; }
.view.active { display: block; }

/* ── Карточки ── */
.search-card, .tool-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-card); padding: 32px;
}
.tool-card + .tool-card { margin-top: 20px; }
.search-card h1, .tool-card h1 { font-size: 30px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 8px; }
.tool-card h2, .h4 { font-family: var(--font-head); font-size: 21px; font-weight: 700; letter-spacing: -0.01em; margin-bottom: 6px; }
.lead { color: var(--text-muted); font-size: 16px; margin-bottom: 24px; }

/* ── Форма поиска ── */
.search-form { display: flex; flex-direction: column; gap: 16px; }
.search-row { display: flex; gap: 12px; align-items: stretch; }
.seed-input {
  flex: 1; min-width: 0;
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  border-radius: var(--r-control); padding: 13px 16px; font-size: 16px; font-family: inherit;
}
.seed-input::placeholder { color: var(--text-faint); }
.seed-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.search-row .btn-accent { padding-left: 24px; padding-right: 24px; }

.settings-row { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--text-faint); text-transform: uppercase; letter-spacing: .06em; padding-left: 2px; }
.field-geo { flex: 1 1 320px; min-width: 260px; }

.select {
  background: var(--surface); border: 1px solid var(--border-strong); color: var(--text);
  border-radius: var(--r-control); padding: 11px 12px; font-size: 14px; font-family: inherit; cursor: pointer;
}
.select:focus { outline: none; border-color: var(--accent); }

/* Комбобокс регионов */
.combo {
  position: relative; display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--r-control);
  padding: 6px 8px; min-height: 46px; cursor: text;
}
.combo:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.combo-tags { display: contents; }
.combo-tag {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--accent-tint); color: var(--accent-hover);
  border-radius: var(--r-pill); padding: 4px 12px; font-size: 13px; font-weight: 600; white-space: nowrap;
}
.combo-tag .x { cursor: pointer; opacity: .65; font-size: 14px; line-height: 1; }
.combo-tag .x:hover { opacity: 1; }
.combo-input { flex: 1; min-width: 120px; background: transparent; border: none; outline: none; color: var(--text); font-family: inherit; font-size: 14px; padding: 4px; }
.combo-dropdown {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-control);
  max-height: 260px; overflow-y: auto; display: none; box-shadow: 0 16px 40px var(--shadow);
}
.combo-dropdown.open { display: block; }
.combo-item { padding: 9px 14px; cursor: pointer; font-size: 14px; }
.combo-item:hover { background: var(--surface-2); color: var(--accent-hover); }

/* ── Прогресс ── */
.progress { margin-top: 28px; }
.progress-bar { height: 6px; background: var(--border); border-radius: var(--r-pill); overflow: hidden; margin-bottom: 18px; }
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width .4s ease; }
.progress-steps { list-style: none; display: flex; flex-wrap: wrap; gap: 18px; }
.progress-steps li { color: var(--text-faint); font-size: 14px; display: flex; align-items: center; gap: 8px; transition: color .2s; }
.progress-steps li::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); transition: all .2s; }
.progress-steps li.active { color: var(--text); }
.progress-steps li.active::before { background: var(--accent); }
.progress-steps li.done { color: var(--green); }
.progress-steps li.done::before { background: var(--green); }

/* ── Ошибка ── */
.error-box {
  margin-top: 24px; padding: 14px 18px;
  background: rgba(216, 88, 79, .1); border: 1px solid rgba(216, 88, 79, .3);
  border-radius: var(--r-control); color: var(--red); font-size: 14px;
}

/* ── Результаты ── */
.results { margin-top: 34px; }
.stats { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 24px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-tile); padding: 18px 22px; min-width: 120px; }
.stat .num { font-family: var(--font-head); font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.stat .lbl { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-top: 4px; }
.stat.vch .num { color: var(--accent); }
.stat.sch .num { color: var(--sky); }
.stat.nch .num { color: var(--slate); }

.results-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.tabs { display: flex; gap: 6px; background: var(--surface-2); padding: 4px; border-radius: var(--r-pill); }
.tab { background: transparent; border: none; color: var(--text-muted); padding: 8px 18px; border-radius: var(--r-pill); cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 600; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px var(--shadow); }
.export-buttons { display: flex; align-items: center; gap: 8px; }
.source-badge { font-size: 12px; color: var(--text-muted); padding: 5px 12px; border: 1px solid var(--border-strong); border-radius: var(--r-pill); background: var(--surface); }

.cluster-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }

/* ── Группы (аккордеон) ── */
.clusters-list { display: flex; flex-direction: column; gap: 12px; }
.cluster { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-tile); overflow: visible; transition: border-color .16s ease; }
.cluster:hover { border-color: var(--grey-300); }
.cluster.drop-target { outline: 2px dashed var(--accent); outline-offset: -2px; }
.cluster-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; cursor: pointer; user-select: none; border-radius: var(--r-tile) var(--r-tile) 0 0; }
.cluster:not(.open) .cluster-head { border-radius: var(--r-tile); }
.cluster-head:hover { background: var(--surface-2); }
.cluster-title { flex: 1; font-family: var(--font-head); font-weight: 700; font-size: 16px; letter-spacing: -0.01em; cursor: text; }

.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 4px 10px; border-radius: var(--r-pill); white-space: nowrap; }
.badge-pillar  { background: var(--accent-tint-strong); color: var(--accent-hover); }
.badge-niche   { background: var(--surface-2); color: var(--slate); }
.badge-tech    { background: var(--surface-2); color: var(--text); }
.badge-info    { background: var(--accent-tint); color: var(--accent); }
.badge-compare { background: var(--accent-tint-strong); color: var(--accent-hover); }

.prio { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: var(--r-pill); border: 1px solid var(--border-strong); }
.prio-высокий { color: var(--accent-hover); border-color: rgba(86, 125, 170, .4); background: var(--accent-tint); }
.prio-средний { color: var(--amber); border-color: rgba(201, 138, 23, .3); }
.prio-низкий  { color: var(--text-faint); }

.kw-count { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.chevron { color: var(--text-faint); transition: transform .2s; font-size: 12px; }
.cluster.open .chevron { transform: rotate(90deg); }

.cluster-body { display: none; padding: 0 20px 20px; }
.cluster.open .cluster-body { display: block; }
.cluster-meta { font-size: 14px; color: var(--text-muted); padding: 4px 0 14px; }
.cluster-meta .intent { color: var(--text); font-weight: 600; }
.cluster-meta .url { color: var(--accent); font-family: ui-monospace, monospace; }
.divider { border: none; border-top: 1px solid var(--border); margin: 0 0 14px; }

/* Ключи — вертикальным списком */
.kw-chips { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.kw {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-control);
  padding: 9px 14px; font-size: 14px; transition: all .14s;
}
.kw:hover { border-color: var(--accent); background: var(--surface-2); }
.kw.removed { opacity: .5; }
.kw.removed .kw-text { text-decoration: line-through; }
.kw.dragging { opacity: .4; }
.kw .freq { flex: none; font-size: 10px; font-weight: 800; padding: 2px 7px; border-radius: var(--r-pill); }
.kw .freq.ВЧ { background: var(--accent-tint-strong); color: var(--accent-hover); }
.kw .freq.СЧ { background: var(--accent-tint); color: var(--accent); }
.kw .freq.НЧ { background: var(--surface-2); color: var(--text-faint); }
.kw-text { flex: 1; }

/* Режим минусации: кликабельные слова */
.kw-text.minus-mode .kw-word { cursor: pointer; border-radius: 4px; padding: 0 1px; transition: all .1s; }
.kw-text.minus-mode .kw-word:hover { background: rgba(216, 88, 79, .15); color: var(--red); }
.kw-text .kw-word.struck { color: var(--red); text-decoration: line-through; opacity: .75; }
#minusModeBtn.btn-accent { box-shadow: 0 0 0 3px var(--accent-tint); }
.kw .shows { color: var(--text-muted); font-size: 13px; font-variant-numeric: tabular-nums; min-width: 48px; text-align: right; }
.kw .muted-shows { opacity: .4; }
.kw-acts { display: inline-flex; align-items: center; gap: 4px; }
.kw-act {
  display: inline-grid; place-items: center; min-width: 22px; height: 22px;
  padding: 0 5px; border-radius: 6px; font-size: 11px; font-weight: 700;
  color: var(--text-muted); text-decoration: none; cursor: pointer;
  background: var(--surface-2); transition: all .12s;
}
.kw-act:hover { background: var(--accent); color: #fff; }
.kw-del:hover { background: var(--red); }

/* Меню "переместить в группу" */
.move-wrap { position: relative; }
.move-menu {
  position: absolute; top: calc(100% + 4px); right: 0; z-index: 40;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-control);
  min-width: 200px; max-height: 260px; overflow-y: auto; display: none; box-shadow: 0 16px 40px var(--shadow);
}
.move-menu.open { display: block; }
.move-menu div { padding: 9px 14px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.move-menu div:hover { background: var(--surface-2); color: var(--accent-hover); }

/* Добавление ключа */
.kw-add { display: flex; gap: 8px; margin-bottom: 14px; }
.kw-add-input { flex: 1; background: var(--surface); border: 1px solid var(--border-strong); color: var(--text); border-radius: var(--r-control); padding: 9px 12px; font-size: 13px; font-family: inherit; }
.kw-add-input:focus { outline: none; border-color: var(--accent); }

.cluster-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Редактирование названия */
.title-edit {
  flex: 1; background: var(--surface); border: 1px solid var(--accent); color: var(--text);
  border-radius: var(--r-control); padding: 6px 10px;
  font-family: var(--font-head); font-size: 16px; font-weight: 700;
}
.title-edit:focus { outline: none; box-shadow: 0 0 0 3px var(--accent-tint); }

/* Меню копирования */
.copy-wrap { position: relative; }
.copy-menu {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 25;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-control);
  min-width: 210px; overflow: hidden; display: none; box-shadow: 0 16px 40px var(--shadow);
}
.copy-menu.open { display: block; }
.copy-menu div { padding: 9px 14px; font-size: 13px; cursor: pointer; }
.copy-menu div:hover { background: var(--surface-2); color: var(--accent-hover); }

/* ── Минус-слова ── */
.minus-add { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.minus-add .seed-input { flex: 1 1 260px; font-size: 14px; padding: 10px 12px; }
.minus-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.minus-word {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(216, 88, 79, .1); border: 1px solid rgba(216, 88, 79, .28);
  color: var(--red); border-radius: var(--r-pill); padding: 6px 12px;
  font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s;
}
.minus-word.kept { background: rgba(47, 158, 110, .12); border-color: rgba(47, 158, 110, .3); color: var(--green); text-decoration: line-through; }
.minus-word.custom { border-style: dashed; }
.minus-word .mx { cursor: pointer; opacity: .6; font-size: 14px; line-height: 1; }
.minus-word .mx:hover { opacity: 1; }

.notes { margin-top: 18px; color: var(--text-muted); font-size: 14px; font-style: italic; }

/* ── Чистка: счётчик вкладки, минус по списку, корзина ── */
.tab-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; margin-left: 4px;
  background: var(--accent-tint-strong); color: var(--accent);
  border-radius: var(--r-pill); font-size: 11px; font-weight: 700;
}
.minus-list-panel {
  margin: 12px 0 4px; padding: 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-tile);
}
.minus-list-input {
  width: 100%; min-height: 96px; resize: vertical; box-sizing: border-box;
  padding: 10px 12px; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-control);
  font-family: var(--font-body); font-size: 14px; line-height: 1.45;
}
.minus-list-input:focus { outline: none; border-color: var(--accent); }
.minus-list-actions { display: flex; gap: 8px; margin-top: 10px; }
.ac-check { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14px; color: var(--text); cursor: pointer; }
.ac-check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }
.ac-check .muted { font-size: 13px; }
#autoCleanPanel .minus-list-input { margin-top: 8px; }

/* ── Подготовка: Матрицы и Импорт (панели на стр. сбора) ── */
.prep-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-tile); margin-top: 16px; padding: 0 18px; }
.prep-panel > summary { cursor: pointer; padding: 16px 0; font-family: var(--font-head); font-weight: 700; font-size: 16px; color: var(--text); list-style: none; }
.prep-panel > summary::-webkit-details-marker { display: none; }
.prep-panel > summary::before { content: '▸'; margin-right: 8px; color: var(--accent); }
.prep-panel[open] > summary::before { content: '▾'; }
.prep-body { padding-bottom: 18px; }
.matrix-fields { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 10px 0; }
.matrix-field { display: flex; flex-direction: column; gap: 6px; }
.matrix-field .minus-list-input { min-height: 120px; }
.matrix-tails { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.matrix-tail { font-size: 12px; padding: 3px 9px; border: 1px dashed var(--border-strong); border-radius: var(--r-pill); cursor: pointer; color: var(--text-muted); background: var(--bg); }
.matrix-tail:hover { border-color: var(--accent); color: var(--accent); }
#mxResult { min-height: 120px; margin-top: 10px; }
@media (max-width: 720px) { .matrix-fields { grid-template-columns: 1fr; } }

/* ── Вкладки-этапы: Подбор / Матрицы / Парсинг / Чистка ── */
.wf-head { margin-bottom: 16px; }
.wf-head h1 { margin-bottom: 4px; }
.wf-tabs { display: flex; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-tile); padding: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.wf-tab { display: inline-flex; align-items: center; gap: 8px; background: transparent; border: none; color: var(--text-muted); padding: 10px 18px; border-radius: var(--r-control); cursor: pointer; font-family: var(--font-head); font-weight: 700; font-size: 15px; transition: all .15s; }
.wf-tab:hover { color: var(--text); background: var(--ghost-bg); }
.wf-tab.active { background: var(--accent-tint); color: var(--accent); }
.wf-i { font-size: 16px; }
.wf-panel { animation: wfIn .2s ease; }
@keyframes wfIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.step-hint { color: var(--text-muted); font-size: 14px; margin-bottom: 16px; }
.step-hint b { color: var(--text); }

/* Парсинг */
.parsing-layout { display: grid; grid-template-columns: 1fr 280px; gap: 16px; align-items: start; }
.parsing-main .minus-list-input { min-height: 320px; }
.parsing-side { background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-tile); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.parsing-side .field { gap: 6px; }
.ps-title { font-family: var(--font-head); font-weight: 700; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.ps-note { font-size: 12px; }
@media (max-width: 760px) { .parsing-layout { grid-template-columns: 1fr; } .parsing-main .minus-list-input { min-height: 200px; } }

/* Переключатель вида: группы ↔ таблица */
.view-toggle { display: inline-flex; background: var(--ghost-bg); border-radius: var(--r-pill); padding: 3px; }
.view-toggle .vt { background: transparent; border: none; color: var(--text-muted); padding: 6px 12px; border-radius: var(--r-pill); cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 600; }
.view-toggle .vt.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px var(--shadow); }

/* Плоская таблица запросов */
.clusters-table { overflow-x: auto; }
.kw-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.kw-table th { text-align: left; padding: 8px 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); border-bottom: 1px solid var(--border); font-weight: 700; }
.kw-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.kw-table tr:hover td { background: var(--accent-tint); }
.kw-table .t-i { width: 40px; color: var(--text-faint); }
.kw-table .t-shows { width: 96px; text-align: right; white-space: nowrap; }
.kw-table .t-group { color: var(--text-muted); white-space: nowrap; }
.kw-table .t-acts { width: 96px; white-space: nowrap; text-align: right; }
.kw-table .t-acts .kw-act { margin-left: 6px; }
.kw-table .t-phrase.minus-mode .kw-word { cursor: pointer; padding: 0 1px; border-radius: 3px; }
.kw-table .t-phrase.minus-mode .kw-word:hover { background: rgba(216, 88, 79, .15); }
.kw-word.struck { text-decoration: line-through; color: var(--red); opacity: .75; }

/* Пустое состояние чистки */
.clean-empty { text-align: center; padding: 60px 20px; background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--r-card); }
.ce-icon { font-size: 40px; margin-bottom: 12px; }
.ce-title { font-family: var(--font-head); font-weight: 700; font-size: 18px; margin-bottom: 6px; }

/* ── Каталог скриптов: поиск, фильтры, список-табы + конструктор ── */
.scripts-toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.scripts-toolbar .seed-input { flex: 1; min-width: 220px; }
.scripts-filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.filter-chip { padding: 6px 14px; border-radius: var(--r-pill); border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); cursor: pointer; font-family: inherit; font-size: 13px; font-weight: 600; transition: all .12s; }
.filter-chip:hover { color: var(--text); border-color: var(--border-strong); }
.filter-chip.active { background: var(--accent-tint); border-color: var(--accent); color: var(--accent); }

.scripts-layout { display: grid; grid-template-columns: 270px 1fr; gap: 16px; align-items: start; }
.scripts-list { display: flex; flex-direction: column; gap: 6px; }
.scr-item { text-align: left; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-control); padding: 12px 14px; cursor: pointer; display: flex; align-items: center; gap: 8px; font-family: inherit; font-size: 14px; color: var(--text); transition: all .12s; }
.scr-item:hover { border-color: var(--border-strong); }
.scr-item.active { border-color: var(--accent); background: var(--accent-tint); color: var(--accent); }
.scr-item .scr-name { flex: 1; font-weight: 600; }
.scr-badge { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: var(--r-pill); flex-shrink: 0; }
.scr-badge.new { background: rgba(47, 158, 110, .15); color: var(--green); }
.scr-badge.hot { background: rgba(201, 138, 23, .14); }

.scripts-detail { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-tile); padding: 22px; min-height: 320px; }
.scripts-empty { color: var(--text-faint); text-align: center; padding: 48px 20px; }
.sc-detail-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.sc-title { font-family: var(--font-head); font-size: 18px; font-weight: 700; margin: 0; }
.sc-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.sc-tag { font-size: 11px; font-weight: 600; color: var(--text-muted); background: var(--ghost-bg); padding: 3px 9px; border-radius: var(--r-pill); }
.sc-desc { color: var(--text-muted); font-size: 14px; margin: 0 0 16px; line-height: 1.5; }
.sc-params { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.sc-params .field { gap: 6px; }
.sc-params .seed-input { padding: 9px 12px; font-size: 14px; }
.sc-code-wrap { position: relative; }
.sc-copy { position: absolute; top: 10px; right: 10px; z-index: 1; }
.sc-code { margin: 0; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-control); padding: 14px 16px; overflow-x: auto; }
.sc-code code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; line-height: 1.55; color: var(--text); white-space: pre; display: block; }
.sc-note { font-size: 13px; margin: 12px 0 0; }
@media (max-width: 760px) { .scripts-layout { grid-template-columns: 1fr; } }
.scripts-detail.embed { padding: 0; overflow: hidden; }
.sc-embed { width: 100%; border: 0; display: block; min-height: 700px; }

/* ── Аккаунт: чип в шапке ── */
.auth-box { display: flex; align-items: center; gap: 8px; }
.auth-chip { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-pill); padding: 5px 12px; color: var(--text); font-size: 13px; font-weight: 600; }
.auth-chip:hover { border-color: var(--accent); }
.auth-tokens { color: var(--accent); font-weight: 700; white-space: nowrap; }
.auth-email { color: var(--text-muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Страница аккаунта ── */
.account-wrap { max-width: 920px; margin: 0 auto; }
.account-wrap > .account-card:only-child { max-width: 440px; margin: 32px auto; }
.account-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 760px) { .account-grid { grid-template-columns: 1fr; } }
.account-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 28px; }
.account-card h1 { font-size: 22px; margin-bottom: 18px; }
.acc-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.acc-val { font-weight: 600; }
.badge-ok { color: var(--green); font-weight: 600; }
.badge-warn { color: var(--amber); font-weight: 600; }
.verify-row { margin-top: 14px; padding: 14px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-control); }
.verify-row p { margin-bottom: 8px; }
.balance-label { font-size: 13px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.balance-value { font-family: var(--font-head); font-size: 42px; font-weight: 800; color: var(--accent); margin: 6px 0 10px; }
.tx-list { margin-top: 18px; }
.tx-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); font-weight: 700; margin-bottom: 8px; }
.tx-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 13px; }
.tx-reason { color: var(--text-muted); }
.tx-amount.plus { color: var(--green); font-weight: 700; }
.tx-amount.minus { color: var(--red); font-weight: 700; }
.account-banner { padding: 12px 16px; border-radius: var(--r-control); margin-bottom: 16px; font-size: 14px; font-weight: 600; }
.account-banner.ok { background: rgba(47,158,110,.12); color: var(--green); border: 1px solid rgba(47,158,110,.3); }
.account-banner.warn { background: rgba(201,138,23,.12); color: var(--amber); border: 1px solid rgba(201,138,23,.3); }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 20px; background: var(--ghost-bg); border-radius: var(--r-pill); padding: 4px; }
.auth-tab { flex: 1; background: transparent; border: none; padding: 9px; border-radius: var(--r-pill); cursor: pointer; font-family: inherit; font-weight: 600; font-size: 14px; color: var(--text-muted); }
.auth-tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 4px var(--shadow); }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
.auth-form .field { gap: 6px; }
.auth-error { background: rgba(216,88,79,.1); border: 1px solid rgba(216,88,79,.3); color: var(--red); padding: 10px 12px; border-radius: var(--r-control); font-size: 13px; }
.auth-switch { margin-top: 14px; font-size: 13px; }

.trash-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 12px; }
.trash-actions { display: flex; gap: 8px; flex-shrink: 0; }
.trash-list { display: flex; flex-direction: column; gap: 6px; }
.trash-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-control);
}
.trash-phrase { flex: 1; font-size: 14px; color: var(--text); }
.trash-reason {
  font-size: 11px; font-weight: 600; color: var(--text-muted);
  background: var(--ghost-bg); padding: 2px 8px; border-radius: var(--r-pill); flex-shrink: 0;
}

/* ── Инструменты (UTM, калькулятор, SEO, кодировщик) ── */
.tool-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.tool-grid .field { gap: 7px; }
.tool-grid .seed-input { font-size: 15px; padding: 12px 14px; }
.utm-presets { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.tool-output {
  margin: 22px 0; padding: 18px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--r-control);
  word-break: break-all; font-family: ui-monospace, monospace; font-size: 14px; color: var(--accent-hover);
}
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 24px; }
.metric { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-tile); padding: 18px; }
.metric .mv { font-family: var(--font-head); font-size: 26px; font-weight: 800; letter-spacing: -0.02em; color: var(--accent); }
.metric .ml { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-top: 6px; }
.metric .mh { font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.counter-row { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 4px; font-size: 13px; }
.counter-bar { height: 6px; border-radius: var(--r-pill); background: var(--border); overflow: hidden; margin-bottom: 16px; }
.counter-bar > i { display: block; height: 100%; background: var(--green); transition: width .2s, background .2s; }
.counter-bar.warn > i { background: var(--amber); }
.counter-bar.over > i { background: var(--red); }
textarea.seed-input { resize: vertical; min-height: 90px; line-height: 1.5; }

/* Калькулятор стоимости сайта */
.cc-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 18px; margin-top: 4px; }
.cc-opt { display: flex; align-items: center; gap: 10px; padding: 7px 0; }
.cc-opt-name { white-space: nowrap; }
.cc-opt-lead { flex: 1; border-bottom: 1px dashed var(--border-strong); height: 0; margin: 6px 2px 0; }
.cc-opt .cc-opt-price { flex: none; }
.cc-subparams { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin-top: 14px; padding: 14px; background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--r-control); }
@media (max-width: 640px) { .cc-subparams { grid-template-columns: 1fr; } }
.cc-stages { display: flex; flex-wrap: wrap; gap: 10px 22px; margin-top: 4px; }
.cc-stages .check { gap: 8px; }
.cc-opt-price { color: var(--text-muted); font-size: 12px; font-weight: 600; white-space: nowrap; }
.cc-total { background: var(--accent-tint); border: 1px solid var(--border); border-radius: var(--r-tile); padding: 22px; text-align: center; margin-bottom: 16px; }
.cc-total-main { font-family: var(--font-head); font-size: 36px; font-weight: 800; letter-spacing: -0.02em; color: var(--accent-hover); }
.cc-total-sub { font-size: 13px; color: var(--text-muted); margin-top: 4px; }
.cc-breakdown { margin-top: 18px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-tile); padding: 16px 18px; }
.cc-bd-title { font-family: var(--font-head); font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.cc-bd-row { display: flex; justify-content: space-between; gap: 16px; padding: 5px 0; font-size: 14px; }
.cc-bd-row + .cc-bd-row { border-top: 1px solid var(--border); }
.cc-bd-mult { color: var(--text-muted); font-size: 12.5px; font-style: italic; }
@media (max-width: 640px) { .cc-options { grid-template-columns: 1fr; } }

/* Калькулятор по каналам */
.combo-input-row { display: flex; gap: 8px; }
.combo-input-row .seed-input { flex: 1; min-width: 0; }
.combo-input-row .select { flex: 0 0 auto; }
.channels-head { display: flex; align-items: center; justify-content: space-between; margin: 24px 0 12px; }
.chan { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-tile); padding: 16px; margin-bottom: 12px; }
.chan-top { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; }
.chan-name { flex: 1; background: var(--surface); border: 1px solid var(--border-strong); color: var(--text); border-radius: var(--r-control); padding: 9px 12px; font-family: inherit; font-size: 15px; font-weight: 600; }
.chan-name:focus { outline: none; border-color: var(--accent); }
.chan-inputs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.chan-inputs .field { gap: 5px; }
.chan-inputs .seed-input { padding: 9px 10px; font-size: 14px; }
.chan-stats { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.cstat { display: flex; flex-direction: column; }
.cstat .cv { font-family: var(--font-head); font-weight: 700; font-size: 16px; }
.cstat .cl { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.chan-verdict { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13.5px; color: var(--text); }
.cv-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-faint); flex: none; }
.cv-dot.ok { background: var(--green); }
.cv-dot.warn { background: var(--amber); }
.cv-dot.bad { background: var(--red); }
@media (max-width: 640px) { .chan-inputs { grid-template-columns: 1fr 1fr; } }

/* Карточки генераторов (объявления / быстрые ссылки) */
.gen-card { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-tile); padding: 18px 20px; margin-top: 16px; }
.gen-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-family: var(--font-head); font-weight: 700; font-size: 15px; margin-bottom: 10px; }
.gen-row { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; padding: 7px 0; }
.gen-row + .gen-row { border-top: 1px solid var(--border); }
.gen-row .gl { font-size: 11px; font-weight: 600; color: var(--text-faint); text-transform: uppercase; letter-spacing: .05em; }
.gen-row .gv { font-size: 15px; font-weight: 500; margin-top: 2px; }
.gen-row .cc { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.gen-row .cc.over { color: var(--red); font-weight: 700; }
.gen-card .divider { margin: 10px 0; }

/* Редактируемые быстрые ссылки */
.sl-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.sl-row + .sl-row { border-top: 1px solid var(--border); }
.sl-row .sl-field:nth-child(1) { flex: 0 0 36%; }
.sl-field { position: relative; flex: 1; display: flex; align-items: center; }
.sl-field input { width: 100%; background: var(--surface); border: 1px solid var(--border-strong); color: var(--text); border-radius: var(--r-control); padding: 8px 56px 8px 12px; font-size: 14px; font-family: inherit; }
.sl-field input:focus { outline: none; border-color: var(--accent); }
.sl-field .cc { position: absolute; right: 10px; font-size: 11px; color: var(--text-faint); font-variant-numeric: tabular-nums; pointer-events: none; }
.sl-field .cc.over { color: var(--red); font-weight: 700; }
@media (max-width: 640px) { .sl-row { flex-wrap: wrap; } .sl-row .sl-field:nth-child(1) { flex-basis: 100%; } }

/* Панель ниши */
.niche-panel {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 14px;
  background: var(--accent-tint); border: 1px solid var(--border);
  border-radius: var(--r-tile); padding: 16px 20px; margin-bottom: 18px;
}
.niche-main { display: flex; align-items: center; gap: 14px; }
.niche-icon { font-size: 26px; }
.niche-label { font-family: var(--font-head); font-weight: 700; font-size: 16px; }
.niche-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.niche-signals { display: flex; gap: 10px; flex-wrap: wrap; }
.nsig { font-size: 13px; font-weight: 600; color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-pill); padding: 5px 12px; }
.niche-tips { flex-basis: 100%; width: 100%; margin: 8px 0 0; padding: 12px 0 0; border-top: 1px solid var(--border); list-style: none; display: flex; flex-direction: column; gap: 6px; }
.niche-tips li { display: flex; align-items: flex-start; gap: 8px; font-size: 13.5px; color: var(--text); line-height: 1.5; }
.niche-tips li::before { content: '✦'; color: var(--accent); flex: none; }

/* Теги ключа */
.kw-tags { display: inline-flex; gap: 4px; flex-wrap: wrap; }
.ktag { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 1px 7px; border-radius: var(--r-pill); background: var(--surface-2); color: var(--text-faint); }
.ktag-заказ, .ktag-цена { background: var(--accent-tint-strong); color: var(--accent-hover); }
.ktag-гео { background: rgba(47, 158, 110, .14); color: var(--green); }
.ktag-инфо { background: rgba(86, 125, 170, .14); color: var(--steel); }
.ktag-отзывы { background: rgba(201, 138, 23, .14); color: var(--amber); }

/* Подвкладки внутри инструмента */
.subtabs { display: inline-flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: var(--r-pill); margin-bottom: 22px; }
.subtab { background: transparent; border: none; color: var(--text-muted); padding: 8px 18px; border-radius: var(--r-pill); cursor: pointer; font-family: inherit; font-size: 14px; font-weight: 600; }
.subtab.active { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px var(--shadow); }
.subpanel { display: block; }
.subpanel.hidden { display: none; }

/* Чекбокс-настройка */
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text); cursor: pointer; user-select: none; padding-bottom: 4px; }
.check input { width: 17px; height: 17px; accent-color: var(--accent); cursor: pointer; }

/* Мини-ИИ помощник */
.ai-hint { display: none; margin: 18px 0; padding: 14px 16px; background: var(--accent-tint); border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: var(--r-control); }
.ai-hint.show { display: block; }
.ai-hint .ai-title { display: flex; align-items: center; gap: 8px; font-family: var(--font-head); font-weight: 700; font-size: 13px; color: var(--accent-hover); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .04em; }
.ai-hint ul { margin: 0; padding-left: 2px; list-style: none; display: flex; flex-direction: column; gap: 6px; }
.ai-hint li { display: flex; align-items: flex-start; gap: 8px; font-size: 13.5px; color: var(--text); line-height: 1.5; }
.ai-hint li::before { content: ''; width: 7px; height: 7px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--accent); }
.ai-hint li.ok::before { background: var(--green); }
.ai-hint li.warn::before { background: var(--amber); }
.ai-hint li.bad::before { background: var(--red); }

/* Фильтр и сортировка ключей */
.kw-filter { background: var(--surface); border: 1px solid var(--border-strong); color: var(--text); border-radius: var(--r-control); padding: 7px 12px; font-size: 13px; font-family: inherit; min-width: 200px; }
.kw-filter::placeholder { color: var(--text-faint); }
.kw-filter:focus { outline: none; border-color: var(--accent); }
.kw-sort { padding: 7px 10px; font-size: 13px; }

/* ── Адаптив ── */
@media (max-width: 760px) {
  .tool-grid, .metric-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .topnav { order: 3; width: 100%; }
  .search-row { flex-direction: column; }
  .search-row .btn-accent { width: 100%; justify-content: center; }
  .settings-row { flex-direction: column; align-items: stretch; }
  .field, .select { width: 100%; }
  .kw { flex-wrap: wrap; }
  .tool-grid, .metric-grid { grid-template-columns: 1fr; }
}
