body {
    margin: 0;
    font-family: Arial, sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    background-color: #3F3F3F;
    padding: 20px;
    box-sizing: border-box;
}

.factory-lines-container {
    display: flex;
    flex-direction: column;
    gap: 20px; /* Space between multiple factory lines */
    width: 100%; /* Take full width to center main-windows */
    align-items: center;
}

.main-window {
    width: calc(100vw - 30px);
    background-color: #fff;
    border: 1px solid #ccc;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    border-radius: 10px;
    /* margin-bottom: 20px; Removed as gap handles spacing */
}

.header-container {
    padding: 10px;
    background-color: #F43535;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    position: relative;
}

.remove-factory-line-btn {
    background-color: transparent;
    border: 1px solid black;
    color: #242424;
    border-radius: 999px;
    cursor: pointer;
    width: 21px;
    height: 21px;
    padding: 0;
    position: absolute;
    top: 5px;
    right: 5px;
    background-image: url('icons/X.svg');
    background-repeat: no-repeat;
    background-position: center;
    background-size: 60%;
}

.remove-factory-line-btn:hover {
    background-color: #da190b;
}

.header {
    margin: 0 10px; /* 10px narrower */
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-bottom: 10px;
}

.edit-icon {
    width: 24px;
    height: 24px;
    margin-right: 10px;
}

.factory-name-input {
    font-size: 2em;
    font-weight: bold;
    border: none;
    background: transparent;
    text-align: left;
    width: 80%;
    outline: none;
    border-bottom: 2px solid black;
}

.material-summary {
    padding: 0 10px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.summary-header {
    display: flex;
    align-items: center;
}

h3 {
    margin: 6px;
}

.send-to-container {
    width: 100%;
    margin-top: 16px;
}

.send-to-dropdown {
    width: 200px;
    height: 30px;
    border-radius: 15px;
    border: 1px solid #ccc;
    padding: 0 10px;
    outline: none;
}

.leftover-list {
    display: flex;
    list-style: none;
    padding: 0;
    margin: 0;
    flex-wrap: wrap;
    margin-left: 10px;
}

.leftover-list li {
    margin-right: 10px;
    display: flex;
    align-items: center;
}

.leftover-list li.received-item img {
    border-radius: 50%;
}

.leftover-list img {
    width: 25px;
    height: 25px;
    vertical-align: middle;
}

.leftover-list span {
    margin-left: 5px;
}

.columns-container {
    flex-grow: 1;
    display: flex;
    overflow-x: auto; /* Enable horizontal scrolling */
    padding: 10px;
    align-items: flex-start; /* Align items to the top */
    border-bottom-left-radius: 10px;
    border-bottom-right-radius: 10px;
    background-color: #E5E5E5;
    border-top: 1px solid #ccc;
}

.column {
    flex-shrink: 0; /* Prevent columns from shrinking */
    width: 315px;
    margin-right: 10px;
    background-color: #f9f9f9;
    border: 1px solid #eee;
    padding: 10px;
    box-sizing: border-box;
    overflow-y: auto; /* Enable vertical scrolling within columns */
    display: flex; /* Make column a flex container */
    flex-direction: column; /* Stack contents vertically */
    justify-content: space-between; /* Push add/remove buttons to top/bottom */
    border-radius: 20px;
    position: relative; /* For positioning the handle */
}

.column-handle {
    width: 100%;
    height: 16px;
    background-color: #ccc;
    cursor: grab;
    margin-bottom: 10px;
    border-radius: 5px;
}

.facility-top-bar {
    position: relative;
    height: 22px; /* Match collapse-btn height */
    margin-bottom: 12px;
}

.collapse-btn {
    width: 204px;
    height: 22px;
    background-color: #ccc;
    cursor: pointer;
    border-radius: 999px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    align-items: center;
}

.column-handle:active {
    cursor: grabbing;
}

.column.dragging {
    opacity: 0.5;
}

.column.drag-over {
    border: 2px dashed #007B9E;
}

.column:last-child {
    margin-right: 0;
}

.facilities-container {
    flex-grow: 1; /* Allows facilities to take up available space */
    min-height: 0px; /* Ensure droppable area even when empty */
}

.add-facility-btn {
    display: block;
    width: 100%;
    padding: 10px;
    background-color: #4CAF50;
    color: white;
    border: none;
    cursor: pointer;
    font-size: 1.2em;
    border-radius: 10px;
}

.add-facility-btn:hover {
    background-color: #45a049;
}

.add-factory-line-btn {
    width: 75%;
    max-width: 1200px;
    padding: 15px;
    background-color: transparent;
    color: #4CAF50;
    border: 2px solid #4CAF50;
    cursor: pointer;
    font-size: 1.5em;
    margin-top: 20px; /* Space from the main window */
    border-radius: 10px;
    transition: background-color 0.3s, color 0.3s;
}

.add-factory-line-btn:hover {
    background-color: #4CAF50;
    color: white;
}

.facility {
    background-color: #fff;
    border: none;
    padding: 12px 10px 10px;
    margin-top: 10px;
    border-radius: 10px;
    position: relative; /* Needed for absolute positioning of the close button */
    transition: height 0.3s ease;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.facility.collapsed {
    height: 130px; /* Adjusted height for new layout */
}

.facility.collapsed .facility-header,
.facility.collapsed .purity-control,
.facility.collapsed .materials-display,
.facility.collapsed .power-display {
    display: none;
}

.facility.collapsed .quantity-control {
    display: none;
}

.facility.collapsed .collapsed-quantity-control {
    display: flex;
}

.collapsed-quantity-control {
    display: none; /* Hidden by default */
}

.facility.collapsed .image-container {
    display: none;
}

.facility.collapsed .collapsed-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.collapsed-info .info-text {
    font-size: 18px;
    padding-left: 20px;
}

.collapsed-info .image-boxes {
    display: flex;
    gap: 10px;
}

.collapsed-info .facility-image-box-collapsed,
.collapsed-info .product-image-box-collapsed {
    width: 54px;
    height: 54px;
    background-color: #eee; /* Placeholder background */
    border: 1px solid #ccc;
    box-sizing: border-box;
    border-radius: 15px; /* Rounded corners */
    background-size: contain; /* Ensure image fits within the box */
    background-repeat: no-repeat;
    background-position: center;
}

.collapsed-info {
    display: none;
}

.collapsed-quantity-control {
    display: none; /* Hidden by default */
    width: 100%;
    margin-top: 10px; /* Space from image boxes */
}

.collapsed-quantity-control .quantity-input {
    width: 45%;
    text-align: center;
    border: 1px solid #ccc;
    border-radius: 0;
    padding: 0; /* Remove padding for exact centering */
    outline: none;
    height: 24px; /* Reduced height */
    box-sizing: border-box;
    font-size: 0.8em; /* Reduced font size */
}

.collapsed-quantity-control .quantity-btn {
    flex-grow: 1;
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    padding: 0 5px; /* Reduced padding */
    cursor: pointer;
    font-size: 0.8em; /* Reduced font size */
    height: 24px; /* Reduced height */
    box-sizing: border-box;
}

.collapsed-quantity-control .quantity-btn.minus {
    border-top-left-radius: 12px; /* Half of height */
    border-bottom-left-radius: 12px;
    margin-right: -1px;
}

.collapsed-quantity-control .quantity-btn.plus {
    border-top-right-radius: 12px;
    border-bottom-right-radius: 12px;
    margin-left: -1px;
}

.image-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px; /* Space between image boxes */
    padding-bottom: 27px; /* 27px space from bottom */
}

.facility-image-box,
.product-image-box {
    width: 35%; /* 35% of facility width */
    padding-bottom: 35%; /* Makes height equal to width for a square box */
    background-color: #eee; /* Placeholder background */
    border: 1px solid #ccc;
    box-sizing: border-box;
    position: relative; /* For content inside if needed */
    border-radius: 15px; /* Rounded corners */
    background-size: contain; /* Ensure image fits within the box */
    background-repeat: no-repeat;
    background-position: center;
}

.facility-header {
    display: flex;
    flex-direction: column;
    align-items: flex-start; /* Align items to the start of the column */
}

.facility-header select {
    width: 100%; /* Make dropdowns take full width */
    margin-bottom: 12px; /* Add some space between them */
    outline: none; /* Remove outline */
    height: 36px;
    border-radius: 18px; /* Max rounding for 36px height */
    border: 1px solid #ccc; /* Add a subtle border back for definition */
    padding: 0 10px; /* Add some padding */
}

.purity-control select {
    width: 100%; /* Make dropdowns take full width */
    margin-bottom: 12px; /* Add some space between them */
    outline: none; /* Remove outline */
    height: 36px;
    border-radius: 18px; /* Max rounding for 36px height */
    border: 1px solid #ccc; /* Add a subtle border back for definition */
    padding: 0 10px; /* Add some padding */
}

.remove-facility-btn {
    background-color: #DDDDDD;
    color: #242424;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    width: 16px;
    height: 16px;
    padding: 0;
    position: absolute;
    top: 0;
    left: calc(50% + 102px + 15px); /* 50% + half of collapse-btn + 18px - 3px */
    background-image: url('icons/X.svg');
    background-repeat: no-repeat;
    background-position: 52% 50%;
    background-size: 54%;
}

.remove-facility-btn:hover {
    background-color: #da190b;
}

.remove-column-btn {
    display: block;
    width: 100%;
    padding: 10px;
    margin-top: 10px; /* Space from add facility button */
    background-color: transparent;
    color: #f44336;
    border: 2px solid #f44336;
    cursor: pointer;
    font-size: 1.2em;
    border-radius: 10px;
    transition: background-color 0.3s, color 0.3s;
}

.remove-column-btn:hover {
    background-color: #f44336;
    color: white;
}

.add-column-btn {
    flex-shrink: 0; /* Prevent from shrinking */
    width: 315px; /* Match column width */
    height: 50px; /* Adjust as needed */
    margin-right: 10px; /* Space from columns */
    background-color: transparent;
    color: #4CAF50;
    border: 2px solid #4CAF50;
    cursor: pointer;
    font-size: 1.2em;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    transition: background-color 0.3s, color 0.3s;
}

.add-column-btn:hover {
    background-color: #4CAF50;
    color: white;
}

.quantity-control {
    display: flex;
    width: 100%; /* Make it span full width */
    margin-bottom: 10px;
}

.quantity-input {
    width: 45%; /* 45% of quantity control width */
    text-align: center;
    border: 1px solid #ccc;
    border-radius: 0; /* Remove rounding */
    padding: 0; /* Remove padding for exact centering */
    outline: none;
    height: 36px; /* Match dropdown height */
    box-sizing: border-box; /* Include padding and border in the element's total width and height */
}

.quantity-btn {
    flex-grow: 1; /* Take remaining space */
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    padding: 0 10px; /* Adjust padding for buttons */
    cursor: pointer;
    font-size: 1em;
    height: 36px; /* Match dropdown height */
    box-sizing: border-box;
}

.quantity-btn.minus {
    border-top-left-radius: 18px; /* Keep rounding on the outside edges */
    border-bottom-left-radius: 18px; /* Keep rounding on the outside edges */
    margin-right: -1px; /* Overlap borders */
}

.quantity-btn.plus {
    border-top-right-radius: 18px; /* Keep rounding on the outside edges */
    border-bottom-right-radius: 18px; /* Keep rounding on the outside edges */
    margin-left: -1px; /* Overlap borders */
}

ul.input-list, ul.output-list {
    padding: 0 20px;
}

ul.input-list li {
    display: flex;
    justify-content: space-between;
}

ul.output-list li {
    display: flex;
    justify-content: space-between;
}

.power-display {
    text-align: center;
    margin-top: 10px;
}

.change-color-btn img {
    width: 15px;
    height: 15px;
}

.change-color-btn {
    background-color: transparent;
    border: 1px solid black;
    border-radius: 4px;
    cursor: pointer;
    width: 21px;
    height: 21px;
    padding: 0;
    position: absolute;
    bottom: 5px;
    right: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.toggle-all-facilities-btn img {
    width: 12px;
    height: 12px;
}

.toggle-all-facilities-btn {
    background-color: transparent;
    border: 1px solid black;
    border-radius: 4px;
    cursor: pointer;
    width: 80px;
    height: 21px;
    padding: 0;
    position: absolute;
    bottom: 5px;
    right: 30px; /* Positioned to the left of change-color-btn (5px + 21px width) */
    display: flex;
    justify-content: center;
    align-items: center;
}

.color-palette {
    display: none;
    position: absolute;
    bottom: 5px;
    right: 30px;
    background-color: white;
    border: 1px solid #ccc;
    border-radius: 5px;
    padding: 5px;
    gap: 5px;
}

.color-swatch {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    cursor: pointer;
}

.color-swatch[data-color="#F43535"] { background-color: #F43535; }
.color-swatch[data-color="#4CAF50"] { background-color: #4CAF50; }
.color-swatch[data-color="#2196F3"] { background-color: #2196F3; }
.color-swatch[data-color="#FFC107"] { background-color: #FFC107; }
.color-swatch[data-color="#9C27B0"] { background-color: #9C27B0; }
.color-swatch[data-color="#FF9800"] { background-color: #FF9800; }
.color-swatch[data-color="#009688"] { background-color: #009688; }
.color-swatch[data-color="#3F51B5"] { background-color: #3F51B5; }
.color-swatch[data-color="#E91E63"] { background-color: #E91E63; }
.color-swatch[data-color="#795548"] { background-color: #795548; }
.color-swatch[data-color="#FF9800"] { background-color: #FF9800; }
.color-swatch[data-color="#009688"] { background-color: #009688; }
.color-swatch[data-color="#3F51B5"] { background-color: #3F51B5; }
.color-swatch[data-color="#E91E63"] { background-color: #E91E63; }
.color-swatch[data-color="#795548"] { background-color: #795548; }

/* Drag and Drop Styles for Facilities */
.facility.dragging {
    opacity: 0.4;
}

.facilities-container.drag-over {
    border: 2px dashed #007B9E;
    background-color: #e0f7fa; /* Light blue background */
}

.send-control {
    margin-top: 5px;
    display: flex;
    flex-direction: column;
}

.send-btn {
    background-color: transparent;
    border: 1px solid #4CAF50;
    color: #4CAF50;
    height: 20px;
    width: 100%;
    transition: background-color 0.3s, color 0.3s;
    padding: 0;
    font-size: 0.8em;
    cursor: pointer;
    border-radius: 5px;
}

.send-btn:hover {
    background-color: #4CAF50;
    color: white;
}

.send-to-dropdown-facility {
    width: 100%;
    height: 30px;
    border-radius: 15px;
    border: 1px solid #ccc;
    padding: 0 10px;
    outline: none;
}

.summary-header h3 {
    margin-right: 10px;
}

.total-power-display {
    font-size: 1em;
    font-weight: normal;
}

.save-load-reset-container {
    display: flex;
    width: 75%;
    max-width: 1200px;
    margin-top: 10px;
    gap: 10px;
}

.save-load-reset-container button {
    flex-grow: 1;
    padding: 15px;
    background-color: transparent;
    color: #4CAF50;
    border: 2px solid #4CAF50;
    cursor: pointer;
    font-size: 1.5em;
    border-radius: 10px;
    transition: background-color 0.3s, color 0.3s;
}

.save-load-reset-container button:hover {
    background-color: #4CAF50;
    color: white;
}

#save-file-display-bar {
    width: 75%;
    max-width: 1200px;
    height: 24px;
    line-height: 24px; /* To vertically center the text */
    background-color: #555;
    color: white;
    text-align: center;
    border-radius: 5px;
    margin-top: 10px;
    font-size: 14px;
}

/* Hide spinners from number inputs */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type=number] {
  -moz-appearance: textfield;
}

.item-usage {
  flex-grow: 1;
  text-align: right;
}

.global-summary-container {
    position: relative; /* Needed for absolute positioning of the button */
    width: calc(100% - 40px);
    max-width: 1200px;
    background-color: #2d2d2d;
    color: white;
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 10px;
    box-sizing: border-box;
}

.global-toggle-all-btn {
    background-color: transparent;
    border: 1px solid white;
    border-radius: 4px;
    cursor: pointer;
    width: 80px;
    height: 21px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 10px auto 0;
}

.global-toggle-all-btn img {
    width: 12px;
    height: 12px;
    filter: invert(1);
}

.global-summary-container h2 {
    margin-top: 0;
    text-align: center;
}

.global-summary-content {
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
}

.global-leftovers {
    flex-basis: 70%;
}

.global-power {
    flex-basis: 30%;
    display: flex;
    flex-direction: column;
}

.power-summary-line {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2px;
}

.power-label {
    text-align: left;
}

.power-value {
    text-align: right;
    font-weight: bold;
}

.global-leftover-list {
    list-style: none;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.global-leftover-list li {
    display: flex;
    align-items: center;
    gap: 5px;
}

.global-leftover-list img {
    width: 25px;
    height: 25px;
}
