:root {
  --bg: #0e1014;
  --bg-2: #161922;
  --panel: #171a23;
  --panel-2: #1c2030;
  --line: #262b39;
  --line-soft: #1f2430;
  --text: #eef1f7;
  --muted: #8b93a7;
  --muted-2: #5d6477;
  --gold: #d6b15f;
  --gold-soft: rgba(214, 177, 95, 0.12);
  --green: #57c08a;
  --green-soft: rgba(87, 192, 138, 0.12);
  --red: #e0726c;
  --blue: #6ea8e6;
  --radius: 14px;
  --bg-glow: radial-gradient(1200px 600px at 80% -10%, #1a1f2e 0%, transparent 60%);
}

/* Светлая тема — тёплая, приятная, без теней на плашках */
:root[data-theme="light"] {
  --bg: #f4f1ea;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --panel-2: #f7f4ec;
  --line: #e4ddcd;
  --line-soft: #efe9db;
  --text: #2a2722;
  --muted: #7d7768;
  --muted-2: #a89f8c;
  --gold: #b8923c;
  --gold-soft: rgba(184, 146, 60, 0.13);
  --green: #2f9466;
  --green-soft: rgba(47, 148, 102, 0.13);
  --red: #c9544c;
  --blue: #3f74ad;
  --bg-glow: radial-gradient(1100px 560px at 82% -12%, #fbf6e9 0%, transparent 62%);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg-glow), var(--bg);
  color: var(--text);
  font-family: 'Manrope', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.app { max-width: 1280px; margin: 0 auto; padding: 28px 28px 80px; }
.hidden { display: none !important; }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 22px; margin-bottom: 24px;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; }
.mark {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center;
  font-weight: 800; font-size: 20px; color: #0e1014;
  background: linear-gradient(135deg, #e7ca7c, var(--gold));
  border: 1px solid rgba(255,255,255,0.15);
}
.brand-title { font-size: 18px; font-weight: 800; letter-spacing: 0.2px; }
.brand-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

.top-actions { display: flex; align-items: center; gap: 12px; }
.theme-toggle {
  width: 42px; height: 42px; border-radius: 11px; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--gold);
  font-size: 18px; display: grid; place-items: center; transition: all .15s ease;
}
.theme-toggle:hover { border-color: var(--gold); }
.tabs { display: flex; gap: 6px; background: var(--bg-2); padding: 5px; border-radius: 12px; border: 1px solid var(--line); }
.tab {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 700; padding: 9px 22px; border-radius: 8px; cursor: pointer;
  transition: all .15s ease;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--gold); color: #14161c; }

/* Controls */
.controls {
  display: flex; gap: 16px; align-items: flex-end; flex-wrap: wrap;
  margin-bottom: 24px;
}
.ctrl { display: flex; flex-direction: column; gap: 7px; }
.ctrl.manager-ctrl { min-width: 280px; }
.ctrl.wide { flex: 1; min-width: 320px; }
.ctrl label { font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.7px; color: var(--muted-2); font-weight: 700; }
select, input {
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 13px; font: inherit; min-width: 120px;
  outline: none; transition: border-color .15s ease;
}
select:focus, input:focus { border-color: var(--gold); }
select { cursor: pointer; }

/* Searchable combobox */
.combo { position: relative; }
.combo-input {
  width: 100%; cursor: text;
  background: var(--bg-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; font: inherit;
}
.combo-input:focus { border-color: var(--gold); outline: none; }
.combo-panel {
  position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 11px;
  padding: 6px; max-height: 280px; overflow-y: auto;
}
.combo-opt { padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 13.5px; }
.combo-opt:hover { background: var(--panel-2); }
.combo-opt.sel { background: var(--gold-soft); color: var(--gold); font-weight: 700; }
.combo-empty { padding: 12px; color: var(--muted-2); font-size: 13px; text-align: center; }

.btn-primary {
  background: var(--gold); color: #14161c; border: 0;
  font: inherit; font-weight: 800; padding: 12px 26px; border-radius: 10px; cursor: pointer;
  transition: filter .15s ease;
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost {
  background: transparent; color: var(--muted); border: 1px solid var(--line);
  font: inherit; font-weight: 600; padding: 7px 14px; border-radius: 8px; cursor: pointer;
}
.btn-ghost:hover { color: var(--red); border-color: var(--red); }
.btn-ghost.gold:hover { color: var(--gold); border-color: var(--gold); }
#plan-table td:last-child { white-space: nowrap; }
#plan-table .btn-ghost { margin-left: 6px; }
.chk-col { width: 34px; text-align: center; }
.chk-col input { width: 17px; height: 17px; accent-color: var(--gold); cursor: pointer; margin: 0; vertical-align: middle; }

/* Segmented control (тип договора) */
.seg-row { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.seg-label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted-2); font-weight: 700; }
.seg { display: inline-flex; gap: 5px; background: var(--bg-2); padding: 5px; border-radius: 11px; border: 1px solid var(--line); }
.seg-btn {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 700;
  padding: 8px 18px; border-radius: 8px; cursor: pointer; transition: all .15s ease;
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--gold); color: #14161c; }

/* KPI */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
.kpi {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px 22px;
}
.kpi .k-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi .k-value { font-size: 27px; font-weight: 800; margin-top: 10px; letter-spacing: -0.4px; }
.kpi .k-foot { font-size: 12px; color: var(--muted-2); margin-top: 6px; }
.kpi.accent { background: linear-gradient(160deg, var(--gold-soft), var(--panel)); border-color: var(--gold-soft); }
.k-value.gold { color: var(--gold); }
.k-value.green { color: var(--green); }
.k-value.red { color: var(--red); }

.progress { height: 7px; border-radius: 99px; background: var(--bg-2); margin-top: 12px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold), #e7ca7c); border-radius: 99px; }

/* Panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; margin-bottom: 22px; }
.panel-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 18px; }
.panel-head h2 { font-size: 16px; font-weight: 800; margin: 0; }
.hint { font-size: 12px; color: var(--muted-2); }
.head-actions { display: flex; align-items: center; gap: 10px; }
.btn-export {
  background: var(--bg-2); color: var(--muted); border: 1px solid var(--line);
  font: inherit; font-weight: 700; font-size: 12px; padding: 7px 14px; border-radius: 8px; cursor: pointer;
  transition: all .15s ease;
}
.btn-export:hover { color: var(--gold); border-color: var(--gold); }
.btn-export:disabled { opacity: .5; cursor: default; }

/* Funnel visual */
.funnel-visual { display: flex; flex-direction: column; gap: 8px; margin-bottom: 22px; }
.fv-row { display: grid; grid-template-columns: 220px 1fr auto; align-items: center; gap: 14px; }
.fv-name { font-size: 13px; color: var(--muted); font-weight: 600; }
.fv-conv { display: block; font-size: 11px; color: var(--muted-2); font-weight: 600; margin-top: 2px; }
.fv-row { cursor: pointer; padding: 4px 8px; margin: -4px -8px; border-radius: 10px; transition: background .12s ease; }
.fv-row:hover { background: var(--panel-2); }
.fv-row:hover .fv-name { color: var(--text); }
.fv-row.active { background: var(--gold-soft); }
.fv-row.active .fv-name { color: var(--gold); }
.fv-track { height: 30px; background: var(--bg-2); border-radius: 8px; overflow: hidden; position: relative; border: 1px solid var(--line-soft); }
.fv-fill { height: 100%; border-radius: 8px; background: linear-gradient(90deg, rgba(214,177,95,.35), var(--gold)); min-width: 2px; }
.fv-val { font-weight: 800; font-size: 14px; min-width: 56px; text-align: right; }
.fv-plan { font-size: 11.5px; color: var(--muted-2); }

/* Tables */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted-2); font-weight: 700; padding: 10px 12px; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.grid th.r { text-align: right; }
table.grid td { padding: 13px 12px; border-bottom: 1px solid var(--line-soft); font-size: 13.5px; }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid tbody tr:hover td { background: var(--panel-2); }
.r { text-align: right; }
.num { width: 40px; color: var(--muted-2); }
td.step-name { font-weight: 700; }
.step-row { cursor: pointer; }
.step-row.active td { background: var(--gold-soft) !important; }
.step-row.active td.step-name { color: var(--gold); }
td.hl { background: var(--gold-soft); }
#reg-clear { color: var(--gold); text-decoration: none; font-weight: 700; }
#reg-clear:hover { text-decoration: underline; }
td.big { font-weight: 800; font-size: 15px; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.gold { background: var(--gold-soft); color: var(--gold); }
.pill.dim { background: var(--bg-2); color: var(--muted-2); }
.cell-dim { color: var(--muted-2); }

/* Registry */
table.registry th, table.registry td { font-size: 12.5px; padding: 10px 11px; }

/* Закреплённые шапка и первый столбец (Сделка) в реестре */
.reg-wrap { max-height: 68vh; overflow: auto; }
#registry-table thead th {
  position: sticky; top: 0; z-index: 3; background: var(--panel);
}
#registry-table th:first-child,
#registry-table td:first-child {
  position: sticky; left: 0; z-index: 2; background: var(--panel);
  box-shadow: 1px 0 0 var(--line);
}
#registry-table thead th:first-child { z-index: 4; }
#registry-table tbody tr:hover td:first-child { background: var(--panel-2); }
.stage-dot { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 7px; font-size: 12px; }
.stage-dot.on { background: var(--green-soft); color: var(--green); }
.stage-dot.off { background: var(--bg-2); color: var(--muted-2); opacity: .5; }
.deal-title { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deal-id { color: var(--muted-2); font-size: 11.5px; }
.deal-link { text-decoration: none; color: inherit; display: block; }
.deal-link:hover .deal-title { color: var(--gold); }
.deal-link:hover .deal-id { color: var(--gold); }
.type-tag { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 11.5px; font-weight: 700; white-space: nowrap; }
.type-tag.recruiting { background: rgba(110, 168, 230, 0.14); color: var(--blue); }
.type-tag.outsourcing { background: var(--gold-soft); color: var(--gold); }
.type-tag.none { background: var(--bg-2); color: var(--muted-2); }

/* Plan form */
.plan-form { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; }
.conv-block { margin-top: 22px; }
.conv-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .7px; color: var(--muted-2); font-weight: 700; margin-bottom: 12px; }
.conv-inputs { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }
.conv-item { display: flex; flex-direction: column; gap: 6px; }
.conv-item span { font-size: 11.5px; color: var(--muted); font-weight: 600; min-height: 30px; }
.conv-item input { min-width: 0; }
.plan-actions { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-top: 24px; flex-wrap: wrap; }
.plan-preview { font-size: 13px; color: var(--muted); }
.plan-preview b { color: var(--gold); }

.empty { text-align: center; color: var(--muted-2); padding: 40px 0; }

/* Кнопка-компакт */
.btn-sm { padding: 8px 16px; font-size: 13px; }

/* Конверсии в таблице планов */
.conv-cell { white-space: nowrap; }
.conv-chip { display: inline-block; min-width: 22px; text-align: center; font-weight: 700; font-size: 12.5px; }
.conv-sep { color: var(--muted-2); font-style: normal; margin: 0 3px; }

/* Модальное окно */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 12, 16, 0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto;
}
:root[data-theme="light"] .modal-overlay { background: rgba(60, 52, 38, 0.4); }
.modal {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  width: 100%; max-width: 720px; margin: auto;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 800; }
.modal-close {
  width: 34px; height: 34px; border-radius: 9px; cursor: pointer;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--muted);
  font-size: 20px; line-height: 1; display: grid; place-items: center;
}
.modal-close:hover { color: var(--red); border-color: var(--red); }
.modal-body { padding: 22px 24px; }
.modal-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 18px 24px; border-top: 1px solid var(--line); flex-wrap: wrap;
}
.modal-actions { display: flex; gap: 10px; }

/* Toast */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  padding: 13px 22px; border-radius: 12px; font-weight: 600; z-index: 50;
}
.toast.err { border-color: var(--red); color: #ffd9d6; }

.loading { opacity: .5; pointer-events: none; }

@media (max-width: 920px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .conv-inputs { grid-template-columns: repeat(3, 1fr); }
  .fv-row { grid-template-columns: 130px 1fr auto; }
}

/* Мобильная версия */
@media (max-width: 640px) {
  .app { padding: 14px 12px 56px; }

  /* Шапка */
  .topbar { flex-wrap: wrap; gap: 12px; padding-bottom: 14px; margin-bottom: 16px; }
  .brand { gap: 10px; flex: 1 1 auto; }
  .mark { width: 38px; height: 38px; font-size: 17px; border-radius: 10px; }
  .brand-title { font-size: 16px; }
  .brand-sub { font-size: 11px; }
  .top-actions { gap: 8px; }
  .tab { padding: 8px 16px; }
  .theme-toggle { width: 38px; height: 38px; }

  /* Фильтры — сетка 2 колонки */
  .controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; align-items: end; margin-bottom: 18px; }
  .controls .ctrl { min-width: 0; }
  select, input, .combo-input { min-width: 0; padding: 10px 12px; }
  .ctrl.manager-ctrl, .ctrl.wide { min-width: 0; grid-column: 1 / -1; }
  #refresh { grid-column: 1 / -1; width: 100%; }

  /* Тип договора */
  .seg-row { flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
  .seg { width: 100%; }
  .seg-btn { flex: 1; padding: 9px 6px; text-align: center; }

  /* KPI */
  .kpi-grid { gap: 10px; margin-bottom: 16px; }
  .kpi { padding: 15px 16px; }
  .kpi .k-value { font-size: 21px; margin-top: 6px; }

  /* Панели */
  .panel { padding: 16px 14px; margin-bottom: 16px; border-radius: 12px; }
  .panel-head { flex-wrap: wrap; gap: 8px; }
  .panel-head h2 { font-size: 15px; }
  .head-actions { width: 100%; flex-wrap: wrap; gap: 8px; }
  .head-actions .hint { flex: 1 1 100%; }

  /* Воронка-визуал */
  .fv-row { grid-template-columns: 104px 1fr auto; gap: 10px; }
  .fv-name { font-size: 12px; }
  .fv-conv { font-size: 10px; }
  .fv-val { font-size: 13px; min-width: 44px; }

  /* Таблицы — горизонтальный скролл */
  .table-wrap { -webkit-overflow-scrolling: touch; margin: 0 -4px; }
  table.grid th { font-size: 10px; padding: 9px 9px; }
  table.grid td { padding: 11px 9px; font-size: 13px; }

  /* Форма плана */
  .plan-form { gap: 12px; }
  .plan-form .ctrl { flex: 1 1 100%; }
  .conv-inputs { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .plan-actions { flex-direction: column; align-items: stretch; gap: 12px; }
  .plan-actions .btn-primary { width: 100%; }
  .plan-preview { text-align: center; }

  /* Combobox список не вылезает за экран */
  .combo-panel { max-height: 240px; }

  .toast { left: 12px; right: 12px; transform: none; text-align: center; }

  /* Реестр: узкий столбец сделки с переносом названия */
  #registry-table th:first-child,
  #registry-table td:first-child { max-width: 132px; min-width: 110px; padding-right: 8px; }
  #registry-table .deal-title {
    max-width: 124px; white-space: normal; overflow-wrap: anywhere; line-height: 1.3;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  }

  /* Модалка на телефоне */
  .modal-overlay { padding: 16px 10px; }
  .modal-head, .modal-body, .modal-foot { padding-left: 16px; padding-right: 16px; }
  .modal-foot { flex-direction: column; align-items: stretch; gap: 12px; }
  .modal-actions { width: 100%; }
  .modal-actions .btn-primary, .modal-actions .btn-ghost { flex: 1; }
}
