/* 基本樣式 */
body {
    margin: 0;
    overflow: hidden;
    user-select: none;
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    height: 100vh;
}

/* 畫布樣式 */
svg {
    border: 1px solid #ccc;
    background-color: #f9f9f9;
    width: 100%;
    height: 100%;
}

/* 部件樣式 */
.part {
    cursor: crosshair;
}

/* 確保所有子元素都有正確的 cursor 和事件處理 */
.part rect,
.part image,
.part text {
    cursor: crosshair;
    pointer-events: all;  /* 確保子元素可以接收事件 */
}

.part.hovered rect {
    stroke: green;
    stroke-dasharray: 5,5;
}

.part.selected rect {
    stroke: red;
    stroke-width: 3;
    stroke-dasharray: none;
}

/* 多選元件的高亮樣式 */
.part-group.multi-selected,
.part.multi-selected {
    filter: drop-shadow(0 0 8px rgba(0, 123, 255, 0.8));
}

.part.multi-selected rect {
    stroke: #007bff;
    stroke-width: 3;
}

.dot {
    fill: black;
    cursor: pointer;
}

.dot.hovered {
    fill: red;
    cursor: pointer;
}

.dot.near {
    fill: orange;
    cursor: pointer;
}

.connection {
    stroke: black;
    stroke-width: 2;
    cursor: pointer;
    pointer-events: stroke; /* 確保線條可接收滑鼠事件 */
}

.connection.hovered {
    stroke: red;
    stroke-dasharray: 5,5;
    stroke-width: 6; /* 增大線條寬度以增加可點擊範圍 */
}

.connection.selected {
    stroke: red;
    stroke-width: 3;
    stroke-dasharray: none;
}

/* 自訂的右鍵選單 */
.context-menu {
    position: absolute;
    background-color: white;
    border: 1px solid #ccc;
    box-shadow: 2px 2px 5px rgba(0,0,0,0.2);
    display: none;
    z-index: 1000;
    width: 220px;
    padding: 10px;
    box-sizing: border-box;
}

.context-title {
    padding: 8px 20px;
    border-bottom: 1px solid #ccc;
    font-weight: bold;
    background-color: #f0f0f0;
    margin-bottom: 10px;
}

.context-menu ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.context-menu li {
    padding: 8px 20px;
    cursor: pointer;
}

.context-menu li:hover {
    background-color: #f0f0f0;
}

.context-menu textarea {
    width: 100%;
    height: 60px;
    resize: none;
    box-sizing: border-box;
    margin-bottom: 10px;
}

/* 工具列樣式 */
.toolbar {
    width: 100%;
    height: 60px;
    background-color: #333;
    display: flex;
    align-items: center;
    padding: 0 20px;
    box-sizing: border-box;
}

.toolbar .action-button {
    margin-right: 10px;
    padding: 5px 20px;
    font-size: 16px;
    color: white;
    background-color: #4CAF50;
    border: none;
    border-radius: 4px; /* 圓角 */
    cursor: pointer;
    transition: background-color 0.3s;
}

.toolbar .action-button:hover {
    background-color: #45a049;
}

.toolbar .deploy-button {
    margin-right: 10px;
    padding: 5px 20px;
    font-size: 16px;
    color: white;
    background-color: #4CAF50;
    border: none;
    border-radius: 4px; /* 圓角 */
    cursor: pointer;
    transition: background-color 0.3s;
}

.toolbar .deploy-button:hover {
    background-color: #45a049;
}

/* 主容器樣式 */
.main-container {
    display: flex;
    flex: 1; /* 佔滿剩餘空間 */
    height: calc(100vh - 60px); /* 扣除工具列高度 */
}

/* 部件清單樣式 */
.parts-list {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 12%;
    overflow-y: auto;
    background-color: #f0f0f0;
    border-right: 1px solid #ccc;
    box-sizing: border-box;
    text-align: center;
    padding: 10px 0;
}

.parts-list ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.parts-list li {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 15px;
    cursor: pointer;
    border: 1px solid #ddd;
    padding: 5px;
    border-radius: 8px; /* 圓角 */
    transition: background-color 0.3s;
}

.parts-list li:hover {
    background-color: #f0f0f0;
}

.parts-list img {
    width: 120px; /* 修改寬度為 160px */
    height: 80px; /* 修改高度為 120px */
    object-fit: cover;
    border-radius: 8px; /* 圓角 */
    margin-bottom: 5px;
}

.parts-list span {
    margin-top: 5px;
    font-size: 14px;
    text-align: center;
}

/* 畫布容器樣式 */
.canvas-container {
    width: 88%;
    height: 100%;
    position: relative; /* 支持絕對定位的子元素 */
}

/* 彈出式模態框樣式 */
.modal {
    display: none; 
    position: fixed; 
    z-index: 1; 
    padding-top: 100px; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    overflow: auto; 
    background-color: rgba(0,0,0,0.4); 
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 640px;
    height: 480px;
    border-radius: 8px; /* 圓角 */
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

#importTextArea {
    width: 100%;
    height: 80%;
    border-radius: 4px; /* 圓角 */
    padding: 5px;
    box-sizing: border-box;
}

/* 調整畫布大小以適應容器 */
svg {
    width: 100%;
    height: 100%;
    border-radius: 8px; /* 圓角 */
}

.property-panel {
    font-family: Arial, sans-serif;
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
  }
  
  .property-panel h2 {
    margin-top: 0;
  }
  
  .property-panel input {
    width: 100%;
    padding: 8px;
    margin-bottom: 10px;
  }

.frequency-input {
    margin-bottom: 10px;
    display: flex;
    align-items: center;
}

.frequency-input label {
    margin-right: 5px;
    font-size: 14px;
}

.frequency-input input {
    width: 100px;
    padding: 5px;
    font-size: 14px;
}

/* 選擇框樣式 */
.selection-box {
    fill: rgba(0, 123, 255, 0.1);        /* 半透明藍色填充 */
    stroke: rgba(0, 123, 255, 0.8);      /* 藍色邊框 */
    stroke-width: 2;
    stroke-dasharray: 5, 5;              /* 虛線 */
    pointer-events: none;                /* 不攔截鼠標事件 */
}

/* 右下角縮放控制 */
.zoom-controls-corner {
    position: absolute;
    right: 20px;
    bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    background-color: rgba(255, 255, 255, 0.95);
    padding: 8px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    z-index: 100;
}

.zoom-btn {
    width: 32px;
    height: 32px;
    font-size: 20px;
    font-weight: bold;
    border: none;
    background-color: #4CAF50;
    color: white;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
}

.zoom-btn:hover {
    background-color: #45a049;
}

.zoom-btn:active {
    background-color: #3d8b40;
}

.zoom-display {
    min-width: 50px;
    text-align: center;
    font-size: 14px;
    font-weight: bold;
    color: #333;
    user-select: none;
}