:root {
  --brand: #0f766e;
  --brand-dark: #115e59;
  --brand-soft: #ccfbf1;
  --bg: #f3f6f8;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(15,23,42,.05), 0 4px 14px rgba(15,23,42,.06);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: 'Heebo', system-ui, -apple-system, 'Segoe UI', Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark)); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; gap: 10px;
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 700; flex: 1; }
.live { font-size: 12px; opacity: .9; display: flex; align-items: center; gap: 6px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 0 rgba(74,222,128,.7); animation: pulse 2s infinite; }
.live.off i { background: #fbbf24; animation: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(74,222,128,0); } 100% { box-shadow: 0 0 0 0 rgba(74,222,128,0); } }
.userchip { background: rgba(255,255,255,.16); border: 0; color: #fff; padding: 6px 12px; border-radius: 999px; font-size: 14px; font-weight: 500; }

.wrap { max-width: 920px; margin: 0 auto; padding: 14px 14px 24px; }

/* period navigator */
.pnav { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.pnav .label { flex: 1; text-align: center; font-weight: 600; background: var(--card); border-radius: 12px; padding: 9px 8px; box-shadow: var(--shadow); font-size: 15px; }
.pnav .label small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.iconbtn { width: 42px; height: 42px; border-radius: 12px; border: 0; background: var(--card); box-shadow: var(--shadow); font-size: 18px; display: grid; place-items: center; }
.iconbtn:disabled { opacity: .35; }

/* cards */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 16px; margin: 0 0 12px; font-weight: 700; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h2 .sub { font-weight: 400; color: var(--muted); font-size: 13px; }
.grid2 { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 760px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* hero */
.hero { background: linear-gradient(135deg, #ffffff, #f0fdfa); }
.hero .big { font-size: 38px; font-weight: 800; line-height: 1.1; }
.hero .big.good { color: var(--good); } .hero .big.warn { color: var(--warn); } .hero .big.bad { color: var(--bad); }
.hero .cap { color: var(--muted); font-size: 14px; margin-bottom: 2px; }
.hero .row3 { display: flex; gap: 10px; margin-top: 14px; }
.hero .row3 > div { flex: 1; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px; }
.hero .row3 b { display: block; font-size: 18px; }
.hero .row3 span.t { color: var(--muted); font-size: 12px; }
.bar { height: 12px; background: #e6eef0; border-radius: 99px; overflow: hidden; margin-top: 14px; }
.bar > i { display: block; height: 100%; border-radius: 99px; background: var(--good); transition: width .5s; }
.bar.warn > i { background: var(--warn); } .bar.bad > i { background: var(--bad); }
.hint { color: var(--muted); font-size: 13px; margin-top: 8px; }
.linkbtn { background: none; border: 0; color: var(--brand); font-weight: 600; padding: 4px 6px; font-size: 14px; }

/* lists */
.item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.item.click { cursor: pointer; }
.badge { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 21px; flex: none; }
.item .main { flex: 1; min-width: 0; }
.item .main b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .main small { color: var(--muted); font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .amt { font-weight: 700; font-size: 16px; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 26px 8px; }
.empty .em { font-size: 40px; display: block; margin-bottom: 6px; }

.rowbar { margin: 10px 0; }
.rowbar .top { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; margin-bottom: 5px; }
.rowbar .top span:first-child { font-weight: 500; }
.rowbar .track { height: 10px; background: #edf2f4; border-radius: 99px; overflow: hidden; }
.rowbar .track i { display: block; height: 100%; border-radius: 99px; }

.donutwrap { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; justify-content: center; }
.donut { width: 150px; height: 150px; flex: none; }
.legend { flex: 1; min-width: 160px; }
.legend div { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 3px 0; }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend span.n { flex: 1; } .legend span.p { color: var(--muted); }

/* insights */
.insight { display: flex; gap: 12px; padding: 12px; border-radius: 12px; background: #f8fafc; margin-bottom: 10px; border: 1px solid var(--line); }
.insight .ic { font-size: 24px; line-height: 1.2; }
.insight b { display: block; margin-bottom: 1px; }
.insight p { margin: 0; color: #334155; font-size: 14.5px; }
.insight.good { background: #f0fdf4; border-color: #bbf7d0; }
.insight.warn { background: #fffbeb; border-color: #fde68a; }
.insight.bad { background: #fef2f2; border-color: #fecaca; }

/* history */
.hist { display: block; width: 100%; text-align: right; background: none; border: 0; border-bottom: 1px solid var(--line); padding: 13px 0; }
.hist:last-child { border-bottom: 0; }
.hist .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.hist .meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 13px; margin-top: 3px; }
.hist .bar { height: 8px; margin-top: 8px; }

/* forms */
label.f { display: block; font-size: 14px; font-weight: 600; margin: 14px 0 6px; color: #334155; }
.inp { width: 100%; border: 1.5px solid var(--line); background: #fff; border-radius: 12px; padding: 12px 14px; font-size: 16px; outline: none; }
.inp:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15,118,110,.15); }
.amount-inp { font-size: 34px; font-weight: 800; text-align: center; padding: 12px; direction: ltr; }
.btn { border: 0; border-radius: 12px; padding: 13px 18px; font-weight: 700; font-size: 16px; background: var(--brand); color: #fff; }
.btn:active { background: var(--brand-dark); }
.btn.block { width: 100%; }
.btn.ghost { background: #eef2f5; color: var(--text); }
.btn.danger { background: #fee2e2; color: var(--bad); }
.btn.sm { padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .55; }
.btnrow { display: flex; gap: 10px; margin-top: 18px; }
.btnrow .btn { flex: 1; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1.5px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 13px; font-size: 14.5px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); font-weight: 700; }
.seg { display: flex; background: #eef2f5; border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: none; padding: 10px 6px; border-radius: 9px; font-weight: 600; }
.seg button.on { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.12); color: var(--brand-dark); }
.err { color: var(--bad); font-size: 14px; margin-top: 10px; min-height: 20px; }
.check { display: flex; align-items: center; gap: 8px; margin-top: 14px; font-size: 15px; }
.check input { width: 20px; height: 20px; accent-color: var(--brand); }

/* sheet */
.overlay { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.sheet { background: #fff; width: 100%; max-width: 520px; border-radius: 22px 22px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); max-height: 94vh; overflow-y: auto; animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h3 { margin: 0 0 4px; font-size: 19px; display: flex; justify-content: space-between; align-items: center; }
.sheet .x { border: 0; background: #eef2f5; width: 34px; height: 34px; border-radius: 50%; font-size: 16px; }
@media (min-width: 640px) { .overlay { align-items: center; } .sheet { border-radius: 22px; } }

/* FAB + nav */
.fab {
  position: fixed; z-index: 30; left: 18px; bottom: calc(84px + env(safe-area-inset-bottom));
  width: 62px; height: 62px; border-radius: 50%; border: 0; background: var(--brand); color: #fff;
  font-size: 34px; box-shadow: 0 6px 20px rgba(15,118,110,.45); display: grid; place-items: center; line-height: 1;
}
.fab:active { transform: scale(.94); }
.nav {
  position: fixed; bottom: 0; inset-inline: 0; z-index: 25; background: #fff; border-top: 1px solid var(--line);
  display: flex; padding-bottom: env(safe-area-inset-bottom); justify-content: center;
}
.nav button { flex: 1; max-width: 140px; border: 0; background: none; padding: 8px 2px 7px; display: flex; flex-direction: column; align-items: center; gap: 1px; color: var(--muted); font-size: 11.5px; font-weight: 500; }
.nav button .i { font-size: 21px; filter: grayscale(1) opacity(.7); }
.nav button.on { color: var(--brand); font-weight: 700; }
.nav button.on .i { filter: none; }

/* toast */
#toast { position: fixed; bottom: calc(150px + env(safe-area-inset-bottom)); right: 50%; transform: translateX(50%) translateY(20px); background: #0f172a; color: #fff; padding: 11px 18px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .25s; z-index: 80; font-size: 15px; max-width: 90vw; text-align: center; }
#toast.show { opacity: 1; transform: translateX(50%) translateY(0); }

/* login */
.loginpage { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #0f766e, #134e4a 70%); }
.logincard { background: #fff; width: 100%; max-width: 380px; border-radius: 22px; padding: 28px 24px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.logo { width: 64px; height: 64px; border-radius: 18px; background: var(--brand); color: #fff; font-size: 34px; font-weight: 800; display: grid; place-items: center; margin: 0 auto 12px; }
.logincard h1 { text-align: center; margin: 0 0 4px; font-size: 24px; }
.logincard p.s { text-align: center; color: var(--muted); margin: 0 0 8px; }

/* settings */
.catrow { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.catrow:last-child { border-bottom: 0; }
.catrow .nm { flex: 1; font-weight: 500; }
.emojis { display: flex; flex-wrap: wrap; gap: 6px; }
.emojis button { width: 40px; height: 40px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; font-size: 20px; }
.emojis button.on { border-color: var(--brand); background: var(--brand-soft); }
.colors { display: flex; flex-wrap: wrap; gap: 8px; }
.colors button { width: 32px; height: 32px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1.5px var(--line); }
.colors button.on { box-shadow: 0 0 0 2.5px var(--text); }

/* report */
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.kpis > div { background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.kpis b { display: block; font-size: 18px; } .kpis span { font-size: 12px; color: var(--muted); }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: right; color: var(--muted); font-weight: 600; font-size: 12.5px; padding: 8px 6px; border-bottom: 2px solid var(--line); }
table.t td { padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.t td.n, table.t th.n { text-align: left; }
table.t tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
.tablewrap { overflow-x: auto; }
.printonly { display: none; }

@media print {
  body { background: #fff; padding: 0; }
  .topbar, .nav, .fab, .pnav, .noprint, #toast { display: none !important; }
  .printonly { display: block; }
  .card { box-shadow: none; border: 1px solid #ddd; break-inside: avoid; }
  .wrap { max-width: none; padding: 0; }
}

/* test mode */
.testbar { position: sticky; top: 52px; z-index: 19; background: #f59e0b; color: #422006; font-size: 13.5px; font-weight: 600; padding: 7px 14px; display: flex; gap: 10px; align-items: center; justify-content: center; text-align: center; flex-wrap: wrap; }
.testbar button { background: #422006; color: #fff; border: 0; border-radius: 8px; padding: 4px 10px; font-size: 13px; }
body.testmode .topbar { background: linear-gradient(135deg, #b45309, #92400e); }
@media print { .testbar { display: none; } }

/* clearer add button */
.fab { left: 50%; transform: translateX(-50%); width: auto; height: 52px; border-radius: 999px; padding: 0 22px; font-size: 17px; font-weight: 700; gap: 8px; display: flex; align-items: center; white-space: nowrap; }
.fab b { font-size: 28px; font-weight: 600; line-height: 1; }
.fab:active { transform: translateX(-50%) scale(.95); }
.addtop { margin-bottom: 14px; font-size: 17px; padding: 15px; box-shadow: 0 4px 14px rgba(15,118,110,.3); }
body { padding-bottom: calc(140px + env(safe-area-inset-bottom)); }

/* statement import */
.irow { display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); align-items: flex-start; }
.irow:last-child { border-bottom: 0; }
.irow.off .imain { opacity: .5; }
.irow.miss { background: #fef2f2; border-radius: 10px; }
.ichk, .xl input { width: 22px; height: 22px; accent-color: var(--brand); margin-top: 2px; flex: none; }
.imain { flex: 1; min-width: 0; }
.itop { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.itop b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.isub { color: var(--muted); font-size: 13px; margin: 1px 0 8px; }
.isub .ai { color: var(--brand); font-weight: 600; }
.ictl { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ictl select { flex: 1; min-width: 160px; padding: 9px 10px; font-size: 15px; }
.xl { display: flex; align-items: center; gap: 6px; font-size: 14px; white-space: nowrap; }
.impfoot { position: sticky; bottom: calc(62px + env(safe-area-inset-bottom)); z-index: 22; background: #fff; border-radius: 16px; box-shadow: 0 -2px 20px rgba(15,23,42,.18); padding: 12px 14px; display: flex; align-items: center; gap: 12px; justify-content: space-between; }
.impfoot .sum { font-size: 14px; line-height: 1.35; }
