@font-face { font-family: "Bricolage"; src: url("/fonts/bricolage.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }
@font-face { font-family: "Plex"; src: url("/fonts/plex-400.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Plex"; src: url("/fonts/plex-500.woff2") format("woff2"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Plex"; src: url("/fonts/plex-600.woff2") format("woff2"); font-weight: 600; font-display: swap; }

:root {
  color-scheme: light dark;
  --paper: #F1F4F1;
  --surface: #FFFFFF;
  --sunk: #E8EDE9;
  --ink: #14201C;
  --muted: #5A6A63;
  --line: #D9E0DB;
  --brand: #0B4F4A;
  --brand-ink: #FFFFFF;
  --brand-soft: #DCEBE8;
  --in: #0C7347;
  --out: #B0301D;
  --mark: #E8B33A;
  --focus: #0B4F4A;
  --shadow: 0 1px 2px rgba(20, 32, 28, .06), 0 12px 32px -16px rgba(20, 32, 28, .22);
  --display: "Bricolage", "Plex", system-ui, sans-serif;
  --text: "Plex", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r-sm: 8px; --r-md: 12px; --r-lg: 20px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0E1513;
    --surface: #161F1C;
    --sunk: #1E2925;
    --ink: #E6ECE8;
    --muted: #93A39B;
    --line: #2A3732;
    --brand: #5CC6B6;
    --brand-ink: #06231F;
    --brand-soft: #173730;
    --in: #58C990;
    --out: #F08A76;
    --focus: #5CC6B6;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 12px 32px -16px rgba(0, 0, 0, .7);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--paper); color: var(--ink);
  font: 400 16px/1.5 var(--text); font-variant-numeric: tabular-nums;
  min-height: 100dvh;
}
h2, h3, p, dl, dd, ul, fieldset { margin: 0; padding: 0; }
fieldset { border: 0; min-width: 0; }
ul { list-style: none; }
button, input { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 10px; font: 650 20px/1 var(--display); letter-spacing: -.01em; }
.brand-lg { font-size: 28px; }
.mark {
  width: 1.3em; height: 1.3em; border-radius: .32em; background: var(--brand); flex: none;
  background-image:
    radial-gradient(circle at 70% 68%, var(--mark) 0 .1em, transparent .11em),
    linear-gradient(var(--brand-ink), var(--brand-ink)), linear-gradient(var(--brand-ink), var(--brand-ink)), linear-gradient(var(--brand-ink), var(--brand-ink));
  background-size: 100% 100%, 58% .09em, 58% .09em, 30% .09em;
  background-position: 0 0, 50% 32%, 50% 50%, 28% 68%;
  background-repeat: no-repeat;
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: var(--r-sm); border: 1px solid transparent;
  font-weight: 500; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color .12s, border-color .12s;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: color-mix(in srgb, var(--brand) 88%, var(--ink)); }
.btn-ghost { border-color: var(--line); background: var(--surface); color: var(--ink); }
.btn-ghost:hover { border-color: var(--muted); }
.btn-quiet { background: transparent; color: var(--muted); }
.btn-quiet:hover { background: var(--sunk); color: var(--ink); }
.btn-danger { background: transparent; color: var(--out); border-color: color-mix(in srgb, var(--out) 35%, transparent); }
.btn-danger:hover { background: color-mix(in srgb, var(--out) 10%, transparent); }
.btn-block { width: 100%; margin-top: 12px; }
.icon-btn {
  width: 40px; height: 40px; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface);
  font-size: 20px; line-height: 1; cursor: pointer; flex: none;
}
.icon-btn:hover { border-color: var(--muted); }
.icon-btn:disabled { opacity: .4; cursor: default; }

/* ---------- fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span, .segment-label { font-size: 13px; font-weight: 500; color: var(--muted); }
input:not([type=radio]):not([type=checkbox]) {
  width: 100%; min-height: 44px; padding: 0 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); font-size: 16px;
}
input::placeholder { color: color-mix(in srgb, var(--muted) 70%, transparent); }
input:focus-visible { outline-offset: 0; border-color: var(--focus); }
.form-error { color: var(--out); font-size: 14px; margin-top: 10px; }
.form-ok { color: var(--in); font-size: 14px; margin-top: 10px; }

.segment { display: grid; grid-template-columns: 1fr 1fr; background: var(--sunk); border-radius: var(--r-sm); padding: 3px; height: 44px; }
.segment label { position: relative; display: grid; cursor: pointer; }
.segment input { position: absolute; inset: 0; opacity: 0; cursor: pointer; margin: 0; }
.segment span { display: grid; place-items: center; padding: 0 16px; border-radius: 6px; font-weight: 500; color: var(--muted); }
.segment input:checked + span { background: var(--surface); box-shadow: 0 1px 2px rgba(0, 0, 0, .12); }
.segment input[value=in]:checked + span { color: var(--in); }
.segment input[value=out]:checked + span { color: var(--out); }
.segment input:focus-visible + span { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ---------- sign in ---------- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.gate-card { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 36px 32px 32px; box-shadow: var(--shadow); }
.gate-lede { color: var(--muted); margin: 12px 0 28px; }
.gate-card .field { margin-bottom: 16px; }
.key-step { display: flex; gap: 16px; align-items: flex-start; margin: 28px 0 8px; }
.key-step h2 { font: 650 20px/1.2 var(--display); margin-bottom: 6px; }
.key-step p { color: var(--muted); font-size: 15px; }
.key-icon {
  flex: none; width: 44px; height: 44px; border-radius: 50%; background: var(--brand-soft);
  background-image: radial-gradient(circle at 36% 50%, transparent 0 4px, var(--brand) 4.5px 8px, transparent 8.5px),
    linear-gradient(var(--brand), var(--brand)), linear-gradient(var(--brand), var(--brand));
  background-size: 100% 100%, 13px 3.5px, 3.5px 7px;
  background-position: 0 0, 26px 50%, 33px 25px;
  background-repeat: no-repeat;
}

/* ---------- app shell ---------- */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 1240px; margin: 0 auto; padding: 16px 24px; }
.top-actions { display: flex; gap: 4px; }
.top-actions .btn { padding: 0 12px; }
.page { max-width: 1240px; margin: 0 auto; padding: 8px 24px 80px; }

/* ---------- balance ---------- */
.summary { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px 48px; flex-wrap: wrap; padding: 20px 0 28px; }
.summary-label { color: var(--muted); font-size: 14px; }
.balance-figure { font: 600 clamp(44px, 9vw, 76px)/1 var(--display); letter-spacing: -.035em; margin-top: 6px; white-space: nowrap; }
.balance-figure .millimes { font-size: .5em; font-weight: 500; letter-spacing: -.02em; color: var(--muted); }
.balance-figure .cur { font-size: .26em; font-weight: 500; letter-spacing: 0; color: var(--muted); margin-left: .5em; }
.balance-figure.neg { color: var(--out); }
.period-totals { display: flex; gap: 28px; align-items: baseline; flex-wrap: wrap; padding-bottom: 6px; }
.period-totals dt { font-size: 13px; color: var(--muted); }
.period-totals > div:first-child dt { font-weight: 600; color: var(--ink); font-size: 14px; }
.period-totals dd { font: 600 19px/1.3 var(--display); white-space: nowrap; }
.total.in dd { color: var(--in); }
.total.out dd { color: var(--out); }

/* ---------- composer ---------- */
.composer {
  display: grid; grid-template-columns: 150px minmax(0, 1fr) auto 160px auto; gap: 12px; align-items: end;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px; box-shadow: var(--shadow);
}
.composer .f-error { grid-column: 1 / -1; margin-top: 0; }
.f-amount input, #edit-amount { text-align: right; font-weight: 600; }

/* ---------- statement ---------- */
.statement { margin-top: 28px; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.period, .tools { display: flex; align-items: center; gap: 8px; }
.period-current { min-width: 168px; min-height: 40px; border: 0; background: none; font: 600 18px/1 var(--display); text-align: center; cursor: default; }
.check { display: inline-flex; align-items: center; gap: 8px; margin-left: 8px; min-height: 40px; color: var(--muted); font-size: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--brand); margin: 0; }
.tools input[type=search] { width: 200px; min-height: 40px; }
.tools .btn { min-height: 40px; padding: 0 14px; font-size: 14px; }
.print-head { display: none; }

.ledger { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow: hidden; border-style: hidden; box-shadow: 0 0 0 1px var(--line); }
.ledger th { text-align: left; font-size: 13px; font-weight: 500; color: var(--muted); padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.ledger td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: baseline; }
.ledger tr:last-child td { border-bottom: 0; }
.ledger .c-num { text-align: right; white-space: nowrap; }
.ledger .c-date { white-space: nowrap; color: var(--muted); width: 1%; }
.ledger .c-act { width: 1%; padding-left: 0; }
.ledger td.c-label { overflow-wrap: anywhere; }
.by-m, .add-bar { display: none; }
.ledger .by { display: block; font-size: 12.5px; color: var(--muted); margin-top: 1px; }
.ledger .out { color: var(--out); font-weight: 500; }
.ledger .in { color: var(--in); font-weight: 500; }
.ledger td.c-bal { font-weight: 600; }
.ledger td.c-bal.neg { color: var(--out); }
.ledger .frac { font-size: .82em; opacity: .75; }
.ledger tbody tr.entry:hover { background: color-mix(in srgb, var(--brand-soft) 45%, transparent); }
.ledger tr.month td { background: var(--sunk); font: 600 14px/1.2 var(--display); padding: 9px 16px; }
.ledger tr.forward td { color: var(--muted); font-style: italic; }
.ledger tr.forward td.c-bal { font-style: normal; }
.row-edit { border: 0; background: none; color: var(--brand); font-size: 14px; font-weight: 500; padding: 6px 10px; border-radius: 6px; cursor: pointer; opacity: 0; }
.entry:hover .row-edit, .row-edit:focus-visible { opacity: 1; }
.row-edit:hover { background: var(--brand-soft); }
@media (hover: none) { .row-edit { opacity: 1; } }
tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: color-mix(in srgb, var(--mark) 38%, transparent); } to { background: transparent; } }

.empty { text-align: center; color: var(--muted); padding: 56px 20px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
.empty strong { display: block; color: var(--ink); font: 600 18px/1.3 var(--display); margin-bottom: 4px; }

/* ---------- dialogs ---------- */
.dialog { width: min(440px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 24px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.dialog-wide { width: min(620px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgba(10, 20, 17, .5); }
.dialog h2 { font: 650 22px/1.2 var(--display); }
.dialog h3 { font: 600 16px/1.2 var(--display); margin: 26px 0 10px; }
.dialog form > h2 { margin-bottom: 18px; }
.dialog .field, .dialog .segment { margin-bottom: 14px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dialog-head .icon-btn { border: 0; background: none; font-size: 26px; color: var(--muted); }
.dialog-note { color: var(--muted); font-size: 14px; margin-top: 6px; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 22px; flex-wrap: wrap; }
.spacer { flex: 1; }
.entry-meta { font-size: 13px; color: var(--muted); }

.keys li, .activity li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.keys li > div, .activity li > div { flex: 1; min-width: 0; }
.keys small, .activity small { display: block; color: var(--muted); font-size: 13px; }
.keys { margin-bottom: 12px; }
.link-btn { border: 0; background: none; color: var(--brand); font-weight: 500; font-size: 14px; cursor: pointer; padding: 8px; border-radius: 6px; }
.link-btn:hover { background: var(--brand-soft); }
.link-btn.danger { color: var(--out); }
.activity { margin-top: 12px; }
.activity .what { overflow-wrap: anywhere; }
.activity .tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 99px; background: var(--sunk); margin-right: 6px; }
.activity .tag.delete { color: var(--out); }
.activity .tag.add, .activity .tag.restore { color: var(--in); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: 11px 18px; border-radius: 99px; font-size: 14px; font-weight: 500; box-shadow: var(--shadow); z-index: 10; max-width: calc(100vw - 32px); }

/* ---------- small screens ---------- */
@media (max-width: 860px) {
  .composer { grid-template-columns: 1fr 1fr; }
  .composer .f-label, .composer .f-submit { grid-column: 1 / -1; }
  .composer .f-date { grid-column: 1 / -1; }
  .tools { width: 100%; }
  .tools input[type=search] { flex: 1; width: auto; }
}
@media (max-width: 640px) {
  body { font-size: 17px; }
  .top { padding: 12px 16px 4px; }
  .page { padding: 0 0 calc(96px + env(safe-area-inset-bottom)); }
  .summary, .toolbar { padding-left: 16px; padding-right: 16px; }
  .summary { padding-top: 12px; padding-bottom: 20px; gap: 18px; }
  .summary-label { font-size: 15px; }
  .balance-figure { font-size: clamp(52px, 15.5vw, 72px); }
  .period-totals { display: grid; grid-template-columns: repeat(3, auto); justify-content: space-between; gap: 4px 16px; width: 100%; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); }
  .period-totals > div:first-child { grid-column: 1 / -1; }
  .period-totals > div:first-child dt { font-size: 15px; }
  .period-totals dt { font-size: 14px; }
  .period-totals dd { font-size: 20px; }

  /* the entry form moves to a sheet opened from the bottom bar */
  .composer { display: none; }
  .add-bar { display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--paper) 62%, transparent); }
  .add-bar .btn { width: 100%; min-height: 54px; font-size: 18px; border-radius: var(--r-md); box-shadow: var(--shadow); }
  .toast { bottom: calc(86px + env(safe-area-inset-bottom)); }

  .statement { margin-top: 4px; }
  .toolbar { margin-bottom: 10px; }
  .period { width: 100%; }
  .period-current { flex: 1; min-width: 0; font-size: 18px; white-space: nowrap; padding: 0; }
  .period { gap: 6px; }
  .check { margin-left: 4px; }
  .icon-btn { width: 46px; height: 46px; font-size: 24px; }
  .check { font-size: 16px; }
  .tools input[type=search], .tools .btn { min-height: 46px; font-size: 16px; }
  #print { display: none; }

  /* statement runs edge to edge, one entry per block */
  .ledger { border-radius: 0; box-shadow: 0 1px 0 var(--line), 0 -1px 0 var(--line); }
  .ledger thead { display: none; }
  .ledger, .ledger tbody { display: block; }
  .ledger tr.entry, .ledger tr.forward { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "label amt" "date bal"; gap: 4px 14px; align-items: baseline; padding: 15px 16px; border-bottom: 1px solid var(--line); position: relative; }
  .ledger tr.entry:last-child, .ledger tr.forward:last-child { border-bottom: 0; }
  .ledger tr.month, .ledger tr.month td { display: block; }
  .ledger tr.month td { padding: 10px 16px; font-size: 15px; }
  .ledger tr.entry td, .ledger tr.forward td { padding: 0; border: 0; width: auto; }
  .ledger td.c-label { grid-area: label; font-size: 18px; font-weight: 500; line-height: 1.3; }
  .ledger .by { display: none; }
  .by-m { display: inline; }
  .ledger td.c-date { grid-area: date; font-size: 14.5px; white-space: normal; }
  .ledger td.c-num.out, .ledger td.c-num.in { grid-area: amt; font-size: 20px; font-weight: 600; }
  .ledger td.nil { display: none; }
  .ledger td.c-bal { grid-area: bal; font-size: 14.5px; font-weight: 600; color: var(--muted); }
  .ledger td.c-bal::before { content: "Balance "; font-weight: 400; }
  .ledger .frac { font-size: .8em; }
  .ledger td.c-act { position: absolute; inset: 0; }
  .row-edit { position: absolute; inset: 0; width: 100%; opacity: 0 !important; }
  .ledger tr.forward td.c-label { font-weight: 400; font-size: 16px; }
  .ledger tr.forward td.c-bal { grid-area: amt; font-size: 18px; color: var(--ink); }
  .ledger tr.forward td.c-bal::before { content: none; }
  .empty { border-radius: 0; border-left: 0; border-right: 0; }

  /* dialogs become bottom sheets */
  .dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--r-lg) var(--r-lg) 0 0; border-width: 1px 0 0; padding: 22px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 92dvh; }
  .dialog input:not([type=radio]):not([type=checkbox]), .dialog .segment { min-height: 50px; height: 50px; font-size: 18px; }
  .dialog .segment span { font-size: 17px; }
  .dialog-actions .btn-primary { flex: 1 1 100%; order: -1; min-height: 52px; font-size: 18px; }
  .dialog-actions .spacer { display: none; }
  .dialog-actions .btn-quiet, .dialog-actions .btn-danger { flex: 1; }
  .gate { padding: 16px; }
  .gate-card { padding: 28px 22px 24px; }
}

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- print: a clean statement ---------- */
@media print {
  :root { --paper: #fff; --surface: #fff; --ink: #000; --muted: #444; --line: #bbb; --in: #000; --out: #000; --sunk: #eee; }
  .top, .composer, .toolbar, .c-act, .toast, dialog { display: none !important; }
  .page { padding: 0; max-width: none; }
  .summary { padding: 0 0 12px; }
  .balance-figure { font-size: 34px; }
  .print-head { display: block; font-size: 14px; margin-bottom: 8px; }
  .ledger { box-shadow: none; border: 1px solid #bbb; font-size: 12px; }
  .ledger td, .ledger th { padding: 6px 8px; }
  .ledger tr { break-inside: avoid; }
}
