:root{
  --ink:#1C1C1C; --muted:#707070; --faint:#A3A3A3; --line:#EDEDED; --line2:#F2F2F2; --field:#E4E4E4;
  --bg:#FFFFFF; --soft:#FAFAFA; --red:#D92D20; --red-bg:#FEF3F2;
  --ok:#17663A; --ok-bg:#E7F6EC; --warn:#8A5A00; --warn-bg:#FDF3D7;
}
*{box-sizing:border-box}
html,body{margin:0;background:var(--bg);color:var(--ink)}
body{font-family:-apple-system,BlinkMacSystemFont,'SF Pro Text','Segoe UI',Roboto,sans-serif;font-size:13px;line-height:1.4;-webkit-font-smoothing:antialiased}
button,input,select,textarea{font-family:inherit;font-size:13px;color:var(--ink)}
button{cursor:pointer}
button:disabled{cursor:default;opacity:.45}
.num{font-variant-numeric:tabular-nums}
.muted{color:var(--muted)}
.red{color:var(--red)}

/* шапка */
.top{display:flex;flex-wrap:wrap;align-items:center;gap:10px 18px;padding:10px 24px;border-bottom:1px solid var(--line);position:sticky;top:0;background:var(--bg);z-index:5;min-height:51px}
.brand{font-weight:600;font-size:15px}
.seg{display:inline-flex;padding:2px;background:var(--line2);border-radius:8px}
.seg button{border:0;background:transparent;padding:5px 14px;border-radius:6px;color:var(--muted)}
.seg button.on{background:var(--bg);color:var(--ink);font-weight:500;box-shadow:0 1px 2px rgba(0,0,0,.08)}
.grow{flex-grow:1}
.top select,.top input[type=date]{height:30px;border:1px solid var(--field);border-radius:6px;padding:0 8px;background:var(--bg)}
.link{border:0;background:none;color:var(--muted);padding:0}
.link:hover{color:var(--ink)}

main{max-width:1440px;margin:0 auto;padding:20px 24px 120px;display:flex;flex-direction:column;gap:16px}
.titlebar{display:flex;flex-wrap:wrap;align-items:center;gap:8px}
h1{margin:0;font-size:22px;font-weight:600;letter-spacing:-.01em}
.btn{height:32px;padding:0 12px;border:1px solid var(--field);border-radius:7px;background:var(--bg);white-space:nowrap}
.btn:hover:not(:disabled){background:var(--soft)}
.btn.dark{border:0;background:var(--ink);color:#fff;font-weight:500}
.btn.dark:hover:not(:disabled){background:#000}
.btn.sm{height:28px;padding:0 10px;font-size:12px;border-radius:6px}
.btn.danger{color:var(--red)}

/* полоса цифр */
.stats{display:grid;grid-template-columns:1.4fr 1.4fr repeat(5,minmax(0,1fr));border:1px solid var(--line);border-radius:10px;overflow:hidden}
.stat{display:flex;flex-direction:column;gap:4px;align-items:flex-start;padding:12px 16px;border:0;border-right:1px solid var(--line);background:var(--bg);text-align:left}
.stat:last-child{border-right:0}
.stat:hover{background:var(--soft)}
.stat.on{background:var(--soft);box-shadow:inset 0 -2px 0 var(--ink)}
.stat .l{display:flex;align-items:center;gap:6px;color:var(--muted);font-size:12px}
.stat .v{font-size:20px;font-weight:600;font-variant-numeric:tabular-nums}
.stat.big .v{font-size:28px}
.stat.ex .v{color:var(--red)}
.dot{width:8px;height:8px;border-radius:50%}

/* панели ввода */
.panel{display:flex;flex-wrap:wrap;align-items:flex-end;gap:10px;padding:14px 16px;background:var(--soft);border:1px solid var(--line);border-radius:10px}
.panel .ttl{flex-basis:100%;font-weight:600}
.panel .hint{flex-basis:100%;color:var(--muted);font-size:12px}
.fld{display:flex;flex-direction:column;gap:4px;color:var(--muted);font-size:12px}
.fld input,.fld select,.fld textarea{height:30px;border:1px solid var(--field);border-radius:6px;padding:0 8px;background:var(--bg)}
.fld textarea{height:60px;padding:6px 8px;resize:vertical}
input.q{width:52px;height:30px;border:1px solid var(--field);border-radius:6px;text-align:center;font-variant-numeric:tabular-nums;background:var(--bg)}
input:focus,select:focus,textarea:focus{outline:2px solid var(--ink);outline-offset:-1px}
.pointpick{min-width:320px}

/* список входящих */
.list{border:1px solid var(--line);border-radius:10px;overflow:hidden}
.row{display:grid;grid-template-columns:105px minmax(180px,1.6fr) 90px 70px minmax(220px,2.4fr) minmax(110px,1fr) 240px;gap:12px;align-items:center;padding:10px 16px;border-bottom:1px solid var(--line2)}
.row:last-child{border-bottom:0}
.row.head{padding:8px 16px;background:var(--soft);border-bottom:1px solid var(--line);color:var(--muted);font-size:12px}
.row.dim{color:var(--faint)}
.row .acts{display:flex;justify-content:flex-end;gap:6px}
.pname{font-weight:500}
.paddr{color:var(--muted);font-size:12px}
.pill{display:inline-flex;align-items:center;height:22px;padding:0 9px;border-radius:11px;font-size:12px;font-weight:500;white-space:nowrap}
.pill.ok{background:var(--ok-bg);color:var(--ok)}
.pill.warn{background:var(--warn-bg);color:var(--warn)}
.pill.gray{background:var(--line2);color:var(--muted)}
.pill.ink{background:var(--ink);color:#fff}
.pill.off{background:var(--line2);color:var(--faint);text-decoration:line-through}
.edit{grid-column:1/-1;display:flex;flex-wrap:wrap;align-items:flex-end;gap:10px;padding:4px 0 6px}
.empty{padding:28px 16px;text-align:center;color:var(--muted)}
.raw{grid-column:1/-1;white-space:pre-wrap;background:var(--soft);border-radius:6px;padding:8px 10px;color:var(--muted);font-size:12px}

/* сводка */
.tablewrap{border:1px solid var(--line);border-radius:10px;overflow:auto}
table.grid{border-collapse:collapse;width:100%;font-variant-numeric:tabular-nums}
.grid th,.grid td{padding:7px 8px;border-bottom:1px solid var(--line2);text-align:center;white-space:nowrap}
.grid th{position:sticky;top:0;background:var(--soft);color:var(--muted);font-weight:500;font-size:12px;border-bottom:1px solid var(--line);z-index:1}
.grid th:first-child,.grid td:first-child{text-align:left;position:sticky;left:0;background:var(--bg);min-width:220px}
.grid th:first-child{background:var(--soft);z-index:2}
.grid td.sumc,.grid th.sumc{text-align:right;min-width:100px}
.grid td.c{cursor:pointer;min-width:54px}
.grid td.c:hover{background:var(--soft)}
.grid td.c.sel{outline:2px solid var(--ink);outline-offset:-2px;background:var(--soft)}
.grid s{color:var(--faint);margin-right:4px}
.grid .ex{color:var(--red);font-size:11px;margin-left:3px}
.grid tfoot td{background:var(--soft);font-weight:500;border-bottom:1px solid var(--line)}
.grid tfoot td:first-child{background:var(--soft);color:var(--muted);font-weight:400}
.grid tfoot tr.key td{font-weight:600;color:var(--ink)}
.grid input.q{width:56px;height:26px}
.tag{display:inline-block;margin-left:6px;padding:0 6px;border:1px solid var(--line);border-radius:4px;color:var(--muted);font-size:11px;font-weight:400}
.neg{color:var(--red);font-weight:600}
.pos{color:var(--ok)}

.editor{position:fixed;left:50%;bottom:20px;transform:translateX(-50%);display:flex;flex-wrap:wrap;align-items:center;gap:10px 14px;padding:12px 16px;background:var(--bg);border:1px solid var(--line);border-radius:12px;box-shadow:0 8px 30px rgba(0,0,0,.12);z-index:10;max-width:calc(100vw - 32px)}
.stepper{display:inline-flex;align-items:center;border:1px solid var(--field);border-radius:7px;overflow:hidden}
.stepper button{width:30px;height:30px;border:0;background:var(--bg);font-size:16px}
.stepper button:hover{background:var(--soft)}
.stepper input{width:48px;height:30px;border:0;border-left:1px solid var(--field);border-right:1px solid var(--field);text-align:center;font-variant-numeric:tabular-nums}
.stepper.red input{color:var(--red)}

.notice{padding:10px 14px;border-radius:8px;background:var(--warn-bg);color:var(--warn)}
.toast{position:fixed;left:50%;top:64px;transform:translateX(-50%);padding:10px 16px;border-radius:8px;background:var(--ink);color:#fff;z-index:20;box-shadow:0 6px 20px rgba(0,0,0,.18)}
.toast.err{background:var(--red)}

/* вход */
.login{min-height:100vh;display:flex;align-items:center;justify-content:center;padding:24px}
.login form{width:340px;display:flex;flex-direction:column;gap:12px;padding:28px;border:1px solid var(--line);border-radius:14px}
.login h1{font-size:20px}
.login input{height:36px;border:1px solid var(--field);border-radius:8px;padding:0 10px;font-size:14px}
.login .btn{height:36px;font-size:14px}
.err{color:var(--red)}

@media (max-width:900px){
  .stats{grid-template-columns:repeat(3,minmax(0,1fr))}
  .stat{border-bottom:1px solid var(--line)}
  .row{grid-template-columns:1fr 1fr;}
  .row.head{display:none}
  .row .acts{justify-content:flex-start;grid-column:1/-1}
  main{padding:16px 12px 120px}
  .top{padding:10px 12px}
}

.stats.sum7{grid-template-columns:repeat(7,minmax(0,1fr))}
.stats.sum7 .stat{cursor:default}
.stats.sum7 .stat:hover{background:var(--bg)}
.stats.sum7 .stat.big .v{font-size:20px}
.grid td.tot,.grid th.tot{font-weight:600;min-width:72px}
@media (max-width:900px){.stats.sum7{grid-template-columns:repeat(3,minmax(0,1fr))}}
.grid tfoot td.neg,.grid tfoot tr.key td.neg{color:var(--red)}
.grid tfoot td.pos,.grid tfoot tr.key td.pos{color:var(--ok)}
.grid tfoot td.red{color:var(--red)}
.stats.sum6{grid-template-columns:repeat(6,minmax(0,1fr))}
.stats.sum6 .stat{cursor:default}
.stats.sum6 .stat:hover{background:var(--bg)}
.stats.sum6 .stat.big .v{font-size:20px}
@media (max-width:900px){.stats.sum6{grid-template-columns:repeat(3,minmax(0,1fr))}}
.stat .sub{color:var(--muted);font-size:13px;font-variant-numeric:tabular-nums}

/* компактная сводка */
.tablewrap{align-self:flex-start;max-width:100%}
table.grid{width:auto}
.grid th,.grid td{padding:8px 12px;line-height:1.4}
.grid tfoot td{padding:7px 12px}
.grid th{font-size:13px}
.grid td.c{min-width:62px;width:62px}
.grid th:first-child,.grid td:first-child{min-width:240px;max-width:320px;white-space:normal;padding-left:10px}
.grid td.tot,.grid th.tot{min-width:72px}
.grid td.sumc,.grid th.sumc{min-width:96px}
.grid input.q{width:52px;height:28px;font-size:15px}
.grid .tag{font-size:10px;padding:0 4px;margin-left:4px}
.row .total{font-weight:600;font-size:15px}
.stats.bake{grid-template-columns:repeat(4,minmax(0,1fr))}
.stats.bake .stat{cursor:default}
.stats.bake .stat:hover{background:var(--bg)}
table.grid{font-size:15px}
.grid .paddr{font-size:13px}
.grid .ex{font-size:13px}
.tag.warn{background:var(--warn-bg);color:var(--warn);border-color:transparent}

/* каркас с боковым меню */
.layout{display:flex;min-height:100vh}
.side{width:200px;flex-shrink:0;display:flex;flex-direction:column;gap:2px;padding:14px 10px;border-right:1px solid var(--line);background:var(--soft);position:sticky;top:0;height:100vh}
.side .brand{font-weight:600;font-size:16px;padding:4px 10px 14px}
.navgrp{padding:12px 10px 4px;color:var(--faint);font-size:11px;text-transform:uppercase;letter-spacing:.04em}
.nav{border:0;background:transparent;text-align:left;padding:7px 10px;border-radius:7px;font-size:14px;color:var(--ink)}
.nav.sub{padding-left:18px}
.nav:hover{background:var(--line2)}
.nav.on{background:var(--bg);box-shadow:0 1px 2px rgba(0,0,0,.08);font-weight:500}
.side .me{display:flex;flex-direction:column;gap:4px;padding:10px;border-top:1px solid var(--line)}
.content{flex:1;min-width:0}
main.wide{max-width:1500px}
.small{font-size:12px}

/* аналитика */
.card{border:1px solid var(--line);border-radius:10px;padding:14px 16px;display:flex;flex-direction:column;gap:10px;min-width:0}
.card-h{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap}
.card h2{margin:0;font-size:15px;font-weight:600}
.grid2{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:16px}
svg.chart{width:100%;height:auto;display:block}
svg.spark{width:100%;height:44px;display:block}
.legend{display:flex;gap:14px;flex-wrap:wrap;color:var(--muted);font-size:12px}
.legend .sw{display:inline-block;width:10px;height:10px;border-radius:3px;margin-right:6px;vertical-align:-1px}
.hbars{display:flex;flex-direction:column;gap:6px}
.hb{display:grid;grid-template-columns:130px minmax(0,1fr) 150px;gap:10px;align-items:center}
.hb-l{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.hb-bar{height:14px;background:var(--line2);border-radius:4px;overflow:hidden}
.hb-bar span{display:block;height:100%;border-radius:4px}
.hb-v{font-size:13px;white-space:nowrap}
.hb:hover .hb-l{font-weight:500}
.minis{display:grid;grid-template-columns:repeat(6,minmax(0,1fr));gap:12px}
.mini{border:1px solid var(--line2);border-radius:8px;padding:8px 10px}
.mini-h{display:flex;justify-content:space-between;gap:6px;font-size:13px}
.mini-h .num{color:var(--red);font-weight:600}
.stats.kpi5{grid-template-columns:repeat(5,minmax(0,1fr))}
.stats.kpi5 .stat{cursor:default}
.stats.kpi5 .stat:hover{background:var(--bg)}
.dl{font-size:12px;font-weight:500;color:var(--muted);margin-left:4px}
.dl.up{color:var(--ok)}
.dl.down{color:var(--red)}
.tip{position:fixed;display:none;z-index:50;background:var(--ink);color:#fff;font-size:12px;line-height:1.45;padding:7px 9px;border-radius:6px;pointer-events:none;max-width:280px;font-variant-numeric:tabular-nums}
table.tbl{border-collapse:collapse;width:100%;font-size:13px}
.tbl th{text-align:left;color:var(--muted);font-weight:500;font-size:12px;padding:6px 8px;border-bottom:1px solid var(--line)}
.tbl td{padding:7px 8px;border-bottom:1px solid var(--line2);vertical-align:top}
.tbl .r{text-align:right}
.tablewrap.wide{align-self:stretch}
.search{height:32px;border:1px solid var(--field);border-radius:7px;padding:0 10px;width:240px}
.chk{display:flex;align-items:center;gap:6px;height:30px}
@media (max-width:1100px){.grid2{grid-template-columns:1fr}.minis{grid-template-columns:repeat(3,minmax(0,1fr))}.stats.kpi5{grid-template-columns:repeat(3,minmax(0,1fr))}}
@media (max-width:900px){.layout{flex-direction:column}.side{width:auto;height:auto;position:static;flex-direction:row;flex-wrap:wrap;align-items:center}.navgrp{display:none}.side .me{border:0;flex-direction:row}}

/* закреплённая шапка: всё выше таблицы стоит на месте, таблица прокручивается */
.freeze{position:sticky;top:var(--top-h,51px);z-index:4;background:var(--bg);display:flex;flex-direction:column;gap:16px;margin-top:-20px;padding:20px 0 14px;box-shadow:0 1px 0 var(--line)}
.list{overflow:clip}
.list .row.head{position:sticky;top:calc(var(--top-h,51px) + var(--fz,0px));z-index:3}
@media (min-width:1101px){.tablewrap{overflow:clip}.grid thead th{top:calc(var(--top-h,51px) + var(--fz,0px))}}

/* ---------- мобильная версия ---------- */
@media (max-width:900px){
  body{font-size:14px}
  .layout{flex-direction:column}
  .side{width:auto;height:auto;position:sticky;top:0;z-index:6;flex-direction:row;align-items:center;gap:4px;padding:8px 10px;border-right:0;border-bottom:1px solid var(--line);overflow-x:auto}
  .side .brand{padding:0 8px 0 4px;font-size:15px}
  .side .grow{display:none}
  .side .me{flex-direction:row;align-items:center;gap:8px;padding:0 0 0 8px;border:0;margin-left:auto}
  .side .me .small{display:none}
  .nav{padding:6px 10px;white-space:nowrap}
  .top{position:static;padding:8px 12px;gap:8px}
  .top .seg{width:100%;overflow-x:auto}
  .top .seg button{flex:1;white-space:nowrap;padding:6px 8px}
  .top input[type=date]{flex:1}
  main,main.wide{padding:12px 10px 140px;gap:12px}
  .freeze{position:static;margin-top:0;padding:0;box-shadow:none;gap:12px}
  h1{font-size:19px}
  .titlebar{gap:6px}
  .titlebar .grow{flex-basis:100%;height:0}
  .titlebar .btn{flex:1 1 auto}
  .stats,.stats.bake,.stats.kpi5{grid-template-columns:repeat(2,minmax(0,1fr))}
  .stat{border-bottom:1px solid var(--line);padding:10px 12px}
  .stat .v{font-size:18px}
  .stat.big .v{font-size:22px}
  /* список заказов — карточками */
  .list .row.head{display:none}
  .row{grid-template-columns:auto minmax(0,1fr) auto;gap:6px 10px;padding:12px}
  .row > :nth-child(1){grid-row:1;grid-column:1}
  .row > :nth-child(2){grid-row:1;grid-column:2}
  .row > :nth-child(3){grid-row:4;grid-column:1/-1;font-size:12px}
  .row > :nth-child(3) br{display:none}
  .row > :nth-child(4){grid-row:1;grid-column:3;text-align:right}
  .row > :nth-child(5){grid-row:2;grid-column:1/-1}
  .row > :nth-child(6){grid-row:3;grid-column:1/-1}
  .row > :nth-child(6):empty{display:none}
  .row > .acts{grid-row:5;grid-column:1/-1;justify-content:flex-start;flex-wrap:wrap}
  .row > .acts .btn{flex:1}
  .row > .edit{grid-row:6}
  .panel .fld,.panel .pointpick{min-width:0}
  .panel .pointpick,.panel input[name=address],.panel input[name=legal],.panel input[name=note]{width:100% !important}
  .panel label.fld:has(.pointpick),.panel label.fld:has([name=address]),.panel label.fld:has([name=legal]){flex-basis:100%}
  /* сводка */
  .tablewrap{overflow:auto;-webkit-overflow-scrolling:touch}
  table.grid{font-size:14px}
  .grid th,.grid td{padding:7px 8px}
  .grid th:first-child,.grid td:first-child{min-width:150px;max-width:170px}
  .grid td.c{min-width:46px;width:46px}
  .editor{left:8px;right:8px;bottom:8px;transform:none;max-width:none}
  /* аналитика */
  .grid2{grid-template-columns:1fr}
  .minis{grid-template-columns:repeat(2,minmax(0,1fr))}
  .hb{grid-template-columns:90px minmax(0,1fr) auto;gap:6px}
  .hb-v .muted{display:none}
  .card{padding:12px}
  .titlebar .seg{overflow-x:auto;max-width:100%}
  .titlebar .seg button{padding:5px 9px}
  /* точки */
  .search{width:100%}
  table.tbl{font-size:13px}
  .tbl th:nth-child(4),.tbl td:nth-child(4),.tbl th:nth-child(5),.tbl td:nth-child(5),.tbl th:nth-child(6),.tbl td:nth-child(6){display:none}
  .toast{top:auto;bottom:16px;max-width:calc(100vw - 32px)}
}
