/* ═══════════════════════════════════════════════════════════
   ИНТЕРФЕЙС CRM
   Построен на tokens.css. Сырые цвета здесь не используются.
   ═══════════════════════════════════════════════════════════ */

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

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
ul, ol { list-style: none; }
table { border-collapse: collapse; width: 100%; }

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

/* Числа выравниваем по разрядам — суммы в колонку читаются мгновенно */
.num, td.num, .metric-value, .plan-price {
  font-variant-numeric: tabular-nums;
}

/* ═══════════════════════════════════════════════════════════
   ЛОГОТИП
   ═══════════════════════════════════════════════════════════ */
.logo { display: flex; align-items: center; gap: 9px; }

/* Знак наследует цвет от .logo — на тёмном фоне достаточно
   переопределить color, отдельная светлая версия не нужна. */
.logo { color: var(--accent); }
.logo-mark { width: 26px; height: 26px; flex-shrink: 0; }

/* ARTELO — латиница, поэтому положительный трекинг: без него
   заглавные слипаются. Кириллические заголовки живут на -0.02em,
   здесь наоборот. */
.logo-text {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 17px;
  letter-spacing: 0.055em;
  color: var(--text);
  white-space: nowrap;
}
.logo-text span { color: var(--accent); }

/* Приписка CRM — тише основного слова, чтобы читалось «ARTELO», а не «ARTELO CRM» */
.logo-suffix {
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.09em;
  color: var(--text-3);
  margin-left: 1px;
}

/* ═══════════════════════════════════════════════════════════
   КАРКАС
   ═══════════════════════════════════════════════════════════ */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 100;
}

.sidebar-head {
  padding: var(--s-5) var(--s-4) var(--s-4);
  border-bottom: 1px solid var(--border);
}

.sidebar-org {
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.sidebar-org-name {
  font-weight: 600;
  font-size: var(--fs-sm);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-org-plan {
  font-size: var(--fs-2xs);
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 2px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--s-3) var(--s-2);
}

.nav-section {
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-3);
  padding: var(--s-4) var(--s-3) var(--s-2);
}
.nav-section:first-child { padding-top: var(--s-1); }

.nav-link {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-radius: var(--r);
  font-size: var(--fs-md);
  color: var(--text-2);
  transition: background var(--t-fast), color var(--t-fast);
  position: relative;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active {
  background: var(--accent-soft);
  color: var(--brand-600);
  font-weight: 600;
}
.nav-link.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.nav-icon { width: 18px; text-align: center; font-size: var(--fs-md); flex-shrink: 0; }

.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: var(--n-0);
  font-size: var(--fs-2xs);
  font-weight: 600;
  min-width: 19px;
  height: 19px;
  padding: 0 6px;
  border-radius: var(--r-full);
  display: flex; align-items: center; justify-content: center;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-4);
  border-top: 1px solid var(--border);
}
.user-avatar {
  width: 32px; height: 32px;
  border-radius: var(--r-full);
  background: var(--brand-500);
  color: var(--n-0);
  display: flex; align-items: center; justify-content: center;
  font-weight: 600;
  font-size: var(--fs-sm);
  flex-shrink: 0;
}
.user-name { font-size: var(--fs-sm); font-weight: 500; line-height: 1.3; }
.user-role { font-size: var(--fs-xs); color: var(--text-3); }
.sidebar-logout {
  margin-left: auto;
  background: none; border: none; cursor: pointer;
  color: var(--text-3);
  padding: var(--s-2);
  border-radius: var(--r-sm);
  font-size: var(--fs-lg);
  line-height: 1;
}
.sidebar-logout:hover { background: var(--surface-2); color: var(--danger); }

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  flex-shrink: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: 0 var(--s-8);
  position: sticky;
  top: 0;
  z-index: 50;
}
.page-title {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.topbar-actions { display: flex; align-items: center; gap: var(--s-2); }

.content { padding: var(--s-6) var(--s-8) var(--s-12); flex: 1; }

/* ═══════════════════════════════════════════════════════════
   КАРТОЧКИ
   ═══════════════════════════════════════════════════════════ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  margin-bottom: var(--s-5);
}
.card-flush { padding: 0; overflow: hidden; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  margin-bottom: var(--s-4);
}
.card-title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.01em;
}
.card-label {
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-3);
  margin-bottom: var(--s-2);
}

/* ═══════════════════════════════════════════════════════════
   КНОПКИ
   ═══════════════════════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  padding: 9px 16px;
  border-radius: var(--r);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-md);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
}
.btn:hover { background: var(--surface-2); border-color: var(--n-300); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--n-0);
  font-weight: 600;
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-danger { border-color: var(--border-strong); color: var(--danger); }
.btn-danger:hover { background: var(--danger); border-color: var(--danger); color: var(--n-0); }

.btn-sm { padding: 6px 11px; font-size: var(--fs-sm); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:disabled:hover { background: var(--surface); border-color: var(--border-strong); }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  border-radius: var(--r-sm);
  border: none; background: none;
  color: var(--text-3);
  cursor: pointer;
  font-size: var(--fs-md);
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon.danger:hover { background: var(--danger-bg); color: var(--danger); }

/* ═══════════════════════════════════════════════════════════
   БЕЙДЖИ
   ═══════════════════════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
}
.badge-neutral { background: var(--surface-2); color: var(--text-2); }
.badge-ok      { background: var(--ok-bg);     color: var(--ok); }
.badge-warn    { background: var(--warn-bg);   color: var(--warn); }
.badge-danger  { background: var(--danger-bg); color: var(--danger); }
.badge-info    { background: var(--info-bg);   color: var(--info); }

/* Статусы договоров */
.st-draft       { background: var(--surface-2); color: var(--text-2); }
.st-negotiation { background: var(--warn-bg);   color: var(--warn); }
.st-signed      { background: var(--info-bg);   color: var(--info); }
.st-active      { background: var(--ok-bg);     color: var(--ok); }
.st-expired     { background: var(--danger-bg); color: var(--danger); }
.st-terminated  { background: var(--surface-2); color: var(--text-3); }

/* ═══════════════════════════════════════════════════════════
   ТАБЛИЦЫ
   ═══════════════════════════════════════════════════════════ */
.table-wrap { overflow-x: auto; }

thead th {
  text-align: left;
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: var(--surface);
}

tbody td {
  padding: 0 var(--s-4);
  height: var(--row-h);
  font-size: var(--fs-sm);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }

.cell-strong { font-weight: 600; color: var(--text); }
.cell-muted  { color: var(--text-2); }
.cell-right  { text-align: right; }

/* ═══════════════════════════════════════════════════════════
   ФОРМЫ
   ═══════════════════════════════════════════════════════════ */
.form-group { margin-bottom: var(--s-4); }

.form-label, label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 6px;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  color: var(--text);
  padding: 9px 12px;
  font-size: var(--fs-md);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  outline: none;
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-3); }

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-input:disabled, .form-select:disabled { background: var(--surface-2); color: var(--text-3); }

.form-select {
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='none' stroke='%23787064' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M1 1.5 6 6.5l5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
select[multiple].form-select { background-image: none; padding-right: 12px; }

.form-textarea { resize: vertical; min-height: 84px; line-height: 1.55; }

.form-help  { font-size: var(--fs-xs); color: var(--text-3); margin-top: 5px; }
.form-error { font-size: var(--fs-xs); color: var(--danger); margin-top: 5px; }
.req { color: var(--danger); }

.form-checkbox, input[type="checkbox"] {
  width: 16px; height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: var(--s-3);
  margin-top: var(--s-6);
  padding-top: var(--s-5);
  border-top: 1px solid var(--border);
}

.filters { display: flex; gap: var(--s-2); align-items: center; flex-wrap: wrap; }
.search-input {
  min-width: 240px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  padding: 8px 12px;
  font-size: var(--fs-md);
  outline: none;
}
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ═══════════════════════════════════════════════════════════
   ПУСТЫЕ СОСТОЯНИЯ / СООБЩЕНИЯ
   ═══════════════════════════════════════════════════════════ */
.empty { text-align: center; padding: var(--s-12) var(--s-4); }
.empty-icon { font-size: 34px; opacity: 0.4; margin-bottom: var(--s-3); }
.empty-text { color: var(--text-2); margin-bottom: var(--s-4); }
.empty-actions { display: flex; flex-direction: column; gap: var(--s-2); margin-top: var(--s-6); }

.messages-list {
  position: fixed;
  top: var(--s-5); right: var(--s-5);
  z-index: 1000;
  display: flex; flex-direction: column; gap: var(--s-2);
}
.message {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--text-3);
  border-radius: var(--r);
  padding: var(--s-3) var(--s-4);
  font-size: var(--fs-sm);
  max-width: 340px;
  box-shadow: var(--shadow-pop);
  animation: slide-in 160ms ease;
}
.message.success { border-left-color: var(--ok); }
.message.error   { border-left-color: var(--danger); }
.message.warning { border-left-color: var(--warn-tint); }

@keyframes slide-in { from { opacity: 0; transform: translateX(12px); } }

/* Статичное сообщение внутри страницы */
.notice {
  border-radius: var(--r);
  padding: var(--s-3) var(--s-4);
  font-size: var(--fs-sm);
  margin-bottom: var(--s-4);
  border: 1px solid;
}
.notice-warn   { background: var(--warn-bg);   border-color: var(--warn-tint); color: var(--warn); }
.notice-danger { background: var(--danger-bg); border-color: var(--danger);    color: var(--danger); }
.notice-info   { background: var(--info-bg);   border-color: var(--info);      color: var(--info); }

/* Баннер пробного периода */
.trial-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  background: var(--warn-bg);
  border: 1px solid var(--warn-tint);
  border-radius: var(--r);
  padding: var(--s-3) var(--s-4);
  font-size: var(--fs-sm);
  margin-bottom: var(--s-5);
}

/* ═══════════════════════════════════════════════════════════
   МЕТРИКИ
   ═══════════════════════════════════════════════════════════ */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: var(--s-4);
  margin-bottom: var(--s-5);
}

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-4) var(--s-5);
}
.metric-label {
  font-size: var(--fs-xs);
  color: var(--text-2);
  margin-bottom: var(--s-2);
}
.metric-value {
  font-family: var(--font-display);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.15;
}
.metric-sub { font-size: var(--fs-xs); color: var(--text-3); margin-top: 5px; }
.metric-delta { font-size: var(--fs-xs); font-weight: 600; margin-top: 5px; }
.delta-up   { color: var(--ok); }
.delta-down { color: var(--danger); }
.delta-flat { color: var(--text-3); }

/* ═══════════════════════════════════════════════════════════
   УТИЛИТЫ
   ═══════════════════════════════════════════════════════════ */
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s-4); }
.text-muted { color: var(--text-2); }
.text-dim   { color: var(--text-3); }
.text-accent{ color: var(--accent); }
.fw-600 { font-weight: 600; }
.mb-4 { margin-bottom: var(--s-4); }
.mt-4 { margin-top: var(--s-4); }
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--s-5);
  align-items: start;   /* карточки по высоте содержимого, а не по самой высокой */
}

/* ═══════════════════════════════════════════════════════════
   АДАПТИВ
   ═══════════════════════════════════════════════════════════ */
@media (max-width: 1000px) {
  .sidebar { transform: translateX(-100%); transition: transform var(--t); }
  .sidebar.open { transform: none; box-shadow: var(--shadow-modal); }
  .main { margin-left: 0; }
  .topbar { padding: 0 var(--s-4); }
  .content { padding: var(--s-4) var(--s-4) var(--s-10); }
  .nav-toggle { display: inline-flex !important; }
}

.nav-toggle {
  display: none;
  align-items: center; justify-content: center;
  width: 36px; height: 36px;
  border: 1px solid var(--border-strong);
  border-radius: var(--r);
  background: var(--surface);
  cursor: pointer;
}

@media (max-width: 600px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  .metric-value { font-size: 22px; }
  .page-title { font-size: var(--fs-lg); }
  .search-input { min-width: 0; width: 100%; }

  /* Шапка на телефоне переносится на две строки.
     В один ряд «Клиенты» и три кнопки не помещаются: кнопки не
     сжимались и выдавливали заголовок за край, а бургер прижимался
     к самой кромке экрана и обрезался. */
  .topbar {
    height: auto;
    min-height: 56px;
    flex-wrap: wrap;
    align-items: center;
    padding: var(--s-3) var(--s-4);
    gap: var(--s-2);
  }
  .topbar > div:first-child { width: 100%; }
  .topbar-actions { width: 100%; flex-wrap: wrap; }
  /* Кнопки делят строку поровну и не вылезают за экран */
  .topbar-actions .btn { flex: 1 1 auto; justify-content: center; }
  .nav-toggle { flex-shrink: 0; }

  /* Счётчик «5 клиентов» зажимался поиском и ломался на две строки.
     Пускаем строку фильтров и счётчик друг под другом. */
  .flex-between { flex-wrap: wrap; gap: var(--s-2); }
  .filters { width: 100%; }
  .filters .form-select { width: auto; flex: 1 1 auto; }
}

@media print {
  .sidebar, .topbar-actions, .btn { display: none; }
  .main { margin-left: 0; }
}

/* ═══════════════════════════════════════════════════════════
   СТРАНИЦЫ ВХОДА И РЕГИСТРАЦИИ
   ═══════════════════════════════════════════════════════════ */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s-8) var(--s-4);
  background:
    radial-gradient(900px 420px at 50% -8%, var(--accent-soft), transparent 72%),
    var(--bg);
}

.auth-wrap { width: 100%; max-width: 400px; }
.auth-wrap-wide { max-width: 464px; }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--s-8) var(--s-8) var(--s-6);
}
.auth-card-center { text-align: center; }

.auth-logo { justify-content: center; margin-bottom: var(--s-6); }

.auth-title {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 800;
  letter-spacing: -0.03em;
  text-align: center;
  margin-bottom: var(--s-2);
}
.auth-subtitle {
  color: var(--text-2);
  text-align: center;
  margin-bottom: var(--s-6);
}
.auth-footer {
  margin-top: var(--s-5);
  padding-top: var(--s-4);
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: var(--fs-sm);
  color: var(--text-2);
}
.auth-footer a { color: var(--accent); font-weight: 600; }
.auth-footer a:hover { text-decoration: underline; }

/* Согласие 152-ФЗ */
.form-consent { margin: var(--s-5) 0; }
.consent-label {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  font-size: var(--fs-sm);
  font-weight: 400;
  line-height: 1.5;
  color: var(--text-2);
  cursor: pointer;
  margin: 0;
}
.consent-label input[type="checkbox"] { margin-top: 2px; flex-shrink: 0; }
.consent-label a { color: var(--accent); text-decoration: underline; }

/* ═══════════════════════════════════════════════════════════
   ТАРИФЫ
   ═══════════════════════════════════════════════════════════ */
.subscription-status { display: flex; flex-wrap: wrap; gap: var(--s-10); }
.subscription-expired { border-color: var(--danger); }
.subscription-plan {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.subscription-state { font-size: var(--fs-md); }

.plans-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: var(--s-5);
  margin-bottom: var(--s-5);
}
.plan-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-xl);
  padding: var(--s-6);
  display: flex;
  flex-direction: column;
}
.plan-card-featured { border-color: var(--accent); border-width: 2px; }

.plan-badge {
  position: absolute;
  top: -11px; left: var(--s-6);
  background: var(--accent);
  color: var(--n-0);
  font-size: var(--fs-2xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 4px 10px;
  border-radius: var(--r-full);
}
.plan-name {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 700;
  margin-bottom: var(--s-2);
}
.plan-price {
  font-family: var(--font-display);
  font-size: 38px;
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.1;
  margin-bottom: var(--s-5);
}
.plan-currency { font-size: var(--fs-2xl); }
.plan-period {
  font-family: var(--font-ui);
  font-size: var(--fs-md);
  font-weight: 400;
  color: var(--text-2);
}
.plan-features { flex: 1; margin-bottom: var(--s-5); }
.plan-features li {
  position: relative;
  padding-left: var(--s-6);
  font-size: var(--fs-sm);
  color: var(--text-2);
  margin-bottom: var(--s-2);
}
.plan-features li::before {
  content: '';
  position: absolute;
  left: 0; top: 6px;
  width: 14px; height: 9px;
  border-left: 2px solid var(--ok);
  border-bottom: 2px solid var(--ok);
  transform: rotate(-45deg);
}
.plan-note { text-align: center; font-size: var(--fs-xs); color: var(--text-3); margin-top: var(--s-2); }

/* ═══════════════════════════════════════════════════════════
   ГРАФИКИ
   Правила: тонкие метки, ненавязчивая сетка, цифры не на каждой
   точке, текст всегда текстовым цветом (не цветом серии).
   ═══════════════════════════════════════════════════════════ */
.chart { width: 100%; height: 170px; display: block; overflow: visible; }

.chart-grid   { stroke: var(--border); stroke-width: 1; }
.chart-line   { fill: none; stroke: var(--dv-1); stroke-width: 2;
                stroke-linejoin: round; stroke-linecap: round;
                vector-effect: non-scaling-stroke; }
.chart-area   { fill: var(--dv-1); opacity: 0.10; }
.chart-dot    { fill: var(--dv-1); stroke: var(--surface); stroke-width: 2;
                vector-effect: non-scaling-stroke; }
.chart-bar    { fill: var(--dv-3); transition: opacity var(--t-fast); }
.chart-bar:hover { opacity: 0.75; }

.chart-caption { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }
.chart-scale   { font-size: var(--fs-xs); color: var(--text-3); white-space: nowrap; }

.chart-axis {
  display: flex;
  justify-content: space-between;
  margin-top: var(--s-2);
  font-size: var(--fs-2xs);
  color: var(--text-3);
}
.chart-axis .axis-now { color: var(--text); font-weight: 600; }

.chart-empty {
  height: 170px;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  background: var(--surface-2);
  border-radius: var(--r);
  padding: var(--s-4);
}
.chart-empty-title { font-weight: 600; margin-bottom: var(--s-2); }
.chart-empty-text  { font-size: var(--fs-xs); color: var(--text-2); max-width: 300px; line-height: 1.5; }

/* Метрика-герой: главное число крупнее остальных */
.metric-hero { background: var(--brand-800); border-color: var(--brand-800); }
.metric-hero .metric-label { color: var(--brand-200); }
.metric-hero .metric-value { color: var(--n-0); font-size: 32px; }
.metric-hero .metric-sub   { color: var(--brand-200); }

/* Полоса распределения по тарифам: зазор 2px между сегментами */
.stack-bar {
  display: flex;
  gap: 2px;
  height: 10px;
  border-radius: var(--r-full);
  overflow: hidden;
  margin-bottom: var(--s-4);
  background: var(--surface-2);
}
.stack-seg { height: 100%; }

.plan-table td { height: 34px; border: none; padding: 0 var(--s-2); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: var(--r-full); }

.usage-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-4) var(--s-3);
}
.usage-grid > div { display: flex; flex-direction: column; }
.usage-num {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.usage-lbl { font-size: var(--fs-xs); color: var(--text-3); }

@media (max-width: 600px) {
  .usage-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ═══════════════════════════════════════════════════════════
   ЮРИДИЧЕСКИЕ ДОКУМЕНТЫ
   Длинный текст: узкая колонка, крупный кегль, воздух.
   ═══════════════════════════════════════════════════════════ */
.legal-body { background: var(--bg); }

.legal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-4) var(--s-6);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.legal-nav { display: flex; gap: var(--s-5); font-size: var(--fs-sm); }
.legal-nav a { color: var(--text-2); }
.legal-nav a:hover { color: var(--accent); }

.legal-main { max-width: 760px; margin: 0 auto; padding: var(--s-8) var(--s-5) var(--s-16); }

.legal-doc {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-10) var(--s-8);
  font-size: 15px;
  line-height: 1.7;
}
.legal-doc h1 {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 800;
  letter-spacing: -0.025em;
  line-height: 1.25;
  margin-bottom: var(--s-2);
}
.legal-doc h2 {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 700;
  margin: var(--s-8) 0 var(--s-3);
  padding-top: var(--s-4);
  border-top: 1px solid var(--border);
}
.legal-doc h3 {
  font-size: var(--fs-md);
  font-weight: 600;
  margin: var(--s-5) 0 var(--s-2);
}
.legal-doc p { margin-bottom: var(--s-4); }
.legal-doc ul { margin: 0 0 var(--s-4) var(--s-5); }
.legal-doc li { list-style: disc; margin-bottom: var(--s-2); }
.legal-doc a { color: var(--accent); text-decoration: underline; }
.legal-doc code {
  background: var(--surface-2);
  padding: 1px 6px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.legal-meta {
  font-size: var(--fs-sm);
  color: var(--text-3);
  margin-bottom: var(--s-6);
}

.legal-table { margin-bottom: var(--s-4); }
.legal-table th {
  text-align: left;
  font-weight: 500;
  color: var(--text-2);
  padding: var(--s-2) var(--s-4) var(--s-2) 0;
  width: 190px;
  vertical-align: top;
  font-size: 15px;
  text-transform: none;
  letter-spacing: normal;
  border: none;
  background: none;
}
.legal-table td {
  padding: var(--s-2) 0;
  height: auto;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
}

.legal-note {
  background: var(--surface-2);
  border-left: 3px solid var(--warn-tint);
  border-radius: var(--r-sm);
  padding: var(--s-3) var(--s-4);
  font-size: var(--fs-sm);
}

.legal-footer { margin-top: var(--s-6); }

@media (max-width: 600px) {
  .legal-doc { padding: var(--s-6) var(--s-5); }
  .legal-table th { width: auto; display: block; padding-bottom: 0; }
  .legal-table td { display: block; padding-top: 2px; }
}

/* ═══════════════════════════════════════════════════════════
   ДАШБОРД: ВОРОНКА ДОГОВОРОВ
   ═══════════════════════════════════════════════════════════ */
.pipeline {
  display: flex;
  gap: var(--s-3);
  overflow-x: auto;
  padding-bottom: var(--s-2);
}
.pipeline-col {
  flex: 1 0 190px;
  background: var(--surface-2);
  border-radius: var(--r);
  padding: var(--s-3);
}
.pipeline-head { margin-bottom: var(--s-3); }
.pipeline-label {
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-2);
}
.pipeline-count {
  font-size: var(--fs-xs);
  color: var(--text-3);
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.pipeline-deal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--s-3);
  margin-bottom: var(--s-2);
  transition: border-color var(--t-fast);
}
.pipeline-deal:hover { border-color: var(--accent); }
.pipeline-deal-name { font-size: var(--fs-sm); font-weight: 600; line-height: 1.35; }
.pipeline-deal-client { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }
.pipeline-deal-amount {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--ok);
  margin-top: var(--s-2);
  font-variant-numeric: tabular-nums;
}
.pipeline-empty { font-size: var(--fs-xs); color: var(--text-3); text-align: center; padding: var(--s-3) 0; }

/* ═══════════════════════════════════════════════════════════
   ЗАДАЧИ В СПИСКЕ
   ═══════════════════════════════════════════════════════════ */
.task-item {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--border);
}
.task-item:last-child { border-bottom: none; }

.task-check {
  width: 20px; height: 20px;
  flex-shrink: 0;
  margin-top: 1px;
  border: 1.5px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-xs);
  color: transparent;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.task-check:hover { border-color: var(--accent); }
.task-check.done { background: var(--accent); border-color: var(--accent); color: var(--n-0); }

.task-info { flex: 1; min-width: 0; }
.task-title { font-size: var(--fs-md); font-weight: 500; }
.task-title:hover { color: var(--accent); }
.task-title.done { text-decoration: line-through; color: var(--text-3); }
.task-meta { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }
.task-meta.overdue { color: var(--danger); font-weight: 500; }

.badge-low    { background: var(--surface-2); color: var(--text-2); }
.badge-medium { background: var(--info-bg);   color: var(--info); }
.badge-high   { background: var(--danger-bg); color: var(--danger); }

/* ═══════════════════════════════════════════════════════════
   ЛЕНТА СОБЫТИЙ
   ═══════════════════════════════════════════════════════════ */
.activity-item {
  display: flex;
  gap: var(--s-3);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
  width: 30px; height: 30px;
  flex-shrink: 0;
  border-radius: var(--r-full);
  background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-sm);
}
.activity-text { font-size: var(--fs-sm); line-height: 1.45; }
.activity-meta { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }

/* ═══════════════════════════════════════════════════════════
   ПРОСТАЯ СТРОКА СПИСКА (две колонки)
   ═══════════════════════════════════════════════════════════ */
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--border);
}
.list-row:last-child { border-bottom: none; }
.list-row-title { font-size: var(--fs-sm); font-weight: 600; }
.list-row-title:hover { color: var(--accent); }
.list-row-sub { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; }
.list-row-right { text-align: right; flex-shrink: 0; }

.text-right { text-align: right; }
.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }

/* ═══════════════════════════════════════════════════════════
   ДЕТАЛЬНЫЕ СТРАНИЦЫ (клиент, договор, объект, задача)
   ═══════════════════════════════════════════════════════════ */
.detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--s-4);
  flex-wrap: wrap;
  margin-bottom: var(--s-5);
}
.detail-title {
  font-family: var(--font-display);
  font-size: var(--fs-2xl);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
}
.detail-meta {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
  font-size: var(--fs-sm);
  color: var(--text-2);
  margin-top: var(--s-2);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: var(--s-5);
  align-items: start;
}

.info-row {
  display: flex;
  gap: var(--s-4);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--border);
}
.info-row:last-child { border-bottom: none; }
.info-label {
  flex: 0 0 40%;
  max-width: 190px;
  font-size: var(--fs-sm);
  color: var(--text-2);
}
.info-value {
  flex: 1;
  font-size: var(--fs-sm);
  min-width: 0;
  overflow-wrap: anywhere;
}

/* ═══════════════════════════════════════════════════════════
   ФОРМА НА ОТДЕЛЬНОЙ СТРАНИЦЕ
   ═══════════════════════════════════════════════════════════ */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-6);
  max-width: 660px;
}

/* ═══════════════════════════════════════════════════════════
   ПОДТВЕРЖДЕНИЕ УДАЛЕНИЯ
   ═══════════════════════════════════════════════════════════ */
.confirm-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-8);
  max-width: 440px;
  margin: var(--s-10) auto;
  text-align: center;
}
.confirm-icon {
  width: 52px; height: 52px;
  margin: 0 auto var(--s-4);
  border-radius: var(--r-full);
  background: var(--danger-bg);
  color: var(--danger);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-2xl);
}
.confirm-title {
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: 700;
  margin-bottom: var(--s-2);
}
.confirm-text { color: var(--text-2); margin-bottom: var(--s-6); }

/* ═══════════════════════════════════════════════════════════
   НАСТРОЙКИ: ПЛИТКИ РАЗДЕЛОВ
   ═══════════════════════════════════════════════════════════ */
.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--s-4);
}
.settings-tile {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--s-5);
  transition: border-color var(--t-fast), transform var(--t-fast);
}
.settings-tile:hover { border-color: var(--accent); transform: translateY(-1px); }
.settings-icon {
  width: 38px; height: 38px;
  border-radius: var(--r);
  background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-lg);
  margin-bottom: var(--s-3);
}
.settings-title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 700;
  margin-bottom: 4px;
}
.settings-desc { font-size: var(--fs-sm); color: var(--text-2); line-height: 1.45; }

/* ═══════════════════════════════════════════════════════════
   СПИСКИ С ПЕРЕТАСКИВАНИЕМ (меню, виджеты)
   ═══════════════════════════════════════════════════════════ */
.sortable-list { display: flex; flex-direction: column; }
.sort-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-3) var(--s-2);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.sort-row:last-child { border-bottom: none; }
.sort-row.dragging { opacity: 0.4; }
.sort-row.drag-over { border-top: 2px solid var(--accent); }
.sort-main { flex: 1; min-width: 0; }
.sort-icon { width: 24px; text-align: center; font-size: var(--fs-lg); flex-shrink: 0; }
.drag-handle {
  cursor: grab;
  color: var(--text-3);
  padding: 0 var(--s-1);
  user-select: none;
  flex-shrink: 0;
}
.drag-handle:active { cursor: grabbing; }

/* ═══════════════════════════════════════════════════════════
   ДОП.ПОЛЯ ОБЪЕКТА
   ═══════════════════════════════════════════════════════════ */
.custom-field {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--border);
}
.cf-name {
  flex: 0 0 34%;
  max-width: 180px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-2);
  padding-top: 7px;
}
.cf-value {
  flex: 1;
  min-height: 38px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 7px 10px;
  font-size: var(--fs-sm);
  font-family: inherit;
  resize: vertical;
  transition: border-color var(--t-fast);
}
.cf-value:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.cf-value.saved { border-color: var(--ok); }

.cf-add { margin-top: var(--s-4); padding-top: var(--s-4); border-top: 1px solid var(--border); }
.cf-add-row { display: flex; gap: var(--s-2); align-items: flex-start; flex-wrap: wrap; }
.cf-add-row .form-input { flex: 1; min-width: 140px; }

/* ═══════════════════════════════════════════════════════════
   ДОП.СОГЛАШЕНИЯ
   ═══════════════════════════════════════════════════════════ */
.agreement {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: var(--s-4);
  margin-bottom: var(--s-3);
  background: var(--surface-2);
}
.agreement-body {
  font-size: var(--fs-sm);
  color: var(--text-2);
  margin-top: var(--s-2);
  line-height: 1.55;
  white-space: pre-wrap;
}

/* ═══════════════════════════════════════════════════════════
   ДОПОЛНИТЕЛЬНЫЕ БЕЙДЖИ И УТИЛИТЫ
   ═══════════════════════════════════════════════════════════ */
/* Статусы. Класс подставляется из значения поля — badge-{{ d.stage }},
   badge-{{ c.status }} — поэтому здесь должно быть описано КАЖДОЕ
   значение из choices. Пропущенное значение выглядит не «нейтрально»,
   а поломанно: в одной колонке часть строк с плашками, часть голым
   текстом. Добавляя статус в модель, добавь строку и сюда. */

/* Клиент: lead · active · vip · inactive */
.badge-active, .badge-green { background: var(--ok-bg);     color: var(--ok); }
.badge-lead                 { background: var(--info-bg);   color: var(--info); }
.badge-vip                  { background: var(--warn-bg);   color: var(--warn); }
.badge-inactive             { background: var(--surface-2); color: var(--text-3); }

/* Договор: draft · negotiation · signed · active · expired · terminated */
.badge-draft                { background: var(--surface-2); color: var(--text-3); }
.badge-negotiation          { background: var(--warn-bg);   color: var(--warn); }
.badge-signed               { background: var(--info-bg);   color: var(--info); }
.badge-expired              { background: var(--danger-bg); color: var(--danger); }
.badge-terminated           { background: var(--surface-2); color: var(--text-3); }

/* Объект: planning · active · paused · completed · archived */
.badge-planning             { background: var(--info-bg);   color: var(--info); }
.badge-paused               { background: var(--warn-bg);   color: var(--warn); }
.badge-completed            { background: var(--ok-bg);     color: var(--ok); }
.badge-archived             { background: var(--surface-2); color: var(--text-3); }

.badge-red                  { background: var(--danger-bg); color: var(--danger); }

.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.text-green { color: var(--ok); }

tr.row-clickable { cursor: pointer; }
tr.row-clickable:hover { background: var(--surface-2); }

.td-actions { white-space: nowrap; text-align: right; width: 1%; }
.td-actions .btn-icon + .btn-icon { margin-left: 2px; }

@media (max-width: 600px) {
  .info-row, .custom-field { flex-direction: column; gap: var(--s-1); }
  .info-label, .cf-name { flex: none; max-width: none; padding-top: 0; }
  .detail-title { font-size: var(--fs-xl); }
}

/* ═══════════════════════════════════════════════════════════
   БАННЕР РЕЖИМА ПОДДЕРЖКИ
   Намеренно контрастный: работа в чужом аккаунте не должна
   выглядеть как обычная работа.
   ═══════════════════════════════════════════════════════════ */
.support-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  flex-wrap: wrap;
  background: var(--warn-tint);
  color: #fff;
  padding: var(--s-3) var(--s-8);
  font-size: var(--fs-sm);
  position: sticky;
  top: 60px;
  z-index: 49;
}
.support-bar .btn { background: #fff; border-color: #fff; }

@media (max-width: 1000px) { .support-bar { padding: var(--s-3) var(--s-4); } }

/* ═══════════════════════════════════════════════════════════
   ПЕРЕКЛЮЧАТЕЛИ ДОСТУПА
   ═══════════════════════════════════════════════════════════ */
.toggle-row {
  display: flex;
  align-items: flex-start;
  gap: var(--s-3);
  padding: var(--s-3) 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  margin: 0;
  font-weight: 400;
}
.toggle-row:last-child { border-bottom: none; }
.toggle-row:hover .toggle-text { color: var(--accent); }
.toggle-row input[type="checkbox"] { margin-top: 2px; flex-shrink: 0; }

.toggle-main { display: flex; flex-direction: column; min-width: 0; }
.toggle-text {
  font-size: var(--fs-md);
  font-weight: 500;
  color: var(--text);
  transition: color var(--t-fast);
}
.toggle-hint { font-size: var(--fs-xs); color: var(--text-3); margin-top: 2px; line-height: 1.4; }

/* Скрытая сумма — когда сотруднику закрыты финансы */
.amount-hidden {
  color: var(--text-3);
  letter-spacing: 0.12em;
  user-select: none;
}

/* ═══════════════════════════════════════════════════════════
   ПОДСКАЗКА О ВОЗМОЖНОСТЯХ СТАРШИХ ТАРИФОВ
   Появляется не сразу и не на каждой странице: раз в неделю,
   на том экране, где функция действительно была бы к месту.
   ═══════════════════════════════════════════════════════════ */
.upsell {
  position: fixed;
  right: var(--s-5);
  bottom: var(--s-5);
  width: 320px;
  max-width: calc(100vw - 32px);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-xl);
  padding: var(--s-5);
  box-shadow: var(--shadow-pop);
  z-index: 900;

  opacity: 0;
  transform: translateY(12px);
  transition: opacity 260ms ease, transform 260ms ease;
  pointer-events: none;
}
.upsell.upsell-in { opacity: 1; transform: none; pointer-events: auto; }

.upsell-badge {
  display: inline-block;
  background: var(--accent-soft);
  color: var(--brand-600);
  font-size: var(--fs-2xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 9px;
  border-radius: var(--r-full);
  margin-bottom: var(--s-3);
}
.upsell-title {
  font-family: var(--font-display);
  font-size: var(--fs-lg);
  font-weight: 700;
  letter-spacing: -0.015em;
  margin-bottom: var(--s-2);
}
.upsell-text {
  font-size: var(--fs-sm);
  color: var(--text-2);
  line-height: 1.5;
  margin-bottom: var(--s-4);
}
.upsell-close {
  position: absolute;
  top: 10px; right: 12px;
  background: none; border: none;
  font-size: 20px; line-height: 1;
  color: var(--text-3);
  cursor: pointer;
  padding: 2px 6px;
  border-radius: var(--r-sm);
}
.upsell-close:hover { background: var(--surface-2); color: var(--text); }

@media (max-width: 600px) {
  .upsell { right: var(--s-3); left: var(--s-3); bottom: var(--s-3); width: auto; }
}
