body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    background: #f4f4f4;
    color: #333;
    /* Default body background (no image). Background image applied only on login page via .login-page class */
    /* Prevent horizontal scrolling */
    overflow-x: hidden;
}

/* Apply universal box-sizing to simplify responsive layouts */
* {
    box-sizing: border-box;
}

header {
    background: #2c3e50;
    color: #fff;
    padding: 10px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
}

/* Ensure the navigation bar spans full width on its own line below the title */
header nav {
    flex: 1 1 100%;
    margin-top: 10px;
}

/* user indicator at top right */
.user-indicator {
    margin-left: auto;
    color: #fff;
    font-size: 0.9em;
    padding-left: 10px;
}

header h1 {
    margin: 0;
    font-size: 1.5em;
}

nav {
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.nav-btn {
    background: #34495e;
    color: #fff;
    border: none;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 4px;
}

.nav-btn:hover, .nav-btn.active {
    background: #1abc9c;
}

main {
    padding: 20px;
}

.page {
    display: none;
}

.page:not(.hidden) {
    display: block;
}

/* Generic grid layout for forms. Use auto-fit so items wrap nicely and set a small min-width.
   At small widths this will collapse to a single column via media queries. */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    align-items: flex-start;
}

label {
    display: flex;
    flex-direction: column;
    font-size: 0.9em;
}

input[type="text"], input[type="number"], select, textarea {
    padding: 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9em;
}

textarea {
    resize: vertical;
}

button {
    background: #1abc9c;
    color: #fff;
    border: none;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 4px;
    margin-top: 10px;
}

/* Center save order button on CSR page */
#saveOrderBtn {
    display: block;
    margin: 20px auto;
}

button:hover {
    background: #16a085;
}

.filters {
    margin-bottom: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.filters label {
    display: flex;
    flex-direction: column;
    font-size: 0.9em;
}

#dispatchOrdersContainer, #dailyOrdersContainer, #ordersListContainer, #driversListContainer {
    margin-top: 10px;
}

/* Make the orders list scrollable horizontally when many columns are displayed */
#ordersListContainer {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
    /* Prevent wrapping so each data cell stays on one line */
    white-space: nowrap;
}

/* --- Additional sections for deleted driver records and facility/organization editing --- */

/* Container for deleted drivers list on the drivers page */
#deletedDriversContainer {
    margin-top: 15px;
}

/* Controls (select all, restore, delete) inside the deleted drivers container */
#deletedDriversContainer > div {
    margin-bottom: 8px;
    display: flex;
    gap: 10px;
}

/* Basic styling for tables in the deleted drivers container */
#deletedDriversContainer table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
}
#deletedDriversContainer th, #deletedDriversContainer td {
    padding: 6px;
    border: 1px solid #ddd;
    font-size: 0.8em;
}
#deletedDriversContainer th {
    background: #ecf0f1;
    text-align: left;
}

/* Hide edit sections by default; style when visible */
#facilityEditSection, #orgEditSection {
    margin-top: 15px;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #f9f9f9;
}
#facilityEditSection h3, #orgEditSection h3 {
    margin-top: 0;
    font-size: 1.1em;
    margin-bottom: 10px;
}
#facilityEditSection label, #orgEditSection label {
    display: flex;
    flex-direction: column;
    font-size: 0.9em;
    margin-bottom: 8px;
}
#facilityEditSection button, #orgEditSection button {
    margin-right: 8px;
    margin-top: 10px;
}

th, td {
    padding: 8px;
    border: 1px solid #ddd;
    text-align: left;
    font-size: 0.8em;
}

th {
    background: #ecf0f1;
}

.actions button {
    margin-right: 5px;
}

.hidden {
    display: none;
}

.suggestions {
    margin-top: 10px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
    font-size: 0.8em;
}

/* Order info section on CSR page */
.order-info {
    background: #f9f9f9;
    border: 1px solid #ddd;
    padding: 10px;
    margin-bottom: 10px;
    min-height: 50px;
    font-size: 0.85em;
    white-space: normal;
}

.suggestion-item {
    padding: 6px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
}

.suggestion-item:hover {
    background: #ecf0f1;
}

/* Login overlay */
.login-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

/* Loading overlay shown during login transition */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.loading-overlay.hidden {
    display: none !important;
}
.loading-box {
    background: #fff;
    padding: 20px 30px;
    border-radius: 6px;
    font-size: 1.2em;
    color: #333;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Logout link styling */
.logout-link {
    color: #fff;
    margin-left: 10px;
    cursor: pointer;
    text-decoration: underline;
    font-size: 0.9em;
}
.logout-link:hover {
    color: #ecf0f1;
}

/* Apply background image only when body has login-page class */
/* Styles applied when the body has the login-page class (displayed during login). */
.login-page {
    /* Use the custom image uploaded for the login background */
    background-image: url('background.png');
    background-size: cover;
    /* Align the image so that the title portion (長照・交通) at the top remains visible */
    background-position: top center;
    background-repeat: no-repeat;
    /* Ensure the image fills the entire viewport height to prevent blank space */
    min-height: 100vh;
}

/* Hide the main header while on the login page to prevent it from covering the background text */
.login-page header {
    display: none;
}

/* On the login page, position the login overlay lower so it doesn’t cover the title area of the background image */
.login-page .login-overlay {
    align-items: flex-start;
    padding-top: 25vh;
}

/* 隱藏登入背景中的版權資訊並將其移至最底部。只有在登入頁面時套用 */
body.login-page footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    opacity: 0;
}

/* 上下車地點區塊橫向排列 */
.location-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    width: 100%;
}
.location-fields .pickup-group,
.location-fields .dropoff-group {
    flex: 1 1 260px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* enlarge labels and controls on page1 (CSR接單) */
#page1 label {
    font-size: 1em;
}
#page1 input[type="text"], #page1 select, #page1 textarea {
    font-size: 0.95em;
    padding: 8px;
}

/* Hide login overlay when hidden class is added */
.login-overlay.hidden {
    display: none !important;
}

.login-box {
    background: #fff;
    padding: 20px;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 300px;
}

.login-box h2 {
    margin: 0 0 10px;
    font-size: 1.2em;
    text-align: center;
}

/* Page selection overlay styling */
.page-selection-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}
.page-selection-overlay.hidden {
    display: none !important;
}
.selection-box {
    background: #fff;
    padding: 20px;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    width: 80%;
    max-width: 500px;
    text-align: center;
}
.selection-box h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.1em;
}
.selection-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}
.selection-buttons .nav-btn {
    flex: 1 1 150px;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    header {
        flex-direction: column;
        align-items: flex-start;
    }
    nav {
        flex-direction: row;
        flex-wrap: wrap;
        width: 100%;
        margin-top: 10px;
    }
    .form-grid,
    .booking-form,
    .driver-form {
        grid-template-columns: 1fr;
    }
    .location-fields {
        flex-direction: column;
    }
    .location-fields .pickup-group,
    .location-fields .dropoff-group {
        flex: 1 1 100%;
    }
    .login-box {
        width: 90%;
        max-width: 320px;
    }
    .selection-box {
        width: 90%;
    }
}

@media (max-width: 480px) {
    .nav-btn {
        flex: 1 1 100%;
    }
}

/* Booking system (page11) styling */
.booking-form {
    display: grid;
    /* Use a slightly smaller min width so fields wrap on narrow screens */
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    align-items: flex-start;
    margin-top: 10px;
}
.booking-form label {
    display: flex;
    flex-direction: column;
    font-size: 0.9em;
}
.booking-form input,
.booking-form select,
.booking-form textarea {
    padding: 6px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 0.9em;
}
.booking-form textarea {
    resize: vertical;
}

/* Backend orders and client search tables (pages 12 & 13) */
#backendOrdersContainer table,
#clientSearchResults table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
    white-space: nowrap;
    overflow-x: auto;
}
#backendOrdersContainer th, #backendOrdersContainer td,
#clientSearchResults th, #clientSearchResults td {
    padding: 8px;
    border: 1px solid #ddd;
    text-align: left;
    font-size: 0.8em;
}
#backendOrdersContainer th, #clientSearchResults th {
    background: #ecf0f1;
}


.login-box label {
    font-size: 0.9em;
}

/* Driver form in page5 */
.driver-form {
    background: #fff;
    border: 1px solid #ddd;
    padding: 10px;
    border-radius: 4px;
    margin-top: 10px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px;
    align-items: flex-start;
}

.driver-form h3 {
    grid-column: span 2;
    margin: 0 0 10px;
    font-size: 1em;
}

/* Modal overlay for order editing */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

/* Hide modal overlay when it has hidden class */
.modal-overlay.hidden {
    display: none !important;
}

.modal-box {
    background: #fff;
    padding: 20px;
    border-radius: 6px;
    width: 80%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-box h3 {
    margin-top: 0;
    font-size: 1.2em;
    margin-bottom: 10px;
}

.settings-section {
    margin-bottom: 20px;
    background: #fff;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
}

#facilityList, #driverManagementList {
    margin-top: 10px;
}

.facility-item, .driver-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px;
    border-bottom: 1px solid #eee;
    font-size: 0.85em;
}

.facility-item button, .driver-item button {
    margin-left: 5px;
    background: #e74c3c;
    padding: 4px 6px;
    font-size: 0.7em;
    border-radius: 4px;
}

.facility-item button.edit, .driver-item button.edit {
    background: #f39c12;
}

footer {
    text-align: center;
    padding: 10px;
    background: #ecf0f1;
    font-size: 0.8em;
    /* 將版權資訊固定在頁面底部並隱藏（透明） */
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    opacity: 0;
}