:root {
  --bg: #0f0b1e;
  --bg-soft: #1a1430;
  --card: #211a3c;
  --card-hi: #2b2250;
  --line: #342a5c;
  --text: #ece9f5;
  --muted: #9a92c0;
  --brand: #8b5cf6;
  --brand-2: #ec4899;
  --brand-grad: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  --good: #34d399;
  --danger: #fb7185;
  --radius: 18px;
  --shadow: 0 10px 40px -12px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(236, 72, 153, .18), transparent 60%),
    radial-gradient(1000px 500px at -10% 10%, rgba(139, 92, 246, .22), transparent 55%),
    var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

.app-shell { max-width: 620px; margin: 0 auto; min-height: 100dvh; }

/* ---------- Topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: rgba(15, 11, 30, .72);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 20px; color: var(--text); text-decoration: none; letter-spacing: -.3px; display: inline-flex; align-items: center; gap: 8px; }
.brand .icon { color: var(--brand); }

/* ---------- Icons ---------- */
.icon { display: inline-block; vertical-align: -.18em; flex: none; }
.icon-lg { width: 26px; height: 26px; }
.topnav { display: flex; align-items: center; gap: 6px; }
.nav-link {
  color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600;
  padding: 8px 12px; border-radius: 12px; transition: background .18s, color .18s;
  display: inline-flex; align-items: center; gap: 6px;
}
.nav-link:hover { background: var(--card); color: var(--text); }

/* ---------- Signed-in user chip ---------- */
.user-chip {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
  padding: 5px 12px 5px 5px; border-radius: 30px; color: var(--text);
  background: var(--card); border: 1px solid var(--line); transition: border-color .18s, background .18s;
  max-width: 180px;
}
.user-chip:hover { border-color: var(--brand); background: var(--card-hi); }
.user-avatar {
  width: 26px; height: 26px; flex: none; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 800; color: #fff; background: var(--brand-grad);
}
.user-name { font-size: 14px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 420px) { .user-name { display: none; } }
.nav-btn { background: none; border: none; cursor: pointer; font: inherit; }
.inline-form { display: inline; }

.content { padding: 18px 16px 120px; }

/* ---------- Toasts ---------- */
.toasts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.toast {
  padding: 12px 16px; border-radius: 14px; font-size: 14px; font-weight: 600;
  border: 1px solid var(--line); background: var(--card);
  animation: toastIn .4s cubic-bezier(.16,1,.3,1) both;
}
.toast-success { border-color: rgba(52,211,153,.4); color: var(--good); }
.toast-error { border-color: rgba(251,113,133,.4); color: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px) scale(.98); } }

/* ---------- Hero / summary ---------- */
.hero {
  background: var(--brand-grad); border-radius: 24px; padding: 22px 22px 24px;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
  animation: rise .5s cubic-bezier(.16,1,.3,1) both;
}
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(400px 200px at 90% -20%, rgba(255,255,255,.25), transparent 60%);
}
.hero-label { font-size: 13px; font-weight: 700; opacity: .85; text-transform: uppercase; letter-spacing: 1px; }
.hero-amount { font-size: 40px; font-weight: 800; margin-top: 4px; letter-spacing: -1px; }
.hero-sub { margin-top: 10px; font-size: 14px; opacity: .9; display: flex; gap: 16px; }

/* ---------- Section head ---------- */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 26px 2px 14px;
}
.section-head h2 { font-size: 17px; font-weight: 700; letter-spacing: -.2px; }
.count-pill { font-size: 12px; color: var(--muted); background: var(--card); padding: 3px 10px; border-radius: 20px; }

/* ---------- Cards / groups ---------- */
.grid { display: grid; gap: 12px; }
.group-card {
  display: flex; align-items: center; gap: 14px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; text-decoration: none; color: var(--text);
  transition: transform .18s cubic-bezier(.16,1,.3,1), background .18s, border-color .18s;
  animation: rise .45s cubic-bezier(.16,1,.3,1) both;
}
.group-card:hover { transform: translateY(-3px); background: var(--card-hi); border-color: var(--brand); }
.group-card:active { transform: translateY(-1px) scale(.99); }
.group-emoji {
  width: 52px; height: 52px; flex: none; display: grid; place-items: center;
  border-radius: 15px; background: var(--bg-soft); border: 1px solid var(--line);
  color: var(--brand);
}
.group-card:hover .group-emoji { color: var(--brand-2); }
.group-meta { flex: 1; min-width: 0; }
.group-name { font-weight: 700; font-size: 16px; }
.group-stat { font-size: 13px; color: var(--muted); margin-top: 2px; }
.group-amount { font-weight: 800; font-size: 17px; white-space: nowrap; }
.chev { color: var(--muted); display: inline-flex; }

/* ---------- Empty state ---------- */
.empty {
  text-align: center; padding: 50px 24px; color: var(--muted);
  border: 2px dashed var(--line); border-radius: 22px; animation: rise .5s both;
}
.empty-emoji { font-size: 46px; }
.empty h3 { color: var(--text); margin: 14px 0 6px; }

/* ---------- Expense rows ---------- */
.exp-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; animation: rise .4s cubic-bezier(.16,1,.3,1) both;
}
.exp-main { flex: 1; min-width: 0; }
.exp-title { font-weight: 700; }
.exp-note { font-size: 13px; color: var(--muted); margin-top: 2px; }
.exp-split-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.tag {
  font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px;
  background: var(--bg-soft); color: var(--muted); border: 1px solid var(--line);
  display: inline-flex; align-items: center; gap: 4px;
}
.hero-label { display: inline-flex; align-items: center; gap: 6px; }
.exp-amount { font-weight: 800; white-space: nowrap; }
.exp-per { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }

/* ---------- Balances ---------- */
.balance-list { display: grid; gap: 10px; }
.balance-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
}
.avatar {
  width: 38px; height: 38px; flex: none; border-radius: 50%; display: grid; place-items: center;
  font-size: 13px; font-weight: 800; color: #fff; background: var(--brand-grad);
}
.balance-name { flex: 1; font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.balance-amt { font-weight: 800; color: var(--brand-2); }

/* ---------- Role badges ---------- */
.role-badge {
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: .5px;
  padding: 2px 7px; border-radius: 20px; background: var(--brand-grad); color: #fff;
}
.role-badge.you { background: var(--bg-soft); color: var(--muted); border: 1px solid var(--line); }
.role-badge.guest { background: none; color: var(--muted); border: 1px dashed var(--line); }

/* ---------- Invite card ---------- */
.invite-card {
  margin-top: 14px; padding: 18px; border-radius: 18px;
  background: var(--card); border: 1px solid var(--line); animation: rise .4s both;
}
.invite-head { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 14px; }
.invite-label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin: 14px 0 6px; }
.invite-link-row { display: flex; gap: 8px; }
.invite-link-row input {
  flex: 1; min-width: 0; padding: 11px 12px; border-radius: 11px; font: inherit; font-size: 13px;
  color: var(--text); background: var(--bg-soft); border: 1px solid var(--line);
}
.invite-inline { display: flex; gap: 8px; }
.invite-inline input {
  flex: 1; min-width: 0; padding: 11px 12px; border-radius: 11px; font: inherit;
  color: var(--text); background: var(--bg-soft); border: 1px solid var(--line);
}
.invite-inline input:focus, .invite-link-row input:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(139,92,246,.18);
}
.invite-inline .btn { padding: 11px 18px; flex: none; }
.btn-copy { padding: 11px 16px; flex: none; }
.btn-copy.copied { color: var(--good); border-color: rgba(52,211,153,.5); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: none; cursor: pointer; font: inherit; font-weight: 700; font-size: 15px;
  padding: 13px 20px; border-radius: 14px; color: #fff; background: var(--brand-grad);
  text-decoration: none; transition: transform .15s, filter .15s, box-shadow .15s;
  box-shadow: 0 8px 24px -8px rgba(139, 92, 246, .7);
}
.btn:hover { transform: translateY(-2px); filter: brightness(1.07); }
.btn:active { transform: translateY(0) scale(.98); }
.btn-ghost {
  background: var(--card); color: var(--text); border: 1px solid var(--line); box-shadow: none;
}
.btn-ghost:hover { background: var(--card-hi); }
.btn-danger { background: none; color: var(--danger); box-shadow: none; padding: 8px; }
.btn-danger:hover { filter: brightness(1.2); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; margin-top: 8px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%);
  z-index: 30; max-width: 588px; width: calc(100% - 32px);
}
/* Keep the horizontal centering on hover/active so it rises in place
   instead of jumping right (the generic .btn transforms drop translateX). */
.fab:hover { transform: translateX(-50%) translateY(-2px); }
.fab:active { transform: translateX(-50%) scale(.98); }

/* ---------- Forms ---------- */
.card-form {
  background: var(--card); border: 1px solid var(--line); border-radius: 22px;
  padding: 22px; box-shadow: var(--shadow); animation: rise .45s cubic-bezier(.16,1,.3,1) both;
}
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 7px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 13px 14px; border-radius: 13px; font: inherit; color: var(--text);
  background: var(--bg-soft); border: 1px solid var(--line); transition: border-color .18s, box-shadow .18s;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(139, 92, 246, .18);
}
.field textarea { resize: vertical; }
.field .errorlist { list-style: none; color: var(--danger); font-size: 12px; margin-top: 6px; }
.field .helptext { font-size: 12px; color: var(--muted); margin-top: 6px; display: block; }
.amount-field { position: relative; }
.amount-field .cur { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 700; }
.amount-field input { padding-left: 32px; font-size: 20px; font-weight: 700; }

/* ---------- Icon picker ---------- */
.icon-picker { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin-top: 6px; }
.icon-opt {
  aspect-ratio: 1; display: grid; place-items: center; cursor: pointer;
  background: var(--bg-soft); border: 1.5px solid var(--line); border-radius: 13px;
  color: var(--muted); transition: all .16s cubic-bezier(.16,1,.3,1);
}
.icon-opt:hover { color: var(--text); border-color: var(--brand); transform: translateY(-2px); }
.icon-opt:active { transform: scale(.94); }
.icon-opt.selected {
  color: #fff; border-color: transparent; background: var(--brand-grad);
  box-shadow: 0 8px 18px -8px var(--brand);
}

/* ---------- Quick-litre buttons (milk) ---------- */
.quick-litres { display: flex; gap: 8px; }
.chip-btn {
  cursor: pointer; font: inherit; font-weight: 700; font-size: 14px;
  padding: 9px 16px; border-radius: 30px; color: var(--text);
  background: var(--bg-soft); border: 1.5px solid var(--line); transition: all .16s;
}
.chip-btn:hover { border-color: var(--brand); transform: translateY(-1px); }
.chip-btn:active { transform: scale(.95); }
.page-title { font-size: 24px; font-weight: 800; letter-spacing: -.5px; margin-bottom: 4px; display: inline-flex; align-items: center; gap: 8px; }
.page-sub { color: var(--muted); font-size: 14px; margin-bottom: 20px; }
.back-link { color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 600; display: inline-block; margin-bottom: 14px; }
.back-link:hover { color: var(--text); }

/* ---------- Splitter chips ---------- */
.splitter-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.chip {
  position: relative; cursor: pointer; user-select: none;
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; border-radius: 30px; font-weight: 700; font-size: 14px;
  background: var(--bg-soft); border: 1.5px solid var(--line); color: var(--muted);
  transition: all .18s cubic-bezier(.16,1,.3,1);
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip .chip-dot {
  width: 20px; height: 20px; border-radius: 50%; border: 2px solid var(--line);
  display: grid; place-items: center; font-size: 12px; transition: all .18s;
}
.chip:has(input:checked) {
  background: rgba(139, 92, 246, .18); border-color: var(--brand); color: var(--text);
  transform: translateY(-1px);
}
.chip:has(input:checked) .chip-dot { background: var(--brand-grad); border-color: transparent; color: #fff; }
.chip:active { transform: scale(.96); }

.split-preview {
  margin-top: 14px; padding: 12px 14px; border-radius: 13px;
  background: var(--bg-soft); border: 1px dashed var(--line); font-size: 14px; color: var(--muted);
}
.split-preview b { color: var(--text); }
.split-preview.over { border-color: rgba(251,113,133,.5); color: var(--danger); }
.split-preview.ok { border-color: rgba(52,211,153,.5); color: var(--good); }

/* ---------- Split mode toggle ---------- */
.split-mode {
  display: flex; gap: 6px; margin-top: 14px; padding: 4px;
  background: var(--bg-soft); border: 1px solid var(--line); border-radius: 14px;
}
.mode-opt { flex: 1; cursor: pointer; }
.mode-opt input { position: absolute; opacity: 0; pointer-events: none; }
.mode-opt span {
  display: block; text-align: center; padding: 9px; border-radius: 10px;
  font-weight: 700; font-size: 14px; color: var(--muted); transition: all .18s;
}
.mode-opt:has(input:checked) span { background: var(--brand-grad); color: #fff; box-shadow: 0 6px 16px -8px var(--brand); }
.mode-opt:active span { transform: scale(.97); }

/* ---------- Custom share rows ---------- */
.custom-shares { display: grid; gap: 8px; margin-top: 12px; }
.share-row { display: flex; align-items: center; gap: 12px; animation: rise .3s both; }
.share-name { flex: 1; font-weight: 600; font-size: 14px; }
.share-input { position: relative; width: 140px; }
.share-input .cur { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 700; }
.share-input input {
  width: 100%; padding: 10px 12px 10px 26px; border-radius: 11px; font: inherit; font-weight: 700;
  color: var(--text); background: var(--bg-soft); border: 1px solid var(--line); text-align: right;
}
.share-input input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(139,92,246,.18); }

/* ---------- Member manager ---------- */
.member-row {
  display: flex; align-items: center; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px;
  animation: rise .4s both;
}
.member-name { flex: 1; font-weight: 600; }

/* ---------- Auth ---------- */
.auth-wrap { max-width: 400px; margin: 7vh auto 0; }
.auth-logo { display: flex; justify-content: center; margin-bottom: 14px; }
.auth-logo .icon {
  box-sizing: content-box; color: var(--brand); padding: 14px;
  border-radius: 18px; background: var(--card); border: 1px solid var(--line);
  box-shadow: 0 10px 30px -12px rgba(139, 92, 246, .6);
}
.auth-wrap h1 { text-align: center; font-size: 26px; font-weight: 800; margin-bottom: 4px; }
.auth-wrap .page-sub { text-align: center; }
.auth-switch { text-align: center; margin-top: 18px; color: var(--muted); font-size: 14px; }
.auth-switch a { color: var(--brand); font-weight: 700; text-decoration: none; }

@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

/* Stagger list children */
.grid > *:nth-child(1), .balance-list > *:nth-child(1) { animation-delay: .02s; }
.grid > *:nth-child(2), .balance-list > *:nth-child(2) { animation-delay: .06s; }
.grid > *:nth-child(3), .balance-list > *:nth-child(3) { animation-delay: .10s; }
.grid > *:nth-child(4), .balance-list > *:nth-child(4) { animation-delay: .14s; }
.grid > *:nth-child(5), .balance-list > *:nth-child(5) { animation-delay: .18s; }
.grid > *:nth-child(n+6) { animation-delay: .22s; }

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