/* Builder Layout */

/* Loader */
#builder-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #f5f5f5;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.spinner-blue-only {
    border-color: var(--zemond-primary);
}

/* Full width wrapper with padding */
.builder-wrapper {
    width: 98%;
    max-width: 1800px;
    margin: 0 auto;
    padding: 10px;
    transition: opacity 0.5s ease-in;
}

.builder-controls {
    margin: 10px 0;
    padding: 10px;
    background: #f1f1f1;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.control-label {
    margin-right: 10px;
    font-weight: 600;
    white-space: nowrap;
}

.size-btn {
    margin: 0 2px;
}

.size-btn.active {
    background-color: var(--zemond-accent) !important;
    box-shadow: inset 0 3px 5px rgba(0,0,0,0.2);
}

.builder-container {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch; 
}

/* Product Library */
.product-library {
    background: #fff;
    padding: 0; /* Ensure NO padding here so it hits the edge of the column */
    border-radius: 4px;
    height: calc(100vh - 180px); 
    min-height: 600px;
    overflow: hidden; 
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 80px; 
    box-shadow: 0 2px 2px 0 rgba(0,0,0,0.14), 0 3px 1px -2px rgba(0,0,0,0.12), 0 1px 5px 0 rgba(0,0,0,0.2);
}

/* Header for Library (Material Card Header Style) */
.library-header {
    padding: 0 16px; 
    background-color: #fafafa;
    border-bottom: 1px solid #eee;
    display: flex;
    align-items: center;
    height: 64px; 
    min-height: 64px; 
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    z-index: 2;
}

.library-header h6 {
    margin: 0;
    font-weight: 600;
    font-size: 1.1rem;
    color: #333;
    flex-grow: 1;
    text-align: center;
    letter-spacing: 0.5px;
    line-height: 64px; 
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.library-header .back-btn {
    margin-right: 8px;
    color: #666;
    cursor: pointer;
    border: none;
    background: none;
    width: 40px; 
    height: 40px;
    border-radius: 50%;
    transition: background-color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0; 
}

.library-header .back-btn:hover {
    background-color: rgba(0,0,0,0.05);
    color: var(--zemond-primary);
}

.library-header .back-placeholder {
    width: 40px; 
}


/* Library Content Scroll Area */
.library-content {
    padding: 0;
    overflow-y: auto;
    flex: 1;
}


/* Mobile Adjustment for Library */
@media only screen and (max-width: 600px) {
    .product-library {
        height: 350px; 
        min-height: auto;
        position: relative;
        top: 0;
        margin-bottom: 20px;
    }
    
    .builder-controls {
        justify-content: center;
    }
    
    .control-label {
        display: block;
        width: 100%;
        text-align: center;
        margin-bottom: 5px;
    }
    
    #export-btn {
        margin-top: 10px;
    }
}

/* Category Grid Styling */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); 
    gap: 10px;
    margin-top: 10px;
    padding: 10px; /* Add padding back to content grid so it's not flush with edge */
}

.category-tile {
    background: #f9f9f9;
    border: 1px solid #eee;
    border-radius: 8px;
    aspect-ratio: 1 / 1; 
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, background-color 0.2s, box-shadow 0.2s;
}

.category-tile:hover {
    background-color: #e3f2fd; 
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    border-color: #bbdefb;
}

.category-tile i {
    font-size: 2.5rem; 
    color: var(--zemond-primary);
    margin-bottom: 5px;
}

.category-tile .cat-name {
    font-size: 0.8rem; 
    text-align: center;
    font-weight: 600;
    line-height: 1.1;
    color: #555;
    padding: 0 2px;
}


.library-items-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); 
    gap: 10px;
    padding: 10px; /* Add padding back to content grid */
}

/* Draggable Product Card */
.draggable-item {
    width: 100%; 
    aspect-ratio: 1/1; 
    height: auto; 
    border: 1px solid #ddd;
    border-radius: 8px; 
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    cursor: pointer; 
    background: #fff;
    font-size: 0.75rem;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    transition: transform 0.2s, box-shadow 0.2s, border-color 0.2s;
    overflow: hidden; 
    touch-action: none;
    position: relative;
}

/* Selected State (Click to Select) */
.draggable-item.selected-product {
    border: 2px solid var(--zemond-accent);
    box-shadow: 0 0 8px rgba(0, 176, 255, 0.4);
    background-color: #e1f5fe; 
    transform: scale(1.05);
}

.draggable-item.selected-product::after {
    content: 'check';
    font-family: 'Material Icons';
    position: absolute;
    top: 0;
    right: 0;
    background: var(--zemond-accent);
    color: white;
    font-size: 14px;
    padding: 3px;
    border-radius: 0 0 0 4px;
}


.draggable-item:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}

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

.draggable-item i {
    font-size: 2.5rem; 
    margin-bottom: 5px;
    color: var(--zemond-primary);
}

.draggable-item img.product-thumb {
    width: 60%; 
    height: 60%;
    object-fit: contain;
    margin-bottom: 5px;
}

.product-name {
    display: block;
    width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding: 0 4px;
    font-weight: 500;
}

/* Virtual Machine */
.machine-frame {
    background: #222;
    padding: 10px; 
    border-radius: 10px 10px 0 0;
    border: 4px solid #444;
    border-bottom: none;
    
    height: calc(100vh - 180px);
    min-height: 600px;
    
    position: relative;
    display: flex;
    flex-direction: column;
}

.machine-glass {
    background: rgba(255, 255, 255, 0.95);
    border-radius: 4px;
    padding: 10px; 
    flex: 1; 
    display: flex;
    flex-direction: column;
    overflow: hidden; 
}

#machine-shelves {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1%; 
    margin-bottom: 15px;
    justify-content: space-between; 
}

.machine-shelf {
    display: grid;
    gap: 4px;
    background: #ddd;
    padding: 4px;
    border-radius: 2px;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.1);
    height: 15.5%; 
}

/* Slot Styling */
.machine-slot {
    background: #fff;
    border: 1px dashed #bbb;
    
    height: 100%; 
    width: 100%;
    
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    color: #999;
    position: relative;
    transition: background-color 0.2s, border-color 0.2s, opacity 0.2s, box-shadow 0.2s;
    overflow: hidden;
    touch-action: manipulation; 
    cursor: pointer;
}

/* Pulse animation for successful placement */
@keyframes pulseGreen {
    0% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(76, 175, 80, 0); }
    100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0); }
}

.machine-slot.filled-pulse {
    animation: pulseGreen 0.5s;
    border-color: #4CAF50;
}

/* Mobile Specific Adjustments */
@media only screen and (max-width: 992px) {
    .machine-frame, .product-library {
        height: auto; 
        min-height: 500px;
    }
}

@media only screen and (max-width: 600px) {
    .machine-frame {
        padding: 5px;
        min-height: 400px;
    }
    .machine-slot {
        min-height: 40px;
    }
    .slot-image {
        max-height: 25px !important;
    }
    .capacity-badge {
        font-size: 0.5rem;
        padding: 0 2px;
    }
    .slot-label {
        font-size: 0.5rem;
    }
}

/* Highlight Logic */
.machine-slot.highlight-valid {
    background-color: rgba(255, 255, 255, 1);
    border-color: var(--zemond-accent);
    border-style: solid;
    box-shadow: 0 0 5px rgba(0, 176, 255, 0.3);
}

.machine-slot.highlight-invalid {
    opacity: 0.3; 
    background-color: #eee;
    border-style: dashed;
    border-color: #ccc;
    pointer-events: none; 
}

.machine-slot.drag-over {
    background-color: #e0f7fa !important; 
    transform: scale(1.02);
    z-index: 5;
}

.machine-slot .slot-content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #fff;
    z-index: 2;
}

/* Capacity Badge */
.capacity-badge {
    position: absolute;
    bottom: 1px;
    right: 1px;
    font-size: 0.6rem;
    color: #bbb;
    border: 1px solid #eee;
    padding: 0 3px;
    border-radius: 2px;
    background: rgba(255,255,255,0.8);
}

.filled-badge {
    background: var(--zemond-primary);
    color: #fff;
    border: none;
}

/* Slot Images */
.slot-image {
    max-width: 90%;
    max-height: 60%; 
    object-fit: contain;
    margin-bottom: 2px;
}

.machine-slot.filled {
    border: 1px solid #ccc;
    background: #fff;
}

.machine-slot .remove-btn {
    position: absolute;
    top: 0;
    right: 0;
    cursor: pointer;
    color: #f44336;
    font-size: 14px;
    display: none;
    z-index: 10;
    background: rgba(255,255,255,0.8);
    border-radius: 0 0 0 4px;
}

.machine-slot:hover .remove-btn {
    display: block;
}

.machine-bottom-panel {
    height: 50px;
    background: #333;
    border-radius: 0 0 4px 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: auto;
}

.delivery-bin {
    width: 60%;
    height: 30px;
    background: #111;
    border: 2px solid #555;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #666;
    font-weight: bold;
    letter-spacing: 2px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
    user-select: none;
}

.delivery-bin:active {
    transform: scale(0.95);
    background-color: #222;
}
.delivery-bin:hover {
    background-color: #1a1a1a;
    border-color: #777;
}

/* Animations */
@keyframes popIn {
    0% { transform: scale(0.8); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.slot-content {
    animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
