:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f5;
  --border: #e3e6ea;
  --text: #15191e;
  --muted: #5f6b7a;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #e0f2ef;
  --pos: #137a3e;
  --pos-soft: #e3f4e9;
  --neg: #b42318;
  --neg-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1215;
    --surface: #171b20;
    --surface-2: #1e242a;
    --border: #2a3138;
    --text: #e9edf1;
    --muted: #9aa6b2;
    --accent: #2bb3a3;
    --accent-ink: #062320;
    --accent-soft: #123a36;
    --pos: #4cc982;
    --pos-soft: #12301f;
    --neg: #ff7b6e;
    --neg-soft: #3a1a17;
    --warn: #f2c14e;
    --warn-soft: #362b10;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.container { width: 100%; max-width: 860px; margin: 0 auto; padding: 0 16px; }

h1, h2, h3 { line-height: 1.25; margin: 0; }
h1 { font-size: 1.6rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
p { margin: 0; }

.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.small-text { font-size: .85rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.topbar-actions { display: flex; gap: 6px; }

main { flex: 1; padding-top: 24px; padding-bottom: 32px; }

.footer { padding-bottom: 28px; color: var(--muted); font-size: .82rem; display: grid; gap: 4px; }

/* Buttons & inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px;
  border: 1px solid transparent; border-radius: 10px;
  background: var(--accent); color: var(--accent-ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.06); }
.btn:disabled { opacity: .5; cursor: not-allowed; filter: none; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.ghost { background: transparent; color: var(--text); border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); filter: none; }
.btn.danger { background: transparent; color: var(--neg); border-color: var(--border); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: .85rem; }
.btn:focus-visible, input:focus-visible, select:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

input[type=text], input[type=date], input[type=search], select, .input {
  width: 100%; min-height: 42px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); font: inherit;
}
input::placeholder { color: var(--muted); opacity: .8; }
label.field { display: grid; gap: 6px; font-weight: 600; font-size: .9rem; }
.prefix-input { position: relative; }
.prefix-input span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.prefix-input input { padding-left: 28px; }
.suffix-input { position: relative; }
.suffix-input span { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; font-size: .85rem; }
.suffix-input input { padding-right: 34px; text-align: right; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 12px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

/* Home */
.hero { display: grid; gap: 8px; margin-bottom: 20px; }
.hero p { color: var(--muted); max-width: 60ch; }
.group-list { display: grid; gap: 10px; margin-top: 16px; }
.group-card { display: flex; align-items: center; gap: 14px; padding: 14px 16px; color: inherit; text-decoration: none; }
.group-card:hover { border-color: var(--accent); }
.group-card .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--muted); font-size: 1.3rem; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); display: grid; gap: 8px; justify-items: center; }

/* Avatars */
.avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: .8rem; font-weight: 700; color: #fff;
}
.avatar.lg { width: 42px; height: 42px; font-size: .95rem; }
.avatars { display: flex; }
.avatars .avatar { width: 26px; height: 26px; font-size: .68rem; border: 2px solid var(--surface); margin-left: -6px; }
.avatars .avatar:first-child { margin-left: 0; }

/* Group header & stats */
.back { color: var(--muted); text-decoration: none; font-size: .9rem; display: inline-flex; gap: 4px; margin-bottom: 8px; }
.back:hover { color: var(--text); }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 16px 0; }
.stat { padding: 14px; }
.stat .label { color: var(--muted); font-size: .8rem; }
.stat .value { font-size: 1.25rem; font-weight: 700; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; scrollbar-width: none; }
.tab {
  background: none; border: 0; border-bottom: 2px solid transparent;
  padding: 10px 12px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; white-space: nowrap;
}
.tab[aria-selected=true] { color: var(--accent); border-bottom-color: var(--accent); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--surface-2); color: var(--muted); font-size: .75rem; margin-left: 4px; }

/* Lists */
.list { display: grid; }
.list > .item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
.list > .item:first-child { border-top: 0; }
.item .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { color: var(--muted); font-size: .84rem; }
.item.invalid { background: var(--warn-soft); }
.item.settlement .title { color: var(--muted); }
.date-chip { flex: none; width: 44px; text-align: center; line-height: 1.1; color: var(--muted); font-size: .72rem; text-transform: uppercase; }
.date-chip b { display: block; font-size: 1.1rem; color: var(--text); }
.amount-col { text-align: right; }
.amount-col .num { font-weight: 650; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.pill.pos { background: var(--pos-soft); }
.pill.neg { background: var(--neg-soft); }
.pill.zero { background: var(--surface-2); color: var(--muted); }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; font: inherit; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.share-list { display: none; padding: 0 16px 12px 72px; color: var(--muted); font-size: .85rem; }
.share-list.open { display: grid; gap: 2px; }
.share-list div { display: flex; justify-content: space-between; gap: 12px; }

.notice { padding: 12px 14px; border-radius: 10px; font-size: .9rem; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.ok { background: var(--pos-soft); color: var(--pos); }
.notice.err { background: var(--neg-soft); color: var(--neg); }

.balance-bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin-top: 6px; }
.balance-bar > i { display: block; height: 100%; border-radius: 3px; }

/* Dialog */
.dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px);
  padding: 0; border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text);
}
.dialog::backdrop { background: rgba(10, 14, 18, .45); }
.dialog form { display: grid; gap: 14px; padding: 20px; }
.dialog .head { display: flex; justify-content: space-between; align-items: center; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 3px; }
.segmented button { border: 0; background: none; padding: 8px 4px; border-radius: 8px; font: inherit; font-size: .85rem; font-weight: 600; color: var(--muted); cursor: pointer; }
.segmented button[aria-pressed=true] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.participants { display: grid; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.participant { display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--border); }
.participant:first-child { border-top: 0; }
.participant input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.participant .value { width: 110px; }
.participant .share { min-width: 90px; text-align: right; font-weight: 600; }
.participant.off { opacity: .55; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: .9rem; box-shadow: 0 8px 24px rgba(0,0,0,.2); z-index: 50; max-width: calc(100vw - 32px);
}

.spinner { width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  h1 { font-size: 1.35rem; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stats .stat:first-child { grid-column: span 2; }
  .two-col { grid-template-columns: 1fr; }
  .participant { grid-template-columns: auto 1fr auto; }
  .participant .share { grid-column: 2 / 4; text-align: left; min-width: 0; font-size: .85rem; color: var(--muted); }
  .participant .value { width: 96px; }
  .share-list { padding-left: 16px; }
  .date-chip { display: none; }
  .topbar-actions .btn { padding: 0 8px; }
}
