:root {
  --navy: #1f2a44;
  --navy-2: #2c3a5c;
  --orange: #f28c28;
  --bg: #f4f5f8;
  --card: #ffffff;
  --text: #1a1d24;
  --muted: #6b7280;
  --line: #e5e7eb;
  --green: #138a4a;
  --red: #c62828;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.4;
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + var(--safe-t)) 16px 10px;
  background: var(--navy); color: #fff;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { width: 34px; height: 34px; border-radius: 8px; }
.brand-name { font-weight: 700; font-size: 17px; }
.brand-sub { font-size: 12px; opacity: .75; }
.sync-pill {
  border: 0; border-radius: 999px; padding: 6px 12px; font-size: 12px; font-weight: 600;
  background: rgba(255,255,255,.14); color: #fff; cursor: pointer; white-space: nowrap;
}
.sync-pill.warn { background: var(--orange); color: #1a1d24; }
.sync-pill.err { background: var(--red); }

/* Main view */
.view { padding: 14px 14px calc(96px + var(--safe-b)); max-width: 720px; margin: 0 auto; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 20px 4px 8px; }
h2:first-child { margin-top: 4px; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.card-title { font-weight: 700; margin-bottom: 4px; }
.hint { color: var(--muted); font-size: 13px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .l { min-width: 0; }
.row .r { text-align: right; flex-shrink: 0; }
.name { font-weight: 600; }
.sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; }
.amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.zero { color: var(--muted); }
.cur { font-size: 11px; font-weight: 600; opacity: .7; margin-left: 2px; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: var(--radius); padding: 12px 14px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }

.settle { background: #fff7ee; border: 1px solid #f7d2ab; }
.settle li { margin: 4px 0; }
.settle ul { margin: 6px 0 0; padding-left: 18px; }

/* Entries */
.entry { cursor: pointer; }
.chip { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: #eef0f5; color: var(--navy-2); margin-right: 4px; }
.chip.room { background: #e8f4ff; color: #0b5cad; }
.chip.in { background: #e6f5ec; color: var(--green); }
.chip.tr { background: #fff1e3; color: #a65a10; }
.chip.pending { background: var(--orange); color: #1a1d24; }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* Forms */
.seg { display: flex; background: #e7e9ef; border-radius: 10px; padding: 3px; margin-bottom: 12px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px 4px; border-radius: 8px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: #fff; color: var(--navy); box-shadow: 0 1px 2px rgba(0,0,0,.1); }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input[type=text], input[type=number], input[type=date], input[type=url], input[type=password], select, textarea {
  width: 100%; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  font-size: 16px; /* prevents iOS zoom */ appearance: none; -webkit-appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, #888 50%), linear-gradient(135deg, #888 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
textarea { min-height: 64px; resize: vertical; }
input.big { font-size: 28px; font-weight: 700; padding: 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choices label { display: flex; align-items: center; gap: 6px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; cursor: pointer; }
.choices input { accent-color: var(--navy); width: 18px; height: 18px; margin: 0; }
.choices label:has(input:checked) { border-color: var(--navy); background: #eef1f8; font-weight: 600; }
.btn { display: block; width: 100%; border: 0; border-radius: 12px; padding: 14px; font-weight: 700; font-size: 16px; background: var(--navy); color: #fff; cursor: pointer; }
.btn.orange { background: var(--orange); color: #1a1d24; }
.btn.ghost { background: #e7e9ef; color: var(--navy); }
.btn.danger { background: #fde8e8; color: var(--red); }
.btn + .btn { margin-top: 10px; }
.btn:disabled { opacity: .5; }
.photo-prev { max-width: 100%; max-height: 220px; border-radius: 10px; margin-top: 8px; display: block; }
.linkbtn { border: 0; background: none; color: #0b5cad; font-weight: 600; padding: 0; cursor: pointer; }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-around;
  background: #fff; border-top: 1px solid var(--line);
  padding: 6px 6px calc(6px + var(--safe-b));
}
.tabbar button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 11px; color: var(--muted); cursor: pointer; padding: 4px 0; }
.tabbar button .ti { font-size: 20px; line-height: 1; }
.tabbar button.on { color: var(--navy); font-weight: 700; }
.tabbar .tab-add { flex: 0 0 auto; width: 56px; height: 56px; border-radius: 50%; background: var(--orange); color: #1a1d24; font-size: 32px; font-weight: 400; margin-top: -26px; box-shadow: 0 4px 12px rgba(242,140,40,.45); justify-content: center; }
.tabbar.hidden { display: none; }

/* Modal & toast */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(15,20,35,.5); display: flex; align-items: flex-end; justify-content: center; }
.modal.hidden, .toast.hidden { display: none; }
.sheet { background: var(--bg); width: 100%; max-width: 720px; max-height: 88vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); }
.sheet h3 { margin: 0 0 10px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; word-break: break-word; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--safe-b)); z-index: 60; background: var(--navy); color: #fff; padding: 10px 16px; border-radius: 10px; font-weight: 600; box-shadow: 0 6px 20px rgba(0,0,0,.25); max-width: 90vw; }

/* Onboarding */
.welcome { text-align: center; padding: 20px 6px; }
.welcome img { width: 84px; height: 84px; border-radius: 20px; }
.welcome h1 { font-size: 22px; margin: 12px 0 4px; }
.people { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 18px 0; }
.people button { padding: 18px 8px; border-radius: 14px; border: 2px solid var(--line); background: #fff; font-size: 17px; font-weight: 700; cursor: pointer; }
.people button.on { border-color: var(--navy); background: #eef1f8; }
.bar { height: 6px; background: #eef0f5; border-radius: 3px; margin-top: 5px; width: 160px; max-width: 45vw; }
.bar i { display: block; height: 100%; background: var(--orange); border-radius: 3px; }
.card.neg { color: var(--red); background: #fff5f5; }
