:root {
  --bg: #f6f7f9; --card: #ffffff; --ink: #14181f; --muted: #5d6673; --line: #e3e6ea;
  --accent: #0f5bd8; --good: #11804a; --bad: #c0392b; --warn: #a86100;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1216; --card: #171b21; --ink: #e8ebef; --muted: #98a1ad; --line: #2a3038; --accent: #5b9bff; --good: #3ccf86; --bad: #ff6b5b; --warn: #f0b350; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 15px; }
.top { display: flex; gap: 12px; align-items: center; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 2; }
.brand { font-size: 18px; margin-right: auto; white-space: nowrap; }
#org { min-width: 0; max-width: 55vw; } .brand b { color: var(--accent); }
select, input, button, .btn { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
button, .btn { background: var(--accent); color: #fff; border-color: var(--accent); cursor: pointer; text-decoration: none; display: inline-block; }
button.ghost, .btn.ghost { background: transparent; color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.narrow { max-width: 380px; margin: 60px auto; }
.narrow label { display: block; margin-bottom: 12px; } .narrow input { width: 100%; margin-top: 4px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 12px; }
.tabs button { background: transparent; color: var(--muted); border: none; white-space: nowrap; }
.tabs button.on { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.range { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin-bottom: 12px; }
.range label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 2px; }
.big { font-size: 34px; font-weight: 650; letter-spacing: -0.5px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi .label { color: var(--muted); font-size: 13px; }
button.kpi.tap { display: block; width: 100%; text-align: left; font: inherit; color: inherit; cursor: pointer; border: 1px solid var(--line, rgba(127,127,127,.25)); min-height: 44px; }
button.kpi.tap:hover, button.kpi.tap:focus-visible { border-color: var(--accent, #007BFF); outline: none; }
.kpi .go { margin-top: 6px; font-weight: 600; color: var(--accent, #007BFF); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
td.n, th.n { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.neg { color: var(--bad); } .pos { color: var(--good); } .muted { color: var(--muted); } .warn { color: var(--warn); }
.err { color: var(--bad); min-height: 1.2em; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.bar { height: 8px; background: var(--accent); border-radius: 4px; min-width: 2px; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.tag.ok { color: var(--good); border-color: var(--good); } .tag.bad { color: var(--bad); border-color: var(--bad); }
.hash { font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; max-width: 90vw; }
form.inline { display: grid; gap: 8px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); align-items: end; }
form.inline label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 2px; }
@media (max-width: 600px) { .top { gap: 8px; padding: 10px 12px; } #logout { padding: 6px 8px; } .big { font-size: 28px; } td, th { padding: 6px 4px; } .hide-sm { display: none; } }

/* ---- Installed-app (PWA) and phone layout ---- */
:root { --brand: #00163f; --brand-ink: #ffffff; --brand-accent: #5bb8ff; --tabbar-h: 0px; }
html { -webkit-text-size-adjust: 100%; }
body { min-height: 100vh; min-height: 100dvh; -webkit-tap-highlight-color: transparent; }
.top { background: var(--brand); color: var(--brand-ink); border-bottom: none; padding-top: max(12px, env(safe-area-inset-top)); padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
.brand { display: flex; align-items: center; gap: 8px; } .brand img { height: 26px; width: auto; display: block; }
.brand b { color: var(--brand-accent); }
.top select, .top button.ghost { background: rgba(255,255,255,.08); color: var(--brand-ink); border-color: rgba(255,255,255,.25); }
.top select option { color: #14181f; background: #fff; }
.hint { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin: 0; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); font-size: 14px; }
.hint[hidden] { display: none; }
.hint button { padding: 2px 10px; font-size: 18px; }
.warnbar { color: var(--warn); }
.card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Phone app: Face ID / fingerprint lock screen and the receipt scan card */
#bioLock { position: fixed; inset: 0; z-index: 1000; background: #00163f; color: #fff; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; }
#bioLock .bio-box { max-width: 320px; display: flex; flex-direction: column; gap: 12px; align-items: center; }
#bioLock .bio-box img { border-radius: 16px; }
#bioLock button.ghost { color: #c9d6ff; border-color: transparent; }
.scan-card { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.scan-card button { font-size: 1.05em; padding: 12px 20px; }
.card table { min-width: 100%; }
button, .btn, select { min-height: 40px; }
@media (max-width: 850px) {
  :root { --tabbar-h: 60px; }
  /* 16px inputs stop iPhone from zooming in on focus */
  input, select, textarea { font-size: 16px; }
  .top { gap: 8px; }
  .brand span { display: none; }
  #org { flex: 1; max-width: none; }
  main { padding: 12px max(12px, env(safe-area-inset-right)) calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left)); }
  .card { padding: 12px; border-radius: 10px; }
  .card h3 { margin-top: 0; font-size: 17px; }
  .kpis { grid-template-columns: 1fr; gap: 10px; }
  .range { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
  .range label { min-width: 0; }
  .range label input { width: 100%; min-width: 0; }
  input, select { max-width: 100%; }
  .range #csv { grid-column: 1 / -1; text-align: center; }
  form.inline { grid-template-columns: 1fr; }
  .narrow { margin: 24px 12px; max-width: none; }
  /* Bottom tab bar, like a native app */
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 3; margin: 0; gap: 0; background: var(--card); border-top: 1px solid var(--line);
    padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); scroll-snap-type: x proximity; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button { flex: 1 0 auto; min-width: 76px; height: var(--tabbar-h); border-radius: 0; font-size: 13px; scroll-snap-align: start; border: none; border-top: 3px solid transparent; }
  .tabs button.on { background: transparent; border: none; border-top: 3px solid var(--accent); color: var(--accent); font-weight: 600; }
  .toast { bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); }
}
@media (display-mode: standalone) {
  .tabs button, .top, .brand { -webkit-user-select: none; user-select: none; }
}

/* Business / Personal switcher: one app, two separate sets of books. */
.modes { display: inline-flex; gap: 2px; padding: 3px; margin-bottom: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; }
.modes button { background: transparent; color: var(--muted); border: none; border-radius: 999px; padding: 6px 16px; font-weight: 600; }
.modes button.on { background: var(--ink); color: var(--card); }
@media (max-width: 850px) { .modes { display: flex; width: 100%; } .modes button { flex: 1; } }

/* ---- Invoices: send + getting paid ---- */
form.stack, .stack { display: grid; gap: 10px; }
form.stack label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 2px; }
form.stack label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); }
textarea { font: inherit; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); color: var(--ink); resize: vertical; }
details.card > summary { cursor: pointer; list-style-position: inside; }
details.card[open] > summary { margin-bottom: 12px; }
.sharegrid { display: grid; grid-template-columns: 170px 1fr; gap: 16px; align-items: start; }
.qrbox { text-align: center; font-size: 12px; } .qrbox svg { width: 100%; height: auto; border-radius: 8px; }
.share input[readonly] { width: 100%; }
@media (max-width: 600px) { .sharegrid { grid-template-columns: 1fr; } .qrbox svg { max-width: 200px; } }

/* Add-organization form */
form.stack label { display: block; margin-bottom: 12px; }
form.stack input, form.stack select { display: block; width: 100%; max-width: 420px; margin-top: 4px; }

tr.click { cursor: pointer; }

.pick { display: block; margin: 4px 0; font-weight: 400; }
.draft { border-top: 1px solid var(--line, #e3e6eb); padding: 8px 0; }
.draft h4 { margin: 4px 0; }
#aiForm textarea { width: 100%; box-sizing: border-box; font: inherit; }

/* Send invoice popup */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(10,15,30,.55); display: flex; justify-content: center; align-items: flex-start; overflow-y: auto; padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom)); }
.modal > .card { width: 100%; max-width: 640px; margin: auto 0; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.sharehead { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sharehead h3 { margin: 0; }
body.modal-open { overflow: hidden; }
.brandimgs { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.brandprev { height: 96px; border: 1px dashed var(--line); border-radius: 10px; display: flex; align-items: center; justify-content: center; background: #fff; margin-bottom: 8px; padding: 8px; }
.brandprev img { max-width: 100%; max-height: 100%; object-fit: contain; }
.brandprev.icon { width: 96px; }
.filebtn { position: relative; overflow: hidden; cursor: pointer; }
.filebtn input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
input[type=color] { width: 64px; height: 40px; padding: 2px; }
@media (max-width: 560px) { .brandimgs { grid-template-columns: 1fr; } }
/* Unpaid customer account: only the billing card shows. */
body.billing #tabs, body.billing #modes, body.billing #range, body.billing #org { display: none !important; }

/* ---- Settings + Connections (BIRCO-CONNECTIONS-SPEC-v1) ---- */
.set.wide { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 16px; align-items: start; }
.set-menu { display: flex; flex-direction: column; gap: 6px; }
.set-row { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; width: 100%; padding: 12px 14px; background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; }
.set-row.on { border-color: var(--accent); }
.set-row .muted { font-size: 13px; }
.cx-top h3 { margin-top: 0; }
.cx-legend { display: flex; flex-wrap: wrap; gap: 6px; }
.cx-gh { margin: 18px 0 2px; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.cx-gl { margin: 0 0 8px; }
.cx-card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 10px; }
.cx-head { display: flex; gap: 10px; align-items: center; }
.cx-mark { flex: none; width: 36px; height: 36px; border-radius: 8px; background: var(--brand); color: var(--brand-ink); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.cx-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cx-pill { flex: none; font-size: 12px; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.cx-pill.connected { color: var(--good); border-color: var(--good); }
.cx-pill.needs_attention, .cx-pill.needs_setup { color: var(--warn); border-color: var(--warn); }
.cx-does { margin: 10px 0 4px; }
.cx-note { margin: 0 0 4px; font-size: 13px; }
.cx-status { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.cx-btns { margin-top: 10px; }

/* ---- BIRCO-DESIGN-SPEC-v1.1 (PontiMax standard, 2026-11-18) ----
   pmx-kit.css loads after this file and owns the palette (light by default, dark when the phone is dark, same tokens as PontiMax).
   These lines map BircoBooks' own names onto the kit. Change colors in the kit, never here. */
:root { --bg: var(--pmx-bg, #e9edf2); --card: var(--pmx-surface, #ffffff); --ink: var(--pmx-ink, #0f1d2e); --muted: var(--pmx-muted, #566579); --line: var(--pmx-line, #d3dae4);
  --accent: var(--pmx-accent, #e8590c); --good: var(--pmx-ok, #1d7a4c); --bad: var(--pmx-bad, #c42b2b); --warn: var(--pmx-warn, #a86a10);
  --wm-silver: #C0C6CC; --wm-blue: #007BFF; --wm-top: var(--pmx-wm-top, #0F2437); --brand: var(--card); --brand-ink: var(--ink); --brand-accent: var(--wm-blue); }
body { font-family: var(--f-body, "IBM Plex Sans", sans-serif); }
.big, .num, td.amt { font-family: var(--f-mono, "IBM Plex Mono", monospace); font-variant-numeric: tabular-nums; }
/* Top bar like PontiMax: surface background, hairline, wordmark left */
.top { background: var(--card); color: var(--ink); border-bottom: 1px solid var(--line); }
.top select, .top button.ghost { background: var(--pmx-surface2, var(--card)); color: var(--ink); border-color: var(--line); }
.top select option { color: var(--ink); background: var(--card); }
.wm { font-family: "Montserrat", "Arial Black", Arial, sans-serif; font-weight: 800; letter-spacing: .015em; font-size: 20px; line-height: 1; white-space: nowrap; }
.wm .wm-s, .top .wm .wm-s { color: var(--wm-top); } .wm .wm-b, .brand b { color: var(--wm-blue); }
.top #logout { display: none; }
/* Buttons: PontiMax orange, 6px corners, accent ink text */
button, .btn { background: var(--accent); color: var(--pmx-accent-ink, #fff); border-color: var(--accent); border-radius: var(--pmx-r, 6px); font-weight: 600; }
button.ghost, .btn.ghost { background: transparent; color: var(--accent); }
select, input, textarea { border-radius: var(--pmx-r, 6px); }
.card { border-radius: var(--pmx-r, 6px); }
.hdr-ic { min-width: 44px; min-height: 44px; padding: 0; display: inline-grid; place-items: center; border-radius: var(--pmx-r, 6px); background: var(--pmx-surface2, transparent); border: 1px solid var(--line); color: var(--ink); }
.top .hdr-ic { color: var(--ink); }
.hdr-ic[hidden], .top [hidden] { display: none !important; }
.hdr-ic svg { pointer-events: none; }
.top { touch-action: manipulation; }
.brand.wm { display: block; gap: 0; }
.avatar { border-radius: 50%; width: 44px; font-weight: 600; font-size: 14px; letter-spacing: .02em; }
.set-row { flex-direction: row; align-items: center; gap: 14px; border-radius: var(--pmx-r, 6px); }
.set-row .set-tx { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.set-row .pmx-chev { color: var(--muted); font-size: 1.6rem; line-height: 1; }
.set-foot { margin-top: 18px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }
#bb-version { color: var(--muted); font-size: 11px; user-select: all; }
/* Phone (850px and below, same as PontiMax): bottom tab bar on the rail color, 62px plus safe area, active tab orange */
@media (max-width: 850px) {
  :root { --tabbar-h: var(--tab-h, 62px); }
  .brand span.wm-s, .brand span.wm-b, .brand span.wm-tm { display: inline; }
  button, .btn { min-height: 42px; }
  .card { border-radius: var(--pmx-r, 6px); }
  .tabs { background: var(--pmx-rail, var(--card)); border-top: 1px solid var(--line); }
  .tabs button { color: var(--pmx-rail-muted, var(--muted)); background: transparent; }
  .tabs button.on { color: var(--pmx-rail-ink, var(--ink)); border-top: 3px solid var(--accent); background: transparent; }
}

/* Opened from PontiMax Assistant IQ: small text link back to the hub (PontiMax style, nothing else changes). */
.pmiq-back { font-size: 13px; font-weight: 600; color: var(--pmx-accent); text-decoration: none; white-space: nowrap; }
.pmiq-back:hover, .pmiq-back:focus-visible { text-decoration: underline; }
@media (max-width: 600px) { .pmiq-back { font-size: 12px; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; } }

/* First-run checklist on Cash */
.start-steps{margin:8px 0 0;padding-left:20px}
.start-steps li{margin:10px 0;line-height:1.4}
.start-steps li button{margin-right:6px}
.start-steps li.ok{color:var(--muted,#5d6673)}

/* Checkbox rows inside narrow forms (sign-up terms): box and its text sit on one line, box at its natural size. */
.narrow label.row { display: flex; flex-wrap: nowrap; align-items: flex-start; gap: 8px; }
.narrow label.row input[type=checkbox], .narrow input[type=checkbox], .narrow input[type=radio] { width: auto; flex: none; margin-top: 3px; min-height: 0; }
.narrow label.row > span { flex: 1; min-width: 0; line-height: 1.4; }

/* Wordmark trademark: small and raised so it never runs into "IQ"; header fits narrow phones (Edgar 2026-11-21). */
.wm .wm-tm { font-size: .42em; font-weight: 700; vertical-align: super; line-height: 0; letter-spacing: 0; margin-left: 1px; }
.top #org[hidden] { display: none !important; }
@media (max-width: 420px) {
  .top { padding: 10px 12px; }
  .wm { font-size: 17px; }
  .top #org { min-width: 0; flex: 1 1 0; }
}
@media (max-width: 340px) { .wm { font-size: 15px; } }

/* ---- Fit any screen (public/fit.js): wide tables become stacked cards, no sideways scrolling ---- */
img, svg, video, canvas { max-width: 100%; }
main, .card { min-width: 0; }
table.stack, table.stack > tbody, table.stack > thead, table.stack tr, table.stack td, table.stack th { display: block; width: 100%; min-width: 0; }
table.stack tr.fit-head { display: none; }
table.stack tr { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 0 0 10px; background: var(--card); }
table.stack tr:has(> th:only-child) { border: 0; padding: 8px 0 0; background: none; }
table.stack td, table.stack th { border: 0; padding: 4px 0; text-align: left; white-space: normal; overflow-wrap: anywhere; }
table.stack td.n { text-align: left; font-size: 1.05em; }
table.stack td[data-label]:not([data-label=""])::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); margin-bottom: 1px; }
table.stack td:empty { display: none; }
table.stack .row { width: 100%; }
table.stack .row select, table.stack .row input:not([type=checkbox]) { flex: 1 1 100%; width: 100%; min-width: 0; }
table.stack .row button, table.stack .row .btn { flex: 1 1 auto; }
table.stack form.inline { grid-template-columns: 1fr; }
table.stack td.hide-sm { display: block; }

/* ---- Approved v3 logo (bircobooks/logo/v3): mark + wordmark, light/dark versions, sized for any screen ---- */
.brand.logo { display: flex; align-items: center; gap: 8px; min-width: 0; }
.brand.logo .logo-mark { height: 30px; width: auto; display: block; flex: none; }
.brand.logo .logo-word { display: block; min-width: 0; }
.brand.logo .logo-word img { height: 24px; width: auto; max-width: 100%; display: block; }
.login-logo { display: flex; flex-direction: column; align-items: center; gap: 10px; margin: 4px 0 14px; }
.login-logo .logo-mark { height: 72px; width: auto; display: block; }
.login-logo .logo-word img { width: min(280px, 100%); height: auto; display: block; }
@media (max-width: 600px) { .brand.logo .logo-mark { height: 26px; } .brand.logo .logo-word img { height: 20px; } }
@media (max-width: 460px) { .top:has(#org:not([hidden])) .brand.logo .logo-word { display: none; } .top:has(#org:not([hidden])) .brand.logo .logo-mark { height: 30px; } }
@media (max-width: 360px) { .top .brand.logo .logo-mark { display: none; } .brand.logo .logo-word img { height: 18px; } }

/* Invoice actions stay beside the selected invoice, including in stacked mobile rows. */
.invoice-buttons button, .invoice-buttons select, .invoice-buttons .btn, button.invoice-state {
  min-height: 44px; touch-action: manipulation;
}
button.invoice-state { font-weight: 600; white-space: nowrap; border-radius: 999px; }
.invoice-confirmation { margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: var(--bg); }
.invoice-confirmation p, .invoice-help, .invoice-feedback { margin: 6px 0 0; overflow-wrap: anywhere; }
.invoice-confirmation p { margin: 0 0 8px; }
.invoice-feedback:empty { display: none; }
.invoice-buttons [aria-invalid="true"] { border-color: var(--bad); }

/* Keep the project beside invoice status in both table rows and narrow cards. */
.invoice-project { margin-top: 5px; min-width: 8em; max-width: 24em; overflow-wrap: anywhere; }
.invoice-project summary { cursor: pointer; }
.invoice-line-text { white-space: pre-line; }
