// Shared product page renderer — Hero, Features, Mock, Use cases, Tech, CTA.
// Loaded as a Babel script after primitives + product mocks.
// Uses window.TA_STRINGS (langs nav) + window.TA_PRODUCTS (per-product strings).

const { useState: useS_, useEffect: useE_, useRef: useR_ } = React;

function useProductI18n() {
  const [lang, setLang] = useS_(() => localStorage.getItem("ta-lang") || "ua");
  useE_(() => { localStorage.setItem("ta-lang", lang); document.documentElement.lang = lang; }, [lang]);
  return [lang, setLang];
}

function PSimpleNav({ p, lang, setLang }) {
  const langs = ["ua", "ru", "en"];
  const back = window.TA_PRODUCTS[lang].common.back;
  return (
    <header style={{
      position: "sticky", top: 0, zIndex: 50,
      background: "color-mix(in oklab, var(--bg) 90%, transparent)",
      backdropFilter: "blur(12px)",
      borderBottom: "1px solid var(--line)",
    }}>
      <div className="ta-container" style={{ display: "flex", alignItems: "center", padding: "16px 32px" }}>
        <a href="../index.html" style={{ textDecoration: "none" }}><Logo /></a>
        <a href="../index.html" style={{
          marginLeft: 28,
          display: "inline-flex", alignItems: "center", gap: 6,
          fontSize: 14, color: "var(--text-2)",
        }}>
          <svg width="14" height="14" viewBox="0 0 14 14"><path d="M9 3L5 7l4 4" stroke="currentColor" strokeWidth="1.5" fill="none" strokeLinecap="round" strokeLinejoin="round"/></svg>
          {back}
        </a>
        <span style={{ marginLeft: 18, paddingLeft: 18, borderLeft: "1px solid var(--line-2)", color: "var(--text-3)", fontFamily: "var(--mono)", fontSize: 12, letterSpacing: ".08em", textTransform: "uppercase" }}>
          {p.label} <span style={{ color: "var(--text-3)", opacity: .7 }}>· {p.version}</span>
        </span>
        <div style={{ marginLeft: "auto", display: "flex", alignItems: "center", gap: 6 }}>
          <div style={{ display: "flex", padding: 3, background: "var(--bg-2)", border: "1px solid var(--line)", borderRadius: 99 }}>
            {langs.map((l) => (
              <button key={l} onClick={() => setLang(l)} style={{
                padding: "6px 12px",
                borderRadius: 99,
                background: lang === l ? "var(--bg-card)" : "transparent",
                color: lang === l ? "var(--text)" : "var(--text-3)",
                fontSize: 11, fontWeight: 600, letterSpacing: ".08em",
                fontFamily: "var(--mono)", textTransform: "uppercase",
              }}>{l}</button>
            ))}
          </div>
          <a href="../index.html#pricing" className="ta-btn ta-btn--accent" style={{ marginLeft: 6 }}>{window.TA_PRODUCTS[lang].common.to_pricing}</a>
        </div>
      </div>
    </header>
  );
}

function PHero({ p, accent, MockComponent }) {
  return (
    <section className="ta-section" style={{ paddingTop: 80, paddingBottom: 80, position: "relative", overflow: "hidden" }}>
      <div className="ta-grid-bg" style={{ opacity: .25 }} />
      <div className="ta-container" style={{ position: "relative" }}>
        <div style={{ display: "flex", flexWrap: "wrap", gap: 8, marginBottom: 24 }}>
          {p.hero_meta.map((m, i) => (
            <span key={i} style={{
              padding: "5px 12px",
              background: "var(--bg-card)",
              border: "1px solid var(--line)",
              borderRadius: 99,
              fontFamily: "var(--mono)", fontSize: 11, letterSpacing: ".08em",
              color: "var(--text-2)", textTransform: "uppercase",
            }}>{m}</span>
          ))}
        </div>
        <div style={{ display: "flex", gap: 4, alignItems: "baseline", marginBottom: 8, color: accent, fontFamily: "var(--mono)", fontSize: 13, letterSpacing: ".08em", textTransform: "uppercase" }}>
          <span style={{ width: 20, height: 1, background: accent, alignSelf: "center", marginRight: 4 }} />
          {p.tagline}
        </div>
        <h1 className="ta-display" style={{ fontSize: "clamp(44px, 6vw, 84px)", margin: "0 0 18px", maxWidth: 980, lineHeight: 1.02 }}>{p.hero_title}</h1>
        <p style={{ fontSize: 19, color: "var(--text-2)", maxWidth: 720, margin: 0, lineHeight: 1.55 }}>{p.hero_sub}</p>
      </div>
    </section>
  );
}

function PFeatures({ p, lang, accent }) {
  const c = window.TA_PRODUCTS[lang].common;
  return (
    <section className="ta-section" style={{ background: "var(--bg-2)" }}>
      <div className="ta-container">
        <div style={{ marginBottom: 50 }}>
          <div className="ta-kicker"><span className="dot" style={{ background: accent }} />{c.kicker_features}</div>
          <h2 className="ta-display" style={{ fontSize: "clamp(36px, 4vw, 56px)", margin: "18px 0 0", maxWidth: 700 }}>{p.features_title}</h2>
        </div>
        <div style={{
          display: "grid",
          gridTemplateColumns: "repeat(auto-fill, minmax(290px, 1fr))",
          gap: 16,
        }}>
          {p.features.map((f, i) => (
            <article key={i} style={{
              background: "var(--bg-card)",
              border: "1px solid var(--line)",
              borderRadius: 18,
              padding: 24,
              display: "flex", flexDirection: "column", gap: 10,
            }}>
              <span className="ta-mono" style={{
                color: accent,
                fontSize: 11,
                fontWeight: 700,
                letterSpacing: ".08em",
                background: "color-mix(in oklab, " + accent + " 14%, transparent)",
                padding: "4px 8px",
                borderRadius: 4,
                alignSelf: "flex-start",
              }}>{String(i + 1).padStart(2, "0")}</span>
              <h3 style={{ margin: 0, fontFamily: "var(--display)", fontSize: 20, fontWeight: 600 }}>{f.t}</h3>
              <p style={{ margin: 0, color: "var(--text-2)", fontSize: 14, lineHeight: 1.55 }}>{f.d}</p>
            </article>
          ))}
        </div>
      </div>
    </section>
  );
}

function PMock({ p, lang, accent, MockComponent, renderMock }) {
  const c = window.TA_PRODUCTS[lang].common;
  const node = renderMock ? renderMock(lang) : MockComponent;
  if (!node) return null;
  return (
    <section className="ta-section">
      <div className="ta-container">
        <div style={{ marginBottom: 36, textAlign: "center" }}>
          <div className="ta-kicker" style={{ justifyContent: "center" }}><span className="dot" style={{ background: accent }} />{c.kicker_mock}</div>
          <h2 className="ta-display" style={{ fontSize: "clamp(32px, 3.6vw, 48px)", margin: "14px auto 0", maxWidth: 680 }}>{p.label}</h2>
        </div>
        <div style={{ position: "relative" }}>
          <div style={{
            position: "absolute", inset: -40,
            background: "radial-gradient(60% 60% at 50% 40%, color-mix(in oklab, " + accent + " 12%, transparent), transparent 70%)",
            pointerEvents: "none",
            borderRadius: 40,
          }} />
          <div style={{ position: "relative" }}>
            {MockComponent}
          </div>
        </div>
      </div>
    </section>
  );
}

function PUseCases({ p, lang, accent }) {
  const c = window.TA_PRODUCTS[lang].common;
  return (
    <section className="ta-section" style={{ background: "var(--bg-2)" }}>
      <div className="ta-container">
        <div style={{ marginBottom: 50 }}>
          <div className="ta-kicker"><span className="dot" style={{ background: accent }} />{c.kicker_usecases}</div>
          <h2 className="ta-display" style={{ fontSize: "clamp(36px, 4vw, 56px)", margin: "18px 0 0", maxWidth: 700 }}>{p.usecases_title}</h2>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fit, minmax(280px, 1fr))", gap: 18 }}>
          {p.usecases.map((u, i) => (
            <div key={i} style={{
              background: "var(--bg-card)",
              border: "1px solid var(--line)",
              borderRadius: 18,
              padding: 26,
              display: "flex", flexDirection: "column", gap: 18,
            }}>
              <div style={{ display: "flex", alignItems: "center", gap: 10 }}>
                <span className="ta-mono" style={{ fontSize: 11, color: "var(--text-3)", letterSpacing: ".08em", textTransform: "uppercase" }}>0{i + 1}</span>
                <h3 style={{ fontSize: 20, fontFamily: "var(--display)", margin: 0 }}>{u.who}</h3>
              </div>
              <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
                <div>
                  <div className="ta-mono" style={{ fontSize: 10, color: "#E84C4C", letterSpacing: ".1em", textTransform: "uppercase", marginBottom: 4 }}>Pain</div>
                  <div style={{ fontSize: 14, color: "var(--text-2)", lineHeight: 1.5 }}>{u.pain}</div>
                </div>
                <div style={{ height: 1, background: "var(--line)" }} />
                <div>
                  <div className="ta-mono" style={{ fontSize: 10, color: accent, letterSpacing: ".1em", textTransform: "uppercase", marginBottom: 4 }}>Win</div>
                  <div style={{ fontSize: 14, color: "var(--text)", lineHeight: 1.5 }}>{u.win}</div>
                </div>
              </div>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

function PTech({ p, lang, accent }) {
  const c = window.TA_PRODUCTS[lang].common;
  return (
    <section className="ta-section">
      <div className="ta-container" style={{ display: "grid", gridTemplateColumns: "minmax(0, 0.7fr) minmax(0, 1.3fr)", gap: 60, alignItems: "start" }}>
        <div>
          <div className="ta-kicker"><span className="dot" style={{ background: accent }} />{c.kicker_tech}</div>
          <h2 className="ta-display" style={{ fontSize: "clamp(32px, 3.6vw, 48px)", margin: "18px 0 0" }}>{p.tech_title}</h2>
        </div>
        <dl style={{ margin: 0, display: "flex", flexDirection: "column" }}>
          {p.tech.map((row, i) => (
            <div key={i} style={{
              display: "grid", gridTemplateColumns: "minmax(0, 200px) minmax(0, 1fr)",
              gap: 24,
              padding: "18px 0",
              borderBottom: i === p.tech.length - 1 ? "none" : "1px solid var(--line)",
            }}>
              <dt className="ta-mono" style={{ color: "var(--text-3)", fontSize: 12, letterSpacing: ".06em", textTransform: "uppercase", paddingTop: 2 }}>{row.k}</dt>
              <dd style={{ margin: 0, fontSize: 15, color: "var(--text)", lineHeight: 1.5 }}>{row.v}</dd>
            </div>
          ))}
        </dl>
      </div>
    </section>
  );
}

/* ---- Screenshots gallery — full MT5 chart style ---- */
function PScreenshots({ p, lang, accent, theme }) {
  const c = window.TA_PRODUCTS[lang].common;
  const themeKey = (theme === "light") ? "light" : "dark";
  const langKey = (lang === "ua") ? "en" : (lang || "en");
  const screenshots = typeof p.screenshots === "function"
    ? p.screenshots(themeKey, langKey)
    : (p.screenshots || []);
  if (!screenshots || screenshots.length === 0) return null;
  const base = (typeof window !== "undefined" && window.__TA_BASE_PATH) || "";
  const [active, setActive] = useS_(0);
  return (
    <section className="ta-section" style={{ background: "var(--bg-2)", padding: "60px 0" }}>
      <div className="ta-container">
        <div style={{ marginBottom: 36, textAlign: "center" }}>
          <div className="ta-kicker" style={{ justifyContent: "center" }}><span className="dot" style={{ background: accent }} />{c.kicker_mock}</div>
          <h2 className="ta-display" style={{ fontSize: "clamp(28px, 3.2vw, 42px)", margin: "14px auto 0", maxWidth: 680 }}>{p.label}</h2>
        </div>
        <div style={{ position: "relative", borderRadius: 12, overflow: "hidden", boxShadow: "0 24px 80px rgba(0,0,0,0.45)", border: "1px solid var(--line)", background: "#0a0c10" }}>
          <div style={{ position: "absolute", inset: 0, background: "radial-gradient(60% 50% at 70% 50%, color-mix(in oklab, " + accent + " 6%, transparent), transparent 70%)", pointerEvents: "none" }} />
          <img
            src={base + screenshots[active].src}
            alt={screenshots[active].label}
            style={{ width: "100%", display: "block" }}
          />
          <div style={{ position: "absolute", bottom: 0, left: 0, right: 0, height: 80, background: "linear-gradient(to top, var(--bg-2), transparent)", pointerEvents: "none" }} />
          <div style={{ position: "absolute", bottom: 16, left: "50%", transform: "translateX(-50%)", background: "rgba(0,0,0,0.7)", backdropFilter: "blur(8px)", border: "1px solid rgba(255,255,255,0.1)", borderRadius: 99, padding: "6px 16px", fontFamily: "var(--mono)", fontSize: 11, color: "rgba(255,255,255,0.7)", whiteSpace: "nowrap" }}>
            {screenshots[active].label}
          </div>
        </div>
        <div style={{ display: "flex", gap: 8, marginTop: 16, justifyContent: "center", flexWrap: "wrap" }}>
          {screenshots.map((s, i) => (
            <button key={i} onClick={() => setActive(i)} style={{
              padding: "6px 14px", borderRadius: 8, fontFamily: "var(--mono)", fontSize: 11,
              background: i === active ? "color-mix(in oklab, " + accent + " 14%, var(--bg-card))" : "var(--bg-card)",
              border: i === active ? "1px solid " + accent : "1px solid var(--line)",
              color: i === active ? accent : "var(--text-2)",
              cursor: "pointer", transition: "all .15s",
            }}>{s.label}</button>
          ))}
        </div>
      </div>
    </section>
  );
}

/* ---- FAQ accordion ---- */
function PFAQ({ p, lang, accent }) {
  const c = window.TA_PRODUCTS[lang].common;
  const [open, setOpen] = useS_(-1);
  if (!p.faq || p.faq.length === 0) return null;
  return (
    <section className="ta-section">
      <div className="ta-container">
        <div style={{ marginBottom: 44 }}>
          <div className="ta-kicker"><span className="dot" style={{ background: accent }} />{c.kicker_faq}</div>
          <h2 className="ta-display" style={{ fontSize: "clamp(32px, 3.6vw, 48px)", margin: "14px 0 0", maxWidth: 680 }}>{c.faq_title}</h2>
        </div>
        <div style={{ display: "flex", flexDirection: "column", gap: 0, maxWidth: 820 }}>
          {p.faq.map((item, i) => (
            <div key={i} style={{ borderBottom: "1px solid var(--line)" }}>
              <button
                onClick={() => setOpen(open === i ? -1 : i)}
                style={{
                  width: "100%", textAlign: "left", background: "none", border: "none",
                  padding: "22px 0", display: "flex", justifyContent: "space-between", alignItems: "center",
                  gap: 16, cursor: "pointer", color: "var(--text)", fontFamily: "inherit",
                }}
              >
                <span style={{ fontFamily: "var(--display)", fontSize: 17, fontWeight: 600, lineHeight: 1.3 }}>{item.q}</span>
                <span style={{
                  flexShrink: 0, width: 28, height: 28, borderRadius: 99,
                  background: open === i ? "color-mix(in oklab, " + accent + " 14%, transparent)" : "var(--bg-3)",
                  border: "1px solid " + (open === i ? accent : "var(--line)"),
                  display: "flex", alignItems: "center", justifyContent: "center",
                  color: open === i ? accent : "var(--text-3)",
                  fontSize: 18, lineHeight: 1, transition: "all .2s",
                  transform: open === i ? "rotate(45deg)" : "none",
                }}>+</span>
              </button>
              {open === i && (
                <p style={{ margin: "0 0 22px", color: "var(--text-2)", fontSize: 15, lineHeight: 1.65, paddingRight: 44 }}>{item.a}</p>
              )}
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

function PCTA({ p, lang, accent }) {
  const c = window.TA_PRODUCTS[lang].common;
  const scrollToPricing = () => {
    const el = document.getElementById("product-pricing") || document.getElementById("copier-pricing");
    if (el) el.scrollIntoView({ behavior: "smooth" });
  };
  return (
    <section className="ta-section">
      <div className="ta-container">
        <div style={{
          padding: "56px 40px",
          borderRadius: 24,
          background: "linear-gradient(135deg, color-mix(in oklab, " + accent + " 18%, var(--bg-2)), var(--bg-2))",
          border: "1px solid color-mix(in oklab, " + accent + " 30%, var(--line-2))",
          textAlign: "center",
          position: "relative", overflow: "hidden",
        }}>
          <div className="ta-grid-bg" style={{ opacity: .2 }} />
          <div style={{ position: "relative" }}>
            <h2 className="ta-display" style={{ fontSize: "clamp(32px, 3.6vw, 50px)", margin: "0 auto 14px", maxWidth: 720 }}>{p.cta_title}</h2>
            <p style={{ color: "var(--text-2)", fontSize: 16, margin: "0 auto 26px", maxWidth: 520 }}>{p.cta_sub}</p>
            <div style={{ display: "flex", justifyContent: "center", gap: 12, flexWrap: "wrap" }}>
              <button onClick={scrollToPricing} className="ta-btn ta-btn--accent">{c.try_free} →</button>
              <a href="../index.html" className="ta-btn ta-btn--ghost">{c.back}</a>
            </div>
          </div>
        </div>
      </div>
    </section>
  );
}

function PFooter({ lang }) {
  const t = window.TA_STRINGS[lang];
  return (
    <footer style={{ background: "var(--bg-2)", borderTop: "1px solid var(--line)", padding: "60px 0 30px" }}>
      <div className="ta-container">
        <div style={{ display: "grid", gridTemplateColumns: "1.5fr 1fr 1fr 1fr", gap: 40, marginBottom: 48 }}>
          <div>
            <Logo />
            <p style={{ color: "var(--text-2)", fontSize: 14, maxWidth: 280, marginTop: 14, lineHeight: 1.6 }}>{t.footer.tagline}</p>
          </div>
          {[
            { title: t.footer.col_product, links: t.footer.links_product, base: "../index.html" },
            { title: t.footer.col_resources, links: t.footer.links_resources, base: "../index.html" },
            { title: t.footer.col_company, links: t.footer.links_company, base: "../index.html" },
          ].map((col, i) => (
            <div key={i}>
              <h4 style={{ fontSize: 11, fontFamily: "var(--mono)", color: "var(--text-3)", letterSpacing: ".14em", textTransform: "uppercase", marginBottom: 14 }}>{col.title}</h4>
              <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "flex", flexDirection: "column", gap: 10 }}>
                {col.links.map((l, j) => (
                  <li key={j}><a href={col.base} style={{ color: "var(--text-2)", fontSize: 14 }}>{l}</a></li>
                ))}
              </ul>
            </div>
          ))}
        </div>
        <div style={{ paddingTop: 24, borderTop: "1px solid var(--line)", display: "flex", justifyContent: "space-between", gap: 24, alignItems: "start", flexWrap: "wrap" }}>
          <span style={{ color: "var(--text-3)", fontSize: 13 }}>{t.footer.rights}</span>
          <p style={{ color: "var(--text-3)", fontSize: 11, maxWidth: 680, margin: 0, lineHeight: 1.5 }}>{t.footer.risk}</p>
        </div>
      </div>
    </footer>
  );
}

function ProductPage({ slug, accent, MockComponent, renderMock }) {
  const [t, lang, setLang] = window.useI18n();
  const tw = window.useTweakState(window.TA_TWEAKS);
  const p = window.TA_PRODUCTS[lang][slug];
  useE_(() => {
    document.title = p.label + " — Trade Axis";
  }, [p.label]);
  const setTweakKeys = (edits) => {
    Object.entries(edits).forEach(([k, v]) => localStorage.setItem("ta-" + k, v));
    window.parent.postMessage({ type: "__edit_mode_set_keys", edits }, "*");
  };
  return (
    <div>
      <window.Nav t={t} lang={lang} setLang={setLang} theme={tw.theme} setTheme={tw.setTheme} />
      <PHero p={p} accent={accent} />
      <PFeatures p={p} lang={lang} accent={accent} />
      {p.screenshots && p.screenshots.length > 0
        ? <PScreenshots p={p} lang={lang} accent={accent} theme={tw.theme} />
        : <PMock p={p} lang={lang} accent={accent} MockComponent={MockComponent} renderMock={renderMock} />
      }
      <PUseCases p={p} lang={lang} accent={accent} />
      <PTech p={p} lang={lang} accent={accent} />
      {slug === "pro" && <ProPricingSection t={window.TA_STRINGS[lang]} />}
      {slug === "copier" && <window.CopierPricingSection t={window.TA_STRINGS[lang]} />}
      {slug === "journal" && <JournalPricingSection t={window.TA_STRINGS[lang]} />}
      <PFAQ p={p} lang={lang} accent={accent} />
      <PCTA p={p} lang={lang} accent={accent} />
      <window.Footer t={t} />
      <window.AIChatLauncher t={t} />
      <window.TweaksPanel t={t} {...tw} setTweakKeys={setTweakKeys} />
    </div>
  );
}

Object.assign(window, { ProductPage });

/* Scaled wrapper — same approach as journal/copier sections on the homepage */
function ScaledMock({ children, baseWidth = 1080 }) {
  const outerRef = useR_(null);
  const innerRef = useR_(null);
  useE_(() => {
    if (!outerRef.current || !innerRef.current) return;
    const fit = () => {
      const ow = outerRef.current.clientWidth;
      innerRef.current.style.width = baseWidth + "px";
      const s = Math.min(1, ow / baseWidth);
      innerRef.current.style.transform = `scale(${s})`;
      const ih = innerRef.current.scrollHeight;
      outerRef.current.style.height = (ih * s) + "px";
    };
    fit();
    const ro = new ResizeObserver(fit);
    ro.observe(outerRef.current);
    return () => ro.disconnect();
  }, [baseWidth]);
  return (
    <div className="ta-journal-scale" ref={outerRef}>
      <div className="ta-journal-inner" ref={innerRef}>{children}</div>
    </div>
  );
}

Object.assign(window, { ScaledMock });

/* --------- Pro Pricing Section (для сторінки pro.html) --------- */
function ProPricingSection({ t }) {
  const p = t.pricing;
  const [modal, setModal] = useS_(null);
  return (
    <section id="product-pricing" className="ta-section" style={{ background: "var(--bg-2)" }}>
      {modal !== null && <window.PaymentsModal t={t} planName={modal?.name} planPrice={modal?.price} onClose={() => setModal(null)} />}
      <div className="ta-container">
        <div style={{ textAlign: "center", marginBottom: 50 }}>
          <div className="ta-kicker" style={{ justifyContent: "center" }}>
            <span className="dot" />{p.kicker}
          </div>
          <h2 className="ta-display" style={{ fontSize: "clamp(36px, 4vw, 56px)", margin: "18px auto 12px", maxWidth: 700 }}>{p.title}</h2>
          <p style={{ fontSize: 17, color: "var(--text-2)", maxWidth: 560, margin: "0 auto" }}>{p.sub}</p>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 20 }}>
          {p.plans.map((plan, i) => (
            <div key={i} style={{
              background: plan.highlight ? "var(--bg)" : "var(--bg-card)",
              border: plan.highlight ? "1.5px solid var(--ta-green)" : "1px solid var(--line)",
              borderRadius: 22, padding: 30, position: "relative",
              display: "flex", flexDirection: "column", gap: 18,
              boxShadow: plan.highlight ? "0 30px 80px -30px color-mix(in oklab, var(--ta-green) 50%, transparent)" : "none",
            }}>
              {plan.badge && (
                <div style={{
                  position: "absolute", top: -12, right: 20,
                  padding: "4px 12px", background: "var(--ta-green)", color: "white",
                  borderRadius: 99, fontSize: 11, fontWeight: 700, letterSpacing: ".08em",
                }}>{plan.badge}</div>
              )}
              <h3 style={{ fontFamily: "var(--display)", fontSize: 24, margin: 0 }}>{plan.name}</h3>
              <div style={{ display: "flex", alignItems: "baseline", gap: 6 }}>
                <span style={{ fontSize: 16, color: "var(--text-2)" }}>$</span>
                <span className="ta-mono" style={{ fontSize: 56, fontWeight: 700, letterSpacing: "-.03em" }}>{plan.price}</span>
                <span style={{ fontSize: 14, color: "var(--text-3)", marginLeft: 4 }}>{plan.period}</span>
              </div>
              {plan.note && <div className="ta-mono" style={{ fontSize: 12, color: "var(--ta-green)", marginTop: -6 }}>{plan.note}</div>}
              <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "flex", flexDirection: "column", gap: 10 }}>
                {plan.features.map((f, j) => (
                  <li key={j} style={{ display: "flex", gap: 10, fontSize: 14, color: "var(--text-2)" }}>
                    <svg width="16" height="16" viewBox="0 0 14 14" style={{ marginTop: 3, flexShrink: 0 }}>
                      <path d="M3 7l3 3 5-6" stroke={plan.highlight ? "var(--ta-green)" : "var(--text-3)"} strokeWidth="2" fill="none" strokeLinecap="round" strokeLinejoin="round"/>
                    </svg>
                    {f}
                  </li>
                ))}
              </ul>
              <button onClick={() => setModal({ name: plan.name, price: plan.price })}
                className={"ta-btn " + (plan.highlight ? "ta-btn--accent" : "ta-btn--ghost")}
                style={{ justifyContent: "center", marginTop: "auto" }}>
                {plan.cta}
              </button>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

Object.assign(window, { ProPricingSection });
function JournalPricingSection({ t }) {
  const jp = t.journal_pricing;
  const [modal, setModal] = useS_(null);
  const JOURNAL_ACCENT = "var(--ta-green)";
  return (
    <section id="product-pricing" className="ta-section" style={{ background: "var(--bg-2)" }}>
      {modal !== null && <window.PaymentsModal t={t} planName={modal?.name} planPrice={modal?.price} onClose={() => setModal(null)} />}
      <div className="ta-container">
        <div style={{ textAlign: "center", marginBottom: 50 }}>
          <div className="ta-kicker" style={{ justifyContent: "center" }}>
            <span className="dot" style={{ background: JOURNAL_ACCENT }} />
            {jp.kicker}
          </div>
          <h2 className="ta-display" style={{ fontSize: "clamp(36px, 4vw, 56px)", margin: "18px auto 12px", maxWidth: 700 }}>{jp.title}</h2>
          <p style={{ fontSize: 17, color: "var(--text-2)", maxWidth: 620, margin: "0 auto" }}>{jp.sub}</p>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(3, 1fr)", gap: 20 }}>
          {jp.plans.map((p, i) => (
            <div key={i} style={{
              background: p.highlight ? "var(--bg)" : "var(--bg-card)",
              border: p.highlight ? ("1.5px solid " + JOURNAL_ACCENT) : "1px solid var(--line)",
              borderRadius: 22, padding: 30, position: "relative",
              display: "flex", flexDirection: "column", gap: 18,
              boxShadow: p.highlight ? ("0 30px 80px -30px color-mix(in oklab, " + JOURNAL_ACCENT + " 50%, transparent)") : "none",
            }}>
              {p.badge && (
                <div style={{
                  position: "absolute", top: -12, right: 20,
                  padding: "4px 12px", background: JOURNAL_ACCENT, color: "#fff",
                  borderRadius: 99, fontSize: 11, fontWeight: 700, letterSpacing: ".08em",
                }}>{p.badge}</div>
              )}
              <h3 style={{ fontFamily: "var(--display)", fontSize: 24, margin: 0 }}>{p.name}</h3>
              <div style={{ display: "flex", alignItems: "baseline", gap: 6 }}>
                <span style={{ fontSize: 16, color: "var(--text-2)" }}>$</span>
                <span className="ta-mono" style={{ fontSize: 56, fontWeight: 700, letterSpacing: "-.03em" }}>{p.price}</span>
                <span style={{ fontSize: 14, color: "var(--text-3)", marginLeft: 4 }}>{p.period}</span>
              </div>
              {p.note && <div className="ta-mono" style={{ fontSize: 12, color: JOURNAL_ACCENT, marginTop: -6 }}>{p.note}</div>}
              <ul style={{ listStyle: "none", padding: 0, margin: 0, display: "flex", flexDirection: "column", gap: 10 }}>
                {p.features.map((f, j) => (
                  <li key={j} style={{ display: "flex", gap: 10, fontSize: 14, color: "var(--text-2)" }}>
                    <svg width="16" height="16" viewBox="0 0 14 14" style={{ marginTop: 3, flexShrink: 0 }}>
                      <path d="M3 7l3 3 5-6" stroke={p.highlight ? JOURNAL_ACCENT : "var(--text-3)"} strokeWidth="2" fill="none" strokeLinecap="round" strokeLinejoin="round"/>
                    </svg>
                    {f}
                  </li>
                ))}
              </ul>
              <button onClick={() => setModal({ name: p.name, price: p.price })}
                className={"ta-btn " + (p.highlight ? "" : "ta-btn--ghost")}
                style={{ justifyContent: "center", marginTop: "auto", ...(p.highlight ? { background: JOURNAL_ACCENT, color: "#fff" } : {}) }}>
                {p.cta}
              </button>
            </div>
          ))}
        </div>
      </div>
    </section>
  );
}

Object.assign(window, { JournalPricingSection });
