/* ──────────────────────────────────────────────────────────────────────────
 * /css/_lib/upgrade.css
 *
 * MANIFEST
 * Purpose: TrustGuard Glass Tier-3 "Upgrade to Business" sheet (C108) —
 *          pairs with /js/_lib/upgrade.js (window.TG.upgrade). A backdrop
 *          scrim + a glass surface that slides up as a BOTTOM SHEET below
 *          the 640px content-column breakpoint and presents as a CENTERED
 *          glass CARD at/above it — same presentation contract as
 *          /css/_lib/dialog.css. Hosts a Stripe Elements card field in a
 *          Tier-2 recessed well.
 *
 * Glass:   Tier-3 recipe (LOCKED C97-A) built ENTIRELY from the Glass
 *          tokens in /css/tokens.css (--tier3-tint / --glass-blur /
 *          --glass-saturate / --glass-edge / --glass-shadow /
 *          --edge-highlight / --tier3-tint-opaque). Card well = Tier-2
 *          recessed (--tier2-bg / --tier2-inset / --hairline). Buttons
 *          consume the LOCKED C107-A --btn-primary-* / --btn-secondary-*
 *          tokens. NO hardcoded glass values. @supports not(backdrop-filter)
 *          → solid opaque-tint fallback.
 *
 * Cascade: A /css/_lib/ shared module (LOCKED C82-A). Loaded AFTER the
 *          shared base layer (tokens → … → shared-themes) and BEFORE the
 *          page CSS. Single-class `.tg-upg-*` rules — no page CSS competes.
 *
 * Dark-only: DARK is the authoritative value set (launch is dark-only per
 *          LOCKED C99-A). LIGHT values resolve from the provisional light
 *          token set — finalized at the Phase 4 light sprint.
 *
 * Precache: in sw.js PRECACHE_URLS (loaded by 9 portal pages — same
 *          rationale as dialog.css).
 *
 * Consumed by: the 7 tier-gate interstitial pages + profile.html +
 *          purchased-lead.html (the three retargeted Upgrade CTA surfaces).
 *
 * Shipped: C108 (Credits Glass conversion + upgrade routing).
 * ────────────────────────────────────────────────────────────────────────── */

/* ── Backdrop scrim — bottom-anchored sheet < 640px, centered card ≥ 640px ── */
.tg-upg-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}

.tg-upg-overlay.tg-upg-open {
  opacity: 1;
  pointer-events: auto;
}

/* ── Glass sheet surface (< 640px) ──────────────────────────────────────── */
.tg-upg {
  width: 100%;
  max-width: 640px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0;
  padding: var(--space-5) var(--space-5) calc(var(--space-5) + env(safe-area-inset-bottom));
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;

  /* Glass recipe — Tier 3 (LOCKED C97-A), tokens only */
  background: var(--tier3-tint);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-saturate));
  border: 1px solid var(--glass-edge);
  border-bottom: none;
  box-shadow: var(--glass-shadow), inset 0 1px 0 var(--edge-highlight);

  transform: translateY(100%);
  transition: transform 0.3s ease;
}

.tg-upg-overlay.tg-upg-open .tg-upg {
  transform: translateY(0);
}

/* Opaque-tint fallback where backdrop-filter is unsupported — AA legibility. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .tg-upg {
    background: var(--tier3-tint-opaque);
  }
}

/* ── Centered glass CARD (≥ 640px) ──────────────────────────────────────── */
@media (min-width: 640px) {
  .tg-upg-overlay {
    align-items: center;
  }
  .tg-upg {
    width: auto;
    min-width: 360px;
    max-width: 440px;
    padding-bottom: var(--space-5);
    border-radius: var(--radius-xl);
    border-bottom: 1px solid var(--glass-edge);
    transform: scale(0.96);
    transition: transform 0.2s ease;
  }
  .tg-upg-overlay.tg-upg-open .tg-upg {
    transform: scale(1);
  }
}

/* ── Title / plan line / body copy ──────────────────────────────────────── */
.tg-upg-title {
  margin: 0 0 var(--space-1-5);
  font-family: var(--font-sans);
  font-size: var(--text-xl);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
  color: var(--text);
}

.tg-upg-plan {
  margin: 0 0 var(--space-2);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  color: var(--red);
}

.tg-upg-copy {
  margin: 0 0 var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--text-md);
  font-weight: var(--weight-regular);
  line-height: var(--leading-relaxed);
  color: var(--text-muted);
}

/* ── Card field — Tier-2 recessed well (LOCKED C97-A) ───────────────────── */
.tg-upg-card-label {
  margin-bottom: var(--space-1-5);
  font-family: var(--font-sans);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--text-muted);
}

.tg-upg-card-well {
  padding: var(--space-3) var(--space-3-5);
  min-height: 44px;
  box-sizing: border-box;
  border-radius: var(--radius-md);
  background: var(--tier2-bg);
  border: 1px solid var(--hairline);
  box-shadow: var(--tier2-inset);
}

/* ── Inline error line (Stripe field errors + function failures) ────────── */
.tg-upg-err {
  display: none;
  margin: var(--space-2-5) 0 0;
  font-family: var(--font-sans);
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
  line-height: var(--leading-normal);
  color: var(--danger, var(--red));
}

.tg-upg-err.tg-upg-err-show {
  display: block;
}

/* ── Action buttons — Glass button system (LOCKED C107-A) ───────────────── */
.tg-upg-actions {
  display: flex;
  gap: var(--space-2-5);
  margin-top: var(--space-4);
}

.tg-upg-btn {
  flex: 1 1 0;
  min-height: 44px;
  padding: var(--space-2-5) var(--space-4);
  border-radius: var(--btn-radius);
  font-family: var(--font-sans);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  cursor: pointer;
  transition: transform 0.18s var(--ease-spring), filter 0.15s ease;
}

.tg-upg-btn:hover {
  filter: brightness(1.1);
}

.tg-upg-btn:active {
  transform: scale(var(--press-scale));
}

.tg-upg-btn:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

.tg-upg-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.tg-upg-confirm {
  background: var(--btn-primary-bg);
  border: var(--btn-primary-border);
  box-shadow: var(--btn-primary-shadow);
  color: var(--btn-primary-text);
}

.tg-upg-cancel {
  background: var(--btn-secondary-bg);
  border: var(--btn-secondary-border);
  box-shadow: var(--btn-secondary-shadow);
  color: var(--btn-secondary-text);
}

/* ── prefers-reduced-motion — no slide/scale, opacity cut-in only ────────── */
@media (prefers-reduced-motion: reduce) {
  .tg-upg-overlay {
    transition: opacity 0.001s linear;
  }
  .tg-upg,
  .tg-upg-overlay.tg-upg-open .tg-upg {
    transition: none;
    transform: none;
  }
  .tg-upg-btn {
    transition: filter 0.15s ease;
  }
}
