:root {
  --bg: #FCFFFC;
  --fg: #191716;
  --muted: #6E6A66;
  --faint: #A39E98;
  --line: rgba(25, 23, 22, 0.12);
  --soft: rgba(25, 23, 22, 0.045);
  --red: #D1495B;
  --on-fg: #FCFFFC;
  --radius: 8px;
  --tabbar: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #191716;
    --fg: #FCFFFC;
    --muted: #A8A39E;
    --faint: #6E6A66;
    --line: rgba(252, 255, 252, 0.13);
    --soft: rgba(252, 255, 252, 0.06);
    --on-fg: #191716;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.bold { font-weight: 600; }
.red { color: var(--red); }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------------------------------------------------------- layout */

.screen {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: calc(var(--safe-b) + 32px);
}
.screen.has-tabs { padding-bottom: calc(var(--tabbar) + var(--safe-b) + 88px); }
.content { padding: 0 20px; }

header.top {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--bg);
  padding: calc(var(--safe-t) + 10px) 12px 10px;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 52px;
  border-bottom: 1px solid transparent;
}
header.top.lined { border-bottom-color: var(--line); }
header.top h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
header.top .side { width: 88px; display: flex; }
header.top .side.end { justify-content: flex-end; }

.wordmark {
  font-weight: 700;
  letter-spacing: -0.045em;
  font-size: 26px;
  line-height: 1;
  text-decoration: none;
  padding-left: 8px;
}
.wordmark.big { font-size: 56px; padding: 0; }

.sync {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.sync::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  margin-right: 6px;
  vertical-align: 1px;
}
.sync.ok { display: none; }

/* ---------------------------------------------------------------- controls */

.iconbtn {
  border: 0;
  background: none;
  padding: 8px;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  text-decoration: none;
  font-size: 15px;
}
.iconbtn:active { background: var(--soft); }
.ico { display: inline-flex; width: 22px; height: 22px; }
.ico svg { width: 100%; height: 100%; }

.btn {
  appearance: none;
  border: 1px solid var(--fg);
  background: var(--fg);
  color: var(--on-fg);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-block;
}
.btn:active { opacity: 0.8; }
.btn:disabled { opacity: 0.35; }
.btn.block { display: block; width: 100%; }
.btn.ghost { background: transparent; color: var(--fg); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--red); border-color: var(--line); }
.btn.sm { padding: 7px 12px; font-size: 14px; font-weight: 500; }
.btn.xs { padding: 4px 10px; font-size: 13px; font-weight: 500; }
.linkbtn {
  border: 0;
  background: none;
  padding: 0;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  font-size: 14px;
}

label.field { display: block; }
label.field > span, .label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.input, select.input, textarea.input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--bg);
  border-radius: var(--radius);
  padding: 11px 12px;
  font-size: 16px; /* >=16px stops iOS zooming on focus */
  outline: none;
  min-height: 46px;
}
.input:focus { border-color: var(--fg); }
textarea.input { min-height: 72px; resize: vertical; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
.input.sm { min-height: 38px; padding: 7px 10px; }

.amount-input {
  display: flex;
  align-items: baseline;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0 10px;
}
.amount-input:focus-within { border-bottom-color: var(--fg); }
.amount-input .cur { font-size: 28px; color: var(--muted); }
.amount-input input {
  border: 0;
  outline: none;
  background: none;
  font-size: 40px;
  font-weight: 600;
  width: 100%;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.seg {
  display: flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 3px;
  gap: 3px;
}
.seg button {
  flex: 1;
  border: 0;
  background: none;
  padding: 7px 4px;
  border-radius: 6px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
}
.seg button.on { background: var(--fg); color: var(--on-fg); font-weight: 600; }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 20px 4px;
  margin: 0 -20px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
.chip {
  flex: none;
  border: 1px solid var(--line);
  background: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.chip.on { border-color: var(--fg); background: var(--fg); color: var(--on-fg); }
.chip.dashed { border-style: dashed; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; display: inline-block; }
.flagdot { width: 8px; height: 8px; border-radius: 50%; background: var(--red); display: inline-block; flex: none; }

/* ---------------------------------------------------------------- lists */

.section-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 28px 0 8px;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.list { border-top: 1px solid var(--line); }
.item {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 13px 0;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  background: none;
  width: 100%;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  text-align: left;
}
.item.static { cursor: default; }
.item:active:not(.static) { background: var(--soft); }
.item .title { font-weight: 500; }
.item .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.item .amt { font-weight: 600; text-align: right; white-space: nowrap; }
.item .amt .sub { font-weight: 400; }
.bar { width: 3px; align-self: stretch; border-radius: 2px; flex: none; }

.day-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
  padding: 22px 0 6px;
  border-bottom: 1px solid var(--line);
}

.summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin: 4px 0 16px;
}
.summary > * { padding: 14px 0; display: block; }
.summary > * + * { border-left: 1px solid var(--line); padding-left: 16px; }
.summary .big { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }

.hero { padding: 18px 0 8px; }
.hero .big { font-size: 34px; font-weight: 600; letter-spacing: -0.03em; }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; }

.note {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 14px;
}
.note.flag { border-color: var(--red); }

.card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.card + .card { margin-top: 10px; }
.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 1px 6px;
}

.transfer { display: flex; align-items: center; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.transfer .who { flex: 1; min-width: 0; }
.transfer .arrow { color: var(--faint); margin: 0 4px; }
.transfer.mine .who { font-weight: 600; }

/* ---------------------------------------------------------------- stats */

.barrow { padding: 9px 0; }
.barrow .row { font-size: 14px; }
.track { height: 6px; background: var(--soft); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.track > i { display: block; height: 100%; border-radius: 3px; background: var(--fg); }
.daycols { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 8px; overflow-x: auto; }
.daycol { flex: 1 0 22px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; }
.daycol i { display: block; width: 100%; background: var(--fg); border-radius: 3px 3px 0 0; min-height: 2px; }
.daycol span { font-size: 10px; color: var(--muted); margin-top: 4px; }
.tablewrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table.grid { border-collapse: collapse; width: 100%; font-size: 14px; }
table.grid th, table.grid td { padding: 8px 10px 8px 0; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.grid th:first-child, table.grid td:first-child { text-align: left; }
table.grid th { font-size: 12px; font-weight: 600; color: var(--muted); }
table.grid tr.total td { font-weight: 600; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------------------------------------------------------------- tabs, fab, sheet, toast */

nav.tabs {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  background: var(--bg);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
nav.tabs .inner { max-width: 560px; margin: 0 auto; display: flex; height: var(--tabbar); }
nav.tabs a {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-size: 14px;
  color: var(--muted);
  position: relative;
}
nav.tabs a.on { color: var(--fg); font-weight: 600; }
nav.tabs a.on::after { content: ""; position: absolute; top: -1px; left: 30%; right: 30%; height: 2px; background: var(--fg); }
nav.tabs a .flagdot { position: absolute; top: 14px; margin-left: 52px; }

.fab {
  position: fixed;
  z-index: 9;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar) + var(--safe-b) + 14px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18);
  padding: 13px 22px;
  border-radius: 999px;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(25, 23, 22, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fade 0.15s ease-out;
}
.sheet {
  background: var(--bg);
  width: 100%;
  max-width: 560px;
  border-radius: 14px 14px 0 0;
  padding: 20px 20px calc(var(--safe-b) + 20px);
  max-height: 90vh;
  overflow-y: auto;
  animation: up 0.18s ease-out;
}
.sheet h2 { margin: 0 0 16px; font-size: 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(30px); opacity: 0.5; } }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--safe-b) + var(--tabbar) + 76px);
  transform: translate(-50%, 20px);
  background: var(--fg);
  color: var(--on-fg);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  max-width: calc(100vw - 40px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--red); color: #fff; }

.login { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 40px 28px; max-width: 420px; margin: 0 auto; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.member-row .name { flex: 1; min-width: 0; }
.member-row input.input { width: 110px; text-align: right; }
.check { width: 20px; height: 20px; accent-color: var(--fg); flex: none; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; outline: 2px solid var(--bg); outline-offset: -4px; }
.swatch.on { border-color: var(--fg); }
.comment { padding: 10px 0; border-bottom: 1px solid var(--line); }
.diff { font-size: 13px; margin-top: 6px; }
.diff div { padding: 2px 0; }
.diff s { color: var(--faint); }
.err-line { color: var(--red); font-size: 14px; min-height: 20px; }

.label.row { display: flex; }
.label .linkbtn { font-size: 13px; }
@media (prefers-color-scheme: dark) {
  .overlay { background: rgba(0, 0, 0, 0.6); }
  .sheet { background: #22201F; border-top: 1px solid var(--line); }
  .sheet .input { background: #22201F; }
}
header.top .mid { flex: 1; min-width: 0; text-align: center; }
header.top .mid .sync { display: block; margin-top: 1px; }
header.top .mid .sync.ok { display: none; }
