* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    height: 100vh;
    padding: 20px;
    color: #333;
    margin: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.container {
    width: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

header {
    background: white;
    padding: 24px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

header h1 {
    font-size: 28px;
    margin-bottom: 8px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

header p {
    color: #666;
    font-size: 14px;
}

.header-actions {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-link {
    color: #667eea;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: color 0.2s;
}

.header-link:hover {
    color: #764ba2;
    text-decoration: underline;
}

.header-separator {
    color: #ccc;
    font-size: 14px;
}

.main-content {
    display: flex;
    gap: 20px;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.canvas-container {
    flex: 1;
    background: white;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    display: flex;
    overflow: hidden;
    min-height: 0;
}

#mainCanvas {
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    cursor: grab;
    background: #fafafa;
    display: block;
    margin: auto;
}

.sidebar {
    width: 320px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    flex-shrink: 0;
}

.panel {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.panel h2 {
    font-size: 18px;
    margin-bottom: 16px;
    color: #333;
}

.panel ul {
    list-style: none;
    color: #666;
    font-size: 14px;
}

.panel ul li {
    padding: 6px 0;
    padding-left: 20px;
    position: relative;
}

.panel ul li:before {
    content: "→";
    position: absolute;
    left: 0;
    color: #667eea;
}

.connection-list {
    max-height: 300px;
    overflow-y: auto;
}

.connection-item {
    background: #f5f5f5;
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 13px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 3px solid #667eea;
}

.connection-item:hover {
    background: #efefef;
}

.connection-label {
    flex: 1;
}

.delete-btn {
    background: #ff4757;
    color: white;
    border: none;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    transition: background 0.2s;
}

.delete-btn:hover {
    background: #ff3838;
}

.empty-state {
    color: #999;
    font-size: 13px;
    font-style: italic;
    text-align: center;
    padding: 20px;
}

.component-palette {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.palette-item {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 12px;
    border-radius: 6px;
    cursor: grab;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
    transition: transform 0.2s, box-shadow 0.2s;
    user-select: none;
}

.palette-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.palette-item:active {
    cursor: grabbing;
    transform: translateY(0);
}

.palette-item.power-supply {
    background: linear-gradient(135deg, #2196F3 0%, #1565C0 100%);
}

.palette-item.button {
    background: linear-gradient(135deg, #E91E63 0%, #AD1457 100%);
}

.palette-item.controller {
    background: linear-gradient(135deg, #9C27B0 0%, #6A1B9A 100%);
}

.palette-item.motor-driver {
    background: linear-gradient(135deg, #FF9800 0%, #E65100 100%);
}

.palette-item.sensor {
    background: linear-gradient(135deg, #4CAF50 0%, #2E7D32 100%);
}

.palette-item.switch {
    background: linear-gradient(135deg, #607D8B 0%, #37474F 100%);
}

.btn {
    width: 100%;
    padding: 12px;
    margin-bottom: 8px;
    border: none;
    border-radius: 6px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn:active {
    transform: translateY(0);
}

/* Scrollbar styling */
.connection-list::-webkit-scrollbar,
.sidebar::-webkit-scrollbar {
    width: 6px;
}

.connection-list::-webkit-scrollbar-track,
.sidebar::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.connection-list::-webkit-scrollbar-thumb,
.sidebar::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 3px;
}

.connection-list::-webkit-scrollbar-thumb:hover,
.sidebar::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}

/* Responsive design */
@media (max-width: 1200px) {
    .main-content {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        max-height: 40vh;
        overflow-y: auto;
    }
    
    .canvas-container {
        min-height: 400px;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    header {
        padding: 16px;
        margin-bottom: 10px;
    }
    
    header h1 {
        font-size: 22px;
    }
    
    .main-content {
        gap: 10px;
    }
    
    .sidebar {
        max-height: 50vh;
    }
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease-in-out;
}

.modal.show {
    display: flex;
    justify-content: center;
    align-items: center;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.modal-content {
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    width: 90%;
    max-width: 700px;
    max-height: 85vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24px;
    border-bottom: 1px solid #e0e0e0;
}

.modal-header h2 {
    margin: 0;
    font-size: 24px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.close-modal {
    font-size: 32px;
    color: #999;
    cursor: pointer;
    transition: color 0.2s;
    line-height: 1;
    font-weight: 300;
}

.close-modal:hover {
    color: #333;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

.modal-body h3 {
    color: #333;
    font-size: 18px;
    margin-top: 16px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 2px solid #667eea;
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body ul {
    list-style: none;
    margin-bottom: 20px;
}

.modal-body ul li {
    padding: 8px 0;
    padding-left: 24px;
    position: relative;
    line-height: 1.6;
    color: #555;
}

.modal-body ul li:before {
    content: "→";
    position: absolute;
    left: 0;
    color: #667eea;
    font-weight: bold;
}

.modal-body ul li strong {
    color: #333;
}

.modal-body::-webkit-scrollbar {
    width: 8px;
}

.modal-body::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb {
    background: #667eea;
    border-radius: 4px;
}

.modal-body::-webkit-scrollbar-thumb:hover {
    background: #5568d3;
}
