:root {
  --bg: #f6f4ef; --card: #fff; --ink: #1c2230; --muted: #5b6370; --line: #e5e1d8;
  --brand: #1d3557; --brand-ink: #fff; --accent: #c9a227; --me: #e8eef8; --bot: #fff; --danger: #b42318;
  --link: #1d4ed8; --warn: #92400e; --ok: #166534; color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12151c; --card: #1b2029; --ink: #e8e9ec; --muted: #9aa1ad; --line: #2c333f;
    --brand: #2f5b93; --me: #22324a; --bot: #1b2029; --danger: #f87171; --link: #8ab4ff; --warn: #fbbf24; --ok: #4ade80; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
[hidden] { display: none !important; }
h1, h3 { margin: 0 0 .5rem; }
h3 { font-size: 1rem; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; }
button, .button { background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 8px; padding: .55rem .9rem; font: inherit; cursor: pointer; text-decoration: none; display: inline-block; }
button.link { background: none; color: inherit; text-decoration: underline; padding: .3rem; }
button.danger { background: var(--danger); }
input, select, textarea { font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { display: grid; gap: .7rem; width: min(340px, 100%); }

.top { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: .8rem; padding: .6rem 16px; background: var(--brand); color: var(--brand-ink); flex-wrap: wrap; }
.top nav { display: flex; gap: .25rem; overflow-x: auto; flex: 1; }
.top nav button { background: transparent; color: inherit; opacity: .75; white-space: nowrap; padding: .4rem .6rem; }
.top nav button.on { opacity: 1; background: rgba(255,255,255,.15); }
main { max-width: 1000px; margin: 0 auto; padding: 16px; }
.tab { display: none; }
.tab.on { display: block; }
.toolbar { display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar input[type=search] { flex: 1; min-width: 180px; }
.pill { background: var(--accent); color: #1c1c1c; border-radius: 999px; padding: .25rem .7rem; font-weight: 600; }

/* chat */
#tab-talk.on { display: flex; flex-direction: column; height: calc(100vh - 90px); }
.chat { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .6rem; padding-bottom: 1rem; }
.msg { max-width: 85%; padding: .6rem .8rem; border-radius: 12px; border: 1px solid var(--line); white-space: pre-wrap; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--me); }
.msg.bot { align-self: flex-start; background: var(--bot); }
.msg .meta { font-size: .75rem; color: var(--muted); margin-top: .25rem; }
.msg img { max-width: 220px; max-height: 220px; border-radius: 8px; display: block; margin-bottom: .3rem; }
.msg audio { max-width: 100%; display: block; margin-bottom: .3rem; }
.composer { border-top: 1px solid var(--line); padding-top: .6rem; }
.composer .row { display: flex; gap: .4rem; align-items: flex-end; }
.composer textarea { flex: 1; resize: none; max-height: 160px; }
.iconbtn { background: var(--card); color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .65rem; cursor: pointer; font-size: 1.1rem; line-height: 1.2; }
.iconbtn.rec { background: var(--danger); color: #fff; }
.pending { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: .4rem; }
.pending .chip { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: .2rem .5rem; font-size: .85rem; display: flex; align-items: center; gap: .3rem; }
.pending img { height: 40px; border-radius: 4px; }
.typing { color: var(--muted); font-style: italic; }

/* stats & lists */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .8rem; }
.stat b { display: block; font-size: 1.4rem; }
.stat span { color: var(--muted); font-size: .85rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: .8rem; }
.bar { display: flex; justify-content: space-between; gap: .5rem; padding: .25rem 0; border-bottom: 1px dashed var(--line); }
.bar:last-child { border-bottom: 0; }
.table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.table th, .table td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.table tr.click { cursor: pointer; }
.table tr.click:hover { background: var(--me); }
.num { text-align: right !important; white-space: nowrap; }
.x { background: none; color: var(--muted); padding: 0 .3rem; text-decoration: none; }
.nowrap { white-space: nowrap; }
button:disabled { opacity: .5; cursor: default; }
@media (max-width: 640px) {
  .table .hide-sm { display: none; }
  .msg { max-width: 95%; }
}

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--card); color: var(--ink); width: min(720px, calc(100vw - 32px)); max-height: 85vh; }
dialog::backdrop { background: rgba(0,0,0,.4); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem .8rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; white-space: pre-wrap; }

.setup-item { padding: .6rem 0; border-bottom: 1px dashed var(--line); }
.setup-item:last-child { border-bottom: 0; }
.setup-item code, .paste code { background: var(--me); padding: .05rem .35rem; border-radius: 4px; word-break: break-all; }
.paste { margin-top: .3rem; }

button.small { padding: .25rem .55rem; font-size: .85rem; }
button.ghost { background: var(--card); color: var(--ink); border: 1px solid var(--line); }
.card.review { margin-bottom: 1rem; border-color: var(--accent); }

.who { padding: .6rem 0; border-top: 1px dashed var(--line); }
.who:first-of-type { border-top: 0; }
.who-opts { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .4rem; }

.stat.warn { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, var(--card)); }
.stat .sub { display: block; font-size: .8rem; }
.warn-text { color: #b45309; font-weight: 600; }
.legend { font-size: .8rem; color: var(--muted); margin: -.2rem 0 .5rem; }
.legend i, .bars i { display: inline-block; }
.legend i { width: .7rem; height: .7rem; border-radius: 2px; margin: 0 .25rem 0 .6rem; vertical-align: -1px; }
.legend i:first-child { margin-left: 0; }
i.don { background: #c9a227; } i.pay { background: #1d3557; } i.wait { background: #d97706; opacity: .6; }
@media (prefers-color-scheme: dark) { i.pay { background: #6f9bd1; } }
.mrow { display: grid; grid-template-columns: 2.4rem 1fr auto; gap: .5rem; align-items: center; padding: .15rem 0; }
.mname { color: var(--muted); font-size: .85rem; }
.bars { display: flex; height: .8rem; background: var(--me); border-radius: 4px; overflow: hidden; }
.bars i { height: 100%; }

#monTable, #donList, #actList, #peopleList { overflow-x: auto; }

/* books, expenses, ask Claude */
#askFab { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 5; border-radius: 999px; padding: .7rem 1.1rem; box-shadow: 0 4px 14px rgba(0,0,0,.25); background: var(--accent); color: #1c1c1c; font-weight: 600; }
.asklog { max-height: 45vh; overflow-y: auto; display: flex; flex-direction: column; gap: .5rem; margin-bottom: .8rem; }
.asklog .msg { max-width: 100%; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem; margin-bottom: .8rem; }
.form-grid label { display: grid; gap: .2rem; font-size: .85rem; color: var(--muted); }
.form-grid input, .form-grid select { width: 100%; }
.prow { display: grid; grid-template-columns: 7rem 6rem 1fr 5.5rem auto; gap: .4rem; align-items: center; margin-bottom: .4rem; }
.prow input, .prow select { min-width: 0; width: 100%; }
@media (max-width: 640px) { .prow { grid-template-columns: 1fr 1fr; } .prow .wide { grid-column: 1 / -1; } }
.left { font-weight: 600; }
.left.ok { color: #15803d; }
.left.bad { color: var(--danger); }
.dlg-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }
.check-item { padding: .35rem 0; display: flex; gap: .5rem; }
.check-item button { margin-left: auto; }
.qb-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .6rem; }
.qb-grid label { display: grid; gap: .2rem; font-size: .85rem; color: var(--muted); }
.qb-grid input, .qb-grid textarea { width: 100%; }
details summary { cursor: pointer; margin: .4rem 0; }
.tag { font-size: .75rem; border-radius: 999px; padding: .05rem .5rem; background: var(--me); }
.tag.personal { background: #fde68a; color: #1c1c1c; }
main { padding-bottom: 5rem; }

/* a Close button that stays at the top of long windows, and clicking outside closes them */
.dlg-top { position: sticky; top: -1rem; z-index: 3; display: flex; justify-content: flex-end; margin: -1rem -1rem .5rem; padding: .5rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); }
#receiptBody, #personBody { overflow-x: auto; }

/* readable links, big tap targets, no sideways scrolling on phones */
a { color: var(--link); }
.warn-text { color: var(--warn); }
.left.ok { color: var(--ok); }
input, select, textarea { font-size: 16px; min-height: 44px; }
button, .button { min-height: 44px; }
button.x, .iconbtn { min-width: 44px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.card, dialog { overflow-x: auto; }
.menu { display: none; }
.toast { position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 50; background: var(--danger); color: #111; padding: .8rem 1rem; border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.3); }
.needs h3 { margin-bottom: .6rem; }
.need { display: flex; gap: .8rem; align-items: center; width: 100%; text-align: left; background: var(--card); color: var(--ink); border: 1px solid var(--line); border-left: 6px solid var(--accent); margin-bottom: .5rem; }
.need.now { border-left-color: var(--danger); }
.need b { font-size: 1.4rem; min-width: 2rem; text-align: center; }
.need span { display: flex; flex-direction: column; }
.need small { color: var(--muted); }
.needs { margin-bottom: 1rem; }
#tab-talk.on { height: calc(100dvh - 120px); }
@media (max-width: 700px) {
  .top { gap: .4rem; }
  .top strong { display: none; }
  .menu { display: block; flex: 1; text-align: left; }
  .top nav { display: none; flex-basis: 100%; flex-direction: column; overflow: visible; }
  .top nav.open { display: flex; }
  .top nav button { text-align: left; font-size: 1.05rem; opacity: 1; }
  table { display: block; overflow-x: auto; max-width: 100%; }
  main { padding: 12px; }
}
.neg { color: var(--danger); }
.chat { padding-bottom: 1.5rem; scroll-padding-bottom: 1.5rem; }

/* answer cards: one payment, big buttons, nothing to scroll sideways */
.paycard { border: 1px solid var(--line); border-radius: 12px; padding: .8rem; margin: .6rem 0; background: var(--card); }
.paycard[hidden] { display: none; }
.pc-top { display: flex; justify-content: space-between; gap: .6rem; font-size: 1.1rem; }
.pc-amt { font-weight: 700; white-space: nowrap; }
.pc-memo { margin: .25rem 0 .5rem; }
.pc-btns, .pc-more, .pc-part { display: flex; flex-direction: column; gap: .4rem; margin-top: .4rem; }
.pc-btns button, .pc-more button, .pc-part button { width: 100%; min-height: 48px; text-align: center; }
.pc-more[hidden], .pc-part[hidden] { display: none; }
.ws-res { display: flex; flex-direction: column; gap: .4rem; }
button.yes { background: var(--ok-bg, #166534); color: #fff; }
button.no { background: #991b1b; color: #fff; }
.pc-part label, .pc-more label { display: flex; flex-direction: column; gap: .25rem; }
@media (min-width: 701px) {
  .pc-btns { flex-direction: row; flex-wrap: wrap; } .pc-btns button { width: auto; flex: 1 1 11rem; }
}

/* every other table turns into a stack of cards on a phone, so the whole row is readable and its buttons are reachable */
@media (max-width: 700px) {
  table.table, table.table tbody { display: block; width: 100%; overflow: visible; }
  table.table tr { display: block; border: 1px solid var(--line); border-radius: 12px; padding: .5rem .7rem; margin: 0 0 .6rem; background: var(--card); }
  table.table tr:has(th) { display: none; }
  table.table td { display: flex; justify-content: space-between; gap: .8rem; padding: .2rem 0; border: 0; text-align: right; }
  table.table td::before { content: attr(data-label); color: var(--muted); text-align: left; flex: 0 0 auto; }
  table.table td:not([data-label])::before, table.table td[data-label=""]::before { content: none; }
  table.table td.hide-sm { display: flex; }
  table.table td.nowrap, table.table td:last-child:has(button) { flex-wrap: wrap; justify-content: flex-start; }
  table.table td button, table.table td .button { min-height: 44px; }
}
main { padding-bottom: 96px; }
.qstatus { margin-bottom: 1rem; border-color: var(--accent); }
.qbar { background: var(--line); border-radius: 8px; height: 12px; overflow: hidden; margin: .4rem 0; }
.qbar > div { background: var(--accent); height: 100%; transition: width .6s; }
.bar.click { cursor: pointer; } .bar.click:hover { background: var(--line); } .bar[hidden] { display: none; }
details.more { margin: 1rem 0; } details.more > summary { cursor: pointer; font-weight: 600; padding: .6rem .8rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; min-height: 44px; }
details.more[open] > summary { margin-bottom: .8rem; }
tr.click { cursor: pointer; } tr.click:hover { background: var(--line); }
.fundcard { border: 1px solid var(--line); border-radius: 12px; padding: .8rem; margin: .6rem 0; background: var(--card); }
.fundbar { background: var(--line); border-radius: 8px; height: 10px; overflow: hidden; margin: .4rem 0; } .fundbar > div { background: var(--accent); height: 100%; }
.remPresets { display: flex; flex-direction: column; gap: .4rem; margin: .6rem 0; }
.remForm { display: flex; flex-direction: column; gap: .5rem; margin-top: .6rem; }
.remForm label { display: flex; flex-direction: column; gap: .2rem; }
body.helper [data-tab="personal"], body.helper [data-tab="books"], body.helper [data-tab="setup"], body.helper [data-tab="baykosher"], body.helper #askFab, body.helper [data-del], body.helper #enDel, body.helper #exDel, body.helper #yearEndBtn, body.helper #searchBtn + #sendBtn { display: none !important; }
@media (max-width: 700px) { dialog, .card, main { scroll-padding-bottom: 40vh; } }
