:root {
  --bg: #f4f5f2;
  --card: #ffffff;
  --text: #1c211d;
  --muted: #667066;
  --line: #dfe3dc;
  --accent: #1d5c3a;
  --accent-soft: #e3efe7;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --radius: 10px;
  --gap: 16px;
  font-size: 15px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 4px; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .87rem; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Шапка */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px;
  padding: 0 20px; height: 56px; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; letter-spacing: .04em; color: var(--text); }
.brand span { font-weight: 500; color: var(--accent); margin-left: 4px; }
.brand:hover { text-decoration: none; }
.mainnav { display: flex; gap: 4px; flex: 1; }
.mainnav a, .bottomnav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.mainnav a:hover { background: var(--bg); text-decoration: none; }
.mainnav a.on { color: var(--accent); background: var(--accent-soft); }
.who { display: flex; align-items: center; gap: 12px; }
.linkbtn { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
.bottomnav { display: none; }

.page { max-width: 1200px; margin: 0 auto; padding: 24px 20px 96px; }
.narrow { max-width: 440px; margin: 8vh auto 0; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.head p { margin: 4px 0 0; }

/* Карточки и сетка */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: var(--gap); }
.grid { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.tile { display: block; color: var(--text); }
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile b { font-size: 1.6rem; display: block; margin: 4px 0; }

/* Таблицы */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .82rem; font-weight: 600; color: var(--muted); background: #fafbf9; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.off td { color: var(--muted); }
td select { min-width: 220px; }

/* Формы */
form.stack { display: grid; gap: 14px; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.field .help { color: var(--muted); font-size: .82rem; margin-top: 4px; }
.field .err, .errorlist { color: var(--danger); font-size: .85rem; margin: 4px 0 0; padding: 0; list-style: none; }
.field.check label { display: flex; gap: 8px; align-items: center; font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=search],
input[type=date], input[type=file], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: #fff;
  font: inherit; color: inherit; min-height: 42px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.filters input[type=search] { max-width: 280px; }
.filters select { width: auto; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 42px;
  padding: 0 16px; border-radius: 8px; border: 1px solid var(--line); background: var(--card);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Сообщения и метки */
.flash { display: grid; gap: 8px; margin-bottom: 16px; }
.msg { padding: 10px 14px; border-radius: 8px; background: var(--accent-soft); }
.msg.error { background: var(--danger-soft); color: var(--danger); }
.msg.warning { background: var(--warn-soft); color: var(--warn); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .8rem; font-weight: 600; background: var(--bg); color: var(--muted); white-space: nowrap; }
.badge.active { background: var(--accent-soft); color: var(--accent); }
.badge.potential { background: var(--warn-soft); color: var(--warn); }
.badge.stopped { background: var(--danger-soft); color: var(--danger); }
.copy { display: flex; gap: 8px; }
.copy input { font-family: ui-monospace, monospace; font-size: .85rem; }
.saved-mark { color: var(--accent); font-size: .82rem; margin-left: 6px; }
dl.props { display: grid; grid-template-columns: 180px 1fr; gap: 8px 16px; margin: 0; }
dl.props dt { color: var(--muted); }
dl.props dd { margin: 0; }
ul.plain { margin: 0; padding: 0; list-style: none; }
ul.plain li + li { margin-top: 6px; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 14px; }

/* Телефон */
@media (max-width: 760px) {
  .topbar { padding: 0 16px; gap: 12px; }
  .mainnav, .who .muted { display: none; }
  .who { margin-left: auto; }
  .page { padding: 16px 16px 96px; }
  .bottomnav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--card);
    border-top: 1px solid var(--line); padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  .bottomnav { overflow-x: auto; justify-content: flex-start; }
  .bottomnav a { font-size: .8rem; padding: 8px 10px; text-align: center; flex: 1 0 auto; white-space: nowrap; }
  .bottomnav a.on { color: var(--accent); }
  dl.props { grid-template-columns: 1fr; gap: 2px; }
  dl.props dd { margin-bottom: 8px; }
  .card { padding: 16px; }
}

/* Таблицы на телефоне превращаются в карточки: подпись колонки берётся из data-label. */
@media (max-width: 760px) {
  table.responsive thead { display: none; }
  table.responsive tr { display: block; padding: 12px 0; border-bottom: 1px solid var(--line); }
  table.responsive tr:last-child { border-bottom: 0; }
  table.responsive td { display: block; border: 0; padding: 3px 14px; text-align: left; }
  table.responsive td.title { font-weight: 600; font-size: 1.02rem; }
  table.responsive td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: .85rem; }
  table.responsive td select { min-width: 0; margin-top: 4px; }
}

/* --- Шаг 2: клиенты и контакты --- */
.topfab { min-height: 36px; padding: 0 14px; }
.fab { display: none; }
.lbl { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 6px; }
label.check { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; display: inline-flex; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span, button.chip {
  display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 99px;
  border: 1px solid var(--line); background: #fff; font: inherit; font-size: .92rem; cursor: pointer; user-select: none;
}
.chip input:checked + span, button.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg .seg-cold input:checked + span { background: #2f6db5; border-color: #2f6db5; }
.seg .seg-warm input:checked + span { background: #c27a00; border-color: #c27a00; }
.seg .seg-hot input:checked + span { background: #c0392b; border-color: #c0392b; }
.step-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.step-row input[type=date] { width: 170px; flex: none; }
.step-row input[type=text] { flex: 1; min-width: 180px; }
.savebar { padding: 4px 0 12px; }
.btn.big { min-height: 50px; font-size: 1.05rem; padding: 0 32px; }
.contact-page .btn.big { width: 100%; }
.contact-page { max-width: 680px; margin: 0 auto; }
.picked-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.picklist { list-style: none; margin: 8px 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; }
.picklist li + li { border-top: 1px solid var(--line); }
.picklist a, .picklist .foreign { display: block; padding: 10px 12px; color: var(--text); }
.picklist a:hover { background: var(--accent-soft); text-decoration: none; }
.picklist .foreign { background: #fafbf9; }
.warn-text { color: var(--warn); }
.bad-text { color: var(--danger); }
.dup:empty { display: none; }
.dup { background: var(--warn-soft); border-radius: var(--radius); padding: 8px 12px; }
.dup .btn { display: none; }

.badge.st-needs_update { background: #eef0ff; color: #3949ab; }
.badge.st-lead { background: #eef2f6; color: #44546a; }
.badge.st-in_work { background: var(--accent-soft); color: var(--accent); }
.badge.st-customer { background: #1d5c3a; color: #fff; }
.badge.st-rejected, .badge.st-archive { background: var(--danger-soft); color: var(--danger); }
.badge.st-archive { background: #eee; color: #666; }
.badge.seg-cold { background: #e6effa; color: #2f6db5; }
.badge.seg-warm { background: #fff1d6; color: #9a6100; }
.badge.seg-hot { background: #fde4e1; color: #c0392b; }
.step-overdue, .step-overdue b { color: var(--danger); }
.step-today b { color: var(--accent); }
.step-card.step-overdue { border-color: #f1b8b3; }
td.act { text-align: right; width: 1%; }
.small-btn { min-height: 34px; padding: 0 12px; font-size: .88rem; }
details.more summary { cursor: pointer; color: var(--accent); padding: 8px 4px; }
details.more[open] { flex-basis: 100%; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); margin-bottom: var(--gap); }
.kpi b { font-size: 1.9rem; display: block; margin: 4px 0; }
.kpi.bad b { color: var(--danger); }
section.card { margin-bottom: var(--gap); }
.card + .card { margin-top: 0; }
.table-wrap.flat { border: 0; border-radius: 0; margin: 0 -20px -20px; }
.cols { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: var(--gap); align-items: start; }
.timeline { list-style: none; margin: 16px 0 0; padding: 0; }
.timeline li { padding: 10px 0 10px 14px; border-left: 3px solid var(--line); margin-left: 4px; }
.timeline li.tl-contact { border-left-color: var(--accent); }
.timeline li.tl-change { border-left-color: #c27a00; }
.timeline li.tl-note { border-left-color: #2f6db5; }
.tl-meta { font-size: .8rem; color: var(--muted); }
.quote { background: var(--bg); border-radius: 8px; padding: 6px 10px; margin-top: 4px; }
.note-form { display: flex; gap: 8px; align-items: flex-start; }
.note-form textarea { min-height: 42px; }
.person-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; align-items: end; padding: 10px 0; border-bottom: 1px solid var(--line); }
.form-grid { max-width: 640px; }

@media (max-width: 760px) {
  .topfab { display: none; }
  .fab {
    display: flex; align-items: center; position: fixed; right: 16px; bottom: calc(70px + env(safe-area-inset-bottom));
    z-index: 11; background: var(--accent); color: #fff; font-weight: 700; padding: 0 20px; height: 52px;
    border-radius: 99px; box-shadow: 0 6px 18px rgba(0,0,0,.25);
  }
  .fab:hover { text-decoration: none; }
  .cols { grid-template-columns: 1fr; }
  .col-side { order: -1; }
  .table-wrap.flat { margin: 0 -16px -16px; }
  td.act { text-align: left; width: auto; }
  .note-form { flex-direction: column; align-items: stretch; }
  .step-row input[type=date] { width: 100%; }
  .savebar { position: sticky; bottom: calc(56px + env(safe-area-inset-bottom)); padding: 12px 0;
             background: linear-gradient(transparent, var(--bg) 30%); }
  .btn.big { width: 100%; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi { padding: 12px; }
  .kpi b { font-size: 1.5rem; margin: 2px 0; }
  .kpi .muted { font-size: .85rem; }
  .chip span, button.chip { min-height: 38px; padding: 0 12px; }
}

/* --- Шаг 3: задачи --- */
ul.tasks { list-style: none; margin: 0; padding: 0; }
ul.tasks li { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
ul.tasks li:last-child { border-bottom: 0; }
ul.tasks li.overdue .t-main b { color: var(--danger); }
ul.tasks li.done { opacity: .75; }
.t-main { min-width: 0; }
.t-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; align-items: center; }
.t-actions form { display: flex; gap: 6px; }
.done-form input { min-height: 34px; padding: 4px 8px; width: 170px; }
.bar { display: inline-block; vertical-align: middle; width: 80px; height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar.wide { width: 100%; max-width: 260px; display: block; margin-bottom: 4px; }
.bar.big { height: 12px; max-width: none; }
.bar span { display: block; height: 100%; max-width: 100%; background: var(--accent); border-radius: 99px; }
.kpi .bar { width: 100%; display: block; margin: 4px 0 6px; }
.kpi b small { font-size: 1rem; color: var(--muted); font-weight: 600; }
.kpi b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.norm b { color: var(--warn); }
.kpi.good b { color: var(--accent); }
@media (max-width: 760px) {
  ul.tasks li { flex-direction: column; }
  .t-actions { justify-content: flex-start; width: 100%; }
  .t-actions form.done-form { flex-basis: 100%; }
  .done-form input { flex: 1; width: auto; min-width: 0; }
}
.timeline li.tl-task, .timeline li.tl-task_done { border-left-color: #7b5ea7; }
@media (max-width: 760px) {
  .done-form { width: 100%; }
  .done-form input { width: 0; flex: 1 1 auto; }
  .filters select, .filters input[type=search] { max-width: 100%; min-width: 0; }
  details.more .filters select { width: 100%; }
}

/* --- Шаг 4: сделки --- */
.board { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.column { background: #eceee9; border-radius: var(--radius); padding: 10px; min-height: 120px; }
.column header { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; padding: 4px 4px 10px; }
.column header .money { flex-basis: 100%; font-size: 1.15rem; font-weight: 700; color: var(--accent); }
.deal-card { display: grid; gap: 2px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 10px; color: var(--text); margin-bottom: 8px; }
.deal-card:hover { border-color: var(--accent); text-decoration: none; }
.money { font-variant-numeric: tabular-nums; }
.stages { display: flex; list-style: none; margin: 0; padding: 0; gap: 4px; }
.stages li { flex: 1; }
.stages li span, .stages li button { display: block; width: 100%; text-align: center; padding: 10px 4px; border: 0; background: var(--bg); color: var(--muted); font: inherit; font-weight: 600; border-radius: 6px; }
.stages li button { cursor: pointer; }
.stages li button:hover { background: var(--accent-soft); color: var(--accent); }
.stages li.on span { background: var(--accent); color: #fff; }
.money-line { font-size: 1.1rem; margin: 12px 0 0; }
@media (max-width: 760px) {
  .board { grid-template-columns: repeat(4, 78vw); }
  .stages li span, .stages li button { font-size: .82rem; padding: 10px 2px; }
}

/* --- Шаг 5: дашборд --- */
.dash-filters { align-items: center; }
.seg-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.seg-switch button { border: 0; background: none; padding: 0 14px; min-height: 40px; font: inherit; cursor: pointer; color: var(--muted); }
.seg-switch button + button { border-left: 1px solid var(--line); }
.seg-switch button.on { background: var(--accent); color: #fff; }
.custom-period { display: inline-flex; gap: 6px; align-items: center; }
.custom-period input { width: 150px; min-height: 40px; }
.cols.two { grid-template-columns: 1fr 1fr; }
.funnel { list-style: none; margin: 0; padding: 0; }
.funnel li { display: grid; grid-template-columns: 150px 1fr 56px; gap: 10px; align-items: center; padding: 5px 0; }
.funnel li small { grid-column: 2 / 4; margin-top: -4px; }
.funnel li.sub span:first-child { padding-left: 14px; color: var(--muted); }
.funnel li.deal { border-top: 1px dashed var(--line); }
.funnel li b { text-align: right; font-variant-numeric: tabular-nums; }
.fbar { height: 14px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.fbar i { display: block; height: 100%; min-width: 2px; background: var(--accent); border-radius: 0 4px 4px 0; }
.funnel li.deal .fbar i { background: #2a78d6; }
.funnel small.money { color: var(--text); font-weight: 600; }
table.conv tr.total td { border-top: 2px solid var(--line); background: #fafbf9; }
.chart-box { position: relative; height: 280px; }
table.matrix th, table.matrix td { text-align: center; }
table.matrix tbody th { text-align: left; color: var(--text); background: none; }
.reasons { list-style: none; padding: 0; margin: 0; }
.reasons li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.reasons li:last-child { border-bottom: 0; }
.good-text { color: var(--accent); }
h3.small { margin: 16px 0 6px; }
@media (max-width: 960px) { .cols.two { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  .seg-switch { width: 100%; }
  .seg-switch button { flex: 1; padding: 0 4px; font-size: .85rem; }
  .custom-period { width: 100%; }
  .custom-period input { flex: 1; width: auto; min-width: 0; }
  .funnel li { grid-template-columns: 110px 1fr 44px; font-size: .9rem; }
  .chart-box { height: 220px; }
}
.day-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: baseline; }
.day-head h2 { margin: 0; }
.day-stats { display: flex; gap: 16px; flex-wrap: wrap; font-size: .92rem; }
.day-card textarea { margin-top: 4px; }
.day-card details { margin: 8px 0; }
.inline-date input { min-height: 42px; }
.review-note { border-left: 4px solid #2a78d6; }
.kpi b.money-kpi { font-size: 1.45rem; }
table.conv td:last-child { white-space: nowrap; }
table.conv .bar { width: 60px; }

/* --- Шаг 6: импорт и дубли --- */
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px 16px; }
.notes-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 0 16px; }
.steps-list { margin: 0; padding-left: 18px; }
.dup-group h2 { margin-bottom: 8px; }
.mainnav a { white-space: nowrap; }
.tile b.tile-title { font-size: 1.05rem; margin: 0 0 4px; }
