/* ============================================================
   BOOMERANG REAL ESTATE — Кабинет агента
   Бренд-система v2 (см. brand-system.md).
   Компоненты используют только семантические токены.
   Тема переключается подменой значений переменных
   через [data-theme="dark"] на <html> — классов dark нет.
   ============================================================ */

/* ---------- Шрифты: самохостинг, кириллица/латиница раздельно ---------- */

@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/Inter-400-cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('fonts/Inter-400-latin.woff2') 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;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/Inter-500-cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('fonts/Inter-500-latin.woff2') 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;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/Inter-600-cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/Inter-600-latin.woff2') 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;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/Inter-700-cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/Inter-700-latin.woff2') 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;
}
@font-face {
  font-family: 'Inter Tight';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/InterTight-600-cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Inter Tight';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('fonts/InterTight-600-latin.woff2') 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;
}
@font-face {
  font-family: 'Inter Tight';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/InterTight-700-cyrillic.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
  font-family: 'Inter Tight';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('fonts/InterTight-700-latin.woff2') 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;
}

/* ---------- Токены: светлая тема ---------- */

:root {
  --bg: #fbfaf8;
  --bg-warm: #f3f1ec;
  --bg-subtle: #f3f1ec;
  --surface: #ffffff;
  --surface-hover: #f3f1ec;

  --fg: #22272c;
  --fg-muted: #6b6862;
  --fg-subtle: #a29d95;
  --fg-inverse: #ffffff;

  --border: #e6e2da;
  --border-strong: #c9c4bb;

  --accent: #134fe0;
  --accent-hover: #0a3cb0;
  --accent-fg: #ffffff;
  --accent-subtle: #eaeffc;
  --accent-graphic: #2f6bf0;

  --success: #4c5a41;
  --success-subtle: #e9ece2;
  --warning: #96580f;
  --warning-subtle: #f8eeda;
  --error: #b03a2f;
  --error-subtle: #f8e8e4;

  /* Тени тёплые в тон подложке: серые тени на тёплом фоне
     выглядят грязным пятном */
  --sh-card: 0 1px 2px rgb(34 39 44 / 0.04), 0 4px 16px rgb(34 39 44 / 0.05);
  --sh-hover: 0 2px 4px rgb(34 39 44 / 0.06), 0 12px 32px rgb(34 39 44 / 0.09);
  --sh-modal: 0 24px 64px rgb(34 39 44 / 0.16);

  --tint: #f3f1ec;
  --contrast: #22272c;
  --on-contrast: #f6f3ee;
  --brand-deep: #0a3cb0;
  --brand-deep-fg: #ffffff;

  --scrim: rgb(19 23 27 / 0.5);
  --scrim-strong: rgb(19 23 27 / 0.92);
  --on-scrim: #ffffff;
  --on-scrim-hover: rgb(255 255 255 / 0.2);

  --logo-color: #22272c;

  /* Кривые движения: одна на весь интерфейс */
  --ease-out-expo: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-out-quart: cubic-bezier(0.25, 1, 0.5, 1);

  /* Радиусы по шкале брендбука */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-2xl: 40px;

  --font-sans: 'Inter', system-ui, sans-serif;
  --font-tight: 'Inter Tight', 'Inter', system-ui, sans-serif;

  /* Смешивание CRM-цвета бейджей с поверхностью, не с белым */
  --badge-base: #ffffff;
  --badge-ink: #22272c;

  color-scheme: light;
}

/* ---------- Токены: тёмная тема ---------- */

[data-theme="dark"] {
  --bg: #0e1113;
  --bg-warm: #16191c;
  --bg-subtle: #16191c;
  --surface: #16191c;
  --surface-hover: #1d2125;

  /* Тёплый белый вместо холодного: ощущение бумаги, а не экрана */
  --fg: #f2ede6;
  --fg-muted: #a8a49d;
  --fg-subtle: #6e6b66;
  --fg-inverse: #0e1113;

  --border: #2a2f34;
  --border-strong: #3a4046;

  /* Акцент приглушён намеренно: электрический синий на чёрном —
     первый признак дешёвого тёмного интерфейса */
  --accent: #7ba3f5;
  --accent-hover: #9cbaf2;
  --accent-fg: #0e1113;
  --accent-subtle: #1a2028;
  --accent-graphic: #6d9bef;

  --success: #8fa97c;
  --success-subtle: #191d16;
  --warning: #d5a56a;
  --warning-subtle: #241d14;
  --error: #d97b6e;
  --error-subtle: #241816;

  --sh-card: 0 1px 2px rgb(0 0 0 / 0.4), 0 4px 16px rgb(0 0 0 / 0.5);
  --sh-hover: 0 2px 4px rgb(0 0 0 / 0.45), 0 12px 32px rgb(0 0 0 / 0.6);
  --sh-modal: 0 24px 64px rgb(0 0 0 / 0.7);

  --tint: #16191c;
  --contrast: #212529;
  --on-contrast: #f2ede6;
  --brand-deep: #1a2028;
  --brand-deep-fg: #f2ede6;

  --scrim: rgb(0 0 0 / 0.65);
  --scrim-strong: rgb(0 0 0 / 0.95);
  --on-scrim: #ffffff;
  --on-scrim-hover: rgb(255 255 255 / 0.2);

  --logo-color: #f2ede6;

  --badge-base: #16191c;
  --badge-ink: #f2ede6;

  color-scheme: dark;
}

/* ---------- База ---------- */

* { margin: 0; padding: 0; box-sizing: border-box; }

html { -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--fg);
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.005em;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent-subtle); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Каркас ---------- */

.shell { display: flex; min-height: 100vh; }

/* Сайдбар — как шапка основного сайта: фон страницы,
   логотип в цвете --logo-color, волосяная граница */
.sidebar {
  width: 264px;
  flex-shrink: 0;
  background: var(--bg);
  color: var(--fg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 28px 20px 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: block; padding: 0 6px; color: var(--logo-color); }
.brand-logo { display: block; width: 100%; max-width: 196px; height: auto; }

.side-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  margin: 34px 6px 10px;
}

/* Обёртка меню: на десктопе — колонка на всю высоту сайдбара,
   на мобильном превращается в выпадающую панель под шапкой */
.side-menu { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.side-mobile { display: none; }

.nav-burger {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: var(--radius-md);
  background: transparent; color: var(--fg-muted);
  cursor: pointer;
  transition: color .2s var(--ease-out-quart), background .2s var(--ease-out-quart);
}
.nav-burger:hover { color: var(--fg); background: var(--surface-hover); }
.nav-burger svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.nav-burger .icon-close { display: none; }
.sidebar.menu-open .nav-burger .icon-burger { display: none; }
.sidebar.menu-open .nav-burger .icon-close { display: block; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  color: var(--fg-muted);
  font-weight: 500;
  font-size: 14.5px;
  transition: background .2s var(--ease-out-quart), color .2s var(--ease-out-quart);
  position: relative;
}
/* Тач-цель ≥ 44px без изменения визуального размера */
.nav-item::after { content: ''; position: absolute; inset: -2px 0; }
.nav-item svg { width: 20px; height: 20px; fill: currentColor; opacity: .9; flex-shrink: 0; }
.nav-item:hover {
  background: var(--surface-hover);
  color: var(--fg);
  text-decoration: none;
}
.nav-item.active {
  background: var(--accent-subtle);
  color: var(--accent);
  font-weight: 600;
}
[data-theme="dark"] .nav-item.active { color: var(--accent-hover); }

.side-bottom { margin-top: auto; padding: 0 6px; }
.side-quote {
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  line-height: 1.6;
  margin-bottom: 18px;
}
.logout {
  display: flex; align-items: center; gap: 10px;
  color: var(--fg-muted);
  font-weight: 500; font-size: 14px;
  transition: color .2s var(--ease-out-quart);
  position: relative;
}
.logout::after { content: ''; position: absolute; inset: -8px 0; }
.logout svg { width: 18px; height: 18px; fill: currentColor; }
.logout:hover { color: var(--fg); text-decoration: none; }

/* ---------- Контент ---------- */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 26px 34px 0;
}
.eyebrow {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--fg-muted);
}
.page-title {
  font-family: var(--font-tight);
  font-weight: 700;
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  line-height: 1.15;
  letter-spacing: 0;
  color: var(--fg);
  margin-top: 2px;
}

.topbar-side { display: flex; align-items: center; gap: 12px; }

/* Как на основном сайте: голый значок без рамки —
   залитая луна в светлой теме, контурное солнце в тёмной */
.theme-toggle {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--fg-muted);
  cursor: pointer;
  transition: color .2s var(--ease-out-quart), background .2s var(--ease-out-quart);
}
.theme-toggle:hover { color: var(--fg); background: var(--surface-hover); }
.theme-toggle svg { width: 22px; height: 22px; }
.theme-toggle .icon-moon { fill: currentColor; stroke: none; }
.theme-toggle .icon-sun { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

.user-chip {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 7px 18px 7px 8px;
  box-shadow: var(--sh-card);
}
.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg); font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.user-meta { line-height: 1.2; }
.user-name { display: block; font-weight: 600; font-size: 14px; }
.user-role { display: block; font-size: 12px; color: var(--fg-muted); letter-spacing: 0; }

.content { padding: 24px 34px 44px; display: flex; flex-direction: column; gap: 20px; }

/* ---------- KPI ---------- */

.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  box-shadow: var(--sh-card);
}
.kpi-label {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--fg-muted);
}
.kpi-value {
  font-family: var(--font-tight);
  font-size: 34px; font-weight: 700;
  letter-spacing: 0;
  line-height: 1.15;
  margin: 4px 0 2px;
  color: var(--fg);
}
.kpi-money { font-size: 24px; }
.kpi-sub { font-size: 12.5px; color: var(--fg-muted); letter-spacing: 0; }

/* ---------- Карточки и графики ---------- */

/* minmax(0, …): canvas графика имеет собственную ширину, и без нулевого
   минимума колонка не сжимается под узкий экран — карточки вылезают за край */
.cards-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
.cards-2-wide { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.cards-2 > * { min-width: 0; }

.card {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--sh-card);
  padding: 22px 24px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.card-title {
  font-family: var(--font-tight);
  font-weight: 600; font-size: 17px;
  letter-spacing: 0;
  color: var(--fg);
}
.legend { font-size: 12.5px; color: var(--fg-muted); display: flex; align-items: center; gap: 6px; letter-spacing: 0; }
.legend .dot { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 10px; }
.dot-accent { background: var(--accent-graphic); }
.dot-success { background: var(--success); }

.chart-box { height: 280px; position: relative; min-width: 0; width: 100%; }
.chart-box-donut { height: 280px; display: flex; align-items: center; justify-content: center; }
.chart-box canvas { max-width: 100%; }

/* ---------- Воронка по этапам (HTML, без canvas) ----------
   Каждая воронка — своя секция с заголовком и счётом «первый → последний
   этап». Пустые этапы не рендерятся (свёрнуты на сервере). Между активными
   ступенями — конверсия перехода. «Не в работе» — приглушённые бары. */

.funnel { display: flex; flex-direction: column; gap: 22px; }

.funnel-group-head {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--fg-muted);
  padding-bottom: 8px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.funnel-range { color: var(--fg-subtle); letter-spacing: 0.06em; }

.funnel-row {
  display: grid;
  grid-template-columns: minmax(120px, 176px) minmax(0, 1fr);
  gap: 14px;
  align-items: center;
}
.funnel-label {
  font-size: 13px;
  color: var(--fg-muted);
  line-height: 1.3;
  overflow-wrap: anywhere; /* длинные названия из CRM переносим, не режем */
}
.funnel-track { min-width: 0; }
.funnel-bar {
  min-width: 42px;
  max-width: 100%;
  box-sizing: border-box;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-tight);
  font-weight: 700; font-size: 14px;
  line-height: 1.2;
  transition: width .5s var(--ease-out-expo);
}
.funnel-bar-accent { background: var(--accent-graphic); color: var(--accent-fg); }
.funnel-bar-success { background: var(--success); color: var(--fg-inverse); }
.funnel-bar-muted {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  color: var(--fg-muted);
}

.funnel-conv {
  display: grid;
  grid-template-columns: minmax(120px, 176px) minmax(0, 1fr);
  gap: 14px;
}
.funnel-conv span {
  grid-column: 2;
  font-size: 12px;
  color: var(--fg-muted);
  padding: 3px 0;
}

.funnel-empty { color: var(--fg-muted); font-size: 14px; padding: 8px 0 4px; }

@media (max-width: 560px) {
  .funnel-row, .funnel-conv { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .funnel-conv span { grid-column: 1; }
  .funnel-label { font-size: 12.5px; }
}

/* ---------- Таблицы ---------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--fg-muted);
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 14px;
}
.table tbody tr { transition: background .2s var(--ease-out-quart); }
.table tbody tr:hover { background: var(--surface-hover); }
.table-compact th, .table-compact td { padding: 7px 10px; font-size: 13px; }
.td-name { font-weight: 600; max-width: 380px; }
.ta-r { text-align: right; }
.nowrap { white-space: nowrap; }
.muted { color: var(--fg-muted); font-weight: 400; }
.small { font-size: 12.5px; }
.commission { font-weight: 700; color: var(--fg); }
.strike { text-decoration: line-through; color: var(--fg-muted); font-weight: 400; }
.empty-row { text-align: center; color: var(--fg-muted); padding: 34px !important; }
.row-agent { background: var(--accent-subtle); }

/* Бейдж статуса: цвет приходит из CRM в --bc,
   смешиваем с поверхностью текущей темы, не с белым */
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0;
  background: color-mix(in srgb, var(--bc, var(--fg-muted)) 16%, var(--badge-base));
  color: color-mix(in srgb, var(--bc, var(--fg-muted)) 60%, var(--badge-ink));
  border: 1px solid color-mix(in srgb, var(--bc, var(--fg-muted)) 34%, var(--badge-base));
  white-space: nowrap;
}

.pay { font-weight: 600; font-size: 13px; }
.pay-done { color: var(--success); }
.pay-wait { color: var(--warning); }
.pay-none { color: var(--fg-muted); font-weight: 500; }

/* ---------- Формы и кнопки ---------- */

.btn {
  font-family: var(--font-sans);
  border: 1px solid transparent;
  cursor: pointer;
  border-radius: var(--radius-md);
  font-weight: 600; font-size: 14px;
  letter-spacing: 0;
  padding: 12px 22px;
  transition: background .2s var(--ease-out-quart), color .2s var(--ease-out-quart), border-color .2s var(--ease-out-quart), transform .05s;
  display: inline-block;
  text-align: center;
  position: relative;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }

/* Основное действие */
.btn-orange, .btn-blue { background: var(--accent); color: var(--accent-fg); }
.btn-orange:hover, .btn-blue:hover { background: var(--accent-hover); }

/* Положительное действие (например, «оплачено») */
.btn-green { background: var(--success-subtle); color: var(--success); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.btn-green:hover { border-color: var(--success); }

.btn-danger { background: var(--error-subtle); color: var(--error); border-color: color-mix(in srgb, var(--error) 25%, transparent); }
.btn-danger:hover { border-color: var(--error); }

.btn-ghost { background: var(--tint); color: var(--fg); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-hover); border-color: var(--border-strong); }
[data-theme="dark"] .btn-ghost:hover { background: var(--surface-hover); }

.btn-block { width: 100%; }
.btn-mini { padding: 7px 14px; font-size: 12.5px; border-radius: var(--radius-sm); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--fg-muted);
}
/* Поля ввода не меньше 16px: иначе iOS зумит страницу при фокусе */
.field input, .field select, .input-search, .input-select {
  font-family: var(--font-sans);
  font-size: 16px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--fg);
  outline: none;
  transition: border-color .2s var(--ease-out-quart), box-shadow .2s var(--ease-out-quart);
}
.field input:focus, .field select:focus, .input-search:focus, .input-select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}
.field input:disabled { background: var(--bg-subtle); color: var(--fg-muted); }
.field input::placeholder, .input-search::placeholder { color: var(--fg-subtle); }

.form-grid { display: flex; flex-direction: column; gap: 14px; max-width: 420px; }

.table-tools { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.input-search { min-width: 220px; padding: 9px 14px; }
.input-select { padding: 9px 12px; }
.input-cell {
  font-family: var(--font-sans);
  width: 100%; min-width: 90px;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 16px;
  background: var(--surface);
  color: var(--fg);
  transition: border-color .2s var(--ease-out-quart);
}
.input-cell:focus { border-color: var(--accent); outline: none; }
.input-num { max-width: 110px; }
.inline-form { display: inline-block; }

.alert {
  border-radius: var(--radius-md);
  padding: 13px 18px;
  font-size: 14px;
  border: 1px solid;
}
.alert-ok   { background: var(--success-subtle); color: var(--success); border-color: color-mix(in srgb, var(--success) 30%, transparent); }
.alert-err  { background: var(--error-subtle);   color: var(--error);   border-color: color-mix(in srgb, var(--error) 30%, transparent); }
.alert-demo { background: var(--warning-subtle); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }

.agent-switch {
  display: flex; align-items: center; gap: 12px;
  font-weight: 500; color: var(--fg-muted); font-size: 14px;
}

.conn-info { display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
.diag-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 18px; }
.diag-title {
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--fg);
  margin-bottom: 10px;
}
.new-user { margin-top: 26px; border-top: 1px solid var(--border-strong); padding-top: 20px; }
.new-user-form {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  align-items: end;
}
.cards-settings .card { align-self: start; }

/* ---------- Академия ---------- */

.academy-intro {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; flex-wrap: wrap;
}
.academy-intro-text { max-width: 640px; }
.academy-intro-text p { margin-top: 8px; color: var(--fg-muted); font-size: 14.5px; }
.academy-progress { text-align: center; padding: 0 14px; }
.academy-progress-num {
  font-family: var(--font-tight);
  font-size: 34px; font-weight: 700; color: var(--fg); letter-spacing: 0;
}
.academy-progress-label {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--fg-muted);
}

.academy-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}
.video-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--sh-card);
  overflow: hidden;
  cursor: pointer;
  transition: transform .3s var(--ease-out-expo), box-shadow .3s var(--ease-out-expo);
}
.video-card:hover { transform: translateY(-3px); box-shadow: var(--sh-hover); }
.video-soon { cursor: default; }
.video-soon:hover { transform: none; box-shadow: var(--sh-card); }

/* Обложка видео — фирменная глубокая синяя плоскость со знаком */
.video-thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--brand-deep);
  color: var(--brand-deep-fg);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
}
.video-thumb-mark {
  position: absolute; width: 54%; height: auto;
  right: -10%; bottom: -20%;
  opacity: .14; transform: rotate(10deg);
  color: var(--brand-deep-fg);
}
.video-num {
  position: absolute; top: 12px; left: 16px;
  font-size: 13px; font-weight: 600;
  letter-spacing: 0.14em;
  color: color-mix(in srgb, var(--brand-deep-fg) 55%, transparent);
}
.video-play {
  width: 62px; height: 62px; border-radius: 50%;
  background: color-mix(in srgb, var(--brand-deep-fg) 16%, transparent);
  border: 1.5px solid color-mix(in srgb, var(--brand-deep-fg) 45%, transparent);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  transition: transform .3s var(--ease-out-expo), background .2s var(--ease-out-quart);
  z-index: 1;
}
.video-play svg { width: 28px; height: 28px; fill: var(--brand-deep-fg); margin-left: 3px; }
.video-card:hover .video-play {
  transform: scale(1.08);
  background: color-mix(in srgb, var(--brand-deep-fg) 26%, transparent);
}
.video-soon-badge {
  padding: 8px 22px; border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--brand-deep-fg) 35%, transparent);
  color: color-mix(in srgb, var(--brand-deep-fg) 75%, transparent);
  font-size: 12px; font-weight: 600;
  letter-spacing: 0.16em; text-transform: uppercase;
  z-index: 1;
}
.video-duration {
  position: absolute; right: 12px; bottom: 10px;
  background: var(--scrim);
  color: var(--on-scrim); font-size: 12px; font-weight: 600;
  padding: 3px 10px; border-radius: var(--radius-sm);
}
.video-body { padding: 16px 18px 18px; }
.video-title { font-family: var(--font-tight); font-weight: 600; font-size: 16px; line-height: 1.35; letter-spacing: 0; color: var(--fg); }
.video-desc { margin-top: 7px; font-size: 13.5px; color: var(--fg-muted); line-height: 1.5; }

/* Модальный плеер */
.player-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--scrim-strong);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
}
.player-overlay[hidden] { display: none; }
.player-box { width: 100%; max-width: 960px; }
.player-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 10px;
}
.player-title {
  font-family: var(--font-tight);
  color: var(--on-scrim); font-weight: 600; font-size: 17px;
  letter-spacing: 0;
}
.player-close {
  background: none; border: none; cursor: pointer;
  color: color-mix(in srgb, var(--on-scrim) 70%, transparent);
  font-size: 34px; line-height: 1;
  width: 44px; height: 44px;
  transition: color .2s var(--ease-out-quart);
}
.player-close:hover { color: var(--on-scrim); }
.player-frame {
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.player-frame iframe, .player-frame video { width: 100%; height: 100%; border: 0; display: block; }

/* ---------- Страница входа ---------- */

/* Фирменная глубокая синяя плоскость на всю высоту */
.login-body {
  min-height: 100vh;
  background: var(--brand-deep);
  display: flex; align-items: center; justify-content: center;
  padding: 30px 18px;
  padding-bottom: calc(30px + env(safe-area-inset-bottom));
  position: relative;
  overflow: hidden;
}
.login-mark-bg {
  position: absolute; pointer-events: none;
  color: var(--brand-deep-fg);
  opacity: .05;
}
.login-mark-a { width: 420px; top: -90px; right: -80px; transform: rotate(12deg); }
.login-mark-b { width: 340px; bottom: -110px; left: -70px; transform: rotate(-24deg); }
.login-mark-bg svg { width: 100%; height: auto; display: block; }

.login-wrap { width: 100%; max-width: 420px; text-align: center; position: relative; }
.login-brand { color: var(--brand-deep-fg); display: flex; justify-content: center; }
.login-logo { width: 240px; max-width: 70%; height: auto; }
.login-tag {
  font-size: 11px; font-weight: 600;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: color-mix(in srgb, var(--brand-deep-fg) 50%, transparent);
  margin-top: 18px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 30px 30px 24px;
  margin-top: 26px;
  display: flex; flex-direction: column; gap: 16px;
  text-align: left;
  box-shadow: var(--sh-modal);
}
.login-title {
  font-family: var(--font-tight);
  font-weight: 700; font-size: 22px;
  letter-spacing: 0;
  color: var(--fg);
  text-align: center;
}
.login-hint { font-size: 12.5px; color: var(--fg-muted); text-align: center; }
.login-footer {
  margin-top: 26px;
  font-size: 11px; font-weight: 500;
  letter-spacing: 0.18em; text-transform: uppercase;
  color: color-mix(in srgb, var(--brand-deep-fg) 35%, transparent);
}
.login-theme-toggle {
  position: absolute; top: 18px; right: 18px; z-index: 2;
  color: color-mix(in srgb, var(--brand-deep-fg) 65%, transparent);
}
.login-theme-toggle:hover {
  color: var(--brand-deep-fg);
  background: color-mix(in srgb, var(--brand-deep-fg) 10%, transparent);
}

/* ---------- Адаптив ---------- */

@media (max-width: 1180px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cards-2, .cards-2-wide { grid-template-columns: minmax(0, 1fr); }
  .diag-cols { grid-template-columns: 1fr; }
  .new-user-form { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .card { padding: 18px 16px; }
  .chart-box, .chart-box-donut { height: 240px; }
  /* Шапка как на основном сайте: логотип слева, тема и бургер справа,
     пункты меню — в выпадающем списке */
  .sidebar {
    width: 100%; height: auto;
    position: sticky; top: 0; z-index: 60;
    flex-direction: row; align-items: center; justify-content: space-between;
    gap: 10px; padding: 10px 16px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .sidebar { border-right: none; border-bottom: 1px solid var(--border); }
  .brand-logo { max-width: 150px; }
  .side-mobile { display: flex; align-items: center; gap: 2px; }
  .side-quote { display: none; }

  .side-menu {
    position: absolute;
    top: 100%; left: 0; right: 0;
    flex-direction: column;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--sh-hover);
    padding: 6px 16px 16px;
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
    opacity: 0;
    transform: translateY(-8px);
    pointer-events: none;
    transition: opacity .25s var(--ease-out-quart), transform .35s var(--ease-out-expo);
  }
  .sidebar.menu-open .side-menu { opacity: 1; transform: none; pointer-events: auto; }
  .side-label { margin: 10px 6px 8px; }
  .nav-item { padding: 12px 12px; }
  .side-bottom { margin-top: 10px; padding-top: 12px; border-top: 1px solid var(--border); }
  .logout { padding: 6px 12px; }
  /* На мобильном тема переключается из шапки, дубль в топбаре не нужен */
  .topbar .theme-toggle { display: none; }
  .topbar { padding: 20px 18px 0; flex-wrap: wrap; gap: 12px; }
  .content { padding: 16px 18px 34px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .kpi-value { font-size: 26px; }
  .new-user-form { grid-template-columns: 1fr; }
  /* Страховка от горизонтального скролла: именно clip, а не hidden —
     hidden на html/body превращает body в скролл-контейнер
     и полностью ломает тач-прокрутку страницы */
  html, body { max-width: 100%; overflow-x: clip; }
}
@media (max-width: 520px) {
  .kpi-grid { grid-template-columns: minmax(0, 1fr); }
  .user-chip { display: none; }
  .chart-box, .chart-box-donut { height: 220px; }
  .content { gap: 14px; }
}

/* prefers-reduced-motion отключает всё */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* ============ Карточка сделки ============ */

.back-link {
  display: inline-block; margin-bottom: 14px; color: var(--accent);
  text-decoration: none; font-weight: 600; font-size: 14px;
}
.back-link:hover { text-decoration: underline; }

/* Шкала этапов воронки */
/* Сетка с фиксированным числом колонок в ряду (а не flex-wrap):
   только так известно, какой этап начинает новый ряд, — у него линия
   связи убирается, иначе она уходит за левый край карточки. */
.stage-track {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  row-gap: 18px;
  padding: 6px 0 2px;
}
.stage-step {
  position: relative;
  text-align: center; padding: 0 6px 4px;
  min-width: 0;
}
/* Линия к предыдущему этапу: от центра соседа до центра этого шага */
.stage-step::before {
  content: ''; position: absolute; top: 9px; left: -50%; width: 100%; height: 3px;
  background: var(--border); z-index: 0;
}
/* Первый в ряду — линии слева нет (число в nth-child = числу колонок) */
.stage-track .stage-step:nth-child(5n + 1)::before { display: none; }
.stage-step.done::before, .stage-step.current::before { background: var(--sc); }
.stage-dot {
  position: relative; z-index: 1; width: 20px; height: 20px; margin: 0 auto 8px;
  border-radius: 50%; background: var(--surface); border: 3px solid var(--border);
}
.stage-step.done .stage-dot { background: var(--sc); border-color: var(--sc); }
.stage-step.current .stage-dot {
  background: var(--surface); border-color: var(--sc);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--sc) 25%, transparent);
}
.stage-name {
  font-size: 12px; color: var(--fg-muted); line-height: 1.25;
  overflow-wrap: anywhere; /* длинные названия этапов из CRM не наезжают друг на друга */
}
.stage-step.current .stage-name { color: var(--fg); font-weight: 600; }
.stage-step.done .stage-name { color: var(--fg-muted); }

/* Данные сделки */
.cards-deal { align-items: start; }
.deal-meta { display: flex; flex-direction: column; gap: 10px; }
.dm-row { display: flex; justify-content: space-between; gap: 14px; font-size: 14px; }
.dm-row span { color: var(--fg-muted); }
.dm-row b a { color: var(--accent); text-decoration: none; }
.dm-row b a:hover { text-decoration: underline; }
.dm-tags { align-items: flex-start; }
.dm-tags > div { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.dm-sep { height: 1px; background: var(--border); margin: 4px 0; }
.tag-chip {
  display: inline-block; padding: 2px 10px; border-radius: var(--radius-sm);
  background: var(--accent-subtle); color: var(--accent); font-size: 12px; font-weight: 600;
  white-space: nowrap;
}

/* История этапов */
.history-list { display: flex; flex-direction: column; }
.history-item {
  padding: 10px 0; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}
.history-item:last-child { border-bottom: none; }
.history-date { font-size: 12px; color: var(--fg-muted); }
.history-move { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.history-arrow { color: var(--fg-muted); }

/* Комментарии из CRM */
.notes-list { display: flex; flex-direction: column; }
.note-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.note-item:last-child { border-bottom: none; }
.note-head { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 6px; }
.note-type {
  padding: 2px 10px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 600;
  background: var(--accent-subtle); color: var(--accent);
}
.note-type.nt-call_in, .note-type.nt-call_out { background: var(--success-subtle); color: var(--success); }
.note-type.nt-sms_in, .note-type.nt-sms_out { background: var(--warning-subtle); color: var(--warning); }
.note-item.note-system .note-type { background: var(--bg-subtle); color: var(--fg-muted); }
.note-author { font-weight: 600; font-size: 13px; color: var(--fg); }
.note-date { font-size: 12px; }
.note-body { font-size: 14px; line-height: 1.55; color: var(--fg); white-space: pre-line; }
.note-item.note-system .note-body { color: var(--fg-muted); font-size: 13px; }
.notes-hint { margin-top: 10px; }
.check-label {
  display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--fg-muted);
  cursor: pointer; user-select: none;
}

/* Привязка сделок */
.assign-self-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 10px; }
.assign-self-form .field.grow { flex: 1 1 320px; }
.assign-row { display: flex; gap: 6px; align-items: center; }
.assign-row select { max-width: 220px; }

@media (max-width: 1180px) {
  .stage-track { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stage-track .stage-step:nth-child(5n + 1)::before { display: block; }
  .stage-track .stage-step:nth-child(4n + 1)::before { display: none; }
}
@media (max-width: 860px) {
  .stage-track { grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 16px; }
  .stage-track .stage-step:nth-child(4n + 1)::before { display: block; }
  .stage-track .stage-step:nth-child(3n + 1)::before { display: none; }
  .stage-name { font-size: 11.5px; }
}
@media (max-width: 520px) {
  .stage-track { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stage-track .stage-step:nth-child(3n + 1)::before { display: block; }
  .stage-track .stage-step:nth-child(2n + 1)::before { display: none; }
}

@media (max-width: 760px) {
  .dm-row { flex-direction: column; gap: 2px; }
  .dm-tags > div { justify-content: flex-start; }
}
