/* tempo-bridge flyout — premium conversion card. Brand colours/fonts are injected at runtime
   as CSS custom properties from the tenant's brand tokens; every var has a neutral fallback so
   an unthemed / offline store still renders cleanly. color-mix is used only for decorative tints
   (glow, rings) with solid fallbacks declared first, so older engines degrade gracefully. */

.tempo-flyout {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  background: var(--tempo-bg, #ffffff);
  color: var(--tempo-text, #18181b);
  border-radius: 18px;
  box-shadow:
    0 1px 1px rgba(0, 0, 0, 0.04),
    0 12px 24px -8px rgba(0, 0, 0, 0.18),
    0 28px 56px -20px rgba(0, 0, 0, 0.18);
  z-index: 2147483000;
  overflow: hidden;
  font-family: var(--tempo-font, ui-sans-serif), system-ui, -apple-system, "Segoe UI", sans-serif;
  /* Desktop: slide in from the right edge (Klaviyo-style). Mobile overrides to a bottom sheet. */
  transform: translateX(calc(100% + 28px));
  opacity: 0;
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s ease;
  will-change: transform, opacity;
}

/* Soft brand-tinted glow behind the headline area. */
.tempo-flyout::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 140px;
  pointer-events: none;
  background: radial-gradient(130% 90% at 30% -30%, color-mix(in srgb, var(--tempo-primary, #6d28d9) 15%, transparent), transparent 72%);
}

.tempo-flyout.is-visible { opacity: 1; transform: translateX(0); }

/* ── Tempo-owned frame for AI-generated custom designs ──────────────────────────────────────────
   When the operator approves an AI-generated design, the AI owns ONLY the inner .tempo-flyout card.
   Tempo owns the chrome: this frame carries position: fixed + the entrance animation + an always-
   visible close button. The class lives OUTSIDE the tempo-flyout* namespace on purpose: the server
   sanitiser prefixes every AI selector with .tempo-flyout, so the AI CSS can never target
   .tempo-frame / .tempo-frame__close. The transform here also establishes a containing block, so any
   stray position: fixed inside the AI design is trapped within the frame. Universal, no browser-
   specific rule. */
.tempo-frame {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 380px;
  max-width: calc(100vw - 32px);
  max-height: calc(100dvh - 48px);
  z-index: 2147483000;
  border-radius: 18px;
  overflow: hidden;
  box-shadow:
    0 1px 1px rgba(0, 0, 0, 0.04),
    0 12px 24px -8px rgba(0, 0, 0, 0.18),
    0 28px 56px -20px rgba(0, 0, 0, 0.18);
  transform: translateX(calc(100% + 28px));
  opacity: 0;
  transition: transform 0.5s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s ease;
  will-change: transform, opacity;
}
.tempo-frame.is-visible { opacity: 1; transform: translateX(0); }

/* Neutralise the AI root so it fills the frame and can never break out of document flow. The AI's
   scoped CSS targets .tempo-flyout; these !important resets win and keep the frame in control. */
.tempo-frame > .tempo-flyout {
  position: static !important;
  inset: auto !important;
  top: auto !important;
  right: auto !important;
  bottom: auto !important;
  left: auto !important;
  width: 100% !important;
  max-width: 100% !important;
  margin: 0 !important;
  transform: none !important;
  /* The .tempo-flyout base rule keeps opacity:0 for the template's own entrance (revealed by adding
     .is-visible to the card). In a frame the ENTRANCE is the frame's job, so force the card opaque —
     otherwise it would stay invisible. */
  opacity: 1 !important;
  min-height: 0 !important;
  box-shadow: none !important;
}

/* Always-visible close, readable on ANY background (light or dark AI design): solid translucent
   dark disc + white X + a 1px white halo + drop shadow so it never disappears into the design. */
.tempo-frame__close {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 2;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: #ffffff;
  background: rgba(17, 17, 19, 0.55);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.55), 0 2px 10px rgba(0, 0, 0, 0.3);
  transition: background 0.15s ease, transform 0.12s ease;
}
.tempo-frame__close:hover { background: rgba(17, 17, 19, 0.78); }
.tempo-frame__close:active { transform: scale(0.94); }

/* Hero product image band (auto-selected per store). Present only when .has-media. */
.tempo-flyout__media { position: relative; height: 150px; overflow: hidden; background: color-mix(in srgb, var(--tempo-primary, #6d28d9) 8%, #f4f4f5); }
.tempo-flyout__media img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Brand-coloured accent laid over the photo (the AI-composed accent will parameterise this later). */
.tempo-flyout__media-accent {
  position: absolute;
  inset: 0;
  pointer-events: none;
  /* The accent colour + intensity come from the AI-composed spec (--tempo-accent / strength),
     falling back to the brand primary at a soft default. Solid fallback first for old engines. */
  background:
    linear-gradient(180deg, transparent 45%, rgba(255, 255, 255, 0.85) 100%),
    radial-gradient(120% 80% at 85% 10%, rgba(109, 40, 217, 0.26), transparent 62%);
  background:
    linear-gradient(180deg, transparent 45%, color-mix(in srgb, var(--tempo-bg, #fff) 88%, transparent) 100%),
    radial-gradient(120% 80% at 85% 10%, color-mix(in srgb, var(--tempo-accent, var(--tempo-primary, #6d28d9)) calc(var(--tempo-accent-strength, 0.24) * 100%), transparent), transparent 62%);
}
/* When there's a media band, the glow behind the headline is redundant — drop it. */
.tempo-flyout.has-media::before { display: none; }
.tempo-flyout.has-media .tempo-flyout__body { padding-top: 22px; }

.tempo-flyout__body { position: relative; padding: 30px 28px 24px; }

.tempo-flyout__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(125, 125, 135, 0.12);
  background: color-mix(in srgb, var(--tempo-text, #000) 7%, transparent);
  color: var(--tempo-text, #52525b);
  cursor: pointer;
  opacity: 0.65;
  transition: opacity 0.15s ease, background 0.15s ease;
}
.tempo-flyout__close:hover { opacity: 1; background: color-mix(in srgb, var(--tempo-text, #000) 13%, transparent); }

.tempo-flyout__badge { display: inline-flex; align-items: baseline; margin-bottom: 14px; }
.tempo-flyout__badge-num {
  font-family: var(--tempo-font-heading, var(--tempo-font, inherit)), system-ui, sans-serif;
  font-size: 36px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--tempo-primary, #6d28d9);
  font-variant-numeric: tabular-nums;
}
.tempo-flyout.is-visible .tempo-flyout__badge-num {
  animation: tempo-pop 0.5s 0.14s cubic-bezier(0.22, 1.4, 0.4, 1) both;
}

.tempo-flyout__title {
  margin: 0 0 6px;
  font-size: 21px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.01em;
  padding-right: 22px;
  font-family: var(--tempo-font-heading, var(--tempo-font, inherit)), system-ui, sans-serif;
}
.tempo-flyout__subtitle { margin: 0 0 18px; font-size: 14px; line-height: 1.5; opacity: 0.72; }

.tempo-flyout__form { display: flex; flex-direction: column; gap: 10px; }
.tempo-flyout__form input[type="email"] {
  width: 100%;
  padding: 13px 15px;
  font-size: 15px;
  font-family: inherit;
  color: var(--tempo-text, #18181b);
  background: var(--tempo-bg, #fff);
  border: 1.5px solid rgba(125, 125, 135, 0.32);
  border-color: color-mix(in srgb, var(--tempo-text, #0a0a0a) 16%, transparent);
  border-radius: var(--tempo-radius, 11px);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.tempo-flyout__form input[type="email"]::placeholder { color: rgba(125, 125, 135, 0.8); color: color-mix(in srgb, var(--tempo-text, #000) 42%, transparent); }
.tempo-flyout__form input[type="email"]:focus {
  outline: none;
  border-color: var(--tempo-primary, #6d28d9);
  box-shadow: 0 0 0 3px rgba(109, 40, 217, 0.18);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--tempo-primary, #6d28d9) 22%, transparent);
}

.tempo-flyout__submit {
  position: relative;
  padding: 13px 16px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: 0;
  border-radius: var(--tempo-radius, 11px);
  color: var(--tempo-on-primary, #ffffff);
  background: var(--tempo-primary, #6d28d9);
  box-shadow: 0 8px 18px -8px rgba(109, 40, 217, 0.7);
  box-shadow: 0 8px 18px -8px color-mix(in srgb, var(--tempo-primary, #6d28d9) 70%, transparent);
  transition: transform 0.12s ease, filter 0.15s ease;
}
.tempo-flyout__submit:hover { filter: brightness(1.07); transform: translateY(-1px); }
.tempo-flyout__submit:active { transform: translateY(0); }
.tempo-flyout__submit:disabled { cursor: wait; }
.tempo-flyout__submit.is-loading { color: transparent; }
.tempo-flyout__submit.is-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: var(--tempo-on-primary, #fff);
  border-radius: 50%;
  animation: tempo-spin 0.6s linear infinite;
}

.tempo-flyout__note { margin: 13px 0 0; font-size: 11.5px; text-align: center; opacity: 0.5; }

.tempo-flyout__message { font-size: 13px; margin-top: 10px; min-height: 0; }
.tempo-flyout__message--error { color: #dc2626; }

.tempo-flyout__success { padding: 10px 0 8px; text-align: center; }
.tempo-flyout__check {
  width: 58px;
  height: 58px;
  margin: 0 auto 16px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--tempo-primary, #16a34a);
  background: rgba(109, 40, 217, 0.13);
  background: color-mix(in srgb, var(--tempo-primary, #16a34a) 14%, transparent);
  animation: tempo-pop 0.42s cubic-bezier(0.22, 1.4, 0.4, 1) both;
}
.tempo-flyout__success-text { margin: 0; font-size: 15px; line-height: 1.5; font-weight: 500; }
.tempo-flyout__success-title {
  margin: 0 0 6px; font-size: 19px; font-weight: 700; letter-spacing: -0.01em;
  font-family: var(--tempo-font-heading, var(--tempo-font, inherit)), system-ui, sans-serif;
}
.tempo-flyout__success-fine { margin: 14px 0 0; font-size: 12.5px; line-height: 1.5; opacity: 0.62; }

/* The inline discount code reveal — the hero of the success state. */
.tempo-flyout__code {
  display: flex; align-items: stretch; margin: 16px auto 0; max-width: 300px;
  border: 2px dashed color-mix(in srgb, var(--tempo-accent, var(--tempo-primary, #6d28d9)) 55%, transparent);
  border-radius: var(--tempo-radius, 12px);
  background: color-mix(in srgb, var(--tempo-accent, var(--tempo-primary, #6d28d9)) 6%, transparent);
  overflow: hidden;
}
.tempo-flyout__code-value {
  flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center;
  padding: 12px 14px; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 18px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--tempo-accent, var(--tempo-primary, #6d28d9));
  user-select: all; -webkit-user-select: all; white-space: nowrap; overflow-x: auto;
}
.tempo-flyout__copy {
  flex: none; border: 0; cursor: pointer; padding: 0 16px;
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--tempo-on-primary, #fff); background: var(--tempo-accent, var(--tempo-primary, #6d28d9));
  transition: filter 0.15s ease, background 0.15s ease;
}
.tempo-flyout__copy:hover { filter: brightness(1.08); }
.tempo-flyout__copy.is-copied { background: #16a34a; }

@keyframes tempo-pop { from { transform: scale(0.55); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes tempo-spin { to { transform: rotate(360deg); } }

/* Mobile: full-width bottom sheet sliding up from the edge. */
@media (max-width: 480px) {
  .tempo-flyout {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    border-radius: 22px 22px 0 0;
    transform: translateY(100%);
  }
  .tempo-flyout.is-visible { transform: translateY(0); }
  .tempo-flyout__body { padding: 28px 22px calc(22px + env(safe-area-inset-bottom, 0px)); }
  .tempo-flyout__badge-num { font-size: 40px; }

  /* AI custom design: same bottom-sheet behaviour on the frame, larger close tap target. */
  .tempo-frame {
    right: 0;
    left: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    max-height: 92dvh;
    border-radius: 22px 22px 0 0;
    transform: translateY(100%);
  }
  .tempo-frame.is-visible { transform: translateY(0); }
  .tempo-frame__close { width: 40px; height: 40px; top: 14px; right: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .tempo-flyout { transition: opacity 0.2s ease; transform: none; }
  .tempo-flyout.is-visible { transform: none; }
  .tempo-flyout.is-visible .tempo-flyout__badge-num,
  .tempo-flyout__check { animation: none; }
  .tempo-frame { transition: opacity 0.2s ease; transform: none; }
  .tempo-frame.is-visible { transform: none; }
}
