/* ОКК — общий стиль. Токены в :root, компоненты ниже. Без сборки и CDN. */
:root {
  /* цвета */
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef0f4;
  --border: #e4e7ec;
  --border-strong: #cfd4dc;
  --text: #101828;
  --text-2: #344054;
  --muted: #667085;
  --faint: #98a2b3;
  --primary: #2b50d6;
  --primary-hover: #2342b5;
  --primary-soft: #eef2fe;
  --primary-ring: rgba(43, 80, 214, .22);
  --success: #067647;
  --success-soft: #ecfdf3;
  --success-border: #abefc6;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --warning-border: #fedf89;
  --danger: #c01048;
  --danger-strong: #d92d20;
  --danger-soft: #fef3f2;
  --danger-border: #fecdca;
  --info: #175cd3;
  --info-soft: #eff8ff;
  --info-border: #b2ddff;
  /* баллы: высокий / средний / низкий */
  --score-high: #067647;
  --score-high-bg: #dcfae6;
  --score-mid: #b54708;
  --score-mid-bg: #fef0c7;
  --score-low: #d92d20;
  --score-low-bg: #fee4e2;
  /* отступы */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px;
  /* радиусы и тени */
  --r-sm: 6px; --r: 10px; --r-lg: 14px; --r-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
  --shadow-lg: 0 12px 32px -8px rgba(16, 24, 40, .16), 0 4px 8px -4px rgba(16, 24, 40, .06);
  /* шрифт */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-xs: 12px; --fs-sm: 13px; --fs: 14px; --fs-md: 16px; --fs-lg: 20px; --fs-xl: 26px;
  --page-max: 1280px;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: var(--fs)/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; color: var(--text); }
h1 { font-size: var(--fs-xl); font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: var(--fs-lg); font-weight: 600; }
h3 { font-size: var(--fs-md); font-weight: 600; }
p { margin: 0 0 var(--s3); }
code { font-family: var(--mono); font-size: .92em; }
:focus-visible { outline: 3px solid var(--primary-ring); outline-offset: 2px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.text-right { text-align: right; }
.num { font-variant-numeric: tabular-nums; }

/* --- шапка ---------------------------------------------------------------- */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(255, 255, 255, .92); backdrop-filter: saturate(180%) blur(8px); border-bottom: 1px solid var(--border); }
.topbar-inner { max-width: var(--page-max); margin: 0 auto; padding: 0 var(--s6); height: 60px; display: flex; align-items: center; gap: var(--s5); }
.brand { display: flex; align-items: center; gap: var(--s2); color: var(--text); font-weight: 700; font-size: 17px; letter-spacing: .02em; flex-shrink: 0; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: linear-gradient(135deg, #3b63f0, var(--primary)); display: grid; place-items: center; box-shadow: 0 2px 6px rgba(43, 80, 214, .35); }
.brand-mark svg { width: 18px; height: 18px; fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.brand-mark-lg { width: 44px; height: 44px; border-radius: 12px; }
.brand-mark-lg svg { width: 26px; height: 26px; }
.nav { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
@media (max-width: 760px) { .nav { -webkit-mask-image: linear-gradient(90deg, #000 88%, transparent); mask-image: linear-gradient(90deg, #000 88%, transparent); } }
.nav a { color: var(--muted); font-weight: 500; padding: 7px 12px; border-radius: var(--r-sm); white-space: nowrap; transition: background .15s, color .15s; }
.nav a:hover { color: var(--text); background: var(--surface-3); text-decoration: none; }
.nav a.active { color: var(--primary); background: var(--primary-soft); }
.userbox { display: flex; align-items: center; gap: var(--s2); margin-left: auto; flex-shrink: 0; }
.user-meta { display: flex; align-items: center; gap: var(--s2); color: var(--text); padding: 4px 8px 4px 4px; border-radius: var(--r-pill); }
.user-meta:hover { background: var(--surface-3); text-decoration: none; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-weight: 650; display: grid; place-items: center; font-size: var(--fs-sm); }
.user-text { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-weight: 550; font-size: var(--fs-sm); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { color: var(--muted); font-size: var(--fs-xs); }
.logout-form { margin: 0; }

/* --- страница ------------------------------------------------------------- */
.page { max-width: var(--page-max); margin: 0 auto; padding: var(--s5) var(--s6) var(--s7); }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--s4); margin-bottom: var(--s5); flex-wrap: wrap; }
.page-subtitle { color: var(--muted); margin: var(--s1) 0 0; }
.page-actions { display: flex; gap: var(--s2); flex-wrap: wrap; }
.breadcrumbs { font-size: var(--fs-sm); color: var(--muted); margin: 0 0 var(--s1); }
.breadcrumbs a { color: var(--muted); }
.narrow { max-width: 640px; margin-left: auto; margin-right: auto; }
.card.narrow { max-width: 560px; margin-top: var(--s6); }
.section { margin-top: var(--s6); }
.section-title { font-size: var(--fs-md); font-weight: 600; margin-bottom: var(--s3); }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s4); }
.stack > * + * { margin-top: var(--s4); }

/* --- карточки ------------------------------------------------------------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); padding: var(--s5); }
.card-flush { padding: 0; overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s4); }
.card-title { font-size: var(--fs-md); font-weight: 600; }

/* KPI-показатель */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: var(--s4); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4) var(--s5); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.kpi-label { color: var(--muted); font-size: var(--fs-sm); font-weight: 500; }
.kpi-value { font-size: 28px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
.kpi-unit { font-size: var(--fs-md); color: var(--muted); font-weight: 500; margin-left: 2px; }
.kpi-delta { font-size: var(--fs-xs); font-weight: 600; color: var(--muted); }
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--danger-strong); }
a.kpi:hover { border-color: var(--border-strong); text-decoration: none; box-shadow: var(--shadow); }

/* --- таблицы -------------------------------------------------------------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs); }
.table th, .table td { padding: 11px var(--s4); text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { background: var(--surface-2); color: var(--muted); font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table th.text-right, .table td.text-right { text-align: right; }
.row-muted td { color: var(--faint); }
.row-muted .cell-title { color: var(--muted); }
.cell-title { font-weight: 550; color: var(--text); }
.cell-sub { font-size: var(--fs-xs); color: var(--muted); }
/* сортируемые заголовки: <th class="sortable" aria-sort="ascending|descending"><a href="?sort=...">…</a></th> */
.table th.sortable a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.table th.sortable a:hover { color: var(--text); text-decoration: none; }
.table th.sortable a::after { content: "↕"; font-size: 11px; opacity: .45; }
.table th[aria-sort="ascending"] a::after { content: "↑"; opacity: 1; color: var(--primary); }
.table th[aria-sort="descending"] a::after { content: "↓"; opacity: 1; color: var(--primary); }
.table th[aria-sort] { color: var(--text); }
.pagination { display: flex; gap: var(--s2); align-items: center; justify-content: flex-end; padding: var(--s3) var(--s4); border-top: 1px solid var(--border); font-size: var(--fs-sm); color: var(--muted); }

/* --- фильтры ------------------------------------------------------------ */
.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s3); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4); margin-bottom: var(--s5); box-shadow: var(--shadow-sm); }
.filters .field { margin: 0; min-width: 150px; flex: 0 1 190px; }
.filters .field label { font-size: var(--fs-xs); }
.filters-actions { display: flex; gap: var(--s2); margin-left: auto; }

/* --- бейджи и баллы --------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; line-height: 18px; white-space: nowrap; border: 1px solid transparent; background: var(--surface-3); color: var(--text-2); }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .8; }
.badge-plain::before { display: none; }
.badge-neutral { background: var(--surface-3); color: var(--muted); border-color: var(--border); }
.badge-info { background: var(--info-soft); color: var(--info); border-color: var(--info-border); }
.badge-success { background: var(--success-soft); color: var(--success); border-color: var(--success-border); }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-border); }
.badge-danger { background: var(--danger-soft); color: var(--danger-strong); border-color: var(--danger-border); }
.badge-demo { background: #f4ebff; color: #6941c6; border-color: #e9d7fe; }
.score { display: inline-flex; align-items: center; justify-content: center; min-width: 44px; padding: 3px 8px; border-radius: var(--r-sm); font-weight: 700; font-variant-numeric: tabular-nums; font-size: var(--fs-sm); }
.score-high { background: var(--score-high-bg); color: var(--score-high); }
.score-mid { background: var(--score-mid-bg); color: var(--score-mid); }
.score-low { background: var(--score-low-bg); color: var(--score-low); }
.score-none { background: var(--surface-3); color: var(--faint); }

/* --- кнопки ---------------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 16px; border-radius: var(--r); border: 1px solid transparent; font: 550 var(--fs)/1 var(--font); cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, color .15s, box-shadow .15s; text-decoration: none; }
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface); color: var(--text-2); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger-strong); color: #fff; }
.btn-danger:hover { background: #b42318; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-ghost-danger { background: transparent; color: var(--danger-strong); }
.btn-ghost-danger:hover { background: var(--danger-soft); }
.btn-sm { height: 30px; padding: 0 10px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-block { width: 100%; }
form.inline { display: inline; margin: 0; }

/* --- формы ------------------------------------------------------------------ */
.form { display: flex; flex-direction: column; gap: var(--s4); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s4); }
.form-actions { display: flex; gap: var(--s2); align-items: center; flex-wrap: wrap; margin-top: var(--s2); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { font-weight: 550; font-size: var(--fs-sm); color: var(--text-2); }
.field .req { color: var(--danger-strong); }
.field input:not([type=checkbox]):not([type=radio]), .field select, .field textarea,
.filters input, .filters select {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface); color: var(--text); font: var(--fs) var(--font); box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
.field textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.field select, .filters select { appearance: none; padding-right: 34px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' stroke='%23667085' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.field select[multiple] { height: auto; min-height: 96px; padding: 6px; background-image: none; }
.field input:focus, .field select:focus, .field textarea:focus, .filters input:focus, .filters select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-ring); }
.field-check label { display: flex; align-items: center; gap: var(--s2); font-weight: 500; color: var(--text); cursor: pointer; }
.field-check input { width: 18px; height: 18px; accent-color: var(--primary); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger-strong); }
.field.has-error input:focus, .field.has-error select:focus { box-shadow: 0 0 0 3px rgba(217, 45, 32, .18); }
.field-error { color: var(--danger-strong); font-size: var(--fs-sm); margin: 0; }
.help { color: var(--muted); font-size: var(--fs-xs); margin: 0; }
.help ul { margin: 2px 0 0; padding-left: 16px; }
.help li + li { margin-top: 1px; }
.narrow > .alert, .page > .alert { margin-bottom: var(--s4); }

/* --- плашки ----------------------------------------------------------------- */
.messages { display: flex; flex-direction: column; gap: var(--s2); margin-bottom: var(--s4); }
.alert { padding: 12px 16px; border-radius: var(--r); border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); font-size: var(--fs); }
.alert-info { background: var(--info-soft); border-color: var(--info-border); color: #1849a9; }
.alert-success { background: var(--success-soft); border-color: var(--success-border); color: #05603a; }
.alert-warning { background: var(--warning-soft); border-color: var(--warning-border); color: #93370d; }
/* красная плашка-предупреждение: сбой источника, неоценённые, стерео < 100% */
.alert-danger { background: var(--danger-soft); border-color: var(--danger-border); color: #b42318; }
.alert-banner { display: flex; align-items: center; gap: var(--s3); border-left: 4px solid var(--danger-strong); font-weight: 500; }
.alert a { color: inherit; text-decoration: underline; }

/* --- пустое состояние ---------------------------------------------------------- */
.empty { text-align: center; padding: var(--s7) var(--s5); display: flex; flex-direction: column; align-items: center; }
.empty-icon { width: 52px; height: 52px; border-radius: 14px; background: var(--primary-soft); display: grid; place-items: center; margin-bottom: var(--s4); }
.empty-icon svg { width: 26px; height: 26px; fill: none; stroke: var(--primary); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.empty-icon.danger { background: var(--danger-soft); }
.empty-icon.danger svg { stroke: var(--danger-strong); }
.empty-title { font-size: var(--fs-md); font-weight: 600; margin-bottom: var(--s1); }
.empty-text { color: var(--muted); max-width: 420px; margin: 0 auto; }
.empty-actions { display: flex; gap: var(--s2); justify-content: center; margin-top: var(--s4); flex-wrap: wrap; }

/* --- пары «ключ — значение» -------------------------------------------------------- */
.kv { display: grid; grid-template-columns: 180px 1fr; gap: var(--s3) var(--s4); margin: var(--s4) 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; }
.copyable { background: var(--surface-3); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 3px 8px; user-select: all; }
.copyable.secret { font-size: var(--fs-md); letter-spacing: .04em; }

/* --- вход ------------------------------------------------------------------ */
.auth-body { background: radial-gradient(1200px 600px at 10% -10%, #e3e9ff 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #e6f4ff 0%, transparent 55%), var(--bg); }
.auth-layout { min-height: 100vh; display: grid; place-items: center; padding: var(--s5) var(--s4); }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); padding: var(--s6); }
.auth-brand { display: flex; align-items: center; gap: var(--s3); margin-bottom: var(--s6); }
.auth-title { font-weight: 750; font-size: 20px; letter-spacing: .03em; }
.auth-subtitle { color: var(--muted); font-size: var(--fs-sm); }
.auth-heading { font-size: var(--fs-lg); margin-bottom: var(--s4); }
.auth-card .alert { margin-bottom: var(--s4); }
.auth-card .btn-block { height: 42px; margin-top: var(--s1); }
.auth-note { color: var(--muted); font-size: var(--fs-sm); text-align: center; margin: var(--s5) 0 0; }

/* --- адаптив ------------------------------------------------------------------ */
@media (max-width: 1024px) {
  .topbar-inner { padding: 0 var(--s4); gap: var(--s3); }
  .page { padding: var(--s5) var(--s4) var(--s7); }
  .user-text { display: none; }
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .topbar-inner { height: auto; flex-wrap: wrap; padding: var(--s2) var(--s4) 0; row-gap: 0; }
  .nav { order: 3; flex-basis: 100%; margin: 0 calc(-1 * var(--s4)); padding: var(--s1) var(--s3) var(--s2); }
  h1 { font-size: 22px; }
  .page-header { align-items: flex-start; }
  .page-actions { width: 100%; }
  .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
  .kpi { padding: var(--s3) var(--s4); }
  .kpi-value { font-size: 22px; }
  .card { padding: var(--s4); border-radius: var(--r); }
  .card-flush { padding: 0; }
  .filters { padding: var(--s3); }
  .filters .field { flex: 1 1 140px; }
  .filters-actions { width: 100%; margin-left: 0; }
  .filters-actions .btn { flex: 1; }
  .table th, .table td { padding: 10px var(--s3); }
  .kv { grid-template-columns: 1fr; gap: 2px; }
  .kv dd { margin-bottom: var(--s2); }
  .auth-card { padding: var(--s5); }
}
