:root {
  --bg: #0e1218;
  --bg-image: none;
  --panel: #161c26;
  --card: #1c2430;
  --line: #2a3444;
  --text: #e8eef6;
  --muted: #8b98ab;
  --accent: #3d9cf0;
  --accent-2: #e36a6a;
  --on-accent: #041018;
  --ok: #3ecf8e;
  --warn: #e6b84d;
  --bad: #e36a6a;
  --paused: #9b8cff;
  --input: #10161f;
  --well: #10161f;
  --table-head: #1a2230;
  --table-sticky: #161c26;
  --table-hover: #222b38;
  --drop: #182433;
  --log: #0a0e14;
  --overlay: rgba(4, 8, 14, .72);
  --modal: linear-gradient(180deg, #1a2230 0%, #141a24 48px);
  --lead-head: #1a2230;
  --lead-foot: #161c26;
  --chip: #10161f;
  --chip-soft: #243044;
  --spark: #3a4d66;
  --spark-mid: #4d8ec8;
  --spark-empty: #2a3444;
  --sep: #3d4a5c;
  --brand-logo-bg: #05070b;
  --switch: #2a3344;
  --switch-knob: #e8eef6;
  --switch-on: #1d6b4a;
  --danger-btn: #5a2222;
  --danger-btn-line: #7a3030;
  --danger-btn-text: #ffd0d0;
  --badge-ok-bg: #163a28;
  --badge-paused-bg: #2a2450;
  --badge-draft-bg: #2a3344;
  --badge-done-bg: #1c3348;
  --badge-err-bg: #3a1d1d;
  --xfer-bg: #163a28;
  --xfer-line: #1d6b4a;
  --shadow: none;
  --glass: transparent;
  --blur: 0px;
  --primary-bg: var(--accent);
  --radius: 12px;
  --ui-font: "Segoe UI", system-ui, sans-serif;
  --display-font: Unbounded, "Segoe UI", sans-serif;
}
[data-theme="light"] {
  --bg: #eef5fb;
  --bg-image: linear-gradient(145deg, #e8f1fa 0%, #f4f7fb 42%, #f7eef0 100%);
  --panel: rgba(255, 255, 255, 0.55);
  --card: rgba(255, 255, 255, 0.72);
  --line: rgba(20, 33, 43, 0.12);
  --text: #14212b;
  --muted: #5b6b76;
  --accent: #004684;
  --accent-2: #e3000f;
  --on-accent: #ffffff;
  --ok: #1f7a4c;
  --warn: #a16207;
  --bad: #b42318;
  --paused: #004684;
  --input: rgba(255, 255, 255, 0.78);
  --well: rgba(255, 255, 255, 0.58);
  --table-head: rgba(0, 70, 132, 0.08);
  --table-sticky: rgba(255, 255, 255, 0.88);
  --table-hover: rgba(0, 70, 132, 0.06);
  --drop: rgba(0, 70, 132, 0.08);
  --log: rgba(255, 255, 255, 0.7);
  --overlay: rgba(20, 33, 43, .38);
  --modal: linear-gradient(180deg, rgba(255,255,255,0.94) 0%, rgba(244,247,251,0.96) 48px);
  --lead-head: rgba(255, 255, 255, 0.92);
  --lead-foot: rgba(238, 245, 251, 0.94);
  --chip: rgba(215, 232, 248, 0.78);
  --chip-soft: rgba(215, 232, 248, 0.9);
  --spark: #9db8d0;
  --spark-mid: #3d8fd1;
  --spark-empty: rgba(20, 33, 43, 0.12);
  --sep: rgba(20, 33, 43, 0.12);
  --brand-logo-bg: #ffffff;
  --switch: #c5d4e2;
  --switch-knob: #ffffff;
  --switch-on: #004684;
  --danger-btn: #e3000f;
  --danger-btn-line: #c4000d;
  --danger-btn-text: #ffffff;
  --badge-ok-bg: rgba(31, 122, 76, 0.12);
  --badge-paused-bg: rgba(0, 70, 132, 0.1);
  --badge-draft-bg: rgba(20, 33, 43, 0.08);
  --badge-done-bg: rgba(0, 70, 132, 0.12);
  --badge-err-bg: rgba(227, 0, 15, 0.1);
  --xfer-bg: rgba(31, 122, 76, 0.12);
  --xfer-line: rgba(31, 122, 76, 0.35);
  --shadow: 0 18px 50px rgba(20, 33, 43, 0.08);
  --glass: rgba(255, 255, 255, 0.42);
  --blur: 22px;
  --primary-bg: linear-gradient(180deg, #0a5fa8, #004684);
  --radius: 16px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background-color: var(--bg);
  background-image: var(--bg-image);
  background-attachment: fixed;
  color: var(--text);
  font: 14px/1.45 var(--ui-font);
  color-scheme: dark;
}
html[data-theme="light"], html[data-theme="light"] body { color-scheme: light; }

.app { display: flex; height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }

.sidebar {
  width: 268px;
  flex: 0 0 268px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 14px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  backdrop-filter: blur(var(--blur));
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 2px 16px;
  border-bottom: 1px solid var(--line);
}
.brand-logo {
  width: 72px; height: 72px; flex: 0 0 72px;
  object-fit: contain;
  border-radius: 50%;
  background: var(--brand-logo-bg);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent), 0 0 20px color-mix(in srgb, var(--accent) 18%, transparent);
}
.brand-title {
  font-family: var(--display-font);
  font-weight: 600;
  font-size: 15px;
  letter-spacing: .03em;
  line-height: 1;
  white-space: nowrap;
}
.brand-title span {
  color: var(--accent);
  font-weight: 600;
  font-size: inherit;
  letter-spacing: inherit;
  margin-left: 4px;
  vertical-align: baseline;
}

.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; min-height: 0; }
.side-sep {
  height: 1px; margin: 10px 12px; background: var(--sep); border: 0;
}
.side-nav button {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: transparent; color: var(--text);
  border: 1px solid transparent; border-radius: 10px;
  padding: 9px 12px; cursor: pointer; font-size: 14px;
  transition: background .2s ease, color .2s ease, border-color .2s ease;
}
.side-nav button:hover { background: var(--card); }
.side-nav button.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.side-nav button.locked { opacity: .38; cursor: not-allowed; }
.side-nav button.locked:hover { background: transparent; }
.side-ico {
  width: 22px; height: 22px; flex: 0 0 22px;
  display: grid; place-items: center;
  color: var(--muted);
}
.side-ico svg { width: 20px; height: 20px; display: block; overflow: visible; }
.side-nav button:hover:not(.locked) .side-ico { color: var(--accent); }
.side-nav button.active .side-ico { color: var(--on-accent); }
.side-nav button:hover:not(.locked) .ico-move { animation: ico-lift .4s ease; }
.side-nav button:hover:not(.locked) .ico-card-a { animation: ico-slide .45s ease; }
.side-nav button:hover:not(.locked) .ico-card-b { animation: ico-slide .45s ease .06s both; }
.side-nav button:hover:not(.locked) .ico-col-a { animation: ico-grow .4s ease; }
.side-nav button:hover:not(.locked) .ico-col-b { animation: ico-grow .4s ease .05s both; }
.side-nav button:hover:not(.locked) .ico-col-c { animation: ico-grow .4s ease .1s both; }
.side-nav button:hover:not(.locked) .ico-down { animation: ico-fall .45s ease; }
.side-nav button:hover:not(.locked) .ico-case { animation: ico-lift .4s ease; }
@keyframes ico-lift {
  0%, 100% { transform: translateY(0); }
  45% { transform: translateY(-1.6px); }
}
@keyframes ico-slide {
  0%, 100% { transform: translateX(0); }
  45% { transform: translateX(1.4px); }
}
@keyframes ico-grow {
  0%, 100% { transform: scaleY(1); transform-origin: bottom center; }
  45% { transform: scaleY(1.08); transform-origin: bottom center; }
}
@keyframes ico-fall {
  0%, 100% { transform: translateY(0); }
  45% { transform: translateY(2px); }
}
@media (prefers-reduced-motion: reduce) {
  .side-nav button:hover:not(.locked) .ico-move,
  .side-nav button:hover:not(.locked) .ico-card-a,
  .side-nav button:hover:not(.locked) .ico-card-b,
  .side-nav button:hover:not(.locked) .ico-col-a,
  .side-nav button:hover:not(.locked) .ico-col-b,
  .side-nav button:hover:not(.locked) .ico-col-c,
  .side-nav button:hover:not(.locked) .ico-down,
  .side-nav button:hover:not(.locked) .ico-case { animation: none; }
}

.side-foot { margin-top: auto; border-top: 1px solid var(--line); padding-top: 10px; }
.side-foot .muted { font-size: 11px; line-height: 1.5; }
.side-foot button { width: 100%; margin-top: 6px; }
.side-foot button:disabled { opacity: .55; cursor: wait; }

.main-col { flex: 1; min-width: 0; min-height: 0; height: 100%; display: flex; flex-direction: column; }
.top { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px 12px; border-bottom: 1px solid var(--line); }
.top-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.theme-toggle {
  width: 42px; height: 42px; padding: 0;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--card);
  color: var(--text);
}
.theme-toggle svg { width: 20px; height: 20px; display: none; }
html:not([data-theme="light"]) .theme-toggle .ico-sun { display: block; }
html[data-theme="light"] .theme-toggle .ico-moon { display: block; }
.user-menu-wrap { position: relative; }
.user-avatar {
  width: 42px; height: 42px; padding: 0;
  border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent), #0a5fa8);
  color: var(--on-accent);
  border: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  overflow: hidden;
  font-weight: 700; font-size: 14px;
}
.user-avatar:hover { filter: brightness(1.06); }
.user-menu {
  position: absolute; right: 0; top: calc(100% + 8px);
  width: 220px; padding: 12px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); z-index: 20;
}
.user-menu-name { font-weight: 600; }
.user-menu-role { color: var(--muted); font-size: 12px; margin: 2px 0 10px; }
.user-menu button { width: 100%; }
h1 { margin: 0; font-size: 20px; letter-spacing: .04em; font-family: var(--display-font); }
h2, h3 { margin: 0 0 12px; }
.muted { color: var(--muted); margin: 4px 0 0; }

.subtabs { display: flex; gap: 4px; padding: 0 0 14px; overflow-x: auto; }
.subtabs button, button {
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 12px; cursor: pointer;
}
.subtabs button.active, button.primary {
  background: var(--primary-bg);
  border-color: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
}
button.ghost { background: transparent; }
button:hover { filter: brightness(1.08); }

main { padding: 18px 24px 40px; flex: 1; min-height: 0; overflow: auto; }
.view { display: none; }
.view.active { display: block; }
main:has(#view-crm.active),
main:has(#view-deals.active),
main:has(#view-collect.active #sub-runs.active) {
  overflow: hidden;
  padding: 12px 24px 0;
  display: flex;
  flex-direction: column;
}
#view-crm.active,
#view-deals.active,
#view-collect.active {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
#view-crm .row-between,
#view-deals .row-between { flex: 0 0 auto; margin-bottom: 10px; }
#view-collect .run-bar,
#view-collect .subtabs { flex: 0 0 auto; }
#sub-runs.active {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}
#sub-runs .row-between,
#sub-runs .cards,
#sub-runs .collapse-box,
#sub-runs .company-toolbar { flex: 0 0 auto; }
#sub-runs .cards { margin-bottom: 10px; }
#sub-runs .company-toolbar { margin: 8px 0; }
#sub-runs .table-scroll {
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  overflow: auto;
}
.subpanel { display: none; }
.subpanel.active { display: block; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 18px; }
.metric { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.metric b { display: block; font-size: 22px; margin-top: 4px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.session-heading { display: flex; align-items: center; gap: 8px; min-width: 0; }
.session-heading h2 { margin: 0; }
.icon-btn {
  width: 34px; height: 34px; flex: 0 0 34px;
  padding: 0; display: grid; place-items: center;
  background: var(--card); color: var(--muted);
}
.icon-btn svg { width: 18px; height: 18px; display: block; }
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn.danger:hover { color: var(--bad); border-color: var(--bad); }
button.danger {
  background: var(--danger-btn); border-color: var(--danger-btn-line); color: var(--danger-btn-text); font-weight: 600;
}
.run-actions {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
}
.grid th.run-actions-cell,
.grid td.run-actions-cell {
  white-space: nowrap; overflow: visible; max-width: none; width: 1%;
}
.grid.wide th.run-actions-cell,
.grid.wide td.run-actions-cell {
  position: sticky; left: 0; z-index: 2; background: var(--table-sticky);
}
.grid.wide th.run-actions-cell { background: var(--table-head); z-index: 3; }
.grid tbody tr.current td.run-actions-cell { background: transparent; }
.run-switch {
  position: relative; width: 40px; height: 22px; flex: 0 0 40px; display: inline-block;
}
.run-switch input {
  position: absolute; inset: 0; z-index: 1; margin: 0; padding: 0;
  width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; background: none;
}
.run-switch i {
  position: relative; display: block; width: 100%; height: 100%;
  border-radius: 99px; background: var(--switch); pointer-events: none;
}
.run-switch i::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 16px; height: 16px; border-radius: 50%; background: var(--switch-knob);
  transition: transform .15s ease;
}
.run-switch input:checked + i { background: var(--switch-on); }
.run-switch input:checked + i::after { transform: translateX(18px); }
.run-switch input:disabled { cursor: not-allowed; }
.run-switch input:disabled + i { opacity: .38; }
.run-actions .icon-btn { width: 28px; height: 28px; flex-basis: 28px; }
.confirm-modal { width: min(460px, 96vw); }
.confirm-body { padding: 18px 22px; }
.confirm-body p { margin: 0 0 12px; color: var(--muted); }
.confirm-body b { color: var(--text); }
.confirm-code {
  display: inline-block; font-size: 26px; letter-spacing: .18em;
  font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums;
}
.confirm-error { color: var(--bad); margin: 8px 0 0; }
.confirm-error:empty { display: none; }
.field-hint { display: block; margin-top: 4px; font-size: 12px; font-weight: 400; color: var(--muted); }
.confirm-foot { padding: 0 22px 18px; display: flex; justify-content: flex-end; }
.actions, .filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.company-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0 10px;
  flex-wrap: wrap;
}
.company-toolbar h3 { margin: 0; flex: 0 0 auto; }
.company-toolbar input[type="search"] {
  width: auto;
  flex: 1 1 280px;
  min-width: 200px;
  max-width: 420px;
}
.company-toolbar select {
  width: auto;
  flex: 0 0 180px;
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 6px;
}
.filter-group span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.money-filter select {
  flex: 0 0 88px;
  width: 88px;
}
.money-filter input[type="number"] {
  width: 110px;
  min-width: 90px;
}
.filter-btn.is-on,
#companiesTable th.is-filtered {
  color: var(--accent);
}
#companiesTable th[data-col] {
  cursor: pointer;
  user-select: none;
}
#companiesTable th[data-col]::after {
  content: "▾";
  margin-left: 6px;
  font-size: 10px;
  color: var(--muted);
  font-weight: 400;
}
#companiesTable th.is-filtered::after {
  content: "●";
  color: var(--accent);
}
.col-filter-pop {
  position: fixed;
  z-index: 80;
  min-width: 260px;
  max-width: 360px;
  max-height: min(70vh, 420px);
  overflow: auto;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.4);
}
.col-filter-pop h4 {
  margin: 0 0 8px;
  font-size: 13px;
}
.col-filter-pop .filter-search {
  width: 100%;
  margin-bottom: 8px;
}
.col-filter-pop .filter-range {
  display: flex;
  gap: 8px;
}
.col-filter-pop .filter-range input {
  width: 100%;
}
.col-filter-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow: auto;
  margin: 8px 0;
}
.col-filter-list label {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
  font-weight: 400;
  color: var(--text);
}
.col-filter-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 10px;
}
.pager {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  white-space: nowrap;
}
.pager button { min-width: 36px; }
#pageInfo { min-width: 4.5em; text-align: center; color: var(--muted); }
.grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.grid.wide {
  width: max-content;
  min-width: 100%;
  overflow: visible;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  background: var(--panel);
}
.collapse-box { margin: 8px 0 4px; }
.collapse-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  text-align: left;
  background: var(--card);
}
.collapse-toggle[aria-expanded="true"] { border-radius: 8px 8px 0 0; }
.collapse-arrow { width: 1em; color: var(--muted); }
.collapse-body {
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 8px 8px;
  max-height: 28vh;
  overflow: auto;
}
.collapse-body .grid { border: 0; border-radius: 0; box-shadow: none; }
.table-scroll {
  overflow: auto;
  max-height: 72vh;
  border: 1px solid var(--line);
  border-radius: 12px;
}
.table-scroll .grid { border: 0; border-radius: 0; box-shadow: none; }
.grid th, .grid td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid th { position: sticky; top: 0; background: var(--table-head); z-index: 1; }
.grid tbody tr.current {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
.grid tbody tr.current td:first-child {
  box-shadow: inset 3px 0 0 var(--accent);
}
.okved-cell { max-width: 140px; }
.okved-more { padding: 2px 8px; font-size: 12px; white-space: nowrap; }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover { background: var(--table-hover); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; }
.badge.running, .badge.searching { background: var(--badge-ok-bg); color: var(--ok); }
.badge.paused { background: var(--badge-paused-bg); color: var(--paused); }
.badge.draft { background: var(--badge-draft-bg); color: var(--muted); }
.badge.completed { background: var(--badge-done-bg); color: var(--accent); }
.badge.error { background: var(--badge-err-bg); color: var(--bad); }
input, select, textarea {
  background: var(--input); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 10px; width: 100%;
}
label { display: block; margin: 8px 0; color: var(--muted); }
.okved-picker { margin: 12px 0 16px; }
.okved-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.okved-toolbar input[type="search"] { flex: 1 1 240px; }
.okved-toolbar select { flex: 1 1 170px; width: auto; }
.okved-toolbar .okved-check { display: flex; gap: 6px; align-items: center; margin: 0; color: var(--text); }
.okved-toolbar .okved-check input { width: auto; }
.okved-presets { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.okved-presets button { padding: 5px 9px; font-size: 12px; }
.okved-meta { color: var(--muted); font-size: 12px; margin: 4px 0 8px; }
.okved-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.okved-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--chip-soft); border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 8px; font-size: 12px; color: var(--text);
}
.okved-chip button { border: 0; background: transparent; color: var(--muted); padding: 0 2px; }
.okved-tree {
  max-height: 48vh;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--well);
  padding: 8px;
}
.okved-node { margin: 2px 0 2px 16px; }
.okved-node.root { margin-left: 0; }
.okved-row { display: flex; align-items: flex-start; gap: 6px; }
.okved-row label { display: flex; gap: 6px; align-items: flex-start; margin: 0; color: var(--text); flex: 1; }
.okved-row input { width: auto; margin-top: 3px; }
.okved-twist {
  width: 20px; height: 20px; padding: 0; flex: 0 0 20px;
  border-radius: 4px; line-height: 18px; font-size: 12px;
}
.okved-twist[disabled] { opacity: .25; cursor: default; }
.okved-kids { margin-left: 4px; }
.okved-kids.hidden { display: none; }
.okved-badge { color: var(--accent); font-size: 11px; }
.okved-why { color: var(--muted); font-size: 12px; }
.hidden { display: none !important; }
.log {
  background: var(--log); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; height: 62vh; overflow: auto; white-space: pre-wrap; font-size: 12px;
}
.log.small { height: 200px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.form-grid .actions, .form-grid .muted, .form-grid .wide { grid-column: 1 / -1; }
.form-grid textarea { resize: vertical; }
.project-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  margin: 8px 0 20px;
}
.project-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
}
.project-card:hover { border-color: var(--accent); }
.project-card h3 { margin: 4px 0 8px; }
.project-card p { color: var(--muted); margin: 0 0 10px; min-height: 3em; }
.project-meta { display: flex; gap: 12px; color: var(--muted); font-size: 12px; }
.run-bar { margin-bottom: 12px; max-width: 420px; }
.crm-toolbar { margin: 0; }
.kanban {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  overflow-y: hidden;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  padding-bottom: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--sep) transparent;
}
.kanban-col {
  flex: 0 0 280px;
  width: 280px;
  max-width: 280px;
  min-width: 0;
  align-self: stretch;
  height: 100%;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.kanban-col.drop { border-color: var(--accent); background: var(--drop); }
.kanban-col.won header { color: var(--ok); }
.kanban-col.lost header { color: var(--bad); }
.deal-xfer {
  margin-top: 10px; width: 100%; font-size: 12px; padding: 6px 8px;
  background: var(--xfer-bg); border-color: var(--xfer-line); color: var(--ok);
}
.deal-meta { margin-top: 8px; font-size: 12px; color: var(--muted); }
.deal-meta b { color: var(--text); font-weight: 600; }
.deal-fields {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px; grid-column: 1 / -1;
}
.lead-crm-actions { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.lead-crm-actions #leadReturn { margin-right: auto; }
.kanban-col header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}
.kanban-list {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
}
.kanban-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  cursor: grab;
  min-width: 0;
  flex: 0 0 auto;
}
.kanban-card.dragging { opacity: .45; }
.kanban-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  min-width: 0;
}
.kanban-card b {
  display: block;
  min-width: 0;
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.run-badge {
  display: inline-flex;
  align-items: center;
  flex: 0 1 42%;
  min-width: 0;
  max-width: 42%;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 650;
  line-height: 1.25;
  color: hsl(var(--run-h, 210) 72% 78%);
  background: hsl(var(--run-h, 210) 52% 42% / .28);
  border: 1px solid hsl(var(--run-h, 210) 48% 52% / .5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lead-kicker-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 2px;
}
.lead-kicker-row .lead-kicker { margin-bottom: 0; }
.lead-kicker-row .run-badge { max-width: min(280px, 70%); font-size: 11px; padding: 3px 8px; }
[data-theme="light"] .run-badge {
  color: hsl(var(--run-h, 210) 62% 28%);
  background: hsl(var(--run-h, 210) 70% 46% / .16);
  border-color: hsl(var(--run-h, 210) 48% 42% / .35);
}
.kanban-person { margin: 8px 0 2px; }
.spark {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  margin: 8px 0 2px;
}
.spark-chart { width: 72px; flex: 0 0 72px; }
.spark-bars {
  height: 42px;
  display: flex;
  align-items: flex-end;
  gap: 4px;
}
.spark-bar {
  flex: 1;
  display: block;
  border-radius: 3px 3px 1px 1px;
  background: var(--spark);
  min-height: 2px;
}
.spark-bar.mid { background: var(--spark-mid); }
.spark-bar.last { background: var(--accent); }
.spark-bar.empty { background: var(--spark-empty); }
.spark-years {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  font-size: 10px;
  color: var(--muted);
}
.spark-cap {
  display: flex;
  flex-direction: column;
  gap: 1px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.3;
}
.spark-cap span { color: var(--muted); font-weight: 500; margin-right: 6px; }
.lead-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: var(--overlay);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.lead-modal {
  width: min(980px, 96vw);
  max-height: 90vh;
  overflow: auto;
  background: var(--modal);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.lead-head {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--lead-head); z-index: 2;
}
.lead-avatar {
  width: 52px; height: 52px; flex: 0 0 52px;
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), #7c5cff);
  color: var(--on-accent); font-weight: 800; letter-spacing: .02em;
}
.lead-head-text { flex: 1; min-width: 0; }
.lead-kicker {
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 2px;
}
.lead-head h2 { margin: 0; font-size: 22px; line-height: 1.25; }
.lead-head-actions { display: flex; gap: 8px; align-items: center; }
.lead-stages {
  display: flex; gap: 6px; flex-wrap: wrap;
  padding: 12px 22px 0;
}
.lead-stage {
  border-radius: 999px; padding: 5px 11px; font-size: 12px;
  background: var(--chip); color: var(--muted); border: 1px solid var(--line);
}
.lead-stage.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); font-weight: 600; }
.lead-stage.won.active { background: var(--ok); border-color: var(--ok); }
.lead-stage.lost.active { background: var(--bad); border-color: var(--bad); color: #1a0a0a; }
.lead-metrics {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  padding: 14px 22px 4px;
}
.lead-metric {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 10px 12px;
}
.lead-metric span { display: block; color: var(--muted); font-size: 11px; }
.lead-metric b { display: block; margin-top: 4px; font-size: 16px; }
.lead-body { padding: 8px 22px 20px; display: grid; grid-template-columns: 1.2fr .8fr; gap: 14px; }
.lead-section {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 14px;
}
.lead-section h3 {
  margin: 0 0 12px; font-size: 12px; letter-spacing: .08em;
  text-transform: uppercase; color: var(--muted); font-weight: 600;
}
.lead-dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; }
.lead-dl dt { color: var(--muted); }
.lead-dl dd { margin: 0; word-break: break-word; }
.lead-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.lead-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--chip); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 10px; font-size: 12px;
  color: var(--text); text-decoration: none;
}
.lead-chip:hover { border-color: var(--accent); }
.lead-fin { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.lead-year {
  background: var(--well);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}
[data-theme="light"] .lead-year {
  background: var(--chip);
  border-color: rgba(0, 70, 132, 0.14);
}
.lead-year span { color: var(--muted); font-size: 11px; }
.lead-year b { display: block; margin: 4px 0 2px; }
.lead-year em { font-style: normal; color: var(--muted); font-size: 12px; }
.lead-crm {
  display: grid; grid-template-columns: 180px 1fr auto;
  gap: 10px; align-items: end;
  padding: 12px 22px 16px;
  border-top: 1px solid var(--line);
  background: var(--lead-foot);
  position: sticky; bottom: 0;
}
.lead-crm:has(#dealFields:not(.hidden)) {
  grid-template-columns: 1fr 1fr auto;
}
.lead-note { margin: 0; }
.lead-status {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; background: var(--badge-ok-bg); color: var(--ok);
}
.lead-status.warn { background: var(--badge-err-bg); color: var(--bad); }

@media (max-width: 860px) {
  .lead-body, .lead-metrics, .lead-crm, .lead-fin { grid-template-columns: 1fr; }
}
[data-theme="light"] .side-nav button.active {
  background: rgba(0, 70, 132, 0.1);
  border-color: transparent;
  color: #004684;
}
[data-theme="light"] .side-nav button.active .side-ico { color: #004684; }
[data-theme="light"] .card,
[data-theme="light"] .metric,
[data-theme="light"] .kanban-col,
[data-theme="light"] .project-card,
[data-theme="light"] .kanban-card,
[data-theme="light"] .lead-section,
[data-theme="light"] .lead-metric {
  backdrop-filter: blur(20px) saturate(160%);
}

.app.auth-blur { visibility: hidden; }
.auth-screen {
  position: fixed; inset: 0; z-index: 80;
  display: grid; place-items: center;
  background-color: var(--bg);
  background-image: var(--bg-image);
}
.auth-card {
  width: min(420px, 92vw);
  padding: 36px 32px 30px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  text-align: center;
}
.auth-card .brand-logo { margin: 0 auto 14px; }
.auth-card .brand-title { justify-content: center; margin-bottom: 0; }
.auth-card .auth-lead { margin: 14px 0 0; }
.auth-card form { display: grid; gap: 16px; text-align: left; margin-top: 28px; }
.auth-card label {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
}
.auth-card input {
  margin-top: 7px;
  height: 48px;
  padding: 0 16px;
  font-size: 16px;
  border-radius: 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.auth-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 28%, transparent);
}
.auth-card button.primary {
  width: 100%;
  height: 50px;
  margin-top: 6px;
  border-radius: 12px;
  font-size: 16px;
  letter-spacing: .02em;
}
.auth-card button.primary:hover {
  filter: none;
  box-shadow: 0 8px 22px color-mix(in srgb, var(--accent) 32%, transparent);
}

.setpanel { display: none; }
.setpanel.active { display: block; }
.pref-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  max-width: 640px;
}
.pref-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.pref-row strong { display: block; font-weight: 600; }
.pref-row .muted { display: block; margin: 4px 0 0; font-size: 13px; }
.pref-row .run-switch { flex: 0 0 40px; }
.roles-layout {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  margin-top: 14px;
}
.roles-side {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 12px;
}
.roles-cap {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.role-item {
  width: 100%; text-align: left;
  background: transparent; color: var(--text);
  border: 1px solid transparent;
  border-radius: 8px; padding: 8px 10px; margin-bottom: 4px;
}
.role-item b { display: block; font-weight: 600; }
.role-item span { display: block; font-size: 12px; color: var(--muted); }
.role-item.active { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.role-item.active span { color: color-mix(in srgb, var(--on-accent) 80%, transparent); }
.roles-new {
  display: grid; gap: 8px;
  margin-top: 12px; padding-top: 12px;
  border-top: 1px solid var(--line);
}
.roles-matrix {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 10px;
  min-width: 0;
}
.roles-note {
  margin: 0 0 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--warn) 14%, transparent);
  color: var(--text);
  font-size: 13px;
}
.perm-group { margin: 0; }
.perm-group + .perm-group {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.perm-group h3 {
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  font-weight: 600;
  margin: 0 0 8px;
  color: var(--muted);
}
.perm-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  column-gap: 20px;
  row-gap: 2px;
}
.perm-item {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 6px 2px;
  min-height: 32px;
  background: none;
  border: 0;
  border-radius: 0;
  font-weight: 400;
  color: var(--text);
}
.perm-item input {
  margin: 0;
  flex: 0 0 15px;
  width: 15px;
  height: 15px;
}
.perm-item span { line-height: 1.3; }
.users-actions { display: flex; gap: 6px; justify-content: flex-end; }

.modal {
  position: fixed; inset: 0; background: var(--overlay);
  display: flex; align-items: center; justify-content: center;
  z-index: 30; padding: 16px;
}
.modal-card {
  width: min(680px, 96vw); max-height: 80vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 16px;
}
.modal-card header { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.okved-modal-list { margin: 8px 0 0; padding-left: 20px; }
.okved-modal-list li { margin: 6px 0; white-space: normal; }
.progress { height: 6px; background: var(--well); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progress > i { display: block; height: 100%; background: var(--accent); }

@media (max-width: 860px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; flex: none; height: auto; position: static; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .brand { border-bottom: 0; }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
  .side-nav button { width: auto; }
  .side-nav { flex: none; }
  .side-sep { width: 1px; height: 22px; margin: 0 6px; }
  .side-foot { border-top: 0; margin-left: auto; margin-top: 0; }
  .deal-fields { grid-template-columns: 1fr; }
  .roles-layout { grid-template-columns: 1fr; }
  .perm-grid { grid-template-columns: 1fr; }
}

.qualify-card { margin: 18px 0 22px; padding: 16px 18px 14px; }
.qualify-card h3 { margin-bottom: 4px; }
.qualify-tree { display: grid; gap: 8px; margin: 10px 0; }
.qualify-group {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--well);
}
.qualify-group-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}
.qualify-group-head select { width: auto; min-width: 180px; }
.qualify-items { display: grid; gap: 8px; }
.qualify-pred {
  display: grid;
  gap: 8px;
  padding: 8px 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.qualify-pred-main {
  display: flex;
  align-items: center;
  gap: 8px;
}
.qualify-pred-main select { flex: 1; min-width: 0; }
.qualify-pred-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}
.qualify-pred-fields select,
.qualify-pred-fields input[type="number"] {
  width: auto;
  flex: 0 1 120px;
  min-width: 92px;
}
.qualify-pred-fields input[type="text"] {
  flex: 1 1 180px;
  min-width: 140px;
}
.qualify-pred-suffix,
.qualify-pred-summary {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.qualify-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.qualify-readonly .qualify-pred { color: var(--text); }
.qualify-readonly .qualify-pred-main { flex-wrap: wrap; }
.qualify-items .qualify-group { margin-left: 4px; }
.qualify-group[data-op="not"] { border-color: color-mix(in srgb, #d35 40%, var(--line)); }
.qualify-new { margin: 14px 0 18px; }
