:root {
    color-scheme: light;
    --bg: #f5f7f8;
    --surface: #ffffff;
    --surface-muted: #eef2f4;
    --text: #172026;
    --muted: #60717b;
    --line: #d9e1e5;
    --accent: #0f766e;
    --accent-dark: #115e59;
    --danger: #b42318;
    --success: #137333;
    --shadow: 0 12px 28px rgba(23, 32, 38, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.5;
}

a {
    color: inherit;
}

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

.sidebar {
    background: #152026;
    color: #f7fafb;
    padding: 24px 18px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    text-decoration: none;
}

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

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: #b8c5cc;
    font-size: 0.82rem;
}

.nav {
    display: grid;
    gap: 4px;
    margin-top: 32px;
}

.nav a,
.nav-section {
    border-radius: 8px;
    padding: 10px 12px;
}

.nav a {
    color: #e8eef1;
    text-decoration: none;
}

.nav a:hover,
.nav a:focus-visible {
    background: rgba(255, 255, 255, 0.1);
    outline: none;
}

.nav-section {
    margin-top: 14px;
    color: #9cafb8;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

.main-column {
    min-width: 0;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 24px clamp(18px, 4vw, 40px);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.topbar h1 {
    margin: 0;
    font-size: 1.55rem;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0;
    text-transform: uppercase;
}

.content {
    padding: 28px clamp(18px, 4vw, 40px) 48px;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 0 16px;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.button-primary {
    background: var(--accent);
    color: #ffffff;
}

.button-primary:hover,
.button-primary:focus-visible {
    background: var(--accent-dark);
}

.button-muted {
    background: var(--surface-muted);
    color: var(--text);
    border-color: var(--line);
}

.button-danger {
    background: #fff0ed;
    color: var(--danger);
    border-color: #ffd3cc;
}

.toolbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 10px;
}

.filters {
    display: flex;
    align-items: end;
    flex-wrap: wrap;
    gap: 12px;
}

.filters label,
.record-form label {
    display: grid;
    gap: 6px;
}

select {
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 12px;
    background: var(--surface);
    font: inherit;
}

textarea {
    width: 100%;
    min-height: 92px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 12px;
    font: inherit;
    resize: vertical;
}

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

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

.stat-card {
    padding: 18px;
}

.stat-card span {
    display: block;
    color: var(--muted);
    font-size: 0.9rem;
}

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

.stat-primary {
    border-color: rgba(15, 118, 110, 0.35);
}

.section-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.75fr);
    gap: 16px;
    align-items: start;
}

.panel {
    padding: 18px;
}

.panel-heading {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
}

.panel-heading h2,
.panel h2 {
    margin: 0;
    font-size: 1.05rem;
}

.panel-heading span,
.hint,
.empty-state,
.compact-row small {
    color: var(--muted);
}

.hint-box {
    display: grid;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-muted);
    padding: 12px;
}

.hint-box code {
    overflow-x: auto;
    border-radius: 6px;
    background: var(--surface);
    padding: 8px;
}

.hint-box p,
.error-list {
    margin: 0;
}

.error-list {
    padding-left: 20px;
}

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

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

th,
td {
    padding: 11px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

.actions-col {
    text-align: right;
}

.row-link,
.text-action {
    color: var(--accent-dark);
    font-weight: 700;
}

.sort-link {
    color: var(--muted);
    font-weight: 800;
    text-decoration: none;
}

.sort-link:hover,
.sort-link:focus-visible,
.sort-link.active {
    color: var(--accent-dark);
}

.text-action + .text-action {
    margin-left: 10px;
}

.inline-form {
    display: inline;
    margin-left: 10px;
}

.inline-form button {
    appearance: none;
    border: 0;
    background: transparent;
    padding: 0;
    font: inherit;
    cursor: pointer;
}

.danger-link {
    color: var(--danger);
}

.muted-row {
    color: #7b8c95;
    background: #f3f6f7;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    border-radius: 999px;
    padding: 0 10px;
    font-size: 0.82rem;
    font-weight: 800;
    white-space: nowrap;
}

.status-active {
    background: #e7f6ee;
    color: var(--success);
}

.status-muted {
    background: #e7ecef;
    color: var(--muted);
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 18px;
}

.pagination a {
    display: grid;
    place-items: center;
    min-width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    text-decoration: none;
}

.pagination a.current {
    background: var(--accent);
    color: #ffffff;
    border-color: var(--accent);
}

th {
    color: var(--muted);
    font-size: 0.82rem;
}

.amount-col {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.amount-positive {
    color: var(--success);
}

.amount-negative {
    color: var(--danger);
}

.compact-list {
    display: grid;
    gap: 12px;
}

.compact-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.compact-row:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.compact-row span,
.compact-row small,
.row-note {
    display: block;
    min-width: 0;
}

.row-note {
    margin-top: 3px;
    color: var(--muted);
    white-space: normal;
}

.compact-row b,
.metric-line {
    font-variant-numeric: tabular-nums;
}

.metric-line {
    margin: 0;
    font-size: 1.45rem;
    font-weight: 800;
}

.member-financial-panel {
    margin-top: 16px;
}

.financial-filters {
    margin-bottom: 16px;
}

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

.record-form {
    display: grid;
    gap: 20px;
}

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

.form-grid-wide {
    grid-column: 1 / -1;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.field-error {
    color: var(--danger);
    font-size: 0.9rem;
    font-weight: 700;
}

.flash-stack {
    display: grid;
    gap: 10px;
    margin-bottom: 18px;
}

.flash {
    margin: 0;
    border-radius: 8px;
    padding: 12px 14px;
    font-weight: 700;
}

.flash-success {
    background: #e7f6ee;
    color: var(--success);
    border: 1px solid #c7ead6;
}

.flash-error {
    background: #fff0ed;
    color: var(--danger);
    border: 1px solid #ffd3cc;
}

.detail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 18px;
}

.detail-header h2,
.detail-header p {
    margin: 0;
}

.detail-header h2 {
    font-size: 1.45rem;
}

.detail-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.definition-list {
    display: grid;
    gap: 12px;
    margin: 0;
}

.definition-list div {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    gap: 12px;
}

.definition-list dt {
    color: var(--muted);
    font-weight: 700;
}

.definition-list dd {
    margin: 0;
}

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

.tabs-static a,
.tabs-static span {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--muted);
    font-weight: 800;
    text-decoration: none;
}

.tabs-static a.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #ffffff;
}

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

.auth-shell {
    width: min(100%, 420px);
}

.login-panel {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 28px;
}

.brand-login {
    color: var(--text);
    margin-bottom: 28px;
}

.brand-login small {
    color: var(--muted);
}

.login-panel h1 {
    margin: 0 0 18px;
    font-size: 1.6rem;
}

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

label {
    font-weight: 700;
}

input {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 12px;
    font: inherit;
}

input[type="checkbox"] {
    width: 18px;
    min-height: 18px;
}

.record-form label.checkbox-label {
    display: flex;
    align-items: center;
    grid-auto-flow: column;
    justify-content: start;
    font-weight: 700;
}

input:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(15, 118, 110, 0.25);
    outline-offset: 2px;
}

.alert {
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
}

.alert p {
    margin: 0;
}

.alert-error {
    background: #fff0ed;
    color: var(--danger);
    border: 1px solid #ffd3cc;
}

.setup-panel pre {
    overflow-x: auto;
    border-radius: 8px;
    background: #172026;
    color: #f7fafb;
    padding: 14px;
}

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

    .sidebar {
        padding: 18px;
    }

    .nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        margin-top: 18px;
    }

    .nav-section {
        grid-column: 1 / -1;
    }

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

@media (max-width: 560px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar .button {
        width: 100%;
    }

    .nav {
        grid-template-columns: 1fr;
    }

    .stat-card strong {
        font-size: 1.25rem;
    }

    .toolbar,
    .detail-header,
    .detail-actions,
    .form-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .filters,
    .filters label,
    .filters .button,
    .toolbar > .button,
    .toolbar-actions,
    .toolbar-actions .button,
    .detail-actions .button,
    .detail-actions form,
    .form-actions .button {
        width: 100%;
    }

    .form-grid,
    .definition-list div {
        grid-template-columns: 1fr;
    }

    th,
    td {
        white-space: normal;
    }
}
