:root {
  --bg: #f6f5f1; --surface: #ffffff; --ink: #1d2430; --muted: #6b7280; --line: #e4e2da;
  --brand: #0f766e; --brand-ink: #ffffff; --brand-soft: #e1f2ef;
  --pos: #15803d; --neg: #b91c1c; --warn-soft: #fff4e5;
  --radius: 10px; --shadow: 0 1px 2px rgba(20,25,35,.06), 0 4px 16px rgba(20,25,35,.05);
}
@media (prefers-color-scheme: dark) {
  :root { --bg:#14171c; --surface:#1c2027; --ink:#e8eaee; --muted:#9aa3b2; --line:#2c323c;
    --brand:#2dd4bf; --brand-ink:#05201d; --brand-soft:#12322f; --pos:#4ade80; --neg:#f87171; --warn-soft:#2d2415;
    --shadow: 0 1px 2px rgba(0,0,0,.4); }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
.muted { color: var(--muted); }
.error { color: var(--neg); min-height: 1.2em; margin: 0; font-size: 14px; }
input, select, button { font: inherit; color: inherit; }
input, select { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0; }
input:focus, select:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 500; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 8px 12px; }
button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.link { border: 0; background: none; padding: 2px 4px; color: var(--brand); text-decoration: underline; }
button.danger { color: var(--neg); }
.stack { display: grid; gap: 14px; }

/* landing / join */
.hero { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.hero-card { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); padding: 32px; width: min(440px, 100%); display: grid; gap: 16px; }
.hero-card h1 { font-size: 24px; }
.logo { font-weight: 800; letter-spacing: -.02em; font-size: 18px; }
.logo span { color: var(--brand); }

/* app shell */
.wrap { max-width: 1120px; margin: 0 auto; padding: 20px 16px 60px; display: grid; gap: 18px; }
header.top { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; }
header.top h1 { font-size: 24px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; }
.live.on .dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.2); }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card h2 { font-size: 16px; margin-bottom: 12px; }
.grid { display: grid; gap: 18px; grid-template-columns: minmax(0, 1fr) 340px; align-items: start; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--brand-soft); color: var(--ink); border-radius: 99px; padding: 2px 10px; font-size: 13px; white-space: nowrap; }
.chip.me { background: var(--brand); color: var(--brand-ink); font-weight: 600; }

/* composer */
.composer { display: grid; gap: 12px; }
.composer .row { display: grid; gap: 10px; grid-template-columns: 130px minmax(0,1fr) 120px 170px; }
@media (max-width: 720px) { .composer .row { grid-template-columns: 1fr 1fr; } .composer .row .wide { grid-column: 1 / -1; } }
.split { border: 1px solid var(--line); border-radius: 8px; padding: 10px; display: grid; gap: 8px; }
.split legend { font-size: 13px; color: var(--muted); font-weight: 500; padding: 0 4px; }
.split .boxes { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.split label.cb { display: inline-flex; grid-template: none; align-items: center; gap: 6px; color: var(--ink); font-size: 14px; }
.split input[type=checkbox] { width: auto; }
.composer .foot { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.composer .foot .grow { flex: 1; }
.editing { background: var(--warn-soft); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; }

/* table */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.mine td:first-child { box-shadow: inset 3px 0 0 var(--brand); }
.thumb { width: 38px; height: 38px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); display: block; }
.pdfbadge { display: inline-block; font-size: 11px; font-weight: 700; padding: 8px 6px; border: 1px solid var(--line); border-radius: 6px; }
.lock { color: var(--muted); font-size: 12px; }
.empty { text-align: center; color: var(--muted); padding: 28px 8px; }

/* balances */
.bal { display: grid; gap: 8px; }
.bal-row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.bal-row small { color: var(--muted); display: block; }
.pos { color: var(--pos); font-weight: 600; }
.neg { color: var(--neg); font-weight: 600; }
.transfer { padding: 8px 10px; border-radius: 8px; background: var(--brand-soft); display: flex; justify-content: space-between; gap: 8px; }
.total { display: flex; justify-content: space-between; padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid var(--line); }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; }
.toast.show { opacity: 1; }
