* {
    box-sizing: border-box;
}

:root {
    --sidebar-width: 250px;
    --radius: 18px;
    --shadow: 0 4px 24px rgba(24, 39, 75, 0.045);
    --success-bg: #ecfdf3;
    --danger-bg: #fff1f2;
    
    --accent-h: 220;
    --accent-s: 85%;
    --accent-l: 56%;

    --primary:
        hsl(
            var(--accent-h),
            var(--accent-s),
            var(--accent-l)
        );

    --primary-hover:
        hsl(
            var(--accent-h),
            var(--accent-s),
            calc(var(--accent-l) - 8%)
        );

    --primary-soft:
        hsl(
            var(--accent-h),
            80%,
            96%
        );
    --primary-dark:
        color-mix(
            in srgb,
            var(--primary) 40%,
            black
        );

    --primary-border:
        hsl(
            var(--accent-h),
            55%,
            82%
        );

    --primary-text:
        hsl(
            var(--accent-h),
            65%,
            28%
        );

    --background: #f5f7fa;
    --surface: #ffffff;
    --border: #e4e7ec;
    --text: #1f2937;
    --muted: #6b7280;

    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
}


html,
body {
    margin: 0;
    min-height: 100%;
}


body {
    font-family:
        Inter,
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;

    background: var(--background);
    color: var(--text);
}


/* ----------------------------------------------------
   Sidebar
---------------------------------------------------- */

.app-sidebar {
    position: fixed;

    left: 0;
    top: 0;
    bottom: 0;

    width: var(--sidebar-width);

    display: flex;
    flex-direction: column;

    background: var(--primary-dark);

    padding: 22px 16px;

    z-index: 1000;
}


.sidebar-brand {
    display: flex;
    align-items: center;

    gap: 12px;

    padding: 6px 8px 28px;

    color: white;
}


.brand-icon {
    width: 40px;
    height: 40px;

    display: flex;
    align-items: center;
    justify-content: center;

    border-radius: 11px;

    background: white;
    color: #15181d;

    font-weight: 800;
    font-size: 20px;
}


.sidebar-brand strong,
.sidebar-brand span {
    display: block;
}


.sidebar-brand strong {
    font-size: 15px;
}


.sidebar-brand span {
    margin-top: 3px;

    font-size: 12px;

    color: #8e96a2;
}


.sidebar-nav {
    display: flex;
    flex-direction: column;

    gap: 5px;
}


.nav-item {
    display: flex;
    align-items: center;

    gap: 11px;

    min-height: 46px;

    padding: 0 13px;

    border-radius: 9px;

    color: #aab0b9;

    text-decoration: none;

    transition:
        background 0.15s ease,
        color 0.15s ease;
}


.nav-item:hover {
    background: rgba(255,255,255,0.06);
    color: white;
}


.nav-item.active {
    background: var(--primary-soft);
    color: var(--primary-text);

    font-weight: 600;
}


.nav-icon {
    width: 22px;

    text-align: center;

    font-size: 17px;
}


/* ----------------------------------------------------
   Sidebar user / theme
---------------------------------------------------- */

.sidebar-footer {
    margin-top: auto;

    padding: 16px;

    border-top:
        1px solid
        rgba(255, 255, 255, 0.08);
}


.sidebar-user {
    display: flex;

    align-items: center;
    justify-content: space-between;

    gap: 12px;

    width: 100%;

    margin-bottom: 12px;
}


.sidebar-user-info {
    display: flex;
    flex-direction: column;

    min-width: 0;
}


.sidebar-user-info strong {
    color: white;

    font-size: 14px;

    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}


.sidebar-user-info small {
    margin-top: 2px;

    color: #9ca3af;

    font-size: 11px;
}


/* Theme picker */

.theme-form {
    flex: 0 0 auto;

    margin: 0;
    padding: 0;
}


.theme-color-picker {
    display: block;

    width: 34px !important;
    height: 34px !important;

    min-width: 34px !important;

    padding: 2px !important;
    margin: 0 !important;

    border:
        1px solid
        rgba(255, 255, 255, 0.18) !important;

    border-radius: 8px;

    background: transparent;

    cursor: pointer;
}


/* Chrome color picker internals */

.theme-color-picker::-webkit-color-swatch-wrapper {
    padding: 2px;
}


.theme-color-picker::-webkit-color-swatch {
    border: 0;

    border-radius: 5px;
}


/* Firefox */

.theme-color-picker::-moz-color-swatch {
    border: 0;

    border-radius: 5px;
}


/* Logout */

.sidebar-logout-form {
    margin: 0;
}


.sidebar-logout {
    padding: 0;

    border: 0;

    background: none;

    color: #9ca3af;

    font: inherit;

    cursor: pointer;
}


.sidebar-logout:hover {
    color: white;
}

/* ----------------------------------------------------
   Main application
---------------------------------------------------- */

.app-main {
    min-height: 100vh;

    margin-left: var(--sidebar-width);
}


.page,
.form-page {
    max-width: 1500px;

    margin: 0 auto;

    padding: 40px 34px;
}


.page-header,
.form-header {
    display: flex;

    justify-content: space-between;
    align-items: center;

    gap: 20px;

    margin-bottom: 28px;
}


h1 {
    margin: 0;

    font-size: 31px;

    letter-spacing: -0.03em;
}


h2 {
    margin: 0;

    font-size: 19px;
}


.subtitle {
    margin: 6px 0 0;

    color: var(--muted);
}


/* ----------------------------------------------------
   Panels
---------------------------------------------------- */

.panel,
.form-card {
    background: var(--surface);

    border: 1px solid var(--border);

    border-radius: var(--radius);

    padding: 24px;

    margin-bottom: 22px;

    box-shadow: var(--shadow);
}


.panel-header {
    display: flex;

    justify-content: space-between;
    align-items: center;

    gap: 20px;

    margin-bottom: 18px;
}


/* ----------------------------------------------------
   KPI cards
---------------------------------------------------- */

.kpi-grid {
    display: grid;

    grid-template-columns:
        repeat(4, minmax(0, 1fr));

    gap: 16px;

    margin-bottom: 22px;
}


.kpi {
    background: var(--surface);

    border: 1px solid var(--border);

    border-radius: var(--radius);

    padding: 21px;

    box-shadow: var(--shadow);
}


.kpi span {
    display: block;

    margin-bottom: 10px;

    color: var(--muted);

    font-size: 14px;
}


.kpi strong {
    font-size: 26px;

    letter-spacing: -0.03em;
}


/* ----------------------------------------------------
   Forms
---------------------------------------------------- */

.field label,
.filters label,
.category-create-form label {
    display: block;

    margin-bottom: 7px;

    font-size: 14px;
    font-weight: 600;
}


input,
select,
textarea {
    width: 100%;

    min-height: 42px;

    padding: 10px 12px;

    border:
        1px solid #d6dbe1;

    border-radius: 8px;

    font: inherit;

    color: var(--text);

    background: white;
}


textarea {
    resize: vertical;
}


input:focus,
select:focus,
textarea:focus {
    outline: none;

    border-color: var(--primary);

    box-shadow:
        0 0 0 3px
        var(--primary-soft);
}


.filters {
    display: grid;

    grid-template-columns:
        repeat(3, minmax(180px, 1fr));

    gap: 16px;
}


.expense-form {
    display: grid;

    gap: 20px;
}


.form-card {
    max-width: 720px;
}


.form-actions,
.filter-actions {
    display: flex;

    gap: 10px;

    align-items: end;
}


/* ----------------------------------------------------
   Buttons
---------------------------------------------------- */

.button {
    display: inline-flex;

    align-items: center;
    justify-content: center;

    min-height: 40px;

    padding: 9px 14px;

    border:
        1px solid #d4d9df;

    border-radius: 8px;

    background: white;

    color: var(--text);

    font: inherit;

    text-decoration: none;

    cursor: pointer;

    transition:
        background 0.15s ease,
        border-color 0.15s ease;
}


.button:hover {
    background: #f4f6f8;
}


.button.primary {
    color: white;

    background: var(--primary);

    border-color: var(--primary);
}


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


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


.button.small {
    min-height: 34px;

    padding: 6px 10px;

    font-size: 13px;
}


/* ----------------------------------------------------
   Tables
---------------------------------------------------- */

.table-container {
    width: 100%;

    overflow-x: auto;
}


table {
    width: 100%;

    border-collapse: collapse;
}


th {
    color: var(--muted);

    font-size: 12px;

    text-transform: uppercase;

    letter-spacing: 0.05em;
}


th,
td {
    padding: 14px 12px;

    text-align: left;

    border-bottom:
        1px solid #edf0f3;
}


tbody tr:hover {
    background: #fafbfc;
}


.amount {
    text-align: right;
}


.actions {
    display: flex;

    gap: 8px;
}


.actions form {
    margin: 0;
}


/* ----------------------------------------------------
   Categories
---------------------------------------------------- */

.category {
    display: inline-block;

    padding: 5px 10px;

    border-radius: 20px;

    background: #eef2f6;

    font-size: 13px;
}


.category-grid {
    display: grid;

    grid-template-columns:
        repeat(3, minmax(0, 1fr));

    gap: 12px;
}


.category-summary {
    display: flex;

    justify-content: space-between;

    gap: 20px;

    padding: 16px;

    border: 1px solid var(--border);

    border-radius: 10px;
}


.category-summary strong,
.category-summary small {
    display: block;
}


.category-summary small {
    margin-top: 4px;

    color: var(--muted);
}


.category-create-form {
    display: grid;

    grid-template-columns:
        170px
        minmax(200px, 1fr)
        minmax(200px, 1fr)
        auto;

    gap: 16px;

    align-items: end;
}


/* ----------------------------------------------------
   Status messages
---------------------------------------------------- */

.status {
    display: inline-flex;

    padding: 5px 9px;

    border-radius: 20px;

    font-size: 12px;

    font-weight: 600;
}


.status.active {
    color: var(--success);

    background: var(--success-bg);
}


.status.inactive {
    color: #667085;

    background: #f2f4f7;
}


.success-message {
    margin-bottom: 20px;

    padding: 12px 14px;

    border:
        1px solid #abefc6;

    border-radius: 8px;

    color: var(--success);

    background: var(--success-bg);
}


.error {
    margin-bottom: 20px;

    padding: 12px 14px;

    border:
        1px solid #f1b8b4;

    border-radius: 8px;

    color: var(--danger);

    background: var(--danger-bg);
}


.empty {
    padding: 36px;

    text-align: center;

    color: var(--muted);
}


.back {
    display: inline-block;

    margin-bottom: 10px;

    color: var(--muted);

    text-decoration: none;
}


/* ----------------------------------------------------
   Mobile navigation
---------------------------------------------------- */

.mobile-topbar,
.mobile-overlay {
    display: none;
}


@media (max-width: 1000px) {

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

    .filters,
    .category-grid {
        grid-template-columns:
            repeat(2, 1fr);
    }

    .category-create-form {
        grid-template-columns:
            repeat(2, 1fr);
    }

}


@media (max-width: 760px) {

    .mobile-topbar {
        position: sticky;

        top: 0;

        z-index: 900;

        height: 58px;

        display: flex;

        align-items: center;
        justify-content: space-between;

        padding: 0 18px;

        background: white;

        border-bottom:
            1px solid var(--border);
    }


    .mobile-menu-button {
        border: 0;

        background: transparent;

        font-size: 24px;

        cursor: pointer;
    }


    /* ----------------------------------------------
       Mobile sidebar
    ---------------------------------------------- */

    .app-sidebar {
        position: fixed;

        top: 0;
        left: 0;
        bottom: 0;

        width: var(--sidebar-width);
        height: 100vh;

        display: flex;
        flex-direction: column;

        /*
         * Hidden by default on mobile
         */
        transform: translateX(-100%);

        transition:
            transform 0.25s ease;

        z-index: 1000;
    }


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


    /* ----------------------------------------------
       Main content
    ---------------------------------------------- */

    .app-main {
        margin-left: 0;

        min-height: 100vh;
    }


    /* ----------------------------------------------
       Overlay
    ---------------------------------------------- */

    .mobile-overlay {
        position: fixed;

        inset: 0;

        z-index: 950;

        background:
            rgba(0, 0, 0, 0.35);

        display: none;
    }


    body.menu-open .mobile-overlay {
        display: block;
    }


    body.menu-open {
        overflow: hidden;
    }


    .page,
    .form-page {
        padding: 24px 16px;
    }


    .page-header {
        flex-direction: column;

        align-items: stretch;
    }


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


    .actions {
        min-width: 150px;
    }

}

/* ----------------------------------------------------
   Budgets
---------------------------------------------------- */

.year-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

.year-selector label {
    color: var(--muted);
    font-size: 14px;
}

.year-selector select {
    width: auto;
    min-width: 110px;
}


.panel-description {
    margin: 5px 0 0;

    color: var(--muted);

    font-size: 14px;
}


.budget-table td {
    vertical-align: middle;
}


.budget-category strong,
.budget-category small {
    display: block;
}


.budget-category small {
    margin-top: 5px;

    color: var(--muted);

    font-size: 12px;
}


.budget-category .status {
    margin-left: 7px;
}


.budget-target-cell {
    width: 190px;
}


.money-input {
    position: relative;

    max-width: 170px;
}


.money-input span {
    position: absolute;

    left: 12px;
    top: 50%;

    transform: translateY(-50%);

    color: var(--muted);

    pointer-events: none;
}


.money-input input {
    padding-left: 27px;

    text-align: right;
}


.budget-progress-info {
    display: flex;

    justify-content: space-between;

    gap: 10px;

    margin-bottom: 7px;

    font-size: 12px;

    color: var(--muted);
}


.progress-bar {
    width: 100%;
    min-width: 130px;
    height: 9px;

    overflow: hidden;

    border-radius: 20px;

    background: #e9edf1;
}


.progress-fill {
    width: 0;
    height: 100%;

    border-radius: inherit;

    background: var(--primary);

    transition:
        width 0.25s ease;
}


.progress-bar.warning
.progress-fill {
    background: #d99a25;
}


.progress-bar.critical
.progress-fill {
    background: #e3672f;
}


.progress-bar.over
.progress-fill {
    background: var(--danger);
}


.budget-no-target {
    color: var(--muted);

    font-size: 13px;
}


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


.budget-inactive {
    opacity: 0.6;
}


@media (max-width: 760px) {

    .year-selector {
        align-items: stretch;
        flex-direction: column;
    }

    .year-selector select {
        width: 100%;
    }

}
/* ----------------------------------------------------
   Dashboard
---------------------------------------------------- */

.dashboard-period {
    display: flex;
    gap: 12px;
    align-items: end;
}

.dashboard-quick-actions {
    display: none;
}

@media (max-width: 760px) {
    .page.dashboard-page {
        padding-bottom: calc(100px + env(safe-area-inset-bottom, 0px));
    }

    .dashboard-quick-actions {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 1100;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        padding: 12px calc(20px + env(safe-area-inset-right, 0px)) calc(12px + env(safe-area-inset-bottom, 0px)) calc(20px + env(safe-area-inset-left, 0px));
        background: var(--surface);
        border-top: 1px solid var(--border);
        box-shadow: 0 -4px 20px rgba(24, 39, 75, 0.08);
    }

    .dashboard-action {
        display: inline-flex;
        flex: 1;
        align-items: center;
        justify-content: center;
        gap: 8px;
        min-width: 0;
        max-width: 240px;
        min-height: 50px;
        padding: 12px 10px;
        border: 1px solid transparent;
        border-radius: 14px;
        font-size: 14px;
        font-weight: 650;
        line-height: 1.25;
        text-decoration: none;
    }

    .dashboard-action svg {
        flex-shrink: 0;
    }

    .dashboard-add-expense {
        background: var(--primary);
        color: white;
        box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 22%, transparent);
    }

    .dashboard-add-expense:hover {
        background: var(--primary-hover);
    }

    .dashboard-add-income {
        background: var(--success-bg);
        border-color: #bbf7d0;
        color: #166534;
    }

    .dashboard-add-income:hover {
        background: #dcfce7;
        border-color: #86efac;
    }
}


.dashboard-period > div {
    min-width: 150px;
}


.dashboard-period label {
    display: block;

    margin-bottom: 6px;

    color: var(--muted);

    font-size: 13px;
}


.dashboard-kpi-grid {
    display: grid;

    grid-template-columns:
        repeat(4, minmax(0, 1fr));

    gap: 16px;

    margin-bottom: 22px;
}


.dashboard-kpi {
    padding: 22px;

    background: var(--surface);

    border:
        1px solid var(--border);

    border-radius: var(--radius);

    box-shadow: var(--shadow);
}


.dashboard-kpi span,
.dashboard-kpi small {
    display: block;
}


.dashboard-kpi span {
    color: var(--muted);

    font-size: 14px;
}


.dashboard-kpi strong {
    display: block;

    margin: 10px 0 7px;

    font-size: 27px;

    letter-spacing: -0.03em;
}


.dashboard-kpi small {
    color: var(--muted);
}


.text-success {
    color: var(--success);
}


.muted {
    color: var(--muted);
}


.month-summary-grid,
.budget-overview-grid {
    display: grid;

    grid-template-columns:
        repeat(4, minmax(0, 1fr));

    gap: 1px;

    overflow: hidden;

    border:
        1px solid var(--border);

    border-radius: 10px;

    background: var(--border);
}


.month-summary-grid {
    grid-template-columns:
        repeat(3, minmax(0, 1fr));
}


.month-summary-grid > div,
.budget-overview-grid > div {
    padding: 18px;

    background: white;
}


.month-summary-grid span,
.budget-overview-grid span {
    display: block;

    margin-bottom: 8px;

    color: var(--muted);

    font-size: 13px;
}


.month-summary-grid strong,
.budget-overview-grid strong {
    font-size: 21px;
}


.dashboard-chart {
    position: relative;

    height: 350px;
}


.progress-label {
    display: block;

    margin-top: 5px;

    color: var(--muted);

    text-align: right;
}


.budget-ytd-detail,
.budget-good,
.budget-bad {
    display: block;

    margin-top: 4px;

    font-size: 12px;
}


.budget-ytd-detail {
    color: var(--muted);
}


.budget-good {
    color: var(--success);
}


.budget-bad {
    color: var(--danger);
}


.transaction-type {
    display: inline-flex;

    padding: 5px 9px;

    border-radius: 20px;

    font-size: 12px;

    font-weight: 600;
}


.transaction-type.income {
    color: var(--success);

    background:
        var(--success-bg);
}


.transaction-type.expense {
    color: var(--danger);

    background:
        var(--danger-bg);
}


@media (max-width: 1100px) {

    .dashboard-kpi-grid {
        grid-template-columns:
            repeat(2, 1fr);
    }

}


@media (max-width: 760px) {

    .dashboard-period {
        width: 100%;

        flex-direction: column;

        align-items: stretch;
    }


    .dashboard-kpi-grid {
        grid-template-columns:
            1fr;
    }


    .month-summary-grid,
    .budget-overview-grid {
        grid-template-columns:
            1fr;
    }


    .dashboard-chart {
        height: 290px;
    }

}

/* ----------------------------------------------------
   Login
---------------------------------------------------- */

.login-page {
    min-height: 100vh;

    display: flex;

    align-items: center;
    justify-content: center;

    padding: 24px;

    background:
        var(--background);
}


.login-card {
    width: 100%;
    max-width: 420px;

    padding: 32px;

    background: var(--surface);

    border:
        1px solid var(--border);

    border-radius: 18px;

    box-shadow:
        var(--shadow);
}


.login-brand {
    display: flex;

    gap: 14px;

    align-items: center;

    margin-bottom: 28px;
}


.login-brand .brand-icon {
    background: var(--primary);

    color: white;
}


.login-brand h1 {
    font-size: 22px;
}


.login-brand p {
    margin:
        4px 0 0;

    color: var(--muted);
}


.login-form {
    display: grid;

    gap: 18px;
}


.login-button {
    width: 100%;

    margin-top: 5px;
}

/* ----------------------------------------------------
   Admin role toggle
---------------------------------------------------- */

.admin-toggle {
    display: flex;
    align-items: center;
    gap: 12px;

    width: 100%;

    padding: 14px 16px;

    border: 1px solid var(--border);
    border-radius: 10px;

    background: var(--surface);

    cursor: pointer;

    box-sizing: border-box;
}


.admin-toggle input[type="checkbox"] {
    position: absolute !important;

    width: 1px !important;
    height: 1px !important;

    margin: 0 !important;
    padding: 0 !important;

    opacity: 0;

    pointer-events: none;
}


.admin-toggle-box {
    position: relative;

    display: inline-block;

    flex: 0 0 44px;

    width: 44px;
    height: 24px;

    min-width: 44px;

    border-radius: 999px;

    background: #d1d5db;

    transition: background 0.2s ease;
}


.admin-toggle-box::after {
    content: '';

    position: absolute;

    top: 3px;
    left: 3px;

    width: 18px;
    height: 18px;

    border-radius: 50%;

    background: #ffffff;

    box-shadow:
        0 1px 4px
        rgba(0, 0, 0, 0.25);

    transition: transform 0.2s ease;
}


.admin-toggle input[type="checkbox"]:checked
+ .admin-toggle-box {
    background: var(--primary);
}


.admin-toggle input[type="checkbox"]:checked
+ .admin-toggle-box::after {
    transform: translateX(20px);
}


.admin-toggle-text {
    display: flex;
    flex-direction: column;

    gap: 3px;

    min-width: 0;
}


.admin-toggle-text strong {
    display: block;

    font-size: 14px;
}


.admin-toggle-text small {
    display: block;

    color: var(--muted);

    font-size: 12px;
    line-height: 1.35;
}

.button.danger {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}


.button.danger:hover {
    opacity: 0.9;
}

.import-form { margin-top: 22px; }
.budget-average-status { display: block; margin-top: 4px; font-size: 12px; }
.pwa-install-dialog {
    width: min(440px, calc(100% - 32px));
    max-height: calc(100dvh - 40px);
    overflow-y: auto;
    margin: auto auto max(20px, env(safe-area-inset-bottom));
    padding: 28px;
    border: 1px solid var(--border);
    border-radius: 22px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 20px 70px rgba(15, 23, 42, 0.2);
}
.pwa-install-dialog[open] { animation: rise-in 300ms var(--ease-out) both; }
.pwa-install-dialog::backdrop { background: rgba(15, 23, 42, 0.45); backdrop-filter: blur(3px); }
.pwa-install-icon { display: block; margin-bottom: 18px; border-radius: 16px; }
.pwa-install-dialog p, .pwa-install-dialog li { color: var(--muted); }
.pwa-install-dialog ol { padding-left: 22px; }
.pwa-install-dialog li + li { margin-top: 8px; }
.pwa-install-dialog .form-actions { margin-top: 22px; }
.pwa-install-close {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-size: 26px;
    cursor: pointer;
}
.pwa-install-close:hover { background: var(--primary-soft); }
.csv-download-dialog {
    width: min(440px, calc(100% - 32px));
    max-height: calc(100dvh - 40px);
    overflow-y: auto;
    padding: 26px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: var(--surface);
    color: var(--text);
    box-shadow: 0 20px 70px rgba(15, 23, 42, 0.2);
}
.csv-download-dialog::backdrop { background: rgba(15, 23, 42, 0.45); }
.csv-download-dialog .form-actions { margin-top: 20px; }
.csv-download-dialog [hidden], .pwa-install-dialog [hidden] { display: none !important; }
.import-confirm, .import-categories { margin-top: 20px; }
.import-text { white-space: pre-wrap; overflow-wrap: anywhere; min-width: 160px; max-width: 360px; }
.button:disabled { opacity: 0.6; cursor: not-allowed; }

/* Shared visual refresh. Keep all financial and form layouts intact. */
:root {
    --background: #f6f7fb;
    --border: #e6e9f1;
    --text: #202b40;
    --muted: #647087;
    --primary-hover: color-mix(in srgb, var(--primary) 84%, #172033);
    --primary-soft: color-mix(in srgb, var(--primary) 7%, white);
    --primary-border: color-mix(in srgb, var(--primary) 25%, white);
    --primary-text: color-mix(in srgb, var(--primary) 65%, #172033);
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

body {
    font-size: 14px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    background: radial-gradient(ellipse at 100% 0, var(--primary-soft), transparent 55%), var(--background);
}

::selection { background: var(--primary-border); color: var(--text); }

:where(a, button, input, select, textarea):focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 4px;
}

.app-sidebar {
    background: linear-gradient(165deg, #202c45, #121c30 80%);
    padding: 28px 16px 20px;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 8px 0 32px rgba(20, 30, 50, 0.04);
    overflow-y: auto;
}

.sidebar-brand { padding: 0 10px 36px; }
.brand-icon {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: var(--primary);
    color: white;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
}
.sidebar-brand strong { font-size: 16px; letter-spacing: -0.025em; }
.sidebar-brand span, .sidebar-user-info small { color: #a8b5ca; }
.sidebar-nav { gap: 8px; }
.nav-item {
    position: relative;
    min-height: 48px;
    border-radius: 12px;
    color: #bac6da;
    font-weight: 500;
    transition: background 180ms ease, color 180ms ease, transform 180ms var(--ease-out);
}
.nav-item.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 5px 16px rgba(0, 0, 0, 0.12);
}
.nav-icon { display: inline-flex; align-items: center; justify-content: center; }
.nav-icon svg { width: 20px; height: 20px; }
.sidebar-footer { padding: 20px 10px 0; margin-top: auto; }
.sidebar-logout { min-height: 44px; color: #bac6da; }
.sidebar-logout:focus-visible, .nav-item:focus-visible { outline-color: #d4dcff; }

.page, .form-page { padding: 42px clamp(20px, 3.5vw, 54px); }
.page-header, .form-header { margin-bottom: 30px; }
h1 { font-size: clamp(26px, 2.6vw, 34px); font-weight: 750; line-height: 1.2; }
h2 { font-size: 18px; letter-spacing: -0.025em; line-height: 1.4; }
.subtitle { margin-top: 10px; }
.panel, .form-card, .kpi, .dashboard-kpi, .login-card {
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}
.panel, .form-card { padding: 26px; margin-bottom: 24px; }
.panel-header { margin-bottom: 22px; }
.kpi-grid, .dashboard-kpi-grid { gap: 18px; margin-bottom: 24px; }
.kpi, .dashboard-kpi {
    position: relative;
    overflow: hidden;
    padding: 24px;
    background: var(--surface);
    transition: box-shadow 220ms ease, border-color 220ms ease, transform 220ms var(--ease-out);
}
.kpi::before, .dashboard-kpi::before {
    content: '';
    position: absolute;
    left: 24px;
    top: 0;
    width: 34px;
    height: 3px;
    border-radius: 0 0 4px 4px;
    background: var(--primary);
}
.kpi strong, .dashboard-kpi strong {
    font-size: clamp(24px, 2.5vw, 30px);
    font-variant-numeric: tabular-nums;
    line-height: 1.25;
}
.dashboard-kpi small { font-size: 12px; }

input, select, textarea {
    min-height: 46px;
    border-color: #dce1eb;
    border-radius: 10px;
    background: #fcfdff;
    transition: border-color 180ms ease, background 180ms ease, box-shadow 180ms ease;
}
input::placeholder, textarea::placeholder { color: #78849a; }
input:hover, select:hover, textarea:hover { border-color: #b7c1d2; }
input:focus, select:focus, textarea:focus {
    background: white;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-soft);
}
.dashboard-period label { font-weight: 600; }
.form-actions, .filter-actions { flex-wrap: wrap; }
.button {
    min-height: 44px;
    gap: 8px;
    padding: 10px 17px;
    border-radius: 10px;
    border-color: #dce1eb;
    font-weight: 600;
    font-size: 13px;
    white-space: nowrap;
    transition: background 180ms ease, border-color 180ms ease, box-shadow 180ms ease, transform 180ms var(--ease-out);
}
.button.primary { box-shadow: 0 4px 10px color-mix(in srgb, var(--primary) 18%, transparent); }
.button.primary:hover { border-color: var(--primary-hover); }
.button:active { transform: translateY(1px); box-shadow: none; }
.button.small { min-height: 36px; border-radius: 8px; }

.table-container { border: 1px solid var(--border); border-radius: 12px; }
th { padding: 13px 16px; background: #f8f9fc; font-size: 11px; letter-spacing: 0.065em; white-space: nowrap; }
td { padding: 16px; font-size: 13px; }
tbody tr { transition: background 160ms ease; }
tbody tr:hover { background: var(--primary-soft); }
tbody tr:last-child td { border-bottom: 0; }
.amount, .money-input input { font-variant-numeric: tabular-nums; }
.category { background: var(--primary-soft); color: var(--primary-text); font-weight: 500; }
.category-summary { border-radius: 12px; padding: 18px; background: #fcfdff; }
.status, .transaction-type { padding: 5px 11px; gap: 6px; align-items: center; }
.status::before, .transaction-type::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.error, .success-message { padding: 14px 18px; border-radius: 12px; }
.empty { padding: 48px 20px; }
.back { padding: 4px 0; transition: color 180ms ease; }
.back:hover { color: var(--primary); }
.month-summary-grid, .budget-overview-grid { border-radius: 12px; }
.month-summary-grid > div, .budget-overview-grid > div { padding: 20px; }
.progress-bar { height: 8px; background: #edf0f6; }
.progress-fill { transform-origin: left center; animation: fill-in 800ms var(--ease-out) both; }
.admin-toggle:has(input:focus-visible) { outline: 3px solid var(--primary); outline-offset: 4px; }

.login-page {
    min-height: 100svh;
    background: radial-gradient(ellipse at 20% 15%, var(--primary-soft), transparent 55%),
        radial-gradient(ellipse at 90% 90%, #e7effa, transparent 50%), var(--background);
}
.login-card { max-width: 440px; padding: 40px; box-shadow: 0 20px 70px rgba(24, 39, 75, 0.09); }
.login-brand { margin-bottom: 32px; }
.login-brand .brand-icon { width: 50px; height: 50px; }
.login-form { gap: 22px; }
.login-button { min-height: 48px; }

/* Content stays visible without JavaScript. Animations run once, on entry. */
.page-header, .form-header, .panel, .form-card, .kpi, .dashboard-kpi, .login-card {
    animation: rise-in 500ms var(--ease-out) both;
}
.kpi:nth-child(2), .dashboard-kpi:nth-child(2) { animation-delay: 50ms; }
.kpi:nth-child(3), .dashboard-kpi:nth-child(3) { animation-delay: 100ms; }
.kpi:nth-child(4), .dashboard-kpi:nth-child(4) { animation-delay: 150ms; }
.success-message, .error { animation: rise-in 300ms var(--ease-out) both; }
@keyframes rise-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fill-in {
    from { transform: scaleX(0); }
    to { transform: scaleX(1); }
}
@keyframes overlay-in { from { opacity: 0; } to { opacity: 1; } }

@media (hover: hover) {
    .nav-item:hover { transform: translateX(3px); }
    .nav-item.active:hover { background: var(--primary-hover); }
    .button:hover { transform: translateY(-1px); }
    .button:active { transform: translateY(1px); }
    .kpi:hover, .dashboard-kpi:hover { border-color: var(--primary-border); box-shadow: 0 8px 28px rgba(24, 39, 75, 0.08); }
}

@media (min-width: 761px) and (max-width: 1100px) {
    .page-header { flex-wrap: wrap; }
    .filters, .category-create-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
    .page, .form-page { padding: 26px 16px; }
    .page-header, .form-header { flex-direction: column; align-items: stretch; gap: 18px; }
    .panel, .form-card { padding: 18px; border-radius: 14px; }
    .panel-header { flex-wrap: wrap; gap: 12px; }
    .kpi, .dashboard-kpi { padding: 20px; }
    .mobile-topbar { height: 64px; background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(12px); }
    .mobile-menu-button { min-width: 44px; min-height: 44px; color: var(--text); border-radius: 10px; }
    .mobile-menu-button svg { width: 22px; height: 22px; vertical-align: middle; }
    .app-sidebar { width: min(var(--sidebar-width), 85vw); height: 100dvh; transition: transform 300ms var(--ease-out); }
    .mobile-overlay { background: rgba(15, 23, 42, 0.45); backdrop-filter: blur(3px); }
    body.menu-open .mobile-overlay { animation: overlay-in 220ms ease both; }
    .dashboard-period > div { min-width: 0; }
    .login-card { padding: 28px 24px; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
.passkey-card { padding: 24px; margin-bottom: 24px; }
.passkey-card .login-form { max-width: 420px; }
.passkey-entry { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--border, #e5e7eb); }
.passkey-entry p, [data-passkey-status] { overflow-wrap: anywhere; }
#passkey-login { margin-top: 16px; width: 100%; }

/* Appearance preference applies to every page, including native form controls. */
:root { color-scheme: light; }
:root[data-theme="dark"] {
    color-scheme: dark;
    --background: #101827;
    --surface: #1b2638;
    --border: #344258;
    --text: #e7edf7;
    --muted: #a9b7cd;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.18);
    --success: #60dea0;
    --danger: #ff929d;
    --warning: #f5bd62;
    --success-bg: #16392e;
    --danger-bg: #422735;
    --primary-soft: color-mix(in srgb, var(--primary) 18%, var(--surface));
    --primary-border: color-mix(in srgb, var(--primary) 45%, var(--border));
    --primary-text: color-mix(in srgb, var(--primary) 30%, #e7edf7);
}

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea,
[data-theme="dark"] .button,
[data-theme="dark"] .category-summary {
    background: var(--surface);
    border-color: var(--border);
}
[data-theme="dark"] input:focus,
[data-theme="dark"] select:focus,
[data-theme="dark"] textarea:focus { background: var(--background); border-color: var(--primary); }
[data-theme="dark"] input::placeholder,
[data-theme="dark"] textarea::placeholder { color: var(--muted); }
[data-theme="dark"] .button:hover { background: var(--primary-soft); }
[data-theme="dark"] .button.primary { background: var(--primary); border-color: var(--primary); }
[data-theme="dark"] .button.primary:hover { background: var(--primary-hover); }
[data-theme="dark"] .button.danger { background: var(--danger); border-color: var(--danger); color: var(--background); }
[data-theme="dark"] th { background: var(--background); }
[data-theme="dark"] th,
[data-theme="dark"] td { border-color: var(--border); }
[data-theme="dark"] .progress-bar { background: var(--border); }
[data-theme="dark"] .status.inactive { background: var(--border); color: var(--text); }
[data-theme="dark"] .success-message,
[data-theme="dark"] .error { border-color: currentColor; }
[data-theme="dark"] .mobile-topbar { background: color-mix(in srgb, var(--surface) 94%, transparent); }
[data-theme="dark"] .login-page {
    background: radial-gradient(ellipse at 20% 15%, var(--primary-soft), transparent 55%), var(--background);
}
[data-theme="dark"] .dashboard-add-income { background: var(--success-bg); color: var(--success); border-color: var(--success); }
[data-theme="dark"] .dashboard-add-income:hover { background: var(--surface); }

.category-symbol { display: inline-block; min-width: 1.3em; margin-right: 0.25em; text-align: center; }
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    margin-bottom: 14px;
    padding: 8px 0;
    border: 0;
    background: transparent;
    color: #e7edf7;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}
.theme-toggle[hidden] { display: none; }
.theme-toggle-track { width: 34px; height: 20px; margin-left: auto; padding: 3px; border-radius: 12px; background: #647087; }
.theme-toggle-track::before { content: ''; display: block; width: 14px; height: 14px; border-radius: 50%; background: white; }
.theme-toggle[aria-pressed="true"] .theme-toggle-track { background: var(--primary); }
.theme-toggle[aria-pressed="true"] .theme-toggle-track::before { transform: translateX(14px); }
.chart-table { margin-top: 20px; }
.chart-table summary { cursor: pointer; color: var(--muted); padding: 8px 0; }
.chart-table .table-container { margin-top: 12px; }
