* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f5f5f5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    background: white;
    border-bottom: 1px solid #e0e0e0;
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.logo {
    font-size: 18px;
    font-weight: 600;
    color: #333;
}

.controls {
    display: flex;
    gap: 8px;
}

.btn {
    padding: 6px 14px;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    background: white;
    color: #333;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn:hover {
    background: #f8f8f8;
    border-color: #b0b0b0;
}

.btn.btn-primary {
    background: #007aff;
    color: white;
    border-color: #007aff;
}

.btn.btn-primary:hover {
    background: #0056b3;
    border-color: #0056b3;
}

.btn.btn-danger {
    background: #ff3b30;
    color: white;
    border-color: #ff3b30;
}

.btn.btn-danger:hover {
    background: #d70015;
    border-color: #d70015;
}

.btn.btn-secondary {
    background: #5856d6;
    color: white;
    border-color: #5856d6;
}

.btn.btn-secondary:hover {
    background: #4340c9;
    border-color: #4340c9;
}

.btn.running {
    background: #ff9500;
    border-color: #ff9500;
}

/* Main Layout */
.main-container {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 60px;
    background: white;
    border-right: 1px solid #e0e0e0;
    padding: 12px 8px;
    overflow-y: auto;
}

.component-group {
    margin-bottom: 16px;
}

.group-title {
    font-size: 11px;
    color: #666;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.component-item {
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 8px;
    margin-bottom: 6px;
    cursor: move;
    text-align: center;
    transition: all 0.2s ease;
    position: relative;
}

.component-item:hover {
    border-color: #007aff;
    transform: translateX(2px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.component-item.dragging {
    opacity: 0.5;
}

.component-icon {
    font-size: 16px;
    margin-bottom: 2px;
    font-family: 'Segoe UI Symbol', 'Symbol', sans-serif;
}

.component-name {
    font-size: 9px;
    color: #666;
    display: none;
}

/* Canvas */
.canvas-container {
    flex: 1;
    background: white;
    position: relative;
    overflow: hidden;
}

#canvas {
    width: 100%;
    height: 100%;
    position: relative;
    background: 
        linear-gradient(rgba(200, 200, 200, 0.15) 1px, transparent 1px),
        linear-gradient(90deg, rgba(200, 200, 200, 0.15) 1px, transparent 1px);
    background-size: 20px 20px;
}

/* Gates */
.gate {
    position: absolute;
    background: white;
    border: 1px solid #d0d0d0;
    border-radius: 6px;
    padding: 8px 12px;
    width: 60px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: move;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    z-index: 10;
    user-select: none;
    box-sizing: border-box;
}

.gate:hover {
    border-color: #007aff;
    box-shadow: 0 2px 8px rgba(0,122,255,0.15);
}

.gate.dragging {
    cursor: grabbing !important;
    transform: scale(1.02);
    opacity: 0.9;
}

.gate.selected {
    border-color: #007aff;
    box-shadow: 0 0 0 2px rgba(0,122,255,0.2);
}

.gate-type-AND { color: #007aff; }
.gate-type-OR { color: #34c759; }
.gate-type-NOT { color: #ff9500; }
.gate-type-XOR { color: #af52de; }
.gate-type-NAND { color: #5ac8fa; }
.gate-type-NOR { color: #8e8e93; }

/* Input/Output */
.input-switch {
    position: absolute;
    background: white;
    border: 1px solid #d0d0d0;
    border-radius: 16px;
    padding: 6px 12px;
    width: 60px;
    height: 32px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 500;
    transition: all 0.2s ease;
    z-index: 10;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    box-sizing: border-box;
}

.input-switch:hover {
    border-color: #007aff;
    transform: scale(1.02);
}

.input-switch.on {
    background: #34c759;
    color: white;
    border-color: #34c759;
}

.input-switch.dragging {
    cursor: grabbing !important;
    transform: scale(1.05);
    opacity: 0.8;
}

.input-switch::before {
    content: '●';
    font-size: 8px;
    opacity: 0.5;
    transition: opacity 0.2s ease;
}

.input-switch.on::before {
    opacity: 1;
}

.output-led {
    position: absolute;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 1px solid #d0d0d0;
    background: #f0f0f0;
    transition: all 0.3s ease;
    z-index: 10;
    position: relative;
    box-sizing: border-box;
}

.output-led::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 5px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.8);
    filter: blur(2px);
}

.output-led.on {
    background: #ffcc00;
    border-color: #ff9500;
    box-shadow: 0 0 15px rgba(255, 204, 0, 0.4);
}

.output-led.dragging {
    cursor: grabbing !important;
    transform: scale(1.05);
    opacity: 0.8;
}

/* Connection Points */
.connection-point {
    position: absolute;
    width: 10px;
    height: 10px;
    border: 2px solid white;
    border-radius: 50%;
    cursor: crosshair;
    z-index: 15;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.gate-input {
    background: #007aff;
}

.gate-output {
    background: #ff3b30;
}

.connection-point:hover {
    transform: scale(1.3);
    box-shadow: 0 0 6px rgba(0,0,0,0.2);
}

.connection-point.highlight {
    background: #34c759;
    transform: scale(1.4);
}

/* Wires */
svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.wire {
    stroke: #666;
    stroke-width: 2;
    fill: none;
    transition: stroke 0.2s ease;
}

.wire:hover {
    stroke: #007aff;
    stroke-width: 3;
}

.wire.active {
    stroke: #34c759;
    stroke-width: 2;
}

.wire.temporary-wire {
    stroke: #007aff;
    stroke-width: 2;
    stroke-dasharray: 4,2;
    opacity: 0.7;
    animation: dash 0.5s linear infinite;
}

/* Info Panel */
.info-panel {
    position: absolute;
    top: 16px;
    right: 16px;
    background: white;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    padding: 12px;
    font-size: 11px;
    z-index: 20;
    max-width: 180px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.info-panel h4 {
    margin-bottom: 8px;
    font-size: 12px;
    font-weight: 600;
    color: #333;
    border-bottom: 1px solid #e0e0e0;
    padding-bottom: 4px;
}

.info-item {
    margin: 4px 0;
    color: #666;
    line-height: 1.3;
}

/* Animations */
@keyframes dash {
    to {
        stroke-dashoffset: -6;
    }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-2px); }
    75% { transform: translateX(2px); }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

.gate-creating {
    animation: fadeIn 0.2s ease-out;
}

/* Tooltips */
component-group [title] {
    position: relative;
}

gate [title] {
    position: absolute;
}

.gate:hover::after,
.input-switch:hover::after,
.output-led:hover::after,
.connection-point:hover::after {
    content: attr(title);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 10px;
    white-space: nowrap;
    z-index: 1000;
    pointer-events: none;
    margin-bottom: 4px;
    max-width: 200px;
    text-align: center;
    line-height: 1.3;
}

.gate-input:hover::after {
    left: auto;
    right: 0;
    transform: translateY(-50%);
    bottom: 50%;
    margin-bottom: 0;
    margin-right: 8px;
}

.gate-output:hover::after {
    left: auto;
    left: 0;
    transform: translateY(-50%);
    bottom: 50%;
    margin-bottom: 0;
    margin-left: 8px;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 50px;
    }
    
    .component-name {
        display: none;
    }
    
    .info-panel {
        display: none;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background: #1a1a1a;
    }
    
    .header, .sidebar, .canvas-container {
        background: #2d2d2d;
        border-color: #404040;
    }
    
    .gate, .input-switch, .output-led {
        background: #2d2d2d;
        border-color: #404040;
    }
    
    .btn {
        background: #2d2d2d;
        color: white;
        border-color: #404040;
    }
    
    .btn:hover {
        background: #404040;
    }
}