:root {
  --bg: #f2f4f7; --panel: #ffffff; --panel-2: #f7f8fa; --ink: #1b2230; --muted: #687285; --line: #e2e6ec;
  --side: #1d2738; --side-ink: #b9c3d3; --side-active: #2c3a52;
  --accent: #2f66d0; --accent-hover: #2556b3; --accent-soft: #e8effc;
  --ok: #17895c; --ok-soft: #e3f4ec; --warn: #b26a00; --warn-soft: #fff3dc; --bad: #c43d3d;
  --c-lead: #17895c; --c-refusal: #d14b4b; --c-negative: #8a44b8; --c-autoanswer: #e08a1e;
  --c-other_start: #3a8fd6; --c-none: #9aa5b5; --c-unanswered: #d3d9e2;
  --c-calls: #c9d6ee; --c-answered: #2f66d0;
  --radius: 8px; --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 1px 1px rgba(20, 30, 50, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 14px/1.45 -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--ink); }
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; font-weight: 600; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }

/* ---------- кнопки и поля ---------- */
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 6px;
  padding: 7px 14px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #c5ccd7; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }
input, select { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 7px 10px; }
input:focus, select:focus, .btn:focus-visible, .chip:focus-visible, th button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- вход ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.login-card h1 { margin: 18px 0 16px; }
.login-card label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.login-card input { display: block; width: 100%; margin-top: 4px; }
.form-error { color: var(--bad); min-height: 1.4em; margin: 10px 0 0; }

/* ---------- каркас ---------- */
.shell { display: grid; grid-template-columns: 216px 1fr; grid-template-rows: 52px 1fr; min-height: 100vh; }
.side { grid-row: 1 / 3; background: var(--side); color: var(--side-ink); padding: 14px 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; color: #fff; padding: 0 18px 16px; }
.brand-dark { color: var(--ink); padding: 0; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; inset: 7px 6px; border: 2px solid #fff; border-width: 0 0 2px 2px; transform: skewX(-12deg); }
.nav-item { display: flex; align-items: center; gap: 10px; color: var(--side-ink); padding: 9px 18px; font-size: 13px; white-space: nowrap; }
.nav-item svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-sep { display: block; height: 1px; background: rgba(255, 255, 255, .08); margin: 10px 18px; }
.nav-item:hover { text-decoration: none; color: #fff; }
.nav-item.active { background: var(--side-active); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.top-right { display: flex; align-items: center; gap: 12px; }
.updated, .who { color: var(--muted); font-size: 13px; }
.view { padding: 20px; min-width: 0; }

/* ---------- панели ---------- */
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.card-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; align-items: center; gap: 12px; justify-content: space-between; }
.card-body { padding: 16px 20px; }
.page-title { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 16px; }
.back { display: inline-block; margin-bottom: 10px; font-size: 13px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { font: inherit; font-size: 13px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 999px; padding: 5px 12px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.custom-range { display: inline-flex; gap: 6px; align-items: center; }
.custom-range input { padding: 4px 8px; font-size: 13px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search { position: relative; }
.search input { width: 260px; max-width: 100%; padding-right: 30px; }
.search button { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 16px; padding: 2px 6px; }

/* ---------- KPI ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.tile { background: var(--panel-2); border-radius: var(--radius); padding: 12px 14px; }
.tile-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.tile-value { font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }

.kv { display: grid; grid-template-columns: minmax(140px, 45%) 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; font-variant-numeric: tabular-nums; }

/* ---------- статус ---------- */
.pill { display: inline-block; font-size: 12px; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.pill-running { background: var(--warn-soft); color: var(--warn); }
.pill-finished { background: var(--ok-soft); color: var(--ok); }

/* ---------- таблицы ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel-2); white-space: nowrap; }
th button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
th button[aria-sort="ascending"]::after { content: " ▲"; font-size: 9px; }
th button[aria-sort="descending"]::after { content: " ▼"; font-size: 9px; }
td.r, th.r { text-align: right; }
tbody tr:hover { background: #f9fafc; }
tbody tr.clickable { cursor: pointer; }
tfoot td { font-weight: 600; background: var(--panel-2); border-bottom: 0; }
.title-cell { min-width: 240px; }
.title-cell a { font-weight: 500; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }
.best { background: var(--ok-soft); }
.tag-best { font-size: 11px; color: var(--ok); margin-left: 6px; }
.reply { max-width: 420px; }

.pager { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 20px; }
.pager .chips .chip { min-width: 34px; text-align: center; }

/* ---------- вкладки ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 20px; overflow-x: auto; }
.tab { font: inherit; background: none; border: 0; border-bottom: 2px solid transparent; padding: 12px 10px; color: var(--muted); cursor: pointer; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 500; }

/* ---------- графики ---------- */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
.donut-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 24px; }
.donut { width: 220px; height: 220px; flex: none; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend .sw { width: 12px; height: 12px; border-radius: 3px; flex: none; }
.legend .lv { margin-left: auto; padding-left: 16px; font-variant-numeric: tabular-nums; color: var(--muted); }
.chart { width: 100%; height: auto; display: block; }
.chart text { font-size: 11px; fill: var(--muted); }
.chart .grid { stroke: var(--line); }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.chart-legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; background: var(--sw); }

audio { height: 32px; width: 220px; max-width: 100%; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto 1fr; }
  .side, .top, .view { min-width: 0; }
  .side { grid-row: auto; display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; }
  .brand { padding: 0; }
  .side { flex-wrap: wrap; gap: 8px; }
  .side nav { display: flex; overflow-x: auto; width: 100%; scrollbar-width: none; }
  .nav-sep { display: none; }
  .nav-item { padding: 6px 10px; }
  .nav-item.active { box-shadow: inset 0 -2px 0 var(--accent); }
  .top { padding: 8px 16px; flex-wrap: wrap; height: auto; }
  .view { padding: 16px; }
  .card-head, .card-body, .pager { padding-left: 16px; padding-right: 16px; }
  .tabs { padding: 0 8px; }
  .search input { width: 100%; }
  .search, .toolbar select { flex: 1 1 100%; }
  .donut { width: 180px; height: 180px; }
  .kv { grid-template-columns: 1fr 1fr; }

  /* таблицы-списки превращаются в карточки */
  table.stack thead { display: none; }
  table.stack, table.stack tbody, table.stack tfoot { display: block; }
  table.stack tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  table.stack td { display: block; padding: 0; border: 0; text-align: left; min-width: 0; }
  table.stack td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); }
  table.stack td.title-cell, table.stack td.wide { grid-column: 1 / -1; min-width: 0; font-weight: 500; }
  table.stack td.cell-date { grid-column: 1 / 3; }
  table.stack td.cell-status { grid-column: 3; grid-row: 1; align-self: end; justify-self: end; }
  table.stack td.span2 { grid-column: span 2; }
  table.stack .m-hide { display: none; }
  table.stack td.cell-action:empty { display: none; }
  table.stack td.cell-action { grid-column: 1 / -1; }
  table.stack tfoot tr { background: var(--panel-2); }
}

/* ---------- разделы ---------- */
.two-col { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; }
@media (max-width: 900px) { .two-col { grid-template-columns: 1fr; } }
.list-plain { list-style: none; margin: 0; padding: 0; }
.list-plain li { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.list-plain li:last-child { border-bottom: 0; }
.list-plain .sub { color: var(--muted); font-size: 12px; }
.report-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.report { border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.report p { margin: 0; color: var(--muted); }
.report .btn { align-self: flex-start; }
.form-narrow { max-width: 380px; }
.form-narrow label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.form-narrow input { display: block; width: 100%; margin-top: 4px; }
.form-ok { color: var(--ok); min-height: 1.4em; margin: 10px 0 0; }
.faq dt { font-weight: 600; margin-top: 14px; }
.faq dd { margin: 4px 0 0; color: var(--muted); }
.bar-inline { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; min-width: 60px; }
.bar-inline span { display: block; height: 100%; background: var(--c-lead); }
