/* ============================================
   CAD风格电气系统图编辑器 - 完整样式表
   ============================================ */

/* === 基础重置 === */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Arial', 'Microsoft YaHei', sans-serif;
    line-height: 1.6;
    color: #333;
    background-color: #E8E8E8;
    overflow: hidden;
    height: 100vh;
    display: flex;          /* 新增：启用 Flex 布局 */
    flex-direction: column; /* 新增：设置为垂直排列 */
}

/* === 主容器布局 === */
.cad-container {
    display: flex;
    flex-direction: row;
    /*height: calc(100vh - 60px);
    /*margin-top: 60px;
    overflow: hidden;
    flex: 1; /* 新增：自动填充剩余空间 */
}

/* === 左侧设备工具条 === */
.device-toolbar {
    width: 52px;
    min-width: 52px;
    background: #2B2B3D;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 8px 0;
    gap: 2px;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 100;
    border-right: 1px solid #3a3a4e;
}

.device-toolbar::-webkit-scrollbar {
    width: 3px;
}
.device-toolbar::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.15);
    border-radius: 2px;
}

.toolbar-icon-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    position: relative;
    flex-shrink: 0;
}

.toolbar-icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
}

.toolbar-icon-btn.active {
    background: #1976D2;
    border-color: #4285f4;
}

.toolbar-icon-btn:active {
    background: rgba(255, 255, 255, 0.15);
}

.toolbar-icon-btn.selected-device-tool {
    background: #FF9800;
    border-color: #FFB74D;
    box-shadow: 0 0 8px rgba(255, 152, 0, 0.5);
}

icon-label {
    font-size: 11px;
    font-weight: 600;
    color: #4285f4;
    text-align: center;
    line-height: 1;
    letter-spacing: 0.5px;
}

.toolbar-divider {
    width: 30px;
    height: 1px;
    background: rgba(255, 255, 255, 0.15);
    margin: 6px 0;
    flex-shrink: 0;
}

/* === 中间主内容区 === */
.cad-main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    min-width: 0;
}

/* === 可拖动浮动工具栏 === */
.floating-toolbar {
    display: flex;
    flex-direction: row; /* 修改：从 column 改为 row，让内部元素横向排列 */
    align-items: center; /* 新增：使拖动把手、按钮等垂直居中对齐 */
    z-index: 800;
    transition: none;
}

/* 停靠状态 */
.floating-toolbar[data-dock="top"] {
    position: relative;
    flex-shrink: 0;
}
.floating-toolbar[data-dock="top"] .toolbar-drag-handle {
    border-radius: 0;
}
.floating-toolbar[data-dock="top"] .toolbar-body {
    justify-content: center;
}

.floating-toolbar[data-dock="bottom"] {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
}
.floating-toolbar[data-dock="bottom"] .toolbar-body {
    justify-content: center;
}

.floating-toolbar[data-dock="left"] {
    position: absolute;
    left: 52px; /* 左侧排列时避开设备工具栏 */
    top: 60px; /* 左侧排列时避开横眉 */
    bottom: 0;
    width: 48px;
    flex-direction: column; /* 新增：恢复垂直排列 */
}
.floating-toolbar[data-dock="left"] .toolbar-drag-handle {
    height: 24px;
    writing-mode: initial;
}
.floating-toolbar[data-dock="left"] .toolbar-body {
    flex-direction: column;
    align-items: center;
}
.floating-toolbar[data-dock="left"] .toolbar-sep {
    width: 30px;
    height: 1px;
    margin: 4px 0;
}
.floating-toolbar[data-dock="left"] .toolbar-group {
    flex-direction: column;
}

.floating-toolbar[data-dock="right"] {
    position: absolute;
    right: 0;
    top: 60px; /* 右侧排列时避开横眉 */
    bottom: 0;
    width: 48px;
    flex-direction: column; /* 新增：恢复垂直排列 */
}
.floating-toolbar[data-dock="right"] .toolbar-drag-handle {
    height: 24px;
}
.floating-toolbar[data-dock="right"] .toolbar-body {
    flex-direction: column;
    align-items: center;
}
.floating-toolbar[data-dock="right"] .toolbar-sep {
    width: 30px;
    height: 1px;
    margin: 4px 0;
}
.floating-toolbar[data-dock="right"] .toolbar-group {
    flex-direction: column;
}

/* 浮动状态 */
.floating-toolbar.floating {
    background: #2B2B3D;
    border-radius: 8px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.08);
}
.floating-toolbar.floating .toolbar-drag-handle {
    border-radius: 8px 0 0 8px;
}

/* 锁定状态 */
.floating-toolbar.locked .toolbar-drag-handle {
    cursor: default;
    opacity: 0.5;
}

/* 拖动把手 */
.toolbar-drag-handle {
    height: 24px;
    background: #353550;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    user-select: none;
    border-bottom: none; /* 移除底边框 */
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    margin-right: 8px; /* 新增：与锁定按钮的间距 */
}

.floating-toolbar[data-dock="top"] .toolbar-drag-handle {
    border-radius: 0;
}

.toolbar-drag-handle:active {
    cursor: grabbing;
}

.drag-grip {
    color: rgba(255, 255, 255, 0.4);
    font-size: 14px;
    letter-spacing: 2px;
    line-height: 1;
}

/* 锁定按钮 */
.toolbar-lock-btn {
    position: static; /* 移除绝对定位（默认值） */
    top: auto;        /* 重置 top（避免残留） */
    right: auto;      /* 重置 right（避免残留） */
    font-size: 14px;
    cursor: pointer;
    opacity: 0.6;
    transition: opacity 0.2s;
    z-index: 10;
    user-select: none;
    margin-left: 8px;  /* 新增：与拖动把手的间距 */
    margin-right: 8px; /* 新增：与工具栏主体的间距 */
}
.toolbar-lock-btn:hover {
    opacity: 1;
}

/* 工具栏主体 */
.toolbar-body {
    display: flex;
    align-items: center;
    background: #2B2B3D;
    padding: 4px 8px;
    gap: 4px;
    flex-wrap: wrap;
    flex: 1; /* 新增：占据剩余空间，使拖动把手/锁定按钮居左 */
}

.floating-toolbar[data-dock="top"] .toolbar-body {
    padding: 6px 12px;
}

/* 工具栏分组 */
.toolbar-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* 分组分隔线 */
.toolbar-sep {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.12);
    margin: 0 4px;
}

/* 工具栏按钮 */
.tb-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: #ccc;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
    position: relative;
    flex-shrink: 0;
}

.tb-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.tb-btn:active {
    background: rgba(255, 255, 255, 0.15);
}

.tb-btn:disabled,
.tb-btn[disabled] {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

.tb-btn.primary {
    background: rgba(33, 150, 243, 0.15);
    color: #64b5f6;
}
.tb-btn.primary:hover {
    background: rgba(33, 150, 243, 0.3);
    color: #90caf9;
}

.tb-btn.danger:hover {
    background: rgba(244, 67, 54, 0.25);
    color: #f44336;
}

.floating-toolbar + .floating-toolbar {
    margin-left: 4px;
}

/* === Tooltip 系统 === */
.cad-tooltip {
    position: fixed;
    background: rgba(20, 20, 30, 0.95);
    color: #fff;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 4px;
    white-space: nowrap;
    pointer-events: none;
    z-index: 9999;
    opacity: 0;
    animation: tooltipFadeIn 0.15s ease forwards;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

@keyframes tooltipFadeIn {
    from { opacity: 0; transform: translateY(2px); }
    to { opacity: 1; transform: translateY(0); }
}

/* 右侧箭头（左侧工具条的tooltip） */
.cad-tooltip-right::before {
    content: '';
    position: absolute;
    left: -6px;
    top: 50%;
    transform: translateY(-50%);
    border-width: 5px;
    border-style: solid;
    border-color: transparent rgba(20, 20, 30, 0.95) transparent transparent;
}

/* 下方箭头（顶部工具栏的tooltip） */
.cad-tooltip-bottom::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 5px;
    border-style: solid;
    border-color: transparent transparent rgba(20, 20, 30, 0.95) transparent;
}

/* === 画布区域 === */
.coordinate-display {
    position: absolute;
    top: 8px;
    left: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 4px 10px;
    border-radius: 4px;
    font-size: 12px;
    font-family: monospace;
    z-index: 1000;
    pointer-events: none;
}

.vector-space {
    flex: 1;
    position: relative;
    background-color: #F0F0F0;
    border: 1px solid #ccc;
    min-height: 400px;
    cursor: crosshair;
    overflow: hidden;
    transform-origin: center center;
    background-image: 
        linear-gradient(rgba(255,255,255,0.8) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.8) 1px, transparent 1px),
        linear-gradient(rgba(255,255,255,0.4) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.4) 1px, transparent 1px);
    background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
}

.vector-space.select-mode {
    cursor: crosshair;
}

.vector-space-content {
    position: absolute;
    top: 0;
    left: 0;
    width: 16384px;
    height: 16384px;
    transform-origin: 0 0;
    will-change: transform;
}

#selection-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
}

.connection-label-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 500;
}

.connection-label {
    position: absolute;
    background: rgba(255, 255, 0, 0.9);
    color: black;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: bold;
    white-space: nowrap;
    pointer-events: auto;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

/* === 右侧属性面板 === */
.property-panel {
    position: absolute;
    top: 0;
    right: 0;
    height: 100%;
    width: 30px;
    background: #2B2B3D;
    z-index: 700;
    display: flex;
    flex-direction: row;
    transition: width 0.25s ease;
    overflow: hidden;
}

.property-panel.expanded {
    width: 220px;
    background: #fff;
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
}

.property-panel-tab {
    width: 30px;
    min-width: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    writing-mode: vertical-rl;
    color: #fff;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    user-select: none;
    letter-spacing: 4px;
    transition: background-color 0.2s;
    padding: 20px 0;
}

.property-panel-tab:hover {
    background: rgba(255, 255, 255, 0.08);
}

.property-panel.expanded .property-panel-tab {
    display: none;
}

.property-panel-inner {
    display: none;
    flex-direction: column;
    width: 100%;
    overflow: hidden;
}

.property-panel.expanded .property-panel-inner {
    display: flex;
}

.property-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}

.property-panel-header h3 {
    margin: 0;
    font-size: 15px;
    color: #333;
}

.property-panel-close {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    font-size: 20px;
    color: #999;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, color 0.15s;
}

.property-panel-close:hover {
    background: #f0f0f0;
    color: #333;
}

.property-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}

.property-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 4px 0;
}

.property-input-group label {
    flex: 0 0 auto;
    min-width: 60px;
}

.property-input-group input {
    flex: 1;
    padding: 4px 6px;
    border: 1px solid #bbb;
    border-radius: 4px;
    font-size: 13px;
    width: 100px;
}

.property-input-group input:focus {
    border-color: #3498db;
    outline: none;
    box-shadow: 0 0 3px rgba(52, 152, 219, 0.5);
}

.property-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background-color: #f9f9f9;
    border-radius: 5px;
}

.property-label {
    font-weight: bold;
    color: #666;
}

.property-value {
    color: #333;
}

/* === 底部连接线表格 === */
.table-section {
    background-color: #fff;
    border-top: 2px solid #ddd;
    overflow: hidden;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    max-height: 40vh;
    max-width: calc(100% - 30px);
}

.table-collapse-bar {
    background: #f5f5f5;
    padding: 8px 16px;
    cursor: pointer;
    user-select: none;
    font-size: 13px;
    font-weight: 600;
    color: #555;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    transition: background-color 0.15s;
}

.table-collapse-bar:hover {
    background: #ebebeb;
}

.collapse-arrow {
    font-size: 11px;
    margin-left: 4px;
}

.table-wrapper {
    overflow: auto;
    flex: 1;
    transition: max-height 0.3s ease;
}

.table-wrapper.collapsed {
    max-height: 0;
    overflow: hidden;
}

#connection-table {
    width: 100%;
    border-collapse: collapse;
}

#connection-table th,
#connection-table td {
    padding: 0.5rem 0.6rem;
    text-align: left;
    border-bottom: 1px solid #ddd;
    font-size: 12px;
}

#connection-table th {
    background-color: #f2f2f2;
    font-weight: bold;
    position: sticky;
    top: 0;
    font-size: 11px;
    white-space: nowrap;
    padding: 0.5rem 0.6rem;
}

#connection-table tr:hover {
    background-color: #f5f5f5;
}

#connection-table tr.duplicate {
    background-color: #ffebee;
}

#connection-table tr.highlighted-row {
    background-color: #ffebee;
    border: 2px solid #f44336;
}

.delete-connection {
    padding: 0.3rem 0.6rem;
    border: none;
    border-radius: 3px;
    background-color: #f44336;
    color: white;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.delete-connection:hover {
    background-color: #da190b;
}

/* === 模态框 === */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.4);
}

.modal-content {
    background-color: white;
    margin: 15% auto;
    padding: 2rem;
    border: 1px solid #888;
    width: 80%;
    max-width: 400px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.modal-content h3 {
    margin-bottom: 1.5rem;
    color: #333;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: bold;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.8rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 1rem;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
}

.modal-buttons button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 5px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

#save-block {
    background-color: #4CAF50;
    color: white;
}

#save-block:hover {
    background-color: #45a049;
}

#cancel-block {
    background-color: #f44336;
    color: white;
}

#cancel-block:hover {
    background-color: #da190b;
}

/* === 画布中的块元素（script.js 依赖） === */
.block {
    position: absolute;
    width: 120px;
    height: 80px;
    border: 2px solid black;
    border-radius: 5px;
    background-color: white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: move;
    transition: all 0.3s ease;
    z-index: 100;
}

.block:hover {
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
}

.block.highlighted {
    background-color: #667eea;
    color: white;
    border-color: #333;
}

.block.selected {
    background-color: #fff3cd;
    border-color: #ff9800;
    border-width: 3px;
    box-shadow: 0 0 8px rgba(255, 152, 0, 0.6);
}

.block.selected .block-name,
.block.selected .block-code {
    color: #856404;
}

.block .block-name {
    font-weight: bold;
    margin-bottom: 5px;
    font-size: 14px;
}

.block .block-code {
    font-size: 12px;
    font-weight: bold;
}

.block.hv { border-color: #d32f2f; }
.block.lv { border-color: #1976d2; }
.block.plc { border-color: #388e3c; }
.block.bp { border-color: #f57c00; }
.block.vf { border-color: #7b1fa2; }
.block.qk { border-color: #7b1fa2; }
.block.m { border-color: #00838f; }
.block.tt { border-color: #e65100; }

/* 电缆沟 */
.block.cable-trench {
    width: 200px;
    height: 40px;
    border: 2px dashed #666;
    background-color: rgba(102, 102, 102, 0.1);
    border-radius: 0;
}

.block.cable-trench .block-name {
    font-size: 12px;
    color: #666;
}

.block.cable-trench .block-code {
    display: none;
}

.block.cable-trench.resizing {
    border-color: #667eea;
    border-style: solid;
    background-color: rgba(102, 126, 234, 0.1);
}

.block.cable-trench.editable {
    cursor: move;
}

.block.cable-trench:not(.editable) {
    cursor: not-allowed;
}

.trench-edit-mode .block.cable-trench {
    outline: 2px solid transparent;
}

.trench-edit-mode .block.cable-trench:hover {
    outline-color: rgba(102, 126, 234, 0.5);
}

.block.cable-trench.connected-highlight {
    border-color: #27ae60;
    border-style: solid;
    border-width: 2px;
    background-color: rgba(39, 174, 96, 0.15);
}

.trench-union-highlight {
    position: absolute;
    pointer-events: none;
    z-index: 50;
}

/* 缩放手柄 */
.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: #667eea;
    border: 2px solid white;
    border-radius: 50%;
    z-index: 200;
    pointer-events: auto;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.resize-handle:hover {
    background-color: #5a6fd8;
    transform: scale(1.2);
}

.resize-handle.dragging {
    background-color: #4a5fd0;
    transform: scale(1.3);
}

/* 旋转手柄 */
.rotate-handle {
    position: absolute;
    width: 16px;
    height: 16px;
    background-color: #e74c3c;
    border: 2px solid white;
    border-radius: 50%;
    z-index: 200;
    pointer-events: auto;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.rotate-handle::after {
    content: '\27F3';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10px;
    color: white;
}

.rotate-handle:hover {
    background-color: #c0392b;
    transform: scale(1.2);
}

.rotate-handle.dragging {
    background-color: #a93226;
    transform: scale(1.3);
}

/* 电缆沟起点高亮 */
.trench-start-point-highlight {
    position: absolute;
    width: 16px;
    height: 16px;
    background-color: #e74c3c;
    border: 3px solid white;
    border-radius: 50%;
    pointer-events: none;
    z-index: 250;
    box-shadow: 0 0 8px rgba(231, 76, 60, 0.8);
    animation: pulse 1.5s infinite;
}

.trench-start-point-label {
    position: absolute;
    background-color: rgba(231, 76, 60, 0.9);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    pointer-events: none;
    z-index: 251;
    white-space: nowrap;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        box-shadow: 0 0 8px rgba(231, 76, 60, 0.8);
    }
    50% {
        transform: scale(1.2);
        box-shadow: 0 0 16px rgba(231, 76, 60, 1);
    }
    100% {
        transform: scale(1);
        box-shadow: 0 0 8px rgba(231, 76, 60, 0.8);
    }
}

/* 选框 */
.selection-box {
    position: absolute;
    border: 2px dashed #f39c12;
    background-color: rgba(243, 156, 18, 0.1);
    pointer-events: auto;
    z-index: 100;
}

.selection-box:hover {
    border-color: #e74c3c;
    background-color: rgba(243, 156, 18, 0.2);
}

.selection-box.highlighted {
    border-color: #3498db;
    border-style: solid;
    background-color: rgba(52, 152, 219, 0.2);
    box-shadow: 0 0 10px rgba(52, 152, 219, 0.5);
}

.selection-box-label {
    position: absolute;
    top: -25px;
    left: 0;
    background-color: #f39c12;
    color: white;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: bold;
    border-radius: 3px;
    white-space: nowrap;
}

/* 连接线 */
.connection-line {
    position: absolute;
    background: linear-gradient(transparent, transparent 4px, black 4px, black 6px, transparent 6px, transparent);
    height: 12px;
    transform-origin: 0 0;
    pointer-events: auto;
    z-index: 10;
    cursor: pointer;
    margin-top: -5px;
}

.connection-line.editable {
    pointer-events: auto;
    background: linear-gradient(transparent, transparent 4px, #667eea 4px, #667eea 6px, transparent 6px, transparent);
    cursor: move;
}

.connection-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background-color: #e74c3c;
    border: 2px solid white;
    border-radius: 50%;
    pointer-events: auto;
    z-index: 300;
    cursor: move;
    box-shadow: 0 0 6px rgba(231, 76, 60, 0.8);
}

.connection-handle:hover {
    background-color: #c0392b;
    transform: scale(1.2);
}

.connection-line.editable:hover {
    background: linear-gradient(transparent, transparent 4px, #5a6fd8 4px, #5a6fd8 6px, transparent 6px, transparent);
}

.connection-line.dragging {
    background-color: #667eea;
    cursor: move;
}

.connection-line.arrow::after {
    content: '';
    position: absolute;
    right: -5px;
    top: -4px;
    border-width: 5px;
    border-style: solid;
    border-color: transparent transparent transparent black;
}

.connection-line-svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 50;
}

.connection-line-svg path {
    stroke: #3498db;
    stroke-width: 2;
    fill: none;
}

/* 连接线列表 */
.connection-list {
    max-height: 200px;
    overflow-y: auto;
    padding-left: 10px;
    border-left: 2px solid #667eea;
}

.connection-list div {
    padding: 2px 0;
    font-size: 13px;
    color: #555;
}

/* 编辑提示 */
.edit-hint {
    position: absolute;
    background: rgba(102, 126, 234, 0.9);
    color: white;
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 12px;
    z-index: 1000;
    pointer-events: none;
}

/* 导入图片 */
.imported-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0.6;
    pointer-events: none;
    z-index: -1;
    user-select: none;
    -webkit-user-drag: none;
}

/* mode-button 类（script.js 使用） */
.mode-button {
    background-color: #4CAF50;
}

.mode-button:hover,
.mode-button.active {
    background-color: #45a049;
}

.mode-button.active {
    background: #1976D2;
    color: #fff;
}

.mode-button.select-mode {
    background-color: #ff9800;
}

.mode-button.select-mode:hover {
    background-color: #f57c00;
}

/* 高亮行 */
.highlighted-row {
    background-color: #ffebee;
}

/* connected-highlight for blocks */
.connected-highlight {
    box-shadow: 0 0 10px rgba(39, 174, 96, 0.5);
}

/* 工具栏中的 mode-button 样式适配 */
.floating-toolbar .mode-button {
    width: 34px;
    height: 34px;
    padding: 0;
    border: none;
    border-radius: 5px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ccc;
    font-size: 0;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.floating-toolbar .mode-button:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.floating-toolbar .mode-button.active {
    background: #1976D2;
    color: #fff;
}

/* === 响应式 - 移动端 === */
@media (max-width: 768px) {
    /* 左侧工具条变为底部水平工具条 */
    .device-toolbar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 52px;
        min-width: unset;
        flex-direction: row;
        padding: 0 8px;
        overflow-x: auto;
        overflow-y: hidden;
        z-index: 900;
        border-right: none;
        border-top: 1px solid #3a3a4e;
        gap: 4px;
    }

    .toolbar-divider {
        width: 1px;
        height: 30px;
        margin: 0 4px;
    }

    .cad-container {
        flex-direction: column;
        height: calc(100vh - 60px - 52px);
    }

    /* 顶部工具栏保持顶部但只显示图标 */
    .floating-toolbar[data-dock="top"] .toolbar-body {
        padding: 4px 8px;
    }

    /* 属性面板全屏 */
    .property-panel.expanded {
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        right: 0;
    }

    /* 底部表格 */
    .table-section {
        max-height: 30vh;
    }

    .vector-space {
        min-height: 300px;
    }

    .block {
        width: 100px;
        height: 70px;
    }

    #connection-table th,
    #connection-table td {
        padding: 0.5rem;
        font-size: 12px;
    }

    /* 触摸设备禁用 tooltip */
    .cad-tooltip {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .toolbar-body {
        padding: 4px;
        gap: 2px;
    }

    .tb-btn {
        width: 30px;
        height: 30px;
    }

    .vector-space {
        min-height: 250px;
    }

    .block {
        width: 80px;
        height: 60px;
        font-size: 0.8rem;
    }
}
/* ===== 通用 tooltip：任何带 data-tooltip 属性的元素自动生效 ===== */
[data-tooltip] {
    position: relative;
}

[data-tooltip]::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 8px);
    transform: translateX(-50%) translateY(4px);
    background: #1f2937;
    color: #fff;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity .15s ease, transform .15s ease;
    z-index: 99999;
}

[data-tooltip]:hover::after {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}
/* ===== 追加：自动判断边界，显示在下方 ===== */
[data-tooltip].tooltip-bottom::after {
    bottom: auto; /* 清除原有的底部定位 */
    top: calc(100% + 8px); /* 改为距离顶部 8px */
    transform: translateX(-50%) translateY(-4px); /* 调整动画起始方向 */
}

[data-tooltip].tooltip-bottom:hover::after {
    transform: translateX(-50%) translateY(0); /* 动画结束方向 */
}