:root {
  --navy: #1b2f57;
  --blue: #0a6eb4;
  --cyan: #1bbdeb;
  --teal: #26a08f;
  --mint: #5ce0a0;
  --red: #c4161c;
  --gold: #e8b84a;
  --green: #1e9e6a;
  --bg: #eef3f8;
  --card: #ffffff;
  --text: #1c2638;
  --muted: #66758c;
  --line: #e1e7ef;
  --soft: #f5f8fb;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(27, 47, 87, .07);
  --sidebar: 248px;
  font-family: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); min-height: 100%; }
body { overflow-x: hidden; } /* last line of defence: never scroll sideways on a phone */
main { min-width: 0; overflow-wrap: break-word; }
body { font-size: 14.5px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--blue); }
img { max-width: 100%; }
[hidden] { display: none !important; }
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot img { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .5; transform: scale(.95); } }

/* ---------- layout ---------- */
.shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(120deg, var(--navy), var(--blue));
  color: #fff; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
  display: flex; align-items: center; gap: 12px; min-height: 58px;
}
.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; text-align: center; }
.topbar .icon-btn { color: #fff; }
.topbar .spacer { width: 38px; }
main { padding: 16px 16px 110px; max-width: 1100px; margin: 0 auto; }

.sidebar { display: none; }
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: linear-gradient(120deg, var(--navy), var(--blue));
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  height: 64px; padding-bottom: env(safe-area-inset-bottom); box-sizing: content-box;
}
.bottomnav a { color: rgba(255, 255, 255, .7); text-decoration: none; display: grid; justify-items: center; gap: 2px; font-size: 10.5px; }
.bottomnav a.on { color: #fff; }
.bottomnav a svg { width: 22px; height: 22px; }
.bottomnav .fab {
  width: 58px; height: 58px; border-radius: 50%; margin: -30px auto 0;
  background: var(--mint); color: var(--navy); display: grid; place-items: center;
  box-shadow: 0 6px 18px rgba(30, 158, 106, .45); border: 4px solid var(--bg);
}
.bottomnav .fab svg { width: 28px; height: 28px; }

@media (min-width: 900px) {
  .bottomnav { display: none; }
  .sidebar {
    display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
    background: var(--navy); color: #fff; padding: 20px 14px; z-index: 30;
  }
  .sidebar .brand { background: #fff; border-radius: 12px; padding: 10px 12px; margin-bottom: 22px; }
  .sidebar .brand img { display: block; width: 100%; height: auto; }
  .sidebar nav { display: grid; gap: 4px; }
  .sidebar nav a {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px;
    color: rgba(255, 255, 255, .78); text-decoration: none; font-weight: 500;
  }
  .sidebar nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; }
  .sidebar nav a.on { background: var(--blue); color: #fff; }
  .sidebar nav a svg { width: 20px; height: 20px; flex: none; }
  .sidebar .add-btn { margin: 18px 0 8px; justify-content: center; }
  .sidebar .me { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 12px; background: rgba(255, 255, 255, .07); }
  .sidebar .me small { color: rgba(255, 255, 255, .6); display: block; }
  .shell { padding-left: var(--sidebar); }
  .topbar { background: var(--bg); color: var(--navy); padding: 18px 28px 6px; max-width: 1156px; }
  .topbar h1 { text-align: left; font-size: 22px; }
  .topbar .icon-btn { color: var(--navy); }
  .topbar .back, .topbar .spacer { display: none; }
  main { padding: 8px 28px 40px; margin: 0; max-width: 1156px; }
}

/* ---------- common ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card, .section + .section { margin-top: 16px; }
.grid > .card + .card { margin-top: 0; }
.card h2, .section-title { font-size: 15.5px; font-weight: 600; margin: 0 0 12px; color: var(--navy); }
.section-head { display: flex; align-items: center; justify-content: space-between; margin: 20px 0 10px; }
.section-head h2 { margin: 0; font-size: 16px; color: var(--navy); }
.section-head a { font-weight: 600; text-decoration: none; font-size: 13.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.grid > * { min-width: 0; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.income { color: var(--green); }
.expense { color: var(--red); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.empty svg { width: 44px; height: 44px; opacity: .4; display: block; margin: 0 auto 8px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; border-radius: 10px; padding: 10px 18px; font-weight: 600; cursor: pointer;
  background: var(--blue); color: #fff; text-decoration: none; min-height: 42px; white-space: nowrap;
  transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }
.btn.mint { background: var(--mint); color: var(--navy); }
.btn.navy { background: var(--navy); }
.btn.red { background: var(--red); }
.btn.ghost { background: transparent; color: var(--blue); box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.sm { padding: 6px 12px; min-height: 34px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.icon-btn {
  background: none; border: 0; width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  cursor: pointer; color: var(--muted); flex: none;
}
.icon-btn:hover { background: rgba(0, 0, 0, .05); }
.icon-btn svg { width: 20px; height: 20px; }

label.field { display: grid; gap: 5px; font-size: 13px; font-weight: 500; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; border: 1.5px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff;
  min-height: 44px; font-size: 15px; color: var(--text); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(10, 110, 180, .12); }
textarea.input { min-height: 80px; resize: vertical; }
.form { display: grid; gap: 14px; }
.form-2 { display: grid; gap: 14px; grid-template-columns: 1fr 1fr; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 4px; }
.err { background: #fde8e8; color: #9b1116; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; }
.note { background: #e8f3fb; color: #12466e; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; }
.warn { background: #fff5dd; color: #7a5300; padding: 10px 12px; border-radius: 10px; font-size: 13.5px; }

.seg { display: inline-grid; grid-auto-flow: column; background: var(--soft); border-radius: 12px; padding: 4px; gap: 4px; box-shadow: inset 0 0 0 1px var(--line); }
.seg button { border: 0; background: none; padding: 8px 16px; border-radius: 9px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.on { background: #fff; color: var(--navy); box-shadow: var(--shadow); }
.seg button.on.expense { color: var(--red); }
.seg button.on.income { color: var(--green); }
.seg.full { display: grid; width: 100%; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--soft); color: var(--muted); }
.chip.active { background: #dcf7ea; color: #13704a; }
.chip.disabled { background: #fde8e8; color: #9b1116; }
.chip.pending { background: #fff1cc; color: #7a5300; }
.chip.admin { background: #e1ecfb; color: var(--navy); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.badge { background: var(--red); color: #fff; border-radius: 99px; font-size: 11px; font-weight: 700; padding: 1px 7px; margin-left: auto; }

.avatar { width: 40px; height: 40px; border-radius: 50%; background: #dfe9f5; display: grid; place-items: center; font-weight: 700; color: var(--navy); flex: none; overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.lg { width: 96px; height: 96px; font-size: 34px; border: 4px solid #fff; box-shadow: var(--shadow); }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(1200px 600px at 110% -10%, rgba(27, 189, 235, .22), transparent 60%),
  radial-gradient(900px 500px at -10% 110%, rgba(92, 224, 160, .22), transparent 60%), var(--bg); }
.login .card { width: 100%; max-width: 400px; padding: 28px 24px; }
.login .logo { display: block; width: 240px; max-width: 80%; margin: 0 auto 6px; }
.login h1 { text-align: center; font-size: 20px; color: var(--navy); margin: 14px 0 4px; }
.login p.sub { text-align: center; color: var(--muted); margin: 0 0 20px; }
.or { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12.5px; margin: 18px 0; }
.or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
#gbtn { display: flex; justify-content: center; min-height: 44px; }
.pw-wrap { position: relative; }
.pw-wrap .icon-btn { position: absolute; right: 3px; top: 3px; }

/* ---------- quick PIN ---------- */
.lock { text-align: center; }
.lock .logo { width: 180px; }
.lock .avatar { margin: 14px auto 0; }
.lock h1 { margin-top: 10px; }
.lock p.sub { margin-bottom: 10px; }
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 10px 0 6px; }
.pin-dots i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--navy); transition: background .1s, transform .1s; }
.pin-dots i.on { background: var(--navy); transform: scale(1.08); }
.pin-dots.shake { animation: shake .4s; }
.pin-dots.shake i { border-color: var(--red); }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }
.pin-msg { min-height: 20px; color: var(--red); font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.keypad { display: grid; grid-template-columns: repeat(3, 72px); gap: 12px 22px; justify-content: center; }
.keypad button {
  width: 72px; height: 72px; border-radius: 50%; border: 0; background: var(--soft); box-shadow: inset 0 0 0 1px var(--line);
  font-size: 26px; font-weight: 600; color: var(--navy); cursor: pointer; display: grid; place-items: center; transition: background .1s, transform .05s;
  -webkit-tap-highlight-color: transparent;
}
.keypad button:hover { background: #e3edf7; }
.keypad button:active { background: #cfe1f3; transform: scale(.95); }
.keypad button svg { width: 26px; height: 26px; }
.keypad button[data-k=del] { background: none; box-shadow: none; }
.pin-icon { width: 60px; height: 60px; border-radius: 50%; background: #e1ecfb; color: var(--navy); display: grid; place-items: center; margin: 0 auto 6px; }

/* ---------- home ---------- */
.hello { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.hello .grow b { display: block; font-size: 17px; color: var(--navy); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hello input[type=month] { border: 0; background: #fff; border-radius: 10px; padding: 8px 10px; font-weight: 600; color: var(--navy); box-shadow: var(--shadow); }
.balance {
  border-radius: 20px; overflow: hidden; color: #fff; box-shadow: 0 10px 28px rgba(38, 160, 143, .3);
  background: linear-gradient(135deg, #2bb594, var(--mint));
}
.balance .bt { background: rgba(27, 47, 87, .22); text-align: center; padding: 12px; font-weight: 600; font-size: 17px; letter-spacing: .3px; }
.balance .amounts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 16px; }
.balance .amt { background: rgba(255, 255, 255, .92); color: var(--navy); border-radius: 12px; padding: 10px 12px; text-align: center; }
.balance .amt small { display: block; color: var(--muted); font-weight: 600; font-size: 11.5px; }
/* money is never cut off: the font shrinks on small phones and very large numbers wrap */
.balance .amt b { font-size: clamp(15px, 5vw, 21px); display: block; overflow-wrap: anywhere; line-height: 1.25; }
.balance .amt b.neg { color: var(--red); }
.balance .month { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 0 16px 16px; }
.balance .month span { overflow-wrap: anywhere; }
.balance .month div { background: rgba(255, 255, 255, .22); border-radius: 12px; padding: 8px 12px; }
.balance .month small { display: block; font-weight: 600; opacity: .95; font-size: 12px; }
.balance .month span { display: block; font-weight: 600; font-size: 13.5px; }

/* ---------- transactions ---------- */
/* minmax(0, 1fr): long descriptions get "..." instead of widening the page past the phone screen */
.tx-list { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); }
.tx {
  display: flex; align-items: center; gap: 12px; background: var(--card); border-radius: 12px; padding: 12px 14px;
  box-shadow: var(--shadow); text-decoration: none; color: inherit; border-left: 4px solid var(--c, var(--line));
}
a.tx:hover { box-shadow: 0 4px 16px rgba(27, 47, 87, .12); }
.tx .grow b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .grow small { color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .amt { text-align: right; flex: none; }
.tx .amt b { display: block; white-space: nowrap; }
.tx .amt small { color: var(--muted); }
.filters { display: grid; gap: 10px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.filters .input { min-width: 0; }
.filters input[type=date] { padding-left: 8px; padding-right: 6px; font-size: 14px; }
.filters .wide { grid-column: 1 / -1; }
@media (min-width: 700px) { .filters { grid-template-columns: minmax(0, 2fr) repeat(5, minmax(0, 1fr)); } .filters .wide { grid-column: auto; } }
.totals-bar { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 14px 0; }
.totals-bar div { background: var(--card); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); }
.totals-bar small { color: var(--muted); display: block; font-size: 12px; font-weight: 500; }
.totals-bar b { font-size: 15px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 12px; margin-top: 16px; }

/* ---------- bill photos ---------- */
.bill-bar { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.bill-bar .btn { white-space: normal; text-align: center; line-height: 1.2; }
#billInfo { display: grid; gap: 8px; }
#billInfo:empty { display: none; }
.bill-preview { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 12px; background: var(--soft); box-shadow: inset 0 0 0 1px var(--line); border: 0; width: 100%; text-align: left; cursor: pointer; font: inherit; }
.bill-thumb { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex: none; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }
.bill-thumb.pdf { display: grid; place-items: center; color: var(--red); }
.bill-thumb.pdf svg { width: 28px; height: 28px; }
.bill-full { display: block; width: 100%; max-height: 70vh; object-fit: contain; border-radius: 10px; background: var(--soft); }
.linkish { background: none; border: 0; padding: 0; color: var(--blue); font-weight: 600; cursor: pointer; font: inherit; font-size: 13px; }
.tx-bill { width: 13px; height: 13px; vertical-align: -2px; margin-right: 4px; color: var(--blue); }
.input.filled { animation: filled 1.6s ease-out; }
@keyframes filled { 0% { background: #d8f7e8; border-color: var(--green); } 100% { background: #fff; } }

/* ---------- dashboard ---------- */
.chart-box { position: relative; height: 260px; }
.chart-box.tall { height: 300px; }
.stat { display: grid; gap: 2px; }
.stat small { color: var(--muted); font-weight: 500; }
.stat b { font-size: 20px; color: var(--navy); }
.cat-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.cat-row:last-child { border-bottom: 0; }
.bar { height: 6px; border-radius: 3px; background: var(--soft); overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; border-radius: 3px; }

/* ---------- menu list (profile) ---------- */
.profile-head { text-align: center; padding: 10px 0 18px; }
.profile-head .avatar { margin: 0 auto 10px; }
.profile-head b { font-size: 18px; color: var(--navy); display: block; }
.menu { display: grid; }
.menu a, .menu button {
  display: flex; align-items: center; gap: 14px; padding: 14px 4px; border: 0; border-bottom: 1px solid var(--line);
  background: none; text-decoration: none; color: var(--text); font-weight: 500; cursor: pointer; text-align: left; width: 100%;
}
.menu a:last-child, .menu button:last-child { border-bottom: 0; }
.menu svg { width: 22px; height: 22px; color: var(--navy); flex: none; }
.menu .chev { margin-left: auto; color: var(--muted); width: 18px; height: 18px; }

/* ---------- tables (admin, import) ---------- */
.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; padding: 8px 10px; border-bottom: 2px solid var(--line); white-space: nowrap; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr.bad td { background: #fff4f4; }
.tbl tr.dup td { background: #fffaf0; }
.tbl .num { text-align: right; white-space: nowrap; }
.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 16px; padding-bottom: 2px; }
.tabs a { padding: 8px 16px; border-radius: 99px; background: #fff; color: var(--muted); text-decoration: none; font-weight: 600; white-space: nowrap; box-shadow: var(--shadow); display: inline-flex; gap: 6px; align-items: center; }
.tabs a.on { background: var(--navy); color: #fff; }
.user-card { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.user-card:last-child { border-bottom: 0; }
.user-card .grow b { display: block; }
.user-card .grow small { color: var(--muted); word-break: break-all; }
.user-card .ctrls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.user-card select { min-height: 34px; padding: 4px 8px; font-size: 13px; width: auto; }
.perm-grid { display: grid; gap: 6px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.check { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: var(--soft); cursor: pointer; font-size: 13.5px; }
.check input { width: 18px; height: 18px; accent-color: var(--blue); }

/* toggle switch */
.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #c9d3df; border-radius: 99px; transition: .2s; cursor: pointer; }
.switch span::before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span::before { transform: translateX(18px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px rgba(10, 110, 180, .3); }

/* drop zone */
.drop { display: grid; justify-items: center; gap: 4px; border: 2px dashed #b9c7d8; border-radius: 16px; padding: 28px 16px; text-align: center; background: var(--soft); cursor: pointer; transition: .15s; }
.drop.over, .drop:hover { border-color: var(--blue); background: #e8f3fb; }
.drop svg { width: 40px; height: 40px; color: var(--blue); }
.export-opts { display: grid; gap: 10px; grid-template-columns: repeat(3, 1fr); }
.export-opts button { border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 16px 8px; cursor: pointer; display: grid; justify-items: center; gap: 6px; font-weight: 600; }
.export-opts button svg { width: 34px; height: 34px; }
.export-opts button:hover { border-color: var(--blue); }

/* ---------- modal + toast ---------- */
.modal { position: fixed; inset: 0; z-index: 100; background: rgba(15, 25, 45, .5); display: grid; place-items: end center; padding: 0; }
.modal .sheet { background: #fff; width: 100%; max-width: 520px; border-radius: 20px 20px 0 0; padding: 20px 16px; padding-bottom: max(20px, env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; animation: up .2s ease-out; }
@media (min-width: 600px) { .modal { place-items: center; padding: 16px; } .modal .sheet { border-radius: 20px; padding: 24px; } }
.modal h3 { margin: 0 0 14px; color: var(--navy); font-size: 18px; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 12px; font-weight: 500; opacity: 0; pointer-events: none; transition: .25s; z-index: 200; max-width: calc(100% - 32px); text-align: center; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--red); }
@media (min-width: 900px) { #toast { bottom: 30px; left: calc(50% + var(--sidebar) / 2); } }

.spin { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--blue); border-radius: 50%; animation: rot .8s linear infinite; margin: 30px auto; }
@keyframes rot { to { transform: rotate(360deg); } }
