:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --ink: #1c1b19;
  --muted: #6b675f;
  --line: #e4dfd4;
  --accent: #0f7b5f;
  --accent-ink: #ffffff;
  --accent-soft: #e1f0ea;
  --owe: #c2410c;
  --owe-soft: #fbeade;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(28, 27, 25, .06), 0 4px 14px rgba(28, 27, 25, .06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121311;
    --surface: #1c1d1a;
    --surface-2: #262823;
    --ink: #f1efe9;
    --muted: #a19d94;
    --line: #30322c;
    --accent: #3cc79f;
    --accent-ink: #0b1f18;
    --accent-soft: #173229;
    --owe: #f39364;
    --owe-soft: #3a2419;
    --danger: #f97066;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
img { max-width: 100%; display: block; }

#app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 16px calc(110px + env(safe-area-inset-bottom));
}
.loading { padding: 80px 0; text-align: center; color: var(--muted); }

/* ---------- top bar ---------- */
.bar { display: flex; align-items: center; gap: 8px; min-height: 52px; margin-bottom: 8px; }
.bar h1 { font-size: 18px; font-weight: 700; margin: 0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  width: 42px; height: 42px; flex: none; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent; text-decoration: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; letter-spacing: -.01em; }
.brand img { width: 34px; height: 34px; border-radius: 10px; }

/* ---------- type ---------- */
h2 { font-size: 26px; line-height: 1.15; letter-spacing: -.02em; margin: 8px 0 6px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin: 26px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.lead { font-size: 17px; color: var(--muted); margin: 0 0 22px; }
.pos { color: var(--accent); }
.neg { color: var(--owe); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 20px; border-radius: 14px; border: 1px solid transparent;
  font-weight: 700; text-decoration: none; background: var(--accent); color: var(--accent-ink);
  transition: transform .08s ease, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--line); }
.btn.block { width: 100%; }
.btn.sm { min-height: 38px; padding: 0 14px; border-radius: 11px; font-size: 14px; }
.btn-row { display: flex; gap: 10px; }
.btn-row > * { flex: 1; }
.stack { display: grid; gap: 12px; }

/* ---------- cards + lists ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px; text-decoration: none;
  border-bottom: 1px solid var(--line); background: transparent; width: 100%; text-align: left; border-left: 0; border-right: 0; border-top: 0;
}
.row:last-child { border-bottom: 0; }
a.row:hover, button.row:hover { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .end { text-align: right; flex: none; font-size: 14px; line-height: 1.25; }
.row .end strong { display: block; font-size: 15px; }
.row.deleted .title { text-decoration: line-through; color: var(--muted); }

.date-chip { width: 44px; flex: none; text-align: center; line-height: 1.1; color: var(--muted); }
.date-chip b { display: block; font-size: 18px; color: var(--ink); }
.date-chip span { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

.avatar {
  width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 15px; color: #fff;
}
.avatar.sm { width: 30px; height: 30px; font-size: 12px; }
.c0 { background: #0f7b5f; } .c1 { background: #c2410c; } .c2 { background: #4f46e5; } .c3 { background: #b45309; }
.c4 { background: #be185d; } .c5 { background: #0e7490; } .c6 { background: #6d28d9; } .c7 { background: #4d7c0f; }
.pay-icon { width: 40px; height: 40px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.pay-icon svg { width: 20px; height: 20px; }
.clip { display: inline-block; width: 14px; height: 14px; vertical-align: -2px; margin-left: 4px; color: var(--muted); }

/* ---------- group summary ---------- */
.summary { padding: 20px; margin-bottom: 14px; }
.summary .label { font-size: 14px; color: var(--muted); font-weight: 600; }
.summary .big { font-size: 34px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; margin: 4px 0 2px; }
.summary .btn-row { margin-top: 16px; }

.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); margin: 6px 0 16px; }
.tabs a, .tabs button {
  flex: 1; text-align: center; padding: 10px 6px; border-radius: 11px; border: 0; background: transparent;
  font-weight: 700; font-size: 14px; text-decoration: none; color: var(--muted);
}
.tabs .on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.month { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 22px 4px 8px; }
.month:first-child { margin-top: 4px; }

.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.empty svg { width: 56px; height: 56px; color: var(--line); margin-bottom: 10px; }
.empty p { margin: 4px 0; }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field > span, .field-label { font-size: 14px; font-weight: 700; }
.field small { color: var(--muted); font-size: 13px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 50px; padding: 12px 14px; border-radius: 13px; border: 1px solid var(--line);
  background: var(--surface); outline: none; font-size: 16px;
}
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.money { position: relative; }
.money::before { content: "₱"; position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-weight: 700; color: var(--muted); }
.money .input { padding-left: 32px; }
.money.big .input { font-size: 28px; font-weight: 800; min-height: 64px; padding-left: 40px; }
.money.big::before { font-size: 26px; left: 16px; }
.pin { letter-spacing: .5em; font-size: 24px; font-weight: 800; text-align: center; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.name-row { display: flex; gap: 8px; margin-bottom: 8px; }
.name-row .input { flex: 1; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; padding: 4px; border-radius: 14px; background: var(--surface-2); }
.seg button { border: 0; background: transparent; padding: 10px 2px; border-radius: 11px; font-weight: 700; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.split-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.split-row:last-child { border-bottom: 0; }
.split-row .grow { flex: 1; min-width: 0; font-weight: 600; }
.split-row .share { font-size: 14px; color: var(--muted); min-width: 84px; text-align: right; }
.split-row .input { width: 96px; min-height: 42px; padding: 8px 10px; text-align: right; }
.split-row input[type=checkbox] { width: 24px; height: 24px; accent-color: var(--accent); }
label.split-row { cursor: pointer; }
.split-foot { display: flex; justify-content: space-between; padding: 12px 14px; font-size: 14px; font-weight: 700; background: var(--surface-2); }
.split-foot .bad { color: var(--owe); }
.split-foot .good { color: var(--accent); }

.receipt-box { display: flex; align-items: center; gap: 12px; }
.receipt-thumb { width: 72px; height: 72px; border-radius: 12px; object-fit: cover; border: 1px solid var(--line); }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.save-bar {
  position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.save-bar .inner { max-width: 528px; margin: 0 auto; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; right: max(16px, calc(50% - 264px)); bottom: calc(20px + env(safe-area-inset-bottom));
  display: inline-flex; align-items: center; gap: 8px; height: 56px; padding: 0 22px; border-radius: 28px; border: 0;
  background: var(--accent); color: var(--accent-ink); font-weight: 800; text-decoration: none;
  box-shadow: 0 6px 20px rgba(15, 123, 95, .35);
}
.fab svg { width: 22px; height: 22px; }

/* ---------- detail ---------- */
.detail-head { text-align: center; padding: 20px 0 10px; }
.detail-head .amount { font-size: 40px; font-weight: 800; letter-spacing: -.02em; }
.detail-head .title { font-size: 20px; font-weight: 700; }
.banner { padding: 12px 14px; border-radius: 13px; background: var(--owe-soft); color: var(--owe); font-weight: 600; margin-bottom: 14px; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.receipt-full { border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }

/* ---------- sheet ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); display: flex; align-items: flex-end; justify-content: center; z-index: 20; animation: fade .15s ease; }
.sheet {
  width: 100%; max-width: 560px; background: var(--bg); border-radius: 22px 22px 0 0; padding: 22px 16px calc(20px + env(safe-area-inset-bottom));
  max-height: 92dvh; overflow: auto; animation: up .2s ease;
}
.sheet h2 { margin-top: 0; }
.invite-box { padding: 16px; border-radius: 14px; background: var(--surface); border: 1px dashed var(--line); margin: 14px 0; word-break: break-all; font-size: 14px; }
.invite-box .pin-show { font-size: 26px; font-weight: 800; letter-spacing: .25em; color: var(--ink); word-break: normal; }
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .92); z-index: 30; display: grid; place-items: center; padding: 16px; }
.lightbox img { max-height: 90dvh; object-fit: contain; border-radius: 8px; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; font-size: 15px;
  opacity: 0; pointer-events: none; transition: .2s ease; z-index: 40; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- home ---------- */
.hero { padding: 30px 0 10px; }
.hero-art { display: flex; margin-bottom: 18px; }
.hero-art .avatar { width: 52px; height: 52px; font-size: 20px; border: 3px solid var(--bg); margin-right: -12px; }
.how { display: grid; gap: 10px; margin: 26px 0; }
.how div { display: flex; gap: 12px; align-items: flex-start; }
.how b { width: 28px; height: 28px; flex: none; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 14px; }

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