/* Tally — paper-ledger palette. Deliberately unlike Streak's ember or Peek's
   violet, so the three home-screen icons never get confused for each other. */
:root {
  --paper:      #F7F4EE;
  --card:       #FFFFFF;
  --ink:        #1B211E;
  --ink-soft:   #5E6A64;
  --ink-faint:  #97A19B;
  --rule:       #E3DED4;
  --pine:       #122D26;
  --good:       #10795A;
  --good-soft:  #E3F3EC;
  --warn:       #B8721A;
  --over:       #B23A28;
  --over-soft:  #FAE9E5;
  --shadow:     0 1px 2px rgba(27, 33, 30, .06), 0 8px 24px rgba(27, 33, 30, .05);
  --radius:     16px;
  --top:        env(safe-area-inset-top);
  --bottom:     env(safe-area-inset-bottom);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:     #101512;
    --card:      #1A211D;
    --ink:       #ECEFEC;
    --ink-soft:  #9AA7A0;
    --ink-faint: #6B7873;
    --rule:      #2A332E;
    --pine:      #0B1512;
    --good:      #3FC795;
    --good-soft: #14312A;
    --warn:      #E0A24A;
    --over:      #F0715A;
    --over-soft: #351A17;
    --shadow:    0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* Without this, iOS Safari sits on every tap for ~300ms waiting to find out
   whether it's a double-tap-to-zoom, which makes the whole app feel a beat
   behind. `user-scalable=no` in the viewport meta does NOT prevent it — Safari
   has ignored that since iOS 10 — so the fix has to be here. */
button, label, select, input, a, .entry, .chip, .place, .bank {
  touch-action: manipulation;
}

/* Several elements here are laid out with `display: flex` by a class, which
   outranks the UA stylesheet's `[hidden] { display: none }` and leaves them
   stubbornly visible. This puts the attribute back in charge. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}
.screen[hidden] { display: none; }

/* ── Top bar ───────────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: calc(var(--top) + 10px) 12px 10px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
}

.week-label { flex: 1; min-width: 0; text-align: center; }
.week-label h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.week-label p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

.icon-btn {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 10px;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
}
.icon-btn:active { background: var(--rule); transform: scale(.9); }
.icon-btn:disabled { opacity: .25; }
.icon-btn.danger { color: var(--over); }

/* ── Scrolling body ────────────────────────────────────────────────────── */
.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
}
.scroll-pad { height: 24px; }

/* ── Weekly summary ────────────────────────────────────────────────────── */
.summary {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  text-align: center;
}

.summary-eyebrow {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.summary-amount {
  margin: 6px 0 16px;
  font-size: 46px;
  font-weight: 700;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.summary.is-over .summary-amount { color: var(--over); }

.meter {
  height: 9px;
  border-radius: 99px;
  background: var(--rule);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: var(--good);
  transition: width .45s cubic-bezier(.4, 0, .2, 1), background-color .3s;
}
.summary.is-warn .meter-fill { background: var(--warn); }
.summary.is-over .meter-fill { background: var(--over); }

.summary-sub {
  margin: 12px 0 0;
  font-size: 14px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.summary-pace {
  margin: 5px 0 0;
  font-size: 13px;
  color: var(--ink-faint);
}
.summary-pace:empty { display: none; }

/* ── Lists ─────────────────────────────────────────────────────────────── */
.list-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 26px 2px 8px;
}
.list-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.muted { color: var(--ink-faint); font-size: 12px; font-variant-numeric: tabular-nums; }

.entries { list-style: none; margin: 0; padding: 0; }
.entries:empty { display: none; }

.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 0;
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  margin-bottom: 8px;
}
.entry:active { transform: scale(.985); filter: brightness(.96); }

.entry-thumb {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border-radius: 9px;
  object-fit: cover;
  background: var(--rule);
}
.entry-thumb.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--rule);
  color: var(--ink-faint);
  font-size: 17px;
  font-weight: 600;
}

.entry-main { flex: 1; min-width: 0; }
.entry-name {
  font-size: 15px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.entry-meta { font-size: 12.5px; color: var(--ink-faint); }

.entry-amount {
  font-size: 16px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}

.empty-note {
  margin: 28px 0;
  text-align: center;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-faint);
}

/* ── Dock ──────────────────────────────────────────────────────────────── */
.dock {
  display: flex;
  gap: 10px;
  padding: 12px 16px calc(var(--bottom) + 12px);
  border-top: 1px solid var(--rule);
  background: var(--paper);
}

.primary-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 50px;
  padding: 0 18px;
  border: 0;
  border-radius: 13px;
  background: var(--pine);
  color: #F7F4EE;
  font: 600 16px/1 inherit;
  cursor: pointer;
}
@media (prefers-color-scheme: dark) {
  .primary-btn { background: var(--good); color: #08120F; }
}
.primary-btn:active { opacity: .82; transform: scale(.98); }
.primary-btn:disabled { opacity: .35; cursor: default; }

.ghost-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  padding: 0 18px;
  border: 1px solid var(--rule);
  border-radius: 13px;
  background: var(--card);
  color: var(--ink);
  font: 550 15px/1 inherit;
  cursor: pointer;
}
.ghost-btn:active { background: var(--rule); transform: scale(.98); }
.ghost-btn.wide { width: 100%; margin-bottom: 10px; }
.ghost-btn.danger { color: var(--over); }

/* ── Fields ────────────────────────────────────────────────────────────── */
.field { margin-bottom: 18px; }
.field label {
  display: block;
  margin: 0 2px 7px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.field input[type="text"],
.field input[type="date"],
.field select {
  width: 100%;
  min-height: 52px;
  padding: 0 14px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink);
  font: 400 17px/1 inherit;
  -webkit-appearance: none;
  appearance: none;
}
.field select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2397A19B' stroke-width='2.2' stroke-linecap='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 13px center;
  background-size: 18px;
  padding-right: 40px;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--good);
  box-shadow: 0 0 0 3px var(--good-soft);
}

.amount-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--card);
}
.amount-row:focus-within {
  border-color: var(--good);
  box-shadow: 0 0 0 3px var(--good-soft);
}
.amount-row .currency {
  font-size: 26px;
  font-weight: 600;
  color: var(--ink-faint);
}
.amount-row input {
  flex: 1;
  min-height: 60px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 700 34px/1 inherit;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  -webkit-appearance: none;
}
.amount-row input:focus { outline: none; }

.hint {
  margin: 8px 2px 0;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--ink-faint);
}
.hint.version { margin-top: 18px; text-align: center; }

/* ── Receipt shot + OCR progress ───────────────────────────────────────── */
.shot-wrap {
  position: relative;
  margin-bottom: 18px;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--card);
  box-shadow: var(--shadow);
}
.shot-wrap img {
  display: block;
  width: 100%;
  max-height: 34vh;
  object-fit: cover;
  object-position: top;
}

.scan-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  background: rgba(18, 45, 38, .82);
  backdrop-filter: blur(3px);
  color: #F7F4EE;
}
.scan-overlay p { margin: 0; font-size: 14px; font-weight: 550; }
.scan-bar {
  width: min(200px, 70%);
  height: 5px;
  border-radius: 99px;
  background: rgba(247, 244, 238, .22);
  overflow: hidden;
}
.scan-bar-fill {
  height: 100%;
  width: 0;
  border-radius: 99px;
  background: #3FC795;
  transition: width .3s ease;
}

.scan-note {
  margin: -6px 2px 16px;
  padding: 11px 13px;
  border-radius: 11px;
  font-size: 13.5px;
  line-height: 1.5;
  background: var(--good-soft);
  color: var(--good);
}
.scan-note.warn { background: var(--over-soft); color: var(--over); }

/* ── Toast ─────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--bottom) + 84px);
  transform: translate(-50%, 14px);
  max-width: 84%;
  padding: 11px 17px;
  border-radius: 11px;
  background: var(--pine);
  color: #F7F4EE;
  font-size: 14px;
  font-weight: 550;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s, transform .22s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ── Split control ─────────────────────────────────────────────────────── */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}
.chip {
  flex: 1 1 auto;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--rule);
  border-radius: 11px;
  background: var(--card);
  color: var(--ink-soft);
  font: 550 14px/1 inherit;
  white-space: nowrap;
  cursor: pointer;
}
.chip:active { background: var(--rule); transform: scale(.95); }
.chip.is-on {
  border-color: var(--good);
  background: var(--good-soft);
  color: var(--good);
}

.share-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 0 14px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--card);
}
.share-row:focus-within {
  border-color: var(--good);
  box-shadow: 0 0 0 3px var(--good-soft);
}
.share-row .share-label {
  font-size: 14px;
  font-weight: 550;
  color: var(--ink-faint);
}
.share-row .currency {
  margin-left: auto;
  font-size: 19px;
  font-weight: 600;
  color: var(--ink-faint);
}
.share-row input {
  flex: 0 1 auto;
  width: 44%;
  min-height: 54px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 700 24px/1 inherit;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
  -webkit-appearance: none;
}
.share-row input:focus { outline: none; }

.entry-split {
  display: inline-block;
  margin-top: 2px;
  padding: 1px 6px;
  border-radius: 5px;
  background: var(--good-soft);
  color: var(--good);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .02em;
}

/* ── The bank: what previous weeks left behind ─────────────────────────── */
.bank {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
  text-align: left;
}
.bank-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.bank-label {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.bank-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
  color: var(--good);
}
.bank-value.is-negative { color: var(--over); }
.bank-all-in {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}
.bank-all-in:empty { display: none; }

.bank-card {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 16px 18px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

/* ── History ───────────────────────────────────────────────────────────── */
.history-summary { margin-top: 16px; }
.history-summary .summary-amount { margin-bottom: 0; }

.places { list-style: none; margin: 0; padding: 0; }
.places:empty { display: none; }

.place {
  padding: 13px 14px;
  border-radius: 12px;
  background: var(--card);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
}
.place-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}
.place-name {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 550;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.place-amount {
  font-size: 15px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}
.place-bar {
  height: 6px;
  margin: 9px 0 7px;
  border-radius: 99px;
  background: var(--rule);
  overflow: hidden;
}
.place-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--good);
}
.place-meta {
  font-size: 12.5px;
  color: var(--ink-faint);
  font-variant-numeric: tabular-nums;
}

/* The bank strip is a button, but must not look like one inside the card. */
button.bank {
  display: block;
  width: 100%;
  border: 0;
  border-top: 1px solid var(--rule);
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
}
button.bank:active { opacity: .55; }

.entry-split.is-fun {
  background: var(--over-soft);
  color: var(--warn);
}

.entry-main .entry-split + .entry-split { margin-left: 5px; }

.bank-all-in.is-warn { color: var(--over); }

.toast.tappable {
  pointer-events: auto;
  cursor: pointer;
  background: var(--good);
  color: #08120F;
}

.reveal-row { display: flex; gap: 8px; align-items: stretch; }
.reveal-row input { flex: 1; min-width: 0; }
.reveal-btn {
  flex: 0 0 auto;
  padding: 0 15px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--card);
  color: var(--ink-soft);
  font: 550 14px/1 inherit;
  cursor: pointer;
  touch-action: manipulation;
}
.reveal-btn:active { background: var(--rule); }

/* ── Paying the pot back out of this week ──────────────────────────────── */
.repay-box {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}
.repay-title {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.repay-box .share-row { margin-top: 0; }
.repay-box .primary-btn { width: 100%; margin-top: 12px; }
.repay-box .hint { margin-bottom: 0; }

.entry-split.is-repay {
  background: var(--rule);
  color: var(--ink-soft);
}
