/* ============================================================
   Popup frame — the public renderer and the editor preview share this.
   Everything is token-driven; the only literals are the scrim and the
   per-element dynamic values the admin authored from the token list.
   ============================================================ */

.otk-popup-overlay {
  position: fixed;
  inset: 0;
  /* Above everything, including the admin sidebar/navbar: site navbar 1200,
     nav dropdowns 10001–10010, messaging/toast layers 99999, the site context
     menu 2147483000. A promo is an overlay on the whole document, so it wins
     against every other layer; nothing in the shell paints over it. */
  z-index: 2147483600;
  display: flex;
  align-items: center;
  justify-content: center;
  /* --pf-safe-top is the navbar's bottom edge, measured by popup-loader.js.
     The plate is centred in the viewport but never underneath the navbar. */
  padding: calc(var(--pf-safe-top, 0px) + 16px) 16px 16px;
  /* Opaque scrim: a popup never shows the page through its own plate. */
  background: rgba(9, 13, 20, 0.62);
  opacity: 0;
  transition: opacity 160ms ease;
}

.otk-popup-overlay.is-open { opacity: 1; }

[data-theme="dark"] .otk-popup-overlay { background: rgba(2, 5, 10, 0.72); }

.otk-popup-frame {
  position: relative;
  width: min(100%, var(--pf-w, 460px));
  max-height: min(900px, calc(100vh - var(--pf-safe-top, 0px) - 32px));
  max-height: min(900px, calc(100dvh - var(--pf-safe-top, 0px) - 32px));
  overflow: auto;
  background: var(--pf-bg, var(--color-surface, var(--white, #fff)));
  color: var(--color-on-surface, var(--ink, #16181d));
  border: 1px solid var(--color-border, var(--line, #e4e6ea));
  border-radius: var(--pf-radius, 16px);
  box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.06));
  transform: translateY(6px) scale(0.995);
  transition: transform 180ms cubic-bezier(0.22, 1, 0.36, 1);
}

.otk-popup-overlay.is-open .otk-popup-frame { transform: none; }

.otk-popup-stage {
  position: relative;
  width: var(--pf-w, 460px);
  height: var(--pf-h, 340px);
  max-width: 100%;
}

.otk-popup-el { position: absolute; box-sizing: border-box; }
.otk-popup-el > * { box-sizing: border-box; }

.otk-popup-text {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.otk-popup-text a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }

.otk-popup-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.otk-popup-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 100%;
  min-height: 40px;
  padding: 0 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease;
}

.otk-popup-btn.is-primary {
  background: var(--color-primary, var(--accent, #1f4e46));
  color: var(--white, #fff);
}

.otk-popup-btn.is-primary:hover,
.otk-popup-btn.is-primary:focus-visible {
  background: var(--color-primary-hover, var(--accent-hover, #173d37));
}

.otk-popup-btn.is-secondary {
  background: var(--white, #fff);
  border-color: var(--color-border, var(--line, #e4e6ea));
  color: var(--color-on-surface, var(--ink, #16181d));
}

.otk-popup-btn.is-secondary:hover,
.otk-popup-btn.is-secondary:focus-visible {
  background: var(--color-surface, #f6f7f8);
}

.otk-popup-btn.is-ghost {
  background: transparent;
  color: var(--color-primary, var(--accent, #1f4e46));
}

.otk-popup-btn.is-ghost:hover,
.otk-popup-btn.is-ghost:focus-visible {
  background: var(--color-primary-soft, rgba(31, 78, 70, 0.08));
}

.otk-popup-btn:focus-visible,
.otk-popup-close:focus-visible {
  outline: 2px solid var(--color-primary, var(--accent, #1f4e46));
  outline-offset: 2px;
}

.otk-popup-box {
  width: 100%;
  height: 100%;
  border: 1px solid transparent;
}

.otk-popup-divider { width: 100%; background: var(--color-border, var(--line, #e4e6ea)); }

.otk-popup-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 9999;
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 999px;
  border: 1px solid var(--color-border, var(--line, #e4e6ea));
  background: var(--white, #fff);
  color: var(--color-on-surface, var(--ink, #16181d));
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.otk-popup-close:hover { background: var(--color-surface, #f6f7f8); }

/* Token colour utilities, shared by renderer and editor preview. */
.pf-t-ink { color: var(--color-on-surface, var(--ink, #16181d)); }
.pf-t-text { color: var(--color-on-surface, var(--text, #3a3f48)); }
.pf-t-muted { color: var(--color-on-muted, var(--muted, #6b7280)); }
.pf-t-white { color: #ffffff; }
.pf-t-surface { color: var(--color-surface, #f6f7f8); }
.pf-t-accent { color: var(--color-primary, var(--accent, #1f4e46)); }

.pf-bg-white { background: var(--white, #fff); }
.pf-bg-surface { background: var(--color-surface, #f6f7f8); }
.pf-bg-ink { background: var(--color-on-surface, var(--ink, #16181d)); }
.pf-bg-text { background: var(--color-on-surface, var(--text, #3a3f48)); }
.pf-bg-muted { background: var(--color-border, #e4e6ea); }
.pf-bg-accent { background: var(--color-primary, var(--accent, #1f4e46)); }

/* dark theme keeps the plate opaque, never transparent */
[data-theme="dark"] .otk-popup-frame { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55); }

@media (max-width: 480px) {
  .otk-popup-overlay {
    padding: calc(var(--pf-safe-top, 0px) + 12px) 12px calc(12px + env(safe-area-inset-bottom, 0px));
    align-items: flex-end;
  }
  .otk-popup-frame { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .otk-popup-overlay,
  .otk-popup-frame,
  .otk-popup-btn { transition: none; }
  .otk-popup-frame { transform: none; }
}

/* Explicit light/dark surfaces for the onboarding welcome popup. Token
   classes on individual elements still win; these are only the base plate and
   fallback text so a late-loaded theme cannot leave unreadable copy. */
:root:not([data-theme="dark"]) .otk-popup-frame {
  color: var(--color-on-surface, #24344a);
}

:root[data-theme="dark"] .otk-popup-frame {
  color: var(--color-on-surface, #dbe6f3);
  border-color: var(--line, #2a3947);
}

/* Only the unclassed plate gets a forced background; authored token classes
   such as pf-bg-accent must keep working in both themes. */
:root:not([data-theme="dark"]) .otk-popup-frame:not([class*="pf-bg-"]) {
  background: var(--color-surface, #ffffff);
}

:root[data-theme="dark"] .otk-popup-frame:not([class*="pf-bg-"]) {
  background: var(--color-surface, #121a2b);
}

:root[data-theme="dark"] .otk-popup-close {
  background: #1a2740;
  border-color: #33475c;
  color: #eaf1f7;
}

:root[data-theme="dark"] .otk-popup-btn.is-secondary {
  background: #1a2740;
  border-color: #33475c;
  color: #eaf1f7;
}

:root[data-theme="dark"] .otk-popup-btn.is-secondary:hover,
:root[data-theme="dark"] .otk-popup-btn.is-secondary:focus-visible {
  background: #24344d;
}

:root:not([data-theme="dark"]) .otk-popup-close {
  background: #ffffff;
  color: #24344a;
}
