/**
 * Credit Meter — header widget
 *
 * Small ring + remaining-number, sits in the app header next to the
 * Charter Member badge. Ambient awareness only; click to dashboard for
 * detail.
 *
 * Learning Notes:
 * - The ring is a single CSS conic-gradient: it draws a coloured arc
 *   from 0deg to (progress * 3.6deg), then transparent the rest of the
 *   way. The "hole" in the middle is a white pseudo-element absolutely
 *   positioned with `inset` (a shorthand for top/right/bottom/left), so
 *   the visible coloured part becomes a ring rather than a filled disk.
 * - The progress value lives in a CSS custom property
 *   (--credit-meter-progress, 0-100). JS only ever sets that and the
 *   colour token — the geometry is pure CSS. This is why no canvas / no
 *   JS render loop is needed.
 * - Colour state is also a CSS custom property (--credit-meter-color).
 *   JS picks the right brand token based on remaining %; the CSS
 *   doesn't care which token it gets.
 * - The transition on `background` makes the ring animate smoothly
 *   when the progress value changes after a generation completes —
 *   the subtle "yes, that cost X" feedback that replaces compulsive
 *   dashboard checking.
 */

.credit-meter {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: 0;
    color: var(--color-text-muted);
    text-decoration: none;
    border: none;
    background: transparent;
    cursor: pointer;
    position: relative;
}

.credit-meter:hover,
.credit-meter:focus-visible {
    color: var(--color-text);
}

.credit-meter:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 4px;
    border-radius: var(--radius-sm);
}

.credit-meter[hidden] {
    display: none;
}

.credit-meter__ring {
    position: relative;
    display: inline-block;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: conic-gradient(
        var(--credit-meter-color, var(--color-primary)) 0deg,
        var(--credit-meter-color, var(--color-primary))
            calc(var(--credit-meter-progress, 100) * 3.6deg),
        var(--color-bg-alt) calc(var(--credit-meter-progress, 100) * 3.6deg),
        var(--color-bg-alt) 360deg
    );
    transition: background 600ms ease;
    flex-shrink: 0;
}

.credit-meter__ring::after {
    content: "";
    position: absolute;
    inset: 4px;
    background: var(--color-white);
    border-radius: 50%;
}

.credit-meter__value {
    display: inline-flex;
    align-items: baseline;
    gap: 0.35em;
    line-height: 1;
}

.credit-meter__number {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-medium);
    font-variant-numeric: tabular-nums;
    line-height: 1;
}

/* "credits" label — slightly muted next to the number so the figure
 * stays the visual anchor. Same font-size as the number to keep the
 * baseline consistent. */
.credit-meter__label {
    font-size: var(--font-size-sm);
    font-weight: var(--font-weight-regular, 400);
    color: var(--color-text-muted);
    line-height: 1;
}

.credit-meter:hover .credit-meter__label,
.credit-meter:focus-visible .credit-meter__label {
    color: inherit;
}

/* Tooltip — appears on hover/focus. CSS-only, no JS toggle.
 *
 * Learning Notes:
 * - The tooltip is positioned absolutely below the meter and revealed
 *   by changing opacity + visibility on parent hover/focus. We can't
 *   use display:none because that breaks the transition.
 * - role="tooltip" on the markup pairs with aria-describedby on the
 *   meter so screen readers announce the credit count when focus lands
 *   on the meter.
 */
.credit-meter__tooltip {
    position: absolute;
    top: calc(100% + var(--space-2));
    right: 0;
    padding: var(--space-2) var(--space-3);
    background: var(--color-dark);
    color: var(--color-white);
    font-size: var(--font-size-xs);
    line-height: 1.3;
    white-space: nowrap;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--transition-fast), visibility var(--transition-fast);
    z-index: 10;
}

.credit-meter:hover .credit-meter__tooltip,
.credit-meter:focus-visible .credit-meter__tooltip {
    opacity: 1;
    visibility: visible;
}

/* Loading state — ring is dimmed, no colour, no number. Prevents the
 * "0 / 3000" flash before the API response lands. */
.credit-meter[data-state="loading"] .credit-meter__ring {
    background: var(--color-bg-alt);
    opacity: 0.5;
}

.credit-meter[data-state="loading"] .credit-meter__value {
    visibility: hidden;
}
