/* Stash — mobile-first money tracker. Built for iPhone Safari standalone
   (Add to Home Screen), so everything respects the notch / home-indicator
   safe areas and uses big thumb-friendly tap targets. */

:root {
  --bg: #0c1116;
  --bg-elev: #141b22;
  --bg-elev2: #1b242d;
  --line: #243038;
  --text: #eef3f7;
  --muted: #8aa0b0;
  --accent: #2ee59d;       /* save / positive */
  --accent-ink: #053826;
  --spend: #ff6b6b;        /* expense / negative */
  --income: #4f8cff;
  --warn: #ffd166;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win, even over class rules that set
   display (e.g. .login is display:grid). Without this, toggling [hidden] in
   JS wouldn't actually hide those elements. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}

body { min-height: 100dvh; }

h1 { font-size: 20px; margin: 0; }
h2 { font-size: 17px; }
button { font-family: inherit; cursor: pointer; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }
code {
  background: var(--bg-elev2); padding: 1px 5px; border-radius: 5px; font-size: 12px;
}

/* ---------- banners ---------- */
.banner { margin: 12px; padding: 12px 14px; border-radius: 12px; font-size: 14px; line-height: 1.4; }
.banner--info  { background: #15263a; color: #cfe2ff; }
.banner--error { background: #3a1620; color: #ffd0d6; }

/* ---------- buttons / fields ---------- */
.btn {
  border: none; border-radius: 12px; padding: 13px 18px; font-size: 15px; font-weight: 600;
  color: var(--text); background: var(--bg-elev2);
}
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--ghost { background: transparent; color: var(--muted); }
.btn--block { width: 100%; }
.btn:active { transform: translateY(1px); }
.linkbtn { background: none; border: none; color: var(--accent); font-size: 14px; font-weight: 600; padding: 4px; }
.linkbtn--danger { color: var(--spend); }
.iconbtn {
  background: var(--bg-elev); border: 1px solid var(--line); color: var(--text);
  width: 38px; height: 38px; border-radius: 11px; font-size: 22px; line-height: 1; display: grid; place-items: center;
}

.field { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.field > span { font-size: 13px; color: var(--muted); }
.field input {
  background: var(--bg-elev2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 13px 14px; font-size: 16px; /* 16px stops iOS zoom-on-focus */
}
.field input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.row { display: flex; gap: 10px; }
.field--grow { flex: 1; }
.card {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin: 12px;
}
.section-title { margin: 18px 12px 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.empty { color: var(--muted); text-align: center; padding: 28px 16px; font-size: 14px; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login__card { width: 100%; max-width: 360px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 28px; font-weight: 800; }
.brand__mark { font-size: 30px; }
.brand__name { letter-spacing: -0.02em; }
.login__card .field { margin: 14px 0; }
.login__switch { text-align: center; margin-top: 18px; }

/* ---------- app shell ---------- */
#app { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px); }
.view { padding-top: var(--safe-top); }

.monthbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 14px 12px 6px;
}
.monthbar h1 { flex: 1; text-align: center; }
.monthbar--plain h1 { text-align: left; }

/* ---------- tiles ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; padding: 6px 12px; }
.tile {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 10px; display: flex; flex-direction: column; gap: 4px;
}
.tile__label { font-size: 12px; color: var(--muted); }
.tile__value { font-size: 17px; font-weight: 700; letter-spacing: -0.02em; }
.tile--spent .tile__value { color: var(--spend); }
.tile--income .tile__value { color: var(--income); }
.tile--net .tile__value { color: var(--accent); }

/* ---------- savings rate ---------- */
.saverate__row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.saverate__row strong { font-size: 18px; color: var(--accent); }

/* ---------- progress bars ---------- */
.bar { background: var(--bg-elev2); border-radius: 999px; height: 8px; overflow: hidden; }
.bar--lg { height: 12px; }
.bar__fill { background: var(--accent); height: 100%; width: 0%; border-radius: 999px; transition: width .35s ease; }
.bar__fill--good { background: var(--accent); }

/* ---------- safe to spend ---------- */
.safe .saverate__row strong { font-size: 20px; color: var(--accent); }
.safe.is-over .saverate__row strong { color: var(--spend); }
.safe.is-over .bar__fill { background: var(--spend); }

/* ---------- section header with action ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; padding-right: 12px; }
.section-head .section-title { flex: 1; }
.section-head .iconbtn { width: 32px; height: 32px; font-size: 19px; }

/* ---------- budget rows (reuse .cat layout, add state colors) ---------- */
.bud__amt--over { color: var(--spend); font-weight: 700; }
.bar__fill--warn { background: var(--warn); }
.bar__fill--over { background: var(--spend); }

/* ---------- trend arrows in breakdown ---------- */
.trend { font-size: 11px; margin-left: 6px; white-space: nowrap; }
.trend--up { color: var(--spend); }
.trend--down { color: var(--accent); }
.trend--flat { color: var(--muted); }

/* ---------- budget editor inputs ---------- */
.budget-inputs { margin: 8px 0; }
.budget-input {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 7px 0; border-bottom: 1px solid var(--line);
}
.budget-input__cat { display: flex; align-items: center; gap: 9px; font-size: 14px; }
.budget-input__cat span:first-child { font-size: 18px; }
.budget-input input {
  width: 120px; text-align: right;
  background: var(--bg-elev2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 9px 11px; font-size: 16px;
}
.budget-input input:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* ---------- breakdown ---------- */
.breakdown { padding: 0 12px 8px; }
.cat {
  display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.cat:last-child { border-bottom: none; }
.cat__icon { font-size: 20px; width: 34px; height: 34px; display: grid; place-items: center; background: var(--bg-elev); border-radius: 10px; }
.cat__body { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.cat__name { font-size: 14px; display: flex; justify-content: space-between; gap: 8px; }
.cat__amt { color: var(--muted); white-space: nowrap; }

/* ---------- history filter bar ---------- */
.filterbar { display: flex; gap: 8px; padding: 2px 12px 10px; }
.filter-search {
  flex: 1; min-width: 0;
  background: var(--bg-elev2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 11px 14px; font-size: 16px;
}
.filter-search:focus { outline: 2px solid var(--accent); border-color: transparent; }
.filter-select {
  background: var(--bg-elev2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 0 12px; font-size: 14px; font-weight: 600;
}

/* ---------- transaction list ---------- */
.txlist { padding: 0 12px; }
.tx {
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px; align-items: center;
  padding: 12px 0; border-bottom: 1px solid var(--line);
}
.tx__icon { font-size: 20px; width: 40px; height: 40px; display: grid; place-items: center; background: var(--bg-elev); border-radius: 12px; }
.tx__body { min-width: 0; }
.tx__title { font-size: 15px; font-weight: 600; }
.tx__sub { font-size: 12px; color: var(--muted); }
.tx__amt { font-weight: 700; white-space: nowrap; }
.tx__amt--expense { color: var(--spend); }
.tx__amt--income { color: var(--income); }
.tx__del { background: none; border: none; color: var(--muted); font-size: 18px; padding: 4px 6px; }
.tx--tappable { cursor: pointer; border-radius: 10px; }
.tx--tappable:active { background: var(--bg-elev); }
.txlist--compact .tx { padding: 9px 0; }
.day-head { font-size: 12px; color: var(--muted); margin: 16px 0 2px; font-weight: 600; }

/* ---------- goals ---------- */
.savings-summary { display: flex; flex-direction: column; gap: 4px; }
.savings-summary strong { font-size: 24px; color: var(--accent); letter-spacing: -0.02em; }
.goals { padding: 0 12px; }
.goal {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 10px;
}
.goal__top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.goal__name { font-size: 16px; font-weight: 700; }
.goal__pct { font-size: 13px; color: var(--accent); font-weight: 700; }
.goal__right { display: flex; align-items: center; gap: 8px; }
.goal__nums { margin-top: 8px; font-size: 13px; color: var(--muted); }
.goal__nums strong { color: var(--text); }

.goaldetail__head { display: flex; justify-content: space-between; align-items: center; }
.goaldetail__actions { display: flex; gap: 6px; }
.goaldetail__progress { margin: 6px 0 14px; }
.goaldetail__nums { font-size: 18px; margin: 10px 0 2px; }
.contrib { display: flex; gap: 8px; margin: 8px 0 4px; }
.contrib input {
  flex: 1; background: var(--bg-elev2); border: 1px solid var(--line); color: var(--text);
  border-radius: 12px; padding: 13px 14px; font-size: 16px;
}

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: 18px; z-index: 30;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
  width: 60px; height: 60px; border-radius: 50%; border: none;
  background: var(--accent); color: var(--accent-ink);
  font-size: 32px; font-weight: 400; line-height: 1; display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(46, 229, 157, 0.35);
}
.fab:active { transform: scale(0.94); }

/* ---------- bottom tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(12, 17, 22, 0.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tab {
  background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 11px; font-weight: 600;
}
.tab__icon { font-size: 20px; filter: grayscale(0.4); }
.tab.is-active { color: var(--accent); }
.tab.is-active .tab__icon { filter: none; }

/* ---------- bottom sheets ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; }
.sheet[hidden] { display: none; }
.sheet__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.sheet__panel {
  position: relative; width: 100%; max-height: 92dvh; overflow-y: auto;
  background: var(--bg-elev); border-top-left-radius: 22px; border-top-right-radius: 22px;
  padding: 8px 16px calc(20px + var(--safe-bottom));
  animation: sheetUp .26s cubic-bezier(.2,.8,.2,1);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.sheet__grip { width: 40px; height: 4px; border-radius: 999px; background: var(--line); margin: 6px auto 12px; }
.sheet__title { margin: 4px 0 10px; }
.sheet__actions { display: flex; gap: 10px; margin-top: 16px; }
.sheet__actions .btn { flex: 1; }

/* segmented control */
.seg { display: flex; background: var(--bg-elev2); border-radius: 12px; padding: 4px; gap: 4px; margin: 4px 0 4px; }
.seg__btn { flex: 1; background: none; border: none; color: var(--muted); padding: 10px; border-radius: 9px; font-weight: 600; font-size: 15px; }
.seg__btn.is-active { background: var(--accent); color: var(--accent-ink); }

/* big amount entry */
.amount { display: flex; align-items: center; justify-content: center; gap: 6px; padding: 18px 0 6px; }
.amount__cur { font-size: 30px; color: var(--muted); font-weight: 700; }
.amount__input {
  background: none; border: none; color: var(--text); font-size: 46px; font-weight: 800;
  width: 70%; text-align: center; letter-spacing: -0.02em; padding: 0;
}
.amount__input:focus { outline: none; }
.amount__input::placeholder { color: var(--line); }

/* ---------- switch row (e.g. Repeat monthly) ---------- */
.switchrow {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin: 14px 0 4px; padding: 12px 14px;
  background: var(--bg-elev2); border: 1px solid var(--line); border-radius: 12px;
}
.switchrow__text { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.switch {
  appearance: none; -webkit-appearance: none; flex: 0 0 auto;
  width: 46px; height: 28px; border-radius: 999px; background: var(--line);
  position: relative; cursor: pointer; transition: background .15s ease;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px;
  border-radius: 50%; background: #fff; transition: transform .15s ease;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(18px); }

/* ---------- goal pace pill ---------- */
.pace { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.pace--ok { background: #0f3b2b; color: var(--accent); }
.pace--behind { background: #3a2417; color: var(--warn); }

/* ---------- recurring list rows ---------- */
.rec { display: grid; grid-template-columns: auto 1fr auto auto auto; gap: 8px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.rec:last-child { border-bottom: none; }
.rec__icon { font-size: 19px; width: 36px; height: 36px; display: grid; place-items: center; background: var(--bg-elev2); border-radius: 10px; }
.rec__body { min-width: 0; }
.rec__title { font-size: 14px; font-weight: 600; }
.rec__sub { font-size: 12px; color: var(--muted); }
.rec__amt { font-weight: 700; font-size: 14px; white-space: nowrap; }
.rec__del { background: none; border: none; color: var(--muted); font-size: 17px; padding: 4px 6px; }
.rec.is-paused { opacity: 0.5; }

/* ---------- toast (undo, confirmations) ---------- */
.toast {
  position: fixed; left: 12px; right: 12px; z-index: 60;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px);
  background: var(--bg-elev2); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.45);
  animation: toastUp .22s ease;
}
.toast[hidden] { display: none !important; }
.toast span { font-size: 14px; }
.toast__action { background: none; border: none; color: var(--accent); font-weight: 700; font-size: 14px; padding: 4px 6px; }
@keyframes toastUp { from { transform: translateY(12px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- pull-to-refresh ---------- */
.ptr {
  position: fixed; top: calc(var(--safe-top) + 6px); left: 50%; transform: translateX(-50%) scale(0.6);
  z-index: 15; width: 34px; height: 34px; border-radius: 50%;
  background: var(--bg-elev2); border: 1px solid var(--line);
  display: grid; place-items: center; font-size: 18px; color: var(--accent);
  opacity: 0; pointer-events: none; transition: opacity .15s ease, transform .15s ease;
}
.ptr.is-pulling { opacity: 1; }
.ptr.is-refreshing { opacity: 1; transform: translateX(-50%) scale(1); animation: spin .7s linear infinite; }
@keyframes spin { to { transform: translateX(-50%) scale(1) rotate(360deg); } }

/* category picker grid */
.catgrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 8px 0; }
.catbtn {
  background: var(--bg-elev2); border: 1px solid transparent; border-radius: 12px;
  padding: 10px 4px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  color: var(--muted); font-size: 11px; font-weight: 600;
}
.catbtn__icon { font-size: 22px; }
.catbtn.is-active { border-color: var(--accent); color: var(--text); background: var(--bg-elev); }
