body, html {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    height: 100vh;
    background-color: #f4f4f4;
    color: #333;
    overflow: hidden; /* Prevent body scroll */
}
#app {
    display: flex;
    flex-direction: column;
    height: 100%;
}
.tabs {
    display: flex;
    background-color: #333;
    color: white;
    flex-shrink: 0;
    padding: 5px;
    justify-content: space-around;
}
.tab-button {
    flex-grow: 1;
    padding: 10px 5px;
    text-align: center;
    cursor: pointer;
    border: 1px solid #555;
    background-color: #444;
    color: white;
    font-size: 16px;
    border-radius: 5px;
    margin: 0 5px;
    transition: background-color 0.2s, border-color 0.2s;
}
.tab-button:hover {
    background-color: #666;
}
.tab-button.active {
    background-color: #007bff;
    border-color: #007bff;
}
.tab-content {
    flex-grow: 1;
    overflow-y: auto;
}
#home.tab-content, #history.tab-content {
    padding: 20px;
}
#products.tab-content {
    padding: 0;
}
.hidden {
    display: none !important;
}

/* Products Tab Toolbar & Search */
#products-toolbar {
    position: sticky;
    top: 0;
    z-index: 4;
    background-color: #e0e0e0;
    padding: 5px 10px;
    display: flex;
    align-items: center;
    gap: 5px;
    border-bottom: 1px solid #ccc;
}
#products-toolbar button {
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 20px;
    cursor: pointer;
    width: 40px;
    height: 34px;
    display: flex;
    justify-content: center;
    align-items: center;
}
#filter-btn {
    width: auto;
    padding: 0 10px;
    font-size: 16px;
}
.filter-container {
    position: relative;
    display: inline-block;
}
#filter-menu {
    position: absolute;
    top: 100%;
    left: 0;
    background-color: white;
    border: 1px solid #ccc;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.15);
    z-index: 5;
    min-width: 150px;
}
#filter-menu a {
    display: block;
    padding: 10px 15px;
    text-decoration: none;
    color: #333;
}
#filter-menu a:hover {
    background-color: #f0f0f0;
}
#search-bar {
    position: sticky;
    top: 45px; /* Height of toolbar + borders */
    z-index: 3;
    background-color: #f0f0f0;
    padding: 5px 10px;
    display: flex;
    border-bottom: 1px solid #ccc;
}
#search-input {
    flex-grow: 1;
    border: 1px solid #ccc;
    border-radius: 5px;
    padding: 8px;
    font-size: 16px;
}
#clear-search-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    padding: 0 10px;
    color: #666;
}

#products-list {
    list-style-type: none;
    padding: 0;
    margin: 0;
}
.category-group, .subcategory-group {
    margin-bottom: 0;
}
.category-title {
    font-weight: bold;
    color: #334;
    position: sticky;
    top: 45px;
    background-color: #d4eaf7; /* Light blue */
    padding: 10px 20px;
    z-index: 2;
    border-bottom: 1px solid #b8d9ee;
    height: 25px; /* Control height */
    line-height: 25px;
}
#products.search-active .category-title {
    top: 90px; /* toolbar + search bar */
}
.subcategory-title {
    font-weight: bold;
    color: #445;
    position: sticky;
    top: 90px; /* category top + category height */
    background-color: #eaf4fb; /* Lighter blue */
    padding: 8px 20px;
    z-index: 1;
    border-bottom: 1px solid #d4eaf7;
    cursor: pointer;
    display: flex;
    align-items: center;
}
#products.search-active .subcategory-title {
    top: 135px; /* search category top + category height */
}
.subcategory-title::before {
    content: '▼';
    display: inline-block;
    margin-right: 10px;
    font-size: 0.8em;
    transition: transform 0.2s ease-in-out;
    transform-origin: center;
}
.subcategory-group.collapsed > .subcategory-title::before {
    transform: rotate(-90deg);
}
.subcategory-group.collapsed > .product-item {
    display: none;
}
.product-item {
    background-color: white;
    padding: 10px 20px;
    margin-bottom: 1px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    border-bottom: 1px solid #eee;
}
.product-item:hover {
    background-color: #f0f0f0;
}
.product-list-empty-message {
    padding: 20px;
    text-align: center;
    color: #666;
}
.product-reference {
    font-size: 0.8em;
    color: #888;
    margin-right: 10px;
    flex-shrink: 0;
}
.product-description {
    flex-grow: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-right: 10px;
}
.product-stock {
    font-weight: bold;
    margin-left: 10px;
    min-width: 40px; /* Helps align numbers */
    text-align: right;
    flex-shrink: 0;
}
.stock-modified {
    color: #28a745;
}
#history-list {
    list-style-type: none;
    padding: 0;
}
#history-list li {
    background-color: white;
    padding: 10px;
    border-radius: 5px;
    margin-bottom: 5px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
#history-list li:hover {
    background-color: #f0f0f0;
}
.history-text {
    flex-grow: 1;
}
.undo-btn {
    background-color: #ffc107;
    color: black;
    border: none;
    padding: 5px 10px;
    border-radius: 5px;
    cursor: pointer;
    margin-left: 10px;
    flex-shrink: 0;
}
.undo-btn:disabled {
    background-color: #e0e0e0;
    cursor: not-allowed;
}


/* Stock Tab Layout */
#current-product-details .current-category-header {
    font-size: 0.75em;
    color: #666;
}

#current-product-details .current-product-header {
    font-size: 1.5em;
    font-weight: bold;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

#stock.tab-content {
    display: flex;
    flex-direction: column;
    padding: 10px;
    box-sizing: border-box;
}
#current-product-details {
    flex-grow: 1;
    overflow-y: auto;
    background-color: #fff;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
#current-product-details.unknown-barcode-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
}
.unknown-barcode-message {
    font-size: 1.5em;
    font-weight: bold;
    color: #dc3545;
}

#create-new-article-btn {
    display: block;
    width: 100%;
    padding: 15px;
    font-size: 16px;
    color: white;
    background-color: #28a745;
    border: none;
    border-radius: 5px;
    margin-top: 20px;
    text-align: center;
    box-sizing: border-box;
    cursor: pointer;
}

#keyboard-area {
    flex-shrink: 0;
    padding-top: 10px;
}
/* Stock Tab Styles */
#current-product-details p {
    margin: 8px 0;
    font-size: 16px;
}
#current-product-details .detail-label {
    font-weight: bold;
    color: #555;
}
.stock-value-current {
    font-size: 1.2em;
    font-weight: bold;
    color: #28a745;
}
.update-success-message, .change-info-message {
    color: #28a745;
    font-weight: bold;
    margin-top: 10px !important;
}
.info-message {
    color: #007bff; /* Blue for info */
    font-weight: bold;
    margin-top: 10px !important;
    background-color: #e7f3ff;
    padding: 10px;
    border-radius: 5px;
    text-align: center;
}
.change-info-message .old-stock {
    color: #dc3545;
}
.error-message {
    color: #dc3545;
    font-weight: bold;
}
.quantity-wrapper {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-bottom: 10px;
    margin-top: 10px;
}
#quantity-input {
    width: 100%;
    box-sizing: border-box;
    padding: 10px;
    margin-bottom: 0;
    border: 1px solid #ccc;
    border-radius: 5px;
    text-align: right;
    font-size: 24px;
    font-weight: bold;
    flex-grow: 1;
    -moz-appearance: textfield;
}
#quantity-input::-webkit-outer-spin-button,
#quantity-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
#quantity-input.input-error {
    border-color: #dc3545;
}
#quantity-input.input-error::placeholder {
    color: #dc3545;
    opacity: 0.8;
}
#clear-quantity-btn {
    padding: 15px;
    width: 50px;
    font-size: 24px;
    font-weight: bold;
    border: none;
    border-radius: 5px;
    background-color: #dc3545;
    color: white;
    cursor: pointer;
    flex-shrink: 0;
    height: 50px;
}

#numpad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    margin-bottom: 5px;
}
#numpad button {
    padding: 10px;
    font-size: 24px;
    font-weight: bold;
    border: none;
    border-radius: 5px;
    background-color: #f9f9f9;
}
#numpad button:disabled {
    background-color: #e0e0e0;
    color: #aaa;
    cursor: not-allowed;
}
#pack-multiplier-btn, #add-pack-btn {
    background-color: #ffc107;
    color: black;
}
#numpad-actions {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
}
#numpad-actions button {
    padding: 15px;
    font-size: 18px;
    border: none;
    border-radius: 5px;
    color: white;
    font-weight: bold;
}
#numpad-actions button:disabled {
    background-color: #cccccc !important;
    cursor: not-allowed;
}
.numpad-action-replace { background-color: #007bff; }
.numpad-action-add { background-color: #28a745; }
.numpad-action-subtract { background-color: #fd7e14; }

#home-buttons-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
}

.home-section button, .file-label {
    padding: 15px;
    font-size: 16px;
    color: white;
    border: none;
    border-radius: 5px;
    text-align: center;
    box-sizing: border-box;
    cursor: pointer;
}
.home-section input[type="file"] {
    display: none;
}
#load-csv-btn { background-color: #007bff; }
#load-url-btn { background-color: #0069d9; }
#save-csv-btn { background-color: #fd7e14; }
#load-example-btn { background-color: #28a745; }
#clear-inventory-btn { background-color: #dc3545; }
#reset-quantities-btn { background-color: #ffc107; color: black; }
#scanner-test-btn { background-color: #17a2b8; }

#inventory-info {
    background-color: white;
    padding: 15px;
    border-radius: 8px;
    margin-bottom: 20px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
#inventory-info p {
    margin: 5px 0;
    font-size: 18px;
}
#inventory-name-display {
    font-weight: bold;
}
#article-count-display {
    color: #555;
}

#version-info {
    text-align: center;
    margin-top: 20px;
    color: #999;
    font-size: 0.8em;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.modal-content {
    background-color: white;
    padding: 20px;
    border-radius: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    box-shadow: none;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}
#scanner-output {
    flex-grow: 1;
    border: 1px solid #ccc;
    border-radius: 5px;
    padding: 10px;
    margin: 15px 0;
    overflow-y: auto;
    background-color: #f9f9f9;
    white-space: pre-wrap;
    word-break: break-all;
    font-family: monospace;
}
.enter-key {
    color: #28a745; /* green */
}
.delay-message {
    color: #dc3545; /* red */
}
.modal-content button {
    width: 100%;
    padding: 10px;
    border: none;
    background-color: #007bff;
    color: white;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
}

/* Mapping Modal Styles */
#mapping-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px 0;
    font-size: 16px;
}
.mapping-row {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    gap: 10px;
}
.mapping-row label {
    font-weight: bold;
    flex-basis: 150px;
    flex-shrink: 0;
    text-align: right;
    padding-right: 10px;
}
.mapping-row select {
    flex-grow: 1;
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #ccc;
    font-size: 1em;
    background-color: #fff;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
}
.modal-actions button {
    width: auto;
    padding: 12px 20px;
    font-weight: bold;
}
#mapping-cancel-btn {
    background-color: #6c757d;
}
#mapping-confirm-btn {
    background-color: #28a745;
}


/* Confirmation Modal */
.modal-dialog {
    background-color: white;
    padding: 30px;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.2);
    text-align: center;
}
#confirm-message, #prompt-message {
    font-size: 18px;
    margin-top: 0;
    margin-bottom: 25px;
}
#confirm-buttons {
    display: flex;
    justify-content: space-around;
    gap: 15px;
}
#confirm-buttons button {
    flex-grow: 1;
    padding: 12px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    width: auto;
}
.confirm-btn-confirm {
    background-color: #dc3545; /* Red for destructive actions */
    color: white;
}
.confirm-btn-cancel {
    background-color: #6c757d;
    color: white;
}

/* Prompt Modal */
#prompt-input {
    width: 100%;
    padding: 10px;
    margin: 15px 0;
    box-sizing: border-box;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 16px;
}
#prompt-buttons {
    display: flex;
    justify-content: space-around;
    gap: 15px;
}
#prompt-buttons button {
    flex-grow: 1;
    padding: 12px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    width: auto;
}
#prompt-buttons #prompt-confirm-btn {
    background-color: #007bff;
    color: white;
}
#prompt-buttons #prompt-cancel-btn {
    background-color: #6c757d;
    color: white;
}

/* Fullscreen Modal */
#fullscreen-buttons button {
    width: 100%;
    padding: 15px;
    font-size: 18px;
    font-weight: bold;
    cursor: pointer;
    border: none;
    border-radius: 5px;
    background-color: #007bff;
    color: white;
}

.fullscreen-test-link {
    display: block;
    margin-top: 15px;
    font-size: 14px;
    color: #6c757d;
    text-decoration: underline;
    cursor: pointer;
}


@keyframes highlight-update {
    0% {
        background-color: rgba(0, 86, 179, 0.3);
    }
    50% {
        background-color: rgba(0, 86, 179, 1);
    }
    100% {
        background-color: rgba(0, 86, 179, 0.3);
    }
}
.product-item.highlight-update {
    animation: highlight-update 2s linear;
}