/* Kepper — спокойный рабочий интерфейс. Цвет несёт смысл: чей ход и просрочка. */
:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --line: #e2e5ea;
  --text: #1c2130;
  --muted: #6b7385;
  --ink: #1f2433;
  --accent: #3b5bdb;
  --accent-soft: #e8edff;
  --red: #d6336c;
  --red-soft: #fff0f4;
  --amber: #b07800;
  --ok: #2b8a3e;
  --me: #7048e8;      /* мой ход */
  --client: #e8a400;  /* ждём клиента */
  --supplier: #0c8599;/* ждём поставщика */
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14161c; --panel: #1c1f27; --panel-2: #242833; --line: #2e3340; --text: #e6e8ee; --muted: #9098aa;
    --ink: #0e1015; --accent: #7d95ff; --accent-soft: #252c48; --red: #ff6b9a; --red-soft: #3a1d29; --amber: #f0b429;
    --ok: #51cf66; --me: #9775fa; --client: #f0b429; --supplier: #3bc9db;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; font-weight: 600; }
h3 { font-size: 13px; margin: 0 0 10px; font-weight: 650; display: flex; gap: 8px; align-items: center; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 6px 9px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; }
code { background: var(--panel-2); padding: 2px 6px; border-radius: 5px; font-size: 13px; }
a { color: var(--accent); text-decoration: none; }
.boot { padding: 40px; color: var(--muted); }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.red { color: var(--red) !important; }
.amber { color: var(--amber) !important; }
.grow { flex: 1; }
.pad { padding: 12px; }
.ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.strike { text-decoration: line-through; color: var(--muted); }
.row-flex { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent; background: var(--ink); color: #fff;
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 550; white-space: nowrap; text-decoration: none;
  transition: background .12s, border-color .12s, transform .08s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.sm { padding: 4px 10px; font-size: 13px; border-radius: 7px; }
.btn.ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn.ghost:hover { background: var(--panel-2); }
.btn.ghost.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.move-select { width: auto; max-width: 100%; font-size: 13px; padding: 3px 6px; }
.btn.icon { padding: 4px 8px; min-width: 30px; justify-content: center; }
.btn.ok { background: var(--ok); color: #fff; border-color: transparent; }
.btn.ghost.ok { background: transparent; color: var(--ok); border-color: var(--line); }
.btn.ghost.ok:hover { background: var(--ok); color: #fff; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.linkish:disabled { color: var(--muted); opacity: .4; }

.tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 20px; background: var(--panel-2); color: var(--muted); white-space: nowrap; font-weight: 550; }
.tag.lead { background: var(--accent-soft); color: var(--accent); }
.tag.stuck { background: var(--red-soft); color: var(--red); }
.tag.stage { background: var(--ink); color: #fff; }
.tag.next { background: var(--panel-2); color: var(--text); }
.tag.s-won { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.tag.s-lost { background: var(--red-soft); color: var(--red); }

/* ---------- каркас ---------- */
.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.app.with-drawer { grid-template-columns: 220px minmax(0, 1fr) min(560px, 46vw); }
.side { background: var(--ink); color: #c9cede; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.logo { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 18px; padding: 4px 8px 18px; }
.logo img { width: 28px; height: 28px; }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: inherit; }
.side nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side nav a.on { background: rgba(255,255,255,.1); color: #fff; }
.side .ic { width: 18px; text-align: center; opacity: .8; }
.badge { margin-left: auto; background: var(--red); color: #fff; font-size: 11px; padding: 0 7px; border-radius: 10px; line-height: 18px; }
.side-new { margin-top: auto; background: #fff; color: var(--ink); justify-content: center; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); padding: 14px 28px 10px; display: flex; gap: 10px; align-items: flex-start; }
.burger { display: none; }
.content { padding: 8px 28px 60px; max-width: 1100px; width: 100%; }

.quick { flex: 1; position: relative; }
.quick-box { display: flex; align-items: center; gap: 6px; background: var(--panel); border-radius: 10px; box-shadow: var(--shadow); padding: 0 6px 0 8px; border: 1px solid transparent; cursor: text; }
.quick-box:focus-within { border-color: var(--accent); }
.quick-box input { border: 0; background: transparent; padding: 10px 6px; font-size: 14px; outline: none !important; }
.pin { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; background: var(--ink); color: #fff; border-radius: 7px; padding: 3px 4px 3px 10px; font-weight: 600; font-size: 13px; }
.pin.isnew { background: var(--accent); }
.pin small { font-weight: 400; opacity: .8; }
.pin button { border: 0; background: rgba(255,255,255,.15); color: #fff; border-radius: 5px; cursor: pointer; width: 20px; height: 20px; line-height: 1; }
.quick-drop { position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 20; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.2); padding: 6px; }
.qd-hint { font-size: 12px; color: var(--muted); padding: 4px 8px 6px; }
.qd-item { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 7px; cursor: pointer; }
.qd-item.on { background: var(--accent-soft); }
.qd-item.isnew { color: var(--accent); border-top: 1px solid var(--line); border-radius: 0 0 7px 7px; }
.qp-result { font-size: 14px; padding: 8px 2px; }
.quick-preview { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.chip { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 2px 10px; font-size: 12px; }
.chip i { font-style: normal; color: var(--muted); margin-right: 4px; }
.quick-preview { flex-direction: column; align-items: stretch; gap: 4px; background: var(--panel); border-radius: 10px; padding: 10px 12px; box-shadow: var(--shadow); }
.qp-line { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.qp-label { font-size: 12px; color: var(--muted); width: 32px; }
.chip.pick { cursor: pointer; background: var(--panel); }
.chip.pick.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.seg.sm button { padding: 2px 10px; font-size: 12px; }
.tag.task { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); }
.tasks { display: flex; flex-direction: column; gap: 4px; }
.task { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 8px; border-left: 3px solid var(--line); background: var(--panel-2); }
.task.done { opacity: .55; background: none; }
.task.done .t-text { text-decoration: line-through; }
.task .t-text { flex: 1; min-width: 0; }
.task-form { display: grid; grid-template-columns: 1fr 200px; gap: 6px; align-items: center; margin-bottom: 10px; }
.task-form .t-input { grid-column: 1 / -1; }
.task-form .presets { grid-column: 1 / -1; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
@media (max-width: 760px) { .task-form { grid-template-columns: 1fr; } }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin: 14px 0 20px; flex-wrap: wrap; }
.page-head .search { width: 260px; }
.kpis { display: flex; gap: 8px; flex-wrap: wrap; }
.kpi { background: var(--panel); border-radius: var(--radius); padding: 8px 14px; min-width: 88px; box-shadow: var(--shadow); }
.kpi b { display: block; font-size: 20px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 12px; color: var(--muted); }
.kpi.red b { color: var(--red); }
.kpis.big { margin-bottom: 20px; }
.kpis.big .kpi { min-width: 130px; padding: 14px 18px; }
.empty { padding: 30px; text-align: center; color: var(--muted); background: var(--panel); border-radius: var(--radius); }
.empty code { display: inline-block; margin-top: 8px; }

/* ---------- повестка ---------- */
.group { margin-bottom: 26px; }
.group h2 .count { background: var(--panel-2); border-radius: 10px; padding: 0 7px; margin-left: 4px; color: var(--text); }
.group h2.red .count { background: var(--red-soft); }
.row {
  display: grid; grid-template-columns: 1fr auto 110px auto auto; gap: 14px; align-items: center;
  background: var(--panel); border-radius: var(--radius); padding: 10px 12px 10px 16px; margin-bottom: 6px; cursor: pointer;
  border-left: 4px solid var(--line); box-shadow: var(--shadow); transition: transform .1s, box-shadow .1s;
}
.row:hover { box-shadow: 0 2px 4px rgba(16,24,40,.08), 0 8px 24px rgba(16,24,40,.08); }
.row.overdue { background: linear-gradient(90deg, var(--red-soft), var(--panel) 40%); }
.b-me { border-left-color: var(--me) !important; }
.b-client { border-left-color: var(--client) !important; }
.b-supplier { border-left-color: var(--supplier) !important; }
.row-main { min-width: 0; }
.row-top, .row-what { display: flex; gap: 8px; align-items: center; min-width: 0; }
.row-top .client { white-space: nowrap; }
.row-what { margin-top: 2px; }
.row-due { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.row-act { display: flex; gap: 4px; }

.ball { border: 0; border-radius: 20px; font-size: 11px; font-weight: 600; padding: 2px 9px; white-space: nowrap; cursor: default; }
.ball.editable { cursor: pointer; }
.ball.b-me { background: color-mix(in srgb, var(--me) 15%, transparent); color: var(--me); }
.ball.b-client { background: color-mix(in srgb, var(--client) 18%, transparent); color: var(--amber); }
.ball.b-supplier { background: color-mix(in srgb, var(--supplier) 15%, transparent); color: var(--supplier); }

.progress { display: inline-flex; gap: 3px; align-items: center; }
.progress i { width: 9px; height: 9px; border-radius: 50%; background: var(--panel-2); border: 1.5px solid var(--line); }
.progress.small i { width: 7px; height: 7px; }
.progress .st-active { background: var(--accent-soft); border-color: var(--accent); }
.progress .st-done { background: var(--ok); border-color: var(--ok); }
.progress .st-skip { background: transparent; border-style: dashed; opacity: .5; }

/* меню «отложить» */
.snooze { position: relative; display: inline-block; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 6px; min-width: 230px; }
.menu > button { display: flex; justify-content: space-between; width: 100%; background: none; border: 0; padding: 7px 10px; border-radius: 6px; cursor: pointer; text-align: left; }
.menu > button:hover { background: var(--panel-2); }
.menu small { color: var(--muted); }
.menu-custom { display: flex; gap: 6px; padding: 6px 4px 2px; border-top: 1px solid var(--line); margin-top: 4px; }

/* ---------- таблицы и карточки ---------- */
.table { display: flex; flex-direction: column; gap: 6px; }
.trow { display: grid; grid-template-columns: 1fr auto 120px 100px; gap: 14px; align-items: center; background: var(--panel); padding: 10px 14px; border-radius: var(--radius); cursor: pointer; box-shadow: var(--shadow); }
.trow.sup { grid-template-columns: 1fr auto 200px; }
.trow:hover { outline: 1px solid var(--line); }
.t-main { min-width: 0; }
.t-due { text-align: right; font-variant-numeric: tabular-nums; }
.t-sum { text-align: right; }
.sup-stats { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }

.seg { display: inline-flex; background: var(--panel-2); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 10px; }
.ccard { background: var(--panel); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); cursor: pointer; display: flex; flex-direction: column; gap: 6px; }
.ccard:hover { outline: 1px solid var(--line); }
.ccard-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.cperson { border-top: 1px solid var(--line); padding-top: 6px; cursor: default; }
.ccard .foot { margin-top: auto; }
.people { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 0; }
.letter { font-weight: 700; color: var(--muted); padding: 10px 16px 2px; font-size: 12px; }
.person { display: grid; grid-template-columns: 220px 200px 1fr; gap: 12px; padding: 8px 16px; cursor: pointer; align-items: center; }
.person:hover { background: var(--panel-2); }

.links { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; }
.lk { display: inline-flex; align-items: center; gap: 2px; white-space: nowrap; }
.cp { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 3px; font-size: 12px; opacity: .6; }
.cp:hover { opacity: 1; color: var(--accent); }

/* ---------- боковая панель ---------- */
.drawer { background: var(--panel); border-left: 1px solid var(--line); height: 100vh; position: sticky; top: 0; overflow-y: auto; box-shadow: -8px 0 30px rgba(16,24,40,.06); }
.drawer-bar { position: sticky; top: 0; z-index: 4; background: var(--panel); display: flex; padding: 10px 16px 4px; gap: 6px; }
.card-body { padding: 0 22px 40px; }
.card-head { padding-bottom: 14px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.client-link { background: none; border: 0; padding: 0; cursor: pointer; color: var(--accent); font-weight: 600; font-size: 13px; }
.title-input { font-size: 19px; font-weight: 650; border-color: transparent; padding: 4px 6px; margin: 2px -6px 6px; width: calc(100% + 12px); background: transparent; }
.title-input:hover { border-color: var(--line); }
.status-line { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.block { padding: 16px 0; border-bottom: 1px solid var(--line); }
.content .block { background: var(--panel); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow); border: 0; }
.next-block { border-left: 4px solid var(--line); padding-left: 14px; margin-left: -18px; }
.next-grid { display: grid; grid-template-columns: 1fr 190px; gap: 8px; }
.next-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }

.stages { display: flex; flex-direction: column; }
.stage { border-radius: 8px; }
.stage.open { background: var(--panel-2); }
.stage-row { display: flex; gap: 10px; align-items: center; padding: 7px 8px; cursor: pointer; border-radius: 8px; min-height: 38px; }
.stage-row:hover { background: var(--panel-2); }
.stage-title { font-weight: 550; white-space: nowrap; }
.st-done .stage-title { color: var(--muted); }
.st-active .stage-title { color: var(--accent); }
.stage-row .start { opacity: 0; transition: opacity .12s; }
.stage-row:hover .start, .stage.open .start { opacity: 1; }
@media (hover: none) { .stage-row .start { opacity: 1; } }
.stage .due { font-variant-numeric: tabular-nums; white-space: nowrap; }
.stage-edit { padding: 2px 10px 12px 40px; display: flex; flex-direction: column; gap: 8px; }
.stage-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.stage-tools label { display: flex; gap: 6px; align-items: center; }
.stage-tools input[type=datetime-local] { width: 190px; }
.check { position: relative; width: 20px; height: 20px; flex: none; cursor: pointer; }
.check input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.check span { position: absolute; inset: 0; border: 2px solid var(--line); border-radius: 6px; background: var(--panel); transition: all .12s; }
.st-active .check span { border-color: var(--accent); }
.check input:checked + span { background: var(--ok); border-color: var(--ok); }
.check input:checked + span::after { content: ''; position: absolute; left: 5px; top: 1px; width: 5px; height: 10px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin-bottom: 10px; }
.form-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.form-grid label > * { color: var(--text); font-size: 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid label .row-flex { flex-wrap: nowrap; }
.check-label { flex-direction: row !important; align-items: center; gap: 8px !important; font-size: 13px !important; color: var(--text) !important; }
.check-label input { width: auto; }
.contact-line { margin: 8px 0; }
.onec-res { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.contacts { display: flex; flex-direction: column; gap: 8px; }
.contact { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; display: flex; flex-direction: column; gap: 4px; }
.contact.main { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.contact-head { display: flex; gap: 8px; align-items: baseline; }
.contact-form { background: var(--panel-2); padding: 12px; border-radius: 8px; }
.mini-deal { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 7px; cursor: pointer; }
.mini-deal:hover { background: var(--panel-2); }

.note-add { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.note-add .row-flex { justify-content: flex-end; }
.note-add > .btn { align-self: flex-end; }
.note-add select { width: auto; }
.journal { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.journal li { display: grid; grid-template-columns: 20px 1fr; gap: 8px; }
.j-ic { color: var(--muted); text-align: center; }
.j-note .j-text { background: var(--panel-2); padding: 6px 10px; border-radius: 8px; white-space: pre-wrap; }
.j-note .j-ic { color: var(--accent); }
.j-touch .j-text { background: color-mix(in srgb, var(--ok) 12%, transparent); padding: 6px 10px; border-radius: 8px; white-space: pre-wrap; }
.j-touch .j-ic { color: var(--ok); }
.j-snooze .j-text, .j-due .j-text, .j-stage .j-text, .j-create .j-text, .j-status .j-text { color: var(--muted); font-size: 13px; }
.danger { padding-top: 20px; text-align: right; }

/* ---------- модальное окно ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(10, 12, 20, .45); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; padding: 22px; width: min(600px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); max-height: 90vh; overflow: auto; }
.modal h2 { color: var(--text); text-transform: none; letter-spacing: 0; font-size: 18px; margin-bottom: 16px; }

/* ---------- напоминания ---------- */
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 40; display: flex; flex-direction: column; gap: 8px; width: 360px; max-width: calc(100vw - 32px); }
.toast { background: var(--panel); border-radius: 12px; padding: 12px 14px; box-shadow: 0 10px 40px rgba(16,24,40,.18); border-left: 4px solid var(--line); position: relative; animation: rise .22s ease-out; }
.toast.summary { border-left-color: var(--accent); }
.toast.more { cursor: pointer; text-align: center; color: var(--muted); padding: 8px; }
.toast-text { cursor: pointer; padding-right: 16px; }
.toast-act { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; align-items: center; }
.toast-act .menu { bottom: calc(100% + 4px); top: auto; }
.toast-x { position: absolute; right: 6px; top: 4px; border: 0; background: none; color: var(--muted); font-size: 18px; cursor: pointer; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }

.flash { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 6px; align-items: center; pointer-events: none; }
.flash div { background: var(--ink); color: #fff; padding: 7px 16px; border-radius: 20px; font-size: 13px; box-shadow: var(--shadow); }
.flash .f-err { background: var(--red); }

/* ---------- настройки и статистика ---------- */
.stage-set { display: grid; grid-template-columns: 40px 160px 1fr 70px 170px 24px; gap: 8px; align-items: center; margin-bottom: 6px; }
.stage-set.head { font-size: 12px; color: var(--muted); }
.arrows { display: flex; flex-direction: column; line-height: 1; font-size: 10px; }
.bar-row { display: grid; grid-template-columns: 140px 1fr 160px; gap: 10px; align-items: center; margin-bottom: 8px; }
.bar { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }

/* ---------- узкие экраны ---------- */
@media (max-width: 1499px) {
  .app.with-drawer { grid-template-columns: 220px minmax(0, 1fr); }
  .drawer { position: fixed; right: 0; top: 0; width: min(560px, 100vw); z-index: 20; box-shadow: -12px 0 40px rgba(0, 0, 0, .35); }
}
@media (max-width: 760px) {
  .app, .app.with-drawer { grid-template-columns: minmax(0, 1fr); }
  .row-top { flex-wrap: wrap; }
  .kpi { min-width: 0; flex: 1; padding: 8px 10px; }
  .kpis { width: 100%; flex-wrap: nowrap; }
  .side { position: fixed; left: 0; top: 0; z-index: 30; width: 240px; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .burger { display: inline-flex; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .row { grid-template-columns: 1fr auto; }
  .row .row-act { grid-column: 1 / -1; justify-content: flex-end; }
  .hide-sm { display: none !important; }
  .trow { grid-template-columns: 1fr auto; }
  .trow .progress { display: none; }
  .person { grid-template-columns: 1fr; gap: 2px; }
  .form-grid, .next-grid { grid-template-columns: 1fr; }
  .stage-set { grid-template-columns: 1fr 1fr; }
  .page-head .search { width: 100%; }
}

/* ---------- заметки ---------- */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: 1px; flex: none; }
.dot.all { background: conic-gradient(#7048e8, #0c8599, #e8590c, #2b8a3e, #7048e8); }
.tag.notetag { background: color-mix(in srgb, #e8590c 15%, transparent); color: #e8590c; }
.notes-layout { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 18px; align-items: start; }
.topics { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 80px; }
.topic-wrap { position: relative; }
.topic { display: flex; align-items: center; width: 100%; gap: 4px; border: 0; background: none; padding: 8px 30px 8px 10px; border-radius: 8px; cursor: pointer; text-align: left; }
.topic:hover { background: var(--panel-2); }
.topic.on { background: var(--accent-soft); font-weight: 600; }
.topic .badge, .topic small { margin-left: auto; }
.topic-edit { position: absolute; right: 4px; top: 6px; border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 5px; opacity: 0; }
.topic-wrap:hover .topic-edit, .topic-edit:focus { opacity: 1; }
.topic-menu { padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; background: var(--panel-2); border-radius: 8px; margin: 2px 0 4px; }
.colors { display: flex; gap: 5px; flex-wrap: wrap; }
.colors button { width: 18px; height: 18px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.colors button.on { border-color: var(--text); }
.add-topic { margin-top: 6px; justify-content: center; }
.note-form { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px; display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.note-form textarea { border-color: transparent; background: var(--panel-2); }
.note-form .due-input { width: 190px; }
.notes-list { display: flex; flex-direction: column; gap: 6px; }
.note { display: flex; gap: 12px; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; transition: box-shadow .3s; }
.note.hl { box-shadow: 0 0 0 2px var(--accent); }
.note.done { opacity: .55; }
.note.done .note-text { text-decoration: line-through; }
.note-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.note-topic { font-size: 12px; color: var(--muted); }
.note-text { white-space: pre-wrap; word-break: break-word; line-height: 1.5; }
.note-text a { word-break: break-all; }
.site { font-size: 11px; padding: 1px 6px; border-radius: 4px; color: #fff; font-weight: 600; }
.site.yt { background: #e03131; } .site.tt { background: #111; } .site.ig { background: linear-gradient(45deg, #f08c00, #d6336c, #7048e8); }
.site.tg { background: #229ed9; } .site.vk { background: #0077ff; } .site.rt { background: #1c1c1c; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumbs img { width: 200px; aspect-ratio: 16 / 9; object-fit: cover; border-radius: 8px; display: block; }
.note-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.note-act { display: flex; gap: 4px; align-items: center; opacity: 0; transition: opacity .12s; }
.note:hover .note-act, .note:focus-within .note-act { opacity: 1; }
@media (hover: none) { .note-act { opacity: 1; } }
.note-act .move { width: auto; font-size: 12px; padding: 3px 6px; }
.due-chip { font-size: 12px; background: var(--accent-soft); color: var(--accent); padding: 1px 8px; border-radius: 10px; cursor: pointer; }
.due-chip.red { background: var(--red-soft); color: var(--red) !important; }
.note-date { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.note-date input { width: 190px; }
.done-block { margin-top: 16px; }
@media (max-width: 760px) {
  .notes-layout { grid-template-columns: 1fr; }
  .topics { position: static; flex-direction: row; flex-wrap: wrap; }
  .topic-wrap { flex: none; }
}

/* ---------- обзвон и ритм контактов ---------- */
.call-banner { display: block; background: var(--accent-soft); color: var(--text); padding: 10px 16px; border-radius: var(--radius); margin-bottom: 20px; }
.call-banner:hover { outline: 1px solid var(--accent); }
.seg .badge { margin-left: 6px; }
.call-card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 10px; border-left: 4px solid var(--client); display: flex; flex-direction: column; gap: 8px; }
.call-card.lvl-hot { border-left-color: var(--red); }
.call-card.lvl-never { border-left-color: var(--muted); }
.cc-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.client-link.big { font-size: 16px; color: var(--text); }
.client-link.big:hover { color: var(--accent); }
.cc-since { font-size: 13px; }
.lvl-hot .cc-since b { color: var(--red); }
.cc-advice { line-height: 1.5; }
.tag.ch { background: var(--panel-2); color: var(--text); }
.tag.reorder { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.cc-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.rhythm { width: auto; font-size: 12px; padding: 3px 6px; }
.touchbar { display: flex; flex-direction: column; gap: 6px; border-top: 1px dashed var(--line); padding-top: 8px; }
.touch-form input { flex: 1; min-width: 200px; }
.rhythm-block { display: flex; flex-direction: column; gap: 8px; }
.rhythm-block.due { background: linear-gradient(90deg, var(--red-soft), transparent 70%); margin: 0 -22px; padding-left: 22px; padding-right: 22px; }
.rtable { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.rrow { display: grid; grid-template-columns: minmax(180px, 1.6fr) 1.1fr 70px 70px 1fr 150px 120px; gap: 10px; align-items: center; padding: 8px 14px; border-top: 1px solid var(--line); }
.rrow.rhead { border-top: 0; font-size: 12px; color: var(--muted); background: var(--panel-2); }
.rrow.rhead button { border: 0; background: none; color: inherit; text-align: left; padding: 0; cursor: pointer; font: inherit; }
.rrow .num { font-variant-numeric: tabular-nums; }
.rrow .ok { color: var(--ok); }
.chart-wrap { position: relative; max-width: 720px; }
.tip.right { transform: translateX(-100%); }
.tip.left { transform: none; }
.chart { width: 100%; height: auto; display: block; }
.chart .grid line { stroke: var(--line); stroke-width: 1; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart .bar { fill: var(--accent); transition: opacity .12s; }
.chart .bar.dim { opacity: .45; }
.tip { position: absolute; top: 0; transform: translateX(-50%); background: var(--ink); color: #fff; font-size: 12px; padding: 6px 10px; border-radius: 7px; pointer-events: none; white-space: nowrap; box-shadow: var(--shadow); }
@media (max-width: 900px) {
  .rrow { grid-template-columns: 1fr auto; }
  .rrow > :nth-child(n+3):not(:last-child) { display: none; }
}

/* ---------- отчёты ---------- */
.page-head .seg { flex-wrap: wrap; }
.rep-head { margin-bottom: 14px; align-items: flex-start; }
.rep-head > .muted { max-width: 620px; }
.rep-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.funnel-row { display: grid; grid-template-columns: 130px 1fr 110px 150px; gap: 12px; align-items: center; padding: 5px 0; transition: opacity .12s; }
.funnel-row.dim { opacity: .5; }
.f-bar { height: 22px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.f-bar i { display: block; height: 100%; background: var(--accent); border-radius: 0 4px 4px 0; }
.f-num { font-variant-numeric: tabular-nums; }
.f-drop { color: var(--red); }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--line); }
.kv:first-of-type { border-top: 0; }
.kv.click { cursor: pointer; }
.kv.click:hover { color: var(--accent); }
.rtable.src .rrow { grid-template-columns: minmax(160px, 1.5fr) 80px 110px 110px 80px 80px 140px; }
.mini-bar { display: block; height: 4px; background: var(--panel-2); border-radius: 2px; margin-top: 4px; max-width: 160px; }
.mini-bar i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }
.call-banner.warn { background: color-mix(in srgb, var(--client) 15%, transparent); }
.bar i.over { background: var(--red); }
@media (max-width: 900px) {
  .rep-grid { grid-template-columns: 1fr; }
  .funnel-row { grid-template-columns: 100px 1fr 80px; }
  .funnel-row .f-drop { display: none; }
}

/* сумма и источник под названием сделки */
.head-fields { display: flex; gap: 8px; margin: 0 0 10px; flex-wrap: wrap; }
.head-fields label { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border-radius: 8px; padding: 0 10px; border: 1px solid transparent; cursor: text; }
.head-fields label:focus-within { border-color: var(--accent); }
.head-fields label.empty { border-style: dashed; border-color: var(--line); background: transparent; }
.head-fields span { font-size: 12px; color: var(--muted); }
.head-fields input { border: 0; background: transparent; padding: 6px 0; outline: none !important; font-weight: 600; }
.head-fields .hf-sum input { width: 110px; font-variant-numeric: tabular-nums; }
.head-fields .hf-src input { width: 150px; }
.head-fields i { font-style: normal; color: var(--muted); }
.onec-order input:not([type=date]) { width: 140px; }
.onec-order input[type=date] { width: 150px; }
.head-fields .hf-src select { border: 0; background: transparent; padding: 6px 2px; font-weight: 600; width: auto; outline: none; cursor: pointer; }
.head-fields .hf-src select option { background: var(--panel); color: var(--text); }

/* таблицы статистики при открытой карточке справа: только главные колонки */
.rrow .client-link { text-align: left; }

/* Карточка рядом со списком — только на широких экранах; уже 1500px она открывается поверх,
   и список сохраняет полную ширину. Поэтому урезание колонок — только здесь. */
@media (min-width: 1500px) {
  .with-drawer .row { grid-template-columns: 1fr 100px auto; }
  .with-drawer .row .progress, .with-drawer .row .ball { display: none; }
  .with-drawer .trow { grid-template-columns: minmax(0, 1fr) auto; }
  .with-drawer .trow .progress, .with-drawer .trow .t-sum { display: none; }
  .with-drawer .rrow { grid-template-columns: minmax(0, 1.6fr) 100px 64px 150px 110px; }
  .with-drawer .rrow > :nth-child(4), .with-drawer .rrow > :nth-child(5) { display: none; }
  .with-drawer .rtable.src .rrow { grid-template-columns: minmax(0, 1.5fr) 80px 100px 100px; }
  .with-drawer .rtable.src .rrow > :nth-child(n+5) { display: none; }
  .with-drawer .rtable.src .rrow > :nth-child(4) { display: block; }
}

/* ================= телефон ================= */
.tabbar, .side-back, .only-mobile { display: none; }

@media (max-width: 760px) {
  body { -webkit-tap-highlight-color: transparent; }
  .burger { display: none !important; }
  .only-mobile { display: inline-flex; }

  /* нижнее меню */
  .tabbar {
    display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    height: calc(62px + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--panel) 94%, transparent); backdrop-filter: blur(10px);
    border-top: 1px solid var(--line);
  }
  .tabbar a, .tabbar > button:not(.tab-plus) {
    position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
    color: var(--muted); font-size: 11px; background: none; border: 0; padding: 6px 0; cursor: pointer; font-family: inherit;
  }
  .tabbar .ti { font-size: 20px; line-height: 1; }
  .tabbar .on { color: var(--accent); }
  .tabbar .badge { position: absolute; top: 2px; left: calc(50% + 6px); margin: 0; font-size: 10px; line-height: 16px; padding: 0 5px; }
  .tab-plus {
    justify-self: center; width: 50px; height: 50px; border-radius: 16px; border: 0; cursor: pointer;
    background: var(--accent); color: #fff; font-size: 28px; line-height: 1; box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 45%, transparent);
  }
  .tab-plus:active { transform: scale(.95); }

  /* «Ещё» — боковое меню поверх с затемнением */
  .side { width: 270px; z-index: 40; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  .side nav a { padding: 12px 12px; font-size: 15px; }
  .side-back { display: block; position: fixed; inset: 0; z-index: 38; background: rgba(0, 0, 0, .45); }

  /* верх и поля */
  .topbar { padding: calc(10px + env(safe-area-inset-top)) 12px 8px; }
  .quick-box input, input, select, textarea { font-size: 16px; }
  .content { padding: 4px 12px calc(96px + env(safe-area-inset-bottom)); }
  .page-head { margin: 8px 0 14px; }
  h1 { font-size: 20px; }
  .kpis { gap: 6px; }
  .kpi { padding: 8px; border-radius: 8px; }
  .kpi b { font-size: 18px; }
  .kpi span { font-size: 11px; }

  /* строки дел: сверху что и кто, снизу срок и кнопки */
  .row {
    grid-template-columns: 1fr auto; grid-template-areas: "main main" "due act";
    gap: 6px 10px; padding: 10px 10px 8px 14px;
  }
  .row .row-main { grid-area: main; }
  .row .row-due { grid-area: due; text-align: left; display: flex; gap: 8px; align-items: baseline; }
  .row .row-act { grid-area: act; grid-column: auto; }
  .row-top { flex-wrap: wrap; row-gap: 2px; }
  .row-what { flex-wrap: nowrap; }
  .row-act .btn, .row-act a.btn { min-width: 40px; height: 38px; font-size: 16px; }
  .group h2 { margin-bottom: 6px; }

  /* карточки — на весь экран */
  .drawer { width: 100vw; box-shadow: none; z-index: 45; }
  .drawer-bar { padding: calc(8px + env(safe-area-inset-top)) 12px 6px; border-bottom: 1px solid var(--line); }
  .card-body { padding: 0 14px calc(40px + env(safe-area-inset-bottom)); }
  .next-block { margin-left: -14px; padding-left: 10px; }
  .head-fields label { flex: 1 1 100%; }
  .head-fields .hf-sum input, .head-fields .hf-src input { width: 100%; }
  .stage-row { min-height: 46px; }
  .stage-edit { padding-left: 10px; }
  .stage-tools input[type=datetime-local] { width: 100%; }
  .status-line .btn { flex: 1; justify-content: center; }
  .rhythm-block.due { margin: 0 -14px; padding-left: 14px; padding-right: 14px; }
  .touchbar .row-flex .btn { flex: 1 1 calc(50% - 8px); justify-content: center; }
  .task-form { grid-template-columns: 1fr; }
  .contact-head { flex-wrap: wrap; }

  /* напоминания и сообщения — над нижним меню */
  .toasts { left: 10px; right: 10px; width: auto; bottom: calc(72px + env(safe-area-inset-bottom)); }
  .flash { bottom: calc(76px + env(safe-area-inset-bottom)); }

  /* форма новой сделки — на весь экран */
  .modal-back { padding: 0; place-items: stretch; }
  .modal { width: 100%; max-height: none; height: 100%; border-radius: 0; padding: calc(16px + env(safe-area-inset-top)) 16px 24px; }

  /* контакты и заметки */
  .cards { grid-template-columns: 1fr; }
  .page-head .row-flex { width: 100%; }
  .page-head .row-flex .search { flex: 1; }
  .notes-layout { gap: 10px; }
  .topics { flex-direction: row; flex-wrap: nowrap; overflow-x: auto; padding: 6px; gap: 4px; scrollbar-width: none; }
  .topics::-webkit-scrollbar { display: none; }
  .topic-wrap { flex: none; }
  .topic { padding: 8px 12px; white-space: nowrap; }
  .topic-edit { display: none; }
  .add-topic { margin: 0; flex: none; }
  .note-act { opacity: 1; flex-wrap: wrap; }
  .thumbs img { width: 100%; max-width: 320px; }
  .note-form .due-input { width: 100%; }

  /* статистика и отчёты */
  .page-head .seg { overflow-x: auto; flex-wrap: nowrap; max-width: 100%; scrollbar-width: none; }
  .page-head .seg button { white-space: nowrap; }
  .call-card .cc-actions .btn, .call-card .cc-actions a.btn { flex: 1 1 auto; justify-content: center; }
  .funnel-row { grid-template-columns: 96px 1fr 70px; gap: 8px; }
  .bar-row { grid-template-columns: 100px 1fr; }
  .bar-row > :last-child { grid-column: 1 / -1; }
}
@media (max-width: 760px) {
  html, body { overflow-x: hidden; }
  .kpis.big { flex-wrap: wrap; }
  .kpis.big .kpi { min-width: 0; flex: 1 1 calc(50% - 6px); }
  .rtable { overflow-x: auto; }
}
