/* K1W1 — styles. No external fonts or assets (keeps the CSP tight and works offline). */

:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --accent: #1c5cab;
  --accent-ink: #ffffff;
  --accent-soft: #cde2fb;
  --pos: #006300;
  --neg: #c02f2f;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --danger-bg: #fde8e8;
  --info-bg: #e7f0fc;
  --s1: #2a78d6;
  --s2: #eb6834;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 5%);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242423; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #9a988f;
    --line: #2c2c2a; --line-strong: #383835; --accent: #3987e5; --accent-ink: #0d0d0d; --accent-soft: #184f95;
    --pos: #3fc03f; --neg: #ff7b7b; --warn: #f5c451; --warn-bg: #3a2e10; --danger-bg: #3a1717; --info-bg: #13253d;
    --s1: #3987e5; --s2: #d95926; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #242423; --ink: #ffffff; --ink-2: #c3c2b7; --muted: #9a988f;
  --line: #2c2c2a; --line-strong: #383835; --accent: #3987e5; --accent-ink: #0d0d0d; --accent-soft: #184f95;
  --pos: #3fc03f; --neg: #ff7b7b; --warn: #f5c451; --warn-bg: #3a2e10; --danger-bg: #3a1717; --info-bg: #13253d;
  --s1: #3987e5; --s2: #d95926; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
p { margin: .4em 0 .8em; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ---------- controls ---------- */
button, input, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line-strong); background: var(--surface); padding: .5em .9em; border-radius: 8px;
  cursor: pointer; min-height: 40px; white-space: nowrap;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.danger { background: var(--neg); border-color: var(--neg); color: #fff; }
button.ghost { background: transparent; border-color: transparent; }
button.ghost.danger { color: var(--neg); background: transparent; }
button.small { min-height: 32px; padding: .3em .7em; font-size: .9em; }
button.icon { min-width: 40px; padding: .3em .5em; }
button.tiny { min-height: 26px; min-width: 26px; padding: 0 .3em; font-size: .85em; }
input, select {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: .5em .65em;
  min-height: 40px; width: 100%; max-width: 100%;
}
input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--accent); flex: none; }
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible, .trow:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.field { display: flex; flex-direction: column; gap: .3em; margin-bottom: .9em; }
.field .label { font-weight: 600; font-size: .9em; }
.hint { color: var(--muted); font-size: .85em; }
.check { display: flex; align-items: center; gap: .5em; margin: .5em 0; cursor: pointer; }
.checks { display: flex; flex-wrap: wrap; gap: .2em 1em; }
.inline { display: flex; gap: .4em; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .9em; }
.actions { display: flex; gap: .5em; justify-content: flex-end; align-items: center; margin-top: 1em; flex-wrap: wrap; }
.actions.left { justify-content: flex-start; }
.toolbar { display: flex; gap: .5em; flex-wrap: wrap; align-items: center; margin: .8em 0; }
.spacer { flex: 1; }
.seg-group { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; margin: .4em 0 .9em; }
.seg { border: 0; border-radius: 0; background: transparent; }
.seg + .seg { border-left: 1px solid var(--line-strong); }
.seg.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: .88em; }
.error { color: var(--neg); min-height: 0; }
.error:empty { display: none; }
.ok { color: var(--pos); }
.warn { color: var(--warn); }
.empty { color: var(--muted); padding: 1.5em 0; text-align: center; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1em 1.2em; margin-bottom: 1em; box-shadow: var(--shadow); }
.card.narrow { max-width: 460px; margin: 10vh auto; }
.banner { display: flex; flex-wrap: wrap; gap: .5em; align-items: center; padding: .7em 1em; border-radius: 8px; background: var(--surface-2); margin: .6em 0; color: var(--ink); }
.banner.warn { background: var(--warn-bg); }
.banner.danger { background: var(--danger-bg); }
.banner.info { background: var(--info-bg); }
.banner select { width: auto; }
.badge { font-size: .75em; padding: .05em .5em; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); margin-left: .4em; border: 1px solid var(--line-strong); }

/* money */
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money.neg { color: var(--neg); }
.money.pos { color: var(--pos); }
.money.big { font-size: 1.8rem; font-weight: 700; }

/* ---------- lock screens ---------- */
.lock { max-width: 480px; margin: 0 auto; padding: 8vh 16px 2em; }
.lock .card { padding: 1.5em; }
.brand { display: flex; align-items: center; gap: .5em; font-weight: 700; font-size: 1.1rem; }
.brand.big { font-size: 1.6rem; justify-content: center; margin-bottom: 1em; }
.logo { display: inline-grid; place-items: center; min-width: 1.6em; padding: 0 .3em; height: 1.6em; font-size: .85em; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-weight: 800; }
.recovery { display: block; padding: 1em; border: 2px dashed var(--accent); border-radius: 8px; font-size: 1.05rem; letter-spacing: .04em; word-break: break-all; margin: 1em 0; background: var(--surface-2); user-select: all; }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin: -.5em 0 .3em; }
.meter span { display: block; height: 100%; width: 0; transition: width .2s; }
.meter[data-score="0"] span { width: 15%; background: var(--neg); }
.meter[data-score="1"] span { width: 40%; background: var(--warn); }
.meter[data-score="2"] span { width: 70%; background: var(--s1); }
.meter[data-score="3"] span { width: 100%; background: var(--pos); }

/* ---------- layout ---------- */
#app { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center;
  padding: .5em 16px; padding-top: max(.5em, env(safe-area-inset-top)); background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar-right { display: flex; gap: .3em; align-items: center; }
.sync-status { font-size: .85em; color: var(--muted); }
.content { padding: 1em 16px 6em; max-width: 1000px; margin: 0 auto; }
.page-title { font-size: 1.3rem; }
.sidebar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.nav-item { display: flex; flex-direction: column; align-items: center; gap: .1em; padding: .45em .2em; font-size: .72rem; color: var(--ink-2); flex: 1; text-decoration: none !important; }
.nav-item.active { color: var(--accent); font-weight: 700; }
.nav-icon { font-size: 1.25rem; line-height: 1; }

@media (min-width: 860px) {
  .sidebar { top: 57px; bottom: 0; right: auto; width: 210px; flex-direction: column; justify-content: flex-start; border-top: 0; border-right: 1px solid var(--line); padding: 1em .6em; gap: .2em; }
  .nav-item { flex-direction: row; font-size: .95rem; gap: .7em; padding: .6em .8em; border-radius: 8px; flex: none; }
  .nav-item.active { background: var(--accent-soft); color: var(--ink); }
  .content { margin-left: 210px; margin-right: 0; padding: 1.5em 2em 3em; max-width: 1100px; }
}

/* ---------- budget ---------- */
.month-nav { display: flex; align-items: center; gap: .5em; margin-bottom: .8em; }
.month-nav strong { font-size: 1.1rem; min-width: 10em; text-align: center; }
.summary { display: grid; gap: .8em; grid-template-columns: 1fr; margin-bottom: .8em; }
@media (min-width: 700px) { .summary { grid-template-columns: 1.2fr 2fr; } }
.rta { border-radius: var(--radius); padding: 1em 1.2em; background: var(--surface-2); border: 1px solid var(--line); }
.rta.pos { background: color-mix(in srgb, var(--pos) 14%, var(--surface)); }
.rta.neg { background: var(--danger-bg); }
.rta-amount { font-size: 1.9rem; font-weight: 800; }
.rta-label { font-size: .9em; color: var(--ink-2); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6em; }
.stats.wide { margin-bottom: 1em; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: .7em .9em; display: flex; flex-direction: column; gap: .2em; }
.stat .money { font-size: 1.15rem; font-weight: 700; }
.stat.big .money { font-size: 1.4rem; }

.budget-table { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.brow { display: grid; grid-template-columns: 1fr 7.5em 7em 7.5em; gap: .6em; align-items: center; padding: .35em .9em; border-top: 1px solid var(--line); }
.brow > :not(:first-child) { text-align: right; justify-self: end; }
.brow.head { font-size: .8em; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border-top: 0; }
.brow.group { background: var(--surface-2); font-weight: 700; }
.cat-name { display: flex; align-items: center; gap: .4em; flex-wrap: wrap; min-width: 0; }
.cat-name a { color: var(--ink); }
.cat-name .tiny { opacity: .35; }
.brow:hover .tiny, .cat-name .tiny:focus-visible { opacity: 1; }
@media (hover: none) { .cat-name .tiny { opacity: .7; } }
.target { font-size: .75em; padding: 0 .45em; border-radius: 99px; border: 1px solid var(--line-strong); }
.target.under { color: var(--warn); }
.target.met { color: var(--pos); }
.amount-input { text-align: right; min-height: 34px; padding: .3em .5em; }
.pill { padding: .15em .6em; border-radius: 99px; font-weight: 700; font-size: .9em; }
.pill.pos { background: color-mix(in srgb, var(--pos) 16%, transparent); color: var(--pos); }
.pill.neg { background: color-mix(in srgb, var(--neg) 18%, transparent); color: var(--neg); }
.pill.zero { background: var(--surface-2); color: var(--muted); }
@media (max-width: 600px) {
  .brow { grid-template-columns: 1fr 6.5em 6.5em; }
  .hide-sm { display: none; }
  .stats { grid-template-columns: 1fr 1fr 1fr; }
  .stat .money { font-size: 1rem; }
  .grid2 { grid-template-columns: 1fr; }
}

/* ---------- transactions ---------- */
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .5em; align-items: center; }
.txn-list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.date-sep { font-size: .8em; font-weight: 700; color: var(--muted); padding: .5em .9em .2em; background: var(--surface-2); }
.trow { display: grid; grid-template-columns: auto 1fr minmax(8em, 13em) 6.5em; gap: .7em; align-items: center; padding: .5em .9em; border-top: 1px solid var(--line); cursor: pointer; }
.trow:hover { background: var(--surface-2); }
.trow > .money { text-align: right; font-weight: 600; }
.trow.pending .name { font-style: italic; }
.payee { display: flex; flex-direction: column; min-width: 0; }
.payee .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.payee .meta { font-size: .8em; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-select { min-height: 32px; padding: .2em .4em; font-size: .9em; }
.cat-select.needs { border-color: var(--warn); background: var(--warn-bg); }
.transfer, .split { font-size: .9em; color: var(--ink-2); }
@media (max-width: 600px) {
  .trow { grid-template-columns: auto 1fr auto; grid-template-areas: "c p m" "c k k"; row-gap: .3em; }
  .trow > input { grid-area: c; }
  .trow .payee { grid-area: p; }
  .trow .cat { grid-area: k; }
  .trow > .money { grid-area: m; }
}
.splits { display: flex; flex-direction: column; gap: .4em; margin-top: .4em; }
.split-row { display: grid; grid-template-columns: 1fr 7em auto; gap: .4em; }

/* ---------- accounts / generic rows ---------- */
.row { display: flex; align-items: center; gap: .6em; padding: .55em 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.card > .row:first-of-type, .card h2 + .row, .card p + .row { border-top: 0; }
.row .grow { flex: 1; min-width: 12em; }
.row.account > .money { font-weight: 700; min-width: 7em; text-align: right; }
.cat-row input:first-child { flex: 1; min-width: 10em; }
.cat-row .small-select { width: auto; min-height: 32px; padding: .2em .4em; }
.hidden-cat { opacity: .55; }
.group-name { font-weight: 700; flex: 1; }
.danger-zone { border-color: color-mix(in srgb, var(--neg) 40%, var(--line)); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: .9em; }
th, td { text-align: left; padding: .35em .5em; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; }
td:has(.money) { text-align: right; }
tr.dup { opacity: .45; }
tr.maybe { background: var(--warn-bg); }

/* ---------- reports ---------- */
.hbars { display: flex; flex-direction: column; gap: 6px; }
.hbar { display: grid; grid-template-columns: minmax(7em, 11em) 1fr 6.5em; gap: .6em; align-items: center; color: var(--ink); text-decoration: none !important; padding: 2px 0; }
.hbar:hover .hbar-fill { filter: brightness(1.1); }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9em; }
.hbar-track { height: 14px; }
.hbar-fill { display: block; height: 100%; min-width: 2px; background: var(--s1); border-radius: 0 4px 4px 0; }
.hbar-value { text-align: right; font-size: .9em; color: var(--ink-2); }
.legend { display: flex; align-items: center; gap: .4em 1em; font-size: .85em; color: var(--ink-2); margin-bottom: .6em; }
.key { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: -.6em; }
.key.s1, .vbar.s1 { background: var(--s1); }
.key.s2, .vbar.s2 { background: var(--s2); }
.vbars { display: flex; align-items: flex-end; gap: 8px; height: 180px; border-bottom: 1px solid var(--line-strong); padding-top: 8px; }
.vgroup { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.vpair { flex: 1; display: flex; align-items: flex-end; gap: 2px; width: 100%; justify-content: center; }
.vbar { width: min(18px, 40%); border-radius: 4px 4px 0 0; min-height: 1px; }
.vlabel { font-size: .75em; color: var(--muted); padding-top: 4px; height: 1.6em; }
.line-chart { width: 100%; height: auto; display: block; }
.line-chart .line { fill: none; stroke: var(--s1); stroke-width: 2; stroke-linejoin: round; }
.line-chart .dot { fill: var(--s1); stroke: var(--surface); stroke-width: 2; }
.line-chart .dot:hover { r: 7; }
.line-chart .baseline { stroke: var(--line-strong); stroke-width: 1; }
.axis-labels { display: flex; justify-content: space-between; font-size: .75em; color: var(--muted); }
details summary { cursor: pointer; color: var(--accent); font-size: .9em; margin: .6em 0; }

/* ---------- modal & toast ---------- */
dialog.modal {
  border: 1px solid var(--line); border-radius: 14px; padding: 0; width: min(520px, calc(100vw - 32px));
  background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / 30%); max-height: calc(100vh - 32px);
}
dialog.modal.wide { width: min(800px, calc(100vw - 32px)); }
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog header { display: flex; justify-content: space-between; align-items: center; padding: .8em 1em .4em 1.2em; }
dialog header h2 { margin: 0; }
.modal-body { padding: 0 1.2em 1.2em; overflow-y: auto; }
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 80px; z-index: 50; display: flex; flex-direction: column; gap: .4em; width: min(460px, calc(100vw - 32px)); }
.toast { background: var(--ink); color: var(--page); padding: .7em 1em; border-radius: 8px; box-shadow: var(--shadow); font-size: .92em; }
.toast.error { background: var(--neg); color: #fff; }

/* link page */
.link-page { padding: 16px; }

/* ---------- receipts ---------- */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
label.button { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--line-strong); background: var(--surface); padding: .5em .9em; border-radius: 8px; cursor: pointer; min-height: 40px; }
label.button.small { min-height: 32px; padding: .3em .7em; font-size: .9em; }
label.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
label.button:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.big-button { width: 100%; min-height: 56px !important; font-size: 1.05rem; margin: .5em 0; }
textarea { font: inherit; color: inherit; width: 100%; border: 1px solid var(--line-strong); background: var(--surface); border-radius: 8px; padding: .5em .65em; }
.pick-list { display: flex; flex-direction: column; gap: .4em; }
.pick { display: flex; justify-content: space-between; align-items: center; text-align: left; white-space: normal; gap: 1em; }
.receipt-top { display: flex; gap: 1em; align-items: flex-start; flex-wrap: wrap; }
.receipt-top .grow { flex: 1; min-width: 260px; }
.receipt-photo { width: 140px; display: flex; flex-direction: column; gap: .3em; }
.receipt-photo img { width: 140px; max-height: 200px; object-fit: cover; object-position: top; border-radius: 8px; border: 1px solid var(--line); display: block; }
.receipt-photo .toolbar { margin: 0; flex-direction: column; align-items: stretch; }
.receipt-full { width: 100%; height: auto; display: block; }
.items-head, .item-row { display: grid; grid-template-columns: 1fr 4em 7em minmax(8em, 11em) auto; gap: .4em; align-items: center; }
.items-head { font-size: .78em; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: .6em 0 .2em; }
.item-row { margin-bottom: .35em; }
.item-row .qty { text-align: center; padding: .3em; }
.item-row input, .item-row select { min-height: 36px; padding: .3em .5em; }
@media (max-width: 600px) {
  .items-head { display: none; }
  .item-row { grid-template-columns: 3.5em 6.5em 1fr auto; padding-bottom: .5em; border-bottom: 1px solid var(--line); }
  .item-row > :nth-child(1) { grid-column: 1 / 4; grid-row: 1; }
  .item-row > :nth-child(2) { grid-column: 1; grid-row: 2; }
  .item-row > :nth-child(3) { grid-column: 2; grid-row: 2; }
  .item-row > :nth-child(4) { grid-column: 3 / 5; grid-row: 2; }
  .item-row > :nth-child(5) { grid-column: 4; grid-row: 1; }
  .receipt-photo { width: 100%; flex-direction: row; }
}
details.paste { flex-basis: 100%; }
details.paste textarea { margin-bottom: .4em; }
.totals { margin-top: .6em; }
.totals .row { padding: .3em 0; }
.receipt-btn { width: 100%; text-align: left; margin: .2em 0 .6em; white-space: normal; }
.item-hits { display: flex; flex-wrap: wrap; gap: .3em 1em; padding: .1em .9em .5em 3em; font-size: .85em; color: var(--ink-2); }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--surface-2); }
.receipt-photo { width: 170px; }
.receipt-photo img { width: 170px; }
.receipt-photo button, .receipt-photo label { white-space: normal; width: 100%; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.money.xfer { color: var(--ink-2); }
.transfer-pair { margin: 0; padding: .6em .9em; }
.transfer-pair .row { border-top: 0; padding: .2em 0; }
