:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --line: #2a2f3a;
  --fg: #e6e8ee;
  --muted: #8b93a5;
  --accent: #4f8cff;
  --bad: #ff5c68;
  --warn: #ffb020;
  --ok: #3ecf8e;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Inter, Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.top {
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px;
  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: 1px; font-size: 18px;
  color: var(--accent); text-decoration: none;
}
.spacer { flex: 1; }
.stats, .meta { color: var(--muted); font-size: 12px; }
.meta b { color: var(--fg); }
.filters { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }

.sel, input[type="search"], input[type="text"], input, textarea, select {
  background: var(--panel2); color: var(--fg);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 8px; font: inherit; font-size: 13px;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
  display: inline-block;
  background: var(--panel2); color: var(--fg);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 12px; cursor: pointer; font: inherit; font-size: 13px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.play { padding: 4px 10px; }
.btn.danger { border-color: #4a2f2f; color: var(--bad); }

main { padding: 16px; }

.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.grid th {
  text-align: left; color: var(--muted); font-weight: 500;
  padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.grid th.warn { color: var(--warn); }
.grid td { padding: 7px 10px; border-bottom: 1px solid #20242d; }
.grid tr:hover td { background: var(--panel); }
.grid tr.hot td { background: rgba(255, 92, 104, 0.06); }
.grid .url { color: var(--muted); font-size: 12px; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bad { color: var(--bad); font-weight: 600; }
.empty { color: var(--muted); text-align: center; padding: 30px; }
.hint { color: var(--muted); margin-top: 14px; font-size: 13px; }

.score {
  display: inline-block; min-width: 26px; text-align: center;
  padding: 2px 6px; border-radius: 5px; font-weight: 700; font-size: 12px;
  background: var(--panel2); color: var(--muted);
}
.score.s1 { background: rgba(255, 176, 32, .15); color: var(--warn); }
.score.s2 { background: rgba(255, 92, 104, .15); color: var(--bad); }
.score.s3 { background: var(--bad); color: #fff; }

/* ---- плеер ---- */
.player-body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }
.stage-wrap { flex: 1; overflow: auto; background: #06070a; padding: 12px; }
.stage { background: #fff; width: fit-content; }
.stage iframe { border: 0; background: #fff; }

.controls {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-top: 1px solid var(--line);
}
.clock { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; min-width: 96px; }
.scrub { flex: 1; accent-color: var(--accent); }
.chk { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 5px; }

.timeline-wrap { background: var(--panel); padding: 0 16px 10px; }
.timeline { position: relative; height: 16px; background: var(--panel2); border-radius: 4px; }
.timeline .m { position: absolute; top: 3px; width: 2px; height: 10px; border-radius: 1px; }
.timeline .m.click { background: var(--accent); }
.timeline .m.page { background: var(--ok); height: 14px; top: 1px; width: 3px; }
.timeline .m.snapshot { background: var(--warn); opacity: .5; }
.timeline .m.rage { background: var(--bad); height: 16px; top: 0; width: 3px; }
.timeline .m.err { background: #ff8a00; height: 16px; top: 0; width: 3px; }

/* ---- демо ---- */
.demo { max-width: 860px; margin: 0 auto; padding: 24px 20px 80px; }
.demo h1 { font-size: 24px; margin: 0 0 8px; }
.lead { color: var(--muted); margin-bottom: 24px; }
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 16px 18px; margin-bottom: 16px;
}
.card h2 { font-size: 15px; margin: 0 0 12px; color: var(--accent); }
.row { margin-bottom: 10px; }
.row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); font-size: 12px; }
.secret { background: #241a1a; border: 1px dashed #4a2f2f; border-radius: 8px; padding: 10px 14px; margin-bottom: 10px; }
.tall { min-height: 200px; }

/* =========================================================================
   Шапка кабинета: вкладки, выбор сайта, бренд клиента
   ========================================================================= */
.brand { display: flex; align-items: center; gap: 8px; }
.brand-logo { height: 22px; width: auto; border-radius: 4px; }
.tabs { display: flex; gap: 2px; }
.tab {
  padding: 6px 12px; border-radius: 6px; color: var(--muted);
  text-decoration: none; font-size: 13px; white-space: nowrap;
}
.tab:hover { background: var(--panel2); text-decoration: none; color: var(--fg); }
.tab.on { background: var(--accent); color: #fff; }
.who { color: var(--muted); font-size: 12px; }
.sel.wide { max-width: 420px; }
.empty-note { margin: 30px auto; max-width: 620px; text-align: center; color: var(--muted); }

.page { padding: 16px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button {
  background: var(--panel2); color: var(--muted); border: 0; border-right: 1px solid var(--line);
  padding: 6px 11px; cursor: pointer; font: inherit; font-size: 13px;
}
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent); color: #fff; }
.btn.tiny { padding: 3px 8px; font-size: 12px; }
.note { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.hidden { display: none !important; }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 14px 16px; margin-bottom: 14px;
}
.panel h2 { font-size: 14px; margin: 0 0 10px; color: var(--accent); }
.panel .row { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 6px; font-size: 13px; }
.panel .row span { color: var(--muted); }

/* =========================================================================
   Карточки рекомендаций
   ========================================================================= */
.finding {
  background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--muted);
  border-radius: 8px; padding: 11px 14px; margin-bottom: 10px;
}
.finding.sev-high { border-left-color: var(--bad); }
.finding.sev-med { border-left-color: var(--warn); }
.finding.sev-low { border-left-color: var(--muted); }
.finding-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.finding h3 { font-size: 14px; margin: 0; font-weight: 600; flex: 1 1 220px; }
.finding .sev {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  padding: 2px 6px; border-radius: 4px; background: var(--panel2); color: var(--muted);
}
.finding.sev-high .sev { background: rgba(255,92,104,.16); color: var(--bad); }
.finding.sev-med .sev { background: rgba(255,176,32,.16); color: var(--warn); }
.finding .area { font-size: 11px; color: var(--muted); }
.finding .evidence {
  font-size: 12px; color: var(--fg); background: var(--panel2);
  padding: 5px 8px; border-radius: 5px; margin: 8px 0; font-variant-numeric: tabular-nums;
}
.finding p { margin: 6px 0 0; font-size: 12.5px; color: var(--muted); }
.finding p b { color: var(--fg); font-weight: 600; }
.finding .goto { margin-top: 9px; }
.summary-line {
  background: var(--panel2); border-radius: 8px; padding: 11px 14px;
  margin-bottom: 14px; font-size: 13.5px; border-left: 3px solid var(--accent);
}

/* =========================================================================
   Тепловые карты
   ========================================================================= */
.hm-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.hm-stage-wrap { overflow: hidden; background: #06070a; border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.hm-stage { position: relative; background: #fff; }
.hm-snapshot { position: absolute; inset: 0; }
.hm-snapshot iframe { border: 0; width: 100%; }
.hm-canvas { position: absolute; inset: 0; pointer-events: none; }
.hm-side .panel { margin-bottom: 12px; }

.el-list { max-height: 340px; overflow: auto; }
.el { position: relative; display: flex; align-items: center; gap: 8px; padding: 5px 7px; border-radius: 5px; margin-bottom: 3px; overflow: hidden; }
.el-bar { position: absolute; inset: 0 auto 0 0; background: rgba(79,140,255,.14); border-radius: 5px; }
.el-txt { position: relative; flex: 1; min-width: 0; font-size: 12px; }
.el-txt b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.el-txt .dim { display: block; color: var(--muted); font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.el-num { position: relative; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 12px; white-space: nowrap; }
.dim { color: var(--muted); font-weight: 400; }
.scroll-stats .row { font-variant-numeric: tabular-nums; }

/* =========================================================================
   Формы
   ========================================================================= */
.form-grid { width: 100%; border-collapse: collapse; font-size: 13px; }
.form-grid th { text-align: left; color: var(--muted); font-weight: 500; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.form-grid td { padding: 8px 10px; border-bottom: 1px solid #20242d; vertical-align: middle; }
.form-grid tr.killer td { background: rgba(255,92,104,.07); }
.form-grid tr:hover td { background: var(--panel); }
.bar { position: relative; height: 18px; background: var(--panel2); border-radius: 4px; min-width: 90px; overflow: hidden; }
.bar > i { position: absolute; inset: 0 auto 0 0; background: var(--ok); border-radius: 4px; }
.bar > i.mid { background: var(--warn); }
.bar > i.low { background: var(--bad); }
.bar > span { position: relative; display: block; text-align: center; font-size: 11px; line-height: 18px; font-variant-numeric: tabular-nums; }
.samples { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.samples code { font-size: 11.5px; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; background: var(--panel2); color: var(--muted); }
.pill.bad { background: rgba(255,92,104,.16); color: var(--bad); }

/* =========================================================================
   Воронки
   ========================================================================= */
.funnel { display: flex; gap: 6px; align-items: flex-end; min-height: 190px; margin: 18px 0 8px; }
.fstep { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 6px; min-width: 0; }
.fbar { width: 100%; background: var(--accent); border-radius: 6px 6px 0 0; min-height: 4px; }
.fbar.worst { background: var(--bad); }
.fstep .fname { font-size: 12px; text-align: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; width: 100%; }
.fstep .fnum { font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; }
.fstep .fpct { font-size: 11px; color: var(--muted); }
.fdrop { color: var(--bad); font-size: 11px; }
.step-editor { display: flex; flex-direction: column; gap: 8px; }
.step-row { display: flex; gap: 6px; align-items: center; }
.step-row input { flex: 1; }
.step-row select { width: 120px; }

/* =========================================================================
   Настройки
   ========================================================================= */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 14px; align-items: start; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input[type="text"], .field input[type="color"], .field select { width: 100%; }
.field input[type="color"] { height: 34px; padding: 2px; }
.radio-card { display: block; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.radio-card.on { border-color: var(--accent); background: rgba(79,140,255,.07); }
.radio-card b { display: block; font-size: 13px; margin-bottom: 3px; }
.radio-card span { font-size: 12px; color: var(--muted); }
.warn-box { background: rgba(255,176,32,.08); border: 1px solid rgba(255,176,32,.3); border-radius: 8px; padding: 10px 12px; font-size: 12.5px; margin-bottom: 12px; }
.token-box { background: #241a1a; border: 1px dashed #4a2f2f; border-radius: 8px; padding: 10px 12px; margin: 10px 0; font-size: 12px; word-break: break-all; }

/* =========================================================================
   Панель рекомендаций в плеере
   ========================================================================= */
.insight-drawer {
  position: fixed; right: 0; top: 0; bottom: 0; width: 420px; max-width: 92vw;
  background: var(--panel); border-left: 1px solid var(--line);
  transform: translateX(100%); transition: transform .22s ease;
  display: flex; flex-direction: column; z-index: 50;
}
.insight-drawer.open { transform: translateX(0); }
.insight-drawer header { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.insight-drawer header h2 { font-size: 15px; margin: 0; flex: 1; }
.insight-body { overflow: auto; padding: 14px 16px; }
.insight-toast {
  position: fixed; right: 18px; bottom: 96px; z-index: 40;
  background: var(--panel); border: 1px solid var(--accent); border-radius: 10px;
  padding: 12px 14px; max-width: 340px; box-shadow: 0 10px 30px rgba(0,0,0,.45);
  animation: pop .25s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(10px); } }
.insight-toast h3 { margin: 0 0 6px; font-size: 13px; }
.insight-toast p { margin: 0 0 9px; font-size: 12.5px; color: var(--muted); }
.badge-count {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--bad); color: #fff; font-size: 11px; font-weight: 700; text-align: center;
}

/* =========================================================================
   Когорты: кривая ухода и срезы
   ========================================================================= */
.chart-wrap { width: 100%; overflow: hidden; }
.chart { width: 100%; height: auto; display: block; }
.chart .g { stroke: #2a2f3a; stroke-width: 1; }
.chart .ax { fill: #8b93a5; font-size: 11px; font-family: inherit; }
.chart .ax.cliff { fill: #ff5c68; font-weight: 700; }

.legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; }
.lg { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.lg > i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }

.stat-row { display: flex; flex-wrap: wrap; gap: 22px; }
.stat-row > div { display: flex; flex-direction: column; gap: 2px; }
.stat-row b { font-size: 17px; font-variant-numeric: tabular-nums; }
.stat-row .dim { font-size: 11.5px; }

.filter-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 10px 14px; margin-bottom: 10px;
}
.pair { display: flex; gap: 6px; }
.pair input { width: 100%; min-width: 0; }

/* =========================================================================
   Пояснения по наведению: интерфейс объясняет себя сам
   ========================================================================= */
[data-hint], [data-hint-text] { cursor: help; }
[data-hint]:hover, [data-hint-text]:hover { color: var(--fg); }
.hint-q {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 50%; margin-left: 4px;
  background: var(--panel2); color: var(--muted);
  font-size: 10px; font-weight: 700; line-height: 1; cursor: help;
  border: 1px solid var(--line); vertical-align: middle;
}
.hint-q:hover, .hint-q:focus { background: var(--accent); color: #fff; border-color: var(--accent); outline: none; }

.hint-pop {
  position: fixed; z-index: 1000; max-width: 380px;
  background: #0b0d11; border: 1px solid var(--accent); border-radius: 10px;
  padding: 12px 14px; box-shadow: 0 14px 40px rgba(0, 0, 0, .6);
  opacity: 0; visibility: hidden; transform: translateY(-4px);
  transition: opacity .12s ease, transform .12s ease;
  pointer-events: none; font-size: 12.5px; line-height: 1.55;
}
.hint-pop.on { opacity: 1; visibility: visible; transform: translateY(0); }
.hint-pop b { display: block; font-size: 13.5px; margin-bottom: 5px; color: var(--accent); }
.hint-pop p { margin: 0 0 7px; color: var(--fg); }
.hint-pop p:last-child { margin-bottom: 0; }
.hint-pop .lbl {
  display: inline-block; font-size: 10px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); margin-right: 5px;
}
.hint-pop .nb { color: var(--warn); font-size: 12px; }

/* =========================================================================
   Обводка элементов на тепловой карте
   ========================================================================= */
.hm-els { position: absolute; inset: 0; pointer-events: none; }
.el-box {
  position: absolute; border: 2px solid; border-radius: 4px;
  pointer-events: auto; cursor: help;
}
.el-box:hover { z-index: 5; border-width: 3px; }
.el-badge {
  position: absolute; top: -11px; left: -2px;
  padding: 1px 6px; border-radius: 4px; color: #fff;
  font-size: 11px; font-weight: 700; white-space: nowrap;
  font-variant-numeric: tabular-nums; box-shadow: 0 1px 4px rgba(0, 0, 0, .4);
}

/* =========================================================================
   Формы: опознание, вырезка, показ на странице
   ========================================================================= */
.form-head { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 900px) { .form-head { grid-template-columns: 1fr; } }
.form-id { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 12px; }
.form-id code { font-size: 11px; color: var(--muted); }

.cutout {
  position: relative; overflow: hidden; background: #fff;
  border: 1px solid var(--line); border-radius: 8px; min-height: 60px;
}
.cutout-inner { position: absolute; left: 0; top: 0; }
.cutout-inner iframe { border: 0; }
.form-preview .btn { margin-top: 10px; }

.modal {
  position: fixed; inset: 24px; z-index: 200;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  display: flex; flex-direction: column; box-shadow: 0 20px 70px rgba(0, 0, 0, .7);
}
.modal-head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.modal-body { flex: 1; overflow: auto; padding: 12px; background: #06070a; position: relative; }
.modal-body iframe { border: 0; background: #fff; }
.form-mark {
  position: absolute; border: 3px solid var(--bad); border-radius: 6px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, .55); pointer-events: none;
}
.form-mark > span {
  position: absolute; top: -13px; left: -3px; background: var(--bad); color: #fff;
  font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 4px; white-space: nowrap;
}

/* =========================================================================
   Управление сайтами
   ========================================================================= */
.add-site { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin: 14px 0 8px; }
.add-site input { flex: 1; min-width: 200px; }
textarea.snip {
  width: 100%; font-family: ui-monospace, Consolas, monospace; font-size: 11px;
  line-height: 1.45; resize: vertical; margin-bottom: 6px;
}
#sitesTable td { vertical-align: top; }
#sitesTable .pill { margin-bottom: 3px; }
.steps { margin: 0 0 10px; padding-left: 20px; font-size: 13px; color: var(--fg); }
.steps li { margin-bottom: 6px; }

/* Цели: заметная, но не кричащая отметка */
.pill.goal-pill { background: rgba(62,207,142,.18); color: var(--ok); font-weight: 700; }
.timeline .m.goal { background: var(--ok); height: 16px; top: 0; width: 4px; border-radius: 2px; }
