/* Оболочка и компоненты портала. Цвета и размеры — только через tokens.css. */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
/* Ссылка в интерфейсе — цветом; черта появляется при наведении. В таблице
   ролей или в карточке блока подчёркнутых ссылок подряд бывает с десяток,
   и постоянная черта превращает строку в помарки. В тексте документа
   правило обратное: там ссылку надо заметить посреди фразы, поэтому черта
   стоит всегда — см. `.doc-body a`.

   Цвет при наведении здесь намеренно не меняется: правило `a:hover`
   специфичнее, чем `.nav-item` или `.btn`, и перекрасило бы пункт меню
   на тёмном фоне и текст кнопки. Где сдвиг цвета нужен, он задаётся
   компонентом — так сделано у ссылки в тексте документа. */
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
button { font: inherit; }
code { font-family: var(--mono); font-size: .9em; background: var(--line-2); padding: 1px 5px; border-radius: 5px; }
:focus-visible { outline: 2px solid var(--green-2); outline-offset: 2px; }
body.no-scroll { overflow: hidden; }

/* ===== Каркас: меню слева, шапка сверху, контент ===== */
.app {
  display: grid;
  grid-template-columns: var(--side-w) minmax(0, 1fr);
  grid-template-rows: var(--top-h) 1fr;
  grid-template-areas: "side top" "side main";
  min-height: 100vh;
}

/* ===== Боковое меню ===== */
.sidebar {
  grid-area: side;
  position: sticky; top: 0;
  height: 100vh;
  display: flex; flex-direction: column;
  background: var(--side);
  color: var(--side-text);
  border-right: 1px solid var(--side-line);
}
.sidebar-head {
  display: flex; align-items: center; gap: 10px; flex: 0 0 auto;
  height: var(--top-h); padding: 0 12px 0 18px;
  border-bottom: 1px solid var(--side-line);
}
.brand {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;
  color: var(--on-color); text-decoration: none; font-weight: 800; font-size: 15px;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 8px; flex: 0 0 auto; position: relative;
  background: linear-gradient(135deg, var(--lime), var(--green-2));
}
.brand-mark::after {
  content: ""; position: absolute; right: 5px; bottom: 5px;
  width: 8px; height: 8px; border-radius: 3px; background: var(--side);
}
.brand-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav { overflow-y: auto; flex: 1; padding: 10px 10px 24px; }
.nav-group {
  color: var(--side-muted);
  font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  padding: 16px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; margin-bottom: 2px; border-radius: var(--radius-sm);
  color: var(--side-text); text-decoration: none; font-size: 13.5px;
}
.nav-item:hover { background: var(--side-2); text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--green); color: var(--on-green); font-weight: 700; }
.nav-item svg { flex: 0 0 auto; }

/* ===== Шапка ===== */
.topbar {
  grid-area: top;
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.icon-btn {
  width: 38px; height: 38px; flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card); color: var(--ink-2); cursor: pointer;
}
.icon-btn:hover { background: var(--bg); }
/* Кнопки меню нужны только на узком экране — см. адаптив ниже */
.menu-btn, .sidebar-close { display: none; }
.tb-title { min-width: 0; font-weight: 700; font-size: 15px; line-height: 1.25; }
.tb-title span, .tb-title small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-title small { font-weight: 400; font-size: 11.5px; color: var(--muted); }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 10px; flex: 0 0 auto; }
/* Кто вошёл, в какой роли и что его ждёт — в шапке. Порядок тот же, что
   в кабинете-референсе: поиск слева от правого края, дальше роль,
   уведомления, человек. */
.tb-search { margin-left: 8px; flex: 1; max-width: 380px; position: relative; display: flex; }
.tb-search input {
  width: 100%; padding: 8px 12px 8px 34px; font-size: 13px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--ink); outline: none;
}
.tb-search input:focus { border-color: var(--green-2); background: var(--card); }
.tb-search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.rolepick {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 4px 9px;
}
.rolepick .rl { font-size: 10.5px; color: var(--muted); }
.rolepick select, .rolepick b {
  border: 0; background: transparent; font-size: 13px; font-weight: 600;
  color: var(--ink); outline: none; max-width: 210px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rolepick select { cursor: pointer; }
.rolepick.is-odna { cursor: default; }
.tb-kolokol { position: relative; }
.tb-kolokol .bdg {
  position: absolute; top: -5px; right: -5px; min-width: 16px; height: 16px;
  padding: 0 4px; border-radius: 9px; background: var(--bad); color: var(--on-color);
  font-size: 9.5px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.avatar {
  width: 36px; height: 36px; flex: 0 0 auto; border-radius: 50%;
  background: linear-gradient(135deg, var(--green), var(--ink-green));
  color: var(--on-color); font-size: 12.5px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.tb-vyhod { display: flex; }

/* ===== Вход =====
   Страница входа без меню: человек ещё не вошёл, разделы ему недоступны.
   Тёмный фон — тот же род, что у бокового меню: портал узнаётся до входа. */
.vhod-page {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1100px 520px at 50% -10%, var(--auth-1), var(--auth-2) 72%);
}
.vhod-box { width: 100%; max-width: 430px; }
.vhod-card {
  background: var(--auth-card); border: 1px solid var(--auth-line);
  border-radius: 22px; padding: 32px 30px 26px; box-shadow: 0 40px 90px rgba(0, 0, 0, .5);
}
.vhod-brand { display: flex; align-items: center; gap: 11px; justify-content: center; }
.vhod-brand .mark {
  width: 32px; height: 32px; border-radius: 50%; border: 4px solid var(--lime);
  position: relative; flex: 0 0 auto;
}
.vhod-brand .mark::after {
  content: ""; position: absolute; right: -3px; bottom: -1px; width: 11px; height: 11px;
  border-radius: 50%; background: var(--green-2); border: 3px solid var(--auth-card);
}
.vhod-brand b { color: #fff; font-size: 19px; font-weight: 800; letter-spacing: .02em; }
.vhod-card h1 { color: #fff; font-size: 19px; margin: 16px 0 4px; text-align: center; }
.vhod-card .sub { color: var(--auth-muted); font-size: 13px; text-align: center; margin: 0 0 20px; }
.vhod-note {
  display: flex; gap: 8px; align-items: flex-start; margin: 4px 0 16px;
  background: var(--auth-note); border: 1px solid var(--auth-note-line);
  border-radius: 11px; padding: 10px 12px;
  color: var(--auth-note-text); font-size: 11.5px; line-height: 1.5;
}
.vhod-note svg { flex: 0 0 auto; margin-top: 1px; }
.vhod-btn {
  width: 100%; padding: 13px; border: 0; border-radius: 12px; cursor: pointer;
  font-size: 15px; font-weight: 700; text-align: center;
  background: linear-gradient(135deg, var(--green), var(--green-2)); color: var(--on-green);
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.vhod-btn:hover { filter: brightness(1.05); text-decoration: none; }
.vhod-lyudi { display: flex; flex-direction: column; gap: 8px; }
.vhod-lyudi .vhod-chelovek {
  width: 100%; padding: 11px 13px; border-radius: 11px; cursor: pointer;
  border: 1px solid var(--auth-field-line); background: var(--auth-field);
  color: #fff; font-size: 14px; text-align: left;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.vhod-lyudi .vhod-chelovek:hover { border-color: var(--green-2); }
.vhod-lyudi .kto { color: var(--auth-muted); font-size: 11.5px; }
.vhod-label { display: block; color: var(--auth-muted); font-size: 12px; margin: 0 0 8px; }
.vhod-snoska { color: var(--auth-muted); font-size: 11.5px; text-align: center; margin: 16px 0 0; }
.vhod-otkaz { color: #fff; font-size: 14px; line-height: 1.6; margin: 0 0 18px; }

/* ===== Уведомления и поиск ===== */
.signal { display: flex; gap: 12px; align-items: flex-start; }
.signal .znak {
  width: 36px; height: 36px; border-radius: 10px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center;
  background: var(--warn-bg); color: var(--warn);
}
.signal.is-bad .znak { background: var(--bad-bg); color: var(--bad); }
.signal h3 { margin: 0 0 3px; font-size: 14.5px; }
.signal p { margin: 0 0 8px; color: var(--text-2); font-size: 13px; }
.nahodka { display: block; padding: 11px 16px; border-bottom: 1px solid var(--line-2); }
.nahodka:last-child { border-bottom: 0; }
.nahodka:hover { background: var(--line-2); text-decoration: none; }
.nahodka b { display: block; font-size: 14px; color: var(--ink); font-weight: 600; }
.nahodka span { color: var(--muted); font-size: 12px; }

/* ===== Контент ===== *//* ===== Контент ===== */
.main { grid-area: main; min-width: 0; padding: 24px 26px 60px; }
.view { max-width: var(--content-max); margin: 0 auto; }

.pagehead { margin: 0 0 18px; }
.pagehead h1 { margin: 0 0 4px; font-size: 22px; line-height: 1.25; text-wrap: balance; }
.pagehead p { margin: 0; color: var(--muted); font-size: 13.5px; max-width: 75ch; }
.pagehead .meta-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; color: var(--muted); font-size: 13px; }

.backlink { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; text-decoration: none; margin-bottom: 12px; }
.backlink:hover { color: var(--ink); text-decoration: none; }

.section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 26px 0 12px; }
.section-head h2 { margin: 0; font-size: 16px; }
.section-head p { margin: 0; color: var(--muted); font-size: 13px; flex-basis: 100%; }

.meta { color: var(--muted); }
.empty { color: var(--muted); padding: 22px 16px; margin: 0; }
.note { color: var(--muted); font-size: 13px; margin: 10px 0 0; }

/* ===== KPI ===== */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 22px; }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px 16px; box-shadow: var(--shadow);
}
.kpi-label { color: var(--muted); font-size: 12px; }
.kpi-value { font-size: 24px; font-weight: 800; margin-top: 6px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 11.5px; margin-top: 4px; color: var(--muted); }
.kpi-sub.bad { color: var(--bad); }
.kpi-sub.ok { color: var(--ok); }

/* ===== Фильтры-чипы ===== */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip {
  font-size: 12.5px; padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--card); color: var(--text-2); text-decoration: none;
}
.chip:hover { border-color: var(--green-2); text-decoration: none; }
.chip[aria-current="true"] { background: var(--ink-green); border-color: var(--ink-green); color: var(--on-color); }

/* ===== Фильтр по уровню документа =====
   Уровень — не категория вперемешку, а лестница (level_order): сегменты
   одной полосы вместо отдельных таблеток чипов, номер перед названием
   явно показывает порядок. Форма намеренно другая, чтобы не читалось
   как второй такой же список блоков. */
.level-filter {
  /* inline-flex, а не flex: полоса шириной по содержимому, а не во всю
     строку — иначе фон и скругление последнего сегмента (Чек-лист)
     растягиваются пустым местом до правого края страницы */
  display: inline-flex; flex-wrap: wrap; max-width: 100%; margin-bottom: 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  background: var(--card); overflow: hidden;
}
.level-filter a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; font-size: 12.5px; color: var(--text-2); text-decoration: none;
  border-right: 1px solid var(--line);
}
.level-filter a:last-child { border-right: 0; }
.level-filter a:hover { background: var(--bg); text-decoration: none; }
.level-filter a[aria-current="true"] { background: var(--ink-green); color: var(--on-color); }
.level-n {
  font-family: var(--mono); font-size: 10.5px; color: var(--muted);
  min-width: 1.2em; text-align: center;
}
.level-filter a[aria-current="true"] .level-n { color: var(--lime); }
@media (max-width: 500px) {
  /* На телефоне — обратно на всю ширину: сегменты становятся строками
     списка, тут узкая проверенная по содержимому полоса неудобна. */
  .level-filter { display: flex; width: 100%; flex-direction: column; }
  .level-filter a { border-right: 0; border-bottom: 1px solid var(--line); }
  .level-filter a:last-child { border-bottom: 0; }
}

/* ===== Карточки разделов ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: 17px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 11px;
  transition: transform .15s, box-shadow .15s;
}
.card.is-link:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.card.is-idle { background: var(--card-idle); }
.card-top { display: flex; align-items: flex-start; gap: 12px; }
.tile {
  width: 44px; height: 44px; border-radius: 12px; flex: 0 0 auto;
  display: flex; align-items: center; justify-content: center; color: var(--on-color);
  background: var(--tile-green);
}
.tile-forest { background: var(--tile-forest); }
.tile-teal { background: var(--tile-teal); }
.tile-blue { background: var(--tile-blue); }
.tile-violet { background: var(--tile-violet); }
.tile-red { background: var(--tile-red); }
.tile-slate { background: var(--tile-slate); }
.card.is-idle .tile { filter: grayscale(.35); opacity: .85; }
.card h3 { margin: 0; font-size: 14.5px; line-height: 1.25; }
.card-group { color: var(--muted); font-size: 11.5px; margin-top: 2px; }
.card-desc { color: var(--text-2); font-size: 12.5px; line-height: 1.5; margin: 0; flex: 1; }
.card-bottom { display: flex; align-items: center; gap: 8px; }
.card-bottom .btn { margin-left: auto; }

/* ===== Кнопки =====
   .btn — основное действие, на экране одно. К нему по смыслу:
   .btn-secondary — второстепенное («Отмена», «Выгрузить»);
   .btn-ghost — тихое, в строках таблиц и рядом с другими кнопками;
   .btn-danger — необратимое («Удалить»).
   .btn-lg — высотой с поле формы. Недоступна — disabled у <button>,
   aria-disabled="true" у ссылки. Ряд кнопок — .actions. */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 12.5px; font-weight: 700; padding: 7px 13px; border-radius: 9px; white-space: nowrap;
  background: var(--green); color: var(--on-color); text-decoration: none; border: 0; cursor: pointer;
}
.btn:hover { filter: brightness(1.05); text-decoration: none; }
.btn svg { flex: 0 0 auto; margin-left: -2px; }
.btn-secondary { background: var(--card); color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--field-line); }
.btn-secondary:hover { filter: none; background: var(--bg); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { filter: none; background: var(--line-2); color: var(--ink); }
.btn-danger { background: var(--bad); color: var(--on-color); }
.btn-danger:hover { filter: brightness(1.12); }
.btn-lg { min-height: var(--control-h); padding: 0 16px; font-size: 13.5px; border-radius: var(--radius-sm); }
.btn:disabled, .btn[aria-disabled="true"] {
  background: var(--line-2); color: var(--muted); box-shadow: none; filter: none; cursor: not-allowed;
}
.btn[aria-disabled="true"] { pointer-events: none; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* ===== Поля форм =====
   Поле — .field: подпись .field-label, элемент, затем .field-hint или .field-error.
   Элемент — .input у <input> и <textarea>; <select class="input"> — внутри
   обёртки .select (стрелка). Поле с иконкой — внутри .input-icon.
   Ошибка — aria-invalid="true" на элементе. readonly — значение из другой
   системы (например, из 1С): видно и копируется, но в портале не правится. */
.form { display: flex; flex-direction: column; gap: 16px; max-width: 640px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-label { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field-label.req::after { content: " *"; color: var(--bad); }
.field-hint { font-size: 12px; color: var(--muted); }
.field-error { font-size: 12px; font-weight: 600; color: var(--bad); }

.input {
  width: 100%; height: var(--control-h); padding: 0 12px;
  font: inherit; font-size: 14px; color: var(--ink);
  background: var(--card); border: 1px solid var(--field-line); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
textarea.input { height: auto; min-height: 88px; padding: 9px 12px; line-height: 1.5; resize: vertical; }
.input::placeholder { color: var(--muted); opacity: 1; }
.input:hover { border-color: var(--field-line-hover); }
.input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--focus-ring); }
.input[aria-invalid="true"] { border-color: var(--bad); }
.input[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--focus-ring-bad); }
.input[readonly] { background: var(--bg); border-color: var(--line); }
.input[readonly]:focus { border-color: var(--field-line-hover); box-shadow: none; }
.input:disabled { background: var(--line-2); color: var(--muted); border-color: var(--line); cursor: not-allowed; }

.select { position: relative; display: block; }
.select .input { appearance: none; padding-right: 36px; cursor: pointer; }
.select::after {
  content: ""; position: absolute; right: 14px; top: 50%; margin-top: -5px;
  width: 7px; height: 7px; pointer-events: none;
  border-right: 1.8px solid var(--muted); border-bottom: 1.8px solid var(--muted); transform: rotate(45deg);
}
.input-icon { position: relative; display: block; }
.input-icon svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon .input { padding-left: 36px; }

.fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.fieldset legend { padding: 0; margin-bottom: 8px; }
.checks { display: flex; flex-direction: column; gap: 8px; }
.check { display: inline-flex; align-items: flex-start; gap: 8px; font-size: 13.5px; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 3px 0 0; flex: 0 0 auto; accent-color: var(--green); cursor: pointer; }
.check input:disabled, .check input:disabled + span { cursor: not-allowed; color: var(--muted); }

/* На телефоне шрифт поля не меньше 16px — иначе iOS увеличивает страницу при вводе */
@media (max-width: 859px) { .input { font-size: 16px; } }
@media (prefers-reduced-motion: reduce) { .input, .doc-body a { transition: none; } }

/* ===== Статусы ===== */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--idle-bg); color: var(--idle);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.st-active, .st-works { background: var(--ok-bg); color: var(--ok); }
.st-review, .st-dev { background: var(--warn-bg); color: var(--warn); }
.st-needs_review { background: var(--bad-bg); color: var(--bad); }
.st-draft, .st-archived, .st-planned { background: var(--idle-bg); color: var(--idle); }
.st-info { background: var(--info-bg); color: var(--info); }

/* ===== Панели и таблицы ===== */
.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 13px 16px; border-bottom: 1px solid var(--line);
  font-weight: 700; font-size: 14px;
}
.panel-head .aside { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--muted); }
.panel-body { padding: 16px; }
.panel-body > :first-child { margin-top: 0; }
.panel-body > :last-child { margin-bottom: 0; }
/* Таблица прокручивается внутри панели, страница вбок не едет */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .04em;
  padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
td { padding: 11px 14px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.nowrap, th.nowrap { white-space: nowrap; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.code-link { font-weight: 600; white-space: nowrap; }

/* Уровень автоматизации шага: как исполняется сегодня и куда должен прийти.
   Две строки в одной ячейке, а не две колонки: это одно движение, а не два
   независимых свойства. Целевая строка тише текущей — она про намерение,
   а не про то, что происходит сейчас. */
.autolevel { min-width: 15rem; }
.auto-now { display: block; color: var(--ink-2); }
.auto-next {
  display: flex; align-items: baseline; gap: 5px; margin-top: 3px;
  color: var(--muted); font-size: 12.5px;
}
.auto-next svg { flex: 0 0 auto; align-self: center; color: var(--green); }
.autolevel .badge { margin-top: 6px; }

/* Карточка «ключ — значение» */
.props th { width: 220px; text-transform: none; letter-spacing: 0; font-size: 13px; border-bottom-color: var(--line-2); }

/* ===== Страница документа =====
   Акцент страницы — уровень документа: `.doc.lvl-N` задаёт --lvl и --lvl-soft,
   дальше все блоки берут их и ничего про уровень не знают. Уровень появится
   седьмой — он получит цвет строкой в tokens.css и правилом здесь, а разметка
   страницы не изменится. Пока цвета нет, работает значение по умолчанию. */
.doc { --lvl: var(--ink-green); --lvl-soft: var(--line-2); }
.doc.lvl-1 { --lvl: var(--lvl-1); --lvl-soft: var(--lvl-1-soft); }
.doc.lvl-2 { --lvl: var(--lvl-2); --lvl-soft: var(--lvl-2-soft); }
.doc.lvl-3 { --lvl: var(--lvl-3); --lvl-soft: var(--lvl-3-soft); }
.doc.lvl-4 { --lvl: var(--lvl-4); --lvl-soft: var(--lvl-4-soft); }
.doc.lvl-5 { --lvl: var(--lvl-5); --lvl-soft: var(--lvl-5-soft); }
.doc.lvl-6 { --lvl: var(--lvl-6); --lvl-soft: var(--lvl-6-soft); }

.doc-back { display: flex; flex-wrap: wrap; gap: 6px 18px; }

.doc-hero {
  position: relative; overflow: hidden;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 22px 24px 20px; margin-bottom: 12px;
}
/* Полоса уровня: цвет на светлом фоне уходит в прозрачность, а не в серый —
   иначе на карточке появляется вторая линия там, где её не задумывали */
.doc-hero::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--lvl), transparent 88%);
}
.doc-hero-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 10px; }
.doc-level {
  font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 3px 10px; border-radius: 999px; background: var(--lvl-soft); color: var(--lvl);
}
.doc-code { font-family: var(--mono); font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.doc-ver { font-size: 12px; color: var(--muted); }
.doc-hero h1 { margin: 0; font-size: 25px; line-height: 1.22; letter-spacing: -.01em; text-wrap: balance; }
/* Ради чего документ существует (ADR-0003) — первое, что читается после названия */
.doc-risk {
  margin: 13px 0 0; padding-left: 13px; border-left: 3px solid var(--lvl);
  color: var(--text-2); font-size: 13.5px; max-width: 82ch;
}
.doc-risk span {
  display: block; margin-bottom: 1px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted);
}

/* Полоса с названием документа: липнет под шапкой, когда герой ушёл вверх.
   Показывает её скрипт (portal.js), поэтому у скрытого состояния свой
   display: none — иначе `display: flex` ниже перебил бы атрибут hidden. */
.doc-bar {
  position: sticky; top: var(--top-h); z-index: 15;
  display: flex; align-items: center; gap: 10px;
  height: var(--doc-bar-h); margin: 0 0 14px; padding: 0 14px;
  background: var(--card); border: 1px solid var(--line);
  border-left: 3px solid var(--lvl); border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.doc-bar[hidden] { display: none; }
.doc-bar-back {
  flex: 0 0 auto; display: inline-flex; align-items: center;
  color: var(--muted); text-decoration: none;
}
.doc-bar-back:hover { color: var(--ink); text-decoration: none; }
.doc-bar-name {
  flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 9px;
  color: var(--ink); text-decoration: none;
}
.doc-bar-name:hover { text-decoration: none; }
.doc-bar-name:hover .doc-bar-title { color: var(--link); }
.doc-bar-code { flex: 0 0 auto; font-family: var(--mono); font-size: 12px; font-weight: 600; color: var(--lvl); }
.doc-bar-title {
  min-width: 0; font-size: 13.5px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.doc-bar-top { flex: 0 0 auto; font-size: 12.5px; }
@media (max-width: 559px) {
  /* На телефоне название важнее статуса и подписи «Наверх»: стрелка назад
     и сам заголовок остаются, остальное уступает место */
  .doc-bar .badge, .doc-bar-top { display: none; }
}

.doc-alert {
  margin: 0 0 14px; padding: 11px 14px; border-radius: var(--radius-sm);
  background: var(--warn-bg); color: var(--warn); font-size: 13px; font-weight: 600;
}
.doc-alert a { color: inherit; }

/* Метаданные плитками, а не строками таблицы: их читают взглядом.
   Цветная грань слева — состояние, а не украшение (дата пересмотра). */
.doc-facts {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
  gap: 10px; margin-bottom: 18px;
}
.fact {
  background: var(--card); border: 1px solid var(--line); border-left: 3px solid var(--line);
  border-radius: var(--radius); padding: 11px 14px; box-shadow: var(--shadow); min-width: 0;
}
.fact-label { font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
.fact-value { margin-top: 4px; font-size: 14px; font-weight: 600; line-height: 1.35; }
.fact-none { color: var(--muted); font-weight: 400; }
.fact-note { margin-top: 2px; font-size: 11.5px; color: var(--muted); }
.fact.is-ok { border-left-color: var(--ok); }
.fact.is-ok .fact-note { color: var(--ok); }
.fact.is-warn { border-left-color: var(--warn); }
.fact.is-warn .fact-note { color: var(--warn); }
.fact.is-bad { border-left-color: var(--bad); }
.fact.is-bad .fact-note { color: var(--bad); }

.doc-grid { display: grid; grid-template-columns: minmax(0, 1fr) 220px; gap: 24px; align-items: start; }
.doc-col { min-width: 0; }
/* Переход из оглавления к «Шагам» и «Ролям» — с тем же запасом, что
   и к заголовку текста */
.doc-col > section { scroll-margin-top: calc(var(--top-h) + var(--doc-bar-h) + 14px); }
/* Оглавление липнет ниже полосы с названием: они прилипают одновременно,
   и без запаса оглавление ушло бы под полосу */
.doc-toc {
  position: sticky; top: calc(var(--top-h) + var(--doc-bar-h) + 14px);
  max-height: calc(100vh - var(--top-h) - var(--doc-bar-h) - 34px); overflow-y: auto;
}

.toc { font-size: 12.5px; border-left: 1px solid var(--line); padding-left: 14px; }
.toc-head {
  font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 8px;
}
.toc-item {
  display: block; margin-left: -15px; padding: 4px 0 4px 13px; line-height: 1.4;
  color: var(--text-2); text-decoration: none; border-left: 2px solid transparent;
}
.toc-item:hover { color: var(--ink); text-decoration: none; }
.toc-item[aria-current="true"] { color: var(--lvl); font-weight: 600; border-left-color: var(--lvl); }
.toc-h3 { padding-left: 25px; font-size: 12px; color: var(--muted); }
.toc-part { margin-top: 7px; font-weight: 600; }
.toc-part span { color: var(--muted); font-weight: 400; }

/* Шаги лентой: у шага один смысл — действие; исполнитель, система
   и результат это его свойства, а в таблице все пятеро выглядели равными */
.flow { list-style: none; margin: 0; padding: 0; }
.flow-step { position: relative; display: flex; gap: 14px; padding-bottom: 18px; }
.flow-step:last-child { padding-bottom: 0; }
.flow-step::before {
  content: ""; position: absolute; left: 13px; top: 32px; bottom: 2px; width: 2px; background: var(--line);
}
.flow-step:last-child::before { display: none; }
.flow-no {
  position: relative; z-index: 1; flex: 0 0 auto;
  width: 28px; height: 28px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--lvl-soft); color: var(--lvl);
  font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.flow-body { flex: 1; min-width: 0; padding-top: 3px; }
.flow-action { margin: 0; font-size: 13.5px; line-height: 1.5; }
.flow-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* Свёрнутый чужой шаг при срезе по роли: он остаётся в ленте, чтобы не
   пропала связка между своими шагами, но не спорит с ними за внимание */
.flow-svernut .flow-action { color: var(--muted); font-size: 12.5px; }
.flow-svernut .flow-no { background: var(--line-2); color: var(--muted); }
.row-svernut td { color: var(--muted); font-size: 12.5px; }
.row-svernut .num { color: var(--muted); }
.tag {
  display: inline-flex; align-items: center; gap: 5px; max-width: 100%;
  font-size: 11.5px; color: var(--text-2);
  background: var(--line-2); border-radius: 7px; padding: 3px 9px;
}
.tag svg { flex: 0 0 auto; color: var(--muted); }
.tag a { color: inherit; text-decoration: none; }
.tag a:hover { text-decoration: underline; }
.tag em { font-style: normal; font-weight: 700; font-size: 10px; letter-spacing: .04em; text-transform: uppercase; color: var(--info); }
.tag-out { color: var(--muted); }

/* Записи о роли — карточкой на адресата: читателю нужен ответ «что записано
   за этой ролью», а не строка таблицы */
.mandates { display: grid; gap: 12px; }
.mandate { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; }
.mandate-who { font-weight: 700; font-size: 13.5px; margin-bottom: 9px; }
.mandate-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 11px; }
.mandate-list li { font-size: 13px; line-height: 1.5; }
/* Вид записи — подпись над текстом, а не колонка слева: записи разной длины
   в колонку рвались каждая по-своему, и список читался рвано */
.mandate-kind {
  display: block; margin-bottom: 2px;
  font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--muted);
}
.mandate-list li.k-responsible_for .mandate-kind { color: var(--ok); }
.mandate-list li.k-decides .mandate-kind { color: var(--info); }
.mandate-list li.k-must_not .mandate-kind { color: var(--bad); }

/* ===== Свод документов (раздел «Система мотивации») =====
   Корень свода — карточкой, подчинённые документы — списками по блокам.
   Акцент тот же, что у страницы документа: цвет уровня через --lvl,
   поэтому Положение и Регламент в списке отличаются не только подписью. */
.svod-root {
  border: 1px solid var(--line); border-left: 3px solid var(--lvl);
  border-radius: var(--radius); padding: 16px 18px; background: var(--card-idle);
}
.svod-top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.svod-title {
  display: block; font-size: 17px; font-weight: 700; line-height: 1.3;
  color: var(--ink); text-decoration: none;
}
.svod-title:hover { color: var(--link); }
.svod-what { margin: 9px 0 0; color: var(--text-2); font-size: 13px; line-height: 1.55; max-width: 80ch; }
.svod-owner { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); }

.svod-block { margin-top: 20px; }
.svod-block-head {
  font-size: 10.5px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted); padding-bottom: 7px; border-bottom: 1px solid var(--line-2);
}
.svod-list { list-style: none; margin: 0; padding: 0; }
.svod-list li {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line-2); font-size: 13.5px;
}
.svod-list li:last-child { border-bottom: 0; }
.svod-level {
  flex: 0 0 auto; min-width: 5.5rem;
  font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  color: var(--lvl);
}

/* Виды выплат — группами по природе вклада: природа задаёт форму оплаты,
   поэтому она и делит перечень, а не алфавит */
.payments { display: grid; grid-template-columns: repeat(auto-fill, minmax(258px, 1fr)); gap: 14px; }
.payment-kind { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; }
.payment-kind-head { font-weight: 700; font-size: 12.5px; margin-bottom: 9px; }
.payment-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.payment-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 13px; }
.payment-name { color: var(--ink-2); }

/* ===== Текст документа =====
   Markdown рендерится в момент показа (documents/markdown.py). Здесь только
   типографика: ширина строки под чтение, воздух между разделами, акцент
   уровня на заголовках и маркерах списка. */
.doc-body { font-size: 14.5px; line-height: 1.68; color: var(--ink-2); }
.doc-body > :first-child { margin-top: 0; padding-top: 0; border-top: 0; }
.doc-body > :first-child::before { display: none; }
.doc-body > :last-child { margin-bottom: 0; }
.doc-body p, .doc-body ul, .doc-body ol, .doc-body blockquote { max-width: 76ch; }
.doc-body p { margin: 0 0 14px; }
/* Отступ якоря учитывает и шапку, и полосу с названием: без него переход
   по оглавлению ставит заголовок ровно под полосу */
.doc-body h2, .doc-body h3, .doc-body h4 {
  color: var(--ink); scroll-margin-top: calc(var(--top-h) + var(--doc-bar-h) + 14px);
}
.doc-body h2 {
  position: relative; margin: 34px 0 13px; padding-top: 19px;
  border-top: 1px solid var(--line-2); font-size: 17.5px; line-height: 1.3; letter-spacing: -.005em;
}
.doc-body h2::before { content: ""; position: absolute; top: -1px; left: 0; width: 36px; height: 2px; background: var(--lvl); }
.doc-body h3 { margin: 24px 0 8px; font-size: 14.5px; }
.doc-body h4 { margin: 18px 0 6px; font-size: 13.5px; color: var(--ink-2); }
.doc-body strong { color: var(--ink); font-weight: 650; }
.doc-body ul, .doc-body ol { margin: 0 0 14px; padding-left: 21px; }
.doc-body li { margin-bottom: 6px; }
.doc-body li::marker { color: var(--lvl); }
.doc-body li > ul, .doc-body li > ol { margin-top: 6px; }
.doc-body blockquote {
  margin: 16px 0; padding: 12px 16px; color: var(--text-2);
  border-left: 3px solid var(--lvl); background: var(--line-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.doc-body blockquote > :last-child { margin-bottom: 0; }
.doc-body hr { border: 0; border-top: 1px solid var(--line); margin: 26px 0; }
.doc-body pre {
  margin: 0 0 14px; padding: 12px 14px; overflow-x: auto;
  background: var(--line-2); border-radius: var(--radius-sm); font-size: 12.5px; line-height: 1.5;
}
.doc-body pre code { background: none; padding: 0; font-size: inherit; }
.doc-body .table-wrap { margin: 4px 0 18px; border: 1px solid var(--line); border-radius: var(--radius-sm); }

/* Раздел, содержимое которого стало данными: таблицу вырезал импортёр,
   и без этой ссылки читатель видел бы заголовок и пустоту под ним */
.section-moved { margin: 4px 0 18px; font-size: 13px; color: var(--muted); }
.section-moved a { color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }
.section-moved a:hover { color: var(--text); }
.doc-body .table-wrap th { background: var(--card-idle); }
/* В тексте ссылка подчёркнута всегда, иначе её не найти в абзаце. Черта
   при этом волосяная и отодвинута от букв: она отмечает ссылку, а не
   перечёркивает выносные элементы. При наведении становится сплошной. */
.doc-body a {
  color: var(--link);
  text-decoration: underline;
  text-decoration-color: var(--link-line);
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  transition: color .12s, text-decoration-color .12s;
}
.doc-body a:hover {
  color: var(--link-strong);
  text-decoration-color: currentColor; text-decoration-thickness: 2px;
}

/* Ссылка на документ реестра: код моноширинным, название обычным.
   «IT-001 — Положение об ИТ-инфраструктуре» одной строкой читается куском
   текста; разделённая — ссылкой на документ, и код в ней видно сразу,
   а его как раз печатают в документах и запоминают сотрудники. */
.ref-code { font-family: var(--mono); font-size: .92em; font-weight: 600; letter-spacing: -.01em; }

/* Название роли, системы или блока подставлено из справочника при показе
   (documents/links.py). Переходить некуда — значит, и выглядеть ссылкой
   оно не должно: цвет текста, только плотнее. */
.ref-role, .ref-system, .ref-block { font-weight: 650; color: var(--ink); }
/* Ссылка в тексте документа на удалённый объект */
.link-broken { color: var(--bad); }

/* ===== Шторка для меню на телефоне ===== */
.scrim { display: none; }

/* ===== Адаптив ===== */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* Узкому экрану колонки под оглавление не хватает: оно уходит наверх
     обычным блоком. Убирать его нельзя — длинный регламент без карты
     читается хуже всего как раз на узком экране. */
  .doc-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .doc-toc { position: static; max-height: none; order: -1; margin-bottom: 18px; }
  .toc {
    border-left: 0; padding: 12px 14px;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  }
  .toc-item { margin-left: 0; padding-left: 9px; }
  .toc-h3 { padding-left: 21px; }
}

@media (max-width: 859px) {
  .app { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }

  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 50;
    width: min(290px, 86vw); height: 100%;
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: var(--shadow-drawer);
  }
  .app.menu-open .sidebar { transform: none; }
  .sidebar-close {
    display: inline-flex; margin-left: auto;
    background: transparent; border-color: var(--side-line); color: var(--side-text);
  }
  .sidebar-close:hover { background: var(--side-2); }

  .scrim {
    display: block; position: fixed; inset: 0; z-index: 40;
    background: var(--scrim);
    opacity: 0; pointer-events: none; transition: opacity .2s;
  }
  .app.menu-open .scrim { opacity: 1; pointer-events: auto; }

  .menu-btn { display: inline-flex; }
  .topbar { padding: 0 12px; gap: 10px; }
  .main { padding: 18px 16px 48px; }
  .pagehead h1 { font-size: 20px; }
  .kpis { gap: 10px; }
  .kpi { padding: 12px 13px; }
  .kpi-value { font-size: 20px; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .props th { width: 40%; }
  /* Широкие таблицы не сжимаем в столбик из слов: они прокручиваются в панели */
  .table-wrap > table:not(.props) { min-width: 620px; }

  .doc-hero { padding: 18px 16px 16px; }
  .doc-hero h1 { font-size: 21px; }
  /* Плитки в две колонки: по одной на строку метаданные занимают весь экран,
     а их роль — быть видимыми целиком, не листаясь */
  .doc-facts { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .doc-body { font-size: 14px; }
  .doc-body h2 { font-size: 16px; margin-top: 28px; }
}

@media (max-width: 380px) {
  .tb-right .badge { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar, .scrim, .card { transition: none; }
}

/* Формы прохождения чек-листа и сообщения после действия.
   Поля в строку: отметка — действие на один клик рядом с пунктом,
   а не отдельная страница. */
.vvod-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.vvod-form select, .vvod-form input[type="text"], .vvod-form input[type="date"] {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--field-line); border-radius: var(--radius-sm); padding: 5px 8px;
}
.vvod-form input[type="text"] { min-width: 120px; }
.messages { margin-bottom: 14px; }
.message {
  margin: 0 0 8px; padding: 10px 12px; border-radius: var(--radius-sm);
  background: var(--card); box-shadow: inset 0 0 0 1px var(--field-line);
}
.message.success { box-shadow: inset 0 0 0 1px var(--green-2); }
.message.error { box-shadow: inset 0 0 0 1px var(--bad); }
