:root {
  --bg: #f6f4fb; --card: #ffffff; --ink: #1d1530; --muted: #6b6380; --line: #e6e1f0;
  --brand: #5b2a9e; --brand-2: #7c45c9; --gold: #c9971c; --gold-soft: #fbf3dc;
  --green: #12805c; --green-soft: #e3f5ee; --red: #c23b3b; --red-soft: #fbe7e7;
  --amber: #b26a00; --amber-soft: #fdf0dc; --blue: #2f5fb3; --blue-soft: #e5edfb;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Public Sans", system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 16px; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px; background: var(--brand); color: #fff; }
.brand { font-size: 18px; display: flex; align-items: center; gap: 8px; }
.logo { background: var(--gold); color: var(--brand); font-weight: 800; border-radius: 8px; padding: 3px 7px; font-size: 14px; }
.demo-tag { font-size: 10px; letter-spacing: .15em; background: rgba(255,255,255,.18); padding: 3px 7px; border-radius: 99px; }
#who { display: flex; align-items: center; gap: 10px; font-size: 14px; }
#who button { background: rgba(255,255,255,.15); color: #fff; border: 0; padding: 7px 12px; border-radius: 8px; }

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.narrow { max-width: 560px; margin: 0 auto; }
h1 { font-size: 26px; margin: 6px 0 4px; }
h2 { font-size: 19px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 16px; }

/* Login */
.role-pick { display: grid; gap: 12px; margin-top: 18px; }
.big-btn { width: 100%; padding: 16px; border-radius: 14px; border: 0; background: var(--brand); color: #fff; font-weight: 700; font-size: 18px; }
.big-btn.gold { background: var(--gold); color: #fff; }
.big-btn.ghost { background: #fff; color: var(--brand); border: 2px solid var(--brand); }
.big-btn:disabled { opacity: .5; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 700; font-size: 15px; }
.field input, .field select, .field textarea { padding: 13px 14px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; font-size: 17px; width: 100%; }
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand-2); }
.pin-input { letter-spacing: .6em; text-align: center; font-size: 26px !important; }

/* Pastor home */
.hero { background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: #fff; border: 0; }
.hero .muted { color: rgba(255,255,255,.75); }
.status-done { background: var(--green-soft); color: var(--green); padding: 12px 14px; border-radius: 12px; font-weight: 700; margin-top: 12px; }

/* Report form */
.steps { display: flex; gap: 6px; margin: 4px 0 16px; }
.steps span { flex: 1; height: 6px; border-radius: 99px; background: var(--line); }
.steps span.on { background: var(--gold); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 10px 14px; border-radius: 99px; border: 1.5px solid var(--line); background: #fff; font-weight: 600; }
.chip.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.counter { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--line); }
.counter:last-child { border-bottom: 0; }
.counter .lbl { font-weight: 700; font-size: 17px; }
.counter .lbl small { display: block; font-weight: 400; color: var(--muted); font-size: 13px; }
.stepper { display: flex; align-items: center; gap: 8px; }
.stepper button { width: 46px; height: 46px; border-radius: 12px; border: 0; background: var(--blue-soft); color: var(--blue); font-size: 24px; font-weight: 800; }
.stepper input { width: 80px; text-align: center; font-size: 22px; font-weight: 800; padding: 8px; border: 1.5px solid var(--line); border-radius: 10px; }
.total-bar { display: flex; justify-content: space-between; background: var(--gold-soft); padding: 14px; border-radius: 12px; font-weight: 800; font-size: 18px; margin-top: 10px; }
.money { position: relative; }
.money span { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); font-weight: 700; color: var(--muted); }
.money input { padding-left: 34px !important; }
.form-nav { display: flex; gap: 10px; margin-top: 8px; }
.form-nav .big-btn { flex: 1; }
.link-btn { background: none; border: 0; color: var(--brand); font-weight: 700; padding: 6px 0; text-decoration: underline; }
.review-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px dashed var(--line); }

/* HQ dashboard */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.tab { padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 700; color: var(--muted); }
.tab.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.kpi .v { font-size: 26px; font-weight: 800; margin-top: 4px; }
.kpi .d { font-size: 13px; font-weight: 700; margin-top: 2px; }
.up { color: var(--green); } .down { color: var(--red); } .flat { color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 820px) { .grid2 { grid-template-columns: 1fr; } }
.trend-groups { display: grid; gap: 10px; }
.tg { border-radius: 12px; padding: 12px; }
.tg h3 { margin: 0 0 6px; font-size: 15px; }
.tg .names { font-size: 14px; line-height: 1.6; }
.tg.growing { background: var(--green-soft); } .tg.growing h3 { color: var(--green); }
.tg.steady { background: var(--blue-soft); } .tg.steady h3 { color: var(--blue); }
.tg.volatile { background: var(--amber-soft); } .tg.volatile h3 { color: var(--amber); }
.tg.declining { background: var(--red-soft); } .tg.declining h3 { color: var(--red); }
.badge { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge.growing { background: var(--green-soft); color: var(--green); }
.badge.steady { background: var(--blue-soft); color: var(--blue); }
.badge.volatile { background: var(--amber-soft); color: var(--amber); }
.badge.declining { background: var(--red-soft); color: var(--red); }
.badge.missing { background: var(--red-soft); color: var(--red); }
.badge.ok { background: var(--green-soft); color: var(--green); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; padding: 8px; border-bottom: 2px solid var(--line); white-space: nowrap; }
td { padding: 10px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
tr.click { cursor: pointer; } tr.click:hover td { background: #faf8fe; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.insight { padding: 10px 12px; border-left: 4px solid var(--gold); background: var(--gold-soft); border-radius: 8px; margin-bottom: 8px; font-size: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { padding: 9px 14px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-weight: 700; color: var(--brand); }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.note-item { padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.note-item b { color: var(--brand); }
canvas { max-height: 280px; }
#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }

/* ---- v2: branch dashboard + settings ---- */
.wide { max-width: 980px; margin: 0 auto; }
.quick { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 16px; }
@media (max-width: 600px) { .quick { grid-template-columns: repeat(2, 1fr); } }
.quick button { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 14px 8px; font-weight: 700; color: var(--ink); display: grid; gap: 6px; justify-items: center; }
.quick button span { font-size: 28px; }
.quick button:hover { border-color: var(--brand-2); }
.progress { height: 14px; background: var(--line); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.progress div { height: 100%; background: linear-gradient(90deg, var(--gold), var(--brand-2)); border-radius: 99px; }
.verse-card { background: var(--gold-soft); border-color: #f0dfae; color: #6b4e00; }
.verse-text { font-size: 17px; line-height: 1.6; font-style: italic; margin: 10px 0; color: var(--ink); }
.ach { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.ach:last-child { border-bottom: 0; }
.ach > span { font-size: 28px; }
.agree { display: flex; gap: 10px; align-items: flex-start; margin: 6px 0 16px; font-size: 15px; line-height: 1.4; }
.agree input { width: 22px; height: 22px; margin-top: 1px; flex-shrink: 0; }
.code-edit { width: 90px; padding: 8px; border: 1.5px solid var(--line); border-radius: 8px; font-size: 15px; letter-spacing: .1em; }

/* ---- Printing (HQ secretary prints for Bishop) ---- */
.print-head { display: none; }
@media print {
  .topbar, .tabs, .actions, .btn, .link-btn, #toast { display: none !important; }
  .print-head { display: block; font-weight: 800; font-size: 16px; margin-bottom: 12px; color: var(--brand); }
  body { background: #fff; }
  main { max-width: none; padding: 0; }
  .card, .kpi { break-inside: avoid; border-color: #ccc; }
  .grid2 { grid-template-columns: 1fr 1fr; }
  canvas { max-height: 220px; }
}

/* ---- v3: weekly questionnaire ---- */
.focus { margin-top: 10px; background: rgba(255,255,255,.14); padding: 10px 12px; border-radius: 10px; font-size: 14px; }
h3.sub { font-size: 15px; margin: 18px 0 4px; color: var(--brand); }
.dated { display: grid; grid-template-columns: 1fr 150px; gap: 10px; align-items: end; }
@media (max-width: 480px) { .dated { grid-template-columns: 1fr; gap: 0; } }
.calc-box { background: var(--blue-soft); border-radius: 12px; padding: 4px 14px; margin: 10px 0 14px; }
.calc-box .review-row { border-bottom-color: rgba(47,95,179,.2); }
.calc-box .review-row:last-child { border-bottom: 0; }
.pay-line { border: 1px solid var(--line); border-radius: 12px; padding: 12px 12px 0; margin-bottom: 12px; }
.acct { font-size: 12px; color: var(--muted); margin-top: 6px; }
.should { font-size: 13px; margin-top: 4px; }
.warn { background: var(--amber-soft); color: var(--amber); padding: 12px 14px; border-radius: 12px; font-size: 14px; line-height: 1.5; margin: 10px 0; }
.exp-row { display: grid; grid-template-columns: 140px 1fr 140px 40px; gap: 8px; margin-bottom: 8px; align-items: center; }
.exp-row input { padding: 10px; border: 1.5px solid var(--line); border-radius: 10px; width: 100%; font-size: 15px; }
@media (max-width: 600px) { .exp-row { grid-template-columns: 1fr 1fr 40px; } .exp-row input[data-f="desc"] { grid-column: 1 / -1; grid-row: 1; } }
.x { border: 0; background: var(--red-soft); color: var(--red); border-radius: 10px; height: 40px; font-weight: 800; }
.click-row { cursor: pointer; } .click-row:hover { color: var(--brand); }
.ok-t { color: var(--green); font-weight: 800; } .bad-t { color: var(--red); font-weight: 800; }
.tiny { font-size: 11px; }

/* ---- Statement document ---- */
.stmt-controls .range, .range { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; }
.range .field { margin-bottom: 8px; }
.narrow-card { max-width: 560px; }
.stmt { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 24px; font-size: 13px; }
.stmt-head { display: flex; gap: 14px; align-items: center; border-bottom: 3px solid var(--brand); padding-bottom: 12px; margin-bottom: 12px; font-weight: 700; }
.stmt-logo { background: var(--brand); color: var(--gold); font-weight: 800; border-radius: 10px; padding: 10px 12px; font-size: 18px; }
.stmt-title { font-size: 22px; color: var(--brand); font-weight: 800; letter-spacing: .04em; }
.stmt h3 { background: var(--brand); color: #fff; font-size: 13px; letter-spacing: .05em; padding: 7px 10px; border-radius: 6px; margin: 20px 0 8px; }
.stmt h4 { margin: 14px 0 6px; font-size: 13px; }
.stmt table.grid, .stmt table.kv { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.stmt table.grid th, .stmt table.grid td, .stmt table.kv td { border: 1px solid #ddd6ea; padding: 6px 8px; white-space: normal; }
.stmt table.grid th { background: #f3eefb; color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 11.5px; }
.stmt table.kv td:nth-child(odd) { background: #f8f6fc; color: var(--muted); width: 16%; }
.stmt tr.tot td { background: var(--gold-soft); font-weight: 800; }
.stmt tr.sub-tot td { background: #f8f6fc; font-weight: 700; }
.stmt tr.month-row td { background: var(--blue-soft); font-weight: 800; color: var(--blue); }
.gross-line { text-align: right; font-size: 15px; margin: 8px 0; }
.sigs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 36px; text-align: center; }
.sig-name { min-height: 18px; font-weight: 700; }
.sig-line { border-top: 1.5px solid var(--ink); padding-top: 6px; margin-top: 18px; font-weight: 800; font-size: 11.5px; letter-spacing: .05em; }

/* ---- Settings ---- */
.acct-edit { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.acct-edit input { padding: 9px 10px; border: 1.5px solid var(--line); border-radius: 8px; font-size: 14px; width: 100%; }
.acct-edit .two { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.acct-edit:last-of-type { margin-bottom: 12px; }
.code-edit.wide-in { width: 130px; letter-spacing: 0; }

@media print {
  .no-print { display: none !important; }
  .stmt { border: 0; padding: 0; font-size: 11px; }
  .stmt h3 { -webkit-print-color-adjust: exact; print-color-adjust: exact; break-after: avoid; }
  .stmt tr.tot td, .stmt table.grid th, .stmt tr.month-row td { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .stmt table { break-inside: auto; } .stmt tr { break-inside: avoid; }
}
.special { border: 2px solid var(--gold); background: #fffdf6; border-radius: 14px; padding: 14px; margin-bottom: 14px; }
.special-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; color: var(--amber); }
.special-head .x { width: 40px; }
@media (max-width: 760px) { .quick { grid-template-columns: repeat(3, 1fr); } }
.sp-pill { display: inline-block; background: var(--gold-soft); color: var(--amber); font-weight: 800; border-radius: 99px; padding: 2px 8px; font-size: 12px; white-space: nowrap; }
.att-block { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; }
.att-head { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.att-head .x { margin-left: auto; width: 40px; }
.att-no { background: var(--brand); color: #fff; font-weight: 800; border-radius: 8px; padding: 3px 9px; font-size: 14px; }
.special .att-no { background: var(--gold); }
.total-bar.grand { background: var(--brand); color: #fff; margin: 4px 0 12px; }

/* ---- Phone layout (most pastors use their phones) ---- */
html { -webkit-text-size-adjust: 100%; }
button, a { -webkit-tap-highlight-color: transparent; }
.big-btn:active, .quick button:active, .stepper button:active, .chip:active { transform: scale(.97); }
@media (max-width: 640px) {
  body { font-size: 15px; }
  main { padding: 12px 12px calc(90px + env(safe-area-inset-bottom)); }
  .topbar { padding: 10px 12px; }
  .brand { font-size: 16px; }
  .demo-tag { display: none; }
  #who span { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  h1 { font-size: 22px; }
  h2 { font-size: 17px; }
  .card { padding: 14px; border-radius: 14px; margin-bottom: 12px; }
  .hero h1 { font-size: 21px; }
  /* number tiles two per row */
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 12px; }
  .kpi .v { font-size: 20px; }
  .quick { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .quick button { padding: 12px 4px; font-size: 13px; }
  .quick button span { font-size: 24px; }
  /* tabs scroll sideways instead of stacking */
  .tabs { flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px 12px; padding: 0 12px 4px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { white-space: nowrap; flex-shrink: 0; }
  /* counters: keep label + stepper on one line */
  .counter .lbl { font-size: 16px; }
  .stepper { gap: 6px; }
  .stepper button { width: 44px; height: 44px; }
  .stepper input { width: 64px; font-size: 20px; }
  .att-block { padding: 10px 12px; }
  /* Next / Back always reachable at the bottom of the screen */
  .form-nav { position: sticky; bottom: 0; background: rgba(255,255,255,.96); backdrop-filter: blur(6px);
    margin: 12px -14px -14px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); border-radius: 0 0 14px 14px; z-index: 5; }
  .big-btn { padding: 14px; font-size: 17px; }
  /* inputs at 16px+ so phones don't zoom in */
  .exp-row input, .acct-edit input, .code-edit, select, textarea { font-size: 16px; }
  .review-row { font-size: 14px; gap: 10px; }
  .grid2 { gap: 0; }
  .stmt { padding: 14px; }
  .stmt-title { font-size: 18px; }
  .stmt-head { gap: 10px; }
  .sigs { grid-template-columns: 1fr; gap: 6px; }
  .range .field { flex: 1 1 140px; }
  .actions .btn { flex: 1 1 auto; }
  #toast { bottom: calc(90px + env(safe-area-inset-bottom)); width: max-content; max-width: 90vw; text-align: center; }
}
@media (max-width: 370px) {
  .stepper button { width: 40px; height: 40px; }
  .stepper input { width: 56px; }
  .quick { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  #who span { display: none; }            /* branch name is already on the page */
  #who button { white-space: nowrap; }
  .quick button:first-child { grid-column: span 2; background: var(--brand); color: #fff; border-color: var(--brand); }
}
@media (max-width: 370px) { .quick button:first-child { grid-column: span 2; } }
.hq-tag { display: inline-block; background: var(--blue-soft); color: var(--blue); font-size: 11px; font-weight: 800; border-radius: 99px; padding: 2px 8px; white-space: nowrap; }
.att-head .hq-tag { margin-left: auto; }
.always-tick { margin: 0 0 8px; align-items: center; align-self: end; padding-bottom: 12px; }
#hp-weeks:disabled { background: var(--bg); color: var(--muted); }
.danger-card { border-color: #f0c4c4; background: #fff8f8; }
.danger-card h2 { color: var(--red); }
.btn.danger { background: var(--red); color: #fff; border-color: var(--red); }
.add-branch { display: grid; gap: 8px; background: var(--bg); border-radius: 12px; padding: 12px; margin-bottom: 14px; }
.prefix-input { display: flex; border: 1.5px solid var(--line); border-radius: 12px; background: #fff; overflow: hidden; }
.prefix-input span { background: #f3eefb; color: var(--brand); font-weight: 700; padding: 12px; white-space: nowrap; }
.prefix-input input { border: 0; padding: 12px; font-size: 16px; flex: 1; min-width: 0; outline: none; }
.add-branch .btn { justify-self: start; }
/* date boxes must stay inside the card */
.dated { grid-template-columns: minmax(0, 1fr) minmax(0, 165px); }
.dated input, .field input, .field select { min-width: 0; max-width: 100%; box-sizing: border-box; }

/* ---- Bank statement check ---- */
.upload-box { display: grid; gap: 4px; justify-items: center; text-align: center; border: 2px dashed var(--brand-2); background: #faf7ff; border-radius: 14px; padding: 22px 14px; cursor: pointer; }
.upload-box span { font-weight: 800; color: var(--brand); font-size: 17px; }
.upload-box small { color: var(--muted); }
.upload-box:hover { background: #f3eefb; }
details summary { cursor: pointer; color: var(--brand); font-weight: 700; margin: 4px 0 8px; }
.print-only { display: none; }
@media print { .print-only { display: block; } }

/* ---- Sign-in page ---- */
.login { max-width: 460px; margin: 0 auto; position: relative; padding-top: 8px; }
.app-tab { position: absolute; top: 0; right: 0; border: 1px solid var(--line); background: #fff; color: var(--brand); font-weight: 800; font-size: 13px; padding: 7px 12px; border-radius: 99px; box-shadow: 0 2px 8px rgba(91,42,158,.12); }
.login-hero { text-align: center; padding: 40px 8px 22px; }
.login-logo { width: 72px; height: 72px; margin: 0 auto 14px; border-radius: 20px; background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: var(--gold); font-weight: 800; font-size: 28px; display: grid; place-items: center; box-shadow: 0 10px 26px rgba(91,42,158,.35); }
.login-kicker { font-size: 12px; font-weight: 800; letter-spacing: .22em; color: var(--gold); }
.login-hero h1 { font-size: 26px; margin: 6px 0 8px; }
.login-hero p { color: var(--muted); margin: 0; }
.login-card { padding: 22px; box-shadow: 0 10px 30px rgba(29,21,48,.07); }
.login-card h2 { margin-bottom: 14px; }
.switch-side { display: block; width: 100%; margin-top: 14px; background: none; border: 0; color: var(--brand); font-weight: 700; padding: 10px; border-top: 1px solid var(--line); }
.sheet-backdrop { position: fixed; inset: 0; background: rgba(29,21,48,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.sheet-backdrop[hidden] { display: none; }
.sheet { background: #fff; width: 100%; max-width: 460px; border-radius: 20px 20px 0 0; padding: 20px 18px calc(18px + env(safe-area-inset-bottom)); display: grid; gap: 12px; }
.sheet-row { border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.sheet-row p { margin: 4px 0 10px; }
a.big-btn { display: block; text-align: center; text-decoration: none; }
@media (max-width: 640px) { .login-hero { padding-top: 46px; } .login-hero h1 { font-size: 23px; } }
