:root {
  color-scheme: light dark;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --line: rgba(60, 60, 67, 0.16);
  --accent: #2f5fb3;
  --accent-soft: rgba(47, 95, 179, 0.12);
  --bar: #9db6dd;
  --bar-selected: #2f5fb3;
  --up: #b3261e;      /* spending above usual, saving below usual */
  --down: #1b7a3e;    /* spending below usual, saving above usual */
  --warn: #c56a00;
  --warn-soft: rgba(197, 106, 0, 0.1);
  --tab-on-bg: #1c1c1e;
  --tab-on-text: #ffffff;
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans Hebrew", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #1c1c1f;
    --text: #f2f2f4;
    --muted: #9a9aa1;
    --line: rgba(235, 235, 245, 0.14);
    --accent: #7ea6ec;
    --accent-soft: rgba(126, 166, 236, 0.16);
    --bar: #3d5378;
    --bar-selected: #7ea6ec;
    --up: #ff8a80;
    --down: #6fd394;
    --warn: #f0a043;
    --warn-soft: rgba(240, 160, 67, 0.12);
    --tab-on-bg: #f2f2f4;
    --tab-on-text: #111113;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 var(--font);
  font-variant-numeric: tabular-nums;
  overflow-x: hidden;
}

button { font: inherit; color: inherit; }

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
}

[hidden] { display: none !important; }

.muted { color: var(--muted); }

/* Header */
.top {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.top h1 {
  margin: 0;
  text-align: center;
  font-size: 1.15rem;
  font-weight: 650;
}
.nav {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--surface);
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 0 0 1px var(--line);
}
.nav:disabled { opacity: 0.3; cursor: default; }

.badge {
  display: inline-block;
  vertical-align: middle;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Tabs */
.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  margin-bottom: 20px;
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line);
}
.tabs button {
  min-height: 44px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  font-size: 0.92rem;
  font-weight: 550;
  cursor: pointer;
}
.tabs button.on { background: var(--tab-on-bg); color: var(--tab-on-text); }

button:focus-visible, [role="button"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Overview */
.hero {
  margin: 8px 0 0;
  font-size: 2.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.hero.negative { color: var(--up); }
.caption { margin: 4px 0 0; }
.compare { margin: 6px 0 0; font-weight: 600; }
.compare.worse { color: var(--up); }
.compare.better { color: var(--down); }

.chart {
  display: block;
  width: 100%;
  height: auto;
  margin: 20px 0 8px;
}
.chart .zero { stroke: var(--line); stroke-width: 1; }
.chart .hit { fill: transparent; }
.chart .fill { fill: var(--bar); }
.chart .partial .fill { opacity: 0.45; }
.chart .selected .fill { fill: var(--bar-selected); }
.chart .negative .fill { fill: var(--up); opacity: 0.55; }
.chart .negative.selected .fill { opacity: 1; }
.chart text { fill: var(--muted); font-size: 10px; font-family: var(--font); }
.chart .selected text { fill: var(--text); font-weight: 700; }
.chart [role="button"] { cursor: pointer; outline: none; }
.chart [role="button"]:focus-visible .hit { fill: var(--accent-soft); }

.rows { margin: 8px 0 0; }
.rows .row {
  display: flex;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.rows dt, .rows dd { margin: 0; }
.rows dd { font-weight: 600; }

/* Lists (Changes, transactions) */
.hint { margin: 0 0 8px; font-size: 0.85rem; }
.list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 0 0 1px var(--line);
  overflow: hidden;
}
.list > li + li { border-top: 1px solid var(--line); }
.list .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  text-align: start;
}
.list button.row { cursor: pointer; }
.list button.row:active { background: var(--accent-soft); }
.list .name {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-wrap: anywhere;
}
.list .name small { font-size: 0.8rem; margin-top: 2px; }
.list .nums {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  flex-shrink: 0;
}
.list .amount { font-weight: 600; white-space: nowrap; }
.list .tx.refund .amount { color: var(--down); }
.delta { font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }
.list.compact .row { min-height: 44px; padding: 8px 12px; }

.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 12px 0 4px;
  margin: 0 0 4px -4px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 550;
  cursor: pointer;
}
.back span { font-size: 1.4rem; line-height: 1; }
.drill-title { margin: 4px 0 12px; font-size: 1.25rem; overflow-wrap: anywhere; }
.drill-title .muted { font-weight: 500; }

/* Alerts */
.alert {
  margin: 0 0 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 0 0 1px var(--line);
  border-inline-start: 4px solid var(--warn);
}
.alert h2 { margin: 0; font-size: 1rem; overflow-wrap: anywhere; }
.alert > p { margin: 4px 0 0; font-size: 0.9rem; }
.alert .list { margin-top: 12px; box-shadow: none; background: var(--bg); }
.alert .list.rest { margin-top: 8px; }
.more {
  display: block;
  min-height: 44px;
  margin: 4px 0 -6px;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 550;
  cursor: pointer;
}

.empty, .status { margin: 32px 0; text-align: center; color: var(--muted); }
.status { color: var(--text); }
