/* Светлая тема в духе админки PrestaShop: белые панели, бирюзовый акцент. */
:root{
  --bg:#f1f1f1; --panel:#fff; --line:#e2e5ea; --line2:#eff1f4;
  --ink:#363a41; --dim:#7a7f85; --head:#fafbfc;
  --acc:#25b9d7; --acc-dark:#1e9ab3; --dark:#2b3a4a;
  --good:#3f9c56; --bad:#e04b4b; --warn:#d98324;
}
*{box-sizing:border-box}
body{margin:0;background:var(--bg);color:var(--ink);
  font:14px/1.5 -apple-system,"Segoe UI",Roboto,Arial,sans-serif}

header{position:sticky;top:0;z-index:20;display:flex;align-items:center;gap:16px;
  padding:0 18px;height:58px;background:var(--dark);
  border-bottom:3px solid var(--acc);box-shadow:0 1px 6px rgba(0,0,0,.18)}
h1{margin:0;font-size:17px;font-weight:700;color:#fff;white-space:nowrap}
h1 span{margin-left:8px;font-size:11px;font-weight:400;color:#8f9bab}
h3{margin:24px 0 8px;font-size:12px;color:var(--dim);font-weight:700;
  text-transform:uppercase;letter-spacing:.7px}
nav{display:flex;gap:2px}
button{font:inherit;color:var(--ink);background:#fff;border:1px solid var(--line);
  border-radius:4px;padding:6px 13px;cursor:pointer;transition:.12s}
button:hover{border-color:var(--acc);color:var(--acc-dark)}
button:disabled{opacity:.5;cursor:default}
.tab{border:none;background:transparent;color:#b6c0cd;font-weight:600;
  padding:8px 14px;border-radius:4px}
.tab:hover{background:rgba(255,255,255,.09);color:#fff}
.tab.on{background:var(--acc);color:#fff}
button.go{background:var(--acc);border-color:var(--acc);color:#fff;font-weight:600}
button.go:hover{background:var(--acc-dark);border-color:var(--acc-dark);color:#fff}
button.danger{background:var(--bad);border-color:var(--bad);color:#fff;font-weight:600}
button.danger:hover{background:#c93b3b;border-color:#c93b3b;color:#fff}
#status{margin-left:auto;font-size:11px;color:#78838f;text-align:right;
  max-height:38px;overflow:hidden;line-height:1.3}

.page{display:none;padding:16px 18px 60px}
.page.on{display:block}

/* ── панели фильтров ─────────────────────────────────────────── */
.bar{display:flex;align-items:flex-end;gap:14px;margin-bottom:12px;flex-wrap:wrap}
.bar.wrap{background:var(--panel);border:1px solid var(--line);border-radius:4px;
  padding:14px 16px;gap:16px 22px}
label{display:flex;flex-direction:column;gap:4px;font-size:11.5px;color:var(--dim);
  font-weight:600;text-transform:uppercase;letter-spacing:.4px}
label.check{flex-direction:row;align-items:center;gap:7px;color:var(--ink);
  font-size:13px;font-weight:400;text-transform:none;letter-spacing:0}
input,select{font:inherit;color:var(--ink);background:#fff;border:1px solid var(--line);
  border-radius:4px;padding:6px 9px;min-height:32px}
input:focus,select:focus{outline:none;border-color:var(--acc)}
input[type=range]{width:150px;padding:0;min-height:0;border:none;background:transparent;
  accent-color:var(--acc)}
input[type=checkbox]{min-height:0;accent-color:var(--acc);width:15px;height:15px}
input[type=number]{width:130px}
input[type=search],input.search{width:260px}
/* «Что везём»: поиск и три дропдауна одного размера */
#s-q,#s-filter,#s-brand-pick,#s-clusters-pick{width:200px;min-width:200px}
output{font-size:13px;color:var(--ink);font-variant-numeric:tabular-nums}
label:has(input[type=range]){display:grid;grid-template-columns:auto auto;
  grid-template-areas:"t t" "r o";align-items:center;gap:2px 8px}
label:has(input[type=range])>input{grid-area:r}
label:has(input[type=range])>output{grid-area:o}

/* ── плитки показателей ──────────────────────────────────────── */
.kpi{display:flex;flex-wrap:wrap;gap:10px;margin:12px 0}
.card{flex:1 1 140px;background:var(--panel);border:1px solid var(--line);
  border-radius:4px;padding:12px 14px}
.card b{display:block;font-size:21px;font-variant-numeric:tabular-nums;
  margin-bottom:3px;font-weight:700}
.card span{font-size:11px;color:var(--dim);text-transform:uppercase;
  letter-spacing:.5px;font-weight:600}

/* ── таблицы ─────────────────────────────────────────────────── */
.tw{overflow:auto;border:1px solid var(--line);border-radius:4px;background:var(--panel)}
/* длинные списки прокручиваются ВНУТРИ рамки — тогда sticky-шапка держится:
   без ограничения высоты обёртка тянется под все строки и не создаёт прокрутки */
#s-items .tw,#g-table .tw{max-height:calc(100vh - 120px)}
table{border-collapse:separate;border-spacing:0;width:100%;font-size:13.5px}
th,td{padding:9px 11px;text-align:left;white-space:nowrap;
  border-bottom:1px solid var(--line2)}
th{position:sticky;top:0;background:var(--head);color:var(--dim);font-weight:700;
  font-size:11px;text-transform:uppercase;letter-spacing:.5px;z-index:2;
  border-bottom:1px solid var(--line);cursor:pointer;user-select:none}
th:hover{color:var(--acc-dark)}
th.sorted::after{content:" ▾";color:var(--acc)}
th.sorted.asc::after{content:" ▴"}
tbody tr:nth-child(even){background:#fcfcfd}
tbody tr:hover{background:#eef9fc}
tr:last-child td{border-bottom:none}
td.n{text-align:right;font-variant-numeric:tabular-nums}
/* Товар переносится по словам; ширину колонок регулируем перетаскиванием */
td.name{white-space:normal;vertical-align:top}
td.art{white-space:nowrap;vertical-align:top}
/* ручка изменения ширины на правой границе заголовка */
.rh{position:absolute;top:0;right:0;width:7px;height:100%;cursor:col-resize;
  user-select:none;z-index:3}
.rh:hover{background:var(--acc)}
/* иконка копирования артикула */
.copy{border:none;background:none;padding:1px 3px;margin-left:6px;min-height:0;
  color:var(--dim);cursor:pointer;line-height:0;border-radius:3px;opacity:.5;
  vertical-align:middle}
.copy:hover{color:var(--acc-dark);background:var(--head);opacity:1;border-color:transparent}
.copy svg{display:block}
/* кнопка разворота строки — крупный жирный плюс в начале */
td.exp{width:1px;text-align:center;padding-left:8px;padding-right:4px}
.expand{border:none;background:none;cursor:pointer;color:var(--acc-dark);
  font-size:20px;font-weight:700;line-height:1;padding:0 4px;min-height:0;
  width:22px;border-radius:3px}
.expand:hover{color:#fff;background:var(--acc)}
/* поле ручного минимума в таблице поставок */
input.mininp{width:54px;min-height:27px;padding:2px 4px;text-align:center;
  font-size:13px;font-variant-numeric:tabular-nums}
input.mininp:hover{border-color:var(--acc)}
/* ссылка скачивания кластера в таблице отгрузок */
a.dl{cursor:pointer;color:var(--acc-dark);font-size:16px;text-decoration:none;
  display:inline-block;padding:0 4px;border-radius:3px}
a.dl:hover{color:#fff;background:var(--acc)}
td.wrap{white-space:normal;max-width:400px;color:var(--dim);font-size:12px}
td.pick{width:1px;padding-right:0}
td.art{font-weight:600;font-variant-numeric:tabular-nums}
.good{color:var(--good)}.bad{color:var(--bad)}.warn{color:var(--warn)}.dim{color:var(--dim)}
.empty{padding:22px;color:var(--dim);text-align:center}
.count{font-size:12px;color:var(--dim);margin-left:auto;align-self:center}

/* значки схемы и статуса */
.tag{display:inline-block;padding:1px 7px;border-radius:3px;font-size:11px;
  font-weight:700;letter-spacing:.3px}
.tag.fbo{background:#e3f4f8;color:#1e7f96}
.tag.fbs{background:#fdf0e3;color:#a8641a}
.tag.both{background:#eae7fb;color:#5b4bb5}
.tag.none{background:#f0f1f3;color:#9aa0a6}
.tag.ok{background:#e8f5e9;color:#357a3f}
.tag.out{background:#fdeaea;color:#c33}

/* ── лента действий ─────────────────────────────────────────── */
.lead{font-size:14px;color:var(--dim);margin:4px 0 16px}
.lead b{color:var(--ink);font-size:16px;font-weight:700}
.card2{background:var(--panel);border:1px solid var(--line);
  border-left:3px solid var(--tone);border-radius:4px;padding:16px 18px;margin-bottom:14px}
.card2>header{position:static;display:flex;align-items:flex-start;gap:20px;
  padding:0;height:auto;background:none;border:none;box-shadow:none;margin-bottom:6px}
.card2 h2{margin:0;font-size:16px;font-weight:700}
.card2 .amt{margin-left:auto;text-align:right;font-size:21px;font-weight:700;
  font-variant-numeric:tabular-nums;line-height:1.15;white-space:nowrap}
.card2 .amt small{display:block;font-size:10px;font-weight:600;color:var(--dim);
  text-transform:uppercase;letter-spacing:.5px;margin-top:3px}
.card2 .why{margin:0 0 12px;font-size:13px;color:var(--dim);max-width:820px;line-height:1.5}
.card2 .tw{max-height:420px}
.acts{display:flex;gap:8px;margin-top:12px}
.acts button:first-child{background:var(--acc);border-color:var(--acc);color:#fff;font-weight:600}
.acts button:first-child:hover{background:var(--acc-dark)}

#toast{position:fixed;right:18px;bottom:18px;display:flex;flex-direction:column;
  gap:8px;z-index:50}
#toast div{background:#fff;border:1px solid var(--line);border-left:3px solid var(--acc);
  border-radius:4px;padding:11px 15px;max-width:420px;box-shadow:0 4px 16px rgba(0,0,0,.13)}
#toast div.err{border-left-color:var(--bad)}
.spin{padding:16px;color:var(--dim)}
@media(max-width:900px){.split{grid-template-columns:1fr}}
.split{display:grid;grid-template-columns:1fr 1fr;gap:22px}

/* ── раскрывающаяся детализация по кластерам ─────────────────── */
tr.detail>td{padding:0;background:#f7fbfd;border-bottom:2px solid var(--line)}
table.inner{width:auto;min-width:760px;margin:6px 0 8px 34px;font-size:12.5px}
table.inner th{position:static;background:transparent;border-bottom:1px solid var(--line);
  cursor:default;font-size:10px}
table.inner td{border-bottom:1px solid var(--line2);padding:5px 10px}
table.inner tbody tr.skip td{color:var(--dim)}
table.inner tbody tr:hover{background:#eaf6fa}

/* ── индикатор наличия и выбор кластеров ─────────────────────── */
.dot{display:inline-block;width:8px;height:8px;border-radius:50%;margin-right:6px;
  vertical-align:middle}
.dot.g{background:var(--good)}
.dot.r{background:var(--bad)}
.dot.n{background:#d3d7dd}
/* рамка на самом summary, а не на обёртке — тогда высота совпадает с select */
details.multi{position:relative;min-width:200px}
details.multi>summary{border:1px solid var(--line);border-radius:4px;background:#fff;
  padding:6px 10px;min-height:32px;display:flex;align-items:center;cursor:pointer;
  list-style:none;font-size:14px;color:var(--ink);white-space:nowrap;overflow:hidden}
details.multi>summary::-webkit-details-marker{display:none}
details.multi>summary::after{content:"▾";color:var(--dim);margin-left:auto;padding-left:8px}
details.multi[open]>summary::after{content:"▴"}
details.multi .opts{position:absolute;z-index:15;top:100%;left:0;min-width:280px;
  max-height:320px;overflow:auto;background:#fff;border:1px solid var(--line);
  border-radius:4px;box-shadow:0 6px 20px rgba(0,0,0,.14);padding:6px}
details.multi .opts label{padding:4px 8px;border-radius:3px}
details.multi .opts label:hover{background:var(--head)}

/* разлиновка столбцов: с таким числом колонок глаз теряет строку */
th, td{border-right:1px solid var(--line2)}
th:last-child, td:last-child{border-right:none}
th{border-right-color:var(--line)}

/* подсказка, когда настройка молча режет план */
.hint{background:#fff8e6;border:1px solid #f0dca8;border-left:3px solid var(--warn);
  border-radius:4px;padding:10px 14px;margin:10px 0;font-size:13px;line-height:1.5}

/* ── статус синхронизации (вкладка Журнал) ───────────────────── */
.sync{margin-bottom:18px}
.sync-card{background:#fff;border:1px solid var(--line);border-left:3px solid var(--acc);
  border-radius:5px;padding:12px 16px;max-width:520px}
.sync-h{font-weight:600;font-size:15px;margin-bottom:4px}
.sync-when{font-size:13px;color:var(--ink);margin-bottom:6px}
.sync-when small{color:var(--dim);margin-left:6px}
.sync-card ul{margin:0;padding-left:18px;font-size:13px;line-height:1.7}
.sync h4{margin:16px 0 6px;font-size:13px;color:var(--dim);text-transform:uppercase;
  letter-spacing:.03em}
#status .dot{margin-right:5px}
.pwbox{display:flex;gap:10px;align-items:center;flex-wrap:wrap;margin-bottom:18px}
.pwbox input{width:220px}

/* ── лента заказов: плотный сплошной список, без воздуха ─────── */
#orders .kpi{gap:6px;margin:8px 0}
#orders .card{flex:1 1 110px;padding:6px 10px}
#orders .card b{font-size:15px;margin-bottom:1px}
#orders .card span{font-size:9.5px;letter-spacing:.3px}
#o-note{margin:2px 2px 6px;font-size:11.5px}

/* Вкладка заказов не прокручивает страницу: тулбар, сводка и шапка колонок
   всегда на месте, крутится только лента. Шапка — ОТДЕЛЬНАЯ полоса над
   рамкой, вне прокрутки: ей физически некуда пропадать. */
#orders.page.on{display:flex;flex-direction:column;
  height:calc(100vh - 58px);padding-bottom:12px;overflow:hidden}
#orders .bar,#orders .kpi,#o-note,#o-head{flex:0 0 auto}
#o-head{display:flex;justify-content:space-between;align-items:center;gap:8px;
  padding:8px 10px;background:var(--dark);border-radius:4px 4px 0 0;
  overflow:hidden;scrollbar-gutter:stable}
#o-head .oid-h,#o-head .osum{color:#fff;font-size:11px;font-weight:700;
  text-transform:uppercase;letter-spacing:.6px}
#o-head .osum{border-left:1px solid rgba(255,255,255,.18)}
#o-feed{border:1px solid var(--line);border-top:none;border-radius:0 0 4px 4px;
  background:#fff;overflow:auto;flex:1 1 auto;min-height:120px;
  scrollbar-gutter:stable}
.order{background:#fff;border:none;border-radius:0;margin:0;overflow:hidden}
.order+.order{border-top:2px solid var(--line)}
.ohead{display:flex;justify-content:space-between;align-items:center;gap:8px;
  flex-wrap:wrap;padding:3px 10px;background:#eef2f6;border-bottom:1px solid var(--line2)}
.ohead .oid{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.ohead .oid>b{font-size:12.5px}
.ohead .dim{font-size:11.5px}
.ohead .tag{padding:0 6px;font-size:10px}
/* фиксированные колонки сумм — числа всех заказов выстраиваются в столбик */
.osums{display:flex;flex-wrap:nowrap;align-items:baseline}
.osum{display:flex;justify-content:flex-end;align-items:baseline;
  width:112px;padding:0 7px;border-left:1px solid #dfe5eb;
  text-align:right;white-space:nowrap}
.ofeed-head .osum{border-left:none}
.osum b{font-size:12px;font-variant-numeric:tabular-nums}
.obody{display:grid;grid-template-columns:1.25fr .85fr}
.obody table{width:100%;border-collapse:collapse;font-size:12px}
.obody td{padding:1px 10px;border-top:1px solid var(--line2);vertical-align:top;
  line-height:1.35}
.obody tr:first-child td{border-top:0}
.obody .copy{margin-left:3px;padding:0 2px}
.oops{border-left:1px solid var(--line2)}
.oops td.dim{width:70px}
.order .tag.good{background:#e3f4e8;color:#2c7a43}
.order .tag.bad{background:#fdeaea;color:#b23434}
.order .tag.warn{background:#fdf3e4;color:#a4670f}
.order .tag.dim{background:#e6eaee;color:#68727d}
@media (max-width:900px){.obody{grid-template-columns:1fr}.oops{border-left:0}}

.b{font-weight:700}

/* ── мобильная адаптация ─────────────────────────────────────── */
@media (max-width: 820px){
  header{height:auto;min-height:48px;padding:0 8px;gap:8px}
  h1{font-size:15px}
  h1 span{display:none}
  #status{display:none}
  nav{overflow-x:auto;flex:1;scrollbar-width:none;-webkit-overflow-scrolling:touch}
  nav::-webkit-scrollbar{display:none}
  .tab{padding:10px 10px;font-size:13px;white-space:nowrap}
  .page{padding:8px 8px 40px}
  .bar{gap:8px;margin-bottom:8px}
  .bar.wrap{padding:10px;gap:10px 12px}
  label{font-size:10.5px}
  input[type=search],input.search{width:100%;min-width:0}
  #s-q,#s-filter,#s-brand-pick,#s-clusters-pick{width:47%;min-width:140px}
  details.multi .opts{max-width:92vw;min-width:0;width:max-content}
  .kpi{gap:6px;margin:8px 0}
  .card{flex:1 1 44%;padding:8px 10px}
  .card b{font-size:16px}
  .card span{font-size:9.5px}
  table{font-size:12px}
  th,td{padding:6px 7px}
  #s-items .tw,#g-table .tw{max-height:calc(100vh - 140px)}
  .card2{padding:10px 12px}
  .card2>header{gap:10px;flex-wrap:wrap}
  .card2 h2{font-size:14px}
  .card2 .amt{font-size:16px}
  .lead{font-size:13px}
  .acts{flex-wrap:wrap}
  #toast{right:8px;bottom:8px;left:8px}
  #toast div{max-width:none}

  /* заказы: страница снова обычная, шапку колонок заменяют подписи в строках */
  #orders.page.on{height:auto;overflow:visible;display:block}
  #o-feed{max-height:calc(100vh - 130px)}
  #o-head{display:none}
  .ohead{flex-direction:column;align-items:flex-start;gap:2px;padding:6px 10px}
  .osums{width:100%;justify-content:flex-start;flex-wrap:wrap;gap:2px 0}
  .osum{width:auto;min-width:0;border-left:0;padding:0 10px 0 0;gap:4px}
  .osum::before{color:#7b8794;font-size:10px;align-self:baseline}
  .osums .osum:nth-child(1)::before{content:'переч.'}
  .osums .osum:nth-child(2)::before{content:'себест.'}
  .osums .osum:nth-child(3)::before{content:'прибыль'}
  .osums .osum:nth-child(4)::before{content:'на влож.'}
  .obody td{padding:3px 10px}
  .oops td.dim{width:56px}

  /* синхронизация и пароль на Журнале */
  .sync-card{max-width:none}
  .pwbox input{width:100%}
}
@media (max-width: 480px){
  .card{flex:1 1 100%}
  #s-q,#s-filter,#s-brand-pick,#s-clusters-pick{width:100%}
}
