:root {
  --bg: #f6f5f2; --surface: #fff; --ink: #16181d; --muted: #6d7078; --line: #e3e1db; --fill: #eeece7;
  --accent: #16181d; --on-accent: #fff; --good: #1d7a4d; --bad: #b3331f; --warn: #9a6400; --warn-bg: #fbf1d9;
  --radius: 12px; --tab: 58px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111214; --surface: #1b1c20; --ink: #ecebe8; --muted: #9a9ca3; --line: #2c2e33; --fill: #25272c;
    --accent: #ecebe8; --on-accent: #111214; --good: #5cc48d; --bad: #f08a76; --warn: #e3b45a; --warn-bg: #33290f;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; overscroll-behavior-y: contain; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1 { font-size: 24px; line-height: 1.15; margin: 0; letter-spacing: -0.01em; text-wrap: balance; }
h2 { font-size: 13px; font-weight: 600; margin: 22px 0 8px; color: var(--muted); text-transform: none; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.muted { color: var(--muted); }
.good { color: var(--good); } .bad { color: var(--bad); }
.small { font-size: 13px; }

.screen { max-width: 720px; margin: 0 auto; padding: 16px 16px calc(var(--tab) + 28px + env(safe-area-inset-bottom)); }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; min-height: 40px; }
.head .actions { display: flex; gap: 8px; }

.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; background: var(--surface); border-top: 1px solid var(--line);
  display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; max-width: 144px; height: var(--tab); border: 0; background: none; color: var(--muted); font-size: 11px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.tabs button[aria-current="page"] { color: var(--ink); font-weight: 600; }
.tabs svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 11px 14px; min-height: 48px; border: 0; border-top: 1px solid var(--line);
  background: none; width: 100%; text-align: left; }
.row:first-child { border-top: 0; }
button.row:active { background: var(--fill); }
.row .grow { flex: 1; min-width: 0; }
.row .title { overflow-wrap: anywhere; }
.row .sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.row .end { text-align: right; flex-shrink: 0; }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); }
.thumb { width: 44px; height: 44px; border-radius: 8px; background: var(--fill); object-fit: cover; flex-shrink: 0;
  display: grid; place-items: center; font-size: 13px; color: var(--muted); font-weight: 600; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 10px; min-height: 44px; padding: 0 16px; font-weight: 600; }
.btn.primary { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: none; }
.btn.mini { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .45; cursor: default; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btns > .btn { flex: 1; }
a.btn { display: inline-grid; place-items: center; text-decoration: none; color: inherit; }
.controls { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }
.line-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.remove { border: 0; background: none; color: var(--muted); font-size: 20px; line-height: 1; width: 32px; height: 32px; margin: -6px -8px 0 0; flex-shrink: 0; }

.seg { display: flex; background: var(--fill); border-radius: 10px; padding: 3px; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.seg button { flex: 1; border: 0; background: none; min-height: 34px; padding: 0 10px; border-radius: 8px; white-space: nowrap; color: var(--muted); font-size: 14px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: 0 1px 2px rgb(0 0 0 / .08); }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
input, select, textarea { width: 100%; min-height: 44px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); padding: 0 12px; }
textarea { padding: 10px 12px; min-height: 72px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible { outline: 2px solid var(--ink); outline-offset: 1px; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cols3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
input.qty { width: 64px; text-align: center; padding: 0 4px; }
input.price { width: 92px; text-align: right; }

.overlay { position: fixed; inset: 0; z-index: 20; background: rgb(0 0 0 / .42); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 720px; max-height: 94dvh; border-radius: 16px 16px 0 0; display: flex; flex-direction: column; }
.sheet > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 16px 10px; }
.sheet > header b { font-size: 17px; }
.sheet > .body { overflow-y: auto; padding: 4px 16px 16px; flex: 1; }
.sheet > footer { padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface); }
.close { border: 0; background: var(--fill); width: 36px; height: 36px; border-radius: 50%; font-size: 18px; line-height: 1; }

.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 20px; background: var(--fill); color: var(--muted); white-space: nowrap; }
.badge.wait { background: var(--warn-bg); color: var(--warn); }
.badge.ok { color: var(--good); }
.badge.off { color: var(--bad); }
.note { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-size: 14px; }

.kv { display: flex; justify-content: space-between; gap: 16px; padding: 9px 14px; border-top: 1px solid var(--line); }
.kv:first-child { border-top: 0; }
.kv.total { font-weight: 700; }
.kv.sub { padding-left: 28px; color: var(--muted); font-size: 14px; }

.stat { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.stat div { padding: 12px 14px; border-left: 1px solid var(--line); min-width: 0; }
.stat div:first-child { border-left: 0; }
.stat span { display: block; font-size: 12px; color: var(--muted); }
.stat b { font-size: 17px; }

.chart { display: flex; align-items: flex-end; gap: 4px; height: 150px; padding: 12px 12px 0; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.chart .bars { display: flex; align-items: flex-end; gap: 2px; width: 100%; height: 100%; justify-content: center; }
.chart .bar { width: 42%; max-width: 16px; background: var(--ink); border-radius: 3px 3px 0 0; min-height: 1px; }
.chart .bar.profit { background: var(--good); }
.chart .bar.loss { background: var(--bad); }
.chart .lbl { font-size: 10px; color: var(--muted); padding: 4px 0 8px; }
.legend { display: flex; gap: 14px; padding: 0 14px 12px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; background: var(--ink); }
.meter { height: 6px; border-radius: 3px; background: var(--fill); overflow: hidden; margin-top: 5px; }
.meter i { display: block; height: 100%; background: var(--ink); }

.wallets { width: 100%; border-collapse: collapse; }
.wallets { font-size: 14px; }
.wallets th, .wallets td { padding: 9px 7px; text-align: right; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; white-space: nowrap; }
.wallets th { font-size: 12px; color: var(--muted); font-weight: 500; border-top: 0; white-space: normal; line-height: 1.25; vertical-align: bottom; }
.wallets td:first-child, .wallets th:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
.scroll-x { overflow-x: auto; }

.toast { position: fixed; left: 50%; bottom: calc(var(--tab) + 18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 10px; max-width: min(92vw, 520px); font-size: 14px; }
.toast.err { background: var(--bad); color: #fff; }
.login { max-width: 360px; margin: 14vh auto 0; padding: 0 20px; }
.login h1 { margin-bottom: 4px; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper button { width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); font-size: 18px; line-height: 1; }
.stepper b { min-width: 22px; text-align: center; }
@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: up .18s ease-out; }
  @keyframes up { from { transform: translateY(28px); } }
}
