:root {
  --bg: #f4f6f3;
  --card: #ffffff;
  --text: #1d2520;
  --muted: #6b766f;
  --brand: #1f6f5c;
  --income: #2e9e5b;
  --expense: #e0533d;
  --line: #e3e8e4;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
button { font: inherit; border: 0; background: #e9eeea; color: var(--text); padding: 10px 14px; border-radius: 10px; cursor: pointer; }
button.primary { background: var(--brand); color: #fff; font-weight: 600; }
button.danger { background: #fde6e2; color: var(--expense); }
button.small { padding: 10px 12px; }
input, select { font: inherit; width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--text); }
h1 { margin: 8px 0; font-size: 22px; }
h2 { font-size: 15px; color: var(--muted); margin: 20px 16px 8px; font-weight: 600; }
.error { color: var(--expense); min-height: 1em; margin: 6px 0 0; font-size: 14px; }
.row { display: flex; gap: 8px; margin-top: 12px; }
.row input { margin-top: 0 !important; }

.screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.key-box { width: 100%; max-width: 380px; background: var(--card); padding: 24px; border-radius: 18px; box-shadow: 0 6px 24px rgba(0,0,0,.06); text-align: center; }
.key-box input { margin-top: 12px; }
.key-box > button { width: 100%; margin-top: 12px; }
.key-box p { color: var(--muted); }
.logo { width: 64px; height: 64px; margin: 0 auto; border-radius: 18px; background: var(--brand); color: #fff; font-size: 34px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.who-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 12px; }
.who-list button { padding: 14px; font-weight: 600; }

main { padding-bottom: 90px; max-width: 640px; margin: 0 auto; }
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; background: var(--brand); color: #fff; padding: 12px 10px; padding-top: max(12px, env(safe-area-inset-top)); }
.top .nav { background: rgba(255,255,255,.15); color: #fff; font-size: 22px; width: 44px; height: 40px; padding: 0; }
.month-title { font-size: 18px; font-weight: 700; }

.summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 14px 16px 0; }
.card { background: var(--card); border-radius: 14px; padding: 12px 14px; }
.card span { display: block; color: var(--muted); font-size: 13px; }
.card b { font-size: 19px; }
.card.income b { color: var(--income); }
.card.expense b { color: var(--expense); }
.card.balance { grid-column: span 2; display: flex; justify-content: space-between; align-items: center; }
.card.balance b { font-size: 22px; }

.member-breakdown { background: var(--card); margin: 0 16px; border-radius: 14px; padding: 6px 14px; }
.mb-row { padding: 10px 0; border-bottom: 1px solid var(--line); }
.mb-row:last-child { border-bottom: 0; }
.mb-head { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.mb-name { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.mb-vals { color: var(--muted); white-space: nowrap; }
.mb-vals .in { color: var(--income); }
.mb-vals .out { color: var(--expense); }
.bar { height: 8px; background: #eef1ee; border-radius: 4px; margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; }
.empty { color: var(--muted); text-align: center; padding: 18px 0; }

.filter { display: flex; gap: 8px; padding: 0 16px 8px; }
.chip { padding: 6px 14px; border-radius: 20px; background: #e4eae6; font-size: 14px; }
.chip.active { background: var(--brand); color: #fff; }
.tx-list { margin: 0 16px; }
.tx-day { color: var(--muted); font-size: 13px; margin: 12px 4px 6px; }
.tx { display: flex; align-items: center; gap: 12px; background: var(--card); padding: 12px; border-radius: 12px; margin-bottom: 6px; cursor: pointer; }
.tx .avatar { width: 36px; height: 36px; border-radius: 50%; color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.tx .info { flex: 1; min-width: 0; }
.tx .cat { font-weight: 600; }
.tx .sub { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .amt { font-weight: 700; white-space: nowrap; }
.tx .amt.income { color: var(--income); }
.tx .amt.expense { color: var(--expense); }

.chart-wrap { background: var(--card); margin: 0 16px; border-radius: 14px; padding: 10px; }
.chart-wrap canvas { width: 100%; display: block; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; padding: 8px 18px 0; color: var(--muted); font-size: 13px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 4px; }
.dot.income { background: var(--income); }
.dot.expense { background: var(--expense); }

.member-list { margin: 0 16px; }
.member-item { display: flex; align-items: center; gap: 10px; background: var(--card); padding: 10px 12px; border-radius: 12px; margin-bottom: 6px; }
.member-item input[type=color] { width: 36px; height: 36px; padding: 0; border: 0; border-radius: 50%; overflow: hidden; flex: none; }
.member-item .mname { flex: 1; }
#tabMembers .row { padding: 0 16px; }
.hint { padding: 0 16px; color: var(--muted); }
.hint a { color: var(--brand); }

.fab { position: fixed; right: 18px; bottom: 84px; width: 58px; height: 58px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 32px; padding: 0; box-shadow: 0 6px 16px rgba(31,111,92,.35); z-index: 6; }
.bottom { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: #fff; border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 6; }
.bottom button { flex: 1; background: none; border-radius: 0; padding: 8px 0 10px; color: var(--muted); font-size: 12px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.bottom button span { font-size: 20px; }
.bottom button.active { color: var(--brand); font-weight: 700; }

dialog { border: 0; border-radius: 18px; padding: 18px; width: min(420px, 94vw); }
dialog::backdrop { background: rgba(0,0,0,.35); }
#txForm { display: flex; flex-direction: column; gap: 10px; }
.type-switch { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.type-switch input { display: none; }
.type-switch span { display: block; text-align: center; padding: 10px; border-radius: 10px; background: #eef1ee; font-weight: 600; cursor: pointer; }
.type-switch input[value=expense]:checked + span { background: var(--expense); color: #fff; }
.type-switch input[value=income]:checked + span { background: var(--income); color: #fff; }
#txAmount { font-size: 22px; font-weight: 700; text-align: right; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.quick button { padding: 6px 10px; font-size: 13px; border-radius: 16px; }
.field { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 8px; justify-content: flex-end; }
.actions .danger { margin-right: auto; }
