/* ---------- токены ---------- */
:root {
  --bg: #ffffff;
  --surface: #fafafa;
  --text: #171717;
  --muted: #6b6b6b;
  --line: #e7e7e7;
  --line-strong: #cfcfcf;
  --primary: #171717;
  --on-primary: #ffffff;
  --hover: #f4f4f4;
  --selected: #f2f2f2;
  --focus: #171717;
  --error: #c62828;
  --error-soft: #fdf3f3;
  --warn-bg: #fff8e1;
  --warn-text: #5c4400;
  --warn-icon: #c98a00;
  --ok-bg: #edf7f0;
  --ok-text: #14482b;
  --ok-icon: #2e7d4f;
  --bar: #171717;
  --bar-track: #ededed;

  --r: 10px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;
  --ease: cubic-bezier(.2, .7, .2, 1);
  color-scheme: light;
}
/* темная тема: по системе, если пользователь не выбрал светлую; или явно через переключатель */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111111;
    --surface: #171717;
    --text: #ededed;
    --muted: #9a9a9a;
    --line: #2a2a2a;
    --line-strong: #3d3d3d;
    --primary: #ededed;
    --on-primary: #111111;
    --hover: #1c1c1c;
    --selected: #222222;
    --focus: #ededed;
    --error: #ff8a80;
    --error-soft: #2a1716;
    --warn-bg: #2b2412;
    --warn-text: #f3dc9b;
    --warn-icon: #e0a91c;
    --ok-bg: #13261b;
    --ok-text: #b9e4c8;
    --ok-icon: #4fb57a;
    --bar: #ededed;
    --bar-track: #2a2a2a;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111111;
  --surface: #171717;
  --text: #ededed;
  --muted: #9a9a9a;
  --line: #2a2a2a;
  --line-strong: #3d3d3d;
  --primary: #ededed;
  --on-primary: #111111;
  --hover: #1c1c1c;
  --selected: #222222;
  --focus: #ededed;
  --error: #ff8a80;
  --error-soft: #2a1716;
  --warn-bg: #2b2412;
  --warn-text: #f3dc9b;
  --warn-icon: #e0a91c;
  --ok-bg: #13261b;
  --ok-text: #b9e4c8;
  --ok-icon: #4fb57a;
  --bar: #ededed;
  --bar-track: #2a2a2a;
  color-scheme: dark;
}

/* ---------- основа ---------- */
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-underline-offset: 3px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
button, label, input[type=radio], input[type=checkbox] { touch-action: manipulation; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

.wrap { max-width: 720px; margin: 0 auto; padding: var(--s7) var(--s4) var(--s8); }
.wrap-wide { max-width: 1200px; }
.wrap.wrap-matrix { max-width: 960px; }

h1 { font-size: 1.75rem; line-height: 1.25; font-weight: 650; letter-spacing: -0.02em; margin: 0; }
h2 { font-size: 1.125rem; font-weight: 600; margin: 0 0 var(--s4); }
h3 { font-size: .9375rem; font-weight: 600; margin: 0 0 var(--s2); }
p { margin: 0; }
.muted { color: var(--muted); }

/* ---------- опрос ---------- */
.progress { position: fixed; top: 0; left: 0; right: 0; height: 3px; z-index: 30; }
.progress-bar { height: 100%; width: 0; background: var(--primary); transition: width .3s var(--ease); }

.eyebrow { font-size: .8125rem; color: var(--muted); margin-bottom: var(--s2); font-variant-numeric: tabular-nums; }
.page-head { margin-bottom: var(--s6); }
.lead { color: var(--muted); margin-top: var(--s3); max-width: 62ch; }
.prose p + p { margin-top: var(--s4); }

.facts { list-style: none; margin: var(--s6) 0 0; padding: 0; border-top: 1px solid var(--line); }
.facts li { padding: var(--s3) 0; border-bottom: 1px solid var(--line); }

/* card в опросе — просто секция без рамки */
.card { margin-bottom: var(--s6); }

fieldset.q { border: 0; padding: var(--s5) 0 0; margin: var(--s5) 0 0; min-width: 0; border-top: 1px solid var(--line); }
.card > fieldset.q:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
legend { display: block; float: left; width: 100%; font-weight: 600; font-size: 1.0625rem; line-height: 1.4; padding: 0; margin-bottom: var(--s2); }
legend + * { clear: both; }
.qnum { color: var(--muted); font-weight: 500; font-variant-numeric: tabular-nums; margin-right: var(--s2); }
.hint { color: var(--muted); font-size: .9375rem; margin: 0 0 var(--s4); clear: both; }
.sub { margin-top: var(--s3); }

.input {
  display: block; width: 100%; font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line-strong); border-radius: var(--r); padding: 12px 14px; margin-top: var(--s2);
  transition: border-color .15s var(--ease);
}
.input::placeholder { color: var(--muted); opacity: .8; }
.input:hover { border-color: var(--muted); }
.input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 1px var(--focus); }
textarea.input { resize: vertical; min-height: 112px; }
.input[aria-invalid="true"], .has-error > .input, .has-error .sub .input { border-color: var(--error); }

/* одиночный выбор — строки списка */
.options { display: grid; margin-top: var(--s2); border-top: 1px solid var(--line); }
.option {
  display: flex; gap: var(--s3); align-items: center; min-height: 48px; padding: var(--s2) var(--s2);
  border-bottom: 1px solid var(--line); cursor: pointer; transition: background .15s var(--ease);
}
.option:hover { background: var(--hover); }
.option:has(input:checked) { font-weight: 550; }
.option input, .check input { width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--primary); cursor: pointer; }

/* вопрос 6 — список процессов */
.dir { margin-top: var(--s6); }
.dir h3 { font-size: .8125rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: var(--s2); }
.check {
  display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s2);
  border-top: 1px solid var(--line); cursor: pointer; transition: background .15s var(--ease);
}
.dir .check:last-child { border-bottom: 1px solid var(--line); }
.check:hover { background: var(--hover); }
.check input { margin-top: 3px; }
.check.on { background: var(--selected); }
.check.off { cursor: not-allowed; }
.check.off .pname { opacity: .45; }
.pname { display: block; }
.pdesc { display: block; color: var(--muted); font-size: .875rem; line-height: 1.45; margin-top: 2px; }
.code { color: var(--muted); font-size: .8125rem; font-variant-numeric: tabular-nums; margin-right: var(--s2); font-weight: 500; }
.check .code { min-width: 2.4em; margin: 1px 0 0; }

.counter {
  position: sticky; top: var(--s3); z-index: 5; display: inline-block; margin-top: var(--s5);
  padding: 6px 14px; border-radius: 999px; font-size: .875rem; font-variant-numeric: tabular-nums;
  background: var(--bg); color: var(--text); border: 1px solid var(--line-strong);
}
.counter.ok { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

.callout { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--r); margin-top: var(--s3); }
.callout:first-child { margin-top: var(--s2); }
.callout svg { flex: none; width: 18px; height: 18px; margin-top: 3px; }
.callout-warn { background: var(--warn-bg); color: var(--warn-text); }
.callout-warn svg { color: var(--warn-icon); }
.callout-ok { background: var(--ok-bg); color: var(--ok-text); }
.callout-ok svg { color: var(--ok-icon); }

/* матрицы В7–В9 */
.grid-title { margin: var(--s6) 0 var(--s3); font-size: 1rem; }
.grid-title:first-of-type { margin-top: var(--s4); }
/* без overflow у обертки: иначе sticky-шапка прилипает к обертке, а не к экрану */
.grid-wrap { margin-top: var(--s2); }
table.grid { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 0; font-size: .9375rem; }
.grid thead th {
  position: sticky; top: 3px; z-index: 2; background: var(--bg);
  font-size: .8125rem; font-weight: 500; color: var(--muted); text-align: center; vertical-align: bottom;
  padding: var(--s3) var(--s1); line-height: 1.3; border-bottom: 1px solid var(--line-strong);
}
.grid thead th.corner { text-align: left; width: 28%; padding-left: 0; }
.grid tbody th { text-align: left; font-weight: 400; padding: var(--s3) var(--s3) var(--s3) 0; line-height: 1.4; }
.grid tbody td { text-align: center; padding: 0; }
.grid tbody tr > * { border-bottom: 1px solid var(--line); transition: background .15s var(--ease); }
.grid tbody tr:hover > * { background: var(--hover); }
.grid tbody tr.has-error > * { background: var(--error-soft); }
.grid tbody tr.has-error th { color: var(--error); }
.cell { display: flex; align-items: center; justify-content: center; min-height: 48px; padding: var(--s2) var(--s1); cursor: pointer; }
.cell input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); cursor: pointer; }
.m-label { display: none; }
@media (max-width: 900px) { .grid thead th { hyphens: auto; overflow-wrap: break-word; } }

@media (max-width: 640px) {
  .grid thead { display: none; }
  table.grid, .grid tbody, .grid tr, .grid tbody th, .grid tbody td { display: block; }
  .grid tbody tr { padding: var(--s4) 0; border-bottom: 1px solid var(--line); }
  .grid tbody tr > * { border: 0; }
  .grid tbody tr:hover > * { background: transparent; }
  .grid tbody tr.has-error { background: var(--error-soft); padding-left: var(--s3); padding-right: var(--s3); border-radius: var(--r); }
  .grid tbody tr.has-error > * { background: transparent; }
  .grid tbody th { padding: 0 0 var(--s2); font-weight: 500; }
  .grid tbody td { text-align: left; }
  .cell { justify-content: flex-start; gap: var(--s3); min-height: 44px; padding: 0; }
  .m-label { display: inline; }
}

/* ошибки, навигация */
.error { color: var(--error); font-size: .875rem; margin-top: var(--s2); }
.error-block { background: var(--error-soft); padding: var(--s3) var(--s4); border-radius: var(--r); margin-top: var(--s4); }

.nav { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); margin-top: var(--s6); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 48px;
  font: inherit; font-weight: 550; border: 1px solid var(--primary); border-radius: var(--r); padding: 0 var(--s5);
  background: var(--primary); color: var(--on-primary); cursor: pointer; text-decoration: none;
  transition: opacity .15s var(--ease), background .15s var(--ease);
}
.btn:hover { opacity: .88; }
.btn:active { opacity: .76; }
.btn:disabled { opacity: .5; cursor: progress; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line-strong); }
.btn-ghost:hover { opacity: 1; background: var(--hover); }
.btn-small { min-height: 36px; padding: 0 var(--s4); font-size: .875rem; }
.btn-danger { background: transparent; color: var(--error); border-color: currentColor; }
.btn-danger:hover { opacity: 1; background: var(--error-soft); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; }

@media (max-width: 560px) {
  .wrap { padding-top: var(--s8); }
  h1 { font-size: 1.5rem; }
  .nav .btn { flex: 1; }
  .nav > span:empty { display: none; }
}

/* ---------- админка ---------- */
.admin .card { border: 1px solid var(--line); border-radius: var(--r); padding: var(--s5); margin-bottom: 0; }
.admin .wrap { padding-top: var(--s6); }
.topbar { display: flex; flex-wrap: wrap; gap: var(--s3); align-items: center; justify-content: space-between; margin-bottom: var(--s5); }
.topbar h1 { font-size: 1.375rem; }
.actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.tabs { display: flex; gap: var(--s5); border-bottom: 1px solid var(--line); margin: var(--s5) 0; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.tab {
  font: inherit; font-size: .9375rem; background: none; border: 0; padding: var(--s3) 0; margin-bottom: -1px; cursor: pointer;
  color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 550; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0; margin-bottom: var(--s6); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.kpi { padding: var(--s4) var(--s4) var(--s4) 0; }
.kpi b { display: block; font-size: 1.75rem; font-weight: 600; line-height: 1.2; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; }
.kpi span { color: var(--muted); font-size: .875rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: var(--s4); }
.bars { display: grid; gap: var(--s3); }
.admin h2.section { font-size: 1rem; margin: var(--s7) 0 var(--s3); padding-top: var(--s5); border-top: 1px solid var(--line); }
.admin .kpis + h2.section { margin-top: 0; border-top: 0; padding-top: 0; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--s4); }
.grid3 .card { margin-bottom: 0; }
@media (min-width: 1000px) { .grid2 > .span2 { grid-column: span 2; } }
.grid2 > .full { grid-column: 1 / -1; }
.site { overflow-wrap: anywhere; word-break: break-all; max-width: 360px; }
.note { font-size: .8125rem; margin: var(--s3) 0; }
.scroll-y { max-height: 360px; overflow-y: auto; }
.answers-list { list-style: none; margin: 0; padding: 0; }
.answers-list li { padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.answers-list li:last-child { border-bottom: 0; }
.answers-list .muted { font-size: .8125rem; margin-bottom: 2px; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.barrow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px var(--s3); font-size: .875rem; }
.barrow .lbl { overflow-wrap: anywhere; }
.barrow .val { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.barrow .track { grid-column: 1 / -1; height: 6px; background: var(--bar-track); border-radius: 3px; overflow: hidden; }
.barrow .fill { height: 100%; background: var(--bar); border-radius: 3px; }
.table-wrap { overflow-x: auto; }
.admin table:not(.grid) { border-collapse: collapse; width: 100%; font-size: .875rem; }
.admin table:not(.grid) th, .admin table:not(.grid) td { text-align: left; padding: var(--s3) var(--s3) var(--s3) 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.admin table:not(.grid) th { color: var(--muted); font-weight: 500; font-size: .8125rem; line-height: 1.3; }
.admin table:not(.grid) th.num { min-width: 76px; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--text); }
td.num, th.num { text-align: right !important; font-variant-numeric: tabular-nums; }
td.pcell { min-width: 240px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--hover); }
tr.detail > td { background: var(--surface); padding: var(--s5) !important; }
tr.detail .grid2 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--s5); }
.filters { display: grid; grid-template-columns: 2fr repeat(2, minmax(0, 1fr)); gap: var(--s2); }
.filters .input { margin: 0; padding: 9px 12px; min-width: 0; }
@media (max-width: 760px) { .filters { grid-template-columns: 1fr 1fr; } .filters .input:first-child { grid-column: 1 / -1; } }
.login { max-width: 360px; margin: 14vh auto 0; }
.admin .login.card { padding: var(--s6); }
.login h1 { font-size: 1.375rem; margin-bottom: var(--s1); }
.login .input { margin-top: var(--s3); }
.login .btn { width: 100%; margin-top: var(--s4); }
dl.answers { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: var(--s2) var(--s4); margin: 0; }
dl.answers dt { color: var(--muted); }
dl.answers dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
@media (max-width: 560px) { dl.answers { grid-template-columns: 1fr; } dl.answers dd { margin-bottom: var(--s2); } }
dialog {
  border: 1px solid var(--line); border-radius: 14px; background: var(--bg); color: var(--text);
  width: min(920px, calc(100vw - 32px)); max-height: 85vh; padding: var(--s6);
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h3 { margin-top: var(--s6); }

/* переключатель темы */
.theme-toggle {
  position: fixed; top: var(--s3); right: var(--s3); z-index: 40; width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center; padding: 0;
  border: 1px solid var(--line); border-radius: 999px; background: var(--bg); color: var(--text); cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.theme-toggle:hover { background: var(--hover); border-color: var(--line-strong); }
.theme-toggle svg { width: 18px; height: 18px; }
.admin .theme-toggle { top: auto; bottom: var(--s4); right: var(--s4); }
