/* ===== CSS Variables ===== */
:root {
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-card: #222636;
    --bg-card-hover: #2a2f42;
    --bg-input: #181b25;
    --border: #2e3348;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0b0;
    --text-muted: #6b7185;
    --accent: #4f8cff;
    --accent-hover: #3a75e6;
    --accent-bg: rgba(79, 140, 255, 0.12);
    --green: #34d399;
    --green-bg: rgba(52, 211, 153, 0.12);
    --red: #f87171;
    --red-bg: rgba(248, 113, 113, 0.12);
    --orange: #fb923c;
    --orange-bg: rgba(251, 146, 60, 0.12);
    --yellow: #fbbf24;
    --yellow-bg: rgba(251, 191, 36, 0.12);
    --purple: #a78bfa;
    --purple-bg: rgba(167, 139, 250, 0.12);
    --blue: #60a5fa;
    --blue-bg: rgba(96, 165, 250, 0.12);
    --cyan: #22d3ee;
    --cyan-bg: rgba(34, 211, 238, 0.12);
    --pink: #ec4899;
    --pink-bg: rgba(236, 72, 153, 0.12);
    --modal-overlay: rgba(0, 0, 0, 0.6);
    --sidebar-width: 240px;
    --radius: 10px;
    --radius-sm: 6px;
}

/* ===== Light Theme ===== */
[data-theme="light"] {
    --bg-primary: #f5f6f8;
    --bg-secondary: #ebedf2;
    --bg-card: #ffffff;
    --bg-card-hover: #f0f1f5;
    --bg-input: #ffffff;
    --border: #d5d9e2;
    --text-primary: #1a1d27;
    --text-secondary: #5a6174;
    --text-muted: #8890a4;
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-bg: rgba(37, 99, 235, 0.08);
    --green: #059669;
    --green-bg: rgba(5, 150, 105, 0.08);
    --red: #dc2626;
    --red-bg: rgba(220, 38, 38, 0.08);
    --orange: #d97706;
    --orange-bg: rgba(217, 119, 6, 0.08);
    --yellow: #b45309;
    --yellow-bg: rgba(180, 83, 9, 0.08);
    --purple: #7c3aed;
    --purple-bg: rgba(124, 58, 237, 0.08);
    --blue: #2563eb;
    --blue-bg: rgba(37, 99, 235, 0.08);
    --cyan: #0891b2;
    --cyan-bg: rgba(8, 145, 178, 0.08);
    --pink: #be185d;
    --pink-bg: rgba(190, 24, 93, 0.08);
    --modal-overlay: rgba(0, 0, 0, 0.4);
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme]) {
        --bg-primary: #f5f6f8;
        --bg-secondary: #ebedf2;
        --bg-card: #ffffff;
        --bg-card-hover: #f0f1f5;
        --bg-input: #ffffff;
        --border: #d5d9e2;
        --text-primary: #1a1d27;
        --text-secondary: #5a6174;
        --text-muted: #8890a4;
        --accent: #2563eb;
        --accent-hover: #1d4ed8;
        --accent-bg: rgba(37, 99, 235, 0.08);
        --green: #059669;
        --green-bg: rgba(5, 150, 105, 0.08);
        --red: #dc2626;
        --red-bg: rgba(220, 38, 38, 0.08);
        --orange: #d97706;
        --orange-bg: rgba(217, 119, 6, 0.08);
        --yellow: #b45309;
        --yellow-bg: rgba(180, 83, 9, 0.08);
        --purple: #7c3aed;
        --purple-bg: rgba(124, 58, 237, 0.08);
        --blue: #2563eb;
        --blue-bg: rgba(37, 99, 235, 0.08);
        --cyan: #0891b2;
        --cyan-bg: rgba(8, 145, 178, 0.08);
        --pink: #be185d;
        --pink-bg: rgba(190, 24, 93, 0.08);
        --modal-overlay: rgba(0, 0, 0, 0.4);
    }
}

/* ===== Reset ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== App Layout ===== */
.app {
    display: flex;
    min-height: 100vh;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.25s ease;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px;
    border-bottom: 1px solid var(--border);
}

.logo {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--accent), #7c3aed);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
}

.logo-text {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.nav-links {
    list-style: none;
    padding: 12px 10px;
    flex: 1;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease;
    margin-bottom: 2px;
}

.nav-link:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

.nav-link.active {
    background: rgba(79, 140, 255, 0.12);
    color: var(--accent);
}

.nav-link svg {
    flex-shrink: 0;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 28px 32px;
    min-height: 100vh;
}

/* ===== Page Header ===== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    flex-wrap: wrap;
    gap: 12px;
}

.page-header h2 {
    font-size: 22px;
    font-weight: 700;
}

.page-header .subtitle {
    color: var(--text-secondary);
    font-size: 13px;
    margin-top: 2px;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

/* Compact stats grid used on Debts / Income / Taxes / Assets.
   Tighter minmax than .card-grid because these cards are smaller
   (label + value only, no sub-text). */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
}

/* Make the compact summary cards a bit tighter to fit more per row */
.stats-grid .stat-card {
    padding: 14px 16px;
}

.stat-card .label,
.stat-card .stat-label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.stat-card .value,
.stat-card .stat-value {
    font-size: 26px;
    font-weight: 700;
}

/* Compact stat-value in .stats-grid — trimmed size so 4 cards fit comfortably */
.stats-grid .stat-card .stat-value {
    font-size: 20px;
}

.stat-card .sub {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

.stat-card.green .value { color: var(--green); }
.stat-card.red .value { color: var(--red); }
.stat-card.orange .value { color: var(--orange); }
.stat-card.blue .value { color: var(--accent); }
.stat-card.purple .value { color: var(--purple); }

/* ===== Tables ===== */
.table-wrapper {
    overflow-x: auto;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13.5px;
}

thead th {
    background: var(--bg-secondary);
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th[data-sort] {
    cursor: pointer;
    user-select: none;
    transition: color 0.15s;
}

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

th .sort-arrow {
    margin-left: 4px;
    font-size: 10px;
    opacity: 0.3;
}

th .sort-arrow.active {
    opacity: 1;
    color: var(--accent);
}

tr[data-bill-id] {
    cursor: default;
    transition: background 0.1s;
}

tr.bill-selected td {
    background: rgba(79, 140, 255, 0.12) !important;
    border-bottom-color: rgba(79, 140, 255, 0.25) !important;
}
tr.bill-selected td:first-child {
    box-shadow: inset 3px 0 0 var(--accent);
}
tr.bill-selected {
    opacity: 1 !important;
}

/* Selection bar for multi-select */
.selection-bar {
    display: flex;
    position: fixed;
    bottom: 0;
    left: var(--sidebar-width, 240px);
    right: 0;
    background: var(--bg-card);
    border-top: 2px solid var(--accent);
    padding: 12px 24px;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.3);
    max-height: 50vh;
    overflow-y: auto;
}

.selection-bar > div {
    display: flex;
    align-items: center;
}

@media (max-width: 768px) {
    .selection-bar {
        left: 0;
        bottom: 56px; /* Above mobile nav */
        padding: 10px 12px;
        flex-direction: column;
        gap: 10px;
        align-items: stretch;
    }
    .selection-bar > div {
        justify-content: center;
        flex-wrap: wrap;
        gap: 8px;
    }
    .selection-bar > div:first-child {
        padding-bottom: 8px;
        border-bottom: 1px solid var(--border);
    }
}

@media (max-width: 400px) {
    .selection-bar {
        bottom: 52px;
        padding: 8px 10px;
        gap: 8px;
    }
    .selection-bar > div {
        gap: 6px;
        font-size: 12px;
    }
    .selection-bar .btn-sm {
        padding: 4px 8px;
        font-size: 11px;
    }
}

/* Selection bar inner elements */
.selection-bar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.selection-count {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
}

.selection-bar-totals {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.selection-source {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
}

.source-name {
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 1px;
}

.source-total {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.selection-grand-total {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    text-align: right;
    border-left: 1px solid var(--border);
    padding-left: 12px;
}

.total-label {
    font-size: 10px;
    color: var(--text-muted);
    margin-bottom: 1px;
}

.total-amount {
    font-size: 16px;
    font-weight: 700;
    color: var(--accent);
}

@media (max-width: 768px) {
    .selection-bar-actions {
        justify-content: center;
        width: 100%;
    }

    .selection-bar-totals {
        justify-content: center;
        width: 100%;
    }

    .selection-source {
        flex-direction: row;
        gap: 6px;
        align-items: center;
    }

    .selection-grand-total {
        flex-direction: row;
        gap: 8px;
        align-items: center;
        border-left: none;
        padding-left: 0;
        border-top: 1px solid var(--border);
        padding-top: 8px;
        width: 100%;
        justify-content: center;
    }

    .total-amount {
        font-size: 18px;
    }
}

@media (max-width: 400px) {
    .selection-count {
        font-size: 12px;
    }

    .source-name {
        font-size: 9px;
    }

    .source-total {
        font-size: 12px;
    }

    .total-label {
        font-size: 9px;
    }

    .total-amount {
        font-size: 16px;
    }

    .selection-grand-total {
        padding-top: 6px;
    }
}

tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

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

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

/* ===== Category Badges ===== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
}

.tag-pill {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    white-space: nowrap;
    line-height: 1.6;
}

.badge-housing, .badge-green { background: var(--green-bg); color: var(--green); }
.badge-car, .badge-orange { background: var(--orange-bg); color: var(--orange); }
.badge-subscription, .badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-necessity, .badge-purple { background: var(--purple-bg); color: var(--purple); }
.badge-credit-card, .badge-red { background: var(--red-bg); color: var(--red); }
.badge-utilities, .badge-yellow { background: var(--yellow-bg); color: var(--yellow); }
.badge-storage, .badge-cyan { background: var(--cyan-bg); color: var(--cyan); }
.badge-insurance, .badge-pink { background: rgba(236, 72, 153, 0.12); color: #ec4899; }

/* ===== Click-to-edit cells & toggle badges =====
   Used in Expenses and Bills tables: tapping a category badge or the
   business/personal toggle opens the inline picker or flips the type.
   Needs clear hover, focus, and :active states so users know the cell is
   interactive — and tap targets need to hit ~44px on mobile. */
.expense-type-toggle,
.expense-category-cell,
.bill-category-cell {
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: opacity 0.1s ease, transform 0.1s ease;
}
.expense-type-toggle:hover,
.expense-category-cell:hover,
.bill-category-cell:hover {
    opacity: 0.85;
}
.expense-type-toggle:active,
.expense-category-cell:active,
.bill-category-cell:active {
    opacity: 0.75;
    transform: scale(0.97);
}
.expense-type-toggle:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 2px;
    border-radius: 4px;
}

/* ===== Category Picker ===== */
.category-picker-wrapper {
    display: flex;
    gap: 0;
}

.category-picker-wrapper .form-input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    flex: 1;
}

.category-picker-btn {
    width: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-left: none;
    border-top-right-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 10px;
    transition: background 0.15s, color 0.15s;
}

.category-picker-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.category-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 280px;
    overflow-y: auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
    z-index: 100;
    margin-top: 4px;
}

.category-dropdown.open {
    display: block;
}

.category-group-header {
    padding: 8px 12px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
}

.category-option {
    padding: 8px 12px;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.1s;
}

.category-option:hover {
    background: var(--bg-hover);
}

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

/* Color Picker */
.color-picker {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.color-option {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.1s, border-color 0.1s;
}

.color-option:hover {
    transform: scale(1.1);
}

.color-option.selected {
    border-color: var(--text-primary);
    box-shadow: 0 0 0 2px var(--bg-primary);
}

/* ===== Status Badges ===== */
.status-paid {
    color: var(--green);
    font-weight: 600;
    font-size: 12px;
}

.status-unpaid {
    color: var(--red);
    font-weight: 600;
    font-size: 12px;
}

.status-frozen {
    color: var(--blue);
    font-weight: 600;
    font-size: 12px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

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

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--bg-card-hover); }

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

.btn-danger:hover { background: rgba(248, 113, 113, 0.2); }

.btn-sm {
    padding: 5px 10px;
    font-size: 12px;
}

.btn-icon {
    width: 32px;
    height: 32px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-icon:hover {
    background: var(--bg-card);
    color: var(--text-primary);
}

/* Other Income: desktop shows table, mobile shows cards */
.other-income-mobile {
    display: none;
}
.other-income-card {
    padding: 12px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

/* ===== Toggle Switch ===== */
.toggle {
    position: relative;
    width: 44px;
    height: 24px;
    cursor: pointer;
}

.toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    transition: all 0.2s ease;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 2px;
    top: 2px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: all 0.2s ease;
}

.toggle input:checked + .toggle-slider {
    background: rgba(79, 140, 255, 0.3);
    border-color: var(--accent);
}

.toggle input:checked + .toggle-slider::before {
    transform: translateX(20px);
    background: var(--accent);
}

/* ===== Form Elements ===== */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-input, .form-select {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s ease;
}

.form-input:focus, .form-select:focus {
    outline: none;
    border-color: var(--accent);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239aa0b0' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

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

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 16px;
    font-weight: 700;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

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

.modal-body {
    padding: 20px;
}

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

/* ===== Vehicle Detail Modal ===== */
.vehicle-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin: -20px -20px 16px -20px;
    padding: 0 20px;
}

.vehicle-tab {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    background: none;
    transition: color 0.15s, border-color 0.15s;
}

.vehicle-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

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

.vehicle-link {
    cursor: pointer;
    color: var(--accent);
    transition: opacity 0.15s;
}

.vehicle-link:hover {
    opacity: 0.8;
    text-decoration: underline;
}

.vehicle-overview-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.vehicle-overview-item {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 12px;
}

.vehicle-overview-item .label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.vehicle-overview-item .value {
    font-size: 18px;
    font-weight: 700;
}

.vehicle-log-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}

.vehicle-log-item:last-child {
    border-bottom: none;
}

.vehicle-log-item .log-info {
    flex: 1;
}

.vehicle-log-item .log-date {
    font-size: 11px;
    color: var(--text-muted);
}

.vehicle-log-item .log-value {
    font-weight: 700;
    font-size: 14px;
}

.vehicle-log-item .log-change {
    font-size: 11px;
    margin-left: 8px;
}

.vehicle-log-item .log-notes {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.vehicle-add-form {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 12px;
}

.vehicle-add-form .form-row {
    gap: 8px;
}

.vehicle-add-form .form-group {
    margin-bottom: 8px;
}

.vehicle-add-form label {
    font-size: 11px;
}

.vehicle-add-form input, .vehicle-add-form textarea {
    font-size: 13px;
    padding: 6px 10px;
}

.vehicle-stats {
    display: flex;
    gap: 16px;
    margin-bottom: 12px;
    font-size: 12px;
    color: var(--text-secondary);
}

.vehicle-stats strong {
    color: var(--text-primary);
}

.vehicle-empty {
    text-align: center;
    padding: 24px 0;
    color: var(--text-muted);
    font-size: 13px;
}

/* ===== Calendar ===== */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px;
    background: var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}

.calendar-header-cell {
    background: var(--bg-secondary);
    padding: 8px;
    text-align: center;
    font-size: 11.5px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
}

.calendar-day {
    background: var(--bg-card);
    min-height: 90px;
    padding: 6px 8px;
    position: relative;
    cursor: pointer;
    transition: background 0.15s ease;
}

.calendar-day:hover { background: var(--bg-card-hover); }

.calendar-day.other-month {
    background: var(--bg-primary);
    opacity: 0.4;
}

.calendar-day.today {
    background: rgba(79, 140, 255, 0.08);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.calendar-day .day-number {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.calendar-day.today .day-number { color: var(--accent); }

.calendar-day .day-bills {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.calendar-bill-dot {
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calendar-payday {
    background: var(--green-bg);
    color: var(--green);
    font-size: 10px;
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: 700;
}

.calendar-payday-amount {
    font-size: 10px;
    font-weight: 600;
    color: var(--green);
    padding: 0 5px;
    margin-top: 1px;
}

.calendar-day-total {
    font-size: 10px;
    font-weight: 600;
    color: var(--red);
    padding: 1px 5px;
    margin-top: 2px;
}

.calendar-nav {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 16px;
}

.calendar-nav h3 {
    font-size: 18px;
    font-weight: 700;
    min-width: 180px;
    text-align: center;
}

/* ===== Upcoming Bills List ===== */
.upcoming-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.upcoming-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.upcoming-item .bill-name {
    font-weight: 600;
    font-size: 13.5px;
}

.upcoming-item .bill-due {
    font-size: 12px;
    color: var(--text-secondary);
}

.upcoming-item .bill-amount {
    font-weight: 700;
    font-size: 14px;
}

.upcoming-item.overdue {
    border-color: var(--red);
    background: var(--red-bg);
}

.upcoming-item.due-soon {
    border-color: var(--orange);
    background: var(--orange-bg);
}

/* ===== Dependent Section ===== */
.dependent-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.dependent-bill-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    transition: all 0.15s ease;
}

.dependent-bill-row.covering {
    border-color: var(--accent);
    background: rgba(79, 140, 255, 0.06);
}

.dependent-bill-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dependent-bill-info .name {
    font-weight: 600;
    font-size: 14px;
}

.dependent-bill-info .amount {
    color: var(--text-secondary);
    font-size: 13px;
}

.dependent-bill-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ===== Filters ===== */
.filters {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.filter-chip {
    padding: 5px 14px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.filter-chip:hover {
    border-color: var(--text-secondary);
    color: var(--text-primary);
}

.filter-chip.active {
    background: rgba(79, 140, 255, 0.12);
    border-color: var(--accent);
    color: var(--accent);
}

/* ===== View Tabs (primary view-mode selector on a page) =====
   Underlined tabs — visually distinct from filter-chip pills so users
   read them as "which view am I in" vs "which filter is applied".
   Horizontally scrollable on narrow screens instead of wrapping. */
.view-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.view-tabs::-webkit-scrollbar { display: none; }

.view-tab {
    padding: 10px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    white-space: nowrap;
    font-family: inherit;
    transition: color 0.15s, border-color 0.15s;
}
.view-tab:hover { color: var(--text-primary); }
.view-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

/* ===== Widget Carousel (horizontal scroll-snap row of cards) =====
   Used on Dashboard to collapse 7+ secondary widgets into a
   swipeable/scrollable row. Native scroll-snap — no JS. */
.widget-carousel-wrapper {
    margin-bottom: 24px;
}

.widget-carousel-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 10px;
    gap: 12px;
}

.widget-carousel-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.widget-carousel-hint {
    font-size: 11px;
    color: var(--text-muted);
}

.widget-carousel {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    gap: 16px;
    padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
    /* Hide native scrollbar — pagination dots below tell the same story cleaner */
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.widget-carousel::-webkit-scrollbar { display: none; }

.widget-carousel > * {
    flex: 0 0 min(calc(100% - 32px), 420px);
    scroll-snap-align: start;
    min-width: 0; /* allow flex children to size down for text wrap */
    margin-bottom: 0 !important; /* cancel any mb-24 on inner cards */
}

.widget-carousel-dots {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
}

.widget-carousel-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    border: none;
    padding: 0;
    background: var(--border);
    cursor: pointer;
    transition: background 0.2s, width 0.2s;
}
.widget-carousel-dot:hover {
    background: var(--text-muted);
}
.widget-carousel-dot.active {
    background: var(--accent);
    width: 22px; /* active dot elongates into a pill — iOS-style pagination */
    border-radius: 4px;
}

@media (max-width: 680px) {
    .widget-carousel > * {
        flex: 0 0 calc(100% - 24px);
    }
    .widget-carousel-hint { display: none; }
}

/* ===== Strategy Drawer (<details> collapsible comparison card) =====
   Used on Debts to hide the Avalanche vs Snowball comparison until
   the user explicitly asks for it — saving ~500px of vertical space.
   Summary row always shows the active strategy + current savings. */
.strategy-drawer[open] > .strategy-drawer-summary {
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 12px;
}

.strategy-drawer-summary {
    list-style: none;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    user-select: none;
}
.strategy-drawer-summary::-webkit-details-marker { display: none; }

.strategy-drawer-title-row {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 12px;
    min-width: 0;
}

.strategy-drawer-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.strategy-drawer-chevron {
    font-size: 14px;
    color: var(--text-muted);
    transition: transform 0.2s;
    flex-shrink: 0;
}

.strategy-drawer[open] .strategy-drawer-chevron {
    transform: rotate(180deg);
}

@media (max-width: 560px) {
    .strategy-drawer-title-row {
        flex-direction: column;
        gap: 4px;
    }
}

/* ===== Settings ===== */
.settings-section {
    margin-bottom: 28px;
}

.settings-section h3 {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

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

.settings-row .setting-label {
    font-weight: 500;
    font-size: 14px;
}

.settings-row .setting-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* Responsive grid for grouping settings cards side-by-side. Cards flow into
   a natural masonry-ish layout: each column gets as many rows as needed,
   and cards keep their intrinsic height so a tall card next to a short
   card doesn't waste space. */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
    align-items: start;
}

.settings-grid > .card {
    margin-bottom: 0;
}

.settings-section-header {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin: 8px 0 12px;
    padding: 0 2px;
}

.settings-section-header:first-child { margin-top: 0; }

@media (max-width: 680px) {
    .settings-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 14px;
    margin-top: 8px;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    html { font-size: 16px; } /* Keep full size on mobile for readability */

    .sidebar {
        transform: translateX(-100%);
        width: 100%;
        max-width: 280px;
    }

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

    .main-content {
        margin-left: 0;
        padding: 12px;
        padding-bottom: 80px;
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }

    /* Bottom tab bar for mobile */
    .mobile-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border);
        z-index: 100;
        padding: 4px 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .mobile-nav a {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        padding: 6px 2px;
        color: var(--text-muted);
        text-decoration: none;
        font-size: 9px;
        font-weight: 600;
        transition: color 0.15s ease;
        white-space: nowrap;
    }

    .mobile-nav a.active { color: var(--accent); }

    .card-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px;
    }

    .stat-card { padding: 14px; }
    .stat-card .value { font-size: 22px; }
    .stat-card .label { font-size: 12px; }
    .stat-card .sub { font-size: 11px; }

    .calendar-day { min-height: 80px; padding: 5px 4px; }
    .calendar-day .day-number { font-size: 11px; }
    .calendar-bill-dot { font-size: 8px; padding: 1px 3px; }
    .calendar-day-total { font-size: 9px; }
    .calendar-payday-amount { font-size: 9px; }

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

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    .page-header h2 { font-size: 20px; }
    .page-header .btn { width: 100%; justify-content: center; }

    .filters {
        gap: 6px;
        flex-wrap: wrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 4px;
    }
    .filter-chip {
        padding: 4px 10px;
        font-size: 11px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    /* Table responsive */
    .table-wrapper {
        margin: 0 -12px;
        border-radius: 0;
        border-left: none;
        border-right: none;
        width: calc(100% + 24px);
        max-width: calc(100vw);
    }

    table {
        font-size: 14px;
        table-layout: fixed;
        width: 100%;
    }

    thead th {
        padding: 10px 8px;
        font-size: 11px;
    }

    tbody td {
        padding: 12px 8px;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    /* Bills table: column widths for mobile */
    .bills-table th:nth-child(1), .bills-table td:nth-child(1) { width: 50px; } /* Paid */
    .bills-table th:nth-child(2), .bills-table td:nth-child(2) { width: auto; } /* Name */
    .bills-table th:nth-child(3), .bills-table td:nth-child(3) { width: 80px; } /* Amount */
    .bills-table th:nth-child(4), .bills-table td:nth-child(4) { width: 80px; } /* Category */

    /* Bills table: hide less important columns on mobile (scoped to bills only) */
    .bills-table th:nth-child(5), .bills-table td:nth-child(5), /* Due Day */
    .bills-table th:nth-child(6), .bills-table td:nth-child(6), /* Payment Source */
    .bills-table th:nth-child(7), .bills-table td:nth-child(7)  /* Status */ {
        display: none;
    }

    /* Bills table: keep Actions column visible but compact on mobile */
    .bills-table th:nth-child(8), .bills-table td:nth-child(8) {
        width: 56px;
        padding: 8px 4px;
    }

    /* All tables: make action buttons larger/more tappable on mobile */
    .btn-icon {
        width: 36px;
        height: 36px;
        min-width: 36px;
    }

    /* Non-bills tables: responsive handling */
    /* Debts table: hide less important middle columns, keep Actions */
    .debts-table th:nth-child(4), .debts-table td:nth-child(4), /* APR */
    .debts-table th:nth-child(6), .debts-table td:nth-child(6), /* Payoff Date */
    .debts-table th:nth-child(7), .debts-table td:nth-child(7)  /* Progress */ {
        display: none;
    }

    /* Deductions table: hide Vendor column, keep Actions */
    .deductions-table th:nth-child(5), .deductions-table td:nth-child(5) /* Vendor */ {
        display: none;
    }

    /* Other Income: hide desktop table, show mobile cards */
    .other-income-desktop {
        display: none !important;
    }
    .other-income-mobile {
        display: flex !important;
        flex-direction: column;
        gap: 10px;
    }

    /* Cards */
    .card {
        padding: 14px;
        border-radius: var(--radius-sm);
    }

    /* Settings rows */
    .settings-row {
        padding: 12px 0;
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .settings-row > div:last-child {
        width: 100%;
        justify-content: flex-start;
    }

    /* Modal */
    .modal-overlay .modal {
        margin: 10px;
        max-height: calc(100vh - 20px);
        width: calc(100% - 20px);
        max-width: none;
    }

    .modal-actions {
        flex-direction: column-reverse;
        gap: 8px;
    }

    .modal-actions .btn {
        width: 100%;
    }

    /* Subtitle */
    .subtitle {
        font-size: 12px;
    }

    /* Buttons */
    .btn {
        padding: 12px 18px;
        font-size: 15px;
    }

    .btn-sm {
        padding: 8px 12px;
        font-size: 13px;
    }

    /* Form elements */
    .form-input, .form-select {
        padding: 12px 14px;
        font-size: 16px; /* 16px prevents iOS zoom on focus */
    }

    .form-group label {
        font-size: 13px;
    }

    /* Mobile nav */
    .mobile-nav a {
        font-size: 10px;
    }

    /* Filter chips */
    .filter-chip {
        padding: 6px 12px;
        font-size: 13px;
    }

    /* Badges */
    .badge {
        font-size: 12px;
        padding: 4px 10px;
    }

    /* Bigger tap targets for interactive badges/cells on touch devices —
       rows themselves give the ~44px vertical target via td padding, so we
       just widen horizontally to make them easier to hit without a miss. */
    .expense-type-toggle,
    .expense-category-cell .badge,
    .bill-category-cell .badge {
        padding: 6px 12px;
        font-size: 12.5px;
    }
}

/* Extra small screens */
@media (max-width: 400px) {
    html { font-size: 15px; } /* Slightly smaller but still readable on small screens */

    .main-content {
        padding: 8px;
        padding-bottom: 70px;
    }

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

    .page-header h2 { font-size: 18px; }

    .stat-card .value { font-size: 20px; }

    table { font-size: 13px; }

    thead th { padding: 8px 6px; font-size: 10px; }
    tbody td { padding: 10px 6px; }

    /* Column widths for extra small */
    th:nth-child(1), td:nth-child(1) { width: 45px; } /* Paid */
    th:nth-child(3), td:nth-child(3) { width: 75px; } /* Amount */

    .mobile-nav a {
        min-width: 0;
        font-size: 9px;
        padding: 6px 2px;
    }

    .mobile-nav a svg {
        width: 20px;
        height: 20px;
    }

    /* Buttons on extra small */
    .btn {
        padding: 10px 14px;
        font-size: 14px;
    }

    .btn-sm {
        padding: 6px 10px;
        font-size: 12px;
    }
}

@media (min-width: 769px) {
    .mobile-nav { display: none; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ===== OCR Import ===== */
.ocr-preview {
    max-width: 100%;
    max-height: 180px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    margin-bottom: 14px;
    object-fit: contain;
    display: block;
}

.ocr-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: ocr-spin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 8px;
}

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

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

.ocr-account-card {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px;
    margin-bottom: 10px;
    position: relative;
}

.ocr-account-card .ocr-remove-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
}

.ocr-account-card .ocr-remove-btn:hover {
    color: var(--red);
    background: var(--red-bg);
}

.badge-unverified {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    background: var(--orange-bg);
    color: var(--orange);
}

/* ===== Utility =====
   Prefer these over inline styles. Combined: use multiple classes, e.g.
   <div class="flex-align-center gap-8 mb-16">…</div>
   Keep inline `style=""` only for truly dynamic values (computed widths,
   per-row colors, calculated transforms). */

/* Text color */
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-orange { color: var(--orange); }
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-accent { color: var(--accent); }

/* Text size */
.text-xs { font-size: 11px; }
.text-sm { font-size: 12px; }
.text-base { font-size: 13px; }

/* Common compound — 12px muted text (very frequent pattern) */
.text-muted-sm { font-size: 12px; color: var(--text-muted); }
.text-secondary-sm { font-size: 12px; color: var(--text-secondary); }

/* Font weight */
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }

/* Margin — vertical scale */
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }

/* Flex helpers */
.flex { display: flex; }
.flex-align-center { display: flex; align-items: center; }
.flex-col { display: flex; flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-center { display: flex; align-items: center; justify-content: center; }

/* Gap scale — composes with any .flex / .flex-align-center / .flex-between / .icon-label */
.gap-4 { gap: 4px; }
.gap-6 { gap: 6px; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }

/* ===== Icon + Label =====
   Inline-flex wrapper for any icon-plus-text pair — buttons, spans,
   chips, nav items. Uses inline-flex (not flex) so the container
   shrinks to content and doesn't force block width.
   Compose gap with .gap-4 / .gap-6 / .gap-8 — default gap is 8px. */
.icon-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.icon-label.gap-4 { gap: 4px; }
.icon-label.gap-6 { gap: 6px; }
/* SVG children shouldn't shrink when the label text wraps */
.icon-label > svg { flex-shrink: 0; }

/* ===== Cashflow Charts ===== */

/* Waterfall Chart */
.waterfall-chart {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 220px;
    padding: 32px 0 28px;
    border-bottom: 2px solid var(--border);
    position: relative;
}

.waterfall-bar-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
    position: relative;
    min-width: 0;
}

.waterfall-bar {
    width: 100%;
    max-width: 60px;
    border-radius: 4px 4px 0 0;
    transition: height 0.3s ease;
    min-height: 2px;
}

.waterfall-bar.positive {
    background: linear-gradient(180deg, var(--green), rgba(52, 211, 153, 0.6));
}

.waterfall-bar.negative {
    background: linear-gradient(180deg, var(--red), rgba(248, 113, 113, 0.6));
}

.waterfall-bar.net-positive {
    background: linear-gradient(180deg, var(--accent), rgba(79, 140, 255, 0.6));
}

.waterfall-bar.net-negative {
    background: linear-gradient(180deg, var(--orange), rgba(251, 146, 60, 0.6));
}

.waterfall-bar-value {
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 4px;
    white-space: nowrap;
}

.waterfall-bar-label {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 6px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    position: absolute;
    bottom: -24px;
    left: 50%;
    transform: translateX(-50%);
}

/* Timeline Chart (6-Month Projection) */
.timeline-chart {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    height: 200px;
    padding: 28px 0 28px;
    border-bottom: 2px solid var(--border);
}

.timeline-month {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
    justify-content: flex-end;
    position: relative;
}

.timeline-net {
    font-size: 11px;
    font-weight: 700;
    margin-bottom: 6px;
    white-space: nowrap;
}

.timeline-bar-group {
    display: flex;
    gap: 4px;
    align-items: flex-end;
    flex: 1;
    width: 100%;
    justify-content: center;
}

.timeline-bar {
    width: 28px;
    border-radius: 4px 4px 0 0;
    transition: height 0.3s ease;
    min-height: 2px;
}

.timeline-bar.income {
    background: linear-gradient(180deg, var(--green), rgba(52, 211, 153, 0.5));
}

.timeline-bar.expense {
    background: linear-gradient(180deg, var(--red), rgba(248, 113, 113, 0.5));
}

.timeline-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
    margin-top: 8px;
    position: absolute;
    bottom: -24px;
}

/* Breakdown Grid */
.breakdown-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.breakdown-item {
    margin-bottom: 10px;
}

.breakdown-bar {
    height: 6px;
    background: var(--bg-input);
    border-radius: 3px;
    overflow: hidden;
}

.breakdown-bar-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.3s ease;
}

.breakdown-bar-fill.green {
    background: var(--green);
}

.breakdown-bar-fill.red {
    background: var(--red);
}

/* ===== Cashflow Mobile Responsive ===== */
@media (max-width: 768px) {
    .waterfall-chart {
        height: 160px;
        gap: 3px;
        overflow-x: auto;
    }

    .waterfall-bar {
        max-width: 40px;
    }

    .waterfall-bar-value {
        font-size: 9px;
    }

    .waterfall-bar-label {
        font-size: 8px;
    }

    .timeline-chart {
        height: 160px;
        gap: 6px;
    }

    .timeline-bar {
        width: 20px;
    }

    .timeline-net {
        font-size: 9px;
    }

    .breakdown-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}

/* ===== AI Chatbot ===== */

.chatbot-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    z-index: 150;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chatbot-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

.chatbot-bubble.active {
    transform: scale(0.95);
}

.chatbot-bubble svg {
    width: 24px;
    height: 24px;
}

.chatbot-panel {
    position: fixed;
    bottom: 90px;
    right: 24px;
    width: 380px;
    height: 500px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    z-index: 150;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

.chatbot-panel.open {
    display: flex;
}

.chatbot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chatbot-header-title {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.chatbot-header-title svg {
    color: var(--accent);
}

.chatbot-header-actions button {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.chatbot-header-actions button:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chatbot-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chatbot-msg-user {
    align-self: flex-end;
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chatbot-msg-assistant {
    align-self: flex-start;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chatbot-msg-assistant strong {
    color: var(--accent);
}

.chatbot-typing {
    align-self: flex-start;
    background: var(--bg-card);
    border: 1px solid var(--border);
    padding: 10px 14px;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 4px;
    align-items: center;
}

.chatbot-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: chatbot-bounce 1.4s infinite ease-in-out;
}

.chatbot-typing-dot:nth-child(1) { animation-delay: 0s; }
.chatbot-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chatbot-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes chatbot-bounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

.chatbot-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    flex-shrink: 0;
}

.chatbot-input {
    flex: 1;
    padding: 9px 14px;
    background: var(--bg-input, var(--bg-secondary));
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s ease;
}

.chatbot-input:focus {
    border-color: var(--accent);
}

.chatbot-input::placeholder {
    color: var(--text-muted);
}

.chatbot-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s ease;
    flex-shrink: 0;
}

.chatbot-send:hover {
    opacity: 0.85;
}

.chatbot-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-send svg {
    width: 16px;
    height: 16px;
}

.chatbot-clear {
    text-align: center;
    padding: 6px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    flex-shrink: 0;
}

.chatbot-clear button {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    padding: 4px 8px;
    font-family: inherit;
}

.chatbot-clear button:hover {
    color: var(--red);
}

/* Mobile responsive */
@media (max-width: 768px) {
    .chatbot-bubble {
        bottom: 72px;
        right: 16px;
        width: 48px;
        height: 48px;
    }

    .chatbot-bubble svg {
        width: 20px;
        height: 20px;
    }

    .chatbot-panel {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
    }
}

/* ===== Balance History Chart ===== */
.balance-history-chart {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    height: 200px;
    padding: 8px 0;
    overflow-x: auto;
    scrollbar-width: thin;
}

.bh-month {
    flex: 1;
    min-width: 50px;
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100%;
}

.bh-values {
    flex-shrink: 0;
    text-align: center;
    margin-bottom: 4px;
    min-height: 16px;
}

.bh-value {
    font-weight: 600;
    white-space: nowrap;
}

.bh-bar-group {
    flex: 1;
    display: flex;
    align-items: flex-end;
    gap: 2px;
    width: 100%;
    min-height: 0;
}

.bh-bar {
    flex: 1;
    border-radius: 3px 3px 0 0;
    min-height: 2px;
    transition: height 0.3s ease;
    cursor: default;
}

.bh-bar.checking {
    background: var(--green);
    opacity: 0.85;
}

.bh-bar.savings {
    background: var(--accent);
    opacity: 0.85;
}

.bh-bar.investment {
    background: var(--purple);
    opacity: 0.85;
}

.bh-label {
    font-size: 10px;
    color: var(--text-muted);
    text-align: center;
    margin-top: 6px;
    flex-shrink: 0;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .balance-history-chart {
        height: 160px;
        gap: 4px;
    }

    .bh-month {
        min-width: 40px;
    }

    .bh-values {
        display: none;
    }

    .bh-label {
        font-size: 9px;
    }
}

/* ===== Dashboard Customization / Edit Mode ===== */

.dashboard-edit-toolbar {
    border: 2px solid var(--accent);
    background: var(--accent-bg);
}

.dashboard-widget-wrapper {
    position: relative;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    margin-bottom: 16px;
    transition: border-color 0.2s, opacity 0.2s;
}

.dashboard-widget-wrapper:hover {
    border-color: var(--accent);
}

.widget-drag-handle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius) var(--radius) 0 0;
    cursor: grab;
    user-select: none;
}

.widget-drag-handle:active {
    cursor: grabbing;
}

.widget-label {
    flex: 1;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.widget-hide-btn {
    opacity: 0.5;
    transition: opacity 0.2s;
}

.widget-hide-btn:hover {
    opacity: 1;
}

.dashboard-widget-wrapper.dragging {
    opacity: 0.4;
}

.dashboard-widget-wrapper.drag-over-top {
    border-top: 3px solid var(--accent);
}

.dashboard-widget-wrapper.drag-over-bottom {
    border-bottom: 3px solid var(--accent);
}

.widget-mobile-controls {
    display: none;
    gap: 4px;
    align-items: center;
}

.widget-grip-icon {
    display: block;
}

@media (max-width: 768px) {
    .widget-mobile-controls {
        display: flex;
    }
    .widget-grip-icon {
        display: none;
    }
    .dashboard-widget-wrapper[draggable="true"] {
        /* Disable visual drag cue on mobile */
        cursor: default;
    }
    .widget-drag-handle {
        cursor: default;
    }
}

/* ===== Reports Tab ===== */
.report-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}
.report-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    transition: border-color 0.2s;
}
.report-card:hover {
    border-color: var(--accent);
}
.report-card .btn {
    margin-top: auto;
}
@media (max-width: 600px) {
    .report-grid {
        grid-template-columns: 1fr;
    }
}

/* ===== Onboarding Guide ===== */
.onboarding-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 10000;
    animation: onboardingFadeIn 0.3s ease;
}
.onboarding-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(2px);
}
.onboarding-highlight-ring {
    position: fixed;
    border: 2px solid var(--accent);
    border-radius: var(--radius);
    box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.55), 0 0 20px rgba(99, 102, 241, 0.5);
    z-index: 10001;
    transition: all 0.35s ease;
    pointer-events: none;
}
.onboarding-card {
    position: fixed;
    z-index: 10002;
    width: 380px;
    max-width: calc(100vw - 32px);
    transition: all 0.35s ease;
}
.onboarding-card-center {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}
.onboarding-card-right {
    left: 260px;
}
.onboarding-card-content {
    /* Positioned dynamically via JS below the highlighted content element */
}
.onboarding-card-inner {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255,255,255,0.05) inset;
}
.onboarding-progress {
    height: 4px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 16px;
}
.onboarding-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.35s ease;
}
.onboarding-step-counter {
    font-size: 11px;
    color: var(--text-muted);
    text-align: right;
    margin-bottom: 8px;
    font-weight: 500;
}
.onboarding-icon {
    font-size: 40px;
    margin-bottom: 12px;
}
.onboarding-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 10px;
    color: var(--text-primary);
}
.onboarding-body {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 8px;
}
.onboarding-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 20px;
    gap: 8px;
}
.onboarding-fade-out {
    animation: onboardingFadeOut 0.3s ease forwards;
}
@keyframes onboardingFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes onboardingFadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}
.onboarding-option-btn:hover {
    border-color: var(--accent) !important;
    transform: translateY(-1px);
    transition: all 0.2s ease;
}
.onboarding-option-selected {
    border-color: var(--accent) !important;
    background: rgba(99, 102, 241, 0.08) !important;
}
@media (max-width: 768px) {
    .onboarding-card-right {
        left: 50%;
        top: 50% !important;
        transform: translate(-50%, -50%);
    }
    .onboarding-highlight-ring {
        display: none !important;
    }
    .onboarding-card {
        width: calc(100vw - 32px);
    }
}

/* ===== Financial Health Score ===== */
.health-score-widget .health-score-ring svg circle:last-of-type {
    animation: healthScoreFill 1.2s ease-out forwards;
}
@keyframes healthScoreFill {
    from { stroke-dashoffset: 364.42; }
}
.health-score-widget .health-score-number {
    animation: healthScoreCount 0.8s ease-out;
}
@keyframes healthScoreCount {
    from { opacity: 0; transform: scale(0.5); }
    to { opacity: 1; transform: scale(1); }
}
@media (max-width: 600px) {
    .health-score-widget .flex-between + div {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }
}

/* ===== Smart Insights ===== */
.smart-insights-widget .insight-suggestion {
    transition: border-color 0.2s, transform 0.15s;
}
.smart-insights-widget .insight-suggestion:hover {
    border-color: var(--accent);
    transform: translateY(-1px);
}
.smart-insights-widget .insight-add-bill {
    transition: background 0.2s, transform 0.1s;
}
.smart-insights-widget .insight-add-bill:active {
    transform: scale(0.97);
}
.smart-insights-widget .insight-dismiss {
    transition: background 0.2s, color 0.2s;
}
.smart-insights-widget .insight-dismiss:hover {
    background: var(--bg-card-hover);
    color: var(--text-primary);
}
