/* Factory Layout System */
.factory-container {
    display: flex;
    height: 100vh;
    background: var(--primary-bg);
    overflow: hidden;
}

.factory-canvas-container {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: linear-gradient(135deg, #2a1a3a 0%, #1a1025 100%);
    border-right: 2px solid rgba(155, 89, 182, 0.2);
}

.factory-sidebar {
    width: 320px;
    background: var(--secondary-bg);
    border-left: 2px solid rgba(155, 89, 182, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.factory-sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.factory-sidebar-content::-webkit-scrollbar {
    width: 8px;
}

.factory-sidebar-content::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
}

.factory-sidebar-content::-webkit-scrollbar-thumb {
    background: rgba(155, 89, 182, 0.3);
    border-radius: 4px;
}

.factory-sidebar-content::-webkit-scrollbar-thumb:hover {
    background: rgba(155, 89, 182, 0.5);
}

.factory-sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(155, 89, 182, 0.2);
    background: rgba(0, 0, 0, 0.3);
}

/* Sidebar Sections */
.sidebar-section {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.sidebar-section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--accent-purple);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(155, 89, 182, 0.2);
}

.sidebar-section-content {
    display: grid;
    gap: 0.5rem;
}

/* Component Palette */
.component-palette {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.component-palette h3 {
    display: none;
}

.tool-selector {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 0rem;
}

.tool-button {
    padding: 0.6rem 0.75rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(155, 89, 182, 0.3);
    border-radius: 6px;
    color: var(--text-light);
    cursor: pointer;
    transition: var(--transition);
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    white-space: nowrap;
}

.tool-button:hover {
    background: rgba(255, 255, 255, 0.12);
    border-color: var(--accent-purple);
}

.tool-button.active {
    border-color: var(--accent-purple);
    background: rgba(155, 89, 182, 0.25);
    color: #fff;
}

.palette-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.6rem;
}

.palette-item {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(155, 89, 182, 0.2);
    border-radius: 8px;
    padding: 0.7rem;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    min-height: 80px;
    justify-content: center;
}

.palette-item:hover {
    background: rgba(255, 255, 255, 0.10);
    border-color: var(--accent-purple);
}

.palette-item.selected {
    border-color: var(--accent-purple);
    background: rgba(155, 89, 182, 0.3);
    box-shadow: 0 0 12px rgba(155, 89, 182, 0.2);
}

.palette-icon {
    font-size: 1.8rem;
    line-height: 1;
}

.palette-name {
    color: var(--text-light);
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1.1;
}

.palette-cost {
    color: var(--text-muted);
    font-size: 0.7rem;
}

/* Peers Panel */
.peers-panel {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.peers-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.peers-list-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    border: 1px solid rgba(155, 89, 182, 0.15);
    color: var(--text-light);
    font-size: 0.9rem;
}

.peers-list-item img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(155, 89, 182, 0.3);
}

.peers-list-empty {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    padding: 1rem 0;
}

/* Factory Controls */
.factory-controls {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 10;
    display: flex;
    gap: 0.5rem;
}

.mode-toggle {
    background: var(--accent-purple);
    color: white;
    border: none;
    padding: 0.6rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--transition);
    box-shadow: 0 2px 8px rgba(155, 89, 182, 0.2);
}

.mode-toggle:hover {
    background: var(--accent-pink);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(155, 89, 182, 0.3);
}

.mode-toggle:active {
    transform: translateY(0);
}

/* Return to Village Button */
.return-to-village-btn {
    width: 100%;
    padding: 0.8rem;
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.2), rgba(46, 204, 113, 0.2));
    border: 1px solid rgba(52, 152, 219, 0.3);
    color: var(--text-light);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.return-to-village-btn:hover {
    background: linear-gradient(135deg, rgba(52, 152, 219, 0.3), rgba(46, 204, 113, 0.3));
    border-color: var(--accent-blue);
    transform: translateY(-1px);
}

/* Modal Styles */
.modal-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal-content {
    background: var(--secondary-bg);
    padding: 2rem;
    border-radius: 12px;
    border: 1px solid rgba(155, 89, 182, 0.3);
    width: 90%;
    max-width: 500px;
    position: relative;
    box-shadow: 0 0 30px rgba(155, 89, 182, 0.3);
    animation: fadeIn 0.3s ease-out;
    max-height: 80vh;
    overflow-y: auto;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    transition: var(--transition);
}

.modal-close-btn:hover {
    color: var(--text-light);
}

#modal-body h3 {
    margin-bottom: 1.5rem;
    color: var(--text-light);
    font-size: 1.2rem;
}

/* Filter Config Form */
.filter-config-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.filter-config-form .form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-config-form label {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
}

.filter-config-form input[type="range"],
.filter-config-form select {
    width: 100%;
    padding: 0.6rem;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(155, 89, 182, 0.3);
    border-radius: 6px;
    color: var(--text-light);
    font-size: 0.9rem;
}

.filter-config-form input[type="range"]:focus,
.filter-config-form select:focus {
    outline: none;
    border-color: var(--accent-purple);
    box-shadow: 0 0 8px rgba(155, 89, 182, 0.2);
}

.properties-panel h3 {
    text-align: center;
    border-bottom: 2px solid var(--accent-purple);
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.section-title {
    font-size: 0.8rem;
    font-weight: bold;
    color: var(--text-muted);
    text-transform: uppercase;
    margin: 15px 0 10px;
}

.node-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    max-width: 260px;
    margin: 0 auto;
}

.node-toggle {
    width: 80px;
    height: 40px;
    border: none;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s;
}

.node-center {
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    font-weight: bold;
}

.btn-blue { background: #3498db; color: white; }
.btn-green { background: #2ecc71; color: white; }
.btn-gray { background: #555; color: #aaa; }

.modal-footer {
    margin-top: 25px;
    display: flex;
    justify-content: center;
}

.primary-btn {
    padding: 10px 25px;
    background: var(--accent-purple);
    color: white;
    border: none;
    border-radius: 6px;
    font-weight: bold;
    cursor: pointer;
}

.filter-config-form .toggle-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    padding: 1rem;
    border-radius: 6px;
    border: 1px solid rgba(155, 89, 182, 0.2);
}

.filter-config-form .toggle-group label {
    margin: 0;
}

.filter-config-form .toggle-group input[type="checkbox"],
.filter-config-form .toggle-group input[type="radio"] {
    width: auto;
    cursor: pointer;
}

/* Responsive adjustments */
@media (max-width: 1024px) {
    .factory-sidebar {
        width: 280px;
    }

    .palette-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .factory-container {
        flex-direction: column;
    }

    .factory-canvas-container {
        flex: 1;
        border-right: none;
        border-bottom: 2px solid rgba(155, 89, 182, 0.2);
    }

    .factory-sidebar {
        width: 100%;
        height: 200px;
        border-left: none;
    }
}