:root {
  --bg: #f4f5f8;
  --card: #ffffff;
  --text: #1d2230;
  --muted: #7a8194;
  --line: #e4e7ee;
  --side: #232838;
  --side-text: #c9cede;
  --accent: #4f5bd5;
  --accent-soft: #eceefc;
  --green: #1f9d55;
  --green-soft: #e3f5ea;
  --blue: #2463eb;
  --blue-soft: #e4ecfd;
  --amber: #b7791f;
  --amber-soft: #fdf3dc;
  --red: #d13b3b;
  --red-soft: #fde8e8;
  --grey-soft: #eef0f4;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
code { font: 13px ui-monospace, Menlo, Consolas, monospace; background: var(--grey-soft); padding: 1px 6px; border-radius: 4px; }
h1 { font-size: 22px; margin: 0; font-weight: 650; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* каркас */
.layout { display: flex; min-height: 100vh; }
.side { width: 220px; flex: none; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { font-size: 20px; font-weight: 700; color: #fff; padding: 0 10px 18px; }
.brand span { display: block; font-size: 12px; font-weight: 400; color: var(--side-text); opacity: .7; }
.brand.big { color: var(--text); font-size: 26px; padding: 0 0 8px; }
.brand.big span { color: var(--muted); }
.side nav { display: flex; flex-direction: column; gap: 2px; }
.side nav a { color: var(--side-text); padding: 9px 12px; border-radius: 8px; }
.side nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side nav a.on { background: var(--accent); color: #fff; }
.me { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid rgba(255,255,255,.08); }
.me-name { color: #fff; font-weight: 600; }
.me-role { font-size: 12px; opacity: .7; margin-bottom: 6px; }
.main { flex: 1; min-width: 0; padding: 24px 28px 40px; }

.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.tiles { display: flex; gap: 10px; flex-wrap: wrap; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 16px; min-width: 120px; }
.tile b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
.tile span { font-size: 12px; color: var(--muted); }
.tile.talk b { color: var(--blue); }
.tile.online b { color: var(--green); }
.tile.ringing b { color: var(--amber); }
.tile.offline b { color: var(--muted); }

/* кнопки и поля */
.btn { display: inline-block; border: 1px solid var(--line); background: var(--card); color: var(--text); padding: 7px 14px; border-radius: 8px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c8cdd9; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn.wide { width: 100%; }
button.link { background: none; border: 0; padding: 0; color: var(--side-text); font: inherit; cursor: pointer; text-decoration: underline; opacity: .8; }
input, select { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text); }
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.toolbar, .filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 14px; }
.filters label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
.toolbar input[type=search] { min-width: 300px; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; display: inline-block; }
.alert.err { background: var(--red-soft); color: var(--red); }
.alert.ok { background: var(--green-soft); color: #145c34; display: block; }
code.secret { font-size: 15px; background: #fff; }

/* таблицы */
.grid { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.grid th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); background: #fafbfd; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: bottom; }
.grid th small { font-weight: 400; }
.grid td { padding: 8px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.grid tr:last-child td { border-bottom: 0; }
.grid tbody tr:hover td { background: #fafbff; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid tr.off td { color: var(--muted); }
.grid.kv { max-width: 560px; }
.grid.kv th { width: 200px; vertical-align: middle; }
.ua { font-size: 12px; color: var(--muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec { white-space: nowrap; }
.rec audio { height: 32px; width: 260px; vertical-align: middle; }
.rec .dl { margin-left: 6px; font-size: 16px; }
.actions { white-space: nowrap; text-align: right; }
form.inline { display: inline; }

/* статусы */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--grey-soft); color: var(--muted); }
.pill.talk, .pill.st-answered { background: var(--blue-soft); color: var(--blue); }
.pill.online { background: var(--green-soft); color: var(--green); }
.pill.ringing, .pill.st-busy { background: var(--amber-soft); color: var(--amber); }
.pill.disabled, .pill.st-failed, .pill.st-congestion { background: var(--red-soft); color: var(--red); }
.q { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.q.good { background: var(--green); }
.q.mid { background: var(--amber); }
.q.bad { background: var(--red); }

.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 16px; color: var(--muted); }

/* вход */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }

@media (max-width: 800px) {
  .layout { flex-direction: column; }
  .side { width: auto; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
  .brand { padding: 0 8px 0 0; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .me { margin: 0 0 0 auto; border: 0; padding: 0; }
  .main { padding: 16px; }
  .grid { display: block; overflow-x: auto; }
  .tile { min-width: 0; flex: 1 1 40%; }
}

/* --- v2: новые разделы --- */
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
.me-name { color: #fff; font-weight: 600; display: block; }
.me-name:hover { text-decoration: underline; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 18px; }
.card.narrow { max-width: 460px; }
.card .grid { border-radius: 8px; }
.card.filters { align-items: flex-end; }
.form-title { width: 100%; font-size: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label, .grid-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.grid-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px 16px; align-items: end; }
.grid-form .span2 { grid-column: 1 / -1; }
textarea { font: inherit; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; resize: vertical; color: var(--text); }
textarea[readonly] { background: var(--grey-soft); }
fieldset.days { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; display: flex; gap: 10px; flex-wrap: wrap; }
fieldset.days legend { font-size: 12px; color: var(--muted); padding: 0 4px; }
label.check { flex-direction: row !important; align-items: center; gap: 4px; color: var(--text) !important; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0 14px; }
.tabs a { padding: 6px 12px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--text); }
.tabs a:hover { border-color: var(--accent); }
.tiles.wide { margin-bottom: 8px; }
.small-note { font-size: 12px; margin: 4px 0 12px; }
.btn.danger { color: var(--red); border-color: #f0c4c4; }
.btn.primary.danger { background: var(--red); color: #fff; }
.delta { font-size: 11px; font-weight: 600; margin-left: 4px; color: var(--muted); }
.delta.up { color: var(--green); }
.delta.down { color: var(--red); }
.legend { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.legend .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-left: 8px; }
.legend .sw.dialed { background: #c9cff5; }
.legend .sw.answered { background: var(--accent); }
.chart { width: 100%; height: auto; max-height: 260px; display: block; }
.chart .bar-dialed { fill: #c9cff5; }
.chart .bar-answered { fill: var(--accent); }
.chart text { font-size: 13px; fill: var(--muted); }
.chart text.val { font-size: 12px; fill: var(--text); }
td.warn { color: var(--amber); font-weight: 600; }
.copyable { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font: 13px ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; margin: 8px 0; color: var(--text); }
.inline-edit { display: flex; gap: 6px; flex-wrap: wrap; }
.inline-edit input[name=name] { min-width: 200px; }
.inline-edit input[name=team] { width: 190px; }
details.inline-details { display: inline-block; position: relative; }
details.inline-details summary { list-style: none; }
details.inline-details summary::-webkit-details-marker { display: none; }
details.inline-details[open] form { position: absolute; right: 0; z-index: 5; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; width: 260px; box-shadow: 0 8px 24px rgba(0,0,0,.08); text-align: left; }
.err-text { font-size: 12px; color: var(--red); max-width: 260px; }
td.details { font-size: 12px; color: var(--muted); max-width: 420px; word-break: break-word; }
.pill.rs-pending { background: var(--grey-soft); color: var(--muted); }
.pill.rs-calling { background: var(--amber-soft); color: var(--amber); }
.pill.rs-done { background: var(--green-soft); color: var(--green); }
.pill.rs-callback { background: var(--blue-soft); color: var(--blue); }
.pill.rs-failed, .pill.rs-cancelled { background: var(--red-soft); color: var(--red); }
table.sortable th[data-sort] { cursor: pointer; user-select: none; }
table.sortable th[data-sort]:hover { color: var(--accent); }
table.sortable th.asc::after { content: " ▲"; }
table.sortable th.desc::after { content: " ▼"; }
.role-form select { padding: 3px 6px; font-size: 13px; }
#texts audio { height: 32px; width: 100%; max-width: 360px; margin: -4px 0 6px; }
h1 .pill { vertical-align: middle; margin-left: 8px; }
