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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #fafafa;
    height: 100vh;
    overflow: hidden;
}

.container {
    display: flex;
    height: 100vh;
    min-width: 0;
}

/* Toolbox Styles */
.toolbox {
    width: 250px;
    min-width: 200px;
    flex-shrink: 0;
    background-color: #ffffff;
    color: #4a5568;
    padding: 20px;
    overflow-y: auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    border-right: 1px dotted #d1d5db;
    z-index: 100;
}

.toolbox h3 {
    margin-bottom: 20px;
    text-align: center;
    color: #374151;
    border-bottom: 1px dotted #9ca3af;
    padding-bottom: 10px;
    font-weight: 500;
}

.category-selector-container {
    margin-bottom: 15px;
    padding: 10px;
    background-color: #f9fafb;
    border-radius: 6px;
    border: 1px dotted #d1d5db;
}

.category-selector-container label {
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 500;
    color: #6b7280;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.category-selector-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
}

.category-icon-display {
    display: none;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    padding: 4px;
    background-color: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.category-icon-display img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.category-selector {
    flex: 1;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    background-color: #ffffff;
    color: #374151;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    outline: none;
}

.category-selector:hover {
    border-color: #9ca3af;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.category-selector:focus {
    border-color: #6b7280;
    box-shadow: 0 0 0 3px rgba(107, 114, 128, 0.1);
}

.category-selector option {
    padding: 8px;
}

.component-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 30px;
}

.component-item {
    display: flex;
    align-items: center;
    padding: 12px;
    background-color: #f9fafb;
    border-radius: 8px;
    cursor: grab;
    transition: all 0.3s ease;
    border: 1px dotted #d1d5db;
}

.component-item:hover {
    background-color: #ffffff;
    border-color: #9ca3af;
    border-style: solid;
    transform: translateX(5px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.component-item:active {
    cursor: grabbing;
}

.component-icon {
    width: 40px;
    height: 40px;
    background-color: #e5e7eb;
    border-radius: 4px;
    margin-right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #6b7280;
    font-size: 12px;
    overflow: hidden;
    border: 1px solid #d1d5db;
}

.component-icon svg {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.component-name {
    font-size: 14px;
    font-weight: 500;
    color: #374151;
}

/* Controls */
.controls {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toggle-control {
    padding: 8px;
    background-color: #f9fafb;
    border-radius: 5px;
    border: 1px dotted #d1d5db;
}

.toggle-control label {
    display: flex;
    align-items: center;
    cursor: pointer;
    color: #4a5568;
    font-size: 12px;
}

.toggle-control input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
}

.controls button {
    padding: 10px;
    border: 1px solid #d1d5db;
    border-radius: 5px;
    background-color: #ffffff;
    color: #4a5568;
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s ease;
}

.controls button:hover {
    background-color: #f3f4f6;
    border-color: #9ca3af;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.controls button:active {
    transform: translateY(1px);
}

/* Canvas Container */
.canvas-container {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background-color: #fafafa;
    position: relative;
    overflow: hidden;
}

/* Component Context Menu */
.context-menu {
    position: absolute;
    background-color: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 1000;
    min-width: 80px;
}

.menu-item {
    padding: 8px 12px;
    color: #4a5568;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s;
    user-select: none;
}

.menu-item:hover {
    background-color: #f3f4f6;
}

.menu-item:active {
    background-color: #e5e7eb;
}

#setupCanvas {
    border: 1px solid #e5e7eb;
    background-color: #ffffff;
    background-image: 
        linear-gradient(rgba(0,0,0,.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0,0,0,.06) 1px, transparent 1px);
    background-size: 20px 20px;
    cursor: crosshair;
    margin: 10px;
    display: block;
    width: calc(100% - 20px);
    height: calc(100vh - 60px);
    flex: 1;
    /* Touch action for better mobile support */
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
}

.canvas-info {
    padding: 10px 20px;
    background-color: #ffffff;
    color: #6b7280;
    font-size: 12px;
    border-top: 1px dotted #e5e7eb;
    flex-shrink: 0;
}

/* Drag and Drop */
.dragging {
    opacity: 0.7;
    transform: rotate(5deg);
}

.component-ghost {
    position: absolute;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.8;
    border: 1px dashed #9ca3af;
    background-color: rgba(243, 244, 246, 0.5);
}

/* Component on Canvas */
.canvas-component {
    position: absolute;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    background-color: #ffffff;
    padding: 8px;
    cursor: move;
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
    user-select: none;
    min-width: 80px;
    min-height: 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.canvas-component.selected {
    border-color: #9ca3af;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.canvas-component .component-icon {
    margin-bottom: 4px;
}

.canvas-component .component-name {
    font-size: 10px;
    text-align: center;
    color: #6b7280;
}

/* Connection Points */
.connection-point {
    position: absolute;
    width: 8px;
    height: 8px;
    background-color: #9ca3af;
    border: 2px solid white;
    border-radius: 50%;
    cursor: crosshair;
    z-index: 10;
    transition: all 0.2s ease;
}

.connection-point:hover {
    background-color: #6b7280;
    transform: scale(1.3);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

/* Wire being drawn */
.drawing-wire {
    stroke: #6b7280;
    stroke-width: 2;
    fill: none;
    pointer-events: none;
    stroke-dasharray: 4, 2;
}

/* Completed wires */
.wire {
    stroke: #9ca3af;
    stroke-width: 1.5;
    fill: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.wire:hover {
    stroke: #6b7280;
    stroke-width: 2;
}

.wire.selected {
    stroke: #4a5568;
    stroke-width: 2;
    stroke-dasharray: 5,3;
}

/* Mobile Responsiveness - Touch-friendly */
@media (hover: none) and (pointer: coarse) {
    /* Increase touch targets for mobile devices */
    .connection-point {
        width: 12px;
        height: 12px;
    }
    
    .component-item {
        padding: 16px;
        min-height: 44px;
    }
    
    .controls button {
        padding: 14px;
        min-height: 44px;
    }
    
    .menu-item {
        padding: 14px 16px;
        font-size: 14px;
        min-height: 44px;
    }
}

/* Tablet and Mobile Layout */
@media screen and (max-width: 1024px) {
    .toolbox {
        width: 220px;
        min-width: 180px;
        padding: 15px;
    }
    
    .component-icon {
        width: 35px;
        height: 35px;
    }
}

@media screen and (max-width: 768px) {
    body {
        overflow: auto;
    }
    
    .container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    
    /* Collapsible toolbox for mobile */
    .toolbox {
        width: 100%;
        max-width: 100%;
        min-width: 0;
        padding: 15px;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        border-right: none;
        border-bottom: 1px solid #d1d5db;
        max-height: 40vh;
        overflow-y: auto;
        position: relative;
        z-index: 200;
    }
    
    .toolbox h3 {
        margin-bottom: 15px;
        font-size: 16px;
    }
    
    .component-list {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
        gap: 8px;
        margin-bottom: 15px;
    }
    
    .component-item {
        flex-direction: column;
        text-align: center;
        padding: 12px 8px;
        min-height: 60px;
    }
    
    .component-icon {
        margin-right: 0;
        margin-bottom: 6px;
        width: 40px;
        height: 40px;
    }
    
    .component-name {
        font-size: 12px;
    }
    
    .controls {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .controls button,
    .toggle-control {
        flex: 1 1 calc(50% - 4px);
        min-width: 120px;
    }
    
    /* Canvas adjustments for mobile */
    .canvas-container {
        min-height: 60vh;
        height: auto;
        flex: 1;
    }
    
    #setupCanvas {
        margin: 10px;
        width: calc(100% - 20px);
        height: 60vh;
        min-height: 400px;
    }
    
    .canvas-info {
        padding: 12px 15px;
        font-size: 11px;
        line-height: 1.4;
    }
    
    .canvas-info p {
        margin: 0;
    }
    
    /* Context menu adjustments */
    .context-menu {
        min-width: 160px;
    }
}

@media screen and (max-width: 480px) {
    .toolbox {
        padding: 12px;
        max-height: 35vh;
    }
    
    .toolbox h3 {
        font-size: 15px;
        margin-bottom: 12px;
    }
    
    .component-list {
        grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
        gap: 6px;
    }
    
    .component-item {
        padding: 10px 6px;
    }
    
    .component-icon {
        width: 32px;
        height: 32px;
    }
    
    .component-name {
        font-size: 11px;
    }
    
    .controls button,
    .toggle-control {
        flex: 1 1 100%;
        font-size: 13px;
    }
    
    #setupCanvas {
        margin: 8px;
        width: calc(100% - 16px);
        height: 55vh;
        min-height: 350px;
    }
    
    .canvas-info {
        padding: 10px 12px;
        font-size: 10px;
    }
}

/* Landscape orientation adjustments for mobile */
@media screen and (max-width: 768px) and (orientation: landscape) {
    .container {
        flex-direction: row;
    }
    
    .toolbox {
        width: 200px;
        max-height: 100vh;
        border-right: 1px solid #d1d5db;
        border-bottom: none;
    }
    
    .component-list {
        grid-template-columns: 1fr;
    }
    
    #setupCanvas {
        height: calc(100vh - 60px);
    }
}