/* ============================================
   Out-of-credits upgrade panel (credit_upgrade.js)
   Flat surfaces, theme tokens only. Centered dialog on desktop,
   bottom sheet on phones.
   ============================================ */

.pmu-root {
    position: fixed;
    inset: 0;
    z-index: 1100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
}

.pmu-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(1, 4, 9, 0.62);
    opacity: 0;
    transition: opacity 200ms ease;
}

.pmu-panel {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-height: calc(100dvh - 2 * var(--space-md));
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong, var(--border-color)) transparent;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-xl) var(--space-lg) var(--space-lg);
    color: var(--text-primary);
    text-align: center;
    opacity: 0;
    transform: translateY(8px) scale(0.98);
    transition: opacity 200ms ease, transform 200ms ease;
}

.pmu-root.is-open .pmu-backdrop { opacity: 1; }
.pmu-root.is-open .pmu-panel { opacity: 1; transform: none; }

.pmu-close {
    position: absolute;
    top: var(--space-sm);
    right: var(--space-sm);
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: var(--radius-full);
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.pmu-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.pmu-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto var(--space-md);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    background: var(--accent-primary-soft);
    color: var(--accent-primary);
}

.pmu-title {
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    line-height: 1.25;
    margin: 0 0 var(--space-xs);
}

.pmu-sub {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0 auto var(--space-lg);
    max-width: 34ch;
}

/* Billing toggle */
.pmu-toggle {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    margin-bottom: var(--space-md);
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
}
.pmu-toggle-btn {
    min-height: 36px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: var(--text-sm);
    font-weight: var(--font-semibold);
    cursor: pointer;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.pmu-toggle-btn.is-active {
    background: var(--bg-elevated);
    color: var(--text-primary);
    box-shadow: var(--shadow-sm);
}
.pmu-save {
    display: inline-block;
    margin-left: 4px;
    padding: 1px 6px;
    border-radius: var(--radius-full);
    background: var(--accent-primary-soft);
    color: var(--accent-primary);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
}

/* Plan card */
.pmu-plan {
    text-align: left;
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
}
.pmu-plan-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-sm);
}
.pmu-plan-name { font-weight: var(--font-bold); }
.pmu-price { color: var(--text-secondary); font-size: var(--text-sm); white-space: nowrap; }
.pmu-price strong {
    color: var(--text-primary);
    font-size: var(--text-xl);
    font-weight: var(--font-bold);
    font-variant-numeric: tabular-nums;
}
.pmu-plan-note {
    margin-top: 2px;
    font-size: var(--text-xs);
    color: var(--text-muted);
    text-align: right;
}
.pmu-features {
    list-style: none;
    margin: var(--space-md) 0 0;
    padding: var(--space-md) 0 0;
    border-top: 1px solid var(--border-light);
    display: grid;
    gap: var(--space-sm);
}
.pmu-features li {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    line-height: 1.4;
}
.pmu-check { color: var(--accent-primary); flex-shrink: 0; margin-top: 1px; }

/* Actions */
.pmu-cta,
.pmu-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    border-radius: var(--radius-md);
    font: inherit;
    font-weight: var(--font-semibold);
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast), opacity var(--transition-fast);
}
.pmu-cta {
    width: 100%;
    min-height: 48px;
    border: 0;
    background: var(--accent-primary);
    color: var(--text-inverse);
    font-size: var(--text-base);
}
.pmu-cta:hover:not(:disabled) { background: var(--accent-primary-hover); }
.pmu-secondary {
    min-height: 40px;
    padding: 0 var(--space-md);
    border: 1px solid var(--border-strong, var(--border-color));
    background: transparent;
    color: var(--text-primary);
    font-size: var(--text-sm);
    white-space: nowrap;
}
.pmu-secondary:hover:not(:disabled) { background: var(--bg-hover); }
.pmu-cta:disabled,
.pmu-secondary:disabled,
.pmu-close:disabled { opacity: 0.6; cursor: progress; }

.pmu-root :focus-visible {
    outline: none;
    box-shadow: var(--focus-ring, 0 0 0 3px rgba(46, 160, 67, 0.35));
}

.pmu-fine {
    margin: var(--space-sm) 0 0;
    font-size: var(--text-xs);
    color: var(--text-muted);
    line-height: 1.5;
}
.pmu-error {
    margin: var(--space-sm) 0 0;
    font-size: var(--text-sm);
    color: var(--accent-red-light);
}

.pmu-divider {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin: var(--space-lg) 0 var(--space-md);
    color: var(--text-muted);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.pmu-divider::before,
.pmu-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.pmu-credits {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-md);
    text-align: left;
}
.pmu-credits-title { font-weight: var(--font-semibold); font-size: var(--text-sm); }
.pmu-credits-sub { font-size: var(--text-xs); color: var(--text-muted); margin-top: 2px; }

.pmu-link {
    display: inline-block;
    margin-top: var(--space-lg);
    font-size: var(--text-sm);
    color: var(--text-link);
    text-decoration: none;
}
.pmu-link:hover { text-decoration: underline; }

.pmu-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: pmu-spin 700ms linear infinite;
}
@keyframes pmu-spin { to { transform: rotate(360deg); } }

/* Phones: bottom sheet */
@media (max-width: 640px) {
    .pmu-root { align-items: flex-end; padding: 0; }
    .pmu-panel {
        max-width: none;
        max-height: 92dvh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        border-bottom: 0;
        padding: var(--space-lg) var(--space-md) calc(var(--space-lg) + env(safe-area-inset-bottom, 0px));
        transform: translateY(24px);
    }
    .pmu-panel::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        margin: -8px auto var(--space-md);
        border-radius: var(--radius-full);
        background: var(--border-strong, var(--border-color));
    }
    .pmu-icon { width: 40px; height: 40px; margin-bottom: var(--space-sm); }
}

@media (max-width: 360px) {
    .pmu-credits { flex-direction: column; align-items: stretch; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
    .pmu-backdrop,
    .pmu-panel { transition: none; }
    .pmu-spinner { animation-duration: 1.6s; }
}
