:root {
  --bg: #f4f5f7; --card: #fff; --ink: #1d1f24; --muted: #6b7280; --line: #e3e5ea; --accent: #3138c5; --accent-soft: #eceefb;
  --red: #c62828; --red-soft: #fdecea; --green: #1b7f3a; --green-soft: #e7f5ec; --amber: #9a6700; --amber-soft: #fff4d6;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; -webkit-text-size-adjust: 100%; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.pad { padding: 16px; }
.small { font-size: 13px; }
[hidden] { display: none !important; }

/* шапка */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 12px; padding: 8px 16px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; color: var(--accent); letter-spacing: .02em; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 6px 10px; border-radius: 8px; color: var(--ink); white-space: nowrap; }
.tabs a:hover { background: var(--bg); text-decoration: none; }
.tabs a.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.badge { display: inline-block; min-width: 18px; padding: 0 5px; margin-left: 2px; border-radius: 9px; background: var(--red); color: #fff; font-size: 12px; line-height: 18px; text-align: center; font-weight: 600; }
.search { flex: 1; max-width: 420px; margin-left: auto; }
.search input { width: 100%; padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.me { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-weight: 600; font-size: 13px; flex: none; }
.menu { position: fixed; right: 12px; top: 54px; z-index: 30; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px 0; min-width: 220px; }
.menu div, .menu a { display: block; padding: 8px 16px; }
.menu .muted { font-size: 13px; }

/* панель над канбаном */
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 16px; }
.bar select, .bar .seg { padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.seg { display: inline-flex; padding: 0 !important; overflow: hidden; }
.seg button { border: 0; background: none; padding: 6px 12px; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.check { display: inline-flex; align-items: center; gap: 6px; }

/* канбан */
.board { display: flex; gap: 12px; padding: 0 16px 24px; overflow-x: auto; align-items: flex-start; min-height: calc(100vh - 120px); -webkit-overflow-scrolling: touch; }
.col { flex: 0 0 272px; background: #eceef2; border-radius: var(--radius); padding: 8px; max-height: calc(100vh - 130px); display: flex; flex-direction: column; }
.col.drop { outline: 2px dashed var(--accent); }
.col-h { background: var(--c, #e6e8ec); color: var(--ink); margin: 0 0 8px; padding: 7px 10px; border-radius: 8px; }
.col-h b { display: block; font-size: 14px; }
.col-h span { font-size: 12px; color: #3d4048; }
.col-body { overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.dcard { display: block; background: var(--card); border-radius: 8px; padding: 8px 10px; box-shadow: var(--shadow); color: var(--ink); font-size: 14px; }
.dcard { transition: box-shadow .12s; }
.dcard:hover { text-decoration: none; box-shadow: 0 2px 10px rgba(16,24,40,.14); }
.dcard .t { font-weight: 600; line-height: 1.3; }
.dcard .m { display: flex; flex-wrap: wrap; gap: 4px 8px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.pill { display: inline-block; padding: 0 6px; border-radius: 6px; font-size: 12px; line-height: 18px; background: var(--bg); color: var(--muted); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }
.pill.blue { background: var(--accent-soft); color: var(--accent); }
.more { border: 0; background: none; color: var(--accent); padding: 6px; }

/* список */
.table-wrap { padding: 0 16px 24px; overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list th, .list td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; font-size: 14px; }
.list th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
.list tr:hover td { background: #fafbff; }

/* карточка сделки */
.deal { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; gap: 16px; padding: 16px; max-width: 1400px; margin: 0 auto; }
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.panel + .panel { margin-top: 12px; }
.panel h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.title-edit { font-size: 20px; font-weight: 700; border: 1px solid transparent; border-radius: 6px; padding: 2px 4px; margin: -3px -5px 4px; width: calc(100% + 10px); background: none; }
.title-edit:hover, .title-edit:focus { border-color: var(--line); background: #fff; }
.stages { display: flex; flex-wrap: wrap; gap: 4px; margin: 10px 0 4px; }
.stages button { border: 1px solid var(--line); background: var(--card); border-radius: 6px; padding: 3px 8px; font-size: 12px; }
.stages button.past { background: var(--accent-soft); border-color: transparent; }
.stages button.cur { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.stages button.final-ok.cur { background: var(--green); border-color: var(--green); }
.stages button.final-bad.cur { background: var(--red); border-color: var(--red); }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 10px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; white-space: pre-wrap; word-break: break-word; }
.form-row { margin-bottom: 10px; }
.form-row label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.form-row input, .form-row select, .form-row textarea { width: 100%; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.form-row textarea { min-height: 60px; resize: vertical; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 6px 12px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.phone { display: flex; gap: 8px; align-items: center; margin: 2px 0; }
.phone a { font-weight: 600; font-size: 16px; }

.ftabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px -16px 12px; padding: 0 12px; overflow-x: auto; }
.ftabs button { border: 0; background: none; padding: 8px 10px; border-bottom: 2px solid transparent; white-space: nowrap; }
.ftabs button.on { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.composer textarea { width: 100%; min-height: 70px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.feed li:last-child { border-bottom: 0; }
.ico { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 14px; background: var(--bg); }
.ico.call { background: var(--green-soft); }
.ico.todo { background: var(--amber-soft); }
.ico.stage { background: var(--accent-soft); }
.feed .h { font-size: 12px; color: var(--muted); }
.feed .h b { color: var(--ink); font-weight: 600; }
.feed .txt { white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.feed audio { width: 100%; max-width: 420px; height: 36px; margin-top: 6px; }
.files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.files a, .files span { font-size: 13px; padding: 2px 8px; border-radius: 6px; background: var(--bg); }

/* переписка */
.chat { display: flex; flex-direction: column; gap: 6px; max-height: 70vh; overflow-y: auto; padding: 4px; }
.msg { max-width: 78%; padding: 6px 10px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.msg.client { align-self: flex-start; background: var(--bg); border-bottom-left-radius: 4px; }
.msg.staff { align-self: flex-end; background: var(--accent-soft); border-bottom-right-radius: 4px; }
.msg.system { align-self: center; background: none; color: var(--muted); font-size: 12px; max-width: 90%; text-align: center; }
.msg .h { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.chat-title { font-weight: 600; margin: 4px 0 8px; }

/* дела */
.todos { max-width: 900px; margin: 0 auto; padding: 0 16px 24px; }
.todos h2 { font-size: 15px; margin: 18px 0 8px; }
.todo { display: grid; grid-template-columns: 26px 1fr auto; gap: 10px; align-items: start; background: var(--card); border-radius: 8px; padding: 10px 12px; margin-bottom: 6px; box-shadow: var(--shadow); }
.todo input[type=checkbox] { width: 20px; height: 20px; margin: 1px 0 0; }
.todo .s { font-weight: 600; }
.todo.done .s { text-decoration: line-through; color: var(--muted); }
.todo .when { font-size: 13px; white-space: nowrap; }
.todo .when.late { color: var(--red); font-weight: 600; }

.toast { position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: #222; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 50; font-size: 14px; max-width: 90vw; }
.login { max-width: 460px; margin: 15vh auto; padding: 24px; text-align: center; }

@media (max-width: 860px) {
  .deal { grid-template-columns: 1fr; padding: 12px; }
  .top { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .search { order: 5; flex-basis: 100%; max-width: none; }
  .tabs a { padding: 6px 8px; }
  .menu { top: 96px; }
  .col { flex-basis: 84vw; max-height: none; }
  .board { scroll-snap-type: x mandatory; padding: 0 12px 24px; }
  .col { scroll-snap-align: start; }
  .col-body { overflow: visible; }
  .bar { padding: 10px 12px; }
  .kv { grid-template-columns: 110px 1fr; }
  .msg { max-width: 90%; }
  .hide-m { display: none; }
}

.tip { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; background: var(--line); color: var(--muted); font-size: 11px; font-weight: 700; cursor: help; position: relative; vertical-align: 1px; text-transform: none; letter-spacing: 0; }
.tip:hover::after, .tip:focus::after { content: attr(data-tip); position: absolute; left: 50%; top: 22px; transform: translateX(-50%); width: 240px; padding: 8px 10px; border-radius: 8px; background: #222; color: #fff; font-size: 13px; font-weight: 400; line-height: 1.35; z-index: 40; text-align: left; }

.seg.wrap { flex-wrap: wrap; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chips button { border: 1px solid var(--line); background: var(--card); border-radius: 6px; padding: 3px 9px; font-size: 13px; line-height: 1.35; text-align: left; }
.chips button:hover { border-color: var(--accent); }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.inp { padding: 5px 8px; border: 1px solid var(--line); border-radius: 6px; }
