:root {
    color-scheme: light;
    --background: #f3f0e8;
    --surface: #fffdf8;
    --text: #25241f;
    --muted: #6f6b60;
    --border: #d9d3c5;
    --accent: #276052;
    --accent-hover: #1d4b40;
    --error: #9f3128;
    --error-background: #fff0ed;
    --expense: #9b3a32;
    --expense-background: #fff1ee;
    --income: #216b50;
    --income-background: #edf8f2;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
        "Segoe UI", sans-serif;
    font-synthesis: none;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--background);
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 15% 10%, rgb(39 96 82 / 10%), transparent 34rem),
        var(--background);
}

button,
input,
select {
    font: inherit;
}

fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

legend {
    margin-bottom: 0.65rem;
    font-size: 0.9rem;
    font-weight: 750;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.75rem;
    padding: 0.7rem 1.1rem;
    border: 1px solid transparent;
    border-radius: 0.65rem;
    color: white;
    background: var(--accent);
    font-weight: 700;
    cursor: pointer;
    transition: background 120ms ease, transform 120ms ease;
}

button:hover {
    background: var(--accent-hover);
}

button:active {
    transform: translateY(1px);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible,
a:focus-visible {
    outline: 3px solid rgb(39 96 82 / 25%);
    outline-offset: 2px;
}

.login-shell {
    display: grid;
    min-height: 100vh;
    place-items: center;
    padding: 1.25rem;
}

.login-card {
    width: min(100%, 25rem);
    padding: clamp(1.75rem, 5vw, 2.5rem);
    border: 1px solid rgb(37 36 31 / 9%);
    border-radius: 1.15rem;
    background: var(--surface);
    box-shadow: 0 1.5rem 4rem rgb(37 36 31 / 10%);
}

.eyebrow {
    margin: 0 0 0.65rem;
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: clamp(2rem, 8vw, 2.75rem);
    letter-spacing: -0.045em;
    line-height: 1;
}

.login-intro {
    margin: 1rem 0 1.6rem;
    color: var(--muted);
    line-height: 1.55;
}

.login-form {
    display: grid;
    gap: 0.65rem;
}

.login-form label {
    font-size: 0.9rem;
    font-weight: 700;
}

.login-form input {
    width: 100%;
    min-height: 3rem;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    color: var(--text);
    background: white;
}

.login-form button {
    margin-top: 0.35rem;
}

.error-message {
    margin: 0 0 1rem;
    padding: 0.75rem 0.85rem;
    border: 1px solid rgb(159 49 40 / 20%);
    border-radius: 0.65rem;
    color: var(--error);
    background: var(--error-background);
    font-size: 0.9rem;
}

.app-shell {
    width: min(100% - 2rem, 70rem);
    margin-inline: auto;
    padding-block: 1.25rem;
}

.app-header {
    position: sticky;
    z-index: 10;
    top: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    min-height: 3rem;
    padding: 0.35rem 0.45rem 0.35rem 0.8rem;
    border: 1px solid rgb(37 36 31 / 12%);
    border-radius: 0.8rem;
    background: rgb(255 253 248 / 94%);
    box-shadow: 0 0.4rem 1.5rem rgb(37 36 31 / 10%);
    backdrop-filter: blur(0.7rem);
}

.session-user {
    min-width: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 0.82rem;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.header-icon-link,
.header-menu summary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.55rem;
    color: var(--text);
    background: transparent;
    font-size: 1.2rem;
    font-weight: 800;
    line-height: 1;
    text-decoration: none;
    cursor: pointer;
}

.header-icon-link:hover,
.header-menu summary:hover {
    background: #f0ede5;
}

.header-menu {
    position: relative;
}

.header-menu summary {
    list-style: none;
}

.header-menu summary::-webkit-details-marker {
    display: none;
}

.header-menu-panel {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    display: grid;
    gap: 0.35rem;
    width: min(18rem, calc(100vw - 2rem));
    padding: 0.55rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: var(--surface);
    box-shadow: 0 1rem 2.5rem rgb(37 36 31 / 16%);
}

.header-menu-panel a,
.header-menu-panel button {
    width: 100%;
    min-height: 2.5rem;
    justify-content: flex-start;
    padding: 0.6rem 0.75rem;
    border-radius: 0.55rem;
    color: var(--text);
    background: transparent;
    font-size: 0.9rem;
    font-weight: 700;
    text-align: left;
    text-decoration: none;
}

.header-menu-panel a:hover,
.header-menu-panel button:hover {
    background: #f0ede5;
}

.dashboard {
    margin-top: 1.5rem;
}

.loading-message {
    padding: 2rem;
    color: var(--muted);
    text-align: center;
}

.dashboard-summary,
.balances-card,
.transaction-list-card {
    border: 1px solid rgb(37 36 31 / 9%);
    border-radius: 1rem;
    background: var(--surface);
    box-shadow: 0 0.75rem 2.5rem rgb(37 36 31 / 7%);
}

.dashboard-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    padding: clamp(1.5rem, 5vw, 2.5rem);
}

.dashboard-summary h1 {
    font-size: clamp(1.6rem, 5vw, 2.2rem);
}

.net-amount {
    margin: 0.65rem 0 0;
    font-size: clamp(2.25rem, 9vw, 4.25rem);
    font-weight: 850;
    letter-spacing: -0.055em;
    line-height: 1;
}

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

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

.zero-amount {
    color: var(--text);
}

.primary-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.75rem;
    padding: 0.7rem 1.1rem;
    border-radius: 0.65rem;
    color: white;
    background: var(--accent);
    font-weight: 700;
    text-align: center;
    text-decoration: none;
}

.primary-link:hover {
    background: var(--accent-hover);
}

.balances-card,
.transaction-list-card {
    margin-top: 1rem;
    padding: clamp(1.25rem, 4vw, 2rem);
}

.balances-card h2,
.transaction-list-card h2 {
    margin: 0 0 1rem;
    font-size: 1.25rem;
}

.balance-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
    gap: 0.75rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.balance-list li {
    display: grid;
    gap: 0.2rem;
    padding: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: white;
}

.balance-list span {
    color: var(--muted);
    font-size: 0.85rem;
}

.balance-list strong {
    font-size: 1.25rem;
}

.transaction-list {
    margin: 0;
    padding: 0;
    list-style: none;
}

.transaction-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto auto;
    align-items: center;
    gap: 0.85rem;
    padding: 0.9rem 0;
    border-top: 1px solid var(--border);
}

.transaction-row:first-child {
    padding-top: 0;
    border-top: 0;
}

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

.transaction-category-icon {
    font-size: 1.5rem;
}

.transaction-details {
    display: grid;
    gap: 0.15rem;
    min-width: 0;
}

.transaction-details span,
.transaction-details small {
    overflow-wrap: anywhere;
}

.transaction-details span {
    color: var(--muted);
}

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

.transaction-amount {
    white-space: nowrap;
}

.transaction-delete {
    width: 2.5rem;
    min-height: 2.5rem;
    padding: 0.55rem;
    border-color: transparent;
    color: var(--muted);
    background: transparent;
}

.transaction-delete:hover {
    color: var(--error);
    background: var(--error-background);
}

.transaction-delete svg {
    width: 1.2rem;
    height: 1.2rem;
}

.transaction-card {
    width: min(100%, 48rem);
    margin: 1.5rem auto 0;
    padding: clamp(1.25rem, 4vw, 2rem);
    border: 1px solid rgb(37 36 31 / 9%);
    border-radius: 1rem;
    background: var(--surface);
    box-shadow: 0 0.75rem 2.5rem rgb(37 36 31 / 7%);
}

.back-link {
    display: inline-block;
    margin-bottom: 1.5rem;
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 700;
    text-decoration: none;
}

.back-link:hover {
    text-decoration: underline;
}

.transaction-card h1 {
    margin-bottom: 1.75rem;
    font-size: clamp(1.75rem, 6vw, 2.35rem);
}

.transaction-form {
    display: grid;
    gap: 1.35rem;
}

.field {
    display: grid;
    gap: 0.5rem;
    font-size: 0.9rem;
    font-weight: 700;
}

.field input,
.field select {
    width: 100%;
    min-height: 3rem;
    padding: 0.7rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    color: var(--text);
    background: white;
}

.amount-entry {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: end;
    gap: 0.75rem;
}

.direction-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    padding: 0;
    border: 1px solid var(--expense);
    border-radius: 0.65rem;
    color: var(--expense);
    background: var(--expense-background);
    font-size: 1.5rem;
    font-weight: 800;
    cursor: pointer;
}

.income-direction {
    display: none;
}

.amount-field input {
    border-color: rgb(155 58 50 / 45%);
    color: var(--expense);
    background: var(--expense-background);
    font-size: 1.15rem;
    font-weight: 750;
}

.direction-input:checked + .amount-entry .direction-toggle {
    border-color: var(--income);
    color: var(--income);
    background: var(--income-background);
}

.direction-input:checked + .amount-entry .expense-direction {
    display: none;
}

.direction-input:checked + .amount-entry .income-direction {
    display: inline;
}

.direction-input:checked + .amount-entry .amount-field input {
    border-color: rgb(33 107 80 / 45%);
    color: var(--income);
    background: var(--income-background);
}

.choice-grid {
    display: grid;
    gap: 0.65rem;
}

.category-grid {
    grid-template-columns: repeat(auto-fit, minmax(7rem, 1fr));
}

.scope-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-input,
.direction-input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    clip-path: inset(50%);
    white-space: nowrap;
}

.choice-card {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    min-height: 3.5rem;
    padding: 0.7rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: white;
    font-size: 0.9rem;
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    transition: border-color 120ms ease, background 120ms ease;
}

.choice-card:hover {
    border-color: var(--accent);
}

.choice-input:checked + .choice-card {
    border-color: var(--accent);
    background: rgb(39 96 82 / 10%);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.choice-input:focus-visible + .choice-card,
.direction-input:focus-visible + .amount-entry .direction-toggle {
    outline: 3px solid rgb(39 96 82 / 25%);
    outline-offset: 2px;
}

.category-icon,
.scope-icon {
    font-size: 1.35rem;
    line-height: 1;
}

.checkbox-field {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: fit-content;
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
}

.checkbox-field input {
    width: 1.15rem;
    height: 1.15rem;
    accent-color: var(--accent);
}

.recurring-toggle {
    padding-top: 0.25rem;
}

.recurring-fields {
    display: grid;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    background: #f8f5ee;
}

.recurring-fields[hidden],
#recurrence-count-field[hidden] {
    display: none;
}

.recurring-list-card {
    width: min(100%, 58rem);
}

.overview-card {
    margin-top: 1.5rem;
}

.overview-card > h1 {
    margin-bottom: 1.5rem;
    font-size: clamp(1.75rem, 6vw, 2.35rem);
}

.overview-filters {
    display: grid;
    gap: 1.25rem;
    padding: clamp(1rem, 3vw, 1.5rem);
    border: 1px solid rgb(37 36 31 / 9%);
    border-radius: 1rem;
    background: var(--surface);
    box-shadow: 0 0.75rem 2.5rem rgb(37 36 31 / 7%);
}

.overview-filter-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
    gap: 1rem;
}

.overview-filter-grid[hidden] {
    display: none;
}

.overview-tax-filter {
    min-height: 3rem;
}

.overview-results {
    margin-top: 1rem;
}

.overview-summary {
    padding: clamp(1.25rem, 4vw, 2rem);
}

.overview-summary h2 {
    margin: 0;
    font-size: clamp(1.5rem, 5vw, 2rem);
}

.recurring-transaction-row:first-child {
    padding-top: 0;
}

.form-result:empty {
    display: none;
}

.form-result .error-message {
    margin: 0;
}

.empty-message {
    margin: 0;
    color: var(--muted);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

@media (max-width: 32rem) {
    .app-shell {
        width: min(100% - 1rem, 70rem);
        padding-top: 0.5rem;
    }

    .dashboard-summary {
        align-items: stretch;
        flex-direction: column;
    }

    .transaction-row {
        grid-template-columns: auto minmax(0, 1fr) auto;
    }

    .transaction-amount {
        grid-column: 2;
    }

    .transaction-delete {
        grid-column: 3;
        grid-row: 2;
    }

    .scope-grid,
    .overview-filter-grid {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    button {
        transition: none;
    }
}
