/* pXpnsP: mobile first (360px and up), a sidebar from 900px; light and dark
   follow the device unless Settings chooses one (data-theme on <html>). */
:root {
  --bg: #f4f6f7; --fg: #1b2226; --muted: #56636b; --card: #ffffff; --line: #d9dfe3;
  --accent: #1f4e5f; --accent-fg: #ffffff; --ok: #23703f; --warn: #8f5100; --neg: #a8322a; --pos: #23703f;
  --focus: #1a73e8; --banner: #fff4d6; --banner-fg: #5a4300; --bar: #7fb0c1;
  --c-income: #3987e5; --c-spend: #d95926; --c-budget: #1b2226;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11161a; --fg: #e6ebee; --muted: #9eabb3; --card: #1a2126; --line: #2c363d;
    --accent: #86c0d4; --accent-fg: #0d1b21; --ok: #74c98f; --warn: #f2b65c; --neg: #ff8a80; --pos: #74c98f;
    --focus: #8ab4f8; --banner: #3a3015; --banner-fg: #f6e3a6; --bar: #3f7385;
    --c-income: #6aa8f0; --c-spend: #ec8455; --c-budget: #e6ebee;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11161a; --fg: #e6ebee; --muted: #9eabb3; --card: #1a2126; --line: #2c363d;
  --accent: #86c0d4; --accent-fg: #0d1b21; --ok: #74c98f; --warn: #f2b65c; --neg: #ff8a80; --pos: #74c98f;
  --focus: #8ab4f8; --banner: #3a3015; --banner-fg: #f6e3a6; --bar: #3f7385;
  --c-income: #6aa8f0; --c-spend: #ec8455; --c-budget: #e6ebee;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: 8px; top: -48px; background: var(--card); padding: 8px 12px; border-radius: 8px; z-index: 30; }
.skip:focus { top: 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.ok { color: var(--ok); }
.warn { color: var(--warn); }

header.top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 12px 16px calc(4px); padding-top: calc(12px + env(safe-area-inset-top)); }
.brand { font-weight: 700; font-size: 20px; color: var(--accent); }

/* Bottom bar on a phone: Home, Ledger, Add, Accounts, More. */
nav#nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom); }
nav#nav a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 2px; min-height: 56px; text-decoration: none; color: var(--muted); font-size: 12px; }
nav#nav a .icon { font-size: 20px; line-height: 28px; height: 28px; display: grid; place-items: center; }
nav#nav a[aria-current="page"] { color: var(--accent); font-weight: 600; }
nav#nav a.add .icon { background: var(--accent); color: var(--accent-fg); border-radius: 999px; width: 28px; height: 28px; display: grid; place-items: center; font-weight: 700; }
nav#nav a.wide { display: none; }

main { max-width: 760px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }
main:focus { outline: none; }
h1 { font-size: 24px; margin: 8px 0 12px; }
h1:focus { outline: none; }
h2 { font-size: 17px; margin: 0 0 8px; }
h3 { font-size: 15px; margin: 14px 0 6px; color: var(--muted); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin: 0 0 14px; }

#banner .banner { max-width: 760px; margin: 0 auto 10px; padding: 8px 16px; background: var(--banner); color: var(--banner-fg); font-size: 14px; border-radius: 0; }

ul.list { list-style: none; margin: 0; padding: 0; }
ul.list > li { display: flex; align-items: baseline; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); }
ul.list > li:first-child { border-top: 0; }
ul.list.big > li a { display: block; padding: 6px 0; font-size: 18px; }
.grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--neg); }
.pos { color: var(--pos); }
ul.totals > li { font-size: 15px; }
.bar { display: block; height: 6px; background: var(--line); border-radius: 3px; margin-top: 4px; }
.bar > span { display: block; height: 6px; background: var(--bar); border-radius: 3px; }
.badge { display: inline-block; margin-left: 8px; padding: 0 6px; border-radius: 6px; background: var(--banner); color: var(--banner-fg); font-size: 12px; }

/* Forms */
.grid { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
.field { margin: 0 0 10px; min-width: 0; }
.field label, fieldset legend { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
input[type="text"], input[type="search"], input[type="date"], input[type="month"], input[type="number"], input[type="file"], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 10px; font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
input.ccy { text-transform: uppercase; }
input[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--neg); border-width: 2px; }
.field .error { color: var(--neg); font-size: 14px; min-height: 0; }
.field .hint { color: var(--muted); font-size: 13px; margin-top: 2px; }
.check { display: flex; align-items: center; gap: 10px; margin: 6px 0 10px; }
.check input { width: 22px; height: 22px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; margin: 0 0 12px; padding: 10px 12px 4px; min-width: 0; }
fieldset.kinds { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px; }
fieldset.kinds legend { padding: 0 4px; }
.seg { flex: 1; }
.seg input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.seg label { display: block; text-align: center; padding: 10px 6px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; color: var(--fg); margin: 0; font-size: 15px; }
.seg input:checked + label { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.seg input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 2px; }
.note { font-size: 14px; color: var(--muted); margin: 0 0 10px; min-height: 0; }
.summary:not(:empty) { background: var(--card); background: color-mix(in srgb, var(--neg) 12%, var(--card)); color: var(--fg); border-left: 4px solid var(--neg); padding: 10px 12px; border-radius: 8px; margin: 0 0 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; margin-top: 6px; }
button, .button { min-height: 44px; padding: 10px 16px; font: inherit; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--fg); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; }
button.primary, .button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--neg); border-color: var(--neg); }
button.link { border: 0; background: none; color: var(--accent); padding: 4px 0; min-height: 32px; }
button:disabled { opacity: 0.5; cursor: default; }
.fx { background: var(--bg); }

/* Ledger rows */
ul.rows { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
li.row { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-top: 1px solid var(--line); }
li.row:first-child { border-top: 0; }
.row-main { flex: 1; min-width: 0; text-decoration: none; color: var(--fg); display: block; }
.row-top { display: flex; gap: 8px; justify-content: space-between; align-items: baseline; }
.row-top .payee { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.row-sub > span:first-child { min-width: 0; overflow-wrap: anywhere; }
.run { white-space: nowrap; }
button.status { min-width: 44px; min-height: 44px; padding: 0; font-weight: 700; border-radius: 999px; }
button.status.cleared { color: var(--ok); border-color: var(--ok); }
button.status.reconciled { background: var(--ok); color: var(--card); border-color: var(--ok); }
.filters .grid { grid-template-columns: 1fr 1fr; }
.filters .grid > .field:last-child { grid-column: 1 / -1; }

/* Part B: reconcile, bills, pockets, budget */
.block { display: block; }
.center { text-align: center; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 14px; }
textarea { min-height: 88px; resize: vertical; }
ul.ticks li.row { gap: 10px; }
ul.ticks input[type="checkbox"], ul.list input[type="checkbox"] { width: 22px; height: 22px; flex: none; }
ul.ticks label { cursor: pointer; min-width: 0; overflow-wrap: anywhere; }
.recon-panel li.ok strong { color: var(--ok); }
.recon-panel li.neg strong { color: var(--neg); }
.actions.sticky { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); background: var(--bg); padding: 8px 0; z-index: 5; }
nav.period { display: flex; align-items: center; gap: 10px; margin: 0 0 6px; }
li.budget-row.sub { padding-left: 14px; }
li.budget-row.state-over .bar > span { background: var(--neg); }
li.budget-row.state-near .bar > span { background: var(--warn); }
li.budget-row.state-under .bar > span { background: var(--ok); }
li.budget-row.state-over { border-left: 4px solid var(--neg); padding-left: 8px; }
li.budget-row.sub.state-over { padding-left: 18px; }
ul.list > li.total { border-top: 2px solid var(--line); }
li.pocket .bar { margin: 4px 0; }
form.pay fieldset .check { margin: 4px 0; }

/* Phase 4: backup, restore, the device lock */
body[data-lock="locked"] nav#nav { display: none; }
body[data-lock="locked"] main { padding-bottom: 32px; }
.card.notice { border-left: 4px solid var(--warn); }
details > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; }
input[type="password"] { width: 100%; min-height: 44px; padding: 8px 10px; font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
button.block { width: 100%; }
[data-role="restore-preview"] ul.list > li { flex-wrap: wrap; }

/* Dialogs and toasts */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; z-index: 40; padding: 16px; }
.dialog { background: var(--card); color: var(--fg); border-radius: 12px; padding: 16px; max-width: 460px; width: 100%; }
.toasts { position: fixed; left: 16px; right: 16px; bottom: calc(72px + env(safe-area-inset-bottom)); z-index: 30; display: grid; gap: 8px; pointer-events: none; }
.toast { background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-size: 15px; max-width: 520px; margin: 0 auto; }
.toast.error { background: var(--neg); color: #fff; }

@media (min-width: 560px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .filters .grid { grid-template-columns: repeat(4, 1fr); }
  .amount-row { grid-template-columns: 2fr 1fr; }
}
/* A sidebar on a desktop, with every screen in it. */
@media (min-width: 900px) {
  nav#nav { top: 0; right: auto; width: 200px; flex-direction: column; border-top: 0; border-right: 1px solid var(--line); padding-top: 64px; overflow-y: auto; }
  .actions.sticky { bottom: 0; }
  nav#nav a { flex: none; flex-direction: row; justify-content: flex-start; gap: 10px; padding: 10px 18px; font-size: 15px; min-height: 44px; }
  nav#nav a.wide { display: flex; }
  nav#nav a.narrow { display: none; }
  header.top, #banner, #update, main { margin-left: 200px; }
  body[data-lock="locked"] header.top, body[data-lock="locked"] #banner, body[data-lock="locked"] #update, body[data-lock="locked"] main { margin-left: auto; }
  main { padding-bottom: 32px; }
  header.top { position: relative; z-index: 21; }
  .toasts { bottom: 16px; }
}

/* ── phase 6: reports and portfolio ── */
nav.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
nav.tabs a { padding: 8px 12px; min-height: 40px; border: 1px solid var(--line); border-radius: 999px; text-decoration: none; color: var(--fg); background: var(--card); }
nav.tabs a[aria-current="page"] { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.scroll-x { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }
table.data { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; font-size: 14px; }
table.data caption { text-align: left; font-weight: 600; padding: 4px 0 6px; }
table.data th, table.data td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data .n { text-align: right; white-space: nowrap; }
table.data tfoot th, table.data tfoot td { font-weight: 700; }
table.data td input { width: 5.5em; min-height: 36px; text-align: right; }
.pos { color: var(--pos); }
.chart-wrap { overflow-x: auto; max-width: 100%; }
svg.chart { display: block; min-width: 320px; height: auto; color: var(--fg); }
svg.chart .grid { stroke: var(--line); stroke-width: 1; }
svg.chart .axis { fill: var(--muted); font-size: 11px; }
svg.chart .bar.spend { fill: var(--c-spend); }
svg.chart .bar.income { fill: var(--c-income); }
svg.chart .budget-line { stroke: var(--c-budget); stroke-width: 2; }
svg.chart g.col[role="button"] { cursor: pointer; }
svg.chart g.col:focus { outline: none; }
svg.chart g.col:focus .bar, svg.chart g.col.sel .bar { stroke: var(--fg); stroke-width: 2; }
ul.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 14px; padding: 0; margin: 6px 0 10px; font-size: 14px; }
ul.legend .swatch { display: inline-block; width: 14px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.swatch.spend { background: var(--c-spend); }
.swatch.income { background: var(--c-income); }
.swatch.budget-key { background: transparent; border-top: 2px dashed var(--c-budget); height: 0; }
.row-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.row-form .field { flex: 1 1 140px; min-width: 0; }
.pv-host { min-width: 0; max-width: 100%; }
label.check { display: inline-flex; gap: 6px; align-items: center; }
ul.list li.off { opacity: .6; }


/* ── P.1.10: the update bar and the install card ── */
.update-slot:empty { display: none; }
.updatebar { position: sticky; top: 0; z-index: 25; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; max-width: 760px; margin: 0 auto 10px; padding: 10px 16px; background: var(--accent); color: var(--accent-fg); }
.updatebar .grow { min-width: 12em; }
.updatebar button.link { color: var(--accent-fg); text-decoration: underline; min-height: 44px; }
.updatebar button.primary { background: var(--accent-fg); color: var(--accent); border-color: var(--accent-fg); }
ol.steps { margin: 6px 0 8px; padding-left: 22px; }
ol.steps li { margin: 4px 0; }
.share-glyph { display: inline-grid; place-items: center; width: 22px; height: 22px; border: 1.5px solid currentColor; border-radius: 5px; font-size: 14px; line-height: 1; vertical-align: middle; }
/* A table that stacks on a phone (dom.js stackTable): each row a block, each
   cell its column's name and its value on one line, nothing off screen. */
@media (max-width: 599.98px) {
  table.data.stack { display: block; }
  table.data.stack caption { display: block; }
  table.data.stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  table.data.stack tbody, table.data.stack tfoot { display: block; }
  table.data.stack tr { display: block; padding: 6px 0; border-bottom: 1px solid var(--line); }
  table.data.stack th[role="rowheader"] { display: block; border: 0; padding: 2px 0; }
  table.data.stack td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; border: 0; padding: 2px 0; text-align: right; white-space: normal; overflow-wrap: anywhere; }
  table.data.stack td::before { content: attr(data-label); color: var(--muted); text-align: left; flex: none; max-width: 50%; }
  table.data.stack td:empty { display: none; }
  table.data.stack td input { width: 7em; }
}
