:root {
  --bg: #f1f4f3; --panel: #fff; --ink: #10201d; --muted: #566763; --line: #d5dedb;
  --accent: #0b6b5a; --accent-soft: #e0f0ec; --hot: #a8310f; --hot-soft: #fdebe4;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
#app { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; font-weight: 600; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
input, select, textarea { width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
textarea { resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 700; color: var(--muted); }
label > * { font-size: 15px; font-weight: 400; color: var(--ink); }
a { color: var(--accent); font-weight: 600; }
.muted, .empty { color: var(--muted); }
.problem { color: var(--hot); font-weight: 600; }

.login { margin: auto; width: min(340px, calc(100% - 32px)); display: flex; flex-direction: column; gap: 14px; background: var(--panel); padding: 28px; border-radius: 14px; border: 1px solid var(--line); }
.login h1 { margin: 0; font-size: 22px; }

header { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
header h1 { margin: 0; font-size: 19px; font-weight: 800; }
header h1 span { color: var(--accent); }
header input { flex: 1 1 220px; max-width: 380px; }
.sync { margin: 0 0 0 auto; font-size: 13px; color: var(--muted); }
.sync.bad { color: var(--hot); font-weight: 700; }
.banner { margin: 0; padding: 10px 16px; background: var(--hot-soft); color: var(--hot); font-weight: 600; }

.tabs { display: none; gap: 6px; overflow-x: auto; padding: 8px 12px; flex: none; }
.tabs button { flex: none; }
.tabs button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

.board { flex: 1; min-height: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(210px, 1fr); gap: 12px; padding: 12px 16px; overflow-x: auto; }
.column { display: flex; flex-direction: column; min-height: 0; background: #e6ecea; border-radius: 12px; border: 2px solid transparent; }
.column.over { border-color: var(--accent); }
.column h2 { display: flex; justify-content: space-between; margin: 0; padding: 12px 12px 8px; font-size: 15px; font-weight: 800; }
.column h2 span { color: var(--muted); }
.cards { flex: 1; overflow-y: auto; padding: 0 8px 8px; display: flex; flex-direction: column; gap: 8px; }
.empty { margin: 0; padding: 8px 4px; font-size: 13px; }
.card { flex: none; display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.card .open { display: flex; flex-direction: column; gap: 4px; text-align: left; font-weight: 400; padding: 10px 12px; border: 0; background: none; }
.contacts { display: flex; flex-wrap: wrap; gap: 6px; }
.contact { display: inline-flex; align-items: center; justify-content: center; padding: 5px 9px; border-radius: 8px; border: 1px solid currentColor; font-size: 13px; font-weight: 700; text-decoration: none; }
.contact.instagram { color: #8f2a72; }
.contact.whatsapp { color: #0f6b3a; }
.contact.telegram { color: #14628f; }
.contact.off { color: var(--muted); border-style: dashed; opacity: .7; }
.answer { display: flex; flex-direction: column; gap: 8px; padding: 12px 14px; background: var(--panel); border-top: 1px solid var(--line); }
.answer p { margin: 0; font-size: 13px; font-weight: 700; color: var(--muted); }
.answer .contact { flex: 1 1 120px; min-height: 44px; font-size: 15px; }
.acts { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 10px 10px; }
.acts:empty { display: none; }
.acts button { padding: 4px 10px; font-size: 12px; }
.acts .answered { flex: 1; color: var(--accent); border-color: var(--accent); }
.acts .add-step { margin-left: auto; color: var(--muted); border-style: dashed; }
.card > .step { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 0 10px 8px; padding: 0; border: 0; background: none; text-align: left; font-size: 13px; font-weight: 500; }
.step .due { padding: 2px 6px; border-radius: 4px; background: #eef1f3; color: #3c4a5c; font-weight: 700; white-space: nowrap; }
.step.is-today .due { background: #f5cd47; color: #453203; }
.step.is-late .due { background: #ffd5d2; color: #9b261e; }
.step-text { overflow-wrap: anywhere; }
.answer .answered { color: var(--accent); border-color: var(--accent); }
.danger { color: var(--hot); border-color: var(--hot); margin-top: 8px; }
.board.removed { grid-auto-columns: minmax(0, 520px); }
.card.waiting { border-color: var(--hot); border-width: 2px; }
.card .row { display: flex; justify-content: space-between; gap: 8px; }
.card strong { overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card time { flex: none; font-size: 12px; color: var(--muted); }
.card .muted { font-size: 13px; }
.card .last { font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { font-style: normal; font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: #eef2f1; overflow-wrap: anywhere; }
.chip.hot { background: var(--hot-soft); color: var(--hot); }
.chip.ok { background: var(--accent-soft); color: var(--accent); }

dialog.lead { width: min(980px, calc(100% - 24px)); height: min(760px, calc(100dvh - 24px)); max-width: none; max-height: none; padding: 0; border: 0; border-radius: 14px; color: var(--ink); }
dialog.lead[open] { display: flex; flex-direction: column; }
dialog.lead::backdrop { background: rgb(16 32 29 / .5); }
.head { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.head > div { margin-right: auto; min-width: 0; }
.head h2 { margin: 0; font-size: 18px; overflow-wrap: anywhere; }
.body { flex: 1; min-height: 0; display: grid; grid-template-columns: 300px 1fr; }
.side { overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 12px; border-right: 1px solid var(--line); }
.side > * { flex: none; }
/* Этапы стрелками сверху, как в CRM недвижимости: текущий закрашен, пройденные и будущие - бледным цветом этапа. */
.steps { display: flex; flex: none; gap: 4px; padding: 10px 16px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.steps button { --col: #475569; flex: 1 0 auto; height: 34px; padding: 0 16px; border: 0; border-radius: 0; font-size: 13px; white-space: nowrap;
  background: color-mix(in srgb, var(--col) 12%, #fff); color: color-mix(in srgb, var(--col) 55%, #000);
  clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%, 10px 50%); }
.steps button:first-child { clip-path: polygon(0 0, calc(100% - 10px) 0, 100% 50%, calc(100% - 10px) 100%, 0 100%); border-radius: 7px 0 0 7px; }
.steps button.past { background: color-mix(in srgb, var(--col) 24%, #fff); }
.steps button:hover { background: color-mix(in srgb, var(--col) 32%, #fff); }
.steps button[aria-pressed="true"] { background: var(--col); color: #fff; }
.steps button:focus-visible { outline-offset: -4px; outline-color: var(--ink); }
.steps [data-stage="new"] { --col: #2563eb; }
.steps [data-stage="talking"] { --col: #b45309; }
.steps [data-stage="booked"] { --col: #7c3aed; }
.steps [data-stage="came"] { --col: #15803d; }
.steps [data-stage="refused"] { --col: #b91c1c; }

.next-form, .next-rest { display: flex; flex-direction: column; gap: 8px; }
.next-quick { display: flex; flex-wrap: wrap; gap: 6px; }
.next-quick button { padding: 7px 10px; font-size: 13px; font-weight: 600; }
.next-quick button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.next-label { font-size: 13px; font-weight: 700; color: var(--muted); }
.next-due { display: flex; align-items: center; gap: 8px; text-align: left; font-weight: 500; }
.next-due > span:last-child { margin-left: auto; }
.next-due em { font-style: normal; font-size: 12px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--hot-soft); color: var(--hot); }
.next-cal { display: flex; flex-direction: column; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cal-head button { padding: 4px 12px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; }
.cal-grid span { font-size: 12px; color: var(--muted); }
.cal-grid button { padding: 0; height: 32px; border-color: transparent; font-weight: 500; }
.cal-grid button.today { border-color: var(--accent); }
.cal-grid button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.cal-time { flex-direction: row; align-items: center; justify-content: space-between; }
.cal-time select { width: 110px; }
.cal-actions { display: flex; gap: 8px; }
.cal-actions .primary { flex: 1; }
.next-remove { color: #44474d; }

dialog.quick { width: min(360px, calc(100% - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto; padding: 16px; border: 0; border-radius: 14px; color: var(--ink); }
dialog.quick::backdrop { background: rgb(16 32 29 / .5); }
.quick-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.quick-head > div { min-width: 0; overflow-wrap: anywhere; }
.quick-head h2 { margin: 0; font-size: 17px; }
.toast { position: fixed; z-index: 5; left: 50%; bottom: 20px; transform: translateX(-50%); margin: 0; padding: 10px 16px; border-radius: 8px; background: var(--ink); color: #fff; font-size: 14px; font-weight: 600; width: max-content; max-width: calc(100% - 24px); text-align: center; pointer-events: none; }

.booked { margin: 0; padding: 8px 10px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.feed-tabs { display: flex; flex: none; gap: 6px; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); }
.feed-tabs button { padding: 4px 12px; font-size: 13px; }
.feed-tabs button[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.msg.note { align-self: stretch; max-width: none; background: #fdf3c8; border-color: #e6d27a; }
.composer { display: flex; flex: none; gap: 8px; align-items: flex-end; padding: 10px 14px; background: #fdf8e1; border-top: 1px solid #e6d27a; }
.composer textarea { flex: 1; min-width: 0; resize: none; }
.title .name { display: flex; align-items: center; gap: 6px; min-width: 0; }
.title .rename { flex: none; padding: 2px 8px; border: 0; background: none; color: var(--muted); }
.title input { max-width: 340px; }
.merge, .joined, .merge-picker, .merge-list { display: flex; flex-direction: column; gap: 8px; }
.joined > div { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; overflow-wrap: anywhere; }
.joined > div span { min-width: 0; }
.joined button { flex: none; padding: 4px 10px; font-size: 12px; }
.merge-picker { padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
.merge-picker p { margin: 0; font-size: 13px; color: var(--muted); }
.merge-list button { display: flex; flex-direction: column; gap: 2px; text-align: left; font-weight: 400; overflow-wrap: anywhere; }
.merge-list button span { font-size: 12px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.msg { align-self: flex-start; max-width: 80%; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; overflow-wrap: anywhere; }
.msg.out { align-self: flex-end; background: var(--accent-soft); border-color: #bfded6; }
.msg.bot { background: #e9ecf4; border-color: #d3d9ea; }
.msg p { margin: 2px 0 0; white-space: pre-wrap; }
.msg small { display: block; font-size: 12px; color: var(--muted); }
.msg img, .msg video { display: block; max-width: 100%; max-height: 280px; margin-top: 6px; border-radius: 8px; }
.msg audio, .msg a, .msg span { display: block; margin-top: 4px; max-width: 100%; }
@media (max-width: 760px) {
  header input { order: 3; max-width: none; flex-basis: 100%; }
  header h1 { margin-right: auto; }
  .sync { order: 4; flex-basis: 100%; margin: 0; }
  .tabs { display: flex; }
  .board { display: flex; flex-direction: column; padding: 0 12px 12px; }
  .column { display: none; flex: 1; }
  .column.current { display: flex; }
  .column h2 { display: none; }
  .cards { padding-top: 8px; }
  dialog.lead { width: 100%; height: 100dvh; border-radius: 0; margin: 0; }
  .head { flex-wrap: wrap; }
  .body { display: flex; flex-direction: column; overflow-y: auto; }
  .side { overflow: visible; flex: none; border-right: 0; border-bottom: 1px solid var(--line); }
  .chat { flex: none; order: -1; border-bottom: 1px solid var(--line); }
  .messages { max-height: 52dvh; }
  .steps { padding: 8px 12px; }
  .steps button { flex: none; height: 44px; }
  .cal-grid button { height: 40px; }
  input, select, textarea { font-size: 16px; }
}
@media (pointer: coarse) { button, input, select, .contact { min-height: 44px; } }
