:root {
    --bg: #f7faf8;
    --surface: #ffffff;
    --text: #17231c;
    --muted: #66756d;
    --line: #dfe8e2;
    --soft: #eef5f0;
    --green: #168a4a;
    --green-dark: #0d6f39;
    --green-soft: #e8f7ee;
    --red: #b93838;
    --amber: #94620d;
    --shadow: 0 18px 45px rgba(23, 35, 28, 0.08);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

a {
    color: var(--green);
    text-decoration: none;
}

button,
input,
select,
textarea {
    font: inherit;
}

.app-shell {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 24px 18px;
    background: var(--surface);
    border-right: 1px solid var(--line);
}

.brand,
.auth-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text);
}

.brand-mark {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    flex: 0 0 42px;
    border-radius: var(--radius);
    background: var(--green);
    color: #fff;
    font-weight: 800;
}

.brand strong,
.auth-brand h1 {
    display: block;
    margin: 0;
    font-size: 18px;
}

.brand small,
.auth-brand p,
.eyebrow,
.section-head p,
.result-panel p {
    color: var(--muted);
    margin: 0;
}

.nav {
    display: grid;
    gap: 7px;
}

.nav a {
    padding: 12px 13px;
    border-radius: var(--radius);
    color: var(--muted);
    font-weight: 700;
}

.nav a:hover,
.nav a.active {
    background: var(--green-soft);
    color: var(--green-dark);
}

.sidebar-footer {
    margin-top: auto;
    padding-top: 18px;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    color: var(--muted);
    font-size: 14px;
}

.main {
    min-width: 0;
    padding: 28px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.topbar h1 {
    margin: 4px 0 0;
    font-size: 30px;
}

.menu-button {
    display: none;
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
}

.quick-add {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 0 18px;
    border-radius: var(--radius);
    background: var(--green);
    color: #fff;
    font-weight: 800;
    box-shadow: var(--shadow);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat-card,
.panel,
.auth-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stat-card {
    padding: 18px;
}

.stat-card span,
.result-panel span {
    display: block;
    color: var(--muted);
    font-weight: 700;
    font-size: 13px;
    text-transform: uppercase;
}

.stat-card strong {
    display: block;
    margin-top: 8px;
    font-size: 24px;
}

.stat-card.good strong,
.stat-card.advance strong {
    color: var(--green);
}

.stat-card.warn strong,
.stat-card.due strong {
    color: var(--amber);
}

.stat-card.settled strong {
    color: var(--text);
}

.split-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(360px, 0.85fr);
    gap: 18px;
    align-items: start;
}

.panel {
    padding: 20px;
    margin-bottom: 18px;
}

.panel.narrow {
    max-width: 860px;
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.section-head h2 {
    margin: 0;
    font-size: 20px;
}

.form {
    display: grid;
    gap: 15px;
}

.form-grid,
.filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.filters {
    grid-template-columns: 1.2fr 1fr 1fr 1fr 1fr auto;
    align-items: end;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-height: 46px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    padding: 11px 12px;
    outline: none;
}

textarea {
    min-height: 92px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 4px var(--green-soft);
}

.type-toggle {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.type-toggle label {
    position: relative;
}

.type-toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.type-toggle span {
    display: grid;
    place-items: center;
    min-height: 48px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--muted);
    background: #fff;
    cursor: pointer;
}

.type-toggle input:checked + span {
    border-color: var(--green);
    background: var(--green-soft);
    color: var(--green-dark);
    font-weight: 800;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 0 18px;
    cursor: pointer;
    font-weight: 800;
}

.btn.primary {
    background: var(--green);
    color: #fff;
}

.btn.primary:hover {
    background: var(--green-dark);
}

.btn.ghost {
    background: #fff;
    border-color: var(--line);
    color: var(--text);
}

.btn.mini {
    min-height: 34px;
    padding: 0 12px;
    background: var(--green-soft);
    color: var(--green-dark);
    font-size: 13px;
}

.btn.danger {
    background: #fff1f1;
    color: var(--red);
}

.btn.danger:hover {
    border-color: #ffd4d4;
    background: #ffe7e7;
}

.btn.full {
    width: 100%;
}

.form-actions,
.filter-actions,
.button-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.form-message {
    color: var(--muted);
    font-weight: 700;
}

.form-message.success {
    color: var(--green);
}

.form-message.error {
    color: var(--red);
}

.is-hidden {
    display: none !important;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
}

.table-wrap.compact table {
    min-width: 520px;
}

table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
    background: #fff;
}

th,
td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    background: var(--soft);
    color: var(--muted);
    font-size: 13px;
    text-transform: uppercase;
}

tr:last-child td {
    border-bottom: 0;
}

.right {
    text-align: right;
    white-space: nowrap;
}

.empty {
    text-align: center;
    color: var(--muted);
    padding: 26px;
}

.pill {
    display: inline-flex;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}

.pill.given {
    background: #fff3d9;
    color: var(--amber);
}

.pill.received {
    background: var(--green-soft);
    color: var(--green-dark);
}

.balance.due {
    color: var(--amber);
    font-weight: 800;
}

.balance.advance {
    color: var(--green);
    font-weight: 800;
}

.balance.settled {
    color: var(--text);
    font-weight: 800;
}

.balance span {
    display: block;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.name-link {
    color: var(--text);
    font-weight: 800;
}

.name-link:hover {
    color: var(--green);
}

.entry-actions {
    display: flex;
    gap: 8px;
    white-space: nowrap;
}

.account-stats {
    grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 18px;
}

.tabs a {
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--muted);
    font-weight: 800;
}

.tabs a.active {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}

.result-panel {
    min-height: 210px;
    display: grid;
    align-content: center;
    gap: 12px;
}

.result-panel strong {
    color: var(--green);
    font-size: 42px;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(100%, 430px);
    padding: 26px;
}

.auth-brand {
    margin-bottom: 22px;
}

.auth-link {
    text-align: center;
    margin: 18px 0 0;
    color: var(--muted);
}

.alert {
    padding: 12px 14px;
    border-radius: var(--radius);
    margin-bottom: 14px;
    font-weight: 700;
}

.alert.error {
    background: #fff1f1;
    color: var(--red);
    border: 1px solid #ffd4d4;
}

@media (max-width: 1120px) {
    .stats-grid {
        grid-template-columns: repeat(3, minmax(150px, 1fr));
    }

    .split-layout,
    .filters {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 780px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        z-index: 20;
        inset: 0 auto 0 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
    }

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

    .main {
        padding: 18px;
    }

    .menu-button {
        display: inline-grid;
        place-items: center;
    }

    .topbar {
        align-items: flex-start;
    }

    .topbar h1 {
        font-size: 24px;
    }

    .quick-add {
        min-height: 42px;
        padding: 0 12px;
        font-size: 14px;
    }

    .stats-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .panel {
        padding: 16px;
    }
}

@media (max-width: 520px) {
    .topbar {
        flex-wrap: wrap;
    }

    .quick-add {
        width: 100%;
    }

    .section-head,
    .form-actions,
    .button-row {
        align-items: stretch;
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }
}

@media print {
    .sidebar,
    .topbar,
    .print-hide,
    .filters {
        display: none !important;
    }

    .app-shell {
        display: block;
    }

    .main {
        padding: 0;
    }

    .panel {
        box-shadow: none;
        border: 0;
        padding: 0;
    }

    body {
        background: #fff;
    }
}
