/* ─────────────────────────────────────────────
   FinApp — Main Stylesheet
   ───────────────────────────────────────────── */

/* 1. CSS Custom Properties (Design Tokens) */
:root {
  --accent:         #4f46e5;
  --accent-hover:   #4338ca;
  --accent-light:   #eef2ff;

  --success:        #10b981;
  --success-light:  #d1fae5;
  --warning:        #f59e0b;
  --warning-light:  #fef3c7;
  --danger:         #ef4444;
  --danger-light:   #fee2e2;

  --bg-primary:     #ffffff;
  --bg-secondary:   #f1f5f9;
  --bg-tertiary:    #e2e8f0;

  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;

  --border:         #e2e8f0;
  --border-strong:  #cbd5e1;

  --sidebar-width:  240px;
  --topbar-height:  60px;
  --radius-sm:      6px;
  --radius:         10px;
  --radius-lg:      16px;

  --shadow-sm:  0 1px 3px rgba(0,0,0,.08);
  --shadow:     0 4px 16px rgba(0,0,0,.08);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.12);
}

[data-theme="dark"] {
  --bg-primary:     #1e293b;
  --bg-secondary:   #0f172a;
  --bg-tertiary:    #334155;
  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;
  --border:         #334155;
  --border-strong:  #475569;
  --accent-light:   #1e1b4b;
}

/* 2. Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; scroll-behavior: smooth; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
  background: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { vertical-align: middle; }
textarea { resize: vertical; }
select, input, textarea, button { font-family: inherit; }

/* 3. Layout — Sidebar + Main */
.sidebar {
  position: fixed;
  left: 0; top: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 200;
  transition: transform .25s ease;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.2rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}
.sidebar-close { display: none; background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 1.1rem; }
.sidebar-nav { flex: 1; padding: .75rem .75rem; overflow-y: auto; }
.nav-item {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .65rem .85rem;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: .9rem;
  font-weight: 500;
  margin-bottom: .15rem;
  transition: background .15s, color .15s;
  position: relative;
}
.nav-item:hover { background: var(--bg-secondary); color: var(--text-primary); text-decoration: none; }
.nav-item.active { background: var(--accent-light); color: var(--accent); }
.nav-icon { flex-shrink: 0; width: 18px; height: 18px; }
.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .6rem;
}
.user-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: .6rem; }
.user-avatar {
  width: 32px; height: 32px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700;
  flex-shrink: 0;
}
.user-name  { font-size: .85rem; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-email { font-size: .75rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-logout { color: var(--text-muted); padding: .4rem; border-radius: 6px; display: flex; transition: color .15s, background .15s; }
.btn-logout:hover { color: var(--danger); background: var(--danger-light); }

.main-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-height);
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.5rem;
  gap: 1rem;
  z-index: 100;
}
.topbar-menu-btn { display: none; background: none; border: none; cursor: pointer; color: var(--text-secondary); padding: .3rem; }
.topbar-title { font-size: 1.05rem; font-weight: 600; color: var(--text-primary); flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: .5rem; }
.btn-icon { background: none; border: none; cursor: pointer; color: var(--text-secondary); padding: .4rem; border-radius: 6px; transition: background .15s, color .15s; }
.btn-icon:hover { background: var(--bg-secondary); color: var(--text-primary); }

.main-content {
  flex: 1;
  padding: 1.5rem;
  max-width: 1200px;
  width: 100%;
}
.sidebar-overlay { display: none; }

/* 4. Cards */
.card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.1rem;
}
.card-title { font-size: 1rem; font-weight: 600; color: var(--text-primary); }
.card-subtitle { font-size: .8rem; color: var(--text-muted); }
.card-link { font-size: .85rem; color: var(--accent); font-weight: 500; }
.card-link:hover { text-decoration: underline; }

/* 5. Dashboard Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.stat-card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 1.25rem;
}
.stat-label { font-size: .8rem; color: var(--text-muted); font-weight: 500; margin-bottom: .4rem; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.6rem; font-weight: 700; color: var(--text-primary); line-height: 1.1; }
.stat-sub   { font-size: .8rem; color: var(--text-muted); margin-top: .3rem; }
.stat-income   .stat-value { color: var(--success); }
.stat-expenses .stat-value { color: var(--danger); }
.stat-positive .stat-value { color: var(--success); }
.stat-negative .stat-value { color: var(--danger); }
.stat-neutral  .stat-value { color: var(--accent); }

/* 6. Dashboard Two-Column */
.dashboard-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 1.25rem; }
.dashboard-left, .dashboard-right { display: flex; flex-direction: column; gap: 1.25rem; }
.dashboard-left .card, .dashboard-right .card { margin-bottom: 0; }

/* 7. Category Bars */
.category-bar-row { display: flex; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.category-bar-label { display: flex; align-items: center; gap: .4rem; width: 180px; flex-shrink: 0; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.cat-group-tag { font-size: .7rem; padding: .1rem .4rem; border-radius: 999px; font-weight: 500; }
.cat-group-business { background: #ede9fe; color: #6d28d9; }
.cat-group-personal { background: #fef3c7; color: #b45309; }
.cat-group-family   { background: #dcfce7; color: #166534; }
.category-bar-wrap  { flex: 1; height: 8px; background: var(--bg-secondary); border-radius: 99px; overflow: hidden; }
.category-bar-fill  { height: 100%; border-radius: 99px; transition: width .4s ease; }
.category-bar-amount { font-size: .82rem; font-weight: 600; width: 70px; text-align: right; flex-shrink: 0; }

/* 8. Transaction List */
.txn-list { display: flex; flex-direction: column; gap: 0; }
.txn-row {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .65rem 0;
  border-bottom: 1px solid var(--border);
}
.txn-row:last-child { border-bottom: none; }
.txn-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.txn-info { flex: 1; min-width: 0; }
.txn-desc { font-size: .88rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txn-meta { font-size: .75rem; color: var(--text-muted); }
.txn-amount { font-size: .9rem; font-weight: 600; white-space: nowrap; }
.amount-income  { color: var(--success); }
.amount-expense { color: var(--danger); }
.amount-usd { font-weight: 600; }
.currency-tag { font-size: .7rem; font-weight: 400; color: var(--text-muted); }

/* 9. Budget Cards */
.budget-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.1rem; }
.budget-card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 1.25rem;
}
.budget-card-ok      { border-left: 4px solid var(--success); }
.budget-card-warning { border-left: 4px solid var(--warning); }
.budget-card-danger  { border-left: 4px solid var(--danger); }
.budget-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: .8rem; }
.budget-name { font-size: .95rem; font-weight: 600; }
.budget-meta { font-size: .75rem; color: var(--text-muted); margin-top: .15rem; }
.budget-card-actions { display: flex; gap: .3rem; }
.budget-amounts { display: flex; gap: .5rem; align-items: baseline; margin-bottom: .5rem; }
.budget-spent { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); }
.budget-total { font-size: .82rem; color: var(--text-muted); }
.budget-footer { display: flex; justify-content: space-between; font-size: .8rem; color: var(--text-muted); margin-top: .4rem; }
.budget-dates { font-size: .75rem; color: var(--text-muted); margin-top: .4rem; }
.budget-pct-label { font-weight: 600; }
.budget-pct-label.pct-ok      { color: var(--success); }
.budget-pct-label.pct-warning { color: var(--warning); }
.budget-pct-label.pct-danger  { color: var(--danger); }

/* Budget mini (dashboard) */
.budget-mini-row { margin-bottom: 1rem; }
.budget-mini-header { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: .3rem; }
.budget-mini-pct { font-weight: 600; }
.budget-mini-pct.ok      { color: var(--success); }
.budget-mini-pct.warning { color: var(--warning); }
.budget-mini-pct.danger  { color: var(--danger); }
.budget-mini-amounts { display: flex; justify-content: space-between; font-size: .75rem; color: var(--text-muted); margin-top: .25rem; }

/* 10. Progress Bar */
.progress-bar {
  height: 8px;
  background: var(--bg-secondary);
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar-lg { height: 10px; }
.progress-fill { height: 100%; border-radius: 99px; transition: width .5s ease; }
.progress-ok      { background: var(--success); }
.progress-warning { background: var(--warning); }
.progress-danger  { background: var(--danger); }

/* 11. Goals */
.goals-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1.1rem; }
.goal-card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 1.25rem;
}
.goal-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: .75rem; }
.goal-name { font-size: .95rem; font-weight: 600; }
.goal-desc { font-size: .78rem; color: var(--text-muted); margin-top: .2rem; }
.goal-card-actions { display: flex; gap: .3rem; align-items: center; }
.goal-progress-section { }
.goal-amounts { display: flex; align-items: baseline; gap: .3rem; margin-bottom: .5rem; }
.goal-current { font-size: 1.2rem; font-weight: 700; }
.goal-separator, .goal-target { color: var(--text-muted); }
.goal-footer { display: flex; justify-content: space-between; font-size: .78rem; color: var(--text-muted); margin-top: .4rem; }
.goal-pct { font-weight: 600; }
.goal-remaining { font-size: .78rem; color: var(--text-muted); margin-top: .2rem; }
.goal-mini-row { margin-bottom: .9rem; }
.goal-mini-header { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: .3rem; font-weight: 500; }
.goal-mini-name { font-weight: 600; }

/* 12. Alerts */
.alerts-banner { margin-bottom: 1.2rem; display: flex; flex-direction: column; gap: .5rem; }
.alert-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--warning-light);
  border: 1px solid var(--warning);
  color: #92400e;
  padding: .7rem 1rem;
  border-radius: var(--radius);
  font-size: .875rem;
}
.alert-item svg { flex-shrink: 0; color: var(--warning); }
.alert-item span { flex: 1; }
.alert-dismiss { background: none; border: none; cursor: pointer; color: #92400e; font-size: 1rem; padding: .2rem .4rem; border-radius: 4px; }
.alert-dismiss:hover { background: rgba(0,0,0,.08); }

/* 13. Data Table */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--border);
}
.data-table td { padding: .7rem .75rem; border-bottom: 1px solid var(--border); font-size: .88rem; vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg-secondary); }
.txn-date { color: var(--text-muted); font-size: .82rem; white-space: nowrap; }
.txn-desc-cell { font-weight: 500; }
.actions-cell { white-space: nowrap; text-align: right; }

/* Category chips */
.cat-chip { display: inline-block; font-size: .75rem; padding: .2rem .55rem; border-radius: 999px; font-weight: 500; }
.cat-chip-empty { font-size: .75rem; color: var(--text-muted); font-style: italic; }

/* Tags */
.tags-row { display: flex; flex-wrap: wrap; gap: .25rem; margin-top: .25rem; }
.tag { background: var(--bg-secondary); color: var(--text-secondary); font-size: .7rem; padding: .1rem .4rem; border-radius: 4px; }

/* 14. Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1.1rem;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all .15s;
  line-height: 1;
}
.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover  { background: var(--accent-hover); }
.btn-ghost    { background: var(--bg-secondary); color: var(--text-secondary); }
.btn-ghost:hover    { background: var(--bg-tertiary); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover   { opacity: .88; }
.btn-outline  { background: transparent; border: 1.5px solid currentColor; }
.btn-sm  { padding: .4rem .75rem; font-size: .82rem; }
.btn-icon-sm {
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); padding: .3rem .45rem;
  border-radius: 5px; font-size: .85rem;
  transition: background .15s, color .15s;
}
.btn-icon-sm:hover    { background: var(--bg-secondary); color: var(--text-primary); }
.btn-icon-sm.btn-delete:hover { background: var(--danger-light); color: var(--danger); }

/* FAB */
.fab {
  position: fixed;
  bottom: 2rem; right: 2rem;
  width: 54px; height: 54px;
  background: var(--accent);
  color: #fff;
  border: none; border-radius: 50%;
  font-size: 1.6rem; line-height: 1;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(79,70,229,.4);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, background .15s;
  z-index: 90;
}
.fab:hover { background: var(--accent-hover); transform: scale(1.06); }

/* 15. Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .84rem; font-weight: 500; color: var(--text-secondary); margin-bottom: .35rem; }
.form-group input[type="text"],
.form-group input[type="email"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group input[type="date"],
.form-group input[type="month"],
.form-group input[type="color"],
.form-group select,
.form-group textarea {
  width: 100%;
  padding: .65rem .9rem;
  background: var(--bg-primary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color .15s;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,70,229,.12); }
.form-group input[type="color"] { padding: .2rem .4rem; height: 40px; cursor: pointer; }
.form-group input[type="range"] { padding: 0; margin-top: .25rem; width: 100%; cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.form-check { display: flex; align-items: center; gap: .5rem; margin-bottom: 1rem; font-size: .88rem; }
.form-check input { width: auto; }
.optional { color: var(--text-muted); font-weight: 400; font-size: .8rem; }
.form-hint { font-size: .78rem; color: var(--text-muted); }
.usd-preview { font-size: .82rem; color: var(--text-muted); font-style: italic; }

/* Type toggle */
.type-toggle-group { display: flex; gap: .5rem; margin-bottom: 1rem; }
.type-toggle {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .55rem; border: 1.5px solid var(--border); border-radius: var(--radius);
  cursor: pointer; font-weight: 500; font-size: .9rem; transition: all .15s;
}
.type-toggle:has(input:checked) { border-color: var(--accent); background: var(--accent-light); color: var(--accent); }
.type-toggle input { display: none; }

/* 16. Modals */
.modal { display: none; position: fixed; inset: 0; z-index: 1000; }
.modal.open { display: flex; align-items: center; justify-content: center; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.45); backdrop-filter: blur(2px); }
.modal-box {
  position: relative;
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: 1.75rem;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: slideUp .2s ease;
}
.modal-sm { max-width: 380px; }
@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.25rem; }
.modal-header h3 { font-size: 1.1rem; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 1.1rem; padding: .2rem; }
.modal-actions { display: flex; gap: .75rem; justify-content: flex-end; margin-top: 1.25rem; }

/* 17. Toolbar & Filters */
.page-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.page-subtitle { color: var(--text-muted); font-size: .9rem; }
.filters-row { display: flex; flex-wrap: wrap; gap: .5rem; flex: 1; }
.filter-input, .filter-select {
  padding: .5rem .85rem;
  background: var(--bg-primary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: .85rem;
  color: var(--text-primary);
  outline: none;
}
.filter-input:focus, .filter-select:focus { border-color: var(--accent); }
.filter-input { min-width: 180px; }
.filter-select { }

/* Summary pills */
.summary-pills { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .75rem; }
.pill { background: var(--bg-primary); border: 1px solid var(--border); color: var(--text-secondary); padding: .3rem .8rem; border-radius: 999px; font-size: .8rem; font-weight: 500; }
.pill-expense { border-color: var(--danger); color: var(--danger); background: var(--danger-light); }
.pill-income  { border-color: var(--success); color: var(--success); background: var(--success-light); }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: .75rem; padding: 1rem 0 .25rem; border-top: 1px solid var(--border); margin-top: .5rem; }
.page-btn { background: var(--bg-secondary); border: 1px solid var(--border); padding: .45rem .9rem; border-radius: var(--radius); font-size: .85rem; cursor: pointer; transition: background .15s; }
.page-btn:hover { background: var(--accent-light); color: var(--accent); }
.page-info { font-size: .85rem; color: var(--text-muted); }

/* 18. Badges */
.badge { display: inline-block; font-size: .72rem; font-weight: 600; padding: .15rem .5rem; border-radius: 999px; }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: #b45309; }
.badge-danger  { background: var(--danger-light); color: var(--danger); }
.badge-muted   { background: var(--bg-tertiary); color: var(--text-muted); }

/* Sidebar nav badge */
.nav-item .badge { position: absolute; right: .75rem; top: 50%; transform: translateY(-50%); }

/* 19. Settings */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.settings-grid .card { margin-bottom: 0; }
.divider { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.section-title { font-size: .9rem; font-weight: 600; color: var(--text-secondary); margin-bottom: .75rem; text-transform: uppercase; letter-spacing: .05em; }
.rates-table { margin-top: .75rem; }
.color-swatch { width: 20px; height: 20px; border-radius: 4px; border: 1px solid var(--border); }
.categories-table-wrap { max-height: 400px; overflow-y: auto; }

/* 20. Toast */
.toast-container { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); z-index: 9999; display: flex; flex-direction: column; align-items: center; gap: .5rem; pointer-events: none; }
.toast {
  background: #1e293b;
  color: #f8fafc;
  padding: .7rem 1.2rem;
  border-radius: var(--radius);
  font-size: .88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toastIn .2s ease;
  pointer-events: auto;
}
.toast-error { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* 21. Loading & Empty States */
.loading-spinner {
  text-align: center;
  padding: 2.5rem;
  color: var(--text-muted);
  font-size: .9rem;
}
.empty-state { color: var(--text-muted); font-size: .9rem; padding: .5rem 0; }
.empty-card {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px dashed var(--border);
}
.empty-card p { margin: .8rem 0 1.2rem; font-size: .95rem; }
.error-msg { color: var(--danger); padding: 1rem; font-size: .9rem; }
.text-danger { color: var(--danger); }
.text-muted  { color: var(--text-muted); font-size: .88rem; }

/* 22. Responsive */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .settings-grid  { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  :root { --sidebar-width: 240px; }
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .sidebar-close { display: block; }
  .sidebar-overlay { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 190; opacity: 0; pointer-events: none; transition: opacity .25s; }
  .sidebar-overlay.visible { opacity: 1; pointer-events: auto; }
  .main-wrapper { margin-left: 0; }
  .topbar-menu-btn { display: flex; }
  .main-content { padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .budget-grid, .goals-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .modal-box { margin: 0 1rem; }
  .fab { bottom: 1.25rem; right: 1.25rem; }
  .page-toolbar { flex-direction: column; }
  .filters-row { flex-direction: column; }
  .filter-input, .filter-select { width: 100%; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 1.3rem; }
}

/* ── Insights & Coach ──────────────────────────────────────────────── */

/* Layout helpers */
.insights-kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.insights-split-6040 {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

.insights-two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
}

/* KPI strip cards */
.ikpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .2rem;
}
.ikpi-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; }
.ikpi-value { font-size: 1.55rem; font-weight: 800; line-height: 1.15; }
.ikpi-foot  { font-size: .78rem; color: var(--text-muted); display: flex; align-items: center; gap: .35rem; }
.ikpi-score { position: relative; }

/* Shared colours */
.income-color  { color: var(--success); }
.expense-color { color: var(--danger); }

/* MoM badges */
.mom-badge      { font-size: .72rem; font-weight: 700; padding: .15rem .5rem; border-radius: 999px; white-space: nowrap; }
.mom-up         { background: #fee2e2; color: #dc2626; }
.mom-up-bad     { background: #fee2e2; color: #dc2626; }
.mom-down       { background: #d1fae5; color: #059669; }
.mom-down-good  { background: #d1fae5; color: #059669; }
.mom-neutral    { background: var(--bg-secondary); color: var(--text-muted); }

/* Chart canvas wrapper */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap canvas { width: 100% !important; height: 100% !important; }

/* Health ring card */
.health-card-v2 { display: flex; flex-direction: column; align-items: center; }
.health-ring-wrap { position: relative; width: 148px; height: 148px; margin: 0 auto 1rem; }
.health-ring { width: 100%; height: 100%; }
.health-ring-label {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.health-score { font-size: 2.2rem; font-weight: 900; line-height: 1; }
.health-grade { font-size: 1.15rem; font-weight: 700; }

.health-components { width: 100%; border-top: 1px solid var(--border); padding-top: .75rem; }
.hc-row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: .8rem; padding: .3rem 0; color: var(--text-secondary); gap: .75rem;
}
.hc-right { display: flex; align-items: center; gap: .5rem; }
.hc-bar-track { width: 80px; height: 6px; background: var(--bg-secondary); border-radius: 99px; overflow: hidden; }
.hc-bar-fill  { height: 100%; border-radius: 99px; transition: width .6s ease; }
.hc-row span:last-child { font-weight: 700; color: var(--text-primary); min-width: 32px; text-align: right; }

/* Donut chart + legend layout */
.donut-layout { display: flex; align-items: center; gap: 1.25rem; }
.donut-legend { flex: 1; display: flex; flex-direction: column; gap: .3rem; }
.dl-row { display: flex; align-items: center; gap: .5rem; font-size: .8rem; }
.dl-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.dl-name { flex: 1; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-pct  { font-weight: 600; color: var(--text-primary); width: 34px; text-align: right; }
.dl-val  { color: var(--text-muted); font-size: .75rem; width: 44px; text-align: right; }

/* Velocity section */
.vel-progress-block { margin-bottom: 1rem; }
.vel-track {
  height: 14px; background: var(--bg-secondary); border-radius: 99px;
  position: relative; overflow: visible; margin-bottom: .4rem;
}
.vel-bar-actual {
  position: absolute; left: 0; top: 0; height: 100%;
  background: var(--accent); border-radius: 99px; transition: width .5s ease;
}
.vel-bar-proj {
  position: absolute; left: 0; top: 0; height: 100%;
  background: rgba(239,68,68,.35); border-radius: 99px;
  border: 2px dashed rgba(239,68,68,.7); transition: width .5s ease;
}
.vel-labels { display: flex; justify-content: space-between; font-size: .75rem; color: var(--text-muted); }
.vel-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: .65rem;
}
.vel-box {
  background: var(--bg-secondary); border-radius: var(--radius-sm);
  padding: .7rem .85rem;
}
.vel-box-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); margin-bottom: .25rem; }
.vel-box-value { font-size: 1.1rem; font-weight: 700; }
.vel-box-value span { font-size: .75rem; font-weight: 400; color: var(--text-muted); }

/* Coach banner (full-width) */
.coach-banner {
  display: flex; align-items: flex-start; gap: 1.1rem;
  background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
}
.coach-banner-emoji  { font-size: 2rem; line-height: 1; flex-shrink: 0; }
.coach-banner-label  { font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; opacity: .75; margin-bottom: .3rem; font-weight: 700; }
.coach-banner-text   { font-size: .95rem; font-style: italic; line-height: 1.6; opacity: .95; }

/* Observations grid */
.obs-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .75rem;
}
.obs-card {
  display: flex; gap: .75rem; align-items: flex-start;
  padding: .85rem 1rem;
  border-radius: var(--radius);
  border-left: 4px solid transparent;
}
.obs-positive { background: #f0fdf4; border-color: var(--success); }
.obs-warning  { background: #fffbeb; border-color: var(--warning); }
.obs-danger   { background: #fef2f2; border-color: var(--danger); }
.obs-info     { background: #eff6ff; border-color: #3b82f6; }
[data-theme="dark"] .obs-positive { background: rgba(16,185,129,.08); }
[data-theme="dark"] .obs-warning  { background: rgba(245,158,11,.08); }
[data-theme="dark"] .obs-danger   { background: rgba(239,68,68,.08); }
[data-theme="dark"] .obs-info     { background: rgba(59,130,246,.08); }
.obs-icon  { font-size: 1.4rem; flex-shrink: 0; line-height: 1.2; }
.obs-title { font-size: .86rem; font-weight: 700; margin-bottom: .2rem; }
.obs-text  { font-size: .8rem; color: var(--text-secondary); line-height: 1.55; }

/* Action items */
.action-items { display: flex; flex-direction: column; gap: .5rem; }
.action-item {
  display: flex; gap: .75rem; align-items: flex-start;
  padding: .6rem .75rem;
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  font-size: .86rem;
  color: var(--text-secondary);
  line-height: 1.5;
}
.action-num {
  flex-shrink: 0; width: 22px; height: 22px;
  background: var(--accent); color: #fff;
  border-radius: 50%; font-size: .72rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}

/* Goal mini */
.goal-pct-badge { font-size: .72rem; font-weight: 700; padding: .1rem .4rem; border-radius: 999px; }

/* Responsive */
@media (max-width: 1100px) {
  .insights-kpi-strip   { grid-template-columns: repeat(2, 1fr); }
  .insights-split-6040  { grid-template-columns: 1fr; }
  .obs-grid             { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .insights-kpi-strip  { grid-template-columns: 1fr 1fr; }
  .insights-two-col    { grid-template-columns: 1fr; }
  .donut-layout        { flex-direction: column; }
  .vel-grid            { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .insights-kpi-strip  { grid-template-columns: 1fr; }
  .vel-grid            { grid-template-columns: 1fr; }
}
