/* ---------------------------------------------------------------------------
   Savings — mobile-first stylesheet.
   Primary target is an installed iOS PWA on iPhone/iPad; it widens to two
   columns on a desktop browser. No framework, no build step.
--------------------------------------------------------------------------- */

:root {
  --bg:            #f1f5f9;
  --surface:       #ffffff;
  --surface-2:     #f8fafc;
  --border:        #e2e8f0;
  --text:          #0f172a;
  --text-soft:     #64748b;
  --accent:        #4f46e5;
  --accent-soft:   #eef2ff;
  --money-in:      #15803d;
  --money-in-bg:   #dcfce7;
  --money-out:     #b91c1c;
  --money-out-bg:  #fee2e2;
  --warn:          #b45309;
  --warn-bg:       #fef3c7;
  --radius:        14px;
  --radius-sm:     10px;
  --shadow:        0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .04);
  --tabbar-h:      64px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:           #0b1220;
    --surface:      #131c2e;
    --surface-2:    #1a2436;
    --border:       #263349;
    --text:         #e6edf7;
    --text-soft:    #93a3b8;
    --accent:       #818cf8;
    --accent-soft:  #1e2745;
    --money-in:     #4ade80;
    --money-in-bg:  #14321f;
    --money-out:    #f87171;
    --money-out-bg: #3a1a1a;
    --warn:         #fbbf24;
    --warn-bg:      #3a2c10;
    --shadow:       0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  /* Stops the rubber-band scroll revealing white behind an installed PWA. */
  overscroll-behavior-y: none;
}

a { color: var(--accent); }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
h1 { font-size: 1.375rem; }
h2 { font-size: 1.0625rem; }
h3 { font-size: .9375rem; }

/* ------------------------------------------------------------------ chrome */

.env-banner {
  background: var(--warn-bg);
  color: var(--warn);
  text-align: center;
  font-size: .8125rem;
  font-weight: 600;
  padding: .375rem .75rem;
  padding-top: calc(.375rem + env(safe-area-inset-top));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  max-width: 60rem;
  margin: 0 auto;
  padding: .625rem max(1rem, env(safe-area-inset-left)) .625rem max(1rem, env(safe-area-inset-right));
}

.topbar-title { font-weight: 650; font-size: 1.0625rem; }
.topbar-actions { display: flex; align-items: center; gap: .75rem; }
.topbar-user { font-size: .8125rem; color: var(--text-soft); text-decoration: none; }
.kid-switch select { font-size: .875rem; padding: .25rem 1.75rem .25rem .5rem; }

.page {
  max-width: 60rem;
  margin: 0 auto;
  padding: 1rem max(1rem, env(safe-area-inset-left))
           calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 1.5rem)
           max(1rem, env(safe-area-inset-right));
}

/* Bottom tab bar. The padding-bottom keeps it clear of the iPhone home
   indicator; without it the last row of buttons is unreachable. */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tabbar-h);
  text-decoration: none;
  color: var(--text-soft);
  font-size: .6875rem;
  font-weight: 600;
  -webkit-tap-highlight-color: transparent;
}

.tab.is-active { color: var(--accent); }
.tab-icon { font-size: 1.25rem; line-height: 1; }

.tab-badge {
  position: absolute;
  top: 8px;
  left: 50%;
  margin-left: 4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--money-out);
  color: #fff;
  font-size: .6875rem;
  line-height: 18px;
  text-align: center;
}

/* ------------------------------------------------------------------ blocks */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  margin-bottom: 1rem;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
  margin-bottom: .75rem;
}

.muted { color: var(--text-soft); }
.small { font-size: .8125rem; }
.tiny  { font-size: .75rem; }
.center { text-align: center; }
.stack > * + * { margin-top: .75rem; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row-end { margin-left: auto; }
.grid-2 { display: grid; gap: 1rem; }

@media (min-width: 48rem) {
  .grid-2 { grid-template-columns: 1fr 1fr; align-items: start; }
}

/* ---------------------------------------------------------------- balances */

.balance {
  text-align: center;
  padding: 1.5rem 1rem 1.25rem;
}

.balance-label {
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-soft);
  font-weight: 700;
}

.balance-total {
  font-size: 2.75rem;
  font-weight: 750;
  letter-spacing: -.02em;
  margin: .25rem 0 .75rem;
  font-variant-numeric: tabular-nums;
}

.balance-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  border-top: 1px solid var(--border);
  padding-top: .75rem;
}

.balance-split div { display: flex; flex-direction: column; gap: 2px; }
.balance-split .v { font-weight: 650; font-variant-numeric: tabular-nums; }
.balance-split .k { font-size: .75rem; color: var(--text-soft); }

.pending-note {
  margin-top: .75rem;
  padding: .5rem .75rem;
  border-radius: var(--radius-sm);
  background: var(--warn-bg);
  color: var(--warn);
  font-size: .8125rem;
  font-weight: 600;
}

/* ------------------------------------------------------------------ ledger */

.ledger { list-style: none; margin: 0; padding: 0; }

.ledger li {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .75rem 0;
  border-bottom: 1px solid var(--border);
}

.ledger li:last-child { border-bottom: 0; }

.ledger-main { flex: 1; min-width: 0; }
.ledger-memo { font-weight: 600; overflow-wrap: anywhere; }
.ledger-meta { font-size: .75rem; color: var(--text-soft); margin-top: 2px; }

.ledger-amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.amount-in  { color: var(--money-in); }
.amount-out { color: var(--money-out); }

.is-pending { opacity: .75; }
.is-void .ledger-memo { text-decoration: line-through; }

/* ------------------------------------------------------------------- chips */

.chips { display: flex; flex-wrap: wrap; gap: .375rem; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  padding: .1875rem .5rem;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: .75rem;
  color: var(--text-soft);
  white-space: nowrap;
}

/* Tappable category selector. The checkbox itself is hidden but stays
   focusable, so keyboard and VoiceOver still work. */
.chip-select { display: flex; flex-wrap: wrap; gap: .5rem; }

.chip-select label {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .5rem .75rem;
  min-height: 40px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  font-size: .875rem;
  font-weight: 550;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.chip-select input { position: absolute; opacity: 0; width: 0; height: 0; }

.chip-select input:checked + span,
.chip-select label:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.chip-select label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ------------------------------------------------------------------- forms */

label.field { display: block; margin-bottom: .75rem; }
label.field > span { display: block; font-size: .8125rem; font-weight: 600; margin-bottom: .25rem; }

input[type="text"], input[type="password"], input[type="date"], input[type="number"],
input[type="search"], select, textarea {
  width: 100%;
  padding: .625rem .75rem;
  /* 16px minimum stops iOS Safari zooming the viewport on focus. */
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  appearance: none;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

.amount-input {
  font-size: 2rem !important;
  font-weight: 700;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .375rem;
  min-height: 44px;
  padding: .625rem 1rem;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--money-out); }
.btn-success { background: var(--money-in); }
.btn-sm { min-height: 36px; padding: .375rem .75rem; font-size: .8125rem; }

/* In / out direction toggle on the entry form. */
.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }

.segmented label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-2);
  font-weight: 650;
  cursor: pointer;
}

.segmented input { position: absolute; opacity: 0; width: 0; height: 0; }
.segmented label:has(input:checked) { border-color: currentColor; }
.segmented label.seg-in:has(input:checked)  { color: var(--money-in);  background: var(--money-in-bg); }
.segmented label.seg-out:has(input:checked) { color: var(--money-out); background: var(--money-out-bg); }

/* ------------------------------------------------------------------ flashes */

.flashes { margin-bottom: 1rem; }

.flash {
  padding: .75rem 1rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: .875rem;
  margin-bottom: .5rem;
}

.flash-success { background: var(--money-in-bg);  color: var(--money-in); }
.flash-error   { background: var(--money-out-bg); color: var(--money-out); }
.flash-info    { background: var(--accent-soft);  color: var(--accent); }

/* -------------------------------------------------------------------- goals */

.goal { border-bottom: 1px solid var(--border); padding: .875rem 0; }
.goal:last-child { border-bottom: 0; }

.goal-head { display: flex; align-items: baseline; gap: .5rem; }
.goal-name { font-weight: 650; flex: 1; }
.goal-figures { font-variant-numeric: tabular-nums; font-size: .875rem; }

.bar {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  overflow: hidden;
  margin: .5rem 0 .375rem;
}

.bar > i {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.goal-eta { font-size: .8125rem; color: var(--text-soft); }
.goal-eta.is-behind { color: var(--warn); font-weight: 600; }
.goal-eta.is-ontrack { color: var(--money-in); font-weight: 600; }

/* ------------------------------------------------------------------- chores */

.chore {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .75rem 0;
  border-bottom: 1px solid var(--border);
}

.chore:last-child { border-bottom: 0; }
.chore-main { flex: 1; min-width: 0; }
.chore-label { font-weight: 600; }
.chore-due { font-size: .75rem; color: var(--text-soft); }
.chore-amount { font-weight: 700; color: var(--money-in); font-variant-numeric: tabular-nums; }
.chore.is-done { opacity: .55; }
.chore.is-done .chore-label { text-decoration: line-through; }

.state-pill {
  display: inline-block;
  padding: .125rem .5rem;
  border-radius: 999px;
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.state-claimed  { background: var(--warn-bg);      color: var(--warn); }
.state-approved { background: var(--money-in-bg);  color: var(--money-in); }
.state-rejected { background: var(--money-out-bg); color: var(--money-out); }

/* ----------------------------------------------------------------- timeline */

.timeline { list-style: none; margin: 0; padding: 0; font-variant-numeric: tabular-nums; }

.timeline li {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .375rem 0;
  border-bottom: 1px dashed var(--border);
  font-size: .875rem;
}

.timeline li:last-child { border-bottom: 0; }
.timeline .tl-date { width: 6.5rem; color: var(--text-soft); font-size: .8125rem; }
.timeline .tl-amount { font-weight: 650; }
.timeline .tl-hit { margin-left: auto; color: var(--money-in); font-weight: 650; font-size: .8125rem; }

/* -------------------------------------------------------------------- login */

.login-wrap {
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}

.login-card { width: 100%; max-width: 22rem; }
.login-logo { font-size: 3rem; text-align: center; margin-bottom: .5rem; }

/* --------------------------------------------------------------- utilities */

.empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-soft);
}

.empty-icon { font-size: 2.5rem; display: block; margin-bottom: .5rem; }

table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data th, table.data td { text-align: left; padding: .5rem .5rem; border-bottom: 1px solid var(--border); }
table.data th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-soft); }

/* Wide content scrolls inside its own box rather than the page. */
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

details.disclosure { border-top: 1px solid var(--border); padding-top: .75rem; margin-top: .75rem; }
details.disclosure > summary { cursor: pointer; font-weight: 650; font-size: .875rem; }
details.disclosure[open] > summary { margin-bottom: .75rem; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
