:root {
  --bg: #f4f6f9; --card: #fff; --ink: #1d2330; --muted: #6a7282; --line: #e3e7ee;
  --accent: #1f4e79; --accent-2: #2f6fab; --good: #1e7d4f; --warn: #b26a00; --bad: #b3261e;
  --radius: 14px; --tab-h: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #11151c; --card: #1a2029; --ink: #e8ecf2; --muted: #9aa3b2; --line: #2a323e; --accent: #7fb2e5; --accent-2: #9cc4ee; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px); -webkit-text-size-adjust: 100%; }
a { color: var(--accent-2); }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .back { font-size: 28px; line-height: 1; border: 0; background: none; color: var(--accent-2); padding: 0 8px 0 0; cursor: pointer; }
.topbar select { width: auto; padding: 6px 8px; font-size: 14px; }

main { max-width: 860px; margin: 0 auto; padding: 16px; }
.loading { color: var(--muted); padding: 40px 0; text-align: center; }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: space-around;
  height: calc(var(--tab-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--card); border-top: 1px solid var(--line); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; color: var(--muted); text-decoration: none; }
.tabbar a .ico { font-size: 20px; line-height: 1; }
.tabbar a.active { color: var(--accent-2); font-weight: 600; }
.tabbar a.scan .ico { background: var(--accent); color: #fff; width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; margin-top: -18px; box-shadow: 0 4px 12px rgba(0,0,0,.2); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 15px; margin: 0 0 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
@media (min-width: 700px) { .grid.g4 { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--muted); margin-top: 2px; }

.list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list li + li { border-top: 1px solid var(--line); }
.list a.row, .list .row { display: flex; gap: 12px; align-items: center; padding: 12px 14px; text-decoration: none; color: inherit; }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amt { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.row .amt .sub { font-weight: 400; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em;
  background: var(--line); color: var(--muted); }
.badge.draft { background: #e9ecf1; color: #59606d; }
.badge.issued { background: #e2edf9; color: #1f4e79; }
.badge.paid { background: #def3e7; color: var(--good); }
.badge.void { background: #f6e1df; color: var(--bad); }
.badge.overdue { background: #fdebd3; color: var(--warn); }

label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
input, select, textarea { width: 100%; font: inherit; font-size: 16px; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-2); outline-offset: -1px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.check { display: flex; gap: 8px; align-items: center; color: var(--ink); font-size: 15px; }
.check input { width: auto; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 15px; font-weight: 600;
  padding: 11px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); color: var(--ink); cursor: pointer; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.actions .btn { flex: 1 1 140px; }
.fab { position: fixed; right: 18px; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 18px); z-index: 9;
  width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 30px; border: 0;
  display: grid; place-items: center; text-decoration: none; box-shadow: 0 6px 16px rgba(0,0,0,.25); }

.filters { display: flex; gap: 8px; margin-bottom: 12px; overflow-x: auto; }
.filters select, .filters input { flex: 1 1 auto; min-width: 120px; }
.chips { display: flex; gap: 6px; margin-bottom: 12px; overflow-x: auto; }
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 13px; color: var(--ink); text-decoration: none; white-space: nowrap; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

.alert { border-radius: 10px; padding: 12px 14px; margin-bottom: 14px; font-size: 14px; background: #fff6e5; color: #6b4300; border: 1px solid #f3d9a4; }
.alert.info { background: #e9f2fb; color: #18406a; border-color: #c4dcf3; }
.alert.bad { background: #fbeaea; color: #7a1c16; border-color: #f0c5c2; }
@media (prefers-color-scheme: dark) { .alert { filter: brightness(.85) contrast(1.1); } }

table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td.n, th.n { text-align: right; white-space: nowrap; }
.scroll { overflow-x: auto; }

.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; align-items: end; height: 140px; margin-top: 8px; }
.bars .m { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; gap: 2px; }
.bars .b { width: 45%; border-radius: 3px 3px 0 0; min-height: 1px; }
.bars .pair { display: flex; gap: 2px; width: 100%; justify-content: center; align-items: flex-end; height: 100%; }
.bars .inc { background: var(--accent-2); }
.bars .exp { background: #e3a33b; }
.bars .lbl { font-size: 10px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.hbar { height: 6px; background: var(--line); border-radius: 3px; margin-top: 4px; }
.hbar > span { display: block; height: 100%; background: var(--accent-2); border-radius: 3px; }

.item { border: 1px solid var(--line); border-radius: 12px; padding: 10px; margin-bottom: 10px; }
.item .row3 label { margin-top: 6px; }
.receipt-preview { width: 100%; max-height: 360px; object-fit: contain; border-radius: 10px; background: var(--line); }
.scan-hero { text-align: center; padding: 26px 10px; }
.scan-hero .big { font-size: 18px; padding: 18px; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--line); border-top-color: var(--accent-2); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 20px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.total-line { display: flex; justify-content: space-between; padding: 4px 0; font-variant-numeric: tabular-nums; }
.total-line.strong { font-weight: 700; font-size: 17px; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 8px; }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; font-size: 14px; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

#toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 20px);
  background: #222a36; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; max-width: 90vw; }
#toast.show { opacity: 1; }
.login { max-width: 360px; margin: 12vh auto 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row2 > *, .row3 > * { min-width: 0; }
input[type="time"], input[type="date"] { min-width: 0; }
