*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: 14px;
    background: #f1f5f9;
    color: #1e293b;
}

/* ── Nav ───────────────────────────────────────────── */
nav {
    background: #1e293b;
    display: flex;
    align-items: center;
    gap: 0;
    padding: 0 24px;
    min-height: 52px;
    position: relative;
    flex-wrap: wrap;
}
nav .brand {
    color: #fff;
    font-weight: 700;
    font-size: 16px;
    margin-right: 16px;
    text-decoration: none;
    white-space: nowrap;
    height: 52px;
    display: flex;
    align-items: center;
}
.nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
}
nav a {
    color: #94a3b8;
    text-decoration: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 13px;
    transition: background .15s, color .15s;
    white-space: nowrap;
}
nav a:hover, nav a.active {
    background: #334155;
    color: #fff;
}
.nav-links .spacer { flex: 1; }
.nav-links .logout {
    color: #94a3b8;
    font-size: 13px;
    text-decoration: none;
}
.nav-links .logout:hover { color: #f87171; background: none; }

/* Hamburger button — hidden on desktop */
.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 24px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    margin-left: auto;
    height: 52px;
    align-items: center;
}
.nav-toggle:hover { color: #fff; }

/* ── Layout ────────────────────────────────────────── */
.container {
    max-width: 960px;
    margin: 32px auto;
    padding: 0 16px;
}

h1 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
    color: #0f172a;
}

h2 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
    color: #0f172a;
}

/* ── Cards / panels ────────────────────────────────── */
.panel {
    background: #fff;
    border-radius: 10px;
    padding: 20px 24px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    margin-bottom: 24px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat {
    background: #fff;
    border-radius: 10px;
    padding: 18px 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.stat .label { font-size: 12px; color: #64748b; margin-bottom: 4px; }
.stat .value { font-size: 22px; font-weight: 700; color: #0f172a; }
.stat .value.red   { color: #ef4444; }
.stat .value.green { color: #10b981; }

/* ── Tables ────────────────────────────────────────── */
table {
    width: 100%;
    border-collapse: collapse;
}
th {
    text-align: left;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 8px 10px;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
}
td {
    padding: 10px 10px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: #f8fafc; }

.amount { font-variant-numeric: tabular-nums; }

/* ── Badges ────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
}
.badge-gray { background: #94a3b8; }

/* ── Forms ─────────────────────────────────────────── */
.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
}
.form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.form-group label { font-size: 12px; color: #64748b; font-weight: 500; }

input[type=text], input[type=number], input[type=color],
select, input[type=month] {
    height: 36px;
    padding: 0 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 13px;
    color: #1e293b;
    background: #fff;
    outline: none;
    transition: border-color .15s;
}
input[type=text]:focus, input[type=number]:focus,
select:focus, input[type=month]:focus {
    border-color: #6366f1;
}
input[type=color] {
    width: 52px;
    padding: 2px 4px;
    cursor: pointer;
}

/* ── Buttons ───────────────────────────────────────── */
.btn {
    height: 36px;
    padding: 0 16px;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    transition: opacity .15s;
    white-space: nowrap;
}
.btn:hover { opacity: .85; }
.btn-primary { background: #6366f1; color: #fff; }
.btn-danger  { background: #fee2e2; color: #ef4444; font-size: 12px; height: 28px; padding: 0 10px; }
.btn-edit    { background: #e0f2fe; color: #0369a1; font-size: 12px; height: 28px; padding: 0 10px; }

/* ── Month / year bar ──────────────────────────────── */
.month-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 24px;
}
.month-bar h1 { margin: 0; text-align: center; flex: 1; }

/* ── Login ─────────────────────────────────────────── */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.login-box {
    background: #fff;
    border-radius: 12px;
    padding: 40px 36px;
    width: 100%;
    max-width: 340px;
    box-shadow: 0 4px 24px rgba(0,0,0,.1);
}
.login-box h1 { text-align: center; margin-bottom: 28px; }
.login-box .form-group { margin-bottom: 16px; }
.login-box input[type=text],
.login-box input[type=password] {
    width: 100%;
}
.login-box .btn { width: 100%; justify-content: center; margin-top: 8px; height: 44px; font-size: 15px; }
.error { color: #ef4444; font-size: 13px; margin-bottom: 12px; text-align: center; }

/* ── Modal ─────────────────────────────────────────── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-overlay.open { display: flex; }
.modal {
    background: #fff;
    border-radius: 12px;
    padding: 28px 32px;
    width: 420px;
    max-width: 100%;
    box-shadow: 0 8px 32px rgba(0,0,0,.18);
}
.modal h2 { margin-bottom: 20px; font-size: 16px; }
.modal .form-group { margin-bottom: 14px; }
.modal .form-group label { display: block; font-size: 12px; color: #64748b; font-weight: 500; margin-bottom: 4px; }
.modal .form-group input,
.modal .form-group select { width: 100%; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
.modal-close { position: absolute; top: 0; right: 0; }

/* ── Toggle ────────────────────────────────────────── */
.inactive td { opacity: .45; }

/* ── Misc ──────────────────────────────────────────── */
.text-right { text-align: right; }
.text-muted  { color: #94a3b8; font-size: 12px; }
.mt-8  { margin-top: 8px; }
.flex-gap { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── Pay modal (inline) ────────────────────────────── */
#payOverlay input,
#payOverlay select {
    box-sizing: border-box;
}

/* ════════════════════════════════════════════════════
   RESPONSIVE — mobile first adjustments
   ════════════════════════════════════════════════════ */
@media (max-width: 768px) {

    /* Nav: show hamburger, hide links by default */
    nav {
        padding: 0 16px;
        gap: 0;
    }
    nav .brand {
        margin-right: 0;
        flex: 1;
    }
    .nav-toggle {
        display: flex;
    }
    .nav-links {
        display: none;
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        padding: 8px 0 12px;
        gap: 2px;
        border-top: 1px solid #334155;
    }
    nav.nav-open .nav-links {
        display: flex;
    }
    .nav-links a {
        padding: 11px 12px;
        font-size: 14px;
        border-radius: 6px;
    }
    .nav-links .spacer { display: none; }
    .nav-links .logout {
        margin-top: 4px;
        border-top: 1px solid #334155;
        padding-top: 12px !important;
    }

    /* Layout */
    .container {
        margin: 16px auto;
        padding: 0 12px;
    }
    h1 { font-size: 18px; }

    /* Panels */
    .panel {
        padding: 16px;
        border-radius: 8px;
        margin-bottom: 16px;
    }

    /* Stat grid: 2 columns on mobile */
    .stat-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
        margin-bottom: 16px;
    }
    .stat {
        padding: 14px 16px;
        border-radius: 8px;
    }
    .stat .value { font-size: 18px; }

    /* Tables: each table scrolls independently */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        white-space: nowrap;
    }
    /* Restore normal display for cells so layout stays correct */
    thead, tbody, tfoot { display: table; width: 100%; table-layout: auto; }
    tr { display: table-row; }
    td, th { display: table-cell; white-space: normal; }
    th { white-space: nowrap; }

    /* Forms: stack vertically */
    .form-row {
        flex-direction: column;
        gap: 12px;
    }
    .form-group {
        width: 100%;
    }
    .form-group input[type=text],
    .form-group input[type=number],
    .form-group select {
        width: 100% !important;
    }

    /* Filter/inline forms stay horizontal (don't stack like add/edit forms) */
    form.filter-form,
    form.filter-form .form-group {
        flex-direction: row !important;
        flex-wrap: wrap;
        width: auto !important;
    }
    form.filter-form .form-group input,
    form.filter-form .form-group select {
        width: auto !important;
    }

    /* Month bar */
    .month-bar {
        margin-bottom: 16px;
    }
    .month-bar h1 {
        font-size: 16px;
    }

    /* Buttons inside rows */
    .flex-gap {
        gap: 6px;
    }

    /* Pay modal overlay */
    #payOverlay > div {
        width: 100% !important;
        max-width: 100% !important;
        padding: 24px 20px !important;
        margin: 0 !important;
        border-radius: 16px 16px 0 0 !important;
        position: fixed !important;
        bottom: 0 !important;
        left: 0 !important;
    }
    #payOverlay {
        align-items: flex-end !important;
    }
}

@media (max-width: 400px) {
    /* Very small phones: single column stats */
    .stat-grid {
        grid-template-columns: 1fr 1fr !important;
    }
    .stat .value { font-size: 16px; }
    .stat .label { font-size: 11px; }
}
