/* ============================================================
   LinkDesk — дизайн-система (Pimpstack dark, лаймовый бренд)
   App-shell: сайдбар (≥1080px) / топ-панель (мобайл), плотный десктоп.
   Тёмная тема: почти-чёрный фон, тёмные карточки с тонким бордером,
   лаймовый акцент (#c8ff3a), лаймовые pill-кнопки с чёрным текстом.
   Сетка отступов — 4px.
   ============================================================ */
:root {
  /* --- поверхности --- */
  --bg:        #0a0a0b;   /* страница — почти чёрный */
  --bg-2:      #101013;   /* инпуты / контролы / сайдбар (чуть темнее контента) */
  --surface:   #131316;   /* карточки / панели */
  --surface-2: #17171b;   /* hover строк */
  --surface-3: #202026;   /* активный сегмент / hover кнопки */

  /* --- границы --- */
  --line:      rgba(255, 255, 255, 0.08);
  --line-2:    rgba(255, 255, 255, 0.14);

  /* --- текст --- */
  --ink:       #f4f5f6;   /* белый основной */
  --ink-2:     rgba(255, 255, 255, 0.72);
  --ink-mute:  rgba(255, 255, 255, 0.55);

  /* --- акцент: лайм (график / активные состояния / ссылки) --- */
  --accent:      #c8ff3a;
  --accent-2:    #d6ff63;
  --accent-soft: rgba(200, 255, 58, 0.10);
  --accent-ink:  #0a0a0b;

  /* --- primary: лаймовые pill-кнопки (как «Book demo» на лендинге) --- */
  --primary:     #c8ff3a;
  --primary-2:   #d6ff63;
  --primary-ink: #0a0a0b;

  /* --- семантика --- */
  --ok:      #c8ff3a;   /* доход — лаймовый (как revenue на лендинге) */
  --ok-soft: rgba(200, 255, 58, 0.14);
  --ok-ink:  #0a0a0b;
  --warn:      #f5b342;
  --warn-soft: rgba(245, 179, 66, 0.16);
  --danger:      #ff5a5a;
  --danger-soft: rgba(255, 90, 90, 0.14);
  --neutral:      #9aa1ae;
  --neutral-soft: rgba(154, 161, 174, 0.16);

  /* --- полупрозрачные тинты facet-строк на тёмном --- */
  --facet-amber: rgba(200, 255, 58, 0.15);   /* модели — лайм */
  --facet-green: rgba(45, 212, 232, 0.13);   /* площадки — циан */
  --facet-pink:  rgba(244, 132, 177, 0.14);  /* рефереры — розовый */

  /* --- цвета площадок (для точек-тегов) --- */
  --p-ig:       #f06595;
  --p-tiktok:   #2dd4e8;
  --p-x:        #9aa3b2;
  --p-reddit:   #ff6a33;
  --p-telegram: #4aa8ec;
  --p-threads:  #a2acbb;
  --p-fanvue:   #c07be0;
  --p-of:       #4a9bf0;
  --p-other:    #9aa1a0;

  /* --- радиусы / тени --- */
  --r-sm: 8px; --r: 12px; --r-lg: 14px; --r-xl: 20px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-hero: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.55);
  --shadow-drawer: -16px 0 48px rgba(0, 0, 0, 0.55);
  --shadow-pop: 0 4px 12px rgba(0, 0, 0, 0.45), 0 12px 32px rgba(0, 0, 0, 0.6);
  --ring: 0 0 0 3px var(--accent-soft);

  --sidebar-w: 232px;
  --content-max: 1720px;
  --gutter: 24px;
  --z-toast: 90;
  --dur: 170ms;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: var(--font); font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  min-height: 100dvh;
}
body.no-scroll { overflow: hidden; }
.hidden { display: none !important; }
.muted { color: var(--ink-mute); }
.mono { font-family: var(--mono); font-size: 0.92em; letter-spacing: -0.01em; }
.num { font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
::selection { background: var(--accent-soft); }
* { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 8px; border: 3px solid transparent; background-clip: content-box; }

/* --- brand --- */
.brand { display: inline-flex; align-items: center; gap: 9px; font-weight: 650; font-size: 18px; letter-spacing: -0.02em; color: var(--ink); }
.brand-mark { display: inline-flex; color: var(--accent); }
.brand-mark .ico { width: 22px; height: 22px; }
.brand--lg { font-size: 28px; }
.brand--lg .ico { width: 30px; height: 30px; }
.ico { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ico--sm { width: 17px; height: 17px; }

/* ============================================================
   КНОПКИ / ПОЛЯ
   ============================================================ */
.btn {
  --bg-btn: var(--surface-2); --fg-btn: var(--ink);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--bg-btn); color: var(--fg-btn);
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  min-height: 40px; padding: 9px 15px; font: inherit; font-weight: 550; cursor: pointer;
  white-space: nowrap; user-select: none;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { box-shadow: var(--ring); outline: none; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn--primary { --bg-btn: var(--primary); --fg-btn: var(--primary-ink); border-color: transparent; border-radius: 999px; font-weight: 700; }
.btn--primary:hover { --bg-btn: var(--primary-2); box-shadow: 0 0 0 1px rgba(200, 255, 58, 0.35), 0 6px 22px rgba(200, 255, 58, 0.22); }
/* без border-radius: маленькие прямоугольные copy-кнопки не должны морфить форму
   на 1.6с фидбека «Скопировано»; primary-пилюли наследуют 999px от .btn--primary */
.btn--success { --bg-btn: var(--ok); --fg-btn: var(--ok-ink); border-color: transparent; font-weight: 700; }
.btn--primary.btn--success { border-radius: 999px; }
.btn--success:hover { background: var(--accent-2); box-shadow: 0 0 0 1px rgba(200, 255, 58, 0.35), 0 6px 22px rgba(200, 255, 58, 0.22); }
.btn--danger { --bg-btn: transparent; --fg-btn: var(--danger); border-color: color-mix(in oklch, var(--danger) 42%, transparent); }
.btn--danger:hover { --bg-btn: var(--danger-soft); border-color: var(--danger); }
.btn--ghost { --bg-btn: transparent; border-color: transparent; color: var(--ink-2); }
.btn--ghost:hover { --bg-btn: var(--surface-2); color: var(--ink); }
.btn--sm { min-height: 38px; padding: 7px 13px; font-size: 14px; }
.btn--lg { min-height: 50px; font-size: 16px; font-weight: 650; }
.btn--block { width: 100%; }
.btn.is-loading { color: transparent !important; pointer-events: none; position: relative; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid currentColor; border-top-color: transparent; color: var(--fg-btn);
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* иконочная кнопка (действия в строке таблицы / закрытие drawer) */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; flex: none; padding: 0; cursor: pointer;
  background: transparent; color: var(--ink-mute);
  border: 1px solid transparent; border-radius: var(--r-sm);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
.icon-btn:focus-visible { box-shadow: var(--ring); outline: none; color: var(--ink); }
.icon-btn.btn--success { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.icon-btn--danger:hover { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in oklch, var(--danger) 40%, transparent); }

.field { display: flex; flex-direction: column; gap: 7px; }
.field-label { font-size: 13.5px; font-weight: 550; color: var(--ink-2); }
input, textarea {
  background: var(--bg-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-sm); min-height: 46px; padding: 11px 14px; font: inherit; font-size: 16px; /* 16px — iOS не зумит */
  outline: none; width: 100%;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
input::placeholder { color: var(--ink-mute); }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: var(--ring); }
.form-error { color: var(--danger); font-size: 14px; min-height: 20px; font-weight: 500; }

/* select (фильтр/сортировка/редактор) */
.select {
  appearance: none; -webkit-appearance: none;
  background: var(--bg-2) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a94a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M6 9l6 6 6-6'/></svg>") no-repeat right 12px center / 16px;
  color: var(--ink); border: 1px solid var(--line); border-radius: var(--r-sm);
  min-height: 44px; padding: 10px 36px 10px 13px; font: inherit; font-size: 15px; width: 100%; cursor: pointer;
}
.select:focus { border-color: var(--accent); box-shadow: var(--ring); outline: none; }

/* ============================================================
   ЭКРАН ВХОДА
   ============================================================ */
.auth {
  min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 24px;
  background:
    radial-gradient(90% 60% at 50% 0%, var(--accent-soft), transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
}
.auth-card {
  width: min(400px, 100%); display: flex; flex-direction: column; gap: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 30px 26px; box-shadow: var(--shadow);
}
.auth-card .brand { align-self: flex-start; margin-bottom: 2px; }
.auth-title { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; margin: 6px 0 0; }
.auth-sub { color: var(--ink-mute); margin: 0 0 4px; font-size: 14.5px; }
.auth-foot { color: var(--ink-mute); font-size: 13px; text-align: center; max-width: 42ch; margin: 0; }

/* ============================================================
   APP SHELL — сайдбар + main; на десктопе grid из двух колонок
   ============================================================ */
.app { min-height: 100dvh; }
@media (min-width: 1080px) {
  .app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
}

/* --- сайдбар (десктоп: фикс. вертикальный) --- */
.sidebar {
  display: flex; flex-direction: column; gap: 6px;
  background: var(--bg-2); border-right: 1px solid var(--line);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 20px 16px; font-weight: 650; font-size: 19px; letter-spacing: -0.02em; color: var(--ink);
}
.sidebar-brand .brand-mark { color: var(--accent); }
.sidebar-brand .ico { width: 24px; height: 24px; }
.nav { display: flex; flex-direction: column; gap: 3px; padding: 6px 12px; }
.nav-item {
  display: flex; align-items: center; gap: 11px; width: 100%;
  padding: 10px 12px; border-radius: var(--r-sm); cursor: pointer;
  color: var(--ink-2); font: inherit; font-size: 15px; font-weight: 550; text-decoration: none;
  background: transparent; border: 1px solid transparent; text-align: left;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-item:hover { background: var(--surface-3); color: var(--ink); }
.nav-item:focus-visible { box-shadow: var(--ring); outline: none; }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.is-active .nav-ico { color: var(--accent); }
.nav-ico { display: inline-flex; color: var(--ink-mute); }
.nav-ico .ico { width: 19px; height: 19px; }
.sidebar-foot { margin-top: auto; padding: 12px; border-top: 1px solid var(--line); }
.nav-item--btn:hover { color: var(--danger); }
.nav-item--btn:hover .nav-ico { color: var(--danger); }

/* --- main + sticky appbar (блок: даёт корректное margin-inline:auto центрирование контента на ультравайде) --- */
.main { min-width: 0; }
.appbar {
  position: sticky; top: 0; z-index: 30;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
}
.appbar-inner {
  display: flex; align-items: center; gap: 14px;
  max-width: var(--content-max); margin-inline: auto;
  padding: 13px max(var(--gutter), env(safe-area-inset-right)) 13px max(var(--gutter), env(safe-area-inset-left));
}
.appbar-lead { min-width: 0; display: flex; align-items: center; gap: 12px; margin-right: auto; }
.page-title { font-size: 20px; font-weight: 650; letter-spacing: -0.02em; margin: 0; white-space: nowrap; }
.appbar-tools { display: flex; align-items: center; gap: 12px; min-width: 0; }
.appbar-new { min-height: 42px; }

.content {
  max-width: var(--content-max); margin-inline: auto;
  padding: 24px max(var(--gutter), env(safe-area-inset-right)) calc(56px + env(safe-area-inset-bottom)) max(var(--gutter), env(safe-area-inset-left));
}
@media (min-width: 1500px) { :root { --gutter: 32px; } }

/* --- глобальный date-range --- */
.range { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; box-shadow: var(--shadow); }
.seg-btn {
  appearance: none; background: transparent; border: 0; color: var(--ink-mute);
  font: inherit; font-size: 13.5px; font-weight: 550; padding: 6px 13px; min-height: 34px; border-radius: 6px;
  cursor: pointer; white-space: nowrap; transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.seg-btn:hover { color: var(--ink-2); background: var(--surface-2); }
.seg-btn.on { background: var(--surface-3); color: var(--ink); font-weight: 600; }
.range-custom { display: inline-flex; align-items: center; gap: 8px; }
.range-custom.hidden { display: none; }
.range-field { display: inline-flex; align-items: center; gap: 6px; }
.range-field .field-label { font-size: 12.5px; color: var(--ink-mute); }
.range-dash { color: var(--ink-mute); }
.range-field input[type="date"] {
  background: var(--bg-2); color: var(--ink); border: 1px solid var(--line);
  border-radius: var(--r-sm); min-height: 40px; padding: 7px 10px; font: inherit; font-size: 14px; width: auto;
}
.range-field input[type="date"]:focus { border-color: var(--accent); box-shadow: var(--ring); outline: none; }
.range-field input::-webkit-calendar-picker-indicator { opacity: 0.55; cursor: pointer; }

/* ============================================================
   ДАШБОРД — 12-колоночная сетка
   ============================================================ */
.dash { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; }
.dash-cell { min-width: 0; }
.dash-analytics { grid-column: 1 / -1; }
.dash-models { grid-column: span 4; }
.dash-plats  { grid-column: span 4; }
.dash-refs   { grid-column: span 4; }
@media (max-width: 1180px) {
  .dash-models, .dash-plats { grid-column: span 6; }
  .dash-refs { grid-column: 1 / -1; }
}
@media (max-width: 820px) {
  .dash-models, .dash-plats, .dash-refs { grid-column: 1 / -1; }
}

/* дельта кликов vs прошлый период (бейдж у таба «Клики») */
.delta { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; line-height: 1; padding: 3px 8px; border-radius: 20px; white-space: nowrap; }
.delta.up { color: var(--ok); background: var(--ok-soft); }
.delta.down { color: var(--danger); background: var(--danger-soft); }
.delta-note { display: none; }
.delta::before { content: "▲"; font-size: 7px; }
.delta.down::before { content: "▼"; }

/* ============================================================
   АНАЛИТИКА-КАРТОЧКА (метрики-табы + единый график) — паттерн Dub
   ============================================================ */
.analytics { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
/* метрики-табы */
.mtabs { display: grid; grid-template-columns: repeat(3, 1fr); border-bottom: 1px solid var(--line); }
.mtab {
  appearance: none; text-align: left; cursor: pointer; background: transparent;
  border: 0; border-bottom: 2px solid transparent; border-right: 1px solid var(--line);
  margin-bottom: -1px; /* активное подчёркивание перекрывает хайрлайн .mtabs */
  padding: 18px 22px 16px; display: flex; flex-direction: column; gap: 6px; min-width: 0;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.mtab:last-child { border-right: 0; }
.mtab:hover { background: var(--surface-2); }
.mtab:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent-soft); }
.mtab.is-active { border-bottom-color: var(--accent); background: var(--surface); }
.mtab-top { display: flex; align-items: center; gap: 10px; }
.mtab-label { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 550; color: var(--ink-mute); }
.mtab.is-active .mtab-label { color: var(--ink-2); }
.mtab-dot { width: 9px; height: 9px; border-radius: 3px; flex: none; background: var(--mc, var(--accent)); }
.mtab-value { font-size: clamp(24px, 2.3vw, 32px); font-weight: 680; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.02; color: var(--ink); }
.mtab-sub { font-size: 12px; color: var(--ink-mute); }
.m-clicks { --mc: var(--accent); }
.m-uniques { --mc: rgba(255, 255, 255, 0.62); }
.m-revenue { --mc: var(--ok); }

/* график выбранной метрики */
.analytics-chart { padding: 20px 20px 12px; }
.ac-wrap { width: 100%; }
.ac { width: 100%; height: auto; display: block; overflow: visible; }
.ac-grid { stroke: var(--line); stroke-width: 1; stroke-dasharray: 3 5; vector-effect: non-scaling-stroke; }
.ac-axis { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.ac-line { fill: none; stroke: var(--ac-stroke, var(--accent)); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.ac-area { fill: url(#acGrad); }
.ac-dot { fill: var(--ac-stroke, var(--accent)); stroke: var(--surface); stroke-width: 2; }
.ac-hit { fill: transparent; }
.ac-col:hover .ac-hit { fill: var(--accent-soft); }
.ac-xlab { fill: var(--ink-mute); font-size: 11px; font-family: var(--font); }
.ac-xlab.end { text-anchor: end; font-weight: 600; fill: var(--ink-2); }
.ac-ylab { fill: var(--ink-mute); font-size: 10.5px; font-family: var(--font); }
.analytics-foot { display: flex; align-items: center; gap: 8px; padding: 6px 20px 16px; font-size: 12.5px; color: var(--ink-mute); }
.analytics-foot .af-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--ink-mute); opacity: 0.5; flex: none; }
.analytics-note { color: var(--ink-mute); font-size: 12px; }
.analytics-empty { padding: 8px 20px 28px; }

/* ============================================================
   FACET-КАРТОЧКИ (строки с пастельным баром позади текста)
   ============================================================ */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); display: flex; flex-direction: column; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px 12px; }
.panel-title { display: inline-flex; align-items: center; gap: 8px; font-family: var(--mono); font-size: 11.5px; font-weight: 600; letter-spacing: 0.09em; text-transform: uppercase; margin: 0; color: var(--ink-mute); }
.panel-title .ico { width: 14px; height: 14px; color: var(--ink-mute); }
.panel-note { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--ink-mute); }
.panel-body { padding: 4px 12px 12px; flex: 1; }

/* строки facet */
.facet { display: flex; flex-direction: column; gap: 3px; }
.facet-row {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 7px; min-height: 38px; overflow: hidden;
  transition: box-shadow var(--dur) var(--ease);
}
.facet-bar {
  position: absolute; left: 0; top: 0; bottom: 0; border-radius: 7px;
  background: var(--fb, var(--accent-soft)); min-width: 6px; z-index: 0;
  transition: width var(--dur) var(--ease);
}
.facet-main { position: relative; z-index: 1; flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.facet-name { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: 13.5px; font-weight: 550; color: var(--ink); }
.facet-name span.txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.facet-sub { font-size: 11.5px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.facet-val { position: relative; z-index: 1; font-size: 13.5px; font-weight: 650; color: var(--ink); font-variant-numeric: tabular-nums; flex: none; }
.facet-val .fv-uniq { color: var(--ink-mute); font-weight: 500; font-size: 12px; margin-left: 6px; }
.facet-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--pc, var(--accent)); flex: none; }
.facet-fav { width: 18px; height: 18px; border-radius: 5px; flex: none; display: inline-flex; align-items: center; justify-content: center; background: var(--surface-3); }
.facet-fav .ico { width: 12px; height: 12px; color: var(--ink-mute); }
/* пастельные оттенки на карточку */
.facet--amber .facet-bar { --fb: var(--facet-amber); }
.facet--green .facet-bar { --fb: var(--facet-green); }
.facet--pink  .facet-bar { --fb: var(--facet-pink); }
/* кликабельные строки моделей */
.facet-row.is-click { cursor: pointer; }
.facet-row.is-click:hover { box-shadow: inset 0 0 0 1px var(--line-2); }
.facet-row.is-click:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }

/* ============================================================
   ТАБЛИЦЫ (общие)
   ============================================================ */
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl thead th {
  text-align: left; font-size: 11.5px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--ink-mute); padding: 9px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.tbl tbody td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl .ta-r { text-align: right; }
.tbl-row { transition: background var(--dur) var(--ease); }
.tbl-row:hover { background: var(--surface-2); }
.tbl-row.is-click { cursor: pointer; }
.tbl-row.is-click:focus-visible { outline: none; background: var(--surface-2); box-shadow: inset 3px 0 0 var(--accent); }
.td-money { color: var(--ok); font-weight: 600; }
.td-mute { color: var(--ink-mute); }
.td-uniq { color: var(--ink); }

/* сводные таблицы дашборда */
.tbl--sum tbody td { padding: 10px 12px; }
.td-model { font-weight: 550; color: var(--ink); display: flex; align-items: center; gap: 9px; }
.dot-model { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); flex: none; opacity: 0.85; }
.tbl-share { width: 26%; }
.share-bar { display: block; height: 7px; background: var(--bg-2); border-radius: 6px; overflow: hidden; }
.share-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }

/* ============================================================
   ССЫЛКИ — тулбар
   ============================================================ */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.tb-search { position: relative; flex: 1; min-width: 0; }
.tb-search .tb-ico { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--ink-mute); pointer-events: none; display: flex; }
.tb-search input { padding-left: 40px; min-height: 44px; }
.tb-search input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }
.toolbar .select { width: auto; min-width: 160px; }
.tb-count { font-size: 13px; color: var(--ink-mute); white-space: nowrap; margin-left: 2px; }

/* --- таблица ссылок --- */
.tbl-scroll { border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; background: var(--surface); }
.tbl--links { table-layout: auto; }
.tbl--links thead th { background: var(--bg-2); }
.td-code { white-space: nowrap; }
.code-chip {
  appearance: none; cursor: pointer; border: 1px solid transparent; background: transparent; padding: 3px 6px 3px 4px; border-radius: 6px;
  font-family: var(--mono); font-size: 14px; font-weight: 600; color: var(--ink); letter-spacing: -0.01em;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.code-chip .path { color: var(--ink-mute); }
.code-chip:hover { background: var(--accent-soft); color: var(--accent); }
.code-chip:focus-visible { box-shadow: var(--ring); outline: none; }
.td-dest { max-width: 320px; }
.td-dest a { color: var(--ink-2); text-decoration: none; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-dest a:hover { color: var(--accent); }
.td-meta { max-width: 220px; }
.td-meta .mdl { color: var(--ink); font-weight: 550; }
.td-meta .lbl { color: var(--ink-mute); }
.td-meta .mdl + .lbl::before { content: "· "; }
.td-when { color: var(--ink-mute); font-size: 13px; white-space: nowrap; }
.td-actions { white-space: nowrap; width: 1%; }
.row-actions { display: inline-flex; gap: 4px; opacity: 0.55; transition: opacity var(--dur) var(--ease); }
.tbl-row:hover .row-actions, .tbl-row:focus-within .row-actions { opacity: 1; }

/* tbl-skel */
.tbl-skel { border: 1px solid var(--line); border-radius: var(--r-lg); overflow: hidden; }
.tbl-skel-row { display: flex; gap: 24px; align-items: center; padding: 16px 16px; border-bottom: 1px solid var(--line); }
.tbl-skel-row:last-child { border-bottom: 0; }
.tbl-skel-row .skel { height: 14px; }

/* переключение таблица(десктоп)/карточки(мобайл).
   Компаунд-селекторы (0,2,0) заведомо перебивают display компонентов (.cards{display:flex}) — без !important и без зависимости от порядка правил. */
.tbl-scroll.only-wide { display: block; }
.cards.only-narrow { display: none; }
@media (max-width: 1080px) {
  .tbl-scroll.only-wide { display: none; }
  .cards.only-narrow { display: flex; }
}

/* ============================================================
   ЧИПЫ / ТУМБЛЕР / ТЕГИ / БЕЙДЖ — общие компоненты
   ============================================================ */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  appearance: none; cursor: pointer; font: inherit; font-size: 14.5px; font-weight: 550;
  display: inline-flex; align-items: center; gap: 7px; min-height: 42px; padding: 8px 14px;
  background: var(--bg-2); color: var(--ink-2); border: 1.5px solid var(--line); border-radius: 40px;
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.chip::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--pc, var(--neutral)); flex: none; }
.chip:hover { border-color: var(--line-2); color: var(--ink); }
.chip[aria-pressed="true"] { border-color: var(--accent); background: var(--accent-soft); color: var(--ink); }
.chip:focus-visible { box-shadow: var(--ring); outline: none; }
.p-ig { --pc: var(--p-ig); } .p-tiktok { --pc: var(--p-tiktok); } .p-x { --pc: var(--p-x); }
.p-reddit { --pc: var(--p-reddit); } .p-telegram { --pc: var(--p-telegram); } .p-threads { --pc: var(--p-threads); }
.p-fanvue { --pc: var(--p-fanvue); } .p-of { --pc: var(--p-of); } .p-other { --pc: var(--p-other); }

.more { border: 0; background: transparent; color: var(--accent); font: inherit; font-size: 14px; font-weight: 550;
  cursor: pointer; padding: 4px 0; display: inline-flex; align-items: center; gap: 6px; align-self: flex-start; }
.more:hover { color: var(--ink); }
.more .chev { transition: transform var(--dur) var(--ease); }
.more[aria-expanded="true"] .chev { transform: rotate(180deg); }
.more-fields { display: flex; flex-direction: column; gap: 13px; }
.more-fields.hidden { display: none; }

.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; user-select: none;
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px; }
.switch:hover { border-color: var(--line-2); }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track { position: relative; flex: none; width: 42px; height: 25px; border-radius: 20px; background: var(--surface-3);
  border: 1px solid var(--line-2); transition: background var(--dur) var(--ease); margin-top: 1px; }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%;
  background: var(--ink-2); transition: transform var(--dur) var(--ease), background var(--dur) var(--ease); }
.switch input:checked + .switch-track { background: var(--accent); border-color: transparent; }
.switch input:checked + .switch-track::after { transform: translateX(17px); background: var(--accent-ink); }
.switch input:focus-visible + .switch-track { box-shadow: var(--ring); }
.switch-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.switch-title { display: inline-flex; align-items: center; gap: 6px; font-size: 14.5px; font-weight: 550; color: var(--ink); }
.switch-title .ico { color: var(--accent); }
.switch-hint { font-size: 12.5px; color: var(--ink-mute); line-height: 1.4; }
.switch--sm { padding: 10px 12px; }
.switch--sm .switch-title { font-size: 13.5px; }

.tag {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 550; white-space: nowrap;
  padding: 4px 10px 4px 9px; border-radius: 20px;
  background: var(--bg-2); border: 1px solid var(--line-2); /* --line сливался с фоном шапки таблицы */
  color: var(--ink-2);
}
.tag::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--pc, var(--neutral)); flex: none; }

.badge-bridge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
  padding: 3px 9px 3px 8px; border-radius: 20px; color: var(--accent);
  background: var(--accent-soft); border: 1px solid color-mix(in oklch, var(--accent) 35%, transparent);
}
.badge-bridge .ico { width: 13px; height: 13px; }

/* --- превью кастомного кода + подсказка --- */
input.is-ok { border-color: color-mix(in oklch, var(--ok) 55%, var(--line)); }
input.is-bad { border-color: color-mix(in oklch, var(--danger) 55%, var(--line)); }
.code-preview { font-family: var(--mono); font-size: 13.5px; color: var(--ink-2); word-break: break-all; padding: 2px 2px 0; }
.code-preview .cp-host { color: var(--ink-mute); }
.code-preview .cp-code { color: var(--accent); }
.code-preview .cp-code.muted { color: var(--ink-mute); font-style: italic; font-family: var(--font); }
.code-preview.code-ro { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 12px 14px; font-size: 15px; }
.code-hint { font-size: 12px; color: var(--ink-mute); line-height: 1.35; }
.code-hint.ok { color: var(--ok); }
.code-hint.bad { color: var(--danger); }

/* ============================================================
   REFERRERS — откуда переходят
   ============================================================ */
.refs { display: flex; flex-direction: column; gap: 0; }
.ref-item { display: flex; align-items: center; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.ref-item:last-child { border-bottom: 0; }
.ref-host { flex: 1; min-width: 0; font-size: 14px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-bar { flex: 0 0 32%; height: 8px; background: var(--bg-2); border-radius: 6px; overflow: hidden; }
.ref-bar > i { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.ref-n { font-size: 13.5px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right; }

/* ============================================================
   КАРТОЧКИ ССЫЛОК (мобайл)
   ============================================================ */
.cards { display: flex; flex-direction: column; gap: 11px; }
.link-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  padding: 14px 15px; display: flex; flex-direction: column; gap: 11px;
  transition: border-color var(--dur) var(--ease);
}
.link-card:hover { border-color: var(--line-2); }
.lc-head { display: flex; align-items: center; gap: 10px; }
.lc-code {
  appearance: none; cursor: pointer; border: 0; background: transparent; padding: 0;
  font-family: var(--mono); font-size: 17px; font-weight: 600; color: var(--ink); letter-spacing: -0.01em;
  display: inline-flex; align-items: center; gap: 7px; min-width: 0;
}
.lc-code .path { color: var(--ink-mute); }
.lc-code:hover { color: var(--accent); }
.lc-code .copy-ico { color: var(--ink-mute); opacity: 0; transition: opacity var(--dur) var(--ease); }
.lc-code:hover .copy-ico { opacity: 1; }
.lc-spacer { flex: 1; }
.lc-dest { font-size: 13.5px; color: var(--ink-2); display: flex; align-items: center; gap: 7px; min-width: 0; }
.lc-dest .arrow { color: var(--ink-mute); flex: none; }
.lc-dest a { color: var(--ink-2); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lc-dest a:hover { color: var(--accent); }
.lc-labels { display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 13px; }
.lc-labels .lbl { color: var(--ink); font-weight: 500; }
.lc-labels .mdl { color: var(--ink-mute); }
.lc-stats { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding-top: 11px; border-top: 1px solid var(--line); font-size: 13px; }
.lc-metric { display: inline-flex; align-items: baseline; gap: 5px; }
.lc-metric b { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; color: var(--ink); }
.lc-metric.is-uniq b { color: var(--ink); }
.lc-metric.is-money b { color: var(--ok); }
.lc-metric span { color: var(--ink-mute); font-size: 12.5px; }
.lc-when { margin-left: auto; color: var(--ink-mute); font-size: 12.5px; white-space: nowrap; }
.lc-actions { display: flex; gap: 9px; flex-wrap: wrap; }
.lc-actions .btn { flex: 1; min-width: 96px; min-height: 44px; }

/* ============================================================
   DRAWER — slide-over справа (десктоп) / sheet (мобайл)
   ============================================================ */
.drawer-root { position: fixed; inset: 0; z-index: 80; }
.drawer-overlay { position: absolute; inset: 0; background: oklch(0 0 0 / 0.5); opacity: 0; transition: opacity var(--dur) var(--ease); }
.drawer-root.is-open .drawer-overlay { opacity: 1; }
.drawer {
  position: absolute; top: 0; right: 0; height: 100dvh; width: min(440px, 100%);
  display: flex; flex-direction: column;
  background: var(--surface); border-left: 1px solid var(--line-2); box-shadow: var(--shadow-drawer);
  transform: translateX(100%); transition: transform var(--dur) var(--ease);
}
.drawer-root.is-open .drawer { transform: translateX(0); }
.drawer-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 20px; border-bottom: 1px solid var(--line); flex: none;
}
.drawer-title { font-size: 18px; font-weight: 650; letter-spacing: -0.01em; margin: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 20px; }
#newForm, #editForm { display: flex; flex-direction: column; gap: 16px; }
.drawer-foot {
  display: flex; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--line); flex: none;
  background: var(--surface);
}
.drawer-foot .btn { flex: 1; min-height: 46px; }

/* success внутри drawer */
.success { display: flex; flex-direction: column; gap: 14px; animation: pop var(--dur) var(--ease); }
@keyframes pop { from { opacity: 0; transform: translateY(-6px); } }
.success-tag { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; font-weight: 650; color: var(--ok); }
.success-tag .ico { color: var(--ok); }
.success-url {
  font-family: var(--mono); font-size: clamp(17px, 4.5vw, 21px); font-weight: 600; letter-spacing: -0.01em;
  color: var(--accent); word-break: break-all; line-height: 1.3; cursor: pointer;
  background: var(--bg); border: 1px solid color-mix(in oklch, var(--accent) 40%, var(--line)); border-radius: var(--r); padding: 16px 16px;
}
.success-dest { font-size: 13px; color: var(--ink-mute); word-break: break-all; }
.success-dest b { color: var(--ink-2); font-weight: 550; }
.success-actions { display: flex; gap: 10px; }
.success-actions .btn { flex: 1; min-height: 46px; }

/* ============================================================
   ПУСТЫЕ / ОШИБКА / СКЕЛЕТОН
   ============================================================ */
.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 9px; padding: 40px 24px; }
.empty .ico { width: 34px; height: 34px; stroke-width: 1.6; color: var(--ink-mute); opacity: 0.75; }
.empty-title { font-weight: 600; color: var(--ink-2); font-size: 15px; }
.empty-hint { color: var(--ink-mute); font-size: 13.5px; max-width: 44ch; line-height: 1.5; }
.empty--card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); }
.empty--flat { padding: 26px 16px; }

.skel { position: relative; overflow: hidden; background: #1c1c20; border-radius: 6px; height: 13px; }
.skel::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.06), transparent);
  transform: translateX(-100%); animation: shimmer 1.3s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  background: var(--surface-3); color: var(--ink); border: 1px solid var(--line-2);
  border-radius: var(--r); padding: 12px 18px; z-index: var(--z-toast); font-size: 14.5px; font-weight: 550;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 9px; max-width: min(92vw, 440px);
  opacity: 0; transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.toast:not(.hidden) { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--ok); flex: none; }
.toast.bad { border-color: color-mix(in oklch, var(--danger) 42%, var(--line-2)); }
.toast.bad::before { background: var(--danger); }

/* колонки таблицы, которые прячем на средних ширинах */
@media (max-width: 1320px) { .hide-lg { display: none; } }
@media (max-width: 1240px) { .hide-md { display: none; } }

/* ============================================================
   МОБАЙЛ / ПЛАНШЕТ (<1080px) — сайдбар → верхняя панель, одна колонка
   ============================================================ */
@media (max-width: 1079px) {
  .sidebar {
    flex-direction: row; align-items: center; gap: 4px;
    border-right: 0; border-bottom: 1px solid var(--line);
    padding: 8px max(12px, env(safe-area-inset-left)); position: sticky; top: 0; z-index: 40;
    background: color-mix(in oklch, var(--bg-2) 92%, transparent); backdrop-filter: blur(10px);
  }
  .sidebar-brand { padding: 6px 8px 6px 6px; font-size: 17px; }
  .sidebar-brand-name { display: none; }
  .nav { flex-direction: row; padding: 0; gap: 4px; }
  .nav-item { padding: 8px 12px; min-height: 40px; }
  .nav-label { font-size: 14px; }
  .sidebar-foot { margin: 0 0 0 auto; padding: 0; border-top: 0; }
  .nav-item--btn .nav-label { display: none; }

  .appbar-inner { flex-wrap: wrap; padding: 12px max(16px, env(safe-area-inset-left)); gap: 12px; }
  .appbar-lead { order: 0; margin-right: auto; }
  .appbar-new { order: 1; }
  .appbar-tools { order: 2; flex-basis: 100%; }
  .range { width: 100%; }
  .seg--range { flex: 1; }
  .seg--range .seg-btn { flex: 1; }
  .range-custom { width: 100%; }
  .range-field { flex: 1; }
  .range-field input[type="date"] { width: 100%; }

  .content { padding: 18px 16px calc(48px + env(safe-area-inset-bottom)); }
  .dash { gap: 14px; }
  .dash-kpis { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 14px; }
  .stat.skel-stat { min-height: 88px; }

  .toolbar { flex-wrap: wrap; }
  .tb-search { flex-basis: 100%; order: 0; }
  .toolbar .select { flex: 1; min-width: 0; order: 1; }
  .tb-count { flex-basis: 100%; order: 2; }
}

@media (max-width: 560px) {
  .dash-kpis { grid-template-columns: 1fr; }
  .page-title { font-size: 18px; }
  .drawer { width: 100%; }
}

@media (max-width: 400px) {
  .ef-grid { grid-template-columns: 1fr; }
}
.ef-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
