@import url('https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;1,400&display=swap');
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --primary: #2c3e50; --primary-dark: #233240; --primary-light: #d5d8dc;
    --bg: #f9f9f9; --surface: #ffffff; --surface2: #ecf0f1; --surface3: #f8f9fa;
    --text: #212529; --text-muted: #95a5a6;
    --border: #dee2e6; --radius: .375rem; --shadow: 0 1px 3px rgba(0,0,0,.08);
    --overlay: rgba(0,0,0,.5);
    --income: #18bc9c; --expense: #e74c3c; --balance: #2c3e50;
    --warning: #f39c12; --info: #3498db;
    --code-bg: #f8f9fa;
    --clear-icon: #95a5a6; --clear-icon-active: #18bc9c;
    --sidebar-bg: #2c3e50; --sidebar-text: rgba(255,255,255,.7);
    --sidebar-hover-bg: rgba(255,255,255,.1); --sidebar-active-text: #fff;
    --sidebar-header-border: rgba(255,255,255,.1);
}
[data-theme="dark"] {
    --primary: #3498db; --primary-dark: #2a7aaf; --primary-light: #1a3a5c;
    --bg: #222222; --surface: #303030; --surface2: #3a3a3a; --surface3: #282828;
    --text: #ffffff; --text-muted: #95a5a6;
    --border: #444444; --shadow: 0 1px 3px rgba(0,0,0,.4);
    --overlay: rgba(0,0,0,.7);
    --income: #18bc9c; --expense: #e74c3c; --balance: #3498db;
    --warning: #f39c12; --info: #3498db;
    --code-bg: #3a3a3a;
    --clear-icon: #95a5a6; --clear-icon-active: #18bc9c;
    --sidebar-bg: #1a1a1a; --sidebar-text: rgba(255,255,255,.6);
    --sidebar-hover-bg: rgba(255,255,255,.08); --sidebar-active-text: #fff;
    --sidebar-header-border: rgba(255,255,255,.08);
}
[data-theme="dark"] .flatpickr-calendar {
    border-color: #555;
    box-shadow: 0 4px 20px rgba(0,0,0,.5);
}
[data-theme="dark"] .flatpickr-day.prevMonthDay,
[data-theme="dark"] .flatpickr-day.nextMonthDay {
    color: #667;
}
[data-theme="dark"] .flatpickr-day.prevMonthDay:hover,
[data-theme="dark"] .flatpickr-day.nextMonthDay:hover {
    background: #3a3a3a;
    color: #889;
}
body {
    font-family: 'Lato', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg); color: var(--text); display: flex; min-height: 100vh;
    line-height: 1.5; font-size: 1rem;
}

/* ─── Flatpickr theme (uses CSS vars from :root/[data-theme]) ─── */
.flatpickr-calendar {
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.flatpickr-months { background: var(--surface); }
.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year,
.flatpickr-month,
span.flatpickr-weekday {
    color: var(--text);
    fill: var(--text);
}
.flatpickr-weekdays { background: transparent; }
.flatpickr-day {
    color: var(--text);
    border-radius: var(--radius);
}
.flatpickr-day.today { border-color: var(--primary); }
.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange,
.flatpickr-day.inRange {
    background: var(--primary) !important;
    border-color: var(--primary) !important;
    color: #fff !important;
}
.flatpickr-day.flatpickr-disabled,
.flatpickr-day.flatpickr-disabled:hover {
    color: var(--text-muted);
}
.flatpickr-day:hover {
    background: var(--surface2);
}
.flatpickr-prev-month svg, .flatpickr-next-month svg { fill: var(--text) !important; }
.flatpickr-prev-month:hover svg, .flatpickr-next-month:hover svg { fill: var(--primary) !important; }
.flatpickr-day.inRange, .flatpickr-day.prevMonthDay.inRange,
.flatpickr-day.nextMonthDay.inRange, .flatpickr-day.today.inRange,
.flatpickr-day.prevMonthDay.today.inRange, .flatpickr-day.nextMonthDay.today.inRange {
    background: var(--primary-light);
    border-color: var(--primary-light);
}
.flatpickr-day.selected:focus, .flatpickr-day.startRange:focus,
.flatpickr-day.endRange:focus, .flatpickr-day.selected:hover,
.flatpickr-day.startRange:hover, .flatpickr-day.endRange:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}
.flatpickr-current-month .numInputWrapper span.arrowUp:after,
.flatpickr-current-month .numInputWrapper span.arrowDown:after {
    border-bottom-color: var(--text);
    border-top-color: var(--text);
}
.flatpickr-day.flatpickr-disabled, .flatpickr-day.flatpickr-disabled:hover,
.flatpickr-day.notAllowed, .flatpickr-day.notAllowed.prevMonthDay,
.flatpickr-day.notAllowed.nextMonthDay {
    color: var(--text-muted);
}

/* Calendar icon on flatpickr inputs */
.flatpickr-wrapper {
    position: relative;
    display: block;
    width: 100%;
}
.flatpickr-wrapper input.flatpickr-input {
    padding-right: 2.2rem;
}
.flatpickr-wrapper::after {
    content: '\F133';
    font-family: 'bootstrap-icons', sans-serif;
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    font-size: 1rem;
    z-index: 1;
}
a { color: #18bc9c; text-decoration: none; }
a:hover { color: #13967d; text-decoration: underline; }

.sidebar {
    width: 240px; background: var(--sidebar-bg); padding: 0;
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; bottom: 0;
    z-index: 100; transition: width .25s ease;
    overflow: hidden; color: var(--sidebar-text);
}
.sidebar-collapsed { width: 60px; }
.sidebar-header {
    padding: .75rem; border-bottom: 1px solid var(--sidebar-header-border);
    display: flex; align-items: center; gap: .5rem;
    min-height: 68px;
}
.sidebar-header .logo { max-width: 100%; height: auto; display: block; transition: opacity .2s; background-repeat: no-repeat; }
.sidebar-collapsed .sidebar-header .logo { display: none !important; }
.sidebar-header .logo-mini { display: none; max-width: 100%; height: auto; background-repeat: no-repeat; }
.sidebar-collapsed .sidebar-header .logo-mini { display: block; max-width: 100%; height: auto; background-repeat: no-repeat; }

.sidebar-toggle {
    position: absolute; top: 50%; right: -12px; transform: translateY(-50%);
    background: var(--surface); border: 1px solid var(--border); border-radius: 0 6px 6px 0;
    color: var(--text-muted); cursor: pointer; font-size: .85rem; font-weight: 700;
    width: 22px; height: 44px; padding: 0; z-index: 10;
    display: flex; align-items: center; justify-content: center;
    transition: color .2s, background .2s; font-family: serif;
}
.sidebar-toggle:hover { color: var(--text); background: var(--surface2); }
.sidebar-collapsed .sidebar-toggle { right: -12px; }
.nav-list { list-style: none; padding: .75rem 0; flex: 1; overflow-y: auto; }
.nav-list li a {
    display: flex; align-items: center; gap: .75rem;
    padding: .7rem 1.25rem; color: var(--sidebar-text);
    transition: all .2s; border-left: 3px solid transparent;
    white-space: nowrap;
}
.nav-list li a:hover, .nav-list li a.active {
    background: var(--sidebar-hover); color: var(--sidebar-active); text-decoration: none;
}
.nav-section-label { padding: .6rem 1rem .2rem; font-size: .65rem; text-transform: uppercase; letter-spacing: .8px; color: var(--sidebar-text); opacity: .45; pointer-events: none; }
.nav-icon { font-size: 1.1rem; flex-shrink: 0; width: 1.25rem; text-align: center; }
.nav-text { transition: opacity .2s; }
.sidebar-collapsed .nav-text { opacity: 0; width: 0; overflow: hidden; }
.sidebar-collapsed .nav-list li a { justify-content: center; padding: .75rem .5rem; }
.sidebar-collapsed .nav-icon { font-size: 1.15rem; }
.sidebar-footer { padding: .75rem 1.25rem; border-top: 1px solid var(--sidebar-header-border); }
.sidebar-profile {
    padding: .7rem 1.25rem;
    display: flex; align-items: center; gap: .75rem;
    white-space: nowrap; border-top: 1px solid var(--sidebar-header-border);
}
.sidebar-profile .nav-icon { font-size: 1.1rem; flex-shrink: 0; width: 1.25rem; text-align: center; color: var(--sidebar-text); }
.sidebar-profile-select {
    flex: 1; padding: .35rem .5rem; font-size: .85rem;
    border: 1px solid rgba(255,255,255,.2); border-radius: var(--radius);
    background: rgba(255,255,255,.1); color: var(--sidebar-text); cursor: pointer;
    min-width: 0; max-width: 140px; font-family: inherit;
}
.sidebar-profile-select:hover, .sidebar-profile-select:focus { color: #fff; border-color: rgba(255,255,255,.4); outline: none; }
.sidebar-collapsed .sidebar-profile { padding: .7rem .75rem; justify-content: center; }
.sidebar-collapsed .sidebar-profile .nav-icon { margin: 0; }
.sidebar-collapsed .sidebar-profile-select { display: none; }
.sidebar-footer a {
    display: flex; align-items: center; gap: .75rem;
    color: var(--sidebar-text); white-space: nowrap;
}
.sidebar-footer a:hover { color: var(--expense); text-decoration: none; }
.sidebar-collapsed .sidebar-footer a { justify-content: center; }
.sidebar-collapsed .sidebar-footer .nav-text { opacity: 0; width: 0; overflow: hidden; }

#main-content { margin-left: 240px; flex: 1; padding: 2rem; width: calc(100% - 240px); transition: margin-left .25s ease, width .25s ease; }
#sidebar.sidebar-collapsed ~ #main-content { margin-left: 60px; width: calc(100% - 60px); }
#main-content.full-width { margin-left: 0; width: 100%; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; flex-wrap: wrap; gap: 1rem; }
.page-header h2 { font-size: 1.75rem; }
.profile-color-tag {
    display: none; font-size: .72rem; font-weight: 600; padding: .15rem .6rem;
    border-radius: 999px; background: var(--profile-tag-color, #2c3e50);
    color: #fff; margin-left: .75rem; vertical-align: middle;
    text-transform: uppercase; letter-spacing: .4px;
}

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.stat-card {
    background: var(--surface); border-radius: var(--radius); padding: 1.5rem;
    box-shadow: var(--shadow); border-left: 4px solid var(--primary);
    border: 1px solid var(--border);
}
.stat-card.income { border-left-color: var(--income); }
.stat-card.expense { border-left-color: var(--expense); }
.stat-card.balance { border-left-color: var(--balance); }
.stat-label { display: block; font-size: .85rem; color: var(--text-muted); margin-bottom: .5rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; }

.charts-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.chart-card { background: var(--surface); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow); border: 1px solid var(--border); }
.chart-card h3 { margin-bottom: 1rem; font-size: 1rem; color: var(--text-muted); }
.chart-card canvas { max-height: 260px; max-width: 100%; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.25rem; }
.card {
    background: var(--surface); border-radius: var(--radius); padding: 1.5rem;
    box-shadow: var(--shadow); cursor: pointer; transition: transform .2s;
    display: flex; flex-direction: column; gap: .35rem;
    border: 1px solid var(--border);
}
.card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.card h4 { font-size: 1.1rem; }
.card .meta { font-size: .85rem; color: var(--text-muted); }
.card .amount { font-size: 1.25rem; font-weight: 700; }
.card-heading { display: flex; align-items: center; justify-content: space-between; }
.card-heading .toggle-default { border: none; box-shadow: none; background: none; padding: .25rem; cursor: pointer; border-radius: var(--radius); color: var(--text-muted); }
.card-heading .toggle-default:hover { background: var(--surface2); }
.card-heading .toggle-default .bi-star-fill { color: #f1c40f; }
.budget-actions { margin-top: .5rem; }

/* ─── AI Insights ─── */
.insights-card { background: var(--surface); border-radius: var(--radius); padding: 1.25rem 1.5rem; margin: 1.5rem 0; box-shadow: var(--shadow); border: 1px solid var(--border); }
.insights-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; padding-bottom: .75rem; border-bottom: 2px solid var(--border); }
.insights-header h3 { margin: 0; font-size: 1.05rem; display: flex; align-items: center; gap: .5rem; }
.insights-header h3 i { color: #f1c40f; }
.insights-header .btn { font-size: .8rem; padding: .3rem .65rem; }
.insight-item { display: flex; gap: .75rem; padding: .8rem .85rem; margin-bottom: .7rem; border-radius: var(--radius); border-left: 4px solid var(--border); background: var(--surface2); transition: box-shadow .15s; }
.insight-item:last-child { margin-bottom: 0; }
.insight-positive { border-left-color: #16a34a; background: linear-gradient(135deg, rgba(22,163,74,.07), transparent 80%); }
.insight-negative { border-left-color: #dc2626; background: linear-gradient(135deg, rgba(220,38,38,.07), transparent 80%); }
.insight-info { border-left-color: #3b82f6; background: linear-gradient(135deg, rgba(59,130,246,.07), transparent 80%); }
.insight-neutral { border-left-color: var(--primary); background: var(--surface2); }
.insight-item-icon { flex: 0 0 1.4rem; padding-top: .05rem; display: flex; align-items: flex-start; justify-content: center; }
.insight-item-icon .bi { font-size: 1.15rem; }
.insight-positive .insight-item-icon .bi { color: #16a34a; }
.insight-negative .insight-item-icon .bi { color: #dc2626; }
.insight-info .insight-item-icon .bi { color: #3b82f6; }
.insight-neutral .insight-item-icon .bi { color: var(--primary); }
.insight-label-do { color: #16a34a; font-weight: 700; }
.insight-label-dont { color: #dc2626; font-weight: 700; }
.insight-item-body { flex: 1; min-width: 0; }
.insight-item-title { font-weight: 700; font-size: .95rem; color: var(--text); margin-bottom: .25rem; letter-spacing: .01em; }
.insight-item-text { font-size: .88rem; line-height: 1.65; color: var(--text); }
.insight-item-text .insight-num { font-weight: 700; }
.insight-meta { font-size: .78rem; color: var(--text-muted); margin-top: .75rem; padding-top: .5rem; display: flex; align-items: center; gap: .5rem; border-top: 1px solid var(--border); }
.insight-meta i { font-size: .7rem; }
.insight-empty { padding: 1.25rem 1rem; text-align: center; color: var(--text-muted); font-size: .92rem; }
.insight-empty strong { color: var(--text); }
@keyframes spin { to { transform: rotate(360deg); } }
.spinning { display: inline-block; animation: spin 1s linear infinite; }
.budget-actions .badge-default { margin-top: 0; }
#tag-list .card { flex-direction: row; align-items: center; justify-content: space-between; }
#tag-list .card .del-tag { flex-shrink: 0; }
.badge { display: inline-block; padding: .15rem .65rem; font-size: .75rem; font-weight: 700; border-radius: 999px; text-transform: uppercase; letter-spacing: .4px; }
.badge-default { background: var(--primary); color: #fff; }
.badge-tag { font-size: .72rem; border-radius: 999px; }
.badge-active { background: var(--primary); color: #fff; }
.badge-completed { background: var(--income); color: #fff; }
.badge-cancelled { background: var(--text-muted); color: #fff; }
.badge-warning { background: rgba(245,158,11,.12); color: var(--warning, #d97706); }
.badge-info { background: rgba(59,130,246,.12); color: var(--info, #2563eb); }
.badge-success { background: rgba(22,163,74,.12); color: var(--income, #16a34a); }
.badge-secondary { background: rgba(100,116,139,.12); color: var(--text-muted, #64748b); }
.badge-danger { background: rgba(220,38,38,.10); color: var(--expense, #dc2626); }
.goal-status-row { display: flex; justify-content: flex-end; margin-bottom: .25rem; }
.goal-amount { font-size: 1.1rem; font-weight: 700; margin: .35rem 0; }
.goal-progress { height: 8px; background: var(--surface2); border-radius: 999px; overflow: hidden; margin-top: .25rem; }
.goal-progress-bar { height: 100%; border-radius: 999px; transition: width .3s ease; background: var(--primary); }
.goal-progress-bar.on_track { background: var(--income); }
.goal-progress-bar.on-track { background: var(--income); }
.goal-progress-bar.behind { background: var(--warning); }
.goal-progress-bar.not-achievable { background: var(--expense); }
.goal-item { margin-bottom: 1rem; }
.goal-item:last-child { margin-bottom: 0; }
.goal-header { display: flex; justify-content: space-between; align-items: center; font-size: .875rem; }
.goal-header span:first-child { font-weight: 600; }
.goal-header span:last-child { color: var(--text-muted); font-size: .8rem; }

.login-page { display: flex; justify-content: center; align-items: center; min-height: 80vh; }
.login-card {
    background: var(--surface); padding: 2.5rem; border-radius: var(--radius);
    width: 100%; max-width: 400px; box-shadow: 0 4px 20px rgba(0,0,0,.1);
    border: 1px solid var(--border);
}
[data-theme="dark"] .login-card { box-shadow: 0 4px 20px rgba(0,0,0,.4); }
.login-card h2 { text-align: center; font-size: 1.75rem; margin-bottom: .25rem; }
.login-card .subtitle { text-align: center; color: var(--text-muted); margin-bottom: 2rem; }
.form-footer { text-align: center; margin-top: 1rem; font-size: .9rem; }

.form-group { margin-bottom: 1rem; position: relative; }
.form-group label { display: block; margin-bottom: .35rem; color: var(--text-muted); font-size: .9rem; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: .65rem .75rem; border: 1px solid var(--border);
    border-radius: var(--radius); background: var(--bg); color: var(--text);
    font-size: .95rem; transition: border-color .2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(44,62,80,.15);
}
[data-theme="dark"] .form-group input:focus, [data-theme="dark"] .form-group select:focus, [data-theme="dark"] .form-group textarea:focus {
    box-shadow: 0 0 0 2px rgba(52,152,219,.25);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }
.form-row-wide { grid-template-columns: 1fr 2fr; }
.form-select, .form-input { padding: .5rem .75rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg); color: var(--text); }
select.form-select, select.form-input, select { color-scheme: light; }
[data-theme="dark"] select.form-select, [data-theme="dark"] select.form-input, [data-theme="dark"] select { color-scheme: dark; }

button { cursor: pointer; }

.btn {
    padding: .65rem 1.25rem; border: none; border-radius: var(--radius);
    cursor: pointer; font-size: .95rem; font-weight: 700; transition: all .2s;
    box-shadow: none; display: inline-flex; align-items: center; gap: .4rem;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: #95a5a6; color: #fff; }
.btn-secondary:hover { background: #7f8c8d; }
.btn-danger { background: var(--expense); color: #fff; }
.btn-danger:hover { background: #b93d30; }
.btn-info { background: var(--info); color: #fff; }
.btn-info:hover { background: #2a7aaf; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: #c9900b; }
.btn-block { width: 100%; }
.btn-sm { padding: .35rem .75rem; font-size: .8rem; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface2); }
.btn-icon { border-radius: var(--radius); display: inline-flex; align-items: center; justify-content: center; padding: .4rem .55rem; line-height: 1; border: none; box-shadow: none; background: none; cursor: pointer; }
.btn-icon.btn-secondary { background: #95a5a6; color: #fff; }
.btn-icon.btn-secondary:hover { background: #7f8c8d; }
.btn-icon.btn-danger { background: var(--expense); color: #fff; }
.btn-icon.btn-danger:hover { background: #b93d30; }
.btn-icon.btn-info { background: var(--info); color: #fff; }
.btn-icon.btn-info:hover { background: #2a7aaf; }
.btn-icon.btn-warning { background: var(--warning); color: #fff; }
.btn-icon.btn-warning:hover { background: #c9900b; }
.btn-icon.edit-txn { background: var(--warning); color: #fff; }
.btn-icon.edit-txn:hover { background: #c9900b; }
.btn-icon.edit-txn[disabled] { opacity: .4; cursor: not-allowed; }

.tabs, .type-tabs { display: flex; gap: .5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }

/* ─── Button Groups (for ledger view toggle, etc.) ─── */
.btn-group { display: inline-flex; }
.btn-group .btn { margin-left: -1px; }
.btn-group .btn:first-child { margin-left: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.btn-group .btn:last-child { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.btn-group .btn.active { z-index: 1; }
.tab {
    padding: .5rem 1rem; border: 1px solid var(--border); border-radius: var(--radius);
    background: transparent; color: var(--text-muted); cursor: pointer; font-size: .9rem;
    transition: all .2s;
}
.tab:hover { border-color: var(--primary); color: var(--primary); }
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.filters { display: flex; gap: 1rem; margin-bottom: 1.5rem; align-items: center; flex-wrap: wrap; }
.period-selector { display: flex; gap: 1rem; align-items: center; }

.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: var(--overlay); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-content { background: var(--surface); border-radius: var(--radius); width: 90%; max-width: 500px; max-height: 90vh; display: flex; flex-direction: column; position: relative; }
.modal-content.modal-lg { max-width: 700px; }
.modal-header { flex-shrink: 0; padding: 1.25rem 1.5rem .5rem; display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { margin: 0; }
.modal-body { flex: 1; overflow-y: auto; padding: .75rem 1.5rem; min-height: 0; }
.modal-content > form { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.modal-footer { flex-shrink: 0; padding: .75rem 1.5rem 1.25rem; border-top: 1px solid var(--border); display: flex; gap: .5rem; justify-content: flex-end; }
.modal-close { font-size: 1.5rem; cursor: pointer; color: var(--text-muted); line-height: 1; }
.modal-close:hover { color: var(--text); }

.modal-tabs { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0; }
.modal-tab { padding: .5rem 1rem; border: 1px solid transparent; border-bottom: none; border-radius: var(--radius) var(--radius) 0 0; background: transparent; color: var(--text-muted); cursor: pointer; font-size: .9rem; transition: all .2s; margin-bottom: -1px; }
.modal-tab:hover { color: var(--primary); }
.modal-tab.active { background: var(--surface); color: var(--text); border-color: var(--border); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Shared Users */
.search-results { position: absolute; z-index: 100; top: 100%; left: 0; right: 0; margin-top: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); max-height: 200px; overflow-y: auto; box-shadow: 0 4px 12px rgba(0,0,0,.12); }
.bu-search-item.already-added { opacity: .45; cursor: default; pointer-events: none; }
.bu-search-item { padding: .5rem .75rem; cursor: pointer; font-size: .9rem; }
.bu-search-item:hover,.bu-search-item.selected { background: var(--primary); color: #fff; }
.bu-user-items { list-style: none; padding: 0; margin: 0; }
.bu-user-items li { display: flex; justify-content: space-between; align-items: center; padding: .5rem .75rem; border-bottom: 1px solid var(--border); font-size: .9rem; }
.bu-user-items li:last-child { border-bottom: none; }

.ff-row { display: flex; gap: .5rem; align-items: center; }
.ff-user-items { list-style: none; padding: 0; margin: 0; }
.ff-user-items li { display: flex; justify-content: space-between; align-items: center; padding: .5rem .75rem; border-bottom: 1px solid var(--border); font-size: .9rem; }
.ff-user-items li:last-child { border-bottom: none; }
.ff-user-items li .field-hint { font-size: .8rem; color: var(--text-muted); }
.category-fields-shared-budget .form-row { display: flex; gap: 1rem; }
.category-fields-shared-budget .form-row .form-group { flex: 1; }

.txn-section-title { margin: 1rem 0 .15rem; font-size: 1rem; }
.txn-row { display: flex; gap: .5rem; margin-bottom: .5rem; align-items: center; flex-wrap: wrap; }
.txn-row .txn-row-sel { flex: 0 0 180px; }
.txn-row .txn-row-amt { flex: 0 0 120px; }
.txn-row .txn-row-payee { flex: 0 0 150px; }
.txn-row .txn-row-desc { flex: 1; min-width: 120px; }
.txn-row .txn-row-del { flex: 0 0 auto; padding: .35rem .6rem; }
.txn-row select, .txn-row input { background: var(--bg); color: var(--text); }
.txn-row-end { display: flex; gap: .5rem; flex: 1; min-width: 140px; }
.txn-row-end .txn-row-desc { flex: 1; min-width: 80px; }

.txn-view-meta { padding: .75rem; margin-bottom: .75rem; background: var(--surface3); border-radius: var(--radius); border: 1px solid var(--border); font-size: .95rem; }
.txn-view-section-title { font-size: .85rem; text-transform: uppercase; color: var(--text-muted); margin: 1rem 0 .5rem; padding-bottom: .25rem; border-bottom: 1px solid var(--border); }
.txn-view-entry { background: var(--surface3); border: 1px solid var(--border); border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: .5rem; }
.txn-view-sections { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); padding: .75rem; }
.txn-view-entry .tve-row { display: flex; gap: .5rem; padding: .2rem 0; }
.txn-view-entry .tve-row-2col { display: flex; gap: 1rem; padding: .2rem 0; }
.txn-view-entry .tve-row-2col > div { display: flex; gap: .5rem; flex: 1; align-items: baseline; }
.txn-view-entry .tve-label { flex: 0 0 80px; font-size: .82rem; color: var(--text-muted); }
.txn-view-entry .tve-value { flex: 1; font-size: .9rem; }
.txn-view-entry .tve-amt { font-weight: 600; }
.txn-view-tags { padding: .5rem .75rem; margin-bottom: .75rem; background: var(--surface3); border-radius: var(--radius); border: 1px solid var(--border); }

#wallet-accounts-list { margin-top: .35rem; }
.wallet-acct-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .6rem;
  display: flex;
  flex-wrap: wrap;
  gap: .15rem .5rem;
}
.wallet-acct-card .form-check {
  flex: 0 0 calc(50% - .25rem);
  display: flex;
  align-items: center;
  gap: .35rem;
  min-height: 0;
  margin: 0;
  padding: 0;
}
.wallet-acct-card .form-check-input {
  float: none;
  margin: 0;
  position: static;
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}
.wallet-acct-card .form-check-label {
  font-size: .85rem;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.form-check .form-check-input:disabled ~ .form-check-label,
.form-check .form-check-input:disabled ~ .form-check-label * {
  opacity: .55;
  cursor: not-allowed;
}
.account-checkbox {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  flex: 0 0 calc(50% - .25rem);
  font-size: .85rem;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.account-checkbox input[type=checkbox] {
  width: auto;
  margin: 0;
  cursor: pointer;
  flex-shrink: 0;
}

.budget-item-row { display: flex; align-items: center; gap: 1rem; padding: .5rem .75rem; background: var(--surface3); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .35rem; }
.budget-item-row span:first-child { flex: 1; }
.budget-item-row span:nth-child(2) { font-weight: 600; min-width: 100px; text-align: right; }

#budget-members-list { margin-top: .5rem; }
.bm-card { background: var(--surface3); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.bm-header { display: grid; grid-template-columns: 1fr 140px 1fr 110px; gap: 0; background: var(--surface2); border-bottom: 1px solid var(--border); font-size: .75rem; text-transform: uppercase; color: var(--text-muted); font-weight: 700; letter-spacing: .5px; }
.bm-header > span { padding: .55rem .75rem; }
.bm-hdr-tag { text-align: center; }
.bm-hdr-actions { text-align: right; }
#bm-rows { display: block; }
.bm-row { display: grid; grid-template-columns: 1fr 140px 1fr 110px; gap: 0; border-bottom: 1px solid var(--border); transition: background .15s; align-items: center; }
.bm-row:last-child { border-bottom: none; }
.bm-row:hover { background: var(--surface); }
.bm-cell { padding: .45rem .75rem; font-size: .88rem; }
.bm-cell-cat { font-weight: 500; }
.bm-cell-tag { text-align: center; }
.bm-cell-group { font-size: .82rem; color: var(--text-muted); }
.bm-cell-actions { text-align: right; white-space: nowrap; }
.bm-cell-actions .btn-icon { padding: .3rem .45rem; margin-left: .15rem; }

.bp-section { margin-bottom: 2rem; }
.bp-section-header { font-size: 1.1rem; margin-bottom: .75rem; padding-bottom: .5rem; border-bottom: 2px solid var(--border); }
.bp-section-header.income { border-bottom-color: var(--income); }
.bp-section-header.expense { border-bottom-color: var(--expense); }
.bp-group-header td { padding: .5rem .75rem .3rem; font-size: .85rem; font-weight: 700; color: var(--text-muted); background: var(--surface2); border-bottom: none; text-transform: uppercase; letter-spacing: .4px; }

.bp-table { width: 100%; border-collapse: collapse; margin-bottom: .75rem; table-layout: fixed; }
.bp-table th, .bp-table td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); }
.bp-table th { color: var(--text-muted); font-size: .82rem; text-transform: uppercase; }
.bp-table td { font-size: .9rem; }
.bp-table .bp-name { font-weight: 600; width: 30%; text-align: left; }
.bp-table .bp-type { font-size: .8rem; color: var(--text-muted); width: 12%; text-align: left; }
.bp-table th.bp-col-plan, .bp-table th.bp-col-actual, .bp-table th.bp-col-status,
.bp-table td.bp-col-plan, .bp-table td.bp-col-actual, .bp-table td.bp-col-status { text-align: right; }
.bp-table .bp-col-plan { width: 18%; }
.bp-table .bp-col-actual { width: 18%; }
.bp-table .bp-col-status { width: 22%; }
.bp-table .bp-amount { width: 100%; max-width: 130px; padding: .35rem .5rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); font-size: .9rem; text-align: right; box-sizing: border-box; }
.bp-table .bp-amount:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(44,62,80,.15); }
[data-theme="dark"] .bp-table .bp-amount:focus { box-shadow: 0 0 0 2px rgba(52,152,219,.25); }
.bp-table .bp-actual { font-weight: 600; }
.bp-table .bp-status { font-weight: 700; }
.bp-table .bp-status-positive { color: var(--income); }
.bp-table .bp-status-negative { color: var(--expense); }
.bp-total { text-align: right; font-weight: 700; font-size: 1rem; padding: .5rem .75rem; margin-top: .25rem; }
.bp-summary-row { display: flex; gap: 1rem; flex-wrap: wrap; }
.bp-summary-col { flex: 1; min-width: 120px; }
.bp-summary-label { display: block; font-size: .82rem; font-weight: 400; text-transform: uppercase; color: var(--text-muted); letter-spacing: .5px; margin-top: .25rem; }
.bp-summary-label:first-child { margin-top: 0; }
.bp-summary-value { display: block; font-weight: 700; font-size: 1.3rem; }
.bp-plan-cell { display: flex; align-items: center; gap: .35rem; justify-content: flex-end; }
.bp-info-icon { cursor: pointer; font-size: .85rem; color: var(--info); opacity: .7; transition: opacity .15s; flex-shrink: 0; }
.bp-info-icon:hover { opacity: 1; }
.bp-info-tooltip { position: fixed; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 12px rgba(0,0,0,.15); padding: .6rem .8rem; font-size: .82rem; line-height: 1.5; white-space: nowrap; z-index: 9999; }
.bp-info-tooltip-arrow { position: absolute; top: -5px; left: 50%; margin-left: -5px; width: 10px; height: 10px; background: var(--surface); border-left: 1px solid var(--border); border-top: 1px solid var(--border); transform: rotate(45deg); }
.bp-info-tooltip-body { position: relative; z-index: 1; }

#transaction-list, .data-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; overflow-x: auto; border: 1px solid var(--border); }
#transaction-list .dataTables_wrapper,
.data-card .dataTables_wrapper { width: 100%; }
.ledger-txn-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; overflow-x: auto; border: 1px solid var(--border); margin-top: 1.5rem; }
.ledger-txn-card .dataTables_wrapper { width: 100%; }

.txn-table { width: 100% !important; border-collapse: collapse; }
.txn-table thead th { padding: .65rem .75rem; font-size: .8rem; text-transform: uppercase; color: var(--text-muted); border-bottom: 2px solid var(--border); font-weight: 700; letter-spacing: .4px; background: var(--surface); }
.txn-table tbody td { padding: .6rem .75rem; border-bottom: 1px solid var(--border); font-size: .9rem; }
.txn-table tbody tr:nth-child(odd) td { background: var(--surface); }
.txn-table tbody tr:nth-child(even) td,
.txn-table tbody tr.even td { background: var(--surface3); }
.txn-table tbody tr:hover td { background: var(--primary-light) !important; }
.txn-table td.td-center { text-align: center; vertical-align: middle; }
.txn-table td.td-left { text-align: left; vertical-align: middle; }
.ticket-table { width: 100% !important; border-collapse: collapse; }
.ticket-table thead th,
.ticket-table tbody td { padding: .65rem .75rem; font-size: .8rem; border-bottom: 1px solid var(--border); }
.ticket-table thead th { text-transform: uppercase; color: var(--text-muted); font-weight: 700; letter-spacing: .4px; background: var(--surface); }
.ticket-table tbody td { font-size: .9rem; }
.ticket-table tbody tr:nth-child(odd) td { background: var(--surface); }
.ticket-table tbody tr:nth-child(even) td,
.ticket-table tbody tr.even td { background: var(--surface3); }
.ticket-table tbody tr:hover td { background: var(--primary-light) !important; }
.ticket-table th.td-center,
.ticket-table td.td-center { text-align: center; vertical-align: middle; }
.ticket-table th.td-left,
.ticket-table td.td-left { text-align: left; vertical-align: middle; }
#tickets-list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; overflow-x: auto; border: 1px solid var(--border); }
.txn-table td.td-amount, .txn-table td.amount { text-align: right; font-variant-numeric: tabular-nums; }

/* Override DataTables vendor box-shadow striping */
table.dataTable.stripe > tbody > tr.odd > *,
table.dataTable.display > tbody > tr.odd > * { box-shadow: none !important; }
table.dataTable.hover > tbody > tr:hover > *,
table.dataTable.display > tbody > tr:hover > * { box-shadow: none !important; }

.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate { font-size: .85rem; color: var(--text-muted); padding: .5rem 0; }
.dataTables_wrapper .dataTables_length select,
.dataTables_wrapper .dataTables_filter input { border: 1px solid var(--border); border-radius: var(--radius); padding: .3rem .5rem; font-size: .85rem; background: var(--surface); color: var(--text); }
.dataTables_wrapper .dataTables_filter { margin-bottom: .5rem; }
.dataTables_wrapper .dataTables_filter label { font-size: .85rem; color: var(--text-muted); }
.dataTables_wrapper .dataTables_paginate .paginate_button { padding: .3rem .6rem; margin: 0 .15rem; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-size: .85rem; }
.dataTables_wrapper .dataTables_paginate .paginate_button.current,
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover { background: var(--primary); color: #fff; border-color: var(--primary); }
.dataTables_wrapper .dataTables_paginate .paginate_button:hover { background: var(--primary-light); border-color: var(--primary); }
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled { opacity: .4; cursor: default; }
.dataTables_wrapper .dataTables_empty { text-align: center; color: var(--text-muted); padding: 2rem 0; font-size: .9rem; }
.icon-clear { cursor: pointer; font-size: 1.25rem; color: var(--clear-icon); transition: color .2s; display: inline-block; }
.icon-clear.active { color: var(--clear-icon-active); }

.tfa-setup-box { background: var(--surface3); border-radius: var(--radius); padding: 1.5rem; text-align: center; margin: 1rem 0; border: 1px solid var(--border); }
.tfa-setup-box img { max-width: 220px; height: auto; margin-bottom: 1rem; }
.tfa-secret { font-family: monospace; font-size: 1.1rem; letter-spacing: 2px; color: var(--text); background: var(--code-bg); padding: .5rem 1rem; border-radius: var(--radius); display: inline-block; margin: .5rem 0; user-select: all; }
.tfa-status { display: flex; align-items: center; gap: .5rem; padding: .75rem; border-radius: var(--radius); margin: 1rem 0; }
.tfa-status.enabled { background: #d1f2eb; color: #0a4b3e; }
.tfa-status.disabled { background: var(--surface2); color: var(--text-muted); }
[data-theme="dark"] .tfa-status.enabled { background: #0a4b3e; color: #d1f2eb; }

.form-check { display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; font-size: .9rem; min-height: 1.5rem; }
.form-check input[type="radio"], .form-check input[type="checkbox"] { width: 1rem; height: 1rem; flex-shrink: 0; margin: 0; cursor: pointer; }
.field-error { border-color: var(--expense) !important; outline: 1px solid var(--expense); }
select.field-error { outline: none; border-color: var(--expense); }
.field-error-msg { color: var(--expense); font-size: .8rem; margin-top: .25rem; display: block; padding-left: .25rem; }
.field-hint { color: var(--text-muted); font-size: .8rem; display: block; margin-bottom: .25rem; }

input[type="date"], input[type="month"], input[type="time"] {
    color-scheme: light dark; accent-color: var(--primary);
    min-height: 2.4rem;
}
.required-star { color: var(--expense); }
.password-wrapper { position: relative; }
.password-wrapper input { padding-right: 2.5rem !important; }
.password-toggle { position: absolute; right: .75rem; top: 50%; transform: translateY(-50%); cursor: pointer; color: var(--text-muted); font-size: 1.1rem; z-index: 2; pointer-events: auto; }
.password-toggle:hover { color: var(--text); }

#toast-container {
    position: fixed; top: 1rem; right: 1rem; z-index: 9999;
    display: flex; flex-direction: column; gap: .5rem;
}
#toast-container > div {
    padding: .75rem 1.25rem; border-radius: var(--radius);
    color: #fff; font-weight: 500; font-size: .9rem;
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
    animation: toastIn .3s ease;
    min-width: 250px;
}
.toast.success { background: var(--income); }
.toast.error   { background: var(--expense); }
.toast.info    { background: var(--primary); }

@keyframes toastIn {
    from { transform: translateX(100%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}

.month-picker-popup {
    display: none; position: fixed;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: 8px; padding: 1rem; z-index: 9999;
    box-shadow: 0 4px 20px rgba(0,0,0,.4); min-width: 220px;
}
.month-picker-popup .month-picker-hdr {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: .75rem;
}
.month-picker-popup .month-picker-year {
    font-size: 1rem; font-weight: 600; color: var(--text);
    min-width: 70px; text-align: center;
}
.month-picker-popup .month-picker-nav {
    background: none; border: 1px solid var(--border);
    color: var(--text); border-radius: var(--radius);
    padding: 2px 10px; cursor: pointer; font-size: .85rem; line-height: 1.4;
}
.month-picker-popup .month-picker-nav:hover {
    background: var(--surface2);
}
.month-picker-popup .month-picker-grid {
    display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px;
}
.month-picker-popup .month-picker-btn {
    background: transparent; border: 1px solid var(--border);
    color: var(--text); border-radius: var(--radius);
    padding: 8px 4px; cursor: pointer; font-size: .85rem;
}
.month-picker-popup .month-picker-btn:hover {
    background: var(--surface2);
}
.month-picker-popup .month-picker-btn.selected {
    background: var(--primary); border-color: var(--primary); color: #fff;
}
.month-picker-popup .month-picker-btn.selected:hover {
    background: var(--primary-dark); border-color: var(--primary-dark); color: #fff;
}
.month-picker-popup .month-picker-btn.current {
    background: var(--primary-light); border-color: var(--border);
}

#bm-category-grid {
    max-height: 320px; overflow-y: auto; border: 1px solid var(--border);
    border-radius: var(--radius); padding: .75rem;
}
.bm-group { margin-bottom: 1rem; }
.bm-group:last-child { margin-bottom: 0; }
.bm-group-title {
    font-size: .85rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: .04em; color: var(--text-muted); margin-bottom: .35rem;
}
.bp-amount-readonly {
    display: inline-block; padding: .25rem .5rem; font-size: .9rem;
    color: var(--text-muted); min-width: 80px; text-align: right;
}
.bm-group-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }
.bm-cb-card { border: 1px solid var(--border); border-radius: var(--radius); padding: .55rem .65rem; background: var(--surface); cursor: pointer; transition: box-shadow .15s; }
.bm-cb-card:hover { box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.bm-cb-card-header { display: flex; align-items: center; gap: .4rem; font-size: .88rem; cursor: pointer; margin-bottom: .35rem; }
.bm-cb-card-body { padding-left: 1.4rem; }
.bm-cb-card-body .bm-cat-group { width: 100%; font-size: .8rem; padding: 2px 6px; height: auto; box-sizing: border-box; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius); }

.txn-tags-container { display: flex; flex-direction: column; gap: .5rem; }
.txn-tag-dropdown { position: relative; }
.txn-tag-selected-display {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    min-height: 2.5rem;
    flex-wrap: wrap;
}
.txn-tag-selected-display:hover { border-color: var(--primary); }
.txn-tag-selected-display:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-transparent); }
.txn-tag-placeholder { color: var(--text-muted); font-size: .9rem; }
.txn-tag-selected-display.has-tags .txn-tag-placeholder { display: none; }
.txn-tag-selected-display .bi-chevron-down { margin-left: auto; color: var(--text-muted); transition: transform .2s; }
.txn-tag-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: .25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 4px 12px rgba(0,0,0,.15);
    z-index: 100;
    max-height: 300px;
    overflow-y: auto;
}
.txn-tag-search-wrapper { padding: .5rem; border-bottom: 1px solid var(--border); }
.txn-tag-list { display: flex; flex-wrap: wrap; gap: .35rem; padding: .5rem; }
.txn-tag-cloud-badge {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    padding: .3rem .6rem;
    border-radius: 999px;
    font-size: .8rem;
    cursor: pointer;
    transition: opacity .15s, transform .15s;
    white-space: nowrap;
}
.txn-tag-cloud-badge:hover { opacity: .85; transform: scale(1.03); }
.txn-tag-cloud-badge.selected { opacity: 1; }
.txn-tag-cloud-badge .txn-tag-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1rem;
    height: 1.1rem;
    margin-left: .25rem;
    border-radius: 50%;
    background: rgba(0,0,0,.15);
    border: none;
    color: inherit;
    font-size: .65rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s;
}
.txn-tag-cloud-badge.selected .txn-tag-remove { opacity: 1; }
.txn-tag-cloud-badge .txn-tag-remove:hover { background: rgba(0,0,0,.3); }
.txn-tag-create-row { display: flex; gap: .5rem; padding: .5rem; border-top: 1px solid var(--border); }
.txn-tag-create-row .form-input { flex: 1; }
.txn-tag-create-row .btn { white-space: nowrap; }

altcha-widget {
    --altcha-color-base: var(--surface, #1e293b);
    --altcha-color-border: var(--border, #334155);
    --altcha-color-text: var(--text, #f1f5f9);
    --altcha-color-error: var(--danger, #ef4444);
    --altcha-color-success: var(--success, #22c55e);
    --altcha-color-footer-bg: var(--surface, #1e293b);
    --altcha-color-footer-text: var(--muted, #94a3b8);
    display: block;
    margin-bottom: .75rem;
}

.tag-filters { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.tag-filters .txn-filter-label { font-size: .85rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.tag-filter-btn { padding: .3rem .65rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); cursor: pointer; font-size: .8rem; transition: all .2s; }
.tag-filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.tag-filter-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.ledger-controls { display: flex; gap: 1rem; margin-bottom: 1.5rem; align-items: center; }
.ledger-view-toggle { margin-left: auto; }
.ledger-view-toggle .btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.ledger-account { margin-bottom: 2rem; border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.ledger-account-title { font-size: 1.1rem; margin: 0 0 1rem 0; display: flex; align-items: center; gap: .5rem; }
.ledger-account-title small { font-size: .8rem; color: var(--text-muted); font-weight: 400; }
.ledger-summary { width: auto; margin-bottom: 1rem; }
.ledger-summary td { padding: .25rem 1rem .25rem 0; font-size: .9rem; }
.ledger-closing { font-weight: 700; border-top: 1px solid var(--border); }
.ledger-closing td { padding-top: .5rem; }
.td-amount { text-align: right; font-variant-numeric: tabular-nums; }
.amount-credit { color: var(--success); }
.amount-debit { color: var(--expense); }
.ledger-txns { width: 100%; border-collapse: collapse; font-size: .85rem; }
.ledger-txns th { padding: .5rem .75rem; border-bottom: 1px solid var(--border); text-align: left; font-weight: 600; color: var(--text-muted); text-transform: uppercase; font-size: .75rem; }
.ledger-txns td { padding: .4rem .75rem; border-bottom: 1px solid var(--border); }
.ledger-txns .badge-tag { display: inline-block; margin-right: .2rem; }
.ledger-totals-card { border: 1px solid var(--primary); background: color-mix(in srgb, var(--primary) 8%, transparent); }
.ledger-totals-card h4 { color: var(--primary); }
.ledger-card { cursor: pointer; }
.ledger-card:hover h4 { color: var(--primary); }
.ledger-list-view { margin-top: 1.5rem; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--border); padding: 1rem; }
.ledger-list-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.ledger-list-table th { padding: .6rem .75rem; border-bottom: 2px solid var(--border); text-align: left; font-weight: 700; color: var(--text-muted); text-transform: uppercase; font-size: .75rem; white-space: nowrap; }
.ledger-list-table td { padding: .5rem .75rem; border-bottom: 1px solid var(--border); }
.ledger-list-table tbody tr:hover { background: color-mix(in srgb, var(--primary) 5%, transparent); }
.ledger-list-table tfoot td { padding: .6rem .75rem; border-top: 2px solid var(--border); font-size: .9rem; }
.ledger-list-table .badge-type { font-size: .72rem; padding: .15rem .5rem; border-radius: .25rem; background: var(--bg-light); color: var(--text-muted); }
.ledger-list-table .td-amount { text-align: right; font-family: 'SF Mono', 'Fira Code', monospace; white-space: nowrap; }

/* ─── Knowledge Base ─── */
.kb-search-wrap { max-width: 600px; margin-bottom: 2rem; }
.kb-search-wrap .form-input { font-size: 1rem; padding: .65rem 1rem; }
.kb-layout { display: flex; gap: 2rem; }
.kb-sidebar { flex: 0 0 220px; position: sticky; top: 2rem; align-self: flex-start; }
.kb-sidebar ul { list-style: none; padding: 0; margin: 0; border-left: 2px solid var(--border); }
.kb-sidebar ul li a { display: block; padding: .4rem 1rem; font-size: .9rem; color: var(--text-muted); border-left: 2px solid transparent; margin-left: -2px; transition: all .15s; }
.kb-sidebar ul li a:hover, .kb-sidebar ul li a.active { color: var(--text); border-left-color: var(--primary); text-decoration: none; }
.kb-sidebar ul li a.kb-section-link { font-weight: 600; color: var(--text); padding-top: .6rem; }
.kb-content { flex: 1; min-width: 0; }
.kb-content h2 { font-size: 1.5rem; margin: 0 0 .25rem; padding-bottom: .4rem; border-bottom: 2px solid var(--border); }
.kb-content h3 { font-size: 1.15rem; margin: 1.5rem 0 .5rem; color: var(--text); }
.kb-content h4 { font-size: 1rem; margin: 1.25rem 0 .4rem; color: var(--text); }
.kb-content p { font-size: .95rem; line-height: 1.65; margin: 0 0 .75rem; color: var(--text); }
.kb-content ul, .kb-content ol { font-size: .95rem; line-height: 1.65; margin: 0 0 .75rem; padding-left: 1.5rem; }
.kb-content li { margin-bottom: .25rem; }
.kb-content code { background: var(--surface2); padding: .15rem .4rem; border-radius: 3px; font-size: .85rem; }
.kb-content .kb-tip { background: var(--surface3); border-left: 3px solid var(--primary); padding: .75rem 1rem; border-radius: var(--radius); margin: 1rem 0; font-size: .9rem; }
.kb-content .kb-tip strong { color: var(--primary); }
.kb-section { margin-bottom: 3rem; }
.kb-highlight { background: #fff3cd; padding: 0 .15rem; border-radius: 2px; }
[data-theme="dark"] .kb-highlight { background: #5c4a10; color: #fff; }
.kb-no-results { text-align: center; padding: 2rem; color: var(--text-muted); display: none; }
.kb-hidden { display: none !important; }

/* ─── Subscription / Account ─── */
.sub-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.sub-card { background: var(--surface); border-radius: var(--radius); padding: 1.25rem 1.5rem; box-shadow: var(--shadow); border: 1px solid var(--border); }
.sub-card h3 { margin: 0 0 .75rem; font-size: 1.05rem; }
.sub-plan-name { font-size: 1.3rem; font-weight: 700; }
.sub-plan-price { font-size: 1.5rem; font-weight: 800; color: var(--primary); }
.sub-plan-price small { font-size: .75rem; font-weight: 400; color: var(--text-muted); }
.sub-plan-period { font-size: .85rem; color: var(--text-muted); margin-bottom: .25rem; }
.sub-plan-status { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .72rem; font-weight: 600; text-transform: uppercase; }
.sub-plan-status.active { background: rgba(22,163,74,.15); color: #16a34a; }
.sub-plan-status.canceled { background: rgba(220,38,38,.12); color: #dc2626; }
.sub-plan-status.past_due { background: rgba(245,158,11,.15); color: #d97706; }
.sub-plan-actions { margin-top: .75rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.sub-plan-actions .btn { font-size: .8rem; padding: .35rem .7rem; }
.sub-plan-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.sub-plan-col { padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius); }
.sub-plan-col-pending { background: var(--surface2); border-color: var(--primary); }
.sub-plan-col-payment-pending { background: rgba(231,76,60,.08); border: 3px solid var(--expense); }
.currency-conversion { font-size: .8rem !important; }
.sub-disclaimer { font-size: .75rem; color: var(--text-muted); margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid var(--border); line-height: 1.5; }
.sub-plan-col-header { font-size: .8rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: .5rem; }
.sub-features { list-style: none; padding: 0; margin: .75rem 0; }
.sub-features li { font-size: .85rem; padding: .3rem 0; color: var(--text); display: flex; align-items: center; gap: .5rem; }
.sub-features li .bi-check-circle-fill { color: #16a34a; }
.sub-features li .bi-x-circle-fill { color: #dc2626; }
.sub-pm-list { list-style: none; padding: 0; margin: 0; }
.sub-pm-list li { display: flex; align-items: center; justify-content: space-between; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .4rem; font-size: .85rem; }
.sub-pm-list li .pm-default { font-size: .65rem; background: var(--primary); color: #fff; padding: .1rem .4rem; border-radius: 999px; margin-left: .4rem; }
.sub-pm-list li .pm-actions { display: flex; gap: .5rem; margin-left: .5rem; flex-shrink: 0; }
.sub-plan-card { background: var(--surface2); border-radius: var(--radius); padding: 1rem 1.25rem; border: 2px solid var(--border); cursor: pointer; transition: border-color .15s; }
.sub-plan-card:hover { border-color: var(--primary); }
.sub-plan-card.sub-plan-active { border-color: var(--primary); background: rgba(37,99,235,.05); }
.sub-plan-card h4 { margin: 0 0 .25rem; font-size: 1rem; }
.sub-plan-card .sub-price { font-size: 1.2rem; font-weight: 700; color: var(--primary); }
.sub-plan-card .sub-price small { font-size: .7rem; font-weight: 400; color: var(--text-muted); }
.sub-plan-card .sub-features-sm { font-size: .82rem; color: var(--text-muted); margin-top: .4rem; }
.sub-plan-card .sub-features-sm li { padding: .15rem 0; }
[data-theme="dark"] .upgrade-save-note { color: #fff !important; background: rgba(217,119,6,.35) !important; }

/* ─── Admin Tiers ─── */
.tier-table { width: 100%; border-collapse: collapse; }
.tier-table th, .tier-table td { padding: .6rem .75rem; text-align: left; border-bottom: 1px solid var(--border); font-size: .9rem; }
.tier-table th { font-weight: 600; color: var(--text-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .3px; }
.tier-table .tier-actions { text-align: right; white-space: nowrap; }
.tier-table .tier-actions .btn-icon { margin-left: .25rem; }
.tier-badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 600; }
.tier-badge.active { background: rgba(22,163,74,.15); color: #16a34a; }
.tier-badge.inactive { background: rgba(220,38,38,.12); color: #dc2626; }
#tier-features { margin-top: .25rem; }
.tier-features-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: .35rem .75rem; }
#tier-features .ff-row { display: flex; gap: .5rem; align-items: center; margin-bottom: .2rem; }
#tier-features .ff-row label { font-size: .85rem; flex: 0 0 200px; }
#tier-features .ff-row input, #tier-features .ff-row select { flex: 0 0 80px; min-width: 60px; max-width: 100px; }
.checkbox-label { display: inline-flex; align-items: center; gap: .5rem; cursor: pointer; font-size: .9rem; }
.checkbox-label input[type="checkbox"] { width: 1rem; height: 1rem; cursor: pointer; }
#tier-features .ff-row.checkbox-row label { flex: 0 0 200px; font-size: .85rem; }
#tier-features .ff-row.checkbox-row input[type="checkbox"] { width: 1rem; height: 1rem; flex: none; }
#role-permissions { display: grid; grid-template-columns: 1fr 1fr; gap: .15rem .75rem; }
.admin-users-page .tier-table td { font-size: .85rem; }
.admin-users-page .tier-table td:last-child { text-align: right; }

/* ─── Budget Plan ─── */
.bp-add-cat-bar select { flex: 1; }

/* ─── Welcome Overlay ─── */
.welcome-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
}
.welcome-modal {
    background: #fff;
    border-radius: 20px;
    padding: 3rem 2.5rem;
    max-width: 480px;
    width: 90%;
    text-align: center;
    box-shadow: 0 30px 80px rgba(0,0,0,0.3);
    animation: welcomeFadeIn 0.4s ease-out;
}
@keyframes welcomeFadeIn {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
.welcome-icon i { font-size: 3.5rem; color: #18bc9c; }
.welcome-modal h2 { font-size: 1.6rem; font-weight: 800; color: #1a252f; margin: 1rem 0 0.4rem; }
.welcome-sub { font-size: 0.95rem; color: #7f8c9b; margin-bottom: 1.5rem; }
.welcome-plan-info { margin-bottom: 1.5rem; }
.plan-badge {
    display: inline-block;
    background: rgba(24,188,156,0.1);
    color: #18bc9c;
    font-weight: 700;
    font-size: 0.8rem;
    padding: 0.3rem 1rem;
    border-radius: 100px;
    margin-bottom: 0.75rem;
}
.trial-note { font-size: 0.85rem; color: #e67e22; margin: 0; }
.trial-note i { margin-right: 0.3rem; }
.welcome-actions { display: flex; flex-direction: column; gap: 0.5rem; }
.welcome-actions .btn-primary { width: 100%; }
.welcome-actions .btn-outline { width: 100%; color: #7f8c9b; border-color: #e4e7ec; }

/* ─── Onboarding Tour ─── */
.onboarding-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0,0,0,0.35);
    pointer-events: none;
}
.onboarding-card {
    position: fixed;
    z-index: 100000;
    background: #fff;
    border-radius: 14px;
    padding: 1.5rem;
    max-width: 340px;
    width: calc(100vw - 40px);
    box-shadow: 0 10px 40px rgba(0,0,0,0.25);
    pointer-events: auto;
    animation: welcomeFadeIn 0.3s ease-out;
}
.onboarding-step-counter {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #18bc9c;
    margin-bottom: 0.5rem;
}
.onboarding-card h4 { font-size: 1rem; font-weight: 700; color: #1a252f; margin-bottom: 0.4rem; }
.onboarding-card p { font-size: 0.85rem; color: #7f8c9b; line-height: 1.5; margin-bottom: 1rem; }
.onboarding-actions { display: flex; gap: 0.5rem; align-items: center; }
.onboarding-actions .btn-sm { padding: 0.35rem 0.9rem; font-size: 0.8rem; }
.onboarding-actions .btn-link { color: #7f8c9b; text-decoration: none; margin-left: auto; }
.onboarding-actions .btn-link:hover { color: #2c3e50; }

.ticket-description-html img { max-width: 100%; height: auto; border-radius: 4px; margin: .5rem 0; }
.ticket-description-html a { color: #18bc9c; text-decoration: underline; }
.ticket-description-html ul, .ticket-description-html ol { padding-left: 1.5rem; margin: .5rem 0; }
.ticket-description-html blockquote { border-left: 3px solid #18bc9c; padding-left: .75rem; color: #7f8c9b; margin: .5rem 0; }
.ticket-description-html pre { background: #f4f6f8; padding: .75rem; border-radius: 4px; overflow-x: auto; font-size: .85rem; }
.ticket-description-html table { border-collapse: collapse; width: 100%; margin: .5rem 0; }
.ticket-description-html th, .ticket-description-html td { border: 1px solid #dee2e6; padding: .5rem; text-align: left; }
.ticket-description-html th { background: #f4f6f8; font-weight: 600; }
.ticket-description-html hr { border: none; border-top: 1px solid #dee2e6; margin: 1rem 0; }

/* ─── Quill editor inside ticket card ─── */
.ticket-create-page .ql-container { min-height: 250px; font-size: .95rem; }
.ticket-create-page .ql-editor { min-height: 250px; }
.ticket-create-page .card .ql-toolbar { border-radius: var(--radius) var(--radius) 0 0; }
.ticket-create-page .card .ql-container { border-radius: 0 0 var(--radius) var(--radius); }

/* ─── Widen support ticket card ─── */
.ticket-create-page .card { max-width: 1000px !important; }

/* ─── Responsive ─── */
@media (max-width: 1024px) {
    .sidebar { width: 60px; }
    .sidebar .logo { display: none !important; }
    .sidebar .logo-mini { display: block; max-width: 100%; height: auto; background-repeat: no-repeat; }
    .sidebar .nav-text, .sidebar .sidebar-profile-select, .sidebar .sidebar-footer .nav-text { opacity: 0; width: 0; overflow: hidden; }
    .sidebar .sidebar-footer a { justify-content: center; }
    .sidebar .sidebar-profile { padding: .7rem .75rem; justify-content: center; }
    .sidebar .sidebar-profile .nav-icon { margin: 0; }
    #main-content { margin-left: 60px; width: calc(100% - 60px); }
    .sidebar-toggle { display: none; }
}

@media (max-width: 768px) {
    .sidebar { width: 60px; overflow: visible; padding: 0; z-index: 100; }
    .sidebar.sidebar-expanded { width: 60px; }
    .sidebar.sidebar-collapsed { width: 60px; }
    .sidebar .sidebar-toggle { display: flex; right: -14px; z-index: 300; }
    .sidebar .logo { display: none !important; }
    .sidebar .logo-mini { display: block; max-width: 100%; }
    .sidebar .nav-text, .sidebar .sidebar-profile-select, .sidebar .sidebar-footer .nav-text { opacity: 0; width: 0; overflow: hidden; }
    .sidebar .sidebar-footer a { justify-content: center; }
    .sidebar .sidebar-profile { padding: .7rem .75rem; justify-content: center; }
    .sidebar .sidebar-profile .nav-icon { margin: 0; }
    #main-content { margin-left: 60px; width: calc(100% - 60px); padding: 1rem; }
    .page-header h2 { font-size: 1.25rem; }
    .page-header { flex-direction: column; align-items: stretch; }
    .page-header .btn, .page-header a.btn { width: 100%; text-align: center; justify-content: center; }
    .stats-grid { grid-template-columns: 1fr; }
    .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_length { float: none; display: block; text-align: left; margin-bottom: .5rem; }
    .dataTables_wrapper .dataTables_filter input { width: 100%; }
    .note-toolbar { overflow-x: auto; white-space: nowrap; }
    .note-toolbar .note-btn-group { margin-right: 3px; }
    .note-toolbar .note-btn { padding: 4px 6px; font-size: 12px; }
}

@media (max-width: 600px) {
    #main-content { padding: .75rem; }
    .card { padding: 1rem !important; }
    .form-group { margin-bottom: .75rem; }
    .form-input, .form-select { font-size: 16px; }
    .btn { font-size: .85rem; padding: .5rem 1rem; }

    .note-toolbar .note-btn-group .note-btn { padding: 3px 5px; font-size: 11px; }
    .note-toolbar { padding: 5px 2px; }

    table.dataTable { font-size: .8rem; }
    table.dataTable td, table.dataTable th { padding: 4px 6px; }
    .dataTables_wrapper .dataTables_info, .dataTables_wrapper .dataTables_paginate { float: none; text-align: center; }
    .dataTables_wrapper .dataTables_paginate .paginate_button { padding: .2rem .5rem; }

    .sub-grid, .sub-plan-grid { grid-template-columns: 1fr !important; }
    .ledger-card { padding: .75rem !important; }
    #bp-income-list, #bp-expense-list { overflow-x: auto; }
    #bp-income-list > div, #bp-expense-list > div { min-width: 500px; }
    .bp-section { overflow-x: auto; }

    .kb-page { flex-direction: column; }
    .kb-page nav { width: 100% !important; border-right: none !important; border-bottom: 1px solid var(--border); }
}

[data-theme="dark"] .ql-toolbar {
    background: var(--surface);
    border-color: var(--border);
}
[data-theme="dark"] .ql-toolbar .ql-stroke {
    stroke: var(--text);
}
[data-theme="dark"] .ql-toolbar .ql-fill {
    fill: var(--text);
}
[data-theme="dark"] .ql-toolbar .ql-picker {
    color: var(--text);
}
[data-theme="dark"] .ql-toolbar .ql-picker-options {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}
[data-theme="dark"] .ql-container {
    border-color: var(--border);
}
[data-theme="dark"] .ql-editor {
    color: var(--text);
    background: var(--surface2);
}
[data-theme="dark"] .ql-editor.ql-blank::before {
    color: var(--text-muted);
}
[data-theme="dark"] .ql-toolbar button:hover .ql-stroke,
[data-theme="dark"] .ql-toolbar button.ql-active .ql-stroke {
    stroke: var(--primary);
}
[data-theme="dark"] .ql-toolbar button:hover .ql-fill,
[data-theme="dark"] .ql-toolbar button.ql-active .ql-fill {
    fill: var(--primary);
}
[data-theme="dark"] .ql-toolbar button:hover,
[data-theme="dark"] .ql-toolbar button.ql-active {
    color: var(--primary);
}

[data-theme="dark"] .onboarding-card {
    background: var(--surface);
}
[data-theme="dark"] .onboarding-card h4 {
    color: var(--text);
}
[data-theme="dark"] .onboarding-card p {
    color: var(--text-muted);
}
[data-theme="dark"] .onboarding-actions .btn-link {
    color: var(--text-muted);
}
[data-theme="dark"] .onboarding-actions .btn-link:hover {
    color: var(--text);
}

