// Cortile marketing site — sections part 2: Managers, Residents, Compliance, Trust, FAQ, CTA, Footer + App.
const DS2 = window.CortileDesignSystem_c3fab1;
const { Button: Btn, Badge: Bdg } = DS2;
// reuse helpers from sections-1 (already on window): LIcon, Container, Eyebrow, SectionHead
const SANS2 = "var(--font-sans)";
const SERIF2 = "var(--font-serif)";

// ─────────────────────── For Property Managers ───────────────────────
function ForManagers({ t }) {
  return (
    <section id="managers" style={{ padding: "88px 0" }}>
      <Container>
        <div className="mgr-grid" style={{ display: "grid", gridTemplateColumns: "0.9fr 1.1fr", gap: 56, alignItems: "center" }}>
          <div>
            <SectionHead eyebrow={t.managers.eyebrow} title={t.managers.title} sub={t.managers.sub} align="left" maxW={420} />
            <div style={{ marginTop: 28 }}><AdminMock /></div>
          </div>
          <div className="grid-2-resp" style={{ display: "grid", gridTemplateColumns: "repeat(2,1fr)", gap: 14 }}>
            {t.managers.points.map((p) => (
              <div key={p.title} style={{ display: "flex", gap: 14, alignItems: "flex-start", background: "var(--bg-surface)", borderRadius: 12, padding: 18, boxShadow: "var(--shadow-1)" }}>
                <span style={{ width: 40, height: 40, borderRadius: 999, background: "var(--primary-50)", color: "var(--primary-500)", display: "inline-flex", alignItems: "center", justifyContent: "center", flexShrink: 0 }}>
                  <LIcon name={p.icon} size={20} />
                </span>
                <div>
                  <div style={{ fontFamily: SANS2, fontWeight: 700, fontSize: 15, color: "var(--neutral-900)" }}>{p.title}</div>
                  <div style={{ fontFamily: SANS2, fontSize: 13, lineHeight: 1.55, color: "var(--neutral-600)", marginTop: 4, textWrap: "pretty" }}>{p.body}</div>
                </div>
              </div>
            ))}
          </div>
        </div>
      </Container>
    </section>
  );
}

// small admin-console preview (browser frame)
function AdminMock() {
  return (
    <div style={{ borderRadius: 14, overflow: "hidden", boxShadow: "var(--shadow-4)", background: "#fff", border: "1px solid var(--hairline)" }}>
      <div style={{ display: "flex", alignItems: "center", gap: 7, padding: "10px 14px", background: "var(--neutral-100)", borderBottom: "1px solid var(--hairline)" }}>
        {["#E29E6E", "#DDD3BE", "#B8AE9A"].map((c) => <span key={c} style={{ width: 10, height: 10, borderRadius: 999, background: c }} />)}
        <span style={{ marginLeft: 8, fontFamily: "var(--font-mono)", fontSize: 11, color: "var(--neutral-500)" }}>admin.cortile.app</span>
      </div>
      <div style={{ display: "flex", height: 230 }}>
        <div style={{ width: 96, background: "var(--neutral-50)", borderRight: "1px solid var(--hairline)", padding: "14px 10px", display: "flex", flexDirection: "column", gap: 4 }}>
          {[["layout-dashboard", "總覽", true], ["users", "住戶", false], ["wrench", "工單", false], ["receipt-text", "帳務", false], ["megaphone", "公告", false]].map(([ic, lb, on]) => (
            <div key={lb} style={{ display: "flex", alignItems: "center", gap: 7, padding: "7px 8px", borderRadius: 8, background: on ? "var(--primary-50)" : "transparent", color: on ? "var(--primary-600)" : "var(--neutral-600)" }}>
              <LIcon name={ic} size={15} /><span style={{ fontFamily: SANS2, fontWeight: on ? 700 : 500, fontSize: 11 }}>{lb}</span>
            </div>
          ))}
        </div>
        <div style={{ flex: 1, padding: 16, background: "var(--bg-app)" }}>
          <div style={{ fontFamily: SERIF2, fontWeight: 900, fontSize: 16, color: "var(--neutral-900)" }}>嘉庭軒 · 總覽</div>
          <div style={{ display: "grid", gridTemplateColumns: "repeat(3,1fr)", gap: 8, marginTop: 12 }}>
            {[["待繳帳單", "12"], ["處理中工單", "5"], ["本月繳費率", "96%"]].map(([lb, v]) => (
              <div key={lb} style={{ background: "#fff", borderRadius: 10, padding: 10, boxShadow: "var(--shadow-1)" }}>
                <div style={{ fontFamily: SANS2, fontSize: 10, color: "var(--neutral-600)" }}>{lb}</div>
                <div style={{ fontFamily: "var(--font-numeric)", fontWeight: 700, fontSize: 20, color: "var(--neutral-900)", marginTop: 2 }}>{v}</div>
              </div>
            ))}
          </div>
          <div style={{ marginTop: 12, display: "flex", flexDirection: "column", gap: 6 }}>
            {[["1802 室 · 管理費", "待繳", "warning"], ["走廊燈故障", "已派工", "success"], ["地下水管滲漏", "處理中", "info"]].map(([title, st, c]) => (
              <div key={title} style={{ display: "flex", alignItems: "center", justifyContent: "space-between", background: "#fff", borderRadius: 8, padding: "8px 10px", boxShadow: "var(--shadow-1)" }}>
                <span style={{ fontFamily: SANS2, fontSize: 11, fontWeight: 500, color: "var(--neutral-800)" }}>{title}</span>
                <Bdg color={c}>{st}</Bdg>
              </div>
            ))}
          </div>
        </div>
      </div>
    </div>
  );
}

// ─────────────────────── For Residents ───────────────────────
function ForResidents({ t }) {
  return (
    <section style={{ padding: "88px 0", background: "var(--bg-surface)" }}>
      <Container>
        <SectionHead eyebrow={t.residents.eyebrow} title={t.residents.title} sub={t.residents.sub} />
        <div className="grid-3-resp" style={{ display: "grid", gridTemplateColumns: "repeat(3,1fr)", gap: 20, marginTop: 48 }}>
          {t.residents.points.map((p) => (
            <div key={p.title} style={{ background: "var(--bg-app)", borderRadius: 16, padding: 28, display: "flex", flexDirection: "column", gap: 14, alignItems: "flex-start" }}>
              <span style={{ width: 52, height: 52, borderRadius: 14, background: "var(--primary-50)", color: "var(--primary-500)", display: "inline-flex", alignItems: "center", justifyContent: "center" }}>
                <LIcon name={p.icon} size={24} />
              </span>
              <h3 style={{ margin: 0, fontFamily: SANS2, fontWeight: 700, fontSize: 18, color: "var(--neutral-900)" }}>{p.title}</h3>
              <p style={{ margin: 0, fontFamily: SANS2, fontSize: 14, lineHeight: 1.65, color: "var(--neutral-600)", textWrap: "pretty" }}>{p.body}</p>
            </div>
          ))}
        </div>
      </Container>
    </section>
  );
}

// ─────────────────────── Pricing ───────────────────────
function Pricing({ t }) {
  if (!t.pricing) return null;

  const mailto = (plan) => {
    const subject = encodeURIComponent(`Cortile ${plan.name}`);
    const body = encodeURIComponent(`你好，我想了解 Cortile ${plan.name}。\n\n物業 / 機構名稱：\n地區：HK / TW / MO\n大廈名稱：\n聯絡人：\n電話：`);
    return `mailto:${t.pricing.email}?subject=${subject}&body=${body}`;
  };
  const card = (plan, featured) => (
    <div style={{
      position: "relative",
      display: "flex",
      flexDirection: "column",
      gap: 22,
      borderRadius: 18,
      padding: 28,
      background: featured ? "var(--neutral-900)" : "var(--bg-surface)",
      color: featured ? "#fff" : "var(--neutral-900)",
      boxShadow: featured ? "var(--shadow-hero)" : "var(--shadow-2)",
      border: featured ? "1px solid rgba(255,255,255,0.10)" : "1px solid var(--hairline)",
      overflow: "hidden"
    }}>
      {featured && <div style={{ position: "absolute", inset: 0, background: "radial-gradient(90% 80% at 100% 0%, rgba(201,97,46,0.30), rgba(0,0,0,0) 58%)", pointerEvents: "none" }} />}
      <div style={{ position: "relative", display: "flex", flexDirection: "column", gap: 18 }}>
        <div style={{ display: "flex", justifyContent: "space-between", gap: 12, alignItems: "flex-start" }}>
          <div>
            <div style={{ fontFamily: SANS2, fontWeight: 700, fontSize: 11, letterSpacing: "0.14em", textTransform: "uppercase", color: featured ? "var(--primary-300)" : "var(--primary-600)" }}>{plan.badge}</div>
            <h3 style={{ margin: "8px 0 0", fontFamily: SERIF2, fontWeight: 900, fontSize: 30, color: featured ? "#fff" : "var(--neutral-900)" }}>{plan.name}</h3>
          </div>
          <span style={{ width: 44, height: 44, borderRadius: 999, background: featured ? "rgba(255,255,255,0.10)" : "var(--primary-50)", color: featured ? "var(--primary-300)" : "var(--primary-500)", display: "inline-flex", alignItems: "center", justifyContent: "center", flexShrink: 0 }}>
            <LIcon name={featured ? "gem" : "building-2"} size={22} />
          </span>
        </div>
        <p style={{ margin: 0, minHeight: 48, fontFamily: SANS2, fontSize: 14, lineHeight: 1.65, color: featured ? "rgba(244,239,229,0.70)" : "var(--neutral-600)", textWrap: "pretty" }}>{plan.audience}</p>
        <div>
          <div style={{ display: "flex", alignItems: "baseline", gap: 8, flexWrap: "wrap" }}>
            <span style={{ fontFamily: SERIF2, fontWeight: 900, fontSize: 36, color: featured ? "#fff" : "var(--neutral-900)" }}>{plan.price}</span>
            {plan.period && <span style={{ fontFamily: SANS2, fontSize: 14, color: featured ? "rgba(244,239,229,0.64)" : "var(--neutral-500)" }}>{plan.period}</span>}
          </div>
          <div style={{ marginTop: 6, fontFamily: SANS2, fontWeight: 700, fontSize: 13, color: featured ? "var(--primary-300)" : "var(--primary-600)" }}>{plan.promo}</div>
        </div>
        <ul style={{ display: "flex", flexDirection: "column", gap: 10, margin: 0, padding: 0, listStyle: "none" }}>
          {plan.features.map((feature) => (
            <li key={feature} style={{ display: "flex", gap: 10, alignItems: "flex-start", fontFamily: SANS2, fontSize: 14, lineHeight: 1.55, color: featured ? "rgba(244,239,229,0.78)" : "var(--neutral-700)" }}>
              <LIcon name="check" size={16} color={featured ? "var(--primary-300)" : "var(--success-500)"} style={{ marginTop: 2, flexShrink: 0 }} />
              {feature}
            </li>
          ))}
        </ul>
        <a href={mailto(plan)} style={{ textDecoration: "none" }}>
          <span style={{
            minHeight: 48,
            display: "inline-flex",
            alignItems: "center",
            justifyContent: "center",
            gap: 8,
            width: "100%",
            borderRadius: 10,
            background: featured ? "#fff" : "var(--primary-500)",
            color: featured ? "var(--neutral-900)" : "#fff",
            fontFamily: SANS2,
            fontWeight: 700,
            fontSize: 15,
            boxShadow: featured ? "none" : "var(--shadow-brand)"
          }}>
            {plan.cta}<LIcon name="arrow-right" size={17} />
          </span>
        </a>
        <p style={{ margin: 0, fontFamily: SANS2, fontSize: 12, lineHeight: 1.6, color: featured ? "rgba(244,239,229,0.56)" : "var(--neutral-500)", textWrap: "pretty" }}>{plan.note}</p>
      </div>
    </div>
  );

  return (
    <section id="pricing" style={{ padding: "88px 0", background: "var(--bg-app)" }}>
      <Container>
        <SectionHead eyebrow={t.pricing.eyebrow} title={t.pricing.title} sub={t.pricing.sub} />
        <div className="grid-2-resp" style={{ display: "grid", gridTemplateColumns: "repeat(2, minmax(0, 1fr))", gap: 20, marginTop: 48, alignItems: "stretch" }}>
          {card(t.pricing.standard, false)}
          {card(t.pricing.flagship, true)}
        </div>
      </Container>
    </section>
  );
}

// ─────────────────────── Compliance ───────────────────────
function Compliance({ t }) {
  return (
    <section id="compliance" style={{ padding: "88px 0" }}>
      <Container>
        <div className="comp-grid" style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 56, alignItems: "center" }}>
          <div>
            <SectionHead eyebrow={t.compliance.eyebrow} title={t.compliance.title} sub={t.compliance.sub} align="left" maxW={460} />
            <div style={{ display: "flex", flexDirection: "column", gap: 10, marginTop: 24 }}>
              {t.compliance.points.map((p) => (
                <div key={p} style={{ display: "flex", gap: 10, alignItems: "flex-start", fontFamily: SANS2, fontSize: 14, color: "var(--neutral-700)" }}>
                  <LIcon name="check" size={17} color="var(--success-500)" style={{ marginTop: 2, flexShrink: 0 }} />{p}
                </div>
              ))}
            </div>
          </div>
          <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
            {t.compliance.regions.map((r) => (
              <div key={r.code} style={{ display: "flex", alignItems: "center", gap: 18, background: "var(--bg-surface)", borderRadius: 14, padding: "18px 22px", boxShadow: "var(--shadow-2)" }}>
                <span style={{ width: 52, height: 52, borderRadius: 12, background: "var(--neutral-900)", color: "#fff", display: "inline-flex", alignItems: "center", justifyContent: "center", fontFamily: SANS2, fontWeight: 700, fontSize: 16, letterSpacing: "0.04em", flexShrink: 0 }}>{r.code}</span>
                <div>
                  <div style={{ fontFamily: SERIF2, fontWeight: 900, fontSize: 18, color: "var(--neutral-900)" }}>{r.name}</div>
                  <div style={{ fontFamily: SANS2, fontSize: 13, color: "var(--neutral-600)", marginTop: 2 }}>{r.law}</div>
                </div>
                <span style={{ marginLeft: "auto" }}><LIcon name="shield-check" size={20} color="var(--primary-500)" /></span>
              </div>
            ))}
            <div style={{ display: "flex", alignItems: "center", gap: 8, fontFamily: SANS2, fontSize: 12, color: "var(--neutral-500)", marginTop: 2 }}>
              <LIcon name="server" size={14} />資料中心 · 台灣
            </div>
          </div>
        </div>
      </Container>
    </section>
  );
}

// ─────────────────────── Trust & Security ───────────────────────
function Trust({ t }) {
  return (
    <section style={{ padding: "88px 0", background: "var(--neutral-900)" }}>
      <Container>
        <div style={{ display: "flex", flexDirection: "column", gap: 12, alignItems: "center", textAlign: "center", maxWidth: 600, margin: "0 auto" }}>
          <Eyebrow color="var(--primary-300)">{t.trust.eyebrow}</Eyebrow>
          <h2 style={{ margin: 0, fontFamily: SERIF2, fontWeight: 900, fontSize: 34, lineHeight: 1.25, color: "#fff" }}>{t.trust.title}</h2>
        </div>
        <div className="grid-4-resp" style={{ display: "grid", gridTemplateColumns: "repeat(4,1fr)", gap: 16, marginTop: 48 }}>
          {t.trust.items.map((it) => (
            <div key={it.title} style={{ background: "rgba(255,255,255,0.05)", border: "1px solid rgba(255,255,255,0.10)", borderRadius: 14, padding: 22, display: "flex", flexDirection: "column", gap: 12 }}>
              <span style={{ width: 44, height: 44, borderRadius: 999, background: "rgba(226,158,110,0.16)", color: "var(--primary-300)", display: "inline-flex", alignItems: "center", justifyContent: "center" }}>
                <LIcon name={it.icon} size={22} />
              </span>
              <div style={{ fontFamily: SANS2, fontWeight: 700, fontSize: 15, color: "#fff" }}>{it.title}</div>
              <div style={{ fontFamily: SANS2, fontSize: 13, lineHeight: 1.6, color: "rgba(244,239,229,0.66)", textWrap: "pretty" }}>{it.body}</div>
            </div>
          ))}
        </div>
        <div style={{ display: "flex", justifyContent: "center", gap: 24, marginTop: 36 }}>
          <a href="/privacy" style={{ fontFamily: SANS2, fontWeight: 700, fontSize: 14, color: "var(--primary-300)", display: "inline-flex", alignItems: "center", gap: 6 }}><LIcon name="lock" size={15} />{t.trust.links.privacy}</a>
          <a href="/terms" style={{ fontFamily: SANS2, fontWeight: 700, fontSize: 14, color: "var(--primary-300)", display: "inline-flex", alignItems: "center", gap: 6 }}><LIcon name="file-text" size={15} />{t.trust.links.terms}</a>
        </div>
      </Container>
    </section>
  );
}

// ─────────────────────── FAQ ───────────────────────
function FAQ({ t }) {
  const [open, setOpen] = React.useState(0);
  return (
    <section style={{ padding: "88px 0" }}>
      <Container style={{ maxWidth: 760 }}>
        <SectionHead eyebrow={t.faq.eyebrow} title={t.faq.title} />
        <div style={{ display: "flex", flexDirection: "column", gap: 12, marginTop: 40 }}>
          {t.faq.items.map((it, i) => {
            const isOpen = open === i;
            return (
              <div key={i} style={{ background: "var(--bg-surface)", borderRadius: 12, boxShadow: "var(--shadow-1)", overflow: "hidden" }}>
                <button onClick={() => setOpen(isOpen ? -1 : i)} style={{
                  width: "100%", border: 0, background: "transparent", cursor: "pointer",
                  display: "flex", alignItems: "center", justifyContent: "space-between", gap: 16,
                  padding: "18px 22px", textAlign: "left",
                }}>
                  <span style={{ fontFamily: SANS2, fontWeight: 700, fontSize: 16, color: "var(--neutral-900)" }}>{it.q}</span>
                  <LIcon name={isOpen ? "minus" : "plus"} size={18} color="var(--primary-500)" style={{ flexShrink: 0 }} />
                </button>
                {isOpen && (
                  <div style={{ padding: "0 22px 20px", fontFamily: SANS2, fontSize: 15, lineHeight: 1.7, color: "var(--neutral-600)", textWrap: "pretty" }}>{it.a}</div>
                )}
              </div>
            );
          })}
        </div>
      </Container>
    </section>
  );
}

// ─────────────────────── Final CTA ───────────────────────
function FinalCTA({ t }) {
  return (
    <section id="contact" style={{ padding: "20px 0 96px" }}>
      <Container>
        <div style={{ position: "relative", overflow: "hidden", borderRadius: 24, background: "var(--grad-metallic)", padding: "64px 48px", textAlign: "center", boxShadow: "var(--shadow-hero)" }}>
          <div style={{ position: "absolute", inset: 0, background: "radial-gradient(80% 120% at 50% -10%, rgba(201,97,46,0.30), rgba(0,0,0,0) 60%)", pointerEvents: "none" }} />
          <div style={{ position: "relative", display: "flex", flexDirection: "column", gap: 18, alignItems: "center" }}>
            <h2 style={{ margin: 0, fontFamily: SERIF2, fontWeight: 900, fontSize: 36, lineHeight: 1.3, color: "#fff", maxWidth: 560 }}>{t.cta.title}</h2>
            <p style={{ margin: 0, fontFamily: SANS2, fontSize: 16, color: "rgba(244,239,229,0.78)" }}>{t.cta.sub}</p>
            <div style={{ display: "flex", gap: 12, flexWrap: "wrap", justifyContent: "center", marginTop: 6 }}>
              <a href={`mailto:${t.cta.email}`} style={{ textDecoration: "none" }}><Btn variant="primary" size="lg">{t.cta.ctaPrimary}</Btn></a>
              <a href={`mailto:${t.cta.email}`} style={{ textDecoration: "none" }}>
                <span style={{ display: "inline-flex", alignItems: "center", justifyContent: "center", gap: 8, minHeight: 52, padding: "0 28px", borderRadius: 8, background: "rgba(255,255,255,0.12)", color: "#fff", boxShadow: "inset 0 0 0 1px rgba(255,255,255,0.20)", fontFamily: SANS2, fontWeight: 700, fontSize: 16 }}>{t.cta.ctaSecondary}</span>
              </a>
            </div>
            <a href={`mailto:${t.cta.email}`} style={{ fontFamily: "var(--font-mono)", fontSize: 13, color: "rgba(244,239,229,0.66)", marginTop: 4 }}>{t.cta.email}</a>
          </div>
        </div>
      </Container>
    </section>
  );
}

// ─────────────────────── Footer ───────────────────────
function Footer({ t }) {
  return (
    <footer style={{ background: "var(--bg-surface)", borderTop: "1px solid var(--hairline)", padding: "56px 0 40px" }}>
      <Container>
        <div className="foot-grid" style={{ display: "grid", gridTemplateColumns: "1.4fr 1fr 1fr", gap: 40 }}>
          <div style={{ display: "flex", flexDirection: "column", gap: 14, maxWidth: 320 }}>
            <img src="../../assets/cortile-wordmark.svg" alt="Cortile 寓家" style={{ height: 32, alignSelf: "flex-start" }} />
            <p style={{ margin: 0, fontFamily: SANS2, fontSize: 14, lineHeight: 1.6, color: "var(--neutral-600)" }}>{t.footer.tagline}</p>
            <p style={{ margin: 0, fontFamily: SANS2, fontSize: 12, lineHeight: 1.6, color: "var(--neutral-500)" }}>{t.footer.parent}</p>
            <div style={{ marginTop: 4, display: "inline-flex", alignItems: "center", gap: 8, padding: "8px 14px", borderRadius: 8, background: "var(--bg-field)", color: "var(--neutral-500)", fontFamily: SANS2, fontSize: 12, alignSelf: "flex-start" }}>
              <LIcon name="apple" size={15} />{t.footer.storeNote}
            </div>
          </div>
          <FootCol title={t.footer.colProduct} items={t.footer.product} hrefs={["#features", "#managers", "#features"]} />
          <FootCol title={t.footer.colCompany} items={t.footer.company} hrefs={["#compliance", "/privacy", "/terms"]} />
        </div>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", flexWrap: "wrap", gap: 12, marginTop: 40, paddingTop: 24, borderTop: "1px solid var(--hairline)" }}>
          <span style={{ fontFamily: SANS2, fontSize: 12, color: "var(--neutral-500)" }}>{t.footer.rights}</span>
          <span style={{ fontFamily: "var(--font-mono)", fontSize: 12, color: "var(--neutral-400)" }}>cortile.enolent.com</span>
        </div>
      </Container>
    </footer>
  );
}
function FootCol({ title, items, hrefs }) {
  return (
    <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
      <div style={{ fontFamily: SANS2, fontWeight: 700, fontSize: 12, letterSpacing: "0.08em", textTransform: "uppercase", color: "var(--neutral-500)" }}>{title}</div>
      {items.map((it, i) => (
        <a key={it} href={hrefs[i]} style={{ fontFamily: SANS2, fontSize: 14, color: "var(--neutral-700)", textDecoration: "none" }}>{it}</a>
      ))}
    </div>
  );
}

// ─────────────────────── App ───────────────────────
function MarketingApp() {
  const [lang, setLang] = React.useState(() => localStorage.getItem("cortile_lang") || "zh");
  const t = window.CORTILE_COPY[lang];
  React.useEffect(() => {
    localStorage.setItem("cortile_lang", lang);
    document.documentElement.lang = lang === "zh" ? "zh-Hant" : "en";
    const id = requestAnimationFrame(() => window.lucide && window.lucide.createIcons());
    return () => cancelAnimationFrame(id);
  }, [lang]);
  return (
    <div style={{ background: "var(--bg-app)" }}>
      <Nav t={t} lang={lang} setLang={setLang} />
      <main>
        <Hero t={t} />
        <ValueThree t={t} />
        <FeatureGrid t={t} />
        <ForManagers t={t} />
        <ForResidents t={t} />
        <Pricing t={t} />
        <Compliance t={t} />
        <Trust t={t} />
        <FAQ t={t} />
        <FinalCTA t={t} />
      </main>
      <Footer t={t} />
    </div>
  );
}
Object.assign(window, { ForManagers, ForResidents, Pricing, Compliance, Trust, FAQ, FinalCTA, Footer, MarketingApp });
