:root {
  --ground: #F4F5F2;
  --surface: #FFFFFF;
  --ink: #15201B;
  --muted: #5B6660;
  --soft: #4A5550;
  --line: #E3E6E1;
  --line-2: #EEF0EC;
  --field: #D3D8D2;
  --bills: #2F5D9E;
  --bills-tint: #E8EFF8;
  --living: #B45309;
  --living-bar: #D9822B;
  --living-tint: #FDF1E3;
  --deposit: #1E7A4C;
  --deposit-tint: #E2F1E8;
  --danger: #B42318;
  --p2: #A7B0AB;
  --radius: 20px;
  --tabbar-h: 76px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: 500 15px/1.4 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, p { margin: 0; }
a { color: var(--bills); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--bills); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Shells ---------- */
.screen {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(20px + env(safe-area-inset-top)) 20px calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.form-screen { background: var(--surface); min-height: 100dvh; }
.form-head {
  max-width: 560px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 12px 0 20px;
}
.form-head h1 { font-size: 20px; font-weight: 800; }
.form-body {
  max-width: 560px; margin: 0 auto;
  padding: 16px 20px calc(24px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 18px;
  min-height: calc(100dvh - 70px);
}

/* ---------- Tab bar (always visible) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  max-width: 560px; margin: 0 auto;
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: center;
  padding: 8px 8px calc(10px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
}
@media (min-width: 561px) { .tabbar { border-left: 1px solid var(--line); border-right: 1px solid var(--line); border-radius: 18px 18px 0 0; } }
.tabbar a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 52px; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
.tabbar a[aria-current] { color: var(--ink); font-weight: 800; }
.tabbar .fab {
  justify-self: center; width: 60px; height: 60px; border-radius: 30px;
  background: var(--ink); color: #FFFFFF; min-height: 0;
}

/* ---------- Headings ---------- */
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.page-head .sub { font-size: 13px; font-weight: 600; color: var(--muted); }
.page-head h1 { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding-bottom: 6px; }
.card-head h2, .sheet h2, .panel h2 { font-size: 16px; font-weight: 800; }

/* ---------- Atoms ---------- */
.meta { font-size: 12px; font-weight: 600; color: var(--muted); display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.overdue { color: var(--danger) !important; font-weight: 800; }
.strong { font-weight: 800; }
.strong.small { font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.label { font-size: 13px; font-weight: 700; color: var(--muted); }
.label.deposit, .total.deposit { color: var(--deposit); }
.label.bills, .total.bills { color: var(--bills); }
.total { font-size: 15px; font-weight: 800; }
.fund-amount { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.amount-md { font-size: 20px; font-weight: 800; }
.hint, .footnote { font-size: 13px; font-weight: 600; color: var(--muted); }
.footnote { text-align: center; font-size: 12px; }
.empty { font-size: 14px; font-weight: 600; color: var(--muted); padding: 10px 0; }
.empty.boxed { padding: 14px; border-radius: 14px; background: #F6F7F4; text-align: center; font-size: 13px; color: var(--soft); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 5px; flex-shrink: 0; }
.dot.b { background: var(--bills); } .dot.l { background: var(--living-bar); } .dot.s { background: var(--ink); }
.dot.p1 { background: var(--ink); } .dot.p2 { background: var(--p2); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack.grow { flex-grow: 1; }
.stack-xs { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stack-xs.right { align-items: flex-end; text-align: right; }
.row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid2.tight { gap: 12px; margin-top: 4px; }

/* ---------- Buttons ---------- */
.btn-primary, .btn-secondary, .btn-dark, .btn-danger {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  font-size: 14px; font-weight: 700; text-decoration: none; cursor: pointer;
}
.btn-primary { width: 100%; min-height: 56px; border-radius: 16px; border: 0; background: var(--ink); color: #FFFFFF; font-size: 16px; font-weight: 800; }
.btn-primary.bottom { margin-top: auto; }
.btn-secondary { border: 1px solid var(--field); background: var(--surface); color: var(--ink); }
.btn-dark { border: 0; background: var(--ink); color: #FFFFFF; }
.btn-danger { width: 100%; min-height: 48px; border: 1px solid #F1C7C2; background: var(--surface); color: var(--danger); }
.icon-btn {
  width: 44px; height: 44px; border-radius: 22px; border: 0; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: #F1F3F0; color: var(--ink); cursor: pointer;
}
.icon-btn.ghost { background: transparent; color: #8A948F; }
.link-btn { min-height: 44px; padding: 0 4px; border: 0; background: transparent; color: var(--bills); font-weight: 700; cursor: pointer; }
.avatar {
  width: 44px; height: 44px; border-radius: 22px; border: 0; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--ink); color: #FFFFFF; font-size: 16px; font-weight: 800; cursor: pointer;
}
.avatar.sm { width: 40px; height: 40px; font-size: 14px; cursor: default; }
.avatar.p2 { background: #D5DBD7; color: var(--ink); }
.avatar.dep { background: var(--deposit-tint); color: var(--deposit); }
.avatar.bill { background: #E3EBF6; color: var(--bills); }

/* ---------- Pills & segmented ---------- */
.pills { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.pills.wrap { flex-wrap: wrap; overflow: visible; }
.pill {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border-radius: 22px;
  border: 1px solid var(--field); background: var(--surface); color: var(--ink);
  font-size: 14px; font-weight: 600; text-decoration: none; white-space: nowrap;
}
.pill[aria-current] { background: var(--ink); border-color: var(--ink); color: #FFFFFF; font-weight: 700; }
.select-pill select {
  min-height: 44px; padding: 0 14px; border-radius: 22px; border: 1px solid var(--field);
  background: var(--surface); font-size: 14px; font-weight: 600; max-width: 180px;
}
.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: #E6E9E4; border-radius: 14px; }
.segmented a {
  min-height: 44px; border-radius: 11px; display: flex; align-items: center; justify-content: center;
  color: var(--soft); text-decoration: none; font-size: 14px; font-weight: 600;
}
.segmented a[aria-current] { background: var(--surface); color: var(--ink); font-weight: 800; }
.segmented a.bills[aria-current] { color: var(--bills); }
.segmented a.deposit[aria-current] { color: var(--deposit); }
.custom-range { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 6px;
}
.card.split { flex-direction: row; justify-content: space-between; align-items: center; gap: 12px; }
.card.list { padding: 4px 16px; gap: 0; }
button.card { text-align: left; cursor: pointer; font: inherit; color: inherit; }
.fund-name { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; }
.fund-name .dot { width: 8px; height: 8px; }
.fund-name.bills { color: var(--bills); }
.fund-name.living { color: var(--living); }

.hero { background: var(--ink); color: #FFFFFF; border-radius: 22px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.hero-label { font-size: 14px; font-weight: 700; }
.hero-sub { font-size: 12px; font-weight: 600; color: #C9D1CC; }
.hero-amount { font-size: 42px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; }
.hero .legend { font-size: 13px; font-weight: 600; color: #E4E9E6; }
.hero .legend span { display: inline-flex; align-items: center; gap: 6px; }
.hero .dot.b { background: #6E9BDB; } .hero .dot.l { background: #F0A94B; }
.splitbar { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: #2A3631; }
.splitbar .b { background: #6E9BDB; } .splitbar .l { background: #F0A94B; }
.splitbar.people { background: var(--line-2); }
.splitbar .p1 { background: var(--ink); } .splitbar .p2 { background: var(--p2); }

.bar-row { display: flex; flex-direction: column; gap: 6px; padding: 4px 0; }
.bar-row .row { font-size: 14px; font-weight: 600; }
.bar { height: 8px; border-radius: 4px; background: #F1EDE6; }
.bar span { display: block; height: 8px; border-radius: 4px; background: var(--living-bar); min-width: 4px; }

/* ---------- List lines ---------- */
.line { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line-2); }
.card.list .line:first-child, .card.list h2.day + .line { border-top: 0; }
.line form { margin: 0; flex-shrink: 0; }
.line-main { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; color: inherit; text-decoration: none; }
.line-title { font-size: 15px; font-weight: 700; overflow-wrap: anywhere; }
.amt { font-size: 15px; font-weight: 800; white-space: nowrap; }
.amt.deposit { color: var(--deposit); }
.amt-col { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.fund-tag { font-size: 11px; font-weight: 700; color: var(--muted); }
.check, .receive {
  width: 44px; height: 44px; border-radius: 22px; flex-shrink: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1.5px solid #C5CCC7; background: var(--surface); color: #8A948F;
}
.check:active { background: var(--bills); border-color: var(--bills); color: #FFFFFF; }
.receive { border-color: #B6D9C4; color: var(--deposit); }
.check-spacer { width: 44px; flex-shrink: 0; }
.datebox { width: 44px; flex-shrink: 0; display: flex; flex-direction: column; align-items: center; }
.datebox span { font-size: 11px; font-weight: 700; color: var(--muted); }
.datebox strong { font-size: 20px; font-weight: 800; line-height: 1.1; }
.datebox.overdue span, .datebox.overdue strong { color: var(--danger); }
h2.day { padding: 14px 0 4px; font-size: 12px; font-weight: 800; color: var(--muted); letter-spacing: 0.02em; }

/* ---------- Filters ---------- */
.filters { display: flex; flex-direction: column; gap: 10px; }
.search {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px;
  background: var(--surface); border: 1px solid var(--field); border-radius: 14px; color: var(--muted);
}
.search input { flex-grow: 1; border: 0; outline: none; background: transparent; font-size: 15px; font-weight: 600; color: var(--ink); min-width: 0; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 14px; font-weight: 800; }
.field input, .field select {
  width: 100%; min-height: 48px; padding: 0 14px; border: 1px solid var(--field); border-radius: 12px;
  background: var(--surface); font-size: 16px; font-weight: 600; color: var(--ink);
}
input[type="date"] { appearance: none; -webkit-appearance: none; }
.amount-field { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 0 0; }
.amount-field > span:first-child { font-size: 13px; font-weight: 700; color: var(--muted); }
.amount-field input {
  width: 100%; border: 0; outline: none; text-align: center; background: transparent;
  font-size: 52px; font-weight: 800; letter-spacing: -0.03em; color: var(--ink);
}
.amount-field input::placeholder { color: #C5CCC7; }
.group { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.group legend, .panel legend { padding: 0 0 10px; font-size: 14px; font-weight: 800; }
.panel { border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin: 0; min-width: 0; }
.panel.tinted { background: #F6F7F4; border-color: transparent; }
.panel legend { float: left; width: 100%; }
.panel legend + * { clear: both; }

.chips { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.chips.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.chip span {
  display: flex; align-items: center; justify-content: center; text-align: center;
  min-height: 48px; padding: 4px 8px; border-radius: 14px; border: 1px solid var(--field);
  background: var(--surface); font-size: 14px; font-weight: 600; cursor: pointer; overflow-wrap: anywhere;
}
.chip input:focus-visible + span { outline: 3px solid var(--bills); outline-offset: 2px; }
.chip.living input:checked + span { border: 2px solid var(--living); background: var(--living-tint); color: #7A3A06; font-weight: 800; }
.chip.bills input:checked + span { border: 2px solid var(--bills); background: var(--bills-tint); color: #1F4277; font-weight: 800; }
.chip.deposit input:checked + span { border: 2px solid var(--deposit); background: var(--deposit-tint); color: #145A37; font-weight: 800; }
.dashed {
  min-height: 48px; border-radius: 14px; border: 1.5px dashed #A7B0AB; background: var(--surface);
  color: var(--soft); font-size: 14px; font-weight: 700; cursor: pointer;
}
.segmented-input { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; background: #E6E9E4; border-radius: 14px; }
.segmented-input label { position: relative; }
.segmented-input input { position: absolute; opacity: 0; inset: 0; margin: 0; }
.segmented-input span {
  display: flex; align-items: center; justify-content: center; min-height: 44px; border-radius: 11px;
  font-size: 14px; font-weight: 600; color: var(--soft); cursor: pointer;
}
.segmented-input input:checked + span { background: var(--surface); color: var(--ink); font-weight: 800; }
.segmented-input input:focus-visible + span { outline: 3px solid var(--bills); }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; cursor: pointer; }
.switch-row strong { font-size: 15px; font-weight: 800; }
.switch {
  appearance: none; -webkit-appearance: none; flex-shrink: 0; margin: 7px 2px; cursor: pointer;
  width: 52px; height: 30px; border-radius: 15px; background: #C5CCC7; position: relative; transition: background .15s;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 12px;
  background: #FFFFFF; transition: transform .15s;
}
.switch:checked::after { transform: translateX(22px); }
.switch.bills:checked { background: var(--bills); }
.switch.deposit:checked { background: var(--deposit); }
.check-row { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; }
.check-row input { width: 20px; height: 20px; }

.split-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.split-row > span { display: inline-flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 700; }
.split-row input {
  width: 140px; min-height: 48px; padding: 0 12px; border: 1px solid var(--field); border-radius: 12px;
  background: var(--surface); font-size: 16px; font-weight: 700; text-align: right;
}
.split-total { display: flex; justify-content: space-between; align-items: center; padding-top: 10px; border-top: 1px solid var(--line); }
.split-total span { font-size: 14px; font-weight: 700; color: var(--soft); }
.split-total strong { font-size: 16px; font-weight: 800; }
.split-total strong.ok { color: var(--deposit); }
.split-total strong.off { color: var(--danger); }

.error, .note, .toast { padding: 12px 14px; border-radius: 12px; font-size: 14px; font-weight: 700; }
.error { background: #FDECEA; color: #8F1D14; }
.note { background: var(--deposit-tint); color: #145A37; }
.toast { background: var(--ink); color: #FFFFFF; animation: toast 3.2s ease forwards; }
@keyframes toast { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- Dialog ---------- */
.sheet {
  border: 0; padding: 20px 20px calc(20px + env(safe-area-inset-bottom)); width: min(560px, 100%); max-width: 100%;
  margin: auto auto 0; border-radius: 22px 22px 0 0; background: var(--surface); color: var(--ink);
}
.sheet::backdrop { background: rgba(21, 32, 27, .45); }

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

.line-main .meta { display: block; }
.meta svg { vertical-align: -2px; margin-right: 2px; }
