/* Палитра, кнопки, карточки — как в «Гигиене CRM» (b24-crm-hygiene); ниже — мастер, редактор стадий, журнал */
:root {
  --ground: #eef2f4;
  --surface: #fff;
  --ink: #333;
  --ink-2: #525c69;
  --muted: #6f7882;
  --line: #e4e8eb;
  --line-strong: #cfd5da;
  --chip-bg: #f5f7f8;
  --accent: #2fc6f6;
  --accent-dark: #11a9d9;
  --link: #2067b0;
  --cta: #bbed21;
  --cta-hover: #d2f95f;
  --danger: #ff5752;
  --ok-bg: #f1fbd0; --ok-ink: #4f7d00; --ok-mark: #7bb300;
  --err-bg: #ffe8e8; --err-ink: #d0312b; --err-mark: #ff5752;
  --info-bg: #e5f9ff; --info-ink: #0b8eb6;
  --warn-bg: #fff4d6; --warn-ink: #8a5a00; --warn-mark: #f5b400;
  --shadow: 0 1px 2px rgba(20, 24, 30, .06), 0 4px 14px rgba(20, 24, 30, .05);
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 15px/1.45 "Golos Text", "Open Sans", "Helvetica Neue", Arial, sans-serif;
}
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--link); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.error { color: var(--err-ink); }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.pad { padding: 24px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; min-width: 0; }

/* ---------- каркас ---------- */
.app { max-width: 1240px; margin: 0 auto; padding: 16px clamp(12px, 3vw, 28px) 40px; display: flex; flex-direction: column; gap: 20px; }
.topbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.seg { display: inline-flex; background: var(--surface); border-radius: 10px; padding: 3px; box-shadow: var(--shadow); max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { border: 0; background: transparent; color: var(--ink-2); padding: 7px 14px; border-radius: 8px; white-space: nowrap; font-size: 14px; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.chip-link { border: 0; background: transparent; padding: 4px 8px; border-radius: 999px; }
.chip-link:hover { text-decoration: underline; }
.chip-link + .chip-link { font-weight: 600; }

.page-head { display: flex; flex-direction: column; gap: 6px; }
.eyebrow { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
h1 { margin: 0; font-size: clamp(22px, 2.6vw, 30px); line-height: 1.15; font-weight: 600; text-wrap: balance; }
h2 { margin: 0; font-size: 18px; font-weight: 600; }
.thesis { margin: 0; max-width: 78ch; color: var(--ink-2); }
.back { align-self: flex-start; border: 0; background: none; padding: 0; color: var(--link); font-size: 14px; }
.back:hover { text-decoration: underline; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 12px; }
.section { display: flex; flex-direction: column; gap: 14px; }

/* ---------- кнопки и поля (ui-btn Битрикс24) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 18px; border-radius: 18px; border: 1px solid var(--line-strong);
  background: #fff; color: var(--ink-2); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .02em;
  white-space: nowrap;
}
.btn:hover { border-color: #a8adb4; }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-cta { background: var(--cta); border-color: var(--cta); color: var(--ink-2); }
.btn-cta:hover:not(:disabled) { background: var(--cta-hover); border-color: var(--cta-hover); }
.btn-danger { color: var(--err-ink); border-color: #f3b7b5; }
.btn-l { height: 46px; border-radius: 23px; font-size: 13px; padding: 0 28px; }
.btn-s { height: 30px; padding: 0 12px; border-radius: 15px; font-size: 11px; }
.x { border: 0; background: var(--surface); color: var(--ink-2); border-radius: 50%; width: 28px; height: 28px; font-size: 16px; line-height: 1; flex: none; }
.x:hover { background: var(--ink-2); color: #fff; }

/* поддержка */
.support { display: flex; flex-direction: column; gap: 10px; border-left: 4px solid var(--accent); }
.support .card-head { margin-bottom: 0; }
.support-ctx { color: var(--ink-2); }
textarea.input { resize: vertical; }

.input {
  width: 100%; min-height: 38px; padding: 7px 10px; font: inherit; font-size: 14px; color: inherit;
  border: 1px solid var(--line-strong); border-radius: 8px; background: #fff;
}
.input:focus { outline: none; border-color: var(--accent); }
.input-s { min-height: 32px; padding: 5px 8px; }
select.input { width: auto; max-width: 100%; }
.num-input { width: 96px; }
.search { max-width: 320px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field-label { font-size: 13px; color: var(--ink-2); }
.inline { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.check-line { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.check-line input { accent-color: var(--accent); margin-top: 3px; flex: none; }

/* метки */
.pill { display: inline-block; font-size: 12px; font-weight: 500; padding: 2px 9px; border-radius: 6px; white-space: nowrap; background: var(--chip-bg); color: var(--ink-2); }
.pill.info { background: var(--info-bg); color: var(--info-ink); }
.pill.ok { background: var(--ok-bg); color: var(--ok-ink); }
.pill.err { background: var(--err-bg); color: var(--err-ink); }
.pill.warn { background: var(--warn-bg); color: var(--warn-ink); }

.dashed { border: 1.5px dashed var(--line-strong); border-radius: var(--radius); padding: 16px 18px; color: var(--ink-2); background: var(--surface); }
.dashed b { color: var(--ink); font-weight: 600; }
.note { border-radius: 10px; padding: 12px 14px; font-size: 14px; display: flex; flex-direction: column; gap: 8px; }
.note.warn { background: var(--warn-bg); color: var(--warn-ink); }
.note.ok { background: var(--ok-bg); color: var(--ok-ink); }
.note.err { background: var(--err-bg); color: var(--err-ink); }
.note.info { background: var(--info-bg); color: var(--info-ink); }

/* ---------- таблицы и фильтры ---------- */
.toolbar { display: flex; gap: 8px 12px; flex-wrap: wrap; align-items: center; }
.toolbar .right { margin-left: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line-strong); background: #fff; border-radius: 14px; padding: 4px 11px; font-size: 13px; color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip .n { opacity: .75; margin-left: 4px; font-variant-numeric: tabular-nums; }

.tablewrap { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; border: 1px solid var(--line-strong); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 13px; font-weight: 600; background: var(--chip-bg); padding: 10px 12px; border-bottom: 1px solid var(--line-strong); white-space: nowrap; }
td { padding: 10px 12px; border-top: 1px solid var(--line); vertical-align: top; }
td.cb, th.cb { width: 36px; padding-right: 0; }
td.cb input, th.cb input { accent-color: var(--accent); width: 16px; height: 16px; margin: 2px 0 0; }
th.num, td.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.nowrap { white-space: nowrap; }

/* ---------- справка ---------- */
.notes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.notes ul { margin: 10px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 7px; font-size: 14px; color: var(--ink-2); }
.notes b { color: var(--ink); }

/* ---------- печать: отчёт для клиента или руководителя ---------- */
@media print {
  body { background: #fff; }
  .topbar, .no-print, .btn { display: none !important; }
  .card, .tablewrap { box-shadow: none; border: 1px solid var(--line-strong); break-inside: avoid; }
  .app { padding: 0; }
}

/* ---------- мастер по шагам ---------- */
.stepper { display: flex; gap: 6px; flex-wrap: wrap; counter-reset: step; }
.stepper button { border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink-2); border-radius: 18px; padding: 6px 14px 6px 8px;
  font-size: 14px; display: inline-flex; align-items: center; gap: 8px; }
.stepper button::before { counter-increment: step; content: counter(step); width: 22px; height: 22px; border-radius: 50%; background: var(--chip-bg);
  display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; }
.stepper button.done::before { content: "✓"; background: var(--ok-bg); color: var(--ok-ink); }
.stepper button[aria-current="step"] { border-color: var(--accent); color: var(--ink); }
.stepper button[aria-current="step"]::before { background: var(--accent); color: #fff; }
.stepper button:disabled { opacity: .5; cursor: default; }
.nav { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.nav .right { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.examples { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.example { border: 1px dashed var(--line-strong); background: #fff; border-radius: 14px; padding: 4px 11px; font-size: 13px; color: var(--link); }
.example:hover { border-color: var(--accent); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.tile { text-align: left; border: 1px solid var(--line-strong); background: #fff; border-radius: 10px; padding: 10px 12px; font-size: 14px; color: var(--ink); }
.tile:hover { border-color: var(--accent); }
.tile[aria-pressed="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); background: #f7fdff; }

/* как понята каждая фраза */
.marks { display: flex; flex-direction: column; gap: 6px; }
.mark { display: flex; gap: 10px; align-items: baseline; font-size: 14px; }
.mark .pill { flex: none; min-width: 112px; text-align: center; }
.mark.unknown .txt { color: var(--warn-ink); }
.mark.filler .txt { color: var(--muted); }

.question { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; border-radius: 10px; background: var(--chip-bg); }
.question.open { background: var(--warn-bg); }
.question b { font-weight: 600; }
.retell { border-left: 4px solid var(--accent); }
.retell ul { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }

/* редактор воронок, стадий и полей */
.entity { display: flex; flex-direction: column; gap: 12px; }
.entity.off > :not(.entity-head) { opacity: .45; }
.entity-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.entity-head .input { max-width: 360px; font-weight: 600; }
.entity-why { font-size: 13px; color: var(--muted); }
.stages { display: flex; flex-direction: column; gap: 6px; }
.stage { display: flex; gap: 6px; align-items: center; }
.stage .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--accent); }
.stage.win .dot { background: var(--ok-mark); }
.stage.lose .dot { background: var(--err-mark); }
.stage .input { max-width: 320px; }
.icon-btn { border: 1px solid transparent; background: transparent; color: var(--muted); border-radius: 6px; width: 28px; height: 28px; flex: none; line-height: 1; }
.icon-btn:hover:not(:disabled) { border-color: var(--line-strong); color: var(--ink); }
.icon-btn:disabled { opacity: .3; cursor: default; }
.add-link { border: 0; background: none; color: var(--link); padding: 2px 0; font-size: 14px; align-self: flex-start; }
.add-link:hover { text-decoration: underline; }
.opts { display: flex; flex-direction: column; gap: 6px; }
.existing { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 14px; color: var(--ink-2); }
.fields td { vertical-align: middle; }
.fields .input { min-width: 140px; }
.fields td.items .input { min-width: 180px; }

/* проверка и журнал */
.tree { display: flex; flex-direction: column; gap: 10px; }
.tree-group h3 { margin: 0 0 6px; font-size: 15px; font-weight: 600; }
.tree-item { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }
.tree-item:first-of-type { border-top: 0; }
.tree-item.skip { color: var(--muted); }
.tree-sub { width: 100%; color: var(--ink-2); font-size: 13px; padding-left: 2px; }
.counts { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 15px; }
.counts b { font-size: 22px; font-weight: 600; margin-right: 4px; font-variant-numeric: tabular-nums; }
.confirm { border: 2px solid var(--accent); background: #f7fdff; }
.log { display: flex; flex-direction: column; gap: 4px; font-size: 14px; max-height: 360px; overflow-y: auto; }
.log-line { display: flex; gap: 8px; align-items: baseline; }
.log-line .pill { flex: none; }
.run-items td { vertical-align: middle; }
.empty-state { text-align: center; padding: 32px 16px; }

@media (max-width: 640px) {
  .card { padding: 16px; }
  .notes { grid-template-columns: minmax(0, 1fr); }
  .mark { flex-direction: column; gap: 2px; }
  .mark .pill { min-width: 0; }
}
details.rules > summary { list-style: none; cursor: pointer; display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
details.rules > summary::-webkit-details-marker { display: none; }
details.rules > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
details.rules[open] > summary::before { transform: rotate(90deg); }
.entity-head input[type="checkbox"], .check-line input { accent-color: var(--accent); width: 18px; height: 18px; }
.field-code { font-size: 11px; line-height: 1.3; color: var(--muted); overflow-wrap: anywhere; }
.data-row td { background: var(--warn-bg); border-top: 0; padding-top: 0; }
.data-panel { padding: 10px 0; }
.data-panel select.input { max-width: 260px; }
.plan-group + .plan-group { margin-top: 8px; }
.plan-group h3 { margin: 0; font-size: 16px; font-weight: 600; }
.plan-table td { vertical-align: top; }
.plan-table th.st, .plan-table td.st { width: 1%; white-space: nowrap; }
.plan-table tr.skip td { color: var(--muted); background: #fafbfc; }
.stage-chain { display: flex; flex-wrap: wrap; gap: 4px; }
.stage-chip { font-size: 13px; padding: 2px 8px; border-radius: 6px; background: var(--info-bg); color: var(--ink); white-space: nowrap; }
.stage-chip.win { background: var(--ok-bg); color: var(--ok-ink); }
.stage-chip.lose { background: var(--err-bg); color: var(--err-ink); }
.recs { display: flex; flex-direction: column; gap: 3px; }
.question.open.soft { background: var(--chip-bg); box-shadow: inset 3px 0 0 var(--warn-mark); }
.fields-pick { display: flex; flex-direction: column; gap: 6px; }

/* ---------- знакомство (как в «Гигиене CRM») ---------- */
.tour-overlay { position: fixed; inset: 0; z-index: 50; background: rgba(23, 32, 43, .55); display: flex; justify-content: center; align-items: flex-start; padding: 24px 16px; overflow-y: auto; }
.tour { width: min(880px, 100%); background: var(--surface); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); overflow: hidden; outline: none; }
.tour-shot { position: relative; background: #eef2f4; border-bottom: 1px solid var(--line); }
.tour-mark { position: absolute; border: 3px solid #ff7a00; border-radius: 10px; box-shadow: 0 0 0 4px rgba(255, 122, 0, .25); pointer-events: none; }
.tour-shot img { display: block; width: 100%; height: auto; aspect-ratio: 1100 / 476; }
.tour-body { padding: 18px 24px 20px; display: flex; flex-direction: column; gap: 10px; }
.tour-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.tour-head h2 { margin: 2px 0 0; }
.tour-text { margin: 0; line-height: 1.5; }
.tour-example { background: var(--info-bg); color: var(--ink); border-radius: 10px; padding: 10px 14px; font-size: 14px; line-height: 1.5; }
.tour-example b { color: var(--info-ink); }
.tour-close { border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; padding: 6px 8px; border-radius: 8px; }
.tour-close:hover { background: var(--chip-bg); color: var(--ink); }
.tour-foot { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.tour-dots { display: flex; gap: 6px; align-items: center; }
.tour-dots button { width: 8px; height: 8px; padding: 0; border: 0; border-radius: 4px; background: var(--line-strong); }
.tour-dots button.on { width: 22px; background: var(--accent); }
@media (max-width: 600px) { .tour-overlay { padding: 8px; } .tour-body { padding: 14px 16px 16px; } }
/* ярлычок у правого края: окно приложения растянуто по содержимому, поэтому он стоит у верха, рядом с меню */
.tour-tab { position: fixed; right: 0; top: 96px; z-index: 5; writing-mode: vertical-rl; transform: rotate(180deg); border: 0; border-radius: 0 8px 8px 0;
  background: var(--accent); color: #fff; padding: 12px 5px; font-size: 13px; box-shadow: var(--shadow); }
.tour-tab:hover { background: var(--accent-dark); }
.tour-tab.hint { z-index: 60; box-shadow: 0 0 0 4px rgba(255, 122, 0, .55); animation: tour-pulse 1.4s ease-in-out infinite; }
@keyframes tour-pulse { 50% { box-shadow: 0 0 0 9px rgba(255, 122, 0, .2); } }
@media (prefers-reduced-motion: reduce) { .tour-tab.hint { animation: none; } }
@media (max-width: 700px) { .tour-tab { display: none; } }
.existing-fields > summary { cursor: pointer; font-size: 13px; color: var(--link); }
.existing-fields[open] > summary { margin-bottom: 6px; }
.existing-fields .chips { margin-bottom: 4px; }
.chip:disabled { opacity: .55; cursor: default; background: var(--chip-bg); }
/* таблица полей портала: закреплённая шапка, своя прокрутка (как в «Гигиене CRM») */
.fields-table { border: 1px solid var(--line-strong); border-radius: 10px; max-height: 360px; overflow: auto; background: #fff; margin: 4px 0 6px; }
.fields-table table { font-size: 14px; }
.fields-table th { position: sticky; top: 0; z-index: 1; padding: 8px 10px; }
.fields-table td { padding: 6px 10px; vertical-align: middle; }
.fields-table td.code, .fields-table th.code { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
@media (max-width: 640px) { .fields-table th.code, .fields-table td.code { display: none; } }
