:root {
  --bg: #f4f6f8; --card: #ffffff; --text: #15191e; --muted: #5b6672; --line: #e1e5ea; --soft: #eef1f4;
  --brand: #0f766e; --brand-2: #0b5e57; --on-brand: #ffffff; --brand-soft: #ccfbf1;
  --pos: #08774f; --neg: #c2410c; --warn: #9a5b00; --danger: #b42318;
  --radius: 14px; --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  color-scheme: light;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1117; --card: #161b22; --text: #e6edf3; --muted: #9ba7b4; --line: #2b323b; --soft: #1f262e;
    --brand: #2dd4bf; --brand-2: #5eead4; --on-brand: #042f2c; --brand-soft: #134e4a;
    --pos: #4ade80; --neg: #fb923c; --warn: #facc15; --danger: #f87171; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0d1117; --card: #161b22; --text: #e6edf3; --muted: #9ba7b4; --line: #2b323b; --soft: #1f262e;
  --brand: #2dd4bf; --brand-2: #5eead4; --on-brand: #042f2c; --brand-soft: #134e4a;
  --pos: #4ade80; --neg: #fb923c; --warn: #facc15; --danger: #f87171; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45; }
body.locked { overflow: hidden; }
a { color: var(--brand); }
h1 { font-size: 1.45rem; line-height: 1.2; margin: 0; overflow-wrap: anywhere; }
h2 { font-size: 1.05rem; margin: 0 0 .7rem; }
p { margin: .3rem 0; }
small, .small { font-size: .85rem; }
.muted, .main small { color: var(--muted); }
.pos, .ok { color: var(--pos); } .neg { color: var(--neg); } .warn { color: var(--warn); }
.center { text-align: center; justify-content: center; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }

/* shell */
#top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 10px; padding: max(8px, env(safe-area-inset-top)) max(16px, calc((100% - 760px) / 2)) 8px; background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; margin-right: auto; color: var(--text); font-weight: 700; font-size: 1.1rem; text-decoration: none; }
.status { font-size: .8rem; color: var(--muted); }
.status.off { color: var(--neg); font-weight: 600; }
.iconbtn { display: grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; color: var(--text); }
.iconbtn:hover { background: var(--soft); }
#view { max-width: 760px; margin: 0 auto; padding: 8px 16px calc(150px + env(safe-area-inset-bottom)); }
#tabs { position: fixed; inset: auto 0 0; z-index: 10; display: flex; justify-content: center; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
#tabs a { position: relative; flex: 0 1 150px; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 6px; color: var(--muted); font-size: .75rem; text-decoration: none; }
#tabs a.on { color: var(--brand); font-weight: 700; }
#tabs .badge { position: absolute; top: 3px; left: calc(50% + 6px); }

/* building blocks */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 0 0 12px; box-shadow: var(--shadow); }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 20px 0 10px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.head .btns, .debts .btns { margin: 0; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input, .inline select { flex: 1; min-width: 0; }
form.inline { margin-top: 12px; }
.big { font-size: 1.15rem; font-weight: 600; }

button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); font: inherit; font-size: .95rem; text-decoration: none; white-space: nowrap; cursor: pointer; }
button:hover, .btn:hover { background: var(--soft); }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); font-weight: 600; }
.primary:hover { background: var(--brand-2); }
.danger { color: var(--danger); }
.ghost { border-color: transparent; background: transparent; }
.sm { min-height: 32px; padding: 4px 10px; font-size: .85rem; }
.link { min-height: 0; padding: 6px 0; border: 0; background: none; color: var(--brand); }
.link:hover { background: none; text-decoration: underline; }

input, select, textarea { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); font: inherit; }
select.auto { width: auto; }
textarea { resize: vertical; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; }
label { display: block; margin: 0 0 12px; font-size: .9rem; font-weight: 500; }
label > input, label > select, label > textarea, label > .inline { margin-top: 4px; }
fieldset { margin: 0 0 14px; padding: 0; border: 0; min-width: 0; }
legend { margin-bottom: 6px; padding: 0; font-size: .9rem; font-weight: 700; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.span2 { grid-column: 1 / -1; }
.num { flex: none; width: 104px; text-align: right; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }
.err { min-height: 1.2em; color: var(--danger); font-weight: 600; }

/* lists */
.list { margin: 0 0 12px; padding: 0; list-style: none; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list.flat { border: 0; border-radius: 0; box-shadow: none; background: none; }
.list > li + li { border-top: 1px solid var(--line); }
.list > li.month { padding: 12px 16px 6px; background: var(--soft); color: var(--muted); font-size: .78rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.list > li.new { background: color-mix(in srgb, var(--brand-soft) 50%, transparent); }
.row-link { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 60px; padding: 10px 16px; border: 0; border-radius: 0; background: none; color: inherit; font: inherit; text-align: left; text-decoration: none; white-space: normal; }
a.row-link:hover, button.row-link:hover { background: var(--soft); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.main > b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.amt { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; font-size: .78rem; text-align: right; }
.amt > span { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.25; }
.amt b { font-size: .95rem; }
.amt.left, .amt.left > span { align-items: flex-start; text-align: left; }
.date { display: flex; flex-direction: column; align-items: center; flex: none; width: 32px; line-height: 1.1; color: var(--muted); }
.date small { font-size: .68rem; text-transform: uppercase; }
.date b { color: var(--text); font-size: 1.05rem; }
.emoji { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 12px; background: var(--soft); font-size: 1.25rem; }
.emoji.big { width: 56px; height: 56px; border-radius: 16px; font-size: 1.8rem; }
.av { display: inline-grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 50%; color: #fff; font-size: .72rem; font-weight: 700; }
.av.more { background: var(--soft); color: var(--muted); }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--neg); color: #fff; font-size: .7rem; font-weight: 700; }
.plain { margin: 0; padding: 0; list-style: none; }
.plain > li { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.plain > li + li { border-top: 1px solid var(--line); }
.rows > li { padding: 6px 0; }
.rows output { width: 92px; flex: none; color: var(--muted); font-size: .9rem; font-variant-numeric: tabular-nums; text-align: right; }
.unit { width: 1.4em; color: var(--muted); }
.check { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 1rem; font-weight: 400; }
.check input, .switch input { width: 20px; height: 20px; accent-color: var(--brand); }
.empty { padding: 24px 12px; color: var(--muted); text-align: center; }
.more { display: block; margin: 0 auto 12px; }
details > summary { padding: 8px 0; font-weight: 600; cursor: pointer; }
details.arch { margin-top: 12px; }

/* summary & group header */
.summary .sumrow { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.summary .sumrow + .sumrow { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.summary small { display: block; color: var(--muted); font-size: .78rem; }
.summary b { font-size: 1.15rem; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.ident { display: flex; align-items: center; gap: 14px; min-width: 0; }
.ident > div { min-width: 0; }
.avs { display: flex; flex-wrap: wrap; margin: 12px 0 4px; }
.avs .av { margin-right: -6px; border: 2px solid var(--card); }
.mybal { margin-top: 8px; }
.budget { margin-top: 10px; }
.track { display: block; height: 8px; overflow: hidden; border-radius: 4px; background: var(--soft); }
.track > span { display: block; height: 100%; border-radius: 4px; background: var(--brand); }
.budget.near .track > span { background: var(--warn); }
.budget.over .track > span { background: var(--danger); }
.tabs2 { display: flex; gap: 4px; margin: 4px 0 12px; overflow-x: auto; scrollbar-width: none; }
.tabs2 a { padding: 8px 14px; border-radius: 999px; color: var(--muted); font-size: .9rem; font-weight: 600; text-decoration: none; white-space: nowrap; }
.tabs2 a.on { background: var(--brand); color: var(--on-brand); }
.back { display: inline-flex; align-items: center; gap: 2px; margin: 10px 0; font-size: .9rem; font-weight: 600; text-decoration: none; }
.fab { position: fixed; right: max(16px, calc((100% - 760px) / 2 + 16px)); bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 9; width: 56px; height: 56px; padding: 0; border: 0; border-radius: 50%; background: var(--brand); color: var(--on-brand); box-shadow: 0 6px 16px rgb(0 0 0 / 25%); }
.fab:hover { background: var(--brand-2); }
.fab svg { width: 26px; height: 26px; }

/* expenses tab */
.filters { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; margin-bottom: 10px; }
.filters select { width: auto; max-width: 170px; }
.search { position: relative; margin: 0; }
.search svg { position: absolute; top: 50%; left: 12px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search input { margin: 0; padding-left: 40px; }
.search.big input { min-height: 50px; font-size: 1.05rem; }

/* balances tab */
.bals .meter { flex: none; width: 28%; height: 8px; overflow: hidden; border-radius: 4px; background: var(--soft); }
.meter > span { display: block; height: 100%; background: var(--pos); }
.meter.neg > span { background: var(--neg); }
.debts > li { justify-content: space-between; flex-wrap: wrap; padding: 12px 0; }
.debts .main { flex-direction: row; align-items: center; gap: 10px; min-width: 180px; }
.tip { margin-top: 12px; padding: 10px 12px; border-radius: 10px; background: var(--soft); }
.switch { display: inline-flex; align-items: center; gap: 8px; margin: 0; }

/* stats tab */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.kpis > div { min-width: 0; padding: 10px 12px; border-radius: 12px; background: var(--soft); }
.kpis small { display: block; overflow: hidden; color: var(--muted); font-size: .78rem; text-overflow: ellipsis; white-space: nowrap; }
.kpis b { display: block; overflow: hidden; font-size: 1.05rem; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
.hbars { display: grid; grid-template-columns: minmax(0, 11em) 1fr auto auto; gap: 8px 10px; align-items: center; margin: 0; padding: 0; list-style: none; }
.hbars li, .people li { display: contents; }
.hbars b { font-size: .9rem; font-variant-numeric: tabular-nums; text-align: right; }
.hbars small { width: 3em; color: var(--muted); text-align: right; }
.vbars { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 8px; }
.vbars > div { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 4px; }
.vbars .col { width: 100%; max-width: 44px; border-radius: 6px 6px 2px 2px; background: var(--brand); }
.vbars small { color: var(--muted); font-size: .7rem; }
.people { display: grid; grid-template-columns: minmax(0, 8em) 1fr auto; gap: 6px 10px; align-items: center; margin: 0; padding: 0; list-style: none; }
.people li > b { grid-row: span 2; overflow: hidden; text-overflow: ellipsis; }
.people .track.share > span, .key.share { background: var(--muted); }
.people small { font-variant-numeric: tabular-nums; text-align: right; }
.legend { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: .8rem; }
.key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--brand); }
.key.share { margin-left: 8px; }

/* expense detail */
.xdetail .amount { margin: 2px 0; font-size: 1.8rem; font-variant-numeric: tabular-nums; font-weight: 700; }
.xdetail.deleted { opacity: .75; }
.split { margin: 12px 0; }
.payline { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 12px 0; }
.banner { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin: 12px 0; padding: 10px 12px; border-radius: 10px; background: color-mix(in srgb, var(--warn) 16%, transparent); }
.note { padding: 10px 12px; border-radius: 10px; background: var(--soft); white-space: pre-wrap; overflow-wrap: anywhere; }
.receipt { display: block; max-width: 100%; max-height: 420px; margin-top: 12px; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.r { font-variant-numeric: tabular-nums; text-align: right; }
.comments li { align-items: flex-start; }
.comments li > div { flex: 1; min-width: 0; }
.comments p { overflow-wrap: anywhere; white-space: pre-wrap; }
.hist li { display: block; font-size: .9rem; }

/* settings, join, account */
.members li.gone { opacity: .6; }
.emojis { display: flex; flex-wrap: wrap; gap: 6px; }
.emojis label { margin: 0; }
.emojis input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.emojis span { display: grid; place-items: center; width: 44px; height: 44px; border: 2px solid var(--line); border-radius: 12px; font-size: 1.3rem; cursor: pointer; }
.emojis input:checked + span { border-color: var(--brand); background: var(--brand-soft); }
.emojis input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); }
.choices { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.welcome h2 { font-size: 1.2rem; }
.keys { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.keys dt { padding: 0 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--soft); font-family: ui-monospace, monospace; text-align: center; }
.keys dd { margin: 0; }

/* dialogs */
#modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
#modal[hidden] { display: none; }
.backdrop { position: absolute; inset: 0; background: rgb(0 0 0 / 45%); }
.dialog { position: relative; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; padding: 0 16px calc(16px + env(safe-area-inset-bottom)); border-radius: 18px 18px 0 0; background: var(--card); box-shadow: 0 -8px 30px rgb(0 0 0 / 25%); }
@media (min-width: 640px) { #modal { align-items: center; } .dialog { max-height: 88vh; border-radius: 18px; } }
.sheet > header { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; padding: 14px 0 10px; border-bottom: 1px solid var(--line); background: var(--card); }
.sheet > header h2 { margin: 0; }
.sheet > footer { position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; padding: 12px 0 calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--card); }
.seg { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; padding: 4px; border-radius: 12px; background: var(--soft); }
.seg button { flex: 1; min-width: 50px; min-height: 36px; padding: 4px 8px; border: 0; background: transparent; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 0; }
.chip { min-height: 30px; padding: 2px 10px; border-radius: 999px; font-size: .85rem; }
.chip.on { border-color: var(--brand); background: var(--brand-soft); color: var(--text); }
span.chip { display: inline-flex; align-items: center; border: 1px solid var(--brand); }
.chip .x { min-height: 0; padding: 0 0 0 6px; border: 0; background: none; font-size: 1rem; }
.items > li { display: block; padding: 10px 0; }
.fx { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; padding: 8px 10px; border-radius: 10px; background: var(--soft); }
.fx label { display: flex; align-items: center; gap: 6px; margin: 0; }
.fx input { width: 110px; min-height: 36px; margin: 0; }
.rcpt { display: flex; align-items: center; gap: 12px; }
.rcpt img { width: 72px; height: 72px; border: 1px solid var(--line); border-radius: 8px; object-fit: cover; }
.payflow { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: end; }
.payflow .arrow { padding-bottom: 22px; color: var(--muted); font-size: 1.3rem; }

#toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 30; display: flex; align-items: center; gap: 12px; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: #1f2937; color: #fff; box-shadow: 0 8px 24px rgb(0 0 0 / 30%); opacity: 0; pointer-events: none; transform: translate(-50%, 16px); transition: opacity .2s, transform .2s; }
#toast.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
#toast button { min-height: 32px; padding: 4px 8px; border: 0; background: transparent; color: #5eead4; font-weight: 700; }

.report { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
.report h2 { margin-top: 22px; }

@media (max-width: 560px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .filters .search { grid-column: 1 / -1; }
  .filters select { width: 100%; max-width: none; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .summary b { font-size: 1rem; }
  .hbars { grid-template-columns: minmax(0, 8em) 1fr auto; }
  .hbars small { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; scroll-behavior: auto !important; } }
@media print {
  #top, #tabs, #toast, .fab, .noprint { display: none !important; }
  body { background: #fff; color: #000; }
  #view { max-width: none; padding: 0; }
  .report { padding: 0; border: 0; }
  .pos, .neg { color: #000; }
}
