/* 全局样式重置 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    overflow: hidden;
}

/* 主容器 */
#app {
    height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 顶部导航栏 */
.navbar {
    background-color: #2c3e50;
    color: white;
    padding: 0 20px;
    height: 48px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.navbar .copyright {
    flex: 1;
    text-align: center;
}

.navbar-brand {
    display: flex;
    align-items: center;
}

.navbar-brand h1 {
    font-size: 24px;
    margin-right: 10px;
    color: #3498db;
}

.navbar-brand p {
    font-size: 14px;
    opacity: 0.8;
}

.navbar-nav ul {
    display: flex;
    list-style: none;
}

.navbar-nav li {
    margin-left: 20px;
}

.navbar-nav a {
    color: white;
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 4px;
    transition: background-color 0.3s;
}

.navbar-nav a:hover {
    background-color: #34495e;
}

/* 主要内容区域 */
.main-content {
    flex: 1;
    display: flex;
    overflow: hidden;
}

/* 左侧工具栏 */
.sidebar {
    width: 250px;
    background-color: white;
    border-right: 1px solid #e0e0e0;
    overflow-y: auto;
    padding: 20px;
}

.tool-section {
    margin-bottom: 12.5px;
}

.tool-section h3 {
    font-size: 16px;
    margin-bottom: 5px;
    color: #2c3e50;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 5px;
}

.device-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 5px;
}

.device-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 5px;
    background-color: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 13px;
    user-select: none;
    -webkit-user-select: none;
}

.device-item:hover {
    background-color: #e3f2fd;
    border-color: #3498db;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(52, 152, 219, 0.2);
}

.device-item:active,
.device-item.touch-active {
    background-color: #bbdefb;
    border-color: #2196f3;
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(52, 152, 219, 0.3);
}

/* 拖动预览样式 */
.drag-preview {
    position: fixed;
    top: 0;
    left: 0;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.8;
    transform: scale(1);
    transition: all 0.1s;
}

.drag-preview .device-icon {
    font-size: 24px;
    margin-bottom: 4px;
}

.drag-preview span {
    font-size: 12px;
    color: #333;
    text-align: center;
}

.device-icon {
    font-size: 24px;
    margin-bottom: 2.5px;
}

/* 连接工具和实验工具按钮 */
.connection-tools {
    display: flex;
    flex-direction: row;
    gap: 4px;
    width: 100%;
}

.connection-tools button {
    flex: 1;
}

.experiment-tools {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
}

.connection-tools button, .experiment-tools button {
    padding: 9px;
    background-color: #3498db;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.3s;
    font-size: 13px;
}

#delete-connection {
    background-color: #e74c3c;
}

#delete-connection:hover {
    background-color: #c0392b;
}

.connection-tools button:hover, .experiment-tools button:hover {
    background-color: #2980b9;
}

/* 预设实验列表 */
.preset-experiments {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
}

/* 原理展示样式 */
.principle-showcase {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px;
}

.principle-item {
    padding: 7.5px;
    background-color: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 13px;
    text-align: center;
}

.principle-item:hover {
    background-color: #e8f5e8;
    border-color: #27ae60;
    transform: translateY(-2px);
    box-shadow: 0 2px 8px rgba(39, 174, 96, 0.2);
}

.experiment-item {
    padding: 7.5px;
    background-color: #f8f9fa;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
    font-size: 13px;
}

.experiment-item:hover {
    background-color: #e8f5e8;
    border-color: #27ae60;
}

/* 中央画布区域 */
.canvas-container {
    flex: 1;
    background-color: #fafafa;
    position: relative;
    overflow: auto;
    cursor: grab;
    /* 隐藏滚动条但保持滚动功能 */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

.canvas-container::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

.canvas-container.dragging {
    cursor: grabbing;
    user-select: none;
}

#canvas-wrapper {
    width: 2000px;
    height: 2000px;
    position: relative;
    background-image: linear-gradient(45deg, #f0f0f0 25%, transparent 25%),
                      linear-gradient(-45deg, #f0f0f0 25%, transparent 25%),
                      linear-gradient(45deg, transparent 75%, #f0f0f0 75%),
                      linear-gradient(-45deg, transparent 75%, #f0f0f0 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

#network-canvas {
    position: absolute;
    top: 0;
    left: 0;
}

/* 右侧属性面板 */
.properties-panel {
    width: 300px;
    background-color: white;
    border-left: 1px solid #e0e0e0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.properties-section {
    padding: 20px;
    border-bottom: 1px solid #e0e0e0;
}

.properties-section h3 {
    font-size: 16px;
    margin-bottom: 5px;
    color: #2c3e50;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 5px;
}

.properties-content {
    font-size: 14px;
}

/* 状态项样式 */
.status-item {
    margin-bottom: 5px;
    display: flex;
    justify-content: space-between;
}

.status-item span:first-child {
    color: #7f8c8d;
}

.status-item span:last-child {
    font-weight: bold;
    color: #2c3e50;
}

/* 日志面板 */
.log-content {
    background-color: #f8f9fa;
    padding: 10px;
    border-radius: 4px;
    height: 200px;
    overflow-y: auto;
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    line-height: 1.5;
}

.log-content p {
    margin-bottom: 2.5px;
    color: #34495e;
}

/* 属性表单样式 */
.property-form {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 2.5px;
}

.form-group label {
    font-size: 13px;
    color: #7f8c8d;
}

.form-group input, .form-group select {
    padding: 8px;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    font-size: 14px;
}

.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: #3498db;
    box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

.form-actions {
    display: flex;
    gap: 5px;
    margin-top: 3.75px;
}

.form-actions button {
    padding: 8px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    transition: background-color 0.3s;
}

.form-actions .btn-save {
    background-color: #27ae60;
    color: white;
}

.form-actions .btn-save:hover {
    background-color: #229954;
}

.form-actions .btn-cancel {
    background-color: #e74c3c;
    color: white;
}

.form-actions .btn-cancel:hover {
    background-color: #c0392b;
}

/* 模态对话框 */
.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.1);
}

.modal-content {
    background-color: white;
    margin: 0;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 600px;
    border-radius: 8px;
    position: fixed;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.9;
    z-index: 1001;
}

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

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

/* 模态框头部样式 */
.modal-header {
    background-color: #f0f0f0;
    padding: 15px 20px;
    border-bottom: 1px solid #ddd;
    margin: -20px -20px 10px -20px;
    border-radius: 8px 8px 0 0;
}

/* 设备样式 */
.device {
    cursor: move;
    transition: filter 0.3s, opacity 0.3s; /* 只对filter和opacity使用过渡，不包括transform */
}

.device:hover {
    filter: drop-shadow(0 0 5px rgba(52, 152, 219, 0.5));
}

.device.selected {
    filter: drop-shadow(0 0 8px rgba(231, 76, 60, 0.8));
}

.device-label {
    text-anchor: middle;
    font-size: 12px;
    font-weight: bold;
    fill: #2c3e50;
    pointer-events: none;
}

/* 连接线样式 */
.connection {
    stroke: #3498db;
    stroke-width: 2;
    fill: none;
    cursor: pointer;
    transition: all 0.3s;
}

.connection:hover {
    stroke: #2980b9;
    stroke-width: 3;
}

.connection.selected {
    stroke: #e74c3c;
    stroke-width: 3;
}

.connection-dot {
    fill: #3498db;
    stroke: white;
    stroke-width: 2;
    cursor: pointer;
}

.connection-dot:hover {
    fill: #2980b9;
    r: 6;
}

/* 数据包样式 */
.packet {
    fill: #e74c3c;
    stroke: white;
    stroke-width: 1;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0% { r: 3; opacity: 1; }
    50% { r: 5; opacity: 0.7; }
    100% { r: 3; opacity: 1; }
}

/* 响应式设计 */
@media (max-width: 1200px) {
    .sidebar {
        width: 200px;
    }
    
    .properties-panel {
        width: 250px;
    }
}

@media (max-width: 768px) {
    .navbar {
        flex-direction: column;
        height: auto;
        padding: 10px;
    }
    
    .navbar-nav ul {
        margin-top: 10px;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .navbar-nav li {
        margin: 0 10px;
    }
    
    .main-content {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: 150px;
        overflow-x: auto;
        overflow-y: hidden;
    }
    
    .device-list {
        grid-template-columns: repeat(6, 1fr);
    }
    
    .properties-panel {
        width: 100%;
        height: 200px;
    }
    
    .canvas-container {
        flex: 1;
    }
}

/* 滚动条样式 */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* 选中状态样式 */
.selected {
    outline: 2px solid #e74c3c;
}

/* 拖拽状态样式 */
.device.dragging,
g.dragging {
    opacity: 0.5;
    cursor: grabbing;
    transition: none !important; /* 拖动时禁用所有过渡，确保实时响应 */
}

/* 提示信息样式 */
.tooltip {
    position: absolute;
    background-color: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    pointer-events: none;
    z-index: 1000;
    opacity: 0;
    transition: opacity 0.3s;
}

.tooltip.visible {
    opacity: 1;
}

/* 版权信息 */
.copyright {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    text-align: center;
    padding: 0 10px;
}

/* 密码输入框容器 */
.password-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
}

.password-input-wrapper input {
    flex: 1;
    padding-right: 35px;
}

.password-toggle-icon {
    position: absolute;
    right: 10px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    font-size: 18px;
    color: #7f8c8d;
    transition: color 0.3s, transform 0.2s;
    z-index: 10;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    line-height: 1;
}

.password-toggle-icon:hover {
    color: #3498db;
    transform: scale(1.1);
}

.password-toggle-icon:active {
    transform: scale(0.95);
}