/* ---------- Colour variables (light theme is the default) ---------- */
:root {
  --bg: #f1f4f9; --surface: #ffffff; --text: #0b1b33; --muted: #5d6d86; --border: #e0e6ef;
  --accent: #1553d6; --accent-text: #ffffff; --income: #0f8a5f; --expense: #c93a3a; --warn-bg: #fdecec;
  --shadow: 0 1px 2px rgba(11, 27, 51, 0.05), 0 8px 24px rgba(11, 27, 51, 0.06);
}
[data-theme="dark"] {
  --bg: #0a1220; --surface: #121c2e; --text: #e7edf7; --muted: #8c9bb3; --border: #22304a;
  --accent: #5b8dff; --accent-text: #071226; --income: #3ed598; --expense: #ff7b7b; --warn-bg: #3a1c22;
  --shadow: none;
}

* { box-sizing: border-box; margin: 0; }
body {
  font-family: "Manrope", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 240px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.logo { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.35rem; color: var(--accent); margin-bottom: 32px; padding: 0 8px; }
nav { display: flex; flex-direction: column; gap: 4px; }
.nav-btn, .ghost-btn {
  display: flex; align-items: center; gap: 12px;
  background: none; border: none; text-align: left;
  padding: 11px 12px; border-radius: 10px; font-weight: 500; color: var(--muted);
  transition: background 0.2s, color 0.2s, transform 0.2s;
}
.nav-btn:hover, .ghost-btn:hover { background: var(--bg); color: var(--text); transform: translateX(3px); }
.nav-btn.active { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.sidebar-bottom { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.ghost-btn.danger:hover { color: var(--expense); }
.nav-btn svg, .ghost-btn svg { width: 20px; height: 20px; }

/* ---------- Main area ---------- */
main { flex: 1; padding: 32px; max-width: 1100px; }
h1 { font-size: 1.8rem; font-weight: 800; margin-bottom: 20px; }
h2 { font-size: 1rem; font-weight: 700; margin-bottom: 12px; }
.view { display: none; }
.view.active { display: block; animation: fade 0.3s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.label { display: block; color: var(--muted); font-size: 0.85rem; margin-bottom: 6px; }
.income { color: var(--income); }
.expense { color: var(--expense); }

/* Summary cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 20px; }
.cards .card { transition: transform 0.2s; }
.cards .card:hover { transform: translateY(-3px); }
.cards strong { font-size: 1.6rem; font-weight: 800; }

/* Charts */
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.chart-wrap { position: relative; height: 260px; }
.empty { color: var(--muted); text-align: center; padding: 16px 0; }

/* Forms */
.form { max-width: 480px; display: flex; flex-direction: column; gap: 16px; margin-bottom: 20px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 0.9rem; }
input[type="number"], input[type="text"], input[type="date"], select {
  padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg);
}
.type-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.type-switch label { position: relative; }
.type-switch input { position: absolute; opacity: 0; }
.type-switch span { display: block; text-align: center; padding: 10px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; transition: all 0.2s; }
.type-switch input:checked + span { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 700; }
.type-switch input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.primary-btn { background: var(--accent); color: var(--accent-text); border: none; padding: 12px 18px; border-radius: 10px; font-weight: 700; transition: transform 0.15s, opacity 0.2s; }
.primary-btn:hover { opacity: 0.9; transform: translateY(-2px); }
.error { color: var(--expense); font-size: 0.9rem; min-height: 1.2em; }

/* History */
.filters { display: flex; gap: 8px; margin-bottom: 16px; }
.filter-btn { padding: 8px 16px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); transition: all 0.2s; }
.filter-btn:hover { border-color: var(--accent); }
.filter-btn.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 700; }
.table-wrap { padding: 8px 12px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 560px; }
th, td { padding: 12px 8px; text-align: left; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; font-size: 0.85rem; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg); }
.right { text-align: right; }
.badge { padding: 3px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; background: var(--bg); }
.badge.income { color: var(--income); }
.badge.expense { color: var(--expense); }
.delete-btn { background: none; border: none; color: var(--muted); padding: 6px; border-radius: 8px; transition: color 0.2s, background 0.2s; }
.delete-btn:hover { color: var(--expense); background: var(--warn-bg); }
.delete-btn svg { width: 18px; height: 18px; }

/* Budget */
.budget-status { max-width: 480px; }
.budget-numbers { display: flex; justify-content: space-between; margin-bottom: 16px; }
.budget-numbers strong { font-size: 1.5rem; font-weight: 800; }
.progress { height: 14px; background: var(--bg); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
#progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: 999px; transition: width 0.5s ease, background 0.3s; }
#progress-bar.over { background: var(--expense); }
.budget-message { margin-top: 12px; font-weight: 500; }
.budget-message.over { color: var(--expense); background: var(--warn-bg); padding: 10px 12px; border-radius: 10px; }

/* Toast message */
.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--text); color: var(--bg);
  padding: 12px 18px; border-radius: 10px; font-weight: 500;
  opacity: 0; transform: translateY(10px); pointer-events: none; transition: all 0.3s;
}
.toast.show { opacity: 1; transform: none; }

/* ---------- Mobile: sidebar becomes a bottom bar ---------- */
@media (max-width: 800px) {
  body { flex-direction: column; }
  .sidebar { position: fixed; bottom: 0; top: auto; left: 0; right: 0; width: 100%; height: auto; flex-direction: row; padding: 6px; z-index: 10; border-right: none; border-top: 1px solid var(--border); }
  .logo, .sidebar-bottom .ghost-btn span { display: none; }
  .sidebar-bottom { flex-direction: row; }
  nav { flex-direction: row; flex: 1; justify-content: space-around; }
  .nav-btn { flex-direction: column; gap: 2px; font-size: 0.7rem; padding: 8px; }
  .nav-btn:hover, .ghost-btn:hover { transform: none; }
  .sidebar-bottom { margin: 0; }
  main { padding: 20px 16px 100px; }
  .toast { bottom: 90px; right: 16px; left: 16px; text-align: center; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Month bar, budget plan, alerts ---------- */
.month-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.month-bar button:not(.filter-btn) { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px; display: flex; transition: border-color 0.2s; }
.month-bar button:not(.filter-btn):hover { border-color: var(--accent); }
.month-bar strong { min-width: 160px; text-align: center; font-size: 1.1rem; }
.hint { color: var(--muted); margin-bottom: 16px; }
#budget .card { max-width: 760px; margin-bottom: 16px; }
.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 16px; }
.plan-grid label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 0.9rem; }
.plan-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
#alerts:not(:empty) { margin-bottom: 16px; }
.alert { background: var(--warn-bg); color: var(--expense); padding: 10px 14px; border-radius: 10px; font-weight: 700; margin-bottom: 8px; }
.progress-row { margin-bottom: 18px; }
.row-head { display: flex; justify-content: space-between; margin-bottom: 6px; font-weight: 500; }
.bar { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.5s ease; }
.bar.over { background: var(--expense); }
.row-note { font-size: 0.85rem; color: var(--muted); margin-top: 4px; }
.row-note.over { color: var(--expense); font-weight: 700; }

/* ---------- Add-expense form on the Budget plan page ---------- */
.plan-form { display: grid; grid-template-columns: 2fr 1fr auto; gap: 12px; align-items: end; margin-bottom: 8px; }
.plan-form label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 0.9rem; }
.plan-form .primary-btn { height: 44px; }
.plan-actions { margin-top: 8px; }
.row-head .delete-btn { vertical-align: middle; padding: 2px 4px; margin-left: 4px; }
.row-head .delete-btn svg { width: 16px; height: 16px; }
@media (max-width: 800px) { .plan-form { grid-template-columns: 1fr; } }

/* ---------- Net worth, accounts, loans ---------- */
.clickable { cursor: pointer; }
.cards .clickable:hover { border-color: var(--accent); }
.card small { font-weight: 400; font-size: 0.75rem; color: var(--muted); }
#networth .card, #loans .card { margin-bottom: 16px; }
#networth .cards .card, #loans .cards .card { margin-bottom: 0; }
#networth .cards, #loans .cards { margin-bottom: 16px; }
.acct { padding: 12px 0; border-bottom: 1px solid var(--border); }
.acct:last-child { border-bottom: none; }
.acct-actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.mini-btn { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 6px 12px; font-size: 0.85rem; font-weight: 500; transition: border-color 0.2s; }
.mini-btn:hover { border-color: var(--accent); }
.mini-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; margin-top: 14px; align-items: center; }
#loans .mini-form { margin-top: 0; }
.mini-form .check { display: flex; gap: 8px; align-items: center; font-size: 0.9rem; }
.transfer-line { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 0.9rem; color: var(--muted); }

/* ---------- Banking theme ---------- */
body { font-variant-numeric: tabular-nums; }
h1 { letter-spacing: -0.02em; }
.card { border-radius: 16px; }
.sidebar { background: #0b1b33; border-right: none; }
.sidebar .logo { color: #fff; }
.sidebar .nav-btn, .sidebar .ghost-btn { color: #9fb0cc; }
.sidebar .nav-btn:hover, .sidebar .ghost-btn:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.sidebar .nav-btn.active { background: var(--accent); color: #fff; }
.sidebar .ghost-btn.danger:hover { color: #ff9a9a; }
th { text-transform: uppercase; font-size: 0.72rem; letter-spacing: 0.06em; }
.hero { background: linear-gradient(135deg, #0b1b33 0%, #16408f 100%); color: #fff; border: none; padding: 28px; margin-bottom: 16px; }
.hero .label, .hero small { color: #b9c8e3; }
.hero strong { display: block; font-size: 2.4rem; font-weight: 800; margin: 4px 0 6px; }
.kind-cash { border-top: 4px solid var(--income); }
.kind-checking { border-top: 4px solid var(--accent); }
.kind-credit { border-top: 4px solid var(--expense); }
.acct, .acct:last-child { border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 12px; }
.acct-credit { background: linear-gradient(135deg, #0b1b33, #1f3f7a); color: #fff; border-color: transparent; }
.acct-credit .row-note { color: #c3d1ea; }
.acct-credit .progress { background: rgba(255, 255, 255, 0.2); border-color: transparent; }
.acct-credit .mini-btn { background: rgba(255, 255, 255, 0.12); color: #fff; border-color: rgba(255, 255, 255, 0.25); }
.acct-credit .delete-btn { color: #c3d1ea; }
.avatar { display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: var(--accent); color: var(--accent-text); font-weight: 700; font-size: 0.85rem; margin-right: 10px; }
dialog { border: none; border-radius: 16px; padding: 24px; width: min(380px, 92vw); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
dialog::backdrop { background: rgba(7, 18, 38, 0.55); }
dialog h2 { font-size: 1.2rem; margin-bottom: 4px; }
dialog input { width: 100%; margin: 8px 0; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }

/* ---------- Account detail, loans ---------- */
.acct { cursor: pointer; transition: box-shadow 0.2s, transform 0.2s; }
.acct:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.back-btn { margin-bottom: 14px; }
.loan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; margin: 14px 0; }
.loan-grid label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 0.9rem; }
#loan-form .check { display: flex; gap: 8px; align-items: center; font-size: 0.9rem; margin-bottom: 8px; }
.progress.thin { height: 8px; margin-bottom: 4px; }
td small { color: var(--muted); }
td.actions { white-space: nowrap; }
.dialog-field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 0.9rem; margin-top: 8px; }
.dialog-field[hidden] { display: none; }
dialog select { width: 100%; }

/* ---------- Welcome screen, set-up wizard ---------- */
[hidden] { display: none !important; }
.overlay { position: fixed; inset: 0; z-index: 100; background: linear-gradient(135deg, #0b1b33, #16408f); display: grid; place-items: center; padding: 20px; overflow: auto; }
.welcome-card { background: var(--surface); color: var(--text); border-radius: 20px; padding: 32px; width: min(440px, 100%); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.35); animation: fade 0.3s ease; }
.welcome-card.wide { width: min(560px, 100%); }
.logo.big { font-size: 1.8rem; margin-bottom: 6px; padding: 0; }
.block { display: block; width: 100%; margin-top: 12px; text-align: center; padding: 12px; }
.stack { display: flex; flex-direction: column; gap: 14px; margin-top: 12px; }
.stack label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 0.9rem; }
.step-label { color: var(--muted); font-size: 0.85rem; font-weight: 700; margin-bottom: 8px; }
.ob-step h2 { font-size: 1.3rem; margin: 18px 0 4px; }
.ob-step .mini-form { margin-top: 10px; }
.ob-list { list-style: none; padding: 0; margin: 12px 0; }
.ob-list li { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); }
#ob-cash { width: 100%; margin-top: 8px; }
.profile-chip { color: #9fb0cc; font-size: 0.8rem; padding: 0 12px 10px; word-break: break-all; }
@media (max-width: 800px) { .profile-chip { display: none; } }

textarea { width: 100%; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; resize: vertical; }
#transfer-dialog { width: min(520px, 92vw); }
#transfer-dialog textarea { margin: 8px 0; font-size: 0.8rem; word-break: break-all; }

/* ============================================================
   v2 — simpler, friendlier layout
   ============================================================ */
button, input, select, textarea { font: inherit; }
.muted { color: var(--muted); }
.grow { flex: 1; min-width: 0; }

/* ---------- Credit: "Designed & made by Kedar" ---------- */
.sidebar { overflow-y: auto; }
.credit { display: flex; flex-direction: column; gap: 2px; margin: 12px 12px 0; padding-top: 14px; border-top: 1px solid rgba(255, 255, 255, 0.14); font-size: 0.78rem; color: #9fb0cc; }
.credit strong { color: #fff; font-size: 1.05rem; font-weight: 800; letter-spacing: 0.01em; }
.credit-line { margin-top: 24px; text-align: center; font-size: 0.85rem; color: var(--muted); }
.credit-line strong { color: var(--text); font-weight: 800; }

/* ---------- Page headers, clickable cards ---------- */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.primary-btn svg { width: 16px; height: 16px; vertical-align: -2px; margin-right: 2px; }
.card.clickable { position: relative; }
.card .go { position: absolute; top: 16px; right: 14px; width: 18px; height: 18px; color: var(--muted); }
.card.clickable:hover .go { color: var(--accent); }
.hint { margin-bottom: 12px; }

/* ---------- Money page: folded forms, tidy account rows ---------- */
details.fold > summary { cursor: pointer; list-style: none; font-weight: 700; color: var(--accent); padding: 8px 0 2px; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold[open] > summary { margin-bottom: 4px; }
details.card.fold { margin-bottom: 16px; }
details.card.fold > summary { color: var(--text); padding: 0; font-size: 1rem; display: flex; justify-content: space-between; align-items: center; }
details.card.fold > summary::after { content: "+"; color: var(--muted); font-size: 1.3rem; line-height: 1; }
details.card.fold[open] > summary::after { content: "−"; }
details.card.fold[open] > summary { margin-bottom: 8px; }
.acct-actions .spacer { flex: 1; }
.acct-actions .delete-btn { padding: 8px; }
.acct { cursor: pointer; }

/* ---------- People rows (Contacts and Loans) ---------- */
.people-list { display: flex; flex-direction: column; gap: 8px; }
#contacts .people-list { margin-bottom: 16px; }
.person-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); cursor: pointer; transition: border-color 0.2s; }
.person-row:hover { border-color: var(--accent); }
.person-row .avatar { margin: 0; flex: none; }
.person-name { flex: 1; min-width: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bal { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.2; }
.bal small { font-size: 0.72rem; color: var(--muted); }
.bal strong { font-size: 1.05rem; }
.go-inline { width: 16px; height: 16px; color: var(--muted); flex: none; }
#contacts .card, #contact-detail .card { margin-bottom: 16px; }
#contacts .mini-form { margin-top: 0; grid-template-columns: 1fr auto; }
#contact-empty { margin-bottom: 0; }

/* ---------- Contact page ---------- */
.person-head { display: flex; align-items: center; gap: 16px; }
.avatar.big { width: 56px; height: 56px; font-size: 1.4rem; margin: 0; flex: none; }
.person-head h1 { margin: 0 0 4px; font-size: 1.5rem; overflow-wrap: anywhere; }
#cd-status { font-weight: 700; }
.person-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.danger-text { color: var(--expense); }
#contact-detail .cards { margin-bottom: 16px; }
.loan-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.loan-item:last-child { border-bottom: none; padding-bottom: 0; }
.loan-item:first-child { padding-top: 0; }
.loan-item .top { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.loan-item .meta { color: var(--muted); font-size: 0.82rem; margin: 2px 0 0; }
.loan-item .actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.activity-row { display: flex; align-items: flex-start; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.activity-row:last-child { border-bottom: none; }
.activity-row p { margin: 0; }
.activity-row small { color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex: none; background: var(--muted); }
.dot.income { background: var(--income); }
.dot.expense { background: var(--expense); }

/* ---------- Loans page ---------- */
#loan-headline { font-size: 1.9rem; }
#loans .card { max-width: 760px; }
#loans .hero { max-width: 760px; }

/* ---------- Add expense pop-up ---------- */
#loan-dialog { width: min(480px, 94vw); max-height: 92vh; overflow: auto; }
#loan-form { display: flex; flex-direction: column; gap: 12px; }
#loan-dialog h2 { margin-bottom: 0; }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 0.9rem; }
.field input, .field select { margin: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset.seg-group { border: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.seg-group legend { font-weight: 500; font-size: 0.9rem; margin-bottom: 6px; padding: 0; }
.seg { position: relative; display: block; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.seg span { display: flex; flex-direction: column; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; font-weight: 700; transition: border-color 0.2s; }
.seg span small { font-weight: 500; color: var(--muted); font-size: 0.8rem; }
.seg input:checked + span { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.seg input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 2px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 0.9rem; }
dialog input[type="checkbox"], dialog input[type="radio"] { width: auto; margin: 0; }
.exp-box { display: flex; flex-direction: column; gap: 10px; padding: 12px; border: 1px dashed var(--border); border-radius: 12px; }
.preview { font-weight: 700; min-height: 1.3em; }
#loan-dialog .error { min-height: 0; }

/* ---------- Set-up wizard extras ---------- */
.link-btn { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 8px 4px; }
.link-btn:hover { color: var(--text); }
.push-left { margin-right: auto; }
.guest-note { margin: 14px 0 0; font-size: 0.85rem; }

/* ---------- Phones and small screens ---------- */
@media (max-width: 800px) {
  /* bottom bar = pages, top bar = credit + menu icons */
  .sidebar { padding-bottom: calc(6px + env(safe-area-inset-bottom)); overflow: visible; }
  .sidebar-bottom { position: fixed; top: 0; left: 0; right: 0; z-index: 11; margin: 0; flex-direction: row; align-items: center; gap: 2px; background: #0b1b33; padding: calc(6px + env(safe-area-inset-top)) 10px 6px 14px; }
  .sidebar-bottom .ghost-btn { padding: 8px; }
  .credit { order: -1; margin: 0 auto 0 0; padding: 0; border: none; font-size: 0.68rem; line-height: 1.15; }
  .credit strong { font-size: 0.95rem; }
  main { padding: calc(64px + env(safe-area-inset-top)) 16px 100px; }
  .nav-btn { font-size: 0.66rem; padding: 8px 4px; white-space: nowrap; }
  .cards { grid-template-columns: 1fr 1fr; gap: 12px; }
  .cards .card { padding: 14px; }
  .cards strong { font-size: 1.25rem; }
  .card .go { top: 12px; right: 10px; }
  h1 { font-size: 1.5rem; }
  #loan-headline { font-size: 1.5rem; }
  .hero strong { font-size: 1.9rem; }
  .charts { grid-template-columns: 1fr; }
  .person-actions .primary-btn, .person-actions .filter-btn { flex: 1; }
  .field-row { grid-template-columns: 1fr; }
  #contacts .mini-form { grid-template-columns: 1fr; }
  .welcome-card { padding: 24px 20px; }
  .dialog-actions { flex-wrap: wrap; }
}
@media (max-width: 380px) { .cards { grid-template-columns: 1fr; } }

/* Tables turn into easy-to-read cards on phones */
@media (max-width: 700px) {
  .table-wrap { padding: 4px 12px; }
  table { min-width: 0; }
  table thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
  tbody tr:last-child { border-bottom: none; }
  td { border: none; padding: 3px 0; display: flex; justify-content: space-between; align-items: baseline; gap: 12px; text-align: right; }
  td::before { content: attr(data-label); color: var(--muted); font-size: 0.8rem; text-align: left; flex: none; }
  td.actions { justify-content: flex-end; }
  td.actions::before { content: none; }
  tbody tr:hover { background: none; }
}

/* ---------- Reports, history tools, savings ---------- */
.kind-savings { border-top: 4px solid #8e5bb5; }
.section-title { font-size: 1rem; margin: 22px 0 10px; color: var(--muted); }
.hist-tools { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.hist-tools input[type="search"] { flex: 1; min-width: 160px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.insights { list-style: none; padding: 0; margin: 0 0 16px; display: grid; gap: 8px; }
.insights li { background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: 12px; padding: 12px 14px; }
.chip-list { display: flex; flex-wrap: wrap; gap: 8px 16px; }
#month-pick { padding: 7px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); color: var(--text); font: inherit; }
.edit-btn:hover { color: var(--accent); background: var(--bg); }
#reports .card { margin-bottom: 16px; }
#reports .cards .card, #reports .charts .card { margin-bottom: 0; }
#reports .cards, #reports .charts { margin-bottom: 16px; }
@media print {
  [data-theme="dark"] { --bg: #fff; --surface: #fff; --text: #0b1b33; --muted: #5d6d86; --border: #e0e6ef; }
  body > *:not(main) { display: none !important; }
  main { padding: 0; max-width: none; }
  .month-bar, .head-actions, .view:not(#reports) { display: none !important; }
  #reports { display: block !important; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* ---------- Dashboard polish ---------- */
.money-hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; align-items: center; margin-bottom: 8px; }
.money-hero .hero-main strong { font-size: 2.6rem; }
.hero-split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hero-split > div { background: rgba(255, 255, 255, 0.1); border-radius: 14px; padding: 14px; transition: background 0.2s, transform 0.2s; }
.hero-split > div:hover { background: rgba(255, 255, 255, 0.18); transform: translateY(-2px); }
.hero-split strong { font-size: 1.35rem; margin: 2px 0 0; }
.cards .card small { display: block; margin-top: 4px; color: var(--muted); font-size: 0.78rem; }
.share-card { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; max-width: 480px; margin-bottom: 16px; }
.share-card .hint { margin: 2px 0 0; }
.share-btns { display: flex; gap: 8px; flex-wrap: wrap; }
@media (max-width: 700px) {
  .money-hero { grid-template-columns: 1fr; padding: 22px; gap: 16px; }
  .money-hero .hero-main strong { font-size: 2.1rem; }
}
