* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f4f5f7;
    color: #222;
}

.container {
    width: 95%;
    max-width: 1100px;
    margin: 0 auto;
}

.main-header {
    background: #1f2933;
    color: #fff;
    padding: 10px 0;
    margin-bottom: 20px;
}

.flex-between {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    font-weight: 700;
    font-size: 1.4rem;
}
.logo span {
    color: #3b82f6;
}

.main-nav a {
    color: #e5e7eb;
    margin-left: 15px;
    text-decoration: none;
    font-size: 0.95rem;
}
.main-nav a:hover {
    text-decoration: underline;
}

.welcome {
    margin-left: 15px;
    font-size: 0.9rem;
    color: #9ca3af;
}

.btn-logout {
    padding: 5px 10px;
    border-radius: 4px;
    border: 1px solid #f97373;
    color: #fee2e2;
}

.main-footer {
    margin-top: 40px;
    padding: 20px 0;
    background: #111827;
    color: #9ca3af;
    text-align: center;
    font-size: 0.85rem;
}

.card {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.auth-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}

.form-group {
    margin-bottom: 15px;
}
.form-group label {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9rem;
}
.form-group input,
.form-group select {
    width: 100%;
    padding: 8px 10px;
    border-radius: 4px;
    border: 1px solid #d1d5db;
    font-size: 0.95rem;
}
.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 1px rgba(59,130,246,0.3);
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-primary,
.btn-secondary,
.btn-small {
    display: inline-block;
    padding: 7px 14px;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    font-size: 0.9rem;
    text-decoration: none;
}

.btn-primary {
    background: #2563eb;
    color: #fff;
}
.btn-primary:hover {
    background: #1d4ed8;
}

.btn-secondary {
    background: #e5e7eb;
    color: #111827;
}
.btn-secondary:hover {
    background: #d1d5db;
}

.btn-small {
    background: #f3f4f6;
    color: #111827;
    padding: 4px 8px;
    font-size: 0.8rem;
}
.btn-small:hover {
    background: #e5e7eb;
}

.alert {
    padding: 10px 12px;
    border-radius: 4px;
    margin-bottom: 15px;
    font-size: 0.9rem;
}
.alert-success {
    background: #ecfdf3;
    color: #166534;
    border: 1px solid #bbf7d0;
}
.alert-error {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
thead {
    background: #f3f4f6;
}
th, td {
    padding: 8px 10px;
    border-bottom: 1px solid #e5e7eb;
}
th {
    text-align: left;
    font-weight: 600;
}
tbody tr:hover {
    background: #f9fafb;
}

tfoot th {
    font-weight: 600;
}

.badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
}
.badge-paid {
    background: #dcfce7;
    color: #166534;
}
.badge-unpaid {
    background: #fee2e2;
    color: #b91c1c;
}

.inline-form {
    display: inline;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 10px 20px;
}
.grid-3 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px 20px;
}

.month-nav {
    margin-bottom: 10px;
    align-items: center;
}

.muted {
    color: #6b7280;
    font-size: 0.85rem;
}

.center {
    text-align: center;
}

.right {
    text-align: right;
}

.actions-bar {
    margin-bottom: 10px;
}

@media (max-width: 600px) {
    .flex-between {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .main-nav a {
        margin-left: 0;
        margin-right: 10px;
    }
}

/* Improved table and layout responsiveness */
.responsive-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.totals-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    justify-content: flex-end;
    font-size: 0.85rem;
}

@media (max-width: 768px) {
    body {
        font-size: 0.9rem;
    }

    .container {
        width: 96%;
    }

    .main-header {
        padding: 8px 0;
    }

    .main-nav {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    .main-nav a,
    .welcome {
        font-size: 0.8rem;
    }

    .card {
        padding: 15px;
        margin-bottom: 16px;
    }

    table.responsive-table,
    table.responsive-table thead,
    table.responsive-table tbody,
    table.responsive-table th,
    table.responsive-table td,
    table.responsive-table tr {
        display: block;
    }

    table.responsive-table thead tr {
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    table.responsive-table tr {
        margin-bottom: 12px;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        padding: 8px 10px;
        box-shadow: 0 1px 2px rgba(0,0,0,0.04);
        background: #fff;
    }

    table.responsive-table td {
        border: none;
        border-bottom: 1px solid #f3f4f6;
        position: relative;
        padding-left: 52%;
        padding-top: 6px;
        padding-bottom: 6px;
        font-size: 0.85rem;
    }

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

    table.responsive-table td::before {
        position: absolute;
        top: 6px;
        left: 10px;
        width: 45%;
        padding-right: 10px;
        white-space: nowrap;
        content: attr(data-label);
        font-weight: 600;
        color: #6b7280;
        font-size: 0.78rem;
    }

    .btn-small {
        margin-bottom: 4px;
    }

    .month-nav h3 {
        font-size: 1rem;
    }

    .month-nav .btn-secondary {
        font-size: 0.8rem;
        padding: 5px 8px;
    }

    .totals-row {
        justify-content: flex-start;
    }
}

@media (max-width: 480px) {
    .main-nav a,
    .welcome {
        font-size: 0.75rem;
    }
    .logo {
        font-size: 1.1rem;
    }
    .btn-primary,
    .btn-secondary {
        padding: 6px 10px;
        font-size: 0.8rem;
    }
}

/* Mobile sidebar menu */
.header-inner {
    align-items: center;
}

.logo-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
}

.menu-toggle {
    display: none;
    border: none;
    background: none;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 4px 6px;
}

.sidebar-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    max-width: 80%;
    height: 100%;
    background: #ffffff;
    box-shadow: 2px 0 12px rgba(0,0,0,0.15);
    transform: translateX(-100%);
    transition: transform 0.25s ease-out;
    z-index: 9999;
    display: flex;
    flex-direction: column;
}

.sidebar-menu.open {
    transform: translateX(0);
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease-out, visibility 0.2s ease-out;
    z-index: 9998;
}

.sidebar-backdrop.show {
    opacity: 1;
    visibility: visible;
}

.sidebar-header {
    padding: 14px 16px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-title {
    font-weight: 600;
    font-size: 1rem;
}

.sidebar-close {
    border: none;
    background: none;
    font-size: 1.4rem;
    cursor: pointer;
    line-height: 1;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 8px 0;
}

.sidebar-nav a {
    padding: 10px 16px;
    text-decoration: none;
    color: #111827;
    font-size: 0.95rem;
}

.sidebar-nav a:hover {
    background: #f3f4f6;
}

.sidebar-logout {
    margin-top: auto;
    border-top: 1px solid #e5e7eb;
}

/* prevent body scroll when sidebar open */
body.sidebar-open {
    overflow: hidden;
}

/* Responsive behaviour: show sidebar toggle on small screens, hide top nav */
@media (max-width: 768px) {
    .menu-toggle {
        display: inline-block;
    }

    .main-nav {
        display: none;
    }
}
