:root {
    --app-max-width: 600px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --nav-height: 64px;
    --nav-gap: 10px;
}

html, body {
    height: 100%;
    margin: 0;
    font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none;
}

body { font-variant-numeric: tabular-nums; }

.amount { font-variant-numeric: tabular-nums; }

.app-shell {
    max-width: var(--app-max-width);
    margin: 0 auto;
    min-height: 100vh;
    min-height: 100dvh;
    position: relative;
    background: var(--mud-palette-background);
}

.status-bar-fill {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--safe-top);
    background: var(--mud-palette-background);
    z-index: var(--mud-zindex-appbar);
}

.visually-hidden {
    position: absolute !important;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.app-content {
    padding: calc(var(--safe-top) + 16px) 16px calc(var(--nav-height) + var(--nav-gap) + var(--safe-bottom) + 32px);
}

/* Floating, rounded navigation bar (MudNavigationBar is already fixed to the bottom). */
.bottom-nav.mud-nav-bar {
    left: var(--nav-gap);
    right: var(--nav-gap);
    bottom: calc(var(--nav-gap) + var(--safe-bottom));
    margin: 0 auto;
    max-width: calc(var(--app-max-width) - 2 * var(--nav-gap));
    height: var(--nav-height);
    padding: 0;
    overflow: visible;
    border-radius: calc(var(--mud-default-borderradius) + 8px);
    border: 1px solid var(--mud-palette-lines-default);
    background: var(--mud-palette-surface);
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.06);
}

.bottom-nav .mud-nav-bar-item {
    min-height: 44px;
    color: var(--mud-palette-text-secondary);
    transition: color 150ms ease;
}

.bottom-nav .mud-nav-bar-item-content { max-width: 100%; }

.bottom-nav .mud-nav-bar-item .mud-typography {
    font-size: 0.66rem;
    font-weight: 500;
    letter-spacing: -0.01em;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bottom-nav .mud-nav-bar-item.nav-selected { color: var(--mud-palette-primary); }

.bottom-nav .mud-nav-bar-item.nav-selected .mud-typography { font-weight: 600; }

/* Large centre button lifted above the bar; the ring in the page colour makes it look notched. */
.bottom-nav .nav-add-item { flex: 0 0 72px; overflow: visible; }

.bottom-nav .nav-add.mud-fab {
    transform: translateY(-24px);
    box-shadow:
        0 0 0 6px var(--mud-palette-background),
        0 10px 20px color-mix(in srgb, var(--mud-palette-primary) 40%, transparent);
    transition: transform 150ms ease;
}

.bottom-nav .nav-add.mud-fab:active { transform: translateY(-24px) scale(0.94); }

/* Keep snackbars above the floating navigation */
.mud-snackbar-location-bottom-center { bottom: calc(var(--nav-height) + var(--nav-gap) + var(--safe-bottom) + 12px) !important; }

/* Full-screen add/edit dialog, limited to the app width on larger screens */
.transaction-dialog.mud-dialog-fullscreen {
    max-width: var(--app-max-width);
    margin: 0 auto;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
}

.page-title:focus { outline: none; }

/* Cards */
.card.mud-paper {
    padding: 16px;
    border-radius: var(--mud-default-borderradius);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 12px rgba(0, 0, 0, 0.04);
}

.card.card-list { padding: 8px 0; }

.card-list .card-header { padding: 0 8px 0 16px; }

.card-title.mud-typography { font-weight: 600; margin-bottom: 12px; }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header .card-title.mud-typography { margin-bottom: 0; }

.skeleton-card { border-radius: var(--mud-default-borderradius); }

/* Month switcher */
.month-switcher {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: -4px -8px 12px;
}

.month-switcher-label.mud-typography { font-weight: 600; }

.month-swipe-area { min-height: 50vh; touch-action: pan-y; }

/* Summary */
.summary-card.mud-paper {
    padding: 20px;
    border-radius: calc(var(--mud-default-borderradius) * 1.25);
    background: linear-gradient(135deg, var(--mud-palette-primary), var(--mud-palette-primary-darken));
    color: var(--mud-palette-primary-text);
}

.summary-caption.mud-typography { opacity: 0.85; display: block; }

.summary-total.mud-typography { font-weight: 700; display: block; margin: 2px 0 16px; letter-spacing: -0.02em; }

.summary-value.mud-typography { font-weight: 600; }

.summary-row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding-top: 12px;
    border-top: 1px solid color-mix(in srgb, var(--mud-palette-primary-text) 25%, transparent);
}

/* Budgets */
.budget-row { display: flex; gap: 12px; align-items: center; }

.budget-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }

.budget-line { display: flex; justify-content: space-between; gap: 8px; }

.budget-name.mud-typography { font-weight: 500; }

/* Donut + legend */
.donut-layout { display: flex; align-items: center; gap: 16px; }


.legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }

.legend li { display: flex; align-items: center; gap: 8px; font-size: 0.875rem; }

.legend-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--dot-color); flex: none; }

.legend-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.legend-value { color: var(--mud-palette-text-secondary); }

/* Category donut with centred total */
.category-donut { position: relative; flex: none; width: var(--donut-size); height: var(--donut-size); }

.category-donut-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.category-donut-label { font-size: 0.75rem; color: var(--mud-palette-text-secondary); }

.category-donut-value { font-size: 1.15rem; font-weight: 700; }

/* Stats */
.stats-donut { display: flex; justify-content: center; margin: 4px 0 12px; }

.stat-pair {
    display: flex;
    justify-content: space-between;
    padding-top: 12px;
    border-top: 1px solid var(--mud-palette-lines-default);
}

.stat-value.mud-typography { font-weight: 600; }

.period-toggle .mud-toggle-item { min-height: 32px; padding: 0 12px; }

.chart-legend { display: flex; gap: 16px; margin-top: 8px; font-size: 0.8rem; color: var(--mud-palette-text-secondary); }

.chart-legend > span { display: inline-flex; align-items: center; gap: 6px; }

.category-row { text-decoration: none; }

.category-row-line { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.share-bar {
    position: relative;
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--mud-palette-lines-default);
    overflow: hidden;
}

.share-bar::after {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--share);
    border-radius: inherit;
    background: var(--bar-color);
}

.share-text { min-width: 36px; text-align: end; }

/* 50/30/20 bars: actual share with a marker at the target */
.bucket-row { display: flex; flex-direction: column; gap: 4px; }

.bucket-name { display: inline-flex; align-items: center; gap: 8px; }

.target-bar {
    position: relative;
    height: 8px;
    border-radius: 4px;
    background: var(--mud-palette-lines-default);
}

.target-bar::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--share);
    border-radius: inherit;
    background: var(--bar-color);
}

.target-bar::after {
    content: "";
    position: absolute;
    top: -3px;
    bottom: -3px;
    left: var(--target);
    width: 2px;
    border-radius: 1px;
    background: var(--mud-palette-text-primary);
}

/* Weekday rose */
.rose-wrap { display: flex; justify-content: center; margin: 4px 0 8px; }

.rose-label { font-size: 12px; fill: var(--mud-palette-text-secondary); }

.rose-label.weekend { font-weight: 700; fill: var(--mud-palette-text-primary); }

.chart-legend.justify-center { justify-content: center; }

/* Income flow */
.sankey-wrap { margin: 0 -4px 8px; }

.sankey-wrap svg { display: block; width: 100%; height: auto; }

/* Node labels sit on dark translucent boxes in both themes */
.sankey-wrap .mud-chart text { fill: #fff; }

.flow-list { margin: 0 -16px; }

.flow-row {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 48px;
    padding: 4px 16px;
    border: 0;
    border-top: 1px solid var(--mud-palette-lines-default);
    background: none;
    color: var(--mud-palette-text-primary);
    font: inherit;
    cursor: pointer;
}

.flow-row:focus-visible { outline: 2px solid var(--mud-palette-primary); outline-offset: -2px; }

.flow-row-name { flex: 1; min-width: 0; text-align: start; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.flow-row-share { color: var(--mud-palette-text-secondary); font-size: 0.85rem; }

.flow-row-amount.mud-typography { font-weight: 600; white-space: nowrap; }

.flow-details { display: flex; flex-direction: column; gap: 6px; padding: 4px 16px 12px 36px; }

.flow-detail { display: flex; justify-content: space-between; gap: 12px; font-size: 0.875rem; }

/* MudBlazor charts: axis labels in the secondary text colour */
.mud-chart text { fill: var(--mud-palette-text-secondary); font-family: inherit; }

/* Category icon */
.category-icon {
    width: var(--category-size);
    height: var(--category-size);
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--category-color);
    background: color-mix(in srgb, var(--category-color) 16%, transparent);
}

/* Transaction row */
.tx-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 60px;
    padding: 8px 16px;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: start;
    cursor: pointer;
}

@media (hover: hover) {
    .tx-row:hover { background: var(--mud-palette-action-default-hover); }
}

.tx-row:focus-visible { outline: 2px solid var(--mud-palette-primary); outline-offset: -2px; }

.tx-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.tx-row-title, .tx-row-subtitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.tx-row-amount.mud-typography { font-weight: 600; white-space: nowrap; }

/* Transactions */
.tx-toolbar { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }

.tx-search { margin: 0 !important; }

.tx-search .mud-input-outlined { background: var(--mud-palette-surface); border-radius: var(--mud-default-borderradius); }

/* Horizontally scrolling filter chips, edge to edge */
.filter-chips { margin: 0 -16px; overflow-x: auto; scrollbar-width: none; }

.filter-chips::-webkit-scrollbar { display: none; }

.filter-chips .mud-chipset { display: flex; flex-wrap: nowrap; padding: 0 12px; }

.filter-chips .mud-chip { flex: none; min-height: 36px; }

.day-header {
    position: sticky;
    top: var(--safe-top);
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 0 -16px;
    padding: 12px 20px 6px;
    background: var(--mud-palette-background);
}

.day-label.mud-typography { font-weight: 600; color: var(--mud-palette-text-secondary); }

.day-totals { display: flex; gap: 10px; }

.day-card.mud-paper { padding: 0; overflow: hidden; }

/* Swipe-to-delete row */
.swipe-row { position: relative; overflow: hidden; }

.swipe-row + .swipe-row { border-top: 1px solid var(--mud-palette-lines-default); }

.swipe-row-action {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    padding-right: 20px;
    background: var(--mud-palette-error);
    color: var(--mud-palette-error-text);
    font-weight: 600;
}

.swipe-row-content {
    position: relative;
    background: var(--mud-palette-surface);
    touch-action: pan-y;
    transition: transform 200ms ease;
}

.swipe-row.dragging .swipe-row-content { transition: none; }

/* Settings */
.section-label.mud-typography {
    display: block;
    margin: 0 4px 8px;
    color: var(--mud-palette-text-secondary);
    font-weight: 600;
}

.settings-list.mud-paper { padding: 4px 0; }

.settings-upload { display: block; width: 100%; margin: 0 !important; }

.settings-row {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    min-height: 56px;
    padding: 8px 16px;
    border: 0;
    background: none;
    color: var(--mud-palette-text-primary);
    font: inherit;
    text-align: start;
    text-decoration: none;
    cursor: pointer;
}

@media (hover: hover) {
    .settings-row:hover { background: var(--mud-palette-action-default-hover); }
}

.settings-row:focus-visible { outline: 2px solid var(--mud-palette-primary); outline-offset: -2px; }

.settings-row + .settings-row,
.settings-upload + .settings-row,
.settings-row + .settings-upload { border-top: 1px solid var(--mud-palette-lines-default); }

.settings-row-icon {
    display: inline-flex;
    padding: 8px;
    border-radius: 12px;
    color: var(--mud-palette-primary);
    background: var(--mud-palette-primary-hover);
}

.settings-row.danger, .settings-row.danger .settings-row-icon { color: var(--mud-palette-error); }

.settings-row.danger .settings-row-icon { background: color-mix(in srgb, var(--mud-palette-error) 12%, transparent); }

.settings-row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.settings-row-label { font-weight: 500; }

.settings-row-secondary { font-size: 0.8rem; color: var(--mud-palette-text-secondary); }

.settings-row-chevron { color: var(--mud-palette-text-secondary); }

.settings-row-value { color: var(--mud-palette-text-secondary); }

.theme-toggle { width: 100%; }

.theme-toggle .mud-toggle-item { flex: 1; min-height: 44px; }

.theme-option { display: inline-flex; align-items: center; gap: 6px; }

/* Sub-page header */
.page-header { display: flex; align-items: center; gap: 4px; margin: -8px -8px 12px; }

.page-header-title.mud-typography { flex: 1; font-weight: 700; }

/* Categories */
.tx-row.archived { opacity: 0.6; }

.category-preview { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 4px 0; }

.category-preview-name.mud-typography { font-weight: 600; }

.icon-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; }

.icon-option {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border: 0;
    border-radius: 50%;
    background: var(--mud-palette-action-default-hover);
    color: var(--mud-palette-text-secondary);
    cursor: pointer;
}

.icon-option.selected {
    color: var(--category-color);
    background: color-mix(in srgb, var(--category-color) 18%, transparent);
    box-shadow: inset 0 0 0 2px var(--category-color);
}

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

.color-option {
    aspect-ratio: 1;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    background: var(--swatch);
    color: #fff;
    cursor: pointer;
}

.color-option.selected { box-shadow: 0 0 0 3px var(--mud-palette-surface), 0 0 0 5px var(--swatch); }

.icon-option:focus-visible, .color-option:focus-visible { outline: 2px solid var(--mud-palette-primary); outline-offset: 2px; }

.archive-row { display: flex; flex-direction: column; gap: 2px; }

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 4px;
    padding: 32px 16px;
}

.empty-state-icon {
    display: inline-flex;
    padding: 16px;
    margin-bottom: 8px;
    border-radius: 50%;
    color: var(--mud-palette-primary);
    background: var(--mud-palette-primary-hover);
}

.empty-state-title.mud-typography { font-weight: 600; }

/* Add / edit dialog */
.dialog-header { display: flex; align-items: center; gap: 4px; }

.transaction-dialog .mud-dialog-title { padding: 8px 16px; }

.transaction-dialog-content.mud-dialog-content { padding: 0 16px 16px; }

.transaction-dialog-actions.mud-dialog-actions {
    padding: 12px 16px calc(12px + var(--safe-bottom));
    border-top: 1px solid var(--mud-palette-lines-default);
}

.transaction-form { display: flex; flex-direction: column; gap: 20px; }

.type-toggle { width: 100%; }

.type-toggle .mud-toggle-item { flex: 1; min-height: 44px; }

.amount-input input {
    font-size: 2.5rem !important;
    font-weight: 700;
    text-align: center;
    font-variant-numeric: tabular-nums;
    height: auto !important;
    padding: 8px 0 !important;
}

.amount-input .mud-input-adornment-text { font-size: 1.5rem; color: var(--mud-palette-text-secondary); }

.field-label.mud-typography { margin-bottom: 8px; color: var(--mud-palette-text-secondary); }

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

.category-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    padding: 8px 0;
    border: 0;
    border-radius: 14px;
    background: none;
    color: var(--mud-palette-text-primary);
    font: inherit;
    cursor: pointer;
}

.category-tile span {
    max-width: 100%;
    font-size: 0.7rem;
    line-height: 1.2;
    text-align: center;
    overflow-wrap: break-word;
}

.category-tile.selected { box-shadow: inset 0 0 0 2px var(--mud-palette-primary); background: var(--mud-palette-primary-hover); }

.category-tile:focus-visible { outline: 2px solid var(--mud-palette-primary); outline-offset: 1px; }

.date-row { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }

.date-row .mud-chip { min-height: 36px; margin: 0; }

.date-picker { flex: 1 1 140px; margin-top: 0 !important; }

.save-button { min-height: 52px; }

/* Splash shown until Blazor renders. MudBlazor variables do not exist yet, so it uses the
   palette values directly; data-theme is set by the inline script in index.html. */
.splash {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 24px;
    background: #F7F8FA;
}

.splash-logo {
    width: 72px;
    height: 72px;
    border-radius: 20px;
    background: #047857 url("../icon-192.png") center / cover;
}

.splash-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid rgba(4, 120, 87, 0.25);
    border-top-color: #047857;
    border-radius: 50%;
    animation: splash-spin 0.9s linear infinite;
}

@keyframes splash-spin { to { transform: rotate(360deg); } }

[data-theme="dark"] .splash { background: #0F1419; }

[data-theme="dark"] .splash-spinner { border-color: rgba(52, 211, 153, 0.2); border-top-color: #34D399; }

#blazor-error-ui {
    background: var(--mud-palette-error, #b32121);
    color: #fff;
    bottom: 0;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem calc(0.7rem + env(safe-area-inset-bottom, 0px));
    position: fixed;
    width: 100%;
    z-index: 2000;
    box-sizing: border-box;
}

#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }
#blazor-error-ui .reload { color: #fff; margin-left: 0.5rem; }

.page-enter { animation: page-in 180ms ease-out; }

@keyframes page-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
