/* ═══════════════════════════════════════════════════════════════
   UTILITY CLASSES
   ═══════════════════════════════════════════════════════════════ */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    z-index: 1000;
    padding: 8px 16px;
    background: var(--primary-color);
    color: #fff;
    font-weight: 600;
    text-decoration: none;
    border-radius: 0 0 6px 0;
}
.skip-link:focus {
    top: 0;
}

/* Respect OS-level reduced-motion preference: shrink all CSS transitions/
   animations (confetti, toasts, accordion toggles, hover effects, etc.) down
   to effectively instant rather than disabling them outright, which keeps
   end-state styles correct without relying on per-component opt-outs. */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Inline styles extracted for CSP compliance */
.target-date-flex-row {
    display: flex;
    align-items: flex-end;
    padding-bottom: 2px;
    flex-basis: 100%;
    margin-top: 8px;
}

.export-margin-top {
    margin-top: 16px;
}

.export-amortization-margin {
    margin-top: 18px;
}

.amortization-modal-fixed {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.45);
    z-index: 10001;
    align-items: center;
    justify-content: center;
}

.amortization-modal-fixed.flex-visible {
    display: flex !important;
}

.amortization-modal-content {
    background: white;
    max-width: 95vw;
    max-height: 90vh;
    overflow: auto;
    border-radius: 12px;
    padding: 32px 24px;
    margin: auto;
    position: relative;
    outline: 0;
}

.amortization-close-btn {
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
}

.help-icon {
    display: inline-block;
    background: #eee;
    color: #333;
    border-radius: 50%;
    width: 1.2em;
    height: 1.2em;
    text-align: center;
    font-size: 0.9em;
    cursor: pointer;
    margin-left: 4px;
}

.help-icon:focus,
.help-icon:hover {
    background: #2563eb;
    color: #fff;
    outline: 2px solid #2563eb;
}

/* CSP-Compliant Display Utilities */
.hidden {
    display: none !important;
}

.visible {
    display: block !important;
}

.flex-visible {
    display: flex !important;
}

.inline-visible {
    display: inline-block !important;
}

.cursor-pointer {
    cursor: pointer;
}

/* Modal Overlay & Content */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.45);
    z-index: 10002;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-overlay[id="ledgerOverrideModal"] {
    z-index: 10003;
}

.modal-content {
    background: var(--bg-secondary, #ffffff);
    color: var(--text-primary, #1e293b);
    max-width: 460px;
    width: 92%;
    border-radius: 12px;
    padding: 28px 24px;
    margin: auto;
    position: relative;
    outline: 0;
    max-height: 90vh;
    overflow-y: auto;
}

#ledgerOverrideModal .modal-content {
    max-width: 440px;
    padding: 26px 22px;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 1.5rem;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-primary, #1e293b);
}

.modal-subtitle {
    margin: 4px 0 14px;
}

.modal-description {
    margin: 6px 0 10px;
    color: var(--text-secondary, #6b7280);
}

.modal-tx-name {
    margin: 0 0 6px;
    font-size: 0.9rem;
}

.modal-helper-text {
    font-size: 0.78rem;
    color: var(--text-secondary, #6b7280);
    margin-bottom: 4px;
}

.modal-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.modal-form-grid .form-group {
    margin: 0;
}

@media (max-width: 480px) {
    .modal-form-grid {
        grid-template-columns: 1fr;
    }
}

.modal-form-group {
    margin: 0 0 12px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

#ledgerOverrideModal .modal-actions {
    margin-top: 18px;
}

/* Inline Style Replacements - CSP Compliance */
.logo-icon {
    vertical-align: middle;
    display: inline-block;
    width: 1.5em;
    height: 1.5em;
    margin-right: 0.3em;
}

.logo-svg {
    display: inline;
    vertical-align: middle;
}

.fixed-amount-fields {
    display: none;
}

.fixed-end-date-container {
    display: none;
}

.cancel-edit-btn {
    display: none;
}

.form-group.no-margin {
    margin: 0;
}

.form-group-no-margin {
    margin: 0;
}

.form-group-flex-1 {
    flex: 1;
    min-width: 160px;
}

.category-filter-label {
    font-weight: 600;
    font-size: 0.875rem;
}

.category-filter {
    margin-left: 6px;
    min-width: 120px;
}

.category-summary {
    margin: 18px 0 0 0;
}

.income-summary {
    display: none;
}

.cashflow-summary {
    display: none;
}

.strategy-income-widget {
    display: none;
}

.submit-button-margin {
    margin-top: 14px;
}

.heading-no-margin {
    margin-top: 0;
}

.liabilities-panel-visible {
    display: block;
}

.liabilities-panel-hidden {
    display: none;
}

/* ═══════════════════════════════════════════════════════════════
   LEDGER PAGE & TABLE
   ═══════════════════════════════════════════════════════════════ */
.ledger-section {
    background: var(--card-bg, #fff);
    border-radius: 12px;
    box-shadow: 0 1px 6px rgba(0,0,0,0.07);
    padding: 28px 24px 32px 24px;
    margin-bottom: 40px;
}
.ledger-section h2 {
    color: var(--primary-color);
    font-size: 1.4rem;
    margin-bottom: 18px;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 8px;
}
#ledgerTableContainer {
    margin-top: 18px;
}
.filter-controls {
    position: sticky;
    top: 0;
    z-index: 10;
    background: #fff;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px 0 12px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.filter-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary, #6b7280);
    white-space: nowrap;
}
.filter-active-badge {
    display: inline-flex;
    align-items: center;
    background: var(--primary-color, #2563eb);
    color: #fff;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 2px 9px;
    white-space: nowrap;
}
.ledger-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--card-bg, #fff);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
    font-size: 1rem;
    margin-bottom: 0;
}
.ledger-table thead {
    background: var(--primary-color);
    color: #fff;
}
.ledger-table th {
    padding: 14px 12px;
    font-weight: 700;
    text-align: left;
    border-bottom: 2px solid var(--border-color);
    cursor: pointer;
    user-select: none;
    background: var(--primary-color);
    color: #fff;
    font-size: 1.02rem;
}
.ledger-table th:hover {
    background: #1d4ed8;
}
.ledger-table td {
    padding: 13px 12px;
    border-bottom: 1px solid var(--border-color);
    background: transparent;
    font-size: 0.98rem;
    color: var(--text-primary);
}
.ledger-table tbody tr:hover {
    background: #f3f4f6;
}
.ledger-table tr:last-child td {
    border-bottom: none;
}
.ledger-table td {
    transition: background 0.15s;
}
.ledger-table td[style*="color:#dc2626"] {
    font-weight: 600;
}
.ledger-table td[style*="color:#059669"] {
    font-weight: 600;
}

.ledger-override-actions {
    margin-top: 6px;
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.ledger-override-btn,
.ledger-override-clear-btn {
    border: 1px solid var(--border-color);
    background: var(--card-bg, #fff);
    color: var(--text-primary);
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 0.76rem;
    font-weight: 600;
    cursor: pointer;
}

.ledger-override-btn:hover,
.ledger-override-clear-btn:hover {
    border-color: #93c5fd;
    background: #eff6ff;
}

.ledger-amount-stack {
    display: inline-flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.2;
}

.ledger-amount-effective {
    font-weight: 700;
}

.ledger-amount-original {
    font-size: 0.75rem;
    opacity: 0.72;
    text-decoration: line-through;
}

.ledger-pagination {
    margin-top: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.ledger-page-summary {
    font-size: 0.92rem;
    color: var(--text-secondary);
}

.ledger-page-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ledger-page-info {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-primary);
}

.ledger-page-btn {
    border: 1px solid var(--border-color);
    background: var(--card-bg, #fff);
    color: var(--text-primary);
    border-radius: 7px;
    padding: 6px 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.ledger-page-btn:hover:not(:disabled) {
    background: #eff6ff;
    border-color: #bfdbfe;
}

.ledger-page-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

body.dark-mode .ledger-section {
    background: #1e293b;
    box-shadow: 0 1px 8px rgba(0,0,0,0.18);
}
body.dark-mode .filter-controls {
    background: #1e293b;
    border-bottom-color: #374151;
}
body.dark-mode .filter-label {
    color: #94a3b8;
}
body.dark-mode .ledger-section h2 {
    color: #60a5fa;
    border-bottom-color: #60a5fa;
}
body.dark-mode .ledger-table {
    background: #1e293b;
    color: #f1f5f9;
    box-shadow: 0 1px 8px rgba(0,0,0,0.28);
}
body.dark-mode .ledger-table thead {
    background: #2563eb;
    color: #fff;
}
body.dark-mode .ledger-table th {
    background: #2563eb;
    color: #fff;
    border-bottom-color: #334155;
}
body.dark-mode .ledger-table th:hover {
    background: #1e40af;
}
body.dark-mode .ledger-table td {
    border-bottom-color: #334155;
    color: #f1f5f9;
}
body.dark-mode .ledger-table tbody tr:hover {
    background: #334155;
}

body.dark-mode .ledger-page-summary {
    color: #94a3b8;
}

body.dark-mode .ledger-page-info {
    color: #f1f5f9;
}

body.dark-mode .ledger-page-btn {
    background: #1e293b;
    color: #f1f5f9;
    border-color: #334155;
}

body.dark-mode .ledger-page-btn:hover:not(:disabled) {
    background: #334155;
    border-color: #475569;
}

body.dark-mode .ledger-override-btn,
body.dark-mode .ledger-override-clear-btn {
    background: #1e293b;
    color: #e2e8f0;
    border-color: #334155;
}

body.dark-mode .ledger-override-btn:hover,
body.dark-mode .ledger-override-clear-btn:hover {
    background: #334155;
    border-color: #60a5fa;
}

/* Dark mode for amortization modal */
body.dark-mode .amortization-modal-content {
    background: #1e293b;
    color: #f1f5f9;
}

body.dark-mode .amortization-modal-content h3 {
    color: #f1f5f9;
}

body.dark-mode .amortization-modal-content table {
    background: #1e293b;
    color: #f1f5f9;
}

body.dark-mode .amortization-modal-content thead {
    background: #2563eb;
}

body.dark-mode .amortization-modal-content th {
    background: #2563eb;
    color: #fff;
    border-bottom-color: #334155;
}

body.dark-mode .amortization-modal-content td {
    border-bottom-color: #334155;
    color: #f1f5f9;
}

/* ═══════════════════════════════════════════════════════════════
   REPORTS MONTH SELECTOR (pagination)
   ═══════════════════════════════════════════════════════════════ */
.rpt-month-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin: 0 0 18px 0;
    background: var(--card-bg, #fff);
    border-radius: 8px;
    border: 1.5px solid var(--border-color, #e5e7eb);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    padding: 7px 18px;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
}
.rpt-month-btn {
    background: var(--primary-color, #2563eb);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 1.25rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.rpt-month-btn:hover, .rpt-month-btn:focus {
    background: #1e40af;
    color: #fff;
    outline: 2px solid #2563eb;
}
.rpt-print-btn {
    width: auto;
    height: 32px;
    border-radius: 6px;
    padding: 0 14px;
    font-size: 0.85rem;
    font-weight: 600;
    gap: 6px;
    margin-left: 4px;
}
.rpt-month-label {
    font-size: 1.08rem;
    font-weight: 600;
    color: var(--primary-color, #2563eb);
    letter-spacing: 0.01em;
    min-width: 120px;
    text-align: center;
    user-select: none;
}
body.dark-mode .rpt-month-nav {
    background: #1e293b;
    border-color: #334155;
    box-shadow: 0 1px 3px rgba(0,0,0,0.18);
}
body.dark-mode .rpt-month-btn {
    background: #2563eb;
    color: #fff;
}
body.dark-mode .rpt-month-btn:hover, body.dark-mode .rpt-month-btn:focus {
    background: #1e40af;
    color: #fff;
    outline: 2px solid #2563eb;
}

/* ── Per-page print button (Health, Accounts, Income) ──────────────────── */
.page-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.page-print-btn {
    background: var(--primary-color, #2563eb);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    transition: background 0.15s, color 0.15s;
}
.page-print-btn:hover, .page-print-btn:focus {
    background: #1e40af;
    color: #fff;
    outline: 2px solid #2563eb;
}
@media (max-width: 768px) {
    .page-print-btn {
        min-height: 44px;
        min-width: 44px;
    }
}
body.dark-mode .page-print-btn {
    background: #2563eb;
    color: #fff;
}
body.dark-mode .page-print-btn:hover, body.dark-mode .page-print-btn:focus {
    background: #1e40af;
    color: #fff;
    outline: 2px solid #2563eb;
}
body.dark-mode .rpt-month-label {
    color: #60a5fa;
}
/* Visually hidden for accessibility */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    border: 0;
}

/* Form field visibility for debt type switching */
.fixed-amount-field {
    display: none;
}

.credit-card-field {
    display: block;
}

/* Help icon styling */
.help-icon {
    display: inline-block;
    background: #eee;
    color: #333;
    border-radius: 50%;
    width: 1.2em;
    height: 1.2em;
    text-align: center;
    font-size: 0.9em;
    cursor: pointer;
    margin-left: 4px;
    line-height: 1.2em;
    vertical-align: middle;
    border: 1px solid #ccc;
}
.help-icon:focus, .help-icon:hover {
    background: var(--primary-color);
    color: #fff;
    outline: 2px solid var(--primary-color);
}

/* Dark mode styles */
body.dark-mode {
    background: linear-gradient(135deg, #232526 0%, #414345 100%);
    color: #f1f5f9;

    /* ── Override all CSS custom properties for dark mode ── */
    --light-bg: #1e293b;
    --primary-hsl: 213 93% 68%;
    --border-color: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #94a3b8;
    --card-bg: #1e293b;
    --text-color: #f1f5f9;
    --bg-color: #0f172a;
    --table-header-bg: #0f172a;
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --shadow: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.5);
}
body.dark-mode .container {
    background: #23272f;
    color: #f1f5f9;
}
body.dark-mode header {
    background: linear-gradient(135deg, #111827 0%, #1e293b 100%);
    color: #f1f5f9;
}
body.dark-mode input, body.dark-mode select, body.dark-mode textarea {
    background: #1e293b;
    color: #f1f5f9;
    border-color: #334155;
    color-scheme: dark;
}
body.dark-mode .btn {
    background: #334155;
    color: #f1f5f9;
    border-color: #475569;
}
body.dark-mode .btn:hover {
    background: #475569;
}
body.dark-mode .help-icon {
    background: #334155;
    color: #f1f5f9;
    border-color: #475569;
}
body.dark-mode .help-icon:focus, body.dark-mode .help-icon:hover {
    background: #2563eb;
    color: #fff;
}

/* ── Tables ── */
body.dark-mode table {
    background: #1e293b;
    color: #f1f5f9;
}
body.dark-mode td {
    border-bottom-color: #334155;
    color: #f1f5f9;
}
body.dark-mode th {
    border-bottom-color: #334155;
}
body.dark-mode tbody tr:last-child td {
    border-bottom: none;
}
body.dark-mode .amount {
    color: #f1f5f9;
}
body.dark-mode .amount small {
    color: #34d399;
}
body.dark-mode .balance {
    color: #93c5fd;
}

/* ── Section headings ── */
body.dark-mode section h2 {
    color: #f1f5f9;
}
body.dark-mode section h3 {
    color: #f1f5f9;
}

/* ── Tab buttons ── */
body.dark-mode .tab-button {
    color: #94a3b8;
}
body.dark-mode .tab-button:hover,
body.dark-mode .tab-button.active {
    color: #93c5fd;
    border-bottom-color: #93c5fd;
}

/* ── Edit button ── */
body.dark-mode .btn-edit {
    background: #334155;
    color: #f1f5f9;
    border-color: #475569;
}
body.dark-mode .btn-edit:hover {
    background: #1e3a5f;
    border-color: #93c5fd;
}

/* ── Progress bars ── */
body.dark-mode .debt-progress-bar,
body.dark-mode .summary-progress-bar {
    background: #334155;
}
body.dark-mode .debt-progress-label,
body.dark-mode .summary-progress-label {
    color: #94a3b8;
}

/* ── Calendar cell states ── */
body.dark-mode .cal-cell.cal-has-events {
    background: #1e3a5f;
    border-color: #1d4ed8;
}
body.dark-mode .cal-cell.cal-has-events .cal-day-num {
    color: #93c5fd;
}
body.dark-mode .cal-day-label {
    color: #64748b;
}

/* ── Comparison table best row ── */
body.dark-mode .comparison-table tr.comparison-best td {
    color: #86efac;
}

/* ── Input validation ── */
body.dark-mode .input-error {
    background: #3b0f0f !important;
    border-color: #f87171 !important;
}

/* ── Chart containers ── */
body.dark-mode .chart-container {
    background: #1e293b;
}

/* ── Inline edit form on debt card ── */
body.dark-mode .debt-edit-form,
body.dark-mode .debt-edit-form input,
body.dark-mode .debt-edit-form select {
    background: #0f172a;
    color: #f1f5f9;
    border-color: #334155;
}

/* ── Summary stats ── */
body.dark-mode .summary-item .label {
    color: #94a3b8;
}
body.dark-mode .summary-item .value {
    color: #93c5fd;
}
body.dark-mode .summary-item--alert .value,
body.dark-mode #monthlyInterestCostValue {
    color: #f87171;
}

/* ── Category summary / filter ── */
body.dark-mode .category-summary,
body.dark-mode #categorySummary {
    color: #94a3b8;
}

/* ── Misc muted text ── */
body.dark-mode .whatif-desc,
body.dark-mode .whatif-hint,
body.dark-mode .whatif-slider-cap,
body.dark-mode .whatif-metric-label,
body.dark-mode .target-date-desc,
body.dark-mode .target-result-meta,
body.dark-mode .income-card-detail {
    color: #94a3b8;
}
body.dark-mode .whatif-metric-val {
    color: #f1f5f9;
}
body.dark-mode .cal-page-label {
    color: #94a3b8;
}
/* Input validation error styling */
.input-error {
    border-color: var(--danger-color) !important;
    background: #fff0f0 !important;
}
.input-error:focus {
    outline: 2px solid var(--danger-color);
}
.error-message {
    color: var(--danger-color);
    font-size: 0.95em;
    margin-top: 2px;
    margin-bottom: 8px;
}
.stimulus-input-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

.stimulus-input-wrapper label {
    margin-bottom: 0;
}
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #2563eb;
    --primary-hsl: 217 89% 61%;
    --primary-hover: #1d4ed8;
    --success-color: #16a34a;
    --success-hover: #15803d;
    --success-active: #166534;
    --danger-color: #dc2626;
    --danger-hover: #b91c1c;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --light-bg: #f8fafc;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #64748b;
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* ═══════════════════════════════════════════════════════════════════════════
   HIGH CONTRAST THEME (GitHub issue #33)
   Applied together with .dark-mode (both classes on <body>, set by
   applyTheme() in src/ui.js) so it inherits dark-mode's surface colors and
   the JS chart/gauge color logic that already branches on `dark-mode`, then
   overrides the shared CSS custom properties plus the specific hardcoded-
   color spots already known to be low-contrast (WCAG AA 4.5:1 minimum;
   values below are chosen to also clear AAA's 7:1 against pure black/white)
   for a pure black/white/bright-accent look with no gradients or shadows.
   Selectors use the compound `body.dark-mode.high-contrast-mode` class pair
   so specificity always wins over the single-class `body.dark-mode` rules
   regardless of source order in this file.

   Scope note: this overrides the ~20 shared CSS custom properties and the
   handful of known trouble spots below, so anything already using var() is
   covered automatically. The few hundred other `body.dark-mode .foo {}`
   rules elsewhere in this file that hardcode dark-mode's own palette
   directly (not through variables) are NOT individually re-themed here -
   those inherit dark mode's existing (generally reasonable) contrast rather
   than getting a bespoke high-contrast pass. ═══════════════════════════════════════════════════════════════════════════ */

body.dark-mode.high-contrast-mode {
    background: #000000;
    color: #ffffff;

    --primary-color: #66b3ff;
    --primary-hsl: 210 100% 70%;
    --primary-hover: #99ccff;
    --success-color: #22ff88;
    --success-hover: #66ffaa;
    --success-active: #66ffaa;
    --danger-color: #ff6b6b;
    --danger-hover: #ff9999;
    --secondary-color: #d4d4d4;
    --secondary-hover: #ffffff;
    --light-bg: #000000;
    --border-color: #ffffff;
    --text-primary: #ffffff;
    --text-secondary: #ffffff;
    --text-muted: #d4d4d4;
    --card-bg: #000000;
    --text-color: #ffffff;
    --bg-color: #000000;
    --table-header-bg: #000000;
    --bg-primary: #000000;
    --bg-secondary: #111111;
    --shadow: none;
    --shadow-lg: none;
}

/* Every focusable element gets one bold, consistent focus ring instead of
   relying on each component's own (often subtle) focus styling. */
body.dark-mode.high-contrast-mode *:focus-visible {
    outline: 3px solid #ffd60a;
    outline-offset: 2px;
}

body.dark-mode.high-contrast-mode .container {
    background: #000000;
    border: 2px solid #ffffff;
}

body.dark-mode.high-contrast-mode header {
    background: #000000;
    border-bottom: 2px solid #ffffff;
}

body.dark-mode.high-contrast-mode .login-gate {
    background: #000000;
}

body.dark-mode.high-contrast-mode .login-gate-header {
    background: #000000;
    border-bottom: 2px solid #ffffff;
}

body.dark-mode.high-contrast-mode .top-nav {
    background: #000000;
    border-top: 2px solid #ffffff;
}

body.dark-mode.high-contrast-mode .header-icon-btn {
    color: #ffffff;
}

body.dark-mode.high-contrast-mode .header-icon-btn:hover {
    background: rgba(255,255,255,0.25);
    color: #ffffff;
}

body.dark-mode.high-contrast-mode .page-button {
    color: #ffffff;
}

body.dark-mode.high-contrast-mode .page-button.active {
    color: #ffffff;
    border-bottom-color: #ffd60a;
    border-bottom-width: 3px;
}

body.dark-mode.high-contrast-mode input,
body.dark-mode.high-contrast-mode select,
body.dark-mode.high-contrast-mode textarea {
    background: #000000;
    color: #ffffff;
    border: 2px solid #ffffff;
}

body.dark-mode.high-contrast-mode table {
    background: #000000;
    color: #ffffff;
}

body.dark-mode.high-contrast-mode td,
body.dark-mode.high-contrast-mode th {
    border-bottom-color: #ffffff;
    color: #ffffff;
}

/* Outline-style buttons: a shared black background + colored border/text
   per variant, rather than trying to find a text color that stays readable
   on every bright fill color a .btn-* class might use as its background. */
body.dark-mode.high-contrast-mode .btn,
body.dark-mode.high-contrast-mode .btn-primary,
body.dark-mode.high-contrast-mode .btn-success,
body.dark-mode.high-contrast-mode .btn-danger,
body.dark-mode.high-contrast-mode .btn-secondary {
    background: #000000;
    border: 2px solid currentColor;
}

body.dark-mode.high-contrast-mode .btn-primary { color: #66b3ff; }
body.dark-mode.high-contrast-mode .btn-success { color: #22ff88; }
body.dark-mode.high-contrast-mode .btn-danger { color: #ff6b6b; }
body.dark-mode.high-contrast-mode .btn-secondary,
body.dark-mode.high-contrast-mode .btn { color: #ffffff; }

body.dark-mode.high-contrast-mode .btn:hover,
body.dark-mode.high-contrast-mode .btn-primary:hover,
body.dark-mode.high-contrast-mode .btn-success:hover,
body.dark-mode.high-contrast-mode .btn-danger:hover,
body.dark-mode.high-contrast-mode .btn-secondary:hover {
    background: #1a1a1a;
}

/* Calendar event/payday pills: per-debt colors (--event-bg) come from a
   fixed palette (src/strategy.js) that isn't guaranteed to pass 4.5:1 with
   white text (WCAG 1.4.3; see docs/audit/a11y/A11Y_AUDIT_REPORT.md S3). In
   high contrast mode the color-coding moves to the left border accent and
   the fill goes to solid black with solid white text, so legibility never
   depends on which palette color a given debt was assigned. */
body.dark-mode.high-contrast-mode .cal-event,
body.dark-mode.high-contrast-mode .cal-income-event,
body.dark-mode.high-contrast-mode .cal-bill-event,
body.dark-mode.high-contrast-mode .cal-expense-event,
body.dark-mode.high-contrast-mode .cal-bonus-event {
    background: #000000;
    color: #ffffff;
    border: 1px solid #ffffff;
    border-left: 3px solid var(--event-bg, #ffffff);
}

body.dark-mode.high-contrast-mode .app-footer {
    color: #ffffff;
    border-top-color: #ffffff;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--text-primary);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* ── Installed PWA: fill the window edge-to-edge instead of floating a
   centered card on the gradient backdrop, which reads as a website, not
   an app, in a standalone window ─────────────────────────────────────── */
@media (display-mode: standalone) {
    body {
        background: white;
        padding: 0;
    }

    body.dark-mode {
        background: #23272f;
    }

    .container {
        max-width: none;
        width: 100%;
        margin: 0;
        border-radius: 0;
        box-shadow: none;
        overflow: visible;
    }
}

header {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: white;
    display: flex;
    flex-direction: column;
}

/* ── Top bar: toolbar pinned to the right ──────────────────────────── */
.header-top {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding: 6px 10px 0;
}

.header-toolbar {
    display: flex;
    gap: 2px;
    align-items: center;
}

.header-toolbar-divider {
    width: 1px;
    height: 16px;
    background: rgba(255,255,255,0.20);
    margin: 0 4px;
}

/* Icon-only toolbar buttons */
.header-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: rgba(255,255,255,0.80);
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
    text-decoration: none;
}

.header-icon-btn:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
}

.header-icon-btn svg {
    display: block;
    flex-shrink: 0;
}

body.dark-mode .header-icon-btn {
    color: rgba(255,255,255,0.70);
}

body.dark-mode .header-icon-btn:hover {
    background: rgba(255,255,255,0.12);
    color: #fff;
}

/* Keep old class names harmless if referenced elsewhere */
.header-toolbar-btn { display: none; }

body.dark-mode .top-nav {
    background: rgba(0,0,0,0.30);
    border-top-color: rgba(255,255,255,0.08);
}

body.dark-mode .page-button {
    color: rgba(255,255,255,0.60);
}

body.dark-mode .page-button:hover {
    color: #fff;
    background: rgba(255,255,255,0.06);
}

body.dark-mode .page-button:focus-visible {
    outline-color: rgba(255,255,255,0.70);
}

body.dark-mode .page-button.active {
    color: #fff;
    border-bottom-color: #93c5fd;
}

/* ── Hero: centred title + subtitle ───────────────────────────────── */
.header-hero {
    text-align: center;
    padding: 20px 20px 8px;
}

header h1 {
    font-size: 2.5rem;
    margin-bottom: 8px;
}

header p {
    font-size: 1.1rem;
    opacity: 0.9;
    margin: 0;
}

.top-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    gap: 8px;
    padding: 6px 16px;
    margin-top: 12px;
    background: rgba(0,0,0,0.18);
    border-top: 1px solid rgba(255,255,255,0.10);
    position: relative;
}

.nav-toggle {
    display: none;
}

.nav-menu {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-end;
    gap: 8px;
}

.nav-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.nav-group-label {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 999px;
    /* A dark badge with near-opaque text (rather than translucent-white-on-
       translucent-white) so contrast doesn't depend on the unpredictable
       header gradient behind it - composited against both the light and
       dark header gradients this measures ~6.8:1 / ~12.7:1 (was ~2.9:1 in
       light mode; WCAG 1.4.3 needs 4.5:1). See GitHub issue #33. */
    background: rgba(0,0,0,0.25);
    color: rgba(255,255,255,0.82);
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.nav-group:has(.page-button.active) .nav-group-label {
    background: rgba(255,255,255,0.90);
    color: #1e40af;
}

.nav-group-btns {
    display: flex;
    gap: 2px;
}

.page-button {
    padding: 6px 11px;
    border-radius: 4px;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: rgba(255,255,255,0.65);
    cursor: pointer;
    font-weight: 600;
    font-size: 11px;
    letter-spacing: 0.02em;
    white-space: nowrap;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.page-button:hover {
    color: #fff;
    background: rgba(255,255,255,0.10);
    border-bottom-color: rgba(255,255,255,0.40);
}

.page-button:focus-visible {
    outline: 2px solid rgba(255,255,255,0.80);
    outline-offset: 2px;
}

.page-button.active {
    color: #fff;
    background: rgba(255,255,255,0.15);
    border-bottom: 2px solid #fff;
}

.nav-group-sep {
    width: 1px;
    height: 30px;
    background: rgba(255,255,255,0.18);
    align-self: flex-end;
    margin-bottom: 2px;
    flex-shrink: 0;
}

.page-section { display: none; }
.page-section.active { display: block; }

main {
    padding: 40px 20px;
}

section {
    margin-bottom: 40px;
}

section h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: var(--text-primary);
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 10px;
}

section h3 {
    font-size: 1.2rem;
    margin-top: 30px;
    margin-bottom: 15px;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

/* Tabs */
/* Divider between strategy controls and inline results */
.plan-divider {
    border: none;
    border-top: 2px solid var(--border-color);
    margin: 32px 0 28px;
}

/* ── Results page — outer tab bar ────────────────────────────────────────── */
.results-tab-bar {
    display: flex;
    gap: 0;
    margin: 20px 0 0;
    border-bottom: 2px solid var(--border-color);
    background: var(--card-background);
    border-radius: 10px 10px 0 0;
    overflow: hidden;
}

.results-tab-btn {
    flex: 1;
    padding: 13px 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    border-bottom: 3px solid transparent;
    transition: color 0.2s, border-color 0.2s, background 0.2s;
    margin-bottom: -2px;
}

.results-tab-btn:hover {
    color: var(--primary-color);
    background: rgba(99,102,241,0.05);
}

.results-tab-btn--active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
    background: #f4f4fe;
}

body.dark-mode .results-tab-btn--active {
    color: #60a5fa;
    border-bottom-color: #60a5fa;
    background: #27293d;
}

.results-tab-panel {
    display: none;
    padding: 24px 0 0;
}

.results-tab-panel--active {
    display: block;
}

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 2px solid var(--border-color);
}

.tab-button {
    padding: 12px 20px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    border-bottom: 3px solid transparent;
    transition: all 0.3s ease;
    margin-bottom: -2px;
}

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

.tab-button.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* Chart */
.chart-container {
    position: relative;
    height: 400px;
    margin: 30px 0;
    padding: 20px;
    background: var(--light-bg);
    border-radius: 8px;
}

.chart-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.chart-container--half {
    flex: 1 1 340px;
    min-width: 280px;
    height: 360px;
    margin: 0;
}

/* Calendar View */
#calendarView {
    width: 100%;
    padding: 8px 0;
}

.cal-pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
}

.cal-page-label {
    font-size: 0.9rem;
    color: #6b7280;
    font-weight: 500;
}

.cal-months-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    width: 100%;
}

.cal-month {
    background: var(--card-bg, #fff);
    border-radius: 10px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    padding: 14px 12px 10px;
    min-width: 0;
}

.cal-month-title {
    font-size: 1rem;
    font-weight: 700;
    margin: 0 0 10px 0;
    color: var(--primary, #2563eb);
    text-align: center;
}

.cal-day-labels {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    margin-bottom: 2px;
}

.cal-day-label {
    text-align: center;
    font-size: 0.72rem;
    font-weight: 600;
    color: #9ca3af;
    padding: 2px 0;
}

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.cal-cell {
    min-height: 36px;
    border-radius: 5px;
    padding: 2px 3px;
    font-size: 0.75rem;
    position: relative;
    background: transparent;
}

.cal-cell.cal-has-events {
    background: #f0f7ff;
    border: 1px solid #bfdbfe;
}

.cal-day-num {
    display: block;
    font-size: 0.72rem;
    color: #6b7280;
    font-weight: 500;
    line-height: 1.4;
}

.cal-cell.cal-has-events .cal-day-num {
    color: #1e40af;
    font-weight: 700;
}

.cal-event {
    border-radius: 3px;
    padding: 2px 4px;
    margin-top: 2px;
    color: #fff;
    font-size: 0.68rem;
    line-height: 1.3;
    overflow: hidden;
    cursor: default;
    background: var(--event-bg, #2563eb);
}

.cal-event-name {
    display: block;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-event-amount {
    display: block;
    opacity: 0.92;
}

/* Income payday chip on the calendar — distinct green style */
.cal-income-event {
    border-radius: 3px;
    padding: 2px 4px;
    margin-top: 2px;
    background: #059669;
    color: #fff;
    font-size: 0.68rem;
    line-height: 1.3;
    overflow: hidden;
    cursor: default;
    border-left: 3px solid #047857;
}

body.dark-mode .cal-income-event {
    background: #065f46;
    border-left-color: #059669;
}

/* Bill due chip on the calendar — amber style */
.cal-bill-event {
    border-radius: 3px;
    padding: 2px 4px;
    margin-top: 2px;
    background: #d97706;
    color: #fff;
    font-size: 0.68rem;
    line-height: 1.3;
    overflow: hidden;
    cursor: default;
    border-left: 3px solid #b45309;
}

body.dark-mode .cal-bill-event {
    background: #92400e;
    border-left-color: #d97706;
}

.cal-bill-name {
    display: block;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-bill-amount {
    display: block;
    opacity: 0.9;
}

.cal-income-name {
    display: block;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-income-amount {
    display: block;
    opacity: 0.9;
}

/* Expense budget chip on the calendar — purple style */
.cal-expense-event {
    border-radius: 3px;
    padding: 2px 4px;
    margin-top: 2px;
    background: #7c3aed;
    color: #fff;
    font-size: 0.68rem;
    line-height: 1.3;
    overflow: hidden;
    cursor: default;
    border-left: 3px solid #6d28d9;
}

body.dark-mode .cal-expense-event {
    background: #5b21b6;
    border-left-color: #7c3aed;
}

.cal-expense-name {
    display: block;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-expense-amount {
    display: block;
    opacity: 0.9;
}

/* Bonus chip on the calendar — teal style */
.cal-bonus-event {
    border-radius: 3px;
    padding: 2px 4px;
    margin-top: 2px;
    background: #0891b2;
    color: #fff;
    font-size: 0.68rem;
    line-height: 1.3;
    overflow: hidden;
    cursor: default;
    border-left: 3px solid #0e7490;
}

body.dark-mode .cal-bonus-event {
    background: #155e75;
    border-left-color: #0891b2;
}

.cal-bonus-name {
    display: block;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-bonus-amount {
    display: block;
    opacity: 0.9;
}

/* Calendar legend */
.cal-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 20px;
    margin-bottom: 14px;
    font-size: 0.8rem;
    align-items: center;
}

.cal-legend-item {
    display: flex;
    align-items: center;
    gap: 5px;
    color: var(--text-color);
}

.cal-legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    flex-shrink: 0;
}

.cal-legend-swatch--income {
    background: #059669;
    border-left: 3px solid #047857;
}

.cal-legend-swatch--bill {
    background: #d97706;
    border-left: 3px solid #b45309;
}

.cal-legend-swatch--expense {
    background: #7c3aed;
    border-left: 3px solid #6d28d9;
}

.cal-legend-swatch--bonus {
    background: #0891b2;
    border-left: 3px solid #0e7490;
}

.cal-legend-swatch--today {
    width: 12px;
    height: 12px;
    border-radius: 2px;
    outline: 2px solid #f59e0b;
    outline-offset: -2px;
    flex-shrink: 0;
}

.cal-empty {
    background: transparent;
}

.cal-today {
    outline: 2px solid #f59e0b;
    outline-offset: -2px;
    border-radius: 5px;
}

.cal-today .cal-day-num {
    color: #b45309;
    font-weight: 800;
}

.cal-today::after {
    content: '';
    display: block;
    width: 5px;
    height: 5px;
    background: #f59e0b;
    border-radius: 50%;
    margin: 1px auto 0;
}

body.dark-mode .cal-today {
    outline-color: #fbbf24;
}

body.dark-mode .cal-today .cal-day-num {
    color: #fcd34d;
}

body.dark-mode .cal-month {
    background: #1e293b;
    box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

body.dark-mode .cal-cell.cal-has-events {
    background: #1e3a5f;
    border-color: #3b82f6;
}

body.dark-mode .cal-day-num {
    color: #94a3b8;
}

body.dark-mode .cal-cell.cal-has-events .cal-day-num {
    color: #93c5fd;
}


/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 12px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: all 0.3s ease;
    background: white;
    color: var(--text-primary);
    font-family: inherit;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-block;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-success {
    /* --success-color (#16a34a) only gives 3.3:1 with white text; --success-hover passes 4.5:1 */
    background: var(--success-hover);
    color: white;
}

.btn-success:hover {
    background: var(--success-active);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

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

.btn-danger:hover {
    background: var(--danger-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.btn-secondary {
    background: var(--secondary-color);
    color: white;
}

.btn-secondary:hover {
    background: var(--secondary-hover);
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

/* ═══════════════════════════════════════════════════════════════════════════
   DEBTS PAGE — merged form + list layout
   ═══════════════════════════════════════════════════════════════════════════ */

.debts-layout {
    display: grid;
    grid-template-columns: 380px 1fr;
    gap: 24px;
    align-items: start;
}

@media (max-width: 900px) {
    .debts-layout {
        grid-template-columns: 1fr;
    }
}

/* Form column card */
.debts-form-card {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
    position: sticky;
    top: 12px;
    overflow: hidden;
}

body.dark-mode .debts-form-card {
    background: #1e293b;
    border-color: #334155;
}

/* ── Debt Overview Card (categorySummary) ─────────────────────────────── */
.debt-overview-card {
    background: var(--light-bg);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.07);
    margin-top: 4px;
}

.debt-overview-header {
    background: var(--primary-color);
    color: #fff;
    font-weight: 700;
    font-size: 1rem;
    padding: 14px 20px;
    letter-spacing: 0.01em;
}

.debt-overview-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    border-bottom: 1px solid var(--border-color);
}

.debt-overview-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 12px;
    border-right: 1px solid var(--border-color);
    text-align: center;
}

.debt-overview-stat:last-child {
    border-right: none;
}

.debt-overview-stat-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted, #6b7280);
    margin-bottom: 6px;
}

.debt-overview-stat-value {
    font-size: 1.35rem;
    font-weight: 700;
    color: var(--primary-color);
    line-height: 1.1;
}

.debt-overview-stat-value--interest {
    color: #dc2626;
}

.debt-overview-stat-value--muted {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted, #9ca3af);
}

.debt-overview-cats {
    padding: 0 0 8px;
}

.debt-overview-cats-header {
    display: grid;
    grid-template-columns: 1fr 80px 90px 100px;
    gap: 0 8px;
    padding: 8px 20px 6px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted, #9ca3af);
    border-bottom: 1px solid var(--border-color);
}

.debt-overview-cat-row {
    display: grid;
    grid-template-columns: 1fr 80px 90px 100px;
    gap: 0 8px;
    align-items: center;
    padding: 10px 20px;
    font-size: 0.88rem;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.15s;
}

.debt-overview-cat-row:last-child {
    border-bottom: none;
}

.debt-overview-cat-row:hover {
    background: rgba(0,0,0,0.025);
}

.debt-overview-cat-name {
    font-weight: 600;
    color: var(--text-color);
}

.debt-overview-cat-count,
.debt-overview-cat-min {
    text-align: center;
    color: var(--text-muted, #6b7280);
    font-size: 0.82rem;
}

.debt-overview-cat-total {
    text-align: right;
    font-weight: 700;
    color: var(--primary-color);
}

/* Dark mode */
body.dark-mode .debt-overview-card {
    background: #1e293b;
    border-color: #334155;
}

body.dark-mode .debt-overview-stat-label,
body.dark-mode .debt-overview-cats-header,
body.dark-mode .debt-overview-cat-count,
body.dark-mode .debt-overview-cat-min {
    color: #94a3b8;
}

body.dark-mode .debt-overview-stat-value {
    color: #60a5fa;
}

body.dark-mode .debt-overview-stat-value--interest {
    color: #f87171;
}

body.dark-mode .debt-overview-stat-value--muted {
    color: #94a3b8;
}

body.dark-mode .debt-overview-cat-total {
    color: #60a5fa;
}

body.dark-mode .debt-overview-cat-row {
    border-color: #334155;
}

body.dark-mode .debt-overview-cats-header {
    border-color: #334155;
}

body.dark-mode .debt-overview-cat-row:hover {
    background: rgba(255,255,255,0.04);
}

@media (max-width: 600px) {
    .debt-overview-stats {
        grid-template-columns: 1fr 1fr;
    }
    .debt-overview-stat:nth-child(2) {
        border-right: none;
    }
    .debt-overview-stat:nth-child(3) {
        grid-column: 1 / -1;
        border-right: none;
        border-top: 1px solid var(--border-color);
    }
    .debt-overview-cats-header {
        display: none;
    }
    .debt-overview-cat-row {
        grid-template-columns: 1fr;
        gap: 4px;
        padding: 10px 20px;
    }
    .debt-overview-cat-name {
        font-weight: 700;
    }
    .debt-overview-cat-count,
    .debt-overview-cat-min,
    .debt-overview-cat-total {
        display: flex;
        justify-content: space-between;
    }
    .debt-overview-cat-count::before,
    .debt-overview-cat-min::before,
    .debt-overview-cat-total::before {
        content: attr(data-label);
        font-size: 0.72rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-muted, #9ca3af);
    }
}

/* Toggle button — acts as the card header */
.debt-form-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 16px 20px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary, #1e293b);
    text-align: left;
    gap: 8px;
    border-radius: 12px;
    transition: background 0.15s;
}
.debt-form-toggle:hover {
    background: rgba(0,0,0,0.03);
}
body.dark-mode .debt-form-toggle {
    color: #f1f5f9;
}
body.dark-mode .debt-form-toggle:hover {
    background: rgba(255,255,255,0.05);
}

/* Open state — show a bottom border separating header from body */
.debt-form-toggle--open {
    border-radius: 12px 12px 0 0;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}
body.dark-mode .debt-form-toggle--open {
    border-bottom-color: #334155;
}

/* Chevron rotation */
.debt-form-toggle-chevron {
    flex-shrink: 0;
    transition: transform 0.2s ease;
}
.debt-form-toggle--open .debt-form-toggle-chevron {
    transform: rotate(180deg);
}

/* Collapsible body */
.debt-form-body {
    padding: 16px 22px 24px;
}
.debt-form-body[hidden] {
    display: none;
}

.debt-form-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

/* List column header */
.debts-list-col { display: flex; flex-direction: column; }

.debts-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 14px;
}

.debts-list-header h2 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

/* Debts page toolbar (filter + import/export actions) */
.debts-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 16px;
}


.debts-toolbar-filter {
    display: flex;
    align-items: center;
    gap: 4px;
}

.debts-toolbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

/* Debts List */
.debts-list {
    display: grid;
    gap: 15px;
}

.debt-card {
    background: var(--light-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.3s ease;
}

.debt-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow);
}

.debt-info {
    flex: 1;
}

.debt-name {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.debt-type-badge {
    display: inline-block;
    background: #dbeafe;
    color: #1e40af;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
}

body.dark-mode .debt-type-badge {
    background: #1e3a8a;
    color: #93c5fd;
}

/* Person / family-member pills — used on debt cards, income cards,
   ledger rows, and the strategy schedule table header */
.person-pill {
    display: inline-block;
    background: #d1fae5;
    color: #065f46;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 500;
}

body.dark-mode .person-pill {
    background: #064e3b;
    color: #6ee7b7;
}

.person-pills {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.debt-person-pills {
    margin: 2px 0 4px;
}

/* Collapsible linked-items section on the People page person card */
.person-linked-details {
    margin-top: 6px;
}

.person-linked-details summary {
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-secondary, #6b7280);
    padding: 2px 0;
    list-style: disclosure-closed;
}

.person-linked-details[open] summary {
    list-style: disclosure-open;
}

.person-linked-body {
    padding: 6px 0 2px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.person-linked-section {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.person-linked-label {
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-secondary, #6b7280);
    letter-spacing: 0.05em;
}

.person-link-btn {
    background: none;
    border: none;
    padding: 0;
    font-size: 0.82rem;
    color: var(--primary-color, #2563eb);
    cursor: pointer;
    text-align: left;
    text-decoration: underline;
}

.person-link-btn:hover {
    opacity: 0.75;
}

.debt-archived-badge {
    display: inline-block;
    background: #f3f4f6;
    color: #6b7280;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    border-radius: 4px;
    padding: 2px 7px;
    text-transform: uppercase;
}

body.dark-mode .debt-archived-badge {
    background: #374151;
    color: #9ca3af;
}

/* Sortable table headers */
th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

th.sortable:hover {
    background: #e0e7ff;
}

th.sort-active {
    color: #2563eb;
}

body.dark-mode th.sortable:hover {
    background: #1e3a8a;
}

body.dark-mode th.sort-active {
    color: #93c5fd;
}

.sort-icon {
    font-size: 0.75rem;
    opacity: 0.6;
    margin-left: 4px;
}

th.sort-active .sort-icon {
    opacity: 1;
}

.debt-details {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.debt-detail {
    display: flex;
    align-items: center;
    gap: 5px;
}

.debt-detail strong {
    color: var(--text-primary);
}

.text-muted {
    color: var(--text-muted, #9ca3af);
}
body.dark-mode .text-muted {
    color: #94a3b8;
}
.debt-payoff-detail--muted {
    font-size: 0.82rem;
}

.debt-actions {
    display: flex;
    gap: 10px;
}

.btn-small {
    padding: 8px 12px;
    font-size: 0.85rem;
}

.btn-delete {
    background: var(--danger-color);
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.3s ease;
}

.btn-delete:hover {
    background: var(--danger-hover);
}

.btn-edit {
    background: #f3f4f6; /* light gray */
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.btn-edit:hover {
    background: #eef2ff; /* subtle primary tint */
    border-color: rgba(37,99,235,0.15);
}

/* Strategy Controls */
.strategy-controls {
    background: var(--light-bg);
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 20px;
}

.strategy-controls .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto auto;
    gap: 15px;
    align-items: flex-end;
}

.strategy-controls .form-group {
    margin-bottom: 0;
}

/* Results Summary */
.summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    margin-bottom: 20px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
}

.summary-item {
    flex: 1 1 180px;
    background: var(--light-bg);
    padding: 10px 18px;
    border-left: 3px solid var(--primary-color);
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    border-right: 1px solid var(--border-color);
}

.summary-item:last-child {
    border-right: none;
}

.summary-item .label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    white-space: nowrap;
    margin-bottom: 0;
}

.summary-item .value {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--primary-color);
    white-space: nowrap;
}

/* Table */
.table-wrapper {
    overflow-x: auto;
    margin: 30px 0;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

thead {
    background: var(--primary-color);
    color: white;
}

th {
    padding: 15px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--border-color);
}

td {
    padding: 12px 15px;
    border-bottom: 1px solid var(--border-color);
}

tbody tr:hover {
    background: var(--light-bg);
}

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

.amount {
    font-weight: 600;
    color: var(--text-primary);
}

.amount small {
    display: block;
    color: #059669;
    font-weight: 600;
    margin-top: 4px;
}

.stimulus-amount {
    color: #059669;
    font-weight: 600;
}

body.dark-mode .stimulus-amount {
    color: #34d399;
}

.principal {
    color: #059669;
}

.interest {
    color: #dc2626;
}

.balance {
    color: #2563eb;
    font-weight: 600;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
    font-size: 1.1rem;
}

/* Responsive */
@media (max-width: 768px) {
    header h1 {
        font-size: 1.8rem;
    }

    .nav-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        position: absolute;
        right: 0;
        top: 0;
        width: 48px;
        height: 48px;
        z-index: 1000;
    }

    .top-nav {
        flex-direction: column;
        align-items: stretch;
        min-height: 48px;
    }

    .nav-menu {
        display: none;
        flex-direction: column;
        align-items: stretch;
        width: 100%;
    }

    .top-nav.menu-open .nav-menu {
        display: flex;
    }

    .nav-group-sep  { display: none; }
    .nav-group-label { display: none; }
    .nav-group      { gap: 0; align-items: stretch; }
    .nav-group-btns { flex-direction: column; align-items: stretch; }
    .page-button {
        width: 100%;
        max-width: 100%;
        font-size: 0.9rem;
        padding: 14px 16px;
        border-bottom: 1px solid rgba(255,255,255,0.10);
        border-right: 3px solid transparent;
        text-align: left;
        white-space: normal;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
    .page-button:hover {
        background: rgba(255,255,255,0.08);
        border-bottom-color: rgba(255,255,255,0.10);
        border-right-color: rgba(255,255,255,0.40);
    }
    .page-button.active {
        background: rgba(255,255,255,0.05);
        border-bottom-color: rgba(255,255,255,0.10);
        border-right: 3px solid #fff;
    }

    main {
        padding: 20px;
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .debt-card {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .debt-actions {
        width: 100%;
    }

    .strategy-controls .form-row {
        grid-template-columns: 1fr;
    }

    .strategy-controls .btn {
        display: block;
        width: 100%;
        margin-top: 10px;
    }

    .summary {
        flex-wrap: wrap;
    }

    .summary-item {
        flex: 1 1 45%;
        border-right: 1px solid var(--border-color);
    }

    table {
        font-size: 0.9rem;
    }

    th,
    td {
        padding: 8px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }
}

@media (max-width: 480px) {
    .header-hero {
        padding: 14px 10px 6px;
    }

    header h1 {
        font-size: 1.5rem;
    }

    .header-toolbar {
        gap: 4px;
    }

    .header-icon-btn {
        width: 44px;
        height: 44px;
    }

    .header-toolbar-divider {
        display: none;
    }

    .header-toolbar-btn {
        padding: 4px 8px;
        font-size: 0.72rem;
    }

    .debt-details {
        flex-direction: column;
        gap: 5px;
    }

    .page-button {
        padding: 12px 14px;
        font-size: 0.85rem;
    }

    .nav-toggle {
        width: 44px;
        height: 44px;
    }
}

/* ============================================================
   NEW FEATURES — Progress Bars, Warnings, Comparison, What-If
   ============================================================ */

/* 4th summary stat alert color */
.summary-item--alert .value,
#monthlyInterestCostValue {
    color: #dc2626;
}

/* ---- Per-debt progress bars ---- */
.debt-progress-wrap {
    margin-top: 8px;
}
.debt-progress-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    color: #6b7280;
    margin-bottom: 3px;
}
.debt-progress-bar {
    height: 7px;
    border-radius: 4px;
    background: #e5e7eb;
    overflow: hidden;
}
.debt-progress-fill {
    height: 100%;
    border-radius: 4px;
    background: linear-gradient(90deg, #2563eb, #059669);
    transition: width 0.4s ease;
    width: var(--progress-width, 0%);
}
.debt-progress-fill--complete {
    background: #059669;
}

/* Summary table inline progress */
.summary-progress-wrap {
    margin-top: 5px;
}
.summary-progress-bar {
    height: 5px;
    border-radius: 3px;
    background: #e5e7eb;
    overflow: hidden;
    min-width: 80px;
}
.summary-progress-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, #2563eb, #059669);
    width: var(--progress-width, 0%);
}
.summary-progress-label {
    font-size: 0.7rem;
    color: #6b7280;
    margin-top: 2px;
}

/* ---- Negative amortization warning ---- */
.neg-amort-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 6px;
    margin-top: 4px;
    cursor: help;
}
body.dark-mode .neg-amort-badge {
    background: #451a03;
    color: #fcd34d;
    border-color: #78350f;
}

/* ---- Strategy comparison panel ---- */
.interest-comparison {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 10px;
    padding: 16px 18px;
    margin-bottom: 16px;
}
.interest-comparison h4 {
    margin: 0 0 10px;
    font-size: 1rem;
    font-weight: 700;
}
.comparison-banner {
    background: #fef9c3;
    border: 1px solid #fde047;
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 0.88rem;
    margin-bottom: 12px;
    color: #713f12;
}
.comparison-banner--good {
    background: #dcfce7;
    border-color: #86efac;
    color: #166534;
}
.comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.comparison-table th {
    background: var(--table-header-bg, #f9fafb);
    padding: 7px 10px;
    text-align: left;
    font-weight: 600;
    border-bottom: 2px solid var(--border-color, #e5e7eb);
}
.comparison-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border-color, #e5e7eb);
}
.comparison-table tr.comparison-current td {
    font-weight: 600;
    background: #eff6ff;
}
.comparison-table tr.comparison-best td {
    color: #166534;
}
.strat-badge {
    display: inline-block;
    font-size: 0.68rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    margin-left: 4px;
    vertical-align: middle;
}
.strat-badge--current {
    background: #dbeafe;
    color: #1d4ed8;
}
.strat-badge--best {
    background: #dcfce7;
    color: #166534;
}
.diff-cost {
    color: #dc2626;
    font-weight: 600;
}
.diff-best {
    color: #4b5563;
}
body.dark-mode .diff-best {
    /* Needs to be lighter than the shared muted-text gray (#94a3b8) since
       this cell can sit on .comparison-current's darker blue row background
       (#1e3a5f) rather than the plain dark card background. */
    color: #a5b2c4;
}

body.dark-mode .interest-comparison {
    background: #1e293b;
    border-color: #334155;
}
body.dark-mode .comparison-banner {
    background: #3f2f00;
    border-color: #78350f;
    color: #fde68a;
}
body.dark-mode .comparison-banner--good {
    background: #052e16;
    border-color: #166534;
    color: #86efac;
}
body.dark-mode .comparison-table th {
    background: #0f172a;
}
body.dark-mode .comparison-table tr.comparison-current td {
    background: #1e3a5f;
}
body.dark-mode .strat-badge--current {
    background: #1e3a5f;
    color: #93c5fd;
}
body.dark-mode .strat-badge--best {
    background: #052e16;
    color: #86efac;
}

/* ---- What-if simulator ---- */
.whatif-panel {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 10px;
    padding: 16px 18px;
    margin-bottom: 20px;
}
.whatif-panel h4 {
    margin: 0 0 6px;
    font-size: 1rem;
    font-weight: 700;
}
.whatif-desc {
    font-size: 0.85rem;
    color: #6b7280;
    margin: 0 0 12px;
}
.whatif-slider-row {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.whatif-slider-label {
    font-size: 0.88rem;
    font-weight: 600;
    min-width: 140px;
    white-space: nowrap;
}
#whatifSlider {
    flex: 1;
    min-width: 180px;
    accent-color: #2563eb;
}
.whatif-slider-cap {
    font-size: 0.8rem;
    color: #6b7280;
}
.whatif-hint {
    font-size: 0.85rem;
    color: #6b7280;
    margin: 10px 0 0;
    font-style: italic;
}
.whatif-metrics {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
    margin-top: 14px;
}
.whatif-metric {
    background: var(--bg-color, #f9fafb);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    padding: 10px 12px;
    text-align: center;
}
.whatif-metric--good {
    background: #f0fdf4;
    border-color: #86efac;
}
.whatif-metric-label {
    font-size: 0.75rem;
    color: #6b7280;
    font-weight: 600;
    margin-bottom: 4px;
}
.whatif-metric-val {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-color, #111827);
}
.whatif-metric--good .whatif-metric-val {
    color: #166534;
}

body.dark-mode .whatif-panel {
    background: #1e293b;
    border-color: #334155;
}
body.dark-mode .whatif-metric {
    background: #0f172a;
    border-color: #334155;
}
body.dark-mode .whatif-metric--good {
    background: #052e16;
    border-color: #166534;
}
body.dark-mode .whatif-metric--good .whatif-metric-val {
    color: #86efac;
}

/* ---- Update balance modal (dark mode) ---- */
body.dark-mode #updateBalanceModal .modal-content {
    background: #1e293b;
    color: #f1f5f9;
}

body.dark-mode #ledgerOverrideModal .modal-content {
    background: #1e293b;
    color: #f1f5f9;
}

/* ---- Interest Paid to Date ---- */
.iptd-detail {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding-top: 6px;
    border-top: 1px solid var(--border-color, #e5e7eb);
    margin-top: 4px;
}
.iptd-value {
    color: #dc2626;
    font-weight: 700;
    font-size: 1em;
}
.iptd-sub {
    display: block;
    font-size: 0.73rem;
    color: #6b7280;
    margin-top: 1px;
}
body.dark-mode .iptd-sub {
    color: #9ca3af;
}
body.dark-mode .iptd-value {
    color: #f87171;
}

/* ---- Target Payoff Date panel ---- */
.target-date-panel {
    margin-top: 20px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 10px;
    overflow: hidden;
}
.target-date-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card-bg, #f9fafb);
    border: none;
    padding: 13px 16px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-color, #111827);
    cursor: pointer;
    text-align: left;
    gap: 8px;
}
.target-date-toggle:hover {
    background: #eff6ff;
}
.target-date-chevron {
    font-size: 0.7rem;
    transition: transform 0.2s;
    flex-shrink: 0;
}
.target-date-toggle[aria-expanded="true"] .target-date-chevron {
    transform: rotate(180deg);
}
.target-date-body {
    padding: 16px;
    border-top: 1px solid var(--border-color, #e5e7eb);
    background: var(--bg-color, #fff);
}
.target-date-desc {
    margin: 0 0 14px;
    font-size: 0.88rem;
    color: #6b7280;
}
.target-date-row {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    align-items: flex-end;
}

/* Result box */
.target-result {
    margin-top: 16px;
    border-radius: 8px;
    padding: 14px 16px;
    background: #f0fdf4;
    border: 1px solid #86efac;
}
.target-result--warn {
    background: #fef3c7;
    border-color: #fcd34d;
}
.target-result--error {
    background: #fef2f2;
    border-color: #fca5a5;
}
.target-result-headline {
    font-size: 1rem;
    font-weight: 700;
    margin: 0 0 8px;
    color: #166534;
}
.target-result--warn .target-result-headline {
    color: #92400e;
}
.target-result--error .target-result-headline {
    color: #991b1b;
}
.target-result-payment {
    font-size: 1.7rem;
    font-weight: 800;
    color: #15803d;
    display: block;
    margin-bottom: 6px;
}
.target-result--warn .target-result-payment {
    color: #b45309;
}
.target-result-meta {
    font-size: 0.83rem;
    color: #6b7280;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 6px;
}
.target-result-meta span {
    display: flex;
    align-items: center;
    gap: 4px;
}
.target-result-action {
    margin-top: 12px;
}

body.dark-mode .target-date-panel {
    border-color: #334155;
}
body.dark-mode .target-date-toggle {
    background: #1e293b;
    color: #f1f5f9;
}
body.dark-mode .target-date-toggle:hover {
    background: #1e3a5f;
}
body.dark-mode .target-date-body {
    background: #0f172a;
    border-color: #334155;
}
body.dark-mode .target-result {
    background: #052e16;
    border-color: #166534;
}
body.dark-mode .target-result-headline {
    color: #86efac;
}
body.dark-mode .target-result-payment {
    color: #4ade80;
}
body.dark-mode .target-result--warn {
    background: #451a03;
    border-color: #78350f;
}
body.dark-mode .target-result--warn .target-result-headline {
    color: #fde68a;
}
body.dark-mode .target-result--warn .target-result-payment {
    color: #fbbf24;
}

/* ═══════════════════════════════════════════════════════════════
   INCOME SECTION
   ═══════════════════════════════════════════════════════════════ */

.income-form-card {
    background: var(--light-bg);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 20px 24px;
    margin-bottom: 24px;
}

.income-form-card h3 {
    margin: 0 0 16px 0;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-color);
}

.income-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px 16px;
    margin-bottom: 16px;
}
@media (max-width: 899px) {
    .income-form-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}
@media (max-width: 480px) {
    .income-form-grid {
        grid-template-columns: 1fr;
    }
}
@media (min-width: 900px) {
    .income-form-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 12px 18px;
    }
    .income-form-card label {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 98%;
        display: block;
    }
}

/* Income list */
.income-list {
    display: grid;
    gap: 12px;
    margin-bottom: 20px;
    grid-template-columns: 1fr;
}
@media (min-width: 900px) {
    .income-list {
        grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
        gap: 14px 18px;
    }
}

.income-card {
    background: var(--light-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

/* Inline edit state — card expands to show the form */
.income-card--editing {
    display: block;
    border-color: var(--primary-color);
}

.income-edit-form {
    width: 100%;
}

.income-edit-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px 16px;
    margin-bottom: 12px;
}

.income-card-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
    margin-left: auto;
    align-items: center;
}

.income-edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.income-card-info {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 20px;
    align-items: baseline;
}

.income-card-name {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text-color);
}

.income-card-detail {
    font-size: 0.88rem;
    color: #6b7280;
}

.income-card-amount {
    font-weight: 700;
    font-size: 1.1rem;
    color: #059669;
    white-space: nowrap;
}

.income-card-freq {
    display: inline-block;
    background: #d1fae5;
    color: #065f46;
    border-radius: 999px;
    padding: 1px 10px;
    font-size: 0.75rem;
    font-weight: 600;
}

body.dark-mode .income-card-freq {
    background: #064e3b;
    color: #6ee7b7;
}

.income-card-upcoming-label {
    font-size: 0.78rem;
    color: #6b7280;
    font-weight: 600;
    white-space: nowrap;
    align-self: center;
}

.income-upcoming-chip {
    display: inline-block;
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

body.dark-mode .income-upcoming-chip {
    background: #1e3a5f;
    color: #93c5fd;
    border-color: #2563eb;
}

body.dark-mode .income-card-upcoming-label {
    color: #94a3b8;
}

body.dark-mode .income-card-amount {
    color: #34d399;
}

/* Monthly income summary panel */
.income-summary {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    border: 2px solid #86efac;
    border-radius: 10px;
    padding: 16px 20px;
}

body.dark-mode .income-summary {
    background: linear-gradient(135deg, #052e16 0%, #064e3b 100%);
    border-color: #166534;
}

.income-summary h4 {
    margin: 0 0 10px 0;
    font-size: 0.95rem;
    color: #166534;
    font-weight: 700;
}

body.dark-mode .income-summary h4 { color: #6ee7b7; }

.income-summary-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 12px 28px;
}

.income-summary-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.income-summary-label {
    font-size: 0.75rem;
    color: #4b7c59;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

body.dark-mode .income-summary-label { color: #6ee7b7; }

.income-summary-value {
    font-size: 1.15rem;
    font-weight: 700;
    color: #15803d;
}

body.dark-mode .income-summary-value { color: #34d399; }

/* Bonus value accent in the summary panel */
.income-summary-value--bonus {
    color: #d97706;
}
body.dark-mode .income-summary-value--bonus { color: #fbbf24; }

/* ── Bonus / Windfall section ─────────────────────────────────────────────── */
.bonus-section {
    margin-top: 24px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
}

.bonus-form-toggle {
    width: 100%;
    text-align: left;
    background: var(--light-bg);
    border: none;
    padding: 13px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text-primary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background 0.2s;
}

.bonus-form-toggle:hover { background: #e2e8f0; }
body.dark-mode .bonus-form-toggle { background: #1e293b; color: #f1f5f9; }
body.dark-mode .bonus-form-toggle:hover { background: #334155; }

.bonus-form-chevron {
    font-size: 0.8rem;
    transition: transform 0.2s;
}

.bonus-form-toggle--open .bonus-form-chevron { transform: rotate(180deg); }

.bonus-form-inner {
    padding: 16px 18px 18px;
    border-top: 1px solid var(--border-color);
    background: var(--card-background);
}

.bonus-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 14px;
}

@media (max-width: 768px) {
    .bonus-form-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
    .bonus-form-grid { grid-template-columns: 1fr; }
}

/* Bonus list */
.bonus-list-wrap {
    margin-top: 16px;
}

.bonus-list-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0 0 10px 0;
}

.bonus-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-left: 4px solid #d97706;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 8px;
    gap: 12px;
}

.bonus-card--current {
    border-left-color: #16a34a;
    background: #f0fdf4;
}
body.dark-mode .bonus-card--current { background: #052e16; }

.bonus-card--editing {
    flex-direction: column;
    align-items: stretch;
    border-left-color: var(--primary-color);
}

.bonus-edit-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 12px;
}
@media (max-width: 768px) {
    .bonus-edit-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
    .bonus-edit-grid { grid-template-columns: 1fr; }
}

.bonus-card-info {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 14px;
    flex: 1;
}

.bonus-card-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.bonus-card-amount {
    font-weight: 700;
    font-size: 1rem;
    color: #d97706;
}
body.dark-mode .bonus-card-amount { color: #fbbf24; }

.bonus-card-meta {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.bonus-cat-badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.bonus-cat--bonus   { background: #fef3c7; color: #92400e; }
.bonus-cat--tax     { background: #dbeafe; color: #1e40af; }
.bonus-cat--other   { background: #f3f4f6; color: #4b5563; }
body.dark-mode .bonus-cat--bonus { background: #451a03; color: #fcd34d; }
body.dark-mode .bonus-cat--tax   { background: #1e3a5f; color: #93c5fd; }
body.dark-mode .bonus-cat--other { background: #1f2937; color: #d1d5db; }

.bonus-this-month-tag {
    font-size: 0.75rem;
    font-weight: 600;
    color: #15803d;
    white-space: nowrap;
}
body.dark-mode .bonus-this-month-tag { color: #4ade80; }

.bonus-purpose-badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 20px;
    letter-spacing: 0.02em;
}
.bonus-purpose--cashflow { background: #dcfce7; color: #166534; }
.bonus-purpose--savings  { background: #e0e7ff; color: #3730a3; }
body.dark-mode .bonus-purpose--cashflow { background: #052e16; color: #86efac; }
body.dark-mode .bonus-purpose--savings  { background: #1e1b4b; color: #a5b4fc; }

.bonus-advice-trigger {
    margin-top: 12px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.bonus-advice-filter-label {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.bonus-advice-filter {
    min-width: 150px;
}

.bonus-advice {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 12px;
}
@media (max-width: 600px) {
    .bonus-advice { grid-template-columns: 1fr; }
}

.bonus-advice-card {
    background: var(--card-background);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px 14px;
}

.bonus-advice-title {
    font-size: 0.88rem;
    font-weight: 700;
    margin: 0 0 8px;
}

.bonus-advice-stat {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.bonus-advice-na {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-style: italic;
}

.bonus-advice-subsection {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--border-color);
}

.bonus-advice-subtitle {
    font-size: 0.8rem;
    font-weight: 700;
    margin: 0 0 6px;
    color: var(--text-secondary);
}

/* Strategy bonus chip */
.strategy-bonus-chip {
    display: inline-block;
    background: #fef3c7;
    color: #92400e;
    font-size: 0.78rem;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: 12px;
    margin-left: 6px;
}
body.dark-mode .strategy-bonus-chip { background: #451a03; color: #fcd34d; }

/* Strategy page income widget */
.strategy-income-widget {
    margin-top: 16px;
    background: #f0fdf4;
    border: 1px solid #86efac;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 0.9rem;
    color: #166534;
}

body.dark-mode .strategy-income-widget {
    background: #052e16;
    border-color: #166534;
    color: #6ee7b7;
}

.strategy-income-widget strong {
    color: #15803d;
}

body.dark-mode .strategy-income-widget strong {
    color: #34d399;
}

.strategy-income-ratio {
    margin-top: 6px;
    font-size: 0.83rem;
    color: #4b7c59;
}

body.dark-mode .strategy-income-ratio { color: #a7f3d0; }

.strategy-income-ratio--warn {
    color: #b45309;
    font-weight: 600;
}

body.dark-mode .strategy-income-ratio--warn { color: #fbbf24; }

/* Accounts net worth dashboard widget */
.net-worth-widget {
    margin: 10px 0 18px;
}

.nw-widget-card {
    background: linear-gradient(145deg, #f8fafc, #ecfeff);
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    padding: 14px 16px;
    box-shadow: 0 3px 10px rgba(30, 64, 175, 0.08);
}

.nw-widget-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.nw-widget-head h3 {
    margin: 0;
    font-size: 1rem;
    color: #1d4ed8;
}

.nw-widget-date {
    font-size: 0.8rem;
    color: #475569;
}

.nw-widget-main {
    margin-top: 4px;
    font-size: 1.6rem;
    font-weight: 800;
    color: #0f172a;
}

.nw-widget-change {
    margin-top: 3px;
    font-size: 0.86rem;
    font-weight: 600;
}

.nw-change--up { color: #15803d; }
.nw-change--down { color: #b91c1c; }
body.dark-mode .nw-change--up { color: #4ade80; }
body.dark-mode .nw-change--down { color: #f87171; }

.nw-widget-breakdown {
    margin-top: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 0.86rem;
    color: #334155;
}

.nw-widget-empty {
    margin: 0;
    padding: 12px;
    border: 1px dashed var(--border-color);
    border-radius: 10px;
    color: var(--text-muted);
    background: var(--card-bg);
}

body.dark-mode .nw-widget-card {
    background: linear-gradient(145deg, #0f172a, #1e293b);
    border-color: #334155;
}

body.dark-mode .nw-widget-head h3 { color: #93c5fd; }
body.dark-mode .nw-widget-date { color: #94a3b8; }
body.dark-mode .nw-widget-main { color: #e2e8f0; }
body.dark-mode .nw-widget-breakdown { color: #cbd5e1; }

/* ── Strategy net cashflow row ──────────────────────────────────────────── */
.strategy-net {
    margin-top: 8px;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}
.strategy-net--positive { background: #d1fae5; color: #065f46; }
.strategy-net--negative { background: #fee2e2; color: #7f1d1d; }
.strategy-net--positive strong { color: #065f46; }
.strategy-net--negative strong { color: #7f1d1d; }
body.dark-mode .strategy-net--positive { background: #064e3b; color: #a7f3d0; }
body.dark-mode .strategy-net--negative { background: #450a0a; color: #fca5a5; }
.strategy-net-breakdown { font-size: 0.78rem; opacity: 0.8; }

/* ═══════════════════════════════════════════════════════════════════════════
   BUDGET PAGE
   ═══════════════════════════════════════════════════════════════════════════ */

/* Two-column layout */
.budget-two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 24px;
}
.budget-col { display: flex; flex-direction: column; }
@media (max-width: 768px) {
    .budget-two-col { grid-template-columns: 1fr; }
}

/* Column heading card */
.budget-col-card,
.budget-form-card {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
    margin-bottom: 12px;
    overflow: hidden;
}
body.dark-mode .budget-col-card,
body.dark-mode .budget-form-card {
    background: #1e293b;
    border-color: #334155;
}

/* Budget form toggle button — acts as the card header */
.budget-form-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 14px 18px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 700;
    color: #1e293b;
    text-align: left;
    gap: 8px;
    border-radius: 12px;
    transition: background 0.15s;
}
.budget-form-toggle:hover {
    background: rgba(0,0,0,0.03);
}
body.dark-mode .budget-form-toggle {
    color: #f1f5f9;
}
body.dark-mode .budget-form-toggle:hover {
    background: rgba(255,255,255,0.05);
}
.budget-form-toggle--open {
    border-radius: 12px 12px 0 0;
    border-bottom: 1px solid #e5e7eb;
}
body.dark-mode .budget-form-toggle--open {
    border-bottom-color: #334155;
}
.budget-form-toggle-chevron {
    flex-shrink: 0;
    transition: transform 0.2s ease;
}
.budget-form-toggle--open .budget-form-toggle-chevron {
    transform: rotate(180deg);
}

/* Collapsible form body */
.budget-form-body {
    padding: 14px 18px 18px;
}
.budget-form-body[hidden] {
    display: none;
}

/* Legacy h3 inside budget cards (kept for non-collapsible uses) */
.budget-col-card h3,
.budget-form-card h3 {
    margin: 0 0 16px 0;
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
}
body.dark-mode .budget-col-card h3,
body.dark-mode .budget-form-card h3 { color: #f1f5f9; }

/* Form grid inside budget forms */
.budget-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}
@media (max-width: 768px) { .budget-form-grid { grid-template-columns: 1fr; } }
.budget-form-grid .form-group { margin: 0; }

/* Item cards */
.budget-item-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}
.budget-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 14px;
}
body.dark-mode .budget-card {
    background: #0f172a;
    border-color: #1e293b;
}
.budget-card--editing {
    flex-direction: column;
    align-items: stretch;
    background: #eff6ff;
    border-color: #3b82f6;
}
body.dark-mode .budget-card--editing {
    background: #1e3a5f;
    border-color: #3b82f6;
}
.budget-card-info {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 14px;
    flex: 1;
    min-width: 0;
}
.budget-card-name {
    font-weight: 600;
    color: #1e293b;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
body.dark-mode .budget-card-name { color: #f1f5f9; }
.budget-card-amount {
    font-weight: 700;
    color: #0f766e;
    font-size: 0.95rem;
}
body.dark-mode .budget-card-amount { color: #2dd4bf; }
.budget-card-period {
    font-size: 0.75rem;
    font-weight: 400;
    color: #94a3b8;
}
.budget-card-meta {
    font-size: 0.78rem;
    color: #64748b;
}
body.dark-mode .budget-card-meta { color: #94a3b8; }
.budget-card-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.budget-edit-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 2fr;
    gap: 8px;
    margin-bottom: 10px;
}
@media (max-width: 600px) {
    .budget-edit-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
    .budget-edit-grid { grid-template-columns: 1fr; }
}
.budget-edit-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}
.empty-budget-msg {
    color: #9ca3af;
    font-style: italic;
    margin: 8px 0 0;
    font-size: 0.85rem;
}

/* ── Budget category summary panels ─────────────────────────────────────── */
.budget-cat-summary {
    margin-top: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    background: #f8fafc;
}
body.dark-mode .budget-cat-summary {
    background: #0f172a;
    border-color: #1e293b;
}

.budget-cat-summary--expense {
    border-color: #ddd6fe;
    background: #faf5ff;
}
body.dark-mode .budget-cat-summary--expense {
    background: #1a0e2e;
    border-color: #3b1f6e;
}

.budget-cat-summary-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 14px;
    background: #e2e8f0;
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #475569;
}
body.dark-mode .budget-cat-summary-header {
    background: #1e293b;
    color: #94a3b8;
}
.budget-cat-summary--expense .budget-cat-summary-header {
    background: #ede9fe;
    color: #5b21b6;
}
body.dark-mode .budget-cat-summary--expense .budget-cat-summary-header {
    background: #2e1065;
    color: #c4b5fd;
}

.budget-cat-summary-total {
    font-size: 0.82rem;
    font-weight: 700;
    color: #1e293b;
}
body.dark-mode .budget-cat-summary-total {
    color: #f1f5f9;
}

.budget-cat-row {
    display: flex;
    align-items: center;
    padding: 7px 14px;
    font-size: 0.83rem;
    border-top: 1px solid #e5e7eb;
    gap: 8px;
}
body.dark-mode .budget-cat-row {
    border-color: #1e293b;
}
.budget-cat-row:hover {
    background: rgba(0,0,0,0.03);
}
body.dark-mode .budget-cat-row:hover {
    background: rgba(255,255,255,0.04);
}

.budget-cat-row--expense {
    border-color: #ddd6fe;
}
body.dark-mode .budget-cat-row--expense {
    border-color: #3b1f6e;
}

.budget-cat-name {
    flex: 1;
    font-weight: 600;
    color: var(--text-color);
}
.budget-cat-count {
    font-size: 0.75rem;
    color: #9ca3af;
    min-width: 56px;
    text-align: center;
}
.budget-cat-amount {
    font-weight: 700;
    color: #d97706;
    min-width: 80px;
    text-align: right;
}
.budget-cat-row--expense .budget-cat-amount {
    color: #7c3aed;
}
body.dark-mode .budget-cat-amount {
    color: #fbbf24;
}
body.dark-mode .budget-cat-row--expense .budget-cat-amount {
    color: #a78bfa;
}


.cashflow-summary {
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07);
}
body.dark-mode .cashflow-summary {
    background: #1e293b;
    border-color: #334155;
}

/* ── Cashflow tabs ─────────────────────────────────────────────────── */
.cashflow-tab-bar {
    display: flex;
    border-bottom: 1px solid #e5e7eb;
    background: #f8fafc;
}
body.dark-mode .cashflow-tab-bar {
    background: #0f172a;
    border-color: #334155;
}
.cashflow-tab {
    padding: 10px 20px;
    font-size: 0.88rem;
    font-weight: 600;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #6b7280;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.15s, border-color 0.15s;
}
.cashflow-tab:hover { color: #1e293b; }
.cashflow-tab--active { color: var(--primary-color); border-bottom-color: var(--primary-color); }
body.dark-mode .cashflow-tab { color: #94a3b8; }
body.dark-mode .cashflow-tab:hover { color: #f1f5f9; }
body.dark-mode .cashflow-tab--active { color: #93c5fd; border-bottom-color: #93c5fd; }

.cashflow-tab-panel { display: none; padding: 20px 24px; }
.cashflow-tab-panel--active { display: block; }

.cashflow-summary h4 {
    margin: 0 0 16px;
    font-size: 1rem;
    font-weight: 700;
    color: #1e293b;
}
body.dark-mode .cashflow-summary h4 { color: #f1f5f9; }

/* ── Cashflow charts panel ─────────────────────────────────────────── */
.cashflow-charts-top {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.cashflow-charts-bottom {
    width: 100%;
}

.cashflow-chart-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.cashflow-chart-wrap--donut {
    width: 100%;
    max-width: 320px;
}

.cashflow-chart-wrap--bar {
    width: 100%;
    align-items: stretch;
}

.cashflow-bar-container {
    position: relative;
    width: 100%;
    height: 300px;
    max-height: 300px;
}

.cashflow-chart-title {
    margin: 0 0 2px;
    font-size: 0.88rem;
    font-weight: 700;
    color: #1e293b;
    text-align: center;
}
body.dark-mode .cashflow-chart-title { color: #f1f5f9; }
.cashflow-chart-sub {
    margin: 0 0 12px;
    font-size: 0.75rem;
    color: #9ca3af;
    text-align: center;
}
#cashflowDonutChart {
    max-width: 280px;
    max-height: 280px;
}
#cashflowBarChart {
    width: 100% !important;
    height: 100% !important;
}

.cashflow-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 32px;
    margin-bottom: 16px;
}
@media (max-width: 600px) { .cashflow-grid { grid-template-columns: 1fr; } }
.cashflow-section-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #94a3b8;
    margin-bottom: 6px;
}
.cashflow-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.88rem;
    margin-bottom: 4px;
}
.cashflow-label { color: #374151; }
body.dark-mode .cashflow-label { color: #d1d5db; }
.cashflow-value { font-weight: 600; color: #1e293b; }
body.dark-mode .cashflow-value { color: #f1f5f9; }
.cashflow-row--income  { background: #d1fae5; }
.cashflow-row--debt    { background: #fee2e2; }
.cashflow-row--bills   { background: #fef3c7; }
.cashflow-row--expenses { background: #ede9fe; }
.cashflow-row--total   { background: #f1f5f9; font-weight: 700; }
body.dark-mode .cashflow-row--income   { background: #064e3b; }
body.dark-mode .cashflow-row--debt     { background: #450a0a; }
body.dark-mode .cashflow-row--bills    { background: #451a03; }
body.dark-mode .cashflow-row--expenses { background: #2e1065; }
body.dark-mode .cashflow-row--total    { background: #0f172a; }

/* Cashflow sub-rows (category / debt breakdowns) */
.cashflow-subrow {
    display: flex;
    justify-content: space-between;
    padding: 3px 10px 3px 24px;
    font-size: 0.78rem;
    border-left: 3px solid transparent;
    margin-bottom: 1px;
}
.cashflow-sublabel { color: #6b7280; }
.cashflow-subvalue { color: #374151; font-weight: 500; }
.cashflow-subrow--bill     { border-left-color: #d97706; background: rgba(254,243,199,0.5); }
.cashflow-subrow--expense  { border-left-color: #7c3aed; background: rgba(237,233,254,0.5); }
.cashflow-subrow--debt     { border-left-color: #dc2626; background: rgba(254,226,226,0.4); }
body.dark-mode .cashflow-sublabel { color: #9ca3af; }
body.dark-mode .cashflow-subvalue { color: #cbd5e1; }
body.dark-mode .cashflow-subrow--bill     { background: rgba(69,26,3,0.5); }
body.dark-mode .cashflow-subrow--expense  { background: rgba(46,16,101,0.5); }
body.dark-mode .cashflow-subrow--debt     { background: rgba(69,10,10,0.4); }
.cashflow-net {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 700;
    margin-top: 4px;
}
.cashflow-net--positive { background: #d1fae5; color: #065f46; }
.cashflow-net--negative { background: #fee2e2; color: #7f1d1d; }
body.dark-mode .cashflow-net--positive { background: #064e3b; color: #a7f3d0; }
body.dark-mode .cashflow-net--negative { background: #450a0a; color: #fca5a5; }

/* ═══════════════════════════════════════════════════════════════════════════
   REPORTS PAGE
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Reports tab bar — grouped chip/pill nav ─────────────────────────────── */
.rpt-tab-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 20;
    background: white;
}
body.dark-mode .rpt-tab-bar {
    background: var(--bg-color);
}

.rpt-tab-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.rpt-tab-group-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 999px;
    background: hsla(var(--primary-hsl), 0.10);
    border: 1px solid hsla(var(--primary-hsl), 0.25);
    color: var(--primary-color);
    align-self: flex-start;
    opacity: 0.55;
    transition: opacity 0.15s;
}
.rpt-tab-group:has(.rpt-tab-btn--active) .rpt-tab-group-label {
    opacity: 1;
}

.rpt-tab-group-tabs {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
}

.rpt-tab-btn {
    padding: 8px 14px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.rpt-tab-btn:hover {
    background: var(--light-bg);
    color: var(--text-primary);
    border-color: var(--primary-color);
}
.rpt-tab-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}
.rpt-tab-btn--active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}
body.dark-mode .rpt-tab-btn--active {
    background: #60a5fa;
    border-color: #60a5fa;
    color: #0f172a;
}
body.dark-mode .rpt-tab-btn:hover {
    background: #1e293b;
    color: #e2e8f0;
}

.rpt-tab-group-sep {
    width: 1px;
    height: 28px;
    background: var(--border-color);
    align-self: flex-end;
    margin-bottom: 2px;
    flex-shrink: 0;
}

/* ── Tab panels ────────────────────────────────────────────────────────── */
.rpt-tab-panel { display: none; padding: 24px 0 0; }
.rpt-tab-panel--active { display: block; }

/* ── Data Transfer modal tabs — same pill pattern as .rpt-tab-btn ───────── */
.dt-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
}
.dt-tab-btn {
    padding: 8px 14px;
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
}
.dt-tab-btn:hover {
    background: var(--light-bg);
    color: var(--text-primary);
    border-color: var(--primary-color);
}
.dt-tab-btn:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}
.dt-tab-btn--active {
    background: var(--primary-color);
    color: #fff;
    border-color: var(--primary-color);
}
body.dark-mode .dt-tab-btn--active {
    background: #60a5fa;
    border-color: #60a5fa;
    color: #0f172a;
}
body.dark-mode .dt-tab-btn:hover {
    background: #1e293b;
    color: #e2e8f0;
}
.dt-tab-panel { display: none; }
.dt-tab-panel--active { display: block; }
.dt-import-choice {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border-color);
}
.dt-import-choice .btn {
    margin-right: 8px;
}

/* ── Stats strip ───────────────────────────────────────────────────────── */
.rpt-stats-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 28px;
}
.rpt-stat {
    flex: 1 1 140px;
    border-radius: 10px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border: 1px solid var(--border-color);
}
.rpt-stat-label { font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.rpt-stat-value { font-size: 1.15rem; font-weight: 700; }
.rpt-stat--income  { background: #f0fdf4; border-color: #86efac; }
.rpt-stat--income .rpt-stat-value  { color: #065f46; }
.rpt-stat--bills   { background: #fffbeb; border-color: #fde68a; }
.rpt-stat--bills   .rpt-stat-value { color: #92400e; }
.rpt-stat--exp     { background: #f5f3ff; border-color: #c4b5fd; }
.rpt-stat--exp     .rpt-stat-value { color: #4c1d95; }
.rpt-stat--recurring { background: #ecfdf5; border-color: #a5f3fc; }
.rpt-stat--recurring .rpt-stat-value { color: #0c4a6e; }
.rpt-stat--debt    { background: #fef2f2; border-color: #fca5a5; }
.rpt-stat--debt    .rpt-stat-value { color: #7f1d1d; }
.rpt-stat--savings { background: #ecfdf5; border-color: #a5f3fc; }
.rpt-stat--savings .rpt-stat-value { color: #065f46; }
.rpt-net--pos      { background: #d1fae5; border-color: #6ee7b7; }
.rpt-net--pos .rpt-stat-value      { color: #064e3b; }
.rpt-net--neg      { background: #fee2e2; border-color: #fca5a5; }
.rpt-net--neg .rpt-stat-value      { color: #7f1d1d; }

body.dark-mode .rpt-stat--income  { background: #022c22; border-color: #065f46; }
body.dark-mode .rpt-stat--income .rpt-stat-value  { color: #6ee7b7; }
body.dark-mode .rpt-stat--bills   { background: #1c1400; border-color: #78350f; }
body.dark-mode .rpt-stat--bills   .rpt-stat-value { color: #fcd34d; }
body.dark-mode .rpt-stat--exp     { background: #1e1b4b; border-color: #4c1d95; }
body.dark-mode .rpt-stat--exp     .rpt-stat-value { color: #c4b5fd; }
body.dark-mode .rpt-stat--recurring { background: #06363c; border-color: #0c4a6e; }
body.dark-mode .rpt-stat--recurring .rpt-stat-value { color: #67e8f9; }
body.dark-mode .rpt-stat--debt    { background: #450a0a; border-color: #7f1d1d; }
body.dark-mode .rpt-stat--debt    .rpt-stat-value { color: #fca5a5; }
body.dark-mode .rpt-stat--savings { background: #06363c; border-color: #0c4a6e; }
body.dark-mode .rpt-stat--savings .rpt-stat-value { color: #a7f3d0; }
body.dark-mode .rpt-net--pos      { background: #064e3b; border-color: #065f46; }
body.dark-mode .rpt-net--pos .rpt-stat-value      { color: #a7f3d0; }
body.dark-mode .rpt-net--neg      { background: #450a0a; border-color: #7f1d1d; }
body.dark-mode .rpt-net--neg .rpt-stat-value      { color: #fca5a5; }

/* ── Chart row ─────────────────────────────────────────────────────────── */
.rpt-charts-row {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}
.rpt-chart-card {
    flex: 1 1 300px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px 18px;
}
.rpt-chart-title  { margin: 0 0 2px; font-size: 1rem; font-weight: 700; color: var(--text-color); }
.rpt-chart-sub    { margin: 0 0 16px; font-size: 0.8rem; color: var(--text-muted); }
.rpt-chart-canvas-wrap { position: relative; height: 280px; }

/* ── Money Flow ─────────────────────────────────────────────────────────── */
.rpt-section-title { margin: 0 0 6px; font-size: 1.1rem; font-weight: 700; }
.rpt-moneyflow-wrap { position: relative; height: 360px; }
.mf-sankey-wrap { position: relative; width: 100%; overflow-x: auto; overflow-y: hidden; margin-bottom: 16px; }
.mf-sankey-wrap svg { display: block; width: 100%; height: auto; min-width: 480px; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.rpt-empty-msg {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 0.95rem;
    border: 2px dashed var(--border-color);
    border-radius: 10px;
    margin-top: 10px;
}

/* ── Calendar ────────────────────────────────────────────────────────────── */
.rpt-cal-month-title {
    margin: 0 0 10px;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-color);
}
.rpt-cal-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 20px;
    margin-bottom: 14px;
    font-size: 0.8rem;
}
.rpt-cal-legend-item { display: flex; align-items: center; gap: 5px; color: var(--text-muted); }
.rpt-cal-swatch {
    display: inline-block;
    width: 12px; height: 12px;
    border-radius: 3px;
    flex-shrink: 0;
}
.rpt-cal-swatch--income { background: #10b981; }
.rpt-cal-swatch--bill   { background: #f59e0b; }
.rpt-cal-swatch--expense { background: #8b5cf6; }
.rpt-cal-swatch--recurring { background: #06b6d4; }
.rpt-cal-swatch--debt { background: #2563eb; }
.rpt-cal-swatch--bonus  { background: #d97706; }
.rpt-cal-swatch--today  { background: #2563eb; border-radius: 50%; }

.rpt-cal-day-labels {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    text-align: center;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.rpt-cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 3px;
}
.rpt-cal-cell {
    min-height: 52px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px 5px;
    background: var(--card-bg);
    overflow: hidden;
    font-size: 0.7rem;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.rpt-cal-empty { background: transparent; border-color: transparent; }
.rpt-cal-has-events {
    border-color: #c7d2fe;
    cursor: pointer;
}
.rpt-cal-has-events:hover,
.rpt-cal-has-events:focus-visible {
    background: #eef2ff;
    outline: 2px solid #6366f1;
    outline-offset: 1px;
}
body.dark-mode .rpt-cal-has-events:hover,
body.dark-mode .rpt-cal-has-events:focus-visible {
    background: #312e81;
}
.rpt-cal-today { background: #eff6ff; border-color: #2563eb; border-width: 2px; }
body.dark-mode .rpt-cal-has-events { border-color: #4338ca; }
body.dark-mode .rpt-cal-today { background: #1e3a5f; border-color: #2563eb; }

.rpt-cal-dots {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 2px;
    margin-top: 2px;
}
.rpt-cal-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}
.rpt-cal-dot--income { background: #047857; }
.rpt-cal-dot--bill   { background: #92400e; }
.rpt-cal-dot--expense { background: #7c3aed; }
.rpt-cal-dot--recurring { background: #0e7490; }
.rpt-cal-dot--bonus  { background: #b45309; }
.rpt-cal-dot--debt   { background: #2563eb; }
.rpt-cal-count {
    font-size: 0.62rem;
    color: var(--text-muted);
    margin-top: 1px;
}
body.dark-mode .rpt-cal-count {
    color: #cbd5e1;
}

.rpt-cal-day-num {
    display: block;
    font-weight: 700;
    font-size: 0.8rem;
    margin-bottom: 3px;
    color: var(--text-color);
}
.rpt-cal-today .rpt-cal-day-num {
    color: #2563eb;
}
body.dark-mode .rpt-cal-today .rpt-cal-day-num {
    color: #60a5fa;
}
.rpt-cal-today .rpt-cal-count {
    color: #475569;
}
body.dark-mode .rpt-cal-today .rpt-cal-count {
    color: #cbd5e1;
}

/* Event chips */
.rpt-cal-evt {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 3px;
    border-radius: 4px;
    padding: 1px 5px;
    margin-bottom: 2px;
    font-size: 0.63rem;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
}
.rpt-cal-evt-name { overflow: hidden; text-overflow: ellipsis; flex: 1; }
.rpt-cal-evt-amt  { flex-shrink: 0; font-weight: 700; }

/* Colors chosen so white .rpt-cal-evt text reaches 4.5:1 contrast (WCAG AA) */
.rpt-cal-evt--income { background: #047857; }
.rpt-cal-evt--bill   { background: #92400e; }
.rpt-cal-evt--expense { background: #7c3aed; }
.rpt-cal-evt--recurring { background: #0e7490; }
.rpt-cal-evt--bonus  { background: #b45309; }
.rpt-cal-evt--debt-dynamic { background: var(--debt-color, #2563eb); }

/* Day-detail modal event list (full names/amounts, opened by tapping a day) */
.rpt-cal-modal-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
    max-height: 60vh;
    overflow-y: auto;
}
.rpt-cal-modal-evt {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    border-radius: 6px;
    padding: 8px 12px;
    color: #fff;
    font-size: 0.9rem;
}
.rpt-cal-modal-evt .rpt-cal-evt-amt { font-weight: 700; }

/* Net worth reports panel */
.nw-report-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}

.nw-report-header h3 {
    margin: 0;
    font-size: 1.2rem;
}

.nw-report-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.nw-range-buttons {
    display: inline-flex;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.nw-range-btn {
    border: none;
    background: var(--card-bg);
    color: var(--text-primary);
    padding: 6px 10px;
    font-weight: 700;
    cursor: pointer;
}

.nw-range-btn + .nw-range-btn {
    border-left: 1px solid var(--border-color);
}

.nw-range-btn.active {
    background: #2563eb;
    color: #fff;
}

.nw-report-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.nw-report-stat {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px 12px;
}

.nw-report-stat span {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.nw-report-stat strong {
    font-size: 1.03rem;
    color: var(--text-primary);
}

.nw-history-card {
    margin-top: 14px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 12px;
}

.nw-history-table-wrap {
    overflow-x: auto;
}

.nw-history-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 680px;
}

.nw-history-table th,
.nw-history-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--border-color);
    text-align: right;
    font-size: 0.86rem;
    color: var(--text-primary);
}

.nw-history-table th:first-child,
.nw-history-table td:first-child {
    text-align: left;
}

.nw-history-table th {
    font-size: 0.76rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--text-muted);
    background: var(--light-bg);
    position: sticky;
    top: 0;
}

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

/* Narrow report tables (Summary Report cash flow / account balances / net
   worth): the shared min-width above exists for wide multi-column tables
   (Net Worth History, Cash Flow Forecast) and just forces an unnecessary
   horizontal scroll on tables that don't need it, so opt them out and
   restack them into label/value cards below the mobile breakpoint. */
.nw-history-table--compact {
    min-width: 0;
}

@media (max-width: 640px) {
    .nw-history-table--compact thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .nw-history-table--compact,
    .nw-history-table--compact tbody,
    .nw-history-table--compact tr,
    .nw-history-table--compact td {
        display: block;
        width: 100%;
    }

    .nw-history-table--compact tr {
        margin-bottom: 8px;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 2px 10px;
    }

    .nw-history-table--compact tr:last-child {
        margin-bottom: 0;
    }

    .nw-history-table--compact td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
        text-align: right;
        border-bottom: 1px solid var(--border-color);
    }

    .nw-history-table--compact td:last-child {
        border-bottom: none;
    }

    .nw-history-table--compact td::before {
        content: attr(data-label);
        text-align: left;
        font-size: 0.76rem;
        letter-spacing: 0.03em;
        text-transform: uppercase;
        color: var(--text-muted);
        font-weight: 600;
    }

    .nw-history-table--compact td:first-child {
        justify-content: flex-start;
        text-align: left;
        font-weight: 700;
    }

    .nw-history-table--compact td:first-child::before {
        content: none;
    }
}

/* Cash Flow Forecast controls */
.cf-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    margin-bottom: 14px;
}

.cf-control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.cf-control-label {
    font-size: 0.82rem;
    color: var(--text-muted);
    font-weight: 600;
}

.cf-threshold-input {
    width: 70px;
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--card-bg);
    color: var(--text-primary);
}

.cf-control-suffix {
    font-size: 0.82rem;
    color: var(--text-muted);
}

/* Negative-balance warning banner */
.cf-warning-banner {
    background: rgba(220, 38, 38, 0.08);
    border: 1px solid #dc2626;
    color: #dc2626;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 0.9rem;
}

body.dark-mode .cf-warning-banner {
    color: #f87171;
    border-color: #f87171;
    background: rgba(248, 113, 113, 0.08);
}

/* Forecast table row highlighting */
.cf-row--negative td {
    background: rgba(220, 38, 38, 0.06);
}

body.dark-mode .cf-row--negative td {
    background: rgba(248, 113, 113, 0.08);
}

.cf-notable-row td {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-style: italic;
    text-align: left;
    padding-top: 2px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

@media (max-width: 640px) {
    .rpt-cal-cell     { min-height: 44px; }
    .rpt-tab-bar      { flex-wrap: nowrap; overflow-x: auto; gap: 8px; }
    .rpt-tab-group-sep { display: none; }
    .rpt-tab-btn      { font-size: 11px; padding: 7px 10px; }
    .rpt-moneyflow-wrap { height: 260px; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   VARIANCE DASHBOARD (What Changed Report)
   ═══════════════════════════════════════════════════════════════════════════ */

.var-container {
    padding: 0;
}

.var-title {
    margin: 0 0 4px;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
}

.var-subtitle {
    margin: 0 0 20px;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.var-table {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 24px;
}

.var-header {
    display: grid;
    grid-template-columns: 2fr 1.4fr 1.4fr 1fr;
    gap: 16px;
    padding: 14px 16px;
    background: var(--primary-color);
    color: #fff;
    font-weight: 700;
    font-size: 0.92rem;
    border-bottom: 2px solid var(--primary-color);
}

.var-label-col { text-align: left; }
.var-period-col { text-align: center; }
.var-delta-col { text-align: right; padding-right: 12px; }

.var-row {
    display: grid;
    grid-template-columns: 2fr 1.4fr 1.4fr 1fr;
    gap: 16px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-color);
    align-items: center;
}

.var-row:last-child {
    border-bottom: none;
}

body.dark-mode .var-row:hover {
    background: rgba(255, 255, 255, 0.03);
}

body.light .var-row:hover {
    background: rgba(0, 0, 0, 0.02);
}

.var-label {
    font-weight: 600;
    font-size: 0.98rem;
}

.var-prev, .var-curr {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.var-small-label {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.var-value {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
}

.var-delta-cell {
    text-align: right;
    padding-right: 12px;
}

.var-delta {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.9rem;
}

.var-delta--pos {
    background: #dcfce7;
    color: #166534;
}

body.dark-mode .var-delta--pos {
    background: #064e3b;
    color: #86efac;
}

.var-delta--neg {
    background: #fee2e2;
    color: #991b1b;
}

body.dark-mode .var-delta--neg {
    background: #7f1d1d;
    color: #fca5a5;
}

/* Summary section */
.var-summary {
    background: var(--light-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 16px;
}

.var-summary-row {
    display: grid;
    grid-template-columns: 2fr 1.4fr 1.4fr 1fr;
    gap: 16px;
    align-items: center;
}

.var-summary-label {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}

.var-summary-prev, .var-summary-curr {
    text-align: center;
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary);
}

.var-summary-delta {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 0.95rem;
    text-align: right;
}

.var-summary-delta.var-delta--pos {
    background: #dcfce7;
    color: #166534;
}

body.dark-mode .var-summary-delta.var-delta--pos {
    background: #064e3b;
    color: #86efac;
}

.var-summary-delta.var-delta--neg {
    background: #fee2e2;
    color: #991b1b;
}

body.dark-mode .var-summary-delta.var-delta--neg {
    background: #7f1d1d;
    color: #fca5a5;
}

@media (max-width: 768px) {
    .var-header,
    .var-row,
    .var-summary-row {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    
    .var-label-col, .var-period-col, .var-delta-col {
        text-align: left;
    }
    
    .var-small-label {
        display: inline;
        margin-right: 8px;
    }
    
    .var-header {
        display: none;
    }
    
    .var-row::before {
        content: attr(data-label);
        font-weight: 700;
        display: block;
    }
}

/* ═══════════════════════════════════════════════════════════════════════════
   ACCOUNTS PAGE
   ═══════════════════════════════════════════════════════════════════════════ */

.accounts-intro {
    margin: 0 0 20px;
    color: var(--text-muted);
    font-size: 0.92rem;
    max-width: 700px;
}

/* ── Add Account form card ─────────────────────────────────────────────── */
.account-form-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 22px 22px 18px;
    margin-bottom: 26px;
}
.account-form-card h3 { margin: 0 0 16px; font-size: 1rem; font-weight: 700; }
.account-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px 20px;
    margin-bottom: 16px;
}

/* ── Account card ──────────────────────────────────────────────────────── */
.acct-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px 18px;
    margin-bottom: 12px;
    transition: border-color 0.15s;
}
.acct-card:hover { border-color: var(--primary-color); }
.acct-card--editing { border-color: var(--primary-color); background: var(--light-bg); }

.acct-card-header {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.acct-type-icon { font-size: 1.6rem; flex-shrink: 0; }
.acct-card-info { flex: 1; min-width: 120px; }
.acct-card-name { display: block; font-weight: 700; font-size: 1rem; }
.acct-type-badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    background: #e0e7ff;
    color: #3730a3;
    margin-top: 2px;
}
body.dark-mode .acct-type-badge { background: #1e1b4b; color: #a5b4fc; }

.acct-rate-badge {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 12px;
    background: #d1fae5;
    color: #065f46;
    margin-top: 2px;
    margin-left: 6px;
    white-space: nowrap;
}
body.dark-mode .acct-rate-badge { background: #064e3b; color: #6ee7b7; }

.retire-cards { display: flex; flex-direction: column; gap: 16px; }
.retire-card { background: var(--card-bg); border: 1px solid var(--border-color); border-radius: 12px; padding: 16px; }
.retire-card-header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.retire-stat { display: flex; flex-direction: column; margin-left: auto; }
.retire-target-date-row { max-width: 260px; margin-bottom: 20px; }
.retire-snapshot-table { width: 100%; border-collapse: collapse; }
.retire-snapshot-table th, .retire-snapshot-table td { padding: 6px 10px; text-align: left; border-bottom: 1px solid var(--border-color); font-size: 0.85rem; }
.retire-empty-msg { text-align: center; color: var(--text-muted); padding: 24px 0; }
.retire-pension-meta { display: flex; gap: 20px; flex-wrap: wrap; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 10px; padding: 6px 0; border-bottom: 1px solid var(--border-color); }

.acct-balances {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}
.acct-balance-item { display: flex; flex-direction: column; align-items: flex-end; }
.acct-balance-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.acct-balance-value { font-size: 1rem; font-weight: 700; }
.acct-balance--pos { color: #059669; }
.acct-balance--neg { color: #dc2626; }
body.dark-mode .acct-balance--pos { color: #34d399; }
body.dark-mode .acct-balance--neg { color: #f87171; }

/* ── Linked-item chips ─────────────────────────────────────────────────── */
.acct-links {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}
.acct-link {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 20px;
    white-space: nowrap;
}
.acct-link--income  { background: #d1fae5; color: #065f46; }
.acct-link--bonus   { background: #fef3c7; color: #92400e; }
.acct-link--debt    { background: #fee2e2; color: #7f1d1d; }
.acct-link--bill    { background: #fffbeb; color: #78350f; }
.acct-link--exp     { background: #f5f3ff; color: #4c1d95; }
body.dark-mode .acct-link--income  { background: #064e3b; color: #6ee7b7; }
body.dark-mode .acct-link--bonus   { background: #451a03; color: #fcd34d; }
body.dark-mode .acct-link--debt    { background: #450a0a; color: #fca5a5; }
body.dark-mode .acct-link--bill    { background: #1c1400; color: #fcd34d; }
body.dark-mode .acct-link--exp     { background: #1e1b4b; color: #c4b5fd; }
/* ── Account replacement modal ─────────────────────────────────────────── */
.account-replacement-links {
    margin: 0.5rem 0 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}
.acct-replacement-group {
    font-size: 0.875rem;
    color: var(--text-secondary, #6b7280);
    padding: 0.25rem 0.5rem;
    background: var(--surface-secondary, #f9fafb);
    border-radius: 4px;
}
body.dark-mode .acct-replacement-group {
    background: var(--surface-secondary, #1f2937);
}

/* ── Inline edit grid ──────────────────────────────────────────────────── */
.acct-edit-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 12px 16px;
    margin-bottom: 12px;
}
.acct-edit-actions { display: flex; gap: 8px; }

/* ── Empty state ───────────────────────────────────────────────────────── */
.acct-empty-msg {
    text-align: center;
    padding: 36px 20px;
    color: var(--text-muted);
    font-size: 0.95rem;
    border: 2px dashed var(--border-color);
    border-radius: 10px;
}

/* ── Money Flow per-account table ─────────────────────────────────────── */
.acct-mf-section {
    margin-top: 32px;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
}
.acct-mf-title {
    margin: 0;
    padding: 14px 18px 0;
    font-size: 1rem;
    font-weight: 700;
}
.acct-mf-section .rpt-chart-sub { padding: 4px 18px 10px; }
.acct-mf-header,
.acct-mf-row {
    display: grid;
    grid-template-columns: 28px 1fr 100px 110px 110px 100px;
    align-items: center;
    padding: 8px 18px;
    gap: 8px;
    font-size: 0.85rem;
}
.acct-mf-header {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--light-bg);
    border-bottom: 1px solid var(--border-color);
}
.acct-mf-row { border-bottom: 1px solid var(--border-color); }
.acct-mf-row:last-child { border-bottom: none; }
.acct-mf-icon { font-size: 1.1rem; }
.acct-mf-name { font-weight: 600; }
.acct-mf-type { color: var(--text-muted); font-size: 0.78rem; }
.acct-mf-start, .acct-mf-proj { font-weight: 600; text-align: right; }
.acct-mf-diff { font-weight: 700; text-align: right; }
.acct-mf-diff--pos { color: #059669; }
.acct-mf-diff--neg { color: #dc2626; }
body.dark-mode .acct-mf-diff--pos { color: #34d399; }
body.dark-mode .acct-mf-diff--neg { color: #f87171; }

@media (max-width: 700px) {
    .acct-mf-header {
        display: none;
    }
    .acct-mf-row {
        grid-template-columns: 1fr;
        gap: 4px;
        padding: 10px 18px;
    }
    .acct-mf-icon {
        display: none;
    }
    .acct-mf-name {
        font-weight: 700;
    }
    .acct-mf-type,
    .acct-mf-start,
    .acct-mf-proj,
    .acct-mf-diff {
        display: flex;
        justify-content: space-between;
        text-align: left;
    }
    .acct-mf-type::before,
    .acct-mf-start::before,
    .acct-mf-proj::before,
    .acct-mf-diff::before {
        content: attr(data-label);
        font-size: 0.72rem;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-muted);
    }
    .acct-edit-grid { grid-template-columns: 1fr 1fr; }
    .acct-card-header { gap: 10px; }
}
@media (max-width: 480px) {
    .acct-edit-grid { grid-template-columns: 1fr; }
}


/* ═══════════════════════════════════════════════════════════════════════════
   RECURRING TRANSACTION TEMPLATES
   ═══════════════════════════════════════════════════════════════════════════ */

.recurring-section {
    background: var(--card-bg, #fff);
    border-radius: 12px;
    padding: 28px 24px 32px;
    margin-bottom: 40px;
}
.recurring-section h2 {
    color: var(--primary-color);
    font-size: 1.4rem;
    margin-bottom: 6px;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 8px;
}
.recurring-intro {
    color: var(--text-muted, #6b7280);
    font-size: 0.92rem;
    margin: 0 0 20px;
}

/* ── Add-template form card ─────────────────────────────────────────────── */
.recurring-form-card {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 10px;
    margin-bottom: 24px;
    overflow: hidden;
}
body.dark-mode .recurring-form-card {
    background: #1e293b;
    border-color: #334155;
}
.recurring-form-toggle {
    width: 100%;
    background: #f8fafc;
    border: none;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    font-size: 0.97rem;
    cursor: pointer;
    color: var(--primary-color);
    transition: background 0.15s;
}
body.dark-mode .recurring-form-toggle {
    background: #1e293b;
    color: #93c5fd;
}
.recurring-form-toggle:hover { background: #e0e7ff; }
body.dark-mode .recurring-form-toggle:hover { background: #1e3a5f; }
.recurring-form-toggle-chevron {
    transition: transform 0.2s;
}
.recurring-form-toggle--open .recurring-form-toggle-chevron {
    transform: rotate(180deg);
}
.recurring-form-body {
    padding: 18px 18px 20px;
}
.recurring-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px 16px;
    margin-bottom: 16px;
}

/* ── Template cards ─────────────────────────────────────────────────────── */
.recurring-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.recurring-empty-msg {
    color: var(--text-muted, #6b7280);
    font-style: italic;
    text-align: center;
    padding: 24px 0;
}
.recurring-card {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 10px;
    padding: 16px 18px 14px;
    transition: box-shadow 0.18s, opacity 0.18s;
}
body.dark-mode .recurring-card {
    background: #1e293b;
    border-color: #334155;
}
.recurring-card:hover { box-shadow: 0 2px 10px rgba(0,0,0,0.09); }
.recurring-card--paused { opacity: 0.6; }
.recurring-card--editing {
    border-color: var(--primary-color);
    background: #f0f4ff;
}
body.dark-mode .recurring-card--editing { background: #172041; }

.recurring-card-header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 8px;
}
.recurring-type-icon { font-size: 1.4rem; line-height: 1; flex-shrink: 0; }
.recurring-card-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}
.recurring-card-name {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-primary, #111827);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
body.dark-mode .recurring-card-name { color: #f1f5f9; }
.recurring-type-label {
    font-size: 0.78rem;
    color: var(--text-muted, #6b7280);
    margin-top: 2px;
}
.recurring-card-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    flex-shrink: 0;
}
.recurring-amount {
    font-size: 1.05rem;
    font-weight: 700;
}
.recurring-amount--pos { color: #059669; }
.recurring-amount--neg { color: #dc2626; }
body.dark-mode .recurring-amount--pos { color: #34d399; }
body.dark-mode .recurring-amount--neg { color: #f87171; }
.recurring-freq-badge {
    font-size: 0.72rem;
    background: #e0e7ff;
    color: #3730a3;
    border-radius: 999px;
    padding: 2px 8px;
    font-weight: 600;
}
body.dark-mode .recurring-freq-badge { background: #1e3a5f; color: #93c5fd; }

.recurring-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-bottom: 8px;
}
.recurring-meta-item {
    font-size: 0.8rem;
    color: var(--text-muted, #6b7280);
}

.recurring-card-status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.recurring-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 999px;
    padding: 2px 10px;
}
.recurring-badge--active  { background: #d1fae5; color: #065f46; }
.recurring-badge--paused  { background: #fef3c7; color: #92400e; }
.recurring-badge--skipped { background: #e0f2fe; color: #075985; }
.recurring-badge--pending { background: #f3f4f6; color: #6b7280; }
body.dark-mode .recurring-badge--active  { background: #064e3b; color: #6ee7b7; }
body.dark-mode .recurring-badge--paused  { background: #451a03; color: #fcd34d; }
body.dark-mode .recurring-badge--skipped { background: #0c4a6e; color: #7dd3fc; }
body.dark-mode .recurring-badge--pending { background: #1f2937; color: #9ca3af; }
.recurring-badge--paid { background: #dbeafe; color: #1e40af; }
body.dark-mode .recurring-badge--paid { background: #1e3a5f; color: #93c5fd; }
.recurring-this-month {
    font-size: 0.8rem;
    color: var(--text-muted, #6b7280);
}
.recurring-this-month strong { color: var(--text-primary, #111827); }
body.dark-mode .recurring-this-month strong { color: #f1f5f9; }

.recurring-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

/* ── Inline edit grid ───────────────────────────────────────────────────── */
.recurring-edit-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 10px 16px;
    margin-bottom: 14px;
}
.recurring-edit-field label {
    font-size: 0.8rem;
    font-weight: 600;
    display: block;
    margin-bottom: 3px;
    color: var(--text-muted, #6b7280);
}
.recurring-edit-field input,
.recurring-edit-field select {
    width: 100%;
}
.recurring-edit-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

@media (max-width: 600px) {
    .recurring-form-grid { grid-template-columns: 1fr; }
    .recurring-edit-grid { grid-template-columns: 1fr 1fr; }
    .recurring-card-header { flex-wrap: wrap; }
}
@media (max-width: 480px) {
    .recurring-edit-grid { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════════════════════
   SAVINGS PAGE — Emergency Fund & Sinking Funds
   ═══════════════════════════════════════════════════════════════ */

.savings-section { background: var(--card-bg, #fff); border-radius: 12px; box-shadow: 0 1px 6px rgba(0,0,0,0.07); padding: 28px 24px 32px 24px; margin-bottom: 40px; }
.savings-section h2 { color: var(--primary-color); font-size: 1.4rem; margin-bottom: 18px; border-bottom: 2px solid var(--primary-color); padding-bottom: 8px; }
.section-description { color: var(--text-muted, #6b7280); font-size: 0.92rem; margin: 0 0 20px; }

.savings-subtabs { display: flex; gap: 8px; margin-bottom: 20px; border-bottom: 2px solid #e5e7eb; }
body.dark-mode .savings-subtabs { border-bottom-color: #334155; }
.savings-subtab-btn { background: none; border: none; padding: 10px 16px; font-size: 0.95rem; font-weight: 600; cursor: pointer; color: #6b7280; border-bottom: 3px solid transparent; transition: all 0.15s; }
body.dark-mode .savings-subtab-btn { color: #cbd5e1; }
.savings-subtab-btn.active { color: var(--primary-color); border-bottom-color: var(--primary-color); }
.savings-subtab-btn:hover { color: var(--primary-color); }

/* ═════════════════════════════════════════════════════════════ */
/* Liabilities Subtabs (Debts & Expenses)                        */
/* ═════════════════════════════════════════════════════════════ */
.liabilities-subtabs { display: flex; gap: 8px; margin-bottom: 20px; border-bottom: 2px solid #e5e7eb; }
body.dark-mode .liabilities-subtabs { border-bottom-color: #334155; }
.liabilities-subtab-btn { background: none; border: none; padding: 10px 16px; font-size: 0.95rem; font-weight: 600; cursor: pointer; color: #6b7280; border-bottom: 3px solid transparent; transition: all 0.15s; }
body.dark-mode .liabilities-subtab-btn { color: #cbd5e1; }
.liabilities-subtab-btn.active { color: var(--primary-color); border-bottom-color: var(--primary-color); }
.liabilities-subtab-btn:hover { color: var(--primary-color); }
.liabilities-subtab-panel { display: none; }


/* Emergency Fund Form & Card */
.emergency-form-card { background: var(--card-bg, #fff); border: 1px solid var(--border-color, #e5e7eb); border-radius: 10px; margin-bottom: 24px; overflow: hidden; }
body.dark-mode .emergency-form-card { background: #1e293b; border-color: #334155; }
.emergency-form-toggle { width: 100%; background: #f8fafc; border: none; padding: 14px 18px; font-weight: 600; font-size: 0.97rem; cursor: pointer; color: var(--primary-color); transition: background 0.15s; }
body.dark-mode .emergency-form-toggle { background: #1e293b; color: #93c5fd; }
.emergency-form-toggle:hover { background: #e0e7ff; }
body.dark-mode .emergency-form-toggle:hover { background: #1e3a5f; }
.emergency-form-body { padding: 18px 18px 20px; }
.emergency-form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 16px; margin-bottom: 16px; }
.emergency-form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.emergency-list { display: flex; flex-direction: column; gap: 14px; }
.emergency-card { background: var(--card-bg, #fff); border: 1px solid var(--border-color, #e5e7eb); border-radius: 10px; padding: 16px 18px; }
body.dark-mode .emergency-card { background: #1e293b; border-color: #334155; }
.emergency-card:hover { box-shadow: 0 2px 10px rgba(0,0,0,0.09); }
.emergency-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.emergency-account { font-weight: 700; color: #1e293b; font-size: 1rem; }
body.dark-mode .emergency-account { color: #f1f5f9; }
.emergency-target { font-size: 0.85rem; color: #6b7280; margin-top: 2px; }
body.dark-mode .emergency-target { color: #cbd5e1; }
.emergency-badge { padding: 4px 8px; border-radius: 4px; font-weight: 700; font-size: 0.8rem; }
.badge-complete { background: #d1fae5; color: #065f46; }
body.dark-mode .badge-complete { background: #064e3b; color: #86efac; }
.badge-excellent { background: #dbeafe; color: #0c4a6e; }
body.dark-mode .badge-excellent { background: #082f49; color: #7dd3fc; }
.badge-good { background: #fef3c7; color: #92400e; }
body.dark-mode .badge-good { background: #451a03; color: #fcd34d; }
.badge-warning { background: #fee2e2; color: #991b1b; }
body.dark-mode .badge-warning { background: #7f1d1d; color: #fca5a5; }
.progress-bar { height: 8px; border-radius: 4px; background: #e5e7eb; overflow: hidden; margin: 10px 0; }
body.dark-mode .progress-bar { background: #334155; }
.progress-fill { height: 100%; border-radius: 4px; background: linear-gradient(90deg, #2563eb, #059669); transition: width 0.4s ease; width: var(--progress-width, 0%); }
.emergency-card-details { margin: 12px 0; }
.detail-row { display: flex; justify-content: space-between; font-size: 0.88rem; padding: 4px 0; color: #4b5563; }
body.dark-mode .detail-row { color: #cbd5e1; }
.emergency-card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }

/* Sinking Funds Form & Card */
.sinking-form-card { background: var(--card-bg, #fff); border: 1px solid var(--border-color, #e5e7eb); border-radius: 10px; margin-bottom: 24px; overflow: hidden; }
body.dark-mode .sinking-form-card { background: #1e293b; border-color: #334155; }
.sinking-form-toggle { width: 100%; background: #f8fafc; border: none; padding: 14px 18px; font-weight: 600; font-size: 0.97rem; cursor: pointer; color: var(--primary-color); transition: background 0.15s; }
body.dark-mode .sinking-form-toggle { background: #1e293b; color: #93c5fd; }
.sinking-form-toggle:hover { background: #e0e7ff; }
body.dark-mode .sinking-form-toggle:hover { background: #1e3a5f; }
.sinking-form-body { padding: 18px 18px 20px; }
.sinking-form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 16px; margin-bottom: 16px; }
.sinking-form-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

.sinking-list { display: flex; flex-direction: column; gap: 14px; }
.sinking-card { background: var(--card-bg, #fff); border: 1px solid var(--border-color, #e5e7eb); border-radius: 10px; padding: 16px 18px; }
body.dark-mode .sinking-card { background: #1e293b; border-color: #334155; }
.sinking-card:hover { box-shadow: 0 2px 10px rgba(0,0,0,0.09); }
.sinking-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; }
.sinking-name { font-weight: 700; color: #1e293b; font-size: 1rem; }
body.dark-mode .sinking-name { color: #f1f5f9; }
.sinking-account { font-size: 0.82rem; color: #6b7280; margin-top: 2px; }
body.dark-mode .sinking-account { color: #cbd5e1; }
.sinking-badge { padding: 4px 8px; border-radius: 4px; font-weight: 700; font-size: 0.8rem; }
.sinking-card-details { margin: 12px 0; }
.sinking-card-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 12px; }
.empty-message { color: #9ca3af; font-style: italic; text-align: center; padding: 24px 0; font-size: 0.9rem; }

@media (max-width: 768px) {
    .emergency-form-grid { grid-template-columns: 1fr; }
    .sinking-form-grid { grid-template-columns: 1fr; }
    .emergency-form-actions { justify-content: flex-start; }
    .sinking-form-actions { justify-content: flex-start; }
}

/* App Footer */
.app-footer {
    text-align: center;
    padding: 12px 0 8px;
    font-size: 0.75rem;
    color: #6b7280;
    border-top: 1px solid var(--border-color, #e5e7eb);
    margin-top: 24px;
    user-select: none;
}
body.dark-mode .app-footer {
    color: #94a3b8;
    border-top-color: #334155;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Financial Health Dashboard
   ═══════════════════════════════════════════════════════════════════════════ */

.health-section { padding: 0; }

.health-header { margin-bottom: 1.25rem; }
.health-header h2 { font-size: 1.4rem; font-weight: 700; color: var(--text-primary); margin: 0 0 0.2rem; }
.health-subtitle { color: var(--text-secondary); font-size: 0.85rem; margin: 0; }

.health-metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}
@media (max-width: 680px) {
    .health-metrics-grid { grid-template-columns: 1fr; }
}

.health-metric-card {
    background: var(--card-bg, #fff);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.1rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    box-shadow: var(--shadow);
}

.health-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    flex-wrap: wrap;
}
.health-card-title { font-weight: 600; font-size: 0.9rem; color: var(--text-primary); }
.health-card-desc  { font-size: 0.78rem; color: var(--text-secondary); margin: 0; line-height: 1.45; }

/* Badges */
.health-badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    white-space: nowrap;
    flex-shrink: 0;
}
.health-badge--sm { font-size: 0.68rem; padding: 0.15rem 0.45rem; }

.health-status--green  { background: #dcfce7; color: #15803d; }
.health-status--yellow { background: #fef9c3; color: #a16207; }
.health-status--orange { background: #ffedd5; color: #c2410c; }
.health-status--red    { background: #fee2e2; color: #b91c1c; }
body.dark-mode .health-status--green  { background: #14532d; color: #86efac; }
body.dark-mode .health-status--yellow { background: #422006; color: #fde68a; }
body.dark-mode .health-status--orange { background: #431407; color: #fdba74; }
body.dark-mode .health-status--red    { background: #450a0a; color: #fca5a5; }

/* Colored progress fills for health cards */
.health-fill--green  { background: #16a34a !important; }
.health-fill--yellow { background: #d97706 !important; }
.health-fill--red    { background: #dc2626 !important; }

/* Utilization-specific progress fill colors (4-tier: green/yellow/orange/red) */
.util-fill--green  { background: #16a34a !important; }
.util-fill--yellow { background: #d97706 !important; }
.util-fill--orange { background: #ea580c !important; }
.util-fill--red    { background: #dc2626 !important; }

/* Credit utilization detail line inside debt card */
.debt-util-badge { font-size: 0.75rem; }
.debt-util-detail { font-size: 0.75rem; color: var(--text-muted, #64748b); margin-top: 0.15rem; }

/* Compact progress bar variant */
.health-compact-bar { height: 6px !important; margin: 4px 0 !important; }

/* Gauge */
.health-gauge-wrap {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 130px;
    height: 130px;
    margin: 0 auto;
}
.health-gauge-canvas { width: 130px !important; height: 130px !important; }
.health-gauge-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -46%);
    text-align: center;
    pointer-events: none;
}
.health-gauge-value { display: block; font-size: 1.4rem; font-weight: 700; color: var(--text-primary); line-height: 1; }
.health-gauge-label { display: block; font-size: 0.65rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }

/* Detail row */
.health-metric-detail { display: flex; justify-content: space-between; font-size: 0.76rem; color: var(--text-secondary); }

/* Emergency Fund rows */
.health-ef-row   { display: flex; flex-direction: column; gap: 0.2rem; }
.health-ef-header { display: flex; justify-content: space-between; align-items: center; }
.health-ef-name  { font-size: 0.83rem; font-weight: 500; color: var(--text-primary); }
.health-ef-detail { font-size: 0.73rem; color: var(--text-secondary); }

/* Timeline */
.health-timeline-hero { display: flex; align-items: baseline; gap: 0.3rem; padding: 0.3rem 0; }
.health-timeline-value { font-size: 2.4rem; font-weight: 800; color: var(--text-primary); line-height: 1; }
.health-timeline-unit  { font-size: 0.95rem; color: var(--text-secondary); }
.health-timeline-date  { font-size: 0.78rem; color: var(--text-secondary); }
.health-progress-label { display: flex; justify-content: space-between; font-size: 0.76rem; color: var(--text-secondary); }

/* Cash flow */
.health-cashflow-hero {
    font-size: 1.8rem;
    font-weight: 800;
    text-align: center;
    padding: 0.5rem;
    border-radius: 8px;
    line-height: 1.1;
}
.health-cashflow-hero--positive { color: #16a34a; background: #f0fdf4; }
.health-cashflow-hero--negative { color: #dc2626; background: #fef2f2; }
body.dark-mode .health-cashflow-hero--positive { color: #4ade80; background: #14532d; }
body.dark-mode .health-cashflow-hero--negative { background: #450a0a; }

.health-cashflow-rows  { display: flex; flex-direction: column; gap: 0.3rem; }
.health-cashflow-row   { display: flex; justify-content: space-between; font-size: 0.8rem; color: var(--text-secondary); }
.health-cashflow-row--total {
    border-top: 1px solid var(--border-color);
    padding-top: 0.3rem;
    font-weight: 600;
    color: var(--text-primary);
}
.health-cf-income  { color: #15803d; font-weight: 500; }
.health-cf-out     { color: var(--text-secondary); }
.health-cf-deficit { color: #dc2626; font-weight: 600; }
body.dark-mode .health-cf-income { color: #4ade80; }

/* Budget allocation */
.health-budget-row     { display: flex; flex-direction: column; gap: 0.15rem; }
.health-budget-cat-hd  { display: flex; justify-content: space-between; align-items: center; }
.health-budget-cat-name { font-size: 0.8rem; color: var(--text-primary); }
.health-budget-cat-amt  { font-size: 0.7rem; color: var(--text-secondary); }

/* Empty state */
.health-empty-state  { display: flex; flex-direction: column; align-items: center; padding: 0.75rem; gap: 0.2rem; }
.health-empty-value  { font-size: 1.6rem; font-weight: 700; color: var(--text-primary); }
.health-empty--green { color: #16a34a; }
.health-empty-sub    { font-size: 0.78rem; color: var(--text-secondary); text-align: center; }

/* Nav links */
.health-link { font-size: 0.76rem; color: var(--primary-color); text-decoration: none; cursor: pointer; margin-top: auto; display: inline-block; }
.health-link:hover { text-decoration: underline; }
body.dark-mode .health-link { color: #60a5fa; }

/* ── Account Reconciliation ── */
.recon-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px 18px;
    margin-bottom: 16px;
}
.recon-card-header {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.recon-card-info { flex: 1; min-width: 120px; }
.recon-current-balance { display: block; font-size: 0.85rem; color: var(--text-secondary); }

.recon-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.recon-diff-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    font-weight: 600;
}
.recon-diff-label { color: var(--text-secondary); font-weight: 500; }
.recon-diff--pos  { color: var(--success-color); }
.recon-diff--neg  { color: var(--danger-color); }
.recon-diff--zero { color: var(--text-secondary); }

.recon-expected { margin-top: 12px; }
.recon-expected summary { cursor: pointer; color: var(--primary-color); font-size: 0.9rem; }
body.dark-mode .recon-expected summary { color: #60a5fa; }
.recon-expected-empty { font-size: 0.85rem; color: var(--text-secondary); margin: 8px 0 0; }
.recon-table-wrap { overflow-x: auto; }
.recon-expected-table { width: 100%; margin-top: 8px; border-collapse: collapse; font-size: 0.85rem; }
.recon-expected-table th, .recon-expected-table td {
    text-align: left;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border-color);
}

.recon-history-table { margin-top: 8px; }

.recon-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 999px;
    padding: 2px 10px;
    background: #e0f2fe;
    color: #075985;
}
body.dark-mode .recon-badge { background: #0c4a6e; color: #7dd3fc; }

/* ── Ledger: reconciliation marker rows ──────────────────────────────────── */
.ledger-row--reconciliation { font-style: italic; color: var(--text-secondary); }
.ledger-recon-diff { font-weight: 600; }

.ledger-recon-info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    margin-left: 6px;
    border-radius: 50%;
    background: var(--border-color);
    color: var(--text-secondary);
    font-size: 0.65rem;
    font-style: normal;
    font-weight: 700;
    line-height: 1;
    vertical-align: middle;
    cursor: help;
    user-select: none;
    transition: background 0.15s, color 0.15s;
}
.ledger-recon-info:hover,
.ledger-recon-info:focus { outline: none; background: var(--text-secondary); color: var(--card-bg); }

.ledger-recon-info--active {
    background: var(--primary-color);
    color: #fff;
}
.ledger-recon-info--active:hover,
.ledger-recon-info--active:focus { background: var(--primary-dark, var(--primary-color)); color: #fff; }

body.dark-mode .ledger-recon-info { background: #1e3a5f; color: #93c5fd; }
body.dark-mode .ledger-recon-info:hover,
body.dark-mode .ledger-recon-info:focus { background: #93c5fd; color: #0f172a; }
body.dark-mode .ledger-recon-info--active { background: #3b82f6; color: #fff; }
body.dark-mode .ledger-recon-info--active:hover,
body.dark-mode .ledger-recon-info--active:focus { background: #60a5fa; color: #0f172a; }

/* ── Settings ─────────────────────────────────────────────────────────────── */
.settings-toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    cursor: pointer;
}
.settings-toggle-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
}
body.dark-mode #settingsModal .modal-content {
    background: #1e293b;
    color: #f1f5f9;
    border: 1px solid #334155;
}
body.dark-mode #settingsModal .modal-close {
    color: #f1f5f9;
}
body.dark-mode #settingsModal .modal-helper-text {
    color: #94a3b8;
}
body.dark-mode #settingsModal .settings-toggle-row input[type="checkbox"] {
    accent-color: #60a5fa;
}

/* ── First-run setup wizard ───────────────────────────────────────────────── */
.setup-wizard-choices {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 18px;
}
.setup-wizard-choice {
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-align: left;
    background: var(--card-bg);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 14px 16px;
    cursor: pointer;
    color: var(--text-primary, #1e293b);
}
.setup-wizard-choice:hover,
.setup-wizard-choice:focus-visible {
    border-color: var(--primary-color);
}
.setup-wizard-choice span {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* ── Spending Analysis ───────────────────────────────────────────────────── */
.spending-summary-strip {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    font-size: 1rem;
    color: var(--text-primary, #1e293b);
}
.spending-change-badge {
    font-size: 0.78rem;
    font-weight: 600;
    padding: 3px 9px;
    border-radius: 9999px;
}
.spending-badge--up   { background: #fee2e2; color: #b91c1c; }
.spending-badge--down { background: #dcfce7; color: #15803d; }
body.dark-mode .spending-badge--up   { background: #450a0a; color: #fca5a5; }
body.dark-mode .spending-badge--down { background: #052e16; color: #86efac; }

.spending-hero-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 28px;
    align-items: start;
}
.spending-pie-wrap { position: relative; height: 280px; }

.spending-ranked-list { display: flex; flex-direction: column; gap: 6px; }
.spending-ranked-row {
    display: grid;
    grid-template-columns: 28px 1fr auto auto;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #f8fafc;
    cursor: pointer;
    transition: background 0.15s;
    border: none;
}
body.dark-mode .spending-ranked-row { background: #1e293b; }
.spending-ranked-row:hover { background: #f1f5f9; }
body.dark-mode .spending-ranked-row:hover { background: #334155; }
.spending-ranked-rank  { font-weight: 700; color: #64748b; font-size: 0.85rem; }
.spending-ranked-name  { font-weight: 500; color: #1e293b; }
.spending-ranked-total { font-weight: 700; color: #1e293b; }
body.dark-mode .spending-ranked-name,
body.dark-mode .spending-ranked-total { color: #e2e8f0; }
.spending-ranked-change--up   { font-size: 0.78rem; font-weight: 600; color: #b91c1c; }
.spending-ranked-change--down { font-size: 0.78rem; font-weight: 600; color: #15803d; }
body.dark-mode .spending-ranked-change--up   { color: #fca5a5; }
body.dark-mode .spending-ranked-change--down { color: #86efac; }

.spending-bar-section { margin-top: 8px; }
.spending-bar-title { font-size: 0.9rem; font-weight: 600; color: #1e293b; margin: 0 0 8px; }
body.dark-mode .spending-bar-title { color: #e2e8f0; }
.spending-bar-wrap { position: relative; height: 280px; }

.spending-empty {
    text-align: center;
    color: #64748b;
    padding: 48px 0;
    font-size: 0.95rem;
}

/* Spending drill-down modal */
.spending-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
}
.spending-modal-title    { font-size: 1.05rem; font-weight: 700; margin: 0 0 4px; }
.spending-modal-subtitle { font-size: 0.85rem; color: #64748b; margin: 0; }
.spending-modal-tx-list  {
    max-height: 320px;
    overflow-y: auto;
    border-top: 1px solid #e5e7eb;
    margin-bottom: 16px;
}
body.dark-mode .spending-modal-tx-list { border-top-color: #374151; }
.spending-modal-tx-row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    gap: 8px;
    padding: 9px 0;
    border-bottom: 1px solid #f1f5f9;
    align-items: center;
}
body.dark-mode .spending-modal-tx-row { border-bottom-color: #1e293b; }
.spending-modal-tx-name { font-weight: 500; color: #1e293b; }
body.dark-mode .spending-modal-tx-name { color: #e2e8f0; }
.spending-modal-tx-meta { font-size: 0.8rem; color: #64748b; }
.spending-modal-tx-amt--neg { color: #b91c1c; font-weight: 600; font-size: 0.9rem; }
body.dark-mode .spending-modal-tx-amt--neg { color: #fca5a5; }
.spending-modal-footer  { text-align: right; }
.spending-empty-detail  { text-align: center; color: #64748b; padding: 16px 0; }

/* var(--primary-color) is too dark against the dark-mode page background for
   small 10px text (WCAG 1.4.3 fails at ~3.45:1); use the lighter dark-mode
   link color already established elsewhere (body.dark-mode .health-link). */
body.dark-mode .rpt-tab-group-label { color: #60a5fa; }

@media (max-width: 640px) {
    .spending-hero-row    { grid-template-columns: 1fr; }
    .spending-pie-wrap    { height: 220px; }
}

/* ── Print stylesheet (Reports, Health, Accounts, Income pages) ─────────── */
@media print {
    header, nav.top-nav, .rpt-tab-bar,
    .rpt-month-btn, button, select, input, .nw-range-buttons,
    .filter-controls, .ledger-pagination {
        display: none !important;
    }
    .page-section { display: none !important; }
    .page-section.active { display: block !important; }
    .rpt-tab-panel { display: none !important; }
    .rpt-tab-panel.rpt-tab-panel--active { display: block !important; }
    .account-form-card, .income-form-card, .bonus-section, .health-link,
    .debts-form-card, .budget-form-card, .recurring-form-card,
    .emergency-form-card, .sinking-form-card,
    .strategy-controls, .target-date-panel,
    .recon-form-grid, .recon-expected {
        display: none !important;
    }
    body {
        background: white !important;
        color: black !important;
    }
    .rpt-chart-card, .nw-history-card, .acct-mf-section {
        border: 1px solid #ccc !important;
        box-shadow: none !important;
        page-break-inside: avoid;
    }
    .rpt-chart-canvas-wrap, .rpt-moneyflow-wrap {
        height: 320px !important;
    }
    .rpt-month-label {
        font-size: 1.2rem;
        font-weight: 700;
    }
}

/* ── Break-Even Analysis ───────────────────────────────────────── */
.break-even-section {
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color, #e5e7eb);
}
.break-even-header {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.4rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.break-even-toggle-row {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
    font-size: 0.8rem;
}
.break-even-toggle-row select,
.break-even-toggle-row input[type="number"] {
    font-size: 0.8rem;
    padding: 0.1rem 0.3rem;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 4px;
    background: var(--input-bg, #fff);
    color: var(--text-primary, #111827);
    width: 4.5rem;
}
.break-even-row {
    display: flex;
    gap: 0.5rem;
    font-size: 0.82rem;
    margin-bottom: 0.2rem;
    align-items: baseline;
}
.break-even-label {
    color: var(--text-secondary, #6b7280);
    min-width: 5.5rem;
    font-weight: 500;
}
.break-even-value {
    color: var(--text-primary, #111827);
}
.break-even-savings {
    margin-top: 0.4rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary, #6b7280);
}
.break-even-savings--positive {
    color: #15803d;
}
.break-even-no-plan-banner {
    font-size: 0.78rem;
    color: var(--text-secondary, #6b7280);
    background: var(--surface-muted, #f9fafb);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 6px;
    padding: 0.35rem 0.6rem;
    margin-bottom: 0.5rem;
}
.break-even-toggle-row .be-min-type,
.break-even-toggle-row .be-min-pct {
    border: 1px solid var(--border-color, #d1d5db);
    background: var(--input-bg, #fff);
    color: var(--text-primary, #111827);
    border-radius: 6px;
}
.break-even-chart-wrap {
    position: relative;
    height: 100px;
    margin-top: 0.5rem;
}
.break-even-show-btn {
    margin-top: 0.1rem;
    font-size: 0.8rem;
    padding: 0.28rem 0.62rem;
}
body.dark-mode .break-even-savings--positive,
body.dark-mode .be-col-saved,
body.dark-mode .accelerate-preview-delta {
    color: #4ade80;
}
body.dark-mode .break-even-no-plan-banner {
    color: #cbd5e1;
    background: #172235;
    border-color: #334155;
}
body.dark-mode .break-even-toggle-row .be-min-type,
body.dark-mode .break-even-toggle-row .be-min-pct {
    background: #0f172a;
    color: #f1f5f9;
    border-color: #334155;
}
.break-even-accelerate-btn {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    padding: 0.25rem 0.6rem;
}

/* ── Accelerate Modal ───────────────────────────────────────────── */
.accelerate-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.accelerate-modal-content {
    background: var(--card-bg, #fff);
    border-radius: 10px;
    padding: 1.5rem;
    width: min(420px, 92vw);
    position: relative;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.accelerate-modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-secondary, #6b7280);
    line-height: 1;
}
.accelerate-modal-close:hover { color: var(--text-primary, #111827); }
.accelerate-modal-content h3 {
    margin: 0 0 1rem;
    font-size: 1rem;
    font-weight: 600;
}
.accelerate-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.88rem;
    margin-bottom: 0.5rem;
}
.accelerate-row label {
    color: var(--text-secondary, #6b7280);
    font-weight: 500;
}
.accelerate-row input[type="number"] {
    width: 7rem;
    padding: 0.3rem 0.5rem;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 6px;
    font-size: 0.88rem;
    background: var(--input-bg, #fff);
    color: var(--text-primary, #111827);
}
.accelerate-divider {
    border: none;
    border-top: 1px solid var(--border-color, #e5e7eb);
    margin: 0.75rem 0;
}
.accelerate-total {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
}
.accelerate-preview {
    background: var(--surface-muted, #f9fafb);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    padding: 0.75rem;
    margin-bottom: 0.75rem;
}
.accelerate-preview-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    margin-bottom: 0.3rem;
}
.accelerate-preview-delta {
    font-size: 0.78rem;
    color: #15803d;
    font-weight: 600;
}
.accelerate-chart-wrap {
    position: relative;
    height: 120px;
    margin-bottom: 0.75rem;
}
.accelerate-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
}
body.dark-mode .accelerate-modal-content {
    background: #1e293b;
    color: #f1f5f9;
    border: 1px solid #334155;
    box-shadow: 0 12px 32px rgba(2, 6, 23, 0.6);
}
body.dark-mode .accelerate-modal-content h3,
body.dark-mode .accelerate-total {
    color: #f1f5f9;
}
body.dark-mode .accelerate-modal-close {
    color: #cbd5e1;
}
body.dark-mode .accelerate-modal-close:hover {
    color: #f8fafc;
}
body.dark-mode .accelerate-row label {
    color: #94a3b8;
}
body.dark-mode .accelerate-row input[type="number"] {
    background: #0f172a;
    border-color: #334155;
    color: #f1f5f9;
}
body.dark-mode .accelerate-divider {
    border-top-color: #334155;
}
body.dark-mode .accelerate-preview {
    background: #0f172a;
    border-color: #334155;
}

/* ── Plan summary table — saved columns ────────────────────────── */
.be-col-saved {
    color: #15803d;
    font-weight: 600;
}
.be-col-zero {
    color: var(--text-secondary, #6b7280);
}
.debt-summary-footnote {
    font-size: 0.78rem;
    color: var(--text-secondary, #6b7280);
    margin-top: 0.5rem;
    font-style: italic;
}

/* Login Gate — full-viewport overlay for Postgres backend. Mirrors the
   site's gradient-backdrop-with-floating-card look (see body/.container/
   header above) so it reads as the same app, not a bare form. */
.login-gate {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    z-index: 2000;
    display: none;
    align-items: center;
    justify-content: center;
}
.login-gate.flex-visible {
    display: flex;
}
body.dark-mode .login-gate {
    background: linear-gradient(135deg, #232526 0%, #414345 100%);
}
.login-gate-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
    overflow: hidden;
}
/* Header band — same blue gradient + logo treatment as the real <header> */
.login-gate-header {
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: #fff;
    text-align: center;
    padding: 1.75rem 2rem 1.25rem;
}
body.dark-mode .login-gate-header {
    background: linear-gradient(135deg, #111827 0%, #1e293b 100%);
}
.login-gate-header .logo-icon {
    display: inline-flex;
    margin-bottom: 0.5rem;
}
.login-gate-body {
    padding: 1.75rem 2rem 2rem;
}
.login-gate-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    color: #fff;
}
.login-gate-subtitle {
    color: var(--text-secondary);
    margin: 0 0 1.5rem;
    font-size: 0.95rem;
}
.login-gate-form .form-group {
    margin-bottom: 1rem;
}
.login-gate-error {
    color: var(--danger-color, #dc3545);
    font-size: 0.875rem;
    min-height: 1.25rem;
    margin: 0.25rem 0 0.75rem;
}
.login-gate-submit {
    width: 100%;
}
.login-gate-back-btn {
    display: block;
    margin-top: 0.5rem;
}
.login-gate-forgot-link {
    margin: 0.5rem 0 0;
    text-align: center;
}
.link-btn {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary-color);
    cursor: pointer;
    font-size: 0.875rem;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.link-btn:hover {
    color: var(--primary-hover);
}

/* Installed PWA: same flat, edge-to-edge treatment as .container — drop the
   gradient backdrop and floating-card chrome; keep the header band gradient,
   matching how the real <header> also keeps its gradient in standalone mode. */
@media (display-mode: standalone) {
    .login-gate {
        background: var(--bg-primary);
    }
    body.dark-mode .login-gate {
        background: var(--bg-primary);
    }
    .login-gate-card {
        max-width: none;
        width: 100%;
        height: 100%;
        border: none;
        border-radius: 0;
        box-shadow: none;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }
}
.pg-migration-error {
    color: var(--danger-color, #dc2626);
    font-size: 0.875rem;
    margin: 0.5rem 0;
}
