:root {
  --bg: #f6f7f9; --surface: #fff; --surface-2: #f1f3f6; --line: #e6e8ec;
  --text: #0f172a; --muted: #64748b; --faint: #94a3b8;
  --accent: #4f46e5; --accent-soft: #eef0ff; --accent-text: #fff;
  --green: #15803d; --green-soft: #e8f6ee; --blue: #2563eb; --blue-soft: #e8f0fe;
  --amber: #b45309; --amber-soft: #fdf3e2; --red: #dc2626; --red-soft: #fdecec;
  --grey-soft: #eef0f3;
  --radius: 14px; --shadow: 0 1px 2px rgba(15,23,42,.04), 0 4px 16px rgba(15,23,42,.05);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117; --surface: #151a22; --surface-2: #1b212b; --line: #262e3a;
    --text: #e6e9ef; --muted: #98a2b3; --faint: #677284;
    --accent: #818cf8; --accent-soft: #23264a; --accent-text: #0d1117;
    --green: #4ade80; --green-soft: #13291d; --blue: #7aa7ff; --blue-soft: #162340;
    --amber: #fbbf24; --amber-soft: #2d2412; --red: #f87171; --red-soft: #321717;
    --grey-soft: #1f2631; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; }

/* шапка */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px;
  padding: 10px max(16px, calc((100vw - 1120px) / 2)); background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -.01em; }
.brand-lg { font-size: 20px; justify-content: center; margin-bottom: 8px; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M11.5 8.5c.6-.6 1.6-.6 2.2 0l2 2c.6.6.6 1.6 0 2.2l-1.2 1.2a10 10 0 0 0 3.6 3.6l1.2-1.2c.6-.6 1.6-.6 2.2 0l2 2c.6.6.6 1.6 0 2.2l-1.3 1.3c-1 1-2.6 1.3-3.9.6a19 19 0 0 1-8.4-8.4c-.7-1.3-.4-2.9.6-3.9z' fill='white'/%3E%3C/svg%3E") center/100% no-repeat; flex: none; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 7px 12px; border-radius: 9px; color: var(--muted); font-weight: 520; }
.tabs a:hover { color: var(--text); background: var(--surface-2); }
.tabs a.on { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.live.stale i { background: var(--amber); }
.icon-btn { width: 34px; height: 34px; border: 0; border-radius: 9px; background: transparent; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.view { max-width: 1120px; margin: 0 auto; padding: 24px 16px 96px; }
h1 { font-size: 24px; letter-spacing: -.02em; margin: 0 0 4px; font-weight: 680; }
h2 { font-size: 16px; margin: 0; font-weight: 640; letter-spacing: -.01em; }
.sub { color: var(--muted); margin: 0 0 22px; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.head .sub { margin: 0; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 18px 12px; flex-wrap: wrap; }
.card-h .hint { color: var(--muted); font-size: 13px; }
.stack { display: grid; gap: 16px; }
.grid2 { display: grid; grid-template-columns: 1.15fr 1fr; gap: 16px; align-items: start; }
.grid2 > *, .kpis > *, .people > * { min-width: 0; }

/* сводка */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi b { display: block; font-size: 26px; font-weight: 680; letter-spacing: -.02em; }
.kpi span { color: var(--muted); font-size: 13px; }
.kpi.alert b { color: var(--red); }

/* звонок сейчас */
.now-call { display: flex; align-items: center; gap: 12px; padding: 12px 16px; margin-bottom: 16px; background: var(--blue-soft); border-color: transparent; }
.pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--blue); box-shadow: 0 0 0 0 var(--blue); animation: pulse 1.6s infinite; flex: none; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--blue) 50%, transparent); } 100% { box-shadow: 0 0 0 10px transparent; } }

/* строки списков */
.rows { list-style: none; margin: 0; padding: 0 6px 6px; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; }
.row + .row { border-top: 1px solid var(--line); }
.row:hover { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .t1 { font-weight: 560; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .t2 { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 22px 18px 26px; color: var(--muted); text-align: center; }

.avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; font-weight: 640; font-size: 13px; flex: none; background: var(--accent-soft); color: var(--accent); position: relative; }
.avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--surface); background: var(--faint); }
.dot.online { background: var(--green); } .dot.talking { background: var(--blue); } .dot.paused { background: var(--amber); } .dot.offline, .dot.disabled { background: var(--faint); }

.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 560; white-space: nowrap; }
.pill.online, .pill.answered, .pill.ok { background: var(--green-soft); color: var(--green); }
.pill.talking { background: var(--blue-soft); color: var(--blue); }
.pill.paused, .pill.tried, .pill.no_answer, .pill.busy { background: var(--amber-soft); color: var(--amber); }
.pill.offline, .pill.disabled, .pill.failed, .pill.muted { background: var(--grey-soft); color: var(--muted); }
.pill.missed, .pill.bad { background: var(--red-soft); color: var(--red); }

/* кнопки, поля */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 560; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: transparent; color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--red); }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13.5px; border-radius: 8px; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); background: var(--surface-2); }
.btn.wide { width: 100%; height: 42px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select { height: 36px; padding: 0 11px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); outline: none; min-width: 0; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
label { display: grid; gap: 6px; font-size: 13.5px; color: var(--muted); font-weight: 520; }
label input, label select { color: var(--text); font-size: 15px; }
.form { display: grid; gap: 14px; }
.form-error { color: var(--red); font-size: 13.5px; min-height: 1em; }

.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 99px; background: var(--line); transition: .2s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.toggle-line { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 18px; }
.toggle-line .t2 { color: var(--muted); font-size: 13px; }

/* журнал */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.seg { display: inline-flex; padding: 3px; border-radius: 11px; background: var(--surface-2); gap: 2px; }
.seg button { border: 0; background: transparent; height: 30px; padding: 0 12px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 540; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.filters input[type=search] { width: 190px; }
.jt { width: 100%; border-collapse: collapse; }
.jt td, .jt th { padding: 11px 12px; text-align: left; border-top: 1px solid var(--line); vertical-align: middle; }
.jt th { border-top: 0; color: var(--muted); font-weight: 540; font-size: 12.5px; text-transform: uppercase; letter-spacing: .04em; }
.jt tr:hover td { background: var(--surface-2); }
.jt .dir { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; }
.dir svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.dir.in { background: var(--green-soft); color: var(--green); } .dir.out { background: var(--blue-soft); color: var(--blue); } .dir.miss { background: var(--red-soft); color: var(--red); }
.day td { background: transparent !important; color: var(--muted); font-size: 12.5px; font-weight: 600; padding-top: 18px; border-top: 0; }
.play { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; cursor: pointer; color: var(--accent); }
.play svg { width: 13px; height: 13px; fill: currentColor; }
.player-row td { padding: 6px 12px 14px !important; background: var(--surface-2); }
.player-row audio { width: 100%; height: 36px; }
.more { display: flex; justify-content: center; padding: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* номера, очередь */
.line-card .card-h { padding-bottom: 6px; }
.line-num { white-space: nowrap; font-size: 20px; font-weight: 680; letter-spacing: -.01em; }
.queue { padding: 4px 18px 18px; display: grid; gap: 10px; }
.step { display: grid; grid-template-columns: 28px 1fr auto; gap: 12px; align-items: start; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.step-n { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-weight: 680; font-size: 13px; }
.step .chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 99px; background: var(--surface-2); font-size: 13.5px; font-weight: 540; }
.chip .x { border: 0; background: transparent; cursor: pointer; color: var(--faint); width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; }
.chip .x:hover { background: var(--line); color: var(--text); }
.chip .s { width: 7px; height: 7px; border-radius: 50%; }
.chips select { height: 28px; width: auto; border-radius: 99px; padding: 0 10px; font-size: 13px; border-style: dashed; color: var(--muted); }
.step .meta { color: var(--muted); font-size: 13px; margin-top: 8px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.secs { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.secs button { border: 0; background: transparent; width: 26px; height: 26px; cursor: pointer; color: var(--muted); }
.secs button:hover { background: var(--surface-2); color: var(--text); }
.secs span { min-width: 44px; text-align: center; font-weight: 600; color: var(--text); font-size: 13px; }
.step-tools { display: flex; gap: 2px; }
.step-tools .icon-btn { width: 28px; height: 28px; }
.flow-arrow { text-align: center; color: var(--faint); font-size: 12px; margin: -4px 0; }
.savebar { display: flex; justify-content: flex-end; gap: 8px; padding: 0 18px 18px; }

/* сотрудники */
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.person { padding: 16px; display: grid; gap: 14px; }
.person-top { display: flex; align-items: center; gap: 12px; }
.person-top .avatar { width: 44px; height: 44px; font-size: 15px; }
.person-name { font-weight: 640; font-size: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; }
.person-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* модальные окна */
.modal-wrap { position: fixed; inset: 0; background: rgba(15,23,42,.38); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: min(440px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 18px; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal h2 { font-size: 18px; margin-bottom: 4px; }
.modal .sub { margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.qr { display: grid; place-items: center; padding: 14px; background: #fff; border-radius: 14px; border: 1px solid var(--line); }
.qr svg { width: 220px; height: 220px; }
.steps-list { margin: 14px 0 0; padding-left: 20px; color: var(--muted); font-size: 13.5px; display: grid; gap: 4px; }
.copy { display: flex; gap: 6px; margin-top: 12px; } .copy input { flex: 1; font-size: 12.5px; color: var(--muted); }
.warn { padding: 10px 12px; border-radius: 10px; background: var(--amber-soft); color: var(--amber); font-size: 13.5px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 540; z-index: 60; box-shadow: 0 8px 30px rgba(0,0,0,.2); }
.toast.err { background: var(--red); color: #fff; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); }

.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

@media (max-width: 860px) {
  .topbar { backdrop-filter: none; background: var(--bg); }
  .card-h .hint { display: none; }
  .grid2 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .topbar { gap: 12px; }
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; justify-content: space-around; padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); z-index: 20; }
  .tabs a { flex: 1; text-align: center; padding: 8px 4px; font-size: 13.5px; }
  .hide-m { display: none; }
  .jt td, .jt th { padding: 10px 8px; }
  .filters input[type=search] { width: 100%; }
  .people { grid-template-columns: 1fr; }
}
