:root {
    --primary: #5750f1;
    --primary-dark: #4540d8;
    --bg: #f3f4f6;
    --card: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --stroke: #e6ebf1;
    --green: #22ad5c;
    --red: #f23030;
    --radius: 10px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #020d1a;
        --card: #122031;
        --text: #e5e7eb;
        --muted: #94a3b8;
        --stroke: #1f2f45;
    }
}

* {
    box-sizing: border-box;
    margin: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    padding-bottom: env(safe-area-inset-bottom);
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    background: var(--card);
    border-bottom: 1px solid var(--stroke);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    font-weight: 800;
    font-size: 1.2rem;
    color: var(--primary);
    letter-spacing: 0.02em;
}

#account-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

main {
    flex: 1;
    width: 100%;
    max-width: 560px;
    margin: 0 auto;
    padding: 18px;
}

h1 {
    font-size: 1.3rem;
    margin-bottom: 10px;
}

h2 {
    font-size: 1.05rem;
    margin: 22px 0 8px;
}

p {
    margin-bottom: 12px;
}

.muted { color: var(--muted); }
.small { font-size: 0.8rem; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }
.wrap { word-break: break-all; }

/* QR codes always need a light background, also in dark mode */
.qr {
    display: block;
    background: #fff;
    padding: 10px;
    border-radius: 8px;
    margin: 10px auto;
    width: 240px;
    height: 240px;
    max-width: 100%;
}

label {
    display: block;
    font-size: 0.85rem;
    color: var(--muted);
    margin: 14px 0 4px;
}

input, select {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid var(--stroke);
    border-radius: var(--radius);
    background: var(--card);
    color: var(--text);
    font-size: 1rem;
}

input:focus, select:focus {
    outline: 2px solid var(--primary);
    border-color: transparent;
}

button {
    appearance: none;
    border: none;
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    padding: 12px 16px;
    margin-top: 16px;
    width: 100%;
    cursor: pointer;
}

button:hover { background: var(--primary-dark); }
button:disabled { opacity: 0.6; cursor: wait; }

button.secondary {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 8px 12px;
    width: auto;
    margin-top: 10px;
    font-size: 0.85rem;
}

button.ghost {
    background: transparent;
    color: var(--muted);
    width: auto;
    padding: 4px 8px;
    margin: 0;
    font-size: 0.9rem;
}

.balance-card {
    background: linear-gradient(135deg, var(--primary), #7a74ff);
    color: #fff;
    border-radius: 14px;
    padding: 22px;
    margin-bottom: 18px;
}

.balance-card .muted { color: rgba(255, 255, 255, 0.75); }

.balance {
    font-size: 2.6rem;
    font-weight: 800;
    line-height: 1.2;
}

.token-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 12px;
}

.token-card {
    background: var(--card);
    border: 1px solid var(--stroke);
    border-radius: var(--radius);
    padding: 14px;
    text-align: center;
}

.token-id {
    font-size: 1.3rem;
    font-weight: 700;
    color: var(--primary);
}

.invoice-box {
    background: var(--card);
    border: 1px solid var(--stroke);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: flex-start;
}

.history-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    background: var(--card);
    border: 1px solid var(--stroke);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 8px;
}

.status {
    font-size: 0.8rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-completed.in { color: var(--green); }
.status-completed.out { color: var(--text); }
.status-accepted { color: var(--muted); }

nav {
    display: flex;
    background: var(--card);
    border-top: 1px solid var(--stroke);
    position: sticky;
    bottom: 0;
    padding-bottom: env(safe-area-inset-bottom);
}

nav button {
    flex: 1;
    background: transparent;
    color: var(--muted);
    border-radius: 0;
    margin: 0;
    padding: 12px 4px;
    font-size: 0.85rem;
    font-weight: 600;
}

nav button.active {
    color: var(--primary);
    box-shadow: inset 0 3px 0 var(--primary);
}

nav button:hover { background: transparent; color: var(--primary); }

#toasts {
    position: fixed;
    bottom: 70px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
    width: min(90vw, 420px);
}

.toast {
    background: var(--text);
    color: var(--bg);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 0.9rem;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.toast-success { background: var(--green); color: #fff; }
.toast-error { background: var(--red); color: #fff; }
