:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --text: #1f2a37;
  --muted: #6b7785;
  --line: #e2e7ec;
  --primary: #1fa855;
  --primary-ink: #ffffff;
  --primary-hover: #17924a;
  --danger: #d64545;
  --danger-bg: #fdecec;
  --warn-bg: #fff6e0;
  --warn-line: #f2d48b;
  --info-bg: #eaf4ff;
  --ok: #1fa855;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
h1 { font-size: 20px; margin: 0 0 2px; }
h2 { font-size: 16px; margin: 0; }
h3 { font-size: 16px; margin: 0 0 8px; }
p { margin: 6px 0; }
b, strong { font-weight: 600; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
[hidden] { display: none !important; }

.page { max-width: 1100px; margin: 0 auto; padding: 16px; }
.page--narrow { max-width: 560px; padding-top: 48px; }
.page--tab { max-width: none; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; min-height: 100vh; }

.topbar { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.who { color: var(--muted); font-size: 13px; white-space: nowrap; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 820px) { .grid { grid-template-columns: 1fr; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.grid .card { margin-bottom: 0; }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }

.banner { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; border: 1px solid transparent; }
.banner--warn { background: var(--warn-bg); border-color: var(--warn-line); }
.banner--error { background: var(--danger-bg); border-color: #f3b9b9; color: #8f1f1f; }
.notice--error h1 { color: var(--danger); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef1f4; color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill--ok { background: #e6f6ec; color: #137a3c; }
.pill--warn { background: var(--warn-bg); color: #a06800; }
.pill--bad { background: var(--danger-bg); color: var(--danger); }
.pill--wait { background: var(--info-bg); color: #1d5fa8; }

.state-text { font-size: 16px; font-weight: 600; margin: 4px 0; }
.hint { background: #f7f9fb; border-left: 3px solid #c9d3dd; padding: 8px 10px; border-radius: 6px; color: #334155; }

.qr { display: flex; gap: 16px; align-items: flex-start; margin: 12px 0; flex-wrap: wrap; }
.qr img { width: 264px; height: 264px; border: 1px solid var(--line); border-radius: 8px; background: #fff; image-rendering: pixelated; }
.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 6px; }

.actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.actions--end { justify-content: flex-end; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.field { margin-top: 12px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field--inline { display: flex; align-items: center; gap: 8px; margin: 0; }
.field--inline label { margin: 0; white-space: nowrap; }

.btn { appearance: none; border: 1px solid #cfd7df; background: #fff; color: var(--text); border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer; transition: background .15s, border-color .15s; }
.btn:hover { background: #f3f6f8; }
.btn:disabled { opacity: .55; cursor: default; }
.btn--primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn--primary:hover { background: var(--primary-hover); }
.btn--danger { color: var(--danger); border-color: #efc2c2; }
.btn--danger:hover { background: var(--danger-bg); }
.btn--small { padding: 5px 10px; font-size: 13px; }
.btn--link { border: 0; background: none; padding: 0; color: #1d5fa8; font-weight: 500; }

select, textarea, input[type=text] { font: inherit; color: inherit; border: 1px solid #cfd7df; border-radius: 8px; padding: 7px 10px; background: #fff; }
select { min-width: 220px; max-width: 100%; }
textarea { width: 100%; resize: vertical; min-height: 64px; }
select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid #8cc9a3; outline-offset: 1px; }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.yes { color: var(--ok); }
.no { color: var(--danger); }

.count { display: inline-block; min-width: 22px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: 12px; text-align: center; vertical-align: middle; }
.count:empty { display: none; }
.problems { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.problem { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: start; }
.problem__title { font-weight: 600; }
.problem__meta { color: var(--muted); font-size: 12px; }
.problem__reason { grid-column: 1 / -1; font-size: 13px; }
.problem__preview { grid-column: 1 / -1; font-size: 13px; color: #334155; background: #f7f9fb; border-radius: 6px; padding: 6px 8px; white-space: pre-wrap; word-break: break-word; }
.problem__actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 600px) { .problem { grid-template-columns: 1fr; } .problem__actions { justify-content: flex-start; } }

.audit { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13px; }
.audit li { padding: 4px 0; border-bottom: 1px dashed var(--line); }

.dialog { border: 0; border-radius: 12px; padding: 20px; max-width: 440px; width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(0,0,0,.2); }
.dialog::backdrop { background: rgba(15, 23, 42, .35); }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: #1f2a37; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); z-index: 10; max-width: calc(100% - 32px); }
.toast--error { background: var(--danger); }

/* ---------- вкладка CRM ---------- */
.tabbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat { flex: 1; min-height: 240px; max-height: 60vh; overflow-y: auto; background: #e9efe9; border-radius: var(--radius); padding: 12px; display: flex; flex-direction: column; gap: 6px; border: 1px solid var(--line); }
.msg { max-width: 78%; padding: 7px 10px 5px; border-radius: 10px; background: #fff; box-shadow: 0 1px 1px rgba(0,0,0,.08); align-self: flex-start; word-wrap: break-word; white-space: pre-wrap; }
.msg--out { align-self: flex-end; background: #dcf8c6; }
.msg__meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; white-space: nowrap; }
.msg__status--bad { color: var(--danger); font-weight: 600; }
.msg__status--warn { color: #a06800; font-weight: 600; }
.msg__origin { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.msg__err { font-size: 12px; color: var(--danger); margin-top: 2px; }
.msg img.thumb { display: block; max-width: 240px; max-height: 240px; border-radius: 6px; margin-bottom: 4px; }
.msg audio, .msg video { display: block; max-width: 260px; margin-bottom: 4px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: rgba(255,255,255,.7); padding: 2px 10px; border-radius: 999px; margin: 6px 0; }
.composer { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.composer__bar { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.composer__bar .btn--primary { margin-left: auto; }
.file-btn { display: inline-flex; align-items: center; gap: 4px; }
.file-name { font-size: 12px; max-width: 50%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
