/* «Где товар» — рабочий экран внутри МоегоСклада.
   Стиль: светлая «книга учёта». Цвета в оформлении нет; один цвет (синий, как у МоегоСклада)
   только на данных — «ушло с клиента». Числа — ровными цифрами, вправо.
   Сетка: поле 24px по краям, один зазор 16px; таблица и сводка во всю ширину поля. */
:root {
  --ground: #f6f7f8;  --surface: #ffffff;  --raised: #f9fafb;  --active: #eef0f2;
  --border: #e6e8eb;  --rule: #f0f2f4;     --control: #cfd4da;
  --text: #15191e;    --muted: #5d646d;    --faint: #6b7178;
  --primary: #1b1f24;
  --accent: #1d6fb8;                 /* ушло с клиента */
  --stock: #b9c0c9;                  /* лежит у клиента */
  --positive: #23794e;  --negative: #c4242a;
  --pill-warning-bg: #fff8e6;  --pill-warning-ink: #8a4b0b;  --notice-border: #f3dc9b;
  --pill-negative-bg: #ffedea; --pill-negative-ink: #831c1e;

  --radius-card: 8px;  --radius-control: 6px;  --radius-chip: 4px;
  --gap: 16px;  --pad: 24px;  --card-pad: 20px;
  --control-height: 34px;  --row: 44px;
  --font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --fs-title: 24px; --fs-lead: 32px; --fs-kpi: 24px; --fs-body: 14px; --fs-small: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--ground); color: var(--text); font: 400 var(--fs-body)/20px var(--font);
  -webkit-font-smoothing: antialiased; }
.num, td.n, th.n { font-variant-numeric: tabular-nums; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.screen { padding: 20px var(--pad) 40px; max-width: 1480px; margin: 0 auto; }

/* --- заголовок */
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.title { display: flex; align-items: center; gap: 12px; }
.mark { width: 28px; height: 28px; flex: none; }
h1 { font-size: var(--fs-title); line-height: 32px; font-weight: 600; margin: 0; letter-spacing: -0.01em; }
.scope { color: var(--muted); }
.finding { margin: 6px 0 0; color: var(--muted); font-size: 15px; line-height: 22px; max-width: 900px; }
.finding b { color: var(--text); font-weight: 500; }
.chz { display: flex; align-items: center; gap: 12px; color: var(--muted); min-height: var(--control-height); }
.chz .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--stock); flex: none; }
.chz.on .dot { background: var(--positive); }
.chz.off .dot { background: var(--negative); }
.chz strong { color: var(--text); font-weight: 500; }

/* --- кнопки и поля */
.btn { height: var(--control-height); padding: 0 14px; border-radius: var(--radius-control); border: 1px solid var(--control);
  background: var(--surface); cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 8px; }
.btn:hover { border-color: #9aa3ad; }
.btn:focus-visible, .pick:focus-visible, .link:focus-visible, tr.click:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 500; }
.btn.primary:hover { background: #000; }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.link:hover { text-decoration: underline; }

/* --- фильтры */
.filters { display: flex; align-items: flex-end; gap: 12px; margin-top: 20px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: var(--fs-small); color: var(--muted); }
.pick { height: var(--control-height); min-width: 220px; max-width: 360px; padding: 0 32px 0 12px; text-align: left;
  border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface) no-repeat right 10px center;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5l3 3 3-3' fill='none' stroke='%235d646d' stroke-width='1.5'/%3E%3C/svg%3E");
  cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick:hover { border-color: #9aa3ad; }
.filters .go { margin-left: auto; display: flex; gap: 12px; align-items: center; }
.filters .go .hint { color: var(--muted); font-size: 13px; }

/* выпадающие окна (плавают — тень допустима) */
.pop { position: absolute; z-index: 20; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  box-shadow: 0 8px 24px rgba(16, 24, 32, .12); width: 380px; max-width: calc(100vw - 32px); }
.pop .pop-head { padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 8px; }
.pop input[type=search], .pop input[type=date] { height: var(--control-height); border: 1px solid var(--control);
  border-radius: var(--radius-control); padding: 0 10px; width: 100%; background: var(--surface); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { height: 26px; padding: 0 10px; border-radius: 13px; border: 1px solid var(--control); background: var(--surface);
  cursor: pointer; font-size: 13px; white-space: nowrap; }
.tag[aria-pressed=true] { background: var(--primary); border-color: var(--primary); color: #fff; }
.pop .list { max-height: 320px; overflow: auto; padding: 4px 0; border-top: 1px solid var(--rule); }
.opt { display: flex; align-items: center; gap: 10px; padding: 7px 12px; cursor: pointer; min-height: 36px; }
.opt:hover { background: var(--raised); }
.opt input { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); flex: none; }
.opt .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.opt .meta { color: var(--faint); font-size: var(--fs-small); flex: none; }
.pop .pop-foot { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px;
  border-top: 1px solid var(--rule); color: var(--muted); font-size: 13px; gap: 12px; }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 8px; }
.preset { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: var(--radius-control); cursor: pointer; }
.preset:hover { background: var(--raised); }
.preset[aria-pressed=true] { background: var(--active); font-weight: 500; }
.dates { display: flex; gap: 8px; align-items: center; padding: 8px 12px 12px; border-top: 1px solid var(--rule); }

/* --- ход проверки */
.run { margin-top: var(--gap); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: 14px var(--card-pad); display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; align-items: center; }
.run .what { font-weight: 500; }
.run .what span { color: var(--muted); font-weight: 400; }
.run .bar { grid-column: 1 / -1; height: 4px; background: var(--rule); border-radius: 2px; overflow: hidden; }
.run .bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .4s ease; }
.run .note { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.run.bad { border-color: #f1c8c4; }
.run.bad .what { color: var(--pill-negative-ink); }

.notice { margin-top: var(--gap); padding: 10px 14px; border: 1px solid var(--notice-border); background: var(--pill-warning-bg);
  color: var(--pill-warning-ink); border-radius: var(--radius-card); font-size: 13px; }

/* --- выбор подписи */
.sign { margin-top: var(--gap); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  padding: 14px var(--card-pad); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.sign select { height: var(--control-height); border: 1px solid var(--control); border-radius: var(--radius-control);
  padding: 0 8px; max-width: 100%; background: var(--surface); }

/* --- сводка: одна панель, колонки через линии */
.kpis { margin-top: var(--gap); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card);
  display: grid; grid-template-columns: 1.3fr 1fr 1fr 1fr; }
.kpi { padding: 16px var(--card-pad) 18px; border-left: 1px solid var(--border); min-width: 0; }
.kpi:first-child { border-left: 0; }
.kpi .l { color: var(--muted); }
.kpi .v { font-size: var(--fs-kpi); line-height: 32px; font-weight: 500; margin-top: 6px; letter-spacing: -0.01em; }
.kpi .v small { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 4px; letter-spacing: 0; }
.kpi.lead .v { font-size: var(--fs-lead); line-height: 40px; color: var(--accent); }
.kpi .d { margin-top: 4px; font-size: 13px; color: var(--muted); min-height: 18px; }
.kpi .d .up { color: var(--positive); font-weight: 500; }
.kpi .d .down { color: var(--negative); font-weight: 500; }
.kpi .s { margin-top: 2px; font-size: 13px; color: var(--muted); }

/* --- таблица клиентов */
.panel { margin-top: var(--gap); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px var(--card-pad) 10px; flex-wrap: wrap; }
.panel-head h2 { font-size: 16px; line-height: 24px; font-weight: 600; margin: 0; }
.panel-head h2 span { color: var(--muted); font-weight: 400; margin-left: 8px; }
.legend { display: flex; gap: 16px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 8px; border-radius: 2px; margin-right: 6px; vertical-align: 0; }
.sw-gone { background: var(--accent); }
.sw-on { background: var(--stock); }
.sw-pend { background: repeating-linear-gradient(135deg, #c7cdd4 0 2px, #f0f2f4 2px 4px); }

table { width: 100%; border-collapse: collapse; }
th { font-size: var(--fs-small); font-weight: 400; color: var(--muted); text-align: left; padding: 8px 12px; white-space: nowrap; height: 36px; }
td { padding: 0 12px; height: var(--row); border-top: 1px solid var(--rule); white-space: nowrap; }
th:first-child, td:first-child { padding-left: var(--card-pad); }
th:last-child, td:last-child { padding-right: var(--card-pad); }
th.n, td.n { text-align: right; }
td.who { width: 34%; max-width: 0; }
td.who .nm { overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 8px; }
td.who .nm span { overflow: hidden; text-overflow: ellipsis; }
td.who .sub { color: var(--faint); font-size: var(--fs-small); line-height: 16px; overflow: hidden; text-overflow: ellipsis; }
tr.client td { height: 56px; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--raised); }
.chev { width: 16px; height: 16px; flex: none; transition: transform .15s ease; color: var(--muted); }
tr[aria-expanded=true] .chev { transform: rotate(90deg); }
tr.line td.who .nm { padding-left: 24px; font-weight: 500; }
tr.item td { height: 36px; }
tr.item td.who .nm { padding-left: 48px; color: var(--text); }
tr.item td { border-top-color: transparent; }
td .pct { color: var(--muted); }
td .gone { color: var(--accent); font-weight: 500; }
td.delta .up { color: var(--positive); }
td.delta .flat, td .dash { color: var(--faint); }
td.delta small { color: var(--faint); margin-left: 6px; font-size: var(--fs-small); }
td.barcell { width: 180px; }
.where { display: flex; height: 8px; border-radius: 2px; overflow: hidden; background: var(--rule); width: 160px; }
.where i { display: block; height: 100%; }
.where .g { background: var(--accent); }
.where .o { background: var(--stock); }
.where .p { background: repeating-linear-gradient(135deg, #c7cdd4 0 2px, #f0f2f4 2px 4px); }
tr.item .where { height: 6px; opacity: .85; }
.foot { padding: 12px var(--card-pad); color: var(--muted); font-size: 13px; border-top: 1px solid var(--rule); }

.empty { padding: 28px var(--card-pad) 32px; border-top: 1px solid var(--rule); color: var(--muted); }
.empty b { color: var(--text); font-weight: 500; }
.skel { display: inline-block; height: 14px; width: 56px; background: var(--rule); border-radius: 3px; vertical-align: middle; }

@media (max-width: 900px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi:nth-child(3) { border-left: 0; }
  .kpi:nth-child(n+3) { border-top: 1px solid var(--border); }
  .filters .go { margin-left: 0; width: 100%; }
  th.opt-col, td.opt-col { display: none; }
}
@media (max-width: 640px) {
  :root { --pad: 16px; --card-pad: 14px; }
  .pick { min-width: 0; width: 100%; max-width: none; }
  .filters .field { flex: 1 1 100%; }
  th.m-hide, td.m-hide { display: none; }
  td.who { width: auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
.pop input:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }
.pop .pop-foot { flex-wrap: wrap; }
@media (max-width: 640px) { .filters .go .btn.primary { width: 100%; justify-content: center; } }
/* шаг 3: заказ, «хватит на», минимальный остаток, инструменты панели */
.panel-head .tools { display: flex; gap: 8px; margin-left: auto; }
.panel-head .legend { flex-basis: 100%; }
td small.pct { color: var(--faint); font-size: var(--fs-small); margin-left: 6px; display: inline-block; min-width: 42px; text-align: right; }
td small.pend { color: var(--faint); font-size: var(--fs-small); }
td .est { color: var(--faint); margin-right: 2px; }
td .warn, .sub .warn { color: var(--negative); font-weight: 500; }
td .order { font-weight: 600; }
tr.is-warn td.who .nm { color: var(--text); }
.sub .link.days { font-size: var(--fs-small); }
.days-input { width: 56px; height: 22px; font-size: var(--fs-small); border: 1px solid var(--control); border-radius: 4px; padding: 0 4px; }
.foot { line-height: 20px; }
td.barcell { width: 150px; }
.where { width: 130px; }
td .soon { color: #8a5a00; font-weight: 500; }
/* Окно «Подробнее»: МойСклад не прокручивает его сам — прокручиваем свой контейнер */
html:has(body.popup), body.popup { height: 100%; overflow: hidden; }
body.popup .screen { height: 100%; overflow-y: auto; overscroll-behavior: contain; max-width: none; }
body.popup .panel-head .sub { color: var(--muted); font-size: 13px; margin-right: auto; }
th.grp { border-left: 1px solid var(--rule); }
td.grp { border-left: 1px solid var(--rule); }
/* даты «закончится»: красная и жёлтая плашки, чтобы отличались с первого взгляда */
td span.warn, td span.soon, .w-fc span.warn, .w-fc span.soon { padding: 1px 6px; border-radius: var(--radius-chip); font-weight: 500; white-space: nowrap; }
td span.warn, .w-fc span.warn { background: var(--pill-negative-bg); color: var(--pill-negative-ink); }
td span.soon, .w-fc span.soon { background: #fff1c7; color: #6b4300; }
/* объяснение «первая проверка — снимок, повторная — динамика» */
.dyn { margin: var(--gap) 0 0; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: var(--radius-card); color: var(--muted); line-height: 21px; }
.dyn b { color: var(--text); font-weight: 500; }
