/* ═══════════════════════════════════════════════════════════════
   UTILITY CLASSES
   ═══════════════════════════════════════════════════════════════ */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* Inline styles extracted for CSP compliance */
.target-date-flex-row {
    display: flex;
    align-items: flex-end;
    padding-bottom: 2px;
}

.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: white;
    max-width: 460px;
    width: 92%;
    border-radius: 12px;
    padding: 28px 24px;
    margin: auto;
    position: relative;
    outline: 0;
}

#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;
}

.modal-subtitle {
    margin: 4px 0 14px;
}

.modal-description {
    margin: 6px 0 10px;
    color: #6b7280;
}

.modal-tx-name {
    margin: 0 0 6px;
    font-size: 0.9rem;
}

.modal-helper-text {
    font-size: 0.78rem;
    color: #6b7280;
    margin-bottom: 4px;
}

.modal-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.modal-form-grid .form-group {
    margin: 0;
}

.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;
}
.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 .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-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;
}
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;
    --border-color: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --card-bg: #1e293b;
    --text-color: #f1f5f9;
    --bg-color: #0f172a;
    --table-header-bg: #0f172a;
    --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-hover: #1d4ed8;
    --success-color: #16a34a;
    --success-hover: #15803d;
    --danger-color: #dc2626;
    --danger-hover: #b91c1c;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --light-bg: #f8fafc;
    --border-color: #e2e8f0;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --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);
}

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;
}

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.70);
    cursor: pointer;
    font-size: 1rem;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
}

.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.55);
}

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.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;
    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;
    background: none;
    border: none;
    cursor: pointer;
    padding: 12px 16px;
    color: rgba(255,255,255,0.72);
    transition: color 0.15s;
}

.nav-toggle:hover {
    color: #fff;
}

.nav-menu {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    justify-content: center;
}

.page-button {
    flex: 1;
    max-width: 160px;
    padding: 12px 16px;
    border-radius: 0;
    border: none;
    border-bottom: 3px solid transparent;
    background: transparent;
    color: rgba(255,255,255,0.72);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.88rem;
    letter-spacing: 0.02em;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
    white-space: nowrap;
}

.page-button:hover {
    color: #fff;
    background: rgba(255,255,255,0.08);
    border-bottom-color: rgba(255,255,255,0.4);
}

.page-button.active {
    color: #fff;
    background: transparent;
    border-bottom: 3px solid #fff;
}

.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: rgba(99,102,241,0.07);
}

.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;
}

.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;
}

/* 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--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 {
    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 {
    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 {
    background: var(--success-color);
    color: white;
}

.btn-success:hover {
    background: var(--success-hover);
    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--muted {
    color: #64748b;
}

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,
    .debt-overview-cat-row {
        grid-template-columns: 1fr 70px 100px;
    }
    .debt-overview-cats-header span:nth-child(2),
    .debt-overview-cat-count {
        display: none;
    }
}

/* 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;
}

/* 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);
}

.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;
}

.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;
        width: 100%;
    }

    .top-nav.menu-open .nav-menu {
        display: flex;
    }

    .page-button {
        flex: 1;
        max-width: 100%;
        font-size: 0.9rem;
        padding: 14px 16px;
        border-bottom: 1px solid rgba(255,255,255,0.1);
        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.1);
        border-right-color: rgba(255,255,255,0.4);
    }

    .page-button.active {
        background: rgba(255,255,255,0.05);
        border-bottom-color: rgba(255,255,255,0.1);
        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;
    }

    .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: 36px;
        height: 36px;
    }

    .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;
}
.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);
}
.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: #9ca3af;
}

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: #9ca3af;
}
.whatif-hint {
    font-size: 0.85rem;
    color: #9ca3af;
    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: #9ca3af;
    margin-top: 1px;
}
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 (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; }
}

/* 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; }
}

.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: #16a34a;
    white-space: nowrap;
}
body.dark-mode .bonus-this-month-tag { color: #4ade80; }

/* 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; }

.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; }
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: 480px) { .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; }
}
.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
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Tab bar ───────────────────────────────────────────────────────────── */
.rpt-tab-bar {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    border-radius: 10px 10px 0 0;
    margin-bottom: 0;
    overflow-x: auto;
}
.rpt-tab-btn {
    flex: 1;
    min-width: 140px;
    padding: 13px 20px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s, border-bottom-color 0.15s;
    white-space: nowrap;
}
.rpt-tab-btn:hover { color: var(--primary-color); }
.rpt-tab-btn--active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

/* ── Tab panels ────────────────────────────────────────────────────────── */
.rpt-tab-panel { display: none; padding: 24px 0 0; }
.rpt-tab-panel--active { display: block; }

/* ── 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; }

/* ── 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: 72px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 4px 5px;
    background: var(--card-bg);
    overflow: hidden;
    font-size: 0.7rem;
}
.rpt-cal-empty { background: transparent; border-color: transparent; }
.rpt-cal-has-events { border-color: #c7d2fe; }
.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-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;
}

/* 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; }

.rpt-cal-evt--income { background: #10b981; }
.rpt-cal-evt--bill   { background: #f59e0b; }
.rpt-cal-evt--expense { background: #8b5cf6; }
.rpt-cal-evt--recurring { background: #06b6d4; }
.rpt-cal-evt--bonus  { background: #d97706; }
.rpt-cal-evt--debt-dynamic { background: var(--debt-color, #2563eb); }

/* 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;
}

@media (max-width: 640px) {
    .rpt-cal-cell     { min-height: 56px; }
    .rpt-cal-evt-amt  { display: none; }
    .rpt-cal-evt      { font-size: 0.58rem; }
    .rpt-tab-btn      { min-width: 100px; font-size: 0.82rem; padding: 10px 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-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; }

/* ── 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,
    .acct-mf-row { grid-template-columns: 28px 1fr 80px 80px; }
    .acct-mf-type, .acct-mf-start { display: none; }
    .acct-edit-grid { grid-template-columns: 1fr 1fr; }
    .acct-card-header { gap: 10px; }
}


/* ═══════════════════════════════════════════════════════════════════════════
   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-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; }
}

/* ═══════════════════════════════════════════════════════════════
   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; }
.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: #9ca3af;
    border-top: 1px solid var(--border-color, #e5e7eb);
    margin-top: 24px;
    user-select: none;
}
body.dark-mode .app-footer {
    color: #64748b;
    border-top-color: #334155;
}
