:root {
  --navy: #0b2447; --navy-2: #19376d; --blue: #2563eb; --teal: #0f9d82; --amber: #b45309; --red: #b42318; --green: #067647;
  --bg: #f3f5f9; --card: #ffffff; --ink: #101828; --muted: #5b667a; --line: #e1e6ef; --chip: #eaf0fb;
  --radius: 14px; --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0a1220; --card: #111c30; --ink: #eef2fa; --muted: #9aa8c2; --line: #223250; --chip: #19284a; --blue: #7aa2ff; --teal: #3fc1a5; --amber: #f5a524; --red: #ff7a70; --green: #4ade80; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; -webkit-text-size-adjust: 100%; }
body { padding-bottom: calc(76px + var(--safe-b)); }
.boot { padding: 40px; text-align: center; color: var(--muted); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.top { background: var(--navy); color: #fff; padding: calc(12px + var(--safe-t)) 16px 14px; position: sticky; top: 0; z-index: 20; }
.top .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 34px; height: 34px; border-radius: 9px; background: #fff; color: var(--navy); display: grid; place-items: center; font-weight: 800; letter-spacing: -1px; flex: none; }
.brand b { display: block; font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { opacity: .75; font-size: .72rem; display: block; }
.tier { background: rgba(255,255,255,.14); border: 1px solid rgba(255,255,255,.3); color: #fff; border-radius: 999px; padding: 6px 12px; font-size: .78rem; font-weight: 700; }
.banner { padding: 10px 16px; font-size: .85rem; border-bottom: 1px solid var(--line); }
.banner.demo { background: #fff4d6; color: #5c3b00; font-weight: 600; }
.banner.info { background: var(--chip); color: var(--ink); }
.banner.warn { background: #fde8e6; color: #7a1d14; }
@media (prefers-color-scheme: dark) { .banner.demo { background: #4a3500; color: #ffe2a0; } .banner.warn { background: #4a1612; color: #ffd0cb; } }
main { padding: 14px 16px 24px; max-width: 760px; margin: 0 auto; }
.nav { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); padding-bottom: var(--safe-b); z-index: 30; }
.nav button { background: none; border: 0; padding: 9px 2px 8px; min-height: 58px; color: var(--muted); font-size: .72rem; display: grid; gap: 2px; justify-items: center; }
.nav button svg { width: 24px; height: 24px; }
.nav button[aria-current="page"] { color: var(--navy-2); font-weight: 700; }
@media (prefers-color-scheme: dark) { .nav button[aria-current="page"] { color: var(--blue); } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h3 + p, .card h2 + p { margin-top: 4px; }
.muted { color: var(--muted); } .small { font-size: .82rem; } .tiny { font-size: .74rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-width: 0; }
.stat .label { color: var(--muted); font-size: .76rem; }
.stat .num { font-size: 1.2rem; font-weight: 750; margin-top: 2px; overflow-wrap: anywhere; }
.stat .hint { color: var(--muted); font-size: .72rem; margin-top: 2px; }
.pos { color: var(--green); } .neg { color: var(--red); } .warnc { color: var(--amber); }
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 14px; min-height: 40px; font-size: .88rem; }
.chip[aria-pressed="true"], .chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn { border: 0; background: var(--navy); color: #fff; border-radius: 12px; padding: 12px 16px; min-height: 46px; font-weight: 650; }
.btn.secondary { background: var(--chip); color: var(--ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); color: var(--ink); }
.btn.danger { background: var(--red); color: #fff; }
.btn.small { min-height: 38px; padding: 8px 12px; font-size: .88rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.actions .btn { text-align: left; display: flex; align-items: center; gap: 8px; }
.list { display: grid; gap: 0; }
.item { display: flex; justify-content: space-between; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--line); width: 100%; background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; }
.item:last-child { border-bottom: 0; }
.item .l { min-width: 0; } .item .r { text-align: right; flex: none; }
.item b { display: block; overflow-wrap: anywhere; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .72rem; font-weight: 700; background: var(--chip); }
.badge.paid { background: #dcfae6; color: #067647; } .badge.partial { background: #fef0c7; color: #93370d; }
.badge.unpaid { background: #e0eaff; color: #1d3a8a; } .badge.overdue { background: #fee4e2; color: #b42318; }
.badge.mock { background: #fff4d6; color: #5c3b00; } .badge.lock { background: #ede9fe; color: #5b21b6; }
label { display: block; font-size: .82rem; font-weight: 650; margin: 12px 0 4px; }
input, select, textarea { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 16px; min-height: 46px; }
textarea { min-height: 96px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 10px; align-items: center; margin: 12px 0; font-weight: 500; }
.check input { width: 22px; height: 22px; min-height: 0; flex: none; }
.line-row { display: grid; grid-template-columns: 1.6fr .7fr 1fr auto; gap: 6px; align-items: end; margin-bottom: 6px; }
.line-row .x { min-height: 46px; padding: 0 12px; }
.seg { display: grid; grid-auto-flow: column; background: var(--chip); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.seg button { border: 0; background: none; padding: 10px; border-radius: 9px; font-weight: 600; min-height: 42px; }
.seg button[aria-pressed="true"] { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.sheet-bg { position: fixed; inset: 0; background: rgba(8,15,30,.55); z-index: 40; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 760px; max-height: 92vh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 16px 16px calc(20px + var(--safe-b)); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; gap: 8px; }
.sheet-head button { border: 0; background: var(--chip); border-radius: 999px; width: 40px; height: 40px; font-size: 1.1rem; }
.toast { position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: #111827; color: #fff; padding: 12px 16px; border-radius: 12px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: 92vw; font-size: .9rem; }
.toast.show { opacity: 1; transform: translateX(-50%); } .toast.error { background: var(--red); }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
th:first-child, td:first-child { text-align: left; } th { color: var(--muted); font-weight: 650; font-size: .74rem; }
.scroll-x { overflow-x: auto; }
.attn { border-left: 4px solid var(--amber); padding: 8px 10px; background: var(--card); border-radius: 8px; margin-bottom: 8px; display: flex; justify-content: space-between; gap: 8px; align-items: center; width: 100%; text-align: left; border-top: 1px solid var(--line); border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.attn.red { border-left-color: var(--red); }
.notice { background: var(--chip); border-radius: 10px; padding: 10px 12px; font-size: .84rem; margin: 10px 0; }
.notice.warn { background: #fff4d6; color: #5c3b00; }
@media (prefers-color-scheme: dark) { .notice.warn { background: #4a3500; color: #ffe2a0; } }
.msgbox { background: var(--card); border: 1px dashed var(--line); border-radius: 10px; padding: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.kv { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; font-size: .92rem; } .kv b { text-align: right; }
.status-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; margin-right: 6px; background: #98a2b3; } .dot.ok { background: var(--green); } .dot.warn { background: var(--amber); }
svg.chart { width: 100%; height: auto; display: block; }
details summary { cursor: pointer; padding: 8px 0; font-weight: 600; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
