:root {
  color-scheme: light dark;
  --bg: #f2f2f7;
  --surface: #ffffff;
  --fill: #e9e9ee;
  --text: #1c1c1e;
  --muted: #6c6c72;
  --line: #d8d8dd;
  --accent: #1c4e80;
  --on-accent: #ffffff;
  --alert: #c4291c;
  --gutter: 16px;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --fill: #2c2c2e;
    --text: #f5f5f7;
    --muted: #98989f;
    --line: #38383a;
    --accent: #7fb2e5;
    --on-accent: #06233f;
    --alert: #ff6b5e;
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) var(--gutter) calc(env(safe-area-inset-bottom) + 96px);
}

body.no-tabs main { padding-bottom: calc(env(safe-area-inset-bottom) + 32px); }

h1 { font-size: 32px; line-height: 1.15; font-weight: 700; letter-spacing: -0.01em; margin: 0; }
h2 {
  font-size: 13px;
  font-weight: 400;
  color: var(--muted);
  margin: 24px var(--gutter) 6px;
}
p { margin: 0; }

button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.amount, .num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.alert { color: var(--alert); }
.note { font-size: 13px; color: var(--muted); margin: 6px var(--gutter) 0; }

.bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; }
.bar .link { color: var(--accent); min-height: 44px; display: inline-flex; align-items: center; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }

.add {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
  display: grid; place-items: center;
  flex: none;
}
.add svg { width: 22px; height: 22px; }

.group { background: var(--surface); border-radius: var(--radius); overflow: hidden; }

.totals { display: grid; grid-template-columns: 1fr 1fr; }
.totals > div { padding: 12px var(--gutter); }
.totals > div + div { border-left: 0.5px solid var(--line); }
.totals .amount { display: block; font-size: 22px; font-weight: 600; }

.banner {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px var(--gutter);
  margin-bottom: 12px;
  font-size: 15px;
}
.banner .link { color: var(--accent); margin-top: 4px; display: inline-block; min-height: 28px; }

.search {
  width: 100%;
  margin-top: 12px;
  height: 40px;
  padding: 0 12px;
  font-size: 16px;
  border: 0;
  border-radius: 10px;
  background: var(--fill);
}
.search::placeholder { color: var(--muted); }

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 12px calc(var(--gutter) * -1) 0;
  padding: 0 var(--gutter);
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  min-height: 36px;
  padding: 0 14px;
  border-radius: 18px;
  background: var(--fill);
  font-size: 15px;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--on-accent); }

.list-head { display: flex; align-items: center; justify-content: space-between; margin: 18px 0 6px; padding: 0 var(--gutter); }
.list-head select {
  border: 0;
  background: none;
  color: var(--accent);
  font-size: 14px;
  text-align: right;
  min-height: 32px;
}

.row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 11px var(--gutter);
  position: relative;
}
.row + .row::before, .field + .field::before, .copy + .copy::before, .setting + .setting::before {
  content: "";
  position: absolute;
  top: 0; left: var(--gutter); right: 0;
  border-top: 0.5px solid var(--line);
}
.row .line { display: flex; justify-content: space-between; gap: 12px; }
.row .line + .line { margin-top: 2px; font-size: 14px; color: var(--muted); }
.row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .amount { flex: none; }
.row .state { flex: none; }

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

.segmented { display: flex; gap: 2px; background: var(--fill); border-radius: 9px; padding: 2px; }
.segmented button {
  flex: 1 1 0;
  min-width: 0;
  min-height: 36px;
  border-radius: 7px;
  font-size: 14px;
  padding: 0 4px;
}
.segmented button[aria-pressed="true"] { background: var(--surface); font-weight: 600; }
@media (prefers-color-scheme: dark) {
  .segmented button[aria-pressed="true"] { background: #55555a; }
}
.block { padding: 10px var(--gutter); }
.block + .block { border-top: 0.5px solid var(--line); }
.block > label, .block > .label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

.field {
  position: relative;
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  align-items: center;
  column-gap: 12px;
  min-height: 46px;
  padding: 6px var(--gutter);
}
.field label { font-size: 15px; }
.field input, .field textarea {
  width: 100%;
  min-width: 0;
  border: 0;
  background: none;
  font-size: 16px;
  text-align: right;
  padding: 4px 0;
  appearance: none;
  -webkit-appearance: none;
}
.field textarea { text-align: left; resize: vertical; min-height: 60px; grid-column: 1 / -1; }
.field input::-webkit-date-and-time-value { text-align: right; }
.field .hint { grid-column: 1 / -1; font-size: 13px; color: var(--alert); text-align: right; }
.field[data-state="ok"] .hint { display: none; }

.copy {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 9px var(--gutter);
  min-height: 56px;
}
.copy .label { display: block; font-size: 13px; color: var(--muted); }
.copy .value { display: block; overflow-wrap: anywhere; }
.copy svg { width: 20px; height: 20px; color: var(--accent); flex: none; }

.hero { padding: 6px 0 16px; }
.hero h1 { font-size: 26px; }
.hero .amount { font-size: 34px; font-weight: 700; display: block; margin-top: 6px; }

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 600;
  text-align: center;
  padding: 8px 16px;
}
.btn.quiet { background: var(--surface); color: var(--accent); font-weight: 400; }
.btn.danger { background: var(--surface); color: var(--alert); font-weight: 400; }
.btn[disabled] { opacity: 0.5; }
.stack { display: grid; gap: 10px; margin-top: 20px; }

.pages { display: flex; gap: 10px; overflow-x: auto; margin: 0 calc(var(--gutter) * -1); padding: 0 var(--gutter) 4px; }
.page { position: relative; flex: none; width: 104px; height: 144px; border-radius: 8px; overflow: hidden; background: var(--fill); display: block; }
.page img { width: 100%; height: 100%; object-fit: cover; display: block; }
.page .tag { position: absolute; inset: 0; display: grid; place-items: center; font-size: 14px; color: var(--muted); }
.page .remove {
  position: absolute; top: 0; right: 0;
  width: 44px; height: 44px;
  display: grid; place-items: start end;
  padding: 6px;
}
.page .remove span {
  width: 24px; height: 24px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.6); color: #fff;
  display: grid; place-items: center; font-size: 15px; line-height: 1;
}

.file-button { position: relative; overflow: hidden; }
.file-button input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; font-size: 0; }

.progress { height: 4px; border-radius: 2px; background: var(--fill); overflow: hidden; margin-top: 10px; }
.progress div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s; }

details { margin-top: 20px; }
summary { color: var(--accent); padding: 8px var(--gutter); min-height: 44px; }
details pre {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 12px var(--gutter);
  font: 13px/1.4 ui-monospace, Menlo, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 6px 0 0;
}

.setting { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; text-align: left; min-height: 46px; padding: 8px var(--gutter); }
.setting .value { color: var(--muted); }
.setting.action { color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 10px 6px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 400; }
th { font-size: 12px; color: var(--muted); }
th:first-child, td:first-child { text-align: left; padding-left: var(--gutter); overflow-wrap: anywhere; }
th:last-child, td:last-child { padding-right: var(--gutter); }
tbody tr { border-top: 0.5px solid var(--line); }
tfoot tr { border-top: 0.5px solid var(--line); }
tfoot td { font-weight: 600; }

#tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  justify-content: center;
  background: var(--surface);
  border-top: 0.5px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 5;
}
#tabs a {
  flex: 1 1 0;
  max-width: 200px;
  min-height: 52px;
  display: grid;
  place-items: center;
  font-size: 14px;
  color: var(--muted);
}
#tabs a[aria-current="page"] { color: var(--accent); font-weight: 600; }
body.no-tabs #tabs { display: none; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 72px);
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--text);
  color: var(--bg);
  font-size: 15px;
  padding: 9px 16px;
  border-radius: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  z-index: 20;
}
#toast.show { opacity: 1; }

dialog {
  border: 0;
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  padding: 18px var(--gutter) var(--gutter);
  width: min(340px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog h3 { margin: 0 0 6px; font-size: 18px; }
dialog p { font-size: 15px; color: var(--muted); }
dialog .stack { margin-top: 16px; gap: 8px; }
dialog input {
  width: 100%;
  margin-top: 12px;
  height: 44px;
  border-radius: 10px;
  border: 0;
  background: var(--surface);
  padding: 0 12px;
  font-size: 16px;
}
dialog .error { color: var(--alert); font-size: 14px; margin-top: 8px; }

.viewer { position: fixed; inset: 0; background: #000; overflow: auto; z-index: 30; }
.viewer img { width: 100%; display: block; }
.viewer button {
  position: fixed;
  top: calc(env(safe-area-inset-top) + 8px);
  right: 12px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 20px;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
}

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