:root {
  --blue: #0b5fa5; --blue2: #e8f2fb; --ink: #16202b; --muted: #66737f; --bg: #f4f7fa; --card: #fff;
  --green: #12805c; --green2: #e4f5ee; --red: #c0392b; --red2: #fdecea; --line: #dfe5eb;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 17px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
[hidden] { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 14px; }
h3 { margin: 22px 4px 8px; font-size: 16px; color: var(--muted); font-weight: 600; }

.screen { max-width: 520px; margin: 0 auto; min-height: 100vh; padding: 0 14px 96px; }
#login, #setpin { text-align: center; padding-top: 48px; }
#login h1, #setpin h1 { margin: 6px 0 0; color: var(--blue); }
#setpin h1 { font-size: 26px; }
.logo { width: 72px; height: 72px; }
.pin-dots { display: flex; gap: 14px; justify-content: center; margin: 18px 0 22px; }
.pin-dots i { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--blue); }
.pin-dots i.on { background: var(--blue); }
.error { color: var(--red); min-height: 24px; }

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 360px; margin: 0 auto; }
.keypad button { background: var(--card); border: 1px solid var(--line); border-radius: 16px; height: 62px; font-size: 26px; font-weight: 600; }
.keypad button:active { background: var(--blue2); }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; background: var(--bg); padding: 12px 0 8px; }
.daybtn { width: 48px; height: 48px; border-radius: 14px; background: var(--card); border: 1px solid var(--line); font-size: 28px; line-height: 1; }
.daybtn:disabled { opacity: .3; }
.daytitle { flex: 1; text-align: center; font-weight: 700; font-size: 19px; }
.sync { background: #fff7e0; border: 1px solid #f0d68a; border-radius: 12px; padding: 8px 12px; font-size: 14px; margin-bottom: 8px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 16px; }
.coh { text-align: center; margin-bottom: 14px; }
.coh .big { font-size: 38px; font-weight: 800; color: var(--blue); margin: 2px 0 8px; }
.coh.neg .big { color: var(--red); }
.ghost { border: 2px solid var(--blue); color: var(--blue); border-radius: 14px; padding: 10px 16px; font-weight: 700; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid.two { grid-template-columns: repeat(2, 1fr); margin-top: 14px; }
.tile { border-radius: 18px; padding: 14px 6px; min-height: 92px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; font-weight: 700; font-size: 15px; border: 1px solid var(--line); background: var(--card); }
.tile .ic { font-size: 28px; }
.tile .sum { font-size: 13px; font-weight: 600; color: var(--muted); }
.tile.plus { background: var(--green2); border-color: #bfe5d4; }
.tile.minus { background: var(--red2); border-color: #f3c7c1; }
.tile:active { transform: scale(.97); }

.counters .row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.counters .row:last-child { border-bottom: 0; }
.counters .name { flex: 1; font-weight: 700; }
.counters .n { min-width: 64px; text-align: center; font-size: 26px; font-weight: 800; color: var(--blue); border-radius: 12px; padding: 4px 0; }
.counters .pm { width: 54px; height: 54px; border-radius: 16px; font-size: 30px; font-weight: 700; }
.counters .minus { background: var(--red2); color: var(--red); }
.counters .plus { background: var(--blue); color: #fff; }
.total { margin-top: 14px; }
.total .line { display: flex; justify-content: space-between; padding: 3px 0; }
.total .line.b { font-weight: 800; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; gap: 10px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; margin-bottom: 8px; }
.list .what { flex: 1; }
.list .what b { display: block; }
.list .amt { font-weight: 800; white-space: nowrap; }
.list .amt.p { color: var(--green); } .list .amt.m { color: var(--red); }
.list .del { width: 40px; height: 40px; border-radius: 12px; background: #f1f3f5; color: var(--muted); font-size: 18px; }
.list .pending { font-size: 12px; color: #a0760a; }
.list .empty { justify-content: center; color: var(--muted); }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 8; }
.tabs button { flex: 1; padding: 8px 0 10px; font-size: 24px; display: flex; flex-direction: column; align-items: center; color: var(--muted); }
.tabs span { font-size: 13px; font-weight: 700; }
.tabs button.on { color: var(--blue); }

.sheet { position: fixed; inset: 0; background: rgba(10, 20, 30, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet-card { background: var(--bg); width: 100%; max-width: 520px; border-radius: 22px 22px 0 0; padding: 14px 14px calc(16px + env(safe-area-inset-bottom)); max-height: 96vh; overflow: auto; }
.sheet-head { display: flex; align-items: center; font-weight: 800; font-size: 20px; }
.sheet-head span { flex: 1; }
.x { width: 44px; height: 44px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 0; }
.chips button { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 9px 14px; font-weight: 600; font-size: 15px; }
.chips button.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.amount { text-align: center; font-size: 40px; font-weight: 800; margin: 12px 0 2px; }
.sheet .small { text-align: center; min-height: 20px; margin-bottom: 8px; }
.check { display: flex; gap: 10px; align-items: center; justify-content: center; font-weight: 700; margin-bottom: 10px; }
.check input { width: 22px; height: 22px; }
.save { display: block; width: 100%; max-width: 360px; margin: 12px auto 0; background: var(--blue); color: #fff; border-radius: 16px; height: 60px; font-size: 21px; font-weight: 800; }
.save:disabled { opacity: .4; }

.toast { position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; z-index: 30; font-weight: 600; max-width: 90vw; text-align: center; }

/* report */
.rep-range { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 12px; }
.rep-range button, .rep-range input { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 9px 12px; font: inherit; font-size: 15px; }
.rep-range button.on { background: var(--blue); color: #fff; border-color: var(--blue); }
.kv { display: flex; justify-content: space-between; padding: 4px 0; }
.kv.b { font-weight: 800; border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; }
.card + .card { margin-top: 12px; }
.card h4 { margin: 0 0 8px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { padding: 6px 6px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
.neg { color: var(--red); } .pos { color: var(--green); }
.btn { background: var(--blue); color: #fff; border-radius: 12px; padding: 10px 14px; font-weight: 700; }
.btn.light { background: var(--card); color: var(--blue); border: 1px solid var(--line); }
.settings label { display: block; font-weight: 700; margin: 10px 0 4px; }
.settings input, .settings textarea { width: 100%; font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 12px; }
.settings textarea { min-height: 80px; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- layout pieces shared by phone + desktop ---------- */
.tabs .brand { display: none; }
.rgrid { display: grid; gap: 12px; }
.rgrid > .card + .card { margin-top: 0; }
.daytable tr.go { cursor: pointer; }
.daytable tr.go:hover td { background: var(--blue2); }
.daytable th { position: sticky; top: 0; background: var(--card); }
.daytable .grp { text-align: center; color: var(--muted); font-weight: 600; border-bottom: 0; }
.kbd-hint { display: none; }

/* ---------- desktop (Madam Lyn) ---------- */
@media (min-width: 900px) {
  html, body { font-size: 16px; }
  .screen#main { max-width: none; margin: 0; padding: 0 32px 40px 252px; }
  .tabs { top: 0; bottom: 0; right: auto; width: 220px; flex-direction: column; justify-content: flex-start; gap: 4px;
    border-top: 0; border-right: 1px solid var(--line); padding: 20px 12px; }
  .tabs .brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 20px; color: var(--blue); padding: 0 8px 18px; }
  .tabs .brand img { width: 36px; height: 36px; }
  .tabs button { flex: 0 0 auto; flex-direction: row; gap: 12px; font-size: 20px; padding: 12px 14px; border-radius: 12px; justify-content: flex-start; }
  .tabs button span { font-size: 16px; }
  .tabs button.on { background: var(--blue2); }
  .top { padding: 20px 0 14px; max-width: 1280px; }
  .daytitle { text-align: left; order: -1; }
  .daytitle #dayLabel { font-size: 24px; }
  .tab { max-width: 1280px; }
  .tab.cols { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 28px; align-items: start; }
  .tab.cols h3:first-child { margin-top: 0; }
  .grid { grid-template-columns: repeat(3, 1fr); }
  .tile { min-height: 104px; font-size: 16px; }
  .tile:hover, .pm:hover, .keypad button:hover, .daybtn:hover:not(:disabled) { filter: brightness(.97); outline: 2px solid var(--blue2); }
  .list li { padding: 12px 16px; }
  .rgrid { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
  .rgrid.wide { grid-template-columns: 1fr; }
  table { font-size: 15px; }
  th, td { padding: 8px 10px; }
  .sheet { align-items: center; }
  .sheet-card { max-width: 440px; border-radius: 22px; }
  .kbd-hint { display: block; text-align: center; color: var(--muted); font-size: 13px; margin-top: 8px; }
  .toast { bottom: 32px; }
  .settings { max-width: 720px; }
  .settings .two { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  #login, #setpin { padding-top: 10vh; }
}

/* ---------- notebook pages: look like Jowana's ruled paper ledger ---------- */
.nb { position: relative; background: #fffef8; border: 1px solid #e6e1cf; border-radius: 14px; padding: 12px 12px 14px 44px; margin-bottom: 14px;
  background-image: linear-gradient(to right, transparent 34px, #f2a7c3 34px, #f2a7c3 36px, transparent 36px),
                    repeating-linear-gradient(to bottom, transparent 0, transparent 29px, #c9dcef 29px, #c9dcef 30px);
  background-position: 0 0, 0 40px; box-shadow: 0 1px 0 #ece6d2; }
.nb-title { font-weight: 800; color: #14365c; font-size: 16px; height: 30px; line-height: 26px; margin-left: -32px; padding-left: 0; }
.nb-sub { font-weight: 800; color: #14365c; margin: 8px 0 2px; }
.nbt { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
.nbt td, .nbt th { height: 30px; padding: 0 6px; border: 0; font-size: 15px; }
.nbt.ledger td.d { color: #7d8794; width: 52px; font-size: 13px; text-align: left; }
.nbt.ledger td.n { text-align: right; font-weight: 700; width: 40%; font-size: 17px; white-space: nowrap; }
.nbt.ledger td.l { text-align: left; color: #44505c; padding-left: 12px; font-size: 14px; line-height: 1.1; }
.nbt.ledger tr.mv td.n { color: #3a4652; font-weight: 600; }
.nbt.ledger td.u { text-decoration: underline; text-underline-offset: 5px; }
.nbt.ledger tr.cnt td { color: #0b5fa5; }
.nbt.grid th { font-size: 12px; color: #5b6774; text-align: right; white-space: nowrap; }
.nbt.grid th:first-child, .nbt.grid td:first-child { text-align: left; }
.nbt.grid td { text-align: right; white-space: nowrap; font-size: 14px; border-left: 1px solid #e7e2d2; }
.nbt.grid td:first-child { border-left: 0; color: #7d8794; font-size: 13px; }
.nbt.grid td.b { font-weight: 700; }
.nbt.grid tr.tot td { font-weight: 800; border-top: 2px solid #14365c; }
.nbt tr.go { cursor: pointer; }
.nbt tr.go:hover td { background: rgba(11, 95, 165, .06); }
.nb .table-wrap { margin-left: -6px; }
.nb-cols { display: grid; gap: 4px 24px; margin-top: 6px; }
.nb .kv { padding: 0; height: 30px; align-items: center; font-variant-numeric: tabular-nums; }
.nb .kv.b { border-top: 2px solid #14365c; padding-top: 0; margin-top: 0; }
.nb .kv.box span:last-child { border: 2px solid #14365c; padding: 0 8px; border-radius: 4px; }
@media (min-width: 900px) {
  .nb-cols { grid-template-columns: 1fr 1fr; }
  #reportBox { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 0 20px; }
  #reportBox > * { grid-column: 1 / -1; }
  #reportBox > .nb:nth-child(1) { grid-column: 1; grid-row: 1 / span 2; }
  #reportBox > .nb:nth-child(2) { grid-column: 2; }
  #reportBox > .nb:nth-child(3) { grid-column: 2; }
}
.mt16 { margin-top: 16px; }
