Files
CatoandClaude 0474c3a887 paykit 0.7.0: prepaid credit, top-ups, auto top-up and per-key limits (#31)
Pay as you go beside the subscriptions, the way OpenRouter charges:

- ./credits: append-only CreditLedger with idempotency keys and an
  in-memory ledger; balance, FIFO lots and debt; charge refused with 402
  below the app's floor or over a spending key's daily/weekly/monthly
  limit; hold then settle or release; top-up quotes with a fee per rail
  in integer arithmetic; refund eligibility (window, fee kept, rails that
  never refund); expiry of old lots; auto top-up decision with backoff
  and a failure cap; credit events applied idempotently; top-ups through
  any PaymentProvider (OrangeCat: sats, never refundable).
- ./stripe: stripeCredits — top-up Checkout Session (saves the method
  off-session when auto top-up is on), off-session PaymentIntent with an
  Idempotency-Key, refunds, and webhook mapping for
  checkout.session.completed, payment_intent.succeeded/payment_failed
  and charge.refunded. The pass provider ignores top-up sessions.
- ./react: CreditBalance, TopUp, AutoTopUp, CreditActivity; PickerTier
  gains optional rates for a pay-as-you-go tier.

No price, fee or threshold is built in; all are the app's config.


Claude-Session: https://claude.ai/code/session_019MDtmtfseicWGK2CMC2U5r

Co-authored-by: Claude <noreply@anthropic.com>
2026-12-03 13:07:29 +01:00

845 lines
19 KiB
CSS

/*
* @bitbaum/paykit/react: PlanPicker, PlanReview and the credit screens
* (CreditBalance, TopUp, AutoTopUp, CreditActivity).
*
* Every colour, radius and font is a --pk-* variable. Each falls back to the
* --sk-* variable sitekit's chrome already reads, and then to the system's
* own colours (Canvas, CanvasText), so the components follow light and dark
* without an app doing anything. An app maps them to its brand once:
*
* :root { --pk-action: var(--color-action); --pk-on-action: var(--color-on-action); … }
*
* Targets are at least 44 px high. Nothing has a fixed width, every grid
* track is min(100%, …) or minmax(0, 1fr), and long words wrap only between
* words, so 320 px is one column without sideways scroll.
*/
:where(.pk-picker, .pk-review, .pk-credits) {
--pk-fg-: var(--pk-fg, var(--sk-fg, CanvasText));
--pk-muted-: var(--pk-muted, var(--sk-muted, color-mix(in srgb, CanvasText 64%, Canvas)));
--pk-surface-: var(--pk-surface, var(--sk-surface, Canvas));
--pk-raised-: var(--pk-raised, var(--sk-raised, color-mix(in srgb, CanvasText 4%, Canvas)));
--pk-line-: var(--pk-line, var(--sk-line, color-mix(in srgb, CanvasText 16%, Canvas)));
--pk-line-strong-: var(--pk-line-strong, var(--sk-line-strong, color-mix(in srgb, CanvasText 70%, Canvas)));
--pk-selected-: var(--pk-selected, var(--pk-fg-));
--pk-action-: var(--pk-action, var(--sk-fg, CanvasText));
--pk-on-action-: var(--pk-on-action, var(--sk-surface, Canvas));
--pk-badge-: var(--pk-badge, var(--pk-action-));
--pk-on-badge-: var(--pk-on-badge, var(--pk-on-action-));
--pk-positive-: var(--pk-positive, var(--pk-fg-));
--pk-warning-: var(--pk-warning, var(--sk-negative, #b3261e));
--pk-focus-: var(--pk-focus, var(--sk-focus, Highlight));
--pk-radius-: var(--pk-radius, var(--sk-radius, 0.75rem));
--pk-radius-small-: var(--pk-radius-small, var(--pk-radius-));
--pk-font-: var(--pk-font, var(--sk-font, system-ui, sans-serif));
--pk-display-: var(--pk-display, var(--pk-font-));
color: var(--pk-fg-);
font-family: var(--pk-font-);
line-height: 1.5;
}
:where(.pk-picker, .pk-review, .pk-credits, .pk-picker *, .pk-review *, .pk-credits *) {
box-sizing: border-box;
}
.pk-picker,
.pk-review,
.pk-credits {
display: flex;
flex-direction: column;
gap: 1.5rem;
width: 100%;
max-width: 34rem;
min-width: 0;
margin-inline: auto;
}
.pk-visually-hidden {
position: absolute;
width: 1px;
height: 1px;
margin: -1px;
padding: 0;
overflow: hidden;
clip: rect(0 0 0 0);
white-space: nowrap;
border: 0;
}
/* ── The tier switch ─────────────────────────────────────────────────── */
.pk-switch {
/* Equal tracks that may shrink below their words: a name wraps between
words inside its tab instead of widening the row. */
display: grid;
grid-auto-flow: column;
grid-auto-columns: minmax(0, 1fr);
gap: 0.25rem;
padding: 0.25rem;
border: 1px solid var(--pk-line-);
border-radius: calc(var(--pk-radius-) + 0.25rem);
background: var(--pk-raised-);
}
.pk-switch-tab {
position: relative;
display: inline-flex;
align-items: center;
justify-content: center;
gap: 0.375rem;
min-width: 0;
min-height: 2.75rem;
padding: 0.375rem 0.5rem;
border: 1px solid transparent;
border-radius: var(--pk-radius-);
background: none;
color: var(--pk-muted-);
font: inherit;
font-size: 0.875rem;
font-weight: 600;
line-height: 1.2;
text-align: center;
cursor: pointer;
}
.pk-switch-name {
/* Wraps between words, never inside one: a name too long for a quarter of
a phone gets a half (the two-row layout below). */
min-width: 0;
overflow-wrap: normal;
}
.pk-switch-tab[aria-selected="true"] {
border-color: var(--pk-line-);
background: var(--pk-surface-);
color: var(--pk-fg-);
box-shadow: 0 1px 2px color-mix(in srgb, CanvasText 8%, transparent);
}
.pk-switch-tab:hover:not([aria-selected="true"]) {
color: var(--pk-fg-);
}
.pk-switch-dot {
flex: none;
width: 0.375rem;
height: 0.375rem;
border-radius: 999px;
background: var(--pk-badge-);
}
/* Four or more tabs on a narrow phone: two rows of two read better than four slivers. */
@media (max-width: 26rem) {
.pk-switch[data-count="4"] {
grid-auto-flow: row;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
/* ── The selected tier ───────────────────────────────────────────────── */
.pk-panel {
display: flex;
flex-direction: column;
gap: 1.25rem;
min-width: 0;
}
.pk-head {
display: flex;
flex-direction: column;
gap: 0.375rem;
}
.pk-badge {
align-self: flex-start;
margin: 0 0 0.25rem;
padding: 0.1875rem 0.625rem;
border-radius: 999px;
background: var(--pk-badge-);
color: var(--pk-on-badge-);
font-size: 0.75rem;
font-weight: 600;
line-height: 1.4;
letter-spacing: 0.02em;
}
.pk-name {
margin: 0;
font-family: var(--pk-display-);
font-size: 1.75rem;
font-weight: 600;
line-height: 1.15;
}
.pk-tagline {
margin: 0;
color: var(--pk-muted-);
font-size: 0.9375rem;
}
/* ── Period cards ────────────────────────────────────────────────────── */
.pk-periods {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 9.5rem), 1fr));
gap: 0.75rem;
margin: 0;
padding: 0;
border: 0;
min-width: 0;
}
.pk-period {
position: relative;
display: flex;
flex-direction: column;
gap: 0.375rem;
min-width: 0;
min-height: 2.75rem;
padding: 1rem;
border: 1px solid var(--pk-line-);
border-radius: var(--pk-radius-);
background: var(--pk-surface-);
cursor: pointer;
transition: border-color 120ms ease, box-shadow 120ms ease;
}
.pk-period:hover {
border-color: var(--pk-line-strong-);
}
.pk-period[data-checked] {
border-color: var(--pk-selected-);
box-shadow: inset 0 0 0 1px var(--pk-selected-);
}
.pk-period:has(input:focus-visible) {
outline: 2px solid var(--pk-focus-);
outline-offset: 2px;
}
.pk-period-top {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 0.25rem 0.5rem;
}
.pk-period-label {
font-size: 0.875rem;
font-weight: 600;
}
.pk-period-badge {
padding: 0.0625rem 0.5rem;
border-radius: 999px;
border: 1px solid currentColor;
color: var(--pk-positive-);
font-size: 0.75rem;
font-weight: 600;
line-height: 1.5;
white-space: nowrap;
}
.pk-period-price {
line-height: 1.2;
}
.pk-amount {
font-family: var(--pk-display-);
font-size: 1.5rem;
font-weight: 600;
font-variant-numeric: tabular-nums;
/* "CHF 12" is one piece. */
white-space: nowrap;
}
.pk-per,
.pk-price-per {
color: var(--pk-muted-);
font-size: 0.875rem;
}
.pk-period-highlight {
font-size: 0.875rem;
font-weight: 600;
line-height: 1.35;
}
.pk-period-detail {
color: var(--pk-muted-);
font-size: 0.8125rem;
line-height: 1.4;
}
.pk-price {
display: flex;
flex-direction: column;
gap: 0.25rem;
margin: 0;
}
.pk-price .pk-amount {
font-size: 1.75rem;
white-space: normal;
}
/* ── Benefits ────────────────────────────────────────────────────────── */
.pk-benefits-wrap {
display: flex;
flex-direction: column;
gap: 0.625rem;
}
.pk-benefits-label {
margin: 0;
color: var(--pk-muted-);
font-size: 0.75rem;
font-weight: 600;
letter-spacing: 0.06em;
text-transform: uppercase;
}
.pk-benefits {
display: flex;
flex-direction: column;
gap: 0.625rem;
margin: 0;
padding: 0;
list-style: none;
}
.pk-benefits li {
display: flex;
gap: 0.625rem;
min-width: 0;
font-size: 0.9375rem;
line-height: 1.45;
}
.pk-benefits li > span {
min-width: 0;
}
.pk-check {
flex: none;
width: 1rem;
height: 1rem;
margin-top: 0.15em;
color: var(--pk-fg-);
}
/* ── Buttons ─────────────────────────────────────────────────────────── */
.pk-action {
display: flex;
flex-direction: column;
}
.pk-button {
display: inline-flex;
align-items: center;
justify-content: center;
width: 100%;
min-height: 3rem;
padding: 0.625rem 1.25rem;
border: 1px solid var(--pk-action-);
border-radius: var(--pk-radius-);
background: var(--pk-action-);
color: var(--pk-on-action-);
font: inherit;
font-weight: 600;
line-height: 1.3;
text-align: center;
text-decoration: none;
cursor: pointer;
transition: opacity 120ms ease;
}
.pk-button:hover:not(:disabled) {
opacity: 0.88;
}
.pk-button:disabled {
opacity: 0.4;
cursor: not-allowed;
}
.pk-button:focus-visible,
.pk-switch-tab:focus-visible,
.pk-quiet:focus-visible,
.pk-note-row:focus-visible,
.pk-checkbox:focus-visible,
.pk-chip:has(input:focus-visible),
.pk-input:focus-visible {
outline: 2px solid var(--pk-focus-);
outline-offset: 2px;
}
.pk-quiet {
align-self: center;
min-height: 2.75rem;
padding: 0.5rem 0.75rem;
border: 0;
background: none;
color: var(--pk-fg-);
font: inherit;
font-size: 0.9375rem;
text-decoration: underline;
text-underline-offset: 0.2em;
cursor: pointer;
display: inline-flex;
align-items: center;
}
.pk-current {
margin: 0;
padding: 0.75rem 1rem;
border: 1px solid var(--pk-line-);
border-radius: var(--pk-radius-);
text-align: center;
font-weight: 600;
}
.pk-custom {
min-width: 0;
}
.pk-fine {
color: var(--pk-muted-);
font-size: 0.8125rem;
line-height: 1.55;
}
.pk-fine p {
margin: 0 0 0.375rem;
}
.pk-fine a {
color: inherit;
}
/* ── Review ──────────────────────────────────────────────────────────── */
.pk-review-head {
display: flex;
flex-direction: column;
gap: 0.25rem;
}
.pk-step {
margin: 0;
color: var(--pk-muted-);
font-size: 0.8125rem;
font-weight: 600;
letter-spacing: 0.04em;
}
.pk-review-title {
margin: 0;
font-family: var(--pk-display-);
font-size: 1.75rem;
font-weight: 600;
line-height: 1.15;
}
.pk-summary {
display: flex;
flex-direction: column;
gap: 0.25rem;
padding: 1.25rem;
border: 1px solid var(--pk-line-);
border-radius: var(--pk-radius-);
background: var(--pk-raised-);
}
.pk-summary p {
margin: 0;
}
.pk-summary-name {
font-weight: 600;
}
.pk-summary-price {
line-height: 1.2;
padding-block: 0.25rem;
}
.pk-summary-detail,
.pk-summary-tax {
color: var(--pk-muted-);
font-size: 0.875rem;
}
.pk-notes {
display: flex;
flex-direction: column;
margin: 0;
padding: 0;
list-style: none;
border-top: 1px solid var(--pk-line-);
}
.pk-notes > li {
border-bottom: 1px solid var(--pk-line-);
}
.pk-note-row {
display: flex;
align-items: center;
gap: 0.875rem;
min-height: 3.5rem;
padding: 0.75rem 0;
list-style: none;
}
summary.pk-note-row {
cursor: pointer;
}
summary.pk-note-row::-webkit-details-marker {
display: none;
}
.pk-note-icon {
flex: none;
display: inline-flex;
align-items: center;
justify-content: center;
width: 2.25rem;
height: 2.25rem;
border-radius: 999px;
background: var(--pk-raised-);
border: 1px solid var(--pk-line-);
font-size: 0.875rem;
font-weight: 600;
}
.pk-note-text {
display: flex;
flex: 1;
flex-direction: column;
min-width: 0;
}
.pk-note-title {
font-size: 0.9375rem;
font-weight: 600;
}
.pk-note-line {
color: var(--pk-muted-);
font-size: 0.875rem;
}
.pk-note-chevron {
flex: none;
width: 1rem;
height: 1rem;
color: var(--pk-muted-);
transition: transform 120ms ease;
}
details[open] > summary .pk-note-chevron {
transform: rotate(180deg);
}
.pk-note-more {
padding: 0 0 1rem 3.125rem;
color: var(--pk-muted-);
font-size: 0.875rem;
}
.pk-note-more p {
margin: 0 0 0.5rem;
}
.pk-account {
display: flex;
flex-direction: column;
gap: 0.125rem;
}
.pk-account p {
margin: 0;
}
.pk-account-label {
color: var(--pk-muted-);
font-size: 0.8125rem;
}
.pk-account-value {
font-weight: 600;
overflow-wrap: anywhere;
}
.pk-account-hint {
color: var(--pk-muted-);
font-size: 0.8125rem;
}
.pk-terms {
display: flex;
flex-direction: column;
gap: 0.25rem;
margin: 0;
padding: 0;
border: 0;
min-width: 0;
}
.pk-term {
display: flex;
align-items: flex-start;
gap: 0.75rem;
min-height: 2.75rem;
padding: 0.5rem 0;
font-size: 0.9375rem;
line-height: 1.45;
cursor: pointer;
}
.pk-checkbox {
flex: none;
width: 1.25rem;
height: 1.25rem;
margin: 0.1em 0 0;
accent-color: var(--pk-action-);
cursor: pointer;
}
.pk-term-label {
min-width: 0;
}
.pk-term-label a {
color: inherit;
text-underline-offset: 0.2em;
}
.pk-hint {
margin: 0;
color: var(--pk-muted-);
font-size: 0.875rem;
text-align: center;
}
.pk-error {
margin: 0;
color: var(--pk-warning-);
font-size: 0.875rem;
}
.pk-overlap {
display: flex;
flex-direction: column;
gap: 0.75rem;
padding: 1rem 1.25rem;
border: 1px solid var(--pk-warning-);
border-left-width: 4px;
border-radius: var(--pk-radius-);
}
.pk-overlap p {
margin: 0;
}
.pk-overlap-title {
font-weight: 600;
}
.pk-overlap-body {
color: var(--pk-muted-);
font-size: 0.9375rem;
}
/* ── Pay as you go: rates in the plan picker ─────────────────────────── */
.pk-rates-wrap {
display: flex;
flex-direction: column;
gap: 0.625rem;
margin-bottom: 1.25rem;
}
.pk-rates {
display: flex;
flex-direction: column;
margin: 0;
}
.pk-rate {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: 0.25rem 1rem;
padding: 0.5rem 0;
border-bottom: 1px solid var(--pk-line-);
font-size: 0.9375rem;
}
.pk-rate dt,
.pk-rate dd {
min-width: 0;
margin: 0;
}
.pk-rate-price {
font-weight: 600;
font-variant-numeric: tabular-nums;
}
/* ── Credit: balance ─────────────────────────────────────────────────── */
.pk-credits {
gap: 1rem;
}
.pk-topup,
.pk-auto,
.pk-activity {
gap: 1.25rem;
}
.pk-balance {
padding: 1.25rem;
border: 1px solid var(--pk-line-);
border-radius: var(--pk-radius-);
background: var(--pk-raised-);
}
.pk-balance p {
margin: 0;
}
.pk-balance-label {
color: var(--pk-muted-);
font-size: 0.875rem;
font-weight: 600;
}
.pk-balance-amount {
font-family: var(--pk-display-);
/* A seven-figure balance still fits a 320 px phone on one line. */
font-size: clamp(1.375rem, 7.5vw, 2rem);
font-weight: 700;
line-height: 1.15;
font-variant-numeric: tabular-nums;
}
.pk-balance[data-state="negative"] .pk-balance-amount {
color: var(--pk-warning-);
}
.pk-balance-held {
color: var(--pk-muted-);
font-size: 0.875rem;
}
.pk-balance-note {
font-size: 0.9375rem;
}
.pk-balance[data-state="negative"] .pk-balance-note,
.pk-balance[data-state="low"] .pk-balance-note {
color: var(--pk-warning-);
}
/* ── Credit: choosing an amount, a way to pay, the quote ─────────────── */
.pk-chips {
/* Wraps: as many chips per row as fit, each at least a thumb wide. */
display: grid;
grid-template-columns: repeat(auto-fill, minmax(min(100%, 6rem), 1fr));
gap: 0.5rem;
min-width: 0;
margin: 0;
padding: 0;
border: 0;
}
.pk-chips > legend {
margin-bottom: 0.5rem;
}
.pk-field-label {
padding: 0;
color: var(--pk-muted-);
font-size: 0.8125rem;
font-weight: 600;
}
.pk-chip {
display: flex;
align-items: center;
justify-content: center;
min-width: 0;
min-height: 2.75rem;
padding: 0.5rem 0.75rem;
border: 1px solid var(--pk-line-);
border-radius: var(--pk-radius-small-);
background: var(--pk-surface-);
font-weight: 600;
font-variant-numeric: tabular-nums;
text-align: center;
cursor: pointer;
}
.pk-chip[data-checked] {
border-color: var(--pk-selected-);
box-shadow: inset 0 0 0 1px var(--pk-selected-);
}
.pk-field {
display: flex;
flex-direction: column;
gap: 0.375rem;
min-width: 0;
}
.pk-input {
width: 100%;
min-height: 2.75rem;
padding: 0.5rem 0.75rem;
border: 1px solid var(--pk-line-strong-);
border-radius: var(--pk-radius-small-);
background: var(--pk-surface-);
color: var(--pk-fg-);
font: inherit;
}
.pk-input[aria-invalid="true"] {
border-color: var(--pk-warning-);
}
.pk-rails {
display: flex;
flex-direction: column;
gap: 0.5rem;
min-width: 0;
margin: 0;
padding: 0;
border: 0;
}
.pk-rails > legend {
margin-bottom: 0.5rem;
}
.pk-rail {
display: flex;
align-items: flex-start;
gap: 0.75rem;
min-height: 2.75rem;
padding: 0.75rem 1rem;
border: 1px solid var(--pk-line-);
border-radius: var(--pk-radius-);
cursor: pointer;
}
.pk-rail[data-checked] {
border-color: var(--pk-selected-);
box-shadow: inset 0 0 0 1px var(--pk-selected-);
}
.pk-rail-text {
display: flex;
flex-direction: column;
min-width: 0;
}
.pk-rail-label {
font-weight: 600;
}
.pk-rail-note {
color: var(--pk-muted-);
font-size: 0.8125rem;
}
.pk-quote {
display: flex;
flex-direction: column;
margin: 0;
padding: 0.75rem 1rem;
border-radius: var(--pk-radius-);
background: var(--pk-raised-);
}
.pk-quote-row {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: 0.25rem 1rem;
padding: 0.25rem 0;
}
.pk-quote-row dt,
.pk-quote-row dd {
min-width: 0;
margin: 0;
font-variant-numeric: tabular-nums;
}
.pk-quote-row dt {
color: var(--pk-muted-);
}
.pk-quote-total {
margin-top: 0.25rem;
padding-top: 0.5rem;
border-top: 1px solid var(--pk-line-);
font-weight: 700;
}
.pk-quote-total dt {
color: var(--pk-fg-);
}
.pk-auto-summary {
margin: 0;
font-size: 0.9375rem;
}
/* ── Credit: activity ────────────────────────────────────────────────── */
.pk-filters {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(min(100%, 10rem), 1fr));
gap: 0.75rem;
}
.pk-rows {
display: flex;
flex-direction: column;
margin: 0;
padding: 0;
list-style: none;
}
.pk-row {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 1rem;
min-width: 0;
padding: 0.75rem 0;
border-bottom: 1px solid var(--pk-line-);
}
.pk-row-main {
display: flex;
flex-direction: column;
gap: 0.125rem;
min-width: 0;
}
.pk-row-kind {
font-weight: 600;
}
.pk-row-detail {
/* Words the app passes (a model's name) may be one long token. */
overflow-wrap: anywhere;
font-size: 0.9375rem;
}
.pk-row-meta {
color: var(--pk-muted-);
font-size: 0.8125rem;
}
.pk-row-amount {
flex: none;
font-weight: 600;
font-variant-numeric: tabular-nums;
white-space: nowrap;
}
.pk-row-amount[data-sign="plus"] {
color: var(--pk-positive-);
}
@media (prefers-reduced-motion: reduce) {
.pk-period,
.pk-button,
.pk-note-chevron {
transition: none;
}
}