/* ─── Tier Widget (inside user popover) ─── */

.tier-widget {
    width: 100%;
    padding: 8px 10px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: background var(--transition-normal);
    text-align: left;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    -webkit-tap-highlight-color: transparent;
}

.tier-widget:hover {
    background: var(--border);
}

.tier-widget:active {
    transform: scale(0.98);
}

.tier-widget-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.tier-badge {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 15%, transparent);
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}

.tier-quota-text {
    font-size: 0.7rem;
    color: var(--text-muted);
    white-space: nowrap;
}

.tier-progress-track {
    background: var(--border);
    border-radius: var(--radius-full);
    height: 3px;
    overflow: hidden;
}

.tier-progress-bar {
    background: var(--accent);
    border-radius: var(--radius-full);
    height: 100%;
    min-width: 0;
    transition: width 0.4s ease, background-color 0.3s ease;
}

.tier-progress-bar.warning {
    background: var(--warning, #f59e0b);
}

.tier-progress-bar.critical {
    background: var(--error, #ef4444);
}

/* ─── Tier Info Modal ─── */

.tier-modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: var(--z-modal, 500);
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: flex-end;
    justify-content: center;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.tier-modal-backdrop.visible {
    display: flex;
}

.tier-modal-content {
    background: var(--bg-color);
    border-radius: var(--radius-lg, 16px) var(--radius-lg, 16px) 0 0;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow-y: auto;
    overscroll-behavior: contain;
    animation: tierModalSlideUp 0.25s ease-out;
    -webkit-overflow-scrolling: touch;
}

@keyframes tierModalSlideUp {
    from { transform: translateY(100%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.tier-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-color);
    z-index: 1;
}

.tier-modal-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.tier-modal-title .tier-badge {
    font-size: 0.7rem;
    padding: 2px 8px;
}

.tier-modal-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1rem;
    transition: background var(--transition-normal);
    -webkit-tap-highlight-color: transparent;
}

.tier-modal-close:hover {
    background: var(--border);
}

.tier-modal-body {
    padding: 16px 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Quota section */
.tier-quota-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tier-quota-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}

.tier-quota-detail {
    display: flex;
    align-items: baseline;
    gap: 6px;
}

.tier-quota-current {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.tier-quota-separator {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.tier-quota-limit {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    line-height: 1;
}

.tier-quota-period {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-left: auto;
}

.tier-modal-progress-track {
    background: var(--border);
    border-radius: var(--radius-full);
    height: 6px;
    overflow: hidden;
}

.tier-modal-progress-bar {
    background: var(--accent);
    border-radius: var(--radius-full);
    height: 100%;
    transition: width 0.4s ease;
}

.tier-modal-progress-bar.warning {
    background: var(--warning, #f59e0b);
}

.tier-modal-progress-bar.critical {
    background: var(--error, #ef4444);
}

.tier-token-usage {
    font-size: 12px;
    color: var(--text-muted, #71717a);
    margin-top: 6px;
}

/* ─── What's included: the two headline allowances ────────────────────────
   The plan-card redesign's core idea — two numbers a person can picture,
   replacing the raw provider slugs and model IDs this modal used to print.
   Styled entirely from theme variables so light/dark need no overrides. */
.tier-value-block {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--border);
    border: 1px solid var(--border);
    border-radius: var(--radius-md, 10px);
    overflow: hidden;

    /* Component-scoped supporting-text colour.
       The base palette has no token between --text-secondary (#71717a, only
       3.87:1 on the dark cell) and --text-primary (14.75:1, too loud for a
       sub-line), and both the unit label and the sub-line are small text that
       must clear 4.5:1. Rather than bend a global token used elsewhere, this
       component declares its own and overrides it per theme.
       Measured: 6.38:1 dark, 5.42:1 light. */
    --tier-support-color: #a1a1aa;
}

.light-theme .tier-value-block {
    --tier-support-color: var(--text-secondary);
}

.tier-value-cell {
    background: var(--input-bg, var(--panel-bg));
    padding: 12px 12px 11px;
    min-width: 0;   /* lets long values wrap instead of blowing out the grid */
}

.tier-value-num {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.05;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    /* break-word, NOT anywhere: `anywhere` permits a break at ANY character, so
       "Unlimited" rendered as "Unlimite / d" in a narrow cell. break-word only
       breaks a word that cannot otherwise fit. */
    overflow-wrap: break-word;
}

/* "≈" marker for the monthly-equivalent figure. The enforced cap is DAILY,
   so the monthly total is genuinely an estimate and must not read as exact. */
.tier-value-approx {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-right: 2px;
}

.tier-value-unit {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--tier-support-color, var(--text-secondary));
    margin-top: 3px;
}

.tier-value-sub {
    font-size: 0.72rem;
    line-height: 1.4;
    /* --text-secondary, not --text-muted: muted (#52525b on #121214) measures
       2.42:1, well under the 4.5:1 WCAG AA floor for text this size. This line
       carries the honest detail (the exact daily figure, what a credit buys),
       so it has to be readable rather than decorative. */
    color: var(--tier-support-color, var(--text-secondary));
    margin-top: 5px;
}

/* Capability ladder — replaces the old "Providers"/"Models" rows entirely. */
.tier-capability-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    padding: 2px 0;
}

.tier-capability-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--accent);
    flex: none;
}

@media (max-width: 480px) {
    /* Stacking beats squeezing: two big numbers side by side on a narrow
       phone truncates the sub-lines, which carry the honest detail. */
    .tier-value-block {
        grid-template-columns: 1fr;
    }
}

/* Features section */
.tier-features-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tier-feature-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.tier-feature-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--text-primary);
}

.tier-feature-item i {
    width: 16px;
    text-align: center;
    font-size: 0.75rem;
}

.tier-feature-allowed i {
    color: var(--accent);
}

.tier-feature-blocked i {
    color: var(--text-muted);
    opacity: 0.5;
}

.tier-feature-blocked .tier-feature-label {
    color: var(--text-muted);
}

.tier-feature-value {
    margin-left: auto;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Limits section */
.tier-limits-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.tier-limit-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 10px;
    font-size: 0.85rem;
}

.tier-limit-label {
    color: var(--text-secondary);
}

.tier-limit-value {
    font-weight: 600;
    color: var(--text-primary);
}

/* Feature-locked button styling */
.feature-locked {
    opacity: 0.45;
    pointer-events: none;
    cursor: not-allowed;
    position: relative;
    user-select: none;
}

/* Desktop: center modal */
@media (min-width: 600px) {
    .tier-modal-backdrop {
        align-items: center;
    }

    .tier-modal-content {
        border-radius: var(--radius-lg, 16px);
        max-height: 70vh;
    }

    @keyframes tierModalSlideUp {
        from { transform: translateY(20px); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }
}

/* ── Upgrade Prompt Overlay ──────────────────────────────── */

.upgrade-prompt-overlay {
    position: fixed;
    inset: 0;
    /* See --z-paywall in style.css: this sheet opens FROM settings (10003), the group panels
       (10004) and the 10050/10051 overlays, so a literal 10001 put it behind all of them. */
    z-index: var(--z-paywall, 10060);
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0);
    opacity: 0;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.upgrade-prompt-overlay.visible {
    opacity: 1;
    background: rgba(0, 0, 0, 0.5);
}

.upgrade-prompt-overlay.closing {
    opacity: 0;
}

.upgrade-prompt-sheet {
    background: var(--panel-bg, #1a1a2e);
    border: 1px solid var(--border, rgba(255,255,255,0.1));
    border-radius: 16px;
    padding: 28px 24px 20px;
    max-width: 380px;
    width: calc(100% - 32px);
    text-align: center;
    transform: translateY(20px);
    transition: transform 0.25s ease;
}

.upgrade-prompt-overlay.visible .upgrade-prompt-sheet {
    transform: translateY(0);
}

.upgrade-prompt-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.upgrade-prompt-header svg {
    color: var(--accent, #6366f1);
    width: 40px;
    height: 40px;
}

/* Icon-font variant (upgradePrompt.js passes a Font Awesome class key). */
.upgrade-prompt-header i {
    color: var(--accent, #6366f1);
    font-size: 32px;
    line-height: 40px;
}

.upgrade-prompt-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary, #e0e0e0);
}

.upgrade-trial-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 12px;
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.upgrade-prompt-message {
    margin: 0 0 8px;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-secondary, #a0a0b0);
}

.upgrade-prompt-current {
    margin: 0 0 20px;
    font-size: 13px;
    color: var(--text-tertiary, #707080);
}

.upgrade-prompt-current strong {
    color: var(--text-primary, #e0e0e0);
}

.upgrade-prompt-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.upgrade-prompt-btn {
    border: none;
    border-radius: 10px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease, transform 0.1s ease;
}

.upgrade-prompt-btn:active {
    transform: scale(0.98);
}

.upgrade-prompt-btn.primary {
    background: var(--accent-cta, var(--accent, #6366f1));
    color: #fff;
}

.upgrade-prompt-btn.primary:hover {
    opacity: 0.9;
}

.upgrade-prompt-btn.secondary {
    background: transparent;
    color: var(--text-secondary, #a0a0b0);
}

.upgrade-prompt-btn.secondary:hover {
    color: var(--text-primary, #e0e0e0);
}

/* Mobile: bottom sheet variant */
.upgrade-prompt-overlay.mobile {
    align-items: flex-end;
}

.upgrade-prompt-overlay.mobile .upgrade-prompt-sheet {
    max-width: 100%;
    width: 100%;
    border-radius: 20px 20px 0 0;
    padding-bottom: max(20px, var(--safe-area-inset-bottom, env(safe-area-inset-bottom)));
    transform: translateY(100%);
}

.upgrade-prompt-overlay.mobile.visible .upgrade-prompt-sheet {
    transform: translateY(0);
}

/* Light theme overrides */
.light-theme .upgrade-prompt-sheet {
    background: var(--panel-bg, #fff);
    border-color: var(--border, rgba(0,0,0,0.1));
}

.light-theme .upgrade-prompt-header h3 {
    color: var(--text-primary, #1a1a2e);
}

.light-theme .upgrade-prompt-message {
    color: var(--text-secondary, #555);
}

.light-theme .upgrade-prompt-current {
    color: var(--text-tertiary, #888);
}

.light-theme .upgrade-prompt-current strong {
    color: var(--text-primary, #1a1a2e);
}

.light-theme .upgrade-prompt-btn.secondary {
    color: var(--text-secondary, #555);
}

.light-theme .upgrade-prompt-btn.secondary:hover {
    color: var(--text-primary, #1a1a2e);
}

/* ─── Trial-first onboarding prompt (extends the upgrade-prompt overlay) ─────────
   Mounted by js/onboarding/trialPrompt.js for eligible NEW accounts only. Reuses the
   .upgrade-prompt-* shell above; rules here are the trial-specific additions. */
/* Trial sheet allowance strip — a compact two-up of the same headline numbers
   the plan cards show. Horizontal here because the sheet is short and the
   sub-lines are omitted; only the number and its unit appear. */
.trial-prompt-values {
    display: flex;
    gap: 10px;
    margin: 14px 0 4px;
}

.trial-prompt-value {
    flex: 1 1 0;
    min-width: 0;
    background: var(--input-bg, var(--panel-bg));
    border: 1px solid var(--border);
    border-radius: var(--radius-md, 10px);
    padding: 10px 12px;
    text-align: center;
}

.trial-prompt-value-num {
    display: block;
    font-size: 1.2rem;
    font-weight: 700;
    line-height: 1.1;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    /* break-word, NOT anywhere: `anywhere` permits a break at ANY character, so
       "Unlimited" rendered as "Unlimite / d" in a narrow cell. break-word only
       breaks a word that cannot otherwise fit. */
    overflow-wrap: break-word;
}

.trial-prompt-value-unit {
    display: block;
    font-size: 0.63rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    /* #a1a1aa clears AA on the dark sheet ground; --text-secondary does not. */
    color: #a1a1aa;
    margin-top: 3px;
}

.light-theme .trial-prompt-value-unit {
    color: var(--text-secondary);
}

.trial-prompt-features {
    list-style: none;
    margin: 0 0 14px;
    padding: 0;
    text-align: left;
}

.trial-prompt-features li {
    position: relative;
    padding: 4px 0 4px 26px;
    color: var(--text-secondary, #aab);
    font-size: 13.5px;
}

.trial-prompt-features li::before {
    content: '✓';
    position: absolute;
    left: 4px;
    color: var(--accent, #6366f1);
    font-weight: 700;
}

.trial-prompt-error {
    margin: 0 0 12px;
    color: #ef4444;
    font-size: 13px;
}

.trial-prompt-dismiss {
    display: block;
    margin: 10px auto 0;
    padding: 8px 12px;           /* comfortable touch target */
    background: none;
    border: none;
    color: var(--text-tertiary, #778);
    font-size: 12.5px;
    text-decoration: underline;
    cursor: pointer;
}

.trial-prompt-dismiss:hover {
    color: var(--text-secondary, #aab);
}

.light-theme .trial-prompt-features li {
    color: var(--text-secondary, #555);
}

.light-theme .trial-prompt-dismiss {
    color: var(--text-tertiary, #888);
}

.light-theme .trial-prompt-dismiss:hover {
    color: var(--text-secondary, #555);
}

/* ── Paywall (P3, iOS IAP) ───────────────────────────────────────────
   Lives here, beside the .upgrade-prompt-* family it reuses, because this file is
   always-loaded from index.html. A lazily-loaded fragment would leave the sheet
   unstyled until the user happened to open some other panel first.

   SMALL TEXT USES A DERIVED COLOR, NOT --text-secondary. That token is fine in four
   themes and fails in the fifth: in base Onyx it is #71717a on a #09090b sheet, 4.12:1,
   under the 4.5:1 AA threshold for normal-weight text — and the text affected included
   the App Store disclosures at 0.78rem, the text that least deserves to be hard to read.
   Mixing --text-primary toward --panel-bg keeps the visual hierarchy while deriving from
   each theme own tokens: 7.81:1 Onyx, 7.23 plum, 5.96 light, 6.19 graphite, 6.53 press.
   Pinned by tests/unit/paywall-contrast.test.mjs.
   Deliberately does NOT use --text-tertiary: that token has 7 uses and 0
   definitions repo-wide, so it resolves to its hardcoded fallback and no theme can
   override it. --text-secondary is real in all five themes.                       */

.paywall-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 4px 0 14px;
}

.paywall-option {
    display: flex;
    align-items: baseline;
    justify-content: flex-start;
    gap: 8px;
    min-height: 48px;          /* touch target */
    text-align: left;
}

.paywall-option-name {
    flex: 1 1 auto;
    font-weight: 600;
    color: var(--text-primary);
}

.paywall-option-price {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--text-primary);
}

.paywall-option-period {
    font-size: 0.85em;
    color: var(--text-primary);
    color: color-mix(in srgb, var(--text-primary) 70%, var(--panel-bg));
}

/* The recommended plan. Emphasis only — it must not be the only readable option. */
.paywall-option.hero {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent) inset;
}

/* Diagnostic line on the no-sale sheet: the failure reason + the SDK's own message. Muted on
   purpose — it exists so a screenshot identifies the failure, not to alarm the user. */
.paywall-diag {
    margin: 0 0 10px;
    font-size: 0.72rem;
    line-height: 1.4;
    word-break: break-word;
    /* Muted via an OPAQUE mix, never opacity: 0.55 alpha over --text-primary lands at ~3.7-4.0:1 in
       the light/graphite/press themes — under AA's 4.5:1 for text this small. Same recipe as
       .paywall-entitled-note, which the contrast gate already covers. */
    color: var(--text-primary);
    color: color-mix(in srgb, var(--text-primary) 72%, var(--panel-bg));
}

.paywall-entitled-note {
    margin: 0 0 14px;
    color: var(--text-primary);
    color: color-mix(in srgb, var(--text-primary) 70%, var(--panel-bg));
    font-size: 0.9rem;
    line-height: 1.45;
}

.paywall-disclosures {
    margin: 12px 0 0;
    font-size: 0.78rem;
    line-height: 1.5;
    color: var(--text-primary);
    color: color-mix(in srgb, var(--text-primary) 70%, var(--panel-bg));
}

/* The disclosures are BUTTONS, not anchors -- see the note in paywallView.js. As anchors they lost
   a cascade fight with themes/light.css`s `html.light-theme a`, which painted App Store legal text
   blue at 3.68:1 on white. Nothing in this codebase colors a bare button, so no specificity
   escalation is needed here and none should be added.                                            */
.paywall-disclosure-link {
    background: none;
    border: 0;
    padding: 0;
    font: inherit;
    color: var(--text-primary);
    color: color-mix(in srgb, var(--text-primary) 70%, var(--panel-bg));
    text-decoration: underline;
    cursor: pointer;
}

.paywall-disclosure-link:hover {
    color: var(--text-primary);
}

/* ⚠️ The skeleton needs its OWN dimensions. It is an empty element, so without a
   height the LOADING state renders a blank sheet — the precise "looks broken"
   impression that showing LOADING instead of UNAVAILABLE exists to avoid.
   Animates opacity only (GPU-composited), per the project's animation rule.       */
.paywall-skeleton {
    min-height: 132px;
    border-radius: 10px;
    background: var(--border);
    opacity: 0.35;
    animation: paywall-skeleton-pulse 1.4s ease-in-out infinite;
}

@keyframes paywall-skeleton-pulse {
    0%, 100% { opacity: 0.25; }
    50%      { opacity: 0.5; }
}

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

@media (max-width: 768px) {
    .paywall-option { min-height: 52px; }
    .paywall-disclosures { font-size: 0.75rem; }

    /* Restore and Not-now inherit .upgrade-prompt-btn.secondary, which measures 41px -- under the
       44pt minimum, on the platform this sheet exists for. Measured in a 375px viewport, not
       assumed. Scoped to the paywall on purpose: the same buttons are shared with the upgrade and
       trial prompts, and resizing those is a separate change with its own regression surface.    */
    .paywall-overlay .upgrade-prompt-actions .upgrade-prompt-btn {
        min-height: 44px;
    }
}
