:root {
  --bg: #f5f7fb; --surface: #fff; --text: #14213d; --muted: #5c677d; --line: #dde3ee;
  --primary: #0b2545; --primary-text: #fff; --accent: #c8102e; --ok: #1b7f4b; --warn: #a15c00; --error: #b00020; --pending: #3559a8;
  --radius: 14px; --tap: 48px; --shadow: 0 1px 3px rgba(20, 33, 61, .08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0e1420; --surface: #172033; --text: #e8edf6; --muted: #9aa6bd; --line: #26324a; --primary: #7fa7ff; --primary-text: #0b1220; --accent: #ff6b7d; --ok: #4cc38a; --warn: #f0b35a; --error: #ff7a8a; --pending: #8fb0ff; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4rem; }
h1 { font-size: 1.25rem; } h2 { font-size: 1.05rem; color: var(--muted); }
.section > h2::first-letter { text-transform: uppercase; } h3 { font-size: 1.1rem; }
p { margin: 0 0 .5rem; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.boot { padding: 2rem; text-align: center; color: var(--muted); }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; gap: .5rem; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + .6rem) 1rem .6rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
main { padding: 1rem 1rem calc(88px + env(safe-area-inset-bottom)); max-width: 720px; margin: 0 auto; outline: none; }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 60px; text-decoration: none; color: var(--muted); font-size: .8rem; }
.tab-icon { font-size: 1.35rem; line-height: 1; }
.tab.active { color: var(--primary); font-weight: 600; }

.status-pill { display: inline-flex; align-items: center; gap: .4rem; min-height: 36px; padding: .2rem .7rem; border-radius: 999px;
  border: 1px solid var(--line); background: var(--bg); font-size: .78rem; white-space: nowrap; cursor: pointer; }
.status-pill .dot { width: .6rem; height: .6rem; border-radius: 50%; background: var(--muted); }
.status-pill.online .dot { background: var(--ok); }
.status-pill.offline .dot { background: var(--error); }
.status-pill.warn { border-color: var(--warn); color: var(--warn); }

.stack > * + * { margin-top: .8rem; }
.row { display: flex; gap: .6rem; align-items: center; }
.row > .field { flex: 1; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.block { display: block; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mono { font-family: ui-monospace, monospace; letter-spacing: .04em; }
.greeting { font-size: 1.3rem; font-weight: 600; }
.section { margin-top: 1.4rem; scroll-margin-top: 72px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); }
.card.highlight { border-left: 5px solid var(--accent); }
.list { display: grid; gap: .5rem; }
.item { display: flex; gap: .8rem; align-items: center; width: 100%; min-height: var(--tap); text-align: left; cursor: pointer; }
button.card.item { font: inherit; }
.item.plain { background: none; border: 0; padding: 0; }
.time { min-width: 4.6rem; font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; }
.kind { font-size: 1.5rem; }
.notes { white-space: pre-wrap; }
.amount { font-size: 1.8rem; font-weight: 700; }
.amount-sm { font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: var(--tap); padding: .5rem 1rem;
  border-radius: 12px; border: 1px solid transparent; font-weight: 600; text-decoration: none; cursor: pointer; }
.btn.small { min-height: 40px; padding: .3rem .8rem; font-size: .9rem; }
.btn.big { min-height: 64px; font-size: 1.05rem; }
.btn.block { width: 100%; }
.btn.primary { background: var(--primary); color: var(--primary-text); }
.btn.secondary { background: var(--surface); border-color: var(--line); color: var(--text); }
.btn.danger { background: transparent; border-color: var(--error); color: var(--error); }
.btn:disabled { opacity: .5; }
.icon-btn { min-width: var(--tap); min-height: var(--tap); border: 0; background: none; font-size: 1.2rem; cursor: pointer; }
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.fab { position: fixed; right: 1rem; bottom: calc(76px + env(safe-area-inset-bottom)); width: 60px; height: 60px; border-radius: 50%;
  border: 0; background: var(--accent); color: #fff; font-size: 1.8rem; box-shadow: 0 4px 12px rgba(0,0,0,.25); cursor: pointer; z-index: 4; }

.segmented { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.segmented a { text-align: center; padding: .6rem .2rem; border-radius: 9px; text-decoration: none; color: var(--muted); min-height: 44px; }
.segmented a.on { background: var(--primary); color: var(--primary-text); font-weight: 600; }

.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .72rem; white-space: nowrap; border: 1px solid var(--line); color: var(--muted); }
.badge.ok { color: var(--ok); border-color: currentColor; }
.badge.pending { color: var(--pending); border-color: currentColor; }
.badge.warn { color: var(--warn); border-color: currentColor; }
.badge.error { color: var(--error); border-color: currentColor; }
.notice { display: block; padding: .7rem .9rem; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: var(--text); }
.notice.warn { border-color: var(--warn); }
.notice.pending { border-color: var(--pending); }
.empty { text-align: center; padding: 1.5rem 1rem; border: 2px dashed var(--line); border-radius: var(--radius); }
.empty-title { font-weight: 600; }

.votes { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin-top: .6rem; }
.vote { min-height: var(--tap); border-radius: 10px; border: 1px solid var(--line); background: var(--bg); cursor: pointer; }
.vote.on { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }
.plain-list { list-style: none; padding: 0; margin: 0; }
.plain-list li { padding: .35rem 0; border-bottom: 1px solid var(--line); }
.balances li { display: flex; justify-content: space-between; }
.pos { color: var(--ok); } .neg { color: var(--error); }
.settle { border-top: 1px dashed var(--line); padding-top: .4rem; }
.conflict { border-color: var(--warn); }

.field { display: flex; flex-direction: column; gap: .25rem; }
.field label { font-weight: 600; font-size: .9rem; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=date], input[type=time], select, textarea {
  width: 100%; min-height: var(--tap); padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
textarea { min-height: 90px; }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: .6rem .8rem; }
legend { font-weight: 600; font-size: .9rem; padding: 0 .3rem; }
.check, .chip { display: flex; align-items: center; gap: .6rem; min-height: var(--tap); }
.chip { padding: 0 .8rem; border: 1px solid var(--line); border-radius: 999px; }
.check input, .chip input { width: 22px; height: 22px; }
.hint { color: var(--muted); font-size: .8rem; }
.field-error { color: var(--error); font-size: .85rem; margin: .2rem 0 0; }
.preview { font-size: .9rem; color: var(--muted); min-height: 1.2em; }
details.more summary { cursor: pointer; min-height: 40px; display: flex; align-items: center; color: var(--muted); }

dialog.sheet { width: 100%; max-width: 640px; max-height: 92vh; margin: auto auto 0; padding: 0; border: 0; border-radius: 18px 18px 0 0; background: var(--surface); color: var(--text); }
dialog.sheet::backdrop { background: rgba(0, 0, 0, .45); }
.sheet-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: .6rem .6rem .4rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; color: var(--text); text-transform: none; font-size: 1.1rem; }
.sheet-body { padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom)); }

.auth { max-width: 420px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 2rem) 1.2rem 2rem; }
.auth > * + * { margin-top: 1rem; }

.toast { position: fixed; left: 1rem; right: 1rem; bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 20; max-width: 560px; margin: 0 auto;
  padding: .8rem 1rem; border-radius: 12px; background: var(--text); color: var(--bg); opacity: 0; transform: translateY(10px); transition: .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: var(--error); color: #fff; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }
@media (min-width: 720px) { .quick { grid-template-columns: repeat(2, minmax(0, 260px)); } }
.segmented { grid-template-columns: repeat(4, 1fr); }
.segmented a { font-size: .92rem; }
.chips { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .2rem; -webkit-overflow-scrolling: touch; }
.chip-btn { flex: none; min-height: 40px; padding: .3rem .8rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; }
.chip-btn.on { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-weight: 600; }
.idea .row.wrap { margin-top: .4rem; }
.attribution a { color: var(--muted); }
