:root {
  --bg: #f4f6f5; --card: #ffffff; --text: #1b2421; --muted: #66736f; --line: #dfe5e3;
  --accent: #0f766e; --accent-ink: #ffffff; --accent-soft: #e3f1ef;
  --ok: #157347; --ok-bg: #e5f4ec; --warn: #8a5a00; --warn-bg: #fff4dc; --err: #b42318; --err-bg: #fde9e7;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101514; --card: #19201e; --text: #e7eeeb; --muted: #94a39e; --line: #2a3431;
    --accent: #2bb3a3; --accent-ink: #062320; --accent-soft: #163330;
    --ok: #6fd3a0; --ok-bg: #12291f; --warn: #f1c46b; --warn-bg: #2d2412; --err: #ff8a80; --err-bg: #331816;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
main { max-width: 720px; margin: 0 auto; padding: 12px 14px; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.35rem; margin: 0 0 12px; }
h2 { font-size: 1.05rem; margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 5px; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); font-size: 1.1rem; }
.pill { font-size: .85rem; padding: 6px 12px; border-radius: 99px; background: var(--accent-soft); }

.tabs {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabs a { flex: 1; min-width: 0; text-align: center; padding: 8px 0 9px; color: var(--muted); font-size: .68rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tabs a span { display: block; font-size: 1.25rem; line-height: 1.3; }
.tabs a.on { color: var(--accent); font-weight: 600; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card.narrow { max-width: 380px; margin: 40px auto; }
.hero .big { font-size: 2.3rem; font-weight: 700; letter-spacing: -.02em; margin: 2px 0; }
.big2 { font-size: 1.3rem; font-weight: 700; }

.flash { padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: .92rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }
.flash.error { background: var(--err-bg); color: var(--err); }

label { display: block; margin-bottom: 12px; font-size: .9rem; color: var(--muted); }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
input, select, textarea {
  display: block; width: 100%; margin-top: 4px; padding: 10px 11px; font: inherit; font-size: 16px;
  color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
label.inline select { width: auto; margin: 0; padding: 6px 8px; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
fieldset { border: 0; padding: 0; margin: 0 0 12px; }
legend { font-size: .9rem; color: var(--muted); margin-bottom: 6px; }

.money-input { position: relative; }
.money-input span { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); margin-top: 2px; }
.money-input input { padding-left: 24px; }
label > .money-input input { margin-top: 4px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 16px;
  font: inherit; font-weight: 600; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--text); cursor: pointer;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { background: transparent; color: var(--err); border-color: var(--err); }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .6; }
.actions { display: flex; gap: 10px; margin: 6px 0 14px; flex-wrap: wrap; }
.actions .btn { flex: 1; min-width: 140px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { margin: 0; }
.chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span {
  display: inline-block; padding: 8px 13px; border-radius: 99px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: .92rem; cursor: pointer;
}
.chip input:checked + span { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip input:focus-visible + span { outline: 2px solid var(--accent); }

.row2, .row3 { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
@media (min-width: 560px) { .row3 { grid-template-columns: 1.2fr 1fr 1fr; } }
.row3 > label:last-child { grid-column: 1 / -1; }
@media (min-width: 560px) { .row3 > label:last-child { grid-column: auto; } }

.bar-row { margin-bottom: 10px; }
.bar-label { display: flex; justify-content: space-between; font-size: .92rem; margin-bottom: 3px; }
.bar { height: 8px; background: var(--accent-soft); border-radius: 99px; overflow: hidden; }
.bar div { height: 100%; background: var(--accent); border-radius: 99px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li + li { border-top: 1px solid var(--line); }
.list a { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; color: var(--text); }
.amt { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }

.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px 12px; text-align: center;
  color: var(--text); cursor: pointer; margin-bottom: 14px;
}
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.drop img { max-width: 100%; max-height: 320px; border-radius: 8px; }

.receipt-img { margin-bottom: 12px; }
.receipt-img img { display: block; max-width: 100%; max-height: 60vh; margin: 8px auto 0; border-radius: 8px; }
summary { cursor: pointer; color: var(--accent); font-size: .92rem; }

.items-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin: 6px 0 8px; }
.items-head h2 { margin: 0; }
.items-head select { width: auto; margin: 0; }
.item {
  display: grid; gap: 6px; grid-template-columns: 64px minmax(0, 1fr) minmax(0, 1.3fr) 30px;
  grid-template-areas: "n n n x" "q p c c" "j j j j"; padding: 10px 0; border-top: 1px solid var(--line);
}
.item input, .item select { margin: 0; padding: 8px 9px; min-width: 0; }
.item .money-input input { padding-left: 22px; }
.item .iname { grid-area: n; } .item .iqty { grid-area: q; text-align: center; }
.item .money-input { grid-area: p; } .item .iproj { grid-area: j; font-size: .88rem; color: var(--muted); } .item .icat { grid-area: c; } .item .x { grid-area: x; }
@media (min-width: 620px) {
  .item { grid-template-columns: 1fr 64px 110px 160px 30px; grid-template-areas: "n q p c x" "j j j j j"; }
}
.x { border: 0; background: none; color: var(--muted); font-size: 1rem; cursor: pointer; }
.sumline { font-size: .88rem; margin: 10px 0 14px; color: var(--muted); }
.sumline.ok { color: var(--ok); } .sumline.warn { color: var(--warn); }
.ocr pre { white-space: pre-wrap; font-size: .8rem; background: var(--bg); padding: 10px; border-radius: 8px; max-height: 300px; overflow: auto; }
.danger-zone { text-align: center; margin-bottom: 20px; }

.addcat { display: flex; gap: 8px; margin-bottom: 8px; }
.addcat input { margin: 0; }
.cats { list-style: none; padding: 0; margin: 0; }
.cats li { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--line); }
.cats li.hidden { opacity: .55; }
.cats .rename { display: flex; gap: 6px; flex: 1; }
.cats .rename input { margin: 0; padding: 7px 9px; }

.bar.over div { background: var(--err); }
.over-text { color: var(--err); font-weight: 600; }
.tag { font-size: .72rem; padding: 2px 7px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); vertical-align: middle; }
.projects li.done { opacity: .65; }
.projects .grow { flex: 1; min-width: 0; }
.projects .bar { margin-top: 6px; }
details.card > summary { font-weight: 600; }
.actions form { flex: 1; display: flex; }
.actions form .btn { flex: 1; }
.wide-select { width: 100%; margin-top: 4px; }
