/* ============================================================
   оболочка редактора
   ============================================================ */
.hi-editor{
  --ed-bar:52px;
  container-type:inline-size;container-name:editor;
  position:relative;display:grid;grid-template-rows:var(--ed-bar) minmax(0,1fr) 30px;grid-template-columns:minmax(0,1fr);
  border-radius:var(--radius-l);border:1px solid var(--line);background:var(--surface);
  box-shadow:var(--shadow-1);overflow:hidden;
  font-size:14px;
}
.hi-editor.is-fullscreen{position:fixed;inset:0;z-index:1000;border-radius:0;height:100vh!important;min-height:0!important}

/* ---------- панель инструментов ---------- */
.ed-toolbar{
  position:relative;z-index:60;
  display:flex;align-items:center;gap:6px;padding:0 10px;
  border-bottom:1px solid var(--line);background:var(--surface);
  overflow:visible;
}
.ed-group{display:flex;align-items:center;gap:2px;flex:none}
.ed-sep{width:1px;height:24px;background:var(--line);margin:0 6px;flex:none}
.ed-spacer{flex:1;min-width:6px}
.tb{
  display:inline-flex;align-items:center;justify-content:center;gap:6px;
  height:36px;min-width:36px;padding:0 10px;border-radius:9px;
  font-weight:600;font-size:13.5px;color:var(--ink-2);white-space:nowrap;
  transition:background .12s,color .12s;
}
.tb:hover{background:var(--surface-2);color:var(--ink)}
.tb:disabled{opacity:.35;cursor:default}
.tb:disabled:hover{background:none}
.tb.on{background:var(--ink);color:var(--surface)}
.tb.on .tb-key{color:color-mix(in srgb,var(--surface) 55%,transparent)}
.tb.accent{background:var(--accent);color:#fff}
.tb.accent:hover{background:var(--accent-2)}
.tb.icon{padding:0;width:36px}
.tb svg{width:18px;height:18px;flex:none}
.tb .tb-key{font-family:var(--mono);font-size:11px;font-weight:500;color:var(--ink-3);margin-left:2px}
.tb .tb-count{min-width:18px;height:18px;padding:0 5px;border-radius:999px;background:var(--warn);color:#fff;font-size:11px;font-weight:700;display:inline-grid;place-items:center}
.tb .tb-count.zero{background:var(--ok)}
@container editor (max-width:1260px){.tb .tb-key{display:none}.tb[data-act="undermenu"] .tb-label{display:none}}
@container editor (max-width:1160px){.tb[data-act="check"] .tb-label,.tb[data-act="spec"] .tb-label,.tb[data-act="filemenu"] .tb-label,.tb[data-act="templates"] .tb-label,.tb[data-tool="text"] .tb-label,.tb[data-act="addrect"] .tb-label{display:none}.ed-title{flex-basis:130px}}
@container editor (max-width:1200px){.tb[data-tool="room"] .tb-label{display:none}}
@container editor (max-width:1050px){.tb[data-tool="line"] .tb-label,.tb[data-tool="select"] .tb-label{display:none}}
@container editor (max-width:900px){.tb[data-tool="draw"] .tb-label,.tb[data-act="addrect"] .tb-label{display:none}}
@container editor (max-width:960px){.tb[data-act="templates"] .tb-label,.tb[data-act="png"] .tb-label,.tb[data-act="addroom"] .tb-label{display:none}.ed-title{flex-basis:140px}}
@media (max-width:760px){.tb .tb-label{display:none}.tb .tb-key{display:none}.tb{padding:0 9px}}

.ed-menu-wrap{position:relative;flex:none}
.ed-menu{
  position:absolute;top:calc(100% + 6px);left:0;z-index:120;min-width:250px;
  background:var(--surface);border:1px solid var(--line);border-radius:12px;padding:6px;
  box-shadow:var(--shadow-2);display:none;
}
.ed-menu.right{left:auto;right:0}
.ed-menu.open{display:block}
.ed-menu button{display:flex;align-items:center;gap:10px;width:100%;text-align:left;padding:9px 11px;border-radius:8px;font-size:14px;color:var(--ink)}
.ed-menu button:hover{background:var(--surface-2)}
.ed-menu button svg{width:18px;height:18px;color:var(--ink-3);flex:none}
.ed-menu button small{display:block;font-size:12px;color:var(--ink-3);font-weight:400}
.ed-menu .ed-menu-sep{height:1px;background:var(--line);margin:5px 4px}

.ed-chips{display:flex;align-items:center;gap:6px;flex:none}
.chip{
  --c:#888;
  display:inline-flex;align-items:center;gap:7px;height:30px;padding:0 11px;border-radius:999px;
  border:1px solid var(--line);background:var(--surface);font-size:12.5px;font-weight:600;color:var(--ink-2);
  white-space:nowrap;
}
.chip i{width:22px;height:0;border-top:3px solid var(--c);border-radius:2px}
.chip i.dash{border-top-style:dashed}
.chip i.dot{border-top-style:dotted;border-top-width:4px}
.chip:hover{border-color:var(--line-2);background:var(--surface-2)}
.chip.on{border-color:var(--c);background:color-mix(in srgb,var(--c) 12%,var(--surface));color:var(--ink)}

/* ---------- тело ---------- */
.ed-body{display:grid;grid-template-columns:232px minmax(0,1fr);min-height:0;min-width:0}
.ed-body>*,.fh-body>*{min-width:0;min-height:0}
.hi-editor.no-palette .ed-body{grid-template-columns:minmax(0,1fr)}
.ed-palette{display:flex;flex-direction:column;min-height:0;border-right:1px solid var(--line);background:var(--surface)}
.ed-search{margin:10px 10px 4px;position:relative}
.ed-search input{width:100%;height:36px;padding:0 10px 0 32px;border-radius:9px;border:1px solid var(--line);background:var(--surface-2);font-size:13.5px}
.ed-search input:focus{outline:none;border-color:var(--sel);background:var(--surface)}
.ed-search svg{position:absolute;left:10px;top:10px;width:16px;height:16px;color:var(--ink-3);pointer-events:none}
.ed-pal-list{overflow-y:auto;padding:4px 10px 14px;flex:1;overscroll-behavior:contain}
.ed-pal-cat{font-size:11px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;color:var(--ink-3);margin:12px 2px 6px}
.ed-pal-grid{display:grid;grid-template-columns:1fr 1fr;gap:6px}
.pal-item{
  display:flex;flex-direction:column;align-items:center;gap:4px;padding:8px 4px 6px;
  border-radius:10px;background:var(--paper);border:1px solid var(--line);
  cursor:grab;user-select:none;-webkit-user-select:none;touch-action:none;
  transition:border-color .12s,box-shadow .12s,transform .12s;
}
.pal-item:hover{border-color:var(--accent);box-shadow:var(--shadow-1);transform:translateY(-1px)}
.pal-item:active{cursor:grabbing}
.pal-item.armed{border-color:var(--sel);box-shadow:0 0 0 2px var(--sel-soft)}
.pal-item svg{width:100%;height:46px;pointer-events:none}
.pal-item span{font-size:11px;line-height:1.2;text-align:center;color:#4A5560;min-height:26px;display:flex;align-items:center;pointer-events:none}
.ed-pal-empty{color:var(--ink-3);font-size:13px;padding:14px 4px}

.ed-canvas-wrap{position:relative;overflow:hidden;background:var(--paper);min-width:0;min-height:0;touch-action:none}
.ed-canvas{width:100%;height:100%;display:block;touch-action:none;user-select:none;-webkit-user-select:none}
.ed-canvas-wrap[data-tool="line"] .ed-canvas{cursor:crosshair}
.ed-canvas-wrap[data-tool="text"] .ed-canvas{cursor:text}
.ed-canvas-wrap[data-tool="room"] .ed-canvas{cursor:crosshair}
.ed-canvas-wrap.is-placing .ed-canvas{cursor:copy}
.ed-canvas-wrap.is-panning .ed-canvas{cursor:grabbing}
.el .hit{cursor:move}
.el:hover .sym{filter:drop-shadow(0 1px 2px rgba(43,49,56,.35))}
.cvtext{cursor:move;user-select:none;-webkit-user-select:none}
.linehit{cursor:pointer}
.roomhit{cursor:move}
.room-resize{cursor:nwse-resize}
.port{fill:#fff;stroke:#2F86D6;stroke-width:2;cursor:crosshair;transition:r .08s}
.port:hover{r:7.5;stroke-width:2.5}
.vhandle{fill:#fff;stroke:#2F86D6;stroke-width:2;cursor:move}
.shandle{fill:#2F86D6;stroke:#fff;stroke-width:1.5}
.shandle.h{cursor:ns-resize}.shandle.v{cursor:ew-resize}
.issue-ring{fill:none;stroke:#D98A06;stroke-width:2;stroke-dasharray:4 3;pointer-events:none}

/* ---------- плавающая панель свойств ---------- */
.ed-props{
  position:absolute;top:12px;right:12px;z-index:40;width:250px;
  background:var(--surface);border:1px solid var(--line);border-radius:14px;padding:12px;
  box-shadow:var(--shadow-2);display:none;flex-direction:column;gap:9px;
  max-height:calc(100% - 24px);overflow:auto;
}
.ed-props.open{display:flex}
.pp-title{display:flex;align-items:center;justify-content:space-between;gap:8px;font-weight:700;font-size:13.5px;padding-bottom:8px;border-bottom:1px solid var(--line)}
.pp-title button{width:28px;height:28px;border-radius:7px;display:grid;place-items:center;color:var(--ink-3)}
.pp-title button:hover{background:var(--surface-2);color:var(--ink)}
.pp-title button svg{width:16px;height:16px}
.pp-label{font-size:11.5px;font-weight:600;color:var(--ink-3);letter-spacing:.03em;text-transform:uppercase}
.pp-input{width:100%;height:36px;padding:0 10px;border-radius:9px;border:1px solid var(--line);background:var(--surface-2);font-size:14px}
.pp-input:focus{outline:none;border-color:var(--sel);background:var(--surface)}
.pp-row{display:flex;gap:6px;flex-wrap:wrap}
.pp-row .pp-input{flex:1;min-width:0}
.pp-btn{
  flex:1;display:inline-flex;align-items:center;justify-content:center;gap:6px;
  height:34px;padding:0 10px;border-radius:9px;background:var(--surface-2);
  font-size:13px;font-weight:600;color:var(--ink);white-space:nowrap;
}
.pp-btn:hover{background:var(--surface-3)}
.pp-btn.on{box-shadow:inset 0 0 0 1.5px var(--sel)}
.pp-btn.danger{background:var(--danger-soft);color:var(--danger)}
.pp-btn.danger:hover{background:color-mix(in srgb,var(--danger) 18%,var(--surface))}
.pp-btn svg{width:16px;height:16px}
.pp-chips{display:flex;flex-wrap:wrap;gap:5px}
.pp-chips .chip{height:28px;padding:0 9px;font-size:12px}
.pp-unit{display:flex;align-items:center;gap:6px}
.pp-unit span{font-size:13px;color:var(--ink-3);flex:none}
.pp-hint{font-size:12px;color:var(--ink-3);line-height:1.4}
.pp-select{width:100%;height:36px;padding:0 8px;border-radius:9px;border:1px solid var(--line);background:var(--surface-2);font-size:14px}
.pp-seg{display:grid;grid-auto-flow:column;grid-auto-columns:1fr;gap:3px;padding:3px;border-radius:9px;background:var(--surface-2)}
.pp-seg button{height:28px;border-radius:7px;font-size:12.5px;font-weight:600;color:var(--ink-2)}
.pp-seg button.on{background:var(--surface);color:var(--ink);box-shadow:var(--shadow-1)}

/* ---------- боковые панели (спецификация, проверка) ---------- */
.ed-drawer{
  position:absolute;top:12px;right:12px;bottom:12px;z-index:45;width:300px;
  background:var(--surface);border:1px solid var(--line);border-radius:14px;
  box-shadow:var(--shadow-2);display:none;flex-direction:column;overflow:hidden;
}
.ed-drawer.open{display:flex}
.ed-drawer-head{display:flex;align-items:center;justify-content:space-between;padding:12px 14px;border-bottom:1px solid var(--line);font-weight:700;font-size:14px}
.ed-drawer-head button{width:30px;height:30px;border-radius:8px;display:grid;place-items:center;color:var(--ink-3)}
.ed-drawer-head button:hover{background:var(--surface-2);color:var(--ink)}
.ed-drawer-head button svg{width:16px;height:16px}
.ed-drawer-body{overflow:auto;padding:8px 14px 14px;font-size:13.5px}
.spec-table{width:100%;border-collapse:collapse}
.spec-table td{padding:7px 0;border-bottom:1px solid var(--line);vertical-align:top}
.spec-table td:last-child{text-align:right;font-family:var(--mono);font-size:13px;white-space:nowrap}
.spec-table tr.total td{font-weight:700;border-bottom:0}
.spec-table td.spec-group{text-align:left}
.spec-group{font-size:11px;font-weight:700;letter-spacing:.08em;text-transform:uppercase;color:var(--ink-3);padding:12px 0 4px}
.spec-empty{color:var(--ink-3);padding:12px 0}
.issue{display:flex;gap:10px;align-items:flex-start;padding:9px 10px;border-radius:9px;cursor:pointer;margin:4px 0}
.issue:hover{background:var(--surface-2)}
.issue .i-dot{width:8px;height:8px;border-radius:50%;background:var(--warn);flex:none;margin-top:6px}
.issue.info .i-dot{background:var(--sel)}
.issue b{display:block;font-weight:600}
.issue small{color:var(--ink-3)}
.issue-ok{display:flex;gap:10px;align-items:center;padding:14px 4px;color:var(--ok);font-weight:600}
.issue-ok svg{width:20px;height:20px}

/* ---------- пустое состояние ---------- */
.ed-empty{position:absolute;inset:0;z-index:30;display:flex;align-items:center;justify-content:center;pointer-events:none;padding:16px}
.ed-empty-card{
  pointer-events:auto;text-align:center;max-width:440px;padding:26px 28px;
  background:var(--surface);border:1px solid var(--line);border-radius:16px;box-shadow:var(--shadow-2);
}
.ed-empty-card h3{font-size:17px;font-weight:800;letter-spacing:-.01em;margin-bottom:8px}
.ed-empty-card p{font-size:14px;color:var(--ink-2);margin-bottom:16px}
.ed-empty-card .row{display:flex;gap:8px;justify-content:center;flex-wrap:wrap}
.ed-empty-card ol{text-align:left;margin:16px 0 0;padding-left:20px;font-size:13px;color:var(--ink-3)}
.ed-empty-card ol li{margin:3px 0}
.ed-empty-card ol b{color:var(--ink-2);font-weight:600}

/* ---------- тост ---------- */
.ed-toast{
  position:absolute;left:50%;bottom:16px;transform:translate(-50%,14px);z-index:90;
  display:flex;align-items:center;gap:12px;
  background:var(--ink);color:var(--surface);font-size:13.5px;padding:10px 14px 10px 16px;border-radius:12px;
  opacity:0;transition:.2s;pointer-events:none;box-shadow:var(--shadow-3);max-width:calc(100% - 32px);
}
.ed-toast.show{opacity:1;transform:translate(-50%,0);pointer-events:auto}
.ed-toast>span{flex:1 1 auto;min-width:0}
@media (max-width:760px){.ed-toast{width:calc(100% - 24px);justify-content:space-between}}
.ed-toast button{padding:6px 10px;border-radius:8px;background:var(--accent);color:#fff;font-weight:600;font-size:13px;white-space:nowrap}
.ed-toast button.ghost{background:rgba(255,255,255,.14)}


/* ---------- модальное окно шаблонов ---------- */
.ed-modal{position:absolute;inset:0;z-index:95;overflow:hidden;background:rgba(18,26,38,.45);display:none;align-items:center;justify-content:center;padding:16px;backdrop-filter:blur(2px)}
.ed-modal.open{display:flex}
.ed-modal-card{width:100%;max-width:860px;min-width:0;max-height:100%;overflow:auto;background:var(--surface);border-radius:16px;box-shadow:var(--shadow-3);padding:20px}
.ed-modal-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:14px}
.ed-modal-head h3{font-size:18px;font-weight:800;letter-spacing:-.01em}
.ed-modal-head p{font-size:13.5px;color:var(--ink-3);margin-top:2px}
.ed-modal-head button{width:34px;height:34px;border-radius:9px;display:grid;place-items:center;color:var(--ink-3)}
.ed-modal-head button:hover{background:var(--surface-2);color:var(--ink)}
.ed-modal-head button svg{width:18px;height:18px}
.tpl-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(min(240px,100%),1fr));gap:12px}
.tpl-card{text-align:left;border:1px solid var(--line);border-radius:12px;overflow:hidden;background:var(--surface);transition:border-color .12s,transform .12s,box-shadow .12s}
.tpl-card:hover{border-color:var(--accent);transform:translateY(-2px);box-shadow:var(--shadow-2)}
.tpl-card .tpl-prev{aspect-ratio:16/9;background:#fff;border-bottom:1px solid var(--line);display:grid;place-items:center;overflow:hidden}
.tpl-card .tpl-prev svg{width:100%;height:100%}
.tpl-card b{display:block;padding:10px 12px 2px;font-size:14px}
.tpl-card small{display:block;padding:0 12px 12px;font-size:12.5px;color:var(--ink-3)}

/* ---------- строка состояния ---------- */
.ed-status{display:flex;align-items:center;gap:12px;padding:0 12px;border-top:1px solid var(--line);font-size:12px;color:var(--ink-3);background:var(--surface)}
.ed-status .hint{flex:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ed-status .xy{font-family:var(--mono);font-size:11.5px;min-width:90px;text-align:right}
.ed-status .zoom{display:flex;align-items:center;gap:2px}
.ed-status .zoom button{width:24px;height:22px;border-radius:5px;font-size:14px;color:var(--ink-2)}
.ed-status .zoom button:hover{background:var(--surface-2)}
.ed-status .zoom span{font-family:var(--mono);font-size:11.5px;min-width:42px;text-align:center}

/* ---------- параметрический тёплый пол ---------- */
.fh-body{display:grid;grid-template-columns:minmax(0,1fr) 320px;min-height:0;min-width:0}
.fh-side{display:flex;flex-direction:column;min-height:0;border-left:1px solid var(--line);background:var(--surface);overflow:auto}
.fh-side section{padding:12px 14px;border-bottom:1px solid var(--line)}
.fh-side h4{font-size:11.5px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:var(--ink-3);margin-bottom:8px}
.fh-rooms{display:grid;gap:4px}
.fh-room{display:flex;align-items:center;gap:8px;padding:7px 8px;border-radius:9px;cursor:pointer;font-size:13.5px}
.fh-room:hover{background:var(--surface-2)}
.fh-room.on{background:var(--sel-soft)}
.fh-room .sw{width:10px;height:10px;border-radius:3px;background:var(--accent);flex:none}
.fh-room .nm{flex:1;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.fh-room .ln{font-family:var(--mono);font-size:12px;color:var(--ink-3)}
.fh-room .ln.bad{color:var(--warn);font-weight:700}
.fh-totals{display:grid;grid-template-columns:1fr 1fr;gap:8px}
.fh-kpi{padding:10px 11px;border-radius:10px;background:var(--surface-2)}
.fh-kpi b{display:block;font-size:19px;font-weight:800;letter-spacing:-.02em;font-family:var(--mono)}
.fh-kpi span{font-size:11.5px;color:var(--ink-3)}
.fh-warn{margin-top:10px;padding:9px 11px;border-radius:9px;background:var(--warn-soft);font-size:12.5px;color:var(--ink);line-height:1.4}
.fh-ok{margin-top:10px;padding:9px 11px;border-radius:9px;background:var(--ok-soft);font-size:12.5px;color:var(--ink);line-height:1.4}
.fh-form{display:grid;gap:8px}
.fh-form .pp-row{gap:6px}
.fh-form label{display:grid;gap:4px}
.fh-form .pp-label{text-transform:none;letter-spacing:0;font-size:12px}
.fh-canvas-wrap .room-body{cursor:move}
.fh-canvas-wrap .room-handle{cursor:nwse-resize}
.fh-canvas-wrap .collector{cursor:move}

/* ---------- мобильная раскладка ---------- */
@media (max-width:760px){
  .hi-editor{--ed-bar:48px}
  .ed-toolbar{padding:0 4px;gap:1px}
  .ed-sep{display:none}
  .ed-spacer{min-width:2px}
  .tb{min-width:34px;padding:0 6px}
  .tb[data-act="full"],.tb[data-act="redo"],.tb[data-act="filemenu"]>svg:last-child{display:none}
  .tb .tb-count{min-width:16px;height:16px;font-size:10px;padding:0 3px}
  .ed-menu{min-width:220px}
  .ed-body{grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr) auto}
  .ed-palette{grid-row:2;border-right:0;border-top:1px solid var(--line);max-height:160px}
  .ed-search{margin:8px 10px 4px}
  .ed-pal-list{display:flex;gap:8px;overflow-x:auto;overflow-y:hidden;padding:2px 10px 10px}
  .ed-pal-cat{display:none}
  .ed-pal-grid{display:flex;gap:8px}
  .pal-item{width:86px;flex:none}
  .ed-props{top:auto;right:8px;left:8px;bottom:8px;width:auto;max-height:52%;border-radius:14px}
  .ed-drawer{top:auto;left:8px;right:8px;bottom:8px;width:auto;max-height:60%}
  .ed-status .xy{display:none}
  .fh-body{grid-template-columns:minmax(0,1fr);grid-template-rows:minmax(0,1fr) 280px}
  .fh-side{border-left:0;border-top:1px solid var(--line);max-height:none}
}

/* название схемы в панели */
.ed-title{height:34px;flex:0 1 210px;min-width:64px;padding:0 10px;border-radius:9px;border:1px dashed var(--line-2);background:transparent;font-size:13.5px;color:var(--ink)}
.ed-group:has(>.ed-title){flex:0 1 auto;min-width:0}
.ed-title:focus{outline:none;border-style:solid;border-color:var(--sel);background:var(--surface-2)}
.ed-title::placeholder{color:var(--ink-3)}
@media (max-width:1000px){.ed-title{flex-basis:150px}}
@media (max-width:760px){.ed-title{display:none}}

/* многоугольные помещения и подложка */
.room-vertex{cursor:move}
.room-mid{cursor:copy}
.underlay{cursor:move}
.underlay.locked{cursor:default}
.fh-canvas-wrap[data-tool="draw"] .ed-canvas{cursor:crosshair}
.fh-form input[type="range"]{width:100%;accent-color:var(--accent)}
.ed-menu .ed-menu-row{display:flex;align-items:center;gap:10px;padding:8px 11px;font-size:13px;color:var(--ink-2)}
.ed-menu .ed-menu-row input[type="range"]{flex:1;accent-color:var(--accent)}
.ed-canvas-wrap.is-calib .ed-canvas{cursor:crosshair}

/* Панель переносит группы, а типы труб/кабелей занимают отдельную строку. */
.hi-editor{grid-template-rows:auto minmax(0,1fr) 30px}
.ed-toolbar{flex-wrap:wrap;gap:4px;min-height:var(--ed-bar);padding:8px}
.ed-group[data-tools]{flex-wrap:wrap;min-width:0}
.ed-chips{order:20;flex:1 0 100%;min-width:0;max-width:100%;overflow-x:auto;padding:4px 0 2px}
.ed-chips .chip{flex:none}
.ed-sep{margin:0 2px}
.ed-empty-card .row .btn{white-space:normal;text-align:center;height:auto;min-height:44px;padding:10px 16px}
@media (max-width:760px){
  .ed-toolbar{padding:6px;gap:3px}
  .ed-group{max-width:100%;flex-wrap:wrap}
  .ed-menu{min-width:min(220px,calc(100vw - 48px))}
}
