/* General Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: Arial, sans-serif;
    background-color: white;
    padding: 20px;
    overflow-x: hidden; /* Prevent horizontal scrolling */
    width: 100%;
    max-width: 100vw; /* Ensure body doesn't exceed viewport width */
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 15px;
    overflow-x: hidden; /* Prevent horizontal scrolling within containers */
}

h2 {
    color: #333;
}

/* Button Styles */
.btn {
    text-align: center;
    display: block;
    width: 100%;
    margin-top: 10px;
}

.btn-primary {
    width: auto;
    font-size: 0.75em;
    padding: 8px 15px;
}

/* Specifically target the Add New Product button */
a.btn-primary {
    font-size: 0.9em;
    padding: 6px 12px;
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Form Styles */
#filterForm .form-control,
#filterForm .form-select {
    width: 100%;
    margin-bottom: 10px;
}

/* Table Styles */
.table-wrapper {
    width: 100%;
    overflow-x: auto; /* Allow horizontal scrolling only within tables if needed */
    -webkit-overflow-scrolling: touch; /* Better scrolling on iOS */
}

table {
    width: 100%;
    border-collapse: collapse;
}

.table {
    table-layout: fixed; /* Fixed table layout to control cell widths */
    width: 100%;
}

.table thead {
    background-color: #f8f9fa;
}

.table th,
.table td {
    text-align: left;
    padding: 10px;
    border: 1px solid #dee2e6;
    word-wrap: break-word; /* Allow text to wrap within cells */
    overflow-wrap: break-word;
}

.table th {
    font-weight: bold;
    background-color: #e9ecef;
}

.table td button {
    width: 100%;
}

/* Responsive images */
img {
    max-width: 100%;
    height: auto;
}

/* Modal adjustments */
.modal-dialog {
    margin: 1.75rem auto;
    max-width: 90%;
}

.modal-content {
    width: 100%;
}

/* 📌 📌 MOBILE-FIRST DESIGN 📌 📌 */
@media (max-width: 768px) {
    /* Ensure the mobile view for delete and edit buttons */
    .desktop {
        display: none;
    }
    
    .mobile {
        display: block;
        width: 100%;
        overflow-x: hidden;
    }
    
    .btn-group-sm>.btn, .btn-sm {
        padding: .65rem .10rem;
        font-size: .875rem;
        border-radius: .2rem;
    }

    .btn-edit,
    .btn-delete {
        width: 100%; /* Make buttons full width on mobile */
        padding: 12px;
        font-size: 1em;
        display: block;
        margin-top: 10px;
    }

    /* Style the edit button (orange) */
    .btn-edit {
        background-color: orange;
        color: white;
        border: none;
        border-radius: 5px;
        text-align: center;
    }

    /* Style the delete button (red) */
    .btn-delete {
        background-color: red;
        color: white;
        border: none;
        border-radius: 5px;
        text-align: center;
    }

    /* Keep other mobile-specific styles for layout and buttons */
    .table thead {
        display: table-header-group;
    }

    .table tr {
        display: block;
        margin-bottom: 10px;
        border: 1px solid #ddd;
        padding: 10px;
        border-radius: 5px;
        background: #fff;
        width: 100%;
    }

    .table td {
        display: block;
        padding: 10px;
        border-bottom: 1px solid #ddd;
        width: 100%;
    }

    .table td::before {
        content: attr(data-label);
        font-weight: bold;
        text-align: left;
        display: inline-block;
        width: 40%;
        padding-right: 10px;
    }

    .table td span {
        text-align: right;
        display: inline-block;
        width: 60%;
    }

    .table td:last-child {
        border-bottom: none;
    }

    .btn {
        width: 100%;
    }

    /* Improve mobile modal */
    .modal-dialog {
        max-width: 95%;
        margin: 10px auto;
    }

    .modal-content {
        padding: 10px;
    }

    .product-images img,
    .business-card-images img {
        width: 100%;
        max-width: 100%;
        height: auto;
    }
    
    /* Form controls for mobile */
    .form-control, .form-select {
        width: 100%;
    }
    
    /* Row and column fixes for small screens */
    .row {
        margin-left: 0;
        margin-right: 0;
    }
    
    .col-12 {
        padding-left: 0;
        padding-right: 0;
    }
}


/* 📌 📌 DESKTOP/LAPTOP DESIGN 📌 📌 */
@media (min-width: 769px) {
    /* Make sure laptop/desktop view displays */
    .mobile {
        display: none;
    }
    
    .desktop {
        display: block;
        width: 100%;
    }

    /* Desktop/Tablet adjustments */
    .table-wrapper {
        margin-top: 20px;
        overflow-x: auto;
    }

    .btn-primary {
        width: auto;
    }

    /* Align filter section with more space on larger screens */
    #filterForm .form-control,
    #filterForm .form-select {
        width: auto;
    }

    /* Reset table styling for larger screens */
    .table td,
    .table th {
        text-align: center;
        padding: 12px;
    }

    /* Remove mobile table block layout */
    .table tr {
        display: table-row;
    }

    /* Reset any mobile-specific styles on table cells */
    .table td::before {
        content: none;
    }

    /* Adjust image views for larger screens */
    .product-images img,
    .business-card-images img {
        max-width: 100%;
        height: auto;
    }
    
    /* Set specific column widths for better control */
    .table th:nth-child(1), .table td:nth-child(1) { width: 20%; } /* Product Name */
    .table th:nth-child(2), .table td:nth-child(2) { width: 10%; } /* Category */
    .table th:nth-child(3), .table td:nth-child(3) { width: 15%; } /* Supplier */
    .table th:nth-child(4), .table td:nth-child(4) { width: 10%; } /* Price RMB */
    .table th:nth-child(5), .table td:nth-child(5) { width: 10%; } /* Price USD */
    .table th:nth-child(6), .table td:nth-child(6) { width: 10%; } /* Retail Price */
    .table th:nth-child(7), .table td:nth-child(7) { width: 10%; } /* Images */
    .table th:nth-child(8), .table td:nth-child(8) { width: 15%; } /* Actions */
}