:root {
  --orange-700: #C2410C;
  --orange-600: #EA580C;
  --orange-500: #F97316;
  --orange-400: #FB923C;
  --orange-200: #FED7AA;
  --orange-100: #FFEDD5;
  --orange-50: #FFF7ED;

  --ink: #1C1512;
  --ink-2: #4A3F38;
  --muted: #8A7D74;
  --line: #F2E6DA;
  --line-strong: #E8D6C5;
  --bg: #FFFBF7;
  --card: #FFFFFF;
  --surface: #FFFFFF;        /* inputs, chips, pills, small raised things */
  --owe: #3B302A;
  --placeholder: #BBAFA6;
  --topbar-bg: rgba(255, 251, 247, .82);
  --topbar-line: rgba(242, 230, 218, .8);
  --toast-bg: #1C1512;
  --glow: rgba(251, 146, 60, .14);

  /* chart palette (validated reference slots, light surface) */
  --viz-1: #2a78d6; --viz-2: #eb6834; --viz-3: #1baf7a; --viz-4: #eda100;
  --viz-5: #e87ba4; --viz-6: #008300; --viz-7: #4a3aa7; --viz-8: #e34948;

  --radius: 20px;
  --radius-sm: 12px;
  --shadow-sm: 0 1px 2px rgba(120, 53, 15, .06);
  --shadow: 0 1px 2px rgba(120, 53, 15, .05), 0 8px 24px -8px rgba(120, 53, 15, .12);
  --shadow-lg: 0 24px 64px -16px rgba(67, 20, 7, .35);
  --focus: 0 0 0 4px rgba(249, 115, 22, .22);

  --font: "Plus Jakarta Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --display: "Fraunces", Georgia, serif;
  color-scheme: light;
}

/* Warm charcoal dark theme. Follows the system setting unless the viewer picked a theme. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --orange-700: #FB923C;
    --orange-200: #7A3A12;
    --orange-100: #3D2618;
    --orange-50: #2A1D15;
    --ink: #F6EEE7;
    --ink-2: #D9CBBF;
    --muted: #A6978C;
    --line: #342A23;
    --line-strong: #4A3D33;
    --bg: #15100D;
    --card: #1F1915;
    --surface: #28201B;
    --owe: #E6D6C9;
    --placeholder: #7D6F65;
    --topbar-bg: rgba(21, 16, 13, .82);
    --topbar-line: rgba(74, 61, 51, .7);
    --toast-bg: #33271F;
    --glow: rgba(234, 88, 12, .16);
    --viz-1: #3987e5; --viz-2: #d95926; --viz-3: #199e70; --viz-4: #c98500;
    --viz-5: #d55181; --viz-6: #008300; --viz-7: #9085e9; --viz-8: #e66767;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px -10px rgba(0, 0, 0, .6);
    --shadow-lg: 0 28px 70px -18px rgba(0, 0, 0, .75);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --orange-700: #FB923C;
  --orange-200: #7A3A12;
  --orange-100: #3D2618;
  --orange-50: #2A1D15;
  --ink: #F6EEE7;
  --ink-2: #D9CBBF;
  --muted: #A6978C;
  --line: #342A23;
  --line-strong: #4A3D33;
  --bg: #15100D;
  --card: #1F1915;
  --surface: #28201B;
  --owe: #E6D6C9;
  --placeholder: #7D6F65;
  --topbar-bg: rgba(21, 16, 13, .82);
  --topbar-line: rgba(74, 61, 51, .7);
  --toast-bg: #33271F;
  --glow: rgba(234, 88, 12, .16);
  --viz-1: #3987e5; --viz-2: #d95926; --viz-3: #199e70; --viz-4: #c98500;
  --viz-5: #d55181; --viz-6: #008300; --viz-7: #9085e9; --viz-8: #e66767;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 10px 28px -10px rgba(0, 0, 0, .6);
  --shadow-lg: 0 28px 70px -18px rgba(0, 0, 0, .75);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 500px at 85% -10%, var(--glow), transparent 60%),
    var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

button, input, select { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--topbar-bg);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--topbar-line);
}
.topbar-inner {
  max-width: 1180px; margin: 0 auto; padding: 14px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px; position: relative; overflow: hidden;
  background: linear-gradient(135deg, var(--orange-500), var(--orange-700));
  box-shadow: 0 4px 12px -2px rgba(234, 88, 12, .45), inset 0 1px 0 rgba(255,255,255,.25);
}
.brand-mark::after {
  content: ""; position: absolute; inset: 7px 16px 7px 7px;
  background: #fff; border-radius: 9px 0 0 9px;
}
.brand-name { font-family: var(--display); font-size: 22px; font-weight: 600; letter-spacing: -.01em; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 18px; border-radius: 999px; border: 1px solid transparent;
  font-weight: 600; font-size: 14px; cursor: pointer; white-space: nowrap;
  transition: transform .15s ease, box-shadow .2s ease, background .2s ease, color .2s ease;
}
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  color: #fff;
  background: linear-gradient(180deg, var(--orange-500), var(--orange-600));
  box-shadow: 0 1px 0 rgba(255,255,255,.25) inset, 0 6px 16px -4px rgba(234, 88, 12, .55);
}
.btn-primary:hover { background: linear-gradient(180deg, var(--orange-600), var(--orange-700)); }
.btn-soft { background: var(--orange-50); color: var(--orange-700); border-color: var(--orange-100); }
.btn-soft:hover { background: var(--orange-100); }
.btn-ghost { background: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--orange-50); }
.btn-sm { height: 36px; padding: 0 14px; font-size: 13px; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 999px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--orange-50); color: var(--orange-700); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.icon-btn svg { width: 16px; height: 16px; }

/* ---------- layout ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 28px 24px 56px; }

.hero {
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: 1fr auto; gap: 24px; align-items: end;
  padding: 34px 36px; border-radius: 28px; color: #fff;
  background:
    radial-gradient(600px 300px at 100% 0%, rgba(255, 237, 213, .35), transparent 60%),
    radial-gradient(500px 260px at 0% 120%, rgba(124, 45, 18, .45), transparent 60%),
    linear-gradient(135deg, #F97316 0%, #EA580C 55%, #C2410C 100%);
  box-shadow: 0 20px 48px -20px rgba(194, 65, 12, .6);
}
.hero::before {
  content: ""; position: absolute; right: -80px; top: -120px; width: 360px; height: 360px;
  border-radius: 50%; border: 1px solid rgba(255,255,255,.18);
  box-shadow: 0 0 0 40px rgba(255,255,255,.04), 0 0 0 90px rgba(255,255,255,.03);
  pointer-events: none;
}
.hero-text { position: relative; min-width: 0; }
.eyebrow {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase;
  color: rgba(255,255,255,.8); margin-bottom: 6px;
}
.group-name {
  display: block; width: 100%; max-width: 560px; padding: 0 0 2px; margin: 0;
  background: transparent; border: 0; border-bottom: 1px dashed transparent; border-radius: 0;
  font-family: var(--display); font-weight: 600; font-size: clamp(30px, 4.4vw, 46px);
  line-height: 1.1; letter-spacing: -.02em; color: #fff;
}
.group-name:hover { border-bottom-color: rgba(255,255,255,.4); }
.group-name:focus { outline: none; border-bottom-color: #fff; }
.hero-sub { margin: 8px 0 0; color: rgba(255,255,255,.85); font-size: 14px; }

[hidden] { display: none !important; }

.hero-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; }
.hero-actions:not(:has(:not([hidden]))) { display: none; }
.share-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 16px; border: 0; border-radius: 999px;
  background: #fff; color: #C2410C; font-weight: 700; font-size: 13.5px; cursor: pointer; /* on the orange hero in both themes */
  box-shadow: 0 6px 16px -6px rgba(67, 20, 7, .45); transition: transform .15s, box-shadow .2s;
}
.share-btn:hover { transform: translateY(-1px); box-shadow: 0 10px 22px -8px rgba(67, 20, 7, .55); }
.share-btn:focus-visible { outline: none; box-shadow: 0 0 0 4px rgba(255, 255, 255, .45); }
.share-btn svg { width: 16px; height: 16px; }
.sync-pill {
  display: inline-flex; align-items: center; gap: 7px; height: 30px; padding: 0 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; color: #fff;
  background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .25);
}
.sync-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #fff; }
.sync-pill.saving::before { animation: pulse 1s ease-in-out infinite; }
.sync-pill.offline::before { background: var(--owe); box-shadow: 0 0 0 2px rgba(255,255,255,.7); }
.sync-pill.local::before { background: transparent; border: 1.5px solid #fff; }
@keyframes pulse { 50% { opacity: .25; } }

.stats { position: relative; display: flex; gap: 10px; margin: 0; }
.stat {
  min-width: 132px; padding: 14px 16px; border-radius: 16px;
  background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.22);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.stat dt { font-size: 12px; color: rgba(255,255,255,.82); margin-bottom: 4px; font-weight: 500; }
.stat dd { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -.01em; font-variant-numeric: tabular-nums; }

.grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(0, 1fr); gap: 20px; margin-top: 24px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 22px 22px 18px;
}
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.card h2 { margin: 0; font-family: var(--display); font-weight: 600; font-size: 21px; letter-spacing: -.01em; }
.card-sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); padding-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-owe { background: var(--owe); }
.dot-get { background: var(--orange-500); }

ul { list-style: none; margin: 0; padding: 0; }

/* ---------- avatars ---------- */
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 13px; font-weight: 700; letter-spacing: .02em;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.6);
}
.avatar-sm { width: 30px; height: 30px; font-size: 11px; }

/* ---------- balances ---------- */
.balance-list li {
  display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(90px, 38%) auto; gap: 14px; align-items: center;
  padding: 12px 4px; border-top: 1px solid var(--line);
}
.balance-list li:first-child { border-top: 0; }
.who { min-width: 0; }
.who strong { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { color: var(--muted); font-size: 12px; }
.bar { position: relative; height: 8px; border-radius: 99px; background: var(--orange-50); }
.bar::before { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 1px; background: var(--line-strong); }
.bar i { position: absolute; top: 0; bottom: 0; border-radius: 99px; transition: width .5s cubic-bezier(.2,.8,.2,1); }
.bar i.get { left: 50%; background: linear-gradient(90deg, var(--orange-400), var(--orange-600)); }
.bar i.owe { right: 50%; background: var(--owe); }
.amt { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt small { display: block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.amt.get { color: var(--orange-600); }
.amt.owe { color: var(--owe); }
.amt.zero { color: var(--muted); }
.amt.zero small { color: var(--muted); }
.amt.get small { color: var(--orange-500); }
.amt.owe small { color: var(--muted); }

/* ---------- transfers ---------- */
.transfer-list li {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-top: 8px;
  border-radius: 16px; background: linear-gradient(180deg, var(--surface), var(--orange-50)); border: 1px solid var(--orange-100);
}
.transfer-list li:first-child { margin-top: 0; }
.route { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; }
.route .names { min-width: 0; font-size: 14px; }
.route .names b { font-weight: 600; }
.route .names span { color: var(--muted); }
.route-arrow { color: var(--orange-500); }
.transfer-amt { font-weight: 700; font-size: 16px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- pairwise debts ---------- */
.debts summary { list-style: none; cursor: pointer; margin: 0; }
.debts summary::-webkit-details-marker { display: none; }
.debts .chev { color: var(--muted); transition: transform .2s; margin-top: 6px; }
.debts[open] .chev { transform: rotate(180deg); }
.debts[open] summary { margin-bottom: 14px; }
.debt-list li {
  display: flex; justify-content: space-between; gap: 12px; padding: 10px 2px; border-top: 1px solid var(--line); font-size: 14px;
}
.debt-list li:first-child { border-top: 0; }
.debt-list span { color: var(--ink-2); min-width: 0; }
.debt-list b { font-weight: 600; color: var(--ink); }
.debt-list .amt { font-weight: 600; }

/* ---------- members ---------- */
.member-list { display: flex; flex-wrap: wrap; gap: 8px; }
.member-list li {
  display: inline-flex; align-items: center; gap: 8px; padding: 4px 6px 4px 4px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); font-weight: 600; font-size: 14px;
}
.member-list .icon-btn { width: 26px; height: 26px; }
.member-list .icon-btn svg { width: 13px; height: 13px; }
.add-member { display: flex; gap: 8px; margin-top: 14px; }
.add-member input { flex: 1; min-width: 0; }

/* ---------- activity ---------- */
.activity li {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center;
  padding: 12px 4px; border-top: 1px solid var(--line); position: relative;
}
.activity li:first-child { border-top: 0; }
.act-icon {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: var(--orange-50); color: var(--orange-600); border: 1px solid var(--orange-100);
}
.act-icon.pay { background: var(--surface); color: var(--owe); border-color: var(--line-strong); }
.act-date { display: block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; line-height: 1.1; text-align: center; }
.act-date b { display: block; font-size: 15px; letter-spacing: 0; }
.act-main { min-width: 0; }
.act-main strong { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.act-main small { display: block; color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.act-side { display: flex; align-items: center; gap: 2px; }
.act-amt { font-weight: 700; font-variant-numeric: tabular-nums; margin-right: 6px; white-space: nowrap; }
.act-tools { display: flex; opacity: 0; transition: opacity .15s; }
.activity li:hover .act-tools, .activity li:focus-within .act-tools { opacity: 1; }
@media (hover: none) { .act-tools { opacity: 1; } }

/* ---------- empty states ---------- */
.empty {
  text-align: center; padding: 26px 16px; color: var(--muted); font-size: 14px;
  border: 1px dashed var(--line-strong); border-radius: 16px; background: var(--orange-50);
}
.empty strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 2px; }
.empty .btn { margin-top: 12px; }
.settled {
  display: flex; align-items: center; gap: 12px; padding: 16px; border-radius: 16px;
  background: var(--orange-50); border: 1px solid var(--orange-100); color: var(--ink-2); font-size: 14px;
}
.settled .check {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--orange-500), var(--orange-700)); color: #fff;
}

/* ---------- form fields ---------- */
:where(input:not([type=radio]):not([type=checkbox]), select) {
  height: 44px; padding: 0 14px; width: 100%;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  transition: border-color .15s, box-shadow .15s;
}
select {
  appearance: none; -webkit-appearance: none; padding-right: 38px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%23EA580C' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 8 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px;
}
:where(input, select):focus { outline: none; border-color: var(--orange-400); box-shadow: var(--focus); }
input::placeholder { color: var(--placeholder); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--ink-2); letter-spacing: .01em; }
.field em { font-style: normal; color: var(--muted); font-weight: 500; }

/* ---------- dialogs ---------- */
.sheet {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0;
  border: 0; border-radius: 26px; background: var(--card); color: var(--ink); box-shadow: var(--shadow-lg);
}
.sheet-sm { width: min(460px, calc(100vw - 24px)); }
.sheet::backdrop { background: rgba(38, 20, 10, .42); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.sheet[open] { animation: rise .28s cubic-bezier(.2,.9,.25,1); }
.sheet[open]::backdrop { animation: fade .25s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(.98); } }
@keyframes fade { from { opacity: 0; } }
.sheet form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 22px 6px; }
.sheet-head h3 { margin: 0; font-family: var(--display); font-weight: 600; font-size: 22px; }
.sheet-body { padding: 10px 22px 8px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.sheet-foot {
  display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px 18px;
  border-top: 1px solid var(--line); background: linear-gradient(180deg, var(--card), var(--orange-50));
  border-radius: 0 0 26px 26px;
}

.amount-field {
  display: flex; align-items: center; gap: 6px; padding: 12px 18px; border-radius: 18px;
  background: var(--orange-50); border: 1px solid var(--orange-100);
  transition: box-shadow .15s, border-color .15s;
}
.amount-field:focus-within { border-color: var(--orange-400); box-shadow: var(--focus); }
.amount-field .currency { font-family: var(--display); font-size: 32px; color: var(--orange-600); }
.sheet .amount-field input {
  height: 52px; border: 0; background: transparent; padding: 0; box-shadow: none;
  font-family: var(--display); font-size: 40px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums;
}

.segmented {
  display: grid; grid-template-columns: repeat(3, 1fr); padding: 4px; gap: 4px;
  background: var(--orange-50); border: 1px solid var(--orange-100); border-radius: 14px;
}
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.segmented span {
  display: block; text-align: center; padding: 8px 6px; border-radius: 10px;
  font-size: 13px; font-weight: 600; color: var(--ink-2); transition: background .15s, color .15s, box-shadow .15s;
}
.segmented input:checked + span { background: var(--surface); color: var(--orange-700); box-shadow: var(--shadow-sm), 0 0 0 1px var(--orange-100); }
.segmented input:focus-visible + span { box-shadow: var(--focus); }

.split-rows { display: flex; flex-direction: column; gap: 6px; }
.split-rows li {
  display: grid; grid-template-columns: auto minmax(0, 1fr) 132px; align-items: center; gap: 12px;
  padding: 6px 8px 6px 6px; border-radius: 14px; border: 1px solid var(--line); transition: background .15s, border-color .15s;
}
.split-rows li.on { border-color: var(--orange-200); background: var(--orange-50); }
.split-rows li.off { opacity: .6; }
.split-rows .name { font-weight: 600; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.split-rows .name small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.split-rows .share { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--ink-2); }
.split-rows .unit-input { position: relative; }
.split-rows .unit-input input { height: 38px; text-align: right; padding: 0 12px 0 26px; font-variant-numeric: tabular-nums; }
.split-rows .unit-input.pct input { padding: 0 28px 0 12px; }
.split-rows .unit-input i { position: absolute; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: 13px; pointer-events: none; }
.split-rows .unit-input:not(.pct) i { left: 11px; }
.split-rows .unit-input.pct i { right: 11px; }
.toggle { position: relative; width: 38px; height: 38px; }
.toggle input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.toggle .avatar { transition: box-shadow .15s; }
.toggle input:checked + .avatar { box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--orange-500); }
.toggle input:not(:checked) + .avatar { filter: grayscale(1); opacity: .5; }
.toggle input:focus-visible + .avatar { box-shadow: var(--focus); }

.split-meter { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.split-meter .track { flex: 1; height: 6px; border-radius: 99px; background: var(--orange-50); overflow: hidden; border: 1px solid var(--orange-100); }
.split-meter .track i { display: block; height: 100%; background: linear-gradient(90deg, var(--orange-400), var(--orange-600)); border-radius: 99px; transition: width .25s; }
.split-meter .track i.over { background: var(--owe); }
.split-meter b { color: var(--ink); font-variant-numeric: tabular-nums; }
.split-meter .ok { color: var(--orange-600); font-weight: 600; }

.form-error { margin: 0; min-height: 0; color: var(--orange-700); font-size: 13px; font-weight: 600; }
.form-error:empty { display: none; }
.form-error::before { content: "⚠ "; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .field-row { grid-template-columns: 1fr; } }

.pay-route { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: end; }
.pay-arrow { height: 44px; display: grid; place-items: center; color: var(--orange-500); }

/* ---------- groups ---------- */
.btn-groups {
  background: var(--surface); color: var(--ink); border-color: var(--line-strong); padding: 0 8px 0 14px; max-width: 300px;
  box-shadow: var(--shadow-sm);
}
.btn-groups:hover { border-color: var(--orange-200); background: var(--orange-50); }
.btn-groups > svg { color: var(--orange-600); }
.groups-label { color: var(--muted); font-weight: 600; }
.groups-current { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-weight: 700; }
.groups-count {
  min-width: 24px; height: 24px; padding: 0 7px; border-radius: 99px; display: grid; place-items: center;
  background: var(--orange-100); color: var(--orange-700); font-size: 12px; font-weight: 700;
}

.sheet-frame { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.sheet-head .card-sub { margin-top: 2px; }
.group-list { display: flex; flex-direction: column; gap: 8px; }
.group-row {
  display: flex; align-items: center; gap: 4px; padding: 4px 6px 4px 4px;
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); transition: border-color .15s, background .15s;
}
.group-row:hover { border-color: var(--orange-200); }
.group-row.active { border-color: var(--orange-200); background: var(--orange-50); }
.group-pick {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; padding: 8px; border: 0; border-radius: 12px;
  background: transparent; text-align: left; cursor: pointer;
}
div.group-pick { cursor: default; }
.group-pick:focus-visible { outline: none; box-shadow: var(--focus); }
.group-badge {
  width: 42px; height: 42px; border-radius: 13px; flex: none; display: grid; place-items: center;
  font-weight: 700; font-size: 14px; box-shadow: inset 0 0 0 1px rgba(0,0,0,.04);
}
.group-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.group-info strong { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-info small { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.group-info .group-rename { height: 32px; padding: 0 10px; margin: -2px 0 2px; font-weight: 600; }
.pill {
  flex: none; font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--orange-700); background: var(--surface); border: 1px solid var(--orange-200); padding: 3px 9px; border-radius: 99px;
}
.group-tools { display: flex; flex: none; }
.sheet form.new-group { flex-direction: row; gap: 8px; width: 100%; max-height: none; }
.new-group input { flex: 1; min-width: 0; }

/* ---------- account ---------- */
.btn-account { background: var(--surface); color: var(--ink); border-color: var(--line-strong); padding: 0 14px 0 10px; max-width: 230px; box-shadow: var(--shadow-sm); }
.btn-account:hover { border-color: var(--orange-200); background: var(--orange-50); }
.btn-account .account-icon { color: var(--orange-600); }
.account-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.account-initial {
  display: none; width: 26px; height: 26px; border-radius: 50%; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--orange-500), var(--orange-700)); color: #fff; font-size: 12px; font-weight: 700;
}
.btn-account.signed-in { padding-left: 6px; }
.btn-account.signed-in .account-initial { display: grid; }
.btn-account.signed-in .account-icon { display: none; }
.btn-account.signed-in .account-label { font-weight: 600; font-size: 13px; color: var(--ink-2); }

.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border-radius: 14px; background: var(--orange-50); border: 1px solid var(--orange-100); }
.auth-tabs button {
  border: 0; background: transparent; padding: 9px 6px; border-radius: 10px; font-weight: 600; font-size: 13px; color: var(--ink-2); cursor: pointer;
}
.auth-tabs button[aria-selected="true"] { background: var(--surface); color: var(--orange-700); box-shadow: var(--shadow-sm), 0 0 0 1px var(--orange-100); }
.auth-tabs button:focus-visible { outline: none; box-shadow: var(--focus); }
.auth-note { margin: 0; font-size: 12.5px; color: var(--muted); }
.sheet form.pw-form { gap: 12px; max-height: none; padding-top: 4px; }
.sheet form.pw-form .btn { align-self: flex-start; }

/* ---------- categories ---------- */
.cat-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cat-chip {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px 0 10px; border-radius: 999px;
  border: 1px solid var(--line-strong); background: var(--surface); font-size: 13px; font-weight: 600; color: var(--ink-2); cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.cat-chip i { width: 9px; height: 9px; border-radius: 3px; flex: none; }
.cat-chip:hover { border-color: var(--orange-200); }
.cat-chip[aria-checked="true"] { background: var(--orange-50); border-color: var(--orange-400); color: var(--ink); box-shadow: 0 0 0 1px var(--orange-400) inset; }
.cat-chip:focus-visible { outline: none; box-shadow: var(--focus); }
#ex-cat-custom { margin-top: 8px; }
.cat-dot { display: inline-block; width: 7px; height: 7px; border-radius: 2px; margin-right: 6px; vertical-align: 1px; }

/* ---------- spending chart ---------- */
.segmented-sm { grid-template-columns: repeat(2, auto); padding: 3px; border-radius: 12px; flex: none; }
.segmented-sm span { padding: 6px 12px; font-size: 12.5px; border-radius: 9px; white-space: nowrap; }
.spend-chart { min-height: 120px; }
.chart-wrap { position: relative; }
/* opt out of the global icon rule (svg: 18px, outlined) */
.chart-svg { display: block; overflow: visible; width: 100%; height: auto; fill: currentColor; stroke: none; stroke-width: 0; }
.chart-grid { stroke: var(--line); stroke-width: 1; }
.chart-baseline { stroke: var(--line-strong); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart-col { transition: opacity .15s; }
.chart-col.dim { opacity: .35; }
.chart-hit { fill: transparent; cursor: default; outline: none; }
.chart-hit.selectable { cursor: pointer; }
.link-btn {
  margin-top: 6px; padding: 4px 0; border: 0; background: none; cursor: pointer;
  color: var(--orange-700); font-weight: 700; font-size: 13px;
}
.link-btn:hover { text-decoration: underline; }
.link-btn:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 6px; }
.chart-hit:focus-visible { stroke: var(--orange-400); stroke-width: 2; }
.chart-tooltip {
  position: absolute; z-index: 2; min-width: 150px; padding: 10px 12px; border-radius: 12px; pointer-events: none;
  background: var(--surface); border: 1px solid var(--line-strong); box-shadow: var(--shadow); font-size: 12.5px;
}
.tt-head { font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.tt-row { display: flex; align-items: center; gap: 8px; line-height: 1.7; }
.tt-row strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.tt-row span { color: var(--muted); }
.tt-total { border-bottom: 1px solid var(--line); margin-bottom: 4px; padding-bottom: 4px; }
.tt-key { width: 12px; height: 2px; border-radius: 1px; flex: none; }
.chart-legend { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 6px 16px; margin-top: 14px; }
.chart-legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
.legend-key { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-name { color: var(--ink-2); font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-value { margin-left: auto; color: var(--ink); font-weight: 600; }
.legend-share { color: var(--muted); font-size: 12px; min-width: 34px; text-align: right; }
.donut-layout { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 18px 24px; }
.donut-wrap { position: relative; width: 176px; flex: none; }
.donut-svg { display: block; width: 100%; height: auto; overflow: visible; fill: currentColor; stroke: none; }
.donut-slice { stroke: var(--card); stroke-width: 2px; stroke-linejoin: round; transition: opacity .15s; outline: none; cursor: default; }
.donut-slice.dim { opacity: .35; }
.donut-slice:focus-visible { stroke: var(--orange-400); stroke-width: 3px; }
.donut-total { fill: var(--ink); font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.donut-caption { fill: var(--muted); font-size: 11px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; }
.donut-tooltip { min-width: 120px; white-space: nowrap; }
.tt-sub { color: var(--muted); font-size: 11.5px; white-space: normal; max-width: 180px; }
/* sits beside the donut when there's room for full names, otherwise wraps below it */
.donut-legend { flex: 1 1 240px; min-width: 0; display: flex; flex-direction: column; gap: 8px; }
.donut-legend li { display: flex; align-items: center; gap: 8px; font-size: 13px; min-width: 0; }
@media (max-width: 420px) { .donut-layout { flex-direction: column; align-items: stretch; } .donut-wrap { align-self: center; } }

.chart-table { margin-top: 12px; font-size: 13px; }
.chart-table summary { cursor: pointer; color: var(--orange-700); font-weight: 600; font-size: 12.5px; width: max-content; }
.table-scroll { overflow-x: auto; margin-top: 8px; }
.chart-table table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.chart-table th, .chart-table td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
.chart-table th:first-child { text-align: left; }
.chart-table thead th { color: var(--muted); font-weight: 600; font-size: 12px; }
.chart-table tfoot th, .chart-table tfoot td { font-weight: 700; border-bottom: 0; }

/* ---------- category icons ---------- */
.cat-icon { width: 14px; height: 14px; stroke-width: 1.8; vertical-align: -2px; margin-right: 5px; }
.cat-chip .cat-icon { width: 15px; height: 15px; margin: 0; }

/* ---------- avatars: photo / emoji ---------- */
.avatar.photo { padding: 0; overflow: hidden; background: var(--orange-100); }
.avatar.photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar.emoji { background: var(--orange-50); box-shadow: inset 0 0 0 1px var(--orange-100); font-size: 20px; line-height: 1; }
.avatar-sm.emoji { font-size: 15px; }
.member-pick {
  display: inline-flex; align-items: center; gap: 8px; border: 0; background: none; padding: 0; margin: 0;
  font: inherit; font-weight: 600; color: inherit; cursor: pointer; border-radius: 999px;
}
.member-pick:hover span { color: var(--orange-700); }
.member-pick:focus-visible { outline: none; box-shadow: var(--focus); }

.person-top { display: flex; align-items: flex-end; gap: 16px; }
.person-top .field { flex: 1; }
.person-preview .avatar { width: 64px; height: 64px; font-size: 22px; }
.person-preview .avatar.emoji { font-size: 34px; }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; }
.emoji-btn {
  height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-size: 20px; cursor: pointer;
  transition: transform .12s, border-color .15s, background .15s;
}
.emoji-btn:hover { transform: scale(1.08); border-color: var(--orange-200); }
.emoji-btn[aria-pressed="true"] { border-color: var(--orange-500); background: var(--orange-50); box-shadow: 0 0 0 1px var(--orange-500) inset; }
.emoji-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.emoji-btn.initials { font-size: 13px; font-weight: 700; color: var(--ink-2); }
.photo-btn { position: relative; align-self: flex-start; margin-top: 10px; }
.photo-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.photo-btn:focus-within { box-shadow: var(--focus); }

/* ---------- theme ---------- */
.btn-theme { width: 42px; height: 42px; color: var(--ink-2); }
.btn-theme .icon-sun { display: none; }
.btn-theme.is-dark .icon-sun { display: block; }
.btn-theme.is-dark .icon-moon { display: none; }
.foot .theme-choice { display: inline-grid; grid-template-columns: repeat(3, auto); margin-bottom: 12px; }
.foot p { margin: 0; }

/* ---------- motion (all switched off by prefers-reduced-motion below) ---------- */
@keyframes row-in { from { opacity: 0; transform: translateY(-8px); } }
@keyframes row-out { from { max-height: 90px; } to { opacity: 0; transform: translateX(14px); max-height: 0; padding-top: 0; padding-bottom: 0; } }
@keyframes chip-out { to { opacity: 0; transform: scale(.8); } }
.activity li.enter, .member-list li.enter { animation: row-in .38s cubic-bezier(.2, .8, .2, 1); }
.activity li.leaving { overflow: hidden; animation: row-out .22s ease forwards; }
.member-list li.leaving { animation: chip-out .2s ease forwards; }

@keyframes col-grow { from { transform: scaleY(0); } }
.chart-svg.enter .chart-col { transform-box: fill-box; transform-origin: 50% 100%; animation: col-grow .7s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes slice-in { from { opacity: 0; transform: scale(.82) rotate(-14deg); } }
.donut-svg.enter .donut-slice { transform-box: view-box; transform-origin: 50% 50%; animation: slice-in .6s cubic-bezier(.2, .8, .2, 1) both; }

@keyframes pop { 0% { transform: scale(.4); } 60% { transform: scale(1.2); } 100% { transform: scale(1); } }
@keyframes ring { from { box-shadow: 0 0 0 0 rgba(249, 115, 22, .45); } to { box-shadow: 0 0 0 18px rgba(249, 115, 22, 0); } }
.settled.pop { animation: ring 1.1s ease-out; }
.settled.pop .check { animation: pop .6s cubic-bezier(.2, 1.6, .4, 1); }
.confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 100; }

/* ---------- toasts ---------- */
.toasts { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; width: max-content; max-width: calc(100vw - 32px); }
.toast {
  display: flex; align-items: center; gap: 14px; padding: 10px 10px 10px 18px; border-radius: 999px;
  background: var(--toast-bg); color: #fff; font-size: 14px; box-shadow: var(--shadow-lg);
  animation: rise .25s cubic-bezier(.2,.9,.25,1);
}
.toast.plain { padding-right: 18px; }
.toast button { border: 0; background: rgba(255,255,255,.12); color: var(--orange-200); font-weight: 700; padding: 6px 12px; border-radius: 999px; cursor: pointer; }
.toast button:hover { background: rgba(255,255,255,.2); }

.foot { margin-top: 36px; text-align: center; color: var(--muted); font-size: 13px; }
.foot a { color: var(--orange-600); font-weight: 600; text-decoration: none; margin-left: 6px; }
.foot a:hover { text-decoration: underline; }

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .hero { grid-template-columns: 1fr; }
  .stats { flex-wrap: wrap; }
  .grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .topbar-inner { padding: 12px 16px; }
  .page { padding: 18px 16px 40px; }
  #btn-demo { display: none; }
  .topbar-actions .btn:not(.btn-groups) span { display: none; }
  .topbar-actions .btn:not(.btn-groups) { width: 42px; padding: 0; }
  .btn-groups { max-width: 190px; padding-left: 12px; }
  .groups-label { display: none; }
  .btn-theme { display: none; } /* the footer has the theme choice on phones */
  .topbar-actions .btn-account .account-icon { display: block; }
  .topbar-actions .btn-account.signed-in .account-initial { display: grid; }
  .topbar-actions .btn-account.signed-in .account-icon { display: none; }
  .card-head:has(.segmented-sm) { flex-wrap: wrap; }
  .hero { padding: 24px 20px; border-radius: 22px; }
  .stats { display: grid; grid-template-columns: repeat(3, 1fr); }
  .stat { min-width: 0; padding: 12px 14px; }
  .stat dd { font-size: 17px; }
  .card { padding: 18px 16px 14px; }
  .legend { display: none; }
  .balance-list li { grid-template-columns: auto minmax(0, 1fr) auto; }
  .balance-list .bar { grid-column: 1 / -1; grid-row: 2; }
  .split-rows li { grid-template-columns: auto minmax(0, 1fr) 110px; }
  .transfer-list li { flex-wrap: wrap; }
  .transfer-list li .btn { width: 100%; }
}

@media (max-width: 480px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .stat:last-child { grid-column: 1 / -1; }
  .brand-name { display: none; }
  .topbar-inner { gap: 10px; }
  .topbar-actions { gap: 6px; }
  .btn-groups { max-width: 148px; }
}

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