/* ---------- тема ---------- */
:root {
  --bg: #f3f4f7; --surface: #ffffff; --surface-2: #f8f9fb; --text: #1a1f27; --muted: #6a7280; --border: #e3e6ec;
  --accent: #2563eb; --accent-text: #ffffff; --accent-soft: #e8efff;
  --ok: #16a34a; --ok-soft: #e6f6ec; --warn: #d97706; --warn-soft: #fff3df; --danger: #dc2626; --danger-soft: #fdeaea;
  --purple: #7c3aed; --purple-soft: #f0e9ff; --teal: #0d9488; --teal-soft: #e0f5f2; --gray-soft: #eceef2;
  --bubble-in: #ffffff; --bubble-out: #dbeafe; --bubble-bot: #efe9ff; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --radius: 12px; --tabbar-h: 58px; --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
:root[data-theme="dark"] {
  --bg: #0f1218; --surface: #181c24; --surface-2: #1e232d; --text: #e8ebf0; --muted: #98a1b0; --border: #2a303b;
  --accent: #4c8dff; --accent-text: #0b0f16; --accent-soft: #1b2b4d;
  --ok: #3ecf73; --ok-soft: #14301f; --warn: #f0a23a; --warn-soft: #382a12; --danger: #ff6b6b; --danger-soft: #3a1c1f;
  --purple: #a78bfa; --purple-soft: #2a2145; --teal: #2dd4bf; --teal-soft: #0f2f2c; --gray-soft: #262c37;
  --bubble-in: #232936; --bubble-out: #1c3358; --bubble-bot: #2a2145; --shadow: none;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.4; }
body { overscroll-behavior: none; overflow: hidden; }
#root { height: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button, a, input, select, textarea, label, summary { touch-action: manipulation; }   /* без задержки и увеличения по двойному тапу */
/* iOS Safari приближает страницу при фокусе на поле со шрифтом меньше 16px и не возвращает масштаб: на телефонах и планшетах поля — 16px+ */
@media (max-width: 899px), (pointer: coarse) { input, select, textarea, .input { font-size: 16px; } }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; }
h2 { font-size: 20px; } h3 { font-size: 16px; } h4 { font-size: 14px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 12px; } .nowrap { white-space: nowrap; }
.right { margin-left: auto; } .center { text-align: center; } .hidden { display: none !important; }
.mt { margin-top: 12px; } .mb { margin-bottom: 12px; } .gap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; } .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.boot { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 50; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- каркас ---------- */
.app { display: flex; height: 100%; }
.sidebar { width: 236px; background: var(--surface); border-right: 1px solid var(--border); display: none; flex-direction: column; padding: 14px 10px; gap: 2px; overflow: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 14px; font-weight: 700; font-size: 17px; }
.brand .logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-weight: 800; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 10px; color: var(--text); cursor: pointer; border: 0; background: none; text-align: left; width: 100%; }
.nav-item:hover { background: var(--surface-2); } .nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .ico { width: 20px; text-align: center; } .nav-sep { margin: 10px 12px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.count { margin-left: auto; background: var(--accent); color: var(--accent-text); font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 10px; min-width: 20px; text-align: center; }
.count.warn { background: var(--danger); color: #fff; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; background: var(--surface); border-bottom: 1px solid var(--border); min-height: 52px; }
.topbar h2 { font-size: 17px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page { flex: 1; overflow: auto; padding: 14px; padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 18px); -webkit-overflow-scrolling: touch; }
.page.wide { max-width: 1280px; width: 100%; margin: 0 auto; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--surface); border-top: 1px solid var(--border); display: flex; z-index: 20; }
.tab { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; color: var(--muted); position: relative; cursor: pointer; }
.tab .ico { font-size: 20px; line-height: 1; } .tab.active { color: var(--accent); font-weight: 600; }
.tab .count { position: absolute; top: 4px; left: 54%; margin: 0; }
@media (min-width: 900px) {
  .sidebar { display: flex; } .tabbar { display: none; } .page { padding: 20px 24px 40px; }
  .back-btn.mobile-only { display: none; }
}

/* ---------- базовые элементы ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; } .card h3 { margin-bottom: 10px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 550; min-height: 40px; }
.btn:hover { background: var(--surface-2); } .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); } .btn.primary:hover { filter: brightness(1.08); }
.btn.ok { background: var(--ok); color: #fff; border-color: var(--ok); } .btn.danger { color: var(--danger); border-color: var(--danger-soft); background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; } .btn.small { padding: 5px 10px; min-height: 32px; font-size: 13px; border-radius: 8px; }
.btn.icon { padding: 0; width: 38px; min-height: 38px; font-size: 18px; }
.input, select.input, textarea.input { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); outline: none; min-height: 40px; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea.input { resize: vertical; min-height: 72px; }
.field { margin-bottom: 12px; } .field > label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 550; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 3px; } .field .hint.warn { color: var(--warn); } .field .err { font-size: 12px; color: var(--danger); margin-top: 3px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; } .check input { width: 18px; height: 18px; accent-color: var(--accent); }
.switch { position: relative; width: 44px; height: 26px; flex: none; } .switch input { opacity: 0; width: 100%; height: 100%; position: absolute; margin: 0; cursor: pointer; z-index: 1; }
.switch i { position: absolute; inset: 0; background: var(--border); border-radius: 13px; transition: .15s; } .switch i::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .15s; box-shadow: 0 1px 2px rgba(0,0,0,.3); }
.switch input:checked + i { background: var(--ok); } .switch input:checked + i::after { left: 21px; }
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; background: var(--gray-soft); color: var(--muted); white-space: nowrap; }
.badge.blue { background: var(--accent-soft); color: var(--accent); } .badge.green { background: var(--ok-soft); color: var(--ok); }
.badge.orange { background: var(--warn-soft); color: var(--warn); } .badge.red { background: var(--danger-soft); color: var(--danger); }
.badge.purple { background: var(--purple-soft); color: var(--purple); } .badge.teal { background: var(--teal-soft); color: var(--teal); }
.chip { padding: 6px 12px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 13px; white-space: nowrap; }
.chip.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; } .chips::-webkit-scrollbar { display: none; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; } .empty .big { font-size: 36px; margin-bottom: 6px; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--muted); flex: none; } .dot.ok { background: var(--ok); } .dot.bad { background: var(--danger); } .dot.warn { background: var(--warn); }
.kv { display: grid; grid-template-columns: 38% 1fr; gap: 6px 10px; font-size: 14px; } .kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }
.sec-title { display: flex; align-items: center; gap: 8px; margin: 18px 2px 8px; } .sec-title h3 { flex: 1; }

/* ---------- списки лидов / задач ---------- */
.list-item { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 8px; cursor: pointer; color: inherit; box-shadow: var(--shadow); }
.list-item:hover { border-color: var(--accent); }
.list-item .l1 { display: flex; align-items: center; gap: 8px; } .list-item .l1 b { font-weight: 650; }
.list-item .l2 { color: var(--muted); font-size: 13px; margin-top: 3px; }
.list-item .l3 { font-size: 13px; margin-top: 6px; display: flex; gap: 8px; align-items: center; }
.list-item.urgent { border-left: 4px solid var(--danger); } .list-item.waiting { border-left: 4px solid var(--warn); }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; } .toolbar .input { flex: 1; min-width: 140px; }

/* ---------- карточка лида ---------- */
.lead-head { display: flex; align-items: flex-start; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; overflow-x: auto; scrollbar-width: none; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 550; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.messages { flex: 1; overflow-y: auto; padding: 8px 2px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: 82%; padding: 8px 12px; border-radius: 14px; background: var(--bubble-in); border: 1px solid var(--border); align-self: flex-start; white-space: pre-wrap; word-break: break-word; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); border-color: transparent; } .bubble.bot { align-self: flex-end; background: var(--bubble-bot); border-color: transparent; }
.bubble .who { font-size: 11px; color: var(--muted); margin-bottom: 2px; font-weight: 600; } .bubble .time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.bubble.failed { border: 1px dashed var(--danger); opacity: .9; }
.bubble .dlv { font-size: 11px; margin-top: 4px; color: var(--muted); } .bubble .dlv.warn { color: var(--warn, #b45309); } .bubble .dlv.bad { color: var(--danger); font-weight: 600; }
.day-sep { align-self: center; font-size: 12px; color: var(--muted); background: var(--gray-soft); padding: 2px 10px; border-radius: 10px; margin: 6px 0; }
.composer { border-top: 1px solid var(--border); padding-top: 8px; margin-top: 4px; } .composer textarea { min-height: 48px; max-height: 160px; }
.banner { padding: 10px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 14px; margin-bottom: 10px; }
.banner.info { background: var(--accent-soft); color: var(--accent); } .banner.err { background: var(--danger-soft); color: var(--danger); } .banner.ok { background: var(--ok-soft); color: var(--ok); }
.lead-cols .pane { display: none; }
.lead-view[data-tab="chat"] .pane-chat { display: flex; }
.lead-view[data-tab="info"] .pane-info, .lead-view[data-tab="work"] .pane-work, .lead-view[data-tab="history"] .pane-history { display: block; }
.side-tabs { display: none; }
.chat { display: flex; flex-direction: column; height: calc(100vh - 360px); min-height: 340px; }
@media (min-width: 960px) {
  .lead-cols { display: grid; grid-template-columns: minmax(420px, 1.25fr) minmax(340px, 1fr); gap: 16px; align-items: start; }
  .narrow-tabs { display: none; } .side-tabs { display: flex; }
  .lead-cols .pane-chat { display: flex !important; }
  .lead-cols .side .pane { display: none !important; }
  .lead-view[data-side="info"] .pane-info, .lead-view[data-side="work"] .pane-work, .lead-view[data-side="history"] .pane-history { display: block !important; }
  .chat { height: calc(100vh - 270px); }
}

/* ---------- таблицы, показатели ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; } table.t th, table.t td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
table.t th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; background: var(--surface-2); cursor: default; }
table.t th.sortable { cursor: pointer; } table.t tr:last-child td { border-bottom: 0; } table.t tr.click { cursor: pointer; } table.t tr.click:hover td { background: var(--surface-2); }
table.t td.wrap { white-space: normal; min-width: 180px; } td.num, th.num { text-align: right; }
.grid { display: grid; gap: 10px; } .grid.kpis { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 2px; } .kpi .l { font-size: 12px; color: var(--muted); } .kpi .s { font-size: 12px; margin-top: 2px; color: var(--muted); }
.cols-2 { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); } @media (min-width: 900px) { .cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.hbar { display: grid; grid-template-columns: minmax(80px, 34%) 1fr auto; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.hbar .track { background: var(--gray-soft); border-radius: 6px; height: 14px; overflow: hidden; } .hbar .fill { height: 100%; background: var(--accent); border-radius: 6px; min-width: 2px; }
.hbar .fill.ok { background: var(--ok); } .hbar .fill.warn { background: var(--warn); } .hbar .fill.red { background: var(--danger); }
.chart { width: 100%; overflow: hidden; } .chart svg { display: block; width: 100%; height: auto; } .legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); margin: 4px 0 0; }
.grid > *, .cols-2 > *, .card, .main, .page { min-width: 0; } .page { overflow-x: hidden; }
.toolbar > .chips { max-width: 100%; }
.toolbar input[type="date"] { flex: 1 1 140px !important; max-width: none !important; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 14px; border-left: 2px solid var(--border); } .timeline li { position: relative; padding: 0 0 12px 14px; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; left: -22px; top: 5px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid var(--surface); }
.timeline li .when { font-size: 12px; color: var(--muted); }
.issue { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; } .issue:last-child { border: 0; }
.health { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--border); } .health:last-child { border: 0; } .health .dot { margin-top: 6px; }
pre.box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; white-space: pre-wrap; word-break: break-word; font-size: 13px; font-family: ui-monospace, Menlo, Consolas, monospace; max-height: 420px; overflow: auto; }

/* ---------- диалоги, уведомления ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10,14,22,.5); z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--surface); width: 100%; max-height: 92vh; border-radius: 18px 18px 0 0; display: flex; flex-direction: column; animation: up .18s ease-out; }
.modal.wide { max-width: 760px; } .modal-h { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); gap: 10px; } .modal-h h3 { flex: 1; }
.modal-b { padding: 16px; overflow: auto; } .modal-f { padding: 12px 16px calc(12px + var(--safe-b)); border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
@keyframes up { from { transform: translateY(30px); opacity: .4; } to { transform: none; opacity: 1; } }
@media (min-width: 640px) { .overlay { align-items: center; } .modal { width: 520px; border-radius: 16px; } .modal.wide { width: 760px; } }
#toasts { position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 90; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: #1f2937; color: #fff; padding: 10px 14px; border-radius: 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25); font-size: 14px; animation: up .15s ease-out; pointer-events: auto; }
.toast.ok { background: #166534; } .toast.err { background: #991b1b; }
.login { max-width: 380px; margin: 0 auto; padding: 8vh 18px 30px; } .login .brand { justify-content: center; font-size: 22px; padding-bottom: 6px; }
.skeleton { background: linear-gradient(90deg, var(--gray-soft), var(--surface-2), var(--gray-soft)); background-size: 200% 100%; animation: sh 1.2s infinite; border-radius: 10px; height: 64px; margin-bottom: 8px; }
@keyframes sh { to { background-position: -200% 0; } }
