:root {
    color-scheme: light;
    font-family: "Segoe UI", sans-serif;
    background: linear-gradient(180deg, #f3fbf5 0%, #dff3e5 55%, #ccead8 100%);
    color: #153226;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    background:
        radial-gradient(circle at top right, rgba(111, 214, 145, 0.22), transparent 28%),
        radial-gradient(circle at bottom left, rgba(22, 163, 74, 0.14), transparent 32%),
        linear-gradient(180deg, #f3fbf5 0%, #dff3e5 55%, #ccead8 100%);
}

.app-shell.hidden {
    display: none;
}

.auth-screen {
    position: relative;
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.auth-backdrop {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at top, rgba(21, 128, 61, 0.2), transparent 35%),
        radial-gradient(circle at bottom right, rgba(34, 197, 94, 0.16), transparent 32%);
}

.auth-card {
    position: relative;
    z-index: 1;
    width: min(30rem, 100%);
    padding: 2rem;
    border-radius: 28px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(34, 116, 74, 0.14);
    backdrop-filter: blur(12px);
    box-shadow: 0 24px 70px rgba(21, 101, 52, 0.14);
}

.auth-form,
.auth-password-fields {
    display: grid;
    gap: 1rem;
}

.auth-actions {
    justify-content: flex-start;
}

.auth-link-button {
    padding: 0;
    border: 0;
    background: transparent;
    color: #166534;
    box-shadow: none;
    text-decoration: underline;
}

.auth-link-button.hidden {
    display: none;
}

.topbar-branding {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.current-user-name {
    color: #46705a;
    font-size: 0.86rem;
    font-weight: 600;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(10px);
    background: rgba(240, 251, 243, 0.88);
    border-bottom: 1px solid rgba(34, 116, 74, 0.16);
    box-shadow: 0 10px 30px rgba(29, 78, 55, 0.06);
}

.topbar-inner {
    width: min(960px, calc(100% - 2rem));
    margin: 0 auto;
    min-height: 4.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    color: #14532d;
    text-decoration: none;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.04em;
}

.menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.menu a {
    color: #1f5138;
    text-decoration: none;
    padding: 0.65rem 0.95rem;
    border-radius: 999px;
    font-weight: 600;
    transition: background-color 160ms ease, color 160ms ease;
}

.menu a:hover,
.menu a.is-active {
    background: rgba(34, 197, 94, 0.14);
    color: #0f3d27;
}

.layout {
    width: min(960px, calc(100% - 2rem));
    margin: 0 auto;
    padding: 3rem 0 4rem;
}

.hero {
    margin-bottom: 2rem;
}

.app-version {
    font-size: 0.52em;
    font-weight: 600;
    color: #2f6b4e;
    vertical-align: middle;
}

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.8rem;
    color: #15803d;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

h1,
h2,
h3 {
    color: #123524;
}

.lede,
.section-copy {
    max-width: 40rem;
    color: #3d6650;
}

.view-section {
    display: none;
}

.view-section.is-active {
    display: block;
}

.panel {
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(34, 116, 74, 0.14);
    border-radius: 20px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    backdrop-filter: blur(10px);
    box-shadow: 0 20px 50px rgba(22, 101, 52, 0.08);
}

.empty-state-panel {
    min-height: 12rem;
}

form {
    display: grid;
    gap: 1rem;
}

.expense-form-row {
    display: grid;
    gap: 1rem;
}

.expense-form-row > label {
    min-width: 0;
}

.expense-advanced {
    border: 1px solid rgba(34, 116, 74, 0.14);
    border-radius: 16px;
    padding: 0.85rem 1rem;
    background: rgba(248, 254, 249, 0.65);
}

.expense-advanced summary {
    cursor: pointer;
    font-weight: 700;
    color: #14532d;
}

.expense-advanced-grid,
.expense-recurring-fields {
    display: grid;
    gap: 1rem;
    margin-top: 0.9rem;
}

.expense-recurring-repeat {
    display: grid;
    gap: 1rem;
}

.expense-recurring-checkbox {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.expense-recurring-checkbox input {
    width: auto;
}

label {
    display: grid;
    gap: 0.4rem;
    font-weight: 600;
    color: #204732;
}

input,
select,
button {
    font: inherit;
    font-size: 0.92rem;
}

input,
select {
    width: 100%;
    padding: 0.8rem 0.9rem;
    border-radius: 12px;
    border: 1px solid #a7d7b6;
    background: #f8fef9;
    color: #153226;
}

input:focus,
select:focus {
    outline: 2px solid rgba(34, 197, 94, 0.22);
    border-color: #22c55e;
}

button {
    width: fit-content;
    border: none;
    border-radius: 999px;
    padding: 0.55rem 0.95rem;
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    color: #ffffff;
    cursor: pointer;
    box-shadow: 0 12px 24px rgba(21, 128, 61, 0.22);
}

button.secondary {
    background: #d9f4e1;
    color: #14532d;
    box-shadow: none;
}

button.danger {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%);
    color: #ffffff;
    box-shadow: 0 12px 24px rgba(185, 28, 28, 0.18);
}

.hidden {
    display: none;
}

.scope-dialog {
    width: min(32rem, calc(100% - 2rem));
    border: 1px solid rgba(34, 116, 74, 0.2);
    border-radius: 18px;
    padding: 0;
    background: rgba(247, 254, 249, 0.97);
    box-shadow: 0 20px 40px rgba(21, 101, 52, 0.22);
}

.scope-dialog::backdrop {
    background: rgba(9, 35, 22, 0.38);
}

.scope-dialog-form {
    padding: 1.25rem;
}

.scope-dialog-form p {
    color: #2b5a41;
    margin-bottom: 1rem;
}

.panel-header,
.form-actions,
.category-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.form-actions {
    justify-content: flex-start;
}

.expense-filters {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto minmax(0, 1fr) minmax(10rem, 0.9fr) auto;
    gap: 0.9rem;
    margin-bottom: 0.5rem;
    align-items: end;
}

.expense-filters .form-actions {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 0.5rem;
}

.expense-month-nav {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
}

.expense-month-nav button {
    min-width: 2rem;
    padding-left: 0;
    padding-right: 0;
}

.expense-balance-summary {
    margin-bottom: 0.45rem;
    padding: 0.45rem 0.7rem;
    border-radius: 12px;
    background: rgba(202, 232, 212, 0.45);
    color: #14532d;
    font-size: 0.88rem;
    font-weight: 600;
}

.expense-list,
.category-list {
    display: grid;
    gap: 0.45rem;
}

.expense-table {
    border: 1px solid #cae8d4;
    border-radius: 16px;
    overflow: hidden;
    background: linear-gradient(180deg, #f9fffa 0%, #effaf2 100%);
}

.expense-date-heading {
    display: none;
}

.expense-table-header,
.expense-row {
    display: grid;
    grid-template-columns: 6.25rem minmax(0, 2fr) minmax(0, 1.2fr) 2.25rem 6rem 7rem 9rem;
    gap: 1rem;
    align-items: center;
    padding: 0.18rem 0.65rem;
}

.expense-table-header {
    font-size: 0.8rem;
    font-weight: 700;
    color: #46705a;
    background: rgba(202, 232, 212, 0.45);
}

.expense-row + .expense-row {
    border-top: 1px solid #cae8d4;
}

.expense-date-group + .expense-date-group {
    border-top: 1px solid #cae8d4;
}

.expense-row {
    font-size: 0.9rem;
    color: #14532d;
    line-height: 1.2;
}

.expense-row-consolidate {
    background: #e8f6ec;
}

.expense-row-non-consolidate {
    background: #ffffff;
}

.expense-table-amount {
    text-align: right;
    color: #14532d;
}

.expense-cell-type {
    text-align: left;
    font-weight: 700;
    color: #46705a;
}

.expense-cell-amount.is-debit {
    color: #b91c1c;
}

.expense-recurring-forever {
    display: inline-block;
    margin-left: 0.3rem;
    color: #15803d;
    font-weight: 700;
}

.expense-cell-balance.is-negative {
    color: #b91c1c;
}

.expense-cell-balance.is-positive {
    color: #166534;
}

.category-list p {
    color: #46705a;
}

.expense-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.55rem;
}

.expense-actions button {
    padding: 0.2rem 0.55rem;
    font-size: 0.82rem;
}

.expense-table-actions {
    text-align: right;
}

.category-groups {
    display: grid;
    gap: 0.9rem;
}

.category-group {
    border: 1px solid #cae8d4;
    border-radius: 16px;
    background: linear-gradient(180deg, #f9fffa 0%, #effaf2 100%);
    overflow: hidden;
}

.category-group-title {
    padding: 0.75rem 0.9rem 0;
    font-size: 0.8rem;
    font-weight: 700;
    color: #46705a;
}

.category-items {
    list-style: none;
    margin: 0;
    padding: 0;
}

.category-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.18rem 0.65rem;
}

.category-item + .category-item {
    border-top: 1px solid #cae8d4;
}

.category-item.is-subcategory {
    padding-left: 1.95rem;
}

.category-item-name {
    font-weight: 600;
    font-size: 0.9rem;
    color: #14532d;
}

.category-item p {
    margin-top: 0.12rem;
    margin-bottom: 0;
    font-size: 0.82rem;
    line-height: 1.2;
}

.category-item.is-expired-user {
    background: rgba(254, 226, 226, 0.6);
}

.category-item.is-expired-user .category-item-name,
.category-item.is-expired-user p {
    color: #991b1b;
}

.expired-user-badge {
    display: inline-block;
    margin-left: 0.45rem;
    padding: 0.14rem 0.45rem;
    border-radius: 999px;
    background: #fecaca;
    color: #991b1b;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.category-actions button {
    padding: 0.2rem 0.55rem;
    font-size: 0.82rem;
}

.expense-meta {
    text-align: right;
}

.expense-meta strong {
    color: #166534;
}

.status {
    min-height: 1.5rem;
    margin-bottom: 0;
    color: #15803d;
}

@media (min-width: 641px) {
    body {
        font-size: 0.85rem;
    }

    .brand {
        font-size: 0.92rem;
    }

    .menu a {
        padding: 0.4rem 0.66rem;
        font-size: 0.8rem;
    }

    .eyebrow {
        font-size: 0.64rem;
    }

    h1 {
        font-size: 1.62rem;
    }

    h2 {
        font-size: 1.06rem;
    }

    h3 {
        font-size: 0.92rem;
    }

    .lede,
    .section-copy,
    p,
    label,
    input,
    select {
        font-size: 0.8rem;
    }

    button {
        padding: 0.34rem 0.64rem;
        font-size: 0.74rem;
    }

    .expense-table-header,
    .expense-row {
        padding: 0.14rem 0.52rem;
        gap: 0.65rem;
    }

    .expense-table-header {
        font-size: 0.7rem;
    }

    .expense-row {
        font-size: 0.78rem;
    }

    .expense-form-row-primary {
        grid-template-columns: minmax(0, 1.85fr) minmax(8rem, 0.9fr);
        align-items: end;
    }

    .expense-form-row-secondary {
        grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.2fr) minmax(9rem, 0.9fr) auto;
        align-items: end;
    }

    .expense-recurring-repeat {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    .topbar-inner,
    .layout {
        width: min(100% - 1rem, 960px);
    }

    .topbar-inner {
        min-height: auto;
        padding: 0.9rem 0;
        flex-direction: column;
        align-items: flex-start;
    }

    .menu,
    .form-actions,
    .category-actions,
    .expense-actions {
        flex-wrap: wrap;
    }

    .layout {
        padding-top: 1rem;
    }

    .panel-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .category-item {
        gap: 0.45rem;
        padding: 0.24rem 0.75rem;
    }

    .expense-filters {
        grid-template-columns: 1fr;
    }

    .expense-table-header {
        display: none;
    }

    .expense-date-heading {
        display: block;
        padding: 0.75rem 0.9rem 0.35rem;
        font-size: 0.82rem;
        font-weight: 700;
        color: #46705a;
    }

    .expense-row {
        grid-template-columns: minmax(0, 1fr) auto auto;
        grid-template-areas:
            "description amount type"
            "category balance balance"
            "actions actions actions";
        gap: 0.35rem 0.75rem;
        padding: 0.28rem 0.75rem;
    }

    .expense-cell-date {
        display: none;
    }

    .expense-cell-description {
        grid-area: description;
        font-weight: 600;
    }

    .expense-cell-category {
        grid-area: category;
        color: #46705a;
        font-size: 0.82rem;
    }

    .expense-cell-amount {
        grid-area: amount;
    }

    .expense-cell-type {
        grid-area: type;
        justify-self: start;
        align-self: center;
    }

    .expense-cell-balance {
        grid-area: balance;
    }

    .expense-actions {
        grid-area: actions;
    }

    .expense-table-amount {
        text-align: right;
    }

    .expense-table-actions {
        text-align: left;
    }

    .expense-actions {
        justify-content: flex-start;
    }
}
