:root {
    --bg: #f4f6f9;
    --panel: #ffffff;
    --panel-2: #f8fafc;
    --border: #d1d5db;
    --text: #1f2937;
    --text-2: #6b7280;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success: #16a34a;
    --warning: #f59e0b;
    --rail: #94a3b8;
    --rail-dark: #475569;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --radius: 8px;
}

* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    color: var(--text);
    background: var(--bg);
}

button, input, select, textarea {
    font-family: inherit;
    font-size: 14px;
}

/* ===== 全局按钮体系 ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 4px;
    padding: 7px 14px;
    background: var(--panel); color: var(--text);
    border: 1px solid var(--border); border-radius: 8px;
    cursor: pointer; font-weight: 500; white-space: nowrap;
    transition: all .15s ease;
    box-shadow: 0 1px 2px rgba(15,23,42,.05);
}
.btn:hover { border-color: #93c5fd; color: var(--primary); background: #f0f6ff; box-shadow: 0 2px 6px rgba(37,99,235,.12); }
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: linear-gradient(135deg, #1d4ed8, #3b82f6);
    border-color: transparent; color: #fff;
    box-shadow: 0 2px 8px rgba(37,99,235,.3);
}
.btn-primary:hover { background: linear-gradient(135deg, #1e40af, #2563eb); color: #fff; border-color: transparent; box-shadow: 0 4px 14px rgba(37,99,235,.4); }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: #fca5a5; color: var(--danger); background: #fef2f2; box-shadow: 0 2px 6px rgba(220,38,38,.12); }
.btn-sm { padding: 4px 10px; font-size: 12.5px; border-radius: 6px; }
.btn-link { background: transparent; border: none; box-shadow: none; color: var(--primary); padding: 4px 6px; }
.btn-link:hover { background: var(--primary-light); box-shadow: none; }

/* ===== Auth 登录/注册（大气蓝色 hero） ===== */
.auth-wrap {
    position: relative; overflow: hidden;
    min-height: 100vh;
    display: flex; flex-direction: column;
    background: linear-gradient(135deg, #071a4a 0%, #10309c 48%, #1d5de0 100%);
    color: #fff;
}
/* 电气网格背景 */
.auth-wrap::before {
    content: ''; position: absolute; inset: 0; pointer-events: none;
    background-image:
        linear-gradient(rgba(255,255,255,.055) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.055) 1px, transparent 1px);
    background-size: 44px 44px;
    -webkit-mask-image: radial-gradient(ellipse at 60% 40%, #000 25%, transparent 78%);
    mask-image: radial-gradient(ellipse at 60% 40%, #000 25%, transparent 78%);
}
/* 右上角光晕 + 左下角光晕 */
.auth-wrap::after {
    content: ''; position: absolute; pointer-events: none;
    width: 640px; height: 640px; border-radius: 50%;
    background: radial-gradient(circle, rgba(96,165,250,.32) 0%, transparent 68%);
    top: -220px; right: -160px;
}
.auth-glow-2 {
    position: absolute; pointer-events: none;
    width: 520px; height: 520px; border-radius: 50%;
    background: radial-gradient(circle, rgba(37,99,235,.4) 0%, transparent 70%);
    bottom: -240px; left: -180px;
}
.auth-main {
    flex: 1; position: relative; z-index: 1;
    display: flex; align-items: center; justify-content: center;
    gap: 84px; flex-wrap: wrap; padding: 56px 32px;
}
.auth-brand { max-width: 470px; }
.auth-logo {
    width: 76px; height: 76px; border-radius: 20px;
    display: flex; align-items: center; justify-content: center;
    font-size: 40px; margin-bottom: 26px;
    background: linear-gradient(135deg, #3b82f6, #60a5fa);
    box-shadow: 0 14px 38px rgba(59,130,246,.5), inset 0 1px 0 rgba(255,255,255,.35);
}
.auth-brand h1 { margin: 0 0 14px; font-size: 42px; font-weight: 800; letter-spacing: 2px; line-height: 1.2; }
.auth-brand h1 .ver {
    font-size: 15px; font-weight: 600; vertical-align: 14px; margin-left: 8px;
    padding: 3px 12px; border-radius: 999px;
    background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.22);
}
.auth-tagline { margin: 0 0 30px; font-size: 16.5px; line-height: 1.8; color: rgba(255,255,255,.72); }
.auth-feats { list-style: none; margin: 0; padding: 0; }
.auth-feats li { padding: 8px 0; font-size: 14.5px; color: rgba(255,255,255,.88); display: flex; align-items: center; gap: 10px; }
.auth-feats li::before {
    content: ''; flex-shrink: 0; width: 7px; height: 7px; border-radius: 50%;
    background: #60a5fa; box-shadow: 0 0 10px #60a5fa;
}
.auth-card {
    width: 404px; max-width: 94vw;
    background: rgba(255,255,255,.98);
    border-radius: 20px; padding: 40px 38px 32px;
    box-shadow: 0 28px 70px rgba(3,15,52,.5), 0 0 0 1px rgba(255,255,255,.12);
    color: var(--text);
}
.auth-card h2 { margin: 0 0 6px; font-size: 24px; text-align: center; color: var(--text); }
.auth-card .auth-sub { margin: 0 0 26px; text-align: center; color: var(--text-2); font-size: 13.5px; }
.auth-card .field { margin-bottom: 16px; }
.auth-card label { display: block; margin-bottom: 6px; color: var(--text-2); font-size: 13px; font-weight: 600; }
.auth-card input {
    width: 100%; padding: 11px 14px;
    border: 1.5px solid var(--border); border-radius: 10px;
    outline: none; transition: border-color .15s, box-shadow .15s;
    background: #f8fafc;
}
.auth-card input:focus {
    border-color: var(--primary); background: #fff;
    box-shadow: 0 0 0 4px rgba(37,99,235,.14);
}
.auth-btn {
    width: 100%; padding: 13px; margin-top: 10px;
    background: linear-gradient(135deg, #1d4ed8, #3b82f6);
    color: #fff; border: none; border-radius: 10px;
    cursor: pointer; font-weight: 700; font-size: 15px; letter-spacing: 4px;
    box-shadow: 0 8px 20px rgba(37,99,235,.35);
    transition: transform .15s, box-shadow .15s, filter .15s;
}
.auth-btn:hover { transform: translateY(-1px); box-shadow: 0 12px 26px rgba(37,99,235,.45); filter: brightness(1.06); }
.auth-btn:active { transform: translateY(0); }
.auth-links { margin-top: 18px; text-align: center; font-size: 13.5px; color: var(--text-2); }
.auth-links a { color: var(--primary); text-decoration: none; font-weight: 600; }
.auth-links a:hover { text-decoration: underline; }
.auth-footer {
    position: relative; z-index: 1; text-align: center;
    padding: 16px; font-size: 13px; color: rgba(255,255,255,.5);
}

/* Layout */
.app-header {
    height: 56px; background: var(--panel);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px; position: fixed; top: 0; left: 0; right: 0; z-index: 100;
    box-shadow: 0 1px 3px rgba(15,23,42,.06);
}
.app-header .logo {
    font-size: 18px; font-weight: 800; letter-spacing: .5px;
    background: linear-gradient(120deg, #1d4ed8, #3b82f6);
    -webkit-background-clip: text; background-clip: text; color: transparent;
    display: flex; align-items: center; gap: 9px;
}
.app-header .logo .site-logo { height: 30px; width: auto; max-width: 180px; object-fit: contain; -webkit-text-fill-color: initial; }
.app-header .logo .logo-emoji { -webkit-text-fill-color: initial; }
.app-header .nav a {
    margin-left: 8px; padding: 6px 14px; border-radius: 8px;
    color: var(--text-2); text-decoration: none; font-weight: 500;
    transition: all .15s ease;
}
.app-header .nav a:hover { color: var(--primary); background: var(--primary-light); }
.app-header .nav a.active { color: var(--primary); font-weight: 700; background: var(--primary-light); }
.app-header .user { color: var(--text-2); font-size: 13px; }

.app-body {
    padding-top: 56px; height: 100vh; display: flex;
}

/* Editor */
.editor-shell {
    display: flex; flex-direction: column; width: 100%; height: calc(100vh - 56px);
    position: relative; /* 文件库下拉面板的定位基准 */
}
.editor-toolbar {
    flex: 0 0 48px; width: 100%;
    background: var(--panel); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 8px; padding: 6px 12px;
    flex-wrap: nowrap; overflow-x: auto; white-space: nowrap;
    position: sticky; top: 0; z-index: 30;
    scrollbar-width: thin;
}
.editor-toolbar::-webkit-scrollbar { height: 4px; background: transparent; }
.editor-toolbar .btn, .editor-toolbar input, .editor-toolbar span, .editor-toolbar select { flex-shrink: 0; }
/* v38 工具栏分组：功能按钮成组 + 竖分隔线，简洁大气 */
.tb-group { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.tb-sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; flex-shrink: 0; border-radius: 1px; }
.editor-toolbar .btn { padding: 7px 12px; }
.editor-toolbar .btn-icon { padding: 7px 10px; font-size: 15px; }
#btn-draw-line.active { background: var(--primary-light); border-color: #93c5fd; color: var(--primary); box-shadow: inset 0 1px 3px rgba(37,99,235,.15); }
/* v38 导出下拉菜单 */
.tb-dropdown { position: relative; flex-shrink: 0; }
.tb-dropdown .tb-caret { font-size: 10px; opacity: .7; margin-left: 2px; transition: transform .15s; }
.tb-dropdown.open .tb-caret { transform: rotate(180deg); }
.tb-dropdown.open > .btn { border-color: #93c5fd; color: var(--primary); background: #f0f6ff; }
.tb-menu {
    position: absolute; top: calc(100% + 6px); left: 0; z-index: 80;
    min-width: 250px; padding: 6px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
    box-shadow: 0 16px 40px -8px rgba(15,23,42,.25);
    display: none; flex-direction: column;
}
.tb-dropdown.open .tb-menu { display: flex; animation: tbMenuIn .14s ease; }
/* 菜单展开时放开工具栏裁剪（overflow:auto 会裁掉超出工具栏高度的下拉面板） */
.editor-toolbar:has(.tb-dropdown.open) { overflow-x: visible; overflow: visible; }
@keyframes tbMenuIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.tb-menu-item {
    display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
    padding: 9px 12px; border: none; background: transparent; border-radius: 8px;
    cursor: pointer; text-align: left; width: 100%;
    font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap;
    transition: background .12s, color .12s;
}
.tb-menu-item:hover { background: var(--primary-light); color: var(--primary); }
.tb-menu-tip { font-size: 11.5px; font-weight: 400; color: var(--text-2); }
.tb-menu-sep { height: 1px; background: var(--border); margin: 5px 8px; }
/* ===== v39 对齐辅助线 + 选中测量 ===== */
.align-guide { position: absolute; background: #ff2d55; pointer-events: none; z-index: 45; box-shadow: 0 0 4px rgba(255,45,85,.6); }
.align-guide.v { top: 0; height: 100%; width: 1px; transform: translateX(-.5px); }
.align-guide.h { left: 0; width: 100%; height: 1px; transform: translateY(-.5px); }
.measure-badge {
    position: absolute; transform: translate(-50%, -50%);
    background: #e60012; color: #fff;
    font-size: 11px; font-weight: 700; line-height: 1;
    padding: 3px 5px; border-radius: 3px;
    pointer-events: none; z-index: 46; white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.measure-line { position: absolute; background: #e60012; opacity: .85; pointer-events: none; z-index: 44; }
/* v40 线段/多边形边长与夹角徽标：与红色距离徽标区分 */
.measure-badge.edge { background: #1d4ed8; box-shadow: 0 1px 3px rgba(29,78,216,.45); }
.measure-badge.ang { background: #0d9488; box-shadow: 0 1px 3px rgba(13,148,136,.45); }
.toolbar-select {
    padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
    background: #fff; color: var(--text); outline: none; cursor: pointer;
}
.toolbar-right {
    margin-left: auto; display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.toolbar-right #project-name { width: 180px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; }
.toolbar-right #box-width, .toolbar-right #box-height { width: 70px; padding: 6px; border: 1px solid var(--border); border-radius: 6px; }
.toolbar-right #scale { width: 60px; padding: 6px; border: 1px solid var(--border); border-radius: 6px; }
.toolbar-right .board-size {
    padding: 6px 10px; background: var(--panel-2); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text-2); font-size: 12px; white-space: nowrap;
}
.editor-content {
    display: flex; flex: 1; min-height: 0;
}

/* 设计文件库下拉面板 */
.file-library {
    position: absolute; top: 48px; left: 12px; z-index: 60;
    width: 380px; max-height: 70vh;
    background: var(--panel); border: 1px solid var(--border);
    border-radius: 0 0 var(--radius) var(--radius);
    box-shadow: 0 12px 24px -6px rgba(0,0,0,0.3);
    display: none; flex-direction: column; overflow: hidden;
}
.file-library.open { display: flex; }
.file-library .fl-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 12px; background: var(--panel-2);
    border-bottom: 1px solid var(--border); font-weight: 700;
}
.file-library .fl-list { overflow-y: auto; padding: 6px; }
.file-library .file-item {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 10px; border-radius: 6px; cursor: pointer; transition: .12s;
}
.file-library .file-item:hover { background: var(--primary-light); }
.file-library .file-item.current { background: var(--primary-light); }
.file-library .file-item.current .fi-name { color: var(--primary); font-weight: 700; }
.file-library .fi-info { flex: 1; min-width: 0; }
.file-library .fi-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-library .fi-meta { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.file-library .fi-actions { display: flex; gap: 6px; flex-shrink: 0; }
.file-library .fl-empty { padding: 24px; text-align: center; color: var(--text-2); }
.editor-sidebar {
    width: 300px; background: var(--panel); border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    overflow: hidden; transition: width .2s ease;
    position: relative; flex-shrink: 0;
}
.editor-sidebar.collapsed { width: 32px; border-right: 1px solid var(--border); }
.editor-sidebar.collapsed .sidebar-content { display: none; }
.editor-sidebar .collapsed-hint {
    display: none; width: 32px; height: 100%;
    writing-mode: vertical-rl; text-orientation: mixed;
    align-items: center; justify-content: center;
    color: var(--text-2); font-size: 12px; letter-spacing: 2px;
    cursor: pointer; background: var(--panel-2);
}
.editor-sidebar.collapsed .collapsed-hint { display: flex; }
/* 侧栏内容：纵向 flex 且高度受限，保证元器件列表区可滚动 */
.editor-sidebar .sidebar-content {
    flex: 1; min-height: 0;
    display: flex; flex-direction: column;
    overflow: hidden;
}
.editor-sidebar .section-title {
    padding: 12px 16px; font-weight: 700; border-bottom: 1px solid var(--border);
    background: var(--panel-2); white-space: nowrap;
}
.editor-search {
    padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.editor-search input {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius);
    outline: none;
}
.editor-search input:focus { border-color: var(--primary); }
.editor-cats {
    display: flex; gap: 6px; padding: 10px 16px; border-bottom: 1px solid var(--border);
    overflow-x: auto;
}
.editor-cats button {
    padding: 6px 12px; border: 1px solid var(--border); background: #fff; border-radius: 999px;
    white-space: nowrap; cursor: pointer;
}
.editor-cats button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.component-list {
    flex: 1; overflow-y: auto; padding: 8px;
    min-height: 0; /* 保证 flex 子项能正确收缩出滚动条 */
}
.component-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px; border: 1px solid var(--border); border-radius: var(--radius);
    margin-bottom: 8px; background: #fff; cursor: pointer; transition: .15s;
}
.component-item:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.component-item .thumb {
    width: 40px; height: 40px; display: flex; align-items: center; justify-content: center;
    background: var(--panel-2); border-radius: 4px; overflow: hidden;
}
.component-item .thumb svg { width: 100%; height: 100%; }
.component-item .thumb img { width: 100%; height: 100%; object-fit: contain; }
.component-item .info { flex: 1; min-width: 0; }
.component-item .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.component-item .meta { font-size: 12px; color: var(--text-2); }

.editor-main {
    flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative;
}
.panel-toggle {
    position: absolute; top: 32px; width: 18px; height: 48px;
    background: var(--panel); border: 1px solid var(--border); border-radius: 4px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; z-index: 50; font-size: 12px; color: var(--text-2);
    box-shadow: var(--shadow);
}
.panel-toggle:hover { color: var(--primary); border-color: var(--primary); background: var(--primary-light); }
.panel-toggle.left { left: 8px; }
.panel-toggle.right { right: 8px; }
.panel-toggle.pinned { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }

/* Fireworks 风格工作区 */
.editor-canvas-area {
    flex: 1; overflow: auto; background: #cbd5e1;
    position: relative;
    padding: 20px 20px 20px 20px;
    /* 左上角定位，滚动条从画布原点开始；内容由 JS 滚动居中 */
}
#canvas {
    background: #ffffff; position: relative;
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.25);
    overflow: visible;
    transform-origin: top left;
    transition: transform .1s ease, background .15s ease;
}
/* v29 深色背景模式（#263535，默认） */
#canvas.bg-dark { background: #263535; }
/* 网格背景模式 */
#canvas.bg-grid {
    background-image:
        linear-gradient(45deg, #f1f5f9 25%, transparent 25%),
        linear-gradient(-45deg, #f1f5f9 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, #f1f5f9 75%),
        linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}
/* 透明背景模式：露出灰色工作区 */
#canvas.bg-transparent {
    background: transparent;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.12);
}

/* 标尺 */
.ruler {
    position: absolute; background: #f8fafc; border: 1px solid #94a3b8;
    color: #64748b; font-size: 10px; z-index: 25; user-select: none;
    overflow: hidden;
}
.ruler.h {
    top: 0; left: 20px; right: 20px; height: 20px;
    background-image: repeating-linear-gradient(90deg, #94a3b8 0, #94a3b8 1px, transparent 1px, transparent 10px);
    border-bottom: 1px solid #94a3b8;
}
.ruler.v {
    top: 20px; left: 0; bottom: 20px; width: 20px;
    background-image: repeating-linear-gradient(0deg, #94a3b8 0, #94a3b8 1px, transparent 1px, transparent 10px);
    border-right: 1px solid #94a3b8;
}
.ruler.h .tick-label { position: absolute; top: 4px; transform: translateX(-50%); }
.ruler.v .tick-label { position: absolute; left: 4px; transform: translateY(-50%) rotate(-90deg); transform-origin: left center; }

/* 状态栏 */
.status-bar {
    flex: 0 0 26px; background: #f1f5f9; border-top: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 12px; font-size: 12px; color: var(--text-2); z-index: 30;
}
.status-bar .coords { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.status-bar .hint { color: #94a3b8; }
/* v28 DIN 导轨：使用素材 SVG 无限平铺延长，高度 35px，y 锚点为导轨中心线 */
.din-rail {
    position: absolute; left: 0; right: 0; height: 35px;
    background: url('../img/din-rail.svg') repeat-x left center;
    background-size: 570px 35px;
}
.canvas-element {
    position: absolute; cursor: grab; user-select: none;
    display: flex; flex-direction: column; align-items: center;
}
.canvas-element:active { cursor: grabbing; }
.canvas-element.selected {
    outline: 2px solid var(--primary); outline-offset: 2px;
}
.canvas-element.locked { cursor: default; }
.canvas-element.locked .lock-badge {
    position: absolute; top: -10px; left: -10px; width: 20px; height: 20px;
    background: var(--warning); color: #fff; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; box-shadow: var(--shadow); z-index: 5;
    pointer-events: auto; cursor: pointer;
}
.canvas-element.locked {
    pointer-events: none;
}
/* 锁定元件内部仅锁图标可点击，用于选中后解锁 */
.canvas-element.locked .lock-badge {
    pointer-events: auto;
}
.canvas-element .el-svg {
    width: 100%; height: 100%; pointer-events: none;
}

/* 相线 / 空开规格标签条（元件上方，宽度随元件宽度）—— v27 背景透明、v28 文字恢复白色 */
.canvas-element .el-phase-strip {
    position: absolute; top: -30px; left: 0; width: 100%; height: 30px;
    background: transparent; color: #fff;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    font-size: 10px; line-height: 1; overflow: hidden;
    pointer-events: none;
}
.canvas-element .el-phase-strip .phase-letters { display: flex; gap: 2px; font-weight: 700; font-size: 16px; line-height: 1; }
.canvas-element .el-phase-strip .phase-letters .l-A { color: #facc15; }
.canvas-element .el-phase-strip .phase-letters .l-B { color: #4ade80; }
.canvas-element .el-phase-strip .phase-letters .l-C { color: #f87171; }
.canvas-element .el-phase-strip .breaker-rating { color: #fff; font-size: 10px; line-height: 1; margin-top: 2px; }

/* 设备标签（元件下方，宽度随元件宽度，高度固定 40px）—— v28 边框 #263535、无圆角 */
.canvas-element .el-label {
    position: absolute; bottom: -40px; left: 0; width: 100%; height: 40px;
    background: #facc15; color: #111827; border: 1px solid #263535; border-top: none;
    border-radius: 0;
    display: flex; align-items: center; justify-content: center;
    padding: 3px 4px; font-size: 12px; font-weight: 600; line-height: 1.2;
    text-align: center; word-break: break-word; white-space: pre-line;
    pointer-events: none;
}
.canvas-element .el-label.vertical {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    white-space: pre-line;
    line-height: 1.4;
}
.canvas-element .el-label:empty::before {
    content: attr(data-placeholder);
    color: #9ca3af;
}


.editor-rightbar {
    width: 320px; background: var(--panel); border-left: 1px solid var(--border);
    display: flex; flex-direction: column; overflow-y: auto;
    overflow-x: hidden; transition: width .2s ease;
    position: relative; flex-shrink: 0;
}
.editor-rightbar.collapsed { width: 32px; border-left: 1px solid var(--border); }
.editor-rightbar.collapsed .sidebar-content { display: none; }
.editor-rightbar .collapsed-hint {
    display: none; width: 32px; height: 100%;
    writing-mode: vertical-rl; text-orientation: mixed;
    align-items: center; justify-content: center;
    color: var(--text-2); font-size: 12px; letter-spacing: 2px;
    cursor: pointer; background: var(--panel-2);
}
.editor-rightbar.collapsed .collapsed-hint { display: flex; }
.right-panel { padding: 16px; border-bottom: 1px solid var(--border); }
.right-panel h3 { margin: 0 0 12px; font-size: 15px; }
.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 5px; color: var(--text-2); font-size: 13px; }
.field input, .field select {
    width: 100%; padding: 8px 10px; border: 1.5px solid var(--border); border-radius: var(--radius);
    outline: none; transition: border-color .15s, box-shadow .15s;
    background: var(--panel);
}
.field input:focus, .field select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.13);
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.load-summary {
    background: var(--panel-2); border-radius: var(--radius); padding: 12px;
}
.load-summary .row {
    display: flex; justify-content: space-between; margin-bottom: 8px;
}
.load-summary .row.total { font-weight: 700; color: var(--primary); }

/* Admin */
.admin-wrap { padding: 76px 20px 20px; max-width: 1200px; margin: 0 auto; }
.admin-card {
    background: var(--panel); border-radius: 14px; border: 1px solid var(--border);
    margin-bottom: 20px; overflow: hidden;
    box-shadow: 0 1px 3px rgba(15,23,42,.05), 0 8px 24px -18px rgba(15,23,42,.18);
}
.admin-card h3 {
    margin: 0; padding: 16px 20px; font-size: 15px;
    background: var(--panel); border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 8px;
}
.admin-card h3::before {
    content: ''; width: 4px; height: 16px; border-radius: 2px;
    background: linear-gradient(180deg, #3b82f6, #1d4ed8);
}
.admin-card .body { padding: 20px; }
.admin-tabs {
    display: flex; gap: 4px;
    background: #e8eef8; border-radius: 12px; padding: 5px;
    margin-bottom: 18px; width: fit-content; max-width: 100%; overflow-x: auto;
}
.admin-tabs button {
    padding: 9px 22px; background: transparent; border: none; border-radius: 8px;
    cursor: pointer; font-weight: 600; color: var(--text-2); white-space: nowrap;
    transition: all .15s ease;
}
.admin-tabs button:hover { color: var(--primary); }
.admin-tabs button.active {
    color: var(--primary); background: var(--panel);
    box-shadow: 0 2px 8px rgba(15,23,42,.12);
}

/* 自定义属性编辑 */
.custom-attrs {
    border: 1px solid var(--border); border-radius: var(--radius);
    padding: 8px; background: var(--panel-2); margin-bottom: 8px;
    max-height: 240px; overflow-y: auto;
}
.custom-attr-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.custom-attr-row input[type="text"] {
    flex: 1; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
    outline: none; min-width: 80px;
}
.custom-attr-row input[type="text"]:focus { border-color: var(--primary); }
.custom-attr-row input[type="text"][readonly] {
    background: #f3f4f6; color: var(--text-2); cursor: default;
}
.custom-attr-row .attr-del {
    width: 28px; height: 28px; border: none; background: transparent;
    color: var(--danger); cursor: pointer; font-size: 16px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
}
.custom-attr-row .attr-del:hover { background: #fee2e2; border-radius: 6px; }
.attr-tip { font-size: 12px; color: var(--text-2); margin-top: 6px; }

.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th {
    background: linear-gradient(180deg, #f0f6ff, #e8f0fe);
    font-weight: 700; color: #1e40af; font-size: 13px; white-space: nowrap;
}
.data-table tbody tr { transition: background .12s ease; }
.data-table tbody tr:hover { background: #f4f8ff; }
.data-table .thumb { width: 40px; height: 40px; background: var(--panel-2); border-radius: 6px; overflow: hidden; }
.data-table .thumb img { width: 100%; height: 100%; object-fit: contain; }

/* Toast */
#toast {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    padding: 12px 24px; border-radius: var(--radius); color: #fff; font-weight: 500;
    box-shadow: var(--shadow); z-index: 9999; display: none;
}
#toast.success { background: var(--success); }
#toast.error { background: var(--danger); }
#toast.info { background: var(--primary); }

/* 画板右键菜单 */
#ctx-menu {
    position: fixed; display: none; z-index: 500;
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: 0 10px 20px -5px rgba(0,0,0,0.25); padding: 4px; min-width: 170px;
}
#ctx-menu .ctx-item {
    display: flex; align-items: center; justify-content: space-between; gap: 16px;
    padding: 8px 12px; border-radius: 6px; cursor: pointer; font-size: 13px; white-space: nowrap;
}
#ctx-menu .ctx-item:hover { background: var(--primary-light); color: var(--primary); }
#ctx-menu .ctx-item .ctx-key { color: var(--text-2); font-size: 12px; }
#ctx-menu .ctx-item:hover .ctx-key { color: var(--primary); }
#ctx-menu .ctx-item.disabled { color: #cbd5e1; cursor: default; }
#ctx-menu .ctx-item.disabled:hover { background: transparent; color: #cbd5e1; }
#ctx-menu .ctx-sep { height: 1px; background: var(--border); margin: 4px 6px; }

/* Modal */
.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    display: none; align-items: center; justify-content: center; z-index: 200;
}
.modal-backdrop.active { display: flex; }
.modal-card {
    background: #fff; border-radius: var(--radius); width: 90%; max-width: 560px;
    max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0; padding: 16px; border-bottom: 1px solid var(--border); }
.modal-card .body { padding: 16px; }
.modal-card .footer { padding: 12px 16px; border-top: 1px solid var(--border); text-align: right; }
.modal-card .footer button { margin-left: 8px; }

/* Labels print */
@media screen {
    .print-only { display: none; }
}
@media print {
    body * { visibility: hidden; }
    .print-only, .print-only * { visibility: visible; }
    .print-only {
        position: absolute; left: 0; top: 0; width: 100%;
    }
    .no-print { display: none !important; }
}
.label-sheet {
    display: flex; flex-wrap: wrap; gap: 0; padding: 0;
}
.label-card {
    width: 4cm; height: 4cm; border: 1px solid #000; padding: 4mm;
    display: flex; flex-direction: column; justify-content: center;
    font-size: 10pt; line-height: 1.4; page-break-inside: avoid;
}
.label-card .l-model { font-weight: 700; font-size: 12pt; }
.label-card .l-name { color: #333; }
.label-card .l-spec { font-size: 9pt; color: #555; }

/* Misc */
.empty-state { text-align: center; padding: 40px; color: var(--text-2); }
.badge {
    display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px;
    background: var(--primary-light); color: var(--primary);
}

/* 框选 */
.selection-rect {
    position: absolute; z-index: 100; pointer-events: none;
    border: 1px dashed var(--primary);
    background: rgba(37, 99, 235, 0.12);
}
.multi-selection-box {
    position: absolute; z-index: 20; pointer-events: none;
    border: 1px solid var(--primary);
    background: rgba(37, 99, 235, 0.04);
}

/* 编组：虚线描边 + 角标 */
.canvas-element.grouped {
    outline: 1px dashed #f59e0b; outline-offset: 3px;
}
.canvas-element.grouped.selected {
    outline: 2px solid var(--primary); outline-offset: 3px;
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.25);
}
.canvas-element .group-badge {
    position: absolute; top: -10px; right: -10px; max-width: 80px;
    background: #f59e0b; color: #fff; border-radius: 10px;
    padding: 2px 6px; font-size: 11px; font-weight: 600;
    box-shadow: var(--shadow); z-index: 6; pointer-events: none;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* 多选属性面板 */
.multi-label-list {
    max-height: 140px; overflow-y: auto;
    background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px;
    padding: 6px 8px; font-size: 12px;
}
.multi-label-list .ml-item {
    padding: 3px 0; border-bottom: 1px solid #e5e7eb;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.multi-label-list .ml-item:last-child { border-bottom: none; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 0; }

/* 线段 */
.canvas-line {
    position: absolute; cursor: grab; user-select: none; z-index: 5;
    /* 仅线身命中区(.line-hit)可交互，包围盒不遮挡下方元素 */
    pointer-events: none;
}
.canvas-line:active { cursor: grabbing; }
/* 框线/画线不显示外框选中色，仅通过圆点拐点手柄提示选中，避免视觉干扰与拖动时尺寸误判 */
.canvas-line.selected { outline: none; }
.canvas-line svg { overflow: visible; }
.canvas-line .line-hit {
    fill: none; stroke: transparent; stroke-width: 12;
    pointer-events: all; cursor: grab;
}

/* 文字标注 */
.canvas-annotation {
    position: absolute; cursor: grab; user-select: none;
    display: flex; align-items: center; justify-content: center;
    padding: 4px 8px; border-radius: 4px;
    font-size: 14px; font-weight: 600; line-height: 1.3;
    text-align: center; white-space: pre-line; word-break: break-word;
    overflow: hidden;
}
.canvas-annotation.boxed {
    border: 1px solid rgba(0,0,0,0.15); box-shadow: 0 2px 4px rgba(0,0,0,0.08);
}
.canvas-annotation:active { cursor: grabbing; }
.canvas-annotation.selected {
    outline: 2px solid var(--primary); outline-offset: 2px;
}
/* 标注缩放手柄（右下角，仅单选时显示） */
.anno-resize-handle {
    position: absolute; width: 10px; height: 10px;
    right: -5px; bottom: -5px;
    background: #fff; border: 2px solid var(--primary);
    border-radius: 50%; cursor: se-resize; z-index: 20;
    box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.anno-resize-handle:hover { background: var(--primary); }

/* 标签打印预览 */
.label-modal-card { max-width: 900px; }
.label-toolbar {
    display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
    padding-bottom: 12px; border-bottom: 1px solid var(--border); margin-bottom: 12px;
}
.label-toolbar input[type="range"] { width: 140px; vertical-align: middle; }
.label-toolbar .label-tip { color: var(--text-2); font-size: 12px; }
/* v27 标签打印预览：无独立方框，标签间实线分隔，两头实线闭合；宽度=元器件宽度(1px=1mm)，高度可调 */
.label-preview-sheet {
    display: flex; flex-wrap: wrap; gap: 0;
    max-height: 60vh; overflow-y: auto; padding: 0;
    border-left: 1px solid #000; border-right: 1px solid #000;
    background: #fff;
}
.label-preview-card {
    height: 40mm; border: none; border-radius: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 2mm; box-sizing: border-box; position: relative;
    background: #facc15; color: #000;
}
.label-preview-card + .label-preview-card { border-left: 1px solid #000; }
.label-preview-card .lp-text {
    width: 100%; flex: 1; display: flex; align-items: center; justify-content: center;
    text-align: center; word-break: break-word; line-height: 1.2;
    overflow: hidden; white-space: pre-line; color: #000;
}
.label-preview-card.vertical .lp-text {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    line-height: 1.4;
}
.label-preview-card .lp-size-row {
    display: flex; align-items: center; gap: 6px; margin-top: 4px;
}
.label-preview-card .lp-size-row input { width: 80px; }
.label-preview-card .lp-font-val { font-size: 11px; color: var(--text-2); white-space: nowrap; }

/* ===== v13: 线段端点手柄 + 画线模式 + 颜色选择器 ===== */
.line-handle {
    position: absolute;
    width: 18px; height: 18px;
    background: transparent;
    border-radius: 50%;
    cursor: move;
    z-index: 20;
    margin-left: -4px; margin-top: -4px;
}
.line-handle::after {
    content: '';
    position: absolute;
    left: 4px; top: 4px;
    width: 10px; height: 10px;
    background: #fff;
    border: 2px solid var(--primary, #2563eb);
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.line-handle:hover::after { background: var(--primary, #2563eb); }

#canvas.draw-mode, #canvas.draw-mode * { cursor: crosshair !important; }
.draw-preview { position: absolute; pointer-events: none; z-index: 30; }
.draw-preview svg { overflow: visible; }
/* 画线模式十字辅助线：从鼠标位置分别连到顶部/左侧标尺 */
.draw-crosshair { position: absolute; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 26; display: none; }
.draw-crosshair .crosshair-h,
.draw-crosshair .crosshair-v { position: absolute; background: #ef4444; opacity: 0.75; box-shadow: 0 0 0 1px rgba(255,255,255,0.6); }
.draw-crosshair .crosshair-h { height: 1px; left: 20px; }
.draw-crosshair .crosshair-v { width: 1px; top: 20px; }
.ruler-cursor { position: absolute; background: #ef4444; z-index: 27; display: none; }
.ruler-h .ruler-cursor { top: 0; width: 1px; height: 100%; }
.ruler-v .ruler-cursor { left: 0; height: 1px; width: 100%; }
#btn-draw-line.active {
    background: var(--primary, #2563eb);
    color: #fff;
    border-color: var(--primary, #2563eb);
}

/* 颜色选择器弹窗 */
.color-picker-pop {
    position: fixed;
    z-index: 1000;
    top: 120px;
    left: 50%;
    transform: translateX(-50%);
    width: 232px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,.2);
}
.color-picker-pop .cp-title { font-size: 13px; font-weight: 600; color: #1f2937; margin-bottom: 8px; }
.color-picker-pop .cp-current { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.color-picker-pop .cp-current-dot {
    width: 16px; height: 16px; border-radius: 4px;
    border: 1px solid rgba(0,0,0,.15);
}
.color-picker-pop .cp-current-label { font-size: 12px; color: #6b7280; font-family: monospace; }
.cp-swatches { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.cp-swatch {
    width: 22px; height: 22px;
    border-radius: 5px;
    border: 1px solid rgba(0,0,0,.15);
    cursor: pointer;
    padding: 0;
}
.cp-swatch:hover { transform: scale(1.15); }
.cp-row { display: flex; gap: 6px; align-items: center; margin-bottom: 10px; }
.cp-row input[type="color"] {
    width: 42px; height: 30px;
    padding: 2px;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    background: #fff;
    cursor: pointer;
}
.cp-row input[type="text"] {
    flex: 1;
    padding: 5px 7px;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    font-size: 12px;
    font-family: monospace;
}
.cp-actions { display: flex; gap: 6px; justify-content: flex-end; }
.cp-actions .btn-primary {
    background: var(--primary, #2563eb);
    color: #fff;
    border-color: var(--primary, #2563eb);
}

/* 属性面板原生取色器 */
.field input[type="color"] {
    width: 100%;
    height: 30px;
    padding: 2px;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    background: #fff;
    cursor: pointer;
}
.hint-box {
    font-size: 12px;
    color: #6b7280;
    background: #f3f4f6;
    border: 1px dashed #d1d5db;
    border-radius: 6px;
    padding: 6px 8px;
    line-height: 1.5;
}

/* ===== v14: PNG 导出弹窗 + 文件库入口 ===== */
.png-modal-card { width: 640px; max-width: 94vw; }
.png-form { display: flex; flex-direction: column; gap: 10px; }
.png-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.png-label { font-size: 13px; color: #6b7280; min-width: 62px; }
.png-opt { font-size: 13px; color: #111827; display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.png-opt input { cursor: pointer; }
.png-hint { color: #9ca3af; font-size: 12px; }
#png-custom-w {
    padding: 5px 8px; border: 1px solid #d1d5db; border-radius: 5px;
    width: 100px; font-size: 13px;
}
.png-preview-wrap { margin-top: 12px; }
.png-preview-meta { font-size: 12.5px; color: #2563eb; margin-bottom: 6px; }
.png-preview-box {
    border: 1px solid #e5e7eb; border-radius: 8px; padding: 8px;
    background: repeating-conic-gradient(#f3f4f6 0% 25%, #fff 0% 50%) 50%/16px 16px;
    max-height: 340px; overflow: auto;
}
.png-preview-box img { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.fl-more {
    padding: 10px 14px; text-align: center; font-size: 13px; color: #2563eb;
    cursor: pointer; border-top: 1px dashed #e5e7eb; background: #f8fafc;
}
.fl-more:hover { background: #eff6ff; }

/* ===== 密码显示/隐藏切换（小眼睛） ===== */
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 40px; }
.pw-eye {
    position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
    width: 28px; height: 28px; border: none; background: transparent;
    border-radius: 6px; cursor: pointer; display: flex; align-items: center; justify-content: center;
    color: #94a3b8; transition: color .15s, background .15s; padding: 0;
}
.pw-eye:hover { color: var(--primary); background: rgba(37,99,235,.08); }
.pw-eye svg { width: 18px; height: 18px; display: block; }

/* ===== v24：品牌筛选 + 子分类 chips ===== */
.editor-brandbar { padding: 8px 16px 0; }
.editor-brandbar select {
    width: 100%; padding: 6px 8px; border: 1.5px solid var(--border); border-radius: var(--radius);
    background: #fff; outline: none; font-size: 13px; color: var(--text, #1e293b); cursor: pointer;
}
.editor-brandbar select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.13); }
.editor-cats.sub { padding-top: 6px; border-bottom: none; }
.editor-cats.sub button { padding: 3px 10px; font-size: 12px; background: var(--panel-2, #f1f5f9); }
.editor-cats.sub button.active { background: var(--primary); color: #fff; }

/* ===== v30 尺寸标注覆盖层（CAD 风格 宽/高/厚 标注） ===== */
.dim-overlay {
    position: absolute;
    pointer-events: none;
    overflow: visible;
    z-index: 40;
}
/* 属性面板尺寸标注行 */
.dim-rows { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.dim-row { display: flex; align-items: center; gap: 6px; }
.dim-row > label {
    display: flex; align-items: center; gap: 4px;
    width: 44px; flex: none; margin: 0;
    font-size: 12.5px; font-weight: 500; color: var(--text, #1f2937);
}
.dim-row input[type="text"] {
    flex: 1; min-width: 0;
    padding: 6px 8px; font-size: 12.5px;
    border: 1px solid var(--border, #d1d5db); border-radius: var(--radius, 6px);
    background: #fff; color: inherit;
}
.dim-row input[type="text"]:focus { outline: none; border-color: var(--primary, #2563eb); }
