:root {
  --paper: #FBF8F1; --paper-2: #F3ECDD; --white: #FFFFFF;
  --ink: #231E15; --ink-2: #5C513F; --gold: #A47A2C; --gold-ink: #7A5A1E; --gold-soft: #D9BE80; --line: #E4D6B6;
  --green: #1C3226; --on-green: #F4EEE0; --on-green-2: #C8C1AD; --good: #2F6A42; --bad: #9B2C1F;
  --serif: 'Bodoni Moda', Didot, Georgia, serif; --caps: Cinzel, Georgia, serif; --sans: Jost, 'Avenir Next', 'Segoe UI', system-ui, sans-serif;
  --r-lg: 20px; --r-md: 16px; --r-sm: 12px;
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold-ink); }
#app { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; max-width: 560px; margin: 0 auto; }

/* boot */
.boot { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; color: var(--ink-2); }
.crest-lg { width: 72px; height: 72px; background: url('/icons/crest.svg') center/contain no-repeat; }

/* layout */
.screen { flex: 1; display: flex; flex-direction: column; padding: calc(16px + var(--safe-t)) 20px calc(96px + var(--safe-b)); gap: 14px; }
.screen.plain { padding-bottom: calc(28px + var(--safe-b)); }
.topbar { display: flex; align-items: center; justify-content: space-between; min-height: 48px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand i { width: 36px; height: 36px; background: url('/icons/crest.svg') center/contain no-repeat; }
.brand span { font-family: var(--caps); font-weight: 600; letter-spacing: .2em; font-size: 13px; line-height: 1.1; }
.brand small { display: block; font-size: 9px; letter-spacing: .42em; color: var(--ink-2); font-weight: 500; }
.back { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; padding: 0 4px; color: var(--gold-ink); text-decoration: none; background: none; border: 0; font-size: 15px; cursor: pointer; }
.back::before { content: ''; width: 9px; height: 9px; border-left: 1.8px solid currentColor; border-bottom: 1.8px solid currentColor; transform: rotate(45deg); margin-right: 4px; }
.avatar { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--gold-soft); background: var(--paper-2); color: var(--gold-ink); font-weight: 600; letter-spacing: .04em; cursor: pointer; }
h1 { margin: 2px 0 0; font-family: var(--serif); font-style: italic; font-weight: 500; font-size: 31px; line-height: 1.15; }
h2 { margin: 6px 0 2px; font-family: var(--caps); font-weight: 600; font-size: 12px; letter-spacing: .18em; color: var(--gold-ink); text-transform: uppercase; }
p { margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.spacer { flex: 1; }

/* cards */
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.card.soft { background: var(--paper-2); }
.card.dark { background: var(--green); color: var(--on-green); border-color: var(--green); }
.card.dark .muted { color: var(--on-green-2); }
.card.alert { border-color: var(--gold); background: #FFFBF2; }
.eyebrow { font-size: 11px; font-weight: 500; letter-spacing: .18em; text-transform: uppercase; color: var(--ink-2); }
.card.dark .eyebrow { color: var(--on-green-2); }
.big { font-family: var(--serif); font-weight: 500; font-size: 52px; line-height: 1; }
.mid { font-family: var(--serif); font-weight: 500; font-size: 30px; line-height: 1.05; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: #7CC596; box-shadow: 0 0 0 3px rgba(124,197,150,.22); }
.dot.off { background: #E2B04A; box-shadow: 0 0 0 3px rgba(226,176,74,.22); }

/* buttons */
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 20px; border-radius: 999px; border: 0; background: var(--ink); color: var(--paper); font-size: 16px; font-weight: 500; text-decoration: none; cursor: pointer; width: 100%; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.light { background: var(--paper-2); color: var(--ink); }
.btn.outline { background: transparent; border: 1px solid var(--gold-soft); color: var(--ink); }
.btn.danger { background: transparent; border: 1px solid #E5C2BC; color: var(--bad); }
.btn.cream { background: var(--on-green); color: var(--green); font-weight: 600; }
.btn.small { min-height: 40px; font-size: 14px; padding: 0 14px; width: auto; }
.link { background: none; border: 0; padding: 8px 0; color: var(--gold-ink); font-size: 15px; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; text-align: left; }
.btn:focus-visible, .link:focus-visible, .step button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .chip:focus-visible, .tab:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* steppers */
.stepper { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.step { display: flex; align-items: center; gap: 10px; }
.step button { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--gold-soft); background: var(--paper); font-size: 22px; line-height: 1; cursor: pointer; }
.step button:disabled { opacity: .35; }
.step output { min-width: 40px; text-align: center; font-family: var(--serif); font-size: 34px; line-height: 1; }

/* forms */
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 500; }
input.text, select.text, textarea.text { min-height: 52px; padding: 0 14px; border-radius: 14px; border: 1px solid var(--gold-soft); background: var(--white); font-size: 18px; width: 100%; }
textarea.text { padding: 12px 14px; min-height: 110px; font-size: 16px; resize: vertical; }
select.text { font-size: 16px; appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--gold-ink) 50%), linear-gradient(135deg, var(--gold-ink) 50%, transparent 50%); background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; }
input.code { letter-spacing: .5em; text-align: center; font-family: var(--serif); font-size: 32px; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 4px; padding: 4px; border-radius: 999px; background: var(--paper-2); }
.seg button { min-height: 40px; border-radius: 999px; border: 0; background: transparent; color: var(--ink-2); font-size: 14px; font-weight: 500; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--paper); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 16px; border-radius: 999px; border: 1px solid var(--gold-soft); background: var(--paper); font-size: 15px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--green); color: var(--on-green); border-color: var(--green); }
.toggle { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 52px; }
.switch { width: 52px; height: 32px; border-radius: 999px; border: 0; background: var(--line); position: relative; cursor: pointer; flex: none; }
.switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: var(--white); box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: left .15s; }
.switch[aria-checked="true"] { background: var(--green); }
.switch[aria-checked="true"]::after { left: 23px; }

/* lists */
.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 60px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.list li .t { font-size: 15px; font-weight: 500; }
.list li .s { font-size: 13px; color: var(--ink-2); }
.list li button.rowbtn { all: unset; display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; cursor: pointer; min-height: 52px; }
.amt { font-weight: 500; white-space: nowrap; }
.amt.credit { color: var(--good); }
.sum { display: flex; justify-content: space-between; font-size: 15px; }
.sum.total { border-top: 1px solid var(--gold-soft); padding-top: 10px; margin-top: 2px; align-items: baseline; }
.sum.total b { font-family: var(--serif); font-size: 26px; font-weight: 500; }

/* bottom nav */
nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; background: rgba(251,248,241,.96); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); border-top: 1px solid var(--line); padding: 6px 8px calc(6px + var(--safe-b)); display: flex; justify-content: center; z-index: 10; }
nav.tabs .in { display: flex; width: 100%; max-width: 560px; }
.tab { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 52px; justify-content: center; border: 0; background: none; color: var(--ink-2); font-size: 12px; font-weight: 500; cursor: pointer; text-decoration: none; }
.tab svg { width: 24px; height: 24px; }
.tab[aria-current="page"] { color: var(--gold-ink); }

/* admin sub-tabs */
.subtabs { display: flex; flex-wrap: wrap; gap: 6px; }
.subtabs::-webkit-scrollbar { display: none; }
.subtabs button { flex: none; min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--white); color: var(--ink-2); font-size: 14px; cursor: pointer; }
.subtabs button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.badge { display: inline-flex; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--gold); color: var(--white); font-size: 12px; align-items: center; justify-content: center; margin-left: 6px; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stats div { background: var(--white); border: 1px solid var(--line); border-radius: var(--r-md); padding: 10px 12px; }
.stats b { display: block; font-family: var(--serif); font-size: 28px; font-weight: 500; line-height: 1.1; }
.stats span { font-size: 12px; color: var(--ink-2); }

/* sheet (modal) */
.sheet-bg { position: fixed; inset: 0; background: rgba(35,30,21,.35); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--paper); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 22px 22px 0 0; padding: 18px 20px calc(24px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; }
.sheet .grab { width: 40px; height: 4px; border-radius: 4px; background: var(--line); margin: 0 auto 4px; }

/* toast */
#toast { position: fixed; left: 50%; transform: translateX(-50%) translateY(20px); bottom: calc(84px + var(--safe-b)); max-width: min(92vw, 520px); background: var(--ink); color: var(--paper); padding: 12px 18px; border-radius: 14px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 40; white-space: pre-line; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--bad); }

.chart { width: 100%; height: auto; }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--ink-2); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 6px; vertical-align: -1px; }
.spin { width: 18px; height: 18px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }
@media (min-width: 600px) { .screen { padding-left: 28px; padding-right: 28px; } }
