/* KM Status — оболочка приложения и компоненты. */

/* Сетка оболочки */
body.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-rows: var(--topbar-h) minmax(0, 1fr);
  grid-template-areas: "side top" "side main";
}
.sidebar {
  grid-area: side;
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: var(--sp-4) var(--sp-3);
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: 40px;
  margin-bottom: var(--sp-5);
  padding: 0 var(--sp-2);
  color: var(--fg);
  font-size: var(--fs-lg);
  font-weight: 750;
  letter-spacing: -.02em;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
}
.brand .ico { width: 28px; height: 28px; color: var(--accent); }
nav.main { display: flex; flex-direction: column; gap: 2px; }
nav.main a {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  min-height: var(--tap);
  padding: 0 var(--sp-3);
  border-radius: var(--r-md);
  color: var(--fg-muted);
  font-size: var(--fs-sm);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
}
nav.main a:hover { background: var(--surface-2); color: var(--fg); }
nav.main a.on { background: var(--accent-soft); color: var(--accent-ink); }
nav.main a .ico { width: 22px; height: 22px; }
.sidebar-foot {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-top: auto;
  padding: var(--sp-3) var(--sp-2) 0;
  border-top: 1px solid var(--line);
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  white-space: nowrap;
  overflow: hidden;
}
.sidebar-foot .name { overflow: hidden; text-overflow: ellipsis; }
.topbar {
  grid-area: top;
  position: sticky;
  top: 0;
  z-index: var(--z-shell);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  min-height: var(--topbar-h);
  padding: 0 var(--sp-6);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.topbar-title { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--fg-muted); font-size: var(--fs-sm); font-weight: 600; white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
main {
  grid-area: main;
  width: 100%;
  max-width: calc(var(--content-max) + 2 * var(--sp-6));
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-6) var(--sp-8);
}
main.wide { max-width: calc(var(--content-max-wide) + 2 * var(--sp-6)); }
main.medium { max-width: calc(1400px + 2 * var(--sp-6)); }  /* «Поставки на Ozon»: широкие таблицы заявок */
.bottombar { display: none; }

/* Индикатор подключения */
.conn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 36px;
  max-width: 100%;
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  color: var(--fg-muted);
  font-size: var(--fs-xs);
  font-weight: 650;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}
.conn-text { overflow: hidden; text-overflow: ellipsis; }
.conn .dot { width: 8px; height: 8px; flex: 0 0 auto; border-radius: 50%; background: var(--fg-faint); }
.conn-ok { border-color: var(--ok-line); background: var(--ok-soft); color: var(--ok); }
.conn-ok .dot { background: var(--ok); }
.conn-off { border-color: var(--wait-line); background: var(--wait-soft); color: var(--wait); }
.conn-off .dot { background: var(--wait); }
.conn-busy { border-color: var(--info-line); background: var(--info-soft); color: var(--info); }
.conn-busy .dot { background: var(--info); animation: km-pulse 1.2s ease-in-out infinite; }
.conn:hover { box-shadow: var(--sh-1); color: inherit; }
@keyframes km-pulse { 50% { opacity: .3; } }

/* Меню пользователя и выпадающие меню */
details.menu { position: relative; }
details.menu > summary { display: inline-flex; }
details.menu .menu-list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: var(--z-menu);
  min-width: 220px;
  padding: var(--sp-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-raised);
  box-shadow: var(--sh-3);
}
details.menu.menu-up .menu-list { top: auto; bottom: calc(100% + 6px); }
details.menu .menu-list > *, details.menu .menu-list form { display: block; width: 100%; margin: 0; }
details.menu .menu-list button, details.menu .menu-list a.button {
  width: 100%;
  justify-content: flex-start;
  min-height: var(--tap);
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--fg);
  font-weight: 500;
  text-align: left;
}
details.menu .menu-list button:hover, details.menu .menu-list a.button:hover { background: var(--surface-2); color: var(--fg); }
.menu-head { padding: var(--sp-2) var(--sp-3); color: var(--fg-muted); font-size: var(--fs-xs); }
.user-menu > summary { gap: var(--sp-2); padding-inline: var(--sp-2); color: var(--fg); }
.user-menu .name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }

/* Иконки: один класс, картинка через custom property */
.ico {
  display: inline-block;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  background: currentColor;
  -webkit-mask: var(--ico) center / contain no-repeat;
  mask: var(--ico) center / contain no-repeat;
}
.ico-brand { --ico: url(/static/icons/brand.svg); }
.ico-codes { --ico: url(/static/icons/codes.svg); }
.ico-orders { --ico: url(/static/icons/orders.svg); }
.ico-documents { --ico: url(/static/icons/documents.svg); }
.ico-check { --ico: url(/static/icons/check.svg); }
.ico-settings { --ico: url(/static/icons/settings.svg); }
.ico-user { --ico: url(/static/icons/user.svg); }
.ico-plus { --ico: url(/static/icons/plus.svg); }
.ico-upload { --ico: url(/static/icons/upload.svg); }
.ico-search { --ico: url(/static/icons/search.svg); }
.ico-key { --ico: url(/static/icons/key.svg); }
.ico-users { --ico: url(/static/icons/users.svg); }
.ico-tools { --ico: url(/static/icons/tools.svg); }
.ico-empty { --ico: url(/static/icons/empty.svg); }

/* Кнопки: базовая = вторичная; .primary — одна на экран */
button, a.button, summary.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 40px;
  margin: 0;
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--fg);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  box-shadow: var(--sh-1);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
button:hover, a.button:hover, summary.button:hover { border-color: var(--fg-faint); background: var(--surface-2); color: var(--fg); }
button:active, a.button:active { transform: translateY(1px); }
.primary, a.button.primary { border-color: var(--accent); background: var(--accent); color: var(--on-accent); box-shadow: 0 1px 2px rgb(37 99 235 / 30%); }
.primary:hover, a.button.primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); color: var(--on-accent); }
.primary:active, a.button.primary:active { background: var(--accent-active); }
.secondary, a.button.secondary { color: var(--accent-ink); }
.danger, a.button.danger { border-color: var(--bad-line); color: var(--bad); }
.danger:hover, a.button.danger:hover { background: var(--bad-soft); color: var(--bad); }
.link, a.button.link, summary.link {
  padding-inline: var(--sp-2);
  border-color: transparent;
  background: transparent;
  color: var(--accent);
  box-shadow: none;
}
.link:hover, summary.link:hover { border-color: transparent; background: var(--accent-soft); color: var(--accent-ink); }
.link.danger-link { color: var(--bad); }
.link.danger-link:hover { background: var(--bad-soft); color: var(--bad); }
.btn-lg { min-height: 48px; padding: 12px 20px; font-size: var(--fs-md); }
.btn-sm { min-height: 34px; padding: 5px 10px; font-size: var(--fs-xs); }
.btn-block { width: 100%; }
button:disabled, a.button[aria-disabled="true"] {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--fg-muted);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}
.is-busy { position: relative; color: transparent !important; pointer-events: none; }
.is-busy::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  color: var(--fg-muted);
  animation: km-spin .8s linear infinite;
}
.primary.is-busy::after { color: var(--on-accent); }
@keyframes km-spin { to { transform: rotate(360deg); } }
label.button { margin: 0; font-size: var(--fs-sm); font-weight: 600; }        /* «Загрузить файл из СУЗ»: label как кнопка */
.file-pick { position: relative; cursor: pointer; }
.file-pick:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
form > button, form > a.button { margin-top: var(--sp-4); }     /* кнопка после полей формы */
.form-actions > button, .form-actions > a.button, .form-row > button, .form-row > a.button, form.inline > button, form.inline > a.button { margin-top: 0; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4) var(--sp-6); margin-bottom: var(--sp-6); }
.page-head-main { min-width: 0; }
.page-lead { max-width: 78ch; margin: var(--sp-2) 0 0; color: var(--fg-muted); font-size: var(--fs-md); line-height: 1.55; }
.page-head-actions { display: flex; flex: 0 0 auto; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--sp-2); }
.page-head-actions > form { margin: 0; }
a.back { display: inline-flex; align-items: center; min-height: 32px; margin: 0 0 var(--sp-2) -4px; padding: 0 var(--sp-1); color: var(--fg-muted); font-size: var(--fs-sm); font-weight: 600; text-decoration: none; }
a.back:hover { color: var(--accent); }

.card {
  margin: 0 0 var(--sp-5);
  padding: var(--sp-6);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--sh-1);
}
.card > :last-child { margin-bottom: 0; }
.card.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--sh-2); }
.card.plan { border-color: var(--info-line); background: var(--info-soft); }
.card.narrow, .narrow { max-width: 480px; }
.card h2 .small, .card h2 a.small { margin-left: var(--sp-2); font-size: var(--fs-sm); font-weight: 500; }
.step-num {
  display: inline-flex;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--fs-xs);
  font-weight: 750;
}
.card h2:has(.step-num) { display: flex; align-items: center; gap: var(--sp-3); }
.card.empty { padding: var(--sp-8) var(--sp-6); text-align: center; }
.card.empty .ico { width: 40px; height: 40px; margin-bottom: var(--sp-3); color: var(--fg-faint); }
.card.empty p { max-width: 46ch; margin-inline: auto; }
.card.empty .button { margin-top: var(--sp-3); }

/* Секции данных: описание и действие не конкурируют, фильтры и пустое
   состояние образуют отдельные визуальные уровни. */
.workflow-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: var(--sp-5);
  margin-bottom: var(--sp-5);
}
.workflow-grid > .card { height: 100%; margin-bottom: 0; }
.section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-4) var(--sp-6);
  margin-bottom: var(--sp-4);
  padding-bottom: var(--sp-4);
  border-bottom: 1px solid var(--line);
}
.section-head-copy { min-width: 0; max-width: 82ch; }
.section-head h2 { margin: 0; }
.section-description { margin: var(--sp-2) 0 0; color: var(--fg-muted); font-size: var(--fs-sm); line-height: 1.55; }
.section-actions { display: flex; flex: 0 0 auto; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: var(--sp-2); }
.section-actions form { margin: 0; }
.section-actions button { white-space: nowrap; }
.filterbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  margin: var(--sp-4) 0;
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.filterbar-label { color: var(--fg-muted); font-size: var(--fs-xs); font-weight: 700; }
.filterbar .chip { min-height: 32px; padding-block: 4px; background: var(--surface); }
.empty-state {
  display: flex;
  min-height: 112px;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-5);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.empty-state.compact { min-height: 88px; padding: var(--sp-4); }
.empty-state .ico { width: 32px; height: 32px; color: var(--fg-faint); }
.empty-state strong { display: block; color: var(--fg); font-size: var(--fs-sm); }
.empty-state p { margin: 3px 0 0; color: var(--fg-muted); font-size: var(--fs-sm); line-height: 1.45; }
.data-section > .progress-text:not([hidden]) { padding: var(--sp-3) var(--sp-4); border: 1px solid var(--info-line); border-radius: var(--r-md); background: var(--info-soft); color: var(--info); }
.data-section > table.grid { margin-top: var(--sp-4); }
.data-section > h3 { margin-top: var(--sp-6); padding-top: var(--sp-4); border-top: 1px solid var(--line); }

.alert {
  position: relative;
  margin: 0 0 var(--sp-4);
  padding: var(--sp-3) var(--sp-4) var(--sp-3) 44px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: var(--fs-sm);
}
.alert::before {
  content: "";
  position: absolute;
  left: 14px;
  top: 13px;
  width: 20px;
  height: 20px;
  background: currentColor;
  -webkit-mask: var(--ico, url(/static/icons/info.svg)) center / contain no-repeat;
  mask: var(--ico, url(/static/icons/info.svg)) center / contain no-repeat;
}
.alert > :last-child { margin-bottom: 0; }
.alert ul { margin: var(--sp-2) 0 0; padding-left: var(--sp-5); }
.alert.info { --ico: url(/static/icons/info.svg); border-color: var(--info-line); background: var(--info-soft); color: var(--info); }
.alert.ok { --ico: url(/static/icons/ok.svg); border-color: var(--ok-line); background: var(--ok-soft); color: var(--ok); }
.alert.wait { --ico: url(/static/icons/warn.svg); border-color: var(--wait-line); background: var(--wait-soft); color: var(--wait); }
.alert.bad { --ico: url(/static/icons/bad.svg); border-color: var(--bad-line); background: var(--bad-soft); color: var(--bad); }
.alert a { color: inherit; font-weight: 600; }

.badge, .state, .st {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 2px 10px;
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-weight: 650;
  line-height: 1.2;
  white-space: nowrap;
}
.badge-lg { min-height: 34px; padding: 6px 14px; font-size: var(--fs-sm); }
.badge::before, .st::before, .state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .85; }
.tone-wait, .state-pending, .state-partial { border-color: var(--wait-line); background: var(--wait-soft); color: var(--wait); }
.tone-run, .state-running { border-color: var(--info-line); background: var(--info-soft); color: var(--info); }
.tone-ok, .state-done { border-color: var(--ok-line); background: var(--ok-soft); color: var(--ok); }
.tone-bad, .state-failed { border-color: var(--bad-line); background: var(--bad-soft); color: var(--bad); }
.tone-muted { border-color: var(--line-strong); background: var(--surface-2); color: var(--fg-muted); }
.st-emitted, .st-none { background: var(--st-emitted-soft); color: var(--st-emitted); }
.st-applied { background: var(--st-applied-soft); color: var(--st-applied); }
.st-introduced { background: var(--st-introduced-soft); color: var(--st-introduced); }
.st-retired, .st-written_off, .st-withdrawn { background: var(--st-retired-soft); color: var(--st-retired); }
a.badge { text-decoration: none; }
a.badge.att { margin-top: 4px; white-space: normal; }
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 1px 6px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  color: var(--fg-muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}
.tag.origin-foreign { border-color: var(--info-line); color: var(--info); }         /* Импорт — синяя */
.tag.origin-reapply, .tag.origin-remains { border-color: var(--ok-line); color: var(--ok); }   /* Остатки — зелёная */
.tag-doc { border-color: var(--accent); color: var(--accent); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: var(--sp-3); margin-bottom: var(--sp-5); }
.kpi {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  padding: var(--sp-4) var(--sp-5);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  color: var(--fg);
  text-decoration: none;
  box-shadow: var(--sh-1);
}
a.kpi:hover { border-color: var(--accent); box-shadow: var(--sh-2); color: var(--fg); }
.kpi b { font-size: var(--fs-2xl); font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.kpi span { color: var(--fg-muted); font-size: var(--fs-xs); font-weight: 600; }
.kpi.on { border-color: var(--accent); background: var(--accent-soft); }
.kpi[data-tone="emitted"] b { color: var(--st-emitted); }
.kpi[data-tone="applied"] b { color: var(--st-applied); }
.kpi[data-tone="introduced"] b { color: var(--st-introduced); }
.kpi[data-tone="retired"] b, .kpi[data-tone="bad"] b { color: var(--bad); }
.kpi[data-tone="wait"] b { color: var(--wait); }

ol.stepper { display: flex; gap: 0; margin: 0 0 var(--sp-5); padding: 0; list-style: none; counter-reset: none; }
ol.stepper li { position: relative; display: flex; flex: 1 1 0; min-width: 0; align-items: center; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3) var(--sp-2) 0; color: var(--fg-muted); font-size: var(--fs-xs); font-weight: 600; }
ol.stepper li + li::before { content: ""; position: absolute; left: -8px; top: 50%; width: 8px; height: 2px; background: var(--line-strong); }
ol.stepper .n { display: inline-flex; width: 26px; height: 26px; flex: 0 0 auto; align-items: center; justify-content: center; border: 2px solid var(--line-strong); border-radius: 50%; background: var(--surface); font-size: 12px; font-weight: 750; }
ol.stepper .t { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
ol.stepper li.done { color: var(--ok); }
ol.stepper li.done .n { border-color: var(--ok); background: var(--ok); color: var(--surface); }
ol.stepper li.done .n::before { content: "✓"; }
ol.stepper li.done .n { font-size: 0; }                /* цифра скрыта, видна галочка */
ol.stepper li.done .n::before { font-size: 13px; }
ol.stepper li.current { color: var(--accent-ink); }
ol.stepper li.current .n { border-color: var(--accent); background: var(--accent); color: var(--on-accent); }
ol.stepper li.current .t { white-space: normal; font-weight: 700; }

.options { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--sp-3); margin: var(--sp-3) 0 var(--sp-4); }
label.option {
  display: flex;
  min-height: 72px;
  align-items: flex-start;
  gap: var(--sp-3);
  margin: 0;
  padding: var(--sp-4);
  border: 1.5px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  font-size: var(--fs-sm);
  font-weight: 400;
  cursor: pointer;
}
label.option:hover { border-color: var(--line-strong); background: var(--surface-2); }
label.option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
label.option input { flex: 0 0 auto; margin-top: 1px; }
label.option b { display: block; font-size: var(--fs-md); }
.summary-line { padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); background: var(--surface-2); font-size: var(--fs-md); font-weight: 650; }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.chips + .chips { margin-top: var(--sp-2); }
.chips-label { margin-right: var(--sp-1); color: var(--fg-muted); font-size: var(--fs-xs); font-weight: 600; }
.chip {
  display: inline-flex;
  min-height: 36px;
  align-items: center;
  gap: var(--sp-2);
  margin: 0;
  padding: 6px 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--fg);
  font-size: var(--fs-xs);
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.chip:hover { border-color: var(--accent); color: var(--fg); }
.chip input { width: 16px; height: 16px; }
.chip b { color: var(--fg-muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.chip.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); }
.chip.on b { color: inherit; }

nav.tabs { display: flex; gap: var(--sp-1); margin: 0 0 var(--sp-5); padding: 3px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); }
nav.tabs a { flex: 0 0 auto; min-height: 38px; padding: 8px 16px; border-radius: var(--r-sm); color: var(--fg-muted); font-size: var(--fs-sm); font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; }
nav.tabs a:hover { color: var(--fg); }
nav.tabs a.on { background: var(--surface); color: var(--fg); box-shadow: var(--sh-1); }

.scroll { max-width: 100%; overflow: auto; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
.scroll > table { border: 0; border-radius: 0; }
.card > table.grid, .card > .scroll { border: 0; border-radius: 0; }     /* таблица внутри карточки: без второй рамки */
.card > table.grid th:first-child, .card > table.grid td:first-child { padding-left: 0; }
.card > table.grid th:last-child, .card > table.grid td:last-child { padding-right: 0; }
.card > table.grid th { background: var(--surface); }
table { font-variant-numeric: tabular-nums; }
table.grid, table.raw, table.kv { width: 100%; border-collapse: separate; border-spacing: 0; }
table.grid, table.raw { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); font-size: var(--fs-sm); }
table.grid thead th:first-child, table.raw thead th:first-child { border-top-left-radius: var(--r-md); }
table.grid thead th:last-child, table.raw thead th:last-child { border-top-right-radius: var(--r-md); }
table.grid th, table.grid td, table.raw th, table.raw td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.grid th, table.raw th { position: sticky; top: 0; z-index: var(--z-sticky); background: var(--surface-2); color: var(--fg-muted); font-size: 12px; font-weight: 700; letter-spacing: .02em; text-transform: uppercase; white-space: nowrap; box-shadow: inset 0 -1px 0 var(--line); }
.card > table.grid th, form > table.grid th { top: var(--topbar-h); }   /* не в .scroll: липнет под верхней панелью */
table.grid th a { color: inherit; text-decoration-color: var(--line-strong); }
table.grid tbody tr:last-child > * { border-bottom: 0; }
table.grid tbody tr:hover > td { background: var(--surface-2); }
table.grid tr.sel > td { background: var(--surface-selected); }
table.grid tr.warn > td { background: var(--bad-soft); }
table.grid .num, table.raw .num { text-align: right; white-space: nowrap; }
table.grid td.code, table.grid .mono.small { font-family: var(--mono); font-size: 13px; overflow-wrap: anywhere; word-break: break-all; max-width: 30ch; }
table.grid td.actions { text-align: right; white-space: nowrap; }
table.grid td.actions .button, table.grid td.actions button { min-height: 34px; padding: 5px 11px; font-size: var(--fs-xs); }
table.grid.list td { vertical-align: middle; }
table.grid td b { font-weight: 650; }
table.kv { font-size: var(--fs-sm); }
table.kv th, table.kv td { padding: 10px 12px 10px 0; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.kv tr:last-child > * { border-bottom: 0; }
table.kv th { width: 34%; color: var(--fg-muted); font-weight: 600; }
table.kv.small th, table.kv.small td { padding-block: 6px; }

@media (max-width: 767px) {
  .scroll:has(> table.grid) { overflow: visible; border: 0; background: transparent; }
  table.grid, table.grid tbody, table.grid tr, table.grid td { display: block; width: 100%; }
  table.grid { border: 0; background: transparent; overflow: visible; }
  table.grid thead { display: none; }
  table.grid tr { position: relative; margin-bottom: var(--sp-3); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--sh-1); }
  table.grid tbody tr:hover > td { background: transparent; }
  table.grid tr.sel { border-color: var(--accent); background: var(--surface-selected); }
  table.grid td { display: grid; grid-template-columns: minmax(96px, 36%) minmax(0, 1fr); gap: var(--sp-3); padding: 6px 0; border-bottom: 1px solid var(--line); text-align: left; }
  table.grid td:last-child { border-bottom: 0; }
  table.grid td[data-label]::before { content: attr(data-label); color: var(--fg-muted); font-size: var(--fs-xs); font-weight: 600; }
  table.grid td[colspan] { display: block; }
  table.grid td.lead { display: block; padding-top: 0; font-size: var(--fs-md); }
  table.grid td.lead::before { content: none; }
  table.grid td.actions { display: flex; flex-wrap: wrap; gap: var(--sp-2); padding-top: var(--sp-3); }
  table.grid td.actions::before { content: none; }
  table.grid td.actions form, table.grid td.actions .button, table.grid td.actions button { width: 100%; margin: 0; }
  table.grid td.num { text-align: left; }
  table.grid td.code { max-width: none; }
  table.grid td[data-label="Выбрать"] { position: absolute; top: 10px; right: 10px; display: block; width: auto; padding: 0; border: 0; }
  table.grid td[data-label="Выбрать"]::before { content: none; }
  table.grid td[data-label="Выбрать"] input { width: 26px; height: 26px; }
  table.grid tr:has(td[data-label="Выбрать"]) td.lead { padding-right: 40px; }
  table.kv th, table.kv td { display: block; width: 100%; padding-inline: 0; }
  table.kv th { padding-bottom: 0; border-bottom: 0; }
  table.kv td { padding-top: 2px; }
}

.actionbar {
  position: sticky;
  bottom: var(--sp-4);
  z-index: var(--z-bar);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3) var(--sp-5);
  margin-top: var(--sp-5);
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  background: var(--surface-raised);
  box-shadow: var(--sh-3);
}
.actionbar .scope, .actionbar .acts { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-4); }
.actionbar .scope label { display: inline-flex; align-items: center; gap: var(--sp-2); min-height: 40px; margin: 0; font-size: var(--fs-sm); font-weight: 500; }
.actionbar .scope b { font-variant-numeric: tabular-nums; }
.actionbar .acts { gap: var(--sp-2); }

@media (max-width: 767px) {
  .actionbar { bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom) + var(--sp-2)); align-items: stretch; padding: var(--sp-3); }
  .actionbar .scope, .actionbar .acts { width: 100%; }
  .actionbar .acts { display: grid; grid-template-columns: 1fr 1fr; }
  .actionbar .acts .primary { grid-column: 1 / -1; }
  .actionbar .acts details.menu, .actionbar .acts details.menu > summary { width: 100%; }
}

.progress { margin-top: var(--sp-3); }
.progress-track { height: 10px; overflow: hidden; border-radius: var(--r-pill); background: var(--line); }
.progress-fill { display: block; width: 0; height: 100%; border-radius: var(--r-pill); background: var(--accent); transition: width .2s linear; }
.progress-track.busy .progress-fill { width: 100%; background: repeating-linear-gradient(45deg, var(--accent) 0 12px, color-mix(in srgb, var(--accent) 55%, var(--surface)) 12px 24px); background-size: 34px 34px; animation: km-busy 1s linear infinite; }
.progress-text { margin: var(--sp-2) 0 0; color: var(--fg-muted); font-size: var(--fs-sm); font-weight: 500; }
@keyframes km-busy { to { background-position: 34px 0; } }
.wait-line { margin: var(--sp-3) 0 0; color: var(--accent-ink); font-size: var(--fs-sm); font-weight: 600; }

.pager { display: flex; align-items: center; justify-content: center; gap: var(--sp-5); min-height: 48px; margin: var(--sp-4) 0; }
.pager a { display: inline-flex; align-items: center; min-height: 40px; padding: 0 var(--sp-3); border-radius: var(--r-md); text-decoration: none; font-weight: 600; }
.pager a:hover { background: var(--accent-soft); }

details.help, details.tech, details.diag { margin: 0 0 var(--sp-5); padding: var(--sp-4) var(--sp-5); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface); }
details.tech { background: transparent; border-style: dashed; }
details.help > summary, details.tech > summary, details.diag > summary, details.more > summary, details.gtins > summary { display: flex; align-items: center; gap: var(--sp-2); min-height: 32px; color: var(--accent); font-size: var(--fs-sm); font-weight: 600; }
details.tech > summary { color: var(--fg-muted); }
details > summary::before { content: ""; width: 16px; height: 16px; flex: 0 0 auto; background: currentColor; -webkit-mask: url(/static/icons/chevron.svg) center / contain no-repeat; mask: url(/static/icons/chevron.svg) center / contain no-repeat; transform: rotate(-90deg); transition: transform var(--dur) var(--ease); }
details[open] > summary::before { transform: rotate(0); }
details.menu > summary::before { content: none; }
details[open] > summary { margin-bottom: var(--sp-3); }
details.tech pre { max-height: 380px; overflow: auto; padding: var(--sp-3); border-radius: var(--r-md); background: var(--surface-2); font-size: 12px; white-space: pre-wrap; word-break: break-all; }
details.more { margin-top: var(--sp-2); }
details.more div { margin-top: 2px; overflow-wrap: anywhere; }
details.gtins { margin-top: var(--sp-4); padding-top: var(--sp-3); border-top: 1px solid var(--line); }
details.gtins .chips { margin-top: var(--sp-3); }

ol.checklist { margin: 0 0 var(--sp-5); padding: 0; list-style: none; }
ol.checklist li { position: relative; min-height: 56px; padding: var(--sp-3) 0 var(--sp-3) 40px; border-bottom: 1px solid var(--line); }
ol.checklist li:last-child { border-bottom: 0; }
ol.checklist li::before { content: ""; position: absolute; left: 0; top: 14px; display: grid; width: 26px; height: 26px; place-items: center; border: 2px solid var(--wait); border-radius: 50%; color: var(--wait); font-size: 13px; font-weight: 800; }
ol.checklist li.done::before { content: "✓"; border-color: var(--ok); background: var(--ok); color: var(--surface); }
ol.checklist li .small { display: block; }

ol.timeline { margin: var(--sp-3) 0 var(--sp-4); padding: 0; list-style: none; }
ol.timeline li { position: relative; display: grid; grid-template-columns: 1fr auto; gap: var(--sp-3); min-height: 44px; padding: var(--sp-2) 0 var(--sp-2) 32px; color: var(--fg-muted); font-size: var(--fs-sm); }
ol.timeline li::before { content: ""; position: absolute; left: 6px; top: 14px; width: 12px; height: 12px; border: 2px solid var(--line-strong); border-radius: 50%; background: var(--surface); }
ol.timeline li::after { content: ""; position: absolute; left: 11px; top: 28px; bottom: -8px; width: 2px; background: var(--line); }
ol.timeline li:last-child::after { content: none; }
ol.timeline li.done { color: var(--fg); }
ol.timeline li.done::before { border-color: var(--ok); background: var(--ok); }
ol.timeline li.bad::before { border-color: var(--bad); background: var(--bad); }
ol.timeline .t { font-weight: 600; }
ol.timeline .d { font-variant-numeric: tabular-nums; color: var(--fg-muted); }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-5); }
a.tile { display: flex; min-height: 128px; flex-direction: column; gap: var(--sp-2); padding: var(--sp-5); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); color: var(--fg); text-decoration: none; box-shadow: var(--sh-1); }
a.tile:hover { border-color: var(--accent); box-shadow: var(--sh-2); color: var(--fg); }
a.tile .ico { width: 26px; height: 26px; color: var(--accent); }
a.tile b { font-size: var(--fs-md); }

.signer { max-width: 680px; }
.picker { max-width: 560px; margin-top: var(--sp-4); padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); }
.picker button { margin-top: var(--sp-3); }
.secondary-actions { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-4); margin-top: var(--sp-6); padding-top: var(--sp-3); border-top: 1px dashed var(--line-strong); }
.secondary-actions form.inline { margin: 0; }
.filters { margin: 0 0 var(--sp-4); padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--surface); }
.filters .form-row { margin-top: var(--sp-3); }
.product-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); padding: var(--sp-4); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--r-md); background: var(--surface); }

.auth-shell main { display: grid; min-height: 100vh; place-content: center; padding: var(--sp-5); }
.auth-panel { width: min(100%, 420px); margin: 0 auto; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-6); text-align: center; }
.auth-brand .ico { width: 44px; height: 44px; color: var(--accent); }
.auth-brand h1 { font-size: var(--fs-xl); }
.auth-panel .card { padding: var(--sp-7); box-shadow: var(--sh-2); }
.auth-panel button[type="submit"] { width: 100%; margin-top: var(--sp-5); }

@media (max-width: 767px) {
  .page-head { flex-direction: column; align-items: stretch; }
  .page-head-actions { justify-content: stretch; }
  .page-head-actions > *, .page-head-actions > form > button { width: 100%; }
  .card { padding: var(--sp-4); border-radius: var(--r-md); }
  .btn-lg { width: 100%; }
  .options, .tiles { grid-template-columns: 1fr; }
  ol.stepper { flex-direction: column; gap: var(--sp-1); }
  ol.stepper li { padding: var(--sp-1) 0; }
  ol.stepper li + li::before { left: 12px; top: -6px; width: 2px; height: 8px; }
  ol.stepper .t { white-space: normal; }
  nav.tabs, .chips.scroll-x { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  nav.tabs::-webkit-scrollbar, .chips.scroll-x::-webkit-scrollbar { display: none; }
  nav.tabs a { flex: 1 0 auto; }
  .product-head { flex-direction: column; align-items: stretch; }
  .product-head .button { width: 100%; }
  .secondary-actions { gap: var(--sp-2); }
  .secondary-actions button { width: 100%; justify-content: flex-start; }
  .workflow-grid { grid-template-columns: 1fr; }
  .section-head { flex-direction: column; align-items: stretch; }
  .section-actions, .section-actions form, .section-actions button { width: 100%; }
  .filterbar { align-items: flex-start; }
  .filterbar-label { width: 100%; }
  .empty-state { align-items: flex-start; padding: var(--sp-4); }
}
@media (max-width: 419px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi b { font-size: var(--fs-xl); }
  .actionbar .acts { grid-template-columns: 1fr; }
  .actionbar .acts .primary { grid-column: auto; }
  .chips { gap: var(--sp-1); }
}

@media (max-width: 1023px) {
  body.app-shell { grid-template-columns: var(--sidebar-w-min) minmax(0, 1fr); }
  .sidebar { padding-inline: var(--sp-2); }
  .brand { justify-content: center; padding: 0; }
  .brand span { display: none; }
  nav.main a { width: 48px; padding: 0 0 0 13px; }     /* подпись уезжает за край и клипается */
  .sidebar-foot { justify-content: center; padding-inline: 0; }
  .sidebar-foot .name { display: none; }
  .topbar { padding-inline: var(--sp-4); }
  main, main.wide { padding: var(--sp-5) var(--sp-4) var(--sp-8); }
}
@media (max-width: 767px) {
  body.app-shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main"; }
  .sidebar { display: none; }
  .topbar { padding-inline: var(--sp-4); }
  .topbar-title { color: var(--fg); font-size: var(--fs-md); font-weight: 700; }
  .user-menu .name { display: none; }
  main, main.wide { padding: var(--sp-4) var(--sp-4) var(--sp-7); }
  body.has-bottombar main { padding-bottom: calc(var(--bottombar-h) + env(safe-area-inset-bottom) + var(--sp-6)); }
  .bottombar {
    position: fixed;
    inset: auto 0 0 0;
    z-index: var(--z-shell);
    display: flex;
    min-height: var(--bottombar-h);
    padding-bottom: env(safe-area-inset-bottom);
    border-top: 1px solid var(--line);
    background: var(--surface);
    box-shadow: 0 -1px 0 var(--line);
  }
  .bottombar a {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-width: 0;
    min-height: var(--bottombar-h);
    padding: 6px 2px;
    color: var(--fg-muted);
    font-size: 11px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .bottombar a .ico { width: 24px; height: 24px; }
  .bottombar a.on { color: var(--accent-ink); }
  .bottombar a.on .ico { color: var(--accent); }
}
@media (max-width: 419px) {
  .conn { padding-inline: 10px; }
  .conn-ok .conn-text { display: none; }   /* зелёная точка, подробности по title */
}

/* «Коды»: one code's DataMatrix on click (OD-48) */
.ico-dm { --ico: url(/static/icons/dm.svg); width: 22px; height: 22px; }
.dm-cell { white-space: nowrap; }
.dm-open { padding: 4px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface);
  cursor: pointer; line-height: 0; color: var(--text); vertical-align: middle; }
.dm-open:hover { border-color: var(--accent); color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.dm-dialog { border: 1px solid var(--line-strong); border-radius: 14px; padding: 20px; max-width: 420px; width: calc(100% - 32px); }
.dm-dialog::backdrop { background: rgba(15, 23, 42, .45); }
.dm-head { display: flex; justify-content: space-between; align-items: center; }
.dm-ki { overflow-wrap: anywhere; margin: 6px 0 10px; }
.dm-view { display: flex; justify-content: center; min-height: 240px; align-items: center; background: #fff; border-radius: 8px; }
.dm-view svg { width: 260px; height: 260px; max-width: 100%; }
.dm-acts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* ЧЗ balance in the side menu (OD-48) */
.sidebar-balance { display: flex; flex-direction: column; gap: 2px; margin: auto 12px 8px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.sidebar-balance b { font-size: 16px; font-variant-numeric: tabular-nums; }
.sidebar-balance + .sidebar-foot { margin-top: 0; }

/* mini DataMatrix in the list (OD-53) */
.dm-switch { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: center; margin: 4px 0 8px; }
.dm-thumb.dm-on { padding: 2px; background: #fff; }
.dm-thumb.dm-on .ico { display: none; }
.dm-thumb svg { width: 52px; height: 52px; display: block; }
.dm-none { white-space: normal; }
.progress.bad .progress-text { color: var(--bad); font-weight: 600; }
.fold-toggle { margin-top: var(--sp-3); }
/* УПД с кодами маркировки (КИЗ) выделены: зелёная полоса слева и значок «КИЗ N» */
tr.has-ki > td { background: color-mix(in srgb, var(--ok-soft) 70%, transparent); }
tr.has-ki > td:first-child { box-shadow: inset 4px 0 0 var(--ok); }
.ki-badge { display: inline-block; padding: 1px 8px; border: 1px solid var(--ok-line); border-radius: var(--r-pill); background: var(--ok-soft); color: var(--ok); font-weight: 700; font-size: var(--fs-sm); white-space: nowrap; }

/* «Отправить УПД в Ozon» (W7.6, OD-61) */
.dropzone { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: var(--sp-2);
  min-height: 112px; margin: var(--sp-3) 0; padding: var(--sp-5); border: 2px dashed var(--line-strong);
  border-radius: var(--r-lg); background: var(--surface-2); text-align: center; cursor: pointer; }
.dropzone.over { border-color: var(--accent); background: var(--surface); }
.dropzone input[type="file"] { max-width: 100%; }
.confirm-box { margin-top: var(--sp-4); padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); }
ol.steps { margin: var(--sp-3) 0; padding-left: var(--sp-5); }
ol.steps li { margin-bottom: var(--sp-3); }
ol.steps .badge { margin: 0 var(--sp-2); }
.card .scroll { margin-top: var(--sp-4); }
.card .scroll > table.grid th { top: 0; }
.kpi small { color: var(--fg-muted); font-size: 11px; line-height: 1.3; }
.banner-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--sp-3); }
.banner-row > div { flex: 1 1 420px; min-width: 0; }
/* «Обновить баланс» (OD-62) */
button.conn-balance { background: var(--surface); cursor: pointer; font-family: inherit; }
button.conn-balance:hover { border-color: var(--accent); color: var(--accent-ink); }
.conn-refresh { font-size: 14px; line-height: 1; }
.js-balance-refresh.loading .conn-refresh { display: inline-block; animation: km-spin .8s linear infinite; }
.sidebar-balance .js-balance-refresh { align-self: flex-start; min-height: 0; margin-top: 4px; padding: 0; font-size: var(--fs-xs); }
@keyframes km-spin { to { transform: rotate(360deg); } }
/* QR-код для приложения с кодами (OD-64): белый фон и в тёмной теме */
.qr-box { display: inline-block; margin: var(--sp-3) 0; padding: 8px; border-radius: var(--r-md); background: #fff; }
.qr-box svg { display: block; width: 240px; height: 240px; }
