body {
    font-family: sans-serif;
    margin: 0;
    padding: 10px;
    background-color: #f4f4f4;
    color: #333;
}

#login-container, #app-container {
    max-width: 100%;
    margin: 20px auto;
    padding: 10px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

h1, h2 {
    color: #333;
    text-align: center;
    margin-bottom: 20px;
}

/* Login Form */
#login-form div {
    margin-bottom: 15px;
}

#login-form label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

#login-form input[type="text"],
#login-form input[type="password"] {
    width: calc(100% - 22px); /* Account for padding and border */
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

#login-form button {
    padding: 10px 20px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
}

#login-form button:hover {
    background-color: #0056b3;
}

.error-message {
    color: #dc3545;
    margin-top: 10px;
    font-size: 0.9em;
}

/* App Container */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eee;
    padding-bottom: 15px;
    margin-bottom: 20px;
}

header h1 {
    margin: 0;
    font-size: 1.8em;
    text-align: left;
}

nav .nav-btn {
    margin-left: 10px;
    padding: 8px 15px;
    background-color: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 4px;
    cursor: pointer;
}

nav .nav-btn.active {
    background-color: #007bff;
    color: white;
    border-color: #007bff;
}

nav .nav-btn:hover:not(.active) {
    background-color: #e2e6ea;
}

/* Search and Controls */
#search-sort-controls {
    margin-bottom: 20px;
    display: flex;
    gap: 15px;
}

#search-input {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    flex-grow: 1; /* Take available space */
}

/* Data Tables */
#data-display {
    margin-bottom: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

th, td {
    border: 1px solid #ddd;
    padding: 10px 12px;
    text-align: left;
    vertical-align: top; /* Align content to top */
    font-size: 0.95em;
}

th {
    background-color: #f2f2f2;
    font-weight: bold;
    cursor: pointer; /* Indicate sortable columns */
    position: relative; /* For sort indicators */
}

th .sort-indicator {
    font-size: 0.8em;
    margin-left: 5px;
    color: #888;
}

th.sorted-asc .sort-indicator::after {
    content: ' ▲';
}

th.sorted-desc .sort-indicator::after {
    content: ' ▼';
}


tbody tr:nth-child(even) {
    background-color: #f9f9f9;
}

tbody tr:hover {
    background-color: #f1f1f1;
}

td a {
    color: #007bff;
    text-decoration: none;
}

td a:hover {
    text-decoration: underline;
}

/* Pagination */
#pagination-controls {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid #eee;
}

#pagination-controls button,
#pagination-controls select {
    padding: 8px 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background-color: #fff;
    cursor: pointer;
}

#pagination-controls button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

#pagination-controls span {
    font-size: 0.9em;
}

/* --- Detail Page Specific Styles --- */

/* Container for detail pages */
.container { /* General container used on detail pages */
    max-width: 1000px; /* Allow wider content for details */
    margin: 30px auto;
    padding: 30px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

#order-details, #goods-details {
    margin-top: 20px;
}

/* Style sections within details */
#order-details h2, #goods-details h2 {
    border-bottom: 2px solid #007bff;
    padding-bottom: 10px;
    margin-bottom: 25px;
    margin-top: 10px; /* Add space above main sections */
    font-size: 1.6em;
    color: #0056b3;
}

#order-details h3, #goods-details h3 {
    margin-top: 25px;
    margin-bottom: 15px;
    font-size: 1.3em;
    color: #333;
    border-left: 4px solid #007bff;
    padding-left: 10px;
}

#order-details hr, #goods-details hr {
    border: 0;
    height: 1px;
    background-color: #eee;
    margin: 30px 0;
}

#order-details p, #goods-details p {
    margin-bottom: 12px;
    line-height: 1.6;
    font-size: 1em;
}

#order-details p strong, #goods-details p strong {
    display: inline-block;
    min-width: 120px; /* Align labels */
    font-weight: bold;
    color: #555;
}

/* Style the goods table specifically if needed */
#order-details table {
    margin-top: 20px;
}

/* Style the back link */
.container > a {
    display: inline-block;
    margin-top: 30px;
    padding: 10px 18px;
    background-color: #6c757d;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    transition: background-color 0.2s ease;
}

.container > a:hover {
    background-color: #5a6268;
}

/* Specific styles for goods detail page if needed */
#goods-details .image-container {
    text-align: center;
    margin-bottom: 20px;
}

#goods-details .image-container img {
    max-width: 100%;
    max-height: 300px;
    border: 1px solid #ddd;
    border-radius: 4px;
    padding: 5px;
}

/* --- Responsive Design --- */

/* Medium screens (tablets, smaller desktops) */
@media (max-width: 992px) {
    #login-container, #app-container, .container {
        max-width: 95%;
        padding: 15px;
    }

    header h1 {
        font-size: 1.6em;
    }

    th, td {
        padding: 8px 10px;
        font-size: 0.9em;
    }

    #order-details p strong, #goods-details p strong {
        min-width: 100px; /* Adjust label width */
    }
}

/* Small screens (smartphones) */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    #login-container, #app-container, .container {
        margin: 10px auto;
        padding: 15px;
        box-shadow: none; /* Simpler look on mobile */
        border-radius: 0; /* Full width feel */
    }

    header {
        flex-direction: column; /* Stack header items */
        align-items: flex-start;
        gap: 10px; /* Add space between stacked items */
    }

    header h1 {
        font-size: 1.5em;
        text-align: center; /* Center title when stacked */
        width: 100%;
    }

    nav {
        width: 100%;
        display: flex;
        justify-content: space-around; /* Distribute nav buttons */
    }

    nav .nav-btn {
        margin-left: 0;
        flex-grow: 1; /* Make buttons fill space */
        text-align: center;
    }

    #search-sort-controls {
        flex-direction: column; /* Stack search and controls */
        gap: 15px; /* Increase gap for better separation */
        padding: 15px; /* Add padding for better spacing */
    }

    /* Ensure labels are above inputs */
    #search-sort-controls .form-label {
        margin-bottom: 0.25rem; /* Add small space below label */
    }

    /* Adjust input groups for stacking */
    #search-sort-controls .input-group {
        width: 100%; /* Make input groups take full width */
    }

    /* Adjust specific inputs/selects if needed */
    #search-sort-controls .form-select,
    #search-sort-controls .form-control {
         /* Bootstrap handles width well, remove fixed width calc */
         /* Ensure consistent height if needed */
    }

    /* Style the date range input group specifically */
    #search-sort-controls .input-group input[type="month"] {
        min-width: 100px; /* Prevent date inputs from becoming too small */
    }

     /* Adjust the filter button container */
    #search-sort-controls > div:last-child { /* Target the button's container */
        margin-top: 5px; /* Add some space above the button */
    }

    #filter-btn {
        padding: 0.5rem 1rem; /* Adjust button padding */
    }


    /* Adjust data display for mobile */
    #data-display {
        /* Remove horizontal scroll */
    }

    /* Hide table header on mobile */
    table thead {
        display: none;
    }

    /* Style table rows as cards */
    table, tbody, tr, td {
        display: block;
        width: 100%;
    }

    table tbody tr {
        margin-bottom: 15px;
        border: 1px solid #eee;
        border-radius: 5px;
        padding: 10px;
        background-color: #fff; /* Ensure white background for cards */
        box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    }

    /* Style table cells */
    table tbody td {
        border: none;
        padding: 5px 0; /* Adjust padding */
        white-space: normal; /* Allow text wrapping */
        position: relative;
        min-height: 22px; /* Ensure space even if empty */
        text-align: right; /* Align value to the right */
    }

    /* Add labels using pseudo-elements */
    table tbody td::before {
        content: attr(data-label); /* Use data-label attribute set by JS */
        position: absolute;
        left: 10px;
        width: calc(40% - 20px); /* Width of the label area */
        font-weight: bold;
        text-align: left; /* Align label text to the left */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        color: #555;
    }

    /* Hide specific columns in the orders table on mobile */
    #orders-table tbody td[data-label="进口商日文地址"],
    #orders-table tbody td[data-label="出口商地址"],
    #orders-table tbody td[data-label="黑名单分类"] {
        display: none;
    }

    /* Explicitly hide pagination on mobile, overriding Bootstrap's d-md-flex */
    #pagination-controls {
        display: none !important; /* Ensure it's hidden on mobile for infinite scroll */
    }

    /* Styles for the content *within* pagination controls if they were ever shown stacked */
    #pagination-controls select, #pagination-controls button {
        /* width: 100%; */
        /* text-align: center; */
    }

    /* Detail Page Adjustments */
    .container {
        padding: 20px;
    }

    #order-details h2, #goods-details h2 {
        font-size: 1.4em;
        padding-bottom: 8px;
        margin-bottom: 20px;
    }

    #order-details h3, #goods-details h3 {
        font-size: 1.2em;
        padding-left: 8px;
        margin-bottom: 10px;
    }

    #order-details p strong, #goods-details p strong {
        display: block; /* Stack label and value */
        min-width: auto;
        margin-bottom: 3px;
    }

    /* Adjust order stats for mobile */
    #order-stats {
        flex-direction: column; /* Stack items vertically */
        align-items: flex-start; /* Align items to the start */
        gap: 5px; /* Add space between stacked items */
        padding: 10px; /* Increase padding for better spacing */
        font-size: 0.9em; /* Slightly smaller font */
    }

    #order-stats div {
        width: 100%; /* Make each stat item take full width */
        text-align: left; /* Ensure text is left-aligned */
    }

    /* Sticky header */
    #app-container > header {
        position: -webkit-sticky; /* Safari */
        position: sticky;
        top: 0;
        z-index: 1020; /* Ensure it's above most content, Bootstrap's standard */
        /* background-color: #fff; /* Already has bg-white */
        /* The header stacks on mobile, need to ensure its height is accounted for */
        transform: translateZ(0); /* Hint for hardware acceleration to reduce jitter */
    }

    /* Sticky order stats - only shown in orders view */
    #orders-view #order-stats-container {
        position: -webkit-sticky; /* Safari */
        position: sticky;
        /* Estimate header height. Adjust if necessary. */
        /* Header: p-3 (1rem*2) + h1 (1.5em) + gap (10px) + nav height (~38px) */
        /* Approx: 32 + 24 + 10 + 38 = 104px. Let's use 110px for buffer. */
        top: 0; /* Let's try sticking stats right below header first */
        /* If header is also sticky, stats top should be header's height */
        /* Let's stick header only for now, simpler */
        /* UPDATE: Sticking both. Header top: 0, Stats top: header height */
        /* Recalculating header height on mobile: padding (1rem*2=32px) + h1 (1.5em~24px) + gap (10px) + nav (button height ~38px) = ~104px */
        /* Let's try 105px */
         top: 105px; /* Adjust this value based on actual header height */
        z-index: 1019; /* Below header, above table */
        background-color: #f8f9fa; /* Light background to prevent overlap issues */
        margin-bottom: 0; /* Remove bottom margin when sticky */
        padding-top: 5px; /* Add some padding */
        padding-bottom: 5px;
        border-bottom: 1px solid #dee2e6; /* Add a separator */
        transform: translateZ(0); /* Hint for hardware acceleration to reduce jitter */
    }

     /* Adjust content below sticky elements */
     #orders-view h2 { /* The "订单列表" heading */
        margin-top: 1rem; /* Add some space below sticky stats */
     }
     #goods-view h2 { /* The "商品列表" heading */
         /* No stats here, but header is sticky */
         /* margin-top: 1rem; /* Add space below sticky header if needed */
     }


    .container > a { /* Back button */
        width: calc(100% - 36px); /* Full width button */
        text-align: center;
        margin-top: 20px;
    }

    #goods-details .image-container img {
        max-height: 200px; /* Smaller image on mobile */
    }

    /* Removed specific styles for #order-details table on mobile to use default card styles */
}
