/*
 * Payout ledger. The full history behind the earnings widget: a full-screen
 * safe overlay (mobile first, a bounded card on desktop) that scrolls inside
 * itself and closes with the ✕, Escape or the backdrop. Every colour and font
 * is a --rr-* theme token (fallbacks match the theme sheet's own values so the
 * panel is readable before it loads); every movement is opacity/transform only.
 */

.rr-ledger {
    --rr-ledger-accent: var(--rr-accent2, #ffb74a);
    --rr-ledger-good: var(--rr-ok, #76d074);
    --rr-ledger-good-soft: var(--rr-ok-soft, rgba(118, 208, 116, .16));
    --rr-ledger-bad: var(--rr-danger, #ff4d5e);
    --rr-ledger-bad-soft: var(--rr-danger-soft, rgba(255, 77, 94, .16));
    --rr-ledger-ink: var(--rr-text, #f2efe9);
    --rr-ledger-dim: var(--rr-text-dim, #b3ab9e);
    --rr-ledger-faint: var(--rr-text-faint, #8b8478);
    --rr-ledger-border: var(--rr-border, rgba(168, 160, 148, .22));
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: grid;
    /* Bounded track: an auto column would size to the rows' nowrap
       max-content and push the panel past a phone's edge. */
    grid-template-columns: minmax(0, 1fr);
    place-items: end center;
    padding: 0;
    font-family: var(--rr-font, ui-sans-serif, system-ui, sans-serif);
    color: var(--rr-ledger-ink);
}

.rr-ledger[hidden] {
    display: none;
}

.rr-ledger__backdrop {
    position: absolute;
    inset: 0;
    border: 0;
    margin: 0;
    padding: 0;
    background: color-mix(in srgb, var(--rr-bg-deep, #070605) 78%, transparent);
    backdrop-filter: blur(10px);
    cursor: pointer;
}

.rr-ledger__panel {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    max-height: calc(100dvh - env(safe-area-inset-top) - 24px);
    min-height: 0;
    overflow: hidden;
    border: 1px solid var(--rr-border-strong, rgba(255, 183, 74, .48));
    border-bottom: 0;
    border-radius: var(--rr-radius-l, 8px) var(--rr-radius-l, 8px) 0 0;
    background: linear-gradient(170deg, var(--rr-panel-raise, rgba(35, 32, 28, .96)), var(--rr-panel-b, rgba(14, 13, 11, .98)) 70%);
    box-shadow: var(--rr-shadow-2, 0 20px 55px rgba(0, 0, 0, .46)), var(--rr-rim, 0 0 0 1px rgba(255, 183, 74, .08));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    animation: rr-ledger-in .28s cubic-bezier(.2, .9, .2, 1);
}

@keyframes rr-ledger-in {
    from { opacity: 0; transform: translateY(18px); }
    to { opacity: 1; transform: none; }
}

.rr-ledger__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--rr-ledger-border);
}

.rr-ledger__heading {
    display: grid;
    gap: 3px;
    min-width: 0;
}

.rr-ledger__kicker {
    font-size: 10px;
    font-weight: 900;
    letter-spacing: .2em;
    color: var(--rr-ledger-accent);
}

.rr-ledger__title {
    margin: 0;
    font-size: 20px;
    line-height: 1;
    letter-spacing: .06em;
    color: var(--rr-ledger-ink);
}

.rr-ledger__close {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border: 1px solid var(--rr-ledger-border);
    border-radius: 999px;
    background: transparent;
    color: var(--rr-ledger-dim);
    font: inherit;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
}

.rr-ledger__close:focus-visible,
.rr-ledger__more:focus-visible,
.rr-ledger__receipt:focus-visible {
    outline: 2px solid var(--rr-ledger-ink);
    outline-offset: 2px;
}

/* The three durable numbers. On a phone LIFETIME PAID takes the full width
   and the two daily figures share the second row; desktop lines up three. */
.rr-ledger__stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--rr-ledger-border);
}

.rr-ledger__stat:first-child {
    grid-column: 1 / -1;
}

.rr-ledger__stat {
    display: grid;
    gap: 4px;
    min-width: 0;
    padding: 8px 10px;
    border: 1px solid var(--rr-ledger-border);
    border-radius: var(--rr-radius-m, 4px);
    background: var(--rr-panel, rgba(23, 21, 19, .96));
}

.rr-ledger__stat-label {
    font-size: 9px;
    font-weight: 900;
    letter-spacing: .16em;
    color: var(--rr-ledger-faint);
}

.rr-ledger__stat > b {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-family: var(--rr-font-mono, ui-monospace, monospace);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
    color: var(--rr-ledger-ink);
}

.rr-ledger__stat-lifetime {
    color: var(--rr-ledger-good);
}

.rr-ledger__stat-refill {
    font-family: var(--rr-font-mono, ui-monospace, monospace);
    font-size: 9px;
    font-weight: 900;
    letter-spacing: .1em;
    font-variant-numeric: tabular-nums;
    color: var(--rr-ledger-accent);
}

.rr-ledger__stat-refill[hidden] {
    display: none;
}

/* The scroll region: everything below the head and the stats. */
.rr-ledger__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 10px 16px;
    scrollbar-width: thin;
    scrollbar-color: color-mix(in srgb, var(--rr-ledger-accent) 45%, transparent) transparent;
}

.rr-ledger__error,
.rr-ledger__empty {
    margin: 0 0 10px;
    padding: 12px 14px;
    border-radius: var(--rr-radius-m, 4px);
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .12em;
    text-align: center;
}

.rr-ledger__error {
    color: var(--rr-ledger-bad);
    background: var(--rr-ledger-bad-soft);
}

.rr-ledger__empty {
    color: var(--rr-ledger-dim);
    background: var(--rr-panel, rgba(23, 21, 19, .96));
    border: 1px dashed var(--rr-ledger-border);
}

.rr-ledger__error[hidden],
.rr-ledger__empty[hidden] {
    display: none;
}

.rr-ledger__days {
    display: grid;
    gap: 14px;
}

.rr-ledger__day-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    padding: 0 2px 6px;
    border-bottom: 1px solid var(--rr-ledger-border);
}

.rr-ledger__day-label {
    font-size: 10px;
    font-weight: 900;
    letter-spacing: .18em;
    color: var(--rr-ledger-faint);
}

.rr-ledger__day-sum {
    font-family: var(--rr-font-mono, ui-monospace, monospace);
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    color: var(--rr-ledger-good);
}

.rr-ledger__day-rows {
    display: grid;
    gap: 4px;
    margin: 6px 0 0;
    padding: 0;
    list-style: none;
}

/* One payout: time · labels + mode · amount · status pill · receipt. */
.rr-ledger__row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas:
        "time main amount"
        "time pill receipt";
    align-items: center;
    column-gap: 10px;
    row-gap: 4px;
    min-width: 0;
    padding: 8px 10px;
    border-radius: var(--rr-radius-m, 4px);
    background: var(--rr-panel, rgba(23, 21, 19, .96));
    border: 1px solid transparent;
}

.rr-ledger__row[data-state="confirmed"],
.rr-ledger__row[data-state="final"] {
    border-color: color-mix(in srgb, var(--rr-ledger-good) 30%, transparent);
}

.rr-ledger__row[data-state="failed"] {
    border-color: color-mix(in srgb, var(--rr-ledger-bad) 35%, transparent);
}

.rr-ledger__time {
    grid-area: time;
    align-self: start;
    font-family: var(--rr-font-mono, ui-monospace, monospace);
    font-size: 10px;
    font-variant-numeric: tabular-nums;
    color: var(--rr-ledger-faint);
}

.rr-ledger__main {
    grid-area: main;
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.rr-ledger__labels {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .08em;
    color: var(--rr-ledger-ink);
}

.rr-ledger__mode {
    flex: 0 0 auto;
    padding: 1px 5px;
    border-radius: 999px;
    font-size: 8px;
    font-weight: 900;
    letter-spacing: .14em;
    color: var(--rr-ledger-accent);
    background: var(--rr-accent2-soft, rgba(255, 183, 74, .12));
}

.rr-ledger__mode[hidden] {
    display: none;
}

.rr-ledger__amount {
    grid-area: amount;
    justify-self: end;
    white-space: nowrap;
    font-family: var(--rr-font-mono, ui-monospace, monospace);
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--rr-ledger-ink);
}

.rr-ledger__row[data-state="retrying"] .rr-ledger__amount,
.rr-ledger__row[data-state="failed"] .rr-ledger__amount {
    color: var(--rr-ledger-faint);
    text-decoration: line-through;
}

/* Grey is queued, amber is signed/sent (pending, never a receipt), green is
   confirmed or final, RETRYING is inert, FAILED needs a manual claim. */
.rr-ledger__pill {
    grid-area: pill;
    justify-self: start;
    padding: 2px 7px;
    border-radius: 999px;
    font-size: 8px;
    font-weight: 900;
    letter-spacing: .14em;
    color: var(--rr-ledger-dim);
    background: color-mix(in srgb, var(--rr-ledger-dim) 18%, transparent);
}

.rr-ledger__row[data-state="signed"] .rr-ledger__pill,
.rr-ledger__row[data-state="sent"] .rr-ledger__pill {
    color: var(--rr-ledger-accent);
    background: var(--rr-accent2-soft, rgba(255, 183, 74, .12));
}

.rr-ledger__row[data-state="confirmed"] .rr-ledger__pill,
.rr-ledger__row[data-state="final"] .rr-ledger__pill {
    color: var(--rr-ink, #0d0b09);
    background: var(--rr-ledger-good);
}

.rr-ledger__row[data-state="final"] .rr-ledger__pill {
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--rr-ledger-good) 60%, transparent);
}

.rr-ledger__row[data-state="failed"] .rr-ledger__pill {
    color: var(--rr-ledger-bad);
    background: var(--rr-ledger-bad-soft);
}

.rr-ledger__receipt {
    grid-area: receipt;
    justify-self: end;
    white-space: nowrap;
    font-size: 9px;
    font-weight: 900;
    letter-spacing: .1em;
    color: var(--rr-ledger-good);
    text-decoration: underline;
    text-underline-offset: 3px;
}

.rr-ledger__row[data-state="sent"] .rr-ledger__receipt {
    color: var(--rr-ledger-accent);
}

.rr-ledger__receipt[hidden] {
    display: none;
}

.rr-ledger__foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 16px 0;
    border-top: 1px solid var(--rr-ledger-border);
}

.rr-ledger__note {
    min-width: 0;
    font-size: 8px;
    font-weight: 900;
    letter-spacing: .14em;
    color: var(--rr-ledger-faint);
}

.rr-ledger__more {
    flex: 0 0 auto;
    padding: 8px 14px;
    border: 1px solid var(--rr-border-strong, rgba(255, 183, 74, .48));
    border-radius: var(--rr-radius-m, 4px);
    background: transparent;
    color: var(--rr-ledger-accent);
    font: inherit;
    font-size: 10px;
    font-weight: 900;
    letter-spacing: .14em;
    cursor: pointer;
}

.rr-ledger__more:disabled {
    border-color: var(--rr-ledger-border);
    color: var(--rr-ledger-faint);
    cursor: default;
}

/* Desktop and tablets: a bounded card in the middle, not a bottom sheet. */
@media (min-width: 720px) {
    .rr-ledger {
        place-items: center;
        padding: 24px;
    }
    .rr-ledger__panel {
        width: min(640px, 100%);
        max-height: min(88dvh, 860px);
        border-bottom: 1px solid var(--rr-border-strong, rgba(255, 183, 74, .48));
        border-radius: var(--rr-radius-l, 8px);
        padding-bottom: 12px;
    }
    .rr-ledger__stats {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
    .rr-ledger__stat:first-child {
        grid-column: auto;
    }
    .rr-ledger__row {
        grid-template-columns: auto minmax(0, 1fr) auto auto auto;
        grid-template-areas: "time main pill amount receipt";
        column-gap: 12px;
    }
    .rr-ledger__pill {
        justify-self: end;
    }
    .rr-ledger__receipt {
        min-width: 64px;
        text-align: right;
    }
}

.rr-ledger[data-reduced-motion="true"] .rr-ledger__panel {
    animation: none;
}

@media (prefers-reduced-motion: reduce) {
    .rr-ledger__panel {
        animation: none;
    }
}
