/* ============ Токены (общие с прототипом LD) ============ */
/* Рабочий инструмент плановика: плотная таблица, цифры моноширинным, жёлтый — только главное действие. */
:root {
  --brand: #FFEE00; --brand-press: #F2E200; --brand-tint: #FFFBDB;
  --ink: #141414;
  --bg: #FFFFFF; --surface: #FFFFFF; --surface-2: #F5F5F2; --surface-3: #ECECE7;
  --line: #E3E3DF; --line-strong: #8F8F89;
  --text: #1A1A1A; --text-2: #5A5A55; --text-3: #6B6B66;
  --ok: #1A7F37; --ok-tint: #EAF5EC;
  --low: #8A5A00; --low-tint: #FFF4D6;
  --danger: #B42318; --danger-tint: #FDECEA;
  --info: #0B57D0; --info-tint: #E8F0FE;
  --focus: var(--ink);
  --r-s: 2px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px; --s12: 48px;
  --row: 48px;
  --shadow-2: 0 24px 64px rgba(20, 20, 20, .22);
  --f-ui: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --f-head: "Inter Tight", Inter, system-ui, -apple-system, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }
body { margin: 0; background: var(--bg); color: var(--text); font: 400 14px/1.5 var(--f-ui); font-feature-settings: "tnum" 1, "cv11" 1; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
.sr { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: var(--s4); top: -60px; background: var(--ink); color: #fff; padding: var(--s2) var(--s4); z-index: 100; }
.skip:focus { top: var(--s2); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
main:focus { outline: none; }
.muted { color: var(--text-2); }
.mono, .num { font-family: var(--f-mono); font-size: 13px; }
.num { text-align: right; white-space: nowrap; }
.wrap { max-width: 1440px; margin: 0 auto; padding: 0 var(--s8) var(--s12); }
@media (max-width: 720px) { .wrap { padding: 0 var(--s4) var(--s10); } }

/* ============ Кнопки и поля ============ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: var(--s2); min-height: 40px; padding: 0 16px;
  border-radius: var(--r-s); border: 1px solid var(--ink); background: transparent; color: var(--ink); font-weight: 500; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--ink); color: #fff; }
.btn--primary { background: var(--brand); border-color: var(--brand); font-weight: 600; }
.btn--primary:hover { background: var(--brand-press); border-color: var(--brand-press); color: var(--ink); }
.btn--ghost { border-color: transparent; }
.btn--ghost:hover { background: var(--surface-2); color: var(--ink); }
.btn--sm { min-height: 32px; padding: 0 12px; font-size: 13px; }
.btn[disabled] { opacity: 1; background: var(--surface-2); border-color: var(--line); color: var(--text-3); cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-weight: 500; }
.link:hover { text-decoration-thickness: 2px; }
.field { display: grid; gap: var(--s1); }
.field > span { font-size: 13px; color: var(--text-2); }
.input, select { min-height: 40px; padding: 0 var(--s3); border: 1px solid var(--line-strong); border-radius: var(--r-s); background: #fff; }
.input:focus, select:focus { outline: 2px solid var(--ink); outline-offset: 0; border-color: var(--ink); }
.hint { font-size: 12px; color: var(--text-3); }

/* ============ Шапка ============ */
.top { position: sticky; top: 0; z-index: 20; background: var(--ink); color: #fff; }
.top__in { max-width: 1440px; margin: 0 auto; padding: 0 var(--s8); height: 56px; display: flex; align-items: center; gap: var(--s4); }
@media (max-width: 720px) { .top__in { padding: 0 var(--s4); } }
.brand { display: flex; align-items: center; gap: var(--s3); color: #fff; text-decoration: none; font-weight: 600; }
.brand__mark { background: var(--brand); color: var(--ink); font: 700 15px/1 var(--f-head); padding: 6px 7px; letter-spacing: -.02em; }
.brand__name .muted { color: #B5B5AF; }
.top__tools { margin-left: auto; display: flex; align-items: center; gap: var(--s2); }
.top .btn--ghost { color: #fff; }
.top .btn--ghost:hover { background: rgba(255,255,255,.12); color: #fff; }
.top select { background: transparent; color: #fff; border-color: rgba(255,255,255,.36); max-width: 300px; }
.top select option { color: var(--ink); }
.top :focus-visible { outline-color: var(--brand); }
.top__tools, .src { min-width: 0; }
.src select { width: 100%; }
@media (max-width: 720px) { .brand__name .muted, #btn-upload { display: none; } .top__in { gap: var(--s2); } .top select { max-width: none; } .top .btn--ghost { padding: 0 10px; } }
@media (max-width: 520px) { .brand__name { display: none; } }

/* ============ Заголовок плана ============ */
.head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s4) var(--s8); padding: var(--s8) 0 var(--s6); border-bottom: 1px solid var(--line); }
.head__main { flex: 1 1 420px; min-width: 0; }
.eyebrow { font-size: 13px; color: var(--text-2); margin-bottom: var(--s2); }
.h1 { font: 600 32px/1.1 var(--f-head); letter-spacing: -.02em; color: var(--ink); }
.h1 small { font: 400 20px/1.2 var(--f-ui); color: var(--text-2); letter-spacing: 0; margin-left: var(--s2); white-space: nowrap; }
.meta { margin-top: var(--s2); color: var(--text-2); font-size: 13px; display: flex; flex-wrap: wrap; gap: 0 var(--s4); }
.meta b { font-weight: 500; color: var(--text); }
.head__act { display: flex; flex-direction: column; align-items: flex-end; gap: var(--s2); }
.head__btns { display: flex; gap: var(--s2); flex-wrap: wrap; justify-content: flex-end; }
.head__why { font-size: 13px; color: var(--text-2); max-width: 360px; text-align: right; }
@media (max-width: 720px) { .h1 { font-size: 26px; } .h1 small { display: block; margin: var(--s1) 0 0; font-size: 16px; } .head__act { align-items: stretch; width: 100%; } .head__btns .btn { flex: 1; } .head__why { text-align: left; } }

.status { display: inline-flex; align-items: center; gap: var(--s2); font-size: 13px; font-weight: 500; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--line-strong); }
.status--ok::before { background: var(--ok); }
.status--draft::before { background: var(--low); border-radius: 0; }

/* ============ Линии ============ */
.lines { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); border-bottom: 1px solid var(--line); }
.ln { all: unset; box-sizing: border-box; display: grid; gap: var(--s2); padding: var(--s5) var(--s6) var(--s5) 0; cursor: pointer; border-right: 1px solid var(--line); margin-right: var(--s6); }
.ln:last-child { border-right: 0; }
.ln:hover .ln__name { text-decoration: underline; text-underline-offset: 3px; }
.ln:focus-visible { outline: 2px solid var(--ink); outline-offset: -2px; }
.ln[aria-pressed="true"] .ln__name::after { content: " · выбрана"; color: var(--text-2); font-weight: 400; }
.ln__name { font-weight: 600; }
.ln__big { display: flex; align-items: baseline; gap: var(--s3); }
.ln__shifts { font: 600 28px/1 var(--f-head); color: var(--ink); }
.ln__unit { color: var(--text-2); }
.ln__bar { display: flex; gap: 3px; flex-wrap: wrap; min-height: 12px; }
.ln__bar i { width: 18px; height: 12px; background: var(--ink); }
.ln__bar i.part { background: linear-gradient(90deg, var(--ink) var(--p), var(--surface-3) var(--p)); }
.ln__bar i.add { background: repeating-linear-gradient(135deg, var(--ink) 0 3px, var(--line-strong) 3px 5px); }
.ln__sub { font-size: 13px; color: var(--text-2); }
.ln--empty .ln__shifts { color: var(--text-3); }
@media (max-width: 720px) { .ln { border-right: 0; border-bottom: 1px solid var(--line); margin-right: 0; padding-right: 0; } .ln:last-child { border-bottom: 0; } }

/* ============ Помощник ============ */
.assist { display: grid; grid-template-columns: minmax(0, 1fr) minmax(280px, 380px); gap: var(--s8); padding: var(--s6) 0; border-bottom: 1px solid var(--line); }
@media (max-width: 980px) { .assist { grid-template-columns: 1fr; gap: var(--s4); } }
.h2 { font: 600 18px/1.25 var(--f-head); color: var(--ink); }
.h2 .cnt { font: 500 13px/1 var(--f-mono); background: var(--ink); color: #fff; padding: 3px 6px; margin-left: var(--s2); vertical-align: 2px; }
.finds { list-style: none; margin: var(--s3) 0 0; padding: 0; display: grid; gap: 0; }
.find { display: grid; grid-template-columns: 4px minmax(0, 1fr) auto; gap: var(--s4); padding: var(--s3) 0; border-top: 1px solid var(--line); }
.find:first-child { border-top: 0; }
.find__mark { background: var(--line-strong); }
.find--block .find__mark { background: var(--danger); }
.find--warn .find__mark { background: var(--low); }
.find--info .find__mark { background: var(--info); }
.find__lvl { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.find--block .find__lvl { color: var(--danger); }
.find--warn .find__lvl { color: var(--low); }
.find--info .find__lvl { color: var(--info); }
.find__title { font-weight: 600; margin-top: 2px; }
.find__text { color: var(--text-2); margin-top: 2px; max-width: 80ch; }
.find__act { display: flex; flex-direction: column; gap: var(--s1); align-items: flex-end; justify-content: center; }
@media (max-width: 720px) { .find { grid-template-columns: 4px minmax(0, 1fr); } .find__act { grid-column: 2; flex-direction: row; align-items: center; justify-content: flex-start; flex-wrap: wrap; } }
.allgood { margin-top: var(--s3); padding: var(--s4); background: var(--ok-tint); color: var(--ok); font-weight: 500; }
.auto { background: var(--surface-2); padding: var(--s4) var(--s5); align-self: start; }
.auto summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; justify-content: space-between; gap: var(--s2); }
.auto summary::-webkit-details-marker { display: none; }
.auto summary::after { content: "Показать"; font-weight: 400; color: var(--text-2); text-decoration: underline; text-underline-offset: 3px; }
.auto[open] summary::after { content: "Скрыть"; }
.auto p { color: var(--text-2); font-size: 13px; margin-top: var(--s1); }
.auto ul { margin: var(--s3) 0 0; padding-left: 18px; display: grid; gap: var(--s2); font-size: 13px; }

/* ============ Таблица позиций ============ */
.pos { padding-top: var(--s6); }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3) var(--s4); margin-bottom: var(--s3); }
.tabs { display: flex; gap: 0; border: 1px solid var(--line-strong); border-radius: var(--r-s); }
.tab { all: unset; cursor: pointer; padding: 0 var(--s4); min-height: 38px; display: inline-flex; align-items: center; gap: var(--s2); font-weight: 500; border-right: 1px solid var(--line); }
.tab:last-child { border-right: 0; }
.tab[aria-selected="true"] { background: var(--ink); color: #fff; }
.tab:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
.tab .n { font: 400 12px/1 var(--f-mono); opacity: .8; }
.search { position: relative; flex: 1 1 240px; max-width: 360px; }
.search .input { width: 100%; padding-right: 40px; }
.search kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font: 12px var(--f-mono); color: var(--text-3); border: 1px solid var(--line); padding: 1px 6px; }
.chip { display: inline-flex; align-items: center; gap: var(--s2); background: var(--brand-tint); border: 1px solid var(--ink); padding: 0 4px 0 10px; min-height: 32px; font-size: 13px; font-weight: 500; }
.chip button { all: unset; cursor: pointer; width: 24px; height: 24px; display: grid; place-items: center; font-size: 16px; }
.chip button:focus-visible { outline: 2px solid var(--ink); }
.bar__right { margin-left: auto; display: flex; gap: var(--s2); }
@media (max-width: 720px) { .bar__right { margin-left: 0; } .search { max-width: none; } }

/* На широком экране шапка таблицы липнет к странице; на узком таблица прокручивается вбок внутри себя */
.tbl-wrap { border-top: 2px solid var(--ink); }
@media (max-width: 1100px) { .tbl-wrap { overflow-x: auto; } .tbl-wrap .tbl th { top: 0; position: static; } .tbl-wrap .tbl th:first-child { position: sticky; left: 0; } }
table.tbl { width: 100%; border-collapse: collapse; min-width: 980px; }
.tbl th { position: sticky; top: 56px; background: #fff; z-index: 2; text-align: left; font-weight: 500; font-size: 12px; color: var(--text-2); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--line-strong); vertical-align: bottom; white-space: nowrap; }
.tbl th.num { text-align: right; }
.tbl th button { all: unset; cursor: pointer; display: inline-flex; gap: 4px; align-items: center; }
.tbl th button:focus-visible { outline: 2px solid var(--ink); }
.tbl th[aria-sort] button::after { content: "↓"; font-family: var(--f-mono); color: var(--ink); }
.tbl th[aria-sort="ascending"] button::after { content: "↑"; }
.tbl td { padding: 0 var(--s3); height: var(--row); border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tbody tr { cursor: pointer; }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl tbody tr.is-sel td { background: var(--brand-tint); }
.tbl tbody tr.is-zero td:not(:first-child) { color: var(--text-3); }
.tbl td:first-child, .tbl th:first-child { position: sticky; left: 0; background: inherit; padding-left: 0; }
.tbl td:first-child, .tbl th:first-child { background: #fff; }
.tbl th:first-child { z-index: 3; }
.tbl tbody tr:hover td:first-child { background: var(--surface-2); }
.tbl tbody tr.is-sel td:first-child { background: var(--brand-tint); }
.tbl th.num { font-family: var(--f-ui); font-size: 12px; }
.tbl .nm { text-align: left; font-weight: 500; display: block; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tbl .nm-sub { font-size: 12px; color: var(--text-3); }
/* Телефон: только то, что нужно для решения — позиция, продажи, остаток, план, запас, излишек */
@media (max-width: 720px) {
  table.tbl { min-width: 0; }
  .tbl th:nth-child(2), .tbl td:nth-child(2), .tbl th:nth-child(6), .tbl td:nth-child(6), .tbl th:nth-child(7), .tbl td:nth-child(7) { display: none; }
  .tbl .nm { max-width: 150px; white-space: normal; font-size: 13px; line-height: 1.3; }
  .tbl td:first-child { padding: var(--s2) var(--s2) var(--s2) 0; max-width: 160px; }
  .tbl td, .tbl th { padding-left: var(--s2); padding-right: var(--s2); }
  .tbl th { white-space: normal; }
  .qty { width: 72px; }
  .tab { padding: 0 var(--s3); white-space: nowrap; font-size: 13px; }
}
.tbl tfoot td { font-weight: 600; border-top: 2px solid var(--ink); border-bottom: 0; height: 44px; }
.tag { display: inline-block; font-size: 12px; padding: 1px 6px; border: 1px solid var(--line-strong); white-space: nowrap; }
.tag--mass { background: var(--ink); color: #fff; border-color: var(--ink); }
.tag--series { background: #fff; }
.tag--small { color: var(--text-3); border-style: dashed; }
.qty { width: 92px; min-height: 34px; text-align: right; font: 500 14px var(--f-mono); padding: 0 8px; border: 1px solid var(--line-strong); border-radius: var(--r-s); background: #fff; }
.qty:focus { outline: 2px solid var(--ink); border-color: var(--ink); }
.qty.is-over { background: var(--brand-tint); border-color: var(--ink); }
.qty-cell { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.reset { all: unset; cursor: pointer; width: 24px; height: 24px; display: grid; place-items: center; color: var(--text-2); font-size: 15px; }
.reset:hover { color: var(--ink); }
.reset:focus-visible { outline: 2px solid var(--ink); }
.was { display: block; font: 12px var(--f-mono); color: var(--text-3); text-align: right; }
.sig { font: 500 13px var(--f-mono); white-space: nowrap; }
.sig--bad { color: var(--danger); }
.sig--warn { color: var(--low); }
.sig--ok { color: var(--ok); }
.sig::before { display: inline-block; width: 14px; }
.sig--bad::before { content: "▼"; }
.sig--warn::before { content: "▲"; }
.empty { padding: var(--s10) 0; text-align: center; color: var(--text-2); display: grid; gap: var(--s3); justify-items: center; }
.empty b { color: var(--text); font-size: 16px; }

/* ============ Боковая панель позиции ============ */
.scrim { position: fixed; inset: 0; background: rgba(20,20,20,.32); z-index: 40; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(560px, 100vw); background: #fff; z-index: 41; box-shadow: var(--shadow-2); display: flex; flex-direction: column; }
.drawer__head { padding: var(--s5) var(--s6); border-bottom: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: var(--s2) var(--s4); }
.drawer__title { font: 600 18px/1.3 var(--f-head); color: var(--ink); }
.drawer__tags { display: flex; flex-wrap: wrap; gap: var(--s2); font-size: 13px; color: var(--text-2); grid-column: 1 / -1; }
.drawer__body { overflow-y: auto; padding: var(--s5) var(--s6) var(--s8); display: grid; gap: var(--s6); align-content: start; }
.x { all: unset; cursor: pointer; width: 40px; height: 40px; display: grid; place-items: center; font-size: 22px; margin: -8px -8px 0 0; }
.x:hover { background: var(--surface-2); }
.x:focus-visible { outline: 2px solid var(--ink); }
.plan-box { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s4); padding: var(--s4); background: var(--surface-2); }
.plan-box .big { font: 600 32px/1 var(--f-head); color: var(--ink); }
.plan-box .field { flex: 0 0 auto; }
.chain { list-style: none; margin: 0; padding: 0; counter-reset: c; }
.chain li { display: grid; grid-template-columns: 24px 1fr auto; gap: 0 var(--s3); padding: var(--s2) 0; border-bottom: 1px dashed var(--line); }
.chain li::before { counter-increment: c; content: counter(c); font: 12px var(--f-mono); color: var(--text-3); padding-top: 2px; }
.chain .k { font-weight: 500; }
.chain .v { font: 500 14px var(--f-mono); text-align: right; white-space: nowrap; }
.chain .note { grid-column: 2 / -1; font-size: 12px; color: var(--text-3); }
.chain li.total { border-bottom: 0; border-top: 2px solid var(--ink); }
.chain li.total .k, .chain li.total .v { font-weight: 700; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 var(--s6); margin: 0; }
.facts div { display: flex; justify-content: space-between; gap: var(--s3); padding: var(--s2) 0; border-bottom: 1px solid var(--line); }
.facts dt { color: var(--text-2); }
.facts dd { margin: 0; font: 500 13px var(--f-mono); white-space: nowrap; }
@media (max-width: 520px) { .facts { grid-template-columns: 1fr; } }
.chart { width: 100%; height: auto; display: block; }
.chart text { font: 11px var(--f-mono); fill: var(--text-3); }
.legend { display: flex; flex-wrap: wrap; gap: var(--s4); font-size: 12px; color: var(--text-2); margin-top: var(--s2); }
.legend i { display: inline-block; width: 12px; height: 10px; margin-right: 6px; vertical-align: -1px; }

/* ============ Диалог параметров ============ */
.dlg { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: var(--s4); background: rgba(20,20,20,.32); }
.dlg__box { background: #fff; width: min(760px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: var(--shadow-2); }
.dlg__head { display: flex; justify-content: space-between; gap: var(--s4); padding: var(--s5) var(--s6); border-bottom: 1px solid var(--line); }
.dlg__body { overflow-y: auto; padding: var(--s5) var(--s6); display: grid; gap: var(--s6); }
.dlg__foot { display: flex; gap: var(--s2); justify-content: flex-end; padding: var(--s4) var(--s6); border-top: 1px solid var(--line); flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--s4); }
.autoval { font: 500 14px var(--f-mono); min-height: 40px; display: flex; align-items: center; gap: var(--s2); }
.autoval .tag { font-family: var(--f-ui); }
table.mini { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini th, .mini td { padding: var(--s2); border-bottom: 1px solid var(--line); text-align: left; }
.mini th { font-weight: 500; color: var(--text-2); font-size: 12px; }
.mini .input { min-height: 34px; width: 90px; text-align: right; font-family: var(--f-mono); }
.method { font-size: 13px; color: var(--text-2); display: grid; gap: var(--s2); }
.method b { color: var(--text); font-weight: 500; }

/* ============ Тосты, загрузка ============ */
.toasts { position: fixed; left: 50%; bottom: var(--s6); transform: translateX(-50%); z-index: 60; display: grid; gap: var(--s2); width: min(560px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: #fff; padding: var(--s3) var(--s4); display: flex; align-items: center; gap: var(--s4); box-shadow: var(--shadow-2); }
.toast--err { background: var(--danger); }
.toast span { flex: 1; }
.toast button { all: unset; cursor: pointer; font-weight: 600; color: var(--brand); text-decoration: underline; text-underline-offset: 3px; }
.toast--err button { color: #fff; }
.toast button:focus-visible { outline: 2px solid var(--brand); }
.skel { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: sh 1.2s infinite linear; margin-top: var(--s6); }
.skel--head { height: 96px; } .skel--block { height: 140px; } .skel--table { height: 420px; }
@keyframes sh { to { background-position: -200% 0; } }
.err-page { padding: var(--s12) 0; display: grid; gap: var(--s3); max-width: 640px; }
.banner { margin-top: var(--s4); padding: var(--s3) var(--s4); background: var(--low-tint); border-left: 4px solid var(--low); font-size: 13px; }
.banner b { font-weight: 600; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
