:root {
    color-scheme: dark;
    --background: #02091f;
    --background-mid: #061b55;
    --panel: rgba(255, 255, 255, 0.075);
    --panel-strong: rgba(255, 255, 255, 0.11);
    --border: rgba(255, 255, 255, 0.14);
    --text: #f7f9ff;
    --muted: rgba(247, 249, 255, 0.68);
    --faint: rgba(247, 249, 255, 0.48);
    --accent: #5c94f7;
    --accent-strong: #72a4ff;
    --expense: #ff434a;
    --warning: #ffad29;
    --success: #7ed35d;
    --danger: #ff7175;
    --shadow: 0 18px 50px rgba(0, 4, 18, 0.24);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
}

* { 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 82% 8%, rgba(30, 76, 176, 0.36), transparent 34rem),
        linear-gradient(135deg, #020719 0%, var(--background-mid) 48%, #03102d 100%);
    background-attachment: fixed;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, select, input[type="radio"], input[type="checkbox"] { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.9rem, 4vw, 2.35rem); margin-bottom: 4px; }
h2 { font-size: 1.08rem; margin-bottom: 14px; }
p { line-height: 1.55; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(2, 9, 31, 0.86);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px) saturate(1.3);
}
.header-inner {
    max-width: 1480px;
    min-height: 72px;
    margin: 0 auto;
    padding: 10px 24px;
    display: flex;
    align-items: center;
    gap: 18px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; flex: 0 0 auto; }
.brand > span:last-child { display: grid; }
.brand strong { font-size: 1.05rem; }
.brand small { color: var(--faint); font-size: 0.7rem; }
.brand-icon, .heading-icon {
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    color: white;
    background: linear-gradient(145deg, #7ab2ff, #3a72dc);
    border-radius: 50%;
    box-shadow: 0 8px 24px rgba(55, 111, 224, 0.36);
    font-weight: 750;
}
.brand-icon { width: 42px; height: 42px; font-size: 1.45rem; }
.heading-icon { width: 56px; height: 56px; font-size: 2rem; }
.main-navigation { display: flex; align-items: center; gap: 4px; flex: 1 1 auto; }
.nav-link { color: var(--muted); padding: 9px 11px; border-radius: 10px; text-decoration: none; white-space: nowrap; }
.nav-link:hover, .nav-link:focus-visible { color: var(--text); background: rgba(255, 255, 255, 0.07); }
.nav-link.active { color: white; background: rgba(92, 148, 247, 0.22); }
.account-menu { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 0.87rem; }
.account-menu a { text-decoration: none; }
.account-menu form { margin: 0; }
.link-button { border: 0; padding: 0; color: var(--muted); background: transparent; }
.link-button:hover, .account-menu a:hover { color: white; }
.nav-toggle { display: none; }

.page-shell { width: min(1180px, calc(100% - 40px)); min-height: calc(100vh - 145px); margin: 0 auto; padding: 28px 0 48px; }
.site-footer { padding: 18px; text-align: center; color: var(--faint); font-size: 0.76rem; }
.page-heading { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; }
.page-heading p { margin: 0; color: var(--muted); }
.panel {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.105), rgba(255, 255, 255, 0.045));
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: var(--shadow);
    padding: 20px;
}
.notice { width: min(100%, 900px); margin: 0 auto 18px; padding: 13px 15px; border-radius: 13px; background: rgba(92, 148, 247, 0.15); border: 1px solid rgba(92, 148, 247, 0.25); }
.notice.error { color: #ffc6c8; background: rgba(255, 67, 74, 0.14); border-color: rgba(255, 67, 74, 0.28); }
.notice.success { color: #c9f4bb; background: rgba(126, 211, 93, 0.14); border-color: rgba(126, 211, 93, 0.28); }
.notice.warning { color: #ffe2aa; background: rgba(255, 173, 41, 0.14); border-color: rgba(255, 173, 41, 0.28); }

.primary-button, .secondary-button, .danger-button {
    min-height: 42px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 7px;
    padding: 10px 16px;
    border: 1px solid transparent;
    border-radius: 11px;
    font-weight: 650;
    text-decoration: none;
}
.primary-button { color: #fff; background: linear-gradient(145deg, #6da7ff, #487ddd); box-shadow: 0 8px 24px rgba(63, 119, 225, 0.24); }
.primary-button:hover { background: linear-gradient(145deg, #7bb0ff, #5388e7); }
.secondary-button { color: var(--text); background: rgba(255, 255, 255, 0.07); border-color: var(--border); }
.secondary-button:hover { background: rgba(255, 255, 255, 0.12); }
.danger-button { color: #ffd4d5; background: rgba(255, 67, 74, 0.1); border-color: rgba(255, 100, 106, 0.34); }
.danger-button:hover { background: rgba(255, 67, 74, 0.18); }
.compact { min-height: 32px; padding: 5px 9px; font-size: 0.78rem; }

label { display: grid; gap: 7px; color: var(--muted); font-size: 0.9rem; }
input, select, textarea {
    width: 100%;
    color: var(--text);
    background: rgba(0, 6, 26, 0.62);
    border: 1px solid var(--border);
    border-radius: 11px;
    padding: 11px 12px;
    outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent-strong); box-shadow: 0 0 0 3px rgba(92, 148, 247, 0.18); }
textarea { resize: vertical; }
.form-stack { display: grid; gap: 15px; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; }
.check-row { display: flex; align-items: center; gap: 9px; }
.check-row input { width: auto; }
.inline-form { display: flex; align-items: end; gap: 12px; }
.grow { flex: 1 1 auto; }

.auth-screen { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.auth-card { width: min(100%, 430px); padding: 30px; background: rgba(5, 18, 55, 0.88); border: 1px solid var(--border); border-radius: 24px; box-shadow: 0 30px 90px rgba(0, 4, 20, 0.48); backdrop-filter: blur(18px); }
.auth-card > p { color: var(--muted); }
.auth-brand { width: 64px; height: 64px; margin-bottom: 18px; font-size: 2.2rem; }
.narrow-panel { max-width: 620px; margin: 0 auto; }

.balance-card { min-height: 190px; display: grid; place-items: center; align-content: center; gap: 8px; text-align: center; border-radius: 24px; }
.balance-card > span { color: var(--muted); font-size: 1.35rem; font-weight: 600; }
.balance-card strong { color: var(--expense); font-size: clamp(2.8rem, 8vw, 4rem); line-height: 1; font-variant-numeric: tabular-nums; }
.balance-card small { color: var(--faint); }
.home-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; margin-top: 20px; }
.action-card { min-height: 174px; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; text-decoration: none; transition: transform 150ms ease, border-color 150ms ease; }
a.action-card:hover { transform: translateY(-2px); border-color: rgba(110, 169, 255, 0.46); }
.action-card strong { margin-top: auto; font-size: 1.18rem; }
.action-card small { color: var(--muted); }
.action-card.disabled { opacity: 0.5; }
.action-symbol { color: var(--accent); font-size: 2.2rem; line-height: 1; }
.action-symbol.plus { font-weight: 500; }
.empty-category-callout { margin-top: 20px; display: flex; justify-content: space-between; align-items: center; gap: 18px; }
.empty-category-callout p { margin: 5px 0 0; color: var(--muted); }

.entry-form { display: grid; gap: 18px; }
.amount-panel > label { color: var(--text); font-weight: 650; }
.amount-input { display: flex; align-items: baseline; gap: 10px; padding: 8px 16px; margin-top: 10px; background: rgba(0, 5, 24, 0.38); border-radius: 14px; }
.amount-input input { border: 0; padding: 0; background: transparent; box-shadow: none; font-size: clamp(2.6rem, 8vw, 3.5rem); font-weight: 750; }
.amount-input span { color: var(--muted); font-size: 2rem; font-weight: 650; }
.selection-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; }
.selection-option { position: relative; display: block; color: var(--text); }
.selection-option input { position: absolute; opacity: 0; pointer-events: none; }
.selection-option span { min-height: 42px; display: grid; place-items: center; padding: 9px; border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 10px; background: rgba(255, 255, 255, 0.07); text-align: center; font-size: 0.86rem; font-weight: 650; }
.selection-option input:checked + span { background: rgba(92, 148, 247, 0.72); border-color: rgba(255, 255, 255, 0.52); }
.selection-option input:focus-visible + span { outline: 3px solid rgba(92, 148, 247, 0.45); }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.settings-grid > .panel:last-child:nth-child(odd), .categories-layout > .panel:not(:first-child) { grid-column: 1 / -1; }
.category-list, .user-list { display: grid; gap: 10px; }
.category-row, .user-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 13px; background: rgba(255, 255, 255, 0.035); border: 1px solid rgba(255, 255, 255, 0.08); border-radius: 13px; }
.category-row > div:first-child, .user-row > div:first-child { display: grid; gap: 3px; }
.category-row span, .user-row span { color: var(--muted); font-size: 0.82rem; }
.category-actions, .user-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.category-actions form, .user-actions form { margin: 0; }
.reassign-form { display: flex; align-items: center; gap: 7px; }
.reassign-form select { min-width: 150px; }
.danger-zone { border-color: rgba(255, 67, 74, 0.28); }
.import-preview { max-width: 760px; margin: 20px auto 0; }

.entries-toolbar { display: flex; align-items: end; gap: 14px; margin-bottom: 18px; }
.entries-toolbar > label { flex: 0 0 auto; }
.entries-toolbar select { min-width: 120px; }
.segmented-control { margin: 0; padding: 0; border: 0; display: flex; }
.segmented-control legend { color: var(--muted); font-size: 0.9rem; margin-bottom: 7px; }
.segmented-control label { display: block; position: relative; }
.segmented-control input { position: absolute; opacity: 0; pointer-events: none; }
.segmented-control span { min-height: 42px; display: grid; place-items: center; padding: 8px 16px; background: rgba(255, 255, 255, 0.07); border: 1px solid var(--border); }
.segmented-control label:first-of-type span { border-radius: 10px 0 0 10px; }
.segmented-control label:last-of-type span { border-radius: 0 10px 10px 0; }
.segmented-control input:checked + span { background: var(--accent); color: white; }
.toolbar-total { display: grid; justify-items: end; margin-left: auto; white-space: nowrap; }
.toolbar-total span { color: var(--muted); font-size: 0.76rem; }
.toolbar-total strong { color: var(--expense); font-size: 1.25rem; font-variant-numeric: tabular-nums; }
.visualization-panel { min-height: 430px; }
.visualization-heading h2 { margin-bottom: 4px; font-size: 1.2rem; }
.visualization-heading p, .chart-caption { color: var(--muted); }
.monthly-chart { width: 100%; height: 320px; display: block; margin-top: 18px; }
.chart-caption { margin: 13px 0 0; font-size: 0.86rem; }
.treemap { position: relative; width: 100%; min-height: 390px; margin-top: 18px; isolation: isolate; }
.treemap-tile { position: absolute; display: flex; flex-direction: column; gap: 5px; padding: 12px; overflow: hidden; color: white; border-radius: 11px; text-decoration: none; transition: left 160ms ease, top 160ms ease, width 160ms ease, height 160ms ease, opacity 160ms ease, box-shadow 160ms ease; }
.treemap-tile strong { line-height: 1.15; overflow-wrap: anywhere; }
.treemap-tile span { margin-top: auto; font-variant-numeric: tabular-nums; font-weight: 650; }
.treemap-tile.color-0 { background: linear-gradient(145deg, #668de4, #3566bd); }
.treemap-tile.color-1 { background: linear-gradient(145deg, #987fe5, #684bb8); }
.treemap-tile.color-2 { background: linear-gradient(145deg, #55b7ca, #2d8296); }
.treemap-tile.color-3 { background: linear-gradient(145deg, #c2934b, #8d642b); }
.treemap-tile.color-4 { background: linear-gradient(145deg, #68a99a, #41786f); }
.treemap-tile.color-5 { background: linear-gradient(145deg, #7583aa, #4f5d83); }
.treemap.has-focus .treemap-tile:not(.focused) { opacity: 0.38; }
.treemap-tile.focused { z-index: 10; overflow: visible; box-shadow: 0 18px 45px rgba(0, 0, 0, 0.45); }
.treemap-back { position: absolute; z-index: 20; top: 8px; left: 8px; }
.matrix-scroll { overflow: auto; max-height: 560px; margin-top: 18px; }
.matrix-table { border-collapse: separate; border-spacing: 6px; min-width: 980px; width: 100%; }
.matrix-table th { color: var(--muted); font-size: 0.75rem; }
.matrix-table thead th { position: sticky; top: 0; z-index: 3; background: #07153d; }
.matrix-table th:first-child { position: sticky; left: 0; z-index: 4; min-width: 150px; text-align: left; background: #07153d; }
.matrix-cell { width: 62px; height: 36px; display: grid; place-items: center; color: var(--text); background: rgba(92, 148, 247, 0.05); border: 2px solid transparent; border-radius: 8px; text-decoration: none; font-size: 0.7rem; font-variant-numeric: tabular-nums; }
.matrix-cell.level-1 { background: rgba(92, 148, 247, 0.18); }.matrix-cell.level-2 { background: rgba(92, 148, 247, 0.26); }.matrix-cell.level-3 { background: rgba(92, 148, 247, 0.34); }.matrix-cell.level-4 { background: rgba(92, 148, 247, 0.42); }.matrix-cell.level-5 { background: rgba(92, 148, 247, 0.50); }.matrix-cell.level-6 { background: rgba(92, 148, 247, 0.58); }.matrix-cell.level-7 { background: rgba(92, 148, 247, 0.66); }.matrix-cell.level-8 { background: rgba(92, 148, 247, 0.74); }.matrix-cell.level-9 { background: rgba(92, 148, 247, 0.82); }.matrix-cell.level-10 { background: rgba(92, 148, 247, 0.92); }
.matrix-cell.selected { border-color: var(--expense); }
.category-summary { padding: 13px; }
.summary-row { display: grid; grid-template-columns: minmax(0, 1fr) 190px; gap: 16px; padding: 12px 9px; border-bottom: 1px solid rgba(255, 255, 255, 0.07); }
.summary-row > :last-child { text-align: right; font-variant-numeric: tabular-nums; }
.summary-head { color: var(--muted); }
.summary-total { border-bottom: 0; color: var(--expense); }
.list-filters { margin-bottom: 14px; }
.list-filters form { display: flex; align-items: end; gap: 12px; }
.list-filters label { flex: 1 1 180px; }
.entries-list { padding: 0; overflow: hidden; }
.entries-table-header, .entry-row { display: grid; grid-template-columns: 105px 150px minmax(180px, 1fr) 120px 145px 175px; gap: 12px; align-items: center; padding: 12px 14px; }
.entries-table-header { color: var(--muted); font-size: 0.78rem; font-weight: 650; border-bottom: 1px solid var(--border); }
.entry-row { border-bottom: 1px solid rgba(255, 255, 255, 0.065); }
.entry-row > strong { text-align: right; font-variant-numeric: tabular-nums; }
.entry-note { color: var(--muted); overflow-wrap: anywhere; }
.entry-actions { display: flex; justify-content: flex-end; gap: 6px; }
.entry-actions form { margin: 0; }
.entries-list footer { padding: 12px 14px; color: var(--muted); font-size: 0.82rem; }
.empty-state { min-height: 280px; display: grid; place-items: center; align-content: center; text-align: center; }
.empty-state p { color: var(--muted); }

@media (max-width: 1120px) {
    .header-inner { flex-wrap: wrap; }
    .main-navigation { order: 3; width: 100%; overflow-x: auto; padding-bottom: 2px; }
    .account-menu { margin-left: auto; }
    .entries-toolbar { flex-wrap: wrap; }
    .toolbar-total { margin-left: 0; min-width: 170px; align-self: end; }
    .entries-table-header { display: none; }
    .entry-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .entry-row > *::before { content: attr(data-label); display: block; margin-bottom: 3px; color: var(--faint); font-size: 0.68rem; font-weight: 500; }
    .entry-row > strong { text-align: left; }
    .entry-actions { justify-content: flex-start; align-self: end; }
}

@media (max-width: 760px) {
    .page-shell { width: min(100% - 24px, 1180px); padding-top: 20px; }
    .header-inner { padding: 9px 12px; }
    .nav-toggle { display: inline-flex; margin-left: auto; color: var(--text); background: rgba(255, 255, 255, 0.07); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; }
    .main-navigation { display: none; order: 4; flex-direction: column; align-items: stretch; width: 100%; }
    .main-navigation.open { display: flex; }
    .nav-link { width: 100%; }
    .account-menu { order: 3; width: 100%; justify-content: flex-end; }
    .page-heading { gap: 12px; }
    .heading-icon { width: 48px; height: 48px; font-size: 1.7rem; }
    .home-actions, .settings-grid { grid-template-columns: 1fr; }
    .settings-grid > .panel, .categories-layout > .panel { grid-column: auto !important; }
    .selection-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .inline-form, .list-filters form { align-items: stretch; flex-direction: column; }
    .entries-toolbar { align-items: stretch; }
    .entries-toolbar > label, .entries-toolbar > fieldset { flex: 1 1 calc(50% - 8px); }
    .entries-toolbar select { width: 100%; }
    .toolbar-total { justify-items: start; min-width: 100%; }
    .monthly-chart { height: 260px; }
    .treemap { min-height: 450px; }
    .summary-row { grid-template-columns: minmax(0, 1fr) 140px; }
    .entry-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .entry-actions { grid-column: 1 / -1; }
    .category-row, .user-row { align-items: flex-start; flex-direction: column; }
    .category-actions, .user-actions { justify-content: flex-start; width: 100%; }
    .reassign-form { width: 100%; flex-wrap: wrap; }
    .reassign-form select { flex: 1 1 160px; }
    .empty-category-callout { align-items: stretch; flex-direction: column; }
}

@media (max-width: 440px) {
    .account-menu { justify-content: space-between; gap: 7px; font-size: 0.78rem; }
    .panel { padding: 16px; border-radius: 15px; }
    .page-heading h1 { font-size: 1.65rem; }
    .balance-card strong { font-size: 2.55rem; }
    .selection-grid { grid-template-columns: 1fr 1fr; gap: 7px; }
    .entries-toolbar > label, .entries-toolbar > fieldset { flex-basis: 100%; }
    .segmented-control label { flex: 1; }
    .entry-row { grid-template-columns: 1fr; }
    .entry-actions { grid-column: auto; }
    .summary-row { grid-template-columns: minmax(0, 1fr) 120px; gap: 8px; }
    .form-actions { align-items: stretch; flex-direction: column-reverse; }
    .form-actions > * { width: 100%; }
}

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

