:root {
  --bg: #f5f6fa; --panel: #ffffff; --panel2: #f9fafb; --line: #e6e8ef; --line2: #eef0f5;
  --text: #171a23; --muted: #6b7180; --faint: #9aa0ad;
  --accent: #4f46e5; --accent-soft: #eef0ff; --accent-text: #4338ca;
  --good: #0f9d58; --good-soft: #e6f6ee; --warn: #c27c0e; --warn-soft: #fdf4e3; --bad: #d93a3a; --bad-soft: #fdecec;
  --plan: #c3c8d4; --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.06);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1117; --panel: #171a22; --panel2: #1c2029; --line: #2a2f3a; --line2: #222631;
    --text: #e8eaf0; --muted: #9aa1b0; --faint: #6c7383;
    --accent: #818cf8; --accent-soft: #23264a; --accent-text: #a5b4fc;
    --good: #34c77b; --good-soft: #163325; --warn: #e3a23b; --warn-soft: #3a2d14; --bad: #f06a6a; --bad-soft: #3c1d1d;
    --plan: #4a5163; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1117; --panel: #171a22; --panel2: #1c2029; --line: #2a2f3a; --line2: #222631;
  --text: #e8eaf0; --muted: #9aa1b0; --faint: #6c7383;
  --accent: #818cf8; --accent-soft: #23264a; --accent-text: #a5b4fc;
  --good: #34c77b; --good-soft: #163325; --warn: #e3a23b; --warn-soft: #3a2d14; --bad: #f06a6a; --bad-soft: #3c1d1d;
  --plan: #4a5163; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
a { color: var(--accent-text); text-decoration: none; }
button { font: inherit; color: inherit; }
input, select, textarea { font: inherit; color: var(--text); }
.num { font-variant-numeric: tabular-nums; }

/* вход */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); }
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.login-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); }
.err { color: var(--bad); margin: 0; min-height: 1em; font-size: 13px; }

.brand { display: flex; gap: 10px; align-items: center; }
.brand b { display: block; font-size: 15px; }
.brand small { color: var(--muted); font-size: 12px; }
.brand.big { margin-bottom: 8px; }
.logo { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }

/* каркас */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 20px; padding: 18px 14px; border-right: 1px solid var(--line); background: var(--panel); }
.side nav { display: grid; gap: 2px; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; color: var(--muted); font-weight: 500; }
.side nav a svg { width: 18px; height: 18px; fill: currentColor; opacity: .8; }
.side nav a:hover { background: var(--panel2); color: var(--text); }
.side nav a.on { background: var(--accent-soft); color: var(--accent-text); }
.side-foot { margin-top: auto; display: grid; gap: 8px; font-size: 12px; color: var(--muted); }
.sync { line-height: 1.4; }
.sync .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--good); margin-right: 6px; }
.sync .dot.bad { background: var(--warn); }
.me { display: flex; justify-content: space-between; gap: 8px; }
.link { background: none; border: 0; padding: 0; color: var(--accent-text); cursor: pointer; font-size: 12px; text-align: left; }
.view { padding: 24px 28px 60px; min-width: 0; }

/* шапка страницы */
.head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 18px; }
.head h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
.head .sub { color: var(--muted); font-size: 13px; }
.head .grow { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.seg button { border: 0; background: none; padding: 7px 12px; cursor: pointer; color: var(--muted); font-weight: 500; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent-soft); color: var(--accent-text); }
.field { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }
.field input, .field select, .inp { padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); }
.btn { border: 1px solid var(--line); background: var(--panel); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; }
.btn:hover { border-color: var(--faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.search { min-width: 200px; }

/* KPI */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .l { color: var(--muted); font-size: 12px; font-weight: 500; }
.kpi .v { font-size: 22px; font-weight: 650; margin-top: 4px; letter-spacing: -.01em; }
.kpi .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.bar { height: 6px; border-radius: 3px; background: var(--line2); overflow: hidden; margin-top: 8px; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar i.good { background: var(--good); } .bar i.warn { background: var(--warn); } .bar i.bad { background: var(--bad); }

/* карточки и таблицы */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.card-h { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.card-h h2 { font-size: 15px; margin: 0; }
.card-h .sub { color: var(--muted); font-size: 12px; }
.scroll { overflow: auto; }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line2); text-align: right; white-space: nowrap; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--panel2); position: sticky; top: 0; z-index: 1; }
th:first-child, td:first-child { text-align: left; }
tbody tr:hover td { background: var(--panel2); }
tr.grp td { background: var(--bg); color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding-top: 12px; }
tr.click { cursor: pointer; }
.art b { display: block; font-weight: 600; }
.art small { color: var(--muted); font-size: 12px; display: block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; }
.pill.good { background: var(--good-soft); color: var(--good); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.mute { background: var(--line2); color: var(--muted); }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.pp { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.pp .bar { width: 64px; margin: 0; }
.spark { display: block; }

/* переключатель акции */
.tgl { position: relative; width: 34px; height: 20px; border-radius: 10px; border: 0; background: var(--line); cursor: pointer; vertical-align: middle; transition: background .15s; }
.tgl::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: transform .15s; }
.tgl.on { background: var(--good); }
.tgl.on::after { transform: translateX(14px); }

/* сетки ввода */
.grid th, .grid td { padding: 0; min-width: 44px; text-align: center; }
.grid th { padding: 6px 4px; font-size: 11px; line-height: 1.2; }
.grid th.we { color: var(--bad); }
.grid th.today, .grid td.today { box-shadow: inset 0 0 0 1px var(--accent); }
.grid td:first-child, .grid th:first-child { position: sticky; left: 0; z-index: 2; background: var(--panel); text-align: left; padding: 6px 10px; min-width: 180px; border-right: 1px solid var(--line); }
.grid th:first-child { z-index: 3; background: var(--panel2); }
.grid td.tot, .grid th.tot { background: var(--panel2); font-weight: 600; padding: 6px 8px; }
.cell { width: 100%; min-width: 44px; height: 34px; border: 0; background: transparent; text-align: center; padding: 0 2px; font-variant-numeric: tabular-nums; }
.cell:focus { outline: 2px solid var(--accent); outline-offset: -2px; background: var(--accent-soft); }
.cell.saved { animation: flash .8s; }
@keyframes flash { from { background: var(--good-soft); } to { background: transparent; } }
.fact { display: block; font-size: 10px; color: var(--faint); line-height: 1; margin-top: -9px; padding-bottom: 3px; pointer-events: none; }
.fact.ok { color: var(--good); } .fact.low { color: var(--bad); }
.chk { width: 100%; height: 34px; border: 0; background: transparent; cursor: pointer; display: grid; place-items: center; }
.chk span { width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--faint); display: grid; place-items: center; }
.chk.on span { background: var(--good); border-color: var(--good); }
.chk.on span::after { content: ""; width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg) translate(-1px, -1px); }

/* карточка артикула */
.metrics td:first-child, .metrics th:first-child { position: sticky; left: 0; background: var(--panel); z-index: 2; border-right: 1px solid var(--line); min-width: 200px; }
.metrics th:first-child { background: var(--panel2); z-index: 3; }
.metrics tr.sec td { background: var(--bg); color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.metrics tr.sec td:first-child { background: var(--bg); }
.metrics tr.edit td:first-child { color: var(--accent-text); font-weight: 600; }
.metrics td.tot, .metrics th.tot { background: var(--panel2); font-weight: 600; }
.metrics td { min-width: 70px; }
.metrics td.cm { min-width: 140px; max-width: 220px; white-space: normal; text-align: left; font-size: 12px; padding: 0; }
.metrics textarea { width: 100%; min-height: 34px; border: 0; background: transparent; resize: vertical; padding: 6px 8px; font-size: 12px; }
.metrics textarea:focus { outline: 2px solid var(--accent); outline-offset: -2px; }
.chart { padding: 12px 16px 6px; }
.legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); padding: 0 16px 12px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.back { color: var(--muted); font-size: 13px; }
.note { color: var(--muted); font-size: 12px; padding: 10px 16px; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; font-weight: 500; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.bad { background: var(--bad); color: #fff; }
.empty { padding: 40px; text-align: center; color: var(--muted); }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; top: 0; z-index: 20; height: auto; flex-direction: row; align-items: center; padding: 8px 12px; gap: 10px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .side .brand div, .side-foot .sync, .side-foot #themeBtn { display: none; }
  .side nav { display: flex; gap: 2px; }
  .side nav a { padding: 7px 9px; font-size: 13px; }
  .side nav a svg { display: none; }
  .side-foot { margin: 0 0 0 auto; }
  .view { padding: 16px 16px 60px; }
  .head h1 { font-size: 19px; }
  .kpi .v { font-size: 19px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 12px; }
}

/* тепловая карта */
.heat th, .heat td { text-align: center; padding: 4px 8px; min-width: 40px; font-variant-numeric: tabular-nums; font-size: 13px; border-bottom: 1px solid var(--panel); }
.heat td:first-child { font-weight: 600; color: var(--muted); }
.heat td.tot { font-weight: 600; }
@media (max-width: 1100px) { .heat-wrap { grid-template-columns: 1fr !important; } }
.heat-wrap .card + .card { margin-top: 0; }
@media (min-width: 861px) { .shell { background: linear-gradient(to right, var(--panel) 220px, var(--bg) 220px); } }

/* общий комментарий на период */
.metrics td.pc { background: var(--good-soft); border-left: 3px solid var(--good); text-align: left; white-space: normal; font-size: 12px; line-height: 1.35; padding: 6px 8px; cursor: pointer; vertical-align: top; max-width: 0; }
.metrics td.pc b { color: var(--good); font-weight: 600; margin-right: 4px; }
.metrics td.pc:hover { filter: brightness(.97); }
.metrics td.pc-empty { cursor: crosshair; height: 34px; }
.metrics td.pc-empty:hover { background: var(--panel2); }
.metrics td.pc-empty.sel { background: var(--accent-soft); box-shadow: inset 0 2px 0 var(--accent), inset 0 -2px 0 var(--accent); }
.metrics tr.pc-row td:first-child { white-space: nowrap; }
.pc-add { margin-left: 8px; font-weight: 500; }
.dlg { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--panel); color: var(--text); width: min(480px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.dlg::backdrop { background: rgba(15,17,23,.45); }
.dlg form { display: grid; gap: 12px; padding: 20px; }
.dlg h3 { margin: 0; font-size: 16px; }
.dlg textarea { width: 100%; resize: vertical; }
.metrics td.pc .pc-in { position: sticky; left: calc(var(--fc, 220px) + 8px); display: inline-block; max-width: 100%; }

/* большие мониторы: всё крупнее, чтобы не было мелко на 2K/4K и широких экранах */
@media (min-width: 1900px) { body { zoom: 1.15; } .side { height: calc(100vh / 1.15); } }
@media (min-width: 2500px) { body { zoom: 1.35; } .side { height: calc(100vh / 1.35); } }
@media (min-width: 3200px) { body { zoom: 1.6; } .side { height: calc(100vh / 1.6); } }

/* план-факт в сетке плана */
.grid tr.plan-row td { border-bottom: 0; }
.grid tr.fact-row td { background: var(--panel2); border-bottom: 1px solid var(--line); height: 30px; }
.grid tr.fact-row td.tot { padding: 4px 8px; }
.grid .rl { display: block; font-size: 10px; font-weight: 500; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; line-height: 1; margin-bottom: 2px; }
.pf { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 4px 5px; }
.pf b { font-size: 12px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.pf.ok b { color: var(--good); } .pf.low b { color: var(--bad); } .pf.none b { color: var(--muted); font-weight: 500; }
.pf-bar { width: 28px; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.pf-bar i { display: block; height: 100%; border-radius: 2px; }
.pf.ok .pf-bar i { background: var(--good); } .pf.low .pf-bar i { background: var(--bad); }
.pf-pct { font-size: 11px; font-weight: 600; }
.pf-pct.ok { color: var(--good); } .pf-pct.low { color: var(--bad); }
.grid tr.fact-row td.tot:first-child { position: static; min-width: 0; text-align: center; border-right: 0; z-index: auto; background: var(--panel2); padding: 4px 8px; }

/* компактнее: подпись и число в одну строку, шрифт мельче */
.grid tr.plan-row td.tot, .grid tr.fact-row td.tot, .grid tr.fact-row td.tot:first-child { font-size: 12px; padding: 2px 8px; white-space: nowrap; }
.grid .rl { display: inline; font-size: 9px; margin: 0 4px 0 0; }
.pf-pct { display: inline; font-size: 10px; margin-left: 4px; }
.grid td.art b { font-size: 13px; }
.grid td.art small { font-size: 11px; }
.grid .cell { height: 30px; font-size: 13px; }
.grid tr.fact-row td { height: 26px; }
.pf { padding: 3px 4px 4px; gap: 2px; }
.pf b { font-size: 11px; }

/* цвет общего комментария */
.metrics td.pc { background: color-mix(in srgb, var(--pc, #22a861) 16%, var(--panel)); border-left-color: var(--pc, #22a861); }
.metrics td.pc b { color: color-mix(in srgb, var(--pc, #22a861) 80%, var(--text)); }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatches label { cursor: pointer; }
.swatches input { position: absolute; opacity: 0; pointer-events: none; }
.swatches span { display: block; width: 28px; height: 28px; border-radius: 50%; background: var(--pc); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--pc) 60%, #000 0%); transition: transform .1s; }
.swatches input:checked + span { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px var(--pc); transform: scale(1.05); }
.swatches input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 3px; }

/* фото товара */
.art-wrap { display: flex; align-items: center; gap: 10px; }
.thumb { width: 34px; height: 44px; border-radius: 6px; object-fit: cover; background: var(--line2); flex: none; display: block; }
.thumb.big { width: 56px; height: 74px; border-radius: 10px; }

/* фильтр кабинета: подсвечен, когда выбран */
.cab-sel { font-weight: 500; }
.cab-sel.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-text); }

/* выбор товара с фото */
.picker { position: relative; display: inline-block; }
.pick-list { position: absolute; top: calc(100% + 4px); left: 0; z-index: 30; width: 380px; max-height: 420px; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.18); padding: 4px; }
.pick-it { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border-radius: 8px; cursor: pointer; color: var(--text); }
.pick-it:hover, .pick-it.on { background: var(--accent-soft); }
.pick-it b { display: block; font-size: 13px; font-weight: 600; }
.pick-it small { display: block; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 290px; }
.pick-it.all .thumb { background: var(--accent-soft); }

/* сигналы */
td.sig { white-space: normal; text-align: left; min-width: 120px; }
td.sig .pill { margin: 1px 0; }
details.card > summary { list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary h2::before { content: "▸ "; color: var(--muted); }
details.card[open] > summary h2::before { content: "▾ "; }

/* подсказка на графике */
.tip { position: absolute; z-index: 5; min-width: 150px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12px; line-height: 1.5; box-shadow: 0 8px 24px rgba(0,0,0,.15); pointer-events: none; }
.chart .hit { cursor: pointer; }

/* верхняя полоса прокрутки широких таблиц */
.top-scroll { overflow-x: auto; overflow-y: hidden; height: 14px; border-bottom: 1px solid var(--line2); }
.top-scroll > div { height: 1px; }

/* свои склады FBS */
.fbs-step { font-size: 12px; padding: 3px 8px; border-radius: 6px; margin: 2px 0; white-space: normal; }
.fbs-step.move { background: var(--accent-soft); color: var(--accent-text); }
.fbs-step.ship { background: var(--warn-soft); color: var(--warn); }
.fbs-lists { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; padding: 12px 16px; }
.fbs-list { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.fbs-list h3 { font-size: 13px; margin: 0 0 6px; }
.fbs-li { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; padding: 3px 0; border-top: 1px solid var(--line2); }

/* подсказки и инструкция */
.has-hint { cursor: help; }
.hint { display: inline-flex; align-items: center; justify-content: center; width: 15px; height: 15px; border-radius: 50%; font-size: 10px; font-weight: 700; background: var(--accent-soft); color: var(--accent-text); vertical-align: 1px; }
.help { max-width: 920px; }
.help-b { padding: 14px 18px; font-size: 14px; line-height: 1.55; }
.help-b p { margin: 0 0 10px; }
.help-b ol, .help-b ul { margin: 0; padding-left: 20px; }
.help-b li { margin: 4px 0; }
.help-b table { margin: 6px 0 12px; }
.help-b dt { font-weight: 600; margin-top: 10px; }
.help-b dd { margin: 2px 0 0; color: var(--muted); }
.help-toc { display: flex; flex-wrap: wrap; gap: 8px; }
.help-toc a { padding: 4px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent-text); text-decoration: none; font-size: 13px; }
.help-b th, .help-b td { text-align: left; white-space: normal; }
.help-b table { width: 100%; table-layout: auto; }
.hint[data-hint] { cursor: pointer; }
.hint[data-hint]:hover { background: var(--accent); color: #fff; }
.hint-pop { position: absolute; z-index: 1000; max-width: 320px; padding: 10px 12px; border-radius: 10px; background: var(--panel); color: var(--text); border: 1px solid var(--line); box-shadow: 0 8px 24px rgba(0,0,0,.18); font-size: 13px; line-height: 1.45; font-weight: 400; white-space: normal; text-transform: none; letter-spacing: 0; }
