/* ============ SafeSpend — offline budgeting ============ */
/* Palette per validated reference (dataviz): dark-first, light override. */

:root {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #232322;
  --ink: #ffffff;
  --ink-2: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --border: rgba(255,255,255,0.10);
  --accent: #0ca30c;         /* good green — the "safe" color */
  --accent-ink: #ffffff;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
  --good: #0ca30c; --warning: #fab219; --serious: #ec835a; --critical: #d03b3b;
  --pos: #0ca30c;
  --shadow: 0 8px 24px rgba(0,0,0,0.45);
}
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --border: rgba(11,11,11,0.10);
  --accent: #0ca30c;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
  --pos: #006300;
  --shadow: 0 6px 18px rgba(0,0,0,0.10);
}

/* Business space: whole app shifts to blue so you always know which books you're in */
:root[data-space="business"] { --accent: #3987e5; }
:root[data-theme="light"][data-space="business"] { --accent: #2a78d6; }

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
input, textarea { user-select: text; -webkit-user-select: text; }

#app { max-width: 560px; margin: 0 auto; min-height: 100%; }

/* ---------- space switcher ---------- */
#space-switcher {
  position: sticky; top: 0; z-index: 30;
  display: flex; gap: 8px;
  padding: 10px 16px 8px;
  background: var(--page);
}
#space-switcher.hidden { display: none; }
.space-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--surface); border: 2px solid var(--border); color: var(--muted);
  border-radius: 14px; padding: 12px 0; font-size: 15px; font-weight: 700;
}
.space-btn .sp-ic { font-size: 17px; }
.space-btn.active {
  background: var(--accent); border-color: var(--accent); color: #ffffff;
}

/* ---------- add-sheet space badge ---------- */
#add-space-badge {
  text-align: center; margin-bottom: 10px;
}
#add-space-badge span {
  display: inline-block; background: var(--accent); color: #fff;
  border-radius: 999px; padding: 5px 14px; font-size: 12.5px; font-weight: 700;
  letter-spacing: .3px;
}

/* ---------- screens ---------- */
.screen { display: none; padding: 14px 16px 0; animation: fadein .18s ease; }
.screen.active { display: block; }
@keyframes fadein { from { opacity: .4; transform: translateY(4px);} to { opacity: 1; transform: none;} }
.bottom-space { height: 96px; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0 14px;
}
.topbar h1 { font-size: 22px; font-weight: 700; }
.greeting { font-size: 20px; font-weight: 700; }
.subtle { color: var(--ink-2); font-size: 13px; }
.iconbtn {
  background: var(--surface); border: 1px solid var(--border); color: var(--ink);
  width: 40px; height: 40px; border-radius: 12px; font-size: 18px; line-height: 1;
}
.linkbtn { background: none; border: none; color: var(--s1); font-size: 14px; font-weight: 600; padding: 6px; }
.monthnav { display: flex; align-items: center; gap: 6px; }
.monthnav span { font-weight: 600; font-size: 15px; min-width: 92px; text-align: center; }

button { font-family: inherit; cursor: pointer; }

/* ---------- cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 16px; margin-bottom: 14px;
}
.card h3 { font-size: 14px; font-weight: 600; color: var(--ink-2); margin-bottom: 12px; }

/* ---------- hero ---------- */
.hero { text-align: center; padding: 22px 16px 16px; }
.hero-label { color: var(--ink-2); font-size: 13px; }
.hero-amount { font-size: 42px; font-weight: 800; letter-spacing: -1px; margin: 6px 0 2px; }
.hero-amount.ok { color: var(--good); }
.hero-amount.tight { color: var(--warning); }
.hero-amount.over { color: var(--critical); }
.hero-sub { color: var(--ink-2); font-size: 13px; min-height: 18px; }
.hero-bar { height: 8px; border-radius: 4px; background: var(--surface-2); margin: 14px 0 8px; overflow: hidden; }
.hero-bar-fill { height: 100%; border-radius: 4px; background: var(--good); width: 0%; transition: width .4s ease; }
.hero-foot { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }

/* ---------- stat tiles ---------- */
.statrow { display: flex; gap: 10px; margin-bottom: 14px; }
.stattile { flex: 1; padding: 12px; margin-bottom: 0; text-align: left; }
.stat-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.stat-value { font-size: 17px; font-weight: 700; margin-top: 4px; }
.stat-value.pos { color: var(--pos); }

/* ---------- sections ---------- */
.sectionhead { display: flex; align-items: center; justify-content: space-between; margin: 6px 0 10px; }
.sectionhead h2 { font-size: 15px; font-weight: 700; }

/* ---------- wallets ---------- */
.wallet-row { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 10px; scrollbar-width: none; }
.wallet-row::-webkit-scrollbar { display: none; }
.walletcard {
  min-width: 132px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px; flex-shrink: 0;
}
.walletcard .wname { font-size: 13px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.walletcard .wbal { font-size: 16px; font-weight: 700; margin-top: 4px; white-space: nowrap; }
.walletcard .wbal.neg { color: var(--critical); }

/* ---------- transaction rows ---------- */
.daygroup { margin-bottom: 4px; }
.dayhead { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; padding: 10px 2px 6px; }
.txrow {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 10px 12px; margin-bottom: 8px;
}
.txic {
  width: 40px; height: 40px; border-radius: 12px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center; font-size: 19px; flex-shrink: 0;
}
.txmain { flex: 1; min-width: 0; }
.txname { font-size: 14.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txmeta { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.txamt { font-weight: 700; font-size: 14.5px; white-space: nowrap; }
.txamt.income { color: var(--pos); }
.empty { text-align: center; color: var(--muted); padding: 26px 12px; font-size: 14px; }
.summaryline { color: var(--ink-2); font-size: 13px; padding: 2px 2px 10px; }

/* ---------- insights ---------- */
.insight {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px; margin-bottom: 8px; font-size: 13.5px; color: var(--ink-2);
}
.insight b { color: var(--ink); }
.insight .iic { font-size: 17px; }

/* ---------- budgets ---------- */
.budgetrow { margin-bottom: 12px; }
.budgetrow .bhead { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 6px; }
.budgetrow .bhead b { font-weight: 600; }
.budgetrow .bhead .bnum { color: var(--ink-2); font-size: 13px; }
.bbar { height: 10px; background: var(--surface-2); border-radius: 5px; overflow: hidden; }
.bbar-fill { height: 100%; border-radius: 5px; transition: width .3s ease; }
.bfoot { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 4px; }
.bstatus { font-weight: 600; }
.hint { color: var(--muted); font-size: 13px; text-align: center; padding: 8px 16px; }

/* ---------- charts ---------- */
#donut-wrap { display: flex; justify-content: center; }
#donut-legend { margin-top: 10px; }
.legendrow { display: flex; align-items: center; gap: 10px; padding: 6px 2px; font-size: 13.5px; }
.legendrow .dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.legendrow .lname { flex: 1; color: var(--ink-2); }
.legendrow .lval { font-weight: 600; }
.legendrow .lpct { color: var(--muted); font-size: 12px; width: 40px; text-align: right; }
.split-seg-bar { display: flex; height: 18px; border-radius: 6px; overflow: hidden; gap: 2px; background: var(--page); }
.split-seg { height: 100%; }
#split-legend { margin-top: 10px; }
.bars { display: flex; align-items: flex-end; gap: 3px; height: 120px; margin-top: 6px; }
.bar { flex: 1; background: var(--s1); border-radius: 3px 3px 0 0; min-height: 1px; position: relative; }
.bar.today { outline: 2px solid var(--ink); outline-offset: 1px; }
.bars-axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 10.5px; margin-top: 4px; }
.momrow { display: flex; align-items: center; gap: 10px; padding: 7px 2px; font-size: 13.5px; }
.momrow .lname { flex: 1; color: var(--ink-2); }
.momrow .delta { font-weight: 600; font-size: 12.5px; }
.momrow .delta.up { color: var(--critical); }
.momrow .delta.down { color: var(--pos); }

/* ---------- settings ---------- */
.settings-group {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; margin-bottom: 14px; overflow: hidden;
}
.setting {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 16px; font-size: 15px; border-bottom: 1px solid var(--border);
}
.setting:last-child { border-bottom: none; }
.setting:active { background: var(--surface-2); }
.setting.danger { color: var(--critical); }
.setvalue { color: var(--muted); font-size: 14px; }
.about { text-align: center; color: var(--muted); font-size: 12px; line-height: 1.6; }

.managerow {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px; margin-bottom: 8px;
}
.managerow .mmain { flex: 1; min-width: 0; }
.managerow .mname { font-weight: 600; font-size: 14.5px; }
.managerow .mmeta { color: var(--muted); font-size: 12px; }

/* ---------- tabbar ---------- */
#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 4px calc(8px + env(safe-area-inset-bottom));
}
.tab {
  background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 10.5px; width: 64px; padding: 4px 0;
}
.tab.active { color: var(--ink); font-weight: 600; }
.tab-ic { font-size: 20px; }
.fab {
  width: 54px; height: 54px; border-radius: 50%; border: none;
  background: var(--accent); color: var(--accent-ink); font-size: 28px; line-height: 1;
  margin-top: -26px; box-shadow: var(--shadow);
}

/* ---------- sheets ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 50;
  display: none; align-items: flex-end; justify-content: center;
}
.sheet-backdrop.open { display: flex; animation: fadein .15s ease; }
.sheet {
  background: var(--page); border-radius: 20px 20px 0 0;
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom));
  animation: slideup .2s ease;
}
@keyframes slideup { from { transform: translateY(40px); opacity:.5; } to { transform: none; opacity:1; } }
.sheet-grip { width: 36px; height: 4px; border-radius: 2px; background: var(--grid); margin: 4px auto 12px; }
.sheet h3 { font-size: 17px; font-weight: 700; margin-bottom: 12px; }
.dialog {
  background: var(--page); border-radius: 20px; padding: 20px;
  width: calc(100% - 48px); max-width: 400px; margin-bottom: 30vh;
}
.dialog h3 { margin-bottom: 8px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 16px; }
.btn {
  flex: 1; border: none; border-radius: 14px; padding: 14px; font-size: 16px; font-weight: 700;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.primary.danger { background: var(--critical); }
.btn.ghost { background: var(--surface); color: var(--ink); border: 1px solid var(--border); }
.btn.big { padding: 16px; }

/* ---------- add sheet ---------- */
.segmented { display: flex; background: var(--surface); border-radius: 12px; padding: 4px; margin-bottom: 10px; }
.segmented button {
  flex: 1; border: none; background: none; color: var(--muted);
  padding: 9px 0; border-radius: 9px; font-size: 14px; font-weight: 600;
}
.segmented button.active { background: var(--surface-2); color: var(--ink); }
.amount-display {
  text-align: center; font-size: 40px; font-weight: 800; letter-spacing: -1px;
  padding: 8px 0 12px; min-height: 64px;
}
.amount-display span:first-child { color: var(--muted); font-size: 24px; margin-right: 4px; }
.chiprow { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.chiprow::-webkit-scrollbar { display: none; }
.chiprow.wrap { flex-wrap: wrap; overflow: visible; }
.chip {
  background: var(--surface); border: 1px solid var(--border); color: var(--ink-2);
  border-radius: 999px; padding: 8px 14px; font-size: 13.5px; white-space: nowrap; flex-shrink: 0;
}
.chip.active { background: var(--ink); color: var(--page); border-color: var(--ink); font-weight: 700; }
.catgrid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px;
  max-height: 172px; overflow-y: auto; margin-bottom: 10px; padding: 2px;
}
.catbtn {
  background: var(--surface); border: 1px solid var(--border); color: var(--ink-2);
  border-radius: 12px; padding: 8px 2px; font-size: 11.5px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.catbtn .cic { font-size: 20px; }
.catbtn.active { border-color: var(--accent); color: var(--ink); background: var(--surface-2); font-weight: 600; }
.addrow { display: flex; gap: 8px; margin-bottom: 8px; }
.addrow input[type="date"] { flex: 0 0 40%; }
.addrow input {
  background: var(--surface); border: 1px solid var(--border); color: var(--ink);
  border-radius: 12px; padding: 11px 12px; font-size: 14px; width: 100%;
}
.switchrow { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); padding: 4px 2px; }
.switchrow input { width: 18px; height: 18px; accent-color: var(--accent); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 4px; }
.keypad button {
  background: var(--surface); border: 1px solid var(--border); color: var(--ink);
  border-radius: 14px; padding: 13px 0; font-size: 22px; font-weight: 600;
}
.keypad button:active { background: var(--surface-2); }

/* ---------- forms ---------- */
.formfield { margin-bottom: 12px; }
.formfield label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; }
.formfield input, .formfield select {
  background: var(--surface); border: 1px solid var(--border); color: var(--ink);
  border-radius: 12px; padding: 12px; font-size: 15px; width: 100%;
}

/* ---------- search ---------- */
.searchrow { margin-bottom: 8px; }
.searchrow input {
  background: var(--surface); border: 1px solid var(--border); color: var(--ink);
  border-radius: 12px; padding: 11px 14px; font-size: 14px; width: 100%;
}

/* ---------- onboarding ---------- */
.onboard {
  position: fixed; inset: 0; background: var(--page); z-index: 100;
  display: none; overflow-y: auto;
}
.onboard.open { display: block; }
.onboard-inner { max-width: 420px; margin: 0 auto; padding: 48px 24px 40px; }
.onboard-logo { font-size: 52px; text-align: center; }
.onboard h1 { text-align: center; font-size: 28px; margin: 8px 0 6px; }
.onboard p { text-align: center; line-height: 1.5; margin-bottom: 24px; }
.oblabel { display: block; font-size: 13px; color: var(--muted); margin: 18px 0 8px; font-weight: 600; }
#ob-income {
  background: var(--surface); border: 1px solid var(--border); color: var(--ink);
  border-radius: 12px; padding: 13px; font-size: 16px; width: 100%;
}
.obmethods { display: flex; gap: 10px; }
.obmethod {
  flex: 1; background: var(--surface); border: 1px solid var(--border); color: var(--ink-2);
  border-radius: 14px; padding: 13px 10px; text-align: left;
  display: flex; flex-direction: column; gap: 4px; font-size: 12px;
}
.obmethod b { color: var(--ink); font-size: 14.5px; }
.obmethod.active { border-color: var(--accent); background: var(--surface-2); }
#ob-start { width: 100%; margin-top: 26px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--page); border-radius: 999px;
  padding: 10px 18px; font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: all .25s ease; z-index: 200; white-space: nowrap; max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- web auth extras ---------- */
#auth-error { color: var(--critical); font-size: 13.5px; min-height: 20px; text-align: center; margin: 4px 0 8px; }
.authswitch { text-align: center; color: var(--ink-2); font-size: 14px; margin-top: 16px; cursor: pointer; }
.authswitch b { color: var(--s1); }
