/* AI-контроль лидов: дизайн-система v2. Без внешних ресурсов (CSP default-src 'self'). */
:root {
  --bg: #F4F6F9;
  --card: #FFFFFF;
  --line: #E5E9F0;
  --sep: #EEF1F5;
  --text: #0F172A;
  --muted: #5B6577;
  --nav: #13233B;
  --nav-accent: #3FB8F0;
  --link: #2563EB;
  --link-h: #1D4ED8;
  --ctl-line: #D5DBE3;
  --head-bg: #F8FAFC;
  --ok: #15803D;   --ok-bg: #E7F6EC;
  --info: #2563EB; --info-bg: #E8EFFD;
  --bad: #B42318;  --bad-bg: #FDECEC;
  --mid: #B45309;  --mid-bg: #FEF3E2;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  font-feature-settings: 'tnum' 1;
  font-size: 14px; line-height: 1.5;
  overflow-x: hidden;
}
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-h); text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.25; }
h2 { font-size: 15px; font-weight: 600; margin-bottom: 12px; }
h3 { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
ul { margin: 0; padding-left: 20px; }
li + li { margin-top: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.txt-bad { color: var(--bad); }
svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
svg.i-sm { width: 14px; height: 14px; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; border-radius: 4px; }
.side :focus-visible { outline-color: #fff; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* Каркас */
.app { display: flex; min-height: 100vh; }
.side { width: 232px; flex: none; background: var(--nav); color: rgba(255,255,255,.72); padding: 18px 12px; }
.brand { display: block; color: #fff; font-size: 18px; font-weight: 600; padding: 0 10px 18px; }
.brand b { font-weight: 600; color: var(--nav-accent); }
.brand:hover { text-decoration: none; color: #fff; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 12px; border-radius: 8px; color: rgba(255,255,255,.72); }
.nav a:hover { background: rgba(255,255,255,.05); color: #fff; text-decoration: none; }
.nav a[aria-current="page"] { background: rgba(255,255,255,.08); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--nav-accent); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; justify-content: flex-end; gap: 12px; min-height: 48px; padding: 6px 24px; background: #fff; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.top form { margin: 0; }
.who { display: flex; align-items: center; gap: 6px; }
.content { padding: 24px 28px 40px; width: 100%; min-width: 0; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.sub { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* Карточки и сетки */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin-bottom: 16px; min-width: 0; }
.card > :last-child { margin-bottom: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 > div > .card:last-child { margin-bottom: 0; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; gap: 4px; }
.kpi .l { font-size: 12px; font-weight: 500; color: var(--muted); }
.kpi .v { font-size: 28px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
.kpi .s { font-size: 12px; color: var(--muted); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }

/* Кнопки и формы */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px; padding: 6px 16px; font: inherit; font-weight: 600; color: var(--text); background: #fff; border: 1px solid var(--ctl-line); border-radius: 8px; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--head-bg); color: var(--text); text-decoration: none; }
.btn-primary { background: var(--link); border-color: var(--link); color: #fff; }
.btn-primary:hover { background: var(--link-h); border-color: var(--link-h); color: #fff; }
.btn-danger { color: var(--bad); }
.btn-sm { min-height: 30px; padding: 3px 12px; font-size: 13px; }
.btn-icon { min-width: 30px; padding: 3px 6px; }
form.inline { display: inline; margin: 0; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  width: 100%; min-height: 36px; padding: 6px 10px; font: inherit; color: var(--text); background: #fff; border: 1px solid var(--ctl-line); border-radius: 8px;
}
textarea { min-height: 120px; resize: vertical; line-height: 1.45; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; border-color: var(--link); }
.diff-up { color: var(--ok); } .diff-down { color: var(--bad); }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; margin: 0; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--link); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.filters .f { flex: 1 1 200px; min-width: 0; }
.filters .f-btn { display: flex; gap: 8px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 16px; }
.toolbar form { display: flex; gap: 8px; align-items: flex-end; margin: 0; flex-wrap: wrap; }
.toolbar .f { min-width: 160px; }
.toolbar .f.grow { flex: 1 1 220px; }

/* Segmented control */
.seg { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; background: var(--sep); border-radius: 8px; max-width: 100%; }
.seg a { display: inline-flex; align-items: center; gap: 6px; min-height: 30px; padding: 0 12px; border-radius: 6px; color: var(--muted); font-weight: 500; font-size: 13px; white-space: nowrap; }
.seg a:hover { color: var(--text); text-decoration: none; }
.seg a[aria-current="true"], .seg a[aria-current="page"] { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(16,24,40,.06); }
.seg .cnt { font-size: 12px; color: var(--muted); font-weight: 500; }
.seg-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; display: block; }

/* Таблицы */
.table-wrap { overflow-x: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--sep); }
th { font-size: 12px; font-weight: 500; color: var(--muted); background: var(--head-bg); white-space: nowrap; }
tbody tr { height: 48px; }
tbody tr:hover { background: var(--head-bg); }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; }
.card .table-wrap { margin: 0 -20px; }
.card .table-wrap th:first-child, .card .table-wrap td:first-child { padding-left: 20px; }
.card .table-wrap th:last-child, .card .table-wrap td:last-child { padding-right: 20px; }
tr.no-touch { background: var(--bad-bg); background: #FFF7F7; }
tr.no-touch:hover { background: #FFF1F1; }
tr.no-touch td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
.cell-title { font-weight: 500; }
.cell-sub { font-size: 12px; color: var(--muted); }

/* Бейджи, оценки */
.badge { display: inline-flex; align-items: center; height: 22px; padding: 0 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--sep); color: #3F4A5C; white-space: nowrap; }
.st-done, .risk-low, .kind-success { background: var(--ok-bg); color: var(--ok); }
.st-error, .risk-high, .kind-lost { background: var(--bad-bg); color: var(--bad); }
.st-running, .kind-handoff { background: var(--info-bg); color: #1D4ED8; }
.risk-mid { background: var(--mid-bg); color: var(--mid); }
.env { background: var(--info-bg); color: #1D4ED8; text-transform: uppercase; letter-spacing: .4px; }
.score { display: inline-block; min-width: 40px; padding: 2px 8px; border-radius: 6px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; }
.score-good { background: var(--ok-bg); color: var(--ok); }
.score-mid { background: var(--mid-bg); color: var(--mid); }
.score-bad { background: var(--bad-bg); color: var(--bad); }
.score-xl { font-size: 40px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.1; padding: 8px 18px; border-radius: 10px; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; background: var(--info-bg); color: #1D4ED8; font-size: 12px; font-weight: 600; flex: none; }
.person { display: inline-flex; align-items: center; gap: 10px; }
.ch { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); margin-right: 10px; white-space: nowrap; }
.ch.zero { opacity: .55; }

/* Полосы */
.bar { height: 8px; background: var(--sep); border-radius: 4px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--link); border-radius: 4px; }
.bar.bad > span { background: var(--bad); }
.bar.good > span { background: var(--ok); }
.bar.mid > span { background: var(--mid); }
.stack { display: flex; gap: 2px; height: 8px; border-radius: 4px; overflow: hidden; background: #fff; min-width: 110px; }
.stack.lg { height: 20px; border-radius: 6px; }
.stack > span { display: block; height: 100%; }
.seg-ok { background: var(--ok); } .seg-info { background: var(--info); } .seg-bad { background: var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; margin-top: 10px; }
.legend b { font-weight: 600; }
.legend .ok { color: var(--ok); } .legend .info { color: var(--info); } .legend .bad { color: var(--bad); }
.rows { display: grid; gap: 10px; }
.row-bar { display: grid; grid-template-columns: minmax(0, 1fr) 160px 56px; gap: 10px; align-items: center; font-size: 13px; }
.row-bar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Тепловая карта */
.heat { border-collapse: separate; border-spacing: 4px; font-size: 13px; min-width: 760px; }
.heat th, .heat td { border: 0; }
.heat th { background: transparent; padding: 4px; font-weight: 500; text-align: center; white-space: normal; vertical-align: bottom; }
.heat th:first-child { text-align: left; }
.heat tbody tr { height: auto; }
.heat tbody tr:hover { background: transparent; }
.heat td { padding: 10px 4px; text-align: center; border-radius: 6px; color: var(--text); font-variant-numeric: tabular-nums; }
.heat td.row-name { text-align: left; font-weight: 500; white-space: nowrap; background: transparent; padding: 4px; }
.card .table-wrap.heat-wrap { margin: 0 -16px; }
.card .table-wrap.heat-wrap th:first-child, .card .table-wrap.heat-wrap td:first-child { padding-left: 4px; }
.card .table-wrap.heat-wrap th:last-child, .card .table-wrap.heat-wrap td:last-child { padding-right: 4px; }
.lv0 { background: #FFFFFF; box-shadow: inset 0 0 0 1px var(--line); color: var(--muted) !important; }
.lv1 { background: #FDECEC; } .lv2 { background: #FBD5D0; } .lv3 { background: #F6F7F9; }
.lv4 { background: #DCEBDD; } .lv5 { background: #C2E3C9; }
.heat-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.heat-legend i { display: inline-block; width: 28px; height: 12px; border-radius: 4px; }
.heat-legend i.lv3 { box-shadow: inset 0 0 0 1px var(--line); }

/* Требуют внимания */
.worst { display: grid; gap: 8px; }
.worst a { display: grid; grid-template-columns: 56px minmax(0, 2fr) minmax(0, 1fr) minmax(0, 2fr); gap: 12px; align-items: center; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--sep); color: var(--text); }
.worst a:hover { background: var(--head-bg); text-decoration: none; color: var(--text); }
.worst .t { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.worst .why { font-size: 12px; color: var(--bad); overflow-wrap: anywhere; }
.worst .who { font-size: 12px; color: var(--muted); }

/* Сообщения */
.flash, .notice { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; background: var(--info-bg); color: #1E3A8A; border: 1px solid #C7D7FA; }
.notice.warn { background: var(--mid-bg); color: #7A3A05; border-color: #F2D3A6; }
.notice.err { background: var(--bad-bg); color: #8A1B15; border-color: #F4C2BE; }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty p { margin-bottom: 14px; font-size: 15px; }

/* Карточка лида */
.meta-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.meta-line .out { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-weight: 500; }
.result-top { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; margin-bottom: 16px; }
.criteria { display: grid; gap: 14px; }
.criteria .head { display: flex; justify-content: space-between; gap: 12px; font-weight: 500; }
.criteria p { color: var(--muted); margin-top: 4px; font-size: 13px; }
.timeline { list-style: none; padding: 0; display: grid; gap: 8px; }
.timeline li { margin: 0; padding: 10px 12px; border: 1px solid var(--sep); border-left: 3px solid #C3CAD5; border-radius: 8px; background: #fff; }
.timeline .client { border-left-color: var(--nav-accent); background: #F7FBFE; }
.timeline .mgr { border-left-color: var(--link); }
.timeline .meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--muted); font-size: 12px; margin-bottom: 4px; }

/* Вход и ошибка */
.center-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--bg); }
.login { width: 100%; max-width: 380px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 32px 28px; }
.login .brand { color: var(--text); text-align: center; padding: 0 0 4px; font-size: 24px; }
.login .sub { text-align: center; margin-bottom: 22px; }
.login .field { margin-bottom: 14px; }
.login .btn { width: 100%; }
.err-code { font-size: 64px; font-weight: 600; color: var(--nav); line-height: 1; margin-bottom: 8px; }
.login.err-box { text-align: center; }
.login.err-box p { margin-bottom: 18px; }
.login.err-box .btn { width: auto; }

/* Настройки */
.agent { border-top: 1px solid var(--sep); padding: 14px 0; }
.agent:first-of-type { border-top: 0; padding-top: 0; }
.agent .head { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: baseline; margin-bottom: 10px; }
.agent .head b { font-size: 15px; }
.agent form > .form-row { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.stage-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px 16px; margin: 0 0 16px; padding: 0; border: 0; min-width: 0; }
fieldset legend { padding: 0; font-weight: 600; margin-bottom: 8px; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
.narrow { max-width: 220px; margin-bottom: 16px; }

/* Чипы: источники и движки */
.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 500; line-height: 1; white-space: nowrap; }
.chip svg { width: 12px; height: 12px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.chip-src { background: #F1F4F8; color: #334155; }
.chip-stt { background: #EEF2FF; color: #3730A3; }
.chip-stt-none { background: #FDECEC; color: #B42318; }
.chip-llm { background: #E8EFFD; color: #1D4ED8; }
.chip-meta { background: #fff; border: 1px solid #E5E9F0; color: #5B6577; }
.chips-note { margin: 6px 0 0; }
.timeline .meta .chip { margin-left: 0; }
.src-list { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
.src-list li { margin: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.src-list .src-label { flex: 1 1 auto; min-width: 0; }
.src-list .src-count { font-weight: 600; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; padding-top: 10px; border-top: 1px solid var(--sep); font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .side { width: 100%; padding: 8px 12px; }
  .brand { padding: 2px 6px 6px; font-size: 16px; }
  .nav { flex-direction: row; flex-wrap: wrap; gap: 4px; }
  .nav a { min-height: 36px; padding: 0 10px; }
  .nav a[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--nav-accent); }
  .top { padding: 6px 12px; }
  .content { padding: 16px 12px 32px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
  .row-bar { grid-template-columns: minmax(0, 1fr) 100px 40px; }
  .worst a { grid-template-columns: 56px minmax(0, 1fr); }
  .card, .kpi { padding: 16px; }
  .card .table-wrap { margin: 0 -16px; }
  .card .table-wrap th:first-child, .card .table-wrap td:first-child { padding-left: 16px; }
  .card .table-wrap th:last-child, .card .table-wrap td:last-child { padding-right: 16px; }
  h1 { font-size: 21px; }
}
.heat th.row-name { text-align: left; background: transparent; color: var(--text); font-size: 13px; font-weight: 500; white-space: nowrap; padding: 4px; vertical-align: middle; }

/* период: даты «с — по» */
.toolbar .f.dates { min-width: 0; }
.date-range { display: inline-flex; align-items: center; gap: 6px; }
.date-range input[type="date"] { width: 150px; }

/* по дням: две диаграммы с общей осью дней */
.txt-ok { color: var(--ok); } .txt-info { color: var(--info); }
.chart-title { font-size: 13px; font-weight: 600; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin: 4px 0 6px; }
.chart-title .lg { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--muted); }
.chart-title .lg i { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.chart-title .lg i.dot-few { border-radius: 50%; border: 1.5px solid var(--muted); background: #fff; }
.chart { display: block; width: 100%; height: auto; margin-bottom: 10px; overflow: visible; }
.chart .grid { stroke: var(--sep); stroke-width: 1; }
.chart .tick { font-size: 11px; fill: var(--muted); }
.chart .val { font-size: 11px; fill: var(--text); font-weight: 500; }
.chart .val.few { fill: var(--muted); font-weight: 400; }
.chart .hit { fill: transparent; }
.chart a:hover .hit { fill: var(--head-bg); }
.chart .bar-ok { fill: var(--ok); } .chart .bar-info { fill: var(--info); }
.chart .bar-bad { fill: var(--bad); } .chart .bar-other { fill: #CBD5E1; }
.chart-title .lg i.seg-other { background: #CBD5E1; }
.chart .avg-line { fill: none; stroke: var(--muted); stroke-width: 1.5; }
.chart .pt { fill: var(--text); }
.chart .pt-few { fill: #fff; stroke: var(--muted); stroke-width: 1.5; }
.daily .table-wrap { margin-top: 6px; }

/* сводки */
.digest-build { display: flex; gap: 8px; align-items: center; }
.digest-build input[type="date"] { width: 160px; }
.digest-last { margin-bottom: 24px; }
.digest-last > .card-head h2 { margin: 0 0 2px; }
.delta { font-weight: 600; margin-left: 4px; white-space: nowrap; }
.digest-archive-h { font-size: 15px; margin: 8px 0 10px; }
.digest-row { padding: 0; margin-bottom: 8px; }
.digest-row > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; padding: 14px 20px; cursor: pointer; list-style: none; }
.digest-row > summary::-webkit-details-marker { display: none; }
.digest-row > summary::before { content: "▸"; color: var(--muted); transition: transform .15s; }
.digest-row[open] > summary::before { transform: rotate(90deg); }
.digest-row > summary:hover { background: var(--head-bg); border-radius: 12px; }
.digest-row-body { padding: 0 20px 20px; }
.digest-row-body .kpi { padding: 16px; }
.digest-row-body .kpi .v { font-size: 22px; }
.digest-last .actions, .digest-row-body .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.digest-last .kpis, .digest-row-body .kpis { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
@media (max-width: 640px) { .digest-row > summary { padding: 12px 14px; } .digest-row-body { padding: 0 12px 14px; } }
