:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #111827;
  --ink-2: #4b5563;
  --ink-3: #9ca3af;
  --line: #e5e7eb;
  --side: #0f172a;
  --side-ink: #cbd5e1;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --good: #16a34a;
  --good-soft: #dcfce7;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --bad: #dc2626;
  --bad-soft: #fee2e2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.45 "Segoe UI", Inter, -apple-system, Roboto, sans-serif;
  color: var(--ink); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.hidden { display: none !important; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side {
  background: var(--side); color: var(--side-ink); padding: 20px 14px;
  display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 650; font-size: 16px; padding: 4px 10px 20px; }
.brand .dot { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, #3b82f6, #22c55e); display: grid; place-items: center; }
.brand .dot svg { width: 16px; height: 16px; }
.nav button {
  width: 100%; display: flex; align-items: center; gap: 10px; text-align: left;
  background: none; border: 0; color: var(--side-ink); padding: 9px 10px; border-radius: 8px; cursor: pointer;
}
.nav button svg { width: 18px; height: 18px; opacity: .8; flex: none; }
.nav button:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav button.on { background: rgba(59, 130, 246, .18); color: #fff; }
.nav .badge-live { margin-left: auto; background: #22c55e; color: #052e16; font-size: 11px; font-weight: 700; padding: 0 7px; border-radius: 999px; }
.side .status { margin-top: auto; display: grid; gap: 6px; font-size: 12px; padding: 12px 10px; border-top: 1px solid rgba(255,255,255,.08); }
.side .status div { display: flex; align-items: center; gap: 8px; }
.led { width: 8px; height: 8px; border-radius: 50%; background: #64748b; flex: none; }
.led.ok { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.18); }
.led.bad { background: #ef4444; }
.led.warn { background: #f59e0b; }
.side .logout { background: none; border: 0; color: #64748b; cursor: pointer; text-align: left; padding: 6px 10px; font-size: 12px; }

main { padding: 24px 28px 60px; min-width: 0; }
.head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -.01em; }
.head .grow { flex: 1; }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: #fff;
  padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; font-weight: 500;
}
.btn:hover { border-color: #cbd5e1; background: #f9fafb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.good { background: var(--good); border-color: var(--good); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn svg { width: 16px; height: 16px; }
input[type=text], input[type=password], input[type=number], input[type=time], input[type=search], select, textarea {
  border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 10px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: #93c5fd; box-shadow: 0 0 0 3px rgba(59,130,246,.15); }
textarea { resize: vertical; min-height: 80px; line-height: 1.5; }
textarea.code { font-family: Consolas, "SF Mono", monospace; font-size: 13px; }
label.f { display: grid; gap: 5px; font-size: 13px; color: var(--ink-2); }
label.f > span { font-weight: 550; color: var(--ink); }
label.f small { color: var(--ink-3); }
.check { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.seg { display: inline-flex; background: #e9ebef; border-radius: 8px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; cursor: pointer; color: var(--ink-2); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: var(--shadow); }

/* ---------- cards ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card > h3, .card .ch { margin: 0; padding: 14px 16px 0; font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card .cb { padding: 14px 16px 16px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: 1fr 1fr; }
.g3 { grid-template-columns: 2fr 1fr; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .l { color: var(--ink-2); font-size: 12px; }
.kpi .v { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .s { color: var(--ink-3); font-size: 12px; }
.kpi.hl { background: linear-gradient(180deg, #f0fdf4, #fff); border-color: #bbf7d0; }
.kpi.hl .v { color: #15803d; }
.chart-box { position: relative; height: 260px; }

.funnel { display: grid; gap: 10px; }
.funnel .row { display: grid; grid-template-columns: 130px 1fr 60px; align-items: center; gap: 10px; font-size: 13px; }
.funnel .bar { height: 22px; background: #eef2f7; border-radius: 6px; overflow: hidden; }
.funnel .bar i { display: block; height: 100%; background: linear-gradient(90deg, #3b82f6, #60a5fa); border-radius: 6px; min-width: 2px; }
.funnel .row:last-child .bar i { background: linear-gradient(90deg, #16a34a, #4ade80); }
.funnel .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- live calls ---------- */
.live { display: grid; gap: 10px; }
.live .empty { color: var(--ink-3); padding: 18px 4px; text-align: center; }
.lc { border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; }
.lc .top { display: flex; align-items: center; gap: 8px; }
.lc .top b { font-variant-numeric: tabular-nums; }
.lc .lines { margin-top: 8px; display: grid; gap: 3px; font-size: 13px; max-height: 150px; overflow: auto; }
.lc .lines .r { color: var(--accent); }
.lc .lines .c { color: var(--ink); }
.lc .lines .p { color: var(--ink-3); font-style: italic; }
.pulse { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; animation: pulse 1.4s infinite; }
.pulse.ring { background: #f59e0b; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34,197,94,.5); } 70% { box-shadow: 0 0 0 8px rgba(34,197,94,0); } 100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); } }

/* ---------- tables ---------- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-weight: 550; color: var(--ink-2); font-size: 12px; padding: 9px 12px; border-bottom: 1px solid var(--line); background: #fafbfc; position: sticky; top: 0; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid #f0f1f3; vertical-align: top; }
.tbl tr.click { cursor: pointer; }
.tbl tr.click:hover td { background: #f8fafc; }
.tbl .sum { color: var(--ink-2); max-width: 420px; }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 550; background: #f1f5f9; color: #334155; white-space: nowrap; }
.tag.lead { background: var(--good-soft); color: #166534; }
.tag.callback, .tag.not_qualified { background: var(--warn-soft); color: #92400e; }
.tag.not_interested, .tag.do_not_call, .tag.hangup { background: var(--bad-soft); color: #991b1b; }
.tag.no_answer, .tag.busy, .tag.failed, .tag.autoanswer, .tag.no_response { background: #f1f5f9; color: #64748b; }
.tag.running { background: var(--good-soft); color: #166534; }
.tag.paused { background: var(--warn-soft); color: #92400e; }
.tag.finished { background: var(--accent-soft); color: #1e40af; }
.tag.test { background: #ede9fe; color: #5b21b6; }
.pager { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; color: var(--ink-2); font-size: 13px; }

/* ---------- campaigns ---------- */
.camps { display: grid; gap: 14px; }
.camp { padding: 16px 18px; display: grid; gap: 12px; }
.camp .t { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.camp .t h3 { margin: 0; font-size: 16px; }
.camp .progress { height: 8px; background: #eef2f7; border-radius: 99px; overflow: hidden; }
.camp .progress i { display: block; height: 100%; background: var(--accent); }
.camp .meta { display: flex; gap: 22px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.camp .meta b { color: var(--ink); font-variant-numeric: tabular-nums; }
.camp .acts { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- drawer / modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .35); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); background: #fff; z-index: 50; box-shadow: -10px 0 30px rgba(0,0,0,.12); display: flex; flex-direction: column; }
.drawer .dh { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.drawer .dh h2 { margin: 0; font-size: 17px; }
.drawer .db { padding: 18px 20px 40px; overflow: auto; display: grid; gap: 18px; align-content: start; }
.x { margin-left: auto; border: 0; background: none; font-size: 22px; line-height: 1; cursor: pointer; color: var(--ink-3); padding: 4px 8px; }
.modal { position: fixed; z-index: 50; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(860px, calc(100vw - 32px)); max-height: calc(100vh - 40px); background: #fff; border-radius: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.2); display: flex; flex-direction: column; }
.modal.narrow { width: min(440px, calc(100vw - 32px)); }
.modal .mb { padding: 18px 22px; overflow: auto; display: grid; gap: 14px; }
.modal .mf { padding: 14px 22px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; }
.form2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.form4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }

.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; }
.summary { background: #f8fafc; border: 1px solid var(--line); border-radius: 9px; padding: 12px 14px; }
audio { width: 100%; }

.chat { display: grid; gap: 8px; }
.msg { max-width: 84%; padding: 8px 12px; border-radius: 12px; font-size: 14px; position: relative; }
.msg.robot { background: var(--accent-soft); justify-self: end; border-bottom-right-radius: 4px; }
.msg.client { background: #f1f5f9; justify-self: start; border-bottom-left-radius: 4px; }
.msg .ts { font-size: 11px; color: var(--ink-3); cursor: pointer; margin-right: 6px; }
.msg .ts:hover { color: var(--accent); }
.msg.cut { opacity: .75; }
.msg.cut::after { content: "перебили"; font-size: 10px; color: var(--ink-3); margin-left: 6px; }
.msg.partial { opacity: .55; font-style: italic; }

/* ---------- settings ---------- */
.settings { display: grid; gap: 16px; max-width: 980px; }
.settings .cb { display: grid; gap: 14px; }
.hint { background: #f8fafc; border: 1px dashed #cbd5e1; border-radius: 9px; padding: 10px 12px; font-size: 13px; color: var(--ink-2); }
.hint b { color: var(--ink); }

/* ---------- web talk ---------- */
.talk { display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: start; }
.mic { width: 120px; height: 120px; border-radius: 50%; border: 0; cursor: pointer; display: grid; place-items: center; margin: 10px auto; background: var(--accent); color: #fff; box-shadow: 0 8px 24px rgba(37,99,235,.35); transition: transform .1s; }
.mic:active { transform: scale(.97); }
.mic.on { background: var(--bad); box-shadow: 0 8px 24px rgba(220,38,38,.35); }
.mic svg { width: 44px; height: 44px; }
.level { height: 6px; background: #eef2f7; border-radius: 9px; overflow: hidden; }
.level i { display: block; height: 100%; width: 0; background: var(--good); transition: width .08s; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(1200px 600px at 20% 10%, #1e293b, #0f172a); }
.login form { background: #fff; padding: 28px; border-radius: 14px; width: 340px; display: grid; gap: 14px; box-shadow: 0 30px 60px rgba(0,0,0,.35); }
.login h1 { margin: 0; font-size: 20px; }

.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 99; box-shadow: 0 10px 30px rgba(0,0,0,.3); max-width: 90vw; }
.toast.err { background: #991b1b; }

@media (max-width: 1100px) { .g2, .g3, .talk { grid-template-columns: 1fr; } }
@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .side .status { display: none; }
  main { padding: 16px; }
  .form2, .form3, .form4 { grid-template-columns: 1fr; }
}

/* правки сетки */
.grid > * { min-width: 0; }
.grid.g2 { align-items: start; }
.tbl td.num, .tbl td.nw { white-space: nowrap; }
.chart-box canvas { max-width: 100%; }
.msg .lat { font-size: 11px; color: var(--ink-3); margin-top: 3px; }

/* разбор */
.tag.disputed { background: var(--warn-soft); color: #92400e; }
.nav .badge-live.warn { background: #fbbf24; color: #451a03; }
.tbl tr.done td { opacity: .5; }
.why { color: #92400e; margin-top: 3px; }
.seg .cnt { font-weight: 600; color: var(--ink-2); margin-left: 4px; }
.rv-acts { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 12px; background: #fafbfc; border: 1px solid var(--line); border-radius: 10px; }
