// Forefront / Content blocks: capability rows, engagement cards, discipline grid.

/* ---------- Status tag (replaces colored badges with quiet mono labels) ---------- */
const StatusTag = ({ status, dark = false }) => {
  const live = status === 'Live';
  return (
    <span style={{
      fontFamily: 'var(--font-mono)', fontSize: 9, letterSpacing: '0.22em', textTransform: 'uppercase',
      color: dark ? 'rgba(250,250,247,0.6)' : MUTE,
      display: 'inline-flex', alignItems: 'center', gap: 7, whiteSpace: 'nowrap',
    }}>
      <span style={{
        width: 5, height: 5, borderRadius: 0,
        background: live ? (dark ? PAPER : INK) : 'transparent',
        border: `1px solid ${dark ? PAPER : INK}`,
        transform: 'rotate(45deg)', display: 'inline-block',
      }} />
      {status}
    </span>
  );
};

/* ---------- Capability list: ruled rows, magazine-spec feel ---------- */
const CapabilityList = ({ items }) => (
  <div style={{ borderTop: `1px solid ${INK}` }}>
    {items.map((it, i) => <CapabilityRow key={i} item={it} index={i} />)}
  </div>
);

const CapabilityRow = ({ item, index }) => {
  const [hover, setHover] = React.useState(false);
  return (
    <div
      className="ff-cap-row"
      onMouseEnter={() => setHover(true)}
      onMouseLeave={() => setHover(false)}
      style={{
        display: 'grid',
        gridTemplateColumns: '64px minmax(200px, 300px) 1fr 110px',
        gap: 32, alignItems: 'baseline',
        padding: '28px 0',
        borderBottom: `1px solid ${HAIR}`,
        transition: `background 240ms ${EASE}`,
        background: hover ? 'rgba(10,10,10,0.02)' : 'transparent',
      }}
    >
      <div className="ff-cap-num" style={{ fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.15em', color: MUTE }}>
        {String(index + 1).padStart(2, '0')}
      </div>
      <div style={{ fontFamily: 'var(--font-display)', fontWeight: 300, fontSize: 26, lineHeight: 1.1, letterSpacing: '-0.02em', fontVariationSettings: '"opsz" 144', color: INK }}>
        {item.title}
      </div>
      <p style={{ fontFamily: 'var(--font-body)', fontWeight: 300, fontSize: 15, lineHeight: 1.6, color: MUTE, margin: 0, maxWidth: '52ch' }}>
        {item.desc}
      </p>
      <div className="ff-cap-status" style={{ textAlign: 'right' }}>
        <StatusTag status={item.status} />
      </div>
    </div>
  );
};

/* ---------- Engagement cards: two ruled cards, shared center border ---------- */
const EngagementGrid = ({ items }) => (
  <div className="ff-eng-grid" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', border: `1px solid ${INK}` }}>
    {items.map((e, i) => (
      <div key={i} className="ff-eng-cell" style={{
        padding: '52px 48px',
        borderRight: i === 0 ? `1px solid ${INK}` : 'none',
        display: 'flex', flexDirection: 'column',
      }}>
        <div style={{ fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.2em', textTransform: 'uppercase', color: MUTE, marginBottom: 28 }}>
          {e.num}
        </div>
        <div style={{ fontFamily: 'var(--font-display)', fontWeight: 300, fontSize: 42, lineHeight: 1, letterSpacing: '-0.03em', fontVariationSettings: '"opsz" 144', color: INK, marginBottom: 18 }}>
          {e.titleLead} <em style={{ fontStyle: 'italic', fontWeight: 400 }}>{e.accent}</em>.
        </div>
        <p style={{ fontFamily: 'var(--font-body)', fontWeight: 300, fontSize: 17, lineHeight: 1.6, color: MUTE, margin: '0 0 36px', maxWidth: '40ch' }}>
          {e.desc}
        </p>
        <ul style={{ listStyle: 'none', margin: 0, padding: 0, borderTop: `1px solid ${HAIR}`, marginTop: 'auto' }}>
          {e.points.map((p, j) => (
            <li key={j} style={{
              fontFamily: 'var(--font-body)', fontWeight: 300, fontSize: 15, color: INK,
              padding: '14px 0', borderBottom: `1px solid ${HAIR}`,
              display: 'flex', alignItems: 'baseline', gap: 14,
            }}>
              <span style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.15em', color: MUTE }}>
                {['i', 'ii', 'iii', 'iv'][j]}.
              </span>
              {p}
            </li>
          ))}
        </ul>
      </div>
    ))}
  </div>
);

/* ---------- Discipline grid: 2x2 teaser on Home, links to Services ---------- */
const DisciplineGrid = ({ pillars, onSelect }) => (
  <div className="ff-disc-grid" style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', border: `1px solid ${INK}` }}>
    {pillars.map((p, i) => {
      const [hover, setHover] = React.useState(false);
      const rightCol = i % 2 === 1;
      const bottomRow = i >= pillars.length - 2;
      return (
        <a key={i} href="#services" className="ff-disc-cell"
          onClick={(ev) => { ev.preventDefault(); onSelect && onSelect(); }}
          onMouseEnter={() => setHover(true)} onMouseLeave={() => setHover(false)}
          style={{
            textDecoration: 'none', color: 'inherit',
            padding: '48px 44px', minHeight: 260,
            borderRight: rightCol ? 'none' : `1px solid ${INK}`,
            borderBottom: bottomRow ? 'none' : `1px solid ${INK}`,
            display: 'flex', flexDirection: 'column', justifyContent: 'space-between',
            background: hover ? INK : PAPER, color: hover ? PAPER : INK,
            transition: `background 240ms ${EASE}, color 240ms ${EASE}`,
          }}>
          <div style={{ fontFamily: 'var(--font-mono)', fontSize: 11, letterSpacing: '0.2em', textTransform: 'uppercase', color: hover ? 'rgba(250,250,247,0.6)' : MUTE }}>
            § {p.number}
          </div>
          <div>
            <div style={{ fontFamily: 'var(--font-display)', fontWeight: 300, fontSize: 38, lineHeight: 1, letterSpacing: '-0.03em', fontVariationSettings: '"opsz" 144', marginBottom: 18 }}>
              {p.title} <em style={{ fontStyle: 'italic', fontWeight: 400 }}>{p.accent}</em>.
            </div>
            <p style={{ fontFamily: 'var(--font-body)', fontWeight: 300, fontSize: 15, lineHeight: 1.6, color: hover ? 'rgba(250,250,247,0.7)' : MUTE, margin: 0, maxWidth: '40ch' }}>
              {p.intro}
            </p>
          </div>
          <div style={{ fontFamily: 'var(--font-mono)', fontSize: 10, letterSpacing: '0.2em', textTransform: 'uppercase', color: hover ? PAPER : MUTE, marginTop: 24 }}>
            {p.items.length} capabilities →
          </div>
        </a>
      );
    })}
  </div>
);

Object.assign(window, { StatusTag, CapabilityList, EngagementGrid, DisciplineGrid });
