body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f4f7f9;
    margin: 0;
    color: #333;
}

/* --- Login Page --- */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    padding: 20px;
    box-sizing: border-box;
}

.login-container form {
    padding: 40px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    width: 100%;
    max-width: 360px;
    box-sizing: border-box;
}

.login-container h2 {
    text-align: center;
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
}

.form-group input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box;
}

button {
    width: 100%;
    padding: 10px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    transition: background-color 0.2s;
}

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

p.error {
    color: #d93025;
    text-align: center;
}

/* --- Main App Layout --- */
.app-container {
    display: flex;
    min-height: 100vh;
}

nav {
    width: 220px;
    background-color: #343a40;
    color: #fff;
    padding-top: 20px;
    flex-shrink: 0;
}

.nav-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 20px 20px;
    border-bottom: 1px solid #495057;
}

.nav-brand {
    font-size: 1.2em;
    font-weight: bold;
}

nav ul {
    list-style: none;
    padding: 0;
    margin-top: 20px;
}

nav ul li a {
    display: block;
    padding: 12px 20px;
    color: #adb5bd;
    text-decoration: none;
    transition: background-color 0.2s;
}

nav ul li a:hover {
    background-color: #495057;
    color: #fff;
}

nav ul li a.active {
    background-color: #007bff;
    color: #fff;
}

.menu-toggle-btn {
    display: none; /* Hidden on desktop */
    background: none;
    border: none;
    cursor: pointer;
}

.menu-toggle-btn span {
    display: block;
    width: 22px;
    height: 2px;
    background-color: white;
    margin: 5px 0;
}

main {
    flex-grow: 1;
    padding: 30px;
    background-color: #fff;
    overflow-x: auto; /* For responsive tables/charts */
}

/* Controls and Table */
.controls {
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.controls label {
    margin-right: 10px;
    margin-bottom: 10px;
}

.controls input[type="date"] {
    padding: 5px;
    border-radius: 4px;
    border: 1px solid #ccc;
    margin-right: 20px;
    margin-bottom: 10px;
}

.chart-container {
    position: relative;
    height: 40vh;
    min-height: 300px;
    margin-bottom: 20px;
}

.chart-navigation {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-bottom: 40px;
}

.nav-btn {
    width: auto;
    padding: 10px 20px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background-color 0.2s;
}

.nav-btn:hover:not(:disabled) {
    background-color: #0056b3;
}

.nav-btn:disabled {
    background-color: #6c757d;
    cursor: not-allowed;
    opacity: 0.6;
}

.table-container {
    overflow-x: auto;
}

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

th, td {
    padding: 12px;
    border: 1px solid #ddd;
    text-align: left;
    vertical-align: middle;
}

th {
    background-color: #f2f2f2;
}

th.sortable-header {
    user-select: none;
    transition: background-color 0.2s;
}

th.sortable-header:hover {
    background-color: #e0e0e0;
}

/* --- Settings Page --- */
#settingsForm .form-section {
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
}

#settingsForm h3 {
    margin-top: 0;
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 10px;
    margin-bottom: 20px;
}

.settings-table td {
    border: none;
    padding: 10px;
}

.settings-table td:first-child {
    font-weight: 500;
    width: 200px;
}

#manualFetchBtn {
    width: auto;
    padding: 8px 15px;
}

#fetchStatus, #saveStatus {
    margin-top: 10px;
    font-weight: bold;
    display: inline-block;
    margin-left: 10px;
}
#fetchStatus:empty, #saveStatus:empty {
    display: none;
}

/* --- Responsive Design for Mobile --- */
@media (max-width: 768px) {
    .app-container {
        flex-direction: column;
    }

    nav {
        width: 100%;
        padding-top: 0;
    }

    .nav-header {
        padding: 15px 20px;
        border-bottom: 0;
    }

    .menu-toggle-btn {
        display: block;
    }

    nav ul {
        display: none; /* Hide menu by default on mobile */
        margin-top: 0;
        width: 100%;
        background-color: #343a40;
    }

    nav ul.show {
        display: block; /* Show menu when toggled */
    }
    
    nav ul li a {
        border-bottom: 1px solid #495057;
    }

    main {
        padding: 20px;
    }

    .settings-table td, .settings-table td:first-child {
        display: block;
        width: 100%;
        padding-left: 0;
        padding-right: 0;
    }
    
    .settings-table td:first-child {
        padding-bottom: 5px;
    }
}

/* --- Danger Zone for destructive actions --- */
.danger-zone {
    margin-top: 40px;
    padding: 20px;
    border: 2px solid #dc3545;
    border-radius: 8px;
    background-color: #f8d7da;
}

.danger-zone h3 {
    margin-top: 0;
    color: #721c24;
}

button.danger {
    background-color: #dc3545;
    border-color: #dc3545;
}

button.danger:hover {
    background-color: #c82333;
    border-color: #bd2130;
}

#truncateStatus {
    margin-top: 10px;
    font-weight: bold;
}
#truncateStatus:empty {
    display: none;
}

/* --- Button Info Style --- */
button.info {
    background-color: #007bff;
    border-color: #007bff;
}

button.info:hover {
    background-color: #0069d9;
    border-color: #0062cc;
}

#testNotificationStatus {
    margin-top: 10px;
    font-weight: bold;
}
#testNotificationStatus:empty {
    display: none;
}

/* --- NEW: Style for "Remember Me" Checkbox --- */
.form-group.remember-me {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9em;
}

.form-group.remember-me input[type="checkbox"] {
    width: auto;
    margin-right: 8px;
}

/* --- Stats Page --- */
.stats-section {
    margin-bottom: 40px;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    padding: 20px;
}

.stats-section h2 {
    margin-top: 0;
    margin-bottom: 20px;
    border-bottom: 2px solid #dee2e6;
    padding-bottom: 10px;
    color: #343a40;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.stat-card {
    background-color: #fff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.15);
}

.stat-card h3 {
    margin: 0 0 15px 0;
    font-size: 0.95em;
    color: #6c757d;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-value {
    font-size: 1.8em;
    font-weight: bold;
    color: #007bff;
    margin-bottom: 8px;
}

.stat-date {
    font-size: 0.9em;
    color: #6c757d;
}

.loading-message {
    text-align: center;
    padding: 40px;
    font-size: 1.1em;
    color: #6c757d;
}

/* Responsive stats grid */
@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .stat-card {
        padding: 15px;
    }

    .stat-value {
        font-size: 1.5em;
    }
}