/* admin.css — десктоп-админка в дизайн-системе v2 «Нейтральный pro» (docs/37).
 *
 * Токены (--bg/--surface/--text/--border/--accent/радиусы/тени) — ОБЩИЕ с mini-app:
 * /css/tokens.css подключается в index.html до этого файла. Шрифт Onest — self-hosted
 * из /fonts (miniapp/fonts в образе). Коралл --accent — ТОЛЬКО главное действие экрана;
 * включённые тумблеры и активный пункт меню — графит; статусы — приглушённые --st-*.
 * Build-free, vanilla. */

@font-face { font-family: "Onest"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url("/fonts/onest-cyrillic.woff2?v=b8d8c87c6f") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Onest"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url("/fonts/onest-latin-ext.woff2?v=f55231b2ff") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
@font-face { font-family: "Onest"; font-style: normal; font-weight: 400 700; font-display: swap;
  src: url("/fonts/onest-latin.woff2?v=2e922429af") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-callout);
  line-height: var(--leading-snug);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }

/* [hidden] должен побеждать class-based display (иначе экраны не прячутся). */
[hidden] { display: none !important; }

.icon { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round; }

/* ═══════════════════════ Бренд (вариант D) ═══════════════════════ */
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand__logo { display: block; flex: none; }
.brand__bg { fill: var(--text); }
.brand__drop { fill: var(--accent); }
.brand__spark { fill: var(--surface); }
.brand__name { font-size: 19px; font-weight: var(--weight-bold); letter-spacing: -0.03em; color: var(--text); }
.brand__tag {
  font-size: var(--text-micro); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps);
  text-transform: uppercase; color: var(--text-muted); background: var(--surface-sunken);
  border-radius: var(--radius-pill); padding: 3px 8px; line-height: 1;
}

/* ═══════════════════════ Экран входа ═══════════════════════ */
.login-screen {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 16px;
}
.login-card {
  width: 440px; max-width: 100%;
  display: flex; flex-direction: column; align-items: center; gap: 20px;
  padding: 32px 36px 20px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-xl); box-shadow: var(--shadow-card);
}
.brand--login .brand__logo { width: 32px; height: 32px; }
.brand--login .brand__name { font-size: 20px; }
.tg-login, .token-login { align-self: stretch; display: flex; flex-direction: column; align-items: center; gap: 20px; }
.login-head { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center; }
.login-title { font-size: var(--text-title-1); line-height: 30px; font-weight: var(--weight-semibold); letter-spacing: -0.01em; }
.login-sub { margin: 0; font-size: var(--text-body); line-height: 22px; color: var(--text-muted); max-width: 34ch; }

.steps { margin: 0; padding: 0; list-style: none; align-self: stretch; display: flex; flex-direction: column; gap: 10px; }
.step { display: flex; align-items: flex-start; gap: 12px; font-size: var(--text-callout); line-height: 20px; }
.step__n {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-sunken); font-size: var(--text-footnote); font-weight: var(--weight-semibold);
}
.tg-qr { padding: 14px; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); line-height: 0; }
.tg-qr svg { width: 184px; height: 184px; }
.tg-match { display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.tg-match__label { font-size: var(--text-callout); color: var(--text-muted); }
.tg-match__code { font-size: 28px; line-height: 1; font-weight: var(--weight-bold); letter-spacing: 0.04em; font-variant-numeric: tabular-nums; color: var(--text); }
.tg-match__hint { font-size: 12px; line-height: 16px; color: var(--text-muted); max-width: 34ch; }
.tg-cta { align-self: stretch; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.tg-status { margin: 0; display: inline-flex; align-items: center; gap: 8px; font-size: var(--text-callout); color: var(--text-muted); }
.tg-status__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--why-icon); animation: tg-pulse 1.6s var(--ease-in-out) infinite; }
.tg-status.is-ok .tg-status__dot { background: var(--col-won); animation: none; }
.tg-status.is-ok .tg-status__text { color: var(--st-won-fg); }
@keyframes tg-pulse { 50% { opacity: 0.35; } }
.tg-ttl { margin: 0; font-size: var(--text-footnote); color: var(--text-faint); }
.tg-ttl__val { color: var(--text-muted); font-weight: var(--weight-semibold); font-variant-numeric: tabular-nums; }
.tg-linktext {
  align-self: stretch; font-family: var(--font-mono); font-size: var(--text-caption); word-break: break-all;
  background: var(--surface-sunken); border-radius: var(--radius-sm); padding: 8px 10px; user-select: all;
}
.tools {
  align-self: stretch; display: flex; justify-content: center; flex-wrap: wrap; gap: 4px;
  border-top: 1px solid var(--border-subtle); padding-top: 8px;
}
.tool, .linkbtn {
  min-height: 40px; padding: 0 12px; border: 0; background: none; border-radius: var(--radius-md);
  font-size: var(--text-callout); font-weight: var(--weight-medium); color: var(--text-muted);
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
}
.tool .icon { width: 16px; height: 16px; }
.tool:hover, .linkbtn:hover { background: var(--surface-hover); color: var(--text); }
.tool:focus-visible, .linkbtn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.linkbtn { font-size: var(--text-footnote); min-height: 32px; color: var(--text-faint); }
.tg-msg { align-self: stretch; display: flex; flex-direction: column; align-items: center; gap: 16px; }
.tg-msg__icon {
  width: 48px; height: 48px; border-radius: var(--radius-lg); background: var(--surface-sunken); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
}
.tg-msg__icon .icon { width: 22px; height: 22px; }
.token-login .field--block { align-self: stretch; }
.login-error {
  align-self: stretch; font-size: var(--text-footnote); line-height: 1.4;
  color: var(--st-overdue-fg); background: var(--st-overdue-bg);
  border-radius: var(--radius-md); padding: 10px 12px;
}

/* ═══════════════════════ Каркас: сайдбар + колонка ═══════════════════════ */
.app-shell { min-height: 100vh; }
@media (min-width: 900px) {
  /* фон сайдбара на всю высоту длинной страницы (fixed-сайдбар заканчивается на вьюпорте) */
  .app-shell { background: linear-gradient(to right, var(--surface) 239px, var(--border) 239px 240px, transparent 240px); }
}
.sidebar {
  position: fixed; top: 0; bottom: 0; left: 0; width: 240px; z-index: var(--z-header);
  display: flex; flex-direction: column;
  padding: var(--space-4) var(--space-3);
  background: var(--surface); border-right: 1px solid var(--border);
}
.sidebar-brand { display: flex; align-items: center; min-height: 44px; padding: 0 var(--space-1) var(--space-4); }
.nav-cap {
  font-size: var(--text-micro); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps);
  text-transform: uppercase; color: var(--text-faint); padding: 0 var(--space-3) 6px;
}
.nav-cap--inner { padding-top: var(--space-4); }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; min-height: 0; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  min-height: 38px; padding: 0 var(--space-3);
  border: 0; background: transparent; border-radius: var(--radius-sm);
  color: var(--text-muted); text-align: left; cursor: pointer;
  font-size: var(--text-callout); font-weight: var(--weight-medium);
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast) var(--ease-out);
}
.nav-item .icon { width: 18px; height: 18px; color: var(--text-faint); }
.nav-item.active { background: var(--surface-sunken); color: var(--text); }
.nav-item.active .icon { color: var(--text); }
.nav-item:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
@media (hover: hover) and (pointer: fine) {
  .nav-item:not(.active):hover { background: var(--surface-2); color: var(--text); }
}
.sidebar-foot { display: flex; flex-direction: column; gap: 8px; padding-top: var(--space-3); border-top: 1px solid var(--border-subtle); }
.whoami { display: flex; align-items: center; gap: 10px; padding: 4px var(--space-2); }
.whoami__avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none; background: var(--text); color: var(--surface);
  display: flex; align-items: center; justify-content: center; font-size: var(--text-micro); font-weight: var(--weight-bold);
}
.whoami__text { display: flex; flex-direction: column; min-width: 0; }
.whoami__name { font-size: var(--text-footnote); font-weight: var(--weight-semibold); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.whoami__via { font-size: var(--text-caption); color: var(--text-faint); }
#logout { justify-content: flex-start; color: var(--text-muted); }

.content {
  margin-left: 240px; max-width: 1280px; min-width: 0;
  padding: var(--space-8) var(--space-10) var(--space-10);
}
.content-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: var(--space-5); flex-wrap: wrap; }
.content-head__text { min-width: 0; }
.content-title { font-size: var(--text-display); line-height: 1.15; font-weight: var(--weight-bold); letter-spacing: var(--tracking-display); }
.content-sub { margin: 4px 0 0; font-size: var(--text-footnote); color: var(--text-muted); }
.content-sub:empty { display: none; }
.content-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.content-actions:empty { display: none; }
#global-error { margin: 0 0 var(--space-4); }
.menu-toggle { display: none; }
.view { min-height: 200px; }

/* узкий экран: сайдбар сверху (админка — десктоп, но не ломаемся на планшете/телефоне) */
@media (max-width: 899px) {
  .sidebar {
    position: sticky; top: 0; width: auto; border-right: 0; border-bottom: 1px solid var(--border);
    padding: 10px var(--space-4); flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px;
  }
  .sidebar-brand { min-height: 40px; padding: 0; flex: 1; }
  .menu-toggle {
    display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px;
    border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface);
    font-size: var(--text-callout); font-weight: var(--weight-medium); cursor: pointer;
  }
  .menu-toggle__txt { color: var(--text-faint); }
  .menu-toggle__txt::before { content: "·"; margin-right: 8px; }
  .nav, .sidebar-foot { display: none; }
  .sidebar.open { max-height: 100dvh; overflow-y: auto; }
  .sidebar.open .nav { display: flex; flex-basis: 100%; padding-top: 8px; }
  .sidebar.open .sidebar-foot { display: flex; flex-basis: 100%; flex-direction: row; align-items: center; justify-content: space-between; }
  #logout { width: auto; }
  .content { margin-left: 0; padding: var(--space-5) var(--space-4) var(--space-8); }
  .login-card { padding: 24px 20px 16px; }
}

/* ═══════════════════════ Карточки / формы ═══════════════════════ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-card);
  padding: var(--space-5) var(--space-6); margin-bottom: var(--space-4);
}
.card-title { margin: 0 0 var(--space-4); font-size: var(--text-headline); line-height: var(--leading-headline); font-weight: var(--weight-semibold); letter-spacing: -0.01em; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field__label {
  font-size: var(--text-micro); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps);
  text-transform: uppercase; color: var(--text-faint);
}
.field input, .field select, .input {
  min-height: 40px; padding: 0 12px; min-width: 200px;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--surface-sunken); font-size: var(--text-callout);
  transition: border-color var(--dur-fast) var(--ease-out), box-shadow var(--dur-fast) var(--ease-out), background var(--dur-fast);
}
.input { width: 100%; min-height: 44px; font-size: var(--text-input); }
.field input::placeholder, .input::placeholder { color: var(--text-faint); }
.field input:focus, .field select:focus, .input:focus {
  outline: none; background: var(--surface); border-color: var(--border-strong); box-shadow: var(--shadow-focus);
}

/* ═══════════════════════ Кнопки ═══════════════════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px;
  border-radius: var(--radius-md); border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  font-size: var(--text-callout); font-weight: var(--weight-medium); text-decoration: none;
  cursor: pointer; white-space: nowrap;
  transition: background var(--dur-fast) var(--ease-out), border-color var(--dur-fast), transform var(--dur-instant) var(--ease-out);
}
.btn .icon { width: 18px; height: 18px; }
.btn:hover { background: var(--surface-hover); }
.btn:active { transform: scale(0.98); }
.btn:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
/* Главное действие — коралл (одно на экран). */
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: var(--weight-semibold); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
/* Действия в строках таблиц — не главные: графитовый контур, коралл не тиражируем. */
table.tbl .btn-primary { background: var(--surface); border-color: var(--border); color: var(--text); font-weight: var(--weight-medium); }
table.tbl .btn-primary:hover { background: var(--surface-hover); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, var(--border)); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-hover); }
.btn-block { width: 100%; }
.btn-lg { min-height: 48px; font-size: var(--text-body); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: var(--text-footnote); border-radius: var(--radius-sm); }

/* ═══════════════════════ Таблицы ═══════════════════════ */
.table-wrap { overflow-x: auto; margin: 0 calc(-1 * var(--space-2)); }
table.tbl { width: 100%; border-collapse: collapse; font-size: var(--text-callout); }
table.tbl th, table.tbl td {
  text-align: left; padding: 10px var(--space-2);
  border-bottom: 1px solid var(--border-subtle); vertical-align: middle;
}
table.tbl th {
  font-size: var(--text-micro); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps);
  text-transform: uppercase; color: var(--text-faint); border-bottom-color: var(--border);
  padding-top: 0;
}
table.tbl tbody tr { transition: background var(--dur-fast) var(--ease-out); }
@media (hover: hover) and (pointer: fine) { table.tbl tbody tr:hover { background: var(--bg); } }
table.tbl tr:last-child td { border-bottom: none; }
.mono { font-family: var(--font-mono); font-size: var(--text-footnote); }
.muted { color: var(--text-muted); }

/* ═══════════════════════ Статус-пилюли (точка + текст) ═══════════════════════ */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px; border-radius: var(--radius-pill);
  font-size: var(--text-caption); font-weight: var(--weight-medium); white-space: nowrap;
  background: var(--st-lost-bg); color: var(--st-lost-fg);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.pill-ok { background: var(--st-won-bg); color: var(--st-won-fg); }
.pill-warn { background: var(--st-work-bg); color: var(--st-work-fg); }
.pill-danger { background: var(--st-overdue-bg); color: var(--st-overdue-fg); }
.pill-muted { background: var(--st-lost-bg); color: var(--st-lost-fg); }

/* ═══════════════════════ Тумблер (включено — графит) ═══════════════════════ */
.toggle {
  position: relative; width: 44px; height: 26px; padding: 0;
  border: 0; border-radius: var(--radius-pill); background: var(--border-strong); cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out);
}
.toggle::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px;
  border-radius: 50%; background: var(--surface); box-shadow: var(--shadow-knob);
  transition: transform var(--dur-base) var(--ease-out);
}
.toggle.on { background: var(--text); }
.toggle.on::after { transform: translateX(18px); }
.toggle.locked { background: var(--surface-sunken); cursor: not-allowed; }
.toggle.locked.on { background: var(--text-faint); }
.toggle:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

/* ═══════════════════════ Баннеры / пустые состояния ═══════════════════════ */
.banner { border-radius: var(--radius-md); padding: 10px 14px; font-size: var(--text-footnote); margin-top: 12px; }
.banner-error { background: var(--st-overdue-bg); color: var(--st-overdue-fg); }
.banner-ok { background: var(--st-won-bg); color: var(--st-won-fg); }
.empty { color: var(--text-faint); padding: var(--space-6); text-align: center; }
.loading { color: var(--text-faint); padding: var(--space-6); text-align: center; }

/* ═══════════════════════ Метрики ═══════════════════════ */
.metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.metric { background: var(--bg); border: 1px solid var(--border-subtle); border-radius: var(--radius-md); padding: 14px 16px; }
.metric-val { font-size: var(--text-title-1); line-height: 1.15; font-weight: var(--weight-semibold); letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.metric-key { font-size: var(--text-caption); color: var(--text-faint); margin-top: 4px; }

/* ═══════════════════════ Модалка ═══════════════════════ */
.modal-root { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: var(--z-toast); padding: 16px; }
/* 🛑 [hidden] должен скрывать модалку — иначе overlay (inset:0) перехватывает клики. */
.modal-root[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(28, 25, 23, 0.32); }
.modal-card {
  position: relative; width: 480px; max-width: 100%; max-height: 88vh; overflow: auto;
  background: var(--surface); border-radius: var(--radius-xl); box-shadow: var(--shadow-overlay);
  padding: var(--space-6);
  animation: modal-in var(--dur-slow) var(--ease-out);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
.modal-title { margin: 0 0 12px; font-size: var(--text-title-2); line-height: var(--leading-title); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-title); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: var(--space-5); }
.token-box { display: flex; gap: 8px; align-items: stretch; margin: 12px 0; }
.token-box .mono {
  flex: 1; background: var(--surface-sunken); border-radius: var(--radius-md);
  padding: 12px; word-break: break-all; user-select: all;
}
.token-warn { color: var(--st-work-fg); background: var(--why-bg); border: 1px solid var(--why-border); border-radius: var(--radius-md); padding: 10px 12px; font-size: var(--text-footnote); }
.actions-cell { display: flex; gap: 8px; }

/* ═══════════════════════ Инфо-плашка (лаг снимка + БД-авторитет) ═══════════════════════ */
.info-note {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 12px 16px; margin-bottom: var(--space-4);
  font-size: var(--text-footnote); color: var(--text-muted);
}
.info-note__icon { color: var(--text-faint); font-weight: var(--weight-semibold); line-height: 1.4; flex-shrink: 0; }
.info-note__text { line-height: 1.45; }

/* ═══════════════════════ Чипы (недавние account_id) ═══════════════════════ */
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }
.chips__label { font-size: var(--text-micro); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-faint); }
.chip {
  height: 30px; padding: 0 12px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-family: var(--font-mono); font-size: var(--text-footnote); cursor: pointer;
}
.chip:hover { background: var(--surface-hover); border-color: var(--border-strong); }

/* ═══════════════════════ config_version на «Гейтах» ═══════════════════════ */
.config-ver { font-size: var(--text-footnote); color: var(--text-faint); margin: -6px 0 14px; }

/* ═══════════════════════ v2 бизнес-экраны (docs/39, макеты на холсте) ═══════════════════════ */
.view { display: flex; flex-direction: column; gap: 12px; }
.view > .card, .view > .info-note { margin-bottom: 4px; }
.card2 {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 18px 20px; min-width: 0;
}
.card2__head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.cap {
  font-size: var(--text-micro); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps);
  text-transform: uppercase; color: var(--text-faint);
}
.big { font-size: 28px; line-height: 1.2; font-weight: var(--weight-bold); letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.big--long { font-size: 22px; line-height: 34px; white-space: normal !important; }
.big--danger { color: var(--st-overdue-fg); }
.sub { font-size: var(--text-footnote); color: var(--text-muted); }
.stat .sub { margin-top: 2px; }
.a, .view a:not(.btn):not(.gt__row) { color: var(--accent-hover); text-decoration: none; }
.view a:not(.btn):not(.gt__row):hover { text-decoration: underline; }
.grow { flex: 1; min-width: 0; }
.col { display: flex; flex-direction: column; }
.gap { gap: 12px; }
.gap-s { gap: 8px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.grid5 { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.span2 { grid-column: span 2; }
.grid-card { display: grid; grid-template-columns: 1.1fr 1fr; gap: 12px; align-items: start; }
.grid-bc { display: grid; grid-template-columns: 1.3fr 1fr; gap: 12px; align-items: start; }
.grid-q { display: grid; grid-template-columns: 1.2fr 1fr; gap: 12px; align-items: start; }
.stat .big { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* сегмент (период / вкладки) */
.seg { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.seg__btn {
  min-height: 36px; padding: 0 14px; border: 1px solid var(--border); background: var(--surface);
  border-radius: var(--radius-md); font-size: var(--text-callout); cursor: pointer;
}
.seg__btn.on { background: var(--text); border-color: var(--text); color: var(--surface); }
.seg__btn:focus-visible, .fchip:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
.seg--tabs { margin-bottom: 4px; }

/* чипы-фильтры со счётчиками */
.fchips { display: flex; flex-wrap: wrap; gap: 8px; }
.fchip {
  min-height: 34px; padding: 0 14px; border-radius: var(--radius-pill); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font-size: var(--text-callout); cursor: pointer; white-space: nowrap;
}
.fchip.on { background: var(--text); border-color: var(--text); color: var(--surface); }
@media (hover: hover) and (pointer: fine) { .fchip:not(.on):hover, .seg__btn:not(.on):hover { background: var(--surface-hover); } }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .search { max-width: 420px; flex: 1 1 280px; min-height: 40px; font-size: var(--text-body); background: var(--surface); }
.chips-slot { min-width: 0; max-width: 100%; }
.foot { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* таблица-сетка */
.gt { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.gt__head, .gt__row { display: grid; grid-template-columns: var(--gt-cols); gap: 12px; padding: 12px 20px; align-items: center; }
.gt__head { background: var(--surface-2); }
.th { font-size: var(--text-micro); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-faint); }
.gt__row { border-top: 1px solid var(--border-subtle); font-size: var(--text-callout); color: var(--text); text-decoration: none; min-height: 56px; }
.gt__row--link { cursor: pointer; transition: background var(--dur-fast) var(--ease-out); }
@media (hover: hover) and (pointer: fine) { .gt__row--link:hover { background: var(--bg); } }
.gt__row--link:focus-visible { outline: none; box-shadow: inset var(--shadow-focus); }
.gt__cell { min-width: 0; overflow-wrap: anywhere; }
.gt__empty { padding: 28px 20px; text-align: center; color: var(--text-faint); border-top: 1px solid var(--border-subtle); }
.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who__ava {
  width: 32px; height: 32px; border-radius: 50%; flex: none; background: var(--surface-sunken);
  display: flex; align-items: center; justify-content: center; font-weight: var(--weight-semibold);
}
.who__text { display: flex; flex-direction: column; min-width: 0; }
.who__name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.leads { display: flex; flex-direction: column; gap: 4px; }
.stale { color: var(--st-overdue-fg); }
.bar { display: block; height: 6px; background: var(--surface-sunken); border-radius: var(--radius-pill); overflow: hidden; }
.bar--thin { height: 4px; }
.bar__fill { display: block; height: 100%; background: var(--text); border-radius: var(--radius-pill); }
.cell-actions, .row-btns { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cell-actions { flex-wrap: nowrap; }

/* строки в карточках */
.lrow { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border-subtle); font-size: var(--text-callout); }
.card2__head + .lrow, .cap + .lrow { margin-top: 10px; }
.empty-row { padding: 14px 0 4px; color: var(--text-faint); font-size: var(--text-callout); }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border-subtle); font-size: var(--text-callout); }
.cap + .kv { margin-top: 8px; }
.kv__k { color: var(--text); }
.kv__v, .kv > span:last-child { text-align: right; }
.kv__v2 { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }

/* график и воронка */
.legend { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-footnote); color: var(--text-muted); }
.legend__sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 6px; }
.legend__sw--a { background: var(--text); }
.legend__sw--b { background: var(--border-strong); }
.legend__sw--miss { background: var(--accent); }
.legend--foot { margin-top: 12px; }
.chart { display: flex; align-items: flex-end; gap: 10px; height: 190px; padding-top: 16px; }
.chart__col { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.chart__bars { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.chart__bar { width: min(18px, 40%); border-radius: 5px 5px 0 0; }
.chart__bar--a { background: var(--text); }
.chart__bar--b { background: var(--border-strong); }
.chart__lbl { font-size: var(--text-caption); color: var(--text-muted); min-height: 16px; white-space: nowrap; }
.funnel { display: flex; flex-direction: column; gap: 10px; padding-top: 14px; }
.funnel__row { display: flex; justify-content: space-between; font-size: var(--text-callout); margin-bottom: 4px; }

/* воронка активации (docs/52 E): шаги-кнопки → список застрявших */
.fsteps { display: flex; flex-direction: column; gap: 2px; padding-top: 10px; }
.fstep {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center;
  width: 100%; padding: 10px 12px; margin: 0 -12px; box-sizing: content-box;
  border: 1px solid transparent; border-radius: var(--radius-md); background: none;
  font: inherit; color: inherit; text-align: left; cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out);
}
.fstep:disabled { cursor: default; }
.fstep.on { background: var(--surface-2); border-color: var(--border); }
.fstep:focus-visible { outline: none; box-shadow: var(--shadow-focus); }
@media (hover: hover) and (pointer: fine) { .fstep:not(:disabled):not(.on):hover { background: var(--surface-hover); } }
.fstep__name { font-size: var(--text-callout); }
.fstep__n { font-variant-numeric: tabular-nums; text-align: right; }
.fstep .bar { grid-column: 1 / -1; }
.fstep__stuck { text-align: right; white-space: nowrap; }
.fstep:not(:disabled) .fstep__stuck { color: var(--text); font-weight: var(--weight-semibold); }
.chart--weeks { height: 170px; }
.chart__val { font-size: var(--text-caption); color: var(--text-muted); font-variant-numeric: tabular-nums; }
.fn-how summary { cursor: pointer; color: var(--text); font-weight: var(--weight-semibold); }
.fn-how p { margin: 8px 0 0; }

/* карточка клиента */
.back { font-size: var(--text-callout); align-self: flex-start; }
.client-head { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.ava-lg {
  width: 56px; height: 56px; border-radius: 50%; flex: none; background: var(--text); color: var(--surface);
  display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: var(--weight-semibold);
}
.client-head .col { gap: 2px; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.h-name { font-size: 22px; font-weight: var(--weight-bold); letter-spacing: -0.02em; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.linkbtn2 { border: 0; background: none; padding: 0; color: var(--accent-hover); cursor: pointer; font-size: inherit; }
.linkbtn2:hover { text-decoration: underline; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding-top: 12px; }
.btn-row.end { justify-content: flex-end; padding-top: 0; }
.feed { display: flex; flex-direction: column; padding-top: 6px; }
.feed__row { display: flex; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border-subtle); font-size: var(--text-callout); }
.feed__t { width: 110px; flex: none; }

/* формы */
.lbl { display: flex; flex-direction: column; gap: 6px; font-size: var(--text-footnote); font-weight: var(--weight-semibold); min-width: 0; }
.inp {
  min-height: 42px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-md);
  background: var(--bg); font-size: var(--text-body); font-weight: var(--weight-regular); width: 100%; min-width: 0;
}
.inp:focus { outline: none; background: var(--surface); border-color: var(--border-strong); box-shadow: var(--shadow-focus); }
.inp::placeholder { color: var(--text-faint); }
.inp--auto { width: auto; }
.inp--sm { max-width: 280px; min-height: 36px; font-size: var(--text-callout); }
textarea.inp { padding: 12px; line-height: 1.45; resize: vertical; }
.ta { min-height: 140px; }
.ta-sm { min-height: 64px; margin-top: 8px; }
.fgrid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.fgrid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.fgrid5 { display: grid; grid-template-columns: 1.2fr 1.2fr 0.8fr 1fr 1fr; gap: 10px; }
.plan-head { display: flex; justify-content: space-between; align-items: center; }
.h-plan { font-size: 18px; font-weight: var(--weight-bold); }
.section-head { display: flex; justify-content: space-between; align-items: center; padding-top: 12px; }
.h2 { font-size: var(--text-title-2); font-weight: var(--weight-bold); letter-spacing: -0.02em; }
.form-err { color: var(--st-overdue-fg); font-size: var(--text-footnote); }
.form-err:empty { display: none; }
.checks { display: flex; flex-direction: column; gap: 8px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: var(--text-callout); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--text); }
.note { font-size: var(--text-footnote); color: var(--text-muted); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 12px 16px; }
.test-mode::before { display: none; }

/* предпросмотр «как в Telegram» */
.tg-card { background: var(--surface-sunken); border-color: transparent; }
.tg-card > .cap { padding-bottom: 10px; }
.tg-bubble {
  background: var(--surface); border-radius: 14px 14px 14px 4px; padding: 12px 14px;
  font-size: var(--text-body); line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere;
}
.tg-bubble.is-empty { color: var(--text-faint); }
.tg-bubble--sm { font-size: var(--text-callout); padding: 10px 14px; white-space: normal; }
.tg-btn { margin-top: 6px; background: var(--surface); border-radius: var(--radius-md); padding: 10px; text-align: center; font-weight: var(--weight-semibold); }

/* качество */
.nbar { flex: 1; height: 8px; background: var(--surface-sunken); border-radius: var(--radius-pill); display: flex; overflow: hidden; }
.nbar__a { background: var(--text); }
.nbar__b { background: var(--accent); }
.niche-name { width: 190px; flex: none; }
.niche-txt { width: 160px; flex: none; text-align: right; }
.src-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; padding-top: 10px; }
.complaint .row-btns { justify-content: flex-end; }

/* уведомления */
.chats { display: inline-flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tag { display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 4px 0 10px; border-radius: var(--radius-pill); background: var(--surface-sunken); font-family: var(--font-mono); font-size: var(--text-caption); }
.tag__x { border: 0; background: none; width: 20px; height: 20px; border-radius: 50%; cursor: pointer; color: var(--text-muted); }
.tag__x:hover { background: var(--surface-hover); }
.add-chat { padding-top: 8px; padding-bottom: 8px; }
.alert-row { padding: 13px 0; font-size: var(--text-body); }
.alert-row .toggle { flex: none; }
.save-state { margin-left: auto; }

/* модалки / тост */
.modal-text { margin: 0 0 8px; color: var(--text-muted); font-size: var(--text-callout); line-height: 1.45; }
.modal-card .lbl { margin-top: 8px; }
.toast {
  position: fixed; right: 24px; bottom: 24px; z-index: calc(var(--z-toast) + 1); max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px; border-radius: var(--radius-md); background: var(--text); color: var(--surface);
  font-size: var(--text-callout); box-shadow: var(--shadow-overlay);
  opacity: 0; transform: translateY(8px); pointer-events: none;
  transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out);
}
.toast.is-on { opacity: 1; transform: none; }
.toast--error { background: var(--st-overdue-fg); }
.btn.is-busy { opacity: 0.7; cursor: progress; }
.flag-name { display: flex; flex-direction: column; gap: 2px; }
.flag-key { font-size: var(--text-caption); }

/* адаптив: планшет */
@media (max-width: 1199px) {
  .grid5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-bc, .grid-q, .grid-card { grid-template-columns: minmax(0, 1fr); }
  .src-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fgrid5 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
/* телефон: сетки в колонку, таблицы → карточки с подписями */
@media (max-width: 899px) {
  .grid5, .grid4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid3, .grid2 { grid-template-columns: minmax(0, 1fr); }
  .span2 { grid-column: auto; }
  .big { font-size: 24px; }
  .big--long { font-size: 22px; }
  .grid5 > :last-child:nth-child(odd) { grid-column: 1 / -1; }
  .lrow .grow { min-width: 55%; }
  .card2 { padding: 16px; }
  .content-head { align-items: flex-start; }
  .gt__head { display: none; }
  .gt__row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px 12px; padding: 14px 16px; }
  .gt__cell { font-size: var(--text-footnote); }
  .gt__cell::before { content: attr(data-label); display: block; font-size: var(--text-micro); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-caps); text-transform: uppercase; color: var(--text-faint); margin-bottom: 2px; }
  .gt__cell--main { grid-column: 1 / -1; font-size: var(--text-callout); }
  .gt__cell--main::before { display: none; }
  .toolbar .search { max-width: none; flex-basis: 100%; }
  .chips-slot { flex-basis: 100%; }
  .content, .view { min-width: 0; overflow-x: clip; }
  .fchips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 0 16px; scrollbar-width: none; }
  .fchips::-webkit-scrollbar { display: none; }
  .chart { gap: 4px; height: 160px; }
  .fgrid2, .fgrid3, .fgrid5 { grid-template-columns: minmax(0, 1fr); }
  .src-grid { grid-template-columns: minmax(0, 1fr); }
  .niche-name { width: 110px; }
  .niche-txt { width: auto; }
  .lrow { flex-wrap: wrap; }
  .feed__t { width: 90px; }
  .toast { right: 16px; left: 16px; bottom: 16px; }
}

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