/* viz.css —— 拖拽搭建编辑器：复用物联网控制台 :root 变量与字号，只补编辑器特有布局。 */

/* 全屏模式：进入可视化时 body 加 .viz-full，整页铺满视口（无 wrap 宽度限制、无 body padding） */
body.viz-full { padding: 0; overflow: hidden; }
body.viz-full #vizView { position: fixed; inset: 0; z-index: 50; background: var(--bg); max-width: none; width: 100%; margin: 0; }
body.viz-full #mainGrid, body.viz-full #mainHeader { display: none; }
#vizView { display: none; }
#vizView.open { display: flex !important; flex-direction: column; padding: 16px 20px; }
#vizView > header { flex: none; }
#mainGrid.hidden, #mainHeader.hidden { display: none; }

/* 三栏：左组件库 220 / 中画布自适应 / 右属性 260 */
.viz-editor { display: flex; gap: 12px; align-items: stretch; flex: 1; min-height: 0; }

/* ---- 左：组件库 ---- */
.viz-lib { width: 220px; flex: none; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--sh-soft); display: flex; flex-direction: column; overflow: hidden; }
.viz-search { margin: 10px; padding: 6px 10px; font-size: 14px; }
.viz-lib-list { overflow: auto; padding: 0 10px 12px; flex: 1; }
.viz-lib-group { font-size: 12px; color: var(--sub); margin: 12px 0 6px; padding-left: 2px; }
.viz-lib-item { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 7px 10px; margin-bottom: 6px; border: 1px solid var(--line); border-radius: 8px; background: #fff; cursor: grab; user-select: none; }
.viz-lib-item:hover { border-color: var(--acc); background: var(--acc2); }
.viz-lib-item:active { cursor: grabbing; }
.viz-lib-item .ic { width: 18px; text-align: center; }
.viz-lib-item.soon { opacity: .45; cursor: not-allowed; }
.viz-lib-item.soon::after { content: "即将上线"; margin-left: auto; font-size: 11px; color: var(--sub); }

/* ---- 中：自由画布（绝对定位，无网格吸附） ---- */
.viz-stage-wrap { position: relative; flex: 1; min-width: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--sh-soft); overflow: auto; }
/* 画布被选中：高亮边框精确框住实际画布（不是可视窗口）+ 鼠标可拖动平移 */
.viz-stage.canvas-sel { outline: 2px solid var(--acc); outline-offset: -2px; box-shadow: inset 0 0 0 3px rgba(79,115,247,.15); cursor: grab; }
.viz-stage.canvas-sel.panning { cursor: grabbing; }
/* 画布：默认由 JS 设为可视区大小（刚好铺满，无滚动条）；SVG 虚线网格铺满整张画布（禁渐变，用单色 SVG） */
.viz-stage { position: relative; width: 100%; height: 100%; background-color: #fff;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Cpath d='M0 0H40M0 0V40' stroke='%23dfe7f7' stroke-width='1' stroke-dasharray='4 4' fill='none'/%3E%3C/svg%3E"); }
/* 右下角拖拽手柄：调整画布显示区域大小 */
.viz-stage-size { position: absolute; right: 12px; bottom: 12px; z-index: 5; width: 36px; height: 36px; border-radius: 8px;
  background: var(--acc2); border: 2px solid var(--acc); color: var(--acc); cursor: nwse-resize;
  display: flex; align-items: center; justify-content: center; font-size: 18px; user-select: none; }
.viz-stage-size:hover { background: var(--acc); color: #fff; }
/* 空画布提示：绝对定位在可视区正中，虚线框；有组件时隐藏 */
.viz-stage-empty { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(520px, 80%); height: 200px; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--sub); font-size: 18px; text-align: center; border: 2px dashed var(--line); border-radius: 12px; pointer-events: none; z-index: 1; }
.viz-stage-empty.hide { display: none; }

/* 画布上的组件（绝对定位，想放哪放哪，拖右下角缩放） */
.vc { position: absolute; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--sh-soft); overflow: hidden; }
.vc.hide-bg { background: transparent; border-color: transparent; box-shadow: none; }
.vc.hide-bg .vc-head { background: transparent; border-bottom-color: transparent; }
.vc.sel { border: 2px solid var(--acc); box-shadow: 0 0 0 3px rgba(79,115,247,.15); }
.vc-head { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--txt); padding: 6px 10px; border-bottom: 1px solid var(--line); background: #fbfcff; cursor: move; }
.vc-head .vc-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vc-head .vc-del { color: var(--sub); cursor: pointer; padding: 0 4px; }
.vc-head .vc-del:hover { color: var(--bad); }
.vc-body { padding: 10px 12px; height: calc(100% - 32px); overflow: auto; }
.vc-resize { position: absolute; right: 0; bottom: 0; width: 16px; height: 16px; cursor: nwse-resize; }
.vc-resize::after { content: ""; position: absolute; right: 3px; bottom: 3px; width: 8px; height: 8px; border-right: 2px solid var(--acc); border-bottom: 2px solid var(--acc); opacity: .5; }

/* 数值类 */
.vc-val { font-size: 26px; color: var(--acc); font-weight: 700; line-height: 1.2; }
.vc-val .u { font-size: 13px; color: var(--sub); font-weight: normal; margin-left: 3px; }
.vc-sub { font-size: 12px; color: var(--sub); margin-top: 4px; }
.vc-gauge { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; }
.vc-progress-bar { height: 18px; background: var(--acc2); border-radius: 9px; overflow: hidden; margin-top: 8px; }
.vc-progress-bar > i { display: block; height: 100%; background: var(--acc); border-radius: 9px; transition: width .4s; }

/* 交互类 */
.vc-ctrl button { font-size: 14px; padding: 6px 14px; margin: 3px; }
.vc-ctrl input[type=text], .vc-ctrl input[type=number] { font-size: 14px; padding: 5px 8px; }
.vc-slider { display: flex; align-items: center; gap: 8px; }
.vc-slider input[type=range] { flex: 1; min-width: 60px; accent-color: var(--acc); padding: 0; border: none; }
.vc-joystick { position: relative; width: 140px; height: 140px; border-radius: 50%; background: var(--acc2); margin: 0 auto; touch-action: none; }
.vc-joystick .knob { position: absolute; width: 34px; height: 34px; border-radius: 50%; background: var(--acc); left: 53px; top: 53px; }
.vc-palette { width: 100%; height: 60px; padding: 0; border: none; cursor: pointer; }

/* 图表容器 */
.vc-chart { width: 100%; height: 100%; }

/* ---- 右：属性面板 ---- */
.viz-props { width: 260px; flex: none; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--sh-soft); padding: 12px; overflow: auto; }
.vp-canvas { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 12px; background: #fbfcff; }
.vp-canvas-title { font-size: 14px; font-weight: 700; color: var(--acc); margin-bottom: 8px; }
.vp-canvas input[type=number], .vp-canvas input[type=text] { width: 100%; font-size: 14px; padding: 5px 8px; }
.vp-canvas input[type=color] { width: 100%; height: 32px; padding: 2px; cursor: pointer; }
.vp-canvas input[type=file] { width: 100%; font-size: 12px; }
.vp-canvas button { width: 100%; font-size: 14px; padding: 5px 8px; margin-top: 4px; cursor: pointer; }
.viz-props-empty { color: var(--sub); font-size: 14px; text-align: center; padding: 20px 10px; line-height: 1.8; }
.vp-row { margin-bottom: 10px; }
.vp-row > label { display: block; font-size: 12px; color: var(--sub); margin-bottom: 3px; }
.vp-row input, .vp-row select { width: 100%; font-size: 14px; padding: 5px 8px; }
.vp-check { display: flex; align-items: center; gap: 10px; }
.vp-check label { margin: 0; flex: none; }
.vp-check input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--acc); cursor: pointer; }
.vp-color { display: flex; align-items: center; gap: 8px; }
.vp-color label { margin: 0; flex: none; }
.vp-color input[type=color] { width: 34px; height: 28px; padding: 0; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; background: none; }
.vp-color-hex { font-size: 12px; color: var(--sub); font-family: var(--mono); }
.vp-row inline { display: flex; gap: 6px; }
.vp-help { background: #eef7f0; border-left: 3px solid var(--ok); border-radius: 0 8px 8px 0; padding: 8px 10px; margin-top: 12px; font-size: 12px; color: #37624a; line-height: 1.7; word-break: break-all; }
.vp-help b { color: #1e7a45; }
.vp-del { width: 100%; margin-top: 10px; }

@media (max-width: 1100px) {
  .viz-editor { flex-direction: column; height: auto; }
  .viz-lib, .viz-props { width: 100%; max-height: 260px; }
  .viz-stage-wrap { height: 520px; }
}
