:root {
  --bg: #f4f5fb; --card: #ffffff; --text: #151628; --muted: #6b6f8a; --line: #e6e8f2;
  --brand: #4f46e5; --brand2: #a855f7; --good: #10b981; --bad: #ef4444; --warn: #f59e0b;
  --ak: #6366f1; --vg: #ec4899; --shadow: 0 1px 2px rgba(20,20,60,.06), 0 8px 24px rgba(20,20,60,.06);
  --r: 18px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1020; --card: #191a2e; --text: #eceefb; --muted: #9a9dbb; --line: #2a2c47; --shadow: 0 1px 2px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] { --bg: #0f1020; --card: #191a2e; --text: #eceefb; --muted: #9a9dbb; --line: #2a2c47; --shadow: 0 1px 2px rgba(0,0,0,.4); }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; padding: 22px 14px; display: flex; flex-direction: column; gap: 4px; border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; padding: 0 10px 18px; }
.brand i { width: 34px; height: 34px; border-radius: 11px; background: linear-gradient(135deg, var(--brand), var(--brand2)); display: grid; place-items: center; color: #fff; font-style: normal; }
.nav { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 12px; border: 0; background: none; color: var(--muted); font-weight: 600; text-align: left; width: 100%; }
.nav .ic { font-size: 19px; width: 24px; text-align: center; }
.nav.on { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }
.nav:hover:not(.on) { background: color-mix(in srgb, var(--muted) 12%, transparent); }
.spacer { flex: 1; }
.who { font-size: 13px; color: var(--muted); padding: 8px 12px; display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.dot.off { background: var(--warn); }
main { min-width: 0; padding: 26px 28px 110px; max-width: 1080px; width: 100%; margin: 0 auto; }
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.top h1 { font-size: 26px; }
.monthnav { display: flex; align-items: center; gap: 4px; background: var(--card); border-radius: 14px; padding: 4px; box-shadow: var(--shadow); }
.monthnav button { border: 0; background: none; width: 34px; height: 34px; border-radius: 10px; font-size: 18px; }
.monthnav button:hover { background: var(--bg); }
.monthnav b { min-width: 130px; text-align: center; text-transform: capitalize; }
.grid { display: grid; gap: 16px; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g2 { grid-template-columns: 1.1fr 1fr; }
.card { background: var(--card); border-radius: var(--r); padding: 18px; box-shadow: var(--shadow); }
.card h3 { flex-wrap: wrap; gap: 8px; font-size: 14px; color: var(--muted); font-weight: 600; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.hero { background: linear-gradient(135deg, var(--brand), var(--brand2)); color: #fff; }
.hero h3 { color: rgba(255,255,255,.8); }
.big { font-size: 32px; font-weight: 800; letter-spacing: -.02em; }
.mid { font-size: 22px; font-weight: 750; }
.sub { color: var(--muted); font-size: 13px; }
.hero .sub { color: rgba(255,255,255,.8); }
.pos { color: var(--good); } .neg { color: var(--bad); }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.emo { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; font-size: 19px; flex: none; }
.amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; color: #fff; }
.tag.AK { background: var(--ak); } .tag.VG { background: var(--vg); } .tag.both { background: var(--muted); }
.day { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 18px 4px 4px; }
.bar { height: 9px; border-radius: 9px; background: var(--line); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 9px; background: linear-gradient(90deg, var(--brand), var(--brand2)); }
.split { display: flex; height: 12px; border-radius: 12px; overflow: hidden; background: var(--line); margin: 8px 0; }
.legend { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.legend div { display: flex; align-items: center; gap: 8px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.legend b { margin-left: auto; font-variant-numeric: tabular-nums; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--card); padding: 7px 13px; border-radius: 99px; font-weight: 600; font-size: 13px; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn { border: 0; background: var(--brand); color: #fff; padding: 11px 18px; border-radius: 13px; font-weight: 700; }
.btn.ghost { background: color-mix(in srgb, var(--brand) 12%, transparent); color: var(--brand); }
.btn.danger { background: color-mix(in srgb, var(--bad) 14%, transparent); color: var(--bad); }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.fab { position: fixed; right: 28px; bottom: 28px; z-index: 5; border: 0; border-radius: 18px; padding: 15px 22px; color: #fff; font-weight: 800; font-size: 16px; background: linear-gradient(135deg, var(--brand), var(--brand2)); box-shadow: 0 10px 30px rgba(79,70,229,.45); }
input, select { width: 100%; padding: 12px 14px; border-radius: 13px; border: 1px solid var(--line); background: var(--bg); outline: none; }
input:focus, select:focus { border-color: var(--brand); }
label { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .05em; }
.amount-in { font-size: 38px; font-weight: 800; text-align: center; border: 0; background: none; padding: 6px; }
.seg { display: grid; grid-auto-flow: column; background: var(--bg); border-radius: 13px; padding: 4px; gap: 4px; }
.seg button { border: 0; background: none; padding: 9px; border-radius: 10px; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.catgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.catgrid button { border: 2px solid transparent; background: var(--bg); border-radius: 14px; padding: 9px 4px; display: flex; flex-direction: column; align-items: center; gap: 3px; font-size: 12px; font-weight: 600; }
.catgrid button .e { font-size: 22px; }
.catgrid button.on { border-color: var(--brand); background: color-mix(in srgb, var(--brand) 10%, var(--card)); }
.scrim { position: fixed; inset: 0; background: rgba(8,8,24,.55); display: grid; place-items: center; z-index: 20; padding: 16px; backdrop-filter: blur(3px); }
.modal { background: var(--card); border-radius: 24px; padding: 22px; width: 100%; max-width: 460px; max-height: 92vh; overflow: auto; box-shadow: 0 30px 80px rgba(0,0,0,.4); }
.modal h2 { margin-bottom: 4px; }
.actions { display: flex; gap: 10px; margin-top: 20px; }
.actions .btn { flex: 1; }
.check { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--line); background: none; display: grid; place-items: center; color: #fff; flex: none; }
.check.on { background: var(--good); border-color: var(--good); }
.empty { text-align: center; color: var(--muted); padding: 34px 10px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.err { color: var(--bad); font-size: 13px; margin-top: 10px; min-height: 18px; }
.toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 99px; font-weight: 600; z-index: 30; }
.tabs { display: none; }
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .side { display: none; }
  main { padding: 18px 14px 130px; }
  .g3, .g2 { grid-template-columns: 1fr; }
  .tabs { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: var(--card); border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); }
  .tabs button { flex: 1; border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11px; font-weight: 700; color: var(--muted); padding: 6px 0; }
  .tabs button .ic { font-size: 20px; }
  .tabs button.on { color: var(--brand); }
  .fab { right: 16px; bottom: 82px; padding: 14px 18px; }
  .top h1 { font-size: 22px; }
}
.sheetwrap { overflow: auto; max-height: calc(100vh - 210px); background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); }
.sheet { border-collapse: separate; border-spacing: 0; font-size: 13px; font-variant-numeric: tabular-nums; width: max-content; }
.sheet th, .sheet td { padding: 6px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); background: var(--card); }
.sheet thead th { position: sticky; top: 0; z-index: 2; font-weight: 700; text-align: center; }
.sheet thead tr:nth-child(2) th { top: 31px; font-size: 11px; z-index: 2; }
.sheet th.cur { color: var(--brand); box-shadow: inset 0 -3px var(--brand); }
.sheet .stick { position: sticky; left: 0; z-index: 3; text-align: left; min-width: 230px; max-width: 230px; overflow: hidden; text-overflow: ellipsis; background: var(--card); }
.sheet thead .stick { z-index: 4; }
.sheet td.nm { cursor: pointer; font-weight: 600; }
.sheet td.nm.off { opacity: .5; }
.sheet tr.sec td { background: color-mix(in srgb, var(--brand) 10%, var(--card)); font-weight: 800; text-align: left; position: sticky; left: 0; }
.sheet td.cell { cursor: cell; min-width: 70px; }
.sheet td.cell:hover { background: color-mix(in srgb, var(--brand) 12%, var(--card)); }
.sheet td.cell.z:hover::after { content: '+'; color: var(--muted); }
.sheet tr.sum td { font-weight: 800; background: color-mix(in srgb, var(--muted) 12%, var(--card)); }
.sheet td.tot { font-weight: 800; position: sticky; right: 0; background: var(--card); }
.sheet tr.sum td.tot { background: color-mix(in srgb, var(--muted) 12%, var(--card)); }
.cellin { width: 78px; padding: 3px 6px; border-radius: 6px; text-align: right; font-size: 13px; }

main.wide { max-width: none; padding-bottom: 40px; }
main.wide .sheetwrap { max-height: calc(100vh - 190px); }
main.wide .fab { display: none; }
@media (max-width: 820px) { main.wide { padding: 14px 8px 90px; } .sheet .stick { min-width: 130px; max-width: 130px; } }

.sheet th.mh { cursor: pointer; user-select: none; }
.sheet th.mh:hover { background: color-mix(in srgb, var(--brand) 12%, var(--card)); }
.sheet th.mh.open { background: color-mix(in srgb, var(--warn) 25%, var(--card)); color: var(--text); }
.sheet td.cell[data-locked] { cursor: default; }
.sheet td.cell[data-locked]:hover { background: var(--card); }
.sheet td.cell[data-locked]:hover::after { content: none; }
.sheet td.cell.open { background: color-mix(in srgb, var(--warn) 9%, var(--card)); cursor: cell; }

.sheet td.cell { position: relative; padding-left: 26px; }
.sheet .ck { position: absolute; left: 5px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; border-radius: 50%; border: 2px solid #b6bad0; display: grid; place-items: center; font-size: 10px; font-style: normal; color: #fff; cursor: pointer; }
.sheet .ck:hover { border-color: var(--good); }
.sheet .ck.on { background: var(--good); border-color: var(--good); }
.sheet td.cell.s-paid { background: color-mix(in srgb, var(--good) 17%, var(--card)); color: color-mix(in srgb, var(--good) 70%, var(--text)); font-weight: 600; }
.sheet td.cell.s-pend, .sheet td.cell.s-plan { background: color-mix(in srgb, #9aa0b8 18%, var(--card)); color: var(--muted); }
.sheet td.cell.s-plan .v { font-style: italic; }
.sheet td.cell.open.s-paid, .sheet td.cell.open.s-pend, .sheet td.cell.open.s-plan { outline: 1px dashed var(--warn); outline-offset: -2px; }
.sheet tr.pendrow td { color: var(--muted); font-weight: 600; }
.mo { color: var(--brand); font-weight: 800; }
.lg { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; border: 1px solid var(--line); }
.lg.paid { background: color-mix(in srgb, var(--good) 17%, var(--card)); color: var(--good); }
.lg.plan { background: color-mix(in srgb, #9aa0b8 18%, var(--card)); color: var(--muted); }

/* no cell backgrounds: only coloured text and the tick circle */
.sheet td.cell.s-paid, .sheet td.cell.s-pend, .sheet td.cell.s-plan, .sheet td.cell.open { background: var(--card); }
.sheet td.cell.s-paid { color: var(--good); font-weight: 700; }
.sheet td.cell.s-pend, .sheet td.cell.s-plan { color: var(--muted); font-weight: 400; }
.sheet td.cell.open.s-paid, .sheet td.cell.open.s-pend, .sheet td.cell.open.s-plan { outline: none; }
.sheet td.cell:hover { background: color-mix(in srgb, var(--brand) 6%, var(--card)); }
.sheet td.cell[data-locked]:hover { background: var(--card); }
.lg.paid, .lg.plan { background: none; border: 0; padding: 0; }
.lg.plan { color: var(--muted); }

.sheet td.cell { padding-left: 10px; cursor: pointer; }
.sheet td.cell.open { cursor: cell; }
.sheet td.cell[data-locked]:hover { background: color-mix(in srgb, var(--brand) 8%, var(--card)); }
.sheet th.newyear, .sheet th.sub2:first-child { }
.sheet th.mh.open { background: var(--card); color: var(--warn); box-shadow: inset 0 -3px var(--warn); }
.sheet tr.sec td { background: color-mix(in srgb, var(--brand) 10%, var(--card)); }
.sheet tr.sec td.stick { z-index: 3; }
.sheet tr.sec td:not(.stick) { position: static; }

.sheet th.pad, .sheet td.pad { background: transparent; border: 0; padding: 0; }
.sheet tr.sec td.pad, .sheet tr.sum td.pad { background: transparent; }

.sheet td.tot { position: static; right: auto; }
.sheet th.visoh { border-left: 2px solid var(--line); }
.sheet td.tot { border-left: 2px solid var(--line); }

label.chk { display: flex; align-items: center; gap: 10px; text-transform: none; letter-spacing: 0; font-size: 14px; color: var(--text); font-weight: 600; }
input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--brand); padding: 0; }

.zoomctl { position: fixed; right: 28px; bottom: 96px; z-index: 6; display: flex; flex-direction: column; align-items: center; background: var(--card); border-radius: 16px; box-shadow: var(--shadow), 0 6px 20px rgba(20,20,60,.18); overflow: hidden; }
.zoomctl button { width: 46px; height: 42px; border: 0; background: none; font-size: 24px; font-weight: 700; color: var(--brand); }
.zoomctl button:hover { background: color-mix(in srgb, var(--brand) 10%, transparent); }
.zoomctl span { font-size: 11px; font-weight: 700; color: var(--muted); padding: 2px 0; cursor: pointer; }
@media (max-width: 820px) { .zoomctl { right: 16px; bottom: 150px; } }

.deltext { margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--line); text-align: center; }
.deltext a { color: var(--muted); font-size: 12px; cursor: pointer; text-decoration: underline; }
.deltext a:hover { color: var(--bad); }
.modal p { margin: 8px 0; }

/* resizable name column + full text on hover */
.sheet .stick { min-width: var(--namew, 230px); max-width: var(--namew, 230px); width: var(--namew, 230px); overflow: visible; }
@media (max-width: 820px) { .sheet .stick { min-width: var(--namew, 130px); max-width: var(--namew, 130px); width: var(--namew, 130px); } }
.sheet td.nm { padding: 0; }
.sheet .nmt { display: block; padding: 6px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet td.nm:hover .nmt { position: absolute; left: 0; top: 0; bottom: 0; z-index: 8; width: max-content; max-width: 560px; overflow: visible; background: var(--card); box-shadow: 4px 0 14px rgba(20,20,60,.22); border-radius: 0 8px 8px 0; }
.sheet th.stick { position: sticky; }
.rz { position: absolute; right: 0; top: 0; bottom: 0; width: 9px; cursor: col-resize; touch-action: none; }
.rz:hover, .rz:active { background: var(--brand); opacity: .5; }

.modal label.chk { background: color-mix(in srgb, var(--brand) 9%, var(--bg)); padding: 13px 14px; border-radius: 13px; margin: 14px 0 4px; line-height: 1.3; }

.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 12px; background: var(--bg); flex: none; }
.bigimg { width: 100%; max-height: 300px; object-fit: contain; border-radius: 14px; background: var(--bg); margin: 8px 0; }
.itbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.itbl td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
.itbl td.r { text-align: right; white-space: nowrap; }
.itbl select { padding: 6px 8px; font-size: 12px; border-radius: 9px; }
.xdel { cursor: pointer; color: var(--muted); padding: 4px 6px; }
.xdel:hover { color: var(--bad); }
.aitext { white-space: pre-wrap; line-height: 1.55; font-size: 14px; }
@media (max-width: 820px) { .tabs button { font-size: 10px; } .tabs button .ic { font-size: 18px; } }

.g4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 820px) { .g4 { grid-template-columns: 1fr; } }

main.wide { padding-bottom: 14px; }
.sheetwrap { overflow: scroll; }

/* member icons: large and easy to see */
.av { font-size: 1.9em; line-height: 1; vertical-align: -0.2em; display: inline-block; }
.chip .av { font-size: 1.7em; margin-right: 2px; }
.row .av { font-size: 2.2em; }
.tag .av { font-size: 1.6em; vertical-align: -0.25em; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; font-size: 12px; }
.sheet th.sub2 .av { font-size: 1.9em; }
h3 .av { font-size: 1.6em; }

.avsvg { width: 1em; height: 1em; display: block; }
.av { width: auto; }
.seg .av { font-size: 1.6em; vertical-align: middle; }


/* member icons: back to a modest size so layouts are not distorted */
.av, .chip .av, .row .av, .tag .av, .sheet th.sub2 .av, h3 .av, .seg .av { font-size: 1.15em; vertical-align: -0.1em; margin-right: 1px; }
.tag { gap: 3px; padding: 2px 8px; }
.tag .av { font-size: 1.1em; }

.qchip{display:inline-block;font-size:11px;font-weight:700;padding:2px 8px;border-radius:999px;margin-left:6px;vertical-align:middle}
.q-wait{background:color-mix(in srgb,var(--warn) 22%,transparent);color:var(--warn)}
.q-run{background:color-mix(in srgb,var(--accent,#7c5cff) 25%,transparent);color:var(--text)}
.q-ok{background:color-mix(in srgb,#10b981 22%,transparent);color:#10b981}
.q-err{background:color-mix(in srgb,var(--bad) 22%,transparent);color:var(--bad)}
.qrow{border-bottom:1px solid var(--line,rgba(255,255,255,.08))}.qrow:last-of-type{border-bottom:0}
.qdet{padding:0 0 12px 62px}
.qdet .itbl th{font-size:11px;color:var(--muted);text-align:left;font-weight:600;padding:4px 8px}
.qdet .itbl td{padding:4px 8px;font-size:13px}
.sheet tr.hidsec td { cursor: pointer; background: color-mix(in srgb, var(--muted) 14%, var(--card)); }
.sheet tr.hid td.nm, .sheet tr.hid td.cell { opacity: .65; }
.sheet tr.annsec td { cursor: pointer; background: color-mix(in srgb, var(--brand) 16%, var(--card)); }
.sheet tr.annsum td { font-weight: 800; background: color-mix(in srgb, var(--brand) 6%, var(--card)); }
.sheet tr.ann td.nm { padding-left: 22px; }
.sheet .annopt { display: inline-flex; align-items: center; gap: 4px; margin-left: 10px; font-size: 10.5px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.sheet .annopt input[type=checkbox] { width: 12px; height: 12px; min-width: 0; padding: 0; margin: 0; flex: none; }
.mnav { display: inline-flex; align-items: center; gap: 6px; }
.mnav select { width: auto; padding: 6px 10px; border-radius: 10px; font-weight: 700; text-transform: capitalize; }
.sheet .loan { display: block; margin-top: 4px; }
.sheet .loanbar { display: block; height: 6px; border-radius: 4px; background: var(--line); overflow: hidden; }
.sheet .loanbar i { display: block; height: 100%; background: var(--good); border-radius: 4px; }
.sheet .loantxt { display: block; font-size: 10px; font-weight: 600; color: var(--muted); white-space: normal; line-height: 1.25; margin-top: 2px; }

/* popup next to a hovered / tapped donut slice */
.pie-pop { position: fixed; z-index: 60; display: none; min-width: 210px; max-width: 280px; padding: 12px 14px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); box-shadow: 0 10px 34px rgba(0, 0, 0, .35); font-size: 13px; line-height: 1.5; pointer-events: none; }
