:root {
  --bg: #f4f5f7;
  --panel: #fff;
  --text: #1a1d23;
  --muted: #8b909a;
  --line: #e3e5e9;
  --in: #1a7f4b;
  --out: #c0392b;
  --accent: #2f6feb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

.brand { font-weight: 700; text-decoration: none; color: var(--text); font-size: 16px; }
.businesses { display: flex; gap: 8px; flex-wrap: wrap; flex: 1; }
.settings-link { color: var(--muted); text-decoration: none; }
.settings-link:hover { color: var(--accent); }

.chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
  border: 1px solid var(--line);
}
.chip--active { background: var(--accent); color: #fff; border-color: var(--accent); }
.chip--ghost { color: var(--muted); }

main { padding: 20px 24px 60px; max-width: 1400px; margin: 0 auto; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 18px;
}

h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 18px 0 10px; }

.month-nav { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.month-nav h1 { min-width: 190px; }

.summary { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 16px; }
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat__label { color: var(--muted); font-size: 12px; }
.stat__value { font-size: 17px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat__value--in { color: var(--in); }
.stat__value--out { color: var(--out); }

.btn {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 7px;
  padding: 7px 14px;
  cursor: pointer;
  font-size: 13px;
  text-decoration: none;
  display: inline-block;
}
.btn:hover { filter: brightness(1.08); }
.btn--ghost { background: var(--panel); color: var(--text); border-color: var(--line); }
.btn--danger { background: var(--panel); color: var(--out); border-color: var(--line); padding: 2px 8px; }
.inline { display: inline; }

.calendar { width: 100%; border-collapse: collapse; table-layout: fixed; }
.calendar th {
  padding: 6px;
  font-size: 12px;
  color: var(--muted);
  text-align: left;
  font-weight: 500;
}
.day {
  border: 1px solid var(--line);
  vertical-align: top;
  height: 104px;
  padding: 5px 6px;
  overflow: hidden;
}
.day--muted { background: #fafbfc; color: var(--muted); }
.day--today { outline: 2px solid var(--accent); outline-offset: -2px; }
.day__head { display: flex; justify-content: space-between; align-items: baseline; gap: 4px; }
.day__num { font-weight: 600; }
.day__balance { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.day__balance.neg { color: var(--out); }

.pmt {
  margin-top: 4px;
  padding: 2px 5px;
  border-radius: 5px;
  font-size: 11px;
  display: flex;
  flex-direction: column;
  background: #eef7f1;
  border-left: 3px solid var(--in);
}
.pmt--out { background: #fdeeec; border-left-color: var(--out); }
.pmt--planned { opacity: .72; border-left-style: dashed; }
.pmt__amount { font-weight: 600; font-variant-numeric: tabular-nums; }
.pmt__title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  align-items: end;
}
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-grid .wide { grid-column: 1 / -1; }
.form-grid h2 { grid-column: 1 / -1; }
input, select {
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 13px;
  color: var(--text);
  background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.list { width: 100%; border-collapse: collapse; }
.list th {
  text-align: left;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}
.list td { padding: 7px 8px; border-bottom: 1px solid var(--line); }
.list .right { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.list .in { color: var(--in); }
.list .out { color: var(--out); }
.row--planned { color: var(--muted); }

.tag {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 11px;
  cursor: pointer;
  background: var(--bg);
  color: var(--text);
}
.tag--paid { background: #eef7f1; border-color: #bfe0cd; color: var(--in); }
.tag--planned { background: #fff7e8; border-color: #f0dcb4; color: #9a6b12; }

.toast { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.toast--ok { background: #eef7f1; border: 1px solid #bfe0cd; color: var(--in); }
.toast--err { background: #fdeeec; border: 1px solid #f2c4bd; color: var(--out); }

.empty, .hint { color: var(--muted); }

/* Склады FBO */
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.filters input[type="search"] { min-width: 220px; }

.stocks th.num, .stocks td.num, .sub th.num, .sub td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.stocks td.muted, .wh .muted { color: var(--muted); font-weight: 400; }
.stocks td.zero { color: var(--out); font-weight: 600; }
.stocks td.need { color: #9a6b12; font-weight: 600; }

.prod { cursor: pointer; }
.prod:hover { background: #fafbfc; }
.prod--open { background: #f2f6fe; }
.prod__art { font-weight: 600; display: block; }
.prod__name {
  color: var(--muted);
  font-size: 12px;
  display: block;
  max-width: 340px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bar { display: flex; gap: 2px; height: 8px; border-radius: 3px; overflow: hidden; min-width: 120px; }
.bar__seg { display: block; }
.out-note { font-size: 11px; color: var(--out); display: block; margin-top: 3px; }

.st-bg-out { background: #d03b3b; }
.st-bg-deficit { background: #e8a317; }
.st-bg-ok { background: #1a7f4b; }
.st-bg-surplus { background: #2f6feb; }
.st-bg-no_sales { background: #b0b4bc; }
.st-bg-idle { background: #dfe1e5; }

.tag.st-out { background: #fdeeec; border-color: #f2c4bd; color: var(--out); }
.tag.st-deficit { background: #fff7e8; border-color: #f0dcb4; color: #9a6b12; }
.tag.st-ok { background: #eef7f1; border-color: #bfe0cd; color: var(--in); }
.tag.st-surplus { background: #eef3fe; border-color: #c3d5f8; color: var(--accent); }
.tag.st-no_sales, .tag.st-idle { color: var(--muted); }

.clusters > td { padding: 0 0 12px 8px; background: #fafbfc; }
.sub { margin-top: 4px; }
.sub th { font-size: 11px; padding: 5px 8px; }
.sub td { padding: 5px 8px; font-size: 13px; }
.wh { max-width: 280px; }
.wh__item {
  display: inline-block;
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  margin: 1px 3px 1px 0;
}
.wh__item b { color: var(--text); }
/* Планирование поставки */
.horizon { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; }
.horizon input { width: 64px; }
.check { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; }
.formula { font-size: 12px; margin: 10px 0 0; }
.note { font-size: 12px; margin: 12px 0 0; }

.clusters-sum th.num, .clusters-sum td.num { text-align: right; font-variant-numeric: tabular-nums; }
.clusters-sum td.muted { color: var(--muted); }
.clusters-sum td.need { color: #9a6b12; font-weight: 600; }

.matrix-wrap { overflow-x: auto; }
.matrix { min-width: 100%; }
.matrix th, .matrix td { white-space: nowrap; }
.matrix th.num, .matrix td.num { text-align: right; font-variant-numeric: tabular-nums; }
.matrix th.rot { font-size: 11px; max-width: 92px; white-space: normal; line-height: 1.2; }
.matrix .sticky {
  position: sticky;
  left: 0;
  background: var(--panel);
  z-index: 1;
  border-right: 1px solid var(--line);
  min-width: 240px;
}
.matrix tbody tr:hover .sticky { background: #fafbfc; }
.matrix tbody tr:hover { background: #fafbfc; }
.matrix td.need { color: #9a6b12; font-weight: 600; }
.matrix td.surplus { color: var(--accent); }
.matrix td.muted { color: #d5d8dd; }

.tag--super {
  background: #eef7f1;
  border-color: #bfe0cd;
  color: var(--in);
  margin-left: 6px;
  font-size: 10px;
}

.cluster-edit input[type="number"] { width: 72px; }

/* Обзор: карточки кластеров */
.stat__sub { font-size: 11px; color: var(--muted); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.chip-note {
  font-size: 12px;
  border-radius: 999px;
  padding: 4px 12px;
  border: 1px solid var(--line);
  text-decoration: none;
}
.chip-note--red { background: #fdeeec; border-color: #f2c4bd; color: var(--out); }
.chip-note--amber { background: #fff7e8; border-color: #f0dcb4; color: #9a6b12; }
.chip-note--blue { background: #eef3fe; border-color: #c3d5f8; color: var(--accent); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.card--red { border-left: 4px solid #d03b3b; border-radius: 0 10px 10px 0; }
.card--amber { border-left: 4px solid #e8a317; border-radius: 0 10px 10px 0; }
.card__head { display: flex; align-items: center; gap: 8px; }
.card__name { font-weight: 600; font-size: 14px; }
.card__badge {
  margin-left: auto;
  font-size: 11px;
  border-radius: 999px;
  padding: 2px 8px;
  white-space: nowrap;
}
.card__badge--red { background: #fdeeec; color: var(--out); }
.card__badge--amber { background: #fff7e8; color: #9a6b12; }
.card__badge--ok { background: #eef7f1; color: var(--in); }
.card__main { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }
.card__main.muted { color: var(--muted); font-weight: 400; }
.card__sub { font-size: 12px; color: var(--muted); }
.card__cost { font-size: 12px; color: var(--text); font-variant-numeric: tabular-nums; }
.card__btn { margin-top: 8px; text-align: center; }

.steps { display: flex; gap: 6px; align-items: center; }
.step {
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 11px;
  color: var(--text);
  text-decoration: none;
  white-space: nowrap;
}
.step--active { background: var(--accent); border-color: var(--accent); color: #fff; }
.step--off { color: var(--muted); border-style: dashed; }

.pallets th.num, .pallets td.num { text-align: right; font-variant-numeric: tabular-nums; }
.pallets td.muted { color: var(--muted); }
.pallets td.need { color: #9a6b12; font-weight: 600; }

.cluster-detail th.num, .cluster-detail td.num { text-align: right; font-variant-numeric: tabular-nums; }
.cluster-detail td.zero { color: var(--out); font-weight: 600; }
.cluster-detail td.ok-cell { color: var(--in); }
.cluster-detail td.muted { color: var(--muted); }

.prod-cell { display: flex; gap: 10px; align-items: center; min-width: 300px; }
.prod-cell__text { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.prod__name-main { font-size: 13px; line-height: 1.3; }
.prod__art-sub { font-size: 11px; color: var(--muted); }
.thumb {
  width: 32px;
  height: 32px;
  flex: none;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
}
.thumb--empty { display: inline-block; background: var(--bg); }

.check-col { width: 26px; }
.row--off { opacity: 0.38; }
.row--off .prod__name-main { text-decoration: line-through; }
th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
th.sortable:hover { color: var(--accent); }
th.sort-asc::after { content: " ↑"; color: var(--accent); }
th.sort-desc::after { content: " ↓"; color: var(--accent); }
.qty-input { width: 70px; text-align: right; padding: 4px 6px; }
.add-row { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.add-row input[type="search"] { min-width: 340px; }

.chip-note--green { background: #eef7f1; border-color: #bfe0cd; color: var(--in); }
.upload-label { position: relative; overflow: hidden; cursor: pointer; }
.upload-label input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.tag--promo { background: #fbeaf0; border-color: #f4c0d1; color: #993556; font-size: 10px; }
.st-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  vertical-align: -1px;
  margin-left: 4px;
}
.st-dot--red { background: #d03b3b; }
.st-dot--orange { background: #e8781a; }
.st-dot--yellow { background: #e8c11a; }
.st-dot--green { background: #1a7f4b; }

.tag--class { font-size: 10px; white-space: nowrap; }
.tag--ФБО { background: #eef7f1; border-color: #bfe0cd; color: var(--in); }
.tag--ФБО5 { background: #fff7e8; border-color: #f0dcb4; color: #9a6b12; }
.tag--ФБО2 { background: #eef3fe; border-color: #c3d5f8; color: var(--accent); }

.matrix td.note-cell { font-size: 11px; max-width: 150px; white-space: normal; }

.panel--warn { border-color: #f0dcb4; background: #fffdf8; }
.shortages th.num, .shortages td.num { text-align: right; font-variant-numeric: tabular-nums; }
.shortages td.zero { color: var(--out); font-weight: 600; }
.shortages td.need { color: #9a6b12; font-weight: 600; }
.shortages td.muted { color: var(--muted); }
.shortages .note-cell { font-size: 11px; max-width: 320px; }
.tag--zone {
  background: #eef3fe;
  border-color: #c3d5f8;
  color: var(--accent);
  font-size: 10px;
  margin-left: 4px;
}
.zone-mark { color: var(--accent); font-size: 10px; }

/* Звезда «кросс-докинг бесплатно»: снимается сама после конца акции.
   Размер 23px — втрое меньше прежних 70px, карточку по высоте уже не растит. */
.free-mark {
  color: #f2b705;
  font-size: 23px;
  line-height: 0.8;
  margin-left: 4px;
  cursor: help;
}

/* В сноске и в таблицах звезда обычного размера: там она только пояснение. */
.free-mark--legend { font-size: 14px; line-height: 1; }
.clusters-sum .free-mark { font-size: 14px; line-height: 1; }

.tag--vet {
  background: #fff7e8;
  border-color: #f0dcb4;
  color: #9a6b12;
  font-size: 10px;
  margin-left: 4px;
}

/* Колонка «Отправим»: число правится руками, поле не должно прыгать по ширине. */
.qty-col { width: 92px; }
.cluster-detail td.qty-col { padding-top: 4px; padding-bottom: 4px; }
.qty-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
/* Красным — когда отправляем меньше, чем нужно по расчёту. */
.qty-input--short { color: var(--out); font-weight: 600; }
.row--off .qty-input { opacity: 0.6; }

/* Пометки: строго одна строка фиксированной высоты, иначе таблица «съезжает». */
.marks-col { width: 210px; }
.marks {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-wrap: nowrap;
  overflow: hidden;
  height: 20px;
}
.mark {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 10px;
  line-height: 1;
  white-space: nowrap;
  flex: none;
  max-width: 88px;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: default;
}
/* Скидка в акции: до 20% рабочая, до 35% тревожно, дальше товар уходит в ноль. */
.mark--ok { background: #eef7f1; border-color: #bfe0cd; color: var(--in); }
.mark--warn { background: #fff7e8; border-color: #f0dcb4; color: #9a6b12; }
.mark--bad { background: #fdeeec; border-color: #f2c4bd; color: var(--out); font-weight: 600; }
.mark--vet { background: #fff7e8; border-color: #f0dcb4; color: #9a6b12; }
.mark--zone { background: #eef3fe; border-color: #c3d5f8; color: var(--accent); }
.mark--note { background: var(--bg); color: var(--muted); }
.marks .st-dot { margin-left: 0; flex: none; }

.biz-list { list-style: none; padding: 0; }
.biz-list li { padding: 8px 0; border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: baseline; }
.biz-list a { color: var(--accent); text-decoration: none; font-weight: 600; }

/* Страница входа: та же вёрстка, но без шапки и на весь экран. */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login { width: 340px; max-width: calc(100vw - 32px); }
.login__brand { font-weight: 700; font-size: 16px; text-align: center; margin-bottom: 14px; }
.login .panel { margin-bottom: 0; }
.login form { display: flex; flex-direction: column; gap: 10px; }
.login__label { font-size: 12px; color: var(--muted); }
.login__remember {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--muted);
}
.login__remember input { width: auto; }
.login p { margin: 0 0 10px; }
.login .muted { color: var(--muted); font-size: 12px; }
.login code { background: var(--bg); border-radius: 4px; padding: 1px 4px; }

.logout { margin: 0; }
.logout button { background: none; border: none; padding: 0; cursor: pointer; font-size: 14px; }

/* Учётки сотрудников. */
.panel--accent { border-color: var(--accent); }
.pass {
  font: 20px/1.3 "Consolas", "Courier New", monospace;
  letter-spacing: 1px;
  user-select: all;
  margin: 6px 0 8px;
}
.row--off { color: var(--muted); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row-actions .btn { padding: 3px 9px; font-size: 12px; }
.form-grid .check { flex-direction: row; align-items: center; gap: 7px; color: var(--text); }
.form-grid .check input { width: auto; }
.login__back { text-align: center; margin: 12px 0 0; }
.login__back a { color: var(--muted); font-size: 13px; }
.who { font-weight: 600; color: var(--text); }

/* Легенда таблицы состава: свёрнутый список «что означает каждая колонка». */
.legend { margin: 0 0 12px; border: 1px solid var(--line); border-radius: 8px; }
.legend > summary {
  cursor: pointer; padding: 8px 12px; color: var(--muted);
  font-size: 13px; user-select: none;
}
.legend > summary:hover { color: var(--text); }
.legend[open] > summary { border-bottom: 1px solid var(--line); }
.legend__list { margin: 0; padding: 10px 14px 14px; font-size: 13px; line-height: 1.5; }
.legend__list dt { font-weight: 600; color: var(--text); margin-top: 10px; }
.legend__list dt:first-child { margin-top: 0; }
.legend__list dd { margin: 2px 0 0; color: var(--muted); }
.legend__list code {
  background: var(--row-alt, #f5f5f5); padding: 1px 5px; border-radius: 4px;
  font-size: 12px; color: var(--text);
}

/* Кратность в составе: показываем, но не даём править — правится на своём экране. */
.pack-col { color: var(--text); }
.pack-col--auto { color: var(--muted); font-weight: 400; }

/* Колонки таблиц: перетаскивание заголовков и меню скрытия. */
table.list thead th[draggable="true"] { cursor: grab; }
table.list thead th.col-dragging { opacity: .45; }
table.list thead th.col-drop { box-shadow: inset 2px 0 0 var(--accent, #2f7d32); }
.col-menu { position: relative; display: flex; justify-content: flex-end; margin: 0 0 6px; }
.col-menu__btn {
  background: none; border: 1px solid var(--line); border-radius: 6px;
  color: var(--muted); font-size: 12px; padding: 3px 9px; cursor: pointer;
}
.col-menu__btn:hover { color: var(--text); }
.col-menu__list {
  display: none; position: absolute; right: 0; top: 100%; z-index: 20;
  min-width: 220px; max-height: 340px; overflow: auto; padding: 8px 10px;
  background: var(--panel, #fff); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 6px 20px rgba(0, 0, 0, .12);
}
.col-menu--open .col-menu__list { display: block; }
.col-menu__list label {
  display: flex; align-items: center; gap: 7px; padding: 3px 0;
  font-size: 13px; color: var(--text); cursor: pointer;
}
.col-menu__reset {
  margin-top: 6px; background: none; border: 0; padding: 4px 0;
  color: var(--muted); font-size: 12px; cursor: pointer; text-decoration: underline;
}

/* Журнал поставок: календарная сетка и статусы. */
.supply-cal { table-layout: fixed; }
.supply-cal__day { vertical-align: top; height: 74px; padding: 4px 6px; }
.supply-cal__day--today { background: var(--row-accent, #f2f8f2); }
.supply-cal__num { font-size: 12px; color: var(--muted); }
.supply-chip {
  margin-top: 3px; padding: 2px 6px; border-radius: 5px; font-size: 11px;
  line-height: 1.3; background: var(--row-alt, #f5f5f5); color: var(--text);
  border-left: 3px solid var(--muted); overflow: hidden; white-space: nowrap;
  text-overflow: ellipsis;
}
.supply-chip--ship { border-left-color: #c98a00; }
.supply-chip--due { border-left-color: #2f7d32; }
.supply-chip--cancelled { opacity: .45; text-decoration: line-through; }
.supply-st--draft { background: #f2f2f2; }
.supply-st--created { background: #fff7e8; border-color: #f0dcb4; color: #9a6b12; }
.supply-st--shipped { background: #e8f1ff; border-color: #bdd4f2; color: #1c5b9e; }
.supply-st--received { background: #ecf7ec; border-color: #c4e3c4; color: #2f7d32; }
.supply-st--cancelled { background: #f7ecec; border-color: #e3c4c4; color: #9e1c1c; }
.supply-lines td { border-top: 0; padding-top: 0; font-size: 12px; }

/* Око на входе: шутка заказчика, полумасонское золото. */
.login__eye { display: block; margin: 0 auto 12px; width: 92px; height: auto; color: #b8912f; }
