:root {
    --bg: #f4f6f5;
    --card: #ffffff;
    --ink: #17201c;
    --muted: #5f6b66;
    --line: #dfe5e2;
    --accent: #0b6e4f;
    --accent-ink: #ffffff;
    --accent-soft: #e2f1eb;
    --warn: #8a5a00;
    --warn-soft: #fff3d6;
    --bad: #b3261e;
    --bad-soft: #fde7e5;
    --radius: 14px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1412;
        --card: #18201d;
        --ink: #e7eeea;
        --muted: #9aa8a1;
        --line: #2a3531;
        --accent: #3ec495;
        --accent-ink: #062a1e;
        --accent-soft: #15332a;
        --warn: #f0c060;
        --warn-soft: #3a2f14;
        --bad: #f2b8b5;
        --bad-soft: #3b1d1b;
    }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    padding-top: max(12px, env(safe-area-inset-top));
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}

.topbar h1 { flex: 1; margin: 0; font-size: 17px; }

main { max-width: 480px; margin: 0 auto; padding: 16px 16px 40px; }

.screen { display: block; }
.screen[hidden] { display: none; }

h2 { font-size: 20px; margin: 0 0 4px; }
h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 24px 0 8px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

.stack { display: flex; flex-direction: column; gap: 10px; }
.stack.tight { gap: 6px; }

label { font-size: 14px; font-weight: 600; }

input, textarea {
    width: 100%;
    font: inherit;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--ink);
}

input:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

button, .file-btn {
    font: inherit;
    font-weight: 600;
    border-radius: 10px;
    padding: 12px 16px;
    border: 1px solid transparent;
    cursor: pointer;
    text-align: center;
}

button.primary { background: var(--accent); color: var(--accent-ink); }
button.primary:disabled { opacity: .55; cursor: progress; }
button.big { padding: 15px; font-size: 17px; width: 100%; }
.chip-row { margin-top: 8px; }
.warn-text { color: var(--warn); }
button.secondary, .file-btn { background: var(--card); color: var(--ink); border-color: var(--line); }
.link-btn { background: none; border: none; color: var(--accent); padding: 6px; font-weight: 600; }
.icon-btn { background: none; border: none; color: var(--ink); font-size: 22px; padding: 2px 8px; }

.hero { text-align: center; margin: 24px 0 28px; }
.logo {
    width: 56px; height: 56px; margin: 0 auto 14px; border-radius: 16px;
    display: grid; place-items: center; font-size: 28px; font-weight: 800;
    background: var(--accent); color: var(--accent-ink);
}

.hint {
    background: var(--warn-soft); color: var(--warn);
    border-radius: 10px; padding: 8px 12px; font-size: 14px; margin: 0;
}

.total-card {
    display: flex; flex-direction: column; gap: 2px;
    background: var(--accent); color: var(--accent-ink);
    border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
}
.total-card .muted { color: inherit; opacity: .8; }
.total-card strong { font-size: 30px; font-variant-numeric: tabular-nums; }

.voucher-card {
    display: block; width: 100%; text-align: left; font-weight: 400;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 14px 16px; color: var(--ink);
}
.voucher-card .row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.voucher-card .name { font-weight: 700; }
.voucher-card .bal { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.voucher-card .sub { font-size: 13px; color: var(--muted); margin-top: 4px; }

.chip {
    display: inline-block; white-space: nowrap; font-size: 12px; font-weight: 600;
    border-radius: 99px; padding: 1px 8px; background: var(--accent-soft); color: var(--accent);
}
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.muted { background: var(--line); color: var(--muted); }

.voucher-hero {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    padding: 18px; margin-bottom: 14px;
}
.voucher-hero .bal { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.voucher-hero .code { font-family: ui-monospace, Menlo, monospace; letter-spacing: .08em; color: var(--muted); font-size: 14px; }

.line-item {
    display: flex; justify-content: space-between; gap: 12px; align-items: center;
    background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
.line-item .l { min-width: 0; }
.line-item .l div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.line-item .r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.credit { color: var(--accent); }
.debit { color: var(--ink); }
.struck { text-decoration: line-through; color: var(--muted); }

.scanner {
    position: relative; overflow: hidden; border-radius: var(--radius);
    background: #000; aspect-ratio: 3 / 4; max-height: 62vh; width: 100%;
}
.scanner video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scanner .frame {
    position: absolute; inset: 18%; border: 3px solid rgba(255, 255, 255, .85); border-radius: 18px;
    box-shadow: 0 0 0 999px rgba(0, 0, 0, .35);
}
.scan-msg {
    position: absolute; left: 0; right: 0; bottom: 10px; margin: 0; text-align: center;
    color: #fff; font-size: 14px; text-shadow: 0 1px 3px #000; padding: 0 12px;
}
.scan-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }

.merchant-card {
    display: flex; gap: 14px; align-items: center;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px;
}
.merchant-icon {
    width: 48px; height: 48px; border-radius: 12px; flex: none;
    display: grid; place-items: center; font-size: 22px; font-weight: 800;
    background: var(--accent-soft); color: var(--accent);
}

.result { text-align: center; padding: 28px 8px; }
.result .big-icon {
    width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 14px;
    display: grid; place-items: center; font-size: 36px; font-weight: 800;
}
.result .ok { background: var(--accent-soft); color: var(--accent); }
.result .pending { background: var(--warn-soft); color: var(--warn); }
.result .fail { background: var(--bad-soft); color: var(--bad); }
.result .amt { font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; }
.result dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; text-align: left; margin: 20px auto 0; max-width: 340px; font-size: 14px; }
.result dt { color: var(--muted); }
.result dd { margin: 0; word-break: break-all; }

.spinner {
    width: 28px; height: 28px; border-radius: 50%;
    border: 3px solid currentColor; border-right-color: transparent;
    animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
    position: fixed; left: 16px; right: 16px; bottom: max(16px, env(safe-area-inset-bottom));
    max-width: 448px; margin: 0 auto; z-index: 10;
    background: var(--ink); color: var(--bg); border-radius: 12px; padding: 12px 14px; font-size: 15px;
}

.empty { text-align: center; margin-top: 30px; }
