:root {
  --bg: #f6f5f1; --card: #fff; --ink: #1b1c1e; --muted: #6c6a64; --line: #e5e2da;
  --accent: #1d5c47; --accent-soft: #e4efe9; --warn: #a8540f; --warn-soft: #fbeedd;
  --danger: #b42318; --danger-soft: #fde8e6; --radius: 14px;
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; margin: 28px 0 10px; }
.num, .big, td.amt { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.pad { padding: 24px 0; }
.wrap { max-width: 780px; margin: 0 auto; padding: 8px 16px 110px; }

/* top bar + tabs */
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 16px; padding: 10px max(16px, calc((100% - 780px) / 2 + 16px)); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; color: var(--ink); text-decoration: none; }
.tabs { display: flex; gap: 2px; margin-left: auto; }
.tabs a { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px; color: var(--muted); text-decoration: none; font-weight: 500; }
.tabs a svg { width: 18px; height: 18px; fill: currentColor; }
.tabs a.on { background: var(--card); color: var(--ink); box-shadow: 0 0 0 1px var(--line); }
@media (max-width: 640px) {
  .tabs { position: fixed; bottom: 0; left: 0; right: 0; margin: 0; background: var(--card); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .tabs a { flex-direction: column; gap: 2px; font-size: 11px; padding: 6px 8px; }
  .tabs a svg { width: 22px; height: 22px; }
  .tabs a.on { box-shadow: none; background: transparent; color: var(--accent); }
}

/* cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.stack > * + * { margin-top: 12px; }
.hero { margin-top: 16px; }
.hero .label { color: var(--muted); font-weight: 500; }
.big { font-size: 40px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; margin: 2px 0 12px; }
.bar { height: 8px; background: #efece5; border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.thin { height: 4px; margin-top: 8px; }
.hero .sub { margin-top: 10px; color: var(--muted); }

.alert { border-radius: var(--radius); padding: 14px 16px; display: flex; gap: 12px; align-items: flex-start; margin-top: 12px; }
.alert.warn { background: var(--warn-soft); color: #5e2f07; }
.alert.danger { background: var(--danger-soft); color: #6d140d; }
.alert.ok { background: var(--accent-soft); color: #123b2d; }
.alert b { display: block; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--line); }
.list li:first-child { border-top: 0; padding-top: 0; }
.list li:last-child { padding-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .right { text-align: right; white-space: nowrap; }
.small { font-size: 13px; }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: #efece5; color: var(--muted); white-space: nowrap; }
.pill.red { background: var(--danger-soft); color: var(--danger); }
.pill.amber { background: var(--warn-soft); color: var(--warn); }
.pill.green { background: var(--accent-soft); color: var(--accent); }

/* account cards */
.acct-head { display: flex; align-items: baseline; gap: 12px; }
.acct-head h3 { font-size: 18px; }
.acct-head .bal { margin-left: auto; font-size: 20px; font-weight: 700; }
.acct-meta { color: var(--muted); font-size: 13px; margin: 2px 0 12px; }
.chunk { padding: 10px 0; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; }
.chunk.done { opacity: .5; }
.chunk .when { font-weight: 600; }
.chunk .amt { text-align: right; font-weight: 600; }
.chunk .of { text-align: right; color: var(--muted); font-size: 13px; }
.chunk .bar { grid-column: 1 / -1; }
.chunk.next { position: relative; }
.chunk.next::before { content: ""; position: absolute; left: -18px; top: 10px; bottom: 10px; width: 3px; border-radius: 3px; background: var(--accent); }
.acct-actions { display: flex; gap: 8px; margin-top: 12px; }
.notes { font-size: 13px; color: var(--muted); background: #faf9f6; border-radius: 10px; padding: 8px 10px; margin-top: 10px; }

/* forms */
label { display: block; font-weight: 600; font-size: 13px; }
label + label, label + .row, .row + label, .row + .row { margin-top: 14px; }
input, select, textarea { width: 100%; margin-top: 6px; font: inherit; font-weight: 400; color: var(--ink); background: #fff; border: 1px solid #d6d2c8;
  border-radius: 10px; padding: 11px 12px; min-height: 44px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.amount-input { font-size: 28px; font-weight: 700; padding: 10px 12px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row > label { margin-top: 0 !important; }
.hint { font-weight: 400; color: var(--muted); font-size: 13px; margin-top: 6px; }
.btn { appearance: none; border: 1px solid #d6d2c8; background: #fff; color: var(--ink); font: inherit; font-weight: 600; padding: 10px 16px;
  border-radius: 10px; cursor: pointer; min-height: 44px; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn:hover { border-color: #b9b4a8; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #164a39; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; margin-top: 18px; }
.btn:disabled { opacity: .5; cursor: default; }
.iconbtn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 8px; border-radius: 8px; font-size: 18px; line-height: 1; min-width: 36px; min-height: 36px; }
.iconbtn:hover { background: #f1efe9; color: var(--danger); }
.err { color: var(--danger); min-height: 1.2em; margin: 10px 0 0; }

.preview { margin-top: 16px; background: var(--accent-soft); border-radius: 12px; padding: 12px 14px; color: #123b2d; }
.preview.bad { background: var(--danger-soft); color: #6d140d; }
.preview ul { margin: 6px 0 0; padding-left: 18px; }

/* dialog */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100% - 24px)); max-height: calc(100% - 40px); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(20, 20, 18, .45); }
dialog form { padding: 20px; }
dialog h3 { font-size: 19px; margin-bottom: 14px; }
.chunk-edit { display: grid; grid-template-columns: 1.3fr 1fr 1.2fr auto; gap: 8px; align-items: end; margin-top: 10px; }
.chunk-edit input { margin-top: 0; }
.chunk-edit .lbl { font-size: 12px; color: var(--muted); font-weight: 600; }
.dlg-actions { display: flex; gap: 8px; margin-top: 20px; }
.dlg-actions .spacer { flex: 1; }
@media (max-width: 520px) { .chunk-edit { grid-template-columns: 1fr 1fr; } .chunk-edit .lblc { grid-column: 1 / -1; } }

#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px;
  border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; z-index: 20; max-width: calc(100% - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }

/* login */
body.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); text-align: center; }
.login-card h1 { font-size: 24px; margin: 8px 0 18px; }
.login-card label { text-align: left; }
.login-card .btn { width: 100%; margin-top: 16px; }

.empty { color: var(--muted); text-align: center; padding: 24px 0; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 28px 0 10px; }
.section-head h2 { margin: 0; }
