/*
 * The web version's styles. A file of its own because the security policy allows no
 * inline styles (firebase.json, headers.conf).
 */
:root {
  --ink: #12211a; --muted: #5b6b63; --line: #dfe6e2;
  --bg: #fbfcfb; --card: #ffffff; --soft: #f1f5f3;
  --keep: #0f5132; --keep-ink: #ffffff; --hold: #8a5a00; --alert: #a12a1f;
  --select: #e6f2ec;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ink: #e8efea; --muted: #9fb0a7; --line: #26312c;
    --bg: #0d1310; --card: #141b17; --soft: #18211c;
    --keep: #6fcf97; --keep-ink: #0d1310; --hold: #f2c14e; --alert: #ff8a7a;
    --select: #1d2d24;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
[hidden] { display: none !important; }
h1 { font-size: 1.6rem; margin: 0 0 .5rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
a { color: var(--keep); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.block { display: block; }
.error { color: var(--alert); }
.note {
  background: var(--soft); border-left: 3px solid var(--hold);
  padding: .5rem .75rem; border-radius: 6px;
}
.loading { padding: 4rem 1rem; text-align: center; color: var(--muted); }

/* ---- buttons and fields ---- */
button {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; padding: .45rem .9rem; cursor: pointer;
}
button:hover { border-color: var(--muted); }
button:disabled { opacity: .6; cursor: default; }
button.primary { background: var(--keep); color: var(--keep-ink); border-color: var(--keep); }
button.link { background: none; border: 0; color: var(--keep); padding: 0; text-decoration: underline; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; padding: .4rem .55rem; min-width: 0;
}
textarea { width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: .04em; }
.field { display: flex; flex-direction: column; gap: .3rem; margin: 0 0 1rem; }
.field > span { font-weight: 600; }
.field small { color: var(--muted); }
.field.inline { margin: 0; gap: .15rem; }
.field.inline > span { font-weight: 500; font-size: .78rem; color: var(--muted); }
.check { display: inline-flex; gap: .35rem; align-items: center; align-self: flex-end; padding-bottom: .4rem; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin: .5rem 0; }

/* ---- unlock ---- */
.unlock { max-width: 68rem; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.unlock-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 2.5rem; }
.unlock-brand { display: inline-flex; align-items: center; gap: .6rem; font-size: 1.05rem; }
.unlock-brand img { display: block; border-radius: 7px; }
.unlock-language { display: inline-flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .9rem; }
/* A phone reads the title, the way in, then why it is safe; a desk has them side by side. */
.unlock-grid { display: grid; gap: 1.5rem; align-items: start; grid-template-areas: "intro" "ways" "about"; }
.unlock-intro { grid-area: intro; }
.unlock-ways { grid-area: ways; }
.unlock-about { grid-area: about; }
@media (min-width: 56rem) {
  .unlock-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 28rem); column-gap: 3.5rem; row-gap: 0;
    grid-template-areas: "intro ways" "about ways";
  }
  .unlock { padding-top: 2rem; }
  .unlock-intro { padding-top: 1rem; }
  .unlock-about { padding-top: 1.25rem; }
}
.unlock h1 { font-size: clamp(1.9rem, 5vw, 2.8rem); line-height: 1.15; margin: 0 0 .75rem; }
.eyebrow { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin: 0 0 .5rem; }
.tagline { font-size: 1.1rem; color: var(--muted); margin-bottom: .5rem; }
.unlock-points { list-style: none; padding: 0; margin: 0 0 1.5rem; display: grid; gap: .9rem; }
.unlock-points li { padding-left: 1.6rem; position: relative; }
.unlock-points li::before {
  content: ""; position: absolute; left: 0; top: .35rem; width: .8rem; height: .8rem;
  border-radius: 50%; background: var(--keep); opacity: .85;
}
.unlock-points strong { display: block; }
.unlock-points span { color: var(--muted); }
.backup-way summary { cursor: pointer; font-weight: 600; color: var(--ink); }
.backup-way[open] summary { margin-bottom: .75rem; }
.backup-way .form { margin: 0; }
.drop { border: 1.5px dashed var(--line); border-radius: 10px; padding: .75rem; transition: border-color .15s, background .15s; }
.drop.over { border-color: var(--keep); background: var(--select); }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 1.1rem 1.25rem; margin: 0 0 1.25rem;
}
.form input[type="file"] { padding: .35rem; }

/* ---- opening with the phone ---- */
.phone-link h2 { margin-bottom: .35rem; }
.phone-step { display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap; margin: 1rem 0; }
.qr { width: 13rem; max-width: 100%; }
.qr-code { width: 100%; height: auto; display: block; }
.qr-light { fill: #fff; }
.qr-dark { fill: #000; }
.match-number {
  font-size: 4rem; font-weight: 700; letter-spacing: .08em; margin: 0;
  font-variant-numeric: tabular-nums; color: var(--keep);
}

/* ---- shell ---- */
.top {
  position: sticky; top: 0; z-index: 2; background: var(--bg);
  display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; align-items: center;
  padding: .6rem 1rem; border-bottom: 1px solid var(--line);
}
.brand { display: flex; flex-direction: column; line-height: 1.25; }
.brand .muted { font-size: .8rem; }
.nav { display: flex; flex-wrap: wrap; gap: .15rem; flex: 1; }
.nav a {
  text-decoration: none; color: var(--muted); padding: .35rem .65rem; border-radius: 8px;
}
.nav a:hover { color: var(--ink); background: var(--soft); }
.nav a.active { color: var(--ink); background: var(--soft); font-weight: 600; }
.top-actions { display: flex; gap: .5rem; align-items: center; }
.view { max-width: 78rem; margin: 0 auto; padding: 1.25rem 1rem 3rem; }

.badge {
  display: inline-block; font-size: .72rem; font-weight: 600; padding: .05rem .45rem;
  border-radius: 999px; background: var(--soft); color: var(--muted); margin-left: .4rem; vertical-align: 1px;
}
.badge.warn { color: var(--hold); border: 1px solid var(--hold); background: transparent; }

/* ---- tiles ---- */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: .75rem; margin: 1rem 0 1.5rem; }
.tiles.compact { grid-template-columns: repeat(auto-fill, minmax(9rem, 1fr)); margin: .5rem 0 1rem; }
.tile {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: .8rem 1rem; display: flex; flex-direction: column; gap: .2rem;
}
.tile .label { font-size: .82rem; color: var(--muted); }
.tile .value { font-size: 1.35rem; font-weight: 650; font-variant-numeric: tabular-nums; }
.tile .value.small { font-size: 1.05rem; }
.tile.strong { border-color: var(--keep); }
.tile.alert .value { color: var(--alert); }

/* ---- chart ---- */
.chart { width: 100%; height: auto; display: block; }
.chart .axis { stroke: var(--line); }
.chart rect.income { fill: var(--keep); }
.chart rect.spend { fill: var(--hold); }
.chart rect.future { opacity: .25; }
.chart circle.profit { fill: var(--ink); }
.chart text.month { font-size: 11px; fill: var(--muted); text-anchor: middle; }
.legend { display: flex; gap: 1rem; font-size: .82rem; color: var(--muted); margin-bottom: .4rem; }
.legend .key::before { content: ""; display: inline-block; width: .7rem; height: .7rem; border-radius: 2px; margin-right: .35rem; vertical-align: -1px; }
.legend .income::before { background: var(--keep); }
.legend .spend::before { background: var(--hold); }
.legend .profit::before { background: var(--ink); border-radius: 50%; }

/* ---- filters and tables ---- */
.filters { display: flex; flex-wrap: wrap; gap: .6rem .9rem; align-items: flex-end; margin: .75rem 0 1rem; }
.scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
.card .scroll { border: 0; }
table.grid { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.grid th, .grid td { padding: .45rem .7rem; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid th { font-size: .78rem; color: var(--muted); font-weight: 600; white-space: nowrap; }
.grid th.sortable { cursor: pointer; user-select: none; }
.grid .num { text-align: right; white-space: nowrap; }
.grid tfoot td { font-weight: 600; border-bottom: 0; }
.grid tr.archived td { color: var(--muted); }
.grid.selectable tr.selected td { background: var(--select); }
.grid tr.edited td:first-child { box-shadow: inset 3px 0 0 var(--hold); }
.statement td.indent { padding-left: 1.6rem; color: var(--muted); }
.statement tr.strong td { font-weight: 650; }
.statement tr.total td { border-top: 2px solid var(--ink); }
.status { font-size: .8rem; font-weight: 600; padding: .05rem .5rem; border-radius: 999px; background: var(--soft); white-space: nowrap; }
.s-OVERDUE { color: var(--alert); }
.s-PAID, .s-CREDITED { color: var(--keep); }
.s-DRAFT, .s-WRITTEN_OFF, .s-QUOTE { color: var(--muted); }
meter { width: 4rem; height: .6rem; vertical-align: middle; }

/* ---- bulk editor ---- */
.bulk { border-color: var(--keep); }
.bulk-head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: baseline; }
.bulk-head h2 { margin: 0; }
.bulk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(12rem, 1fr)); gap: .75rem; margin: .75rem 0; }

.flash {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: .55rem 1rem; border-radius: 8px; z-index: 5;
}

.receipt-dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); max-width: min(92vw, 48rem); }
.receipt-dialog img { max-width: 100%; max-height: 75vh; display: block; margin: 0 auto .75rem; }
.receipt-dialog::backdrop { background: rgb(0 0 0 / .5); }

/* ---- one invoice ---- */
.grid tr.clickable { cursor: pointer; }
.grid tr.clickable:hover td, .grid tr.clickable:focus td { background: var(--soft); }
.button-link {
  display: inline-block; text-decoration: none; color: var(--ink);
  border: 1px solid var(--line); border-radius: 8px; padding: .45rem .9rem; background: var(--card);
}
.invoice-paper {
  background: #fff; color: #1a1a1a; max-width: 52rem; margin: 0 auto 2rem;
  padding: 2.5rem 2.75rem; border: 1px solid var(--line); border-radius: 6px;
  box-shadow: 0 1px 3px rgb(0 0 0 / .08); font-size: .95rem;
}
.doc-head { display: flex; justify-content: space-between; gap: 2rem; flex-wrap: wrap; margin-bottom: 2rem; }
.doc-title { text-align: right; }
.doc-title h1 { font-size: 1.8rem; margin: 0 0 .5rem; }
.doc-field { display: flex; gap: .5rem; justify-content: inherit; }
.doc-title .doc-field { justify-content: flex-end; }
.doc-label { color: #6b6b6b; }
.doc-from .doc-field:first-child { font-weight: 650; font-size: 1.05rem; }
.doc-to { margin-bottom: 1.75rem; }
.doc-to h2, .doc-payment h2 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: #6b6b6b; margin: 0 0 .35rem; }
.doc-lines, .doc-totals { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.doc-lines th { text-align: left; font-size: .8rem; color: #6b6b6b; border-bottom: 2px solid #1a1a1a; padding: .4rem .5rem; }
.doc-lines td { padding: .5rem; border-bottom: 1px solid #e3e3e3; vertical-align: top; white-space: pre-line; }
.doc-lines .num, .doc-totals .num { text-align: right; white-space: nowrap; }
.doc-totals { width: auto; margin: 1rem 0 0 auto; min-width: 18rem; }
.doc-totals td { padding: .3rem .5rem; }
.doc-totals tr.strong td { font-weight: 700; border-top: 2px solid #1a1a1a; font-size: 1.05rem; }
.doc-notes { margin-top: 1.75rem; color: #333; font-size: .88rem; }
.doc-payment { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px solid #e3e3e3; }
.letter-paper p { margin: 0 0 .8rem; line-height: 1.5; }
.letter-paper .doc-from { text-align: right; }
.letter-paper .doc-to p { white-space: pre-line; margin: 0; }
.letter-subject { font-size: 1.15rem; margin: 1.5rem 0 1rem; }
.letter-sum { margin: .5rem auto 1rem 0; }
.letter-payment { display: flex; justify-content: space-between; align-items: flex-start; gap: 1.5rem; flex-wrap: wrap; }
.letter-qr { margin: 0; width: 8rem; text-align: center; font-size: .75rem; color: #6b6b6b; }
.letter-sender { margin-top: 2rem; }
ul.plain { list-style: none; padding: 0; margin: .25rem 0 .5rem; }

@media (max-width: 40rem) {
  .top { position: static; }
  .tile .value { font-size: 1.15rem; }
}

@media print {
  .top, .no-print, .filters, button { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: 0; padding: 0; break-inside: avoid; }
  .view { padding: 0; max-width: none; }
  .invoice-paper { border: 0; box-shadow: none; padding: 0; max-width: none; }
}

/* ---- forms that make or change a record ---------------------------------------- */

.record-form { max-width: 44rem; }
.record-form .check { display: flex; align-self: auto; margin: 0 0 1rem; padding: 0; }
.record-form h2 { margin: 1.25rem 0 .75rem; font-size: 1rem; }
.record-form h2:first-child { margin-top: 0; }
.record-form textarea { resize: vertical; }
.suggestions {
  list-style: none; margin: -.1rem 0 0; padding: .25rem; border: 1px solid var(--line);
  border-radius: 8px; background: var(--card); max-height: 18rem; overflow-y: auto;
}
.suggestions button.suggestion {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  width: 100%; text-align: left; border: 0; border-radius: 6px; background: transparent;
  padding: .45rem .6rem; color: var(--ink); font-weight: 400;
}
.suggestions button.suggestion:hover, .suggestions button.suggestion:focus { background: var(--select); outline: none; }
.suggestions .name { font-weight: 600; overflow-wrap: anywhere; }
.supplier-note { margin: 0; }
.route { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem .75rem; margin: -.5rem 0 1rem; }
.route p { margin: 0; }
.record-form .actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.lines { margin: 0 0 1rem; }
.lines-grid { width: 100%; margin-bottom: .5rem; }
.lines-grid td { padding: .25rem .35rem .25rem 0; vertical-align: middle; }
.lines-grid input, .lines-grid select { width: 100%; min-width: 4rem; }
.lines-grid input.num { text-align: right; }
.lines-grid td:first-child { width: 8.5rem; }
.lines-grid td:nth-child(2) { width: 40%; }
.lines-grid td:nth-child(5) { min-width: 10rem; }
a.link { color: var(--keep); }
.button-link.primary { background: var(--keep); color: var(--keep-ink); border-color: var(--keep); }
button.danger { color: var(--alert, #a3271f); border-color: currentColor; background: none; }
#send { white-space: nowrap; }

/* ---- the account page ---- */
.account-page { max-width: 40rem; }
.account-page h1 { margin-top: 1rem; }
.danger-zone { margin-top: 1.25rem; border-top: 1px solid var(--line); padding-top: .9rem; }
.danger-zone summary { cursor: pointer; font-weight: 600; color: var(--alert); }
.danger-zone[open] summary { margin-bottom: .6rem; }

/* Follow-ups: a late one in the alert colour, and the row's two actions side by side. */
td.alert { color: var(--alert); font-weight: 600; }
.row-actions { display: inline-flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
