:root {
  --bg: #f6f7f9; --panel: #ffffff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb; --line2: #d3d8df;
  --accent: #2f6fde; --accent-soft: #e8f0fd; --input: #fff8db; --input-manual: #fff1b3; --past: #f0f1f4;
  --current: #e2f3e5; --err: #c62828; --err-soft: #fdecec; --ok: #2e7d32; --flash: #c8f0cf; --head: #eef1f5;
  --m-cur: #f1f6ff; --m-cur-head: #d9e7ff; --m-next: #f7f1fd; --m-next-head: #eadcfb;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171c; --panel: #1c2027; --text: #e6e8ec; --muted: #9aa2ad; --line: #2c323b; --line2: #39404b;
    --accent: #6c9cf0; --accent-soft: #1f2b40; --input: #2e2a1a; --input-manual: #403718; --past: #191c21;
    --current: #1d3122; --err: #ff7b7b; --err-soft: #3a1f22; --ok: #7bd389; --flash: #24452b; --head: #232831;
    --m-cur: #18233a; --m-cur-head: #1f3156; --m-next: #241b33; --m-next-head: #34264b;
  }
}
:root[data-theme="dark"] {
  --bg: #14171c; --panel: #1c2027; --text: #e6e8ec; --muted: #9aa2ad; --line: #2c323b; --line2: #39404b;
  --accent: #6c9cf0; --accent-soft: #1f2b40; --input: #2e2a1a; --input-manual: #403718; --past: #191c21;
  --current: #1d3122; --err: #ff7b7b; --err-soft: #3a1f22; --ok: #7bd389; --flash: #24452b; --head: #232831;
    --m-cur: #18233a; --m-cur-head: #1f3156; --m-next: #241b33; --m-next-head: #34264b;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 8px 16px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap; }
/* шапка (вкладки + фильтры) закреплена; при прокрутке вниз уезжает, возвращается при прокрутке вверх
   или если подвести мышь к верхнему краю окна */
.sticky-head { position: sticky; top: 0; z-index: 30; transition: transform .22s ease; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.sticky-head.hide { transform: translateY(-100%); box-shadow: none; }
.brand { font-weight: 650; font-size: 15px; }
.tabs { display: flex; gap: 4px; }
.tabs button { border: 0; background: none; padding: 6px 12px; border-radius: 6px; cursor: pointer; color: var(--muted); }
.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topinfo { color: var(--muted); margin-left: auto; }
.user a { color: var(--accent); margin-left: 8px; }

.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: end; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line); }
.filters label, .toolbar label { display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: 12px; }
.filters label.grow { flex: 1 1 200px; }
label.check { flex-direction: row !important; align-items: center; gap: 6px !important; color: var(--text) !important; font-size: 13px !important; }
select, input:not([type]), input[type="text"], input[type="password"] {
  border: 1px solid var(--line2); background: var(--panel); border-radius: 6px; padding: 5px 8px; min-width: 120px; }
main { padding: 12px 16px 40px; }
.toolbar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin: 6px 0 8px; }
.toolbar label:not(.check) { flex-direction: row; align-items: center; gap: 6px; }
.btn { border: 1px solid var(--line2); background: var(--panel); border-radius: 6px; padding: 5px 12px; cursor: pointer; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 2px 8px; font-size: 12px; }
/* недели текущего месяца и следующего — разными цветами (шапка ярче, ячейки — лёгкий оттенок) */
th.m-cur { background: var(--m-cur-head); }
th.m-next { background: var(--m-next-head); }
td.m-cur:not(.past) { background: var(--m-cur); }
td.m-next:not(.past) { background: var(--m-next); }
tr.input td.m-cur:not(.past), tr.input td.m-next:not(.past) { background: var(--input); }
tr.input td.manual.m-cur, tr.input td.manual.m-next { background: var(--input-manual); }
/* блок SKU на «Своде»: SKU и артикул закреплены при прокрутке вбок */
table.list .fx1, table.list .fx2 { position: sticky; z-index: 1; background: var(--panel); }
table.list .fx1 { left: 0; min-width: 105px; max-width: 105px; }
table.list .fx2 { left: 105px; min-width: 210px; max-width: 210px; overflow: hidden; text-overflow: ellipsis;
  box-shadow: inset -1px 0 0 var(--line2); }
table.list thead .fx1, table.list thead .fx2 { z-index: 3; background: var(--head); }
table.list tfoot td { z-index: 2; }
table.list tfoot .fx1, table.list tfoot .fx2 { z-index: 4; background: var(--head); }
table.list tbody tr:hover td.fx1, table.list tbody tr:hover td.fx2 { background: var(--accent-soft); }
.btn.blue { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.blue.active { box-shadow: 0 0 0 3px var(--accent-soft), inset 0 0 0 2px #fff; font-weight: 700; }
.sku-head .desc { display: flex; flex-direction: column; gap: 2px; }
.sku-head .facts { color: var(--text); font-size: 12px; }
.sku-head .facts .arr-text b, .arr-tag { color: #b45309; }
.sku-head .facts .unpl { color: #fff; background: var(--accent); border-radius: 3px; padding: 0 5px; font-size: 11px; }
/* неделя приезда новинки — оранжевые границы колонки; пиковая неделя — 🔥 */
th.arrival, td.arrival { box-shadow: inset 2px 0 0 #f59e0b, inset -2px 0 0 #f59e0b !important; }
.arr-tag { font-size: 10px; font-weight: 700; }
.fire { margin-right: 3px; }
.st-table input.st-date { min-width: 140px; }
.dlg { border: 1px solid var(--line2); border-radius: 12px; padding: 0; background: var(--panel); color: var(--text);
  width: min(760px, calc(100vw - 32px)); }
.dlg::backdrop { background: rgba(0, 0, 0, .35); }
.dlg form { padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; }
.dlg h3 { margin: 0; }
.dlg .row { display: flex; gap: 10px; align-items: end; }
.dlg .row.end { justify-content: flex-end; }
.dlg label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); font-size: 12px; }
.dlg label.grow { flex: 1; }
.dlg label input, .dlg label select { width: 100%; }
.dlg .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.add-list tr { cursor: pointer; }
.add-list tr:hover td { background: var(--accent-soft); }
@media (max-width: 600px) { .dlg .grid2 { grid-template-columns: 1fr; } }
.pager { display: inline-flex; gap: 8px; align-items: center; margin-left: auto; }
.sku-card { margin-bottom: 22px; }
#sku-cards.list .grid-wrap { max-height: none; }   /* в списке — без внутренней прокрутки по вертикали */
tr.more-row td { background: var(--head); border-top: 2px solid var(--line2); }
tr.more-row td.lab { color: var(--accent); font-weight: 600; cursor: pointer; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--accent); }
.consts-wrap { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start; }
.const-block { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px 14px; min-width: 300px; }
.const-block h3 { margin: 2px 0 8px; font-size: 14px; }
table.consts td.lab { min-width: 200px; }
table.consts td.cinput { min-width: 100px; background: var(--input-manual); font-weight: 600; cursor: cell; }
table.consts tr.sum td { color: var(--muted); }
.consts-wrap > p { flex-basis: 100%; }
/* заданный фильтр подсвечивается */
label.set, details.multi.set > summary { color: var(--accent) !important; font-weight: 600; }
label.set select, label.set input:not([type=checkbox]) { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 1px var(--accent); }
label.check.set { background: var(--accent-soft); border-radius: 6px; padding: 2px 6px; }
details.multi { position: relative; }
details.multi > summary { list-style: none; cursor: pointer; border: 1px solid var(--line2); border-radius: 6px; padding: 5px 10px;
  background: var(--panel); max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
details.multi > summary::after { content: " ▾"; color: var(--muted); }
details.multi.set > summary { border-color: var(--accent); background: var(--accent-soft); }
.multi-list { position: absolute; z-index: 40; top: calc(100% + 4px); left: 0; min-width: 240px; background: var(--panel);
  border: 1px solid var(--line2); border-radius: 8px; padding: 8px 10px; box-shadow: 0 6px 18px rgba(0,0,0,.12);
  display: flex; flex-direction: column; gap: 4px; }
#view-statuses .scroll { width: 100%; }
.st-table { width: 100%; }
.btn.danger { color: var(--err); border-color: var(--err); }
.d-up { color: var(--ok); }
.d-down { color: var(--err); }
td.cmp { line-height: 1.3; font-size: 12px; }
td.cmp b { font-size: 13px; }
.btn.danger:hover { background: var(--err-soft); }
.st-table td, .st-table th { text-align: left; vertical-align: middle; }
.st-table td.ph { width: 56px; padding: 2px 6px; }
.st-table td.ph img { width: 42px; height: 56px; object-fit: cover; border-radius: 4px; display: block; }
.st-table select { min-width: 180px; }
.st-errors { color: var(--err); background: var(--err-soft); padding: 6px 10px; border-radius: 6px; margin-bottom: 8px; }
.btn.past-toggle.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
tr.sec-head td { background: var(--head); font-weight: 700; letter-spacing: .02em; border-top: 2px solid var(--line2); }
tr.sec-head td.lab { background: var(--head); }
td.minput { cursor: cell; background: var(--input-manual) !important; font-weight: 600; }
table.rnp td.lab { min-width: 280px; }
table.managers td.lab { min-width: 140px; }
.seg { display: inline-flex; border: 1px solid var(--line2); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 5px 12px; cursor: pointer; }
.seg button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.scroll { overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; max-width: 100%; }
.scroll.tall { max-height: 62vh; }
.grid-wrap { max-height: calc(100vh - 250px); }
table { border-collapse: separate; border-spacing: 0; white-space: nowrap; }
th, td { padding: 4px 8px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); text-align: right; }
thead th { position: sticky; top: 0; background: var(--head); z-index: 2; font-weight: 600; }
thead tr:nth-child(2) th { top: 26px; }
th.lab, td.lab { position: sticky; left: 0; background: var(--panel); text-align: left; z-index: 1; min-width: 230px; max-width: 330px;
  overflow: hidden; text-overflow: ellipsis; }
thead th.lab { z-index: 3; background: var(--head); }
td.num { font-variant-numeric: tabular-nums; }
td.past { background: var(--past); color: var(--muted); }
/* текущая (календарная) неделя — вся колонка; начало плана — зелёная линия слева */
th.cur, td.cur { background: var(--current) !important; box-shadow: inset 2px 0 0 var(--ok), inset -2px 0 0 var(--ok); }
thead th.cur { box-shadow: inset 2px 0 0 var(--ok), inset -2px 0 0 var(--ok), inset 0 3px 0 var(--ok); }
tr.input td.cur { background: var(--input-manual) !important; }
th.start, td.start { border-left: 2px solid var(--ok); }
.now { display: inline-block; font-size: 10px; font-weight: 700; color: #fff; background: var(--ok); border-radius: 3px;
  padding: 0 4px; vertical-align: 1px; }
tr.input td:not(.lab) { background: var(--input); cursor: cell; }
tr.input td.manual { background: var(--input-manual); font-weight: 600; }
tr.input td.past { background: var(--past); cursor: default; }
tr.input td.lab { font-weight: 600; }
tr.input td.lab::before { content: "✎ "; color: var(--accent); }
tr.size td.lab { color: var(--muted); padding-left: 30px; }
.toggle { width: 18px; height: 18px; line-height: 14px; padding: 0; margin-right: 6px; border: 1px solid var(--line2);
  border-radius: 4px; background: var(--panel); color: var(--accent); font-weight: 700; cursor: pointer; vertical-align: 1px; }
.toggle:hover { border-color: var(--accent); }
tr.sec td { border-top: 2px solid var(--line2); }
td.err { color: var(--err); background: var(--err-soft); }
td.low { color: var(--err); background: var(--err-soft) !important; font-weight: 650; }
td.flash { animation: flash 1.4s ease-out; }
@keyframes flash { from { background: var(--flash); } }
td.editing { padding: 0; }
td.editing input { width: 100%; min-width: 80px; border: 2px solid var(--accent); border-radius: 0; padding: 3px 6px; text-align: right; }
tr.text td:not(.lab) { text-align: left; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }

table.list tbody tr { cursor: pointer; }
table.list tbody tr:hover td { background: var(--accent-soft); }
table.list td:nth-child(-n+6), table.list th:nth-child(-n+6) { text-align: left; }
table.list td.lab, table.totals td.lab { min-width: 120px; }
tfoot td { font-weight: 650; background: var(--head); position: sticky; bottom: 0; }

.sku-head { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.sku-head .title { font-size: 16px; font-weight: 650; }
.sku-head .photo { width: 72px; height: 96px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }
.sku-head .photo.none { display: inline-flex; align-items: center; justify-content: center; text-align: center;
  font-size: 11px; color: var(--muted); background: var(--past); padding: 4px; }
.sku-head .attr { color: var(--muted); }
.sku-head input.peak { width: 110px; min-width: 0; text-align: right; background: var(--input-manual); font-weight: 600; }
.sku-head .nav { margin-left: auto; display: flex; gap: 6px; }

.log-table td, .log-table th { text-align: left; }
.log-table td.reverted { text-decoration: line-through; color: var(--muted); }

.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 16px; border-radius: 8px; z-index: 50; max-width: 90vw; }
.toast.error { background: var(--err); color: #fff; }

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-box { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 28px; width: 100%;
  max-width: 340px; display: flex; flex-direction: column; gap: 12px; }
.login-box h1 { font-size: 18px; margin: 0; }
.login-box p { margin: 0 0 6px; }
.login-box label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
.login-box input { width: 100%; }
.login-err { color: var(--err); background: var(--err-soft); padding: 6px 10px; border-radius: 6px; }

@media (max-width: 700px) {
  .topbar { gap: 8px; } .topinfo { margin-left: 0; width: 100%; order: 5; }
  th.lab, td.lab { min-width: 140px; max-width: 170px; }
}
