/* Universal box-sizing for consistent sizing model */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    height: 100%; /* Ensure html and body take full viewport height */
    overflow-y: auto; /* Allow scrolling on the entire document */
    font-family: Arial, sans-serif;
    margin: 0;
    background-color: #f4f7f6;
}

.container {
    display: flex;
    width: 100%;
    height: 100%; /* Ensure container takes full height on desktop */
}

.sidebar {
    width: 250px;
    background-color: #2c3e50;
    color: #ecf0f1;
    padding: 20px;
    box-shadow: 2px 0 5px rgba(0,0,0,0.1);
}

.sidebar h2 {
    text-align: center;
    margin-bottom: 30px;
    color: #ecf0f1;
}

.sidebar ul {
    list-style: none;
    padding: 0;
}

.sidebar ul li {
    margin-bottom: 10px;
}

.sidebar ul li a {
    color: #ecf0f1;
    text-decoration: none;
    padding: 10px 15px;
    display: block;
    border-radius: 5px;
    transition: background-color 0.3s ease;
}

.sidebar ul li a:hover,
.sidebar ul li a.active {
    background-color: #34495e;
}

.main-content {
    flex-grow: 1;
    padding: 20px;
    background-color: #ffffff;
    border-radius: 8px;
    margin: 20px; /* Default margin for smaller screens, overridden by media query */
    box-shadow: 0 0 10px rgba(0,0,0,0.05);
    /* Removed overflow-y: auto; here, as html/body will handle it */
    /* Removed height: auto; here, as it will be managed by flex or content */
}

header {
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

h1, h2 {
    color: #333;
}

.page {
    display: none;
}

.page.active {
    display: block;
}

/* Dashboard Styles */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-top: 20px;
}

.stat-card {
    background-color: #f0f4f7;
    padding: 20px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.stat-card h3 {
    color: #555;
    margin-bottom: 10px;
}

.stat-card p {
    font-size: 2em;
    font-weight: bold;
    color: #007bff;
}

/* Table Styles */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

.data-table th,
.data-table td {
    border: 1px solid #ddd;
    padding: 10px;
    text-align: left;
}

.data-table th {
    background-color: #f2f2f2;
    font-weight: bold;
    color: #333;
}

.data-table tr:nth-child(even) {
    background-color: #f9f9f9;
}

.data-table tr:hover {
    background-color: #e9e9e9;
}

/* Status Colors */
.status-paid {
    color: #28a745; /* Green */
    font-weight: bold;
}

.status-partial {
    color: #ffc107; /* Yellow/Orange */
    font-weight: bold;
}

.status-missed, .status-overdue {
    color: #dc3545; /* Red */
    font-weight: bold;
}

.status-active {
    color: #007bff; /* Blue */
    font-weight: bold;
}

.status-completed {
    color: #6c757d; /* Gray */
    font-weight: bold;
}

/* Form Styles */
input[type="text"],
input[type="number"],
input[type="password"] {
    width: calc(100% - 22px);
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

button {
    background-color: #007bff;
    color: white;
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    margin-right: 10px;
    transition: background-color 0.3s ease;
}

button:hover {
    background-color: #0056b3;
}

button.cancel-btn {
    background-color: #6c757d;
}

button.cancel-btn:hover {
    background-color: #5a6268;
}

.hidden {
    display: none;
}

/* Daily Collections specific styles */
.collection-entry {
    background-color: #f9f9f9;
    border: 1px solid #ddd;
    padding: 15px;
    margin-bottom: 10px;
    border-radius: 5px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap; /* For mobile responsiveness */
}

.collection-entry div {
    margin-right: 20px;
    margin-bottom: 10px; /* For mobile responsiveness */
}

.collection-entry select,
.collection-entry input[type="number"] {
    padding: 8px;
    border-radius: 4px;
    border: 1px solid #ccc;
}

.collection-entry.overdue {
    background-color: #fdd; /* Light red background for overdue */
    border-color: #fbc;
}

/* Login Page Styles */
.login-form-container {
    max-width: 400px;
    margin: 50px auto;
    padding: 30px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    text-align: center;
}

.login-form-container input {
    width: calc(100% - 20px); /* Adjust width for padding */
    margin-bottom: 15px;
    padding: 12px;
    border: 1px solid #ddd;
    border-radius: 5px;
}

.login-form-container button {
    width: 100%;
    padding: 12px;
    font-size: 1.1em;
}

.error-message {
    color: #dc3545;
    margin-top: 10px;
    font-weight: bold;
}

/* Navigation items visibility */
.nav-item.logged-in-only {
    display: none; /* Hidden by default, shown by JS after login */
}

/* Search Bar Styling */
.search-bar-container {
    margin-top: 20px;
    margin-bottom: 15px;
}

.search-bar-container input {
    width: calc(100% - 22px);
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

/* Modal Styles */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex; /* Show when active */
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%; /* Could be responsive */
    max-width: 700px;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    position: relative;
}

.close-button {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    top: 10px;
    right: 20px;
    cursor: pointer;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.history-controls {
    margin-bottom: 15px;
    text-align: center;
}

.history-controls button {
    margin: 5px;
}

.history-data {
    max-height: 400px; /* Scrollable area for history */
    overflow-y: auto;
    border: 1px solid #eee;
    padding: 10px;
    border-radius: 5px;
}

.history-entry {
    padding: 8px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.history-entry:last-child {
    border-bottom: none;
}

/* Desktop styles for fixed sidebar */
@media (min-width: 769px) { /* Apply fixed sidebar for larger screens */
    .sidebar {
        position: fixed;
        height: 100vh; /* Full viewport height */
        top: 0;
        left: 0;
        overflow-y: auto; /* Allow scrolling within the sidebar if content overflows */
    }

    .main-content {
        margin-left: 300px; /* Sidebar width (250px) + some margin (20px) */
        margin-top: 0; /* Removed top margin to align with sidebar top */
        margin-right: 20px;
        margin-bottom: 20px;
        height: calc(100vh - 40px); /* Calculate height to fill remaining space, accounting for top/bottom margin */
        /* overflow-y: auto; is now handled by html/body */
    }
}

/* Mobile Responsiveness */
@media (max-width: 768px) {
    .container {
        flex-direction: column;
        height: auto; /* Allow container to grow with content on mobile */
    }

    .sidebar {
        width: 100%;
        padding: 10px;
        box-shadow: 0 2px 5px rgba(0,0,0,0.1);
        position: static; /* Override fixed position for mobile */
        height: auto; /* Override fixed height for mobile */
    }

    .sidebar ul {
        display: flex;
        flex-wrap: wrap;
        justify-content: center;
    }

    .sidebar ul li {
        margin: 5px;
    }

    .sidebar ul li a {
        padding: 8px 12px;
        font-size: 0.9em;
    }

    .main-content {
        margin: 10px; /* Reset margins for mobile */
        padding: 15px;
        height: auto; /* Allow content to dictate height on mobile */
        /* overflow-y: auto; is now handled by html/body */
    }

    .stats-grid {
        grid-template-columns: 1fr; /* Stack columns on small screens */
    }

    .data-table th, .data-table td {
        padding: 8px;
        font-size: 0.9em;
    }

    .collection-entry {
        flex-direction: column;
        align-items: flex-start;
    }

    .collection-entry div {
        margin-right: 0;
        width: 100%;
        margin-bottom: 5px;
    }

    input[type="text"],
    input[type="number"],
    input[type="password"],
    .collection-entry select,
    .search-bar-container input {
        width: 100%;
        box-sizing: border-box; /* Include padding in width */
    }

    .login-form-container {
        margin: 20px auto;
        padding: 20px;
    }

    .modal-content {
        width: 95%;
        padding: 15px;
    }
}
