:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f4f5);
  --card: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1f2a30);
  --muted: var(--tg-theme-hint-color, #7b868c);
  --line: rgba(127, 140, 150, .18);
  --accent: #1aa37a;
  --accent-soft: rgba(26, 163, 122, .12);
  --warn: #e8590c;
  --warn-soft: rgba(232, 89, 12, .12);
  --danger: #d6336c;
  --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* header + tabs */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 6px;
  padding: 10px 12px; background: var(--card); border-bottom: 1px solid var(--line); min-height: 54px; }
.top-title { flex: 1; min-width: 0; }
#title { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { border: 0; background: none; font-size: 26px; line-height: 1; width: 36px; height: 36px; border-radius: 50%; }
.icon-btn:active { background: var(--line); }
main { padding: 12px 12px calc(90px + var(--safe-b)); max-width: 720px; margin: 0 auto; }
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--card);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tabs button { flex: 1; border: 0; background: none; padding: 8px 0 10px; font-size: 20px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tabs button span { font-size: 11.5px; font-weight: 600; }
.tabs button.active { color: var(--accent); }

/* cards and rows */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 10px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.section-title { font-size: 12.5px; font-weight: 700; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; margin: 18px 4px 8px; }
.btn { border: 0; border-radius: 12px; padding: 11px 16px; font-weight: 650; background: var(--accent); color: #fff; }
.btn:disabled { opacity: .45; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--accent); padding: 8px 10px; }
.btn.danger { background: rgba(214, 51, 108, .12); color: var(--danger); }
.btn.block { width: 100%; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 650;
  padding: 3px 9px; border-radius: 999px; background: var(--line); color: var(--muted); border: 0; }
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
input[type=text], input[type=number], input[type=search], select {
  width: 100%; padding: 11px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
.banner { border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; font-size: 13.5px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.ok { background: var(--accent-soft); color: var(--accent); }

/* avatars */
.av { --c: #1aa37a; width: 34px; height: 34px; flex: 0 0 34px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; color: #fff; background: var(--c); border: 0; padding: 0; position: relative;
  transition: transform .08s; }
.av.off { background: transparent; color: var(--c); box-shadow: inset 0 0 0 1.5px var(--c); opacity: .45; }
.av:active { transform: scale(.9); }
.av.sm { width: 26px; height: 26px; flex-basis: 26px; font-size: 11px; }

/* bill summary */
.owes { display: flex; gap: 8px; overflow-x: auto; padding: 2px 2px 6px; margin: 0 -2px 6px; scrollbar-width: none; }
.owes::-webkit-scrollbar { display: none; }
.owe { flex: 0 0 auto; min-width: 92px; background: var(--card); border-radius: var(--radius); padding: 10px 12px;
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px; border: 0; text-align: left; }
.owe.sel { box-shadow: inset 0 0 0 2px var(--accent); }
.owe .n { font-size: 12.5px; color: var(--muted); font-weight: 600; }
.owe .a { font-weight: 750; font-size: 15.5px; }
.filters { display: flex; gap: 6px; overflow-x: auto; margin: 6px 0 10px; scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.filters .pill { padding: 7px 12px; font-size: 13px; flex: 0 0 auto; }
.filters .pill.on { background: var(--text); color: var(--card); }

/* items */
.item { background: var(--card); border-radius: var(--radius); padding: 12px; margin-bottom: 8px; }
.item.need { box-shadow: inset 3px 0 0 var(--warn); }
.item .name { font-weight: 600; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.item .meta { display: flex; align-items: center; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.item .price { font-weight: 700; text-align: right; }
.who { display: flex; gap: 7px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.who .quick { margin-left: auto; display: flex; gap: 2px; }
.who .quick button { border: 0; background: none; color: var(--accent); font-weight: 650; font-size: 13px; padding: 6px 7px; }

/* bottom action bar on a bill */
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: var(--card);
  border-top: 1px solid var(--line); padding: 10px 12px calc(10px + var(--safe-b)); }
.actionbar .inner { max-width: 720px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }

/* bottom sheet */
#sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
#sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; background: var(--card); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(18px + var(--safe-b)); max-height: 88vh; overflow-y: auto; max-width: 720px; margin: 0 auto; }
#sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
#sheet h3 { margin: 0 0 12px; font-size: 18px; }
.list-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list-row:last-child { border-bottom: 0; }
#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + var(--safe-b)); z-index: 60;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; max-width: 90vw; text-align: center; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 40px; margin-bottom: 8px; }
.switch { appearance: none; width: 44px; height: 26px; border-radius: 13px; background: var(--line); position: relative; flex: 0 0 44px; margin: 0; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: left .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch:checked { background: var(--accent); }
.switch:checked::after { left: 21px; }
