:root {
  --paper: #f4f1ea;
  --card: #fffdf8;
  --ink: #1d2422;
  --muted: #6b716d;
  --line: #e2ddd1;
  --brand: #1f3a34;
  --brand-ink: #f4f1ea;
  --accent: #d9902f;
  --accent-soft: #fbefdc;
  --neg: #b4321f;
  --ok: #2f7a55;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(29,36,34,.06), 0 4px 16px rgba(29,36,34,.05);
  --font: ui-sans-serif, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #141917; --card: #1c2321; --ink: #e9ece8; --muted: #9aa39e; --line: #2c3532;
    --brand: #0f1f1b; --brand-ink: #e9ece8; --accent: #e6a24a; --accent-soft: #33291b;
    --neg: #ff7a66; --ok: #6cc79a; --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.45 var(--font); }
body.has-bottombar { padding-bottom: 88px; }
a { color: inherit; }
h1 { font-size: 1.5rem; margin: .2rem 0 1rem; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin: 0; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: calc(.7rem + env(safe-area-inset-top)) 1rem .7rem; background: var(--brand); color: var(--brand-ink);
}
.brand { font-weight: 700; text-decoration: none; letter-spacing: .02em; display: flex; align-items: center; gap: .5rem; }
.brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #1f3a34; font-weight: 800; }
.topbar nav { display: flex; align-items: center; gap: 1rem; font-size: .95rem; }
.topbar nav a { text-decoration: none; opacity: .85; }
.topbar nav a:hover { opacity: 1; }
.linkish { background: none; border: 0; color: inherit; font: inherit; opacity: .85; cursor: pointer; padding: 0; }
form.inline { display: inline; margin: 0; }

.wrap { max-width: 960px; margin: 0 auto; padding: 1rem; }

.messages { display: grid; gap: .5rem; margin-bottom: 1rem; }
.msg { padding: .7rem .9rem; border-radius: 10px; background: var(--card); border-left: 4px solid var(--brand); box-shadow: var(--shadow); }
.msg-success { border-color: var(--ok); }
.msg-warning, .msg-error { border-color: var(--neg); }

/* Summary --------------------------------------------------------------- */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin-bottom: 1rem; }
.stat { background: var(--card); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); border: 1px solid var(--line); }
.stat-accent { background: var(--accent-soft); border-color: transparent; }
.stat-label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.stat-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.neg { color: var(--neg); }

.toolbar { display: flex; align-items: center; justify-content: space-between; margin: .25rem 0 .5rem; gap: .5rem; }
.addgroup { position: relative; }
.addgroup summary, .menu summary { list-style: none; cursor: pointer; }
.addgroup summary::-webkit-details-marker, .menu summary::-webkit-details-marker { display: none; }
.addgroup-form { position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; display: flex; gap: .4rem; background: var(--card); padding: .6rem; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.15); border: 1px solid var(--line); width: max-content; }

/* Groups & rows ---------------------------------------------------------- */
.group { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: .9rem; overflow: visible; }
.group-head { display: flex; align-items: center; gap: .5rem; padding: .6rem .75rem; border-bottom: 1px solid var(--line); }
.group-head h2 { flex: 1; }
.group-sub { color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.group-none .group-head h2 { color: var(--muted); font-weight: 600; }

.rows { min-height: 8px; }
.rows:empty { min-height: 52px; display: grid; place-items: center; }
.rows:empty::before { content: attr(data-empty-text); color: var(--muted); font-size: .85rem; }

.row {
  display: grid; align-items: center; gap: .25rem .75rem;
  grid-template-columns: 22px 26px minmax(0, 1fr) 110px 120px auto;
  padding: .55rem .75rem; border-top: 1px solid var(--line); background: var(--card);
}
.rows .row:first-child { border-top: 0; }
.row.is-done .name strong { color: var(--muted); }
.row-ghost { opacity: .4; background: var(--accent-soft); }
.name { text-decoration: none; min-width: 0; }
.name strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name:hover strong { text-decoration: underline; text-underline-offset: 2px; }
.meta { color: var(--muted); font-size: .8rem; }
.done { color: var(--ok); }
.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.num .lbl { display: none; }
.weekly { color: var(--muted); font-weight: 500; }
.actions { display: flex; gap: .15rem; justify-content: flex-end; }

.handle { color: var(--muted); cursor: grab; display: grid; place-items: center; touch-action: none; opacity: .55; }
.handle:hover { opacity: 1; }
.ico { width: 18px; height: 18px; fill: currentColor; vertical-align: middle; }
.ico-inline { width: 14px; height: 14px; }
.iconbtn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; color: var(--muted); text-decoration: none; background: none; border: 0; cursor: pointer; }
.iconbtn:hover { background: var(--paper); color: var(--ink); }

.check { display: inline-flex; align-items: center; gap: .45rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); margin: 0; }
@media (prefers-color-scheme: dark) { .check input { accent-color: var(--accent); } }
.selectall { font-weight: 600; padding-left: .75rem; }

.menu { position: relative; }
.menu-panel { position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; display: grid; gap: .5rem; background: var(--card); padding: .7rem; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.18); border: 1px solid var(--line); width: 250px; }
.menu-panel form { display: flex; gap: .4rem; margin: 0; }
.menu-panel input { flex: 1; min-width: 0; }

.hint { color: var(--muted); font-size: .85rem; text-align: center; }

/* Bottom deposit bar ------------------------------------------------------ */
.bottombar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(0,0,0,.06); padding-bottom: env(safe-area-inset-bottom); }
.bottombar-inner { max-width: 960px; margin: 0 auto; padding: .7rem 1rem; display: flex; justify-content: space-between; align-items: center; gap: 1rem; font-variant-numeric: tabular-nums; }

/* Forms & buttons --------------------------------------------------------- */
.btn { display: inline-flex; align-items: center; gap: .35rem; background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 10px; padding: .65rem 1.1rem; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
@media (prefers-color-scheme: dark) { .btn { background: var(--accent); color: #1a1a1a; } }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-sm { padding: .4rem .7rem; font-size: .9rem; }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-danger { background: var(--neg); color: #fff; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; }
.form-grid { display: grid; gap: .9rem; max-width: 520px; }
.form-grid .field { display: grid; gap: .3rem; }
.form-grid label { font-weight: 600; font-size: .9rem; }
.form-grid .help { color: var(--muted); font-size: .8rem; }
.form-grid .errors { color: var(--neg); font-size: .85rem; margin: 0; padding-left: 1rem; }
.field-check { display: flex !important; align-items: center; gap: .5rem; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; align-items: end; }
.form-row .field { display: grid; gap: .25rem; }
.form-row label { font-size: .8rem; color: var(--muted); font-weight: 600; }

.page-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: .5rem; margin-bottom: .5rem; }
.page-head h1 { margin: 0; }
.big-balance { font-size: 1.8rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.subtle { color: var(--muted); }
.back { color: var(--muted); text-decoration: none; font-size: .9rem; display: inline-block; margin-bottom: .5rem; }

table.list { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.list th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: .5rem; border-bottom: 1px solid var(--line); }
table.list td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list td.r, table.list th.r { text-align: right; }
table.list tr:last-child td { border-bottom: 0; }
.tag { display: inline-block; font-size: .72rem; padding: .1rem .45rem; border-radius: 99px; background: var(--paper); color: var(--muted); border: 1px solid var(--line); }
.tag-Y { background: var(--accent-soft); color: var(--ink); border-color: transparent; }
.tag-W { color: var(--ok); }
.credit { color: var(--ok); }

.auth { max-width: 380px; margin: 8vh auto 0; }
.auth h1 { text-align: center; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }

/* Phone layout ------------------------------------------------------------ */
@media (max-width: 680px) {
  .wrap { padding: .75rem; }
  .hide-sm { display: none; }
  .summary { grid-template-columns: 1fr 1fr; }
  .summary .stat:last-child { grid-column: 1 / -1; }
  .stat-value { font-size: 1.25rem; }
  .row {
    grid-template-columns: 22px 26px minmax(0, 1fr) auto;
    grid-template-areas: "h c n b" "h c w a";
    row-gap: 0;
  }
  .row .row-handle { grid-area: h; }
  .row .check { grid-area: c; }
  .row .name { grid-area: n; }
  .row .balance { grid-area: b; }
  .row .weekly { grid-area: w; text-align: left; font-size: .85rem; }
  .row .actions { grid-area: a; }
  .num .lbl { display: inline; font-weight: 400; font-size: .75rem; color: var(--muted); margin-right: .3rem; }
  .balance .lbl { display: none; }
  .iconbtn { width: 32px; height: 30px; }
  table.list .hide-sm { display: none; }
}
.group-none .group-head { padding-left: calc(.75rem + 18px + .5rem); }
.form-row input, .form-row select, .form-grid input:not([type=checkbox]), .form-grid select { width: 100%; min-width: 0; }
.nowrap { white-space: nowrap; }
.card:has(> table.list) { overflow-x: auto; }
@media (max-width: 680px) { table.list td, table.list th { padding: .5rem .35rem; } }

/* Billing ----------------------------------------------------------------- */
.banner { background: var(--accent-soft); color: var(--ink); text-align: center; padding: .55rem 1rem; font-size: .92rem; }
.banner a { font-weight: 700; }
.banner-warn { background: #f7d9d3; }
@media (prefers-color-scheme: dark) { .banner-warn { background: #4a2620; } }
body.readonly .bottombar .btn, body.readonly .actions a[href$="/add/"] { display: none; }
.plans { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .9rem; margin: 1rem 0; }
.plan { text-align: center; }
.plan .price { font-size: 1.6rem; font-weight: 700; margin: .3rem 0 .8rem; }
.plan form { margin: 0; }
.plan .btn { width: 100%; justify-content: center; }
.status-line { font-size: 1.05rem; }

/* Bank import ------------------------------------------------------------- */
.upload { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; }
.bankcheck { display: flex; flex-wrap: wrap; gap: .4rem 1.4rem; align-items: baseline; background: var(--card); border: 1px dashed var(--line);
  border-radius: var(--radius); padding: .6rem 1rem; margin: -.25rem 0 1rem; font-size: .92rem; font-variant-numeric: tabular-nums; }
.bankcheck.ok { border-style: solid; border-color: var(--ok); }
.review { padding: 0; }
.rv-row { display: grid; grid-template-columns: 82px minmax(0,1fr) 100px 220px 190px; gap: .3rem .8rem; align-items: center;
  padding: .6rem .9rem; border-top: 1px solid var(--line); }
.rv-row:first-child { border-top: 0; }
.rv-row.is-auto { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
.rv-desc { min-width: 0; }
.rv-desc strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rv-desc .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rv-amt { text-align: right; }
.rv-choice select { width: 100%; }
.rv-remember { display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; }
.rv-remember .pattern { display: none; font-size: .8rem; padding: .3rem .45rem; font-family: var(--mono); }
.rv-row.remembering .pattern { display: block; }
.rule-row { display: grid; grid-template-columns: minmax(0,1fr) auto minmax(0,1fr) auto auto; gap: .5rem; align-items: center; padding: .4rem 0; border-bottom: 1px solid var(--line); margin: 0; }
.rule-row:last-child { border-bottom: 0; }
.rule-row input[type=text] { font-family: var(--mono); font-size: .85rem; min-width: 0; }
.done-list summary { cursor: pointer; }
@media (max-width: 760px) {
  .rv-row { grid-template-columns: minmax(0,1fr) auto; grid-template-areas: "desc amt" "date date" "choice choice" "rem rem"; }
  .rv-date { grid-area: date; font-size: .8rem; color: var(--muted); order: -1; }
  .rv-desc { grid-area: desc; } .rv-amt { grid-area: amt; } .rv-choice { grid-area: choice; } .rv-remember { grid-area: rem; }
  .rule-row { grid-template-columns: minmax(0,1fr) auto; }
  .rule-row > span { display: none; }
  .rule-row select { grid-column: 1 / 2; }
}

.rv-sched { grid-column: 2 / -1; font-size: .85rem; color: var(--ink); background: var(--accent-soft); padding: .35rem .6rem; border-radius: 8px; }
.rv-sched[hidden] { display: none; }
@media (max-width: 760px) { .rv-sched { grid-column: 1 / -1; } }

/* Weekly-amount suggestions ------------------------------------------------ */
.row .suggest { grid-column: 3 / -1; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: .4rem .8rem; margin: .35rem 0 .1rem; padding: .45rem .7rem; border-radius: 8px; font-size: .85rem; background: var(--accent-soft); }
.row .suggest-down { background: color-mix(in srgb, var(--ok) 12%, transparent); }
.suggest-btns { display: flex; gap: .4rem; }
body.readonly .row .suggest { display: none; }
@media (max-width: 680px) { .row .suggest { grid-column: 1 / -1; } }

/* Help page --------------------------------------------------------------- */
.help { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 2rem; align-items: start; }
.help-toc { position: sticky; top: 72px; font-size: .9rem; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; }
.help-toc ol { margin: .5rem 0 0; padding-left: 1.2rem; display: grid; gap: .3rem; }
.help-toc a { text-decoration: none; color: var(--muted); }
.help-toc a:hover { color: var(--ink); text-decoration: underline; }
.help-body { max-width: 68ch; line-height: 1.6; }
.help-body .lead { font-size: 1.1rem; color: var(--muted); margin-top: -.4rem; }
.help-body section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .4rem 1.3rem 1rem; margin-bottom: 1rem; scroll-margin-top: 72px; }
.help-body h2 { font-size: 1.2rem; margin: .9rem 0 .5rem; }
.help-body h3 { font-size: 1rem; margin: 1.1rem 0 .3rem; }
.help-body li { margin: .25rem 0; }
.help-body .steps > li { margin: .5rem 0; }
.help-body code { font-family: var(--mono); font-size: .85em; background: var(--paper); padding: .05rem .35rem; border-radius: 4px; }
.help-body .kbd { display: inline-block; border: 1px solid var(--line); border-radius: 5px; padding: 0 .35rem; font-size: .85em; background: var(--paper); }
.help-body .tip { background: var(--accent-soft); border-radius: 8px; padding: .6rem .8rem; font-size: .93rem; }
.help-body .example { background: var(--accent-soft); border-radius: 8px; padding: .6rem .8rem; font-size: .9rem; }
.help-body .example .btn { pointer-events: none; margin-left: .3rem; }
.help-body dl.defs dt { font-weight: 700; margin-top: .6rem; }
.help-body dl.defs dd { margin: .1rem 0 0 0; color: var(--ink); }
.help-body details { border-top: 1px solid var(--line); padding: .55rem 0; }
.help-body details:first-of-type { border-top: 0; }
.help-body summary { cursor: pointer; font-weight: 600; }
@media (max-width: 760px) {
  .help { grid-template-columns: 1fr; gap: .8rem; }
  .help-toc { position: static; }
  .help-toc ol { grid-template-columns: 1fr 1fr; column-gap: 1rem; }
  .help-body section { padding: .2rem 1rem .8rem; }
}

@media (max-width: 480px) {
  .brand-word { display: none; }
  .topbar { gap: .6rem; padding-left: .75rem; padding-right: .75rem; }
  .topbar nav { gap: .75rem; font-size: .9rem; }
}

/* Home page (visitors) ------------------------------------------------------ */
.tagline { text-align: center; color: var(--muted); margin: -.6rem 0 1rem; }
.btn-lg { padding: .85rem 1.4rem; font-size: 1.05rem; border-radius: 12px; }
body.landing .wrap { max-width: 1040px; }
.hero { display: grid; grid-template-columns: 1.15fr .85fr; gap: 2.5rem; align-items: center; padding: 2.5rem 0 2rem; }
.hero h1 { font-size: clamp(2rem, 4.2vw, 3.1rem); line-height: 1.08; letter-spacing: -.025em; margin: 0 0 .8rem; }
.hero-sub { font-size: 1.2rem; color: var(--muted); margin: 0 0 1.5rem; max-width: 34ch; }
.hero-cta { display: flex; gap: .7rem; flex-wrap: wrap; }
.hero-note { color: var(--muted); font-size: .9rem; margin-top: .8rem; }
.hero-pots { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 1.1rem 1.2rem; box-shadow: 0 12px 40px rgba(29,36,34,.08);
  display: grid; gap: .55rem; transform: rotate(1.2deg); }
.pot { display: grid; grid-template-columns: 1fr auto; gap: .25rem .8rem; font-size: .95rem; }
.pot b { font-variant-numeric: tabular-nums; }
.pot i { grid-column: 1 / -1; height: 7px; border-radius: 99px; background: var(--paper); position: relative; overflow: hidden; }
.pot i::after { content: ""; position: absolute; inset: 0 auto 0 0; width: var(--fill); background: var(--brand); border-radius: inherit; }
.pot-misc i::after { background: var(--accent); }
.pot-misc span, .pot-misc b { color: var(--ink); font-weight: 700; }
.pot-caption { font-size: .82rem; color: var(--muted); border-top: 1px dashed var(--line); padding-top: .55rem; margin-top: .2rem; }
@media (prefers-color-scheme: dark) { .pot i::after { background: var(--ok); } .pot-misc i::after { background: var(--accent); } }

.story { max-width: 62ch; margin: 1.5rem auto 2.5rem; font-size: 1.12rem; line-height: 1.7; border-left: 4px solid var(--accent); padding: .2rem 0 .2rem 1.4rem; }
.story p { margin: 0 0 1rem; }
.story-key { font-weight: 700; font-size: 1.2rem; }
.story-sign { font-style: italic; color: var(--muted); }
.story-sign::before { content: "— "; }

.how { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 1.4rem 1.6rem; max-width: 820px; margin: 0 auto 2rem; }
.how h2 { font-size: 1.3rem; margin: 0 0 .8rem; }
.how ol { counter-reset: step; list-style: none; padding: 0; margin: 0; display: grid; gap: .9rem; }
.how li { counter-increment: step; display: grid; grid-template-columns: 2.2rem 1fr; gap: .8rem; align-items: center; line-height: 1.5; }
.how li::before { content: counter(step); display: grid; place-items: center; width: 2.2rem; height: 2.2rem; border-radius: 50%; background: var(--accent-soft); font-weight: 800; }
.how-more { margin: 1rem 0 0; }
.cta-end { text-align: center; margin: 2.5rem 0 3rem; }
.cta-end .subtle { margin-top: .7rem; }

@media (max-width: 760px) {
  .hero { grid-template-columns: 1fr; gap: 1.6rem; padding: 1.2rem 0 1rem; }
  .hero-pots { transform: none; }
  .story { font-size: 1.04rem; padding-left: 1rem; }
  .how { padding: 1.1rem 1.1rem; }
}
