/* Finance: light, in the manner of iOS (grouped lists, large titles, tab bar). */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #000000;
  --muted: #8a8a8e;
  --sub: #6c6c70;
  --sep: rgba(60, 60, 67, 0.16);
  --fill: rgba(118, 118, 128, 0.12);
  --blue: #007aff;
  --green: #248a3d;
  --red: #d70015;
  --orange: #c93400;
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
/* Like an app: no text selection or long-press menus outside the fields; on a touch screen also no zoom (pinch,
   double tap), no rubber band or pull-to-refresh (app.js and login.js cancel the pinch gestures iOS lets through).
   A computer keeps its ordinary scrolling: Safari on a Mac would not scroll the page with these. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
@media (pointer: coarse) {
  html, body { touch-action: pan-x pan-y; overscroll-behavior: none; }
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.3 var(--font);
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
input, textarea, .selectable { -webkit-user-select: text; user-select: text; }
img, svg { -webkit-user-drag: none; }
button, input, select { font: inherit; color: inherit; letter-spacing: inherit; }
button { -webkit-tap-highlight-color: transparent; }
a { color: var(--blue); text-decoration: none; }
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.he { direction: rtl; unicode-bidi: isolate; }

/* ---------------------------------------------------------------- header with the large title and months */
.top {
  position: sticky; top: 0; z-index: 20;
  padding-top: env(safe-area-inset-top);
  background: rgba(242, 242, 247, 0.86);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  transition: box-shadow 0.2s;
}
.top.scrolled { box-shadow: 0 0.5px 0 var(--sep); }
.top-in { max-width: 680px; margin: 0 auto; padding: 6px 16px 8px; }
.title { margin: 0; font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: 0.01em; transition: font-size 0.2s var(--ease), line-height 0.2s var(--ease); }
.top.scrolled .title { font-size: 22px; line-height: 30px; }
.back { display: inline-flex; align-items: center; border: 0; background: none; color: var(--blue); font-size: 17px; padding: 2px 10px 2px 0; margin: 0 0 2px -7px; cursor: pointer; transition: opacity 0.15s; }
.back svg { width: 24px; height: 24px; stroke-width: 2.4; flex: none; }
.back:active { opacity: 0.45; }
#info-back:empty { display: none; }
#info-back .back { font-size: 16px; margin-bottom: 6px; max-width: 100%; }
#info-back .back span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.months { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 8px -16px 0; padding: 0 16px 2px; scroll-padding: 0 16px; }
.months::-webkit-scrollbar { display: none; }
.months:empty { display: none; }
.month {
  flex: none; border: 0; border-radius: 999px; padding: 7px 14px; background: var(--fill); color: var(--text);
  font-size: 15px; font-weight: 500; cursor: pointer; transition: background 0.18s, color 0.18s, transform 0.12s;
}
.month[aria-pressed="true"] { background: var(--text); color: #fff; }
.month:active { transform: scale(0.95); }
.month small { font-size: 12px; opacity: 0.6; margin-left: 4px; font-weight: 400; }

/* ---------------------------------------------------------------- screen */
.screen {
  max-width: 680px; margin: 0 auto;
  padding: 8px 16px calc(96px + env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right));
}
.screen.enter > * { animation: rise 0.34s var(--ease) backwards; animation-delay: calc(var(--i, 0) * 30ms); }
.screen.enter[data-dir="next"] > * { animation-name: from-right; }
.screen.enter[data-dir="prev"] > * { animation-name: from-left; }

/* a big number on top of a screen */
.hero { padding: 6px 4px 18px; }
.hero-label { color: var(--sub); font-size: 15px; }
.hero-value { font-size: 40px; line-height: 1.1; font-weight: 700; letter-spacing: -0.02em; margin-top: 2px; }
.hero-sub { color: var(--muted); font-size: 14px; margin-top: 4px; }

/* the month at a glance: money in, money out, the result */
.summary { background: var(--card); border-radius: 14px; padding: 16px; margin-bottom: 28px; }
.summary-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.summary-label { color: var(--sub); font-size: 14px; }
.summary-value { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; margin-top: 2px; }
.summary-bar { display: flex; gap: 3px; height: 8px; margin: 14px 0 12px; }
.summary-bar span { border-radius: 4px; min-width: 4px; transform-origin: left center; animation: grow 0.6s var(--ease) backwards 0.1s; }
.summary-total { display: flex; justify-content: space-between; align-items: baseline; padding-top: 12px; border-top: 0.5px solid var(--sep); font-size: 15px; color: var(--sub); }
.summary-total b { font-size: 17px; color: var(--text); font-weight: 600; }

/* ---------------------------------------------------------------- grouped lists */
.group { margin-bottom: 28px; }
.group-h { color: var(--sub); font-size: 13px; text-transform: uppercase; letter-spacing: 0.02em; padding: 0 16px 7px; }
.group-f { color: var(--muted); font-size: 13px; line-height: 1.35; padding: 7px 16px 0; margin: 0; }
.list { background: var(--card); border-radius: 12px; overflow: hidden; }
.cell {
  position: relative; display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 9px 16px;
  background: none; border: 0; text-align: left; color: inherit; cursor: default;
}
button.cell { cursor: pointer; transition: background 0.15s; }
button.cell:active { background: #e5e5ea; transition: none; }
.cell + .cell::before { content: ""; position: absolute; top: 0; right: 0; left: 16px; border-top: 0.5px solid var(--sep); }
.cell.has-icon + .cell::before, .cell + .cell.has-icon::before { left: 58px; }
.cell-main { flex: 1; min-width: 0; }
.cell-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-sub { color: var(--muted); font-size: 14px; margin-top: 1px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-sub.wrap, .cell-title.wrap { white-space: normal; }
.cell-end { text-align: right; flex: none; max-width: 60%; }
.cell-value { font-weight: 500; white-space: nowrap; }
.cell-value-sub { color: var(--muted); font-size: 13px; margin-top: 1px; white-space: nowrap; }
.cell.current .cell-title { color: var(--blue); font-weight: 600; }
.chev { width: 14px; height: 14px; color: #c4c4c7; flex: none; margin-right: -4px; stroke-width: 2.6; }
.cell.action { color: var(--blue); justify-content: flex-start; }
.cell.danger { color: var(--red); }
.cell.action:disabled { color: var(--muted); }
.ic { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex: none; color: #fff; }
.ic svg { width: 18px; height: 18px; stroke-width: 2; }
.in { color: var(--green); }
.out { color: var(--text); }
.bad { color: var(--red); }
.ok { color: var(--green); }
.money small { font-size: 0.72em; font-weight: inherit; opacity: 0.75; }
.share { height: 3px; border-radius: 2px; background: var(--fill); margin-top: 6px; overflow: hidden; }
.share span { display: block; height: 100%; border-radius: 2px; transform-origin: left center; animation: grow 0.6s var(--ease) backwards 0.15s; }
.empty { color: var(--muted); text-align: center; padding: 28px 16px; font-size: 15px; }

/* operations */
.search { display: flex; align-items: center; gap: 6px; background: var(--fill); border-radius: 10px; padding: 0 10px; height: 38px; margin-bottom: 10px; color: var(--muted); }
.search svg { width: 17px; height: 17px; flex: none; }
.search input { border: 0; background: none; outline: none; flex: 1; min-width: 0; font-size: 17px; color: var(--text); }
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--fill); border-radius: 9px; padding: 2px; margin-bottom: 14px; }
.segmented button { border: 0; background: none; border-radius: 7px; padding: 6px 0; font-size: 14px; font-weight: 500; cursor: pointer; transition: background 0.18s, box-shadow 0.18s; }
.segmented button[aria-pressed="true"] { background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.filter { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: #e8f0fe; color: var(--blue); border-radius: 10px; padding: 8px 12px; margin-bottom: 14px; font-size: 15px; }
.filter button { border: 0; background: none; color: var(--blue); font-weight: 600; cursor: pointer; padding: 2px 4px; }
.day-h { display: flex; justify-content: space-between; color: var(--sub); font-size: 13px; text-transform: uppercase; letter-spacing: 0.02em; padding: 0 16px 7px; }

/* forms and buttons */
.field { width: 100%; border: 0; border-radius: 10px; padding: 12px 14px; background: var(--card); font-size: 17px; outline: none; }
.list .field { border-radius: 0; }
.list .field + .field { border-top: 0.5px solid var(--sep); }
.field.code { text-align: center; font-size: 26px; letter-spacing: 0.3em; font-variant-numeric: tabular-nums; padding: 14px; text-transform: uppercase; }
.btn { border: 0; border-radius: 12px; padding: 13px 16px; background: var(--fill); color: var(--blue); font-weight: 600; font-size: 17px; cursor: pointer; transition: transform 0.12s, opacity 0.15s; width: 100%; }
.btn.primary { background: var(--blue); color: #fff; }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn.big { padding: 15px 16px; }
.stack { display: grid; gap: 10px; }
.note { color: var(--sub); font-size: 15px; line-height: 1.4; margin: 0; }
.card { background: var(--card); border-radius: 12px; padding: 14px 16px; }
.card + .card { margin-top: 10px; }
.code-box { text-align: center; padding: 16px; }
.code-box b { display: block; font-size: 30px; letter-spacing: 0.12em; color: var(--blue); margin-bottom: 6px; }
.steps { margin: 6px 0 0; padding-left: 20px; color: var(--sub); font-size: 15px; line-height: 1.45; }
.steps li + li { margin-top: 4px; }
.drop { display: block; border: 1.5px dashed #c7c7cc; border-radius: 12px; padding: 18px; text-align: center; color: var(--sub); font-size: 15px; cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.drop.over { border-color: var(--blue); background: #e8f0fe; }

/* ---------------------------------------------------------------- numbers and charts */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 28px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px 14px; min-width: 0; }
.stat-label { color: var(--sub); font-size: 13px; }
.stat-value { font-size: 21px; font-weight: 650; margin-top: 3px; letter-spacing: -0.02em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; line-height: 1.3; }
.chart { background: var(--card); border-radius: 14px; padding: 14px 12px 12px; margin-bottom: 28px; }
.chart-h { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; padding: 0 4px 12px; }
.chart-h b { font-size: 15px; font-weight: 600; }
.chart-h span { color: var(--muted); font-size: 13px; text-align: right; }
.bars { display: flex; align-items: stretch; gap: 6px; height: 132px; }
.col { flex: 1; min-width: 0; display: flex; flex-direction: column; border: 0; background: none; padding: 0; cursor: pointer; border-radius: 8px; }
.col .stack-v { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 3px; }
.col .b { width: 40%; max-width: 15px; border-radius: 4px 4px 2px 2px; min-height: 2px; transform-origin: bottom; animation: bar 0.5s var(--ease) backwards; }
.col .tower { width: 62%; max-width: 26px; display: flex; flex-direction: column-reverse; gap: 2px; transform-origin: bottom; animation: bar 0.5s var(--ease) backwards; }
.col .tower span { display: block; border-radius: 3px; min-height: 0; }
.col .lbl { font-size: 11px; color: var(--muted); margin-top: 6px; text-align: center; white-space: nowrap; }
.col[aria-pressed="true"] .lbl { color: var(--text); font-weight: 650; }
.col[aria-pressed="false"] .b, .col[aria-pressed="false"] .tower { opacity: 0.45; }
.days { display: flex; align-items: flex-end; gap: 2px; height: 96px; }
.days .d { flex: 1; min-width: 0; display: flex; flex-direction: column-reverse; gap: 1px; height: 100%; }
.days .d span { display: block; border-radius: 2px; transform-origin: bottom; animation: bar 0.45s var(--ease) backwards; }
.days .d.today { box-shadow: inset 0 -2px 0 var(--text); }
.ticks { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; margin-top: 6px; padding: 0 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; font-size: 12.5px; color: var(--sub); margin-top: 12px; }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; vertical-align: -0.5px; }
.split { display: flex; height: 6px; gap: 2px; margin-top: 8px; }
.split span { border-radius: 3px; min-width: 3px; transform-origin: left center; animation: grow 0.6s var(--ease) backwards 0.1s; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: var(--fill); color: var(--sub); margin-left: 6px; vertical-align: 1px; }
.pill.green { background: #e3f6e8; color: var(--green); }
.pill.orange { background: #fff1e0; color: var(--orange); }
.info-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 9px 0; font-size: 15px; }
.info-row > span:first-child { color: var(--sub); flex: none; }
.info-row + .info-row { border-top: 0.5px solid var(--sep); }
.info-value { text-align: right; min-width: 0; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px max(8px, env(safe-area-inset-left)) calc(4px + env(safe-area-inset-bottom));
  background: rgba(249, 249, 249, 0.92);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--sep);
}
.tab { border: 0; background: none; display: grid; justify-items: center; gap: 2px; color: #999; font-size: 10.5px; font-weight: 500; padding: 2px 0; cursor: pointer; transition: color 0.15s, transform 0.12s; }
.tab svg { width: 26px; height: 26px; stroke-width: 1.8; }
.tab[aria-selected="true"] { color: var(--blue); }
.tab[aria-selected="true"] svg path:first-child { fill: currentColor; fill-opacity: 0.12; }
.tab:active { transform: scale(0.92); }
.tab { position: relative; }
.tab.alert::after { content: ""; position: absolute; top: 1px; left: calc(50% + 8px); width: 9px; height: 9px; border-radius: 50%; background: #ff3b30; box-shadow: 0 0 0 2px rgba(249, 249, 249, 0.92); }
@media (min-width: 700px) { .tabbar { left: 50%; right: auto; width: 520px; transform: translateX(-50%); bottom: 14px; border-radius: 18px; border: 0.5px solid var(--sep); padding-bottom: 6px; box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08); } }

/* ---------------------------------------------------------------- category sheet */
dialog.sheet {
  border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 100%; max-height: 88dvh; overflow: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 14px 14px 0 0; padding-bottom: env(safe-area-inset-bottom);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.3); }
/* backwards, not both: once open, a finger dragging the sheet moves it. */
dialog.sheet[open] { animation: sheet 0.32s var(--ease) backwards; }
dialog.sheet[open]::backdrop { animation: fade 0.25s var(--ease) backwards; }
.sheet-in { padding: 6px 16px 20px; }
.grabber { width: 36px; height: 5px; border-radius: 3px; background: #c7c7cc; margin: 2px auto 10px; }
.sheet-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 18px; }
.sheet-titles { flex: 1; min-width: 0; }
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 650; }
.sheet-sub { color: var(--sub); font-size: 15px; margin-top: 3px; }
.close { width: 30px; height: 30px; border-radius: 50%; border: 0; background: var(--fill); color: var(--sub); display: grid; place-items: center; cursor: pointer; flex: none; }
.close svg { width: 15px; height: 15px; stroke-width: 2.6; }
.check { display: flex; gap: 10px; align-items: center; color: var(--sub); font-size: 15px; padding: 14px 4px 4px; }
.check input { width: 20px; height: 20px; accent-color: var(--blue); }
.text-btn { border: 0; background: none; color: var(--blue); font-size: 16px; padding: 12px 4px 0; cursor: pointer; }
.tick { color: var(--blue); width: 20px; height: 20px; stroke-width: 2.6; flex: none; }
@media (min-width: 700px) {
  dialog.sheet { margin: auto; width: 460px; border-radius: 16px; max-height: 80dvh; }
  dialog.sheet[open] { animation: pop 0.22s var(--ease) backwards; }
}

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
  background: rgba(30, 30, 32, 0.92); color: #fff; padding: 11px 16px; border-radius: 14px; font-size: 15px; max-width: calc(100vw - 32px);
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
}
.toast:not([hidden]) { animation: toast-in 0.28s var(--ease) backwards; }

/* ---------------------------------------------------------------- sign-in page */
.login-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login { width: min(380px, 100%); text-align: center; display: grid; gap: 14px; }
.login h1 { margin: 0; font-size: 28px; font-weight: 700; }
.login-mark { width: 64px; height: 64px; border-radius: 15px; margin: 0 auto 2px; display: block; box-shadow: 0 6px 20px rgba(0, 122, 255, 0.22); }
.login form, .login #signin { display: grid; gap: 10px; margin-top: 6px; }
.login .field { text-align: center; }
.link { background: none; border: 0; color: var(--blue); cursor: pointer; padding: 8px; font-size: 16px; }
.login-error { margin: 0; font-size: 15px; }

/* ---------------------------------------------------------------- motion */
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes from-right { from { opacity: 0; transform: translateX(22px); } }
@keyframes from-left { from { opacity: 0; transform: translateX(-22px); } }
@keyframes grow { from { transform: scaleX(0); } }
@keyframes bar { from { transform: scaleY(0); } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(0.98); } }
@keyframes sheet { from { transform: translateY(100%); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 10px); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0s !important; transition-duration: 0.01ms !important; }
}
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
