
:root {
  color-scheme: light;
  --bg: #f4f5f7; --surface: #ffffff; --surface-2: #f9fafb;
  --border: #e5e7eb; --border-strong: #d1d5db;
  --text: #111827; --text-2: #374151; --muted: #6b7280;
  --primary: #4f46e5; --primary-hover: #4338ca; --primary-soft: #eef2ff;
  --danger: #dc2626; --danger-soft: #fef2f2;
  --ok: #15803d; --ok-soft: #f0fdf4;
  --warn: #b45309; --warn-soft: #fffbeb;
  --sidebar: #0f172a; --sidebar-hover: #1e293b; --sidebar-text: #cbd5e1; --sidebar-muted: #64748b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 1px 3px rgba(16, 24, 40, 0.08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.icon { width: 18px; height: 18px; flex: none; }

/* Каркас: боковое меню и содержимое */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 252px; flex: none; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; gap: 18px; padding: 18px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 6px; color: #fff; text-decoration: none; }
.brand:hover { text-decoration: none; }
.logo { display: inline-flex; align-items: center; justify-content: center; width: 34px; height: 34px; border-radius: 9px; background: var(--primary); color: #fff; flex: none; }
.logo .icon { width: 19px; height: 19px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text b { font-size: 15px; font-weight: 650; }
.brand-text small { color: var(--sidebar-muted); font-size: 12px; margin-top: 2px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-label { padding: 0 10px 4px; font-size: 11px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--sidebar-muted); }
.nav-caption { padding: 0 10px 8px; color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-link { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--sidebar-text); text-decoration: none; font-weight: 500; }
.nav-link:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.sidebar-foot { margin-top: auto; border-top: 1px solid #1e293b; padding-top: 14px; display: flex; flex-direction: column; gap: 10px; }
.user { display: flex; align-items: center; gap: 10px; padding: 0 6px; min-width: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: #334155; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; flex: none; }
.user-info { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.user-info .email { color: #fff; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info small { color: var(--sidebar-muted); font-size: 12px; }
.content { flex: 1; min-width: 0; }
main { max-width: 1180px; margin: 0 auto; padding: 28px 32px 56px; }
.topbar { display: none; }
.nav-toggle, .scrim { display: none; }

/* Шапка страницы */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
h1 { margin: 0; font-size: 24px; line-height: 1.25; font-weight: 650; letter-spacing: -0.01em; }
.crumb { margin: 4px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
h2 { margin: 28px 0 10px; font-size: 16px; font-weight: 650; }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
small { color: var(--muted); }

/* Кнопки */
button, .button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 38px; padding: 0 16px; font: inherit; font-weight: 550; border: 1px solid var(--primary); border-radius: 8px; background: var(--primary); color: #fff; cursor: pointer; text-decoration: none; transition: background 0.15s, border-color 0.15s, box-shadow 0.15s; white-space: nowrap; }
button:hover, .button:hover { background: var(--primary-hover); border-color: var(--primary-hover); text-decoration: none; }
button.secondary, .button.secondary { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); }
button.secondary:hover, .button.secondary:hover { background: var(--surface-2); border-color: #9ca3af; }
button.danger { background: var(--surface); color: var(--danger); border-color: #fca5a5; }
button.danger:hover { background: var(--danger-soft); }
button.ghost { width: 100%; justify-content: flex-start; background: transparent; border-color: transparent; color: var(--sidebar-text); height: 36px; padding: 0 10px; font-weight: 500; }
button.ghost:hover { background: var(--sidebar-hover); color: #fff; }
td button, td .button { height: 32px; padding: 0 12px; font-size: 13px; }
form.inline { display: inline; margin: 0; }
:focus-visible { outline: 3px solid rgba(79, 70, 229, 0.45); outline-offset: 1px; }

/* Формы */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; margin-bottom: 18px; box-shadow: var(--shadow); }
.card > h2:first-child { margin-top: 0; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px 4px; margin: 0 0 16px; }
legend { font-weight: 600; padding: 0 6px; }
.card.narrow, .narrow { max-width: 440px; }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; margin-bottom: 6px; font-weight: 600; color: var(--text-2); }
.field small { display: block; margin-top: 5px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea { width: 100%; max-width: 680px; height: 38px; padding: 0 12px; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; transition: border-color 0.15s, box-shadow 0.15s; }
textarea { height: auto; min-height: 90px; padding: 10px 12px; max-width: 100%; line-height: 1.5; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: #9ca3af; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.18); }
input[type=color] { width: 56px; height: 38px; padding: 3px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); cursor: pointer; }
select { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; background-size: 16px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 6px; }
td.actions { margin: 0; }

/* Панель фильтров */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 16px; padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.filters .field { margin: 0; }
.filters .check { margin: 0 0 8px; }
.filters input[type=text] { width: 260px; }
.filters select { width: 180px; }

/* Сообщения */
.flash { display: flex; gap: 8px; padding: 11px 14px; margin: 0 0 16px; border-radius: 8px; border: 1px solid transparent; border-left-width: 4px; font-weight: 500; }
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: #bbf7d0; border-left-color: var(--ok); }
.flash.error { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; border-left-color: var(--danger); }
.flash.warn { background: var(--warn-soft); color: #92400e; border-color: #fde68a; border-left-color: #f59e0b; }

/* Таблицы */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 16px; text-align: left; font-size: 12px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafbfc; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.muted { text-align: center; padding: 32px 16px; }
td a { font-weight: 550; }
td.nowrap, td time.dt { white-space: nowrap; }
.excerpt { margin-top: 4px; font-size: 13px; font-weight: 400; }
mark { background: #fde68a; color: inherit; padding: 0 2px; border-radius: 3px; }
.badge { display: inline-flex; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 550; background: #f3f4f6; color: var(--text-2); margin-right: 4px; }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.error { background: #fee2e2; color: #991b1b; }
tr.rejected td { color: var(--muted); background: var(--surface-2); }
tr.rejected td a { color: var(--muted); text-decoration: line-through; }
.source-box { white-space: pre-wrap; max-height: 420px; overflow: auto; padding: 12px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: minmax(0, 1fr); } }
.full-text { margin-top: 4px; }
.full-text summary { cursor: pointer; }
.full-text[open] summary .excerpt { display: none; }
.full-text summary .less { display: none; }
.full-text[open] summary .more { display: none; }
.full-text[open] summary .less { display: inline; }
.full-text .source-box { margin-top: 6px; max-height: 260px; }
.more { color: var(--muted); font-size: 12px; font-style: italic; }
.dup-group { border: 1px solid var(--border); border-radius: 8px; margin: 10px 0; }
.dup-item { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; padding: 10px 14px; }
.dup-item + .dup-item { border-top: 1px solid var(--border); }
input[type=file] { padding: 8px; background: var(--surface); }
.pager { display: flex; gap: 16px; align-items: center; margin: 16px 0; color: var(--muted); }

/* Карточки показателей */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 14px; }
.cards .card { margin: 0; padding: 18px 20px; }
.cards .card b { display: block; font-size: 28px; line-height: 1.15; font-weight: 650; letter-spacing: -0.02em; }
.cards .card span { display: block; margin-top: 4px; color: var(--muted); font-size: 13px; }
.cards .card small { display: block; margin-top: 2px; font-size: 12px; }
/* Воронка: доля перехода рядом с числом, строка итогов */
td.num small { margin-left: 4px; font-size: 12px; }
tfoot td { font-weight: 600; border-top: 1px solid var(--border); }

/* Заполнение лимита */
progress { display: block; width: 100%; max-width: 360px; height: 8px; margin-top: 10px; appearance: none; border: 0; border-radius: 999px; background: #e5e7eb; overflow: hidden; }
progress::-webkit-progress-bar { background: #e5e7eb; border-radius: 999px; }
progress::-webkit-progress-value { background: var(--primary); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--primary); border-radius: 999px; }
progress.over::-webkit-progress-value { background: var(--danger); }
progress.over::-moz-progress-bar { background: var(--danger); }

/* Переписка */
.msg { max-width: 780px; padding: 11px 14px; margin: 10px 0; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { background: var(--primary-soft); border: 1px solid #c7d2fe; margin-left: auto; }
.msg.assistant { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.msg.assistant.unanswered { border-color: #f59e0b; background: var(--warn-soft); }
.msg small { display: block; margin-top: 6px; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
pre.pre, code.pre { display: block; padding: 12px 14px; background: #0f172a; color: #e2e8f0; border-radius: 8px; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* Страница входа и ошибок */
body.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: linear-gradient(135deg, #eef2ff 0%, #f4f5f7 55%, #e0e7ff 100%); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 32px; box-shadow: 0 10px 30px rgba(15, 23, 42, 0.1); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; font-size: 16px; }
.auth-card h1 { font-size: 22px; margin-bottom: 18px; }
.auth-card .card { border: 0; box-shadow: none; padding: 0; margin: 0; max-width: none; }
.auth-card .button, .auth-card form button { width: 100%; }

/* Телефон и планшет */
@media (max-width: 900px) {
  .topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--sidebar); color: #fff; position: sticky; top: 0; z-index: 20; }
  .burger { display: inline-flex; width: 38px; height: 38px; align-items: center; justify-content: center; border-radius: 8px; cursor: pointer; }
  .burger:hover { background: var(--sidebar-hover); }
  .topbar-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: 0 0 40px rgba(0, 0, 0, 0.35); }
  .nav-toggle { display: block; position: fixed; left: -9999px; }
  .nav-toggle:checked ~ .shell .sidebar { transform: none; }
  .nav-toggle:focus-visible ~ .shell .burger { outline: 3px solid rgba(79, 70, 229, 0.6); }
  .nav-toggle:checked ~ .scrim { display: block; position: fixed; inset: 0; z-index: 30; background: rgba(15, 23, 42, 0.5); }
  main { padding: 20px 16px 40px; }
  .filters input[type=text], .filters select { width: 100%; }
  .filters .field { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
