:root{
  --bg:#eef1f5; --panel:#ffffffee; --line:#dde2ea; --text:#1d2430; --muted:#6b7585;
  --accent:#e8692c; --accent-soft:#fde9df; --sel:#2f7cf6;
}
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:var(--bg);color:var(--text);
  font:14px/1.4 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;overflow:hidden}
#view{position:fixed;inset:0}
canvas{display:block;touch-action:none}
svg{fill:none;stroke:currentColor;stroke-width:2;stroke-linecap:round;stroke-linejoin:round}
.btn svg{width:18px;height:18px;flex:none}

.bar{position:fixed;top:12px;left:12px;right:12px;display:flex;gap:8px;align-items:center;pointer-events:none;z-index:5}
.bar > *{pointer-events:auto}
.title{background:var(--panel);border:1px solid var(--line);border-radius:12px;padding:6px 12px;
  font-weight:600;max-width:50vw;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;backdrop-filter:blur(8px)}
.title small{display:block;font-weight:400;color:var(--muted);font-size:12px}
.spacer{flex:1}
.btn{background:var(--panel);border:1px solid var(--line);border-radius:12px;height:40px;min-width:40px;padding:0 12px;
  display:inline-flex;align-items:center;justify-content:center;gap:6px;cursor:pointer;font:inherit;color:inherit;backdrop-filter:blur(8px)}
.btn:hover{border-color:#c4ccd8}
.btn.on{background:var(--accent-soft);border-color:var(--accent);color:#a2400f}
.btn.primary{background:var(--accent);border-color:var(--accent);color:#fff}
.btn.wide{width:100%}
.mini{border:1px solid var(--line);background:#fff;border-radius:8px;min-width:32px;height:32px;padding:0 10px;cursor:pointer;font:inherit;color:inherit}
.mini.on{background:var(--accent-soft);border-color:var(--accent);color:#a2400f}

#cube{position:fixed;top:60px;right:10px;width:96px;height:96px;z-index:4;cursor:pointer}
#chips{position:fixed;top:64px;left:50%;transform:translateX(-50%);display:flex;gap:6px;z-index:5}
#chips button{background:#1d2430;color:#fff;border:0;border-radius:20px;padding:6px 12px;font:inherit;font-size:13px;cursor:pointer;white-space:nowrap}

.tools{position:fixed;left:12px;bottom:12px;right:12px;display:flex;gap:6px;flex-wrap:wrap;z-index:5;pointer-events:none}
.tools > *{pointer-events:auto}

.pop{position:fixed;background:var(--panel);border:1px solid var(--line);border-radius:14px;z-index:8;display:none;
  backdrop-filter:blur(10px);box-shadow:0 6px 24px #1d243018}
.pop.open{display:block}
#menu{top:58px;right:12px;padding:6px;min-width:230px}
#menu button{display:flex;align-items:center;gap:10px;width:100%;border:0;background:none;padding:10px;border-radius:8px;font:inherit;color:inherit;cursor:pointer;text-align:left}
#menu button svg{width:18px;height:18px;color:var(--accent)}
#menu button:hover{background:#0000000a}
#menu button.on{background:var(--accent-soft);color:#a2400f}
#explode{left:12px;top:62px;padding:12px 14px;width:min(300px,calc(100vw - 120px))}
#explode label{display:flex;align-items:center;gap:10px;font-weight:600;margin-bottom:6px}
#explode input{flex:1;accent-color:var(--accent)}
.exHint{font-size:12px;color:var(--muted);margin:2px 0 8px}
.row{display:flex;gap:6px}

#card{position:fixed;right:12px;bottom:12px;width:min(380px,calc(100vw - 24px));background:var(--panel);
  border:1px solid var(--line);border-radius:14px;padding:14px 16px;display:none;z-index:6;backdrop-filter:blur(10px);
  box-shadow:0 6px 24px #1d243014;max-height:60vh;overflow:auto}
#card h3{margin:0 0 2px;font-size:16px;padding-right:24px}
#card h3 .num{display:inline-block;background:var(--accent);color:#fff;border-radius:6px;padding:0 7px;margin-right:6px;font-size:14px}
#card .sub{color:var(--muted);font-size:12px;margin-bottom:8px}
#card table{width:100%;border-collapse:collapse}
#card td{padding:4px 0;vertical-align:top;border-top:1px solid var(--line)}
#card td:first-child{color:var(--muted);width:92px;padding-right:8px}
#card .x{position:absolute;top:8px;right:8px;border:0;background:none;font-size:22px;cursor:pointer;color:var(--muted)}
#card .plist{max-height:150px;overflow:auto;margin-top:6px}
#card .plist div{display:flex;gap:8px;padding:3px 4px;border-radius:6px;cursor:pointer;font-size:13px}
#card .plist div:hover{background:#0000000a}
#card .plist b{min-width:26px;color:var(--accent)}
#card .plist i{margin-left:auto;color:var(--muted);font-style:normal}
.acts{display:grid;grid-template-columns:repeat(5,1fr);gap:5px;margin-top:10px}
.acts button{border:1px solid var(--line);background:#fff;border-radius:10px;padding:8px 4px;font:inherit;font-size:12px;cursor:pointer;
  display:flex;flex-direction:column;align-items:center;gap:4px;color:var(--text)}
.acts button svg{width:18px;height:18px;color:var(--accent)}
.acts button.primary{background:var(--accent);border-color:var(--accent);color:#fff}
.acts button.primary svg{color:#fff}
.edge{display:inline-block;width:10px;height:10px;border-radius:2px;margin-right:4px;vertical-align:-1px;background:var(--accent)}

#list{position:fixed;top:62px;left:12px;bottom:62px;width:min(320px,calc(100vw - 24px));background:var(--panel);
  border:1px solid var(--line);border-radius:14px;display:none;flex-direction:column;z-index:7;backdrop-filter:blur(10px)}
#list.open{display:flex}
#list input{margin:10px;padding:8px 10px;border:1px solid var(--line);border-radius:10px;font:inherit}
#list .items{overflow:auto;padding:0 6px 10px}
#list .grp{font-size:12px;color:var(--muted);padding:8px 6px 2px;font-weight:600;cursor:pointer}
#list .grp:hover{color:var(--accent)}
#list .it{padding:6px 8px;border-radius:8px;cursor:pointer;display:flex;gap:8px}
#list .it:hover{background:#0000000a}
#list .it.sel{background:#e8692c1f}
#list .it b{min-width:28px;color:var(--accent)}
#list .it span{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
#list .it i{color:var(--muted);font-style:normal;font-size:12px;white-space:nowrap}

#labels{position:fixed;inset:0;pointer-events:none;z-index:3;overflow:hidden}
.dimlbl{position:absolute;transform:translate(-50%,-50%);background:#fff;border:1.5px solid #1d2430;color:#1d2430;
  border-radius:8px;padding:2px 8px;font-weight:700;font-size:14px;white-space:nowrap;box-shadow:0 2px 8px #1d243022}
.dimlbl small{font-weight:500;color:var(--muted);margin-left:3px;font-size:11px}
.dimlbl.ruler{border-color:var(--sel);color:var(--sel)}
.numlbl{position:absolute;transform:translate(-50%,-50%);background:#fff;border:1px solid #9aa3af;border-radius:5px;
  padding:0 4px;font-size:11px;font-weight:600;color:#1d2430;white-space:nowrap}
.numlbl.sel{background:var(--accent);border-color:var(--accent);color:#fff}

#d2{position:fixed;inset:0;background:#f6f7f9;z-index:12;display:none}
#d2.open{display:flex}
.d2draw{flex:1;position:relative;min-width:0;min-height:0}
#d2svg{position:absolute;inset:0;width:100%;height:100%;cursor:grab;touch-action:none}
.d2zoom{position:absolute;top:12px;left:12px;display:flex;gap:6px}
.d2side{width:340px;background:#fff;border-left:1px solid var(--line);display:flex;flex-direction:column;padding:12px;gap:10px}
.d2head{display:flex;align-items:center;gap:6px}
#d2Title{flex:1;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
#d2Title small{color:var(--muted);font-weight:400}
#d2Info{flex:1;overflow:auto}
#d2Info h4{margin:12px 0 4px;font-size:12px;color:var(--muted);text-transform:uppercase;letter-spacing:.04em}
#d2Info .r{display:flex;justify-content:space-between;gap:8px;padding:4px 0;border-bottom:1px solid var(--line)}
#d2Info .r span:last-child{text-align:right}

#scan{position:fixed;inset:0;background:#000c;z-index:15;display:none;align-items:center;justify-content:center}
#scan.open{display:flex}
.scanBox{background:#fff;border-radius:16px;padding:12px;width:min(440px,calc(100vw - 24px));max-height:calc(100vh - 24px);overflow:auto;
  display:flex;flex-direction:column;gap:8px}
.tabs{display:flex;gap:6px}
.tabs .mini:first-child,.tabs .mini:nth-child(2){flex:1}
#reader{width:100%;border-radius:10px;overflow:hidden;min-height:200px;background:#111}
#paneQr p{text-align:center;color:var(--muted);margin:6px 0 0}
.cam{position:relative;border-radius:10px;overflow:hidden;background:#111;aspect-ratio:4/3}
.cam video{width:100%;height:100%;object-fit:cover;display:block}
.cam .frame{position:absolute;inset:14% 8%;border:2px dashed #ffffffb0;border-radius:8px;pointer-events:none}
#paneLabel{display:flex;flex-direction:column;gap:8px}
#paneLabel .row .btn{flex:1}
#lblText{padding:10px;border:1px solid var(--line);border-radius:10px;font:inherit}
#lblStatus{font-size:13px;color:var(--muted);white-space:pre-wrap}
#lblStatus .ocr{display:block;background:#f3f5f8;border-radius:8px;padding:6px 8px;margin-top:4px;color:var(--text);font-family:ui-monospace,Menlo,monospace;font-size:12px}
.res{border:1px solid var(--line);border-radius:10px;padding:8px 10px;cursor:pointer;text-align:left;margin-bottom:6px}
.res:hover{border-color:var(--accent)}
.res.best{border-color:var(--accent);background:var(--accent-soft)}
.res .t{display:flex;gap:8px;align-items:baseline;font-weight:600}
.res .t b{color:var(--accent)}
.res .t i{margin-left:auto;font-style:normal;font-size:12px;color:var(--muted);font-weight:500}
.res .m{font-size:12px;color:var(--muted);margin-top:2px}
.res .n{display:inline-block;background:#1d2430;color:#fff;border-radius:10px;padding:0 7px;font-size:12px;margin-left:4px}

#drop{position:fixed;inset:0;display:flex;align-items:center;justify-content:center;z-index:20;background:var(--bg)}
#drop.hidden{display:none}
#drop .box{border:2px dashed #b7c0cd;border-radius:20px;padding:40px 32px;text-align:center;max-width:440px;margin:16px;background:#fff}
#drop .box h1{font-size:20px;margin:0 0 8px}
#drop .box p{color:var(--muted);margin:0 0 18px}
#drop.drag .box{border-color:var(--accent);background:var(--accent-soft)}
#msg{position:fixed;left:50%;top:110px;transform:translateX(-50%);background:#1d2430;color:#fff;padding:8px 14px;
  border-radius:10px;display:none;z-index:30;max-width:90vw;text-align:center}

@media (max-width:700px){
  .btn .lbl{display:none}
  .title{max-width:52vw}
  #cube{width:72px;height:72px;top:58px}
  #card{bottom:62px;max-height:48vh}
  .dimlbl{font-size:12px;padding:1px 6px}
  #d2.open{flex-direction:column}
  .d2side{width:auto;height:45%;border-left:0;border-top:1px solid var(--line)}
}

/* ---------- раскрой ---------- */
#cut{position:fixed;inset:0;background:#f6f7f9;z-index:13;display:none;overflow:auto}
#cut.open{display:block}
.cutTop{position:sticky;top:0;background:#fff;border-bottom:1px solid var(--line);padding:10px 14px;display:flex;gap:12px;align-items:center;flex-wrap:wrap;z-index:2}
.cutTop > div{flex:1;min-width:180px}
.cutTop small{display:block;color:var(--muted);font-size:12px}
.cutTop input{width:56px;padding:4px 6px;border:1px solid var(--line);border-radius:6px;font:inherit}
.cutBody{padding:14px;max-width:1200px;margin:0 auto}
.cutSum{width:100%;border-collapse:collapse;background:#fff;border:1px solid var(--line);border-radius:12px;overflow:hidden;font-size:13px}
.cutSum th{text-align:left;color:var(--muted);font-weight:600;padding:8px;border-bottom:1px solid var(--line);background:#fafbfc}
.cutSum td{padding:8px;border-bottom:1px solid var(--line);vertical-align:top}
.cutSum tr.off td{color:var(--muted)}
.cutSum td.big{font-size:22px;font-weight:700;color:var(--accent)}
.cutSum small{display:block;font-size:11px;font-weight:400;color:var(--muted)}
.cutSum .warn,.warn{color:#c0392b}
.sheetEdit input{width:62px;padding:3px 5px;border:1px solid var(--line);border-radius:6px;font:inherit;margin:0 2px}
.sheetEdit .rot{display:block;font-size:12px;margin-top:4px;color:var(--muted)}
.cutExtra{display:grid;grid-template-columns:repeat(auto-fit,minmax(300px,1fr));gap:10px;margin:12px 0}
.cutCard{background:#fff;border:1px solid var(--line);border-radius:12px;padding:10px 12px;font-size:13px}
.cutCard .r{display:flex;justify-content:space-between;gap:10px;padding:4px 0;border-top:1px solid var(--line)}
#cut h3{font-size:15px;margin:22px 0 8px}
.sheets{display:grid;grid-template-columns:repeat(auto-fill,minmax(340px,1fr));gap:12px}
.sheet{background:#fff;border:1px solid var(--line);border-radius:10px;padding:8px}
.sheet .sh{font-size:12px;color:var(--muted);margin-bottom:4px}
.sheet svg{width:100%;height:auto;display:block;stroke:none}
.sheet .pc{cursor:pointer}
.sheet .pc:hover rect{fill:#e8692c33}
.cutNote{font-size:12px;color:var(--muted);margin-top:16px}
@media (max-width:700px){ .cutSum{font-size:12px} .cutSum th:nth-child(4),.cutSum td:nth-child(4){display:none} .sheets{grid-template-columns:1fr} }
@media print{
  body.printing > *:not(#cut){display:none!important}
  #cut{position:static;overflow:visible} .cutTop button,.cutSum button{display:none}
  .sheet{break-inside:avoid}
}

/* карточки материалов и каталог */
.mcards{display:grid;gap:10px}
.mcard{background:#fff;border:1px solid var(--line);border-radius:12px;padding:10px 12px}
.mcard.off{opacity:.6}
.mhead{display:flex;gap:8px;align-items:baseline;flex-wrap:wrap;margin-bottom:8px}
.mname{font-weight:600;flex:1;min-width:200px}
.mmeta{color:var(--muted);font-size:12px}
.tag{font-size:11px;font-weight:700;border-radius:6px;padding:1px 7px;background:#eef1f5;color:#3a4250;white-space:nowrap}
.tag.t9{background:#e7eefb;color:#2a5bb8}          /* Корпусный */
.tag.t8{background:var(--accent-soft);color:#a2400f} /* Фасадный */
.mrow{display:flex;gap:10px 16px;flex-wrap:wrap;align-items:center;font-size:13px}
.mrow label{display:flex;align-items:center;gap:5px;color:var(--muted)}
.mrow select{padding:6px 8px;border:1px solid var(--line);border-radius:8px;font:inherit;color:var(--text);max-width:260px}
.mrow input[type=number]{width:72px;padding:5px 6px;border:1px solid var(--line);border-radius:8px;font:inherit;color:var(--text)}
.mrow input:disabled{background:#f3f5f8;color:var(--muted)}
.mres{display:flex;gap:12px;align-items:center;flex-wrap:wrap;margin-top:8px;padding-top:8px;border-top:1px solid var(--line);font-size:13px;color:var(--muted)}
.mres .big{font-size:20px;font-weight:700;color:var(--accent)}
.mres .sum{margin-left:auto;font-size:16px;font-weight:700;color:var(--text)}
.mres .sum i{font-weight:400;font-size:13px;color:var(--muted)}
.mcard .hint{font-size:12px;color:#b26a00;margin-top:6px}
.cutCard input{width:80px;padding:3px 6px;border:1px solid var(--line);border-radius:6px;font:inherit;margin-top:3px}
.cutCard .r span:last-child{text-align:right}
.total{display:flex;gap:20px;justify-content:flex-end;flex-wrap:wrap;background:#1d2430;color:#fff;border-radius:12px;padding:12px 16px;font-size:15px;margin:10px 0}
.total b{font-size:18px}
.catEd{background:#fff;border:2px solid var(--accent);border-radius:12px;padding:12px;margin-bottom:12px;overflow:auto}
.catEd small{display:block;color:var(--muted);margin:2px 0 8px}
.catEd table{border-collapse:collapse;font-size:13px;min-width:640px}
.catEd th{text-align:left;color:var(--muted);font-weight:600;padding:4px}
.catEd td{padding:3px 4px;white-space:nowrap}
.catEd input,.catEd select{padding:5px 6px;border:1px solid var(--line);border-radius:6px;font:inherit}
.catEd input.n{width:70px}.catEd input.s{width:50px}
.catEd td:first-child input{width:200px}
@media print{ .catEd,.mrow select{display:none} }
