:root {
    color-scheme: light;
    --bg: #f5f7f3;
    --surface: #ffffff;
    --surface-strong: #edf2ec;
    --line: #d9e0d7;
    --text: #1d2a2f;
    --muted: #617078;
    --primary: #256f5a;
    --primary-strong: #17513f;
    --income: #1f7a5c;
    --expense: #b24747;
    --warning: #b77824;
    --info: #315f9d;
    --shadow: 0 14px 35px rgba(29, 42, 47, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    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 {
    min-height: 100vh;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 16px clamp(16px, 4vw, 44px);
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(14px);
}

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

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

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

.brand small {
    color: var(--muted);
    font-size: 0.78rem;
}

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

.topbar-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 14px;
}

.main-nav a {
    border-radius: 8px;
    padding: 9px 12px;
    color: var(--muted);
    font-weight: 700;
    text-decoration: none;
}

.main-nav a:hover,
.main-nav a.active {
    background: var(--surface-strong);
    color: var(--text);
}

.user-menu {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    border-left: 1px solid var(--line);
    padding-left: 14px;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 800;
}

.user-menu a {
    color: var(--expense);
    text-decoration: none;
}

.user-menu a:hover {
    text-decoration: underline;
}

.page {
    width: min(1280px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 56px;
}

.page-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 22px;
}

.page-heading h1 {
    margin: 0;
    font-size: clamp(2rem, 4vw, 3.4rem);
    line-height: 1.05;
}

.eyebrow {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
    text-transform: uppercase;
}

.heading-actions,
.form-actions,
.filters-actions,
.inline-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.button,
button {
    min-height: 42px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 10px 14px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

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

.button-primary:hover {
    background: var(--primary-strong);
}

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

.button-secondary:hover,
.button-ghost:hover {
    background: var(--surface-strong);
}

.button-ghost {
    background: transparent;
    border-color: transparent;
    color: var(--muted);
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

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

.metric-card {
    display: grid;
    gap: 8px;
    min-height: 132px;
    padding: 18px;
}

.metric-card span,
.metric-card small {
    color: var(--muted);
}

.metric-card strong {
    font-size: 1.55rem;
    line-height: 1.1;
}

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

.auth-page {
    display: grid;
    min-height: calc(100vh - 160px);
    place-items: center;
    padding: 24px 0;
}

.auth-panel {
    width: min(100%, 460px);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
    padding: 24px;
}

.auth-panel h1 {
    margin: 0;
    font-size: 1.8rem;
}

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

.section-alert {
    border-color: rgba(183, 120, 36, 0.4);
    background: #fffaf1;
}

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

.section-header h2 {
    margin: 0;
    font-size: 1.15rem;
}

.section-header p {
    margin: 3px 0 0;
    color: var(--muted);
}

.two-column {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 18px;
}

.form-grid,
.filters {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 14px;
    align-items: end;
}

.field {
    display: grid;
    gap: 6px;
}

.field span {
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 800;
}

.field-wide {
    grid-column: span 2;
}

.field-full {
    grid-column: 1 / -1;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid #cdd6ca;
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font: inherit;
    padding: 9px 11px;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(37, 111, 90, 0.14);
}

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

.filters {
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
    margin-bottom: 14px;
}

.summary-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 20px;
    margin-bottom: 14px;
    color: var(--muted);
    font-weight: 700;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

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

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

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

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

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

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 0.8rem;
    font-weight: 800;
}

.badge-income,
.badge-success {
    background: rgba(31, 122, 92, 0.12);
    color: var(--income);
}

.badge-expense {
    background: rgba(178, 71, 71, 0.12);
    color: var(--expense);
}

.badge-warning {
    background: rgba(183, 120, 36, 0.13);
    color: var(--warning);
}

.badge-muted {
    background: #edf0ef;
    color: var(--muted);
}

.category-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 7px;
    border-radius: 50%;
    background: var(--dot-color, var(--primary));
    vertical-align: middle;
}

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

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

.empty-state {
    border: 1px dashed #bfcbc0;
    border-radius: 8px;
    padding: 18px;
    color: var(--muted);
    background: #fbfcfa;
}

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

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

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

.list-row div {
    display: grid;
    gap: 2px;
}

.list-row span,
.cell-note {
    display: block;
    color: var(--muted);
    font-size: 0.86rem;
}

.inline-form {
    display: inline;
}

.link-button {
    min-height: auto;
    border: 0;
    background: transparent;
    color: var(--info);
    padding: 0;
    font-weight: 800;
}

.danger-text {
    color: var(--expense);
}

.muted-row {
    color: var(--muted);
    background: #fafafa;
}

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

.flash-success {
    border: 1px solid rgba(31, 122, 92, 0.28);
    background: rgba(31, 122, 92, 0.1);
    color: var(--income);
}

.flash-error {
    border: 1px solid rgba(178, 71, 71, 0.3);
    background: rgba(178, 71, 71, 0.1);
    color: var(--expense);
}

@media (max-width: 980px) {
    .topbar,
    .page-heading,
    .section-header {
        align-items: stretch;
        flex-direction: column;
    }

    .brand {
        min-width: 0;
    }

    .main-nav {
        justify-content: flex-start;
    }

    .topbar-actions {
        align-items: flex-start;
        flex-direction: column;
    }

    .user-menu {
        border-left: 0;
        padding-left: 0;
    }

    .metric-grid,
    .two-column {
        grid-template-columns: 1fr 1fr;
    }

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

@media (max-width: 640px) {
    .page {
        width: min(100% - 20px, 1280px);
        padding-top: 18px;
    }

    .topbar {
        padding: 12px 10px;
    }

    .metric-grid,
    .two-column,
    .form-grid,
    .filters {
        grid-template-columns: 1fr;
    }

    .field-wide,
    .field-full,
    .form-actions {
        grid-column: auto;
    }

    .page-heading h1 {
        font-size: 2rem;
    }
}
