:root {
  --bg: #F6F3EC; --surface: #FFFDF8; --sunk: #EFEBE1; --line: #E2DCCE; --line-strong: #CFC7B5;
  --ink: #1C1A15; --muted: #6B6558; --faint: #9A9384;
  --accent: #1E5B47; --accent-ink: #FFFDF8; --accent-soft: #E1ECE5;
  --p1: #2F4C8F; --p1-soft: #E4E9F4; --p2: #A94A27; --p2-soft: #F5E6DE; --shared: #1E5B47; --shared-soft: #E1ECE5;
  --in: #1E7A4C; --out: #1C1A15; --warn: #9A6412; --warn-soft: #F6EBD3; --bad: #B3261E; --bad-soft: #F7E1DE;
  --radius: 14px; --radius-sm: 9px;
  --display: 'Fraunces', Georgia, serif; --body: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12120F; --surface: #1A1A16; --sunk: #222119; --line: #2E2D26; --line-strong: #3E3C33;
    --ink: #EEEAE0; --muted: #A9A394; --faint: #77725F;
    --accent: #7CC6A6; --accent-ink: #0F1F18; --accent-soft: #1D3229;
    --p1: #94ACE8; --p1-soft: #1E2638; --p2: #EC9C78; --p2-soft: #36231B; --shared: #7CC6A6; --shared-soft: #1D3229;
    --in: #7CC6A6; --out: #EEEAE0; --warn: #E3B262; --warn-soft: #33291A; --bad: #F08C82; --bad-soft: #3A1F1C;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; box-shadow: none !important; text-shadow: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--body); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.money { font-family: var(--display); font-variation-settings: 'opsz' 72; font-weight: 600; font-variant-numeric: lining-nums tabular-nums; letter-spacing: -0.02em; }
.muted { color: var(--muted); } .faint { color: var(--faint); } .small { font-size: 13px; } .tiny { font-size: 12px; }
.in { color: var(--in); } .bad-t { color: var(--bad); } .warn-t { color: var(--warn); }
.boot { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* layout */
.app { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.rail { position: sticky; top: 0; height: 100vh; border-right: 1px solid var(--line); padding: 20px 14px; display: flex; flex-direction: column; gap: 2px; background: var(--bg); }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-family: var(--display); font-size: 19px; font-weight: 600; }
.brand img { width: 28px; height: 28px; }
.rail a { display: flex; align-items: center; gap: 11px; padding: 9px 10px; border-radius: var(--radius-sm); text-decoration: none; color: var(--muted); font-weight: 500; }
.rail a:hover { background: var(--sunk); color: var(--ink); }
.rail a[aria-current] { background: var(--surface); color: var(--ink); border: 1px solid var(--line); padding: 8px 9px; }
.rail svg, .tabs svg { width: 19px; height: 19px; flex: none; }
.rail .who { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); }
.main { min-width: 0; padding: 0 32px 64px; max-width: 1080px; }
.top { display: flex; align-items: center; gap: 12px; padding: 22px 0 18px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.top h1 { font-family: var(--display); font-size: 26px; letter-spacing: -0.02em; margin-right: auto; }
.monthnav { display: flex; align-items: center; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); }
.monthnav button { border: 0; background: none; padding: 7px 11px; cursor: pointer; color: var(--muted); }
.monthnav button:hover { color: var(--ink); }
.monthnav svg { width: 16px; height: 16px; display: block; }
.monthnav span { min-width: 112px; text-align: center; font-weight: 500; font-size: 14px; }
.tabs { display: none; }
.fab { display: none; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .rail { display: none; }
  .main { padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
  .top { padding: calc(12px + env(safe-area-inset-top)) 0 12px; flex-wrap: wrap; }
  .top h1 { font-size: 23px; }
  .top .add-btn { display: none; }
  .tabs { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0; z-index: 20; background: var(--surface); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabs a, .tabs button { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 5px 0; font-size: 11px; color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer; }
  .tabs [aria-current] { color: var(--accent); font-weight: 600; }
  .tabs .plus span { display: grid; place-items: center; width: 44px; height: 44px; margin-top: -2px; border-radius: 14px; background: var(--accent); color: var(--accent-ink); }
  .tabs .plus svg { width: 22px; height: 22px; }
}

/* building blocks */
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 820px) { .g2, .g3 { grid-template-columns: 1fr; } .g3.keep { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.card.flat { background: transparent; }
.card h2 { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card h2 .link { margin-left: auto; font-weight: 500; font-size: 13px; color: var(--muted); text-decoration: none; }
.card h2 .link:hover { color: var(--ink); }
.section { margin-top: 26px; }
.section > h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.section > h2 .link { margin-left: auto; text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--muted); text-decoration: none; }
.stat .label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat .value { font-size: 30px; margin-top: 4px; line-height: 1.1; }
.stat .delta { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.hero { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 0; padding: 0; overflow: hidden; }
.hero > div { padding: 20px 20px 18px; }
.hero > div + div { border-left: 1px solid var(--line); }
.hero .left .value { font-size: 38px; }
@media (max-width: 820px) {
  .hero { grid-template-columns: 1fr 1fr; }
  .hero .left { grid-column: 1 / -1; border-bottom: 1px solid var(--line); }
  .hero > div + div { border-left: 0; } .hero > div:last-child { border-left: 1px solid var(--line); }
  .stat .value { font-size: 24px; } .hero .left .value { font-size: 34px; }
}

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid var(--line-strong); background: var(--surface); padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 500; text-decoration: none; white-space: nowrap; min-height: 38px; }
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--sunk); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 13.5px; border-radius: 8px; }
.btn svg { width: 17px; height: 17px; }
.btn[disabled] { opacity: .55; cursor: default; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--sunk); color: var(--muted); white-space: nowrap; }
.pill.p1 { background: var(--p1-soft); color: var(--p1); } .pill.p2 { background: var(--p2-soft); color: var(--p2); }
.pill.shared { background: var(--shared-soft); color: var(--shared); }
.pill.warn { background: var(--warn-soft); color: var(--warn); } .pill.bad { background: var(--bad-soft); color: var(--bad); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.p1 { background: var(--p1); } .dot.p2 { background: var(--p2); } .dot.shared { background: var(--shared); }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 2px; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.list .main-t { flex: 1; min-width: 0; }
.list .title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .sub { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.list .amt { text-align: right; font-weight: 600; white-space: nowrap; }
.list li.tap { cursor: pointer; border-radius: 8px; }
.list li.tap:hover { background: var(--sunk); }
.daygroup { font-size: 12.5px; font-weight: 600; color: var(--muted); padding: 18px 2px 4px; display: flex; justify-content: space-between; }
.icon-badge { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--sunk); color: var(--muted); font-weight: 600; font-size: 13px; }
.icon-badge.in { background: var(--accent-soft); color: var(--in); }
.icon-badge svg { width: 18px; height: 18px; }
.empty { padding: 28px 12px; text-align: center; color: var(--muted); }
.empty strong { display: block; color: var(--ink); font-size: 16px; margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }

/* bars */
.bar { height: 8px; border-radius: 99px; background: var(--sunk); overflow: hidden; position: relative; }
.bar > i { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--accent); }
.bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }
.bar.thick { height: 12px; }
.catrow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; padding: 10px 0; border-top: 1px solid var(--line); align-items: baseline; }
.catrow:first-of-type { border-top: 0; }
.catrow .bar { grid-column: 1 / -1; }
.catrow .meta { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.split-bar { display: flex; height: 10px; border-radius: 99px; overflow: hidden; background: var(--sunk); }
.split-bar i { display: block; height: 100%; }

/* alerts */
.alerts { display: grid; gap: 8px; margin-bottom: 14px; }
.alert { display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); }
.alert.warn { border-color: color-mix(in srgb, var(--warn) 35%, var(--line)); background: var(--warn-soft); }
.alert.bad { border-color: color-mix(in srgb, var(--bad) 35%, var(--line)); background: var(--bad-soft); }
.alert .txt { flex: 1; min-width: 0; font-size: 14px; }
.alert svg { width: 18px; height: 18px; flex: none; }

/* together */
.owe { font-family: var(--display); font-size: 24px; line-height: 1.25; letter-spacing: -0.015em; }
.owe .money { font-size: 1em; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* chart */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 11px; font-family: var(--body); }
.chart .gl { stroke: var(--line); }
.chart .b-in { fill: var(--accent); } .chart .b-out { fill: var(--line-strong); }

/* forms */
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--muted); }
.field input, .field select, .field textarea, .input { width: 100%; padding: 10px 12px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); min-height: 42px; }
.field textarea { min-height: 72px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.field .hint { font-size: 12px; color: var(--faint); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.amount-in { display: flex; align-items: baseline; gap: 6px; border-bottom: 2px solid var(--line-strong); padding: 4px 2px 6px; }
.amount-in:focus-within { border-color: var(--accent); }
.amount-in .cur { font-family: var(--display); font-size: 28px; color: var(--muted); }
.amount-in input { border: 0; background: none; font-family: var(--display); font-size: 40px; font-weight: 600; width: 100%; padding: 0; outline: none; font-variant-numeric: tabular-nums; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--sunk); border-radius: 11px; padding: 3px; gap: 3px; }
.seg label { text-align: center; padding: 7px 6px; border-radius: 8px; cursor: pointer; font-size: 14px; font-weight: 500; color: var(--muted); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--surface); color: var(--ink); border: 1px solid var(--line); padding: 6px 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips label { padding: 6px 11px; border: 1px solid var(--line-strong); border-radius: 999px; font-size: 13.5px; cursor: pointer; background: var(--surface); }
@media (max-width: 820px) {
  .chips.scroll { display: grid; grid-auto-flow: column; grid-template-rows: repeat(3, auto); grid-auto-columns: max-content; overflow-x: auto; padding-bottom: 6px; margin: 0 -18px; padding-inline: 18px; scrollbar-width: none; }
  .chips.scroll::-webkit-scrollbar { display: none; }
}
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips label:has(input:checked) { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chips label:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.switch input { width: 40px; height: 24px; appearance: none; border-radius: 99px; background: var(--line-strong); position: relative; flex: none; cursor: pointer; transition: background .15s; }
.switch input::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: var(--surface); transition: transform .15s; }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(16px); }
.switch .t { flex: 1; } .switch .t small { display: block; color: var(--muted); font-size: 12.5px; }
.error { color: var(--bad); font-size: 13.5px; min-height: 0; }
.scan { display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px dashed var(--line-strong); border-radius: 12px; cursor: pointer; background: var(--sunk); }
.scan:hover { border-color: var(--accent); }
.scan svg { width: 22px; height: 22px; color: var(--accent); flex: none; }
.scan .t { flex: 1; font-size: 14px; } .scan .t small { display: block; color: var(--muted); font-size: 12.5px; }
.thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; border: 1px solid var(--line); }

/* sheet (dialog) */
.sheet { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: rgb(20 18 12 / .45); padding: 20px; }
.sheet[hidden] { display: none; }
.sheet .panel { width: min(520px, 100%); max-height: calc(100vh - 40px); overflow: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 18px; }
.sheet .head { display: flex; align-items: center; gap: 8px; padding: 16px 18px 12px; position: sticky; top: 0; background: var(--bg); z-index: 1; border-bottom: 1px solid var(--line); }
.sheet .head h2 { font-family: var(--display); font-size: 20px; margin-right: auto; }
.sheet .body { padding: 16px 18px 20px; }
.sheet .foot { display: flex; gap: 8px; padding: 12px 18px calc(16px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); position: sticky; bottom: 0; background: var(--bg); }
.sheet .foot .btn.primary { flex: 1; }
@media (max-width: 820px) {
  .sheet { place-items: end stretch; padding: 0; }
  .sheet .panel { width: 100%; max-height: 92vh; border-radius: 18px 18px 0 0; border-bottom: 0; }
}
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 60; font-size: 14px; max-width: calc(100% - 32px); }
@media (max-width: 820px) { .toast { bottom: calc(86px + env(safe-area-inset-bottom)); } }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.auth .box { width: min(400px, 100%); }
.auth .brand { padding: 0 0 22px; font-size: 24px; }
.auth h1 { font-family: var(--display); font-size: 30px; letter-spacing: -0.02em; margin-bottom: 6px; }
.auth p { color: var(--muted); margin: 0 0 22px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.filters select, .filters input { width: auto; min-height: 36px; padding: 6px 10px; font-size: 14px; border-radius: 9px; border: 1px solid var(--line-strong); background: var(--surface); }
.filters input { flex: 1; min-width: 150px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; text-align: right; font-weight: 500; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 9px 8px; border-bottom: 1px solid var(--line); }
.table td.r, .table th.r { text-align: right; }
.table tr:last-child td { border-bottom: 0; }
.up { color: var(--bad); } .down { color: var(--in); }
.stack > * + * { margin-top: 14px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
