:root {
  --bg: #17171a;
  --panel: #222226;
  --panel-2: #2a2a2f;
  --border: #36363d;
  --text: #ececf1;
  --muted: #9a9aa6;
  --accent: #5b4bff;
  --accent-soft: rgba(91, 75, 255, 0.18);
  --up: #3ecf8e;
  --down: #ff6b6b;
  --warn: #f5b942;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
img { display: block; }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: #1d1d21;
  border-right: 1px solid var(--border);
  padding: 18px 12px;
  display: flex; flex-direction: column; gap: 4px;
  position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; font-size: 16px; padding: 4px 10px 16px; }
.brand span { color: var(--accent); }
.nav a {
  display: block; padding: 9px 12px; border-radius: 8px; text-decoration: none; color: var(--muted);
}
.nav a:hover { background: var(--panel); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--text); }
.sidebar-foot { margin-top: auto; font-size: 12px; color: var(--muted); padding: 10px; display: grid; gap: 8px; }
.quota-bar { height: 6px; border-radius: 3px; background: var(--panel-2); overflow: hidden; }
.quota-bar i { display: block; height: 100%; background: var(--accent); }

main { padding: 24px 28px 60px; min-width: 0; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 20px; }

.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-bottom: 16px;
}
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 200px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ---------- controls ---------- */
.btn {
  border: 1px solid var(--border); background: var(--panel-2); border-radius: 8px;
  padding: 8px 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: #4a4a54; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.ghost { background: transparent; }
.btn.danger:hover { border-color: var(--down); color: var(--down); }
.btn:disabled { opacity: .5; cursor: default; }

input[type=text], input[type=password], input[type=number], select {
  background: #151518; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 17px; height: 17px; margin: 0; flex: none; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--panel-2);
  border-radius: 8px; padding: 6px 10px;
}
.chip select { border: 0; background: transparent; padding: 0; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); }
.tag { display: inline-block; background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 1px 7px; font-size: 12px; margin: 2px 4px 2px 0; }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 6px 12px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--accent-soft); color: var(--text); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 12px; white-space: nowrap; user-select: none; }
th.sortable { cursor: pointer; }
th.sortable:hover { color: var(--text); }
tr.click { cursor: pointer; }
tr.click:hover td { background: #26262b; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.ch { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.ava { width: 36px; height: 36px; border-radius: 50%; background: var(--panel-2); flex: none; object-fit: cover; }
.ava.lg { width: 64px; height: 64px; }
.thumb { width: 160px; aspect-ratio: 16/9; border-radius: 8px; object-fit: cover; background: var(--panel-2); flex: none; }
.thumb.sm { width: 96px; }
.title-cell { font-weight: 500; }
.delta { font-size: 12px; }
.up { color: var(--up); }
.down { color: var(--down); }
.mult { display: inline-block; padding: 1px 7px; border-radius: 6px; font-weight: 600; font-size: 12px; background: var(--panel-2); }
.mult.hot { background: rgba(62, 207, 142, .18); color: var(--up); }
.mult.cold { background: rgba(255, 107, 107, .14); color: var(--down); }
.pending { color: var(--muted); font-size: 12px; font-style: italic; }

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.card .label { color: var(--muted); font-size: 12px; }
.card .value { font-size: 22px; font-weight: 650; margin: 2px 0; font-variant-numeric: tabular-nums; }

.chart-box { position: relative; height: 280px; }

/* ---------- search ---------- */
.results { display: grid; gap: 10px; }
.result {
  display: grid; grid-template-columns: 160px 1fr auto; gap: 14px; background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 12px;
}
.result .meta { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--muted); font-size: 13px; margin-top: 6px; }
.result .meta b { color: var(--text); font-weight: 600; }
.result .actions { display: flex; flex-direction: column; gap: 6px; }
.result h3 { margin: 0; font-size: 15px; font-weight: 550; }
.result h3 a { text-decoration: none; }
.result h3 a:hover { text-decoration: underline; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.filters h4 { margin: 0 0 10px; font-size: 13px; letter-spacing: .04em; text-transform: uppercase; }
.check { display: flex; gap: 10px; align-items: center; padding: 5px 0; cursor: pointer; }
.range { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-top: 10px; }
.range .rlabel { margin-bottom: 6px; }
.range .rrow { display: grid; grid-template-columns: auto 30px 1fr; align-items: center; gap: 8px; margin: 4px 0; }
.range input[type=number] { width: 100%; }
details summary { cursor: pointer; font-weight: 600; font-size: 16px; }
details[open] summary { margin-bottom: 14px; }

.score { display: inline-block; width: 60px; height: 6px; background: var(--panel-2); border-radius: 3px; overflow: hidden; vertical-align: middle; margin-right: 6px; }
.score i { display: block; height: 100%; background: var(--accent); }

.banner { border: 1px solid var(--warn); background: rgba(245, 185, 66, .08); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }
.error { color: var(--down); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; right: 20px; bottom: 20px; background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 16px; max-width: 380px; z-index: 50; box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.toast.err { border-color: var(--down); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 360px; display: grid; gap: 12px; }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; }
  .brand { padding: 0 12px 0 0; }
  .nav { display: flex; flex-wrap: wrap; gap: 4px; }
  .sidebar-foot { display: none; }
  main { padding: 16px 16px 40px; }
  .filters { grid-template-columns: 1fr; }
  .result { grid-template-columns: 1fr; }
  .result .thumb { width: 100%; }
  .result .actions { flex-direction: row; flex-wrap: wrap; }
}

/* ---------- channel page (profile + analytics) ---------- */
.ch-layout { display: grid; grid-template-columns: 270px 1fr; gap: 16px; align-items: start; }
.ch-layout aside { position: sticky; top: 16px; }
.profile { text-align: center; }
.profile h1 { font-size: 18px; margin: 10px 0 2px; }
.ava.xl { width: 84px; height: 84px; margin: 0 auto; }
.pstats { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--panel-2); border-radius: 8px; margin-top: 12px; overflow: hidden; }
.pstats.two { grid-template-columns: 1fr 1fr; margin-top: 8px; }
.pstat { padding: 9px 4px; }
.pstat + .pstat { border-left: 1px solid var(--border); }
.pv { font-weight: 650; font-size: 15px; }
.pl { color: var(--muted); font-size: 11px; }
.pactions { display: grid; gap: 8px; margin-top: 14px; }
.pactions .btn { text-align: center; text-decoration: none; }
.cards.three { grid-template-columns: repeat(3, 1fr); }
.delta-card .value { font-size: 24px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.two-col > .panel { margin-bottom: 16px; min-width: 0; }
.chart-box.sm { height: 190px; }
.big { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.mid { font-size: 18px; font-weight: 650; font-variant-numeric: tabular-nums; }
.pub-stats { display: grid; gap: 12px; }
.seg button:disabled { opacity: .4; cursor: default; }

.heatmap-wrap { display: flex; gap: 6px; }
.hm-days { display: grid; grid-template-rows: repeat(7, 16px); gap: 4px; font-size: 10px; color: var(--muted); line-height: 16px; }
.heatmap { display: grid; grid-template-rows: repeat(7, 16px); grid-auto-flow: column; grid-auto-columns: 16px; gap: 4px; }
.heatmap i { border-radius: 4px; display: block; }
.hm.l0 { background: var(--panel-2); }
.hm.l1 { background: rgba(62, 207, 142, .45); }
.hm.l2 { background: rgba(62, 207, 142, .75); }
.hm.l3 { background: #3ecf8e; }

.vgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.vcard { text-decoration: none; display: grid; gap: 8px; align-content: start; }
.vcard:hover .vtitle { text-decoration: underline; }
.vthumb { position: relative; }
.vthumb .thumb { width: 100%; }
.vdur { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.8); border-radius: 4px; padding: 0 5px; font-size: 12px; }
.vtitle { font-weight: 550; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.thumbs-row { display: flex; gap: 4px; margin-top: 6px; }
.thumbs-row img { width: 72px; aspect-ratio: 16/9; object-fit: cover; border-radius: 4px; }
.sim-thumbs { display: flex; gap: 6px; }
.sim-thumbs a { display: block; flex: none; }
.sim-thumbs img { display: block; width: 168px; aspect-ratio: 16/9; object-fit: cover; border-radius: 6px; background: var(--panel-2); }
.sim-thumbs a:hover img { outline: 2px solid var(--accent); }
.sim-source { font-weight: 700; font-size: 15px; }
@media (max-width: 1800px) { .sim-thumbs img { width: 148px; } }
@media (max-width: 1500px) { .sim-thumbs img { width: 128px; } }

@media (max-width: 1100px) {
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .ch-layout { grid-template-columns: 1fr; }
  .ch-layout aside { position: static; }
  .cards.three { grid-template-columns: 1fr; }
}

/* ---------- similar channels: search history ---------- */
.hist-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }
.hist-item { display: flex; align-items: center; gap: 6px; border: 1px solid transparent; border-radius: 8px; }
.hist-item:hover { background: var(--panel-2); }
.hist-item.current { border-color: var(--accent); background: var(--accent-soft); }
.hist-item.hidden { display: none; }
.hist-link { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 8px 10px; text-decoration: none; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- settings & niche hunter ---------- */
.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field > span:first-child { font-weight: 500; }
.field input, .field select, .field textarea { width: 100%; }
textarea { background: #151518; border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; outline: none; font: inherit; color: inherit; resize: vertical; }
textarea:focus { border-color: var(--accent); }
.settings { max-width: 760px; }
.hunter-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 0 14px; margin-top: 4px; }
.hunter-grid .field span { font-size: 13px; }
.job-box { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-2); }
.job-box.error { border-color: var(--down); }
.inline-details { display: inline; }
.inline-details summary { display: inline; font-size: 12px; font-weight: 400; cursor: pointer; text-decoration: underline; }

.niche h3 { margin: 0; font-size: 17px; }
.niche-head { display: flex; gap: 14px; align-items: flex-start; }
.niche-head select { flex: none; }
.score-badge { flex: none; width: 52px; height: 52px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; font-weight: 700; background: var(--panel-2); border: 1px solid var(--border); cursor: help; }
.score-badge.mid { border-color: var(--warn); color: var(--warn); }
.score-badge.hi { border-color: var(--up); color: var(--up); background: rgba(62, 207, 142, .1); }
.stage { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; background: var(--panel-2); }
.st-emerging { background: rgba(91, 75, 255, .2); color: #a99fff; }
.st-growing { background: rgba(62, 207, 142, .16); color: var(--up); }
.st-single { background: rgba(154, 154, 166, .16); color: var(--muted); }
.st-peak { background: rgba(245, 185, 66, .16); color: var(--warn); }
.st-cooling { background: rgba(255, 107, 107, .14); color: var(--down); }
.st-predicted { background: rgba(76, 201, 240, .16); color: #4cc9f0; }
.st-season { background: rgba(199, 125, 255, .16); color: #c77dff; }
.niche-more { margin: 8px 0 4px; }
.niche-more summary { font-size: 13px; font-weight: 500; color: var(--muted); }
.niche-more[open] summary { margin-bottom: 6px; }
.niche-more > div { margin-bottom: 4px; }
.trend-line { display: flex; gap: 12px; align-items: center; margin-top: 8px; }
.spark { flex: none; background: var(--panel-2); border-radius: 6px; }
.niche-channels { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-top: 12px; }
.nch { text-decoration: none; min-width: 0; }
.nch .thumb { width: 100%; }
.nch:hover .ellipsis { text-decoration: underline; }
.ava.sm { width: 26px; height: 26px; }
.notes { min-height: 34px; }
@media (max-width: 860px) {
  .niche-head { flex-wrap: wrap; }
}

/* ---------- my channels ---------- */
.own-row td { background: var(--accent-soft); }
.mine h2 { font-size: 18px; }

/* ---------- similar: summary & evidence ---------- */
.sim-summary { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: var(--panel-2); display: grid; gap: 4px; }
.evidence { display: flex; flex-wrap: wrap; gap: 4px 10px; color: var(--muted); margin-top: 2px; }

.multi-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 0 16px; max-height: 260px; overflow: auto; }

/* ---------- fixed "← Назад" ---------- */
.back-fab {
  position: fixed; top: 14px; left: 248px; z-index: 40;
  padding: 10px 20px; font-size: 15px; font-weight: 600;
  border-radius: 10px; border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .45); cursor: pointer;
}
.back-fab:hover { border-color: var(--accent); background: #34343b; }
body.has-back main { padding-top: 72px; }
@media (max-width: 860px) {
  .back-fab { top: auto; bottom: 16px; left: 16px; }
  body.has-back main { padding-top: 16px; padding-bottom: 80px; }
}

.activity-note { margin-top: 8px; padding: 6px 8px; border-radius: 8px; background: rgba(245, 185, 66, .1); color: var(--warn); }

/* «Поиск видео»: saved searches as tabs on the left */
.search-layout { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 20px; align-items: start; }
.search-side { position: sticky; top: 16px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.side-new { justify-content: center; text-align: center; }
.side-head { font-weight: 600; font-size: 13px; padding: 6px 4px 0; border-top: 1px solid var(--border); padding-top: 12px; }
.side-list { overflow-y: auto; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.side-item { display: block; position: relative; padding: 8px 28px 8px 10px; border-radius: 8px; color: inherit; text-decoration: none; border: 1px solid transparent; }
.side-item:hover { background: var(--panel-2); }
.side-item.on { background: var(--accent-soft); border-color: var(--accent); }
.side-q { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-q .spinner { width: 12px; height: 12px; margin-right: 6px; vertical-align: -1px; }
.side-del { position: absolute; top: 6px; right: 4px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 6px; border-radius: 6px; opacity: 0; }
.side-item:hover .side-del, .side-del:focus { opacity: 1; }
.side-del:hover { color: var(--down); background: var(--panel); }
@media (max-width: 900px) {
  .search-layout { grid-template-columns: 1fr; }
  .search-side { position: static; max-height: none; }
  .side-list { max-height: 240px; }
  .side-del { opacity: 1; }
}

/* «Агент» */
.agent-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.agent-field { display: flex; flex-direction: column; gap: 4px; }
.agent-field input { width: 100%; }
.agent-card.voted-down { opacity: .55; }
