/* Bookkeeper: "Sunroom" (light) + "Dusk" (dark). Chosen 2026-11-10 from the four-look pitch.
   Every color is a token. Contrast for each text pair is measured by scripts/contrast-test.mjs,
   which reads THIS file, and the build fails under 4.5:1 in either theme. */
:root, :root[data-theme="light"] {
  --bg:#eff7f5; --card:#ffffff; --surface2:#e6f1ee; --line:#d5e6e2;
  --ink:#1b2b33; --muted:#52666d;
  --accent:#7b2d8e; --btn-ink:#ffffff; --link:#6e267f;
  --soft:#f3e4f6; --soft-ink:#5f1f6f;
  --good:#0a6f67; --bad:#b9382a;
  --warn-bg:#fde9b5; --warn-ink:#5c4300;
  --shadow:0 6px 18px rgba(27,43,51,.08);
  --glass:rgba(255,255,255,.92);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg:#171423; --card:#211d31; --surface2:#2a2540; --line:#352f4a;
  --ink:#f1eef8; --muted:#a39cb8;
  --accent:#f5b83d; --btn-ink:#241800; --link:#f7c75f;
  --soft:#332a4d; --soft-ink:#e2d4ff;
  --good:#3fd6c2; --bad:#ff7482;
  --warn-bg:#40320f; --warn-ink:#f7c75f;
  --shadow:0 10px 26px rgba(0,0,0,.42);
  --glass:rgba(33,29,49,.94);
  color-scheme: dark;
}
:root { --r:18px; --r-sm:12px; --brand:#7b2d8e; /* the logo tile; carries no text, same in both themes */
  --font: ui-rounded, "SF Pro Rounded", "Segoe UI Variable Display", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --sl: env(safe-area-inset-left, 0px); --sr: env(safe-area-inset-right, 0px);
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px); }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.35;
  overflow: hidden; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: clamp(24px, 4vw, 30px); font-weight: 800; }
h2 { font-size: 18px; font-weight: 800; }
h3 { font-size: 13px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
a { color: var(--link); }
.muted { color: var(--muted); } .small { font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--good); } .neg { color: var(--bad); }

/* version badge: light 5.9:1 (#52666d on #eff7f5), dark 6.6:1 (#a39cb8 on #171423) */
#ver { position: fixed; z-index: 5000; top: calc(var(--st) + 2px); left: calc(var(--sl) + 10px);
  font-size: 9px; line-height: 1; color: var(--muted); pointer-events: none; font-variant-numeric: tabular-nums; }

.center-screen { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(8px, 2vh, 18px); padding: calc(var(--st) + 14px) calc(var(--sr) + 16px) calc(var(--sb) + 10px) calc(var(--sl) + 16px); background: var(--bg); text-align: center; }
.logo { width: clamp(44px, 9vh, 68px); aspect-ratio: 1; border-radius: 28%; background: var(--brand) url("/icons/glyph.svg") center / 62% no-repeat; }

/* ---------- PIN keypad (team-manager/docs/pin-keypad-standard.md) ---------- */
.pin-gate { display: flex; flex-direction: column; align-items: center; gap: clamp(8px, 2vh, 20px);
  touch-action: manipulation; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.pin-dots { display: flex; gap: 10px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); }
.pin-dots span.on { background: var(--ink); }
.pin-gate.busy .pin-dots span.on { animation: bk-pinpulse .9s ease-in-out infinite; }
@keyframes bk-pinpulse { 50% { opacity: .35; } }
.pin-gate.bad .pin-dots { animation: bk-pinshake .35s; }
@keyframes bk-pinshake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pin-msg { min-height: 1.35em; font-size: 16px; color: var(--muted); text-align: center; }
.pin-pad { display: grid; grid-template-columns: repeat(3, clamp(64px, 22vw, 84px)); gap: clamp(8px, 1.8vh, 16px); }
.pin-pad button { height: clamp(64px, 10vh, 84px); border-radius: 50%; border: 1px solid var(--line); background: var(--card); color: var(--ink);
  font-family: inherit; font-weight: 700; font-size: clamp(26px, 4vh, 32px); line-height: 1; touch-action: manipulation; cursor: pointer; }
.pin-pad button:active { background: var(--accent); color: var(--btn-ink); }
.pin-pad button:disabled { opacity: .5; }
.pin-pad button.pin-del { border: none; background: transparent; font-size: 24px; }
@media (orientation: landscape) and (max-height: 520px) {
  #gate { flex-direction: row; flex-wrap: wrap; column-gap: 28px; }
  #gate .pin-pad { grid-template-columns: repeat(6, 56px); gap: 8px; }
  #gate .pin-pad button { height: 56px; font-size: 24px; }
  #gate .small { display: none; }
}

/* ---------- app frame: fixed header and tabs, only the middle ever scrolls ---------- */
.app { height: 100%; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); }
.top { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(var(--st) + 14px) calc(var(--sr) + 14px) 8px calc(var(--sl) + 14px); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex-wrap: wrap; }
.brand { flex-wrap: nowrap; }
.brand-name { font-weight: 800; font-size: 20px; }
.brand .logo-sm { width: 30px; flex: none; border-radius: 9px; }
/* On a phone the tile stands in for the name, so the books switcher stays on the header row. */
@media (max-width: 520px) { .brand-name { display: none; } }
@media (min-width: 521px) { .brand .logo-sm { display: none; } }
select, input, textarea, button { font-family: inherit; font-size: 16px; color: var(--ink); }
.book-pill { appearance: none; -webkit-appearance: none; border: 0; border-radius: 999px; background: var(--soft); color: var(--soft-ink);
  font-weight: 700; padding: 7px 30px 7px 14px; max-width: 46vw; text-overflow: ellipsis; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%; background-size: 5px 5px; background-repeat: no-repeat; }
.seg { display: inline-flex; background: var(--surface2); border-radius: 999px; padding: 3px; flex: none; }
.seg button { border: 0; background: transparent; color: var(--muted); font-weight: 700; font-size: 14px; min-width: 34px; height: 30px; border-radius: 999px; cursor: pointer; padding: 0 10px; }
.seg button.on { background: var(--accent); color: var(--btn-ink); }

main { min-height: 0; min-width: 0; padding: 4px calc(var(--sr) + 14px) 10px calc(var(--sl) + 14px); display: flex; flex-direction: column; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; box-shadow: var(--shadow); min-width: 0; }
.card.fill { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.card.fill > .card-head { padding: 12px 14px 8px; }
.scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.empty { padding: 26px 16px; text-align: center; color: var(--muted); }

.tabs { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); background: var(--glass); border-top: 1px solid var(--line);
  padding: 6px calc(var(--sr) + 4px) calc(var(--sb) + 6px) calc(var(--sl) + 4px); }
.tabs button { border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 11px; font-weight: 600; padding: 4px 0; cursor: pointer; min-width: 0; position: relative; }
.tabs svg { width: 22px; height: 22px; }
.tabs button.on { color: var(--link); font-weight: 800; }
.tabs .dot { position: absolute; top: 0; left: calc(50% + 6px); min-width: 17px; height: 17px; border-radius: 99px; background: var(--warn-bg); color: var(--warn-ink);
  font-size: 11px; font-weight: 800; display: grid; place-items: center; padding: 0 4px; }

/* ---------- pieces ---------- */
.btn { border: 1px solid var(--accent); background: var(--accent); color: var(--btn-ink); font-weight: 700; border-radius: var(--r-sm);
  padding: 9px 14px; min-height: 40px; cursor: pointer; white-space: nowrap; }
.btn.ghost { background: transparent; color: var(--link); border-color: var(--line); }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--line); }
.btn.sm { padding: 6px 11px; min-height: 34px; font-size: 14px; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn { border: 0; background: var(--surface2); color: var(--ink); width: 38px; height: 38px; border-radius: 50%; cursor: pointer; flex: none; font-size: 16px; }
.chip { display: inline-block; font-size: 12px; font-weight: 700; border-radius: 99px; padding: 3px 9px; background: var(--soft); color: var(--soft-ink); white-space: nowrap; }
.chip.warn { background: var(--warn-bg); color: var(--warn-ink); }
.chip.plain { background: var(--surface2); color: var(--ink); }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field > span { font-size: 13px; font-weight: 700; color: var(--muted); }
.in, select.in, textarea.in { width: 100%; min-width: 0; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: var(--r-sm); padding: 9px 11px; min-height: 42px; }
.in:focus-visible, .btn:focus-visible, .seg button:focus-visible, .tabs button:focus-visible, .book-pill:focus-visible, .icon-btn:focus-visible, summary:focus-visible { outline: 2px solid var(--link); outline-offset: 2px; }
.row2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form-msg { min-height: 1.3em; font-size: 14px; color: var(--muted); }
.form-msg.err { color: var(--bad); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 15px; }
.check input { width: 20px; height: 20px; flex: none; accent-color: var(--accent); margin-top: 1px; }

/* Home */
.home { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr); flex: 1; min-height: 0; }
.month-nav { display: flex; align-items: center; gap: 6px; }
.month-nav b { min-width: 9.5ch; text-align: center; }
.totals { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 10px; }
.totals span { display: block; font-size: 12.5px; color: var(--muted); }
.totals strong { font-size: clamp(15px, 4.4vw, 22px); font-weight: 800; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 9px; background: var(--surface2); margin-top: 10px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 9px; }
.needs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 8px; }
.need { border: 1px solid var(--line); background: var(--surface2); color: var(--ink); border-radius: var(--r-sm); padding: 8px 10px; text-align: left; cursor: pointer; display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.need b { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.need span { font-size: 13px; color: var(--muted); min-width: 0; }
.need.hot { background: var(--warn-bg); border-color: transparent; }
.need.hot b, .need.hot span { color: var(--warn-ink); }

/* Transactions */
.tx { display: grid; grid-template-columns: 36px minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; padding: 10px 14px; border-top: 1px solid var(--line); }
.tx:first-child { border-top: 0; }
.tx .ic { width: 36px; height: 36px; border-radius: 12px; background: var(--soft); color: var(--soft-ink); display: grid; place-items: center; }
.tx .ic svg { width: 18px; height: 18px; }
.tx .nm { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 0; background: none; padding: 0; text-align: left; cursor: pointer; color: var(--ink); max-width: 100%; display: block; }
.tx .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tx .amt { font-weight: 800; font-variant-numeric: tabular-nums; }
.tx .ctl { grid-column: 2 / -1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tx .ctl select { flex: 1 1 150px; min-width: 0; max-width: 260px; min-height: 36px; padding: 5px 9px; }
.divider { padding: 8px 14px; font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); background: var(--surface2); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .in { flex: 1 1 160px; }
.drop-hint { display: none; }
@media (max-width: 520px) { .toolbar .in[type="search"] { flex-basis: 100%; } .toolbar .btn { flex: 1; } }
@media (min-width: 900px) and (hover: hover) { .drop-hint { display: block; } }
.drop { outline: 3px dashed var(--accent); outline-offset: -6px; }

/* Invoices and reports */
.inv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; padding: 11px 14px; border-top: 1px solid var(--line); align-items: center; }
.inv:first-child { border-top: 0; }
.inv .ctl { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
table.pl { width: 100%; border-collapse: collapse; }
table.pl td, table.pl th { padding: 8px 14px; text-align: left; border-top: 1px solid var(--line); }
table.pl td:last-child, table.pl th:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.pl tr.head th { background: var(--surface2); font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); border-top: 0; }
table.pl tr.sum td { font-weight: 800; }

/* Settings */
.settings { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
details.card { padding: 0; }
details.card > summary { list-style: none; cursor: pointer; padding: 14px; font-weight: 800; display: flex; justify-content: space-between; align-items: center; gap: 10px; border-radius: var(--r); }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "+"; color: var(--muted); font-size: 20px; line-height: 1; }
details.card[open] > summary::after { content: "–"; }
details.card > summary small { font-weight: 600; color: var(--muted); font-size: 13px; margin-left: auto; text-align: right; }
.d-body { padding: 0 14px 14px; display: flex; flex-direction: column; gap: 12px; }
.list-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-top: 1px solid var(--line); min-width: 0; }
.list-row:first-child { border-top: 0; }
.list-row > :first-child { min-width: 0; overflow-wrap: anywhere; }
.logbox { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 2px 10px; }

/* Sheet (always has its own close button) */
.sheet { position: fixed; inset: 0; z-index: 2000; background: rgba(10, 8, 20, .5); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card { background: var(--card); color: var(--ink); width: min(560px, 100%); max-height: calc(100% - var(--st) - 20px); overflow-y: auto; border-radius: var(--r) var(--r) 0 0;
  padding: 16px calc(var(--sr) + 16px) calc(var(--sb) + 16px) calc(var(--sl) + 16px); display: flex; flex-direction: column; gap: 12px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

#toast { position: fixed; left: 50%; bottom: calc(76px + var(--sb)); transform: translateX(-50%) translateY(160px); transition: transform .25s ease;
  background: var(--ink); color: var(--bg); padding: 10px 12px 10px 16px; border-radius: 999px; font-size: 14.5px; z-index: 3000;
  display: flex; gap: 10px; align-items: center; max-width: min(92vw, 520px); }
#toast.show { transform: translateX(-50%) translateY(0); }
#toast button { background: transparent; border: 0; color: var(--bg); font-weight: 800; cursor: pointer; font-size: 14.5px; padding: 2px 4px; }
#toastAct { text-decoration: underline; }

/* ---------- wider screens: tabs become a side rail, Home goes two-up ---------- */
@media (min-width: 900px) {
  .app { grid-template-columns: 190px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .top { grid-column: 1 / -1; padding-left: calc(var(--sl) + 22px); padding-right: calc(var(--sr) + 22px); }
  .tabs { grid-row: 2; grid-column: 1; display: flex; flex-direction: column; gap: 4px; border-top: 0; background: transparent; padding: 6px 8px 14px calc(var(--sl) + 14px); }
  .tabs button { flex-direction: row; gap: 10px; font-size: 15px; padding: 10px 12px; border-radius: var(--r-sm); justify-content: flex-start; }
  .tabs button.on { background: var(--soft); color: var(--soft-ink); }
  .tabs .dot { position: static; margin-left: auto; }
  main { grid-row: 2; grid-column: 2; padding: 4px calc(var(--sr) + 22px) 18px 8px; }
  .home { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); grid-template-rows: auto minmax(0, 1fr); }
  .home .recent { grid-column: 2; grid-row: 1 / -1; }
  .tx { grid-template-columns: 36px minmax(0, 1fr) auto auto; }
  .tx .ctl { grid-column: auto; grid-row: 1; grid-column-start: 3; flex-wrap: nowrap; }
  .tx .amt { grid-column: 4; min-width: 9ch; text-align: right; }
  .inv { grid-template-columns: minmax(0, 1fr) auto auto; }
  .inv .ctl { grid-column: auto; }
  .sheet { align-items: center; }
  .sheet-card { border-radius: var(--r); }
  #toast { bottom: calc(24px + var(--sb)); }
}
/* A phone on its side is short, not wide: tighten instead of taking the desktop layout's spacing. */
@media (max-height: 480px) {
  .top { padding-top: calc(var(--st) + 10px); padding-bottom: 4px; }
  .card { padding: 10px; }
  .totals { margin-top: 4px; } .bar { display: none; }
  .tabs button { flex-direction: row; justify-content: center; gap: 6px; }
  .tabs .dot { position: static; }
  .needs { gap: 6px; } .need { padding: 5px 8px; } .need b { font-size: 16px; }
}
/* Short and wide (a phone on its side): Home goes two-up so the Latest list keeps real height. */
@media (min-width: 600px) and (max-height: 560px) {
  .home { grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); grid-template-rows: auto minmax(0, 1fr); }
  .home .recent { grid-column: 2; grid-row: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
