/* Money tracker. One number dominates; everything else is quiet.
   Green, amber and red are used for status only. The accent is blue. */

:root {
  color-scheme: light dark;
  --bg: #F5F3EE;
  --card: #FFFFFF;
  --ink: #17181C;
  --muted: #666A73;
  --line: #E3E0D8;
  --chip: #EBE8E0;
  --accent: #3446DB;
  --accent-ink: #FFFFFF;
  --green: #17914E;
  --amber: #B97400;
  --red: #CF3A2E;
  --toast: #1D1F25;
  --toast-ink: #FFFFFF;
  --toast-accent: #AEB7FF;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121317;
    --card: #1B1D23;
    --ink: #F1F1EE;
    --muted: #9B9EA8;
    --line: #2B2E37;
    --chip: #262932;
    --accent: #97A2FF;
    --accent-ink: #0F1120;
    --green: #3FCB82;
    --amber: #F0B24C;
    --red: #FF6F62;
    --toast: #ECECE8;
    --toast-ink: #17181C;
    --toast-accent: #3446DB;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

h1, h2, p, dl, dd { margin: 0; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

#app, .setup { max-width: 520px; margin: 0 auto; }

/* ------------------------------------------------------------ top bar */

.top {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(env(safe-area-inset-top, 0px) + 6px) 8px 0 20px;
  min-height: 52px;
}
.top h1 { flex: 1; font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.top #back { margin-left: -12px; }

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--muted);
}
.icon-btn:active { background: var(--chip); }
.icon-btn:disabled { opacity: 0.3; }
.icon-btn svg, .tabs svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

.sync-flag {
  font-size: 12px; color: var(--muted);
  padding: 4px 10px; border-radius: 999px; background: var(--chip);
}

main { padding: 0 16px calc(var(--nav-h) + var(--safe-b) + 24px); }

/* --------------------------------------------------------------- hero */

.hero { padding: 10px 4px 4px; --status: var(--muted); }
.hero[data-status="green"] { --status: var(--green); }
.hero[data-status="amber"] { --status: var(--amber); }
.hero[data-status="red"] { --status: var(--red); }

.label { font-size: 13px; color: var(--muted); }
.sub { font-size: 13px; color: var(--muted); min-height: 18px; }

.big {
  display: flex; align-items: baseline; gap: 8px;
  margin-top: 2px;
  color: var(--status);
  font-size: clamp(64px, 23vw, 96px);
  font-weight: 750;
  line-height: 1;
  letter-spacing: -0.04em;
}
.hero[data-status="idle"] .big { color: var(--ink); }
.big .unit { font-size: 16px; font-weight: 600; letter-spacing: 0; color: var(--muted); }
.hero .sub { font-size: 15px; margin-top: 4px; }

.bar {
  height: 8px; margin-top: 14px;
  border-radius: 999px; background: var(--line); overflow: hidden;
}
.bar-fill { height: 100%; width: 0; border-radius: 999px; background: var(--status); transition: width 0.3s ease; }

.split { margin-top: 8px; font-size: 13px; color: var(--muted); }
.over { margin-top: 6px; font-size: 15px; font-weight: 650; color: var(--red); }

/* ------------------------------------------------------------- meters */

.meters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.meter { background: var(--card); border-radius: 16px; padding: 12px 14px; }
.meter .label { font-size: 12px; line-height: 1.3; min-height: 32px; }
.meter .num { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.meter .sub { font-size: 12px; }
.meter.low .num { color: var(--red); }

/* ------------------------------------------------------------- notice */

.notice {
  display: flex; align-items: center; gap: 12px;
  margin-top: 12px; padding: 12px 14px;
  border-radius: 16px; background: var(--card);
  border: 1.5px solid var(--amber);
  font-size: 14px;
}
.notice p { flex: 1; }

/* --------------------------------------------------------------- card */

.card { background: var(--card); border-radius: 20px; padding: 16px; margin-top: 12px; }
.card h2, .sheet h2 { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }

/* ---------------------------------------------------------- quick add */

.amount-row {
  display: flex; align-items: baseline; gap: 10px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 4px;
}
.amount-row:focus-within { border-color: var(--accent); }
#amount {
  flex: 1; min-width: 0; width: 100%;
  border: 0; outline: 0; background: transparent;
  font-size: 40px; font-weight: 700; letter-spacing: -0.02em;
  padding: 0; height: 52px;
}
#amount::placeholder { color: var(--line); }
.amount-cur { font-size: 16px; font-weight: 600; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip {
  min-height: 44px; padding: 0 15px;
  border: 0; border-radius: 22px;
  background: var(--chip); color: var(--ink);
  font-size: 15px; line-height: 1.2; text-align: left;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
#cat-chips { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }

.other-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }

.more { margin-top: 14px; border-top: 1px solid var(--line); }
.more summary {
  min-height: 44px; display: flex; align-items: center;
  font-size: 14px; color: var(--muted); cursor: pointer; list-style: none;
}
.more summary::-webkit-details-marker { display: none; }
.more summary::after { content: "+"; margin-left: auto; font-size: 20px; line-height: 1; }
.more[open] summary::after { content: "\2212"; }
.more .chips { margin-top: 0; }

.field { display: block; margin-top: 10px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select {
  width: 100%; min-height: 46px; padding: 0 12px;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: var(--bg); outline: 0;
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.error { margin-top: 12px; font-size: 14px; color: var(--red); }
.error.ok { color: var(--green); }
.hint { margin-top: 10px; font-size: 12px; color: var(--muted); }
.center { text-align: center; }

.save-row {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px;
  margin-top: 16px;
}
/* Once a category is picked, the Save buttons float in reach of the thumb. */
.save-row.ready {
  position: sticky;
  bottom: calc(var(--nav-h) + var(--safe-b) + 10px);
  z-index: 2;
  isolation: isolate;
}
/* A soft fade behind the floating buttons, so chips scrolling under them do not look cut off. */
.save-row.ready::before {
  content: "";
  position: absolute;
  inset: -22px -16px -10px;
  z-index: -1;
  background: linear-gradient(to bottom, transparent, var(--card) 45%);
  pointer-events: none;
}

.btn {
  min-height: 52px; padding: 0 18px;
  border: 0; border-radius: 16px;
  background: var(--chip); color: var(--ink);
  font-size: 16px; font-weight: 650;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.danger { background: transparent; color: var(--red); }
.btn.small { min-height: 44px; border-radius: 12px; font-size: 14px; }
.btn:disabled { background: var(--chip); color: var(--muted); }
.btn:active:not(:disabled) { filter: brightness(0.94); }
.save-row.ready .btn { box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18); }

/* ------------------------------------------------------------ entries */

.day-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 18px 4px 8px;
  font-size: 13px; color: var(--muted);
}
.day-head b { font-weight: 650; color: var(--ink); }
.day { background: var(--card); border-radius: 16px; overflow: hidden; }
.entry {
  width: 100%; min-height: 56px;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  border: 0; border-top: 1px solid var(--line);
  background: transparent; text-align: left;
}
.entry:first-child { border-top: 0; }
.entry:active { background: var(--chip); }
.entry-main { flex: 1; min-width: 0; }
.entry-cat { font-size: 15px; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-meta { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-amt { text-align: right; font-size: 16px; font-weight: 650; }
.entry-amt small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
.unsynced {
  display: inline-block; margin-right: 6px; padding: 1px 7px;
  border: 1px solid var(--muted); border-radius: 999px;
  font-size: 11px; color: var(--muted);
}
.empty { padding: 48px 12px; text-align: center; color: var(--muted); font-size: 15px; }
.more-btn { display: block; width: 100%; margin-top: 16px; }

/* -------------------------------------------------------------- month */

.month-nav { display: flex; align-items: center; justify-content: space-between; padding-top: 4px; }
.month-nav h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.rows > div {
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  padding: 9px 0; border-top: 1px solid var(--line);
  font-size: 15px;
}
.rows > div:first-child { border-top: 0; }
.rows .amt { text-align: right; font-weight: 650; white-space: nowrap; }
.rows .amt small { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
#month-copy { display: block; width: 100%; margin-top: 16px; }

/* ----------------------------------------------------------- settings */

.facts > div {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 8px 0; border-top: 1px solid var(--line);
  font-size: 15px;
}
.facts > div:first-child { border-top: 0; }
.facts dt { color: var(--muted); }
.facts dd { text-align: right; font-weight: 600; }
#sync-now, #conn-save { display: block; width: 100%; margin-top: 14px; }

/* ---------------------------------------------------------- first run */

.setup { padding: calc(env(safe-area-inset-top, 0px) + 56px) 24px 40px; }
.setup h1 { font-size: 40px; font-weight: 750; letter-spacing: -0.03em; }
.setup .lead { margin: 8px 0 20px; color: var(--muted); }
.setup .btn { display: block; width: 100%; margin-top: 20px; }

/* ----------------------------------------------------------- bottom nav */

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(3, 1fr);
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--card);
  border-top: 1px solid var(--line);
}
.tabs button {
  display: grid; place-items: center; align-content: center; gap: 3px;
  border: 0; background: transparent;
  color: var(--muted); font-size: 11px; font-weight: 550;
}
.tabs button[aria-current="page"] { color: var(--accent); }

/* -------------------------------------------------------------- toast */

.toast {
  position: fixed; z-index: 10;
  left: 12px; right: 12px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 12px);
  max-width: 496px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  min-height: 56px; padding: 6px 8px 6px 18px;
  border-radius: 16px;
  background: var(--toast); color: var(--toast-ink);
  font-size: 15px; font-weight: 550;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}
.toast span { flex: 1; }
.toast button {
  min-height: 44px; min-width: 64px; padding: 0 14px;
  border: 0; border-radius: 12px; background: transparent;
  color: var(--toast-accent); font-weight: 700;
}

/* -------------------------------------------------------- edit sheet */

.sheet {
  width: 100%; max-width: 520px; max-height: 92dvh;
  margin: auto auto 0; padding: 20px 16px calc(16px + var(--safe-b));
  border: 0; border-radius: 22px 22px 0 0;
  background: var(--card); color: var(--ink);
  overflow-y: auto;
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
.sheet-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 18px; }
.sheet-actions .danger { grid-column: 1 / -1; }

@media (prefers-reduced-motion: reduce) {
  .bar-fill { transition: none; }
}
