/* CRM — сначала телефон, потом компьютер. Без сборки и без внешних библиотек. */
:root {
  --bg: #f4f5f7; --card: #fff; --ink: #1d2433; --muted: #6b7385; --line: #e2e5eb;
  --brand: #1f6f5c; --brand-ink: #fff; --hot: #c2410c; --hot-bg: #fff4ec; --warn: #a16207; --warn-bg: #fef6dc;
  --ok: #15803d; --ok-bg: #e9f7ee; --bad: #b42318; --bad-bg: #fdecea; --info-bg: #e8f1fd; --info: #1d4ed8;
  --grey-bg: #eef0f3; --radius: 10px; --nav-h: 58px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; padding-bottom: calc(var(--nav-h) + 16px); }
a { color: var(--brand); }
h1 { font-size: 20px; margin: 0 0 6px; }
h2 { font-size: 17px; margin: 0 0 8px; }
h3 { font-size: 14px; margin: 16px 0 6px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
p { margin: 4px 0; }
code { font-size: 12px; background: var(--grey-bg); padding: 1px 4px; border-radius: 4px; word-break: break-all; }
blockquote { margin: 6px 0; padding: 6px 10px; border-left: 3px solid var(--line); background: var(--bg); border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- шапка и меню ---------- */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; text-decoration: none; color: var(--brand); font-size: 17px; }
.nav { position: fixed; left: 0; right: 0; bottom: 0; height: var(--nav-h); display: flex; background: var(--card); border-top: 1px solid var(--line); z-index: 30; }
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; color: var(--muted); font-size: 11px; position: relative; }
.nav a .ic { font-size: 18px; line-height: 1.1; }
.nav a.on { color: var(--brand); font-weight: 600; }
.badge { background: var(--hot); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; position: absolute; top: 6px; right: calc(50% - 26px); }
.whoami { margin-left: auto; display: flex; align-items: center; gap: 4px; font-size: 14px; }
.whoami a { color: var(--ink); text-decoration: none; }
.auth-form { display: grid; gap: 10px; margin-top: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 3px; }
.auth-form input { font-size: 16px; }
.mode { background: var(--grey-bg); color: var(--muted); font-size: 12px; text-align: center; padding: 3px 16px; }
main { padding: 12px 16px; max-width: 1180px; margin: 0 auto; }

/* ---------- общие элементы ---------- */
.box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 12px; }
.box.narrow { max-width: 420px; margin: 24px auto; }
.box.hot, .row.hot { border-color: #f5b48f; background: var(--hot-bg); }
.btn { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px; padding: 7px 12px; font: inherit; font-size: 14px; cursor: pointer; text-decoration: none; min-height: 36px; }
.btn:hover { border-color: #c5cad3; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--bad); border-color: #f1b8b2; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.sm { padding: 4px 9px; font-size: 13px; min-height: 30px; }
.btn.big { width: 100%; justify-content: flex-start; padding: 12px 14px; font-size: 16px; }
.btn.wa { background: #e7f8ee; border-color: #b6e6c8; color: #11663a; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.actions form, form.inline { display: inline; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--info-bg); color: var(--info); white-space: nowrap; }
.pill.warn, .tag.warn { background: var(--warn-bg); color: var(--warn); }
.st-won { background: var(--ok-bg); color: var(--ok); }
.st-lost, .st-junk { background: var(--grey-bg); color: var(--muted); }
.tag { display: inline-block; font-size: 12px; padding: 1px 6px; border-radius: 6px; background: var(--grey-bg); color: #3f4757; white-space: nowrap; }
.tag.ad { background: #f3e8ff; color: #7e22ce; }
.hint { font-size: 13px; color: var(--muted); }
.hint.warn { color: var(--warn); background: var(--warn-bg); padding: 6px 8px; border-radius: 6px; }
input, select, textarea { font: inherit; font-size: 15px; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: #fff; color: var(--ink); max-width: 100%; min-height: 36px; }
textarea { width: 100%; }
label { font-size: 13px; color: var(--muted); }
label.check { display: inline-flex; gap: 6px; align-items: center; color: var(--ink); font-size: 14px; }
details > summary { list-style: none; cursor: pointer; }
details > summary::-webkit-details-marker { display: none; }
details.sub { margin-top: 8px; }
details.sub[open] > summary { margin-bottom: 8px; }
.row-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; }
.grid-form { display: grid; grid-template-columns: 1fr; gap: 8px; margin-top: 8px; }
.grid-form label { display: flex; flex-direction: column; gap: 3px; }
.grid-form label.check { flex-direction: row; }
.grid-form button { justify-self: start; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list > li.done { color: var(--muted); text-decoration: line-through; }
.list > li.overdue { color: var(--bad); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; margin: 6px 0 4px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ---------- сообщение после действия ---------- */
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + 10px); margin: 0 auto; max-width: 520px; padding: 10px 14px; border-radius: 10px; z-index: 40; box-shadow: 0 4px 18px rgba(0,0,0,.15); transition: opacity .4s; }
.toast.ok { background: #13352c; color: #fff; }
.toast.err { background: var(--bad); color: #fff; }
.toast.hide { opacity: 0; pointer-events: none; }

/* ---------- Клиенты ---------- */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.filters input[type=search] { flex: 1 1 100%; }
.filters select { flex: 1 1 140px; }
.count { margin: 4px 0; font-size: 13px; }
.rows { list-style: none; padding: 0; margin: 0; }
.row { display: flex; align-items: flex-start; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 6px; }
.row.junk { opacity: .65; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; padding: 9px 12px; color: inherit; text-decoration: none; }
.row-top { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.row-top .name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-top .phone { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-top .time { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.last { color: #3f4757; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.ic-mode { font-size: 14px; }
.quick { position: relative; padding: 8px 10px; }
.quick summary { font-size: 18px; color: var(--muted); padding: 0 4px; }
.quick-menu { position: absolute; right: 6px; top: 34px; z-index: 10; display: flex; flex-direction: column; gap: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.1); }
.empty { padding: 16px; color: var(--muted); text-align: center; }

/* ---------- Карточка клиента ---------- */
.card-grid { display: grid; grid-template-columns: 1fr; gap: 0; }
.back { margin: 0 0 4px; font-size: 13px; }
.head-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.head-row h1 { margin: 0; }
.contact { font-size: 14px; }
.note-text { background: var(--warn-bg); padding: 6px 8px; border-radius: 6px; font-size: 14px; }
.chat-state .state { font-size: 15px; }
.lead-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; align-items: center; }
.tab { font-size: 13px; padding: 3px 9px; border-radius: 12px; background: var(--grey-bg); color: var(--ink); text-decoration: none; }
.tab.on { background: var(--brand); color: #fff; }
.lead h2 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.visits .pill.vs-held { background: var(--warn-bg); color: var(--warn); }
.visits .pill.vs-confirmed { background: var(--info-bg); color: var(--info); }
.visits .pill.vs-done { background: var(--ok-bg); color: var(--ok); }
.visits .pill.vs-cancelled, .visits .pill.vs-no_show { background: var(--grey-bg); color: var(--muted); }
details.book { margin-top: 8px; border-top: 1px dashed var(--line); padding-top: 8px; }
.slots-form { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.slot-day { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.slot-day > b { min-width: 64px; }
.slot-list { display: flex; flex-wrap: wrap; gap: 6px; }
.slot input { position: absolute; opacity: 0; }
.slot span { display: inline-block; padding: 5px 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; font-size: 14px; }
.slot input:checked + span { background: var(--brand); color: #fff; border-color: var(--brand); }
.slot input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: 1px; }
.feed { display: flex; flex-direction: column; gap: 6px; max-height: 70vh; overflow-y: auto; padding: 4px 2px; }
.msg { max-width: 88%; padding: 6px 10px; border-radius: 12px; font-size: 14px; }
.msg.in { align-self: flex-start; background: var(--grey-bg); border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; background: #dcf3e6; border-bottom-right-radius: 4px; }
.msg.out.a-bot { background: var(--info-bg); }
.msg .meta { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg .text { white-space: pre-wrap; word-wrap: break-word; }
.msg .text.revoked { text-decoration: line-through; color: var(--muted); }
.ad-note { font-size: 12px; color: #7e22ce; }
.event { align-self: center; font-size: 12px; color: var(--muted); background: var(--bg); border-radius: 8px; padding: 2px 8px; text-align: center; max-width: 95%; }
.event.ev-handoff { color: var(--hot); }
.note-form { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.note-form button { align-self: flex-start; }

/* ---------- Воронка ---------- */
.legend { margin: 4px 0 10px; }
.board { display: flex; flex-direction: column; gap: 8px; }
.col { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.col > summary { display: grid; grid-template-columns: 1fr auto; gap: 0 8px; padding: 10px 12px; }
.col-name { font-weight: 600; }
.col-n { font-weight: 700; font-size: 17px; }
.col-sub { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.col.st-won > summary { color: var(--ok); }
.col.st-lost > summary, .col.st-junk > summary { color: var(--muted); }
.col.over { outline: 2px dashed var(--brand); }
.col-body { padding: 0 8px 8px; display: flex; flex-direction: column; gap: 6px; }
.fcard { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; }
.fcard[draggable=true] { cursor: grab; }
.fcard-link { display: flex; flex-direction: column; gap: 1px; color: inherit; text-decoration: none; }
.move-form { margin-top: 6px; }
.move-form select { width: 100%; font-size: 13px; min-height: 30px; padding: 3px 6px; }

/* ---------- Календарь ---------- */
.cal-nav { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.legend .cell-demo { display: inline-block; padding: 1px 6px; border-radius: 6px; margin-right: 4px; }
.cal-day.today { border-color: var(--brand); }
.cal-day.off { opacity: .6; padding: 8px 14px; }
.cal-day.off h2 { margin: 0; }
.cal { width: 100%; border-collapse: collapse; table-layout: fixed; }
.cal th, .cal td { border: 1px solid var(--line); padding: 5px 6px; vertical-align: top; font-size: 13px; text-align: left; }
.cal thead th { font-size: 13px; background: var(--bg); }
.cal .slot-h { width: 64px; font-weight: 500; color: var(--muted); background: var(--bg); }
.cal td a { color: inherit; text-decoration: none; display: block; }
.cal td .tag { margin-top: 2px; }
.load { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.load.full { color: var(--hot); font-weight: 600; }
.vs-held { background: var(--warn-bg); }
.vs-confirmed { background: var(--info-bg); }
.vs-done { background: var(--ok-bg); }
.busy { background: repeating-linear-gradient(45deg, #eef0f3, #eef0f3 6px, #e3e6eb 6px, #e3e6eb 12px); color: var(--muted); }
.quick-cell summary { color: var(--muted); margin-top: 3px; }
.quick-cell form { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.quick-cell input { width: 100%; font-size: 13px; min-height: 30px; }

/* ---------- Нужен человек ---------- */
.handoff.taken { border-left: 4px solid var(--info); }
.handoff.hot { border-left: 4px solid var(--hot); }

/* ---------- компьютер ---------- */
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .nav { position: static; height: auto; border: 0; background: none; gap: 4px; }
  .nav a { flex: none; flex-direction: row; gap: 6px; font-size: 14px; padding: 6px 10px; border-radius: 8px; }
  .nav a.on { background: var(--grey-bg); }
  .nav a .ic { font-size: 14px; }
  .badge { position: static; }
  .toast { bottom: 20px; }
  .filters input[type=search] { flex: 1 1 260px; }
  .card-grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); gap: 12px; align-items: start; }
  .col-b { position: sticky; top: 64px; }
  .grid-form { grid-template-columns: 1fr 1fr; }
  .grid-form .wide { grid-column: 1 / -1; }
  main.wide-page { max-width: none; }
  .board { flex-direction: row; overflow-x: auto; align-items: flex-start; padding-bottom: 8px; }
  .col { flex: 0 0 230px; }
  .col > summary { pointer-events: none; }
  .col:not([open]) > .col-body { display: none; }
}
