// Page-level sections used across Services, Work, Case Study, About, Contact

const { useState: useS2, useEffect: useE2 } = React;

// ═══════════════════════════════════════════════════════════
// SERVICES INDEX PAGE
// ═══════════════════════════════════════════════════════════
function ServicesIndex() {
  return (
    <section className="svc-alt-list" style={{maxWidth:1440, margin:'0 auto', padding:'0 clamp(24px, 5vw, 96px) 128px'}}>
      {SERVICES.map((s, i) => (
        <a key={s.slug} href={`service-${s.slug}.html`} className="svc-alt-row" style={{
          display:'grid',
          gridTemplateColumns:'72px 1fr 1fr 120px',
          gap:48,
          padding:'48px 0',
          borderTop:'1px solid rgba(244,241,236,0.1)',
          textDecoration:'none',
          color:'inherit',
          alignItems:'start',
          transition:'opacity .3s ease'
        }}>
          <div style={{fontFamily:"'JetBrains Mono', monospace", fontSize:13, color:'var(--ldo-accent-live, #C9A86A)', paddingTop:14}}>
            {s.num}
          </div>
          <div>
            <h3 style={{fontSize:'clamp(36px, 4.5vw, 64px)', fontWeight:500, letterSpacing:'-0.025em', lineHeight:1.0, margin:0, color:'#F4F1EC'}}>{s.title}</h3>
            <p style={{fontSize:17, color:'#B6B3AE', lineHeight:1.55, margin:'20px 0 0', maxWidth:460}}>{s.lede}</p>
          </div>
          <div style={{paddingTop:16}}>
            <p style={{fontSize:14, color:'#7A7874', lineHeight:1.6, margin:0, maxWidth:380}}>{s.body.split('.')[0] + '.'}</p>
          </div>
          <div style={{paddingTop:14, textAlign:'right', fontSize:12, letterSpacing:'.14em', textTransform:'uppercase', color:'var(--ldo-accent-live, #C9A86A)', fontWeight:500}}>
            Open <span style={{fontFamily:"'JetBrains Mono', monospace", marginLeft:6}}>→</span>
          </div>
        </a>
      ))}
      <div style={{borderTop:'1px solid rgba(244,241,236,0.1)'}}/>
    </section>
  );
}

// ═══════════════════════════════════════════════════════════
// SERVICE DETAIL PAGE
// ═══════════════════════════════════════════════════════════
function ServiceDetail({ slug }) {
  const s = SERVICES.find(x => x.slug === slug);
  if (!s) return <div>Not found</div>;

  const SIGNALS = {
    transformation: [
      'Operating-model redesign that ties structure, process, and incentives to outcomes.',
      'Change journeys that build belief, not just compliance.',
      'Transition plans that carry the organisation through the in-between.',
      'Measurement frameworks that prove transformation is actually working.',
    ],
    governance: [
      'Decision rights and escalation paths that clear rather than congest.',
      'Risk and assurance frameworks proportionate to the actual risk appetite.',
      'Policy and control design that scales with ambition.',
      'Board-level reporting that surfaces what matters, not what\'s measurable.',
    ],
    futures: [
      'Long-range scenario sets grounded in current-state signals.',
      'Foresight capability embedded into strategy and investment cycles.',
      'Back-casting from future states to present-day choices.',
      'Strategic options mapped against plausible futures, not a single bet.',
    ],
    capability: [
      'Leadership practices that outlast any individual engagement.',
      'Design-thinking fluency across product, ops, and strategy teams.',
      'Internal coaching structures that compound over time.',
      'Knowledge transfer measured by what your teams do, not what we document.',
    ],
  };

  const QUESTIONS = {
    transformation: ["Are the structures carrying the strategy, or resisting it?", "Where is energy leaking between the ambition and the day-to-day?", "Who, specifically, is accountable for change taking hold?"],
    governance: ["Are decisions being made at the right altitude?", "Where does governance enable speed, and where does it throttle it?", "Is risk oversight proportionate, or performative?"],
    futures: ["What would we do differently if we believed the long-range view?", "Where is our strategy over-indexed on recent signals?", "Which futures, if they arrive, we cannot afford to be unprepared for?"],
    capability: ["What would internal teams need to do to stop needing us?", "Where is capability concentrated in individuals rather than practice?", "What stays when the programme ends?"],
  };

  const signals = SIGNALS[slug] || [];
  const questions = QUESTIONS[slug] || [];
  const related = WORKS.filter(w => w.service.toLowerCase().includes(s.title.split(' ')[0].toLowerCase())).slice(0,2);
  const others = SERVICES.filter(x => x.slug !== slug);

  return (
    <>
      <PageIntro eyebrow={`Service · ${s.num}`} title={s.title} body={s.lede}/>

      <section style={{maxWidth:1440, margin:'0 auto', padding:'0 clamp(24px, 5vw, 96px) 96px'}}>
        <div style={{borderRadius:4, overflow:'hidden', aspectRatio:'21/9', background:'#141416'}}>
          <img src={s.img} alt="" style={{width:'100%', height:'100%', objectFit:'cover', display:'block'}}/>
        </div>
      </section>

      <section style={{maxWidth:1440, margin:'0 auto', padding:'0 clamp(24px, 5vw, 96px) 128px',
                       display:'grid', gridTemplateColumns:'1fr 1.6fr', gap:96}}>
        <div style={{fontSize:11, letterSpacing:'.14em', textTransform:'uppercase', fontWeight:500, color:'#7A7874'}}>— What it involves</div>
        <div>
          <p style={{fontSize:22, lineHeight:1.55, color:'#F4F1EC', margin:0, maxWidth:720, textWrap:'pretty'}}>{s.body}</p>
        </div>
      </section>

      <section style={{maxWidth:1440, margin:'0 auto', padding:'0 clamp(24px, 5vw, 96px) 128px',
                       display:'grid', gridTemplateColumns:'1fr 1.6fr', gap:96,
                       borderTop:'1px solid rgba(244,241,236,0.08)', paddingTop:96}}>
        <div>
          <div style={{fontSize:11, letterSpacing:'.14em', textTransform:'uppercase', fontWeight:500, color:'#7A7874'}}>— What we bring</div>
          <h3 style={{fontSize:'clamp(28px, 3vw, 44px)', fontWeight:500, letterSpacing:'-0.02em', lineHeight:1.05, margin:'24px 0 0', color:'#F4F1EC', maxWidth:'12ch'}}>Signals of good work.</h3>
        </div>
        <ul style={{margin:0, padding:0, listStyle:'none', display:'flex', flexDirection:'column'}}>
          {signals.map((sig, i) => (
            <li key={i} style={{padding:'24px 0', borderTop:'1px solid rgba(244,241,236,0.08)',
                                display:'grid', gridTemplateColumns:'56px 1fr', gap:24, alignItems:'baseline'}}>
              <span style={{fontFamily:"'JetBrains Mono', monospace", fontSize:12, color:'var(--ldo-accent-live, #C9A86A)'}}>— {String(i+1).padStart(2,'0')}</span>
              <span style={{fontSize:18, lineHeight:1.5, color:'#F4F1EC', textWrap:'pretty'}}>{sig}</span>
            </li>
          ))}
        </ul>
      </section>

      <section style={{background:'#141416', padding:'96px 0'}}>
        <div style={{maxWidth:1440, margin:'0 auto', padding:'0 clamp(24px, 5vw, 96px)',
                     display:'grid', gridTemplateColumns:'1fr 1.6fr', gap:96}}>
          <div>
            <div style={{fontSize:11, letterSpacing:'.14em', textTransform:'uppercase', fontWeight:500, color:'#7A7874'}}>— Where we start</div>
            <h3 style={{fontSize:'clamp(28px, 3vw, 44px)', fontWeight:500, letterSpacing:'-0.02em', lineHeight:1.05, margin:'24px 0 0', color:'#F4F1EC', maxWidth:'14ch'}}>Questions worth asking first.</h3>
          </div>
          <div style={{display:'flex', flexDirection:'column', gap:32}}>
            {questions.map((q, i) => (
              <div key={i} style={{display:'grid', gridTemplateColumns:'48px 1fr', gap:24, alignItems:'baseline'}}>
                <span style={{fontFamily:"'JetBrains Mono', monospace", fontSize:14, color:'var(--ldo-accent-live, #C9A86A)'}}>Q{i+1}</span>
                <p style={{fontSize:'clamp(20px, 2vw, 28px)', lineHeight:1.25, color:'#F4F1EC', margin:0, letterSpacing:'-0.01em', fontWeight:500, textWrap:'pretty'}}>{q}</p>
              </div>
            ))}
          </div>
        </div>
      </section>

      {related.length > 0 && (
        <section style={{maxWidth:1440, margin:'0 auto', padding:'128px clamp(24px, 5vw, 96px) 64px'}}>
          <div style={{fontSize:11, letterSpacing:'.14em', textTransform:'uppercase', fontWeight:500, color:'#7A7874', marginBottom:32}}>— This practice in the work</div>
          <div style={{display:'grid', gridTemplateColumns:'repeat(2, 1fr)', gap:32}}>
            {related.map(w => (
              <a key={w.slug} href={`case-${w.slug}.html`} style={{textDecoration:'none', color:'inherit'}}>
                <div style={{aspectRatio:'16/10', borderRadius:4, overflow:'hidden', background:'#141416'}}>
                  <img src={w.img} alt="" style={{width:'100%', height:'100%', objectFit:'cover', display:'block'}}/>
                </div>
                <div style={{padding:'20px 0 0'}}>
                  <div style={{fontSize:11, letterSpacing:'.14em', textTransform:'uppercase', color:'#7A7874', fontWeight:500}}>{w.client} · {w.year}</div>
                  <h4 style={{fontSize:24, fontWeight:500, letterSpacing:'-0.015em', margin:'12px 0 0', color:'#F4F1EC'}}>{w.title}</h4>
                </div>
              </a>
            ))}
          </div>
        </section>
      )}

      <section style={{maxWidth:1440, margin:'0 auto', padding:'64px clamp(24px, 5vw, 96px) 128px',
                       borderTop:'1px solid rgba(244,241,236,0.08)', marginTop:64}}>
        <div style={{fontSize:11, letterSpacing:'.14em', textTransform:'uppercase', fontWeight:500, color:'#7A7874', marginBottom:32, paddingTop:32}}>— Other practices</div>
        <div style={{display:'grid', gridTemplateColumns:'repeat(3, 1fr)', gap:24}}>
          {others.map(o => (
            <a key={o.slug} href={`service-${o.slug}.html`} style={{
              display:'block', padding:'28px', border:'1px solid rgba(244,241,236,0.08)', borderRadius:8,
              textDecoration:'none', color:'inherit', background:'#141416'
            }}>
              <div style={{fontFamily:"'JetBrains Mono', monospace", fontSize:12, color:'var(--ldo-accent-live, #C9A86A)', marginBottom:12}}>{o.num}</div>
              <h5 style={{fontSize:20, fontWeight:500, letterSpacing:'-0.01em', margin:0, color:'#F4F1EC'}}>{o.title}</h5>
              <p style={{fontSize:14, color:'#B6B3AE', lineHeight:1.55, margin:'12px 0 0'}}>{o.lede}</p>
            </a>
          ))}
        </div>
      </section>
    </>
  );
}

// ═══════════════════════════════════════════════════════════
// WORK INDEX PAGE
// ═══════════════════════════════════════════════════════════
function WorkIndex() {
  return (
    <section className="work-hover-group" style={{maxWidth:1440, margin:'0 auto', padding:'0 clamp(24px, 5vw, 96px) 128px'}}>
      {WORKS.map((w, i) => (
        <a key={w.slug} href={`case-${w.slug}.html`} className="work-hover-item" style={{
          display:'grid',
          gridTemplateColumns: i % 2 === 0 ? '1.1fr 1fr' : '1fr 1.1fr',
          gap:64,
          padding:'64px 0',
          borderTop:'1px solid rgba(244,241,236,0.1)',
          textDecoration:'none',
          color:'inherit',
          alignItems:'center',
          transition:'opacity .3s ease'
        }}>
          <div style={{aspectRatio:'16/10', borderRadius:4, overflow:'hidden', order: i%2===0 ? 1 : 2}}>
            <img src={w.img} alt="" style={{width:'100%', height:'100%', objectFit:'cover', display:'block'}}/>
          </div>
          <div style={{order: i%2===0 ? 2 : 1}}>
            <div style={{fontSize:11, letterSpacing:'.14em', textTransform:'uppercase', color:'#7A7874', fontWeight:500, marginBottom:20}}>
              {w.client} · {w.year} · {w.service}
            </div>
            <h3 style={{fontSize:'clamp(32px, 3.6vw, 56px)', fontWeight:500, letterSpacing:'-0.025em', lineHeight:1.0, margin:0, color:'#F4F1EC', textWrap:'balance'}}>{w.title}</h3>
            <p style={{fontSize:17, color:'#B6B3AE', lineHeight:1.55, margin:'24px 0 32px', maxWidth:520}}>{w.lede}</p>
            <div style={{display:'flex', gap:40, marginBottom:32}}>
              {w.stats.map((st, j) => (
                <div key={j}>
                  <div style={{fontSize:'clamp(28px, 3vw, 40px)', fontWeight:500, letterSpacing:'-0.02em', color:'var(--ldo-accent-live, #C9A86A)', lineHeight:1}}>{st.big}</div>
                  <div style={{fontSize:11, letterSpacing:'.14em', textTransform:'uppercase', color:'#7A7874', fontWeight:500, marginTop:10}}>{st.small}</div>
                </div>
              ))}
            </div>
            <span style={{fontSize:12, letterSpacing:'.14em', textTransform:'uppercase', color:'var(--ldo-accent-live, #C9A86A)', fontWeight:500}}>
              Read case study <span style={{fontFamily:"'JetBrains Mono', monospace", marginLeft:6}}>→</span>
            </span>
          </div>
        </a>
      ))}
      <div style={{borderTop:'1px solid rgba(244,241,236,0.1)'}}/>
    </section>
  );
}

Object.assign(window, { ServicesIndex, ServiceDetail, WorkIndex });
