:root {
    --primary-color: rgb(51, 152, 219);
    --primary-color-dark: #287eb8;
    --danger-color: #e74c3c;
    --danger-color-dark: #c0392b;
    --text-color: #333;
    --bg-color: #f1f1f1;
    --header-bg: #2c3e50;
    --white: #fff;
    --gray-light: #ecf0f1;
    --gray-dark: #7f8c8d;
    --yellow: #f39c12;
}

/* Base Styles */
body {
    font-family: 'Arial', sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 20px;
    line-height: 1.6;
    scroll-behavior: smooth;
}

html, body {
    height: 100%;
    margin: 0;
    display: flex;
    flex-direction: column;
}

header {
    background-color: var(--primary-color);
    color: var(--white);
    padding: 20px 0;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

h1 {
    margin: 0;
    font-size: 40px;
}

main {
    padding: 2rem 1.25rem;
    max-width: 100%;
    flex: 1;
}

h3, h4 {
    margin-bottom: 15px;
    color: var(--text-color);
}

/* Form Styles */
form {
    display: flex;
    flex-wrap: wrap;
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

form div {
    flex: 1 1 200px;
    min-width: 150px;
    display: flex;
    flex-direction: column;
}

input[type="text"],
input[type="number"] {
    padding: 0.625rem;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 1rem;
    width: 100%;
    box-sizing: border-box;
}

select{
    padding: 0.625rem;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 1rem;
    width: 100%;
    box-sizing: border-box;
}

form button {
    margin-top: 1.5rem;
    align-self: flex-start;
}

/* General Buttons */
button {
    padding: 0.75rem 1.25rem;
    background-color: var(--primary-color);
    color: var(--white);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.3s ease, transform 0.2s ease;
    font-size: 1rem;
    width: auto;
    max-width: 100%;
}

button:hover {
    background-color: var(--primary-color-dark);
    transform: translateY(-3px);
}

.delete-btn {
    background-color: var(--danger-color);
    padding: 0.75rem 1.25rem;
    border-radius: 6px;
    font-size: 1.1rem;
    transition: background-color 0.3s ease, transform 0.2s ease;
    text-align: center;
    display: inline-block;
    cursor: pointer;
    width: auto;
    margin: 0;
}

.delete-btn:hover {
    background-color: var(--danger-color-dark);
    transform: scale(1.05);
}

/* Layout Buttons */
#button-parm,
#reset-table,
#go-to-cart,
#confirm-order,
#go-back,
#download-table {
    margin: 0.5rem 0.625rem 0.625rem 0;
}

/* Containers */
#search-container,
#filter-container,
#cart-list {
    background-color: var(--white);
    padding: 1.5rem;
    border-radius: 8px;
    margin-bottom: 2rem;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

#filter-container #filter-form button#button-filtre {
    margin-top: 31px; /* Reduced space between button and input fields */
}

.wrapper {
    width: 100%;
    margin-inline: auto;
}

/* Table Styles */
table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1.25rem;
    background-color: var(--white);
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

#product-table thead {
    position: sticky;
    top: 0;
    background-color: var(--header-bg) !important;
    z-index: 2;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    padding: 1rem 1.5rem; /* Increased padding for more space */
    text-align: center; /* Ensure text is centered */
}

#product-table thead th {
    background-color: var(--header-bg);
    color: var(--white);
}

th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

table tr:hover {
    background-color: var(--gray-light);
}

table tr:nth-child(even) {
    background-color: var(--gray-light);
}

table tr:nth-child(odd) {
    background-color: var(--white);
}

table thead tr th:last-child {
    text-align: center;
    width: 90px;
    padding-left: 10px;
}

/* Total Container Styling */
#total-container {
    margin-top: 20px;
    padding: 15px;
    background-color: var(--primary-color);
    color: var(--white);
    border-radius: 6px;
    font-size: 1.5rem;
    text-align: center;
    font-weight: bold;
    width: 100%;
    box-sizing: border-box;
}

/* Table container styling */
#product-table-container {
    position: relative;
    width: 100%;
}

/* Ensure the table has space for the total below */
#product-table {
    width: 100%;
    border-collapse: collapse;
}

#product-table td,
#product-table th {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid #ddd;
}

/* Add extra space for better visual distinction of the last row */
#product-table tfoot {
    text-align: center;
    font-size: 1.2rem;
    background-color: var(--gray-light);
    font-weight: bold;
}

#product-table tfoot td {
    padding-top: 1rem;
    padding-bottom: 1rem;
}

#product-table tfoot td:first-child {
    padding-left: 0;
    padding-right: 0;
    width: 100%;
}

#product-table tfoot td:last-child {
    text-align: right;
}

/* Footer */
footer {
    background-color: var(--primary-color);
    color: var(--white);
    text-align: center;
    padding: 0.75rem 0;
    margin-top: 3rem;
}

/* Low Stock Popup */
#low-stock-popup {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: #fff;
    border: 2px solid #f39c12;
    border-radius: 10px;
    z-index: 10000;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    width: 90vw;
    max-width: 400px;
    max-height: 90vh;
    padding: 1rem;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#low-stock-popup.hidden {
    display: none;
}

.popup-content {
    position: relative;
    padding-top: 1.5rem;
    overflow-y: auto;
    flex: 1 1 auto;
    max-height: 75vh;
}

/* Close Button (X) */
.close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    background: none;
    border: none;
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--danger-color-dark);
    cursor: pointer;
    z-index: 10100;
    line-height: 1;
    padding: 0;
    transition: transform 0.2s ease, color 0.2s ease;
}

.close-btn:hover {
    color: var(--danger-color);
    transform: scale(1.2);
}

/* Low stock list */
.popup-content h4 {
    margin-top: 0;
    color: #e67e22;
    font-size: 1.25rem;
    margin-bottom: 1rem;
}

#low-stock-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#low-stock-list li {
    padding: 0.5rem 0;
    border-bottom: 1px solid #eee;
    color: #333;
    font-size: 1rem;
    word-wrap: break-word;
}

/* Optional button styling */
#low-stock-btn {
    background-color: #f39c12;
    margin-left: 11px;
    border-radius: 6px;
}

#low-stock-btn:hover {
    background-color: #e67e22;
}

/* QR Reader */
#reader {
    width: 100%;
}

#result {
    text-align: center;
    font-size: 1.5rem;
}

.custom-number-wrapper{
    display: flex !important;
}
.increment{
    margin-left: 2%;
}

.decrement{
    margin-right: 2%;
}

@media (max-width: 768px) {
    header h1 {
        font-size: 2.28rem; /* Réduction de la taille du titre pour mobile */
    }

    main {
        padding: 1rem;
        flex: 1;
    }

    form {
        flex-direction: column;
    }

    form div {
        width: 100%;
        height: 50%;
    }

    #filter-container {
        padding: 0.75rem; /* Reduced padding on mobile for compactness */
        gap: 0.5rem; /* Reduced gap between elements inside the filter */
    }

    #filter-container form div {
        margin-bottom: -8rem; /* Reduced space between filter items */
    }

    /* Adjusting input and select sizes and spacing */
    #filter-container input,
    #filter-container select {
        padding: 0.5rem; /* Reduced padding to save space */
        width: 100%; /* Full-width to fit better */
        box-sizing: border-box; /* Ensures inputs fit correctly */
    }

    /* Button Styling */
    #filter-container button {
        padding: 0.75rem;
        font-size: 1rem;
        margin-top: 0.5rem; /* Reduced space between button and input fields */
        width: 100%; /* Button takes full width on mobile */
    }

    #button-parm,
    form button,
    #go-to-cart,
    #confirm-order,
    #go-back,
    #download-table {
        width: 100%;
        margin-top: 0.75rem;
    }

    table {
        width: 100%;
        font-size: 0.75rem; /* Réduction de la taille de la police des éléments du tableau */
        table-layout: fixed;
        border-collapse: collapse;
    }

    thead {
        display: table-header-group;
    }

    th {
        font-size: 0.6rem; /* Petits titres pour les colonnes */
        background-color: var(--header-bg);
        padding: 0.5rem 1rem; /* Less padding for better compactness */
    }

    td {
        font-size: 0.75rem;
    }

    #product-list,
    #cart-list {
        padding: 0.9rem;
    }

    #cart-table {
        width: 100%;
        table-layout: fixed;
        font-size: 0.75rem;
        border-collapse: collapse;
    }

    #cart-table th {
        color: white;
        word-break: keep-all;
        text-align: center;
        width: 40px;
        padding-left: 10px;
        font-size: 8.5px !important;
    }
    
    #cart-table th,
    #cart-table td {
        padding: 0.5rem;
        text-align: center;
        word-wrap: break-word;
        font-size: 11px;
    }
    
    #cart-table th:nth-child(1),
    #cart-table td:nth-child(1) {
        width: 40%; /* Nom */
        text-align: left;
    }
    
    #cart-table th:nth-child(2),
    #cart-table td:nth-child(2),
    #cart-table th:nth-child(3),
    #cart-table td:nth-child(3),
    #cart-table th:nth-child(4),
    #cart-table td:nth-child(4) {
        width: 10%; /* Quantité, Prix, Emplacement */
    }
    
    #cart-table th:nth-child(5),
    #cart-table td:nth-child(5) {
        width: 10%; /* Action button */
    }
    

    table thead tr th:nth-child(4) {
        text-align: center;
        width: 40px;
        padding-left: 10px;
    }

    td:nth-child(2),
    th:nth-child(2) {
        width: 25%;
    }

    td:nth-child(1),
    th:nth-child(1),
    td:nth-child(3),
    th:nth-child(3),
    td:nth-child(4),
    th:nth-child(4),
    td:nth-child(5),
    th:nth-child(5),
    td:nth-child(6),
    th:nth-child(6) {
        width: 12.5% !important; 
    }


    #product-table-container {
        margin-top: 1rem;
    }

    #total-container {
        font-size: 1.2rem;
        padding: 1rem;
    }
    #button-parm,
    #reset-table,
    #go-to-cart,
    #add-product,
    #low-stock-btn,
    #download-table {
        display: block;
        width: 100%;
        margin: 0.4rem 0; /* Small vertical gap between buttons */
        font-size: 1rem;
        box-sizing: border-box;
        text-align: center;
    }

    .custom-number-wrapper {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.3rem;
    }

    .custom-number-wrapper input.cart-quantity {
        width: 50px;
        text-align: center;
        font-size: 1rem;
        -moz-appearance: textfield; /* pour Firefox */
    }

    .custom-number-wrapper button.increment,
    .custom-number-wrapper button.decrement {
        width: 20px;
        height: 20px;
        font-size: 1.2rem;
        padding: 0;
        border: none;
        background: #ccc;
        color: #333;
        border-radius: 5px;
        cursor: pointer;
    }

    .cart-price{
        margin-left: 10px;
    }
}
