/* Базовые стили и компоненты. Токены — tokens.css. */
*, *::before, *::after { box-sizing: border-box; }
/* Атрибут hidden сильнее любых display из компонентов. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-md);
  line-height: 1.5;
}

/* Блокировка: содержимое скрывается мгновенно, до ответа сервера. */
html.is-locking body > *:not(.lock-veil) { visibility: hidden !important; }
.lock-veil { display: none; }
html.is-locking .lock-veil {
  display: grid; place-items: center; position: fixed; inset: 0;
  background: var(--bg); color: var(--text-muted); font-size: var(--fs-lg);
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--sp-3); font-weight: 600; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
p { margin: 0 0 var(--sp-3); }
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-hover); }
.num, td.num, th.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.muted { color: var(--text-muted); }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible { outline: var(--focus); outline-offset: 2px; }
/* Фокус не должен уходить под липкую шапку или нижнюю навигацию. */
:where(a, button, input, select, textarea, summary, [tabindex]) {
  scroll-margin-top: calc(var(--topbar-h) + var(--sp-4));
  scroll-margin-bottom: calc(var(--bottomnav-h) + var(--sp-4));
}

.skip-link {
  position: absolute; left: var(--sp-3); top: -100px; z-index: 100;
  background: var(--surface); color: var(--text); padding: var(--sp-3) var(--sp-4);
  border: 2px solid var(--accent); border-radius: var(--r-md);
}
.skip-link:focus { top: var(--sp-3); }

svg.sprite { display: none; }
svg.icon { width: 1.25rem; height: 1.25rem; flex: none; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Каркас ---------- */
.shell { min-height: 100vh; min-height: 100dvh; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  min-height: var(--topbar-h);
  padding: var(--sp-1) var(--sp-4);
  padding-left: max(var(--sp-4), env(safe-area-inset-left));
  padding-right: max(var(--sp-4), env(safe-area-inset-right));
  background: var(--surface);
  border-bottom: 1px solid var(--divider);
}
.brand { display: inline-flex; align-items: center; gap: var(--sp-2); min-height: var(--hit);
  min-width: 0; color: var(--text); font-weight: 700; letter-spacing: 0.04em;
  text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-weight: 400; color: var(--text-muted); letter-spacing: 0; }
.topbar-actions { display: flex; align-items: center; gap: var(--sp-1); flex: none; }
@media (max-width: 1023.98px) { .topbar .hide-sm { display: none; } }
@media (max-width: 400px) {
  .brand-sub { display: none; }
  .topbar { padding-left: max(var(--sp-3), env(safe-area-inset-left)); padding-right: max(var(--sp-3), env(safe-area-inset-right)); }
}
.topbar-actions form { margin: 0; }

.nav ul { list-style: none; margin: 0; padding: 0; }
.nav a {
  display: flex; align-items: center; gap: var(--sp-3);
  min-height: var(--hit); padding: var(--sp-2) var(--sp-3);
  color: var(--text); text-decoration: none; border-radius: var(--r-md);
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] {
  background: var(--accent-soft); color: var(--text); font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-short { display: none; }
.nav .nav-more { display: none; }
@media (max-width: 599.98px) {
  .nav .is-overflow { display: none; }
  .nav .nav-more { display: block; }
}

/* min-width: 0 — широкая таблица прокручивается внутри своей обертки, а не растягивает страницу. */
.main { padding: var(--sp-5) var(--sp-4) var(--sp-7); max-width: 1440px; min-width: 0; outline: none; }
.auth-main { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center;
  padding: var(--sp-5) var(--sp-4); outline: none; }

/* ≥ 1024: боковая навигация с подписями */
@media (min-width: 1024px) {
  .shell { display: grid; grid-template-columns: 14rem 1fr; grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / -1; }
  .nav { border-right: 1px solid var(--divider); background: var(--surface);
    padding: var(--sp-3); position: sticky; top: var(--topbar-h);
    height: calc(100dvh - var(--topbar-h)); overflow-y: auto; }
  .nav li + li { margin-top: var(--sp-1); }
  .main { padding: var(--sp-5) var(--sp-6) var(--sp-7); }
}

/* 600–1023: узкая боковая панель — значок + короткая подпись */
@media (min-width: 600px) and (max-width: 1023.98px) {
  .shell { display: grid; grid-template-columns: 5.5rem 1fr; grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / -1; }
  .nav { border-right: 1px solid var(--divider); background: var(--surface);
    padding: var(--sp-2); position: sticky; top: var(--topbar-h);
    height: calc(100dvh - var(--topbar-h)); }
  .nav a { flex-direction: column; gap: var(--sp-1); text-align: center;
    font-size: var(--fs-xs); padding: var(--sp-2) var(--sp-1); }
  .nav a[aria-current="page"] { box-shadow: inset 0 -3px 0 var(--accent); }
  .nav-label { display: none; }
  .nav-short { display: block; }
}

/* < 600: нижняя навигация в зоне большого пальца */
@media (max-width: 599.98px) {
  .main { padding: var(--sp-4) var(--sp-4) calc(var(--bottomnav-h) + var(--sp-6) + env(safe-area-inset-bottom)); }
  .nav { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0;
    background: var(--surface); border-top: 1px solid var(--divider);
    padding: var(--sp-1) max(var(--sp-2), env(safe-area-inset-left)) calc(var(--sp-1) + env(safe-area-inset-bottom)); }
  .nav ul { display: flex; justify-content: space-around; }
  .nav li { flex: 1; }
  .nav a { flex-direction: column; gap: 2px; justify-content: center; text-align: center;
    min-height: 3.5rem; font-size: var(--fs-xs); padding: var(--sp-1); }
  .nav a[aria-current="page"] { box-shadow: inset 0 3px 0 var(--accent); }
  .nav-label { display: none; }
  .nav-short { display: block; }
  .hide-sm { display: none; }
}

/* ---------- Кнопки ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: var(--hit); min-width: var(--hit); padding: var(--sp-2) var(--sp-4);
  font: inherit; font-weight: 600; line-height: 1.2; text-decoration: none;
  border: 1px solid transparent; border-radius: var(--r-md); cursor: pointer;
  transition: background-color var(--motion), border-color var(--motion);
}
.btn-primary, .btn-commit { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover, .btn-commit:hover { background: var(--accent-hover); color: var(--on-accent); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: var(--danger); color: var(--on-danger); }
.btn-danger:hover { background: var(--danger-hover); color: var(--on-danger); }
.btn-ghost { background: transparent; color: var(--text); font-weight: 500; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-lock { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-lock:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn[data-busy="true"] { cursor: progress; }
.btn-block { width: 100%; }
/* Кнопка темы в шапке — без подписи; на телефоне тема меняется в профиле, а в шапке
   остается место для «Заблокировать» с текстом: критичное действие не прячется в значок. */
.theme-label { display: none; }
@media (max-width: 599.98px) {
  .topbar [data-theme-toggle] { display: none; }
  .btn-lock { padding-inline: var(--sp-3); }
}

/* ---------- Формы ---------- */
.form { max-width: 36rem; }
.field { margin-bottom: var(--sp-4); }
.field > label, .fieldset > legend { display: block; font-weight: 600; margin-bottom: var(--sp-1); }
.req { color: var(--danger); }
.input, .field input:not([type="checkbox"]):not([type="radio"]), .field select, .field textarea {
  display: block; width: 100%; min-height: var(--hit);
  padding: var(--sp-2) var(--sp-3);
  font: inherit; font-size: var(--fs-md); color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm);
}
.field input:focus-visible, .field select:focus-visible { outline: var(--focus); outline-offset: 1px; }
.field [aria-invalid="true"] { border-color: var(--danger); border-width: 2px; }
.hint { color: var(--text-muted); font-size: var(--fs-sm); margin: var(--sp-1) 0 0; }
.error { display: flex; gap: var(--sp-2); align-items: flex-start; color: var(--danger);
  font-size: var(--fs-sm); font-weight: 600; margin: var(--sp-1) 0 0; }
.error svg.icon { width: 1.1rem; height: 1.1rem; margin-top: 1px; }

.fieldset { border: 0; padding: 0; margin: 0 0 var(--sp-4); min-width: 0; }
.check { display: flex; align-items: flex-start; gap: var(--sp-3); min-height: var(--hit);
  padding: var(--sp-2) 0; cursor: pointer; }
.check input { width: 1.25rem; height: 1.25rem; margin: 0.15rem 0 0; accent-color: var(--accent); flex: none; }
.check-text small { display: block; color: var(--text-muted); font-size: var(--fs-sm); }
.check.is-disabled { cursor: not-allowed; color: var(--text-muted); }
.field ul, .field div[id] > div { list-style: none; padding: 0; margin: 0; }
.field ul li label, .field div[id] > div > label { display: flex; align-items: center; gap: var(--sp-3); min-height: var(--hit); font-weight: 400; }
.field ul li input, .field div[id] > div > label > input { width: 1.25rem; height: 1.25rem; accent-color: var(--accent); }

.form-actions { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: center; margin-top: var(--sp-5); }

.filters { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fill, minmax(11rem, 1fr));
  align-items: end; margin-bottom: var(--sp-4); }
.filters .field, .filters .filters-actions { margin: 0; }
/* Поля выравниваются по верху (подсказка под полем не сдвигает соседей); кнопки — на уровне полей. */
.filters { align-items: start; }
.filters .filters-actions { padding-top: calc(1.5em + var(--sp-1)); }
.search-bar { display: flex; flex-wrap: wrap; gap: var(--sp-3); align-items: flex-end; margin-bottom: var(--sp-4); }
.search-bar .field { flex: 1 1 16rem; max-width: 28rem; margin: 0; }

/* ---------- Панели, заголовки ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--sp-3); margin-bottom: var(--sp-5); }
.page-head h1 { margin: 0; }
.panel { background: var(--surface); border: 1px solid var(--divider); border-radius: var(--r-md);
  padding: var(--sp-4); margin-bottom: var(--sp-5); }
.panel > h2:first-child { margin-top: 0; }
.panel-danger { border-color: var(--danger); }
/* minmax(0, …): широкие таблицы прокручиваются внутри колонки, а не раздвигают страницу. */
.two-col { display: grid; gap: var(--sp-5); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1024px) { .two-col { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; } }
.backlink { display: inline-flex; align-items: center; gap: var(--sp-1); min-height: var(--hit); margin-bottom: var(--sp-2); }

/* ---------- Ярлыки статусов (всегда текст + значок) ---------- */
.tag { display: inline-flex; align-items: center; gap: var(--sp-1); padding: 2px var(--sp-2);
  font-size: var(--fs-sm); font-weight: 600; border-radius: var(--r-sm); border: 1px solid currentColor;
  white-space: nowrap; }
.tag svg.icon { width: 1rem; height: 1rem; }
.tag-success { color: var(--success); background: var(--success-bg); }
.tag-warning { color: var(--warning); background: var(--warning-bg); }
.tag-danger { color: var(--danger); background: var(--danger-bg); }
.tag-info { color: var(--info); background: var(--info-bg); }
.tag-restricted { color: var(--text-muted); border-style: dashed; background: transparent; }

/* ---------- Уведомления ---------- */
.notices { display: grid; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.notice { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-md); border: 1px solid currentColor; }
.notice p { margin: 0; color: var(--text); }
.notice-success { color: var(--success); background: var(--success-bg); }
.notice-info { color: var(--info); background: var(--info-bg); }
.notice-warning { color: var(--warning); background: var(--warning-bg); }
.notice-error { color: var(--danger); background: var(--danger-bg); }

/* ---------- Таблицы ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--divider); border-radius: var(--r-md); overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
table.data caption { text-align: left; padding: var(--sp-3) var(--sp-4); font-weight: 600; }
table.data th, table.data td { padding: var(--sp-2) var(--sp-3); text-align: left; vertical-align: top;
  border-bottom: 1px solid var(--divider); }
table.data thead th { position: sticky; top: 0; background: var(--surface-2); font-weight: 600;
  color: var(--text); white-space: nowrap; }
table.data tbody tr:hover { background: var(--surface-2); }
table.data th.num, table.data td.num { text-align: right; }
table.data td.primary-cell a { font-weight: 600; }
table.data tfoot td { border-top: 2px solid var(--text); font-weight: 600; }
.empty { padding: var(--sp-6) var(--sp-4); text-align: center; color: var(--text-muted); }
.empty strong { display: block; color: var(--text); margin-bottom: var(--sp-1); }

/* < 600: строки таблицы превращаются в карточки */
@media (max-width: 599.98px) {
  .table-wrap { background: transparent; border: 0; overflow: visible; }
  table.data.stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.data.stack, table.data.stack tbody, table.data.stack tr, table.data.stack td { display: block; width: 100%; }
  table.data.stack tr { background: var(--surface); border: 1px solid var(--divider);
    border-radius: var(--r-md); padding: var(--sp-3); margin-bottom: var(--sp-3); }
  table.data.stack td { border: 0; padding: var(--sp-1) 0; display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--sp-1) var(--sp-3); text-align: right; }
  table.data.stack td::before { content: attr(data-label); color: var(--text-muted); text-align: left; font-weight: 400; }
  table.data.stack td.primary-cell { display: block; text-align: left; font-size: var(--fs-md); }
  table.data.stack td.primary-cell::before { content: none; }
  table.data { font-size: var(--fs-md); }
}

details.json summary { cursor: pointer; min-height: var(--hit); display: inline-flex; align-items: center; color: var(--accent); }
details.json pre { margin: var(--sp-2) 0 0; padding: var(--sp-2); background: var(--surface-2);
  border-radius: var(--r-sm); font-size: var(--fs-xs); white-space: pre-wrap; word-break: break-word; max-width: 40rem; }

.pager { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); margin-top: var(--sp-4); }

/* ---------- Вход ---------- */
.auth-card { width: 100%; max-width: 24rem; background: var(--surface); border: 1px solid var(--divider);
  border-radius: var(--r-md); padding: var(--sp-5); }
.auth-brand { font-weight: 700; letter-spacing: 0.04em; margin-bottom: var(--sp-1); }

/* ---------- Диалог ---------- */
.dialog { width: min(28rem, calc(100vw - 2rem)); border: 1px solid var(--divider); border-radius: var(--r-md);
  padding: var(--sp-5); background: var(--surface); color: var(--text); box-shadow: var(--shadow-overlay); }
.dialog::backdrop { background: rgba(20, 22, 25, 0.55); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-3); margin-top: var(--sp-5); }
@media (max-width: 599.98px) {
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions .btn { width: 100%; }
}

.home-links { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  list-style: none; padding: 0; margin: 0; }
.home-links a { display: flex; align-items: center; gap: var(--sp-3); min-height: 3.5rem; padding: var(--sp-3) var(--sp-4);
  background: var(--surface); border: 1px solid var(--divider); border-radius: var(--r-md); color: var(--text); text-decoration: none; font-weight: 600; }
.home-links a:hover { border-color: var(--accent); }

.head-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.field-row { display: grid; gap: 0 var(--sp-4); grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }

/* Переключатель-фильтр: ссылки, а не скрытые вкладки — работает без JS и с клавиатуры. */
.segmented { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.segmented a { display: inline-flex; align-items: center; gap: var(--sp-1); min-height: var(--hit);
  padding: var(--sp-2) var(--sp-3); border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text); text-decoration: none; }
.segmented a:hover { background: var(--surface-2); }
.segmented a[aria-current="page"] { background: var(--accent-soft); border-color: var(--accent);
  font-weight: 600; box-shadow: inset 0 -3px 0 var(--accent); }

.commit-panel { border-color: var(--accent); border-width: 2px; }
.commit-panel .form-actions { margin-top: var(--sp-3); }
.commit-panel form { margin: 0; }

.alias-list { list-style: none; padding: 0; margin: 0 0 var(--sp-4); }
.alias { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) 0; border-bottom: 1px solid var(--divider); }
.alias > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.alias-text { font-weight: 600; overflow-wrap: anywhere; }
.alias .muted { font-size: var(--fs-sm); }
.alias.is-inactive .alias-text { text-decoration: line-through; color: var(--text-muted); }
.alias form { margin: 0; flex: none; }
.notice ul { margin: var(--sp-1) 0 0; padding-left: var(--sp-5); color: var(--text); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-2) var(--sp-4); margin: 0; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; }

@media print {
  .topbar, .nav, .skip-link { display: none !important; }
  body { background: #fff; color: #000; }
}

/* ---------- Склад и приемка ---------- */
.qty-strong { font-weight: 600; font-size: 1.05em; }
.section-gap { margin-top: var(--sp-6); }
.search-bar .search-actions { display: flex; gap: var(--sp-2); padding-top: calc(1.5em + var(--sp-1)); }
.search-bar { align-items: flex-start; }

.add-block > summary { cursor: pointer; min-height: var(--hit); display: flex; align-items: center;
  font-weight: 600; color: var(--accent); }
.add-block[open] > summary { margin-bottom: var(--sp-3); }
section .add-block { margin-top: var(--sp-4); border-top: 1px solid var(--divider); padding-top: var(--sp-2); }

table.data tr.is-excluded td { color: var(--text-muted); }
table.data tr.is-excluded td.primary-cell { text-decoration: line-through; }
table.data tr.has-diff td:first-child { box-shadow: inset 4px 0 0 var(--warning); }
table.data tr.is-unfilled td:first-child { box-shadow: inset 4px 0 0 var(--border); }

.receipt-table input { width: 100%; min-width: 5.5rem; max-width: 9rem; min-height: var(--hit);
  padding: var(--sp-2); font: inherit; font-size: var(--fs-md); text-align: right;
  font-variant-numeric: tabular-nums; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r-sm); }
.receipt-table td[data-label="Комментарий"] input { text-align: left; max-width: none; min-width: 9rem; }
.receipt-table input[aria-invalid="true"] { border: 2px solid var(--danger); }
.receipt-table .error { justify-content: flex-end; }

.accept-all { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-3); }
.accept-all form { margin: 0; }
.accept-all .hint { margin: 0; flex: 1 1 18rem; }

/* Итог и действия приемки всегда под рукой, но не перекрывают таблицу. */
.sticky-actions { position: sticky; bottom: 0; z-index: 5; margin-top: var(--sp-4);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); background: var(--surface); border: 1px solid var(--divider);
  border-radius: var(--r-md); box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.06); }
.sticky-actions .form-actions { margin: 0; }
.sticky-summary { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin: 0; }
.receipt-table input { scroll-margin-bottom: 12rem; }
@media (max-width: 599.98px) {
  /* Компактная панель: две кнопки в ряд, чтобы не закрывать поля над экранной клавиатурой. */
  .sticky-actions { bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom));
    padding: var(--sp-2); gap: var(--sp-2); }
  .sticky-actions .form-actions { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
  .sticky-actions .btn { width: 100%; padding-inline: var(--sp-2); font-size: var(--fs-sm); }
  .sticky-summary .tag { font-size: var(--fs-xs); }
  .receipt-table input { max-width: none; }
  table.data.stack.receipt-table td { align-items: center; }
  table.data.stack td[data-diff] { justify-content: flex-end; }
  table.data.stack td[data-diff]::before { margin-right: auto; }
  /* Отметка расхождения — рамкой карточки, а не полосой у первой ячейки. */
  table.data.stack tr.has-diff { border-left: 4px solid var(--warning); }
  table.data.stack tr.is-unfilled { border-left: 4px solid var(--border); }
  table.data.stack tr.has-diff td:first-child, table.data.stack tr.is-unfilled td:first-child { box-shadow: none; }
}
.disc-list { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--sp-2); }

/* ---------- Проверка документа ---------- */
.review { display: grid; gap: var(--sp-5); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1400px) {
  /* Широкий экран: оригинал и распознанные данные рядом. */
  .review { grid-template-columns: minmax(0, 4fr) minmax(0, 7fr); align-items: start; }
  .review-original { position: sticky; top: calc(var(--topbar-h) + var(--sp-3));
    max-height: calc(100dvh - var(--topbar-h) - var(--sp-5)); overflow-y: auto; }
}
.review-tabs button { min-height: var(--hit); padding: var(--sp-2) var(--sp-3); font: inherit;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); color: var(--text); cursor: pointer; }
.review-tabs button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent);
  font-weight: 600; box-shadow: inset 0 -3px 0 var(--accent); }
.page-figure { margin: 0 0 var(--sp-4); }
.page-figure img { display: block; width: 100%; height: auto; border: 1px solid var(--divider);
  border-radius: var(--r-sm); background: #fff; }
.page-figure figcaption { font-size: var(--fs-sm); color: var(--text-muted); margin-top: var(--sp-1); }
.check-list { list-style: none; padding: 0; margin: 0; display: grid; gap: var(--sp-2); }
.check-item { display: flex; gap: var(--sp-2); align-items: flex-start; }
.check-item .tag { flex: none; }
.match-list { display: grid; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.match-row { display: grid; gap: var(--sp-2); grid-template-columns: minmax(0, 1fr); padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--divider); }
@media (min-width: 700px) { .match-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: center; } }
.match-source { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.match-text { font-weight: 600; overflow-wrap: anywhere; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: var(--fs-sm); }
.match-source .muted { font-size: var(--fs-sm); }
.match-input { width: 100%; min-height: var(--hit); padding: var(--sp-2) var(--sp-3); font: inherit;
  color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); }
.source-text { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: var(--fs-sm);
  background: var(--surface-2); padding: var(--sp-3); border-radius: var(--r-sm); overflow-wrap: anywhere; }
.plain-list { margin: 0; padding-left: var(--sp-5); display: grid; gap: var(--sp-1); }
.inline-form { margin-top: var(--sp-3); }
.reject-block { margin-top: var(--sp-4); }
.reject-block > summary { cursor: pointer; min-height: var(--hit); display: inline-flex; align-items: center; color: var(--danger); font-weight: 600; }
table.doc-lines td.primary-cell { min-width: 10rem; max-width: 22rem; overflow-wrap: break-word; }
.ocr-text > summary { cursor: pointer; min-height: var(--hit); display: inline-flex; align-items: center; color: var(--accent); font-weight: 600; }
.ocr-text pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--fs-xs); background: var(--surface-2);
  padding: var(--sp-3); border-radius: var(--r-sm); max-height: 28rem; overflow-y: auto; }

/* ---------- Списания ---------- */
.outcome-cards { display: grid; gap: var(--sp-3); grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); margin-top: var(--sp-5); }
.outcome-cards legend { font-weight: 600; margin-bottom: var(--sp-2); }
.outcome-card { display: flex; gap: var(--sp-3); align-items: flex-start; padding: var(--sp-4); min-height: var(--hit);
  border: 2px solid var(--border); border-radius: var(--r-md); background: var(--surface); cursor: pointer; }
.outcome-card input { width: 1.25rem; height: 1.25rem; margin-top: 0.15rem; accent-color: var(--accent); flex: none; }
.outcome-card small { display: block; color: var(--text-muted); margin-top: var(--sp-1); }
.outcome-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.outcome-card:has(input:focus-visible) { outline: var(--focus); outline-offset: 2px; }
.writeoff-table input[type="text"] { width: 100%; min-width: 5.5rem; max-width: 9rem; min-height: var(--hit);
  padding: var(--sp-2); font: inherit; text-align: right; font-variant-numeric: tabular-nums; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-sm); }
.writeoff-table .check { min-height: var(--hit); padding: 0; }
@media (max-width: 599.98px) { .writeoff-table input[type="text"] { max-width: none; } }

/* ---------- Продажи ---------- */
.input-num { width: 100%; min-width: 5.5rem; max-width: 9rem; min-height: var(--hit);
  padding: var(--sp-2) var(--sp-3); border: 1px solid var(--border);
  border-radius: var(--r-sm); background: var(--surface); color: var(--text);
  font: inherit; text-align: right; font-variant-numeric: tabular-nums; }
.row-actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: flex-end; }
.pick-list { margin: 0 0 var(--sp-3); }
.pick-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: var(--sp-2); padding: var(--sp-2) 0; border-bottom: 1px solid var(--divider); }
.sale-table tfoot th, .sale-table tfoot td { padding-top: var(--sp-3); }
@media (max-width: 599.98px) {
  .input-num { max-width: none; }
  .row-actions { justify-content: stretch; }
  .row-actions .btn { flex: 1 1 auto; }
}

.print-toolbar { display: flex; gap: var(--sp-2); justify-content: space-between; padding: var(--sp-3) var(--sp-4); }
.invoice-sheet { max-width: 52rem; margin: 0 auto; padding: var(--sp-4); position: relative; }
.invoice-sheet h1 { font-size: 1.4rem; margin: 0 0 var(--sp-4); }
.invoice-wrap { overflow-x: auto; }
.invoice-table { width: 100%; border-collapse: collapse; margin: var(--sp-4) 0; font-variant-numeric: tabular-nums; }
.invoice-table th, .invoice-table td { border: 1px solid var(--text-muted); padding: var(--sp-1) var(--sp-2); text-align: left; }
.invoice-table .num { text-align: right; }
@media (max-width: 599.98px) { .invoice-table { font-size: .85rem; } .invoice-table th, .invoice-table td { padding: var(--sp-1); } }
.invoice-signs { display: flex; flex-wrap: wrap; gap: var(--sp-6); margin-top: var(--sp-6); }
.invoice-stamp { position: absolute; top: var(--sp-4); right: var(--sp-4); margin: 0; padding: var(--sp-1) var(--sp-3);
  border: 3px solid var(--danger); color: var(--danger); font-weight: 700; letter-spacing: .1em; transform: rotate(-6deg); }
@media print {
  .print-toolbar, .print-page .hint { display: none !important; }
  .print-page { background: #fff; color: #000; }
  .invoice-sheet { max-width: none; padding: 0; }
  .invoice-table th, .invoice-table td { border-color: #000; }
}
.invoice-title { font-weight: 700; }
.invoice-parties { display: grid; grid-template-columns: max-content 1fr; gap: var(--sp-1) var(--sp-3); margin: 0 0 var(--sp-3); }
.invoice-parties dd { margin: 0; font-weight: 600; font-style: italic; }
.invoice-words { border-bottom: 1px solid var(--text-muted); padding-bottom: var(--sp-1); }
.sign-line { display: inline-block; width: 12rem; max-width: 40vw; border-bottom: 1px solid currentColor; vertical-align: bottom; }

/* Аварийное отключение: всегда в шапке, маленький красный квадрат. */
.panic-form { display: flex; }
.btn-panic { display: inline-flex; align-items: center; justify-content: center;
  width: var(--hit); height: var(--hit); min-width: var(--hit); padding: 0; border: 0;
  border-radius: var(--r-sm); background: #C62828; color: #fff; cursor: pointer; }
.btn-panic:hover { filter: brightness(1.1); }
.btn-panic:focus-visible { outline: 3px solid #C62828; outline-offset: 2px; }
.btn-panic .icon { width: 1.25rem; height: 1.25rem; }
@media (max-width: 479.98px) {
  .btn-lock span { display: none; }  /* место для красной кнопки; название — в aria-label */
}
