:root,
:root[data-theme="light"] {
    color-scheme: light;
    --lh-primary: #2457d6;
    --lh-primary-hover: #1946b8;
    --lh-primary-soft: #eaf0ff;
    --lh-page: #f5f7fb;
    --lh-surface: #ffffff;
    --lh-surface-muted: #f0f3f8;
    --lh-text: #172033;
    --lh-text-muted: #657087;
    --lh-border: #dce2ec;
    --lh-focus: #4275f5;
    --lh-success: #16794b;
    --lh-success-surface: #e8f6ef;
    --lh-danger: #b42332;
    --lh-danger-surface: #fff0f1;
    --lh-shadow: 0 12px 32px rgb(21 39 78 / 8%);
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --lh-primary: #8caaff;
    --lh-primary-hover: #aac0ff;
    --lh-primary-soft: #26385f;
    --lh-page: #0c2027;
    --lh-surface: #16323b;
    --lh-surface-muted: #214550;
    --lh-text: #edf2fb;
    --lh-text-muted: #a9b5c8;
    --lh-border: #3d626d;
    --lh-focus: #7dd3fc;
    --lh-success: #8be0b5;
    --lh-success-surface: #19392d;
    --lh-danger: #ff9ba5;
    --lh-danger-surface: #48282f;
    --lh-shadow: 0 12px 32px rgb(0 0 0 / 24%);
}

:root {
    --lh-space-1: 0.25rem;
    --lh-space-2: 0.5rem;
    --lh-space-3: 0.75rem;
    --lh-space-4: 1rem;
    --lh-space-5: 1.5rem;
    --lh-space-6: 2rem;
    --lh-space-7: 3rem;
    --lh-radius-sm: 0.5rem;
    --lh-radius-md: 0.875rem;
    --lh-radius-lg: 1.25rem;
    --lh-content-width: 76rem;
    --lh-section-gap: clamp(1.25rem, 3vw, 2rem);
    --lh-control-height: 2.75rem;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--lh-page);
    color: var(--lh-text);
    font-synthesis: none;
    text-rendering: optimizeLegibility;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: var(--lh-space-6) var(--lh-space-4);
    background: radial-gradient(circle at top, var(--lh-primary-soft), var(--lh-page) 48%);
}

.login-card {
    width: min(100%, 26rem);
    padding: clamp(1.5rem, 5vw, 2.5rem);
    background: var(--lh-surface);
    border: 1px solid var(--lh-border);
    border-radius: var(--lh-radius-lg);
    box-shadow: var(--lh-shadow);
}

.login-brand { color: var(--lh-primary); font-size: 1.5rem; font-weight: 800; letter-spacing: -0.03em; }
.login-eyebrow { margin: var(--lh-space-5) 0 var(--lh-space-2); color: var(--lh-primary); font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; }
.login-card h1 { margin: 0; font-size: clamp(1.6rem, 5vw, 2rem); }
.login-subtitle { margin: var(--lh-space-2) 0 var(--lh-space-5); color: var(--lh-text-muted); }
.login-form { display: grid; gap: var(--lh-space-3); }
.login-form label { display: grid; gap: var(--lh-space-2); font-weight: 600; }
.login-form input { width: 100%; min-height: var(--lh-control-height); box-sizing: border-box; padding: 0 var(--lh-space-3); color: var(--lh-text); background: var(--lh-surface-muted); border: 1px solid var(--lh-border); border-radius: var(--lh-radius-sm); }
.login-form input:focus { outline: 3px solid color-mix(in srgb, var(--lh-focus) 35%, transparent); border-color: var(--lh-focus); }
.login-submit { width: 100%; margin-top: var(--lh-space-2); }
.login-version { margin-top: var(--lh-space-4); color: var(--lh-text-muted); font-size: 0.68rem; text-align: center; }

.form-card {
    display: grid;
    gap: var(--lh-space-3);
    width: min(100%, 42rem);
    box-sizing: border-box;
    padding: var(--lh-space-5);
    border: 1px solid var(--lh-border);
    border-radius: var(--lh-radius-md);
    background: var(--lh-surface);
    box-shadow: var(--lh-shadow);
}

.form-card h2 { margin: 0 0 var(--lh-space-2); }
.form-card label { display: grid; gap: var(--lh-space-2); font-weight: 600; }
.form-card input { min-height: var(--lh-control-height); box-sizing: border-box; padding: 0 var(--lh-space-3); color: var(--lh-text); background: var(--lh-surface-muted); border: 1px solid var(--lh-border); border-radius: var(--lh-radius-sm); }
.admin-users-table { width: 100%; overflow-x: auto; }
.admin-users-table table { min-width: 42rem; }

@media (max-width: 42rem) {
    .form-card { padding: var(--lh-space-4); }
    .admin-users-table { margin-inline: 0; }
}

.user-greeting {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    min-width: 0;
    color: var(--lh-text);
    font-size: 0.9rem;
    font-weight: 700;
}

.user-greeting small {
    color: var(--lh-text-muted);
    font-size: 0.75rem;
    font-weight: 600;
}

.sidebar-footer .user-greeting { margin-bottom: var(--lh-space-3); }
.mobile-header .user-greeting { flex: 1; margin: 0 var(--lh-space-3); }

@media (max-width: 42rem) {
    .mobile-header .user-greeting { font-size: 0.8rem; }
    .mobile-header .user-greeting small { font-size: 0.68rem; }
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    min-height: 100%;
    background: var(--lh-page);
    scroll-behavior: smooth;
}

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    background: var(--lh-page);
    color: var(--lh-text);
    font-size: 1rem;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

body,
button,
input,
select,
textarea {
    font-family: inherit;
}

a {
    color: var(--lh-primary);
}

button,
.btn,
input,
select,
textarea {
    min-height: var(--lh-control-height);
}

button,
.btn {
    touch-action: manipulation;
}

:focus-visible {
    outline: 3px solid var(--lh-focus);
    outline-offset: 3px;
}

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

.btn-primary {
    --bs-btn-color: #ffffff;
    --bs-btn-bg: var(--lh-primary);
    --bs-btn-border-color: var(--lh-primary);
    --bs-btn-hover-bg: var(--lh-primary-hover);
    --bs-btn-hover-border-color: var(--lh-primary-hover);
}

:root[data-theme="dark"] .btn-primary {
    --bs-btn-bg: #2457d6;
    --bs-btn-border-color: #2457d6;
    --bs-btn-hover-bg: #1946b8;
    --bs-btn-hover-border-color: #1946b8;
}

:root[data-theme="dark"] .btn-outline-primary {
    --bs-btn-color: #a9c1ff;
    --bs-btn-border-color: #a9c1ff;
    --bs-btn-hover-color: #ffffff;
    --bs-btn-hover-bg: #1946b8;
    --bs-btn-hover-border-color: #1946b8;
    --bs-btn-active-color: #ffffff;
    --bs-btn-active-bg: #1946b8;
    --bs-btn-active-border-color: #1946b8;
    --bs-btn-disabled-color: #a9c1ff;
    --bs-btn-disabled-border-color: #a9c1ff;
}

:root[data-theme="dark"] .btn-outline-danger {
    --bs-btn-color: #ff9ba5;
    --bs-btn-border-color: #ff9ba5;
    --bs-btn-hover-color: #ffffff;
    --bs-btn-hover-bg: #b42332;
    --bs-btn-hover-border-color: #b42332;
    --bs-btn-active-color: #ffffff;
    --bs-btn-active-bg: #b42332;
    --bs-btn-active-border-color: #b42332;
    --bs-btn-disabled-color: #ff9ba5;
    --bs-btn-disabled-border-color: #ff9ba5;
}

:root[data-theme="dark"] .btn-outline-secondary {
    --bs-btn-color: #d3deef;
    --bs-btn-border-color: #a9b5c8;
    --bs-btn-hover-color: #111722;
    --bs-btn-hover-bg: #d3deef;
    --bs-btn-hover-border-color: #d3deef;
    --bs-btn-disabled-color: #d3deef;
    --bs-btn-disabled-border-color: #a9b5c8;
}

:root[data-theme="dark"] .form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23d3deef' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

.form-control,
.form-select {
    border-color: var(--lh-border);
    background-color: var(--lh-surface);
    color: var(--lh-text);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--lh-focus);
    box-shadow: 0 0 0 0.2rem color-mix(in srgb, var(--lh-focus) 24%, transparent);
}

.validation-message {
    color: var(--lh-danger);
}

.theme-toggle {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    gap: 0.55rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--lh-border);
    border-radius: 0.7rem;
    background: var(--lh-surface);
    color: var(--lh-text);
    font-size: 0.85rem;
    font-weight: 600;
}

.theme-toggle:hover {
    border-color: var(--lh-primary);
    color: var(--lh-primary);
}

.page-content {
    width: min(100%, var(--lh-content-width));
    margin-inline: auto;
}

.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1.5rem;
    margin-bottom: 1.75rem;
}

.page-header h1 {
    margin: 0;
    color: var(--lh-text);
    font-size: clamp(1.75rem, 4vw, 2.35rem);
    font-weight: 750;
    letter-spacing: -0.045em;
}

.page-header .page-eyebrow {
    margin-bottom: 0.4rem;
}

.page-header-description {
    max-width: 46rem;
    margin: 0.45rem 0 0;
    color: var(--lh-text-muted);
}

.page-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.shared-state,
.shared-message {
    padding: 1.1rem 1.25rem;
    border: 1px solid var(--lh-border);
    border-radius: var(--lh-radius-md);
    background: var(--lh-surface);
    color: var(--lh-text);
}

.shared-message {
    position: fixed;
    z-index: 1000;
    top: max(1rem, env(safe-area-inset-top));
    right: max(1rem, env(safe-area-inset-right));
    width: min(28rem, calc(100vw - 2rem));
    margin: 0;
    box-shadow: var(--lh-shadow);
    animation: lifehub-notification-in 180ms ease-out, lifehub-notification-out 500ms ease-in 9.5s forwards;
    touch-action: pan-y;
    cursor: grab;
}

@keyframes lifehub-notification-in { from { opacity: 0; transform: translateY(-.75rem); } to { opacity: 1; transform: translateY(0); } }
@keyframes lifehub-notification-out { to { opacity: 0; transform: translateY(-.75rem); pointer-events: none; } }
.shared-message.notification-dismissed { opacity: 0; transform: translateY(-1rem); pointer-events: none; transition: opacity 180ms ease, transform 180ms ease; }

.card-item, .transaction-card, .invoice-item, .direct-transaction-form {
    background: var(--lh-surface);
    box-shadow: var(--lh-shadow);
}

.amount-income { color: var(--lh-success); }
.amount-expense { color: var(--lh-danger); }
.amount-transfer { color: var(--lh-primary); }

.btn + .btn { margin-left: 0; }
.page-content > section, .page-content > details, .page-content > .card-item, .page-content > .transaction-card, .page-content > .invoice-item { margin-block: var(--lh-section-gap); }
.card-actions, .transaction-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: 1rem; }
.card-actions .btn, .transaction-actions .btn { min-width: 7.5rem; margin: 0; }
.icon-action { display: inline-grid; width: 2.5rem; height: 2.5rem; min-height: 2.5rem; place-items: center; padding: .45rem; border: 1px solid currentColor; border-radius: .65rem; background: transparent; color: var(--lh-primary); }
.icon-action .nav-icon { width: 1.25rem; height: 1.25rem; }
.icon-action-edit { color: var(--lh-primary); }
.icon-action-primary { color: var(--lh-primary); }
.icon-action-danger { color: var(--lh-danger); }
.icon-action-secondary { color: var(--lh-text-muted); }
.icon-action:hover:not(:disabled) { background: var(--lh-primary-soft); }
.icon-action:disabled { cursor: not-allowed; opacity: .45; }
.section-subtitle { margin: -.25rem 0 .75rem; color: var(--lh-text-muted); }
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); gap: 1rem; margin-top: 2rem; }
.module-card { display: grid; min-height: 12rem; place-items: center; align-content: center; gap: .6rem; padding: 1.5rem; border: 1px solid var(--lh-border); border-radius: var(--lh-radius-lg); background: var(--lh-surface); color: var(--lh-text); text-align: center; text-decoration: none; box-shadow: var(--lh-shadow); }
.module-card .nav-icon { width: 2.75rem; height: 2.75rem; color: var(--lh-text-muted); }
.module-card h2, .module-card p { margin: 0; }
.module-card p, .module-card span { color: var(--lh-text-muted); }
.module-card-enabled { border-color: var(--lh-primary); }
.module-card-enabled .nav-icon { color: var(--lh-primary); }
.module-card-enabled:hover { background: var(--lh-primary-soft); color: var(--lh-primary); }
.module-card-disabled { opacity: .52; cursor: not-allowed; filter: grayscale(.35); box-shadow: none; }
.finance-entry-card { display: grid; justify-items: start; gap: .75rem; padding: 2rem; border: 1px solid var(--lh-border); border-radius: var(--lh-radius-lg); background: var(--lh-surface); box-shadow: var(--lh-shadow); }
.finance-entry-card .nav-icon { width: 2.5rem; height: 2.5rem; color: var(--lh-primary); }
.dashboard-filters{display:flex;flex-wrap:wrap;align-items:end;gap:1rem;margin:1.5rem 0}.dashboard-filters label{display:grid;gap:.35rem;color:var(--lh-text-muted);font-size:.9rem}.dashboard-filters select{min-height:2.5rem;padding:.5rem .75rem;border:1px solid var(--lh-border);border-radius:var(--lh-radius-sm);background:var(--lh-surface);color:var(--lh-text)}.dashboard-check{display:flex!important;align-items:center;min-height:2.5rem}.dashboard-kpis{display:grid;grid-template-columns:repeat(4,1fr);gap:1rem;margin:1.5rem 0}.dashboard-kpi,.dashboard-panel{padding:1.25rem;border:1px solid var(--lh-border);border-radius:var(--lh-radius-lg);background:var(--lh-surface);box-shadow:var(--lh-shadow)}.dashboard-kpi{display:grid;gap:.4rem}.dashboard-kpi span,.dashboard-kpi small,.dashboard-panel p{color:var(--lh-text-muted)}.dashboard-kpi strong{font-size:1.45rem}.dashboard-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:1rem;margin:1rem 0}.dashboard-panel h2{margin-top:0}.dashboard-bar-row{display:grid;grid-template-columns:8rem 1fr auto;align-items:center;gap:.6rem;margin:.7rem 0}.dashboard-bar-row>div{height:.7rem;background:var(--lh-surface-muted);border-radius:1rem;overflow:hidden}.dashboard-bar-row i{display:block;height:100%;background:var(--lh-danger);border-radius:inherit}.dual-bars{display:flex!important;align-items:end;gap:2px;height:2rem!important;background:none!important}.dual-bars i{width:50%;height:0;border-radius:2px 2px 0 0}.income-bar{background:var(--lh-success)!important}.expense-bar{background:var(--lh-danger)!important}.dashboard-line{height:9rem;display:flex;align-items:end;gap:.75rem;border-bottom:1px solid var(--lh-border)}.dashboard-line span{height:100%;flex:1;display:flex;flex-direction:column;justify-content:end;align-items:center;gap:.3rem}.dashboard-line b{display:block;width:1.1rem;min-height:2px;background:var(--lh-primary);border-radius:.25rem .25rem 0 0}.dashboard-line small{color:var(--lh-text-muted)}.dashboard-invoice,.dashboard-recent{display:flex;justify-content:space-between;align-items:center;gap:1rem;padding:.7rem 0;border-bottom:1px solid var(--lh-border);color:var(--lh-text);text-decoration:none}.dashboard-invoice span{display:grid;gap:.2rem}.dashboard-invoice small,.dashboard-recent small{color:var(--lh-text-muted)}
.dashboard-refresh{width:auto!important;min-width:8rem;display:inline-flex;align-items:center;justify-content:center;gap:.4rem}
.dashboard-donut{width:min(13rem,70vw);aspect-ratio:1;border-radius:50%;margin:1rem auto;display:grid;place-items:center;position:relative}.dashboard-donut::after{content:"";position:absolute;inset:24%;border-radius:50%;background:var(--lh-surface)}.dashboard-donut span{position:relative;z-index:1;font-weight:700}.dashboard-legend{display:grid;gap:.45rem}.dashboard-legend>div{display:grid;grid-template-columns:auto 1fr auto;gap:.5rem;align-items:center;font-size:.9rem}.legend-dot{width:.7rem;height:.7rem;border-radius:50%;background:#4f8cff}.legend-0{background:#4f8cff}.legend-1{background:#ef6a6a}.legend-2{background:#55c98a}.legend-3{background:#e1b65c}.legend-4{background:#9b7bea}
@media (max-width:48rem){.dashboard-kpis,.dashboard-grid{grid-template-columns:1fr}.dashboard-filters{align-items:stretch}.dashboard-filters>*{width:100%}.dashboard-bar-row{grid-template-columns:7rem 1fr auto;font-size:.9rem}}

table { width: 100%; border-collapse: separate; border-spacing: 0; }
th, td { padding: .75rem .9rem; border-bottom: 1px solid var(--lh-border); vertical-align: middle; }
th { color: var(--lh-text-muted); font-size: .78rem; letter-spacing: .04em; text-transform: uppercase; }
tbody tr:hover { background: var(--lh-surface-muted); }

.loading-state {
    display: flex;
    min-height: 4.25rem;
    align-items: center;
    gap: 0.8rem;
    color: var(--lh-text-muted);
}

.loading-indicator {
    width: 1.15rem;
    height: 1.15rem;
    flex: 0 0 auto;
    border: 2px solid var(--lh-border);
    border-top-color: var(--lh-primary);
    border-radius: 50%;
    animation: lifehub-spin 750ms linear infinite;
}

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

.empty-state {
    text-align: center;
}

.empty-state h2 {
    margin: 0 0 0.45rem;
    font-size: 1.2rem;
    font-weight: 700;
}

.empty-state p {
    margin: 0;
    color: var(--lh-text-muted);
}

.empty-state-actions {
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    margin-top: 1rem;
}

.shared-message strong {
    display: block;
    margin-bottom: 0.2rem;
}

.shared-message p {
    margin: 0;
}

.error-message {
    border-color: color-mix(in srgb, var(--lh-danger) 35%, var(--lh-border));
    background: var(--lh-danger-surface);
    color: var(--lh-danger);
}

.success-message {
    border-color: color-mix(in srgb, var(--lh-success) 35%, var(--lh-border));
    background: var(--lh-success-surface);
    color: var(--lh-success);
}

.page-eyebrow {
    margin: 0 0 0.65rem;
    color: var(--lh-primary);
    font-size: 0.78rem;
    font-weight: 750;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

@media (max-width: 40rem) {
    .page-header {
        align-items: stretch;
        flex-direction: column;
        gap: 1rem;
    }

    .page-header-actions {
        width: 100%;
    }

    .btn + .btn { margin-top: .4rem; margin-left: 0; }
    table { display: block; overflow-x: auto; white-space: nowrap; }
}

#blazor-error-ui {
    display: none;
    position: fixed;
    z-index: 1000;
    right: 0;
    bottom: 0;
    left: 0;
    padding: var(--lh-space-4) var(--lh-space-5);
    background: var(--lh-danger-surface);
    color: var(--lh-text);
    box-shadow: 0 -2px 12px rgb(0 0 0 / 12%);
}

#blazor-error-ui .dismiss {
    position: absolute;
    top: var(--lh-space-2);
    right: var(--lh-space-3);
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    border: 0;
    background: transparent;
    color: var(--lh-text);
    font-size: 1.5rem;
}

.blazor-error-boundary {
    padding: var(--lh-space-4) var(--lh-space-5);
    border-radius: var(--lh-radius-sm);
    background: var(--lh-danger-surface);
    color: var(--lh-danger);
}

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