:root {
  --nav: #1b2532;
  --nav-hover: #263446;
  --nav-active: #2f3f55;
  --nav-text: #9aa8b8;
  --bg: #eef1f4;
  --panel: #ffffff;
  --line: #e1e5ea;
  --text: #313942;
  --muted: #8c97a4;
  --blue: #4c8bf7;
  --blue-dark: #3a76de;
  --green: #4caf50;
  --red: #e5534b;
  --orange: #f5a623;
  --radius: 4px;
  font-family: "PT Sans", -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
a { color: var(--blue); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); }

.app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- Левое меню ---------- */
.nav { width: 82px; flex: none; background: var(--nav); display: flex; flex-direction: column; align-items: stretch; overflow-y: auto; }
.nav-logo { height: 64px; display: flex; align-items: center; justify-content: center; flex-direction: column; color: #fff; font-weight: 700; letter-spacing: .5px; border-bottom: 1px solid #2a3646; }
.nav-logo b { font-size: 18px; color: #fff; }
.nav-logo span { font-size: 9px; color: var(--nav-text); letter-spacing: 2px; }
.nav a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 4px; color: var(--nav-text); font-size: 11px; text-align: center; line-height: 1.15; }
.nav a svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.7; }
.nav a:hover { background: var(--nav-hover); color: #fff; }
.nav a.active { background: var(--nav-active); color: #fff; }
.nav a.active::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--blue); }
.nav .badge { position: absolute; top: 6px; right: 14px; background: var(--red); color: #fff; border-radius: 9px; font-size: 10px; min-width: 18px; padding: 1px 5px; font-weight: 700; }
.nav-spacer { flex: 1; }
.nav-user { padding: 10px 6px 14px; color: var(--nav-text); font-size: 11px; text-align: center; }
.nav-user .nav-me { display: block; padding: 0; color: #fff; font-size: 12px; font-weight: 700; word-break: break-word; }
.nav-user .nav-me:hover { background: none; text-decoration: underline; }
.nav-user .small { font-size: 10px; margin: 2px 0 8px; }
.nav-logout { width: 100%; background: var(--nav-hover); color: var(--nav-text); border: 0; border-radius: 3px; padding: 5px 4px; font-size: 11px; }
.nav-logout:hover { color: #fff; background: var(--nav-active); }

/* ---------- Контент ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar { height: 64px; flex: none; background: var(--panel); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 0 24px; }
.topbar h1 { margin: 0; font-size: 15px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; white-space: nowrap; }
.topbar .sub { color: var(--muted); font-size: 13px; white-space: nowrap; }
.topbar .grow { flex: 1; }
.search { display: flex; align-items: center; gap: 6px; background: #f5f7f9; border: 1px solid var(--line); border-radius: 3px; padding: 0 10px; height: 34px; min-width: 220px; max-width: 420px; flex: 1; }
.search input { border: 0; background: transparent; outline: none; flex: 1; height: 100%; }
.search svg { width: 16px; height: 16px; stroke: var(--muted); fill: none; stroke-width: 2; }
.content { flex: 1; overflow: auto; padding: 20px 24px; }
.content.flush { padding: 0; }

.btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 16px; border-radius: 3px; border: 1px solid var(--line); background: #fff; color: var(--text); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; white-space: nowrap; }
.btn:hover { border-color: #c5ccd4; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-dark); }
.btn.green { background: var(--green); border-color: var(--green); color: #fff; }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.link { border: 0; background: none; color: var(--blue); text-transform: none; font-weight: 400; padding: 0 4px; }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; }

.card { background: var(--panel); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.card-h { padding: 14px 18px; border-bottom: 1px solid var(--line); font-weight: 700; display: flex; align-items: center; gap: 10px; }
.card-b { padding: 16px 18px; }

/* ---------- Рабочий стол ---------- */
.widgets { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.widget { background: var(--panel); border-radius: var(--radius); padding: 16px 18px; box-shadow: 0 1px 2px rgba(0,0,0,.06); cursor: pointer; border-top: 3px solid var(--blue); }
.widget .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.widget .value { font-size: 32px; font-weight: 700; margin-top: 6px; }
.widget .value small { font-size: 15px; color: var(--muted); font-weight: 400; }
.progress { height: 6px; background: #edf0f3; border-radius: 3px; margin-top: 10px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--green); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.bars { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 10px; }
.bars div { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: 10px; color: var(--muted); gap: 4px; }
.bars div i { display: block; width: 100%; background: var(--blue); border-radius: 2px 2px 0 0; min-height: 2px; }
.funnel-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; font-size: 13px; }
.funnel-row .nm { width: 180px; flex: none; }
.funnel-row .bar { flex: 1; height: 18px; background: #f2f4f6; border-radius: 2px; overflow: hidden; }
.funnel-row .bar i { display: block; height: 100%; }
.funnel-row .n { width: 40px; text-align: right; font-weight: 700; }

/* ---------- Воронка (канбан) ---------- */
.pipeline { display: flex; gap: 10px; padding: 16px 24px; height: 100%; overflow-x: auto; align-items: flex-start; }
.col { width: 260px; flex: none; display: flex; flex-direction: column; max-height: 100%; }
.col-h { background: var(--panel); padding: 10px 12px 8px; border-bottom: 3px solid; border-radius: 3px 3px 0 0; }
.col-h .t { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.col-h .c { color: var(--muted); font-size: 12px; margin-top: 2px; }
.col-b { overflow-y: auto; padding: 8px 0; flex: 1; min-height: 80px; }
.col-b.drag { background: rgba(76,139,247,.08); }
.kcard { background: var(--panel); border-radius: 3px; padding: 10px 12px; margin-bottom: 8px; box-shadow: 0 1px 2px rgba(0,0,0,.08); cursor: pointer; border-left: 3px solid transparent; }
.kcard:hover { box-shadow: 0 2px 6px rgba(0,0,0,.12); }
.kcard .nm { font-weight: 700; color: var(--blue); }
.kcard .ph { margin-top: 4px; }
.kcard .meta { color: var(--muted); font-size: 12px; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 8px; }
.kcard.new { border-left-color: var(--blue); }

/* ---------- Таблица ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar select, .toolbar input { height: 32px; border: 1px solid var(--line); border-radius: 3px; background: #fff; padding: 0 8px; font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 3px; overflow: hidden; background: #fff; }
.seg button { border: 0; background: transparent; padding: 0 12px; height: 30px; font-size: 13px; color: var(--muted); }
.seg button.on { background: var(--blue); color: #fff; }
table.list { width: 100%; border-collapse: collapse; background: var(--panel); font-size: 13px; }
table.list th { text-align: left; color: var(--muted); font-weight: 400; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; padding: 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #fafbfc; z-index: 1; white-space: nowrap; }
table.list td { padding: 10px; border-bottom: 1px solid #f0f2f4; vertical-align: top; }
table.list tr:hover td { background: #f7f9fc; }
table.list tr.unseen td:first-child { box-shadow: inset 3px 0 0 var(--blue); }
.nm-link { font-weight: 700; cursor: pointer; color: var(--blue); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; white-space: nowrap; color: #313942; }
.tag { display: inline-block; padding: 1px 6px; border-radius: 3px; background: #eef2f7; color: #5a6878; font-size: 11px; white-space: nowrap; }
.q { display: inline-block; min-width: 30px; text-align: center; padding: 1px 6px; border-radius: 3px; font-size: 12px; font-weight: 700; color: #fff; }
.phone { white-space: nowrap; font-weight: 700; color: var(--text); }
.call-btns { display: flex; gap: 6px; }
.icon-btn { width: 30px; height: 30px; border-radius: 50%; border: 0; display: inline-flex; align-items: center; justify-content: center; color: #fff; flex: none; }
.icon-btn svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; }
.icon-btn.call { background: var(--green); }
.icon-btn.tg { background: #2aabee; }
.empty { text-align: center; color: var(--muted); padding: 50px 20px; }

/* ---------- Карточка клиента (как в amoCRM) ---------- */
.lead { display: flex; height: 100%; }
.lead-left { width: 380px; flex: none; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; }
.lead-head { padding: 18px 20px; color: #313942; }
.lead-head .back { font-size: 12px; cursor: pointer; color: rgba(0,0,0,.55); }
.lead-head h2 { margin: 8px 0 4px; font-size: 20px; }
.lead-head .id { font-size: 12px; color: rgba(0,0,0,.5); }
.status-select { margin-top: 12px; width: 100%; height: 34px; border: 0; border-radius: 3px; padding: 0 8px; background: rgba(255,255,255,.75); font-weight: 700; }
.fields { padding: 8px 20px 20px; }
.field { display: flex; align-items: flex-start; border-bottom: 1px dashed #e6e9ed; padding: 8px 0; gap: 10px; }
.field label { width: 110px; flex: none; color: var(--muted); font-size: 13px; padding-top: 6px; }
.field .v { flex: 1; min-width: 0; }
.field input, .field select, .field textarea { width: 100%; border: 1px solid transparent; background: transparent; padding: 5px 6px; border-radius: 3px; font-size: 13px; }
.field input:hover, .field select:hover, .field textarea:hover { border-color: var(--line); }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue); outline: none; background: #fff; }
.field textarea { resize: vertical; min-height: 54px; }
.ai-box { margin: 0 20px 16px; background: #f4f8ff; border: 1px solid #d9e6fd; border-radius: 4px; padding: 10px 12px; font-size: 13px; }
.ai-box b { color: var(--blue-dark); }
.lead-right { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #f5f7f9; }
.feed { flex: 1; overflow-y: auto; padding: 18px 24px; display: flex; flex-direction: column-reverse; gap: 10px; }
.ev { background: var(--panel); border-radius: 4px; padding: 10px 14px; box-shadow: 0 1px 1px rgba(0,0,0,.05); max-width: 760px; }
.ev .h { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ev .t { margin-top: 4px; white-space: pre-wrap; }
.ev.system, .ev.status, .ev.duplicate { background: transparent; box-shadow: none; padding: 2px 14px; font-size: 12px; color: var(--muted); }
.ev.duplicate { color: #b26a00; }
.ev.call { border-left: 3px solid var(--green); }
.ev.note { border-left: 3px solid var(--orange); }
.task-strip { background: #fff8e1; border-bottom: 1px solid #f3e2a9; padding: 8px 24px; font-size: 13px; display: flex; gap: 10px; align-items: center; }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 12px 24px 16px; }
.composer .tabs { display: flex; gap: 18px; margin-bottom: 10px; }
.composer .tabs span { cursor: pointer; color: var(--muted); font-size: 13px; padding-bottom: 4px; }
.composer .tabs span.on { color: var(--text); border-bottom: 2px solid var(--blue); }
.composer textarea { width: 100%; min-height: 64px; border: 1px solid var(--line); border-radius: 3px; padding: 8px 10px; resize: vertical; }
.composer .row { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.composer input[type=datetime-local] { height: 32px; border: 1px solid var(--line); border-radius: 3px; padding: 0 8px; }
.st-grid { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.st-grid button { border: 1px solid transparent; border-radius: 14px; padding: 4px 12px; font-size: 12px; color: #313942; }
.st-grid button.on { border-color: #313942; box-shadow: 0 0 0 1px #313942; font-weight: 700; }

/* ---------- Задачи ---------- */
.task-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; margin: 18px 0 8px; color: var(--muted); }
.task-group h3.over { color: var(--red); }
.task { background: var(--panel); border-radius: 3px; padding: 10px 14px; display: flex; gap: 14px; align-items: center; margin-bottom: 6px; box-shadow: 0 1px 1px rgba(0,0,0,.05); }
.task .when { width: 120px; flex: none; font-weight: 700; }
.task .when.over { color: var(--red); }
.task .body { flex: 1; min-width: 0; }
.task .chk { width: 20px; height: 20px; border: 2px solid #c5ccd4; border-radius: 3px; background: #fff; flex: none; }
.task .chk:hover { border-color: var(--green); }

/* ---------- AI ---------- */
.ai-log { background: #10161f; color: #b9c7d8; font-family: ui-monospace, Menlo, monospace; font-size: 12px; padding: 12px 14px; border-radius: 4px; height: 280px; overflow-y: auto; white-space: pre-wrap; }
.form-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; align-items: flex-end; }
.form-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-row input, .form-row select, .form-row textarea { height: 34px; border: 1px solid var(--line); border-radius: 3px; padding: 0 10px; font-size: 14px; color: var(--text); background: #fff; }
.form-row textarea { height: auto; padding: 8px 10px; }
.note { background: #fffbe6; border: 1px solid #f3e2a9; padding: 10px 14px; border-radius: 4px; font-size: 13px; margin-bottom: 14px; }
.note.blue { background: #f4f8ff; border-color: #d9e6fd; }
code { background: #f1f3f5; padding: 1px 5px; border-radius: 3px; font-size: 12px; }
pre.code { background: #f1f3f5; padding: 10px 12px; border-radius: 4px; overflow-x: auto; font-size: 12px; }

/* ---------- Модалка и тосты ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(20,28,38,.55); display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 4px; width: 100%; max-width: 560px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 16px; display: flex; align-items: center; }
.modal-h .x { margin-left: auto; border: 0; background: none; font-size: 22px; color: var(--muted); line-height: 1; }
.modal-b { padding: 16px 20px; }
.modal-f { padding: 12px 20px 16px; display: flex; gap: 8px; justify-content: flex-end; }
.modal .form-row label { flex: 1; min-width: 160px; }
.modal .form-row input, .modal .form-row select, .modal .form-row textarea { width: 100%; }
.toasts { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: #263446; color: #fff; padding: 10px 16px; border-radius: 4px; box-shadow: 0 4px 14px rgba(0,0,0,.2); font-size: 13px; max-width: 360px; }
.toast.err { background: var(--red); }

@media (max-width: 900px) {
  .nav { width: 64px; }
  .nav a { font-size: 9px; }
  .nav-logo b { font-size: 13px; }
  .grid2 { grid-template-columns: 1fr; }
  .lead { flex-direction: column; height: auto; }
  .lead-left { width: 100%; border-right: 0; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar .sub { display: none; }
  .content { padding: 14px 12px; }
  .hide-sm { display: none; }
}

.chk-wrap { display: flex; flex-wrap: wrap; gap: 6px; }
.chk-pill { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); border-radius: 16px; padding: 4px 12px 4px 8px; font-size: 13px; background: #fff; cursor: pointer; user-select: none; }
.chk-pill:has(input:checked) { border-color: var(--blue); background: #eef4ff; }
.chk-pill input { margin: 0; }
.seg button svg { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2; vertical-align: -2px; }
.seg button { white-space: nowrap; }
