/* VibeCRM — мобильная версия. Токены из docs/mobile-ui/MOBILE-UI.md, раздел 2. Без градиентов */
:root {
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f5f6fa;
  --chip: #eef0f6;
  --line: #e6e8f0;
  --line-soft: #eef0f6;
  --text: #171a26;
  --text-2: #4a5068;
  --muted: #6b7186;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-text: #4f46e5;
  --accent-soft: #eef2ff;
  --accent-line: #c7d2fe;
  --accent-ring: #e0e7ff;
  --bubble-in: #ffffff;
  --chat-bg: #eef0f7;
  --danger: #dc2626;
  --danger-text: #b91c1c;
  --danger-soft: #fee2e2;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --ok: #10b981;
  --ok-text: #047857;
  --ok-soft: #ecfdf5;
  --shadow: 0 1px 2px rgba(20, 24, 40, .05), 0 1px 3px rgba(20, 24, 40, .06);
  --shadow-l: 0 -10px 40px rgba(20, 24, 40, .16);
  --r-card: 16px;
  --r-ctl: 14px;
  --tabbar-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d14; --surface: #141824; --surface-2: #1e2433; --chip: #1e2433; --line: #232a3b; --line-soft: #1e2433;
    --text: #e8eaf2; --text-2: #b4b9cc; --muted: #8f95ab;
    --accent-text: #a5b4fc; --accent-soft: rgba(99, 102, 241, .16); --accent-line: rgba(129, 140, 248, .35); --accent-ring: rgba(99, 102, 241, .3);
    --bubble-in: #1c2232; --chat-bg: #0e111a;
    --danger: #fca5a5; --danger-text: #fca5a5; --danger-soft: rgba(239, 68, 68, .16);
    --warn-bg: rgba(245, 158, 11, .18); --warn-text: #fcd34d;
    --ok: #6ee7b7; --ok-text: #6ee7b7; --ok-soft: rgba(16, 185, 129, .16);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-l: 0 -10px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0d14; --surface: #141824; --surface-2: #1e2433; --chip: #1e2433; --line: #232a3b; --line-soft: #1e2433;
  --text: #e8eaf2; --text-2: #b4b9cc; --muted: #8f95ab;
  --accent-text: #a5b4fc; --accent-soft: rgba(99, 102, 241, .16); --accent-line: rgba(129, 140, 248, .35); --accent-ring: rgba(99, 102, 241, .3);
  --bubble-in: #1c2232; --chat-bg: #0e111a;
  --danger: #fca5a5; --danger-text: #fca5a5; --danger-soft: rgba(239, 68, 68, .16);
  --warn-bg: rgba(245, 158, 11, .18); --warn-text: #fcd34d;
  --ok: #6ee7b7; --ok-text: #6ee7b7; --ok-soft: rgba(16, 185, 129, .16);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-l: 0 -10px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

/* ---------- база ---------- */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; overscroll-behavior-y: none; }
a { color: var(--accent-text); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.grow { flex: 1; }
.danger-text { color: var(--danger-text) !important; }
.pad { padding: 4px 16px 20px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
/* Горизонтальные ленты — без полосы прокрутки */
.hscroll { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
.hscroll::-webkit-scrollbar { display: none; }

/* ---------- кнопки ---------- */
.btn {
  min-height: 44px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.primary:active { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: transparent; color: #fff; }
:root[data-theme="dark"] .btn.danger { background: #dc2626; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--accent-text); }
.btn.block { width: 100%; }
.btn.primary.block { height: 52px; border-radius: var(--r-ctl); font-size: 16px; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; border: 0; border-radius: 12px; background: transparent; color: var(--text); cursor: pointer; flex-shrink: 0; }
.icon-btn:active { background: var(--chip); }

/* ---------- каркас ---------- */
.shell { min-height: 100dvh; }
.view { padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 8px); min-height: 100dvh; }
body.detail .view { padding-bottom: var(--safe-b); }
body.detail .tabbar { display: none; }

/* Шапка экрана-вкладки */
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: calc(16px + var(--safe-t)) 16px 10px; }
.top h1 { font-size: 28px; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }

/* Шапка экрана деталей */
.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 4px;
  min-height: calc(56px + var(--safe-t)); padding: var(--safe-t) 6px 0; background: var(--surface); border-bottom: 1px solid var(--line);
}
.bar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bar-title b { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-title span { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Нижняя панель: 56 px + safe-area */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding: 4px 4px var(--safe-b);
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--surface); border-top: 1px solid var(--line);
}
.tabbar a {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: #5b6178; font-size: 11px; font-weight: 500; min-height: 44px;
}
:root[data-theme="dark"] .tabbar a { color: var(--muted); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tabbar a { color: var(--muted); } }
.tabbar a .ico { width: 24px; height: 24px; }
.tabbar a.on { color: var(--accent-text); font-weight: 600; }
.tab-badge {
  position: absolute; top: 2px; left: 50%; margin-left: 6px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: #dc2626; color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}

/* ---------- карточки и списки ---------- */
.card { background: var(--surface); border-radius: var(--r-card); }
.group-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); padding: 0 4px 6px; }
.list { overflow: hidden; }
.list-row { display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 8px 14px; color: var(--text); border-bottom: 1px solid var(--line-soft); }
.list-row:last-child { border-bottom: 0; }
.list-row:active { background: var(--surface-2); }
.list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.list-main b { font-size: 15px; font-weight: 500; }
.list-main span { font-size: 12px; color: var(--text-2); }
.list-row .chev { width: 18px; height: 18px; color: var(--muted); }
.count { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 8px; background: var(--chip); color: var(--text-2); }
.tile { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; }
.tile .ico { width: 18px; height: 18px; }
.tone-indigo { background: #eef2ff; color: #4338ca; }
.tone-teal { background: #ccfbf1; color: #0f766e; }
.tone-amber { background: #fef3c7; color: #92400e; }
.tone-violet { background: #ede9fe; color: #6d28d9; }
.tone-slate { background: #eef0f6; color: #4a5068; }
:root[data-theme="dark"] [class*="tone-"] { background: var(--surface-2); color: var(--accent-text); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) [class*="tone-"] { background: var(--surface-2); color: var(--accent-text); } }

.status-card { padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.status-row { display: flex; align-items: center; gap: 10px; }
.status-row b { flex: 1; font-size: 15px; font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dot.ok { background: #10b981; box-shadow: 0 0 0 4px var(--ok-soft); }
.dot.danger { background: #dc2626; box-shadow: 0 0 0 4px var(--danger-soft); }
.dot.accent { background: #6366f1; box-shadow: 0 0 0 4px var(--accent-soft); }

.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 6px 10px; border-radius: 999px; white-space: nowrap; }
.status-pill i { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.status-pill.ok { color: var(--ok-text); background: var(--ok-soft); }
.status-pill.ok i { background: #10b981; }
.status-pill.warn { color: var(--warn-text); background: var(--warn-bg); }
.status-pill.danger { color: var(--danger-text); background: var(--danger-soft); }

/* Переключатель */
.switch-row { display: flex; align-items: center; gap: 12px; min-height: 54px; padding: 8px 14px; cursor: pointer; }
.switch { appearance: none; width: 50px; height: 30px; border-radius: 15px; background: var(--line); position: relative; cursor: pointer; flex-shrink: 0; transition: background .2s; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); transition: transform .2s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

/* Аватар — сплошной цвет, как в десктопе */
.avatar { width: 48px; height: 48px; border-radius: 50%; background: hsl(var(--h, 235) 60% 52%); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 16px; flex-shrink: 0; }

/* Пустое состояние */
.empty { text-align: center; padding: 56px 24px; color: var(--text-2); }
.empty-ico { width: 40px; height: 40px; color: var(--muted); }
.empty h3 { margin: 14px 0 6px; font-size: 17px; font-weight: 600; color: var(--text); }
.empty p { margin: 0 auto; max-width: 300px; font-size: 14px; }

/* ---------- шторка ---------- */
.sheet-back { position: fixed; inset: 0; z-index: 50; background: rgba(10, 12, 20, 0); transition: background .2s; display: flex; align-items: flex-end; }
.sheet-back.in { background: rgba(10, 12, 20, .45); }
.sheet-back.out { background: rgba(10, 12, 20, 0); }
.sheet {
  width: 100%; max-height: 85dvh; display: flex; flex-direction: column; background: var(--surface); color: var(--text);
  border-radius: 20px 20px 0 0; box-shadow: var(--shadow-l); padding-bottom: var(--safe-b);
  transform: translateY(100%); transition: transform .22s cubic-bezier(.2, .8, .2, 1);
}
.sheet.tall { height: 85dvh; }
.sheet-back.in .sheet { transform: none; }
.sheet-back.out .sheet { transform: translateY(100%); }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 8px auto 2px; flex-shrink: 0; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 4px 16px; }
.sheet-head h2 { font-size: 18px; font-weight: 700; }
.sheet-body { overflow-y: auto; padding: 4px 16px 16px; overscroll-behavior: contain; }
.sheet-actions { display: flex; gap: 10px; margin-top: 12px; }
.sheet-actions .btn { flex: 1; }
.ask-text { margin: 12px 0 4px; font-size: 16px; line-height: 1.4; }

/* ---------- уведомления ---------- */
.toasts { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 12px); z-index: 60; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
body.detail .toasts { bottom: calc(var(--safe-b) + 84px); }
.toast { padding: 12px 14px; border-radius: 12px; background: #171a26; color: #fff; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); transition: opacity .3s, transform .3s; }
.toast.error { background: #b91c1c; }
.toast.warn { background: #92400e; }
.toast.ok { background: #047857; }
.toast.out { opacity: 0; transform: translateY(8px); }
.offline { position: fixed; top: 0; left: 0; right: 0; z-index: 40; padding: calc(6px + var(--safe-t)) 16px 6px; background: var(--warn-bg); color: var(--warn-text); font-size: 13px; text-align: center; }

/* ---------- экран PIN ---------- */
.pin {
  min-height: 100dvh; display: flex; flex-direction: column; background: var(--surface);
  padding: calc(40px + var(--safe-t)) 24px calc(24px + var(--safe-b)); max-width: 480px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { width: 44px; height: 44px; border-radius: 14px; }
.brand b { font-size: 17px; font-weight: 700; display: block; }
.brand span { font-size: 13px; color: var(--text-2); }
.pin h1 { margin: 32px 0 0; font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.pin p.lead { margin: 8px 0 0; color: var(--text-2); }
.pin-field { margin-top: 24px; position: relative; }
.login-field { width: 100%; height: 56px; margin-top: 24px; border: 1.5px solid var(--line); border-radius: var(--r-ctl); background: var(--surface-2); color: var(--text); font: 500 18px var(--font); padding: 0 16px; outline: none; }
.login-field:focus { border: 2px solid var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); background: var(--surface); }
.login-field + .pin-field { margin-top: 12px; }
.pin-field + .pin-field { margin-top: 12px; }
.field-hint { margin: 6px 2px 0; font-size: 13px; color: var(--muted); }
.field-hint + .pin-field { margin-top: 12px; }
.pin-field input.with-ph::placeholder { letter-spacing: normal; font-size: 18px; font-weight: 500; }
.pin-field input {
  width: 100%; height: 60px; border: 1.5px solid var(--line); border-radius: var(--r-ctl); background: var(--surface-2);
  color: var(--text); font: 600 24px var(--font); letter-spacing: .3em; text-align: center; outline: none;
}
.pin-field input:focus { border: 2px solid var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); background: var(--surface); }
.pin-field input.bad { border-color: var(--danger); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.pin-toggle { position: absolute; right: 6px; top: 8px; width: 44px; height: 44px; border: 0; background: none; color: var(--muted); display: grid; place-items: center; cursor: pointer; }
.pin-error { min-height: 22px; margin-top: 10px; color: var(--danger-text); font-size: 14px; }
/* Компьютер и планшет: вход — карточкой по центру окна, а не колонкой во всю высоту, как на телефоне */
@media (min-width: 720px) and (min-height: 560px) {
  .pin {
    min-height: 0; margin: max(24px, calc((100dvh - 780px) / 2)) auto 24px; padding: 40px 40px 32px;
    max-width: 440px; border: 1px solid var(--line); border-radius: 24px; box-shadow: 0 24px 64px rgba(0, 0, 0, .18);
  }
  .pin .grow { flex: none; height: 24px; }
}
.note { display: flex; gap: 10px; align-items: flex-start; background: var(--surface-2); border-radius: var(--r-ctl); padding: 12px 14px; margin-bottom: 16px; }
.note p { margin: 0; font-size: 13px; line-height: 1.4; color: var(--text-2); }
.note .ico { color: var(--text-2); }

/* Планшет: держим ширину телефона по центру */
.nav-brand { display: none; }
@media (min-width: 600px) and (max-width: 1023.98px) {
  .shell, .pin { max-width: 520px; margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .tabbar { max-width: 520px; margin: 0 auto; }
  .sheet { max-width: 520px; margin: 0 auto; }
}
/* Компьютер: меню слева, контент шире, шторки — окнами по центру, чаты — список и диалог рядом */
@media (min-width: 1024px) {
  :root { --nav-w: 232px; }
  .tabbar, body.detail .tabbar {
    display: flex; flex-direction: column; gap: 2px; top: 0; right: auto; width: var(--nav-w); height: auto;
    padding: 16px 12px; border-top: 0; border-right: 1px solid var(--line);
  }
  .nav-brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
  .nav-brand img { width: 32px; height: 32px; border-radius: 10px; }
  .nav-brand b { font-size: 16px; font-weight: 700; }
  .tabbar a { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 0 12px; min-height: 42px; border-radius: 10px; font-size: 14px; }
  .tabbar a:hover { background: var(--surface-2); }
  .tabbar a.on { background: var(--accent-soft); }
  .tabbar a .ico { width: 20px; height: 20px; }
  .tab-badge { position: static; margin-left: auto; }
  .shell { margin-left: var(--nav-w); }
  .view:not(.split) { max-width: 1040px; margin: 0 auto; padding-bottom: 32px; }
  .top { padding-top: 24px; }
  .fab { right: 32px; bottom: 32px; }
  .sel-bar, .bc-foot { left: var(--nav-w); }
  .bc-foot { padding-left: max(16px, calc((100vw - var(--nav-w) - 1040px) / 2 + 16px)); padding-right: max(16px, calc((100vw - var(--nav-w) - 1040px) / 2 + 16px)); }
  .toasts, body.detail .toasts { left: auto; right: 24px; bottom: 24px; width: 380px; }
  .sheet-back { align-items: center; justify-content: center; }
  .sheet { max-width: 560px; border-radius: 20px; padding-bottom: 8px; transform: translateY(24px); opacity: 0; transition: transform .18s, opacity .18s; }
  .sheet-back.in .sheet { transform: none; opacity: 1; }
  .sheet-back.out .sheet { transform: translateY(24px); opacity: 0; }
  .sheet.tall { height: min(85dvh, 780px); }
  .sheet-grip { display: none; }
  .sheet-head { padding-top: 12px; }
  .chat-row:hover, .list-row:hover, .ccard:hover { background: var(--surface-2); }
  /* Чаты в две колонки */
  .view.split { max-width: none; padding: 0; display: flex; height: 100dvh; min-height: 0; }
  .pane-list { width: 380px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--line); background: var(--surface); }
  .pane-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .pane-main > .empty { margin: auto; }
  .pane-main .chat-screen { height: 100dvh; }
  .pane-main .chat-bar [data-back="/chats"] { display: none; }
  .pane-main .chat-bar { padding-left: 12px; }
  .chat-row.on { background: var(--accent-soft); }
  .bubble { max-width: min(70%, 560px); }
}

/* ================= ЧАТЫ ================= */
.list-tools { padding: 0 16px 8px; display: flex; flex-direction: column; gap: 10px; }
.search { position: relative; display: flex; align-items: center; }
.search .ico { position: absolute; left: 12px; width: 18px; height: 18px; color: var(--muted); pointer-events: none; }
.search input { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); padding: 0 12px 0 40px; font-size: 15px; outline: none; -webkit-appearance: none; }
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); }
.chips { padding-top: 2px; }
.chip { flex-shrink: 0; height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.chip b { font-weight: 700; }
.chip b.accent { color: var(--accent-text); }
.chip b.danger { color: var(--danger); }
.chip b.warn { color: #b45309; }
:root[data-theme="dark"] .chip b.warn { color: var(--warn-text); }
.chip.on { background: var(--text); border-color: var(--text); color: var(--surface); font-weight: 600; }
.chip.on b { color: inherit; }
:root[data-theme="dark"] .chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .chip.on { background: var(--accent); border-color: var(--accent); color: #fff; } }
.chip-ico { width: 14px; height: 14px; }

.chat-list { background: var(--surface); border-top: 1px solid var(--line-soft); }
.chat-row { display: flex; gap: 12px; padding: 10px 16px 0; min-height: 76px; color: var(--text); align-items: flex-start; }
.chat-row:active { background: var(--surface-2); }
.chat-row .avatar { width: 50px; height: 50px; font-size: 17px; margin-top: 2px; }
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; padding-bottom: 10px; border-bottom: 1px solid var(--line-soft); }
.chat-line { display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-line b { flex: 1; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-line time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.chat-text { flex: 1; font-size: 14px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; display: grid; place-items: center; flex-shrink: 0; }
.chat-tags { display: flex; gap: 6px; margin-top: 2px; flex-wrap: wrap; }
.tag { font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 6px; background: var(--chip); color: var(--text-2); white-space: nowrap; }
.tag.flag-wait { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.tag.flag-urgent, .tag.flag-late { background: var(--danger-soft); color: var(--danger-text); font-weight: 600; }
.tag.flag-silent { background: var(--warn-bg); color: var(--warn-text); font-weight: 600; }
.loading { padding: 32px 16px; text-align: center; color: var(--muted); }

/* Выбор из списка (стадии, шаблоны) */
.option-list { display: flex; flex-direction: column; gap: 6px; }
.option { min-height: 48px; display: flex; align-items: center; gap: 12px; padding: 0 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); text-align: left; font-size: 15px; cursor: pointer; }
.option .ico { margin-left: auto; color: var(--accent-text); }
.option.on { border-color: var(--accent-line); background: var(--accent-soft); font-weight: 600; }
.stage-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.stage-dot.s0 { background: #8a90a6; } .stage-dot.s1 { background: #3b82f6; } .stage-dot.s2 { background: #8b5cf6; }
.stage-dot.s3 { background: #0891b2; } .stage-dot.s4 { background: #f59e0b; } .stage-dot.s5 { background: #f97316; }
.stage-dot.s6 { background: #10b981; } .stage-dot.s7 { background: #0d9488; } .stage-dot.s8 { background: #ef4444; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--chip); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.seg button { height: 38px; border: 0; border-radius: 10px; background: transparent; color: var(--text-2); font-size: 14px; font-weight: 500; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.tpl { display: flex; flex-direction: column; gap: 3px; text-align: left; padding: 12px 14px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); cursor: pointer; }
.tpl b { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 6px; }
.tpl span { font-size: 13px; color: var(--text-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ico.tiny { width: 14px; height: 14px; }

/* ================= ДИАЛОГ ================= */
.chat-screen { height: 100dvh; display: flex; flex-direction: column; background: var(--chat-bg); }
body.detail .view:has(.chat-screen) { padding-bottom: 0; }
.chat-head { flex-shrink: 0; background: var(--surface); border-bottom: 1px solid var(--line); padding-top: var(--safe-t); }
.chat-bar { height: 60px; display: flex; align-items: center; gap: 4px; padding: 0 8px; }
.chat-who { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; color: var(--text); min-height: 44px; }
.avatar.sm { width: 38px; height: 38px; font-size: 14px; }
.who-text { display: flex; flex-direction: column; min-width: 0; }
.who-text > b { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who-sub { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-link { border: 0; background: none; padding: 0; color: var(--accent-text); font-size: 12px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 2px; min-height: 24px; }
.btn.analyze { height: 40px; min-height: 40px; padding: 0 12px; font-size: 14px; gap: 6px; }
.btn.analyze .ico { width: 18px; height: 18px; }
.next-step { width: 100%; display: flex; align-items: center; gap: 8px; padding: 8px 16px; min-height: 36px; border: 0; background: var(--accent-soft); color: #312e81; font-size: 13px; text-align: left; cursor: pointer; }
:root[data-theme="dark"] .next-step { color: var(--accent-text); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .next-step { color: var(--accent-text); } }
.next-step .ico { width: 16px; height: 16px; }
.next-step span { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.messages { flex: 1; overflow-y: auto; padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 6px; overscroll-behavior: contain; }
.messages > :first-child { margin-top: auto; }
.day-sep { align-self: center; font-size: 12px; font-weight: 500; color: var(--text-2); background: var(--surface); background: color-mix(in srgb, var(--surface) 80%, transparent); padding: 3px 10px; border-radius: 999px; margin: 6px 0; }
.msg { display: flex; }
.msg.out { justify-content: flex-end; }
.bubble { max-width: 78%; padding: 9px 12px; border-radius: 18px 18px 18px 6px; background: var(--bubble-in); font-size: 15px; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; }
.msg.out .bubble { background: var(--accent); color: #fff; border-radius: 18px 18px 6px 18px; }
.bubble time { font-size: 11px; color: var(--muted); margin-left: 8px; float: right; margin-top: 6px; white-space: nowrap; }
.msg.out .bubble time { color: rgba(255, 255, 255, .8); }
.bubble .auto { font-size: 11px; opacity: .8; clear: both; }
.voice { display: flex; align-items: center; gap: 10px; min-width: 190px; }
.voice-play { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; flex-shrink: 0; }
.msg.out .voice-play { background: rgba(255, 255, 255, .22); }
.voice-play .ico { width: 16px; height: 16px; fill: currentColor; stroke: none; margin-left: 2px; }
.voice-info { display: flex; flex-direction: column; font-size: 14px; }
.voice-info span { font-size: 12px; opacity: .8; }
.voice audio { width: min(240px, 60vw); height: 40px; }
.voice.loading { opacity: .6; }
.video-note { width: 200px; height: 200px; border-radius: 50%; object-fit: cover; }
.file-msg { display: flex; align-items: center; gap: 10px; }
.file-msg > span:last-child { display: flex; flex-direction: column; font-size: 14px; }
.file-msg > span:last-child span { font-size: 12px; opacity: .85; }
.file-ico { width: 36px; height: 36px; border-radius: 10px; background: var(--chip); display: grid; place-items: center; flex-shrink: 0; }
.msg.out .file-ico { background: rgba(255, 255, 255, .18); }
.small-empty { padding: 32px 16px; }

.rem-suggest { margin-top: 6px; background: var(--surface); border: 1px solid #fde68a; border-radius: 14px; padding: 8px 6px 8px 12px; display: flex; align-items: center; gap: 10px; }
:root[data-theme="dark"] .rem-suggest { border-color: rgba(245, 158, 11, .35); }
.rem-ico { width: 32px; height: 32px; border-radius: 10px; background: var(--warn-bg); color: var(--warn-text); display: grid; place-items: center; flex-shrink: 0; }
.rem-ico .ico { width: 18px; height: 18px; }
.rem-text { flex: 1; font-size: 13px; line-height: 1.35; display: flex; flex-direction: column; }
.rem-text > span:not(.rem-main) { font-size: 12px; color: var(--muted); }
.rem-main b { font-weight: 600; }
.btn.small { min-height: 36px; height: 36px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.btn.dark { background: var(--text); color: var(--surface); border-color: transparent; }

.composer-wrap { flex-shrink: 0; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.hints { padding-top: 10px; }
.hints-head { display: flex; align-items: center; gap: 6px; padding: 0 16px 6px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.hints-head .ico { width: 14px; height: 14px; color: var(--accent-text); }
.hints-head span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hint-strip { margin: 0; padding: 0 16px 10px; }
.hint { flex-shrink: 0; width: 230px; min-height: 52px; text-align: left; padding: 8px 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text); font-size: 13px; line-height: 1.35; cursor: pointer; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.hint.best, .hint.ai { border-color: var(--accent-line); background: var(--accent-soft); }
.hint:active { transform: scale(.98); }
.composer { display: flex; align-items: flex-end; gap: 8px; padding: 6px 10px 10px; }
.composer textarea { flex: 1; min-height: 44px; max-height: 140px; resize: none; border: 1px solid var(--line); border-radius: 22px; background: var(--surface-2); padding: 11px 16px; font-size: 15px; line-height: 1.4; outline: none; }
.composer textarea:focus { border-color: var(--accent); background: var(--surface); }
.round-btn { width: 44px; height: 44px; flex-shrink: 0; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); color: var(--text-2); display: grid; place-items: center; cursor: pointer; }
.round-btn.send { border: 0; background: var(--accent); color: #fff; }
.round-btn.send:disabled { opacity: .55; }

/* ================= AI-ПОДСКАЗКИ ================= */
.ai-head { display: flex; align-items: center; gap: 10px; padding: 0 0 12px; }
.ai-head h2 { font-size: 18px; font-weight: 700; }
.ai-badge { width: 34px; height: 34px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); display: grid; place-items: center; flex-shrink: 0; }
.ai-content { display: flex; flex-direction: column; gap: 14px; }
.ai-content section p { margin: 0; font-size: 15px; line-height: 1.45; }
.ai-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.ai-cell { background: var(--surface-2); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; }
.ai-cell span { font-size: 12px; color: var(--text-2); }
.ai-cell b { font-size: 15px; font-weight: 600; margin-top: 2px; }
.link { border: 0; background: none; padding: 4px 0 0; color: var(--accent-text); font-size: 13px; font-weight: 600; text-align: left; cursor: pointer; }
.label { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); margin-bottom: 6px; }
.label.accent { color: var(--accent-text); }
.next-card { border: 1px solid var(--accent-line); background: var(--accent-soft); border-radius: 16px; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.reply { display: block; width: 100%; text-align: left; border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; background: var(--surface); font-size: 14px; line-height: 1.4; cursor: pointer; }
.reply:active { background: var(--accent-soft); }
.product { display: flex; justify-content: space-between; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line-soft); font-size: 14px; }
.risk { display: flex; gap: 10px; align-items: flex-start; background: #fff7ed; color: #7c2d12; border-radius: 14px; padding: 10px 12px; }
:root[data-theme="dark"] .risk { background: rgba(249, 115, 22, .14); color: #fdba74; }
.risk .ico { width: 18px; height: 18px; margin-top: 1px; }
.risk p { margin: 0; font-size: 13px; line-height: 1.4; }
.ai-busy { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 14px; color: var(--text-2); }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--accent-line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.browser-mode { display: flex; flex-direction: column; gap: 10px; }
.browser-mode textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); padding: 10px 12px; font-size: 14px; resize: vertical; outline: none; }
.row-btns { display: flex; gap: 8px; }
.row-btns .btn { flex: 1; }
/* ================= КЛИЕНТЫ ================= */
.clients-top { gap: 2px; }
.clients-top h1 { flex: 1; }
.search-row { display: flex; gap: 8px; }
.search-row .search { flex: 1; }
.square-btn { width: 44px; height: 44px; flex-shrink: 0; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); display: grid; place-items: center; cursor: pointer; }
.seg button span { opacity: .75; font-weight: 500; }
.cards { padding: 4px 16px 96px; display: flex; flex-direction: column; gap: 8px; }
.list-hint { margin: 0; padding: 0 2px; font-size: 12px; color: var(--text-2); }
.ccard { display: flex; flex-direction: column; gap: 8px; background: var(--surface); border-radius: 16px; padding: 12px 14px; color: var(--text); box-shadow: var(--shadow); border: 1.5px solid transparent; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.ccard:active { background: var(--surface-2); }
.ccard.sel { border-color: var(--accent); background: var(--accent-soft); }
.ccard.dim { opacity: .55; }
.ccard-row { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar.md { width: 40px; height: 40px; font-size: 14px; }
.avatar.xl { width: 68px; height: 68px; font-size: 24px; }
.avatar.xs { width: 28px; height: 28px; font-size: 11px; }
.ccard-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ccard-main b { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ccard-main span { font-size: 13px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sum { font-size: 15px; font-weight: 600; white-space: nowrap; }
.small-row { font-size: 13px; }
.stage-pill { flex-shrink: 0; min-height: 32px; padding: 4px 10px; border-radius: 8px; border: 0; font-size: 12px; font-weight: 600; cursor: pointer; background: var(--chip); color: var(--text-2); }
.stage-pill.s1 { background: #dbeafe; color: #1d4ed8; } .stage-pill.s2 { background: #ede9fe; color: #6d28d9; }
.stage-pill.s3 { background: #cffafe; color: #0e7490; } .stage-pill.s4 { background: #fef3c7; color: #92400e; }
.stage-pill.s5 { background: #ffedd5; color: #c2410c; } .stage-pill.s6 { background: #d1fae5; color: #047857; }
.stage-pill.s7 { background: #ccfbf1; color: #0f766e; } .stage-pill.s8 { background: #fee2e2; color: #b91c1c; }
:root[data-theme="dark"] .stage-pill { background: var(--surface-2) !important; color: var(--accent-text) !important; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .stage-pill { background: var(--surface-2) !important; color: var(--accent-text) !important; } }
.ccard-next { flex: 1; min-width: 0; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ccard-next.late { color: var(--danger-text); font-weight: 600; }
.check { width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--line); display: grid; place-items: center; flex-shrink: 0; }
.check.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.check .ico { width: 14px; height: 14px; stroke-width: 3; }
.fab { position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px); z-index: 9; width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; box-shadow: 0 8px 20px rgba(79, 70, 229, .35); cursor: pointer; }
.fab .ico { width: 26px; height: 26px; }
body.selecting .tabbar { display: none; }
.sel-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; background: var(--surface); border-top: 1px solid var(--line); box-shadow: var(--shadow-l); padding: 4px 8px calc(8px + var(--safe-b)); }
.sel-head { display: flex; align-items: center; gap: 6px; }
.sel-head b { flex: 1; }
.sel-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
.sel-actions button { min-height: 56px; border: 0; border-radius: 12px; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-size: 12px; font-weight: 600; color: var(--text); cursor: pointer; }
.sel-actions button:active { background: var(--chip); }
.sel-actions button:disabled { opacity: .4; }
.card-line { margin-top: 12px; border: 1px solid var(--line); border-radius: 14px; }
.option:disabled { opacity: .55; }
.option > .ico:first-child { margin-left: 0; color: var(--text-2); }
.opt-text { display: flex; flex-direction: column; padding: 8px 0; }
.opt-text b { font-size: 15px; font-weight: 600; }
.opt-text span { font-size: 12px; color: var(--text-2); }

/* Формы в шторках */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 500; color: var(--text-2); }
.form input, .form select, .form textarea, .picker {
  width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2);
  padding: 10px 12px; font-size: 16px; color: var(--text); outline: none; -webkit-appearance: none;
}
.form input:focus, .form select:focus, .form textarea:focus { border-color: var(--accent); background: var(--surface); }
.picker { display: flex; align-items: center; justify-content: space-between; text-align: left; cursor: pointer; }
.quick-times { display: flex; gap: 6px; flex-wrap: wrap; margin-top: -4px; }
.quick-times button { min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; cursor: pointer; }
.pick-list { margin-top: 10px; }
.pick-list .option { gap: 10px; }

/* ================= КАРТОЧКА КЛИЕНТА ================= */
.card-screen { min-height: 100dvh; padding-bottom: calc(16px + var(--safe-b)); }
.center-title { align-items: center; }
.hero { background: var(--surface); padding: 8px 16px 16px; display: flex; flex-direction: column; align-items: center; gap: 4px; text-align: center; }
.hero h1 { margin-top: 6px; font-size: 21px; font-weight: 700; }
.hero p { margin: 0; font-size: 14px; color: var(--text-2); }
.quick { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; width: 100%; margin-top: 14px; }
.quick > * { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 0; min-height: 60px; border-radius: 14px; border: 0; font-size: 12px; font-weight: 600; cursor: pointer; }
.quick > :disabled { opacity: .45; }
.q-indigo { background: #eef2ff; color: #3730a3; } .q-green { background: #ecfdf5; color: #065f46; }
.q-amber { background: #fef3c7; color: #78350f; } .q-violet { background: #f3e8ff; color: #6b21a8; }
:root[data-theme="dark"] .quick > * { background: var(--surface-2); color: var(--accent-text); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .quick > * { background: var(--surface-2); color: var(--accent-text); } }
.block { background: var(--surface); padding: 14px 16px; margin-top: 12px; }
.block.lost { background: var(--danger-soft); color: var(--danger-text); font-size: 14px; display: flex; align-items: center; gap: 8px; }
.block-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.block-head .label { margin: 0; display: flex; align-items: center; gap: 6px; }
.stepper { gap: 6px; }
.step { flex-shrink: 0; height: 36px; padding: 0 12px; border-radius: 10px; border: 1px dashed #c3c7d6; background: var(--surface); color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer; }
.step.done { border: 0; background: #e0e7ff; color: #3730a3; }
.step.now { border: 0; background: var(--accent); color: #fff; font-weight: 600; }
:root[data-theme="dark"] .step.done { background: var(--accent-soft); color: var(--accent-text); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .step.done { background: var(--accent-soft); color: var(--accent-text); } }
.fields { padding-top: 4px; padding-bottom: 4px; }
.field { display: flex; align-items: center; min-height: 52px; gap: 12px; border-bottom: 1px solid var(--line-soft); font-size: 14px; color: var(--text-2); }
.field:last-of-type { border-bottom: 0; }
.field > span { width: 120px; flex-shrink: 0; }
.field input, .field select { flex: 1; min-width: 0; border: 0; background: transparent; font-size: 15px; font-weight: 500; color: var(--text); text-align: right; outline: none; min-height: 44px; }
.field.col { flex-direction: column; align-items: stretch; gap: 4px; padding: 12px 0; }
.field.col textarea { border: 0; resize: none; background: transparent; padding: 0; font-size: 15px; line-height: 1.4; color: var(--text); outline: none; min-height: 44px; }
.saved { margin: 0 0 8px; color: var(--ok-text); }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.facts div { background: var(--surface-2); border-radius: 12px; padding: 8px 10px; display: flex; flex-direction: column; }
.facts b { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.facts span { font-size: 12px; color: var(--text-2); }
.mini-rem { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line-soft); font-size: 14px; }
.mini-rem > span { flex: 1; }
.mini-rem.late b { color: var(--danger-text); }

/* ================= РАССЫЛКА ================= */
.bc-screen { min-height: 100dvh; display: flex; flex-direction: column; }
.bc-body { flex: 1; padding: 16px 16px 140px; display: flex; flex-direction: column; gap: 16px; }
.bc-foot { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--surface); border-top: 1px solid var(--line); padding: 12px 16px calc(12px + var(--safe-b)); }
.aud-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.aud { min-height: 60px; text-align: left; padding: 10px 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 600; display: flex; flex-direction: column; gap: 2px; cursor: pointer; }
.aud span { font-size: 12px; font-weight: 500; color: var(--text-2); }
.aud.on { border: 2px solid var(--accent); background: var(--accent-soft); }
.aud:disabled { opacity: .55; }
.stage-multi { margin-top: 10px; }
.msg-card { padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.msg-card textarea { width: 100%; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); padding: 10px 12px; font-size: 16px; line-height: 1.4; resize: vertical; outline: none; }
.mini-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.mini-btns button { min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; cursor: pointer; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview { background: var(--chat-bg); border-radius: 16px; padding: 12px; display: flex; justify-content: flex-end; }
.bubble-out { max-width: 85%; background: var(--accent); color: #fff; border-radius: 18px 18px 6px 18px; padding: 9px 12px; font-size: 15px; line-height: 1.4; white-space: pre-wrap; }
.pv-file { margin-top: 6px; font-size: 13px; opacity: .9; display: flex; align-items: center; gap: 4px; }
.eta { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 13px; color: var(--text-2); }
.warn-note { margin: 0; font-size: 12px; color: var(--warn-text); background: var(--warn-bg); border-radius: 12px; padding: 8px 12px; }
.bc-progress { display: flex; flex-direction: column; gap: 6px; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.progress { height: 8px; background: var(--chip); border-radius: 6px; overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--accent); border-radius: 6px; transition: width .3s; }

/* ================= ДЕЛА ================= */
.round-btn.add { border: 0; background: var(--accent); color: #fff; }
.stack-s { display: flex; flex-direction: column; gap: 8px; }
.group-line { display: flex; align-items: center; gap: 8px; padding: 12px 2px 2px; font-size: 13px; }
.group-line b { font-weight: 700; }
.group-line span { font-size: 12px; color: var(--text-2); }
.group-line.late b { color: var(--danger-text); } .group-line.today b { color: var(--accent-text); }
.rem-card { background: var(--surface); border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow); transition: opacity .2s; }
.rem-card.leaving { opacity: .4; }
.rem-top { display: flex; gap: 12px; align-items: flex-start; cursor: pointer; }
.kind { width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0; font-size: 13px; font-weight: 700; }
.rem-who { display: flex; gap: 8px; align-items: baseline; }
.rem-who b { flex: 1; font-weight: 600; font-size: 15px; }
.rem-time { font-size: 13px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.rem-time.late { color: var(--danger-text); } .rem-time.today { color: var(--accent-text); }
.rem-what { font-size: 14px; color: var(--text-2); margin-top: 2px; }
.rem-acts { display: flex; gap: 8px; }
.rem-acts .grow { flex: 1; }
.btn.icon-only { width: 44px; padding: 0; }
.btn.soft { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }

/* ================= СТАТИСТИКА ================= */
.kpi-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.kpi { background: var(--surface); border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; }
.kpi span { font-size: 13px; color: var(--text-2); }
.kpi b { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; }
.kpi em { font-style: normal; font-size: 12px; font-weight: 600; color: var(--muted); min-height: 16px; }
.kpi em.up { color: var(--ok-text); } .kpi em.down { color: var(--danger-text); }
.pad-card { padding: 14px; }
.pad-card h2 { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.funnel { display: flex; flex-direction: column; gap: 7px; }
.f-row { display: grid; grid-template-columns: 112px 1fr 28px; align-items: center; gap: 8px; font-size: 13px; }
.f-row > span:first-child { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.f-row b { text-align: right; font-weight: 600; }
.f-track { height: 12px; background: var(--chip); border-radius: 6px; overflow: hidden; }
.f-bar { display: block; height: 100%; background: #6366f1; border-radius: 6px; }
.f-bar.s8 { background: #ef4444; }
.cold-row { display: flex; align-items: center; gap: 10px; min-height: 48px; border-top: 1px solid var(--line-soft); font-size: 14px; }

/* ================= ЕЩЁ: разделы ================= */
.wrap { white-space: normal !important; }
.tpl-row { width: 100%; border: 0; background: none; text-align: left; cursor: pointer; }
.tpl-row .list-main span { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.switch-line { cursor: pointer; }
.rule-reply { margin-top: 4px; color: var(--muted) !important; }
.kb-text { white-space: pre-wrap; font-size: 14px; line-height: 1.5; max-height: 65dvh; overflow-y: auto; }
.check-box { width: 22px; height: 22px; accent-color: var(--accent); flex-shrink: 0; margin: 0; }
.sticky-act { position: sticky; bottom: calc(var(--safe-b) + 8px); }
.form-card { padding: 0 14px; }
.tip .list-main span { margin-top: 2px; }
.kb-edit { width: 100%; min-height: 55dvh; border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--surface); color: var(--text); padding: 12px 14px; font: 14px/1.5 var(--font); resize: vertical; outline: none; }
.kb-edit:focus, .plain-area:focus { border-color: var(--accent); }
.plain-area { width: 100%; border: 0; background: transparent; color: var(--text); padding: 12px 0; font: 15px/1.45 var(--font); resize: vertical; outline: none; }
.pad-s { padding: 10px 0; margin: 0; }
.ellipsis-r { flex: 1; min-width: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-weight: 500; }
.field .btn { margin-left: auto; }
.field .push-acts { margin-left: auto; display: flex; gap: 8px; }
.field .push-acts .btn { margin-left: 0; }
.form label.switch-row { flex-direction: row; padding: 8px 14px; color: var(--text); font-size: 15px; }
.form input.switch { width: 50px; min-height: 0; height: 30px; padding: 0; border: 0; border-radius: 15px; background: var(--line); }
.form input.switch:checked { background: var(--accent); }

/* ================= Telegram: вход и выбор чатов ================= */
.tg-screen {
  min-height: 100dvh; display: flex; flex-direction: column; background: var(--surface);
  padding: calc(24px + var(--safe-t)) 24px calc(24px + var(--safe-b)); max-width: 480px; margin: 0 auto;
}
.tg-screen .brand .icon-btn { margin-left: auto; }
.tg-screen h1 { margin: 24px 0 0; font-size: 26px; font-weight: 700; letter-spacing: -.02em; line-height: 1.2; }
.tg-screen .lead { margin: 8px 0 0; color: var(--text-2); font-size: 15px; line-height: 1.45; }
.tg-screen .lead a { color: var(--accent-text); }
.tg-screen > .btn.block { margin-top: 10px; }
.tg-steps { list-style: none; display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 24px 0 0; padding: 0; }
.tg-steps li { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 6px; }
.tg-steps li span { height: 4px; border-radius: 2px; background: var(--line); }
.tg-steps li.done span, .tg-steps li.now span { background: var(--accent); }
.tg-steps li.now { color: var(--text); font-weight: 600; }
.tg-steps li.done { color: var(--accent-text); }
.tg-form { margin-top: 20px; }
.tg-form > input, .tg-form label input {
  width: 100%; height: 60px; border: 1.5px solid var(--line); border-radius: var(--r-ctl); background: var(--surface-2);
  color: var(--text); font: 500 18px var(--font); padding: 0 16px; outline: none;
}
.tg-form label input { height: 52px; font-size: 16px; }
.tg-form input:focus { border: 2px solid var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); background: var(--surface); }
.tg-form .code-input { font-size: 24px; font-weight: 600; letter-spacing: .3em; text-align: center; }
.tg-screen .btn.primary { min-height: 52px; font-size: 16px; }
.tg-screen .note { margin: 16px 0 6px; }
.tg-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 12px; }
.btn-link { border: 0; background: none; color: var(--accent-text); font: 500 14px var(--font); padding: 10px 0; cursor: pointer; text-align: left; align-self: flex-start; }
.btn-link:disabled { color: var(--muted); cursor: default; }
.btn-link.block { align-self: stretch; width: 100%; text-align: center; min-height: 44px; }
.qr-box { margin: 20px auto 12px; width: min(260px, 100%); aspect-ratio: 1; border-radius: 16px; background: #fff; padding: 12px; display: grid; place-items: center; border: 1px solid var(--line); }
.qr-box svg { width: 100%; height: 100%; }

/* Профиль и команда */
.profile-card { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
.profile-card .list-main { min-width: 0; }
.profile-card .btn { flex-shrink: 0; }
.tile.letter { font-weight: 700; font-size: 15px; }
button.member-row { width: 100%; border: 0; background: none; text-align: left; font: inherit; cursor: pointer; }
.link-field { width: 100%; height: 44px; border: 1px solid var(--line); border-radius: var(--r-ctl); background: var(--surface-2); color: var(--text); font: 13px var(--font); padding: 0 12px; text-overflow: ellipsis; }
.state-line { display: inline-flex; align-items: center; gap: 6px; }
.state-line .dot { width: 8px; height: 8px; box-shadow: none; }
.dot.warn { background: #d97706; }
.dot.muted { background: var(--muted); }
.qr-left { min-height: 20px; font-variant-numeric: tabular-nums; }
.qr-box .loading { color: #64748b; }
.tg-done { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 48px 0 32px; }
.tg-done h1 { margin-top: 20px; }
.dot.big { width: 18px; height: 18px; box-shadow: 0 0 0 8px var(--ok-soft); }
.pick-screen { padding-bottom: calc(140px + var(--safe-b)); }
.pick-rows { margin: 0 16px; }
.pick-rows .list-row { cursor: pointer; }
.pick-rows .list-main span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* ================= Настоящие телефоны ================= */
/* iPhone приближает страницу при фокусе на поле со шрифтом меньше 16 px — на сенсорных экранах держим 16 */
@media (pointer: coarse) {
  .search input, .composer textarea, .browser-mode textarea, .field input, .field select, .field.col textarea { font-size: 16px; }
}
/* Браузеры без dvh (iOS < 15.4, старый Android) — обычная высота окна */
@supports not (height: 100dvh) {
  .shell, .view, .pin, .tg-screen, .card-screen, .bc-screen { min-height: 100vh; }
  .chat-screen { height: 100vh; }
  .sheet { max-height: 85vh; }
  .sheet.tall { height: 85vh; }
  .kb-text { max-height: 65vh; }
}
/* Без :has() (старые браузеры) у диалога остаётся нижний отступ — он не мешает, просто пустое место */
/* Установленное приложение (с главного экрана): отступ под «чёлку» уже учтён через safe-area */
@media (display-mode: standalone) {
  body { -webkit-user-select: none; user-select: none; }
  input, textarea, .bubble, .kb-text, .rem-what, .ai-content p { -webkit-user-select: text; user-select: text; }
}
/* Мелкие текстовые кнопки (стадия в шапке чата, «+ Добавить») — зона нажатия больше, чем видимый текст */
.stage-link, .link { position: relative; }
.stage-link::after, .link::after { content: ""; position: absolute; inset: -10px -8px; }.composer textarea { scrollbar-width: none; }
.composer textarea::-webkit-scrollbar { display: none; }
.composer textarea::placeholder { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* ================= Компьютер: экраны, которые на телефоне занимают всю высоту ================= */
/* Правила в конце файла: перекрывают телефонные, объявленные ниже общего блока для компьютера */
@media (min-width: 1024px) {
  /* Вход в Telegram — карточкой по центру, как экран входа в CRM */
  .tg-screen {
    min-height: 0; max-width: 520px; margin: 40px auto; padding: 32px 40px;
    border: 1px solid var(--line); border-radius: 24px; box-shadow: 0 24px 64px rgba(0, 0, 0, .18);
  }
  .tg-screen .grow { flex: none; height: 20px; }
  /* Нижняя панель (рассылка, выбор чатов) — по ширине содержимого, а не всего окна */
  .bc-foot {
    left: var(--nav-w);
    padding-left: max(16px, calc((100vw - var(--nav-w) - 1040px) / 2 + 16px));
    padding-right: max(16px, calc((100vw - var(--nav-w) - 1040px) / 2 + 16px));
  }
  /* Дела: действия справа в строке, без кнопки во всю ширину */
  .rem-card { flex-direction: row; align-items: center; gap: 16px; }
  .rem-top { flex: 1; min-width: 0; }
  .rem-acts { flex-shrink: 0; }
  .rem-acts .grow { flex: none; padding: 0 16px; }
  /* Карточка клиента: профиль слева, разделы справа */
  .card-screen #ccBody { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: 12px 16px; padding: 16px; align-items: start; }
  .card-screen .hero { grid-column: 1; grid-row: 1 / span 8; border-radius: 16px; padding: 24px 16px 16px; position: sticky; top: 72px; }
  .card-screen .quick { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-screen .block { grid-column: 2; margin: 0; border-radius: 16px; }
  .card-screen #ccBody > .loading, .card-screen #ccBody > .empty { grid-column: 1 / -1; }
  /* Поля форм: подпись шире — «Клиент не отвечает» в одну строку */
  .field > span { width: 200px; }
}

/* ================= Компьютер: десктопный интерфейс (≥ 1024 px) ================= */
/* Телефон и планшет эти правила не затрагивают */
@media (min-width: 1024px) {
  /* Мышь и клавиатура: курсоры, наведение, фокус, тонкие полосы прокрутки */
  button, a, label.switch-row, .chip, .stage-pill, select { cursor: pointer; }
  button:disabled { cursor: default; }
  :focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
  input:focus-visible, textarea:focus-visible, select:focus-visible { outline: none; }
  * { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 2px solid transparent; background-clip: padding-box; }
  ::-webkit-scrollbar-thumb:hover { background-color: var(--muted); }
  ::-webkit-scrollbar-track { background: transparent; }
  .hscroll { scrollbar-width: none; }
  .btn:hover:not(:disabled) { background: var(--surface-2); }
  .btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
  .btn.ghost:hover:not(:disabled) { background: var(--accent-soft); }
  .btn.soft:hover:not(:disabled) { background: var(--accent-line); }
  .btn.dark:hover:not(:disabled) { opacity: .88; background: var(--text); }
  .icon-btn:hover, .square-btn:hover, .round-btn:not(.send):not(.add):hover { background: var(--surface-2); }
  .round-btn.send:hover:not(:disabled), .round-btn.add:hover { background: var(--accent-hover); }
  .chip:hover:not(.on) { border-color: var(--accent-line); background: var(--accent-soft); }
  .stage-pill:hover { box-shadow: inset 0 0 0 1.5px currentColor; }
  .reply:hover, .hint:hover, .tpl:hover, .option:hover { border-color: var(--accent); }
  .link:hover { text-decoration: underline; }
  .seg button:hover:not(.on) { color: var(--text); }
  .fab:hover { background: var(--accent-hover); }

  /* Ширина колонок чатов: список уже на небольших мониторах */
  .pane-list { width: 340px; }
  @media (max-width: 1439.98px) { .pane-list:has(+ .pane-main .with-side) { width: 320px; } }

  /* Диалог: переписка + панель клиента справа */
  .chat-screen.with-side { flex-direction: row; }
  .chat-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .chat-side { display: none; }
  .messages { padding: 16px 24px 10px; }
  .composer-wrap { padding: 0 8px 4px; }

  /* Клиенты: таблица; «Новый клиент» — в шапке */
  .clients-top h1 { margin-right: auto; }
  .clients-top ~ .fab { display: none; }
  #clNewTop { margin-right: 6px; }
  .cards:has(.ctable-wrap) { padding: 4px 16px 32px; }
  .ctable-wrap { background: var(--surface); border-radius: var(--r-card); box-shadow: var(--shadow); overflow: auto; }
  .ctable { width: 100%; border-collapse: collapse; font-size: 14px; }
  .ctable th { position: sticky; top: 0; z-index: 1; background: var(--surface); text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
  .ctable td { padding: 8px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
  .ctable tbody tr { cursor: pointer; }
  .ctable tbody tr:hover td { background: var(--surface-2); }
  .ctable tbody tr.sel td { background: var(--accent-soft); }
  .ctable tbody tr:last-child td { border-bottom: 0; }
  .ctable tr.dim { opacity: .6; }
  .ctable .c-check { width: 40px; padding-right: 0; }
  .ctable input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }
  .ctable .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; font-weight: 600; }
  .ctable .c-time { white-space: nowrap; text-align: right; font-size: 13px; }
  .c-who { display: flex; align-items: center; gap: 10px; color: var(--text); min-width: 0; max-width: 300px; }
  .c-who > span:not(.avatar) { display: flex; flex-direction: column; min-width: 0; }
  .c-who b { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .c-who > span:not(.avatar) > span { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .c-who:hover b { color: var(--accent-text); }
  .c-next { color: var(--text-2); max-width: 340px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .c-next.late { color: var(--danger-text); font-weight: 600; }
  .ctable .stage-pill { min-height: 28px; white-space: nowrap; }
  /* Панель выбора: по ширине содержимого, кнопки в строку */
  .sel-bar { display: flex; align-items: center; gap: 12px; padding: 8px max(16px, calc((100vw - var(--nav-w) - 1040px) / 2 + 16px)); }
  .sel-bar .sel-head { flex: 1; }
  .sel-bar .sel-actions { display: flex; gap: 4px; }
  .sel-bar .sel-actions button { min-height: 40px; flex-direction: row; gap: 6px; padding: 0 14px; font-size: 13px; }
  .sel-bar .sel-actions button:hover:not(:disabled) { background: var(--surface-2); }

  /* Статистика: KPI в строку, воронка и «без касания» рядом */
  #statBody { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 14px; align-items: start; }
  #statBody > .kpi-grid { grid-column: 1 / -1; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
  #statBody > .empty, #statBody > .loading { grid-column: 1 / -1; }
  .kpi { padding: 16px 18px; }

  /* «Ещё»: меню разделов слева, раздел справа; формы не на всю ширину */
  .more-split { display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 24px; padding: 24px 16px 0; align-items: start; }
  .more-nav { position: sticky; top: 24px; display: flex; flex-direction: column; gap: 2px; }
  .more-nav .group-title { padding: 14px 12px 4px; }
  .more-nav a { display: flex; align-items: center; gap: 12px; min-height: 40px; padding: 0 12px; border-radius: 10px; color: var(--text-2); font-size: 14px; font-weight: 500; }
  .more-nav a .ico { width: 18px; height: 18px; }
  .more-nav a:hover { background: var(--surface); color: var(--text); }
  .more-nav a.on { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
  .more-nav .count { margin-left: auto; }
  .more-main { min-width: 0; max-width: 760px; }
  .more-main > .top { padding: 0 0 12px; }
  .more-main > .bar { position: static; min-height: 0; padding: 0 0 12px; background: none; border: 0; }
  .more-main > .bar [data-back] { display: none; }
  .more-main > .bar .bar-title b { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
  .more-main > .pad { padding: 0 0 24px; }
  .more-main .more-group { display: none; }
}

/* Экран шире 1280 px — справа от переписки помещается панель клиента */
@media (min-width: 1280px) {
  .chat-side {
    display: block; width: 320px; flex-shrink: 0; overflow-y: auto; background: var(--surface);
    border-left: 1px solid var(--line);
  }
  .side-block { padding: 14px 16px; border-bottom: 1px solid var(--line-soft); display: flex; flex-direction: column; gap: 8px; }
  .side-block:last-child { border-bottom: 0; }
  .side-who { flex-direction: row; align-items: center; gap: 10px; padding-top: 16px; }
  .side-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  .side-name b { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .side-name span { font-size: 12px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .side-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 32px; font-size: 14px; }
  .side-row > span { color: var(--text-2); font-size: 13px; }
  .side-row b { font-weight: 600; }
  .side-notes { display: flex; flex-direction: column; gap: 4px; }
  .side-notes > span { font-size: 13px; color: var(--text-2); }
  .side-notes p { margin: 0; font-size: 14px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; }
  .side-notes .reply { margin-bottom: 0; font-size: 13px; }
  .side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
  .side-head .label { margin: 0; display: inline-flex; align-items: center; gap: 6px; }
  .side-head .link { padding: 0; }
  .side-rem { display: flex; flex-direction: column; gap: 1px; width: 100%; text-align: left; border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; background: var(--surface); color: var(--text); font-size: 13px; }
  .side-rem:hover { border-color: var(--accent-line); background: var(--accent-soft); }
  .side-rem b { font-size: 13px; font-weight: 600; }
  .side-rem b.late { color: var(--danger-text); }
  .side-rem span { color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .side-next { background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; }
  .side-next .label { margin-bottom: 2px; }
  .side-next p { margin: 0; font-size: 14px; line-height: 1.4; }
  .side-ai .btn.block { margin-top: 2px; }
}
@media (min-width: 1600px) {
  .pane-list { width: 380px; }
  .chat-side { width: 360px; }
}
