:root {
  --bg: #f5f1ea; --card: #fff; --ink: #1f1a1d; --mute: #7a7075; --line: #ebe4db;
  --brand: #4a1f3d; --brand2: #6b2d58; --gold: #e8a93a; --gold-soft: #fbefd7;
  --ok: #1d7f53; --ok-soft: #e3f4ea; --debt: #c2410c; --debt-soft: #fdeadf; --bad: #b91c1c; --bad-soft: #fde4e4;
  --r: 16px; --shadow: 0 1px 2px rgba(40, 20, 30, .06), 0 4px 16px rgba(40, 20, 30, .06);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { min-height: 100vh; overscroll-behavior-y: contain; }
button, input, select, textarea { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }
.mute { color: var(--mute); }
.small { font-size: 13px; }
.hidden, [hidden] { display: none !important; }

/* header */
.top { position: sticky; top: 0; z-index: 5; background: var(--brand); color: #fff; padding: 12px 16px 14px; display: flex; align-items: center; gap: 12px; }
.top .t1 { font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .t2 { font-size: 13px; opacity: .75; }
.top .grow { flex: 1; min-width: 0; }
.pill { border: 0; border-radius: 999px; padding: 6px 11px; font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,.14); color: #fff; }
.pill i { width: 8px; height: 8px; border-radius: 50%; background: #5ee09a; display: inline-block; }
.pill.wait i { background: var(--gold); }
.pill.off i { background: #ff7b7b; }
.pill.spin i { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

.page { padding: 14px 14px calc(96px + var(--safe-b)); max-width: 720px; margin: 0 auto; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px; }
.card h3 { margin: 0 0 10px; font-size: 15px; color: var(--mute); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }

/* date switcher */
.daybar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.daybar button.arrow { width: 44px; height: 44px; border-radius: 12px; border: 0; background: var(--card); box-shadow: var(--shadow); font-size: 20px; }
.daybar label { flex: 1; position: relative; height: 44px; border-radius: 12px; background: var(--card); box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; font-weight: 700; gap: 8px; }
.daybar label input { position: absolute; inset: 0; opacity: 0; width: 100%; }
.tag { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--gold-soft); color: #8a5a00; }

/* summary */
.sum { background: linear-gradient(135deg, var(--brand), var(--brand2)); color: #fff; }
.sum h3 { color: rgba(255,255,255,.7); }
.sum .big { font-size: 34px; font-weight: 800; letter-spacing: -.02em; }
.sum .big small { font-size: 18px; font-weight: 600; opacity: .8; }
.sum .row { display: flex; gap: 10px; margin-top: 12px; }
.sum .row > div { flex: 1; background: rgba(255,255,255,.1); border-radius: 12px; padding: 10px; }
.sum .row b { display: block; font-size: 17px; }
.sum .row span { font-size: 12px; opacity: .75; }

.mrow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.mrow:last-child { border-bottom: 0; }
.mrow .name { font-weight: 700; font-size: 17px; min-width: 64px; }
.mrow .mid { flex: 1; font-size: 13px; color: var(--mute); }
.mrow .amt { text-align: right; font-weight: 700; }
.mrow .amt small { display: block; font-weight: 500; color: var(--mute); font-size: 12px; }

/* entry list */
.entry { display: flex; gap: 12px; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.entry:last-child { border-bottom: 0; }
.entry .seq { width: 44px; height: 44px; border-radius: 12px; background: var(--gold-soft); color: #7a4e00; font-weight: 800; display: flex; align-items: center; justify-content: center; flex: none; font-size: 15px; }
.entry .body { flex: 1; min-width: 0; }
.entry .l1 { font-weight: 700; display: flex; gap: 6px; align-items: center; }
.entry .l2 { font-size: 13px; color: var(--mute); }
.entry .amt { text-align: right; font-weight: 800; white-space: nowrap; }
.entry .amt small { display: block; font-size: 12px; font-weight: 600; }
.entry.void { opacity: .45; }
.entry.void .amt { text-decoration: line-through; }
.b-cash { color: var(--ok); }
.b-debt { color: var(--debt); }
.chip-s { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 6px; background: var(--line); color: var(--mute); }
.chip-s.debt { background: var(--debt-soft); color: var(--debt); }
.chip-s.ok { background: var(--ok-soft); color: var(--ok); }
.chip-s.bad { background: var(--bad-soft); color: var(--bad); }

.empty { text-align: center; color: var(--mute); padding: 28px 10px; }
.empty .e1 { font-size: 40px; }

/* FAB */
.fab { position: fixed; right: 16px; bottom: calc(80px + var(--safe-b)); z-index: 6; height: 60px; padding: 0 24px; border: 0; border-radius: 30px; background: var(--gold); color: #3b2300; font-size: 18px; font-weight: 800; box-shadow: 0 6px 20px rgba(160, 100, 0, .35); display: flex; align-items: center; gap: 8px; }
.fab:active { transform: scale(.97); }

/* bottom nav */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; background: #fff; border-top: 1px solid var(--line); display: flex; padding-bottom: var(--safe-b); }
.nav button { flex: 1; border: 0; background: none; padding: 9px 0 10px; font-size: 12px; color: var(--mute); display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; }
.nav button .ic { font-size: 22px; filter: grayscale(1); opacity: .7; }
.nav button.on { color: var(--brand); font-weight: 700; }
.nav button.on .ic { filter: none; opacity: 1; }
.nav .dot { position: absolute; top: 6px; left: 55%; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--debt); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; }

/* forms */
.btn { border: 0; border-radius: 14px; padding: 14px 18px; font-weight: 700; font-size: 16px; background: var(--line); color: var(--ink); display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.gold { background: var(--gold); color: #3b2300; }
.btn.ok { background: var(--ok); color: #fff; }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.btn.sm { padding: 9px 12px; font-size: 14px; border-radius: 11px; }
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 13px; font-weight: 700; color: var(--mute); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .04em; }
.inp { width: 100%; border: 2px solid var(--line); border-radius: 14px; padding: 13px 14px; font-size: 18px; background: #fff; outline: none; }
.inp:focus { border-color: var(--brand2); }
.inp.huge { font-size: 30px; font-weight: 800; padding: 10px 14px; text-align: right; }
.inp-wrap { position: relative; }
.inp-wrap .unit { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--mute); font-weight: 700; pointer-events: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 2px solid var(--line); background: #fff; border-radius: 12px; padding: 10px 14px; font-weight: 800; font-size: 17px; min-width: 64px; }
.chip.on { border-color: var(--brand); background: var(--brand); color: #fff; }
.chip.add { border-style: dashed; color: var(--mute); font-weight: 600; }
.seg { display: flex; background: var(--line); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 11px; padding: 12px; font-weight: 800; font-size: 16px; color: var(--mute); }
.seg button.on.cash { background: var(--ok); color: #fff; }
.seg button.on.debt { background: var(--debt); color: #fff; }
.seg button.on.plain { background: #fff; color: var(--ink); }
.calc { background: var(--gold-soft); border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.calc .f { font-size: 14px; color: #7a4e00; }
.calc .v { font-size: 26px; font-weight: 800; color: #3b2300; white-space: nowrap; }
.saved { background: var(--ok-soft); color: var(--ok); border-radius: 12px; padding: 10px 12px; font-weight: 700; margin-bottom: 12px; font-size: 14px; }
.warn { background: var(--debt-soft); color: var(--debt); border-radius: 12px; padding: 10px 12px; font-weight: 600; margin-bottom: 12px; font-size: 14px; }
.err { background: var(--bad-soft); color: var(--bad); border-radius: 12px; padding: 10px 12px; font-weight: 600; margin-bottom: 12px; font-size: 14px; }
.list-pick { max-height: 220px; overflow: auto; border: 2px solid var(--line); border-radius: 14px; margin-top: 8px; }
.list-pick button { display: flex; width: 100%; justify-content: space-between; border: 0; border-bottom: 1px solid var(--line); background: #fff; padding: 12px 14px; text-align: left; }
.list-pick button:last-child { border-bottom: 0; }
.list-pick button.on { background: var(--debt-soft); font-weight: 700; }

/* farmer list */
.frow { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.frow:last-child { border-bottom: 0; }
.ava { width: 42px; height: 42px; border-radius: 50%; background: var(--debt-soft); color: var(--debt); display: flex; align-items: center; justify-content: center; font-weight: 800; flex: none; }
.frow .body { flex: 1; min-width: 0; }
.frow .n { font-weight: 700; }
.frow .amt { font-weight: 800; text-align: right; }
.frow .amt small { display: block; font-size: 12px; font-weight: 600; color: var(--gold); }

.hrow { padding: 11px 0; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.hrow:last-child { border-bottom: 0; }
.hrow .body { flex: 1; font-size: 14px; }
.hrow .amt { font-weight: 800; white-space: nowrap; }

/* sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; background: rgba(20, 10, 16, .45); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 720px; max-height: 94vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 0 16px calc(20px + var(--safe-b)); }
.sheet.anim { animation: up .18s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
.sheet .sh { position: sticky; top: 0; background: var(--bg); display: flex; align-items: center; gap: 10px; padding: 16px 0 12px; z-index: 2; }
.sheet .sh h2 { margin: 0; font-size: 20px; flex: 1; }
.sheet .x { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--line); font-size: 20px; }
.qrbox { background: #fff; border-radius: var(--r); padding: 16px; text-align: center; }
.qrbox svg { width: min(78vw, 300px); height: auto; }
.link { word-break: break-all; font-size: 13px; color: var(--mute); background: #fff; padding: 10px; border-radius: 10px; margin: 10px 0; user-select: all; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns .btn { flex: 1; }

/* login */
.login { min-height: 100vh; display: flex; flex-direction: column; justify-content: center; padding: 24px; max-width: 420px; margin: 0 auto; }
.login .logo { width: 84px; height: 84px; margin: 0 auto 14px; }
.login h1 { text-align: center; margin: 0 0 4px; color: var(--brand); }
.login p { text-align: center; color: var(--mute); margin: 0 0 26px; }
.login .inp { text-align: center; font-size: 26px; letter-spacing: .15em; font-weight: 800; text-transform: uppercase; }

.toast { position: fixed; left: 50%; bottom: calc(150px + var(--safe-b)); transform: translateX(-50%); z-index: 30; background: #1f1a1d; color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 600; max-width: 90vw; box-shadow: 0 8px 24px rgba(0,0,0,.25); }
.search { margin-bottom: 12px; }
.kv { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.kv:last-child { border-bottom: 0; }
