:root {
  color-scheme: light dark;
  --ink: #1a1712; --ink-2: #2a251c; --on-ink: #f6efe0; --on-ink-muted: #b5aa94; --gold: #e0b64d; --gold-deep: #c4952b;
  --bg: #f4efe4; --card: #fffdf8; --soft: #f2ecdf; --text: #211c14; --muted: #6e6555;
  --line: #e5ddcc; --accent: #8c6508; --accent-bg: #f9edcb; --danger: #b3261e;
  --bar: #c99a2e; --bar-track: #efe8d8;
  --serif: "Songti SC", "STSong", "Noto Serif CJK SC", "Source Han Serif SC", serif;
  --num: "DIN Alternate", "Avenir Next", "Roboto", -apple-system, "PingFang SC", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12100c; --card: #1f1b15; --soft: #2a251c; --text: #f3ecdf; --muted: #a89e8b;
    --line: #362f24; --accent: #e7bf5e; --accent-bg: #3a2e12; --danger: #f2a198;
    --bar-track: #2f2920;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
}
h1 { font-family: var(--serif); font-size: 24px; font-weight: 700; margin: 0; letter-spacing: .04em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
[hidden] { display: none !important; }

.shell { max-width: 1040px; margin: 0 auto; padding: 0 14px calc(90px + env(safe-area-inset-bottom)); }

/* Dark ledger band at the top of every page; the first card overlaps its lower edge. */
.head {
  margin: 0 -14px; padding: calc(14px + env(safe-area-inset-top)) 18px 40px;
  background: var(--ink); color: var(--on-ink);
}
.head-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 36px; }
.head .muted { color: var(--on-ink-muted); }
.head .btn { background: transparent; border-color: #5a4f3c; color: var(--on-ink); }
.head .btn:hover { background: var(--ink-2); }
.head + * { position: relative; margin-top: -26px; }
.who { display: inline-flex; align-items: center; gap: 7px; color: var(--on-ink-muted); font-size: 13px; }
.who i { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; background: var(--ink-2); color: var(--gold); font-style: normal; font-size: 12px; }

.hero-stats { display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 5fr) minmax(0, 2fr); gap: 10px; margin-top: 10px; }
.hero-stats small { display: block; font-size: 12px; color: var(--on-ink-muted); }
.hero-stats b { font: 600 22px/1.25 var(--num); color: var(--gold); overflow-wrap: anywhere; }
.hero-stats div + div { border-left: 1px solid #3a3326; padding-left: 10px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(60, 44, 10, .05), 0 8px 24px rgba(60, 44, 10, .05); }
.two { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 14px; align-items: start; }
.muted { color: var(--muted); font-size: 13px; }
.strong { font-weight: 600; }

.field { margin-bottom: 12px; }
.label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 5px; }
.input {
  width: 100%; height: 46px; padding: 0 12px; background: var(--soft);
  border: 1px solid transparent; border-radius: 11px; font-size: 17px; outline: none; transition: border-color .12s, background .12s;
}
.input:focus { background: var(--card); border-color: var(--gold-deep); box-shadow: 0 0 0 2px rgba(196, 149, 43, .22); }
.input::placeholder { color: var(--muted); opacity: .65; }
.input.big { height: 54px; font: 600 24px var(--num); }
textarea.input { height: 72px; padding: 10px 12px; resize: vertical; }
select.input { font-size: 15px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; }
.date-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.date-row .label { margin: 0; flex: none; }
.date-row .input { width: auto; min-width: 150px; height: 40px; font-size: 15px; }

/* One scrolling row of recent names keeps the save button on screen. */
.chips { display: flex; gap: 7px; margin: 8px -14px 0; padding: 0 14px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips:empty { display: none; }
.chip {
  flex: none; min-height: 38px; padding: 6px 14px; border-radius: 19px; font-size: 15px;
  background: var(--card); border: 1px solid var(--line); white-space: nowrap;
}
.chip.on { background: var(--ink); color: var(--gold); border-color: var(--ink); font-weight: 600; }
.results { margin-top: 6px; border: 1px solid var(--line); border-radius: 11px; overflow: hidden; }
.results button {
  display: block; width: 100%; min-height: 44px; padding: 8px 12px; text-align: left;
  background: var(--card); border: 0; border-top: 1px solid var(--line);
}
.results button:first-child { border-top: 0; }
.results button:hover, .results button:focus-visible { background: var(--soft); outline: none; }
.results .add { color: var(--accent); font-weight: 600; }

.seg { display: flex; background: var(--soft); border-radius: 11px; padding: 3px; gap: 3px; overflow-x: auto; }
.seg button { flex: 1; min-height: 36px; padding: 4px 10px; background: transparent; border: 0; border-radius: 8px; font-size: 14px; white-space: nowrap; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(60, 44, 10, .14); }
.total { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 2px 10px; margin-bottom: 12px; border-bottom: 1px dashed var(--line); font-size: 14px; color: var(--muted); }
.total b { font: 600 26px var(--num); color: var(--accent); }

.btn { min-height: 44px; padding: 8px 16px; background: var(--card); border: 1px solid var(--line); border-radius: 11px; font-size: 15px; }
.btn:hover { background: var(--soft); }
.btn.primary { width: 100%; min-height: 52px; margin-top: 6px; background: var(--ink); border-color: var(--ink); color: var(--gold); font-size: 17px; font-weight: 600; letter-spacing: .06em; }
.btn.primary:hover { background: var(--ink-2); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.btn[disabled] { opacity: .6; cursor: default; }
.err { color: var(--danger); font-size: 14px; min-height: 21px; margin-bottom: 8px; }
.err:empty { min-height: 0; margin: 0; }

.metrics { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; margin-bottom: 12px; }
.metrics.three { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr) minmax(0, 3fr); }
.metric { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; min-width: 0; }
.metric small { display: block; font-size: 12px; color: var(--muted); }
.metric b { font: 600 20px/1.3 var(--num); overflow-wrap: anywhere; }
.metrics.three .metric { padding: 10px; }
.metrics.three .metric b { font-size: 17px; }
.metric.lead b { color: var(--accent); }

.row {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 0; text-align: left;
  background: none; border: 0; border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.row.void { opacity: .55; text-decoration: line-through; }
.row .r { text-align: right; white-space: nowrap; flex: none; }
.row .l { min-width: 0; flex: 1; overflow-wrap: anywhere; }
.row .amount { font: 600 17px var(--num); }
.mark { flex: none; width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-bg); color: var(--accent); font-family: var(--serif); font-weight: 700; }

.bar-row { width: 100%; display: block; padding: 9px 0; background: none; border: 0; border-top: 1px solid var(--line); text-align: left; }
.bar-row:first-child { border-top: 0; }
.bar-top { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; }
.bar-top span:first-child { min-width: 0; overflow-wrap: anywhere; }
.bar-top span:last-child { white-space: nowrap; font-family: var(--num); }
.bar { height: 6px; margin-top: 6px; background: var(--bar-track); border-radius: 3px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--bar); border-radius: 3px; }

.filters { display: grid; gap: 10px; }
.filters .field { margin-bottom: 0; }
.empty { padding: 26px 8px; text-align: center; color: var(--muted); font-size: 14px; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 12px; background: var(--ink); color: var(--gold); border: 0; border-radius: 16px; font-size: 14px; min-height: 32px; flex: none; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
details summary { cursor: pointer; color: var(--accent); font-size: 14px; padding: 6px 0; min-height: 34px; }
details[open] summary { margin-bottom: 8px; }

.login-page { min-height: 100vh; min-height: 100dvh; background: var(--ink); color: var(--on-ink); display: flex; flex-direction: column; }
.login-art { flex: 1 1 38vh; min-height: 220px; position: relative; background: url(/login.jpg) center 45% / cover no-repeat; }
.login-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(to bottom, rgba(26, 23, 18, .15), rgba(26, 23, 18, .15) 50%, #1a1712); }
.login-form { padding: 0 22px calc(30px + env(safe-area-inset-bottom)); width: 100%; max-width: 420px; margin: -44px auto 0; position: relative; }
.login-form h1 { font-size: 32px; color: var(--gold); }
.login-form > p { margin: 2px 0 22px; color: var(--on-ink-muted); font-size: 14px; }
.login-form .label { color: var(--on-ink-muted); }
.login-form .input { background: var(--ink-2); color: var(--on-ink); border-color: #3a3326; }
.login-form .input:focus { background: var(--ink-2); }
.login-form .btn.primary { background: var(--gold); border-color: var(--gold); color: var(--ink); }
.login-form .btn.primary:hover { background: var(--gold-deep); }
.login-form .err { color: #f2a198; }

nav {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; z-index: 5;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
nav a { flex: 1; max-width: 200px; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 4px 6px; min-height: 56px; color: var(--muted); text-decoration: none; font-size: 12px; }
nav svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
nav a.on { color: var(--accent); font-weight: 600; }

#toast {
  position: fixed; left: 50%; bottom: calc(68px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 9;
  display: none; align-items: center; gap: 12px; width: max-content; max-width: calc(100vw - 24px);
  padding: 10px 14px; background: var(--ink); color: var(--on-ink); border: 1px solid #3a3326; border-radius: 12px; font-size: 14px;
}
#toast.show { display: flex; }
#toast button { background: none; border: 0; color: var(--gold); font-weight: 600; padding: 4px; white-space: nowrap; }

@media (min-width: 820px) {
  .shell { padding: 56px 20px 30px; }
  .head { margin: 0 -20px; padding: 26px 24px 46px; border-radius: 0 0 20px 20px; }
  .two { grid-template-columns: minmax(0, 5fr) minmax(0, 4fr); }
  .metrics.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .filters.wide { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero-stats { max-width: 620px; }
  nav { top: 0; bottom: auto; height: 56px; background: var(--ink); border: 0; }
  nav a { flex: none; width: 110px; flex-direction: row; justify-content: center; gap: 6px; padding: 0; font-size: 14px; color: var(--on-ink-muted); align-items: center; }
  nav svg { width: 18px; height: 18px; }
  nav a.on { color: var(--gold); box-shadow: inset 0 -2px 0 var(--gold); }
  #toast { bottom: 24px; }
  .login-page { flex-direction: row; }
  .login-art { flex: 1 1 55%; background-position: center; }
  .login-art::after { background: linear-gradient(to right, rgba(26, 23, 18, 0) 60%, #1a1712); }
  .login-form { flex: 0 0 440px; margin: auto; padding: 30px 40px; max-width: 440px; }
}
@media (prefers-color-scheme: dark) {
  .btn.primary { background: var(--gold); border-color: var(--gold); color: var(--ink); }
  .btn.primary:hover { background: var(--gold-deep); }
  .chip.on, .tag { background: var(--gold); border-color: var(--gold); color: var(--ink); }
  .head { border-bottom: 1px solid var(--line); }
}
.offer { display: grid; gap: 8px; padding: 12px 0; border-top: 1px solid var(--line); justify-items: stretch; }
.offer:first-child { border-top: 0; padding-top: 0; }
.offer .btn { justify-self: start; }
.level { display: inline-block; padding: 1px 8px; border-radius: 8px; background: var(--accent-bg); color: var(--accent); font-size: 12px; font-weight: 600; }
a.row:first-child { border-top: 0; }
.chips.wrap { flex-wrap: wrap; margin: 0; padding: 0; overflow: visible; }
.chips.wrap + .input { margin-top: 8px; }
.chip.tool { background: transparent; border-style: dashed; color: var(--accent); }
.chips.wrap { gap: 6px; }
.chips.wrap .chip { min-height: 36px; padding: 5px 12px; font-size: 14px; }
/* Framed choosers: supplier, payer, and fees read as the main things to fill in. */
.pick { background: var(--card); border: 1.5px solid var(--gold-deep); border-radius: 14px; padding: 12px; margin-bottom: 12px; }
.pick.compact { padding: 10px; margin-bottom: 0; border-width: 1px; }
.pick-title { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 16px; font-weight: 700; }
.pick-title em { font-style: normal; font-size: 14px; font-weight: 600; color: var(--accent); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick .chips.grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 10px 0 8px; padding: 0; overflow: visible; }
.pick .chip { min-height: 46px; padding: 4px; border-radius: 11px; font-size: 15px; background: var(--soft); border: 1px solid transparent; overflow: hidden; text-overflow: ellipsis; }
.pick .chip.on { background: var(--ink); color: var(--gold); border-color: var(--ink); }
.pick .chip.tool { background: transparent; border: 1px dashed var(--gold-deep); color: var(--accent); font-weight: 600; }
.pick.compact .chip { min-height: 40px; font-size: 14px; }
.pick .input { font-size: 15px; }
.money-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px; margin-top: 10px; }
.money-field span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 5px; }
.money-field .input.big { height: 52px; font-size: 22px; }
.savebar {
  position: sticky; bottom: calc(57px + env(safe-area-inset-bottom)); z-index: 3; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); align-items: center; gap: 10px;
  margin: 8px -14px -14px; padding: 10px 14px; background: var(--card); border-top: 1px solid var(--line); border-radius: 0 0 16px 16px;
}
.savebar .btn.primary { margin: 0; font-size: 16px; letter-spacing: 0; }
.bar-total small { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-total b { font: 600 24px/1.2 var(--num); color: var(--accent); overflow-wrap: anywhere; }
.perms { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.perm { display: flex; align-items: center; gap: 12px; padding: 11px 12px; min-height: 56px; cursor: pointer; border-top: 1px solid var(--line); }
.perm:first-child { border-top: 0; }
.perm input { flex: none; width: 22px; height: 22px; accent-color: var(--gold-deep); }
.perm b { display: block; font-size: 15px; font-weight: 600; }
.perm small { display: block; font-size: 12px; color: var(--muted); }
.perm:has(input:disabled) { opacity: .5; cursor: default; }
@media (prefers-color-scheme: dark) { .pick .chip.on { background: var(--gold); border-color: var(--gold); color: var(--ink); } }
@media (min-width: 820px) { .savebar { bottom: 0; } }
