/* SINOX CRM: оформление. Две темы: «Светлая» и «Чернильная» (графитовая).

   ---------- ЦВЕТА: только здесь ----------
   Каждая строка: light-dark(светлая, чернильная). Браузер берёт первый цвет в светлой теме и второй
   в чернильной. Тема выбирается в «Настройках» (cookie theme → data-theme на <html>);
   «Авто» — как в системе (prefers-color-scheme).
   Проверка контраста этих цветов: modules/base/web/contrast.py и тест test_shell.py (текст ≥ 4.5:1,
   рамки полей и значки ≥ 3:1). Меняете цвет — запустите pytest. */
:root {
  color-scheme: light dark;
  --side: light-dark(#ffffff, #0b0c0e);          /* боковое меню */
  --top: light-dark(#ffffff, #111315);           /* верхняя строка */
  --bg: light-dark(#f4f6fa, #181b1f);            /* фон страницы */
  --panel: light-dark(#ffffff, #181b1f);         /* панели, строка таблицы чётная */
  --row-odd: light-dark(#f8fafc, #15181b);       /* строка таблицы нечётная */
  --head: light-dark(#eef1f6, #14171a);          /* заголовок таблицы */
  --input: light-dark(#ffffff, #1d2126);         /* поле ввода, кнопка */
  --border: light-dark(#dfe3ea, #262a30);        /* линии-разделители (таблицы, меню, панели) */
  --field-border: light-dark(#898e98, #696c71);  /* рамка поля и кнопки: ≥ 3:1 к фону (подобрано, в таблице не было) */
  --text: light-dark(#1b2230, #e5e7eb);          /* текст */
  --muted: light-dark(#5b6678, #8b949e);         /* второй текст, заголовки групп меню */
  --icon: light-dark(#5b6678, #8b949e);          /* значки меню */
  --active: light-dark(#e6f4ee, #0c2720);        /* активный пункт меню: фон */
  --active-text: light-dark(#047857, #14e7a1);   /* активный пункт меню: текст */
  --accent: light-dark(#047857, #10b981);        /* акцент: ссылки, рамка фокуса */
  --btn-bg: light-dark(#047857, #10b981);        /* главная кнопка: фон */
  --btn-text: light-dark(#ffffff, #052e22);      /* главная кнопка: текст */
  --danger: light-dark(#da2626, #f87171);        /* ошибка (светлая: #dc2626 → #da2626 для 4.5:1 на фоне) */
  --warn: light-dark(#b45309, #fbbf24);          /* срок */
  --ok: light-dark(#047857, #34d399);            /* успех */
  --info: light-dark(#1d4ed8, #60a5fa);          /* инфо */
  --mark: light-dark(#fde68a, #4a3b0a);          /* подсветка совпадения в поиске (фон) */
  --shadow: light-dark(rgba(16, 24, 40, .14), rgba(0, 0, 0, .5));
  --overlay: light-dark(rgba(16, 24, 40, .45), rgba(0, 0, 0, .62));
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="ink"] { color-scheme: dark; }

/* ---------- плотность интерфейса ----------
   Все размеры полей, кнопок форм и отступов — здесь. Чтобы сделать интерфейс плотнее или свободнее,
   меняйте эти строки. На телефоне (ниже) поля и кнопки не ниже 44px — правило доступности TASK_web_ui. */
:root {
  --field-h: 28px;        /* высота поля, списка, даты и кнопки в форме */
  --field-pad-y: 4px;     /* отступ текста в поле сверху и снизу */
  --field-pad-x: 8px;     /* отступ текста в поле слева и справа */
  --gap: 6px;             /* между строками полей */
  --col-gap: 12px;        /* между колонками полей */
  --label-gap: 2px;       /* между подписью и полем */
  --section-pad: 6px;     /* отступы внутри разделов формы */
  --summary-h: 32px;      /* заголовок раздела-«гармошки» */
  --row-pad-y: 8px;       /* отступ сверху и снизу в строке списка */
  --row-h: 32px;          /* строка в окне выбора компании */
}
@media (max-width: 800px) {
  :root {
    --field-h: 44px; --field-pad-y: 8px; --field-pad-x: 12px; --gap: 10px; --col-gap: 10px;
    --label-gap: 3px; --section-pad: 8px; --summary-h: 44px; --row-pad-y: 14px; --row-h: 44px;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif; font-size: 14px; line-height: 1.45;
}
a { color: inherit; }
h1 { margin: 0; font-size: 26px; font-weight: 600; }
h2 { margin: 0; font-size: 16px; font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.strong { font-weight: 600; text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.pad { padding: 18px 20px; }
.pad-x { padding: 0 20px; }
.top-gap { margin-top: 12px; }
.caps { margin: 0 0 12px; font-size: 13px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); font-weight: 500; }
.link { color: var(--accent); text-decoration: none; font-weight: 500; min-height: 44px; display: inline-flex; align-items: center; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- каркас: боковое меню, верхняя строка, рабочая область ---------- */
.app { display: flex; min-height: 100vh; }
.icon { flex: none; }
.side {
  flex: 0 0 228px; width: 228px; background: var(--side); border-right: 1px solid var(--border);
  padding: 12px 10px; display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 0; height: 100vh; overflow: hidden; transition: flex-basis .15s, width .15s;
}
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; min-height: 36px; padding: 0 2px 0 8px; }
.brand { display: inline-flex; align-items: center; gap: 8px; color: var(--accent); text-decoration: none; min-width: 0; }
.brand-text { font-size: 18px; font-weight: 700; letter-spacing: 1px; color: var(--text); }
.side-toggle {
  display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; padding: 0;
  border: 0; border-radius: 6px; background: transparent; color: var(--icon); cursor: pointer;
}
.side-toggle:hover { background: var(--active); color: var(--active-text); }
.tenant { padding: 0 10px 8px; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-scroll { flex: 1 1 auto; overflow-y: auto; overflow-x: hidden; margin: 0 -4px; padding: 0 4px; }
.nav-section { display: flex; flex-direction: column; gap: 1px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; min-height: 34px; padding: 0 10px; border-radius: 6px;
  text-decoration: none; color: var(--text); white-space: nowrap; font-size: 14px;
}
.nav-item .icon { color: var(--icon); }
.nav-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav-item:hover { background: var(--active); }
.nav-item[aria-current="page"] { background: var(--active); color: var(--active-text); font-weight: 600; }
.nav-item[aria-current="page"] .icon { color: var(--active-text); }
.nav-group { margin: 14px 0 4px; padding: 0 10px; font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.nav-off, .nav-off .icon { color: var(--muted); cursor: default; }
.nav-off:hover { background: none; }
.nav-note { margin-left: auto; font-size: 11px; color: var(--muted); }
.side-bottom { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 1px; }
.as-button { width: 100%; border: 0; background: none; font: inherit; cursor: pointer; text-align: left; }

/* свёрнутое меню: только значки (выбор запоминается в cookie side) */
.side-collapsed .side { flex-basis: 56px; width: 56px; padding: 12px 6px; }
.side-collapsed .side .brand-text, .side-collapsed .side .nav-text, .side-collapsed .side .nav-note,
.side-collapsed .side .tenant { display: none; }
.side-collapsed .side .nav-group { height: 1px; margin: 10px 6px; padding: 0; font-size: 0; background: var(--border); }
.side-collapsed .side-head { flex-direction: column; padding: 0; gap: 8px; }
.side-collapsed .side-toggle svg { transform: rotate(180deg); }
.side-collapsed .nav-item { justify-content: center; padding: 0; }

.work { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 7; display: flex; align-items: center; gap: 16px; min-height: 52px; padding: 8px 24px;
  background: var(--top); border-bottom: 1px solid var(--border);
}
.top-title { flex: 0 1 220px; min-width: 0; font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }

.main { flex: 1 1 auto; min-width: 0; padding: 20px 24px 40px; display: flex; flex-direction: column; gap: 16px; }
.mob-head, .bottom, .fab, .mobile-only { display: none; }

/* выпадающие меню «+ Создать» и пользователя */
.menu-pop { position: relative; }
.menu-pop > summary { list-style: none; cursor: pointer; }
.menu-pop > summary::-webkit-details-marker { display: none; }
.create-pop > summary.btn { min-height: var(--field-h); padding: 0 12px; gap: 6px; border-radius: 6px; }
.pop-list {
  position: absolute; z-index: 20; top: calc(100% + 6px); left: 0; min-width: 200px; padding: 4px;
  display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px var(--shadow);
}
.pop-list.right, .create-pop .pop-list { left: auto; right: 0; }
.pop-head { padding: 8px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.pop-list form { margin: 0; }
.pop-item {
  display: flex; align-items: center; gap: 8px; width: 100%; min-height: 32px; padding: 0 10px; border: 0; border-radius: 6px;
  background: none; color: var(--text); font: inherit; text-decoration: none; text-align: left; cursor: pointer;
}
.pop-item:hover, .pop-item:focus-visible { background: var(--active); color: var(--active-text); }
.avatar {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%;
  background: var(--active); color: var(--active-text); font-size: 13px; font-weight: 700; letter-spacing: .5px;
}

/* общий поиск в верхней строке */
.gsearch { position: relative; flex: 1 1 420px; max-width: 560px; margin: 0 auto; display: flex; align-items: center; }
.gsearch > .icon { position: absolute; left: 10px; color: var(--icon); pointer-events: none; }
.gsearch input[type=search] {
  height: var(--field-h); min-height: var(--field-h); padding: 0 64px 0 32px; border-radius: 6px;
  background: var(--input); border-color: var(--field-border);
}
.gsearch-key {
  position: absolute; right: 8px; padding: 1px 6px; border: 1px solid var(--border); border-radius: 4px;
  font: 11px/16px inherit; font-family: inherit; color: var(--muted); pointer-events: none;
}
.gsearch-results:empty { display: none; }
.gsearch-results {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; right: 0; max-height: 70vh; overflow-y: auto; padding: 4px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 28px var(--shadow);
}
.gs-group + .gs-group { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
.gs-title { padding: 6px 10px 2px; font-size: 11px; font-weight: 600; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); }
.gs-item { display: flex; flex-direction: column; gap: 1px; padding: 6px 10px; border-radius: 6px; text-decoration: none; color: var(--text); }
.gs-item:hover, .gs-item[aria-selected="true"] { background: var(--active); }
.gs-main { font-weight: 500; }
.gs-sub, .gs-match { font-size: 12px; color: var(--muted); }
.gs-all { margin-top: 4px; border-top: 1px solid var(--border); border-radius: 0 0 6px 6px; color: var(--accent); font-weight: 500; }
.gs-empty { padding: 10px; color: var(--muted); }
mark { background: var(--mark); color: var(--text); border-radius: 2px; padding: 0 1px; }

/* ---------- окна-диалоги ---------- */
body.dialog-lock { overflow: hidden; }
.dialog-backdrop {
  position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-start; justify-content: center;
  padding: 5vh 16px; background: var(--overlay);
}
.dialog {
  width: min(960px, 100%); max-height: 90vh; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 20px 50px var(--shadow);
}
.dialog:focus { outline: none; }
.dialog-form { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.dialog-head {
  flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px 10px 18px; border-bottom: 1px solid var(--border);
}
.dialog-head h2 { font-size: 16px; }
.dialog-x {
  display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 6px;
  color: var(--icon); text-decoration: none;
}
.dialog-x:hover { background: var(--active); color: var(--text); }
.dialog .dialog-body { flex: 1 1 auto; overflow-y: auto; min-height: 0; }
.dialog .form-actions { position: static; flex: none; border-radius: 0 0 10px 10px; }

/* ---------- элементы ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.crumbs { font-size: 13px; color: var(--muted); }
.crumbs a { color: var(--muted); text-decoration: none; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 20px;
  border-radius: 8px; border: 1px solid var(--field-border); background: var(--input); color: var(--text);
  font: inherit; font-weight: 500; text-decoration: none; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { border: 1px solid var(--btn-bg); background: var(--btn-bg); color: var(--btn-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.wide { width: 100%; }

.search, input[type=search], input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; min-height: var(--field-h); padding: var(--field-pad-y) var(--field-pad-x); background: var(--input); color: var(--text);
  border: 1px solid var(--field-border); border-radius: 8px; font: inherit;
}
.search { width: 300px; max-width: 100%; }
textarea { resize: vertical; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 22px;
  border: 1px solid var(--field-border); background: var(--input); color: var(--muted); text-decoration: none;
}
.chip[aria-current="true"], .chip[aria-selected="true"] { border-color: var(--accent); color: var(--accent); font-weight: 600; }

.segmented { display: inline-flex; border: 1px solid var(--field-border); border-radius: 8px; overflow: hidden; }
.segmented a { display: inline-flex; align-items: center; min-height: 42px; padding: 0 14px; text-decoration: none; color: var(--muted); background: var(--input); }
.segmented a[aria-current="true"] { background: var(--active); color: var(--active-text); font-weight: 600; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
.logo { font-size: 20px; font-weight: 700; letter-spacing: .5px; color: var(--accent); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px 4px; }
.panel-head.tight { padding: 0 0 4px; }
.list { display: flex; flex-direction: column; }
.row-item { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 14px 20px; border-top: 1px solid var(--border); text-decoration: none; }
.list > .row-item:first-child, .tab-body > .row-item:first-child { border-top: 0; }
.nav-row { min-height: 52px; }
.nav-row[aria-current="page"] { font-weight: 600; color: var(--accent); }
.grow { flex: 1 1 200px; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 20px; align-items: start; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; }
.table-wrap.flat { border: 0; border-top: 1px solid var(--border); border-radius: 0 0 8px 8px; }
.table { width: 100%; min-width: 640px; border-collapse: collapse; }
.table th { background: var(--head); border-bottom: 1px solid var(--border); text-align: left; padding: calc(var(--row-pad-y) - 2px) 18px; font-weight: 500; font-size: 12px; letter-spacing: .5px; text-transform: uppercase; color: var(--muted); }
.table td { padding: var(--row-pad-y) 18px; border-top: 1px solid var(--border); }
.table tbody tr:nth-child(odd) td { background: var(--row-odd); }
.table tbody tr:hover td { background: var(--active); }
.table td a { text-decoration: none; }
.table td a:hover { color: var(--accent); }

.badge { display: inline-block; padding: 4px 12px; border-radius: 12px; font-size: 12px; font-weight: 600; background: var(--bg); border: 1px solid currentColor; white-space: nowrap; }
.st-draft { color: var(--muted); }
.st-active { color: var(--ok); }
.st-paused { color: var(--warn); }
.st-done { color: var(--info); }
.st-cancelled { color: var(--danger); }

.split { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.split-side { flex: 1 1 280px; max-width: 380px; display: flex; flex-direction: column; gap: 20px; }
.split-main { flex: 999 1 380px; min-width: 0; }
.narrow { max-width: 560px; }
.props { margin: 0; display: grid; grid-template-columns: 110px 1fr; gap: 10px 12px; }
.props dt { color: var(--muted); }
.props dd { margin: 0; overflow-wrap: anywhere; }
.notes { margin: 14px 0 0; white-space: normal; }
.contact { padding: 10px 0; border-top: 1px solid var(--border); }

.tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 8px 12px 0; border-bottom: 1px solid var(--border); }
.tabs a { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs a[aria-selected="true"] { color: var(--text); font-weight: 600; border-bottom-color: var(--accent); }
.tab-tools { padding: 8px 20px 0; }
.changes { overflow-wrap: anywhere; }

/* задачи */
.task { display: flex; gap: 12px; align-items: flex-start; padding: var(--row-pad-y) 16px; background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--border); border-radius: 12px; margin: 0 0 10px; }
.panel .task { margin: 10px 16px; }
.task.overdue { border-left-color: var(--danger); }
.task.overdue .due { color: var(--danger); }
.task.due-today { border-left-color: var(--warn); }
.task.due-today .due { color: var(--warn); }
.task.done { opacity: .7; }
.task.done .strong { text-decoration: line-through; }
.task .due { margin-top: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.task form { margin: 0; }
.check {
  flex: none; display: inline-block; width: 44px; height: 44px; margin: -10px -6px -10px -10px; padding: 0;
  border: 0; background: none; cursor: pointer; position: relative;
}
.check::before {
  content: ""; position: absolute; inset: 10px; border: 2px solid var(--muted); border-radius: 6px;
}
button.check:hover::before { border-color: var(--accent); }
.check.checked::before { background: var(--accent); border-color: var(--accent); }

/* формы */
.form { display: flex; flex-direction: column; gap: 16px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px 20px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { color: var(--muted); font-size: 13px; }
.field.wide { grid-column: 1 / -1; }
fieldset.field { margin: 0; padding: 0; border: 0; min-width: 0; }
fieldset.field > legend { padding: 0; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
/* флажки «Тип» */
.field ul, .field div[id$="_kinds"] { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.field ul li, .field div[id$="_kinds"] > div { margin: 0; }
.field input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; }
.field ul label, .field div[id$="_kinds"] label {
  display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px;
  border: 1px solid var(--field-border); border-radius: 22px; background: var(--input); cursor: pointer;
}
/* выбор компании */
.picker { display: flex; flex-direction: column; gap: 6px; }
.picked { display: flex; align-items: center; gap: 12px; padding: 2px 2px 2px var(--field-pad-x); border: 1px solid var(--accent); border-radius: 8px; background: var(--input); }
.picker-results { display: flex; flex-direction: column; max-height: 280px; overflow-y: auto; border-radius: 8px; }
.picker-results:not(:empty) { border: 1px solid var(--border); background: var(--panel); }
.pick-item {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-height: var(--row-h); padding: var(--field-pad-y) var(--field-pad-x);
  border: 0; border-top: 1px solid var(--border); background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.pick-item:first-child { border-top: 0; }
.pick-item:hover, .pick-item:focus-visible { background: var(--active); }
.pick-empty { padding: var(--field-pad-y) var(--field-pad-x); margin: 0; }
.chips.secondary { margin-top: -10px; }
.small-chip { min-height: 44px; font-size: 13px; }
.field.has-error input, .field.has-error select { border-color: var(--danger); }
.error { color: var(--danger); }
.alert { padding: 12px 14px; border: 1px solid var(--danger); border-radius: 8px; color: var(--danger); }
.form-actions { display: flex; flex-wrap: wrap; gap: 12px; }
.danger-zone { margin-top: 4px; }
.theme-switch { display: flex; gap: 4px; }
.theme-switch button {
  flex: 1; min-height: var(--field-h); padding: 0 6px; border: 1px solid var(--field-border); border-radius: 8px;
  background: var(--input); color: var(--muted); font: inherit; font-size: 12px; cursor: pointer;
}
.theme-switch button[aria-pressed="true"] { border-color: var(--accent); background: var(--active); color: var(--active-text); font-weight: 600; }
.settings-block .theme-switch { max-width: 420px; margin-top: 8px; }
.empty-state { padding: 32px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }

/* страницы без меню: вход, нет доступа */
.bare { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px 16px; }
.bare-panel { width: 100%; max-width: 400px; padding: 28px; display: flex; flex-direction: column; gap: 16px; }
.bare-panel h1 { font-size: 22px; }

/* ---------- телефон ---------- */
@media (max-width: 800px) {
  body { font-size: 15px; }
  .side, .topbar, .desktop-only, .page-head h1 { display: none; }
  .mobile-only { display: flex; }
  .app { flex-direction: column; }
  .mob-head {
    display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--top);
    border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 5;
  }
  .icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 8px; background: var(--input); color: var(--text); flex: none; }
  .mob-search { margin-left: auto; }
  .mob-title { font-size: 20px; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .main { padding: 14px 16px 110px; gap: 14px; }
  .page-head .actions, .search { width: 100%; }
  .search { min-height: 48px; border-radius: 10px; }
  .bottom {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--side);
    border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom);
  }
  .bottom a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    min-height: 56px; padding: 6px 0; text-decoration: none; color: var(--muted); font-size: 12px; }
  .bottom a[aria-current="page"] { color: var(--active-text); font-weight: 600; }
  .more-group { padding-bottom: 2px; }
  .more-title { margin: 12px 0 2px; padding: 0 20px; }
  .nav-row { gap: 12px; justify-content: flex-start; }
  .nav-row .icon { color: var(--icon); }
  /* окно-диалог на телефоне — на весь экран */
  .dialog-backdrop { padding: 0; }
  .dialog { width: 100%; height: 100%; max-height: none; border: 0; border-radius: 0; }
  .dialog .form-actions { border-radius: 0; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
  .dialog-x { width: 44px; height: 44px; }
  .fab {
    display: inline-flex; align-items: center; justify-content: center; position: fixed; right: 18px;
    bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 6; width: 56px; height: 56px; border-radius: 28px;
    background: var(--btn-bg); color: var(--btn-text); box-shadow: 0 4px 14px rgba(0, 0, 0, .3);
  }
  .cards { flex-direction: column; gap: 10px; }
  .card { display: block; padding: 14px 16px; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; text-decoration: none; }
  .card .strong { margin-bottom: 4px; display: block; }
  .card-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; }
  .chips.period .chip { flex: 1; justify-content: center; }
  .segmented { width: 100%; }
  .segmented a { flex: 1; justify-content: center; }
  .split-side { max-width: none; }
  .props { grid-template-columns: 96px 1fr; }
}

/* ---------- контакты ---------- */
.accent { color: var(--accent); }
.form-section { display: flex; flex-direction: column; gap: 12px; padding-top: 16px; border-top: 1px solid var(--border); }
.form-section:first-of-type { padding-top: 0; border-top: 0; }
.form-section > .caps { margin: 0; }
.hint { margin: 0 0 6px; }
.check-field { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; }
.check-field input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--accent); margin: 0; flex: none; }
.channel-list { display: flex; flex-direction: column; gap: 10px; }
.channel-row { display: grid; grid-template-columns: 150px minmax(180px, 1fr) 140px auto auto; gap: 8px 10px; align-items: center; }
.channels .error { display: block; }
.channel-view { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.channel-view li { display: flex; flex-direction: column; gap: 2px; overflow-wrap: anywhere; }
.channel-view a { color: var(--accent); text-decoration: none; font-weight: 500; min-height: 28px; display: inline-flex; align-items: center; }
.tag { display: inline-block; margin: 0 6px 4px 0; padding: 2px 10px; border-radius: 12px; border: 1px solid var(--border); background: var(--bg); font-size: 13px; }
.cst-active { color: var(--ok); }
.cst-left { color: var(--muted); }
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filters select { width: auto; min-width: 180px; }
.more-types { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.more-types > summary { list-style: none; cursor: pointer; }
.more-types > summary::-webkit-details-marker { display: none; }
@media (max-width: 800px) {
  .channel-row { grid-template-columns: 1fr 1fr; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
  .channel-row input[name=ch_value] { grid-column: 1 / -1; order: -1; }
  .filters select { flex: 1 1 140px; min-width: 0; }
}

/* ---------- компактные формы ----------
   Размеры берутся из переменных «плотности» в начале файла: на ПК поле 28px, на телефоне 44px. */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.form { gap: 0; padding: 0; }
.form-body { display: flex; flex-direction: column; gap: var(--gap); padding: calc(var(--section-pad) * 2) 18px var(--section-pad); }
.form input[type=text], .form input[type=email], .form input[type=password], .form input[type=date],
.form input[type=number], .form input[type=search], .form select {
  height: var(--field-h); min-height: var(--field-h); padding: var(--field-pad-y) var(--field-pad-x); border-radius: 6px;
}
/* заметки: 2 строки, дальше растут по тексту (field-sizing; для остальных браузеров — app.js) */
.form textarea {
  min-height: calc(2lh + var(--field-pad-y) * 2 + 2px); padding: var(--field-pad-y) var(--field-pad-x); border-radius: 6px;
  field-sizing: content; resize: vertical;
}
.form .btn { min-height: var(--field-h); padding: 0 12px; border-radius: 6px; }
.form .check-field { min-height: var(--field-h); }
.form .field { gap: var(--label-gap); }
.form .field > span, .form .field > label, .form fieldset.field > legend { font-size: 12px; color: var(--muted); margin: 0; }
.form .form-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--gap) var(--col-gap); }
@media (max-width: 1199px) { .form .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
/* форма компании: БИН (с кнопкой), форма собственности, название и тип в одной строке от 1200 px;
   ниже город и руководитель (руководитель на две колонки — рядом пометка «из реестра») */
@media (min-width: 1200px) {
  .form .form-grid.grid-4 { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) minmax(0, 1.5fr) minmax(0, 1fr); }
  .form .form-grid.grid-4 .director-field { grid-column: span 2; }
}
.registry-mark {
  display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 4px; font-size: 11px; line-height: 16px;
  color: var(--text); background: var(--active); border: 1px solid var(--field-border);
}
.registry-note { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 4px; }
.registry-note .registry-mark { margin-left: 0; }
.registry-note .btn { white-space: nowrap; }
.contact-head .ghost-col { visibility: hidden; height: 0; min-height: 0; padding-top: 0; padding-bottom: 0; overflow: hidden; }

/* контакты: одна строка на человека (форма компании и карточка) */
.contact-lines { list-style: none; margin: 0; padding: 0; }
.contact-line {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.2fr);
  gap: 4px 12px; align-items: center; padding: 6px 0; border-top: 1px solid var(--border);
}
.contact-line:first-child { border-top: 0; }
.contact-line > * { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.existing-contacts .contact-line { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.2fr) auto; }
.existing-contacts { margin-bottom: var(--gap); }
.count { color: var(--muted); font-weight: 400; margin-left: 4px; }
.stack { display: flex; flex-direction: column; gap: 20px; }

/* строки новых контактов в форме компании */
.contact-head, .form .contact-row {
  display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.2fr) auto;
  gap: var(--gap) 8px; align-items: start;
}
.contact-head { font-size: 12px; color: var(--muted); margin-bottom: var(--label-gap); }
.contact-rows { display: flex; flex-direction: column; gap: var(--gap); }
.contact-row .cell { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.contact-row .cell input { width: 100%; }
.contact-row .row-error { grid-column: 1 / -1; }
.contact-head[hidden] { display: none; }

/* разделы: <details>, «Основное» и «Как связаться» открыты, редкие свёрнуты */
.form details.form-section { display: block; padding: var(--section-pad) 0 0; border-top: 1px solid var(--border); }
.form details.form-section:first-of-type { border-top: 0; padding-top: 0; }
.form details.form-section > summary {
  display: flex; align-items: center; gap: 10px; min-height: var(--summary-h); cursor: pointer; list-style: none;
}
.form details.form-section > summary::-webkit-details-marker { display: none; }
.form details.form-section > summary::before {
  content: ""; width: 7px; height: 7px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg); transition: transform .15s; flex: none; margin: 0 2px;
}
.form details.form-section[open] > summary::before { transform: rotate(45deg); }
.form details.form-section > summary .caps { margin: 0; font-size: 12px; }
.form details.form-section[open] > summary { margin-bottom: var(--label-gap); }
.form details.form-section > .channels { margin-bottom: var(--section-pad); }

/* кнопки «Сохранить / Отмена» всегда видны внизу */
.form-actions {
  position: sticky; bottom: 0; z-index: 4; padding: var(--section-pad) 18px; background: var(--panel);
  border-top: 1px solid var(--border); border-radius: 0 0 12px 12px;
}

/* поле с кнопкой рядом (БИН + «Найти в реестре», день рождения + календарь) */
.with-button { display: flex; gap: 6px; align-items: center; position: relative; }
.with-button > input[type=text] { flex: 1 1 auto; min-width: 0; }
.with-button > .btn { flex: none; white-space: nowrap; }
.btn.icon-only { padding: 0; width: var(--field-h); flex: none; }
.date-proxy { position: absolute; right: 0; bottom: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; border: 0; padding: 0; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.ok { color: var(--ok); }
.check-cell { justify-content: flex-end; }

/* «Фактический совпадает с юридическим»: второе поле скрывается */
.form-grid:has(input[name=actual_same]:checked) .actual-address { display: none; }

/* выпадающий список с флажками (тип компании) */
.dropdown { position: relative; }
.dropdown > summary {
  display: flex; align-items: center; gap: 0; height: var(--field-h); padding: 0 30px 0 var(--field-pad-x); list-style: none; cursor: pointer;
  background: var(--input); border: 1px solid var(--field-border); border-radius: 6px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.dropdown > summary::-webkit-details-marker { display: none; }
.dropdown > summary::after {
  content: ""; position: absolute; right: 12px; top: calc(var(--field-h) / 2 - 5px); width: 6px; height: 6px;
  border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg);
}
.dropdown-pick + .dropdown-pick::before { content: ", "; }
.dropdown-pick ~ .dropdown-empty { display: none; }
.dropdown-list {
  position: absolute; z-index: 8; left: 0; right: 0; top: calc(100% + 4px); padding: var(--field-pad-y) var(--field-pad-x);
  display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
}
.dropdown-list .check-field { gap: 8px; }

/* строки каналов: компактно, метка «другое» открывает своё поле */
.form .channel-list { gap: var(--gap); }
.form .channel-row { grid-template-columns: 140px minmax(160px, 1fr) minmax(150px, 220px) auto auto; gap: var(--gap) 8px; }
.label-cell { display: flex; gap: 6px; min-width: 0; }
.label-cell select { flex: 1 1 50%; min-width: 0; }
.label-other { display: none; flex: 1 1 50%; min-width: 0; }
.label-cell:has(option[value=other]:checked) .label-other { display: block; }
.add-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-top: var(--gap); }
.form .hint { margin: 0 0 var(--label-gap); }

/* фильтры списков: выпадающие списки с подписью */
.filters .search { flex: 1 1 260px; width: auto; }
.filters .search, .filters select { height: var(--field-h); }

/* кнопки в шапке страниц той же высоты, что поля (на телефоне 44px из переменной) */
.page-head .btn { min-height: var(--field-h); padding: 0 14px; border-radius: 6px; }
.page-head .segmented a { min-height: calc(var(--field-h) - 2px); }
.filter { display: inline-flex; align-items: center; gap: 8px; }
.filter > span { color: var(--muted); font-size: 13px; }

@media (max-width: 800px) {
  .form .form-grid { grid-template-columns: 1fr; }
  .form-body { padding: 12px 14px 6px; }
  .form-actions { bottom: calc(52px + env(safe-area-inset-bottom)); padding: 10px 14px; }
  .form-actions .btn { flex: 1; }
  .form .channel-row { grid-template-columns: 1fr 1fr; }
  .form .channel-row .label-cell { grid-column: 1 / -1; }
  .contact-head { display: none; }
  .form .contact-row { grid-template-columns: 1fr 1fr; padding: 10px; border: 1px solid var(--border); border-radius: 8px; }
  .form .contact-row .cell:first-of-type { grid-column: 1 / -1; }
  .form .contact-row [data-remove-row] { grid-column: 1 / -1; }
  .contact-line, .existing-contacts .contact-line { grid-template-columns: 1fr 1fr; }
  .contact-line .cl-name { grid-column: 1 / -1; }
  .filter { flex: 1 1 140px; }
  .filter > span { display: none; }
  .filter select { width: 100%; }
}
.gsearch input:not(:placeholder-shown) ~ .gsearch-key { display: none; }

/* ---------- таблицы списков (компании, контакты, проекты) ---------- */
[hidden] { display: none !important; }
.list-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 10px 0 8px; }
.list-tools .btn { min-height: var(--field-h); padding: 0 12px; gap: 6px; border-radius: 6px; }
.filter-check { min-height: var(--field-h); }
.note { padding: 8px 12px; border: 1px solid var(--ok); border-radius: 8px; color: var(--ok); margin: 0 0 8px; }

/* «Вид» */
.view-pop > summary.btn { min-height: var(--field-h); padding: 0 12px; gap: 6px; border-radius: 6px; max-width: 360px; }
.view-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-list { min-width: 260px; max-height: 70vh; overflow-y: auto; }
.view-list .pop-item[aria-checked="true"] { font-weight: 600; color: var(--active-text); background: var(--active); }
.pop-sep { height: 1px; background: var(--border); margin: 4px 0; }
.pop-sub > summary { list-style: none; }
.pop-sub > summary::-webkit-details-marker { display: none; }
.pop-form { display: flex; gap: 6px; padding: 6px 10px 8px; }
.pop-form input { flex: 1 1 auto; min-width: 0; height: var(--field-h); }
.pop-form .btn { min-height: var(--field-h); padding: 0 10px; border-radius: 6px; flex: none; }
.danger-text { color: var(--danger); }
.badge.shared { padding: 1px 8px; font-size: 11px; color: var(--info); }
.badge.arch { padding: 1px 8px; font-size: 11px; color: var(--warn); }
.badge.left { padding: 1px 8px; font-size: 11px; color: var(--muted); }   /* контакт уволился */
.contact-line.is-archived .cl-name { color: var(--muted); }
.contact-more { padding: 6px 0 0; }

/* панель массовых действий */
.bulk-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 8px; padding: 6px 10px;
  background: var(--active); border: 1px solid var(--accent); border-radius: 8px;
}
.bulk-bar .btn { min-height: var(--field-h); padding: 0 12px; border-radius: 6px; }
.bulk-count { margin-right: 6px; }

/* сама таблица: прокрутка вбок, первый столбец закреплён, длинный текст с многоточием */
.data-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.data-table { min-width: 0; }
.data-table th, .data-table td { padding-left: 12px; padding-right: 12px; white-space: nowrap; }
.data-table td .cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table td.strong .cell { max-width: 340px; }
.data-table .num { text-align: right; }
.data-table th.num .sort-link { justify-content: flex-end; }
.data-table tbody tr[data-href] { cursor: pointer; }
.data-table tbody tr.is-selected td { background: var(--active); }
.data-table tbody tr.is-archived td { color: var(--muted); }
.data-table .empty { white-space: normal; }
.col-check { width: 40px; min-width: 40px; max-width: 40px; text-align: center; }
.data-table th.col-check, .data-table td.col-check { padding-left: 10px; padding-right: 6px; }
.col-check input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; vertical-align: middle; }
/* Закреплённые слева: столбец флажков и первый столбец данных. Фон нужен, чтобы прокрученное не просвечивало. */
.data-table .col-check, .data-table .col-pin { position: sticky; left: 0; z-index: 1; background: var(--panel); }
.data-table.has-check .col-pin { left: 40px; }
.data-table thead .col-check, .data-table thead .col-pin { z-index: 2; background: var(--head); }
.data-table tbody tr:nth-child(odd) td.col-pin, .data-table tbody tr:nth-child(odd) td.col-check { background: var(--row-odd); }
.data-table tbody tr:hover td.col-pin, .data-table tbody tr:hover td.col-check,
.data-table tbody tr.is-selected td.col-pin, .data-table tbody tr.is-selected td.col-check { background: var(--active); }
.data-table .col-pin { box-shadow: 1px 0 0 var(--border); }
.sort-link { display: inline-flex; align-items: center; gap: 4px; color: inherit; text-decoration: none; }
.sort-link:hover { color: var(--accent); }
.sort-mark { font-size: 10px; color: var(--accent); min-width: 10px; }
.table-foot { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.table-foot .btn { min-height: var(--field-h); padding: 0 14px; border-radius: 6px; }

/* окно «Столбцы» */
.columns-dialog { width: min(520px, 100%); }
.columns-dialog .dialog-body { padding: 10px 18px; overflow-y: auto; }
.col-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.col-item { display: flex; align-items: center; gap: 8px; padding: 2px 6px; border: 1px solid transparent; border-radius: 6px; background: var(--panel); }
.col-item:hover { border-color: var(--border); }
.col-item.dragging { opacity: .5; border-color: var(--accent); }
.col-grip { cursor: grab; color: var(--muted); font-size: 16px; user-select: none; padding: 0 2px; }
.col-name { flex: 1 1 auto; min-height: var(--field-h); }
.col-move { display: flex; gap: 4px; flex: none; }
.col-move .btn { min-height: var(--field-h); border-radius: 6px; }
.col-move .btn.icon-only { width: var(--field-h); font-size: 11px; }
.confirm-dialog { width: min(440px, 100%); margin-top: 15vh; }
.confirm-dialog .dialog-body { padding: 18px; }
.confirm-dialog p { margin: 0; }
.confirm-backdrop { z-index: 60; }

/* плашка «В архиве» в карточке */
.archived-banner {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin: 0 0 14px; padding: 10px 14px;
  border: 1px solid var(--warn); border-left-width: 4px; border-radius: 8px; background: var(--panel);
}
.archived-banner strong { color: var(--warn); }
.archived-banner form { margin-left: auto; }
.archived-banner .btn, .danger-zone .btn { min-height: var(--field-h); padding: 0 14px; border-radius: 6px; }
.danger-zone { display: flex; flex-wrap: wrap; gap: 8px; }
.row-actions { display: inline-flex; gap: 6px; justify-content: flex-end; }
.row-actions .btn { min-height: var(--field-h); padding: 0 10px; border-radius: 6px; }
@media (max-width: 760px) {
  .data-table td .cell { max-width: 200px; }
  .view-pop > summary.btn { max-width: 220px; }
  .col-check { width: 44px; min-width: 44px; }
  .data-table.has-check .col-pin { left: 44px; }
  .col-check input { width: 22px; height: 22px; }
}
