// ============================================================
// Evidia · Versão MOBILE (<768px) — revisão pro (alta qualidade).
// Hero sem foto/eyebrow · manifesto enxuto · pilares 1-card com
// setas+dots · comunidade empilhada · casos em carrossel com dots ·
// tecnologia com tela do portal · convite compacto.
// Reaproveita window.BrazilMap.
// ============================================================

const arcTxt = { background: "var(--grad-arc)", WebkitBackgroundClip: "text", backgroundClip: "text", color: "transparent" };

const MHeader = () => {
  const [open, setOpen] = React.useState(false);
  const links = [["Quem somos", "#m-quem"], ["O que entregamos", "#m-pilares"], ["Médicos da rede", "#m-casos"], ["Como entrar", "#m-como"], ["FAQ", "FAQ.html"]];
  return (
    <React.Fragment>
      <header style={{ position: "fixed", top: 0, left: 0, right: 0, height: 54, zIndex: 1000, background: "rgba(255,255,255,0.95)", backdropFilter: "blur(10px)", borderBottom: "1px solid var(--line)", display: "flex", alignItems: "center", justifyContent: "space-between", padding: "0 20px" }}>
        <a href="#m-top"><img src="assets/logo_evidia_notag.png" alt="Evidia" style={{ height: 36, display: "block" }} /></a>
        <button onClick={() => setOpen(true)} aria-label="Menu" style={{ background: "none", border: "none", padding: 8, cursor: "pointer", color: "var(--blue-900)" }}>
          <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><line x1="3" y1="6" x2="21" y2="6" /><line x1="3" y1="12" x2="21" y2="12" /><line x1="3" y1="18" x2="21" y2="18" /></svg>
        </button>
      </header>
      {open &&
      <div style={{ position: "fixed", inset: 0, zIndex: 1100, background: "#fff", display: "flex", flexDirection: "column", padding: "20px" }}>
          <div style={{ display: "flex", alignItems: "center", justifyContent: "space-between", marginBottom: 24 }}>
            <img src="assets/logo_evidia_notag.png" alt="Evidia" style={{ height: 42 }} />
            <button onClick={() => setOpen(false)} aria-label="Fechar" style={{ background: "none", border: "none", padding: 8, color: "var(--blue-900)" }}>
              <svg width="26" height="26" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" /></svg>
            </button>
          </div>
          {links.map((l, i) =>
        <a key={i} href={l[1]} onClick={() => setOpen(false)} style={{ fontFamily: "var(--font-display)", fontSize: 26, fontWeight: 600, color: "var(--blue-900)", textDecoration: "none", padding: "14px 0", borderBottom: "1px solid var(--line)", letterSpacing: "-0.01em" }}>{l[0]}</a>
        )}
          <a href="https://credenciamento.evidiasaude.com.br/interesse" target="_blank" rel="noopener noreferrer" onClick={() => setOpen(false)} style={{ marginTop: "auto", textAlign: "center", background: "var(--indigo-600)", color: "#fff", textDecoration: "none", fontWeight: 600, fontSize: 16, padding: "16px", borderRadius: 999 }}>Quero me credenciar</a>
          <a href="https://credenciamento.evidiasaude.com.br/login" target="_blank" rel="noopener noreferrer" onClick={() => setOpen(false)} style={{ marginTop: 12, textAlign: "center", color: "var(--blue-900)", textDecoration: "none", fontWeight: 500, fontSize: 15.5, padding: "14px", borderRadius: 999, border: "1px solid var(--line)" }}>Entrar</a>
        </div>
      }
    </React.Fragment>);

};

// CTAs do convite (fundo escuro)
const MCtas = ({ dark }) =>
<div style={{ marginTop: 26, display: "flex", flexDirection: "column", gap: 11 }}>
    <a href="https://credenciamento.evidiasaude.com.br/interesse" target="_blank" rel="noopener noreferrer" style={{ textAlign: "center", background: dark ? "#fff" : "var(--indigo-600)", color: dark ? "var(--indigo-700)" : "#fff", textDecoration: "none", fontWeight: 600, fontSize: 16, padding: "15px", borderRadius: 999 }}>Quero me credenciar</a>
    <a href="#fale-especialista" style={{ textAlign: "center", color: dark ? "#fff" : "var(--blue-900)", textDecoration: "none", fontWeight: 500, fontSize: 16, padding: "14px", borderRadius: 999, border: dark ? "1px solid rgba(255,255,255,0.3)" : "1px solid var(--line)" }}>Fale com um especialista</a>
  </div>;


const PILL = [
{ n: "01", k: "Conexão", t: "Contrato único.", d: "Acesse múltiplas operadoras com um único credenciamento. Sem negociar plano a plano.", id: "pilar-cover-1" },
{ n: "02", k: "Comunidade", t: "Você não negocia sozinho.", d: "Faça parte de uma comunidade que tem voz e peso junto às operadoras.", id: "pilar-cover-2" },
{ n: "03", k: "Tecnologia", t: "Portal único, 100% gratuito.", d: "Prontuário, faturamento e IA clínica numa só interface. Gratuito para o médico.", id: "pilar-cover-3" },
{ n: "04", k: "Segurança", t: "Previsibilidade financeira.", d: "Auditorias e regras predefinidas tornam seu faturamento mais seguro e previsível.", id: "pilar-cover-4-mobile" }];


const COMM = [
{ t: "Cuidado baseado em evidências.", d: "Protocolos revisados pela própria comunidade médica." },
{ t: "Melhores desfechos.", d: "Condutas padronizadas melhoram o resultado do paciente." },
{ t: "Menos desperdício.", d: "Menos retrabalho, menos exame redundante, menos glosa." }];


const CASES = [
{ name: "Prof. Dr. Elie Fiss", meta: "Pneumologista · São Paulo · SP", real: "assets/photo_dr_elie.png", pos: "center 12%", q: "Quis fazer parte de um grupo que leva a sério a medicina de excelência. É essa a mudança que eu quero ver na saúde." },
{ name: "Dra. Amanda Moreto", meta: "Gastro · Araraquara · SP", real: "assets/photo_doctor_amanda.jpg", pos: "center 2%", q: "O que me convenceu foi tirar a parte administrativa da minha mesa e devolver esse tempo ao paciente." },
{ name: "Dr. Renato Macchione", meta: "Oftalmologista · Sorocaba · SP", real: "assets/photo_doctor_renato.jpg", pos: "center 22%", q: "O acesso a operadoras que eu não alcançava sozinho foi o que me convenceu. E tudo num credenciamento só, sem negociação plano a plano." },
{ name: "Dr. Luiz Felipe Dipe", meta: "Reumatologista · Santos · SP", real: "assets/photo_doctor_dipe.jpg", pos: "center 18%", q: "Ser fundador é estar na frente de uma mudança que a categoria precisa: o médico sendo valorizado de novo. Quis liderar isso na minha cidade." }];


const NUMS = [
{ v: "500", sfx: "+", k: "Membros ativos", d: "Médicos credenciados na rede hoje." },
{ v: "1", sfx: " milhão+", k: "Consultas", d: "Já realizadas por médicos da rede." },
{ v: "R$ 200", sfx: " milhões", k: "Receita membros", d: "Faturados por médicos da rede." }];


const sec = { padding: "44px 22px" };
const eyebrow = { fontFamily: "var(--font-eyebrow)", fontSize: 10.5, fontWeight: 700, letterSpacing: "0.2em", textTransform: "uppercase", color: "var(--cyan-700)", marginBottom: 14 };
const rail = { display: "flex", gap: 14, overflowX: "auto", scrollSnapType: "x mandatory", paddingBottom: 6, WebkitOverflowScrolling: "touch", scrollbarWidth: "none" };

// rastreia o card ativo de um carrossel de scroll livre + navegação por setas
function useRail() {
  const ref = React.useRef(null);
  const [idx, setIdx] = React.useState(0);
  const step = () => {
    const el = ref.current;if (!el) return 0;
    const card = el.querySelector("[data-card]");
    return card ? card.offsetWidth + 14 : 0;
  };
  const onScroll = () => {
    const el = ref.current,s = step();
    if (el && s) setIdx(Math.max(0, Math.round(el.scrollLeft / s)));
  };
  const go = (dir) => {
    const el = ref.current,s = step();
    if (el && s) el.scrollBy({ left: dir * s, behavior: "smooth" });
  };
  return { ref, idx, onScroll, go };
}

const Dots = ({ n, idx, dark }) =>
<div style={{ display: "flex", gap: 7, justifyContent: "center" }}>
    {Array.from({ length: n }).map((_, i) =>
  <span key={i} style={{ width: i === idx ? 22 : 7, height: 7, borderRadius: 999, background: i === idx ? dark ? "var(--cyan-400)" : "var(--blue-600)" : dark ? "rgba(255,255,255,0.28)" : "var(--ink-200)", transition: "width .22s, background .22s" }}></span>
  )}
  </div>;


const Arrow = ({ dir, onClick, disabled }) =>
<button onClick={onClick} disabled={disabled} aria-label={dir < 0 ? "Anterior" : "Próximo"} style={{ width: 42, height: 42, flexShrink: 0, borderRadius: "50%", border: "1px solid var(--line)", background: "#fff", color: "var(--blue-900)", display: "inline-flex", alignItems: "center", justifyContent: "center", cursor: disabled ? "default" : "pointer", opacity: disabled ? 0.35 : 1, transition: "opacity .15s" }}>
    <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
      {dir < 0 ? <polyline points="15 18 9 12 15 6" /> : <polyline points="9 18 15 12 9 6" />}
    </svg>
  </button>;


// Notebook flutuante com dashboard real (versão 1 — orientação original)
const MLaptop = () =>
<img src="assets/laptop-portal.png" alt="Portal Evidia — dashboard do médico no notebook" style={{ width: "100%", height: "100%", objectFit: "cover", objectPosition: "center center", display: "block" }} />;

// PILARES · accordion vertical com cascata de bounce (substituiu o carrossel)
// >>> backup do carrossel original em archive/10-mobile.carousel-backup.jsx <<<

// ícones por categoria
const MIconNetwork = ({ color, size = 24 }) =>
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" strokeLinecap="round" strokeLinejoin="round">
    <circle cx="12" cy="12" r="2.5" fill={color} />
    <circle cx="5" cy="5" r="2" stroke={color} strokeWidth="1.75" />
    <circle cx="19" cy="5" r="2" stroke={color} strokeWidth="1.75" />
    <circle cx="12" cy="20.5" r="2" stroke={color} strokeWidth="1.75" />
    <line x1="6.9" y1="6.9" x2="10.6" y2="10.6" stroke={color} strokeWidth="1.75" />
    <line x1="17.1" y1="6.9" x2="13.4" y2="10.6" stroke={color} strokeWidth="1.75" />
    <line x1="12" y1="14.5" x2="12" y2="18.5" stroke={color} strokeWidth="1.75" />
  </svg>;

const MIconPortal = ({ color, size = 24 }) =>
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round">
    <rect x="2" y="3" width="20" height="14" rx="2.5" />
    <line x1="8" y1="21" x2="16" y2="21" />
    <line x1="12" y1="17" x2="12" y2="21" />
    <line x1="6" y1="10" x2="8.5" y2="10" />
    <line x1="6" y1="13" x2="10" y2="13" />
    <polyline points="13 12 15.5 9.5 18 12" strokeWidth="1.5" />
  </svg>;

const MIconShield = ({ color, size = 24 }) =>
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round">
    <path d="M12 2L4 5.5v5.5c0 5.25 3.5 9.8 8 11 4.5-1.2 8-5.75 8-11V5.5L12 2z" />
    <polyline points="8.5 12 10.5 14 15.5 10" />
  </svg>;

const MIconCommunity = ({ color, size = 24 }) =>
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round">
    <circle cx="9" cy="7" r="3" />
    <path d="M3 21v-2a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v2" />
    <circle cx="18.5" cy="8" r="2.5" />
    <path d="M22 21v-1.5a3.5 3.5 0 0 0-2.8-3.4" />
  </svg>;

const MBENEFITS = [
{ id: 1, title: "Credenciamento único.", body: "Acesse múltiplas operadoras com um único credenciamento. Sem negociar plano a plano.", from: "#00a3e0", to: "#0178ab", Icon: MIconNetwork },
{ id: 2, title: "Portal único.", body: "Prontuário, faturamento e apoio em glosas numa só interface. Gratuito para o médico.", from: "#1e62a4", to: "#444ca2", Icon: MIconPortal },
{ id: 3, title: "Previsibilidade financeira.", body: "Regras claras reduzem divergências e tornam seu faturamento mais seguro e previsível.", from: "#7868e6", to: "#583e96", Icon: MIconShield },
{ id: 4, title: "Comunidade médica.", body: "Faça parte de uma comunidade que tem voz e peso junto às operadoras.", from: "#00b89a", to: "#00a3e0", Icon: MIconCommunity }];

const MAccordionCard = ({ card, isOpen, onToggle, pulse, cascadeIndex }) => {
  const { from, to, Icon, title, body } = card;
  const animatesChevron = pulse && cascadeIndex >= 0;
  return (
    <div onClick={onToggle} style={{ padding: "1.5px", borderRadius: 17, background: "linear-gradient(135deg, " + from + ", " + to + ")", cursor: "pointer", WebkitTapHighlightColor: "transparent" }}>
      <div style={{ background: "#0d1b2e", borderRadius: "15.5px", padding: isOpen ? "15px 18px 12px" : "13px 18px 12px" }}>
        <div style={{ display: "flex", flexDirection: "column", alignItems: "center", textAlign: "center", gap: 9 }}>
          <Icon color={from} size={24} />
          <span style={{ fontFamily: "var(--font-display)", fontSize: 15.5, fontWeight: 600, color: "#fff", letterSpacing: "-0.015em", lineHeight: 1.2 }}>{title}</span>
        </div>
        {!isOpen &&
        <div style={{ marginTop: 8, display: "flex", alignItems: "center", justifyContent: "center", gap: 4 }}>
            <span style={{ fontFamily: "var(--font-display)", fontSize: 12.5, fontWeight: 500, color: "#00a3e0", lineHeight: 1 }}>Saiba mais</span>
            <svg className={animatesChevron ? "m-chevron-pulse" : ""} style={{ display: "block", animationDelay: 2 + cascadeIndex * 1.7 + "s" }} width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="#00a3e0" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
              <polyline points="6 9 12 15 18 9" />
            </svg>
          </div>
        }
        {isOpen &&
        <React.Fragment>
            <p style={{ marginTop: 9, textAlign: "center", fontFamily: "var(--font-display)", fontSize: 13.5, lineHeight: 1.6, color: "rgba(255,255,255,0.7)" }}>{body}</p>
            <div style={{ marginTop: 10, display: "flex", alignItems: "center", justifyContent: "center", gap: 4 }}>
              <span style={{ fontFamily: "var(--font-display)", fontSize: 12, color: "rgba(255,255,255,0.35)", fontWeight: 400 }}>Fechar</span>
              <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="rgba(255,255,255,0.35)" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round">
                <polyline points="18 15 12 9 6 15" />
              </svg>
            </div>
          </React.Fragment>
        }
      </div>
    </div>);

};

const MConnector = ({ fromColor, toColor }) =>
<div style={{ width: 2, height: 15, margin: "0 auto", background: "linear-gradient(to bottom, " + fromColor + ", " + toColor + ")", opacity: 0.8 }}></div>;

const MPillars = () => {
  const [openId, setOpenId] = React.useState(1);
  const [pulse, setPulse] = React.useState(false);
  const sectionRef = React.useRef(null);
  const toggle = (id) => setOpenId((prev) => prev === id ? null : id);

  React.useEffect(() => {
    const el = sectionRef.current;
    if (!el) return;
    let fired = false;
    const check = () => {
      if (fired) return;
      const rect = el.getBoundingClientRect();
      const vh = window.innerHeight || document.documentElement.clientHeight;
      // dispara quando o topo da seção entra na metade superior da viewport
      const visibleEnough = rect.top < vh * 0.6 && rect.bottom > vh * 0.1;
      if (visibleEnough) {
        fired = true;
        setPulse(true);
        setTimeout(() => setPulse(false), 7400);
        window.removeEventListener("scroll", check, true);
      }
    };
    // captura na fase de captura → pega scroll de QUALQUER container aninhado
    // (window no site real, o div do chassis no mockup) sem precisar detectá-lo
    window.addEventListener("scroll", check, { passive: true, capture: true });
    const timers = [300, 900, 1600].map((t) => setTimeout(check, t));
    return () => {
      window.removeEventListener("scroll", check, true);
      timers.forEach(clearTimeout);
    };
  }, []);

  return (
    <section ref={sectionRef} style={{ padding: "44px 20px", background: "#050a14" }}>
      <style>{"@keyframes mChevronTapTap{0%{transform:translateY(0)}50%{transform:translateY(5px)}100%{transform:translateY(0)}}.m-chevron-pulse{animation:mChevronTapTap .52s ease-in-out 2 both}@media (prefers-reduced-motion:reduce){.m-chevron-pulse{animation:none}}"}</style>
      <div style={{ ...eyebrow, color: "#00a3e0" }}>Por que fazer parte</div>
      <h2 style={{ fontFamily: "var(--font-display)", fontSize: 26, lineHeight: 1.12, fontWeight: 600, letterSpacing: "-0.025em", margin: "0 0 20px", color: "#fff" }}>O que você ganha ao entrar na rede.</h2>
      <div>
        {(() => {
          let casc = 0;
          return MBENEFITS.map((card, i) => {
            const open = openId === card.id;
            const cascadeIndex = open ? -1 : casc++;
            return (
              <React.Fragment key={card.id}>
                <MAccordionCard card={card} isOpen={open} onToggle={() => toggle(card.id)} pulse={pulse} cascadeIndex={cascadeIndex} />
                {i < MBENEFITS.length - 1 &&
                <MConnector fromColor={card.to} toColor={MBENEFITS[i + 1].from} />}
              </React.Fragment>);

          });
        })()}
      </div>
    </section>);

};

// CASOS · carrossel de scroll + dots
const MCases = () => {
  const { ref, idx, onScroll } = useRail();
  return (
    <section style={{ padding: "44px 0 44px 22px", background: "#fff" }}>
      <div style={{ paddingRight: 22 }}>
        <div style={eyebrow}>Quem já faz parte</div>
        <h2 style={{ fontFamily: "var(--font-display)", fontSize: 28, lineHeight: 1.12, fontWeight: 600, letterSpacing: "-0.02em", margin: "0 0 14px", color: "var(--blue-900)" }}>Médicos que confiaram na Evidia.</h2>
        <p style={{ margin: "0 0 22px", fontSize: 15, lineHeight: 1.55, color: "var(--ink-600)" }}>Conheça alguns dos médicos que já fazem parte da Evidia e atuam como referência em suas regiões.</p>
      </div>
      <div ref={ref} onScroll={onScroll} style={rail}>
        {CASES.map((d, i) =>
        <div key={i} data-card style={{ scrollSnapAlign: "start", flex: "0 0 82%", border: "1px solid var(--line)", borderRadius: 18, overflow: "hidden", boxShadow: "var(--shadow-sm)" }}>
            <div style={{ position: "relative", aspectRatio: "3/2", background: "var(--ink-100)" }}>
              <img src={d.real} alt={d.name} style={{ width: "100%", height: "100%", objectFit: "cover", objectPosition: d.pos }} />
              <div style={{ position: "absolute", left: 14, top: 14, padding: "5px 11px", background: "rgba(255,255,255,0.92)", borderRadius: 999, fontFamily: "var(--font-eyebrow)", fontSize: 8.5, fontWeight: 700, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--blue-700)" }}>Membro fundador</div>
            </div>
            <div style={{ padding: "20px 22px 24px" }}>
              <div style={{ fontFamily: "var(--font-eyebrow)", fontSize: 9.5, fontWeight: 600, letterSpacing: "0.18em", textTransform: "uppercase", color: "var(--ink-500)", marginBottom: 6 }}>{d.meta}</div>
              <div style={{ fontFamily: "var(--font-display)", fontSize: 19, fontWeight: 600, color: "var(--blue-900)", marginBottom: 12 }}>{d.name}</div>
              <blockquote style={{ margin: 0, fontFamily: "var(--font-display)", fontSize: 15.5, fontStyle: "italic", lineHeight: 1.45, color: "var(--ink-700)", borderLeft: "2px solid var(--cyan-500)", paddingLeft: 14 }}>“{d.q}”</blockquote>
            </div>
          </div>
        )}
        <div style={{ flex: "0 0 8px" }}></div>
      </div>
      <div style={{ paddingRight: 22, marginTop: 20 }}><Dots n={CASES.length} idx={idx} /></div>
    </section>);

};

// TECNOLOGIA · renderiza o MESMO portal do desktop (PortalMock 1248×700) escalado p/ a largura mobile
const MPortalShot = () => {
  const Portal = window.PortalMock;
  const wrapRef = React.useRef(null);
  const [scale, setScale] = React.useState(0.27);
  React.useEffect(() => {
    const el = wrapRef.current;
    if (!el) return;
    const update = () => { const w = el.clientWidth; if (w > 0) setScale(w / 1248); };
    update();
    const ro = new ResizeObserver(update);
    ro.observe(el);
    window.addEventListener("resize", update);
    window.addEventListener("load", update);
    const timers = [200, 800, 1600, 3000].map((t) => setTimeout(update, t));
    return () => { ro.disconnect(); window.removeEventListener("resize", update); window.removeEventListener("load", update); timers.forEach(clearTimeout); };
  }, []);
  return (
    <div ref={wrapRef} style={{ position: "relative", width: "100%", height: Math.round(700 * scale), overflow: "hidden", background: "#fff" }}>
      <div style={{ position: "absolute", top: 0, left: 0, width: 1248, height: 700, transform: "scale(" + scale + ")", transformOrigin: "top left" }}>
        {Portal ? <Portal /> : null}
      </div>
    </div>);

};

// ============================================================
// COMO ENTRAR NA REDE · stepper vertical compacto + motion scroll-linked
// (portado do mockup aprovado · backup: archive/10-mobile.pre-comoentrar-backup.jsx)
// ============================================================
const EASE = "cubic-bezier(.2,.7,.2,1)";
const clamp01 = (x) => x < 0 ? 0 : x > 1 ? 1 : x;
const easeInOut = (x) => x < 0.5 ? 2 * x * x : 1 - Math.pow(-2 * x + 2, 2) / 2;

const IconUpload = ({ color, size = 19 }) =>
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
    <path d="M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z" /><polyline points="14 3 14 8 19 8" /><path d="M12 18v-5" /><polyline points="9.5 14.5 12 12 14.5 14.5" />
  </svg>;
const IconReview = ({ color, size = 19 }) =>
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
    <path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2" /><circle cx="9" cy="7" r="4" /><polyline points="16 11 18 13 22 9" />
  </svg>;
const IconContract = ({ color, size = 19 }) =>
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
    <rect x="5" y="3" width="14" height="18" rx="2" /><line x1="8.5" y1="8" x2="15.5" y2="8" /><line x1="8.5" y1="11.5" x2="13" y2="11.5" /><path d="M8 16.5c1-1 2-1 3 0s2 1 3 0" />
  </svg>;
const IconReady = ({ color, size = 19 }) =>
<svg width={size} height={size} viewBox="0 0 24 24" fill="none" stroke={color} strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round">
    <circle cx="12" cy="12" r="9" /><polyline points="8.5 12 11 14.5 15.5 9.5" />
  </svg>;

const STEPS = [
{ n: "01", name: "Cadastro e documentos", desc: "Você preenche seu perfil e envia os documentos pelo portal. Simples e 100% digital.", acc: "#6b3f9c", accBg: "#efeaf5", Icon: IconUpload },
{ n: "02", name: "Revisão do perfil", desc: "Nossa equipe revisa suas informações. Se precisar, agendamos uma videochamada rápida para tirar dúvidas.", acc: "#1e62a4", accBg: "#e7f0f9", Icon: IconReview },
{ n: "03", name: "Contrato e tabela", desc: "Você revisa a tabela base de valores e assina o contrato de credenciamento. Tudo transparente, sem surpresas.", acc: "#00a3e0", accBg: "#e0f3fb", Icon: IconContract },
{ n: "04", name: "Pronto para atender", desc: "Credenciamento concluído. Você já pode atender pelas operadoras parceiras da sua região e faturar pelo portal único.", acc: "#1ec9a0", accBg: "#e2f7f1", Icon: IconReady }];

function ComoEntrarSection() {
  const reduce = typeof window !== "undefined" && window.matchMedia && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
  const sectionRef = React.useRef(null);
  const circleRefs = React.useRef([]);
  const scrollerRef = React.useRef(null);

  // dispara UMA vez quando o 1º bloco aparece; só fade-in (sem fade-out)
  const [play, setPlay] = React.useState(reduce ? true : false);

  React.useEffect(() => {
    if (reduce || play) return;
    const el = sectionRef.current; if (!el) return;
    let done = false;
    const check = () => {
      if (done) return;
      const r = el.getBoundingClientRect();
      const vh = window.innerHeight || document.documentElement.clientHeight;
      // o 1º bloco entrou na metade superior da viewport
      if (r.top < vh * 0.72 && r.bottom > vh * 0.1) {
        done = true; setPlay(true);
        window.removeEventListener("scroll", check, true);
        clearInterval(iv);
      }
    };
    window.addEventListener("scroll", check, { passive: true, capture: true });
    const iv = setInterval(check, 160);
    return () => { window.removeEventListener("scroll", check, true); clearInterval(iv); };
  }, [reduce, play]);

  return (
    <section ref={sectionRef} style={{ padding: "34px 22px 38px", background: "var(--ink-050)", borderTop: "1px solid var(--line)" }}>
      <div style={{ marginBottom: 24 }}>
        <p style={{ fontFamily: "var(--font-eyebrow)", fontSize: 10.5, fontWeight: 700, letterSpacing: "0.2em", textTransform: "uppercase", color: "var(--cyan-700)", marginBottom: 11 }}>Como entrar</p>
        <h2 style={{ fontFamily: "var(--font-display)", fontSize: 25, lineHeight: 1.1, fontWeight: 600, letterSpacing: "-0.025em", color: "var(--blue-900)" }}>Passo a passo.</h2>
      </div>

      <div style={{ display: "flex", flexDirection: "column", position: "relative" }}>
        {STEPS.map((s, i) => {
          const Icon = s.Icon;
          const last = i === STEPS.length - 1;
          const nextAcc = last ? s.acc : STEPS[i + 1].acc;
          const a = play ? 1 : 0;
          const segFill = last ? 0 : (play ? 1 : 0);
          const isReached = reduce || play;
          const delay = (i * 0.30).toFixed(2) + "s";              // cascata suave (stagger maior)
          const segDelay = (i * 0.30 + 0.12).toFixed(2) + "s";
          const lastDone = last && isReached;
          const circleBg = lastDone ? s.acc : isReached ? s.accBg : "#fff";
          const numColor = lastDone ? "#fff" : s.acc;

          return (
            <div key={i} style={{ display: "flex", gap: 14, paddingBottom: last ? 0 : 16 }}>
              <div style={{ flex: "0 0 44px", display: "flex", flexDirection: "column", alignItems: "center" }}>
                <div style={{ position: "relative", flex: "0 0 auto" }}>
                  <div data-ce-c={i} ref={(el) => {circleRefs.current[i] = el;}} style={{
                    position: "relative", zIndex: 1,
                    width: 44, height: 44, borderRadius: "50%",
                    background: circleBg, border: "2px solid " + s.acc,
                    display: "flex", alignItems: "center", justifyContent: "center",
                    fontFamily: "var(--font-display)", fontSize: 19, fontWeight: 700, letterSpacing: "-0.03em", color: numColor,
                    boxShadow: "0 2px 8px rgba(10,37,64,0.07)",
                    opacity: 0.35 + 0.65 * a, transform: "scale(" + (0.86 + 0.14 * a) + ")",
                    transition: "opacity .8s " + EASE + ", transform .8s " + EASE + ", background .9s " + EASE + ", color .8s " + EASE, transitionDelay: delay }}>{s.n}</div>
                </div>
                {!last &&
                <div style={{ position: "relative", width: 3, flex: "1 1 auto", marginTop: 5, marginBottom: 5, borderRadius: 999, background: "var(--ink-100)", overflow: "hidden", minHeight: 14 }}>
                  <div style={{ position: "absolute", inset: 0, borderRadius: 999, background: "linear-gradient(to bottom, " + s.acc + ", " + nextAcc + ")", transformOrigin: "top", transform: "scaleY(" + segFill + ")", transition: "transform .85s cubic-bezier(.2,.7,.2,1)", transitionDelay: segDelay }}></div>
                </div>}
              </div>

              <div style={{ display: "flex", gap: 12, flex: 1, paddingTop: 1, opacity: a, transform: "translateY(" + ((1 - a) * 14).toFixed(2) + "px)", transition: "opacity .8s " + EASE + ", transform .8s " + EASE, transitionDelay: delay }}>
                <div style={{ flex: "0 0 36px", width: 36, height: 36, borderRadius: 11, background: s.accBg, display: "flex", alignItems: "center", justifyContent: "center", color: s.acc, marginTop: 2 }}>
                  <Icon color={s.acc} size={19} />
                </div>
                <div style={{ flex: 1, paddingBottom: 4 }}>
                  <h3 style={{ fontFamily: "var(--font-display)", fontSize: 16.5, fontWeight: 700, letterSpacing: "-0.015em", color: "var(--blue-900)", lineHeight: 1.2, marginBottom: 4 }}>{s.name}</h3>
                  <p style={{ fontFamily: "var(--font-display)", fontSize: 13, fontWeight: 400, lineHeight: 1.5, color: "var(--ink-600)" }}>{s.desc}</p>
                </div>
              </div>
            </div>);

        })}
      </div>
    </section>);

}

const MobileHome = () => {
  const Convite = window.ConviteCard;
  const heroRef = React.useRef(null);
  React.useEffect(() => {
    const vh = () => (window.visualViewport ? window.visualViewport.height : window.innerHeight);
    const setH = () => { if (heroRef.current) heroRef.current.style.minHeight = Math.round(vh() - 54) + "px"; };
    setH();
    window.addEventListener("load", setH);
    const t = setTimeout(setH, 250);
    const onOrient = () => setTimeout(setH, 350);
    window.addEventListener("orientationchange", onOrient);
    return () => { window.removeEventListener("load", setH); clearTimeout(t); window.removeEventListener("orientationchange", onOrient); };
  }, []);
  return (
    <div id="m-top" style={{ fontFamily: "var(--font-body)", paddingTop: 54, paddingBottom: 12, overflowX: "hidden" }}>

      {/* HERO · foto translúcida como composição de fundo, atrás do conteúdo agrupado */}
      <section ref={heroRef} style={{ position: "relative", padding: "clamp(36px, 7vh, 68px) 22px 14px", background: "var(--blue-050)", minHeight: "calc(100svh - 54px)", boxSizing: "border-box", display: "flex", flexDirection: "column", overflow: "hidden" }}>

        {/* Foto Dr. Renato — faixa DIREITA em altura total, preenchendo a hero; fade na esquerda e dissolve na base (zona do CTA) */}
        <div style={{
          position: "absolute", top: 0, right: 0, height: "100%", width: "58%",
          zIndex: 0, pointerEvents: "none",
          WebkitMaskImage: "linear-gradient(to left, black 64%, transparent 100%)",
          maskImage: "linear-gradient(to left, black 64%, transparent 100%)",
        }}>
          <img src="assets/photo_doctor_renato.jpg" alt="" style={{ width: "100%", height: "100%", objectFit: "cover", objectPosition: "22% 5%", display: "block", opacity: 0.92, WebkitMaskImage: "linear-gradient(to bottom, black 70%, transparent 95%)", maskImage: "linear-gradient(to bottom, black 70%, transparent 95%)" }} />
        </div>

        {/* Conteúdo — distribuído na altura via spacers proporcionais; texto preso à coluna esquerda */}
        <div style={{ position: "relative", zIndex: 1, flex: 1, display: "flex", flexDirection: "column" }}>
          <h1 style={{ fontFamily: "var(--font-display)", fontSize: 38, lineHeight: 1.1, fontWeight: 600, letterSpacing: "-0.03em", margin: 0, color: "var(--blue-900)", maxWidth: 250 }}>
            Foque na medicina.<br />
            <span style={arcTxt}>Nós cuidamos do resto.</span>
          </h1>

          <p style={{ marginTop: 18, fontSize: 15.5, lineHeight: 1.55, color: "var(--ink-600)", maxWidth: 215 }}>
            A Evidia conecta você a operadoras e pacientes com um único credenciamento. Portal único e apoio em faturamento e glosas, sem mensalidade para o médico.
          </p>

          <div style={{ flex: "1 1 0", minHeight: 24 }}></div>

          <div style={{ display: "flex", flexDirection: "column" }}>
            <a href="https://credenciamento.evidiasaude.com.br/interesse" target="_blank" rel="noopener noreferrer" style={{ textAlign: "center", background: "var(--indigo-600)", color: "#fff", textDecoration: "none", fontWeight: 600, fontSize: 16, padding: "15px", borderRadius: 999 }}>Quero me credenciar</a>
            <a href="#fale-especialista" style={{ marginTop: 12, textAlign: "center", color: "var(--blue-700)", textDecoration: "none", fontWeight: 500, fontSize: 15, display: "flex", alignItems: "center", justifyContent: "center", gap: 6, padding: "8px 0", whiteSpace: "nowrap" }}>
              Fale com um especialista
              <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round" strokeLinejoin="round"><polyline points="9 18 15 12 9 6" /></svg>
            </a>
          </div>
        </div>
      </section>

      {/* MANIFESTO · enxuto (frase-âncora) */}
      <section id="m-quem" style={{ ...sec, background: "var(--bg-soft)" }}>
        <div style={eyebrow}>Quem é a Evidia</div>
        <p style={{ margin: 0, fontFamily: "var(--font-display)", fontSize: 21, lineHeight: 1.4, fontWeight: 500, color: "var(--blue-900)", letterSpacing: "-0.012em" }}>
          A Evidia reúne os <strong style={{ color: "var(--blue-700)" }}>melhores médicos</strong> sob um único credenciamento, dá a eles <strong style={{ color: "var(--blue-700)" }}>voz de comunidade</strong> e cuida de toda a parte chata: faturamento, glosa e tecnologia, para o médico <strong style={{ color: "var(--blue-700)" }}>focar na medicina</strong>.
        </p>
        <div className="ev-arc-rule" style={{ width: 80, marginTop: 26 }}></div>
      </section>

      {/* PILARES · carrossel 1-card com setas + dots */}
      <div id="m-pilares"><MPillars /></div>

      {/* COMUNIDADE · dark · blocos empilhados — OCULTA NO MOBILE (reversível: remover display:"none") */}
      <section id="m-comunidade" style={{ ...sec, background: "#050a14", color: "#fff", display: "none" }}>
        <h2 style={{ fontFamily: "var(--font-display)", fontSize: 29, lineHeight: 1.12, fontWeight: 600, letterSpacing: "-0.02em", margin: 0, color: "#fff" }}>
          Quando bons médicos se organizam a <span style={arcTxt}>saúde ganha.</span>
        </h2>
        <p style={{ margin: "14px 0 22px", fontSize: 15.5, lineHeight: 1.55, color: "rgba(255,255,255,0.72)" }}>
          Quando os melhores médicos do país compartilham protocolos e padrão clínico, todo o ecossistema de saúde ganha, e é isso que dá à rede relevância junto às operadoras.
        </p>
        <div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
          {COMM.map((c, i) =>
          <div key={i} style={{ background: "rgba(255,255,255,0.05)", border: "1px solid rgba(255,255,255,0.1)", borderRadius: 16, padding: "18px 20px" }}>
              <div style={{ fontFamily: "var(--font-display)", fontSize: 18, fontWeight: 600, color: "#fff", letterSpacing: "-0.015em", marginBottom: 7 }}>{c.t}</div>
              <div style={{ fontSize: 14, lineHeight: 1.5, color: "rgba(255,255,255,0.64)" }}>{c.d}</div>
            </div>
          )}
        </div>
      </section>

      {/* CASOS · carrossel de scroll + dots */}
      <div id="m-casos"><MCases /></div>

      {/* NÚMEROS · dark · empilhado */}
      <section style={{ ...sec, background: "#050a14", color: "#fff" }}>
        <div style={{ ...eyebrow, color: "var(--cyan-400)" }}>Evidia em números</div>
        <div style={{ display: "flex", flexDirection: "column", gap: 24 }}>
          {NUMS.map((n, i) =>
          <div key={i} style={{ borderTop: i === 0 ? "none" : "1px solid rgba(255,255,255,0.14)", paddingTop: i === 0 ? 0 : 20 }}>
              <div style={{ fontFamily: "var(--font-eyebrow)", fontSize: 10, fontWeight: 700, letterSpacing: "0.2em", textTransform: "uppercase", color: "var(--cyan-400)", marginBottom: 8 }}>{n.k}</div>
              <div style={{ display: "flex", alignItems: "baseline", flexWrap: "nowrap", gap: 3 }}>
                <span style={{ fontFamily: "var(--font-display)", fontSize: 52, lineHeight: 0.9, fontWeight: 600, color: "#fff", letterSpacing: "-0.03em" }}>{n.v}</span>
                <span style={{ fontSize: 22, fontWeight: 500, color: "rgba(255,255,255,0.7)" }}>{n.sfx}</span>
              </div>
              <div style={{ marginTop: 10, fontSize: 13.5, color: "rgba(255,255,255,0.6)" }}>{n.d}</div>
            </div>
          )}
        </div>
        <div style={{ marginTop: 22, fontSize: 12.5, color: "rgba(255,255,255,0.42)", fontStyle: "italic" }}>Dados consolidados da rede de parceiros credenciados Evidia.</div>
      </section>

      {/* COMO ENTRAR NA REDE · stepper vertical + motion scroll-linked (entre Números e FAQ) */}
      <div id="m-como"><ComoEntrarSection /></div>

      {/* TECNOLOGIA · OCULTA NO MOBILE (reversível: remover display:"none") — argumento já coberto no card "Portal único" e na hero */}
      <section id="m-tec" style={{ ...sec, background: "var(--bg-soft)", display: "none" }}>
        <div style={eyebrow}>Tecnologia</div>
        <h2 style={{ fontFamily: "var(--font-display)", fontSize: 30, lineHeight: 1.1, fontWeight: 600, letterSpacing: "-0.02em", margin: 0, color: "var(--blue-900)" }}>Um portal único. E <em style={{ fontStyle: "normal", color: "var(--blue-700)" }}>100% gratuito</em>.</h2>
        <p style={{ marginTop: 18, fontSize: 16, lineHeight: 1.6, color: "var(--ink-600)" }}>Prontuário, faturamento e IA clínica numa só interface. Sem mensalidade para o médico.</p>
        <div style={{ marginTop: 24, borderRadius: 16, overflow: "hidden", border: "1px solid var(--line)", boxShadow: "0 30px 60px rgba(10,37,64,0.16)", background: "#fff" }}>
          <div style={{ height: 34, background: "#0d1320", display: "flex", alignItems: "center", gap: 6, padding: "0 14px" }}>
            {["#ff5f57", "#febc2e", "#28c840"].map((c, i) => <span key={i} style={{ width: 9, height: 9, borderRadius: "50%", background: c }}></span>)}
            <div style={{ marginLeft: 12, flex: 1, height: 18, borderRadius: 5, background: "rgba(255,255,255,0.08)", display: "flex", alignItems: "center", padding: "0 10px", fontFamily: "var(--font-eyebrow)", fontSize: 8.5, letterSpacing: "0.08em", color: "rgba(255,255,255,0.55)" }}>portal.evidiasaude.com.br</div>
          </div>
          <MPortalShot />
        </div>
      </section>

      {/* TEM DÚVIDAS · só título + CTA */}
      <section id="m-faq" style={{ ...sec, background: "#fff" }}>
        <h2 style={{ fontFamily: "var(--font-display)", fontSize: 26, fontWeight: 600, letterSpacing: "-0.02em", margin: 0, color: "var(--blue-900)" }}>Tem dúvidas?</h2>
        <a href="FAQ.html" style={{ marginTop: 18, display: "inline-flex", alignItems: "center", gap: 9, fontFamily: "var(--font-eyebrow)", fontSize: 12, fontWeight: 600, letterSpacing: "0.12em", textTransform: "uppercase", color: "var(--blue-700)", textDecoration: "none", borderBottom: "2px solid var(--blue-200)", paddingBottom: 6 }}>Ver perguntas frequentes
          <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><polyline points="9 18 15 12 9 6" /></svg>
        </a>
      </section>

      {/* CONVITE · ConviteCard responsivo (mesmo componente do desktop) */}
      <section id="m-convite" style={{ padding: "12px", background: "var(--bg-soft)" }}>
        {Convite ? <Convite ctaHref="https://credenciamento.evidiasaude.com.br/interesse" especialistaHref="#fale-especialista" lead="A rede está se formando cidade a cidade. Entre agora e ajude a liderar essa mudança na sua região." /> : null}
      </section>

      {/* RODAPÉ */}
      <footer style={{ background: "#fff", borderTop: "1px solid var(--line)", padding: "40px 22px 28px" }}>
        <img src="assets/logo_evidia_notag.png" alt="Evidia" style={{ height: 36, marginBottom: 16 }} />
        <p style={{ margin: 0, fontSize: 14, lineHeight: 1.6, color: "var(--ink-600)", maxWidth: "36ch" }}>A rede que reúne os melhores médicos sob um único credenciamento.</p>
        <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 26, margin: "28px 0" }}>
          {[["Rede", [["Quem somos", "#m-quem"], ["O que entregamos", "#m-pilares"], ["Médicos da rede", "#m-casos"], ["Como entrar", "#m-como"]]], ["Acesso", [["Entrar", "https://credenciamento.evidiasaude.com.br/login"], ["Para operadoras", "mailto:anderson@grupoevidia.com.br?subject=Operadoras%20%C2%B7%20Evidia"], ["FAQ", "FAQ.html"], ["Fale conosco", "#fale-especialista"]]]].map((c, i) =>
          <div key={i}>
              <div style={{ fontFamily: "var(--font-eyebrow)", fontSize: 10, fontWeight: 700, letterSpacing: "0.16em", textTransform: "uppercase", color: "var(--blue-900)", marginBottom: 13 }}>{c[0]}</div>
              <div style={{ display: "flex", flexDirection: "column", gap: 11 }}>{c[1].map((l, j) => <a key={j} href={l[1]} target={/^https?:/.test(l[1]) ? "_blank" : undefined} rel={/^https?:/.test(l[1]) ? "noopener noreferrer" : undefined} style={{ fontSize: 14, color: "var(--ink-600)", textDecoration: "none" }}>{l[0]}</a>)}</div>
            </div>
          )}
        </div>
        <div style={{ paddingTop: 22, borderTop: "1px solid var(--line)", display: "flex", flexDirection: "column", gap: 16 }}>
          <div>
            <div style={{ fontSize: 13, color: "var(--ink-700)" }}><strong style={{ color: "var(--blue-900)" }}>Evidia Saúde LTDA</strong><span style={{ color: "var(--ink-500)" }}> · CNPJ 65.629.630/0001-75</span></div>
            <div style={{ marginTop: 6, fontSize: 12.5, color: "var(--ink-500)" }}>© 2026 Todos os direitos reservados.</div>
          </div>
          <div style={{ alignSelf: "flex-start", padding: "11px 20px", background: "var(--ink-950)", color: "#fff", borderRadius: 8, fontFamily: "var(--font-eyebrow)", fontSize: 12, fontWeight: 700, letterSpacing: "0.08em" }}>ANS – nº 42487-1</div>
        </div>
      </footer>

    </div>);

};

Object.assign(window, { MobileHome, MHeader, MLaptop });