/* global React, CoastGroup */
const { useState } = React;

// ====================================================================
// Group Health Score — at-a-glance editorial card
// ====================================================================
function GroupHealthCard() {
  const G = window.CoastGroup;
  const m = G.metrics;

  // Radar chart for the five metrics
  const dims = [
    { k: "1to1s",     v: 0.92, label: "Total 1to1s",      n: m.total1to1s.value, fmt: (n) => n },
    { k: "reach",     v: 0.78, label: "Group reach",       n: m.groupReach.value, fmt: (n) => n },
    { k: "breadth",   v: 0.79, label: "Industry breadth",  n: `${m.breadth.value}/14`, fmt: (n) => n },
    { k: "ratio",     v: 0.71, label: "Ext : Int ratio",   n: m.ratio.value.toFixed(2), fmt: (n) => n },
    { k: "cp",        v: 0.84, label: "Cross-poll",        n: m.crossPoll.value.toFixed(2), fmt: (n) => n },
  ];

  const W = 280, cx = W/2, cy = 150, R = 110;
  const pts = dims.map((d, i) => {
    const a = (i / dims.length) * Math.PI * 2 - Math.PI/2;
    return { x: cx + Math.cos(a) * R * d.v, y: cy + Math.sin(a) * R * d.v, ax: cx + Math.cos(a)*R, ay: cy + Math.sin(a)*R, lx: cx + Math.cos(a) * (R + 18), ly: cy + Math.sin(a) * (R + 18), a, ...d };
  });
  const path = pts.map((p, i) => (i === 0 ? `M ${p.x} ${p.y}` : `L ${p.x} ${p.y}`)).join(" ") + " Z";

  return (
    <div style={{ width: "100%", height: "100%", padding: 32, background: "var(--bg)", color: "var(--text)", display: "flex", flexDirection: "column" }}>
      <div className="eyebrow">Group health · summary</div>
      <h2 className="serif" style={{ fontSize: 30, margin: "8px 0 0", letterSpacing: "-0.015em" }}>
        Coast Referral Collective<span className="serif-i" style={{ color: "var(--accent)" }}>.</span>
      </h2>
      <div className="muted" style={{ fontSize: 13, marginTop: 4 }}>14 members · Gold Coast · 90-day window</div>

      <div className="perf" style={{ margin: "20px 0" }}/>

      <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 20, alignItems: "center", flex: 1 }}>
        {/* Radar */}
        <svg viewBox={`0 0 ${W} 320`} width="100%">
          {[0.25, 0.5, 0.75, 1].map((s, i) => (
            <polygon key={i}
              points={dims.map((_, j) => {
                const a = (j / dims.length) * Math.PI * 2 - Math.PI/2;
                return `${cx + Math.cos(a)*R*s},${cy + Math.sin(a)*R*s}`;
              }).join(" ")}
              fill="none" stroke="var(--border-soft)" strokeWidth="1"/>
          ))}
          {pts.map((p, i) => (
            <line key={i} x1={cx} y1={cy} x2={p.ax} y2={p.ay} stroke="var(--border-soft)"/>
          ))}
          <path d={path} fill="var(--accent)" fillOpacity="0.15" stroke="var(--accent)" strokeWidth="1.5" strokeLinejoin="round"/>
          {pts.map((p, i) => (
            <g key={i}>
              <circle cx={p.x} cy={p.y} r="3" fill="var(--accent)"/>
              <text x={p.lx} y={p.ly} textAnchor={Math.cos(p.a) > 0.3 ? "start" : Math.cos(p.a) < -0.3 ? "end" : "middle"} dominantBaseline="middle"
                style={{ font: "500 9px var(--mono)", fill: "var(--text-3)", letterSpacing: "0.08em" }}>
                {p.label.toUpperCase()}
              </text>
            </g>
          ))}
        </svg>

        {/* Metrics list */}
        <div>
          {dims.map((d, i) => (
            <div key={i} style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline", padding: "10px 0", borderBottom: i < dims.length-1 ? "1px solid var(--border-soft)" : "none" }}>
              <span style={{ fontSize: 13, color: "var(--text-2)" }}>{d.label}</span>
              <span className="mono" style={{ fontSize: 16, fontWeight: 500 }}>{d.n}</span>
            </div>
          ))}
        </div>
      </div>

      <div style={{ marginTop: 16, paddingTop: 16, borderTop: "1px solid var(--border-soft)", display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
        <span className="mono" style={{ fontSize: 10, letterSpacing: "0.12em", color: "var(--text-3)" }}>OVERALL HEALTH</span>
        <div style={{ display: "flex", alignItems: "baseline", gap: 8 }}>
          <span className="serif-i" style={{ fontSize: 14, color: "var(--accent)" }}>Top decile</span>
          <span className="mono" style={{ fontSize: 22, fontWeight: 500, color: "var(--accent)" }}>0.81</span>
        </div>
      </div>
    </div>
  );
}

// ====================================================================
// Mini sparkline
// ====================================================================
function Spark({ data, w = 80, h = 24, color = "var(--accent)" }) {
  const max = Math.max(...data), min = Math.min(...data);
  const pts = data.map((v, i) => `${(i/(data.length-1))*w},${h - ((v-min)/(max-min||1))*h}`).join(" ");
  return (
    <svg width={w} height={h}>
      <polyline fill="none" stroke={color} strokeWidth="1.2" points={pts}/>
    </svg>
  );
}

// ====================================================================
// GROUP — MEMBER VIEW
// ====================================================================
function GroupMemberView() {
  const G = window.CoastGroup;
  const m = G.metrics;
  return (
    <div style={{ width: "100%", height: "100%", background: "var(--bg)", color: "var(--text)", overflow: "auto", padding: 0 }}>
      {/* Hero */}
      <div style={{ padding: "40px 48px 32px", borderBottom: "1px solid var(--border-soft)" }}>
        <div style={{ display: "flex", justifyContent: "space-between", alignItems: "flex-start" }}>
          <div>
            <div className="eyebrow">Group · member view</div>
            <h1 className="serif" style={{ fontSize: 56, margin: "12px 0 0", letterSpacing: "-0.02em", lineHeight: 1 }}>
              Coast Referral<br/><span className="serif-i" style={{ color: "var(--accent)" }}>Collective.</span>
            </h1>
            <div style={{ marginTop: 16, color: "var(--text-2)", fontSize: 15, maxWidth: 520, lineHeight: 1.55 }}>
              Professional services for small business owners across the Gold Coast.
            </div>
            <div className="mono" style={{ marginTop: 14, fontSize: 11, color: "var(--text-3)", letterSpacing: "0.1em" }}>
              GOLD COAST QLD · EST. AUG 2024 · 14 MEMBERS · NEXT MEETING TUE 12 MAY
            </div>
          </div>
          <button className="btn btn-ghost" style={{ height: 40 }}>Group settings</button>
        </div>
      </div>

      {/* Stats strip — five health metrics */}
      <div style={{ padding: "0 48px", borderBottom: "1px solid var(--border-soft)" }}>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(5, 1fr)", padding: "28px 0" }}>
          <Metric n={m.total1to1s.value} l="Total 1to1s"      d="last 90d"           series={m.total1to1s.series}/>
          <Metric n={m.groupReach.value} l="Group reach"      d="ext. connections"   series={m.groupReach.series} hairline/>
          <Metric n={`${m.breadth.value}/14`} l="Industry breadth" d="of 14 sectors"  series={m.breadth.series}    hairline/>
          <Metric n={m.ratio.value.toFixed(2)} l="Ext : Int ratio" d={m.ratio.label}  series={m.ratio.series}      hairline/>
          <Metric n={m.crossPoll.value.toFixed(2)} l="Cross-poll" d="vs 0.51 avg" series={m.crossPoll.series} hairline accent/>
        </div>
      </div>

      {/* Body */}
      <div style={{ display: "grid", gridTemplateColumns: "1fr 380px", gap: 0 }}>
        {/* Left: directory + power teams */}
        <div style={{ padding: "32px 48px", borderRight: "1px solid var(--border-soft)" }}>
          <h3 className="section-h">Members · 14</h3>
          <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 12, marginTop: 4 }}>
            {G.members.map(mem => <MemberCard key={mem.id} m={mem}/>)}
          </div>

          <h3 className="section-h" style={{ marginTop: 40 }}>Power Teams</h3>
          {G.powerTeams.map((pt, i) => (
            <div key={i} className="card" style={{ marginBottom: 12 }}>
              <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
                <div className="serif" style={{ fontSize: 20, letterSpacing: "-0.01em" }}>{pt.name}</div>
                <span className="mono" style={{ fontSize: 11, color: "var(--text-3)" }}>{pt.deals} DEALS · 90D</span>
              </div>
              <div className="muted" style={{ fontSize: 13, marginTop: 4 }}>{pt.focus}</div>
              <div style={{ display: "flex", gap: 6, marginTop: 14 }}>
                {pt.members.map((id, j) => (
                  <div key={j} style={{ width: 32, height: 32, borderRadius: 8, background: "var(--surface-2)", border: "1px solid var(--border)", display: "grid", placeItems: "center", fontFamily: "var(--mono)", fontSize: 10, color: "var(--text-2)" }}>{id}</div>
                ))}
              </div>
            </div>
          ))}
        </div>

        {/* Right: activity feed */}
        <div style={{ padding: "32px 32px" }}>
          <h3 className="section-h">Activity</h3>
          {G.activity.map((a, i) => (
            <div key={i} style={{ padding: "14px 0", borderBottom: i < G.activity.length-1 ? "1px solid var(--border-soft)" : "none" }}>
              <div className="mono" style={{ fontSize: 10, letterSpacing: "0.1em", color: "var(--text-3)" }}>{a.when.toUpperCase()}</div>
              <div style={{ fontSize: 14, marginTop: 4, lineHeight: 1.5 }}>
                <span style={{ color: "var(--text)", fontWeight: 500 }}>{a.who}</span>
                <span className="muted"> {a.what}</span>
              </div>
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}

const Metric = ({ n, l, d, series, hairline, accent }) => (
  <div style={{ padding: "0 18px", borderLeft: hairline ? "1px solid var(--border-soft)" : "none" }}>
    <div className="mono" style={{ fontSize: 30, fontWeight: 500, letterSpacing: "-0.02em", color: accent ? "var(--accent)" : "var(--text)" }}>{n}</div>
    <div style={{ marginTop: 6, fontSize: 12, fontWeight: 500 }}>{l}</div>
    <div className="muted-2" style={{ fontSize: 11, marginTop: 2 }}>{d}</div>
    {series && <div style={{ marginTop: 10 }}><Spark data={series} color={accent?"var(--accent)":"var(--text-2)"}/></div>}
  </div>
);

const MemberCard = ({ m }) => (
  <div style={{ padding: 14, background: "var(--surface)", border: "1px solid var(--border-soft)", borderRadius: 10, display: "flex", gap: 12, alignItems: "center", cursor: "pointer" }}>
    <div style={{ width: 44, height: 44, borderRadius: 8, background: m.self ? "var(--accent-soft)" : "var(--surface-2)", border: "1px solid " + (m.self?"var(--accent)":"var(--border)"), display: "grid", placeItems: "center", fontFamily: "var(--mono)", fontSize: 12, color: m.self ? "var(--accent)" : "var(--text-2)", flex: "0 0 44px" }}>{m.initials}</div>
    <div style={{ flex: 1, minWidth: 0 }}>
      <div style={{ fontSize: 13, fontWeight: 500, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }}>{m.name}</div>
      <div className="muted" style={{ fontSize: 12, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis" }}>{m.role} · {m.firm}</div>
    </div>
    <span className="mono" style={{ fontSize: 10, color: "var(--text-3)", letterSpacing: "0.08em" }}>{m.conn}</span>
  </div>
);

// ====================================================================
// GROUP — ADMIN VIEW
// ====================================================================
function GroupAdminView() {
  const G = window.CoastGroup;
  const m = G.metrics;
  return (
    <div style={{ width: "100%", height: "100%", background: "var(--bg)", color: "var(--text)", overflow: "auto" }}>
      <div style={{ padding: "40px 48px 24px", borderBottom: "1px solid var(--border-soft)", display: "flex", justifyContent: "space-between", alignItems: "flex-end" }}>
        <div>
          <div className="eyebrow">Group · admin</div>
          <h1 className="serif" style={{ fontSize: 44, margin: "10px 0 0", letterSpacing: "-0.02em", lineHeight: 1 }}>
            Coast Referral Collective<span className="serif-i" style={{ color: "var(--accent)" }}>.</span>
          </h1>
          <div className="muted" style={{ marginTop: 8, fontSize: 14 }}>Marcus Chen · Convenor · 8 months</div>
        </div>
        <div style={{ display: "flex", gap: 8 }}>
          <button className="btn btn-ghost" style={{ height: 40 }}>Settings</button>
          <button className="btn btn-primary" style={{ height: 40 }}>Invite member</button>
        </div>
      </div>

      <div style={{ display: "grid", gridTemplateColumns: "1fr 360px", gap: 0 }}>
        <div style={{ padding: "28px 48px", borderRight: "1px solid var(--border-soft)" }}>
          {/* Analytics */}
          <h3 className="section-h">Health metrics · 6 months</h3>
          <div style={{ display: "grid", gridTemplateColumns: "1fr 1fr", gap: 16 }}>
            <TrendCard title="Total 1to1s"        v={m.total1to1s.value} delta="+24" series={m.total1to1s.series}/>
            <TrendCard title="Group reach"        v={m.groupReach.value} delta="+34" series={m.groupReach.series}/>
            <TrendCard title="Industry breadth"   v={`${m.breadth.value}/14`} delta="+1" series={m.breadth.series}/>
            <TrendCard title="Ext : Int ratio"    v={m.ratio.value.toFixed(2)} delta="+0.03" series={m.ratio.series} prefix=""/>
            <TrendCard title="Cross-pollination"  v={m.crossPoll.value.toFixed(2)} delta="+0.05" series={m.crossPoll.series} accent/>
            <TrendCard title="Attendance"         v="89%" delta="+4pp" series={[78, 81, 84, 86, 87, 89]}/>
          </div>

          {/* Member management */}
          <h3 className="section-h" style={{ marginTop: 40 }}>Member management</h3>
          <div className="card" style={{ padding: 0 }}>
            <div style={{ padding: "14px 20px", borderBottom: "1px solid var(--border-soft)", display: "grid", gridTemplateColumns: "2fr 1.5fr 1fr 1fr 80px", gap: 12 }}>
              {["MEMBER","ROLE","1to1s · 90d","ATTENDANCE",""].map((h,i) => (
                <span key={i} className="mono" style={{ fontSize: 10, letterSpacing: "0.1em", color: "var(--text-3)" }}>{h}</span>
              ))}
            </div>
            {G.members.slice(0,8).map((mem, i) => (
              <div key={i} style={{ padding: "14px 20px", borderBottom: i<7?"1px solid var(--border-soft)":"none", display: "grid", gridTemplateColumns: "2fr 1.5fr 1fr 1fr 80px", gap: 12, alignItems: "center" }}>
                <div style={{ display: "flex", gap: 10, alignItems: "center" }}>
                  <div style={{ width: 28, height: 28, borderRadius: 6, background: "var(--surface-2)", border: "1px solid var(--border)", display: "grid", placeItems: "center", fontFamily: "var(--mono)", fontSize: 10, color: "var(--text-2)" }}>{mem.initials}</div>
                  <span style={{ fontSize: 13, fontWeight: 500 }}>{mem.name}</span>
                </div>
                <span style={{ fontSize: 12, color: "var(--text-2)" }}>{mem.role}</span>
                <span className="mono" style={{ fontSize: 13 }}>{mem.conn}</span>
                <span className="mono" style={{ fontSize: 12, color: mem.conn > 5 ? "var(--accent)" : "var(--text-2)" }}>{Math.min(100, 70 + mem.conn*2)}%</span>
                <button style={{ background: "transparent", border: "none", color: "var(--text-3)", cursor: "pointer", fontSize: 14 }}>···</button>
              </div>
            ))}
          </div>
        </div>

        {/* Right: applications */}
        <div style={{ padding: "28px 32px" }}>
          <div style={{ display: "flex", justifyContent: "space-between", alignItems: "baseline" }}>
            <h3 className="section-h" style={{ margin: 0 }}>Applications</h3>
            <span className="mono" style={{ fontSize: 11, color: "var(--accent)", letterSpacing: "0.08em" }}>{G.applications.length} PENDING</span>
          </div>
          <div style={{ marginTop: 14 }}>
            {G.applications.map((app, i) => (
              <div key={i} className="card" style={{ marginBottom: 10, padding: 16 }}>
                <div style={{ display: "flex", justifyContent: "space-between" }}>
                  <div>
                    <div style={{ fontWeight: 500 }}>{app.name}</div>
                    <div className="muted" style={{ fontSize: 12 }}>{app.role} · {app.firm}</div>
                  </div>
                  <span className="mono" style={{ fontSize: 10, color: "var(--text-3)" }}>{app.date.toUpperCase()}</span>
                </div>
                <div className="serif-i" style={{ fontSize: 13, marginTop: 10, color: "var(--text-2)" }}>"{app.intro}"</div>
                <div style={{ display: "flex", gap: 8, marginTop: 12 }}>
                  <button className="btn btn-primary" style={{ height: 32, fontSize: 12, flex: 1 }}>Review</button>
                  <button className="btn btn-ghost" style={{ height: 32, fontSize: 12, padding: "0 14px" }}>Decline</button>
                </div>
              </div>
            ))}
          </div>

          <h3 className="section-h" style={{ marginTop: 32 }}>Settings</h3>
          <SettingRow l="Group visibility" v="Application required"/>
          <SettingRow l="Industry exclusivity" v="One per category"/>
          <SettingRow l="Meeting cadence" v="Fortnightly · Tuesdays"/>
          <SettingRow l="Quorum rule" v="80% attendance"/>
        </div>
      </div>
    </div>
  );
}

const TrendCard = ({ title, v, delta, series, accent }) => (
  <div className="card" style={{ padding: 18 }}>
    <div className="eyebrow">{title}</div>
    <div style={{ display: "flex", alignItems: "baseline", gap: 10, marginTop: 10 }}>
      <span className="mono" style={{ fontSize: 28, fontWeight: 500, letterSpacing: "-0.02em", color: accent?"var(--accent)":"var(--text)" }}>{v}</span>
      <span className="mono" style={{ fontSize: 11, color: "var(--accent)", letterSpacing: "0.06em" }}>{delta}</span>
    </div>
    <div style={{ marginTop: 12 }}>
      <Spark data={series} w={220} h={36} color={accent?"var(--accent)":"var(--text-2)"}/>
    </div>
  </div>
);

const SettingRow = ({ l, v }) => (
  <div style={{ display: "flex", justifyContent: "space-between", padding: "12px 0", borderBottom: "1px solid var(--border-soft)" }}>
    <span style={{ fontSize: 13, color: "var(--text-2)" }}>{l}</span>
    <span style={{ fontSize: 13 }}>{v}</span>
  </div>
);

// ====================================================================
// GROUP — PUBLIC VIEW (recruiting page)
// ====================================================================
function GroupPublicView() {
  const G = window.CoastGroup;
  return (
    <div style={{ width: "100%", height: "100%", background: "var(--bg)", color: "var(--text)", overflow: "auto" }}>
      {/* Hero — feels like a private members' club */}
      <div style={{ position: "relative", padding: "80px 64px 64px", borderBottom: "1px solid var(--border-soft)" }}>
        <div className="mono" style={{ fontSize: 11, letterSpacing: "0.16em", color: "var(--text-3)" }}>
          A 1to1 GROUP · BY APPLICATION · GOLD COAST QLD
        </div>
        <h1 className="serif" style={{ fontSize: 84, margin: "20px 0 0", letterSpacing: "-0.025em", lineHeight: 0.95, maxWidth: 900 }}>
          Coast Referral<br/>
          <span className="serif-i" style={{ color: "var(--accent)" }}>Collective.</span>
        </h1>
        <div style={{ marginTop: 28, fontSize: 19, lineHeight: 1.5, maxWidth: 620, color: "var(--text-2)", fontFamily: "var(--serif)" }}>
          Fourteen practitioners — one per discipline — meeting fortnightly to refer their best clients to people they trust. Founded August 2024. Currently accepting applications in <span style={{ color: "var(--accent)" }}>tax advisory</span> and <span style={{ color: "var(--accent)" }}>HR consulting</span>.
        </div>

        {/* Verified stamp, top right */}
        <div style={{ position: "absolute", top: 64, right: 64, width: 110, height: 110, border: "1.5px solid var(--accent)", borderRadius: "50%", color: "var(--accent)", display: "grid", placeItems: "center", textAlign: "center", transform: "rotate(-6deg)", opacity: 0.85 }}>
          <div>
            <div className="mono" style={{ fontSize: 9, letterSpacing: "0.16em" }}>1to1</div>
            <div className="serif-i" style={{ fontSize: 18, marginTop: 4 }}>verified</div>
            <div className="mono" style={{ fontSize: 9, letterSpacing: "0.16em", marginTop: 4 }}>2024–26</div>
          </div>
        </div>
      </div>

      {/* Aggregate stats — no individual data */}
      <div style={{ padding: "40px 64px", borderBottom: "1px solid var(--border-soft)" }}>
        <div className="eyebrow" style={{ marginBottom: 24 }}>What members have built together</div>
        <div style={{ display: "grid", gridTemplateColumns: "repeat(4, 1fr)", gap: 32 }}>
          <BigStat n="312" l="1to1s held" sub="across the membership"/>
          <BigStat n="184" l="Connections made" sub="for one another, attributed"/>
          <BigStat n="$4.2M" l="Attributed business" sub="closed via referrals · 12mo"/>
          <BigStat n="11/14" l="Industries" sub="represented in the room"/>
        </div>
      </div>

      <div style={{ display: "grid", gridTemplateColumns: "1.3fr 1fr", gap: 0 }}>
        {/* What this group focuses on */}
        <div style={{ padding: "48px 64px", borderRight: "1px solid var(--border-soft)" }}>
          <h2 className="serif" style={{ fontSize: 36, margin: 0, letterSpacing: "-0.015em", lineHeight: 1.1 }}>
            We refer the work that <span className="serif-i" style={{ color: "var(--accent)" }}>matters</span> for our clients.
          </h2>
          <p style={{ marginTop: 20, fontSize: 16, lineHeight: 1.65, color: "var(--text-2)", maxWidth: 540 }}>
            Most of our clients are first-time commercial buyers, founders making their first hire, and operators who've outgrown their current advisors. They need a network they didn't have to build themselves.
          </p>
          <p style={{ marginTop: 16, fontSize: 16, lineHeight: 1.65, color: "var(--text-2)", maxWidth: 540 }}>
            We meet at <span style={{ color: "var(--text)" }}>The Pantry</span> in Robina, every second Tuesday at 7:30am. We track every introduction. We hold each other accountable for the quality of those referrals.
          </p>

          <div className="perf" style={{ margin: "36px 0" }}/>

          <h3 className="eyebrow">Currently filling</h3>
          <div style={{ marginTop: 14, display: "flex", flexDirection: "column", gap: 10 }}>
            <OpenSeat role="Tax advisor" why="Our accountant gets asked weekly. We don't have anyone to send."/>
            <OpenSeat role="HR consultant" why="Our coaches and operators need help with first-hire systems."/>
          </div>
        </div>

        {/* Industry breakdown */}
        <div style={{ padding: "48px 48px" }}>
          <h3 className="eyebrow">Composition</h3>
          <div style={{ marginTop: 16 }}>
            {G.industryBreakdown.map((b, i) => (
              <div key={i} style={{ padding: "14px 0", borderBottom: "1px solid var(--border-soft)" }}>
                <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 8 }}>
                  <span style={{ fontSize: 14 }}>{b.industry}</span>
                  <span className="mono" style={{ fontSize: 13, color: "var(--text-2)" }}>{b.count}</span>
                </div>
                <div style={{ display: "flex", gap: 4 }}>
                  {Array.from({length: 6}).map((_, j) => (
                    <div key={j} style={{ flex: 1, height: 4, borderRadius: 2, background: j < b.count ? "var(--accent)" : "var(--surface-2)" }}/>
                  ))}
                </div>
              </div>
            ))}
          </div>
        </div>
      </div>

      {/* CTA */}
      <div style={{ padding: "64px", borderTop: "1px solid var(--border-soft)", textAlign: "center", background: "var(--surface)" }}>
        <h2 className="serif" style={{ fontSize: 40, margin: 0, letterSpacing: "-0.02em" }}>
          Apply to be considered<span className="serif-i" style={{ color: "var(--accent)" }}>.</span>
        </h2>
        <p className="muted" style={{ fontSize: 15, marginTop: 14, maxWidth: 520, marginLeft: "auto", marginRight: "auto" }}>
          Members review every application together. We respond within two weeks. A referral from an existing member is preferred but not required.
        </p>
        <div style={{ marginTop: 28, display: "flex", gap: 12, justifyContent: "center" }}>
          <button className="btn btn-primary">Apply to join</button>
          <button className="btn btn-ghost">Request a visit</button>
        </div>
      </div>
    </div>
  );
}

const BigStat = ({ n, l, sub }) => (
  <div>
    <div className="mono" style={{ fontSize: 52, fontWeight: 500, letterSpacing: "-0.03em", color: "var(--text)", lineHeight: 1 }}>{n}</div>
    <div style={{ marginTop: 12, fontSize: 13, fontWeight: 500 }}>{l}</div>
    <div className="muted-2" style={{ fontSize: 12, marginTop: 2 }}>{sub}</div>
  </div>
);
const OpenSeat = ({ role, why }) => (
  <div style={{ padding: 16, background: "var(--surface)", border: "1px solid var(--accent-soft)", borderRadius: 10, display: "flex", justifyContent: "space-between", alignItems: "flex-start", gap: 16 }}>
    <div>
      <div style={{ fontSize: 14, fontWeight: 500 }}>{role}</div>
      <div className="muted" style={{ fontSize: 13, marginTop: 4 }}>{why}</div>
    </div>
    <span className="mono" style={{ fontSize: 10, color: "var(--accent)", letterSpacing: "0.1em", whiteSpace: "nowrap", marginTop: 4 }}>1 SEAT</span>
  </div>
);

window.GroupHealthCard = GroupHealthCard;
window.GroupMemberView = GroupMemberView;
window.GroupAdminView = GroupAdminView;
window.GroupPublicView = GroupPublicView;
