/* ---------- Базовые токены ---------- */
:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --border: #e3e6ea;
  --border-soft: #eef0f3;
  --text: #1f2328;
  --muted: #6e7781;
  --primary: #2b6cb0;
  --primary-hover: #224d80;
  --primary-soft: #ebf4ff;
  --danger: #c53030;
  --green: #2f855a;
  --yellow: #b7791f;
  --gray: #718096;
  --sidebar-bg: #ffffff;
  --sidebar-border: #e3e6ea;
  --sidebar-w: 240px;
  --drawer-w: 560px;
  --radius: 8px;
}

/* Funding workspace: compact financial review with an explicit breakdown. */
.funding-head { display:flex; align-items:flex-start; justify-content:space-between; gap:20px; margin-bottom:18px; }
.funding-head h1 { margin:2px 0 4px; }
.funding-kpis { display:grid; grid-template-columns:repeat(4,minmax(120px,1fr)); gap:10px; margin-bottom:16px; }
.funding-kpi { border:1px solid var(--border); border-radius:10px; padding:12px 14px; background:var(--panel); }
.funding-kpi strong { display:block; font-size:20px; margin-top:4px; font-variant-numeric:tabular-nums; }
.funding-controls { display:flex; align-items:end; gap:10px; flex-wrap:wrap; margin-bottom:12px; }
.funding-controls label { display:grid; gap:5px; font-size:12px; color:var(--muted); }
.funding-controls input, .funding-controls select { min-height:38px; }
.funding-table-wrap { overflow-x:auto; border:1px solid var(--border); border-radius:10px; background:var(--panel); }
.funding-table { width:100%; border-collapse:collapse; min-width:930px; }
.funding-table th, .funding-table td { padding:11px 12px; border-bottom:1px solid var(--border); text-align:left; vertical-align:top; }
.funding-table th { color:var(--muted); font-size:12px; font-weight:600; background:var(--panel-2); }
.funding-table tr:last-child td { border-bottom:0; }
.funding-money { text-align:right !important; white-space:nowrap; font-variant-numeric:tabular-nums; }
.funding-detail-row td { padding:0; background:var(--panel-2); }
.funding-detail { padding:18px; display:grid; grid-template-columns:minmax(300px,1.15fr) minmax(280px,.85fr); gap:22px; }
.funding-breakdown { display:grid; gap:8px; }
.funding-line { display:grid; grid-template-columns:1fr auto; gap:12px; padding:8px 0; border-bottom:1px dashed var(--border); }
.funding-line b { font-variant-numeric:tabular-nums; }
.funding-line.total { font-size:16px; border-bottom:0; padding-top:12px; }
.funding-line.negative b { color:var(--danger,#b42318); }
.funding-formula { border-left:3px solid var(--accent,#4263eb); padding-left:14px; }
.funding-warnings { margin:10px 0 0; padding-left:20px; color:var(--danger,#b42318); }
.funding-settings { margin-bottom:16px; }
.funding-settings summary { cursor:pointer; font-weight:600; padding:12px 14px; }
.funding-settings-form { display:grid; grid-template-columns:repeat(4,minmax(150px,1fr)) auto; align-items:end; gap:10px; padding:0 14px 14px; }
.funding-settings-form label { display:grid; gap:5px; font-size:12px; color:var(--muted); }
.funding-status { display:inline-flex; align-items:center; border-radius:999px; padding:3px 8px; font-size:12px; white-space:nowrap; background:var(--panel-2); border:1px solid var(--border); }
.funding-status.confirmed { color:#067647; background:#ecfdf3; border-color:#abefc6; }
.funding-status.draft { color:#175cd3; background:#eff8ff; border-color:#b2ddff; }
.funding-status.unlinked, .funding-status.needs_data { color:#b54708; background:#fffaeb; border-color:#fedf89; }
.funding-status.deficit { color:#b42318; background:#fef3f2; border-color:#fecdca; }

@media (max-width: 850px) {
  .funding-kpis { grid-template-columns:repeat(2,minmax(120px,1fr)); }
  .funding-detail { grid-template-columns:1fr; }
  .funding-settings-form { grid-template-columns:1fr 1fr; }
}
@media (max-width: 560px) {
  .funding-head { display:block; }
  .funding-kpis { grid-template-columns:1fr; }
  .funding-settings-form { grid-template-columns:1fr; }
}

/* Only this new workspace gets a compact mobile shell; existing ERP pages stay untouched. */
@media (max-width: 720px) {
  body.funding-view { max-width:100%; overflow-x:hidden; }
  body.funding-view .app { display:block; min-height:100vh; }
  body.funding-view .sidebar {
    position:sticky; top:0; z-index:600; width:100%; height:auto;
    padding:8px 10px; border-right:0; border-bottom:1px solid var(--sidebar-border);
  }
  body.funding-view .brand { padding:0 4px 8px; margin-bottom:6px; }
  body.funding-view .brand-mark { width:28px; height:28px; }
  body.funding-view .sidebar-nav {
    flex-direction:row; overflow-x:auto; overscroll-behavior-inline:contain;
    scrollbar-width:thin; padding-bottom:3px;
  }
  body.funding-view .nav-item { flex:0 0 auto; white-space:nowrap; padding:7px 9px; }
  body.funding-view .nav-label { flex:0 0 auto; }
  body.funding-view .nav-divider, body.funding-view .sidebar-footer { display:none; }
  body.funding-view .content { padding:16px 14px 24px; }
  body.funding-view .funding-head > div,
  body.funding-view .funding-head .muted { max-width:100%; overflow-wrap:anywhere; }
  body.funding-view .funding-controls label { min-width:0; max-width:100%; }
  body.funding-view .funding-controls input,
  body.funding-view .funding-controls select { max-width:100%; }
  body.funding-view .funding-table-wrap { width:100%; max-width:100%; }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

button { font-family: inherit; }

/* ---------- App layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 16px 8px;
  border-bottom: 1px solid var(--border-soft);
  margin-bottom: 12px;
}
.brand-mark {
  width: 32px; height: 32px;
  background: var(--primary); color: white;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.brand-title { font-weight: 600; font-size: 14px; line-height: 1.1; }
.brand-version { color: var(--muted); font-size: 11px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 6px;
  color: var(--muted); text-decoration: none;
  font-size: 13.5px; cursor: pointer; user-select: none;
}
.nav-item:hover { background: var(--panel-2); color: var(--text); }
.nav-item.active {
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}
.nav-ico {
  width: 18px;
  display: inline-flex; justify-content: center;
  font-size: 14px; opacity: 0.85;
}
.nav-item.active .nav-ico { opacity: 1; }
.nav-label { flex: 1; }
.nav-soon {
  font-size: 10px; color: var(--muted);
  background: var(--panel-2);
  padding: 2px 6px; border-radius: 8px;
  text-transform: uppercase; letter-spacing: 0.04em;
}

/* Красный кружок-счётчик неразобранных лидов (как в мессенджерах) */
.nav-badge {
  margin-left: auto;
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #e5484d; color: #fff;
  font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  line-height: 1;
}
.nav-badge.hidden { display: none; }

.nav-divider { height: 1px; background: var(--border-soft); margin: 10px 4px; }

.sidebar-footer {
  margin-top: 8px; padding-top: 12px;
  border-top: 1px solid var(--border-soft);
}
.me { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 6px; }
.me-avatar {
  width: 32px; height: 32px;
  background: #ed8936; color: white;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.me-name { font-weight: 600; font-size: 13px; }
.me-role { color: var(--muted); font-size: 11px; }

/* ---------- Content ---------- */
.content { padding: 24px 28px; min-width: 0; }

.page-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 18px;
}
.page-head h1 { margin: 0; font-size: 22px; font-weight: 600; }
.page-head .crumb { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.page-head .right { display: flex; gap: 8px; align-items: center; }

.toolbar {
  display: flex; justify-content: space-between; align-items: center;
  margin: 0 0 16px 0; gap: 12px;
}
.toolbar h2 { margin: 0; font-size: 18px; font-weight: 600; }
.toolbar .right { display: flex; gap: 8px; align-items: center; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Buttons ---------- */
.btn-primary, .btn-secondary, .btn-link, .btn-danger {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 14px;
  font-size: 13px; cursor: pointer;
  font-family: inherit; font-weight: 500;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled {
  background: var(--panel-2); color: var(--muted);
  cursor: not-allowed; border-color: var(--border);
}
.btn-secondary { background: white; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--panel-2); }
.btn-link { background: transparent; color: var(--primary); padding: 4px 6px; }
.btn-link:hover { text-decoration: underline; }
.btn-danger { background: transparent; color: var(--danger); padding: 4px 6px; }
.btn-danger:hover { text-decoration: underline; }
.btn-close {
  background: none; border: none;
  font-size: 22px; color: var(--muted);
  cursor: pointer; line-height: 1; padding: 4px 8px;
}
.btn-close:hover { color: var(--text); }

select, input, textarea {
  padding: 7px 10px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--panel);
  font-size: 14px; font-family: inherit;
}
textarea { min-height: 70px; resize: vertical; width: 100%; }

/* ---------- Cards / tables ---------- */
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); margin-bottom: 16px; overflow: hidden;
}
.card-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px; border-bottom: 1px solid var(--border-soft);
}
.card-head h2 { margin: 0; font-size: 20px; }
.card-head h3 { margin: 0; font-size: 15px; }
.card-body { padding: 16px 20px; }

table {
  width: 100%; border-collapse: collapse;
  background: var(--panel);
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden;
}
table th, table td {
  padding: 10px 14px; text-align: left;
  border-bottom: 1px solid var(--border-soft); font-size: 13px;
}
table th {
  background: var(--panel-2); font-weight: 600;
  font-size: 11.5px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}
table tr:last-child td { border-bottom: none; }
table tr.clickable { cursor: pointer; }
table tr.clickable:hover td { background: #f2f6fb; }

.inner-table { border: none; border-radius: 0; }
.inner-table th { background: transparent; }
.row-actions { white-space: nowrap; text-align: right; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 2px 10px;
  border-radius: 10px;
  font-size: 12px; font-weight: 500;
  background: #edf2f7; color: var(--gray);
}
.badge-active   { background: #c6f6d5; color: var(--green); }
.badge-crm_invoice { background: #dbeafe; color: #1d4ed8; }
.badge-training { background: #fefcbf; color: var(--yellow); }
.badge-paused   { background: #feebc8; color: var(--yellow); }
.badge-fired    { background: #fed7d7; color: var(--danger); }
.badge-closed   { background: #e2e8f0; color: var(--gray); }
.badge-draft    { background: #e2e8f0; color: var(--gray); }
.badge-candidate{ background: #bee3f8; color: #2c5282; }

/* ---------- Pair (label/value rows in cards) ---------- */
.pair {
  display: grid; grid-template-columns: 220px 1fr;
  padding: 6px 0; gap: 12px;
  border-bottom: 1px dashed var(--border-soft);
}
.pair:last-child { border-bottom: none; }
.pair-label { color: var(--muted); }
.pair-value { color: var(--text); }
.pair.notes .pair-value { white-space: pre-wrap; }
.pair-value code {
  background: var(--bg); padding: 1px 6px;
  border-radius: 3px;
  font-family: ui-monospace, monospace;
  font-size: 12px; margin-right: 8px;
}
.pair-value .badge { margin-right: 8px; }

/* ---------- Drawer (right slide-over) ---------- */
.drawer {
  position: fixed; top: 0; right: 0;
  width: var(--drawer-w); max-width: 96vw; height: 100vh;
  background: var(--panel); border-left: 1px solid var(--border);
  box-shadow: -8px 0 30px rgba(15, 23, 42, 0.08);
  display: flex; flex-direction: column;
  z-index: 200;
  transform: translateX(0);
  transition: transform 0.22s ease;
}
.drawer.hidden { transform: translateX(105%); pointer-events: none; }
.drawer-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  padding: 18px 22px; border-bottom: 1px solid var(--border-soft);
}
.drawer-eyebrow {
  color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 2px;
}
.drawer-head h2 { margin: 0; font-size: 18px; font-weight: 600; }
.drawer-body { flex: 1; overflow-y: auto; padding: 18px 22px; }
.drawer-foot {
  padding: 14px 22px; border-top: 1px solid var(--border-soft);
  display: flex; justify-content: flex-end; gap: 8px;
}
.drawer-foot.hidden { display: none; }

.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.25);
  z-index: 150;
  opacity: 1;
  transition: opacity 0.2s ease;
}
.drawer-backdrop.hidden { opacity: 0; pointer-events: none; }

/* ---------- Form (внутри drawer) ---------- */
.form {
  display: grid; grid-template-columns: 180px 1fr;
  gap: 10px 14px; align-items: center;
}
.form label { font-size: 13px; color: var(--muted); }
.form input, .form select, .form textarea { width: 100%; }
.form .req { color: var(--danger); margin-left: 2px; }
.form-hint-row {
  grid-column: 1 / -1;
  display: grid; grid-template-columns: 180px 1fr; gap: 14px;
  margin-top: -4px;
}
.form-hint { font-size: 12px; color: var(--muted); font-style: italic; }
.form details.extra {
  grid-column: 1 / -1; margin-top: 8px;
  border-top: 1px solid var(--border-soft); padding-top: 8px;
}
.form details.extra summary {
  cursor: pointer; font-size: 13px; color: var(--muted); padding: 4px 0;
}
.form .extra-grid {
  display: grid; grid-template-columns: 180px 1fr; gap: 10px 14px;
  align-items: center; margin-top: 8px;
}

/* ---------- Toast ---------- */
#toast-layer {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 1000;
  display: flex; flex-direction: column; gap: 8px; max-width: 420px;
}
.toast {
  background: #2d3748; color: white;
  padding: 12px 16px; border-radius: 8px;
  display: flex; align-items: flex-start; gap: 12px;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}
.toast a { color: #90cdf4; text-decoration: underline; }
.toast code {
  background: rgba(255,255,255,0.15);
  padding: 1px 6px; border-radius: 3px;
  font-family: ui-monospace, monospace; font-size: 12px;
}
.toast-msg { flex: 1; line-height: 1.45; }
.toast-close {
  background: none; border: none; color: white;
  cursor: pointer; font-size: 18px; line-height: 1; opacity: 0.6;
}
.toast-close:hover { opacity: 1; }
.toast-info { background: #2b6cb0; }

/* ---------- Progress bar (карточка проекта) ---------- */
.progress-row { display: flex; flex-direction: column; gap: 10px; }
.progress-numbers { display: flex; align-items: baseline; gap: 10px; }
.progress-big { font-size: 32px; font-weight: 600; color: var(--text); }
.progress-bar {
  height: 10px; background: var(--bg);
  border-radius: 5px; overflow: hidden; border: 1px solid var(--border);
}
.progress-fill { height: 100%; background: var(--green); transition: width 0.3s ease; }
.progress-fill.overrun { background: var(--danger); }
.progress-meta { font-size: 13px; }

/* ---------- Чек-лист ---------- */
.checklist { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.checklist li { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 14px; }
.checklist li.done .check-label { color: var(--text); }
.checklist li.pending .check-label { color: var(--muted); }
.check-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  font-size: 13px; font-weight: 600;
}
.checklist li.done .check-mark { background: #c6f6d5; color: var(--green); }
.checklist li.pending .check-mark { background: #edf2f7; color: var(--muted); }

/* ---------- Артефакты клиента ---------- */
.artifact-row {
  display: grid; grid-template-columns: 220px 1fr auto;
  gap: 14px; padding: 10px 0;
  border-bottom: 1px dashed var(--border-soft);
  align-items: center;
}
.artifact-row:last-child { border-bottom: none; }
.artifact-label { color: var(--muted); font-size: 13px; }
.artifact-value { font-size: 13px; }
.artifact-value code {
  background: var(--bg); padding: 1px 6px;
  border-radius: 3px;
  font-family: ui-monospace, monospace;
  font-size: 12px; margin-right: 8px;
}
.reset-btn {
  font-size: 16px; font-weight: bold; color: var(--danger);
  padding: 0 6px; margin-left: 6px;
  background: none; border: none; cursor: pointer; vertical-align: middle;
}
.reset-btn:hover { color: #9b2c2c; }

/* ---------- Integrations cards ---------- */
.integrations-list { display: flex; flex-direction: column; gap: 16px; }
.int-card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px;
}
.int-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.int-head h3 { margin: 0; font-size: 16px; }
.int-meta { display: flex; gap: 10px; align-items: center; margin-top: 6px; font-size: 12px; color: var(--muted); }
.int-meta code {
  background: var(--bg); padding: 1px 6px; border-radius: 3px;
  font-family: ui-monospace, monospace;
}
.int-desc { margin: 10px 0 14px 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.int-form {
  border-top: 1px dashed var(--border-soft); padding-top: 14px; margin-top: 8px;
  display: flex; flex-direction: column; gap: 12px;
}
/* ---------- Form (MD bill modal etc) ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid .field { display: flex; flex-direction: column; gap: 4px; }
.form-grid .field > .label,
.form-row .field > .label {
  font-size: 12px; color: var(--muted); font-weight: 500;
}
.form-grid .field > input,
.form-grid .field > select,
.form-grid .field > textarea,
.form-row  .field > input,
.form-row  .field > select,
.form-row  .field > textarea {
  width: 100%; height: 36px; box-sizing: border-box;
}
.form-grid .field > textarea,
.form-row  .field > textarea { height: auto; min-height: 60px; }
.form-row { display: flex; gap: 12px; }
.form-row .field { flex: 1; display: flex; flex-direction: column; gap: 4px; }

.int-field { display: grid; grid-template-columns: 200px 1fr; gap: 8px 14px; align-items: center; }
.int-field label { color: var(--muted); font-size: 13px; }
.int-field input {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  font-family: inherit; font-size: 13px; width: 100%;
}
.int-field .form-hint { grid-column: 2 / 3; margin-top: -4px; }
.int-actions { display: flex; gap: 10px; align-items: center; padding-top: 6px; border-top: 1px dashed var(--border-soft); }
.int-last-check { margin-left: auto; font-size: 12px; }
.int-error {
  margin-top: 8px; padding: 8px 12px;
  background: #fff5f5; color: var(--danger);
  border: 1px solid #fed7d7; border-radius: 6px;
  font-size: 12px; font-family: ui-monospace, monospace; white-space: pre-wrap;
}
.toggle { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; font-size: 13px; }
.toggle input { width: 16px; height: 16px; cursor: pointer; }

/* ---------- Прогресс в ячейке таблицы ---------- */
.cell-progress { display: flex; flex-direction: column; gap: 4px; min-width: 180px; }
.cell-progress-bar {
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.cell-progress-fill {
  height: 100%;
  background: var(--green);
  transition: width 0.3s ease;
}
.cell-progress-fill.overrun { background: var(--danger); }
.cell-progress-text { font-size: 12px; color: var(--text); }
.cell-balance { font-size: 12px; font-weight: 600; margin-top: 2px; }
.cell-balance.bad { color: var(--danger); }
.cell-balance.ok  { color: var(--green);  }

/* ---------- Dashboard ---------- */
.dash-period { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.period-tabs { display: flex; gap: 4px; }
.period-btn {
  padding: 6px 12px; font-size: 13px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  cursor: pointer;
}
.period-btn:hover { background: var(--bg-hover, #f5f5f5); }
.period-btn.active { background: var(--primary); color: white; border-color: var(--primary); }
.period-custom { display: flex; gap: 6px; align-items: center; font-size: 13px; }
.period-custom input { padding: 4px 8px; border: 1px solid var(--border); border-radius: 4px; }

/* ============ Дашборд ============ */
/* Тайлы KPI: спокойная поверхность, крупное число, статус — точкой, не рамкой */
.dash-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px 12px;
  min-width: 0;
}
.kpi-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  margin-bottom: 6px; white-space: nowrap; overflow: hidden;
}
.kpi-dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; }
.kpi-dot-bad  { background: var(--danger); }
.kpi-dot-warn { background: var(--yellow); }
.kpi-value {
  font-size: 26px; font-weight: 700; line-height: 1.15;
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.kpi-hint { font-size: 12px; color: var(--muted); margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Сетка карточек */
.dash-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 14px;
  align-items: start;
}
.dash-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 18px;
  min-width: 0;
}
.dash-card-wide { grid-column: 1 / -1; }
.dash-card-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 12px;
}
.dash-card-head h3, .dash-card h3 {
  margin: 0; font-size: 12px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.dash-count {
  font-weight: 600; color: var(--text);
  background: var(--panel-2); border: 1px solid var(--border-soft);
  border-radius: 10px; padding: 0 8px; margin-left: 6px; font-size: 11px;
}
.dash-empty { font-size: 13px; color: var(--muted); padding: 6px 0 2px; }

.link-btn {
  background: none; border: none; padding: 0;
  color: var(--primary); cursor: pointer; font-size: 13px;
}
.link-btn:hover { text-decoration: underline; }

/* Здоровье пакетов: тонкий бар, статусные цвета только по смыслу */
.health-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 10px 14px;
}
.health-mini {
  padding: 10px 12px 9px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: var(--panel);
  display: flex; flex-direction: column; gap: 7px;
  cursor: pointer;
}
.health-mini:hover { border-color: var(--border); background: var(--panel-2); }
.health-mini-top {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.health-mini-name {
  font-weight: 600; font-size: 13px; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hb-badge {
  flex: 0 0 auto; font-size: 11px; font-weight: 600;
  color: var(--muted); background: var(--panel-2);
  border-radius: 9px; padding: 2px 8px;
}
.hb-badge.bad  { color: #fff; background: var(--danger); }
.hb-badge.done { color: var(--green); background: #e6f4ec; }
.hbar {
  height: 6px; border-radius: 4px; background: var(--border-soft);
  overflow: hidden;
}
.hbar-fill {
  height: 100%; border-radius: 4px; background: var(--primary);
  min-width: 2px;
}
.hbar-fill.overrun { background: var(--danger); }
.health-mini-meta {
  font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums;
}

/* Списки (пакеты на исходе, должники) */
.dash-list { list-style: none; padding: 0; margin: 0; }
.dash-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 9px 8px; border-bottom: 1px solid var(--border-soft);
  border-radius: 6px; cursor: pointer;
}
.dash-list li:last-child { border-bottom: none; }
.dash-list li:hover { background: var(--panel-2); }
.dash-list-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dash-list-main strong {
  font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.dash-days {
  flex: 0 0 auto; font-size: 20px; font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.dash-days span { font-size: 11px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.dash-days.bad  { color: var(--danger); }
.dash-days.warn { color: var(--yellow); }
.dash-owed { flex: 0 0 auto; font-size: 14px; font-weight: 700;
  font-variant-numeric: tabular-nums; }
.dash-owed.bad  { color: var(--danger); }
.dash-owed.warn { color: var(--yellow); font-size: 12px; font-weight: 600; }

/* Сигналы */
.dash-alerts { list-style: none; padding: 0; margin: 0;
  display: flex; flex-direction: column; gap: 6px; }
.dash-alerts li {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 8px 10px; border-radius: 8px; font-size: 13px; line-height: 1.35;
}
.dash-alerts li.alert-danger { background: #fdf1f1; }
.dash-alerts li.alert-warn   { background: #fbf6ec; }
.alert-ico { flex: 0 0 auto; font-size: 13px; line-height: 1.35; }
.alert-body { min-width: 0; }
.dash-alerts li a { color: inherit; font-weight: 600; text-decoration: none; }
.dash-alerts li a:hover { text-decoration: underline; }

/* История TG-алертов — свёрнута по умолчанию */
.dash-details summary {
  display: flex; justify-content: space-between; align-items: center;
  cursor: pointer; list-style: none;
  font-size: 12px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
}
.dash-details summary::-webkit-details-marker { display: none; }
.dash-details summary::before { content: "▸ "; color: var(--muted); }
.dash-details[open] summary::before { content: "▾ "; }

.dash-table { width: 100%; font-size: 13px; border-collapse: collapse; }
.dash-table th { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); font-weight: 600; color: var(--muted); }
.dash-table td { padding: 8px; border-bottom: 1px solid var(--border-soft); }
.dash-table tr.clickable:hover { background: var(--panel-2); cursor: pointer; }
.bal { font-weight: 600; font-size: 12px; }
.bal.bad { color: var(--danger); }
.bal.ok  { color: var(--green);  }

/* KPI delta (стрелки прирост/убыль) */
.kpi-delta { font-size: 12px; font-weight: 600; margin-left: 6px; vertical-align: middle; }
.kpi-delta.kpi-up   { color: var(--green); }
.kpi-delta.kpi-down { color: var(--danger); }
.kpi-delta.muted    { color: var(--muted); }

/* ---------- Analytics: controls ---------- */
.conversion-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.conversion-controls label { display: flex; align-items: center; gap: 5px; font-size: 13px; }
.conversion-controls input[type="date"] { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; background: white; }
.conversion-project-filter { position: relative; z-index: 5; }
.conversion-project-filter summary { cursor: pointer; border: 1px solid var(--border); border-radius: 6px; background: white; padding: 7px 10px; min-width: 170px; }
.conversion-project-panel { position: absolute; top: calc(100% + 4px); left: 0; width: min(380px, 85vw); background: white; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 22px #0002; padding: 10px; }
.conversion-project-actions { display: flex; gap: 10px; padding-bottom: 8px; }
.conversion-project-options { display: grid; gap: 2px; max-height: 280px; overflow-y: auto; }
.conversion-controls .conversion-project-option { display: flex; align-items: flex-start; gap: 8px; padding: 5px; cursor: pointer; line-height: 1.35; }
.conversion-project-option:hover { background: var(--panel-2); }
.conversion-project-option input { flex: none; margin-top: 2px; }
.conversion-project-option span { overflow-wrap: anywhere; }
.conversion-scroll { overflow-x: auto; max-width: 100%; border: 1px solid var(--border); border-radius: 8px; }
.conversion-table { width: max-content; min-width: 100%; border: 0; border-collapse: separate; border-spacing: 0; overflow: visible; font-size: 12px; }
.conversion-table th, .conversion-table td { min-width: 116px; padding: 8px; vertical-align: top; border-right: 1px solid var(--border-soft); border-bottom: 1px solid var(--border-soft); }
.conversion-table thead th { background: var(--panel-2); text-align: center; white-space: nowrap; }
.conversion-table .conversion-project-col { position: sticky; left: 0; z-index: 2; min-width: 220px; max-width: 280px; background: white; text-align: left; white-space: normal; box-shadow: 2px 0 4px #0001; }
.conversion-table thead .conversion-project-col { z-index: 3; background: var(--panel-2); }
.conversion-project-label { display: flex; align-items: flex-start; gap: 8px; cursor: pointer; font-size: 12px; font-weight: 600; line-height: 1.35; text-transform: none; letter-spacing: normal; }
.conversion-project-label input { flex: none; margin-top: 2px; }
.conversion-project-label span { overflow-wrap: anywhere; }
.conversion-project-label small { display: block; margin-top: 3px; font-weight: 400; }
.conversion-table .conversion-total { background: var(--panel-2); }
.conversion-table .conversion-group-row td, .conversion-table .conversion-group-row .conversion-project-col { background: var(--panel-2); }
.conversion-cell { display: grid; gap: 3px; white-space: nowrap; }
.conversion-cell span { display: flex; justify-content: space-between; gap: 10px; }

.analytics-controls { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.an-project {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: white; min-width: 240px; font-size: 13px;
}

/* ---------- Analytics: chart ---------- */
.chart { width: 100%; height: auto; max-height: 240px; display: block; }
.ch-line { fill: none; stroke: var(--accent, #2563eb); stroke-width: 2; }
.ch-dot  { fill: var(--accent, #2563eb); }
.ch-label { font-size: 10px; fill: var(--muted); }
.ch-grid  { stroke: var(--border); stroke-width: 1; stroke-dasharray: 2 3; opacity: 0.6; }

/* ---------- Analytics: heatmap ---------- */
.heatmap { display: flex; flex-direction: column; gap: 2px; font-size: 11px; }
.heatmap-row { display: grid; grid-template-columns: 28px repeat(15, 1fr); gap: 2px; }
.heatmap-row .cell {
  height: 22px; display: flex; align-items: center; justify-content: center;
  background: #f5f5f5; border-radius: 2px; color: #333;
}
.heatmap-row .cell.hdr {
  background: transparent; font-weight: 600; color: var(--muted); font-size: 10px;
}

/* ---------- Payouts ---------- */
.payouts-head {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 24px; align-items: center;
  padding: 16px;
  background: var(--card-bg, white);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 14px;
}
.payouts-period { font-size: 18px; font-weight: 700; }
.payouts-totals {
  display: flex; gap: 24px; flex-wrap: wrap;
}
.payouts-totals > div b { font-size: 18px; }
.payouts-actions { display: flex; gap: 8px; align-items: center; }

.payouts-table th.right, .payouts-table td.right { text-align: right; }
.payouts-table tbody tr:hover { background: var(--bg-hover, #fafafa); }

.payout-status {
  padding: 4px 8px; border-radius: 12px;
  border: 1px solid var(--border); font-size: 12px; font-weight: 600;
  cursor: pointer;
}
.payout-status.status-not_paid { background: #fff4e0; color: #b45309; border-color: #fbbf24; }
.payout-status.status-paid     { background: #dcfce7; color: #166534; border-color: #4ade80; }
.payout-status.status-deferred { background: #e0e7ff; color: #3730a3; border-color: #818cf8; }

.alert-warn {
  background: rgba(245, 158, 11, 0.1);
  border-left: 3px solid #f59e0b;
  padding: 10px 14px; border-radius: 4px;
  font-size: 13px;
}

.btn-secondary.small { padding: 3px 10px; font-size: 12px; }
td.empty { text-align: center; padding: 30px; color: var(--muted); }

/* ---------- Analytics: operator bar in table ---------- */
.op-bar { display: inline-block; width: 60px; height: 6px; background: var(--bg, #f0f0f0);
          border-radius: 3px; vertical-align: middle; margin-right: 6px; overflow: hidden; }
.op-bar-fill { height: 100%; background: var(--accent, #2563eb); }

/* ---------- Finance / Pace / Tasks ---------- */
.finance-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 12px;
}
.finance-cell {
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.finance-cell.finance-margin {
  background: #f0fff4;
  border-color: #c6f6d5;
}
.cell-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.cell-big {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
}
.cell-sub {
  font-size: 11.5px;
  margin-top: 4px;
  line-height: 1.4;
}
.finance-notes {
  border-top: 1px dashed var(--border-soft);
  padding-top: 10px;
  margin-top: 8px;
  line-height: 1.55;
}

/* Pace */
.pace-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
.pace-stat {
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.pace-graph {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px 0 4px 0;
  border-top: 1px dashed var(--border-soft);
  margin-top: 6px;
}
.pace-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: default;
}
.pace-bar-fill {
  width: 100%;
  max-width: 28px;
  background: var(--primary);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
}
.pace-bar-count {
  font-size: 10px;
  color: var(--muted);
  height: 12px;
}
.pace-bar-label {
  font-size: 10px;
  color: var(--muted);
  white-space: nowrap;
}

/* Tasks */
.tasks {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.task {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 12px;
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.task-mark {
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  background: #fefcbf; color: var(--yellow);
  border-radius: 50%;
  font-weight: 700;
}
.task-title { font-size: 14px; }
.task-meta { margin-top: 2px; }
.task-action { white-space: nowrap; }

/* Прогресс-ячейка в общей таблице проектов */
.cell-progress {
  display: flex; flex-direction: column; gap: 4px;
}
.cell-progress-bar {
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.cell-progress-fill { height: 100%; background: var(--green); }
.cell-progress-fill.overrun { background: var(--danger); }
.cell-progress-text { font-size: 12px; }

/* ---------- Плитки проектов на карточке клиента ---------- */
.project-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.proj-tile {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s, transform 0.05s;
}
.proj-tile:hover { border-color: var(--primary); }
.proj-tile:active { transform: scale(0.995); }
.proj-tile-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.proj-tile-head strong { font-size: 14px; }
.proj-tile-stats { font-size: 13px; }
.proj-tile-big { font-size: 22px; font-weight: 600; color: var(--text); }
.proj-tile-bonus {
  margin-top: -4px;
  color: var(--green) !important;
  font-weight: 500;
}
.proj-tile-foot {
  display: flex; gap: 8px; align-items: center;
  margin-top: 2px;
}
.proj-tile-foot code {
  background: var(--bg); padding: 1px 6px; border-radius: 3px;
  font-family: ui-monospace, monospace; font-size: 11px;
}

.projects-table-toggle { margin-top: 8px; }
.projects-table-toggle summary {
  cursor: pointer; padding: 6px 0;
  border-top: 1px dashed var(--border-soft);
}

/* ---------- Timeline (история событий) ---------- */
.timeline {
  list-style: none;
  padding: 0;
  margin: 0;
  position: relative;
}
.timeline::before {
  content: "";
  position: absolute;
  left: 7px;
  top: 6px;
  bottom: 6px;
  width: 1px;
  background: var(--border-soft);
}
.tl-item {
  position: relative;
  padding: 6px 0 14px 28px;
}
.tl-item:last-child { padding-bottom: 0; }
.tl-marker {
  position: absolute;
  left: 0;
  top: 9px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--panel);
  border: 2px solid var(--gray);
}
.tl-client_created  .tl-marker { border-color: var(--primary); background: var(--primary-soft); }
.tl-project_created .tl-marker { border-color: var(--green); }
.tl-project_started .tl-marker { background: var(--green); border-color: var(--green); }
.tl-contract_added  .tl-marker { border-color: var(--yellow); }
.tl-contract_signed .tl-marker { background: var(--yellow); border-color: var(--yellow); }
.tl-head {
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
  margin-bottom: 2px;
}
.tl-date { color: var(--muted); font-size: 12px; }
.tl-time { color: var(--muted); }
.tl-tag {
  background: var(--panel-2);
  color: var(--muted);
  padding: 1px 7px;
  border-radius: 8px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.tl-title { font-size: 14px; }
.tl-details { margin-top: 2px; }

/* ---------- Заглушка «скоро» ---------- */
.placeholder {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 100px 30px; text-align: center;
  background: var(--panel); border: 1px dashed var(--border);
  border-radius: var(--radius);
}
.placeholder-ico { font-size: 48px; color: var(--muted); opacity: 0.4; margin-bottom: 16px; }
.placeholder h2 { margin: 0 0 8px 0; font-size: 18px; color: var(--text); }
.placeholder p { margin: 0; color: var(--muted); max-width: 480px; font-size: 13.5px; line-height: 1.5; }

/* --- Auth: login-модал и user-chip --- */
.login-backdrop {
  position: fixed; inset: 0; background: rgba(15,20,30,.45);
  display: flex; align-items: center; justify-content: center; z-index: 9000;
}
.login-card {
  background: var(--panel); padding: 32px; border-radius: var(--radius);
  width: 340px; display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 16px 48px rgba(15,20,30,.18);
  border: 1px solid var(--border);
}
.login-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; color: var(--text); }
.login-card input {
  padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 6px; background: var(--panel-2); color: var(--text);
  font-size: 14px;
}
.login-card input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.login-card button {
  padding: 10px; background: var(--primary); color: #fff;
  border: 0; border-radius: 6px; font-weight: 600; cursor: pointer;
}
.login-card button:hover { background: var(--primary-hover); }
.login-error { color: var(--danger); font-size: 13px; min-height: 16px; }

/* Бейдж роли (используется внутри .me в сайдбар-футере) */
.user-chip-role {
  display: inline-block;
  font-size: 10px; padding: 1px 8px; border-radius: 999px;
  text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600;
}
.user-chip-role.role-admin  { background: var(--primary-soft); color: var(--primary); }
.user-chip-role.role-viewer { background: var(--border-soft); color: var(--muted); }

/* Кнопка выхода рядом с именем */
.me-logout {
  margin-left: auto;
  width: 28px; height: 28px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  border-radius: 6px;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}
.me-logout:hover { background: var(--border-soft); color: var(--text); }

/* В viewer-режиме все кнопки .admin-only прячутся */
body.role-viewer .admin-only { display: none !important; }
/* Опасные действия (recalc/resync/import) — только super-admin */
body:not(.is-super) .super-only { display: none !important; }

/* --- Сворачивание .card-блоков по клику на h3 --- */
.card.collapsible .card-head {
  cursor: pointer;
  user-select: none;
}
.card.collapsible .card-head h3::before {
  content: "▾";
  display: inline-block;
  margin-right: 8px;
  font-size: 0.75em;
  color: var(--muted);
  transition: transform 0.15s;
}
.card.collapsible.collapsed .card-head h3::before {
  transform: rotate(-90deg);
}
.card.collapsible.collapsed > .card-body {
  display: none;
}
.card.collapsible:not(.collapsed) .card-head:hover h3::before {
  color: var(--primary);
}

/* --- Универсальная сортировка таблиц --- */
table th {
  cursor: pointer;
  user-select: none;
  position: relative;
}
table th:empty {
  cursor: default;
}
table th[data-no-sort="true"] {
  cursor: default;
}
table th:not(:empty):not([data-no-sort="true"]):hover {
  background: var(--border-soft);
}
table th[data-sort-dir]::after {
  content: "↑";
  margin-left: 4px;
  opacity: 0.7;
  font-size: 0.9em;
}
table th[data-sort-dir="desc"]::after {
  content: "↓";
}

/* --- Матрица команды (чекбоксы) --- */
.team-matrix .cell-tick {
  text-align: center;
  padding: 6px;
}
.team-matrix .team-tick {
  cursor: pointer;
  width: 18px;
  height: 18px;
}
.team-matrix th {
  font-size: 12px;
  white-space: nowrap;
}

/* --- Действия рядом с пунктом чек-листа --- */
.checklist li .btn-link {
  margin-left: 8px;
  font-size: 12px;
}

/* --- Платежи клиента --- */
.payments-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.ps-item {
  background: var(--panel-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.ps-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.ps-value { font-size: 18px; font-weight: 600; margin-top: 4px; color: var(--text); }

/* --- Подзакладки на карточке проекта --- */
.sub-tabs {
  display: flex;
  gap: 4px;
  margin: 14px 0;
  border-bottom: 1px solid var(--border);
}
.sub-tab {
  padding: 10px 18px;
  text-decoration: none;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  font-weight: 500;
  font-size: 14px;
  transition: color 0.1s, border-color 0.1s;
}
.sub-tab:hover { color: var(--text); }
.sub-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* --- Матрица прав сотрудника --- */
.perm-matrix th, .perm-matrix td { text-align: left; padding: 8px 12px; }
.perm-matrix th:nth-child(2), .perm-matrix th:nth-child(3),
.perm-matrix td:nth-child(2), .perm-matrix td:nth-child(3) {
  text-align: center; width: 90px;
}
.perm-matrix .perm-check { width: 18px; height: 18px; cursor: pointer; }

/* --- Лог действий --- */
.event-log { list-style: none; padding: 0; margin: 0; }
.event-item {
  padding: 10px 12px;
  border-left: 3px solid var(--border);
  margin-bottom: 8px;
  background: var(--panel-2);
  border-radius: 4px;
}
.event-item.event-payment   { border-left-color: var(--green); }
.event-item.event-lead      { border-left-color: var(--yellow); }
.event-item.event-project   { border-left-color: var(--primary); }
.event-head {
  display: flex; gap: 8px; align-items: baseline;
  font-size: 13px;
}
.event-kind { font-weight: 600; color: var(--text); }
.event-summary { font-size: 13px; color: var(--text); margin-top: 4px; }

/* Отклонённый ОКК квал-лид */
tr.lead-rejected {
  background: rgba(197, 48, 48, 0.04);
  color: var(--muted);
}
tr.lead-rejected code { opacity: 0.7; }

.cell-purpose {
  max-width: 360px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* --- Finance banner на странице клиентов --- */
.finance-banner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.fb-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.fb-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.fb-value { font-size: 20px; font-weight: 600; margin-top: 4px; color: var(--text); }
.fb-warn {
  border-color: var(--yellow);
  background: #fffbeb;
  cursor: pointer;
}
.fb-warn:hover { background: #fef3c7; }
.fb-warn .fb-value { color: var(--yellow); }

/* --- Страница «К разбору» --- */
.unmatched-group .card-head {
  flex-wrap: wrap;
  gap: 10px;
}
.unmatched-actions {
  display: flex; gap: 8px; align-items: center;
}
.match-client-select {
  min-width: 240px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  font-size: 13px;
}

/* ---------- ОКК-таблица ---------- */
.okk-table td { vertical-align: top; }
.okk-row-kval { background: #f6fff6; }

/* Трёх-сегментный переключатель решения ОКК.
   Каждая клетка таблицы — это group из 3 кнопок (Да / Ожидает / Нет),
   активная подсвечена цветом. */
.okk-decision-seg {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.okk-decision-seg .seg {
  border: 0;
  border-left: 1px solid var(--border);
  background: var(--panel);
  cursor: pointer;
  padding: 4px 10px;
  font-size: 12px;
  color: #555;
  white-space: nowrap;
}
.okk-decision-seg .seg:first-child { border-left: 0; }
.okk-decision-seg .seg:hover { background: #f4f5f6; color: #000; }
.okk-decision-seg .seg-active-yes {
  background: #d8f5d8; color: #1b7a1b; font-weight: 700;
}
.okk-decision-seg .seg-active-no {
  background: #f5d8d8; color: #b81b1b; font-weight: 700;
}
.okk-decision-seg .seg-active-pending {
  background: #eee; color: #444; font-weight: 700;
}

/* ---------- Матрица прав на странице Настройки ---------- */
.perm-grid {
  border-collapse: collapse;
  font-size: 13px;
  width: auto;
  min-width: 100%;
}
.perm-grid th, .perm-grid td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: center;
  vertical-align: middle;
}
.perm-grid th { background: var(--panel-2); white-space: nowrap; }
.perm-grid th.emp-name, .perm-grid td.emp-name {
  text-align: left; min-width: 220px;
}
.perm-grid td.emp-role, .perm-grid th.emp-role { min-width: 100px; }
.perm-grid tr:nth-child(even) td { background: var(--panel-2); }
.perm-grid input[type="checkbox"] { transform: scale(1.15); cursor: pointer; }

/* ---------- Поисковый селект (combobox «как в поисковике») ---------- */
.ssel { position: relative; display: block; width: 100%; }
.ssel-input {
  width: 100%; box-sizing: border-box; padding-right: 30px; display: block;
}
.ssel-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.ssel-clear {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 13px; padding: 4px 6px; display: none; line-height: 1;
}
.ssel-clear:hover { color: var(--danger); }
.ssel.has-value .ssel-clear { display: block; }
.ssel.has-value .ssel-input { font-weight: 500; }
.ssel-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 500;
  max-height: 320px; overflow-y: auto; background: var(--panel);
  border: 1px solid var(--border); border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); font-weight: 400;
}
.ssel-item {
  padding: 7px 10px; cursor: pointer; display: flex; justify-content: space-between;
  gap: 10px; align-items: baseline; font-size: 14px; color: var(--text);
}
.ssel-item + .ssel-item { border-top: 1px solid var(--border-soft); }
.ssel-item:hover, .ssel-item.is-active { background: var(--primary-soft); }
.ssel-item.is-selected .ssel-label { color: var(--primary); font-weight: 600; }
.ssel-all { color: var(--muted); font-style: italic; }
.ssel-label { flex: 1 1 auto; min-width: 0; }
.ssel-hint { flex: 0 0 auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.ssel-item mark { background: #fff3b0; color: inherit; padding: 0 1px; border-radius: 2px; }
.ssel-empty { padding: 8px 10px; color: var(--muted); font-size: 13px; }

/* ---------- Контроль запуска ---------- */
.launch-head { align-items: center; }
.launch-summary { display: grid; grid-template-columns: repeat(4, minmax(140px, 1fr)); border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); margin-bottom: 16px; }
.launch-summary > div { padding: 16px 18px; border-right: 1px solid var(--border-soft); }
.launch-summary > div:last-child { border-right: 0; }
.launch-summary span { display: block; color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.launch-summary strong { font-size: 23px; }
.launch-loading, .launch-error { grid-column: 1 / -1; padding: 20px; color: var(--muted); }
.launch-error { color: var(--danger); background: #fff7f7; border: 1px solid #f4cccc; border-radius: var(--radius); }
.launch-layout { display: grid; grid-template-columns: minmax(440px, 1.15fr) minmax(360px, .85fr); gap: 16px; align-items: start; margin-bottom: 16px; }
#launch-list, #launch-detail { min-width: 0; }
#launch-list { display: grid; gap: 8px; }
.launch-row { width: 100%; display: grid; grid-template-columns: minmax(180px, 1.5fr) minmax(80px, .8fr) 48px auto; gap: 12px; align-items: center; min-height: 72px; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: var(--text); text-align: left; cursor: pointer; }
.launch-row:hover, .launch-row.active { border-color: #94b9dc; background: #f7fbff; }
.launch-row.active { box-shadow: inset 3px 0 var(--primary); }
.launch-row-main { min-width: 0; }
.launch-row-main strong, .launch-row-main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.launch-row-main small { color: var(--muted); margin-top: 5px; }
.launch-row > .badge { justify-self: end; }
.launch-progress { height: 7px; border-radius: 7px; background: #e8ebee; overflow: hidden; }
.launch-progress i { display: block; height: 100%; background: var(--primary); }
.launch-score { font-size: 12px; font-variant-numeric: tabular-nums; color: var(--muted); }
#launch-detail { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); min-height: 230px; position: sticky; top: 16px; }
.launch-placeholder { padding: 42px 28px; color: var(--muted); text-align: center; }
.launch-detail-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--border-soft); }
.launch-detail-head h2 { margin: 4px 0 0; font-size: 19px; }
.launch-head-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.readiness-list { list-style: none; padding: 8px 20px 16px; margin: 0; }
.readiness-list li { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border-soft); }
.readiness-list li:last-child { border-bottom: 0; }
.readiness-mark { width: 22px; height: 22px; flex: 0 0 22px; display: grid; place-items: center; border-radius: 50%; font-weight: 700; }
.readiness-list .is-ok .readiness-mark { background: #d9f1e3; color: #1e7047; }
.readiness-list .is-blocked .readiness-mark { background: #fbe1df; color: var(--danger); }
.readiness-list .is-optional .readiness-mark { background: #eceff2; color: var(--muted); }
.readiness-list strong, .readiness-list small { display: block; }
.readiness-list small { color: var(--muted); margin-top: 3px; line-height: 1.3; }
.launch-subhead { padding: 14px 20px 0; margin: 0; font-size: 14px; border-top: 1px solid var(--border-soft); }
.launch-step-list, .launch-stage { padding: 10px 20px 18px; }
.launch-step-list > div { display: grid; grid-template-columns: 1fr auto; gap: 8px; padding: 7px 0; }
.launch-step-list small, .launch-stage small { grid-column: 1 / -1; color: var(--danger); overflow-wrap: anywhere; }
.launch-stage { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.launch-queue-card { overflow: visible; }
.launch-table-wrap { overflow-x: auto; }
.launch-cell-note { display: block; color: var(--muted); margin-top: 3px; }
.launch-modal-backdrop { position: fixed; inset: 0; z-index: 10000; background: rgba(20,28,35,.55); display: grid; place-items: center; padding: 16px; }
.launch-modal { width: min(580px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--panel); border-radius: 10px; padding: 20px; box-shadow: 0 24px 70px rgba(0,0,0,.25); }
.launch-modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.launch-modal-head h2 { margin: 0; font-size: 20px; }
.launch-modal .label { display: block; font-weight: 600; margin: 14px 0 6px; }
.launch-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.launch-modal-error { min-height: 20px; margin-top: 8px; color: var(--danger); }
.launch-invite-result { margin-top: 16px; padding: 12px; border: 1px solid #9fd2b4; background: #f0fbf4; border-radius: 7px; }
.launch-invite-result strong { display: block; margin-bottom: 8px; }
.launch-invite-result input { margin-bottom: 8px; }
.launch-operations { border-top: 1px solid var(--border-soft); }
.launch-op-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px 8px; }
.launch-op-head h3 { margin: 0; font-size: 15px; }
.launch-op-head .is-error { color: var(--danger); }
.launch-op { border-top: 1px solid var(--border-soft); }
.launch-op summary { min-height: 46px; padding: 10px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; font-weight: 600; list-style: none; }
.launch-op summary::-webkit-details-marker { display: none; }
.launch-op summary::before { content: "›"; color: var(--muted); transition: transform .15s ease; }
.launch-op[open] summary::before { transform: rotate(90deg); }
.launch-op summary > span:first-of-type { flex: 1; }
.launch-form { padding: 2px 20px 18px; }
.launch-form > label:not(.launch-check), .launch-form-grid label { display: grid; gap: 5px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.launch-form input, .launch-form select { min-height: 42px; color: var(--text); font-size: 14px; }
.launch-form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.launch-check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13px; }
.launch-check input { min-height: auto; width: 18px; height: 18px; }
.launch-form-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.launch-path, .launch-inline-error { margin: 10px 0 0; padding: 8px 10px; border-radius: 6px; overflow-wrap: anywhere; font-size: 12px; }
.launch-path { background: var(--bg); }
.launch-inline-error { color: var(--danger); background: #fff7f7; }
.launch-account-list { padding: 0 20px 16px; }
.launch-account-list > div { min-height: 54px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid var(--border-soft); }
.launch-account-list > div:first-child { border-top: 0; }
.launch-account-list strong, .launch-account-list small { display: block; }
.launch-account-list small { color: var(--muted); margin-top: 3px; }
.launch-activity { padding: 2px 20px 18px; }
.launch-activity > div { position: relative; display: grid; grid-template-columns: 112px 1fr; gap: 3px 10px; padding: 9px 0 9px 14px; border-left: 2px solid var(--border); }
.launch-activity > div.is-success { border-left-color: #54a776; }
.launch-activity > div.is-warning { border-left-color: #c88b2f; }
.launch-activity > div.is-error { border-left-color: var(--danger); }
.launch-activity time { color: var(--muted); font-size: 11px; }
.launch-activity strong { font-size: 13px; font-weight: 600; }
.launch-activity small { grid-column: 2; color: var(--muted); overflow-wrap: anywhere; }
.launch-ops-empty { padding: 18px 20px; border-top: 1px solid var(--border-soft); color: var(--muted); }
@media (max-width: 980px) {
  .launch-layout { grid-template-columns: 1fr; }
  #launch-detail { position: static; }
}
@media (max-width: 700px) {
  .launch-summary { grid-template-columns: 1fr 1fr; }
  .launch-summary > div:nth-child(2) { border-right: 0; }
  .launch-summary > div:nth-child(-n+2) { border-bottom: 1px solid var(--border-soft); }
  .launch-row { grid-template-columns: 1fr auto; }
  .launch-progress { grid-column: 1; }
  .launch-score { grid-column: 2; }
  .launch-row > .badge { grid-column: 1 / -1; justify-self: start; }
  .launch-detail-head { align-items: flex-start; flex-direction: column; }
  .launch-head-actions { justify-content: flex-start; }
  .launch-form-grid { grid-template-columns: 1fr; gap: 0; }
  .launch-activity > div { grid-template-columns: 1fr; }
  .launch-activity small { grid-column: 1; }
}

/* Подсказка, если виджет Telegram-входа не загрузился */
.login-widget-fail {
  margin: 4px 0 8px; padding: 10px 12px; border: 1px solid #f0d9a8;
  background: #fff8e6; border-radius: 6px; font-size: 13px;
}
.login-widget-fail-title { font-weight: 600; margin-bottom: 4px; color: #8a5a00; }
.login-widget-fail a { color: var(--primary); }
