// Landing page — 2 variações lado a lado em design canvas

const TWEAK_DEFAULTS = /*EDITMODE-BEGIN*/{
  "primaryColor": "#673a8f",
  "deepColor": "#3d2963",
  "secondaryColor": "#8f3a8b",
  "lightColor": "#e4d7eb",
  "gridDensity": "comfortable",
  "cardStyle": "sober"
}/*EDITMODE-END*/;

function applyTheme(t) {
  Object.assign(window.RR, {
    primary: t.primaryColor, deep: t.deepColor,
    secondary: t.secondaryColor, light: t.lightColor,
  });
  document.documentElement.style.setProperty("--rr-primary", t.primaryColor);
  document.documentElement.style.setProperty("--rr-deep", t.deepColor);
  document.documentElement.style.setProperty("--rr-secondary", t.secondaryColor);
  document.documentElement.style.setProperty("--rr-light", t.lightColor);
}

// ===== Card variants (sem imagens da capa) =====
function CardSober({ revisao }) {
  return (
    <a href={`revisao.html?slug=${revisao.slug}`} className="rr-card"
       style={{
         textDecoration: "none", color: "inherit",
         display: "flex", flexDirection: "column", gap: 14,
         background: "#fff", padding: "26px 24px 22px",
         borderRadius: 16, border: "1px solid #efe6f3",
         minHeight: 260, position: "relative",
       }}>
      <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between" }}>
        <span style={{
          fontSize: 11, fontWeight: 600, color: "var(--rr-primary)",
          background: "var(--rr-light)", padding: "5px 12px",
          borderRadius: 999, letterSpacing: "0.04em", textTransform: "uppercase",
        }}>{revisao.tema}</span>
        <FileIcon size={20} color="var(--rr-primary)" />
      </div>
      <h3 style={{
        fontSize: 17, lineHeight: 1.35, fontWeight: 600,
        color: "var(--rr-deep)", margin: "8px 0 0", flex: 1,
        textTransform: "uppercase", letterSpacing: "0.005em",
      }}>{revisao.titulo}</h3>
      <Waves color="var(--rr-secondary)" width={40} strokeWidth={1.2} />
      <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", paddingTop: 12, borderTop: "1px solid #f1eaf6", fontSize: 12, color: "#888" }}>
        <span>{revisao.data}</span>
        <span style={{ display: "inline-flex", alignItems: "center", gap: 4, fontWeight: 600, color: "var(--rr-primary)" }}>
          Ler <ArrowRight size={13} color="var(--rr-primary)" />
        </span>
      </div>
    </a>
  );
}

function CardHybrid({ revisao }) {
  return (
    <a href={`revisao.html?slug=${revisao.slug}`} className="rr-card"
       style={{
         textDecoration: "none", color: "inherit",
         display: "flex", flexDirection: "column",
         background: "#fff", borderRadius: 16, overflow: "hidden",
         border: "1px solid #efe6f3", position: "relative",
       }}>
      <div style={{
        position: "relative", height: 130,
        background: `linear-gradient(120deg, var(--rr-deep) 0%, var(--rr-primary) 75%, var(--rr-secondary) 100%)`,
        overflow: "hidden",
      }}>
        <PillShape color="rgba(255,255,255,0.18)" size={190} rotate={20}
          style={{ position: "absolute", top: -50, right: -50 }} />
        <PillOutline color="rgba(255,255,255,0.35)" size={140} rotate={20} strokeWidth={1.4}
          style={{ position: "absolute", bottom: -60, left: 30 }} />
        <Waves color="rgba(255,255,255,0.4)" width={70} strokeWidth={1.2}
          style={{ position: "absolute", bottom: 14, right: 18 }} />
        <div style={{ position: "absolute", top: 16, left: 18, color: "#fff", fontSize: 11, fontWeight: 500, letterSpacing: "0.08em", textTransform: "uppercase", opacity: 0.92 }}>
          {revisao.data}
        </div>
        <div style={{ position: "absolute", top: 16, right: 18, background: "rgba(255,255,255,0.22)", color: "#fff", fontSize: 10, fontWeight: 600, padding: "4px 10px", borderRadius: 999, letterSpacing: "0.06em", textTransform: "uppercase", backdropFilter: "blur(4px)" }}>
          {revisao.tema}
        </div>
      </div>
      <div style={{ padding: "20px 22px 22px", display: "flex", flexDirection: "column", gap: 14, minHeight: 170 }}>
        <h3 style={{
          fontSize: 16, lineHeight: 1.35, fontWeight: 600,
          color: "var(--rr-primary)", margin: 0,
          textTransform: "uppercase", letterSpacing: "0.005em",
          flex: 1,
        }}>{revisao.titulo}</h3>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", fontSize: 12, color: "#888" }}>
          <span style={{ display: "inline-flex", alignItems: "center", gap: 6 }}>
            <FileIcon size={14} color="#888" /> {revisao.paginas} páginas
          </span>
          <span style={{ display: "inline-flex", alignItems: "center", gap: 4, fontWeight: 600, color: "var(--rr-primary)" }}>
            Ler <ArrowRight size={13} color="var(--rr-primary)" />
          </span>
        </div>
      </div>
    </a>
  );
}

function CardLine({ revisao }) {
  // Card minimalista com faixa lateral roxa (sem imagem)
  return (
    <a href={`revisao.html?slug=${revisao.slug}`} className="rr-card"
       style={{
         textDecoration: "none", color: "inherit",
         display: "flex", background: "#fff",
         borderRadius: 14, overflow: "hidden",
         border: "1px solid #efe6f3", minHeight: 180,
       }}>
      <div style={{
        width: 8, flexShrink: 0,
        background: `linear-gradient(180deg, var(--rr-primary) 0%, var(--rr-secondary) 100%)`,
      }} />
      <div style={{ flex: 1, padding: "22px 24px", display: "flex", flexDirection: "column", gap: 10 }}>
        <div style={{ display: "flex", alignItems: "center", gap: 10, fontSize: 11 }}>
          <span style={{ color: "var(--rr-primary)", fontWeight: 600, letterSpacing: "0.06em", textTransform: "uppercase" }}>{revisao.tema}</span>
          <span style={{ color: "#bbb" }}>·</span>
          <span style={{ color: "#888" }}>{revisao.data}</span>
        </div>
        <h3 style={{
          fontSize: 15, lineHeight: 1.4, fontWeight: 600,
          color: "var(--rr-deep)", margin: 0, flex: 1,
          textTransform: "uppercase", letterSpacing: "0.005em",
        }}>{revisao.titulo}</h3>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", fontSize: 12, color: "#888" }}>
          <span style={{ display: "inline-flex", alignItems: "center", gap: 6 }}>
            <FileIcon size={13} color="#888" /> {revisao.paginas} páginas
          </span>
          <span style={{ display: "inline-flex", alignItems: "center", gap: 4, fontWeight: 600, color: "var(--rr-primary)" }}>
            Ler <ArrowRight size={13} color="var(--rr-primary)" />
          </span>
        </div>
      </div>
    </a>
  );
}

function pickCard(style) {
  if (style === "hybrid") return CardHybrid;
  if (style === "line") return CardLine;
  return CardSober;
}

function SearchFilter({ query, setQuery, year, setYear, years }) {
  return (
    <div className="rr-searchfilter" style={{
      display: "flex", gap: 0, alignItems: "stretch",
      background: "#fff", padding: 6, borderRadius: 14,
      boxShadow: "0 20px 60px -20px rgba(61,41,99,0.35), 0 1px 0 #efe6f3",
      border: "1px solid #efe6f3",
    }}>
      <div style={{ flex: 1, display: "flex", alignItems: "center", gap: 12, padding: "0 16px" }}>
        <SearchIcon size={20} color="var(--rr-primary)" />
        <input value={query} onChange={(e) => setQuery(e.target.value)}
          placeholder="Buscar por título, tema ou pergunta de pesquisa…"
          style={{
            flex: 1, border: "none", outline: "none",
            fontSize: 15, fontFamily: '"Poppins", sans-serif',
            color: "var(--rr-deep)", background: "transparent", padding: "14px 0",
          }} />
      </div>
      <div className="rr-searchfilter-year" style={{ display: "flex", alignItems: "center", borderLeft: "1px solid #efe6f3", padding: "0 8px 0 14px" }}>
        <span style={{ fontSize: 12, color: "#888", marginRight: 10, fontWeight: 500 }}>Ano</span>
        <YearDropdown year={year} setYear={setYear} years={years} />
      </div>
    </div>
  );
}

function YearDropdown({ year, setYear, years }) {
  const [open, setOpen] = React.useState(false);
  const [hover, setHover] = React.useState(null);
  const [pos, setPos] = React.useState({ top: 0, right: 0 });
  const ref = React.useRef(null);
  const popRef = React.useRef(null);

  const place = React.useCallback(() => {
    const el = ref.current;
    if (!el) return;
    const r = el.getBoundingClientRect();
    setPos({ top: r.bottom + 8, right: window.innerWidth - r.right });
  }, []);

  React.useEffect(() => {
    if (!open) return;
    place();
    const onDown = (e) => {
      if (ref.current && ref.current.contains(e.target)) return;
      if (popRef.current && popRef.current.contains(e.target)) return;
      setOpen(false);
    };
    const onKey = (e) => { if (e.key === "Escape") setOpen(false); };
    const onScroll = () => place();
    document.addEventListener("mousedown", onDown);
    document.addEventListener("keydown", onKey);
    window.addEventListener("scroll", onScroll, true);
    window.addEventListener("resize", onScroll);
    return () => {
      document.removeEventListener("mousedown", onDown);
      document.removeEventListener("keydown", onKey);
      window.removeEventListener("scroll", onScroll, true);
      window.removeEventListener("resize", onScroll);
    };
  }, [open, place]);

  const options = [{ value: "all", label: "Todos" }, ...years.map((y) => ({ value: String(y), label: String(y) }))];
  const current = options.find((o) => o.value === String(year)) || options[0];

  const popover = ReactDOM.createPortal(
    <div ref={popRef} style={{
      position: "fixed", top: pos.top, right: pos.right, minWidth: 132,
      background: "#fff", borderRadius: 12, padding: 6,
      border: "1px solid #efe6f3",
      boxShadow: "0 24px 50px -16px rgba(61,41,99,0.32), 0 2px 0 #f3edf7",
      zIndex: 1000,
      transformOrigin: "top right",
      opacity: open ? 1 : 0,
      transform: open ? "translateY(0) scale(1)" : "translateY(-6px) scale(0.97)",
      pointerEvents: open ? "auto" : "none",
      transition: "opacity .18s ease, transform .18s ease",
      maxHeight: 280, overflowY: "auto",
    }}>
      {options.map((o) => {
        const active = o.value === String(year);
        const hot = hover === o.value;
        return (
          <button
            key={o.value}
            type="button"
            onClick={() => { setYear(o.value); setOpen(false); }}
            onMouseEnter={() => setHover(o.value)}
            onMouseLeave={() => setHover(null)}
            style={{
              display: "flex", alignItems: "center", justifyContent: "space-between", width: "100%",
              border: "none", textAlign: "left", cursor: "pointer",
              fontFamily: '"Poppins", sans-serif', fontSize: 14,
              fontWeight: active ? 700 : 500,
              color: active ? "#fff" : "var(--rr-deep)",
              background: active ? "var(--rr-primary)" : hot ? "var(--rr-light)" : "transparent",
              padding: "9px 12px", borderRadius: 8, transition: "background .14s, color .14s",
              marginBottom: 2,
            }}>
            <span>{o.label}</span>
            {active && (
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="#fff"
                strokeWidth="3" strokeLinecap="round" strokeLinejoin="round">
                <polyline points="20 6 9 17 4 12" />
              </svg>
            )}
          </button>
        );
      })}
    </div>,
    document.body
  );

  return (
    <div ref={ref} style={{ position: "relative" }}>
      <button
        type="button"
        onClick={() => setOpen((o) => !o)}
        style={{
          display: "flex", alignItems: "center", gap: 8,
          border: "1px solid", borderColor: open ? "var(--rr-primary)" : "transparent",
          background: open ? "var(--rr-light)" : "transparent",
          fontFamily: '"Poppins", sans-serif', fontSize: 14, fontWeight: 600,
          color: "var(--rr-primary)", cursor: "pointer",
          padding: "8px 12px", borderRadius: 9, transition: "background .18s, border-color .18s",
        }}
        onMouseEnter={(e) => { if (!open) e.currentTarget.style.background = "var(--rr-light)"; }}
        onMouseLeave={(e) => { if (!open) e.currentTarget.style.background = "transparent"; }}>
        <span>{current.label}</span>
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor"
          strokeWidth="2.6" strokeLinecap="round" strokeLinejoin="round"
          style={{ transform: open ? "rotate(180deg)" : "rotate(0deg)", transition: "transform .2s ease" }}>
          <polyline points="6 9 12 15 18 9" />
        </svg>
      </button>
      {popover}
    </div>
  );
}

const PER_PAGE = 12;

function useFiltered(revisoes) {
  const list = revisoes || [];
  const [query, setQuery] = React.useState("");
  const [year, setYear] = React.useState("all");
  const [page, setPage] = React.useState(1);
  const years = React.useMemo(() => [...new Set(list.map(r => r.ano))].sort((a, b) => b - a), [list]);
  const filtered = list.filter((r) => {
    const q = query.toLowerCase().trim();
    const matchQ = !q || r.titulo.toLowerCase().includes(q) || r.tema.toLowerCase().includes(q) || r.pergunta.toLowerCase().includes(q);
    const matchY = year === "all" || r.ano === Number(year);
    return matchQ && matchY;
  });

  // Reseta para a página 1 sempre que a busca ou o filtro de ano mudam
  React.useEffect(() => { setPage(1); }, [query, year]);

  const totalPages = Math.max(1, Math.ceil(filtered.length / PER_PAGE));
  const safePage = Math.min(page, totalPages);
  const pageItems = filtered.slice((safePage - 1) * PER_PAGE, safePage * PER_PAGE);

  return { query, setQuery, year, setYear, years, filtered, page: safePage, setPage, totalPages, pageItems };
}

// Gera a sequência de páginas com reticências: 1 … 4 5 [6] 7 8 … 12
function pageList(current, total) {
  if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1);
  const pages = new Set([1, total, current, current - 1, current + 1]);
  const sorted = [...pages].filter((p) => p >= 1 && p <= total).sort((a, b) => a - b);
  const out = [];
  let prev = 0;
  for (const p of sorted) {
    if (p - prev > 1) out.push("…");
    out.push(p);
    prev = p;
  }
  return out;
}

function Pagination({ page, totalPages, onChange }) {
  if (totalPages <= 1) return null;
  const items = pageList(page, totalPages);

  const navBtn = (label, disabled, onClick, key) => (
    <button
      key={key}
      type="button"
      disabled={disabled}
      onClick={onClick}
      style={{
        display: "flex", alignItems: "center", justifyContent: "center",
        width: 38, height: 38, borderRadius: 10,
        border: "1px solid #e7daee", background: "#fff",
        color: disabled ? "#c9bcd4" : "var(--rr-primary)",
        cursor: disabled ? "default" : "pointer",
        transition: "background .15s, border-color .15s, color .15s",
      }}
      onMouseEnter={(e) => { if (!disabled) { e.currentTarget.style.background = "var(--rr-light)"; e.currentTarget.style.borderColor = "var(--rr-primary)"; } }}
      onMouseLeave={(e) => { e.currentTarget.style.background = "#fff"; e.currentTarget.style.borderColor = "#e7daee"; }}>
      <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round"
        style={{ transform: label === "prev" ? "none" : "rotate(180deg)" }}>
        <polyline points="15 18 9 12 15 6" />
      </svg>
    </button>
  );

  return (
    <nav aria-label="Paginação" style={{ display: "flex", justifyContent: "center", alignItems: "center", gap: 8, marginTop: 48, flexWrap: "wrap" }}>
      {navBtn("prev", page === 1, () => onChange(page - 1), "prev")}
      {items.map((it, i) =>
        it === "…" ? (
          <span key={`e${i}`} style={{ width: 24, textAlign: "center", color: "#b7a8c4", fontWeight: 600, userSelect: "none" }}>…</span>
        ) : (
          <button
            key={it}
            type="button"
            onClick={() => onChange(it)}
            aria-current={it === page ? "page" : undefined}
            style={{
              minWidth: 38, height: 38, padding: "0 6px", borderRadius: 10,
              border: "1px solid", borderColor: it === page ? "var(--rr-primary)" : "#e7daee",
              background: it === page ? "var(--rr-primary)" : "#fff",
              color: it === page ? "#fff" : "var(--rr-deep)",
              fontFamily: '"Poppins", sans-serif', fontSize: 14,
              fontWeight: it === page ? 700 : 500,
              cursor: it === page ? "default" : "pointer",
              transition: "background .15s, border-color .15s, color .15s",
            }}
            onMouseEnter={(e) => { if (it !== page) { e.currentTarget.style.background = "var(--rr-light)"; e.currentTarget.style.borderColor = "var(--rr-primary)"; } }}
            onMouseLeave={(e) => { if (it !== page) { e.currentTarget.style.background = "#fff"; e.currentTarget.style.borderColor = "#e7daee"; } }}>
            {it}
          </button>
        )
      )}
      {navBtn("next", page === totalPages, () => onChange(page + 1), "next")}
    </nav>
  );
}

function gridConfig(density) {
  if (density === "compact") return { cols: "repeat(auto-fill, minmax(240px, 1fr))", gap: 18 };
  if (density === "spacious") return { cols: "repeat(auto-fill, minmax(360px, 1fr))", gap: 32 };
  return { cols: "repeat(auto-fill, minmax(290px, 1fr))", gap: 24 };
}

// ===== Variation A: Hero claro expressivo =====
function LandingVariantA({ tweaks, revisoes, loading }) {
  const { query, setQuery, year, setYear, years, filtered, page, setPage, totalPages, pageItems } = useFiltered(revisoes);
  const Card = pickCard(tweaks.cardStyle);
  const { cols, gap } = gridConfig(tweaks.gridDensity);

  const goTo = (p) => {
    setPage(p);
    const grid = document.getElementById("rr-grid-top");
    if (grid) window.scrollTo({ top: grid.getBoundingClientRect().top + window.scrollY - 24, behavior: "smooth" });
  };

  return (
    <div style={{ minHeight: "100vh", background: "#fbf8fd" }}>
      <SiteHeader />
      {/* HERO */}
      <section style={{ position: "relative", overflow: "hidden", paddingBottom: 80 }}>
        <div style={{
          position: "absolute", inset: 0,
          background: `linear-gradient(180deg, #fbf8fd 0%, #f3e8f9 70%, #fbf8fd 100%)`,
          zIndex: 0,
        }} />
        {/* Decorações — camada única atrás do conteúdo (nunca à frente do texto) */}
        <div className="rr-hero-deco" aria-hidden="true" style={{ position: "absolute", inset: 0, overflow: "hidden", pointerEvents: "none", zIndex: 0 }}>
          <PillShape className="rr-drift rr-drift-1" color="var(--rr-deep)" size={400} rotate={-12} opacity={0.92}
            style={{ position: "absolute", top: -120, right: -120 }} />
          <PillShape className="rr-drift rr-drift-2" color="var(--rr-primary)" size={240} rotate={-12}
            style={{ position: "absolute", top: 100, right: 80 }} />
          <CircleDot className="rr-drift rr-drift-3" color="var(--rr-secondary)" size={80}
            style={{ position: "absolute", top: 360, right: 260 }} />
          <ConcentricCircles className="rr-drift rr-spin" color="var(--rr-deep)" size={160}
            style={{ position: "absolute", bottom: 40, left: 40, opacity: 0.7 }} />
          <DotsDiagonal className="rr-drift rr-drift-4" color="var(--rr-deep)" size={70}
            style={{ position: "absolute", top: 160, left: 60 }} />
        </div>

        <div className="rr-hero-inner" style={{ maxWidth: 1280, margin: "0 auto", padding: "100px 32px 0", position: "relative", zIndex: 5 }}>
          <div style={{ maxWidth: 760 }}>
            <div style={{
              display: "inline-flex", alignItems: "center", gap: 10,
              padding: "8px 16px", background: "#fff", borderRadius: 999,
              fontSize: 12, fontWeight: 600, color: "var(--rr-primary)",
              letterSpacing: "0.06em", textTransform: "uppercase",
              marginBottom: 28, boxShadow: "0 1px 0 #efe6f3",
            }}>
              <span style={{ width: 8, height: 8, borderRadius: 999, background: "var(--rr-primary)" }} />
              Sínteses rápidas de evidências
            </div>
            <h1 className="rr-hero-h1" style={{
              fontSize: 64, lineHeight: 1.05, fontWeight: 800,
              color: "var(--rr-primary)", margin: 0, letterSpacing: "-0.02em",
            }}>
              Evidências que<br />
              <span style={{ color: "var(--rr-deep)" }}>informam decisões</span><br />
              em saúde pública.
            </h1>
            <Waves color="var(--rr-secondary)" width={110} strokeWidth={1.5} style={{ margin: "32px 0 24px" }} />
            <p style={{ fontSize: 17, lineHeight: 1.6, color: "#666", maxWidth: 580, margin: 0 }}>
              Revisões rápidas reúnem o melhor da literatura científica em sínteses objetivas, prontas para apoiar a tomada de decisão por gestores e profissionais do SUS.
            </p>
          </div>
          {/* Busca em destaque */}
          <div style={{ maxWidth: 880, marginTop: 56, position: "relative", zIndex: 20 }}>
            <SearchFilter query={query} setQuery={setQuery} year={year} setYear={setYear} years={years} />
          </div>
        </div>
      </section>

      {/* GRID */}
      <section id="rr-grid-top" style={{ maxWidth: 1280, margin: "0 auto", padding: "0 32px 80px" }}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end", marginBottom: 32 }}>
          <div>
            <h2 style={{ fontSize: 28, fontWeight: 700, color: "var(--rr-primary)", margin: 0 }}>Todas as revisões</h2>
            <p style={{ fontSize: 14, color: "#888", marginTop: 6 }}>
              {filtered.length} {filtered.length === 1 ? "revisão encontrada" : "revisões encontradas"}
            </p>
          </div>
        </div>
        <div style={{ display: "grid", gridTemplateColumns: cols, gap }}>
          {pageItems.map((r) => <Card key={r.slug} revisao={r} />)}
        </div>
        {loading && (
          <div style={{ padding: "80px 0", textAlign: "center", color: "#888" }}>
            Carregando revisões…
          </div>
        )}
        {!loading && filtered.length === 0 && (
          <div style={{ padding: "80px 0", textAlign: "center", color: "#888" }}>
            Nenhuma revisão encontrada. Tente ajustar a busca.
          </div>
        )}
        <Pagination page={page} totalPages={totalPages} onChange={goTo} />
      </section>

      <SiteFooter />
    </div>
  );
}

// ===== Variation B: Hero escuro + grid em painel branco =====
function LandingVariantB({ tweaks, revisoes, loading }) {
  const { query, setQuery, year, setYear, years, filtered, page, setPage, totalPages, pageItems } = useFiltered(revisoes);
  const Card = pickCard(tweaks.cardStyle);
  const { cols, gap } = gridConfig(tweaks.gridDensity);

  const goTo = (p) => {
    setPage(p);
    const grid = document.getElementById("rr-grid-top-b");
    if (grid) window.scrollTo({ top: grid.getBoundingClientRect().top + window.scrollY - 24, behavior: "smooth" });
  };

  return (
    <div style={{ minHeight: "100vh", background: "#fff" }}>
      <SiteHeader variant="dark" />
      <section style={{
        position: "relative", overflow: "hidden",
        background: `linear-gradient(135deg, var(--rr-deep) 0%, var(--rr-primary) 100%)`,
        color: "#fff", paddingTop: 100, paddingBottom: 200,
      }}>
        <PillShape color="rgba(255,255,255,0.10)" size={520} rotate={20}
          style={{ position: "absolute", top: -160, left: -160, zIndex: 1 }} />
        <PillOutline color="rgba(255,255,255,0.25)" size={300} rotate={-10} strokeWidth={2}
          style={{ position: "absolute", top: 80, right: -50, zIndex: 1 }} />
        <PillShape color="var(--rr-secondary)" size={200} rotate={-10} opacity={0.85}
          style={{ position: "absolute", bottom: 80, right: 200, zIndex: 1 }} />
        <DotsDiagonal color="rgba(255,255,255,0.35)" size={90}
          style={{ position: "absolute", top: 110, right: 380, zIndex: 1 }} />
        <ConcentricCircles color="rgba(255,255,255,0.25)" size={220}
          style={{ position: "absolute", bottom: -80, left: 120, zIndex: 1 }} />
        <Waves color="rgba(255,255,255,0.55)" width={110} strokeWidth={1.5}
          style={{ position: "absolute", top: 200, left: 60, zIndex: 1 }} />

        <div style={{ maxWidth: 1280, margin: "0 auto", padding: "0 32px", position: "relative", zIndex: 4, textAlign: "center" }}>
          <div style={{ display: "inline-flex", alignItems: "center", gap: 10, padding: "8px 16px", background: "rgba(255,255,255,0.14)", border: "1px solid rgba(255,255,255,0.22)", borderRadius: 999, fontSize: 11, fontWeight: 600, color: "#fff", letterSpacing: "0.12em", textTransform: "uppercase", marginBottom: 32, backdropFilter: "blur(6px)" }}>
            <span style={{ width: 6, height: 6, borderRadius: 999, background: "var(--rr-light)" }} />
            Biblioteca de revisões rápidas · Fiocruz Brasília
          </div>
          <h1 style={{
            fontSize: 76, lineHeight: 1, fontWeight: 800,
            color: "#fff", margin: 0, letterSpacing: "-0.025em",
            maxWidth: 980, marginInline: "auto",
          }}>
            A síntese certa, no<br />tempo certo da decisão.
          </h1>
          <p style={{
            fontSize: 18, lineHeight: 1.6, color: "rgba(255,255,255,0.85)",
            marginTop: 32, maxWidth: 640, marginInline: "auto",
          }}>
            Encontre revisões rápidas sobre os principais temas da Política Nacional de Promoção da Saúde, prontas para informar gestores, equipes e pesquisadores.
          </p>
          <div style={{ maxWidth: 760, margin: "44px auto 0", position: "relative", zIndex: 30 }}>
            <SearchFilter query={query} setQuery={setQuery} year={year} setYear={setYear} years={years} />
          </div>
        </div>
      </section>

      <section id="rr-grid-top-b" style={{ maxWidth: 1280, margin: "-140px auto 0", padding: "0 32px 80px", position: "relative", zIndex: 5 }}>
        <div style={{ background: "#fff", borderRadius: 24, padding: "48px 40px 56px", boxShadow: "0 30px 80px -30px rgba(61,41,99,0.35)", border: "1px solid #efe6f3" }}>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-end", marginBottom: 28, gap: 24, flexWrap: "wrap" }}>
            <div>
              <h2 style={{ fontSize: 26, fontWeight: 700, color: "var(--rr-primary)", margin: 0 }}>Todas as revisões</h2>
              <p style={{ fontSize: 14, color: "#888", marginTop: 6 }}>
                {filtered.length} {filtered.length === 1 ? "revisão encontrada" : "revisões encontradas"}
              </p>
            </div>
            <div style={{ display: "flex", alignItems: "center", gap: 12, fontSize: 12, color: "#888" }}>
              <Waves color="var(--rr-secondary)" width={50} strokeWidth={1.2} />
              <span>Atualizado em abril/2026</span>
            </div>
          </div>
          <div style={{ display: "grid", gridTemplateColumns: cols, gap }}>
            {pageItems.map((r) => <Card key={r.slug} revisao={r} />)}
          </div>
          {loading && (
            <div style={{ padding: "80px 0", textAlign: "center", color: "#888" }}>
              Carregando revisões…
            </div>
          )}
          {!loading && filtered.length === 0 && (
            <div style={{ padding: "80px 0", textAlign: "center", color: "#888" }}>
              Nenhuma revisão encontrada. Tente ajustar a busca.
            </div>
          )}
          <Pagination page={page} totalPages={totalPages} onChange={goTo} />
        </div>
      </section>

      <SiteFooter />
    </div>
  );
}

function LandingTweaks({ tweaks, setTweak }) {
  return (
    <TweaksPanel title="Tweaks">
      <TweakSection label="Cores">
        <TweakColor label="Primária" value={tweaks.primaryColor} onChange={(v) => setTweak("primaryColor", v)} />
        <TweakColor label="Profunda" value={tweaks.deepColor} onChange={(v) => setTweak("deepColor", v)} />
        <TweakColor label="Secundária" value={tweaks.secondaryColor} onChange={(v) => setTweak("secondaryColor", v)} />
        <TweakColor label="Clara" value={tweaks.lightColor} onChange={(v) => setTweak("lightColor", v)} />
      </TweakSection>
      <TweakSection label="Grid">
        <TweakRadio label="Densidade" value={tweaks.gridDensity}
          onChange={(v) => setTweak("gridDensity", v)}
          options={[
            { value: "compact", label: "Compacto" },
            { value: "comfortable", label: "Conforto" },
            { value: "spacious", label: "Espaçoso" },
          ]} />
      </TweakSection>
      <TweakSection label="Card">
        <TweakRadio label="Estilo" value={tweaks.cardStyle}
          onChange={(v) => setTweak("cardStyle", v)}
          options={[
            { value: "sober", label: "Sóbrio" },
            { value: "hybrid", label: "Híbrido" },
            { value: "line", label: "Linha" },
          ]} />
      </TweakSection>
    </TweaksPanel>
  );
}

function App() {
  const [tweaks, setTweak] = useTweaks(TWEAK_DEFAULTS);
  const [revisoes, setRevisoes] = React.useState(null);
  React.useEffect(() => { applyTheme(tweaks); }, [tweaks]);
  React.useEffect(() => {
    fetch("content/index.json")
      .then((r) => r.json())
      .then((d) => setRevisoes(d))
      .catch(() => setRevisoes([]));
  }, []);

  return (
    <React.Fragment>
      <LandingVariantA tweaks={tweaks} revisoes={revisoes || []} loading={revisoes === null} />
      <LandingTweaks tweaks={tweaks} setTweak={setTweak} />
    </React.Fragment>
  );
}

ReactDOM.createRoot(document.getElementById("root")).render(<App />);
