:root {
  --bg: #f1f4f1;
  --surface: #ffffff;
  --ink: #15211b;
  --muted: #5b6a62;
  --line: #d7ded9;
  --line-soft: #e9eee9;
  --green: #1c5240;
  --green-ink: #ffffff;
  --green-soft: #e2eee7;
  --pos: #1d7646;
  --neg: #b4322a;
  --neg-soft: #f8e3e1;
  --low: #9a6608;
  --low-soft: #f8edcf;
  --ok-cell: #2f8a5b;
  --low-cell: #e0a526;
  --neg-cell: #c4392f;
  --radius: 10px;
  --font: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); }
a { color: var(--green); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: .95rem; font-weight: 650; margin-top: 1rem; }
p { margin: 0 0 .6em; }
small, .small { font-size: .82rem; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.big { font-size: 1.5rem; font-weight: 700; display: block; letter-spacing: -0.02em; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.low { color: var(--low); }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 3px solid #6fb08f; outline-offset: 2px; }

/* ---------- Header ---------- */
.top { background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 1rem; padding: .55rem 1.25rem; position: sticky; top: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; color: var(--ink); text-decoration: none; white-space: nowrap; }
.mark { width: 22px; height: 22px; border-radius: 5px; background:
  linear-gradient(var(--green), var(--green)) 0 0 / 100% 100%; position: relative; display: inline-block; flex: none; }
.mark::after { content: ""; position: absolute; left: 4px; right: 4px; top: 6px; height: 10px;
  border-top: 2px solid #9fd3b6; border-bottom: 2px solid #9fd3b6; }
.mark.big { width: 44px; height: 44px; border-radius: 10px; }
.mark.big::after { left: 9px; right: 9px; top: 13px; height: 18px; border-width: 3px; }
.nav { display: flex; align-items: center; gap: .15rem; flex: 1; flex-wrap: wrap; }
.nav > a { padding: .45rem .7rem; border-radius: 7px; color: var(--ink); text-decoration: none; font-weight: 500; }
.nav > a:hover { background: var(--line-soft); }
.nav > a[aria-current="page"] { background: var(--green-soft); color: var(--green); font-weight: 650; }
.who { margin-left: auto; display: flex; align-items: center; gap: .5rem; font-size: .88rem; }
.who a { color: var(--ink); font-weight: 600; text-decoration: none; }
.who form { display: inline; }
.menu-btn { display: none; margin-left: auto; }

/* ---------- Layout ---------- */
.main { max-width: 1240px; margin: 0 auto; padding: 1.5rem 1.25rem 4rem; }
.main.narrow { max-width: 680px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; }
.page-head h1 { margin: 0; }
.crumb { font-size: .85rem; text-decoration: none; display: inline-block; margin-bottom: .2rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.15rem 1.25rem; margin-bottom: 1.1rem; }
.section-head { display: flex; flex-wrap: wrap; gap: .2rem 1rem; align-items: baseline; justify-content: space-between; }
.grid2, .grid3 { display: grid; gap: .1rem 1rem; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span2 { grid-column: span 2; }
.span3 { grid-column: 1 / -1; }

/* ---------- Forms ---------- */
label { display: block; font-size: .85rem; font-weight: 600; color: var(--ink); margin-bottom: .8rem; }
input, select, textarea { display: block; width: 100%; margin-top: .3rem; font: inherit; font-weight: 400; color: var(--ink);
  background: var(--surface); border: 1px solid #c3ccc6; border-radius: 7px; padding: .55rem .65rem; min-height: 42px; }
input:focus, select:focus { border-color: var(--green); outline: 2px solid var(--green-soft); }
input.amount { font-variant-numeric: tabular-nums; font-size: 1.05rem; font-weight: 600; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; display: inline; margin: 0 .35rem 0 0; accent-color: var(--green); }
label.check { font-weight: 500; display: flex; align-items: center; margin-bottom: .45rem; }
fieldset { border: 0; padding: 0; margin: 0 0 .9rem; }
legend { font-size: .85rem; font-weight: 600; margin-bottom: .45rem; padding: 0; }
.checks { display: flex; flex-wrap: wrap; gap: .2rem 1.1rem; }
.form h2 { margin-bottom: .9rem; }
.form h2 + p { margin-top: -.5rem; }
.narrow-form { max-width: 460px; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; margin-top: .4rem; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600; font-size: .92rem;
  padding: .55rem 1rem; min-height: 42px; border-radius: 8px; border: 1px solid #c3ccc6; background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--line-soft); }
.btn.primary { background: var(--green); border-color: var(--green); color: var(--green-ink); }
.btn.primary:hover { background: #163f31; }
.btn.wide { width: 100%; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--green); cursor: pointer; text-decoration: underline; }
.link.danger { color: var(--neg); }

.filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem; }
.filters label { margin: 0; min-width: 150px; }
.filters p { margin: 0 0 .6rem auto; }
.card-filters { margin-bottom: .9rem; }
.pager { display: flex; gap: .4rem; }

.seg { display: inline-flex; border: 1px solid #c3ccc6; border-radius: 9px; padding: 3px; gap: 3px; margin-bottom: .9rem; }
.seg legend { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.seg label { margin: 0; padding: .4rem .9rem; border-radius: 6px; cursor: pointer; font-weight: 600; display: flex; align-items: center; }
.seg input { position: absolute; opacity: 0; }
.seg label:has(input:checked) { background: var(--green); color: var(--green-ink); }
.seg label:has(input:focus-visible) { outline: 3px solid #6fb08f; }

/* ---------- Flash ---------- */
.flash { border-radius: 8px; padding: .7rem .95rem; margin-bottom: 1rem; font-weight: 500; border: 1px solid; }
.flash-ok { background: var(--green-soft); border-color: #b9d8c6; color: #154533; }
.flash-err { background: var(--neg-soft); border-color: #eab8b3; color: #7d1f19; }
.warn-line { color: var(--neg); font-weight: 600; font-size: .9rem; margin-top: .6rem; }
.warn-box { margin-top: 1rem; background: var(--neg-soft); border-radius: 8px; padding: .9rem 1rem; }
.warn-box h3 { margin-top: 0; color: #7d1f19; }
.warn-box ul { margin: 0; padding-left: 1.1rem; }
.empty { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-inline { color: var(--muted); padding: .6rem 0; margin: 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin: 0 -1.25rem; padding: 0 1.25rem; }
table.ledger { width: 100%; border-collapse: collapse; font-size: .9rem; }
.ledger th { text-align: left; font-weight: 600; font-size: .78rem; color: var(--muted); padding: .5rem .55rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
.ledger td { padding: .55rem .55rem; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
.ledger th.r, .ledger td.r { text-align: right; }
.ledger tfoot th { color: var(--ink); font-size: .9rem; border-top: 2px solid var(--ink); border-bottom: 0; padding-top: .6rem; }
.ledger tr.newday td { border-top: 1px solid var(--line); }
.ledger tr.weekend td:first-child { font-weight: 650; }
.ledger tr.future td { color: #9aa59f; }
.ledger tr.inactive td { opacity: .5; }
.ledger td.low { background: var(--low-soft); }
.ledger td.neg { font-weight: 650; }
.ledger.wide { min-width: 760px; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions a, .row-actions form { margin-left: .6rem; display: inline; font-size: .85rem; }
.row-actions .link { font-size: .85rem; }
.inline-form td { background: var(--green-soft); }
.row-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .6rem; }
.row-form label { margin: 0; min-width: 140px; }
form.inline { margin: 0; }

.tag { display: inline-block; font-size: .74rem; font-weight: 650; padding: .05rem .45rem; border-radius: 99px; margin-top: .15rem; }
.tag.neg { background: var(--neg-soft); color: var(--neg); }
.tag.low { background: var(--low-soft); color: var(--low); }
.tag.ok { background: var(--green-soft); color: var(--pos); }

.pri { display: inline-block; font-size: .74rem; font-weight: 650; padding: .05rem .5rem; border-radius: 4px; white-space: nowrap; }
.pri-1 { background: #3a1d1a; color: #fff; }
.pri-2 { background: var(--neg-soft); color: var(--neg); }
.pri-3 { background: var(--line-soft); color: var(--muted); }
.pri-4 { background: transparent; color: var(--muted); border: 1px dashed #b8c2bc; }
select.pri-select { min-height: 34px; padding: .25rem .4rem; font-size: .82rem; font-weight: 650; margin: 0; width: auto; max-width: 220px; }
select.pri-select.pri-4 { border-style: dashed; }

/* ---------- Balance strip (signature element) ---------- */
.strip { display: grid; grid-template-columns: repeat(30, minmax(0, 1fr)); gap: 3px; margin: .3rem 0 .9rem; }
.strip .cell { height: 34px; border-radius: 4px; position: relative; display: flex; align-items: flex-end; justify-content: center; }
.strip .cell i { font-style: normal; font-size: .62rem; font-weight: 600; color: rgba(255,255,255,.85); padding-bottom: 2px; }
.cell.ok { background: var(--ok-cell); }
.cell.low { background: var(--low-cell); }
.cell.neg { background: var(--neg-cell); }
.strip .cell.neg { height: 34px; box-shadow: inset 0 -6px 0 rgba(0,0,0,.18); }
.strip-label { font-size: .8rem; font-weight: 600; color: var(--muted); margin: .2rem 0 0; }
.legend { font-size: .78rem; color: var(--muted); display: flex; align-items: center; flex-wrap: wrap; gap: .35rem; }
.legend .cell { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-left: .5rem; }
.legend .cell:first-child { margin-left: 0; }

.forecast-head .stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.stats > div { display: flex; flex-direction: column; gap: .1rem; }
.stats span { font-size: .8rem; }
.stats b { font-size: 1.2rem; }
.stats b.big { font-size: 1.5rem; }

/* ---------- Dashboard ---------- */
.acc-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1.1rem; margin-bottom: 1.1rem; }
.acc-grid .card { margin: 0; }
.acc-head { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: .6rem; }
.acc-head h2 { margin: 0; }
.acc .strip { grid-template-columns: repeat(30, minmax(0, 1fr)); gap: 2px; }
.acc .strip .cell { height: 26px; }
.acc .strip .cell i { display: none; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .6rem 1rem; margin: .8rem 0; }
.facts dt { font-size: .78rem; color: var(--muted); }
.facts dd { margin: 0; font-weight: 650; }
ul.plain { list-style: none; padding: 0; margin: 0 0 .6rem; }
ul.plain li { display: flex; justify-content: space-between; gap: 1rem; padding: .3rem 0; border-bottom: 1px solid var(--line-soft); font-size: .9rem; }

.link-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: .8rem; margin-bottom: 1.1rem; }
.link-card { display: flex; flex-direction: column; gap: .2rem; text-decoration: none; color: var(--ink); margin: 0; }
.link-card:hover { border-color: var(--green); }
.steps { padding-left: 1.2rem; margin: 0 0 1rem; }
.steps li { margin-bottom: .3rem; }

/* ---------- Key-in ---------- */
.keyin { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 1.1rem; align-items: start; }
.keyin .card { margin: 0; }
.entry { position: sticky; top: 70px; }
.day-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .3rem 1rem; align-items: baseline; }

details.card > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary h2 { display: inline; }
details.card > summary::after { content: " Papar"; font-size: .85rem; color: var(--green); font-weight: 600; }
details[open].card > summary::after { content: " Sembunyi"; }

/* ---------- Login ---------- */
.login { min-height: 80vh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 2rem 1.75rem; }
.login-card h1 { margin-top: 1rem; }

p.hint { background: var(--green-soft); border-radius: 8px; padding: .65rem .85rem; font-size: .88rem; }
code { background: var(--line-soft); padding: .1rem .35rem; border-radius: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 980px) {
  .keyin { grid-template-columns: 1fr; }
  .entry { position: static; }
  .forecast-head .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .top { flex-wrap: wrap; padding: .55rem 1rem; }
  .menu-btn { display: inline-flex; font: inherit; font-weight: 600; background: var(--line-soft); border: 1px solid var(--line); border-radius: 7px; padding: .4rem .8rem; min-height: 38px; }
  .nav { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; padding: .4rem 0; }
  .nav.open { display: flex; }
  .nav > a { padding: .65rem .7rem; }
  .who { margin: .5rem 0 0; padding: .7rem .7rem 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
  .main { padding: 1rem 1rem 3rem; }
  h1 { font-size: 1.35rem; }
  .card { padding: 1rem; }
  .table-wrap { margin: 0 -1rem; padding: 0 1rem; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .filters label { flex: 1 1 140px; min-width: 0; }
  .filters p { margin-left: 0; flex-basis: 100%; }
  .strip { gap: 2px; }
  .strip .cell { height: 28px; }
  .strip .cell i { display: none; }
  .acc-grid { grid-template-columns: 1fr; }
  .page-head .btn.primary { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print {
  .top, .filters, .actions, .row-actions, .btn { display: none !important; }
  body { background: #fff; }
  .card { border: 0; padding: 0; }
}
