:root {
  --bg: #0A0C10;
  --surface: #11141B;
  --surface-2: #171B24;
  --surface-hover: #1C212C;
  --glass: rgba(22,24,34,0.72);

  --border: rgba(255,255,255,.06);
  --border-strong: rgba(255,255,255,.10);
  --border-accent: rgba(91,140,255,.40);
  --ring: rgba(91,140,255,.45);

  --text: #EAECF2;
  --text-2: #9BA1B0;
  --text-3: #5C6270;

  --accent: #5B8CFF;
  --accent-hi: #82A4FF;
  --accent-soft: rgba(91,140,255,.12);
  --accent-glow: rgba(91,140,255,.35);

  --ok: #34D399;  --ok-soft: rgba(52,211,153,.14);
  --bad: #FB7185; --bad-soft: rgba(251,113,133,.14);
  --warn: #FBBF24; --warn-soft: rgba(251,191,36,.14);

  --gold: #FBBF24; --silver: #CBD5E1; --bronze: #D08C5A;

  --grad-page: radial-gradient(1100px 560px at 72% -12%, rgba(91,140,255,.10), transparent 60%);
  --grad-accent: linear-gradient(135deg, #5B8CFF 0%, #82A4FF 100%);
  --shadow-card: 0 1px 0 rgba(255,255,255,.03) inset, 0 8px 24px rgba(0,0,0,.35);

  --r-card: 12px; --r-sm: 8px; --r-chip: 6px; --r-pill: 999px;

  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--grad-page), var(--bg); color: var(--text);
  font: 14px/1.5 var(--font); min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
.num, .mono { font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum"; letter-spacing: -0.01em; }
.hidden { display: none !important; }
.muted { color: var(--text-2); }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 4px; color: var(--accent); font-family: var(--mono); font-size: 12px; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50; height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; background: rgba(13,15,20,.8); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand-logo { width: 28px; height: 28px; border-radius: 7px; }
.brand-name { font-size: 15px; font-weight: 600; }
.brand-badge { font-size: 10px; font-weight: 600; padding: 2px 7px; border-radius: var(--r-pill);
  background: var(--accent-soft); color: var(--accent-hi); letter-spacing: .03em; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.freshness { font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.freshness::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 0 var(--ok-soft); animation: pulse 2.4s infinite; }
@keyframes pulse { 0%{box-shadow:0 0 0 0 rgba(52,211,153,.4)} 70%{box-shadow:0 0 0 7px rgba(52,211,153,0)} 100%{box-shadow:0 0 0 0 rgba(52,211,153,0)} }
.user-chip { width: 30px; height: 30px; border-radius: 50%; background: var(--accent-soft);
  color: var(--accent-hi); display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; }

main { max-width: 1240px; margin: 0 auto; padding: 28px; }
h2 { font-size: 22px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 18px; }
h3 { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-2); margin: 0 0 14px; }
h3 .hint { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--text-3); font-size: 11px; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
  padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow-card);
}
.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
/* minmax(0,1fr) + min-width:0 on children — otherwise a wide child (the 24-col
   heatmap, a chart canvas) forces its track past the viewport and the page gets
   a horizontal scroll on mobile. */
.two-col { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); gap: 16px; }
.two-col > * { min-width: 0; }
@media (max-width: 820px) { .two-col { grid-template-columns: minmax(0,1fr); } main { padding: 16px; } }

.insight {
  font-size: 13px; color: var(--text); background: var(--accent-soft);
  border: 1px solid var(--border-accent); border-radius: var(--r-sm);
  padding: 10px 14px; margin-top: 12px; line-height: 1.45;
}
.insight::before { content: "💡 "; }
.insight:empty { display: none; }

/* ---------- login ---------- */
.login-wrap { min-height: 70vh; display: flex; align-items: center; justify-content: center;
  background-image: url(/static/img/hero.png); background-size: cover; background-position: center;
  border-radius: 16px; position: relative; overflow: hidden; }
.login-wrap::after { content: ""; position: absolute; inset: 0;
  background: radial-gradient(circle at center, rgba(10,12,16,.55), rgba(10,12,16,.9)); }
.login-card { position: relative; z-index: 1; max-width: 420px; text-align: center;
  background: var(--glass); backdrop-filter: blur(14px); }
.login-logo { width: 44px; height: 44px; border-radius: 10px; margin-bottom: 14px; }
.login-status { margin-top: 12px; font-size: 13px; }
.login-status.err { color: var(--bad); }

/* ---------- portfolio (channels list) ---------- */
.portfolio-kpis { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.pk { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 12px 16px; min-width: 130px; }
.pk .pk-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); }
.pk .pk-val { font-size: 24px; font-weight: 700; margin-top: 3px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px,1fr)); gap: 16px; }
.channel-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card);
  padding: 16px; cursor: pointer; text-decoration: none; color: var(--text);
  transition: border-color .15s, box-shadow .15s, transform .15s;
  animation: cardin .35s both; }
@keyframes cardin { from { opacity: 0; transform: translateY(8px);} to {opacity:1;transform:none;} }
.channel-card:hover { border-color: var(--border-accent); box-shadow: 0 0 0 1px var(--border-accent), 0 8px 30px var(--accent-glow); transform: translateY(-2px); }
.channel-card .title { font-size: 16px; font-weight: 600; }
.channel-card .id { color: var(--text-3); font-size: 11px; font-family: var(--mono); margin-top: 2px; }
.channel-card .welcome { color: var(--accent-hi); font-size: 12px; margin-top: 6px; }
.channel-card .cc-stats { display: flex; gap: 16px; margin-top: 12px; }
.channel-card .cc-stat { font-size: 11px; color: var(--text-2); }
.channel-card .cc-stat b { display: block; font-size: 20px; font-weight: 650; font-family: var(--mono); }
.cc-stat.ok b { color: var(--ok); } .cc-stat.bad b { color: var(--bad); }
.channel-card .cc-spark { margin-top: 10px; height: 30px; }

/* ---------- channel sub-header / tabs ---------- */
.sub-header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.back { color: var(--text-2); text-decoration: none; font-size: 18px; line-height: 1;
  padding: 6px 10px; border: 1px solid var(--border); border-radius: var(--r-sm); }
.back:hover { color: var(--accent); border-color: var(--border-accent); }
.channel-select {
  flex: 1; min-width: 150px; max-width: 360px;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  border-radius: var(--r-sm); padding: 8px 12px; font: 600 16px var(--font);
  cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239BA1B0' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 30px;
}
.channel-select:hover { border-color: var(--border-accent); }
.channel-select:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.sub-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
@media (max-width: 700px) {
  .sub-header { gap: 8px; }
  .channel-select { flex: 1 1 auto; max-width: none; order: 1; }
  .back { order: 0; }
  .sub-actions { order: 2; width: 100%; justify-content: space-between; }
}
.period-seg { position: relative; display: flex; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-pill); padding: 3px; }
.period-seg .seg { position: relative; z-index: 1; border: none; background: none; color: var(--text-2);
  font: 500 13px var(--font); padding: 5px 13px; border-radius: var(--r-pill); cursor: pointer; transition: color .2s; }
.period-seg .seg.active { color: #fff; }
.seg-slider { position: absolute; top: 3px; bottom: 3px; border-radius: var(--r-pill);
  background: var(--grad-accent); transition: left .25s cubic-bezier(.2,.8,.2,1), width .25s; z-index: 0; }
.btn-ghost { background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  padding: 6px 14px; border-radius: var(--r-sm); text-decoration: none; font-size: 13px; cursor: pointer; }
.btn-ghost:hover { border-color: var(--border-strong); }
.daterange { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
  padding: 10px 14px; margin-bottom: 14px; }
.daterange label { font-size: 13px; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
.daterange input[type=date] { background: var(--surface-2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--r-sm); padding: 6px 10px; font: 13px var(--font); color-scheme: dark; }
.btn-apply { background: var(--grad-accent); color: #fff; border: none; cursor: pointer;
  padding: 7px 16px; border-radius: var(--r-sm); font: 600 13px var(--font); }
.range-label { font-size: 12px; color: var(--accent-hi); font-family: var(--mono); }

.tabs { position: relative; display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tab { position: relative; background: none; border: none; color: var(--text-2);
  font: 500 14px var(--font); padding: 10px 16px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); font-weight: 600; }
.tab-slider { position: absolute; bottom: -1px; height: 2px; background: var(--grad-accent);
  transition: left .2s, width .2s; }
/* On phones the 4 tabs don't fit one row → let the strip scroll horizontally
   (instead of pushing the whole page wider) and tighten the padding a touch. */
@media (max-width: 820px) {
  .tabs { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: 0 0 auto; padding: 10px 11px; font-size: 13px; }
}
.tab-pane { animation: fadein .15s; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ---------- KPI row ---------- */
/* minmax(0,1fr) (не plain 1fr): иначе трек не сжимается ниже min-content
   карточки → на узких экранах колонки раздуваются (~334px) и весь дашборд
   уходит в горизонтальный скролл с обрезанными KPI. */
.kpi-row { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 14px; margin-bottom: 16px; }
@media (max-width: 820px) { .kpi-row { grid-template-columns: repeat(2,minmax(0,1fr)); } }
.kpi { background: var(--glass); backdrop-filter: blur(14px); border: 1px solid var(--border);
  border-radius: var(--r-card); padding: 14px 16px; box-shadow: var(--shadow-card); min-width: 0; }
.kpi-top { display: flex; justify-content: space-between; align-items: center; }
.kpi-label { font-size: 11px; font-weight: 500; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); }
.kpi-val { font-size: 32px; font-weight: 700; line-height: 1; margin: 8px 0 2px; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.kpi.ok .kpi-val { color: var(--ok); } .kpi.bad .kpi-val { color: var(--bad); }
.kpi-spark { height: 36px; margin-top: 6px; }
.delta { font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: var(--r-pill); font-family: var(--mono); }
.delta.up { background: var(--ok-soft); color: var(--ok); }
.delta.down { background: var(--bad-soft); color: var(--bad); }

/* ---------- hero funnel ---------- */
.funnel { display: flex; align-items: stretch; gap: 0; margin: 6px 0 4px; }
.funnel-step { background: var(--accent-soft); border: 1px solid var(--border-accent);
  border-radius: var(--r-sm); padding: 14px 16px; min-width: 22%; display: flex; flex-direction: column; justify-content: center;
  transition: width .6s cubic-bezier(.2,.8,.2,1); }
.funnel-step .fs-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); }
.funnel-step .fs-val { font-size: 28px; font-weight: 700; font-family: var(--mono); margin-top: 4px; }
.funnel-conn { display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 0 12px; min-width: 80px; }
.funnel-conn .fc-pct { font-size: 14px; font-weight: 600; font-family: var(--mono); color: var(--accent-hi); }
.funnel-conn .fc-leak { font-size: 11px; color: var(--bad); font-family: var(--mono); margin-top: 2px; }
.funnel-summary { font-size: 14px; margin-top: 12px; }
.funnel-summary b { font-size: 26px; font-weight: 700; font-family: var(--mono); color: var(--accent-hi); }
@media (max-width: 640px) { .funnel { flex-direction: column; } .funnel-conn { flex-direction: row; gap: 8px; padding: 6px 0; } }

/* ---------- growth ---------- */
.growth-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 8px; }
.growth-value { font-size: 40px; font-weight: 700; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.chart-wrap { position: relative; height: 200px; }
.chart-wrap.tall { height: 240px; }

/* ---------- heatmap ---------- */
/* minmax(0,1fr): .hm-cell has an implied min-width (min-height:12 + aspect-ratio:1),
   so plain 1fr keeps each of the 24 columns ≥~15px → the grid stays ~460px wide and
   spills past its card on phones. minmax(0,…) lets the cells shrink to fit. */
.heatmap { display: grid; grid-template-columns: 28px repeat(24, minmax(0,1fr)); gap: 3px; }
.hm-cell { aspect-ratio: 1; border-radius: 3px; background: var(--surface-2); min-height: 12px; }
.hm-daylabel { font-size: 10px; color: var(--text-3); display: flex; align-items: center; }
.hm-hourlabel { font-size: 9px; color: var(--text-3); text-align: center; }
.heatmap-legend { display: flex; align-items: center; gap: 8px; justify-content: flex-end; margin-top: 10px; font-size: 11px; color: var(--text-3); }
.hm-scale { width: 90px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #11141B, #1E3A5F, #2E5BA8, #5B8CFF); }

/* ---------- churn ---------- */
.churn-bar { display: flex; height: 22px; border-radius: var(--r-sm); overflow: hidden; background: var(--surface-2); }
.churn-seg { transition: width .5s; }
.churn-seg.s1 { background: var(--bad); } .churn-seg.s2 { background: var(--warn); } .churn-seg.s3 { background: var(--ok); }
.churn-chips { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.chip { font-size: 12px; padding: 5px 10px; border-radius: var(--r-chip); background: var(--surface-2); color: var(--text-2); }
.chip b { color: var(--text); font-family: var(--mono); }
.chip.c1 { border-left: 3px solid var(--bad); } .chip.c2 { border-left: 3px solid var(--warn); } .chip.c3 { border-left: 3px solid var(--ok); }

/* ---------- leaderboard ---------- */
.sources-layout { grid-template-columns: 1.4fr 1fr; }
/* override AFTER the rule above (equal specificity → source order wins) so the
   sources tab collapses to one column on mobile instead of staying 2-col. */
@media (max-width: 820px) { .sources-layout { grid-template-columns: 1fr; } }
.lb-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.lb-rank { width: 26px; text-align: center; font-weight: 700; font-size: 14px; font-family: var(--mono); color: var(--text-3); }
.lb-rank.r1 { color: var(--gold); } .lb-rank.r2 { color: var(--silver); } .lb-rank.r3 { color: var(--bronze); }
.lb-main { flex: 1; min-width: 0; }
.lb-label { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-bar { height: 6px; border-radius: 3px; background: var(--surface-2); margin-top: 5px; overflow: hidden; }
.lb-bar > div { height: 100%; background: var(--accent); border-radius: 3px; transition: width .5s; }
.lb-joins { font-family: var(--mono); font-weight: 700; font-size: 15px; min-width: 36px; text-align: right; }
.ret-chip { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: var(--r-pill); min-width: 44px; text-align: center; font-family: var(--mono); }
.ret-chip.hi { background: var(--ok-soft); color: var(--ok); }
.ret-chip.mid { background: var(--warn-soft); color: var(--warn); }
.ret-chip.lo { background: var(--bad-soft); color: var(--bad); }
.donut-wrap { position: relative; height: 240px; }
.donut-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; pointer-events: none; }
.donut-center .dc-val { font-size: 28px; font-weight: 700; font-family: var(--mono); }
.donut-center .dc-label { font-size: 11px; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; }

/* ---------- links ---------- */
.budget-card .budget-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.budget-row label { font-size: 13px; color: var(--text-2); }
input[type=number], input[type=search] { background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--r-sm); color: var(--text); padding: 8px 12px; font: 14px var(--font); }
input:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); border-color: var(--border-accent); }
.cpf-out { font-size: 18px; font-weight: 700; font-family: var(--mono); color: var(--accent-hi); }
.link-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); padding: 14px 16px; margin-bottom: 12px; }
.link-card .lc-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.link-card .lc-label { font-size: 14px; font-weight: 600; }
.lc-funnel { display: flex; align-items: center; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.lc-step { font-size: 12px; color: var(--text-2); }
.lc-step b { display: block; font-size: 17px; font-weight: 700; font-family: var(--mono); color: var(--text); }
.lc-arrow { font-size: 11px; color: var(--accent-hi); font-family: var(--mono); }
.lc-conv { font-size: 12px; font-weight: 700; font-family: var(--mono); padding: 3px 9px; border-radius: var(--r-pill); }
.lc-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.utm-chip { font-size: 11px; padding: 2px 7px; border-radius: var(--r-chip); background: var(--surface-2); color: var(--text-2); font-family: var(--mono); }
.copy-link { font-size: 11px; padding: 3px 9px; border-radius: var(--r-chip); background: var(--surface-2);
  color: var(--accent-hi); font-family: var(--mono); cursor: pointer; border: 1px solid var(--border);
  max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.copy-link:hover { border-color: var(--border-accent); }
.cpf-cell { font-family: var(--mono); font-weight: 700; }
.cpf-cell.cheap { color: var(--ok); }

/* ---------- subscribers ---------- */
.search { min-width: 200px; }
.sub-row { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.sub-av { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 600; flex-shrink: 0; }
.sub-name { flex: 1; min-width: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub-src { font-size: 11px; color: var(--text-2); }
.sub-time { font-size: 12px; color: var(--text-3); font-family: var(--mono); white-space: nowrap; }
.sub-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sub-dot.on { background: var(--ok); } .sub-dot.off { background: var(--text-3); }

/* ---------- skeleton ---------- */
.skel { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-hover) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: var(--r-sm); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- toast / empty ---------- */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface-2); border: 1px solid var(--ok); color: var(--ok); padding: 10px 18px;
  border-radius: var(--r-pill); font-size: 13px; opacity: 0; transition: .25s; z-index: 100; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.empty { text-align: center; color: var(--text-2); padding: 28px 0; }
.empty img { width: 200px; height: auto; opacity: .85; margin-bottom: 8px; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001s !important; transition-duration: .001s !important; }
}
