/* Billy identity v1.0: Ink, Paper, Ledger, Mint, Rust, Tide (+ Stone, Rule, Card, Night). */
:root {
  --paper: #F6F7F4;      /* Paper: background, never pure white */
  --ink: #17231F;        /* Ink: text, app tile, theme */
  --muted: #6B7570;      /* Stone */
  --rule: #D8DDD9;       /* Rule */
  --card: #FFFFFF;       /* Card */
  --paid: #1E7A58;       /* Ledger: paid on light, the tick, progress */
  --paid-soft: #E4F1EA;
  --due: #A8492B;        /* Rust: still to pay, used sparingly */
  --due-soft: #F6E6DF;
  --pending-soft: #FBF4EA;
  --focus: #4FBF90;      /* Mint */
  --series: #2D6E8E;     /* Tide: charts and data series */
  --series-soft: #AFCAD8;
  --font-display: "Bricolage Grotesque", "Avenir Next", system-ui, sans-serif;
  --font-ui: "Figtree", "Avenir Next", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121816;    /* Night */
    --ink: #F6F7F4; --muted: #98A39D; --rule: #2B3531; --card: #1A211E;
    --paid: #4FBF90;     /* Mint: paid on dark */
    --paid-soft: #1C3A2D;
    --due: #E48A6A;      /* lighter rust for dark */
    --due-soft: #3D2419; --pending-soft: #2A2620;
    --focus: #4FBF90;
    --series: #6DB0D2; --series-soft: #2C4553;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--font-ui); font-size: 16px;
  -webkit-tap-highlight-color: transparent; }
body { padding: 16px 16px 100px; max-width: 560px; margin: 0 auto; padding-top: calc(16px + env(safe-area-inset-top)); }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, li:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
input, select { font: inherit; color: var(--ink); background: var(--card); }

/* Tabs */
.tabs { display: flex; gap: 4px; background: var(--rule); padding: 4px; border-radius: 12px; margin-bottom: 18px; }
.tabs button { flex: 1; border: none; background: transparent; padding: 8px; border-radius: 9px; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--card); color: var(--ink); }

/* Header */
.month-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.month-row h1 { font-family: var(--font-display); font-size: 1.6rem; letter-spacing: -0.02em; margin: 0; }
.month-row select { border: none; background: transparent; font-weight: 600; font-size: 1.1rem; padding: 4px 0; text-align: center; flex: 1; }
.month-row .nav { border: 1px solid var(--rule); background: var(--card); border-radius: 10px; width: 36px; height: 36px; font-size: 1.3rem; line-height: 1; flex: none; }
.month-row .nav:disabled { opacity: .35; cursor: default; }
.month-row { align-items: center; }
.remaining { margin-top: 10px; }
.remaining .big { font-family: var(--font-display); font-size: 2.75rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.remaining .big.done { color: var(--paid); }
.remaining .sub { color: var(--muted); font-size: 0.9rem; margin-top: 6px; }
.bar { height: 6px; background: var(--rule); border-radius: 3px; margin-top: 12px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--paid); width: 0; transition: width .25s ease; }
@media (prefers-reduced-motion: reduce) { .bar span { transition: none; } }

/* Account sections */
section { margin-top: 22px; }
.acct { display: flex; justify-content: space-between; align-items: baseline; padding: 0 4px 8px; gap: 8px; }
.acct h2 { font-size: 1rem; font-weight: 600; margin: 0; }
.acct .tally { font-size: 0.85rem; color: var(--muted); font-variant-numeric: tabular-nums; text-align: right; }
.acct .tally.done { color: var(--paid); }
ul { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 12px; overflow: hidden; border: 1px solid var(--rule); }
li { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-top: 1px solid var(--rule); user-select: none; -webkit-user-select: none; }
li.row { cursor: pointer; }
li:first-child { border-top: none; }
li .box { width: 24px; height: 24px; border-radius: 7px; border: 2px solid var(--rule); flex: none; display: grid; place-items: center; color: white; font-size: 15px; }
li.paid .box { background: var(--paid); border-color: var(--paid); }
li .name { flex: 1; min-width: 0; }
li .name small { display: block; font-size: 0.75rem; color: var(--muted); text-decoration: none; }
li.paid .name { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--rule); }
li .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
li.paid .amt { color: var(--muted); }
li.confirm { background: var(--pending-soft); }
li .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--due); flex: none; margin: 0 7px; }
li input { padding: 6px 8px; border: 1px solid var(--rule); border-radius: 8px; min-width: 0; }
li input.name { flex: 1; }
li input.amt { width: 110px; text-align: right; }
li .ok { border: none; background: var(--ink); color: var(--paper); border-radius: 8px; padding: 8px 12px; font-weight: 600; }
li .vt { border: 1px solid var(--rule); background: transparent; color: var(--muted); border-radius: 8px; padding: 6px 8px; font-size: 0.8rem; flex: none; }
li .vt.on { background: var(--due-soft); color: var(--due); border-color: transparent; }
li .del { border: none; background: var(--due-soft); color: var(--due); border-radius: 8px; width: 32px; height: 32px; font-size: 18px; flex: none; }
.add { width: 100%; border: 1px dashed var(--rule); background: transparent; color: var(--muted); padding: 10px; border-radius: 12px; margin-top: 8px; }

/* History */
.hist-months li { display: grid; grid-template-columns: 1fr auto; row-gap: 2px; cursor: pointer; }
.hist-months .m { font-weight: 600; }
.hist-months .r { text-align: right; font-variant-numeric: tabular-nums; }
.hist-months .s { grid-column: 1 / -1; font-size: 0.85rem; color: var(--muted); }
.hist-months .s b { color: var(--paid); font-weight: 600; }
.hist-months .s i { color: var(--due); font-style: normal; font-weight: 600; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--rule); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { padding: 10px 12px; text-align: right; white-space: nowrap; border-top: 1px solid var(--rule); font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-weight: 600; border-top: none; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); }
tr.total td { font-weight: 700; }
.help { color: var(--muted); font-size: 0.9rem; line-height: 1.45; margin: 6px 4px 0; }
.ghost { border: 1px solid var(--rule); background: var(--card); padding: 12px; border-radius: 12px; font-weight: 600; width: 100%; margin-top: 8px; }

/* Footer */
footer { position: fixed; left: 0; right: 0; bottom: 0; background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(8px); border-top: 1px solid var(--rule); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
.actions { max-width: 560px; margin: 0 auto; display: flex; gap: 10px; }
.actions button { flex: 1; font-weight: 600; padding: 12px; border-radius: 12px; border: 1px solid var(--rule); background: var(--card); }
.actions button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.status { color: var(--muted); font-size: 0.85rem; text-align: center; padding: 24px; }
.toast { position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 14px; border-radius: 10px; font-size: 0.9rem; opacity: 0; pointer-events: none; transition: opacity .2s; }
.toast.show { opacity: 1; }
.hidden { display: none !important; }

/* Sign-in */
.signin-card { margin: 12vh auto 0; max-width: 380px; }
.signin-card .lockup img { display: block; width: 136px; height: auto; margin-bottom: 40px; }
.signin-card h1 { font-family: var(--font-display); font-size: 2.4rem; line-height: 1.02; letter-spacing: -0.02em; margin: 0 0 14px; }
.signin-card p { color: var(--muted); margin: 0 0 28px; line-height: 1.45; }
.signin-card button { width: 100%; padding: 13px; border-radius: 12px; border: 1px solid var(--rule); background: var(--card); font-weight: 600; margin-top: 10px; }
.signin-card button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.signin-card button:disabled { opacity: .5; cursor: default; }
.userbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; font-size: 0.9rem; color: var(--muted); margin: 0 2px 16px; }
.userbar .lockup img { display: block; width: 98px; height: auto; }
.userbar button { border: none; background: transparent; color: var(--muted); text-decoration: underline; padding: 4px; }

/* Shared bits */
.muted { color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--rule); border-radius: 12px; }
.card.pad { padding: 10px 12px; }
select.full { width: 100%; border: none; padding: 6px 0; }
.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 22px; }
.stack .ghost { margin-top: 0; }
.ghost.danger, .link.danger { color: var(--due); }
.link { border: none; background: transparent; color: var(--ink); text-decoration: underline; padding: 4px; font-weight: 600; }
.chip { border: 1px solid var(--rule); background: transparent; color: var(--ink); border-radius: 8px; padding: 6px 10px; font-size: 0.85rem; flex: none; }
li .editlink { text-align: left; border: none; background: transparent; padding: 0; font-weight: 500; }
li .editlink small { text-decoration: underline; }
header.month-row { margin-bottom: 4px; }
.banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: var(--pending-soft); border: 1px solid var(--rule);
  border-radius: 12px; padding: 12px 14px; margin-top: 18px; font-size: 0.92rem; }
.banner button { border: none; background: var(--ink); color: var(--paper); border-radius: 9px; padding: 9px 12px; font-weight: 600; flex: none; }
.empty { text-align: center; padding: 28px 8px; }
.empty h2 { margin: 0 0 8px; font-family: var(--font-display); font-size: 1.6rem; letter-spacing: -0.02em; }
.empty p { color: var(--muted); line-height: 1.45; margin: 0 0 16px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; padding: 12px; border: 1px solid var(--rule); border-radius: 12px; }
.inline-form button { border: none; background: var(--ink); color: var(--paper); border-radius: 12px; padding: 12px 14px; font-weight: 600; }

/* Dialog */
dialog { border: 1px solid var(--rule); border-radius: 16px; background: var(--card); color: var(--ink); padding: 20px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 0.4); }
dialog h2 { margin: 0 0 14px; font-family: var(--font-display); font-size: 1.4rem; letter-spacing: -0.02em; }
dialog label { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
dialog label input, dialog label select { font-size: 1rem; font-weight: 400; padding: 10px; border: 1px solid var(--rule); border-radius: 10px; color: var(--ink); background: var(--card); }
dialog label.check { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--ink); font-weight: 500; font-size: 0.95rem; }
dialog label.check input { width: 20px; height: 20px; padding: 0; }
dialog label.check small { flex-basis: 100%; color: var(--muted); font-weight: 400; padding-left: 28px; }
.dialog-actions { display: flex; gap: 10px; margin-top: 8px; }
.dialog-actions button { flex: 1; padding: 12px; border-radius: 12px; border: 1px solid var(--rule); background: var(--card); font-weight: 600; }
.dialog-actions button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.dialog-delete { display: block; margin: 0 0 8px; }

/* History extras */
.hist-months .s.d:empty { display: none; }
.delta { font-size: 0.82rem; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--due); }
.delta.down { color: var(--paid); }
.delta.flat { color: var(--muted); font-weight: 500; }
th[scope="row"] { text-align: left; font-weight: 500; color: var(--ink); position: sticky; left: 0; background: var(--card); border-top: 1px solid var(--rule); }
tr.total th[scope="row"] { font-weight: 700; }

/* Insights */
.seg { display: inline-flex; gap: 4px; background: var(--rule); padding: 3px; border-radius: 10px; }
.seg button { border: none; background: transparent; padding: 6px 14px; border-radius: 8px; font-weight: 600; color: var(--muted); font-size: 0.85rem; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.kpi { background: var(--card); border: 1px solid var(--rule); border-radius: 12px; padding: 12px; min-width: 0; }
.kpi .k { font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.kpi .v { font-family: var(--font-display); letter-spacing: -0.02em; font-size: clamp(1rem, 4.6vw, 1.35rem); font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi .s { font-size: 0.8rem; margin-top: 4px; }
.chart { position: relative; padding: 4px 0; overflow: hidden; }
.chart svg { display: block; }
.chart .grid { stroke: var(--rule); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .axis.strong { fill: var(--ink); font-weight: 700; }
.chart .bar { fill: var(--series-soft); }
.chart .bar.sel { fill: var(--series); }
.chart .avg { stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart .hit { fill: transparent; cursor: pointer; outline: none; }
.chart .hit:focus-visible { fill: color-mix(in srgb, var(--focus) 18%, transparent); }
.chart .tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--paper); border-radius: 8px; padding: 8px 10px;
  font-size: 0.8rem; line-height: 1.35; white-space: nowrap; font-variant-numeric: tabular-nums; }
.chart .tip .muted { color: color-mix(in srgb, var(--paper) 70%, transparent); }
.as-table { margin-top: 8px; }
.as-table summary { color: var(--muted); font-size: 0.85rem; cursor: pointer; padding: 4px; }
.breakdown li { display: block; }
.breakdown .line { display: flex; justify-content: space-between; gap: 10px; }
.breakdown .line .amt { font-variant-numeric: tabular-nums; }
.hbar { height: 6px; background: var(--rule); border-radius: 3px; margin: 8px 0 6px; overflow: hidden; }
.hbar span { display: block; height: 100%; background: var(--series); border-radius: 3px; }
.breakdown .meta { display: flex; justify-content: space-between; gap: 10px; font-size: 0.8rem; }
.changes li { justify-content: space-between; }
@media (max-width: 360px) { .kpis { grid-template-columns: 1fr; } }

/* Tabular figures for every amount */
.amt, .tally, .r, td, .delta, .kpi .v, .remaining .sub { font-variant-numeric: tabular-nums; }
.chart .axis { font-family: var(--font-ui); }
/* Boot: same layout as sign-in so loading and errors stay on-brand */
.boot .boot-loading { color: var(--muted); margin: 0; }
.boot h1 { font-size: 1.9rem; }
