* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
}

body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: var(--text-base);
    color: var(--text-primary);
    background: var(--surface-page);
    overflow: hidden;
}

.topbar {
    display: flex;
    align-items: center;
    height: 56px;
    padding: 0 var(--space-6);
    background: var(--surface-inverse);
    color: var(--text-inverse);
}

.topbar-menu-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 32px;
    height: 32px;
    padding: 0;
    margin-right: var(--space-3);
    background: none;
    border: none;
    cursor: pointer;
}

.topbar-menu-btn span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text-inverse);
    border-radius: 1px;
}

.topbar-title {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
}

.topbar-spacer {
    flex: 1;
}

.topbar-ai-btn {
    color: var(--text-inverse);
    text-decoration: none;
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    padding: 6px 14px;
    border-radius: var(--radius-md);
    background: var(--surface-inverse-hover);
    border: 1px solid var(--border-inverse);
    cursor: pointer;
    transition: background 0.15s;
}

.topbar-ai-btn:hover {
    background: var(--border-inverse);
}

.topbar-ai-dropdown {
    position: relative;
}

.topbar-user {
    font-size: var(--text-sm);
    margin-left: var(--space-4);
    margin-right: var(--space-3);
    opacity: 0.8;
}

.topbar-ai-menu {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 4px;
    min-width: 160px;
    background: var(--surface-inverse);
    border: 1px solid var(--border-inverse);
    border-radius: var(--radius-md);
    padding: 4px;
    z-index: var(--z-ai-menu);
    box-shadow: var(--shadow-lg);
}

.topbar-ai-option {
    display: block;
    color: var(--text-inverse-muted);
    text-decoration: none;
    font-size: var(--text-sm);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    transition: background 0.12s;
}

.topbar-ai-option:hover {
    background: var(--surface-inverse-hover);
    color: var(--text-inverse);
}

/* The user menu (Settings / Log off) uses <button> items — reset button
   chrome so they look identical to the <a> dropdown options above. */
button.topbar-ai-option {
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    cursor: pointer;
}

.layout {
    display: flex;
    height: calc(100vh - 56px);
}

.sidebar-overlay {
    display: none;
}

.sidebar {
    width: 200px;
    background: var(--surface-card);
    border-right: 1px solid var(--border-default);
    padding: var(--space-4) 0;
    display: flex;
    flex-direction: column;
}

.sidebar a {
    padding: 12px var(--space-6);
    color: var(--text-primary);
    text-decoration: none;
    font-size: var(--text-base);
}

.sidebar a.active {
    background: var(--surface-sunken);
    font-weight: var(--weight-semibold);
    border-right: 3px solid var(--accent);
}

.sidebar a:hover {
    background: var(--surface-sunken);
}

.sidebar a.sidebar-bottom {
    margin-top: auto;
    border-top: 1px solid var(--border-default);
    padding-top: var(--space-4);
}

.sidebar a.sidebar-sub {
    padding-left: 40px;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.sidebar a.sidebar-sub-sub {
    padding-left: 56px;
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.content {
    flex: 1;
    min-width: 0;
    padding: var(--space-7);
    overflow: auto;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-6);
}

.page-header-actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.filter-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
    font-size: var(--text-base);
}

.filter-bar select,
.filter-bar input {
    padding: 6px 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
}

.pager {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-top: var(--space-3);
    font-size: var(--text-base);
}

.pager-top {
    justify-content: flex-end;
    margin-top: 0;
    margin-bottom: var(--space-3);
}

.pager-info {
    color: var(--text-secondary);
}

.pager-prev:disabled,
.pager-next:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.search-box {
    position: relative;
    width: 400px;
}

.search-box input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
}

.search-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--surface-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    max-height: 320px;
    overflow-y: auto;
    z-index: var(--z-dropdown);
}

.search-results {
    list-style: none;
    margin: 0;
    padding: 4px 0;
}

.search-results li {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-subtle);
}

.search-results li:last-child {
    border-bottom: none;
}

.search-result-name {
    font-weight: var(--weight-semibold);
    font-size: var(--text-base);
}

.search-result-meta {
    font-size: var(--text-sm);
    margin-top: 2px;
}

.search-result-symbol {
    margin-left: var(--space-2);
}

.search-result-portfolios {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 6px;
}

.search-result-portfolio-link {
    color: var(--text-secondary);
    font-size: var(--text-sm);
    text-decoration: underline;
}

.search-result-portfolio-link:hover {
    color: var(--accent);
}

.search-empty {
    padding: var(--space-3);
    color: var(--text-secondary);
    font-size: var(--text-base);
}

.since-loading {
    display: none;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
}

.since-loading.visible {
    display: inline-flex;
}

.spinner-small {
    width: 14px;
    height: 14px;
    border-width: 2px;
}

.content-loading {
    opacity: 0.5;
    pointer-events: none;
}

.button {
    display: inline-block;
    background: var(--accent);
    color: var(--text-inverse);
    border: none;
    border-radius: var(--radius-md);
    padding: 8px var(--space-4);
    font-size: var(--text-base);
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s;
}

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

.button-secondary {
    background: var(--surface-sunken);
    color: var(--text-primary);
    border: 1px solid var(--border-default);
}

.button-secondary:hover {
    background: var(--border-default);
}

.button-danger {
    background: var(--surface-sunken);
    color: var(--negative);
    border: 1px solid var(--negative);
}

.button-danger:hover {
    background: var(--negative-bg);
}

.button[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--space-4);
}

.card-grid > .card {
    display: flex;
    flex-direction: column;
}

.card-grid > .card .card-actions {
    margin-top: auto;
    padding-top: var(--space-4);
}

.bank-group {
    margin-bottom: var(--space-7);
}

.bank-group h2 {
    margin: 0 0 var(--space-3);
    font-size: var(--text-xl);
}

.card {
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
}

.card h2 {
    margin: 0 0 var(--space-3);
    font-size: var(--text-lg);
}

#bank-detail-content > .card,
#bank-detail-content > .detail-top-row,
#lts-detail-content > .card,
#lts-detail-content > .detail-top-row,
#realestate-detail-content > .card,
#realestate-detail-content > .detail-top-row,
#crypto-detail-content > .card,
#crypto-detail-content > .detail-top-row {
    margin-bottom: var(--space-5);
}

/* Crypto workbench pages (matching / bank statements): stacked cards keep the
   same vertical rhythm as the detail-page card stacks above. */
#matching-auto-view > .card,
#matching-manual-view > .card,
#bank-statements-content > .card {
    margin-bottom: var(--space-5);
}

.detail-top-row {
    display: flex;
    align-items: flex-start;
    gap: var(--space-5);
}

.detail-top-row .bank-account-info {
    flex: 0 0 auto;
    max-width: 480px;
}

.detail-top-row .credit-cards {
    flex: 1 1 auto;
    min-width: 0;
}

.detail-top-row .map-card {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.map-card #property-map {
    flex: 1;
    min-height: 320px;
    border-radius: var(--radius-lg);
    /* Leaflet's internal panes/controls use z-index values up to 1000 (see
       vendor/leaflet.css), well above --z-modal-overlay (100). Without its
       own stacking context those values compare directly against the rest
       of the page and paint over open modals -- isolate so they're
       contained to the map itself. */
    isolation: isolate;
}

.map-card .map-placeholder {
    flex: 1;
    min-height: 320px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    text-align: center;
    padding: var(--space-4);
}

.bank-account-info {
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    column-gap: var(--space-3);
    row-gap: 6px;
    align-items: baseline;
}

.bank-account-info .card-header-row {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

.bank-account-info .card-header-row h2 {
    margin: 0;
}

.bank-account-info .card-header-actions {
    display: flex;
    align-items: center;
}

.bank-account-info .card-row {
    display: contents;
}

.bank-account-info .card-row .label {
    text-align: right;
    white-space: nowrap;
}

.bank-account-info .card-row .value {
    text-align: left;
    min-width: 0;
    overflow-wrap: break-word;
    word-break: break-word;
}

.card-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 6px;
    font-size: var(--text-base);
}

.card-row .label {
    color: var(--text-secondary);
}

.card-row .value.positive {
    color: var(--positive);
}

.card-row .value.negative {
    color: var(--negative);
}

.value-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.value-bold {
    font-weight: var(--weight-bold);
    font-variant-numeric: tabular-nums;
}

.bank-group .bank-summary {
    display: inline-block;
    margin-left: var(--space-3);
    margin-bottom: var(--space-3);
}

.bank-group .bank-summary .bank-summary-rows {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    gap: var(--space-4) var(--space-8);
}

.bank-group .bank-summary .card-row {
    justify-content: flex-start;
    gap: var(--space-4);
    margin-bottom: 0;
}

.bank-summary-lg .card-row {
    font-size: var(--text-lg);
}

.card-note {
    margin-top: var(--space-2);
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.filter-toggle-row {
    margin-bottom: var(--space-3);
}

.toggle-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.toggle-label input[type="checkbox"] {
    width: 15px;
    height: 15px;
    accent-color: var(--accent);
    cursor: pointer;
}

.card-actions {
    margin-top: var(--space-4);
}

.decision-card {
    margin: var(--space-2) 0;
    background: var(--surface-sunken);
}

.decision-options {
    border: none;
    margin: 0 0 var(--space-2);
    padding: 0;
}

.decision-option-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 6px;
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    cursor: pointer;
}

.decision-option-row:hover {
    background: var(--border-default);
}

.decision-confirm-btn {
    margin-top: var(--space-2);
}

.decision-option-manual {
    margin: 2px 0 6px 26px;
    padding: 8px 10px;
    border-left: 2px solid var(--border-strong);
    background: var(--surface-card);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
}

.decision-back-link {
    display: inline-block;
    margin-top: var(--space-2);
    background: none;
    border: none;
    padding: 0;
    color: var(--text-secondary);
    font-size: var(--text-xs);
    text-decoration: underline;
    cursor: pointer;
}

.decision-back-link:hover {
    color: var(--text-primary);
}

.decision-checkbox {
    display: block;
    margin: 4px 0;
    font-size: var(--text-base);
}

.decision-text-input {
    padding: 6px 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
    margin-right: 6px;
}

.pp-card {
    padding: 10px 12px;
    border-radius: var(--radius-md);
}

.pp-items {
    max-height: 220px;
    overflow-y: auto;
}

.pp-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.pp-item .pp-amount {
    width: 100px;
}

.pp-new-row {
    margin: 6px 0 0 22px;
    display: flex;
    gap: var(--space-2);
}

.pp-hint {
    margin-top: var(--space-2);
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.pp-hint-ok {
    color: var(--positive);
}

.pp-hint-error {
    color: var(--negative);
}

.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
    font-variant-numeric: tabular-nums;
}

.table-banks {
    table-layout: fixed;
}

.table-banks th:nth-child(1), .table-banks td:nth-child(1) { width: 4%; }
.table-banks th:nth-child(2), .table-banks td:nth-child(2) { width: 14%; }
.table-banks th:nth-child(3), .table-banks td:nth-child(3) { width: 10%; }
.table-banks th:nth-child(4), .table-banks td:nth-child(4) { width: 24%; }
.table-banks th:nth-child(5), .table-banks td:nth-child(5) { width: 14%; }
.table-banks th:nth-child(6), .table-banks td:nth-child(6) { width: 15%; }
.table-banks th:nth-child(7), .table-banks td:nth-child(7) { width: 19%; }

.table-admin {
    table-layout: fixed;
    margin-bottom: var(--space-6);
}

.table-admin td:nth-child(1) { width: 260px; }

.banner {
    padding: 12px var(--space-4);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
    font-size: var(--text-base);
}

.banner-success {
    background: var(--positive-bg);
    color: var(--positive);
}

.banner-error {
    background: var(--negative-bg);
    color: var(--negative);
}

.spinner-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    align-items: center;
    justify-content: center;
    z-index: var(--z-spinner-overlay);
}

.spinner-overlay.visible {
    display: flex;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 5px solid var(--border-default);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spinner-rotate 0.8s linear infinite;
}

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

.table-portfolios {
    table-layout: fixed;
}

.table-portfolios th:nth-child(1), .table-portfolios td:nth-child(1) { width: 4%; }
.table-portfolios th:nth-child(2), .table-portfolios td:nth-child(2) { width: 26%; }
.table-portfolios th:nth-child(3), .table-portfolios td:nth-child(3) { width: 17%; }
.table-portfolios th:nth-child(4), .table-portfolios td:nth-child(4) { width: 23%; }
.table-portfolios th:nth-child(5), .table-portfolios td:nth-child(5) { width: 15%; }
.table-portfolios th:nth-child(6), .table-portfolios td:nth-child(6) { width: 15%; }

.table-fund-products {
    table-layout: fixed;
}

.table-fund-products th:nth-child(1), .table-fund-products td:nth-child(1) { width: 4%; }
.table-fund-products th:nth-child(2), .table-fund-products td:nth-child(2) { width: 24%; }
.table-fund-products th:nth-child(3), .table-fund-products td:nth-child(3) { width: 9%; }
.table-fund-products th:nth-child(4), .table-fund-products td:nth-child(4) { width: 15%; }
.table-fund-products th:nth-child(5), .table-fund-products td:nth-child(5) { width: 9%; }
.table-fund-products th:nth-child(6), .table-fund-products td:nth-child(6) { width: 12%; }
.table-fund-products th:nth-child(7), .table-fund-products td:nth-child(7) { width: 12%; }
.table-fund-products th:nth-child(8), .table-fund-products td:nth-child(8) { width: 8%; }
.table-fund-products th:nth-child(9), .table-fund-products td:nth-child(9) { width: 7%; }

.table-fund-products td:nth-child(4) div:not(:last-child) {
    margin-bottom: 4px;
}

.table th, .table td {
    text-align: left;
    padding: 12px var(--space-4);
    font-size: var(--text-base);
    border-bottom: 1px solid var(--border-default);
}

.table th {
    color: var(--text-secondary);
    font-weight: var(--weight-semibold);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table th[data-sort-key] {
    cursor: pointer;
    user-select: none;
}

.table th[data-sort-key]:hover {
    color: var(--text-primary);
}

.sort-arrow {
    display: inline-block;
    font-size: 10px;
}

.table .positive {
    color: var(--positive);
}

.table .negative {
    color: var(--negative);
}

.table-actions {
    display: flex;
    gap: 6px;
}

.button-secondary[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.icon-button {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-md);
    line-height: 1;
    color: var(--text-inverse);
    cursor: pointer;
    transition: background 0.15s;
}

.icon-button:hover:not([disabled]) {
    background: var(--accent-hover);
}

.icon-button[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
}

.icon-button-buy {
    background: var(--positive);
}

.icon-button-sell {
    background: var(--negative);
}

.icon-button-dividend {
    background: var(--accent);
}

.icon-button-edit {
    display: inline-flex;
    width: 22px;
    height: 22px;
    font-size: var(--text-sm);
    background: var(--text-muted);
    vertical-align: middle;
    margin-left: 6px;
}

.icon-button-delete {
    display: inline-flex;
    width: 22px;
    height: 22px;
    font-size: var(--text-base);
    background: var(--negative);
    vertical-align: middle;
    margin-left: 6px;
}

.icon-button-report {
    display: inline-flex;
    width: 26px;
    height: 26px;
    font-size: var(--text-sm);
    background: var(--text-muted);
}

.expenditure-accordion-nav .icon-button {
    background: var(--text-muted);
    flex-shrink: 0;
}

.badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 10px;
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    vertical-align: middle;
    color: var(--text-inverse);
}

.table-banks td:nth-child(3) div:not(:last-child) {
    margin-bottom: 4px;
}

.value-group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.value-amount {
    white-space: nowrap;
}

.badge-kind-checking { background: var(--badge-checking); }
.badge-kind-savings { background: var(--badge-savings); }
.badge-kind-investment { background: var(--badge-investment); }
.badge-kind-pension { background: var(--badge-pension); }
.badge-kind-other { background: var(--badge-other); }
.badge-business { background: var(--badge-business); }
.badge-count { background: var(--accent); color: var(--accent-contrast-text); }

.badge-match-direct { background: var(--badge-match-direct); }
.badge-match-onchain { background: var(--badge-match-onchain); }
.badge-match-heuristic { background: var(--badge-match-heuristic); }
.badge-match-manual { background: var(--badge-match-manual); }
.badge-lightning { background: #f7931a; color: #fff; font-weight: 600; }
.badge-lightning-channel { background: #f7931a; color: #fff; font-weight: 600; }
.badge-muted { background: var(--table-border, #e0e0e0); color: var(--text, #333); }
.badge-match-none { background: var(--badge-match-none); }
.badge-direction-deposit { background: var(--positive); }
.badge-direction-withdrawal { background: var(--negative); }
.badge-cross-currency { background: var(--accent-subtle); color: var(--accent); }

.matching-cross-currency-panel { margin-top: var(--space-3); }
.matching-link-bar { margin-top: var(--space-4); }
.matching-link-bar .matching-link-line { margin: 0 0 var(--space-2); }
.matching-link-bar .matching-link-diff { color: var(--text-muted); }

.matching-mode-switch { display: flex; gap: var(--space-2); margin-bottom: var(--space-4); }
tr.matching-row-selected { background: var(--accent-subtle); }

.button-link {
    background: none;
    border: none;
    padding: 0;
    margin-left: var(--space-2);
    color: var(--accent);
    font-size: var(--text-xs);
    text-decoration: underline;
    cursor: pointer;
}
.button-link:hover { color: var(--accent-hover); }

.row-highlighted { outline: 2px solid var(--accent); outline-offset: -2px; }

.table .num {
    text-align: right;
}

.table-compact th,
.table-compact td {
    padding: 6px 12px;
    font-size: var(--text-sm);
    white-space: nowrap;
}

.table-compact th {
    font-size: var(--text-xs);
}

.table-subline {
    display: block;
    margin-top: 2px;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.table-subline.positive {
    color: var(--positive);
}

.table-subline.negative {
    color: var(--negative);
}

.negative-holding {
    color: var(--negative);
}

.detail-page {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.detail-page-body {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.table-scroll {
    /* bounded to the space left after page-header/filter-bar, so this box - not .content -
       is what scrolls and shows a scrollbar, right at the table's own edge */
    flex: 1;
    min-height: 0;
    min-width: 0;
    overflow: auto;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.table-scroll .table {
    /* .table's base overflow: hidden would otherwise become the sticky containing block
       instead of .table-scroll, breaking the sticky header when this table scrolls */
    overflow: visible;
    /* border-collapse: collapse causes a rendering seam where scrolled body content
       bleeds through the sticky header's shared border */
    border-collapse: separate;
    border-spacing: 0;
    box-shadow: none;
    border-radius: 0;
    width: max-content;
    min-width: 100%;
}

.table-scroll thead th {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    background: var(--surface-card);
}

/* Jaren / transactions / person tables: let header labels wrap onto multiple lines
   (space-separated words, not mid-word) instead of forcing the column open to their
   full unwrapped width. Combined with the data cells' own white-space:nowrap, the
   browser's table auto-layout sizes each column to whichever is wider -- the data
   rows' unbreakable content, or the header's single longest word -- so a short data
   column stays compact even under a long header, letting width:min-content size the
   whole table to that, no wider. Scoped to >=640px/1024px (matching the stacked-card
   breakpoints below) so it never fights the phone/tablet card layout, where these
   tables have no header row to wrap. */
@media (min-width: 640px) {
    #pnl-years-table,
    #pnl-person-table {
        width: min-content;
        min-width: 0;
    }

    #pnl-years-table th,
    #pnl-person-table th {
        white-space: normal;
    }
}

@media (min-width: 1024px) {
    #pnl-transactions-table {
        width: min-content;
        min-width: 0;
    }

    #pnl-transactions-table th {
        white-space: normal;
    }
}

.asset-grid {
    display: grid;
    grid-template-columns: 340px 1fr;
    grid-template-rows: auto auto;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
}

.asset-info {
    grid-column: 1;
    grid-row: 1;
}

.hold-info {
    grid-column: 1;
    grid-row: 2;
}

.chart-card {
    grid-column: 2;
    grid-row: 1 / 3;
    display: flex;
    flex-direction: column;
    min-height: 420px;
}

.pnl-section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-3);
}

.pnl-section-header h2 {
    margin-bottom: 0;
}

.pnl-header-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.pnl-cached-note {
    white-space: nowrap;
}

.pnl-grid {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: var(--space-4);
    flex: 1;
    min-height: 0;
}

.pnl-left, .pnl-right {
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
}

.pnl-left .table-scroll {
    min-height: 200px;
}

.pnl-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-style: italic;
    text-align: center;
}

.pnl-detail-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.pnl-detail-header {
    display: flex;
    align-items: baseline;
    gap: var(--space-3);
    padding: 12px var(--space-4);
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.pnl-detail-year {
    font-weight: var(--weight-semibold);
    font-size: 1.1em;
}

.pnl-detail-summary {
    color: var(--text-secondary);
}

.pnl-year-row.selected {
    background: var(--accent-subtle);
}

.pnl-summary {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px 20px;
    margin-bottom: var(--space-4);
    padding: 14px var(--space-5);
    font-size: var(--text-base);
}

.pnl-summary-item {
    white-space: nowrap;
}

.pnl-summary-item strong {
    font-weight: var(--weight-semibold);
}

.pnl-summary-note {
    width: 100%;
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 4px;
}

.button-small {
    padding: 4px 10px;
    font-size: var(--text-xs);
    white-space: nowrap;
}

.pnl-tx-actions {
    /* Deliberately not display:flex here: overriding a <td>'s display takes it out of
       table-cell layout, so its border-bottom would hug the short icon button's height
       instead of spanning the full (taller) row -- vertical-align keeps it a real cell. */
    vertical-align: middle;
}

.pnl-person-breakdown {
    margin-top: var(--space-4);
}

.pb-tax-person-checkbox {
    display: block;
    font-weight: normal;
}

.chart-header,
.card-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-2);
}

/* Crypto summary stat blocks (crypto/_summary.html): label stacked above
   value, matching the app's stat styling language used elsewhere. */
.stat-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-block .stat-label {
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.stat-block .stat-value {
    font-size: var(--text-base);
    font-weight: var(--weight-semibold);
    font-variant-numeric: tabular-nums;
}

.stat-block .stat-value.positive {
    color: var(--positive);
}

.stat-block .stat-value.negative {
    color: var(--negative);
}

.chart-header select {
    padding: 6px 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
}

.chart-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chart-settings {
    position: relative;
}

.icon-button-settings {
    background: var(--text-secondary);
}

.chart-settings-panel {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    width: 430px;
    background: var(--surface-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 14px;
    z-index: var(--z-flyout);
}

.chart-settings-section + .chart-settings-section {
    margin-top: var(--space-4);
}

.chart-settings-section-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 6px;
}

.chart-settings-section-header h3 {
    font-size: var(--text-base);
    margin: 0;
}

.chart-settings-hint {
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.chart-settings-table {
    width: 100%;
}

.chart-settings-table th,
.chart-settings-table td {
    padding: 6px 8px;
}

.chart-settings-table .cs-type {
    padding: 4px 6px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
}

.chart-settings-table .cs-period {
    width: 60px;
    padding: 4px 6px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
}

.chart-settings-table .cs-unit {
    padding: 4px 6px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
}

.chart-settings-table .cs-color {
    width: 28px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
}

.chart-settings-row-remove {
    background: none;
    border: none;
    color: var(--negative);
    cursor: pointer;
    font-size: var(--text-md);
    line-height: 1;
}

.chart-settings-add {
    margin-top: 6px;
    font-size: var(--text-sm);
    padding: 6px 12px;
}

.chart-settings-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 14px;
}

.chart-settings-status {
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.resolve-symbol {
    margin-top: var(--space-2);
}

.resolve-symbol-panel {
    background: var(--surface-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 14px;
}

.resolve-symbol-candidates {
    list-style: none;
    margin: 8px 0;
    padding: 0;
}

.resolve-symbol-candidate {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 0;
    font-size: var(--text-sm);
    border-bottom: 1px solid var(--border-subtle);
}

.resolve-symbol-candidate-info {
    flex: 1;
}

.resolve-symbol-manual {
    display: flex;
    gap: 6px;
    margin-top: 10px;
}

.resolve-symbol-input {
    flex: 1;
    padding: 6px 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
}

.resolve-symbol-status,
.resolve-symbol-error {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    margin-top: 4px;
}

.resolve-symbol-error {
    color: var(--negative);
}

.resolve-symbol-confirm-details {
    font-size: var(--text-sm);
    margin-bottom: var(--space-3);
}

.resolve-symbol-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.resolve-symbol-fallback-toggle {
    display: inline-block;
    margin-top: 10px;
    background: none;
    border: none;
    padding: 0;
    color: var(--text-secondary);
    font-size: var(--text-xs);
    text-decoration: underline;
    cursor: pointer;
}

.resolve-symbol-fallback-toggle:hover {
    color: var(--text-primary);
}

.resolve-symbol-fallback-sources {
    margin-top: 6px;
    padding: 8px 10px;
    border-left: 2px solid var(--border-strong);
    background: var(--surface-card);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.cash-card {
    display: inline-flex;
    flex-direction: column;
    max-width: 560px;
}

.cash-card .card-header-row {
    gap: var(--space-4);
}

.cash-card .card-header-row h2 {
    flex-shrink: 0;
}

.cash-table-scroll {
    overflow-x: auto;
}

.cash-table-scroll .cash-table {
    width: max-content;
    min-width: 100%;
}

.cash-table th,
.cash-table td {
    text-align: center;
}

.cash-actions {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    gap: 8px;
}

.cash-exchange,
.cash-transfer,
.cash-inventory {
    position: relative;
}

.cash-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    width: 340px;
    background: var(--surface-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    padding: 14px;
    z-index: var(--z-flyout);
    box-sizing: border-box;
}

.cash-field-row {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.cash-field-row label {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.cash-full-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: var(--text-xs);
    color: var(--text-secondary);
    margin-bottom: 10px;
}

.cash-input,
.cash-field-row select,
.cash-full-row select,
.cash-full-row input {
    width: 100%;
    box-sizing: border-box;
    padding: 6px 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
}

.owner-checkbox-list {
    gap: 6px;
    align-items: flex-start;
}

.owner-checkbox-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    font-size: var(--text-sm);
    color: var(--text-primary);
}

.owner-checkbox-row input[type="checkbox"] {
    width: auto;
    margin: 0;
    flex-shrink: 0;
}

.expenditure-readonly-toggle {
    margin-left: 12px;
    white-space: nowrap;
}

.merge-account-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 320px;
    overflow-y: auto;
    padding: 2px;
}

.merge-account-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    padding: 8px 10px;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.15s ease, background-color 0.15s ease;
}

.merge-account-row:hover {
    border-color: var(--border-strong);
    background: var(--surface-sunken, rgba(0, 0, 0, 0.02));
}

.merge-account-row:has(input:checked) {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 8%, transparent);
}

.merge-account-row input[type="checkbox"] {
    width: auto;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--accent);
}

.merge-account-type {
    margin-left: auto;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.cash-error {
    font-size: var(--text-xs);
    color: var(--negative);
    margin-top: 4px;
    min-height: 14px;
}

.cash-confirm-details {
    font-size: var(--text-sm);
    margin-bottom: var(--space-3);
}

.cash-footer {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal-overlay);
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 420px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 64px);
    overflow-y: auto;
    box-sizing: border-box;
    z-index: var(--z-modal);
}

.modal.modal-wide {
    width: 640px;
}

/* Back arrow shown only when a flow renders as a phone full screen
   (.screen-modal); hidden on desktop popups. */
.screen-modal-back {
    display: none;
}

.bs-evidence-pdf-frame {
    display: block;
    width: 100%;
    height: 60vh;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-4);
}

.modal-header {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border-default);
}

.modal-header h3 {
    margin: 0;
    font-size: var(--text-md);
}

.modal-body {
    padding: var(--space-4) var(--space-5);
}

.modal-divider {
    border: none;
    border-top: 1px solid var(--border-default);
    margin: var(--space-4) 0;
}

.trace-flow {
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.trace-node {
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-sm);
}

.trace-node-address {
    text-align: center;
    word-break: break-all;
}

.trace-node-self {
    font-weight: var(--weight-semibold);
}

.trace-node-wallet {
    font-weight: var(--weight-semibold);
    font-size: var(--text-sm);
    margin-bottom: 2px;
}

.trace-node-tx {
    background: var(--surface-sunken);
}

.trace-node-txid {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    margin-bottom: var(--space-1);
}

.trace-node-line {
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.trace-node-relevant {
    color: var(--text-primary);
    font-weight: var(--weight-semibold);
}

.trace-arrow {
    text-align: center;
    color: var(--text-muted);
    font-size: var(--text-md);
    line-height: 1;
    padding: var(--space-1) 0;
}

.trace-flow-heuristic {
    flex-direction: row;
    gap: var(--space-4);
}

.trace-flow-forwarded {
    flex-direction: row;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    margin-bottom: var(--space-2);
    background: var(--surface-sunken);
    border-radius: var(--radius-md);
    font-size: var(--text-xs);
}

.trace-flow-forwarded .trace-node {
    border: none;
    padding: var(--space-1);
    min-width: 0;
    flex: 1;
}

.trace-flow-forwarded .trace-arrow {
    flex-shrink: 0;
    font-size: var(--text-sm);
}

.trace-flow-forwarded .trace-node-self {
    background: var(--accent-subtle);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    border: 1px solid var(--accent);
}

.trace-flow-forwarded .trace-node-address code {
    font-size: 10px;
    word-break: break-all;
}

.trace-flow-forwarded .trace-node-line {
    font-size: 10px;
    line-height: 1.4;
}

.trace-flow-side {
    flex: 1;
}

.trace-node-label {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
    margin-bottom: var(--space-1);
    text-transform: uppercase;
}

.cash-overview-totals-card .card-row {
    gap: 24px;
}

.cash-overview-layout {
    display: flex;
    align-items: flex-start;
    gap: var(--space-6);
}

.cash-overview-left-col {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    flex-shrink: 0;
}

.cash-overview-left-col .cash-overview-totals-card {
    width: 220px;
}

.cash-overview-totals-card .cash-actions {
    flex-direction: column;
    align-items: stretch;
    margin-top: var(--space-4);
}

.cash-overview-table {
    flex: 1;
    min-width: 0;
}

.cash-overview-sidebar {
    width: 380px;
    flex-shrink: 0;
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.cash-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px var(--space-4);
    background: var(--surface-inverse);
    color: var(--text-inverse);
}

.cash-sidebar-title {
    font-weight: var(--weight-semibold);
    font-size: 15px;
}

.cash-sidebar-close {
    background: none;
    border: none;
    color: var(--text-inverse);
    font-size: var(--text-xl);
    cursor: pointer;
    line-height: 1;
    padding: 0 2px;
}

.cash-inline-form {
    padding: 14px;
}

.table-fit-content {
    width: auto;
    min-width: 400px;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-3);
    min-height: 20px;
    margin-bottom: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-primary);
}

.chart-legend .legend-date {
    color: var(--text-secondary);
}

.chart-legend .legend-currency {
    color: var(--text-secondary);
}

.chart-canvas-wrap {
    position: relative;
    display: flex;
    flex-direction: column;
    flex: 1;
}

#asset-chart {
    flex: 1;
}

.chart-tooltip {
    display: none;
    position: absolute;
    pointer-events: none;
    z-index: var(--z-dropdown);
    max-width: 260px;
    padding: 8px 10px;
    background: var(--surface-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-size: var(--text-xs);
    line-height: 1.5;
    color: var(--text-primary);
}

.chart-tooltip .tooltip-row + .tooltip-row {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-default);
}

.chart-tooltip .tooltip-action {
    font-weight: var(--weight-semibold);
}

.chart-tooltip .tooltip-portfolio {
    color: var(--text-secondary);
}

.chart-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-secondary);
}

.derive-summary {
    margin-bottom: var(--space-5);
    padding: var(--space-4);
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    font-size: var(--text-base);
}

.derive-section {
    margin-bottom: var(--space-5);
}

.derive-cluster {
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    margin-bottom: var(--space-4);
    box-shadow: var(--shadow-sm);
}

.derive-cluster-meta {
    margin-bottom: var(--space-3);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.derive-cluster-meta p {
    margin: 2px 0;
}

.derive-cluster-meta code {
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    background: var(--surface-sunken);
    padding: 1px 4px;
    border-radius: var(--radius-sm);
}

.derive-cluster-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-top: var(--space-4);
    padding-top: var(--space-3);
    border-top: 1px solid var(--border-default);
}

.derive-cluster-actions label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.derive-cluster-actions .cash-input {
    width: 260px;
}

.derive-privacy {
    background: var(--accent-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    margin-bottom: var(--space-4);
    border: 1px solid var(--accent);
}

.derive-unsupported {
    opacity: 0.7;
}

.derive-synthetic {
    opacity: 0.7;
}

.hint {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    margin: 4px 0;
}

.derive-details {
    margin-top: var(--space-3);
    font-size: var(--text-sm);
}

.derive-details summary {
    cursor: pointer;
    color: var(--accent);
    font-weight: var(--weight-semibold);
}

.derive-tx-checkbox {
    width: 28px;
    text-align: center;
    padding: 12px 6px !important;
}

.derive-tx-checkbox input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: var(--accent);
}

.derive-select-toggle {
    font-size: var(--text-xs);
    font-weight: var(--weight-normal);
    color: var(--accent);
    cursor: pointer;
    user-select: none;
    text-transform: none;
    letter-spacing: normal;
}

.derive-select-toggle:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.derive-outgoings-container {
    margin-top: var(--space-3);
}

.trace-flow-forwarded-row {
    display: flex;
    align-items: flex-start;
    gap: var(--space-1);
    margin-bottom: var(--space-2);
}

.derive-out-cb-label {
    display: flex;
    align-items: center;
    padding-top: var(--space-2);
    flex-shrink: 0;
}

.derive-out-cb-label input[type="checkbox"] {
    width: 15px;
    height: 15px;
    cursor: pointer;
    accent-color: var(--accent);
}

.trace-flow-forwarded-row .trace-flow-forwarded {
    flex: 1;
    min-width: 0;
}

.clickable-row {
    cursor: pointer;
}

.clickable-row:hover {
    background: var(--surface-page);
}

.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 80px;
    gap: var(--space-4);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-default);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    max-width: 400px;
}

.form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: var(--text-base);
}

.form input, .form textarea {
    padding: 8px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    font-size: var(--text-base);
}

.form-actions {
    display: flex;
    gap: 8px;
}

.report-meta {
    margin-bottom: var(--space-4);
}

.markdown-body {
    line-height: 1.6;
    font-size: var(--text-base);
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
    margin: 20px 0 10px;
    line-height: 1.3;
}

.markdown-body h1:first-child,
.markdown-body h2:first-child,
.markdown-body h3:first-child {
    margin-top: 0;
}

.markdown-body p {
    margin: 0 0 12px;
}

.markdown-body ul,
.markdown-body ol {
    margin: 0 0 12px;
    padding-left: var(--space-6);
}

.markdown-body li {
    margin-bottom: 4px;
}

.markdown-body code {
    background: var(--surface-sunken);
    border-radius: var(--radius-sm);
    padding: 2px 5px;
    font-size: var(--text-sm);
    font-family: var(--font-mono);
}

.markdown-body pre {
    background: var(--surface-inverse);
    color: var(--surface-page);
    border-radius: var(--radius-md);
    padding: 14px var(--space-4);
    overflow-x: auto;
    margin: 0 0 12px;
}

.markdown-body pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.markdown-body blockquote {
    margin: 0 0 12px;
    padding: 4px var(--space-4);
    border-left: 3px solid var(--border-strong);
    color: var(--text-secondary);
}

.markdown-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 12px;
}

.markdown-body th,
.markdown-body td {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-default);
    font-size: var(--text-sm);
}

.markdown-body th {
    color: var(--text-secondary);
    font-weight: var(--weight-semibold);
}

.login-page {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    background: var(--surface-page);
    font-family: var(--font-sans);
}

.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    padding: var(--space-7);
    box-shadow: var(--shadow-md);
}

.login-card h1 {
    font-size: var(--text-xl);
    margin: 0 0 var(--space-6);
    color: var(--text-primary);
}

.login-card .form {
    max-width: none;
}

/* ======================================================================
   Responsive: tablet and down (<1024px) — hamburger drawer, bottom-sheet
   panels/flyouts, two-column grid collapse.
   ====================================================================== */
@media (max-width: 1023px) {
    .topbar-menu-btn {
        display: inline-flex;
    }

    .sidebar {
        position: fixed;
        top: 56px;
        left: 0;
        bottom: 0;
        z-index: var(--z-drawer);
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: var(--shadow-lg);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 56px 0 0 0;
        background: rgba(15, 23, 42, 0.4);
        z-index: var(--z-drawer-overlay);
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.2s ease;
    }

    .sidebar-overlay.open {
        opacity: 1;
        pointer-events: auto;
    }

    .content {
        width: 100%;
    }

    .asset-grid {
        grid-template-columns: 1fr;
        grid-template-rows: none;
    }

    .asset-info, .hold-info, .chart-card {
        grid-column: 1;
        grid-row: auto;
    }

    .chart-card {
        min-height: 320px;
    }

    .pnl-grid {
        grid-template-columns: 1fr;
    }

    /* #pnl-transactions-table -> stacked cards a breakpoint earlier than the
       generic .table treatment below, since its action-buttons column makes
       the row too wide to fit once .pnl-grid has already gone single-column. */
    #pnl-transactions-table,
    #pnl-transactions-table thead,
    #pnl-transactions-table tbody,
    #pnl-transactions-table th,
    #pnl-transactions-table td,
    #pnl-transactions-table tr {
        display: block;
    }

    #pnl-transactions-table {
        table-layout: auto !important;
        width: 100%;
    }

    #pnl-transactions-table thead {
        position: absolute;
        left: -9999px;
    }

    #pnl-transactions-table tbody tr {
        margin-bottom: var(--space-3);
        border-radius: var(--radius-md);
        border: 1px solid var(--border-default);
        box-shadow: var(--shadow-sm);
        overflow: hidden;
    }

    #pnl-transactions-table td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: var(--space-3);
        text-align: right;
        white-space: normal;
        border-bottom: 1px solid var(--border-subtle);
    }

    #pnl-transactions-table tbody tr td:last-child {
        border-bottom: none;
    }

    #pnl-transactions-table td::before {
        content: attr(data-label);
        font-weight: var(--weight-semibold);
        color: var(--text-muted);
        text-align: left;
        flex-shrink: 0;
    }

    #pnl-transactions-table td[colspan] {
        display: block;
        text-align: center;
        color: var(--text-muted);
    }

    #pnl-transactions-table td[colspan]::before {
        content: none;
    }

    .cash-overview-layout {
        flex-direction: column;
        align-items: stretch;
    }

    .cash-overview-left-col {
        flex-direction: row;
        flex-wrap: wrap;
    }

    .cash-overview-left-col .cash-overview-totals-card {
        width: auto;
        flex: 1 1 240px;
    }

    .cash-overview-sidebar {
        width: 100%;
    }

    .detail-top-row {
        flex-direction: column;
    }

    .detail-top-row .bank-account-info {
        max-width: none;
        width: 100%;
    }

    /* Anchored flyouts become bottom sheets so they can't overflow a narrow viewport */
    .chart-settings-panel,
    .cash-panel {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        max-height: 80vh;
        overflow-y: auto;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        box-shadow: var(--shadow-lg);
        z-index: var(--z-drawer);
    }

    .topbar-ai-menu {
        position: fixed;
        top: 56px;
        right: 0;
        left: auto;
        min-width: 0;
        width: 220px;
        border-radius: 0 0 0 var(--radius-lg);
    }

    .modal {
        max-height: calc(100vh - 40px);
    }
}

/* ======================================================================
   Responsive: phone only (<640px) — normal document scroll, table->card
   stacking, sidebar-as-bottom-sheet.
   ====================================================================== */
@media (max-width: 639px) {
    body {
        overflow: visible;
    }

    .expenditure-grid-scroll {
        display: none;
    }

    .topbar {
        padding: 0 var(--space-4);
    }

    .topbar-title {
        font-size: var(--text-md);
        white-space: nowrap;
    }

    .topbar-user {
        display: none;
    }

    .topbar-ai-btn {
        padding: 6px 10px;
    }

    .layout {
        height: auto;
        min-height: calc(100vh - 56px);
    }

    .content {
        overflow: visible;
        padding: var(--space-4);
    }

    .detail-page,
    .detail-page-body {
        height: auto;
    }

    .table-scroll {
        overflow: visible;
        max-height: none;
    }

    .cash-overview-left-col {
        flex-direction: column;
    }

    .cash-overview-sidebar {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 85vh;
        overflow-y: auto;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        z-index: var(--z-drawer);
        box-shadow: var(--shadow-lg);
    }

    .page-header {
        flex-wrap: wrap;
        gap: var(--space-3);
    }

    /* Expenditure sheet detail: on phone, only the granularity picker
       (.filter-bar) and the "+ Boeking toevoegen" button stay -- print/
       detail-print/send-copy/settings/back-link in the page header and the
       add-future-period/copy-budget toolbar buttons all crowd and wrap on
       narrow screens, so they're dropped there in favor of the simpler
       accordion + single primary action. */
    .expenditure-desktop-only {
        display: none;
    }

    .search-box {
        width: 100%;
    }

    /* Table -> stacked cards. Targets the existing base .table class and its
       variants (.table-compact/.table-banks/.table-admin/.table-portfolios/
       .table-fund-products/.table-fit-content) with no markup changes
       beyond the data-label attributes added per template. */
    .table, .table thead, .table tbody, .table th, .table td, .table tr {
        display: block;
    }

    .table {
        table-layout: auto !important;
        width: 100%;
    }

    .table thead {
        /* visually hidden but still announced by screen readers, unlike display:none */
        position: absolute;
        left: -9999px;
    }

    .table tbody tr {
        margin-bottom: var(--space-3);
        border-radius: var(--radius-md);
        border: 1px solid var(--border-default);
        box-shadow: var(--shadow-sm);
        overflow: hidden;
    }

    .table td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: var(--space-3);
        text-align: right;
        white-space: normal;
        border-bottom: 1px solid var(--border-subtle);
    }

    .table tbody tr td:last-child {
        border-bottom: none;
    }

    .table td::before {
        content: attr(data-label);
        font-weight: var(--weight-semibold);
        color: var(--text-muted);
        text-align: left;
        flex-shrink: 0;
    }

    .table td:not([data-label]) {
        display: block;
        text-align: left;
    }

    .table td[colspan] {
        display: block;
        text-align: center;
        color: var(--text-muted);
    }

    .table td[colspan]::before {
        content: none;
    }

    .clickable-row {
        border-radius: var(--radius-md);
    }

    /* Compact SMA/EMA row-editor (chart_settings.js) isn't a record table — scroll
       horizontally inside its bottom sheet instead of stacking into label/value cards. */
    .chart-settings-table,
    .chart-settings-table thead,
    .chart-settings-table tbody,
    .chart-settings-table tr,
    .chart-settings-table th,
    .chart-settings-table td {
        display: revert;
    }

    .chart-settings-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }

    .chart-settings-table thead {
        position: static;
        left: auto;
    }

    .chart-settings-table td::before {
        content: none;
    }

    /* Bank accounts table: the leading data-label="" column holds only the
       "edit account" pencil button. Left in normal flow it stacks as an
       orphan full-width row with no visible label. Pin it to the card's
       top-right corner instead and reserve room for it above the IBAN row. */
    .table-banks tbody tr {
        position: relative;
        padding-top: 40px;
    }

    .table-banks td:first-child {
        position: absolute;
        top: var(--space-2);
        right: var(--space-3);
        width: auto;
        padding: 0;
        border-bottom: none;
    }

    .table-banks td:first-child::before {
        content: none;
    }

    /* Add-booking, cell-detail, and user settings open as dedicated full screens
       on phone instead of centered popups (screen_modal.js toggles
       .screen-modal on the modal and .screen-modal-active on the overlay). */
    .modal-overlay.screen-modal-active {
        background: var(--surface-page);
        align-items: stretch;
        justify-content: stretch;
    }

    .modal.screen-modal {
        width: 100%;
        max-width: none;
        max-height: none;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        box-shadow: none;
        display: flex;
        flex-direction: column;
    }

    .modal.screen-modal .modal-header {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: var(--space-3);
        padding-top: calc(var(--space-4) + env(safe-area-inset-top));
        flex-shrink: 0;
    }

    .modal.screen-modal .modal-body {
        flex: 1;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
    }

    .modal.screen-modal .screen-modal-back {
        display: inline-flex;
        width: 40px;
        height: 40px;
        font-size: var(--text-lg);
        flex-shrink: 0;
    }

    /* 16px inputs/buttons stop iOS from zooming in on focus. */
    .modal.screen-modal input,
    .modal.screen-modal button {
        font-size: 16px;
    }
}

@media print {
    .topbar,
    .sidebar,
    .sidebar-overlay,
    .page-header-actions {
        display: none;
    }

    .layout {
        height: auto;
    }

    .content {
        overflow: visible;
        padding: 0;
    }
}

/* Crypto flow visualization (web/templates/crypto/flow.html, js/crypto_flow.js) */
.flow-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    margin-bottom: var(--space-4);
    flex-wrap: wrap;
}

.flow-legend {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    flex-wrap: wrap;
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

.flow-toolbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.flow-save-status {
    font-size: var(--text-xs);
}

.flow-save-status.flow-save-status-ok {
    color: var(--color-success, #059669);
}

.flow-save-status.flow-save-status-error {
    color: var(--color-danger, #DC2626);
}

.flow-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.flow-legend-sep {
    width: 1px;
    height: 16px;
    background: var(--border-default);
}

.flow-swatch {
    display: inline-block;
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

.flow-swatch-circle {
    border-radius: 50%;
    border: 2px solid var(--text-secondary);
}

.flow-swatch-square {
    border: 2px solid var(--text-secondary);
}

.flow-swatch-diamond {
    border: 2px solid var(--text-secondary);
    transform: rotate(45deg);
}

.flow-swatch-dashed {
    border-radius: 50%;
    border: 2px dashed var(--text-secondary);
}

.flow-swatch-triangle {
    width: 0;
    height: 0;
    background: none;
    border-left: 7px solid transparent;
    border-right: 7px solid transparent;
    border-bottom: 12px solid var(--text-secondary);
}

.flow-swatch-gradient {
    width: 56px;
    height: 6px;
    border-radius: 3px;
    border: none;
    background: linear-gradient(90deg, hsl(0, 70%, 45%), hsl(60, 70%, 45%), hsl(120, 70%, 45%));
}

.flow-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin: calc(-1 * var(--space-3)) 0 var(--space-4);
}

.flow-date-range {
    margin-bottom: var(--space-4);
}

.flow-date-range-labels {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    margin-bottom: var(--space-3);
}

#flow-date-from-label,
#flow-date-to-label {
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
}

.flow-slider {
    position: relative;
    height: 24px;
}

.flow-slider-track {
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--border-default);
    border-radius: 2px;
    transform: translateY(-50%);
    pointer-events: none;
}

.flow-slider-input {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 24px;
    margin: 0;
    background: transparent;
    pointer-events: none;
    -webkit-appearance: none;
    appearance: none;
}

.flow-slider-input::-webkit-slider-runnable-track {
    background: transparent;
}

.flow-slider-input::-moz-range-track {
    background: transparent;
}

.flow-slider-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    pointer-events: auto;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface-card);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    margin-top: 2px;
}

.flow-slider-input::-moz-range-thumb {
    pointer-events: auto;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface-card);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
}

.flow-canvas-wrap {
    position: relative;
    padding: 0;
    height: 70vh;
    min-height: 480px;
    overflow: hidden;
}

#flow-canvas {
    display: block;
    width: 100%;
    height: 100%;
    cursor: grab;
}

#flow-canvas:active {
    cursor: grabbing;
}

.flow-tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--surface-inverse);
    color: var(--text-inverse);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: var(--text-xs);
    max-width: 280px;
    box-shadow: var(--shadow-md);
    z-index: var(--z-flyout);
    line-height: 1.5;
}

.flow-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    pointer-events: none;
}

.flow-empty[hidden] {
    display: none;
}

.flow-trace-panel {
    position: absolute;
    top: var(--space-3);
    right: var(--space-3);
    bottom: var(--space-3);
    width: 340px;
    max-width: calc(100% - var(--space-6));
    background: var(--surface-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    z-index: var(--z-flyout);
    overflow: hidden;
}

.flow-trace-panel[hidden] {
    display: none;
}

.flow-trace-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-default);
    font-size: var(--text-sm);
}

.flow-trace-close {
    background: none;
    border: none;
    font-size: var(--text-lg);
    line-height: 1;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 var(--space-1);
}

.flow-trace-close:hover {
    color: var(--text-primary);
}

.flow-trace-summary {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-default);
    font-size: var(--text-xs);
    color: var(--text-secondary);
    line-height: 1.5;
}

.flow-trace-rows {
    overflow-y: auto;
    flex: 1;
    padding: var(--space-2) 0;
}

.flow-trace-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-xs);
    border-bottom: 1px solid var(--border-subtle, var(--border-default));
}

.flow-trace-row-edge {
    cursor: pointer;
}

.flow-trace-row-edge:hover {
    background: var(--surface-hover, rgba(0, 0, 0, 0.03));
}

.flow-trace-weight {
    flex-shrink: 0;
    width: 44px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
}

.flow-trace-body {
    flex: 1;
    min-width: 0;
}

.flow-trace-body-main {
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.flow-trace-body-sub {
    color: var(--text-muted);
}

.flow-trace-dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.flow-trace-empty {
    padding: var(--space-4);
    color: var(--text-muted);
    font-size: var(--text-xs);
}

/* ---- Expenditure grid ---- */

/* .page-header is justify-content: space-between, so the sheet name and its
   all-time saldo are wrapped together here -- a bare third flex child would
   float the saldo into the middle of the header instead. */
.expenditure-header-title {
    display: flex;
    align-items: baseline;
    gap: var(--space-4);
    min-width: 0;
}

.expenditure-header-saldo {
    color: var(--text-muted);
    font-size: var(--text-base);
    white-space: nowrap;
}

.expenditure-saldo-scope {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* Only on the sheet page, where it shares a filter bar with the granularity
   picker; on the overview it is the bar's only control. */
#expenditure-granularity ~ .expenditure-saldo-scope {
    margin-left: var(--space-4);
}

.expenditure-header-saldo strong {
    font-size: var(--text-lg);
}

/* .positive/.negative are only ever scoped selectors in this stylesheet
   (.table, .stat-block, .expenditure-balance-row ...), so the saldo needs its
   own pair rather than relying on a generic utility class. */
.expenditure-header-saldo .positive,
.expenditure-accordion-saldo .positive {
    color: var(--positive);
}

.expenditure-header-saldo .negative,
.expenditure-accordion-saldo .negative {
    color: var(--negative);
}

.expenditure-toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-3);
}

.expenditure-toolbar-right {
    margin-left: auto;
}

/* No unconditional display:none here on purpose: this stylesheet's shared
   phone-only overrides live in the @media (max-width: 639px) block near the
   top of the file, which is earlier in source order than this section. An
   unconditional rule here would win the cascade tie-break (same #id
   specificity, later source position) and permanently hide the accordion
   regardless of viewport -- so "hide on tablet/desktop" instead lives in its
   own later @media rule below, guaranteed to be the last word on this
   selector. Below 640px it just keeps the div's default display: block. */
@media (min-width: 640px) {
    #expenditure-accordion {
        display: none;
    }
}

/* Sits above the period nav as part of the accordion's header block, so it
   reads as a sheet-wide figure rather than another category row. */
.expenditure-accordion-saldo {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 8px;
    font-weight: 600;
    border-bottom: 1px solid var(--border-strong);
}

.expenditure-accordion-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3) 8px;
    border-bottom: 1px solid var(--border-strong);
}

.expenditure-accordion-nav-label {
    flex: 1;
    text-align: center;
    font-weight: 600;
}

.expenditure-accordion-section + .expenditure-accordion-section {
    border-top: 1px solid var(--border-strong);
}

.expenditure-accordion-toggle,
.expenditure-accordion-leaf {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 12px 8px;
    border: none;
    background: none;
    text-align: left;
    border-bottom: 1px solid var(--border-default);
    min-height: 44px;
}

.expenditure-accordion-toggle {
    cursor: pointer;
}

.expenditure-accordion-section-toggle {
    font-weight: 600;
    background: var(--surface-inverse);
    color: var(--text-inverse);
}

.expenditure-accordion-name {
    flex: 1;
}

.expenditure-accordion-amount {
    flex-shrink: 0;
}

.expenditure-accordion-chevron,
.expenditure-accordion-toggle-spacer {
    display: inline-block;
    width: 16px;
    transition: transform 0.1s;
}

.expenditure-accordion-toggle.is-open .expenditure-accordion-chevron {
    transform: rotate(-180deg);
}

.expenditure-accordion-children {
    border-bottom: 1px solid var(--border-default);
}

.expenditure-accordion-empty {
    padding: var(--space-3);
    color: var(--text-muted);
}

.expenditure-category-field-btn {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

.expenditure-picker-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: var(--space-3);
}

.expenditure-picker-list {
    display: flex;
    flex-direction: column;
}

.expenditure-picker-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    padding: 10px 8px;
    min-height: 44px;
    border: none;
    background: none;
    text-align: left;
    border-bottom: 1px solid var(--border-default);
    cursor: pointer;
}

.expenditure-picker-row-check {
    color: var(--accent);
    font-weight: 700;
}

.expenditure-grid-scroll {
    /* bounded to the space left in .detail-page-body (below the page-header/
       filter-bar/toolbar), so this box -- not the whole page -- scrolls once
       the table gets taller than the viewport. */
    flex: 1;
    min-height: 0;
    overflow: auto;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
}

.expenditure-grid {
    border-collapse: collapse;
    width: max-content;
    min-width: 100%;
}

.expenditure-grid th, .expenditure-grid td {
    padding: 8px 14px;
    border-bottom: 1px solid var(--border-strong);
    white-space: nowrap;
    text-align: right;
}

.expenditure-grid thead th {
    position: sticky;
    top: 0;
    z-index: var(--z-sticky);
    text-align: right;
    background: var(--surface-sunken);
    font-weight: 600;
}

.expenditure-tree-col {
    position: sticky;
    left: 0;
    z-index: var(--z-sticky);
    background: var(--surface-card);
    text-align: left !important;
    box-shadow: 1px 0 0 0 var(--border-strong);
    /* fixed regardless of depth -- only .expenditure-row-label indents with
       the hierarchy, so the action menu button stays put on the left */
    padding-left: 8px;
}

.expenditure-row-label {
    display: inline-flex;
    align-items: center;
}

.expenditure-tree-cell-inner {
    display: flex;
    align-items: center;
    gap: 16px;
}

/* Main-category-only readout of this period's share of the section total --
   actual/actual-total on top (inherits the row's ambient bold/larger text,
   same treatment as an amount cell's primary value), budget/budget-total
   below in parens via .table-subline (same treatment as an amount cell's
   "(€budget)" line), so both lines follow the grid's existing convention.
   margin-left: auto (rather than justify-content: space-between on the
   parent) pushes just this block to the right, so the menu+label stay
   left-aligned at a consistent x regardless of label/indicator width. */
.expenditure-row-indicators {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    flex-shrink: 0;
    line-height: 1.3;
    margin-left: auto;
}

.expenditure-grid thead .expenditure-tree-col {
    /* the corner cell is sticky in both directions at once (top from the
       thead th rule above, left from .expenditure-tree-col) -- bump it above
       the plain row/column stickies so it stays on top during diagonal scroll. */
    background: var(--surface-sunken);
    z-index: calc(var(--z-sticky) + 1);
}

.expenditure-current-period {
    background: var(--blue-50);
}

.expenditure-grid thead .expenditure-current-period {
    background: var(--blue-100);
}

.expenditure-future-period {
    background: var(--surface-sunken);
}

.expenditure-grid thead .expenditure-future-period {
    font-style: italic;
    color: var(--text-secondary);
}

.expenditure-cell {
    cursor: pointer;
}

.expenditure-cell[draggable="true"]:hover {
    cursor: grab;
}

.expenditure-cell-dragging {
    opacity: 0.4;
}

.expenditure-cell-drop-target {
    box-shadow: inset 0 0 0 2px var(--accent);
}

.expenditure-over-budget {
    color: var(--negative);
    font-weight: 600;
}

/* Second level: the tinted/bold treatment the top level used to have. */
.expenditure-row-depth-1 td {
    font-weight: 600;
}

.expenditure-row-depth-1 .expenditure-tree-col,
.expenditure-row-depth-1 .expenditure-cell:not(.expenditure-current-period):not(.expenditure-future-period) {
    background: var(--surface-sunken);
}

.table tr.expenditure-row-depth-1 td {
    background: var(--surface-sunken);
}

/* Top level: a step darker and a step larger than the second level, so the
   hierarchy reads at a glance. Third level and deeper stay unstyled. */
.expenditure-row-depth-0 td {
    font-weight: 600;
    font-size: var(--text-md);
}

.expenditure-row-depth-0 .expenditure-tree-col,
.expenditure-row-depth-0 .expenditure-cell:not(.expenditure-current-period):not(.expenditure-future-period) {
    background: var(--slate-200);
}

.table tr.expenditure-row-depth-0 td {
    background: var(--slate-200);
    font-size: var(--text-md);
}

/* Automatic, non-editable grand-total row pinned at the top of the tree --
   inverted (dark bg / light text) so it visually stands apart from the
   editable category rows below it. */
.expenditure-totals-row td {
    background: var(--surface-inverse);
    color: var(--text-inverse);
    font-weight: var(--weight-bold);
    font-size: var(--text-md);
    border-bottom: 2px solid var(--border-inverse);
}

.expenditure-totals-row .table-subline {
    color: var(--text-inverse-muted);
}

.expenditure-totals-label-cell {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.expenditure-totals-cell {
    cursor: default;
}

/* Income section starts right after the expense rows in the same table --
   a thicker top border marks the boundary since there's no gap between them. */
.expenditure-totals-row-income td {
    border-top: 3px solid var(--border-strong);
}

/* Automatic Income − Expenses row, pinned at the very bottom. */
.expenditure-balance-row td {
    border-top: 3px solid var(--accent);
}

.expenditure-balance-row .positive,
.expenditure-balance-row .table-subline.positive {
    color: var(--positive);
}

.expenditure-balance-row .negative,
.expenditure-balance-row .table-subline.negative {
    color: var(--negative);
}

.expenditure-cell:hover {
    background: var(--surface-sunken);
}

.expenditure-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    font-size: 24px;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--text-secondary);
    transition: transform 0.1s;
}

.expenditure-toggle-collapsed {
    transform: rotate(-90deg);
}

.expenditure-toggle-spacer {
    display: inline-block;
    width: 32px;
}

.expenditure-category-name {
    margin-left: 4px;
}

.expenditure-category-name.expenditure-budget-negative {
    color: var(--negative);
}

.expenditure-note-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    margin-left: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    color: var(--text-inverse);
    font-size: 11px;
    font-style: italic;
    font-weight: bold;
    line-height: 1;
    vertical-align: middle;
    cursor: pointer;
}

.expenditure-drag-handle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    cursor: grab;
    color: var(--text-secondary);
    letter-spacing: -3px;
    user-select: none;
}

.expenditure-row-dragging {
    opacity: 0.4;
}

.expenditure-row-drop-before td {
    box-shadow: inset 0 2px 0 var(--accent);
}

.expenditure-row-drop-after td {
    box-shadow: inset 0 -2px 0 var(--accent);
}

.expenditure-row-menu {
    position: relative;
    display: inline-block;
    margin-right: 8px;
    vertical-align: middle;
}

.expenditure-row-menu-btn {
    font-weight: var(--weight-bold);
}

/* Positioned via JS (fixed, top/left computed from the button's
   bounding rect) and reparented to <body> while open -- the tree column
   is `position: sticky`, which creates its own stacking context, so an
   absolutely-positioned dropdown nested inside it would be painted behind
   any later row's sticky cell no matter its z-index. */
.expenditure-row-menu-dropdown {
    display: none;
    position: fixed;
    min-width: 170px;
    background: var(--surface-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    padding: 4px;
    z-index: var(--z-dropdown);
    box-shadow: var(--shadow-lg);
}

.expenditure-row-menu-dropdown.is-open {
    display: block;
}

.expenditure-row-menu-dropdown .expenditure-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 8px 12px;
    font-size: var(--text-sm);
    font-weight: normal;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.expenditure-row-menu-dropdown .expenditure-menu-item:hover {
    background: var(--surface-sunken);
}

.expenditure-row-menu-dropdown .expenditure-menu-item-danger {
    color: var(--negative);
}

.expenditure-tabs {
    display: flex;
    gap: var(--space-2);
    margin-top: var(--space-3);
}

.expenditure-tab-btn.is-active {
    background: var(--accent);
    color: var(--text-inverse);
    border-color: transparent;
}

.expenditure-table-scroll {
    overflow-x: auto;
    margin-top: var(--space-3);
}

.expenditure-cell-detail-close {
    justify-content: flex-end;
    margin-top: var(--space-4);
}

.expenditure-formula-builder {
    margin-top: var(--space-4);
    padding: var(--space-3);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: var(--surface-sunken);
}

.expenditure-formula-builder.is-disabled {
    opacity: 0.6;
}

.expenditure-formula-header {
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.expenditure-formula-disabled-hint {
    margin: var(--space-2) 0 0;
}

.expenditure-formula-tokens {
    line-height: 1.9;
    min-height: 76px;
    max-height: 200px;
    overflow-y: auto;
    margin-top: var(--space-2);
    padding: 8px 10px;
    background: var(--surface-page);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    font-size: var(--text-sm);
    white-space: pre-wrap;
    word-break: break-word;
    cursor: text;
    outline: none;
}

.expenditure-formula-tokens.is-empty::before {
    content: attr(data-placeholder);
    font-size: var(--text-xs);
    font-style: italic;
    color: var(--text-muted);
}

.expenditure-formula-token-ref {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    border: 1px solid var(--accent);
    color: var(--accent);
    font-weight: var(--weight-semibold);
    font-size: var(--text-sm);
    white-space: nowrap;
}

.expenditure-formula-preview {
    margin-top: var(--space-2);
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    min-height: 18px;
}

.expenditure-formula-preview-error {
    color: var(--negative);
    font-weight: normal;
}

.expenditure-formula-preview-warning {
    color: #b45309;
}

.expenditure-formula-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-top: var(--space-3);
}

.expenditure-formula-op-btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-page);
    font-size: var(--text-base);
    cursor: pointer;
}

.expenditure-formula-op-btn:hover:not([disabled]) {
    background: var(--surface-sunken);
}

.expenditure-formula-picker {
    margin-top: var(--space-3);
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    background: var(--surface-page);
}

.expenditure-formula-picker-group {
    padding: 4px 0;
}

.expenditure-formula-picker-group:not(:last-child) {
    border-bottom: 1px solid var(--border-default);
}

.expenditure-formula-picker-heading {
    padding: 4px 10px;
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.expenditure-formula-picker-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
    padding: 6px 10px;
    border: none;
    background: none;
    text-align: left;
    font-size: var(--text-sm);
    cursor: pointer;
}

.expenditure-formula-picker-row:hover:not([disabled]) {
    background: var(--surface-sunken);
}

.expenditure-formula-picker-row-label {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.expenditure-formula-picker-row-budget {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: var(--text-xs);
    font-variant-numeric: tabular-nums;
    color: var(--text-secondary);
    white-space: nowrap;
}

.expenditure-formula-picker-row-total {
    font-weight: var(--weight-semibold);
    color: var(--accent);
}

.expenditure-formula-picker-fx {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 1px 4px;
    border-radius: 3px;
    background: var(--accent);
    color: var(--text-inverse);
    font-size: 9px;
    font-style: italic;
    font-weight: var(--weight-semibold);
    line-height: 1.4;
    cursor: help;
}

.expenditure-budget-rollup {
    font-style: italic;
}

.expenditure-sum-rollup {
    font-style: italic;
    cursor: help;
}

.expenditure-formula-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    margin-left: 4px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--text-inverse);
    font-size: 10px;
    font-style: italic;
    line-height: 1;
    vertical-align: middle;
    cursor: help;
}

.expenditure-formula-error {
    color: var(--negative);
    margin-right: 4px;
    cursor: help;
}

.expenditure-formula-warning {
    color: #b45309;
    cursor: help;
}

.expenditure-formula-warning-text {
    font-size: var(--text-xs);
    color: #b45309;
    margin: 4px 0 0;
}

/* Bank balance update wizard */
.wizard-progress {
    margin-bottom: var(--space-5);
}

.wizard-progress-bar {
    height: 6px;
    background: var(--surface-sunken);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.wizard-progress-bar span {
    display: block;
    height: 100%;
    width: 0;
    background: var(--accent);
    transition: width 0.2s ease;
}

.wizard-progress-text {
    margin-top: var(--space-2);
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.wizard-group {
    margin-bottom: var(--space-4);
}

.wizard-group-bank {
    font-size: var(--text-lg);
    font-weight: 600;
}

.wizard-group-kind,
.wizard-group-owner {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

.wizard-group-count {
    display: inline-block;
    margin-left: 6px;
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    background: var(--surface-sunken);
    border: 1px solid var(--border-default);
    font-size: var(--text-xs);
}

.wizard-account-owner {
    font-weight: 600;
}

.wizard-card {
    max-width: 520px;
    padding: var(--space-5);
    background: var(--surface-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
}

.wizard-account {
    margin-bottom: var(--space-4);
}

.wizard-account-label {
    font-weight: 600;
}

.wizard-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: var(--text-xs);
    color: var(--text-secondary);
    margin-bottom: var(--space-4);
}

.wizard-cards {
    margin-bottom: var(--space-4);
}

.wizard-cards h4 {
    margin: 0 0 var(--space-2);
    font-size: var(--text-sm);
}

.wizard-card-row {
    display: flex;
    align-items: flex-end;
    gap: var(--space-4);
    padding: var(--space-3) 0;
    border-top: 1px solid var(--border-default);
}

.wizard-card-row .wizard-field {
    margin-bottom: 0;
    flex: 1;
}

.wizard-card-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 120px;
}

.wizard-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    justify-content: flex-end;
}

.wizard-actions-start {
    justify-content: flex-start;
    margin-bottom: var(--space-3);
}

.wizard-last-date {
    font-size: var(--text-xl);
    font-weight: 600;
    margin-bottom: var(--space-4);
}

/* Fund update wizard: wider card (it holds a transaction table) plus the
   figure summary, cash and inline add/edit form blocks. */
#fund-wizard .wizard-card {
    max-width: 900px;
}

.wizard-figures {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    padding: var(--space-3) 0;
    border-top: 1px solid var(--border-default);
    border-bottom: 1px solid var(--border-default);
}

.wizard-figures > div {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.wizard-cash-row {
    margin-bottom: var(--space-3);
}

.wizard-manual,
.wizard-transactions {
    margin-bottom: var(--space-4);
}

.wizard-manual h4,
.wizard-transactions h4 {
    margin: 0 0 var(--space-2);
    font-size: var(--text-sm);
}

.wizard-txn-table,
.wizard-history-table {
    margin: var(--space-2) 0 var(--space-3);
}

.wizard-txn-edit-row td {
    background: var(--surface-sunken);
}

.wizard-add-form {
    margin-top: var(--space-3);
    padding: var(--space-4);
    background: var(--surface-sunken);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
}

.wizard-done {
    max-width: 520px;
    padding: var(--space-5);
    background: var(--surface-card);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    align-items: flex-start;
}
