/* Spend: one dark, phone-first sheet. No outside fonts (CSP font-src 'none'). */
:root {
    --bg: #14171a;
    --card: #1d2125;
    --line: #2c3238;
    --text: #e8eaec;
    --dim: #9aa3ab;
    --ok: #3fb68b;
    --warn: #e8b34a;
    --bad: #e5534b;
    /* Within 10% of a goal (rollup.js goalStatus): a clear yellow, more
       yellow than the amber of --warn. About 9:1 on --card and --bg. The app
       has one dark theme (color-scheme: dark), so no light value is needed. */
    --near: #e2c83a;
    --radius: 10px;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-text-size-adjust: 100%;
}

.wrap {
    max-width: 560px;
    margin: 0 auto;
    padding: env(safe-area-inset-top) 12px calc(24px + env(safe-area-inset-bottom));
}

a { color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
h1 { font-size: 1.1rem; flex: 1; }
h2 { font-size: 1.05rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--dim); margin: 20px 0 8px; }

.topbar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 0;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 2;
}
.brand { font-weight: 700; color: var(--ok); margin-right: 4px; }

button, .icon {
    font: inherit;
    color: var(--text);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 8px 14px;
    cursor: pointer;
}
button:disabled { opacity: .4; cursor: default; }
.icon {
    min-width: 40px;
    height: 40px;
    padding: 0 10px;
    display: inline-grid;
    place-items: center;
    text-decoration: none;
    font-size: 1.1rem;
}
.primary { background: var(--ok); border-color: var(--ok); color: #0b1410; font-weight: 600; }
.danger { border-color: var(--bad); color: var(--bad); }

.notice { padding: 10px 12px; border-radius: var(--radius); margin: 8px 0; border: 1px solid var(--line); }
.notice.warn { border-color: var(--warn); color: var(--warn); }
.notice.error { border-color: var(--bad); color: var(--bad); }
.notice.info { color: var(--dim); }

.asof { color: var(--dim); font-size: .85rem; margin: 0 0 8px; }
.asof.stale { color: var(--warn); }
.tag {
    display: inline-block;
    margin-left: 6px;
    padding: 0 6px;
    border: 1px solid var(--line);
    border-radius: 6px;
    font-size: .75rem;
}

.sub { color: var(--dim); font-weight: 400; }

/* The period bar: first on the spending screens, a full-width control. */
.periodbar { margin: 4px 0 12px; }
.periodrow { display: flex; gap: 6px; align-items: stretch; }
.monthpick {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px;
    background: var(--card);
    border: 2px solid var(--line);
    border-radius: var(--radius);
}
.monthpick.is-active { border-color: var(--ok); }
.monthpick .step { flex: none; font-size: 1.5rem; width: 44px; height: 48px; }
.monthname {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 2px 4px;
    background: transparent;
    border: 0;
}
.mlabel { font-size: 1.4rem; font-weight: 700; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.monthpick:not(.is-active) .mlabel { color: var(--dim); font-weight: 500; }
.monthname .sub { font-size: .8rem; }
.twelve {
    flex: none;
    width: 6.5em;
    padding: 4px 8px;
    border: 2px solid var(--line);
    background: transparent;
    color: var(--dim);
    font-size: .9rem;
    line-height: 1.2;
}
.twelve.is-active { background: var(--card); color: var(--text); border-color: var(--ok); font-weight: 600; }
.period-range { margin: 6px 0 0; text-align: center; color: var(--dim); font-size: .9rem; }

/* The Accounts page. */
.acct-name { display: flex; flex-direction: column; min-width: 0; }
.acct-inst { color: var(--dim); font-size: .8rem; font-weight: 400; }
.mask, .owed { color: var(--dim); }
.icon.text { font-size: .85rem; padding: 0 10px; }

.summary { color: var(--dim); margin: 4px 0 12px; font-size: .9rem; }
.over { color: var(--bad); font-weight: 600; }
.near { color: var(--near); font-weight: 600; }
.left { color: var(--dim); }

/* The summary under the period bar (and the plan / outside subtotals):
   Spent / Goal / Over side by side, each with its unit, and one bar of spent
   against the goal with the goal as a line. Yellow within 10%, red over 10%. */
.figs { margin: 12px 0 8px; }
.figrow { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.fig { display: flex; flex-direction: column; min-width: 0; }
.fig-label { color: var(--dim); font-size: .8rem; }
.fig-main { font-size: clamp(.95rem, 4.6vw, 1.35rem); font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.fig-main.dim { color: var(--dim); font-weight: 400; }
.fig-sub { color: var(--dim); font-size: .8rem; font-variant-numeric: tabular-nums; }
.fig.over .fig-main, .fig.over .fig-sub { color: var(--bad); }
.fig.near .fig-main, .fig.near .fig-sub { color: var(--near); }
.figbar { position: relative; height: 10px; margin-top: 10px; background: var(--line); border-radius: 4px; }
.figbar .fill { height: 100%; background: var(--ok); border-radius: 4px; }
.figs.is-over .figbar .fill { background: var(--bad); }
.figs.is-near .figbar .fill { background: var(--near); }
.figbar .goalmark {
    position: absolute; top: -4px; bottom: -4px; width: 2px; margin-left: -1px; background: var(--text);
}
.figs.small { margin: 6px 0 0; }
.figs.small .fig-main { font-size: 1rem; }
.figs.small .figbar { height: 8px; margin-top: 8px; }
.proposed-note { margin: 0 0 8px; }

.list { display: grid; gap: 8px; }
.cat {
    display: block;
    text-decoration: none;
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 12px;
}
.cat.is-over { border-color: var(--bad); }
.cat.is-near { border-color: var(--near); }
.cat-top, .cat-foot { display: flex; justify-content: space-between; gap: 8px; }
.cat-name { font-weight: 500; }
.cat-amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.of { color: var(--dim); }
.cat-foot { font-size: .8rem; margin-top: 4px; }
.pctx { color: var(--dim); }

.cat .bar {
    position: relative;
    height: 8px;
    margin-top: 8px;
    padding: 0;
    background: var(--line);
    border-radius: 4px;
    overflow: visible;
    z-index: auto;
}
.cat .bar .fill { height: 100%; background: var(--ok); border-radius: 4px; }
.cat.is-over .bar .fill { background: var(--bad); }
.cat.is-near .bar .fill { background: var(--near); }
.cat .bar .pace {
    position: absolute;
    top: -3px;
    bottom: -3px;
    width: 2px;
    margin-left: -1px;
    background: var(--text);
    opacity: .6;
}

.toggle { display: flex; align-items: center; gap: 8px; margin: 20px 0 8px; color: var(--dim); font-size: .9rem; }
.toggle input { width: 20px; height: 20px; }

.empty, .note { color: var(--dim); }
.note { font-size: .85rem; }

.cat-month { margin: 4px 0; }
.rows { width: 100%; border-collapse: collapse; font-size: .9rem; }
.rows th, .rows td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.rows th { color: var(--dim); font-weight: 500; font-size: .8rem; }
.rows .n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.history { display: grid; gap: 4px; }
.hrow {
    display: grid;
    grid-template-columns: 5.5em 1fr 5.5em;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: transparent;
    border: 1px solid transparent;
    text-align: left;
}
.hrow.is-current { border-color: var(--line); background: var(--card); }
.hlabel { color: var(--dim); font-size: .85rem; }
.hbar { position: relative; height: 10px; background: var(--line); border-radius: 4px; }
.hbar .fill { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.hrow.is-over .hbar .fill { background: var(--bad); }
.hrow.is-near .hbar .fill { background: var(--near); }
.hbar .goal { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--warn); }
.hamt { text-align: right; font-variant-numeric: tabular-nums; }

.setup-screen p { max-width: 40em; }
.setup { display: grid; gap: 8px; margin: 16px 0; }
.setup input {
    font: inherit;
    color: var(--text);
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 10px 12px;
}
.scan-box { display: grid; gap: 8px; }
.scan { width: 100%; border-radius: var(--radius); background: #000; }
.npub { font-family: ui-monospace, monospace; font-size: .8rem; word-break: break-all; color: var(--dim); }

/* Budget view: tabs, the "more" fold, "Not sorted yet" and the month total. */
.tabs { display: flex; gap: 6px; margin: 8px 0 4px; }
.tab {
    flex: 1;
    text-align: center;
    text-decoration: none;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--dim);
    font-size: .9rem;
}
.tab.is-active { background: var(--card); color: var(--text); border-color: var(--ok); }
.status { font-size: .85rem; }
.cat-name .tag { color: var(--warn); border-color: var(--warn); font-weight: 400; }
details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
details.more > summary { color: var(--dim); font-size: .9rem; padding: 6px 2px; }
details.more > summary::before { content: "▸ "; }
details[open].more > summary::before { content: "▾ "; }
details.more > .list { margin-top: 8px; }
.cat.total { border-color: var(--dim); }
.cat.total.is-over { border-color: var(--bad); }
.cat.total.is-near { border-color: var(--near); }
.cat.total .cat-name { font-weight: 600; }

/* Plan total note, yearly bills, outside lines and "Not spending". */
.cat-note { color: var(--dim); font-size: .8rem; margin-top: 4px; }
.paid { color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 0 6px; }
.list.below { margin-top: 20px; }
details.notspending > summary .cat-name::before { content: "▸ "; }
details[open].notspending > summary .cat-name::before { content: "▾ "; }
.notspending > summary > span { display: flex; }
.notspending .groups { margin-top: 8px; }
.cat.group { background: var(--bg); }

/* Period switch (budget screen) and sort switch (transactions). */
.period { display: flex; gap: 6px; margin: 16px 0 0; }
.seg {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: transparent;
    color: var(--dim);
    font-size: .9rem;
}
.seg.is-active { background: var(--card); color: var(--text); border-color: var(--ok); }
.period.sort { margin: 8px 0; }

/* Transactions: the drill-down list. */
.tx-head strong { color: var(--text); font-weight: 600; }
.tx-note { margin: 0 0 4px; }
.txlist { display: grid; gap: 4px; }
.tx { padding: 8px 2px; border-bottom: 1px solid var(--line); }
.tx-top { display: flex; justify-content: space-between; gap: 8px; }
.tx-name { overflow: hidden; text-overflow: ellipsis; }
.tx-amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.tx.is-in .tx-amt { color: var(--ok); }
.tx-foot { display: flex; flex-wrap: wrap; gap: 4px 10px; color: var(--dim); font-size: .8rem; margin-top: 2px; }
.more-link { color: var(--ok); font-size: .9rem; }

/* ADD TO HOME SCREEN card (js/pwa-install.js decides when it shows). */
.install-card {
    background: var(--card);
    border: 1px solid var(--ok);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin: 8px 0 12px;
}
.install-card h2 { font-size: .9rem; letter-spacing: .06em; color: var(--ok); }
.install-card p { margin: 8px 0; }
.install-card ol { margin: 8px 0; padding-left: 22px; }
.install-card li { margin: 4px 0; }
.install-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
