:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f0f3f7;
  --text: #17202b;
  --muted: #627084;
  --border: #dde3ea;
  --primary: #0b75b5;
  --navy: #130f2d;
  --jci-blue: #0097d7;
  --jci-teal: #5bbdbd;
  --primary-ink: #ffffff;
  --income: #13804b;
  --expense: #c2412d;
  --warn-bg: #fff6e0;
  --warn: #8a5a00;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141a; --surface: #171e26; --surface-2: #1f2832; --text: #e6ebf1; --muted: #93a1b3;
    --border: #2b3643; --primary: #4eb3e8; --primary-ink: #06121d; --income: #4cc98a; --expense: #f07a66;
    --warn-bg: #3a2e12; --warn: #f2c66d; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans", sans-serif; }
[hidden] { display: none !important; }
a { color: var(--primary); }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 0 0 18px; }
.muted { color: var(--muted); }
.error { color: var(--expense); min-height: 1em; margin: 8px 0 0; }

/* Layout */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; }
.brand b { display: block; font-size: 15px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }
.brand.big b { font-size: 18px; }
.logo { display: block; width: 36px; height: 36px; border-radius: 9px; }
.install { margin-left: auto; }
.offline { background: var(--warn-bg); color: var(--warn); text-align: center; padding: 8px 16px; font-size: 13px; }
.quick { display: flex; gap: 10px; margin-bottom: 16px; }
.quick .btn { padding: 14px 18px; font-size: 16px; }
@media (max-width: 760px) { .quick { display: grid; grid-template-columns: 1fr 1fr; } }
.nav { display: flex; gap: 4px; }
.nav a { position: relative; display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--surface-2); color: var(--primary); }
.ico { font-size: 15px; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--expense); color: #fff; font-size: 11px; font-weight: 700; display: inline-grid; place-items: center; }
main { max-width: 1100px; margin: 0 auto; padding: 24px; }

@media (max-width: 760px) {
  .topbar { padding: 10px 16px; }
  .nav { position: fixed; bottom: 0; left: 0; right: 0; justify-content: space-around; gap: 0; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--border); }
  .nav a { flex-direction: column; gap: 0; padding: 6px 4px; font-size: 11px; flex: 1; text-align: center; }
  .nav a .ico { font-size: 18px; }
  .nav .badge { position: absolute; top: 2px; right: 50%; transform: translateX(20px); }
  main { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
  .topbar { padding-top: calc(10px + env(safe-area-inset-top)); }
}

/* Cards & grids */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(3, 1fr); margin-bottom: 16px; }
.two { grid-template-columns: 1fr 1fr; }
@media (max-width: 760px) { .stats { grid-template-columns: 1fr 1fr; } .stats .stat:first-child { grid-column: 1 / -1; } .two { grid-template-columns: 1fr; } }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.stat.balance .value { font-size: 32px; }
.pos { color: var(--income); }
.neg { color: var(--expense); }
.notice { display: flex; justify-content: space-between; align-items: center; gap: 12px; background: var(--warn-bg); color: var(--warn); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; }

/* Bars */
.bars { display: grid; gap: 12px; }
.bar-row .top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin-bottom: 4px; }
.bar-row .top span:last-child { font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; display: flex; }
.bar i { display: block; height: 100%; }
.bar .e { background: var(--expense); }
.bar .i { background: var(--income); }
.months { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 10px; align-items: end; height: 150px; }
.month { display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.month .cols { flex: 1; display: flex; align-items: end; gap: 3px; width: 100%; justify-content: center; }
.month .cols i { width: 12px; border-radius: 3px 3px 0 0; min-height: 2px; }
.month small { color: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.list li:last-child { border-bottom: 0; }
.list .t { font-weight: 500; }
.list .m { color: var(--muted); font-size: 13px; }
.amt { font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }

/* Forms & buttons */
label { display: block; font-size: 13px; color: var(--muted); font-weight: 500; }
input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 10px 12px; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 40%, transparent); border-color: var(--primary); }
textarea { min-height: 70px; resize: vertical; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form .full { grid-column: 1 / -1; }
@media (max-width: 520px) { .form { grid-template-columns: 1fr; } }
.tag { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 6px; background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); font-size: 11px; font-weight: 600; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 16px; font: inherit; font-weight: 600; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--expense); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: progress; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; margin-top: 18px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-top: 4px; }
.seg button { padding: 9px 16px; font: inherit; font-weight: 600; background: var(--surface); color: var(--muted); border: 0; cursor: pointer; }
.seg button.on[data-v="expense"] { background: var(--expense); color: #fff; }
.seg button.on[data-v="income"] { background: var(--income); color: #fff; }

/* Scan */
.scan-hero { display: grid; gap: 12px; text-align: center; padding: 28px 18px; }
.scan-hero .big-ico { font-size: 40px; }
.scan-buttons { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.scan-layout { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
@media (max-width: 860px) { .scan-layout { grid-template-columns: 1fr; } }
.bill-img { width: 100%; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); }
details summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 10px; }
pre.ocr { white-space: pre-wrap; font-size: 12px; background: var(--surface-2); padding: 10px; border-radius: 8px; max-height: 240px; overflow: auto; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 0 auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Table */
.filters { display: grid; grid-template-columns: 2fr 1fr 1.4fr 1fr 1fr auto; gap: 10px; align-items: end; margin-bottom: 14px; }
@media (max-width: 900px) { .filters { grid-template-columns: 1fr 1fr; } .filters .grow { grid-column: 1 / -1; } }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.totals td { font-weight: 700; cursor: default; }
@media (max-width: 640px) { .hide-sm { display: none; } }

/* Review cards */
.review { display: grid; grid-template-columns: 120px 1fr; gap: 16px; }
.review + .review { margin-top: 14px; }
.review .thumb { width: 120px; height: 150px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); cursor: zoom-in; }
.review .noimg { width: 120px; height: 150px; display: grid; place-items: center; border-radius: 8px; background: var(--surface-2); color: var(--muted); font-size: 28px; }
.review .meta { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
@media (max-width: 560px) { .review { grid-template-columns: 1fr; } .review .thumb, .review .noimg { width: 100%; height: 160px; } }

/* WhatsApp simulator */
.chat { display: flex; flex-direction: column; gap: 8px; height: 360px; overflow-y: auto; padding: 12px; background: color-mix(in srgb, var(--income) 6%, var(--surface-2)); border-radius: 8px; }
.bubble { max-width: 85%; padding: 8px 11px; border-radius: 10px; white-space: pre-wrap; font-size: 14px; box-shadow: var(--shadow); }
.bubble.me { align-self: flex-end; background: color-mix(in srgb, var(--income) 22%, var(--surface)); }
.bubble.bot { align-self: flex-start; background: var(--surface); }
.bubble img { max-width: 160px; border-radius: 6px; display: block; }
.chat-input { display: flex; gap: 8px; margin-top: 10px; }
.chat-input input[type=text] { margin: 0; }
.steps { padding-left: 18px; margin: 0; }
.steps li { margin-bottom: 6px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; font-size: 13px; }

/* Activities */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 6px 6px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }
.chip.off { opacity: .5; text-decoration: line-through; }
.chip button { border: 0; background: var(--surface-2); color: var(--muted); width: 22px; height: 22px; border-radius: 50%; cursor: pointer; }

/* Modal, toast, login */
dialog { border: 0; border-radius: var(--radius); padding: 0; width: min(720px, calc(100vw - 32px)); background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(10, 15, 20, .5); }
#modalBody { padding: 20px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.x { border: 0; background: none; font-size: 22px; color: var(--muted); cursor: pointer; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 100; font-weight: 500; max-width: calc(100vw - 32px); }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(360px, 100%); display: grid; gap: 16px; }

/* Users, members */
.who { color: var(--muted); font-size: 13px; white-space: nowrap; }
.install + .who { margin-left: 0; }
.topbar .who { margin-left: auto; }
.topbar .install:not([hidden]) + .who { margin-left: 12px; }
@media (max-width: 760px) { .who { display: none; } }
.row-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.row-head h2 { margin: 0; }
.role { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); align-self: center; }
.role-admin { background: color-mix(in srgb, var(--primary) 16%, transparent); color: var(--primary); }
.role-treasurer { background: color-mix(in srgb, var(--income) 16%, transparent); color: var(--income); }
.members-grid { grid-template-columns: 1.4fr 1fr; align-items: start; }
@media (max-width: 860px) { .members-grid { grid-template-columns: 1fr; } }
.when { font-size: 13px; font-weight: 600; color: var(--muted); white-space: nowrap; align-self: center; }
.when.today { color: var(--income); }
.child-row { display: grid; grid-template-columns: 1.4fr 1fr auto; gap: 8px; align-items: center; margin-top: 6px; }
.child-row input { margin: 0; }
h3.sec { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 8px 0 -4px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; margin: 0; }
.errs { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--warn); }
.small-print { font-size: 12px; margin: 0; }
input:disabled, select:disabled, textarea:disabled { background: var(--surface-2); color: var(--text); opacity: 1; }
#memberList li > .m:last-child { white-space: nowrap; }

/* JCI Salem Rungs branding */
.topbar { background: var(--navy); border-bottom-color: var(--navy); color: #fff; }
.topbar .brand { color: #fff; text-decoration: none; }
.topbar .brand small, .topbar .who { color: #b9c4dc; }
.topbar .logo { width: 30px; height: 37px; border-radius: 0; object-fit: contain; }
@media (min-width: 761px) {
  .topbar .nav a { color: #c9d3e6; }
  .topbar .nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
  .topbar .nav a.active { background: rgba(0,151,215,.22); color: #fff; }
}
.topbar .btn.install { background: var(--jci-blue); border-color: var(--jci-blue); color: #fff; }
.login { background: var(--navy); }
.login-card { border: 0; }
.login { align-content: center; gap: 20px; }
.login-logo { width: 260px; max-width: 72vw; display: block; }
