// playbook-sections.jsx — all 10 section components

const { useState } = React;
const T = window.PDATA;

/* ─── SHARED UI ──────────────────────────────────────── */

const typeColors = {
  A: { bg: 'rgba(139,92,246,.12)', border: 'rgba(139,92,246,.3)', text: 'oklch(72% .18 295)', badge: 'rgba(139,92,246,.85)' },
  B: { bg: 'rgba(59,130,246,.12)', border: 'rgba(59,130,246,.3)', text: 'oklch(72% .18 235)', badge: 'rgba(59,130,246,.85)' },
  C: { bg: 'rgba(34,197,94,.12)',  border: 'rgba(34,197,94,.3)',  text: 'oklch(72% .18 160)', badge: 'rgba(34,197,94,.85)' },
};
const accentColors = {
  blue:  { bg:'rgba(59,130,246,.1)',  border:'rgba(59,130,246,.25)', text:'oklch(70% .18 235)' },
  teal:  { bg:'rgba(20,184,166,.1)',  border:'rgba(20,184,166,.25)', text:'oklch(68% .17 195)' },
  green: { bg:'rgba(34,197,94,.1)',   border:'rgba(34,197,94,.25)',  text:'oklch(68% .18 155)' },
  amber: { bg:'rgba(245,158,11,.1)',  border:'rgba(245,158,11,.25)', text:'oklch(75% .18 85)' },
  red:   { bg:'rgba(239,68,68,.1)',   border:'rgba(239,68,68,.25)',  text:'oklch(65% .22 25)' },
  purple:{ bg:'rgba(139,92,246,.1)', border:'rgba(139,92,246,.25)', text:'oklch(70% .18 295)' },
};

const SH = ({ num, title, desc }) => (
  <div className="section-header" style={{ marginBottom: 40, paddingBottom: 28, borderBottom: '1px solid var(--br)' }}>
    <span style={{ display:'block', fontFamily:'var(--ffd)', fontSize: 12, fontWeight: 700, color:'var(--acc)', letterSpacing:'.1em', textTransform:'uppercase', marginBottom: 10 }}>{num}</span>
    <h1 style={{ fontFamily:'var(--ffd)', fontSize: 34, fontWeight: 800, letterSpacing:'-.02em', lineHeight: 1.1, color:'var(--fg)', marginBottom: 12 }}>{title}</h1>
    <p style={{ fontSize: 17, color:'var(--fg2)', lineHeight: 1.6, maxWidth: 680 }}>{desc}</p>
  </div>
);

const Card = ({ children, style }) => (
  <div className="playbook-card" style={{ background:'var(--card)', border:'1px solid var(--br)', borderRadius: 12, padding: 24, ...style }}>{children}</div>
);

const TypeBadge = ({ type }) => (
  <span style={{ display:'inline-flex', alignItems:'center', padding:'3px 10px', borderRadius: 999, fontSize: 12, fontWeight: 700, letterSpacing:'.06em', background: typeColors[type].badge, color:'#fff' }}>{type}</span>
);

const Avatar = ({ initials, type }) => (
  <div style={{ width: 32, height: 32, borderRadius: '50%', background: typeColors[type]?.bg || 'var(--bg3)', border: `1px solid ${typeColors[type]?.border || 'var(--br)'}`, display:'flex', alignItems:'center', justifyContent:'center', fontSize: 11, fontWeight: 700, color: typeColors[type]?.text || 'var(--fg2)', flexShrink: 0 }}>{initials}</div>
);

const Chip = ({ children, color = 'default' }) => {
  const c = accentColors[color] || { bg:'var(--bg3)', border:'var(--br)', text:'var(--fg2)' };
  return <span className="chip" style={{ display:'inline-flex', alignItems:'center', padding:'4px 12px', borderRadius: 6, fontSize: 13, fontWeight: 500, background: c.bg, border:`1px solid ${c.border}`, color: c.text, whiteSpace:'nowrap' }}>{children}</span>;
};

const RowDivider = () => <div style={{ height: 1, background:'var(--br)', margin:'0' }} />;

/* ─── SECTION 01: VISÃO GERAL ────────────────────────── */
const Overview = () => (
  <div>
    <SH num="01" title="Visão Geral" desc="Como organizamos e escalamos o trabalho criativo com clareza e previsibilidade." />
    <div style={{ display:'grid', gridTemplateColumns:'repeat(3,1fr)', gap: 16, marginBottom: 24 }}>
      {[
        { color:'blue', label:'Direção', title:'Design como Direção', desc:'Design não é só execução. É direção criativa, construção de identidade e diferencial competitivo para cada conta.' },
        { color:'teal', label:'Clareza', title:'Clareza Operacional', desc:'Este playbook define como trabalhamos: processos, decisões, rituais e métricas. Menos ambiguidade, mais autonomia.' },
        { color:'amber', label:'Sustentabilidade', title:'Qualidade Sustentável', desc:'Previsibilidade não mata criatividade. Governança criativa garante qualidade consistente sem burnout.' },
      ].map(p => {
        const c = accentColors[p.color];
        return (
          <div key={p.label} style={{ background: c.bg, border:`1px solid ${c.border}`, borderRadius: 12, padding: 24 }}>
            <p style={{ fontSize: 11, fontWeight: 700, letterSpacing:'.09em', textTransform:'uppercase', color: c.text, marginBottom: 10 }}>{p.label}</p>
            <p style={{ fontFamily:'var(--ffd)', fontSize: 20, fontWeight: 700, marginBottom: 10 }}>{p.title}</p>
            <p style={{ fontSize: 15, color:'var(--fg2)', lineHeight: 1.55 }}>{p.desc}</p>
          </div>
        );
      })}
    </div>

    <div style={{ display:'grid', gridTemplateColumns:'1fr 1fr', gap: 16, marginBottom: 24 }}>
      <Card>
        <p style={{ fontSize: 13, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color:'var(--fg3)', marginBottom: 16 }}>Contexto da Operação</p>
        <div className="overview-stats" style={{ display:'flex', gap: 0 }}>
          {[[String(T.meta.designerCount),'Designers no time'],[String(T.meta.accountCount),'Contas ativas'],[(T.meta.accountCount / T.meta.designerCount).toFixed(1),'Contas / designer']].map(([n,l],i) => (
            <div key={i} style={{ flex: 1, textAlign:'center', padding:'16px 8px', borderRight: i < 2 ? '1px solid var(--br)' : 'none' }}>
              <p style={{ fontFamily:'var(--ffd)', fontSize: 42, fontWeight: 800, color:'var(--acc)', lineHeight: 1 }}>{n}</p>
              <p style={{ fontSize: 13, color:'var(--fg2)', marginTop: 6 }}>{l}</p>
            </div>
          ))}
        </div>
      </Card>
      <Card>
        <p style={{ fontSize: 13, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color:'var(--fg3)', marginBottom: 16 }}>O que você vai encontrar aqui</p>
        <div style={{ display:'flex', flexDirection:'column', gap: 10 }}>
          {['Como as contas são classificadas e por quê','Como designers são alocados por tipo de conta','Fluxo padrão de trabalho da entrada à entrega','O que você pode decidir sozinho vs. alinhar','Rituais para manter o time sincronizado','Métricas simples para aprender e melhorar'].map(item => (
            <div key={item} style={{ display:'flex', gap: 10, alignItems:'flex-start' }}>
              <span style={{ color:'var(--acc)', fontWeight: 700, fontSize: 16, lineHeight: 1.4, flexShrink: 0 }}>✓</span>
              <p style={{ fontSize: 15, color:'var(--fg2)', lineHeight: 1.4 }}>{item}</p>
            </div>
          ))}
        </div>
      </Card>
    </div>

    <Card style={{ background:'var(--bg2)', borderColor:'var(--br)' }}>
      <p style={{ fontSize: 15, color:'var(--fg2)', lineHeight: 1.6 }}>
        <strong style={{ color:'var(--fg)' }}>Este playbook não é:</strong> manual de design, guia de marca, sistema de vigilância ou microgestão. É um <strong style={{ color:'var(--fg)' }}>documento vivo</strong> — muda conforme o time aprende.
      </p>
    </Card>
  </div>
);

/* ─── SECTION 02: TIPOLOGIA DE CONTAS ───────────────── */
const Accounts = () => {
  const [active, setActive] = useState('A');
  const store = window.useStore();
  const acc = T.accounts[active];
  const tc = typeColors[active];
  const liveItems = store.getAccountsByType(active).map(a => {
    const d = store.getDesigners().find(x => x.name === a.designerName);
    return { name: a.name, designer: a.designerName, initials: d?.initials || null };
  });
  return (
    <div>
      <SH num="02" title="Tipologia de Contas" desc="Nem toda conta funciona igual. Classificar corretamente define alocação, processo e nível de decisão." />

      <div className="horizontal-tabs" style={{ display:'flex', gap: 8, marginBottom: 24 }}>
        {['A','B','C'].map(t => (
          <button key={t} onClick={() => setActive(t)} style={{ display:'flex', alignItems:'center', gap: 10, padding:'10px 20px', borderRadius: 10, border:`1.5px solid ${active===t ? typeColors[t].border : 'var(--br)'}`, background: active===t ? typeColors[t].bg : 'var(--card)', cursor:'pointer', transition:'all .15s', flex: 1, justifyContent:'center' }}>
            <TypeBadge type={t} />
            <span style={{ fontFamily:'var(--ffd)', fontSize: 15, fontWeight: 700, color: active===t ? typeColors[t].text : 'var(--fg2)' }}>{T.accounts[t].label}</span>
          </button>
        ))}
      </div>

      <div style={{ display:'grid', gridTemplateColumns:'1fr 1fr', gap: 16, marginBottom: 16 }}>
        <div style={{ background: tc.bg, border:`1.5px solid ${tc.border}`, borderRadius: 12, padding: 24 }}>
          <p style={{ fontSize: 11, fontWeight: 700, letterSpacing:'.09em', textTransform:'uppercase', color: tc.text, marginBottom: 12 }}>Características</p>
          <div style={{ display:'flex', flexDirection:'column', gap: 10 }}>
            {acc.characteristics.map(c => (
              <div key={c} style={{ display:'flex', gap: 10 }}><span style={{ color: tc.text, fontSize: 16, lineHeight: 1.5, flexShrink:0 }}>→</span><p style={{ fontSize: 15, color:'var(--fg)', lineHeight: 1.5 }}>{c}</p></div>
            ))}
          </div>
        </div>
        <Card>
          <p style={{ fontSize: 11, fontWeight: 700, letterSpacing:'.09em', textTransform:'uppercase', color:'var(--fg3)', marginBottom: 12 }}>Perfil de Atuação</p>
          <div style={{ display:'flex', flexDirection:'column', gap: 0 }}>
            {[['Objetivo criativo', active==='A'?'Construir sistema':active==='B'?'Aplicar sistema':'Executar pontual'],['Nível de decisão',acc.decision],['Risco de retrabalho',acc.rework],['Iterações esperadas',acc.iterations],['Autonomia do designer',active==='A'?'Baixa (alta direção)':active==='B'?'Média':'Alta']].map(([k,v],i) => (
              <div className="account-profile-row" key={k} style={{ display:'flex', justifyContent:'space-between', alignItems:'center', padding:'12px 0', borderBottom: i < 4 ? '1px solid var(--br)' : 'none' }}>
                <span style={{ fontSize: 15, color:'var(--fg2)' }}>{k}</span>
                <span style={{ fontSize: 15, fontWeight: 600, color: tc.text }}>{v}</span>
              </div>
            ))}
          </div>
        </Card>
      </div>

      <Card style={{ marginBottom: 16 }}>
        <p style={{ fontSize: 11, fontWeight: 700, letterSpacing:'.09em', textTransform:'uppercase', color:'var(--fg3)', marginBottom: 8 }}>Exemplos</p>
        <p style={{ fontSize: 16, color:'var(--fg2)', lineHeight: 1.6 }}>{acc.examples}</p>
      </Card>
      <Card>
        <p style={{ fontSize: 11, fontWeight: 700, letterSpacing:'.09em', textTransform:'uppercase', color:'var(--fg3)', marginBottom: 12 }}>Contas Tipo {active} ({liveItems.length})</p>
        <div style={{ display:'flex', flexWrap:'wrap', gap: 8 }}>
          {liveItems.map(it => (
            <div key={it.name} style={{ display:'inline-flex', alignItems:'center', gap: 8, padding:'6px 12px', background: tc.bg, border:`1px solid ${tc.border}`, borderRadius: 999 }}>
              <span style={{ fontSize: 13, fontWeight: 600, color: tc.text }}>{it.name}</span>
              {it.designer ? <span style={{ fontSize: 12, color:'var(--fg2)' }}>· {it.designer}</span> : <span style={{ fontSize: 11, color:'var(--fg3)', fontStyle:'italic' }}>· a alocar</span>}
            </div>
          ))}
        </div>
      </Card>
    </div>
  );
};

/* ─── SECTION 03: ALOCAÇÃO ───────────────────────────── */
const Allocation = () => (
  <div>
    <SH num="03" title="Alocação de Designers" desc="Como distribuímos talento entre contas para garantir qualidade sem sobrecarga." />
    <div style={{ display:'grid', gridTemplateColumns:'1fr 1fr', gap: 16, marginBottom: 24 }}>
      {[
        { color:'purple', title:'Dedicação Exclusiva', desc:'Designer alocado 100% para uma única conta. Ideal para contas Tipo A.', pros:['Imersão total no contexto da conta','Consistência criativa máxima','Relacionamento forte com cliente'], cons:['Menos exposição a outros projetos'] },
        { color:'blue', title:'Dedicação Compartilhada', desc:'Designer atende 2–3 contas. Ideal para contas Tipo B e C.', pros:['Maior variedade de projetos','Melhor uso da capacidade do time','Cross-pollination de ideias'], cons:['Requer gestão de contexto e prioridades'] },
      ].map(m => {
        const c = accentColors[m.color];
        return (
          <div key={m.title} style={{ background: c.bg, border:`1px solid ${c.border}`, borderRadius: 12, padding: 24 }}>
            <p style={{ fontFamily:'var(--ffd)', fontSize: 18, fontWeight: 700, marginBottom: 8 }}>{m.title}</p>
            <p style={{ fontSize: 15, color:'var(--fg2)', marginBottom: 16, lineHeight: 1.5 }}>{m.desc}</p>
            <div style={{ display:'flex', flexDirection:'column', gap: 6 }}>
              {m.pros.map(p => <div key={p} style={{ display:'flex', gap: 8 }}><span style={{ color: c.text, fontWeight: 700, flexShrink:0 }}>+</span><p style={{ fontSize: 14, color:'var(--fg2)' }}>{p}</p></div>)}
              {m.cons.map(p => <div key={p} style={{ display:'flex', gap: 8 }}><span style={{ color:'var(--fg3)', fontWeight: 700, flexShrink:0 }}>−</span><p style={{ fontSize: 14, color:'var(--fg3)' }}>{p}</p></div>)}
            </div>
          </div>
        );
      })}
    </div>

    <Card style={{ marginBottom: 16 }}>
      <p style={{ fontSize: 13, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color:'var(--fg3)', marginBottom: 16 }}>Limites de Carga por Tipo</p>
      <div style={{ display:'grid', gridTemplateColumns:'repeat(3,1fr)', gap: 12 }}>
        {[['A','1','conta','Dedicação exclusiva recomendada','purple'],['B','2–3','contas','Máximo em dedicação compartilhada','blue'],['C','4–5','contas','Demanda baixa e pontual','green']].map(([t,n,u,d,col]) => {
          const tc = typeColors[t]; const ac = accentColors[col];
          return (
            <div key={t} style={{ textAlign:'center', padding: 20, background: ac.bg, border:`1px solid ${ac.border}`, borderRadius: 10 }}>
              <TypeBadge type={t} />
              <p style={{ fontFamily:'var(--ffd)', fontSize: 40, fontWeight: 800, color: ac.text, lineHeight: 1, margin:'10px 0 4px' }}>{n}</p>
              <p style={{ fontSize: 14, fontWeight: 600, marginBottom: 4 }}>{u}</p>
              <p style={{ fontSize: 13, color:'var(--fg2)' }}>{d}</p>
            </div>
          );
        })}
      </div>
    </Card>

    <Card>
      <p style={{ fontSize: 13, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color:'var(--fg3)', marginBottom: 16 }}>Senioridade por Tipo de Conta</p>
      <div style={{ display:'flex', flexDirection:'column', gap: 10 }}>
        {[['A','Sênior / Lead','Pensamento sistêmico, gestão de complexidade, autonomia criativa, relacionamento com stakeholders C-level'],['B','Pleno / Sênior','Produtividade, atenção a padrões, adaptação criativa dentro de sistemas, gestão de tempo'],['C','Júnior / Pleno','Execução técnica, follow-through, comunicação clara, gestão de expectativas']].map(([t,level,comp]) => (
          <div key={t} style={{ display:'flex', gap: 14, alignItems:'flex-start', padding:'14px 0', borderBottom:'1px solid var(--br)', lastChild:{ borderBottom:'none' } }}>
            <TypeBadge type={t} />
            <div style={{ flex: 1 }}>
              <p style={{ fontSize: 15, fontWeight: 600, marginBottom: 4 }}>{level}</p>
              <p style={{ fontSize: 14, color:'var(--fg2)', lineHeight: 1.5 }}>{comp}</p>
            </div>
          </div>
        ))}
      </div>
    </Card>
  </div>
);

/* ─── SECTION 04: MAPA DE ALOCAÇÃO ──────────────────── */
const AllocationMap = () => {
  const [filter, setFilter] = useState('all');
  const store = window.useStore();
  const liveAccounts = store.getAccounts();
  const liveDesigners = store.getDesigners();
  const allocated = liveAccounts.filter(a=>a.designerName).length;
  const unallocated = liveAccounts.filter(a=>!a.designerName).length;
  const accountsByType = (t) => liveAccounts.filter(a => a.type === t).map(a => {
    const d = liveDesigners.find(x => x.name === a.designerName);
    return { name: a.name, designer: a.designerName, initials: d?.initials || null };
  });

  return (
    <div>
      <SH num="04" title="Mapa de Alocação Criativa" desc="Leitura sistêmica da distribuição de contas, responsabilidades e capacidade do time." />

      <div className="mobile-two-col" style={{ display:'grid', gridTemplateColumns:'repeat(4,1fr)', gap: 12, marginBottom: 24 }}>
        {[[String(liveAccounts.length),'Contas Ativas','var(--fg)'],[String(liveDesigners.length),'Designers','var(--fg)'],[String(allocated),'Contas Alocadas','var(--acc)'],[String(unallocated),'A Alocar','oklch(72% .18 85)']].map(([n,l,col]) => (
          <Card key={l} style={{ textAlign:'center', padding: 20 }}>
            <p style={{ fontFamily:'var(--ffd)', fontSize: 36, fontWeight: 800, color: col, lineHeight: 1, marginBottom: 6 }}>{n}</p>
            <p style={{ fontSize: 13, color:'var(--fg2)' }}>{l}</p>
          </Card>
        ))}
      </div>

      <div className="filter-row" style={{ display:'flex', gap: 8, marginBottom: 20 }}>
        {[['all','Todas'],['A','Tipo A'],['B','Tipo B'],['C','Tipo C']].map(([v,l]) => (
          <button key={v} onClick={() => setFilter(v)} style={{ padding:'7px 16px', borderRadius: 8, border:`1px solid ${filter===v?'var(--acc)':'var(--br)'}`, background: filter===v?'rgba(99,102,241,.12)':'var(--card)', color: filter===v?'var(--acc)':'var(--fg2)', fontSize: 13, fontWeight: 600, cursor:'pointer', transition:'all .15s' }}>{l}</button>
        ))}
      </div>

      <div style={{ display:'grid', gridTemplateColumns:'repeat(3,1fr)', gap: 16 }}>
        {['A','B','C'].filter(t => filter==='all'||filter===t).map(type => {
          const tc = typeColors[type];
          const items = accountsByType(type);
          return (
            <div key={type} style={{ background: tc.bg, border:`1px solid ${tc.border}`, borderRadius: 12, padding: 20 }}>
              <div style={{ display:'flex', alignItems:'center', justifyContent:'space-between', marginBottom: 14 }}>
                <div style={{ display:'flex', alignItems:'center', gap: 8 }}>
                  <TypeBadge type={type} />
                  <span style={{ fontSize: 15, fontWeight: 600 }}>{T.accounts[type].label}</span>
                </div>
                <span style={{ fontFamily:'var(--ffd)', fontSize: 18, fontWeight: 700, color: tc.text }}>{items.filter(i=>i.designer).length}/{items.length}</span>
              </div>
              <div style={{ display:'flex', flexDirection:'column', gap: 8 }}>
                {items.length === 0 && <p style={{ fontSize: 13, color:'var(--fg3)', textAlign:'center', padding: 12 }}>Nenhuma conta neste tipo.</p>}
                {items.map(item => (
                  <div key={item.name} style={{ display:'flex', alignItems:'center', justifyContent:'space-between', padding:'10px 14px', background: item.designer?'var(--card)':'transparent', border: item.designer?`1px solid ${tc.border}`:`1px dashed ${tc.border}`, borderRadius: 8 }}>
                    <span style={{ fontSize: 14, fontWeight: 600 }}>{item.name}</span>
                    {item.designer
                      ? <div style={{ display:'flex', alignItems:'center', gap: 8 }}><Avatar initials={item.initials || '—'} type={type} /><span style={{ fontSize: 13, color:'var(--fg2)' }}>{item.designer}</span></div>
                      : <span style={{ fontSize: 13, color:'var(--fg3)', fontStyle:'italic' }}>A alocar</span>}
                  </div>
                ))}
              </div>
            </div>
          );
        })}
      </div>

      <Card style={{ marginTop: 16 }}>
        <p style={{ fontSize: 13, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color:'var(--fg3)', marginBottom: 14 }}>Visão por Designer</p>
        <div style={{ display:'grid', gridTemplateColumns:'repeat(2,1fr)', gap: 8 }}>
          {liveDesigners.map(d => {
            const myAccs = liveAccounts.filter(a => a.designerName === d.name);
            return (
            <div key={d.id} style={{ display:'flex', alignItems:'center', gap: 12, padding:'10px 14px', background:'var(--bg2)', borderRadius: 8 }}>
              <div style={{ width: 36, height: 36, borderRadius: '50%', background:'var(--bg3)', display:'flex', alignItems:'center', justifyContent:'center', fontSize: 12, fontWeight: 700, color:'var(--fg2)', flexShrink: 0 }}>{d.initials}</div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <p style={{ fontSize: 14, fontWeight: 600, marginBottom: 2 }}>{d.name}</p>
                <div style={{ display:'flex', gap: 4, flexWrap:'wrap' }}>
                  {myAccs.length > 0 ? myAccs.map(a => <span key={a.id} style={{ fontSize: 11, padding:'1px 7px', borderRadius: 4, background: typeColors[a.type]?.bg||'var(--bg3)', color: typeColors[a.type]?.text||'var(--fg3)', border:`1px solid ${typeColors[a.type]?.border||'var(--br)'}` }}>{a.name}</span>)
                  : <span style={{ fontSize: 11, color:'var(--fg3)' }}>Sem conta ativa</span>}
                </div>
              </div>
              {myAccs.length > 0 && <span style={{ fontSize: 12, fontWeight: 600, color:'var(--fg2)', flexShrink: 0 }}>{myAccs.length} {myAccs.length === 1 ? 'conta':'contas'}</span>}
            </div>
            );
          })}
        </div>
      </Card>
    </div>
  );
};

/* ─── SECTION 05: PIPELINE ───────────────────────────── */
const Pipeline = () => {
  const [tab, setTab] = useState('A');
  return (
    <div>
      <SH num="05" title="Pipeline de Trabalho" desc="Fluxo único que se adapta à complexidade de cada tipo de conta. Previsibilidade sem rigidez." />

      <Card style={{ marginBottom: 24 }}>
        <div className="pipeline-stages" style={{ display:'flex', alignItems:'stretch', gap: 0 }}>
          {T.pipeline.stages.map((s, i) => (
            <React.Fragment key={s.label}>
              <div className="pipeline-stage" style={{ flex: 1, padding:'16px 14px' }}>
                <p style={{ fontSize: 11, fontWeight: 700, letterSpacing:'.09em', textTransform:'uppercase', color:'var(--acc)', marginBottom: 6 }}>{s.num}</p>
                <p style={{ fontSize: 16, fontWeight: 700, marginBottom: 4 }}>{s.label}</p>
                <p style={{ fontSize: 13, color:'var(--fg2)', lineHeight: 1.4 }}>{s.desc}</p>
              </div>
              {i < T.pipeline.stages.length - 1 && <div style={{ width: 1, background:'var(--br)', margin:'8px 0', flexShrink: 0 }} />}
            </React.Fragment>
          ))}
        </div>
      </Card>

      <div style={{ marginBottom: 16 }}>
        <p style={{ fontSize: 13, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color:'var(--fg3)', marginBottom: 12 }}>Profundidade por Tipo de Conta</p>
        <div className="horizontal-tabs" style={{ display:'flex', gap: 8, marginBottom: 16 }}>
          {['A','B','C'].map(t => (
            <button key={t} onClick={() => setTab(t)} style={{ display:'flex', alignItems:'center', gap: 8, padding:'8px 18px', borderRadius: 8, border:`1.5px solid ${tab===t?typeColors[t].border:'var(--br)'}`, background: tab===t?typeColors[t].bg:'var(--card)', cursor:'pointer', transition:'all .15s' }}>
              <TypeBadge type={t} />
              <span style={{ fontSize: 13, fontWeight: 600, color: tab===t?typeColors[t].text:'var(--fg2)' }}>{T.accounts[t].label}</span>
            </button>
          ))}
        </div>
        <div style={{ display:'flex', flexDirection:'column', gap: 0, background:'var(--card)', border:'1px solid var(--br)', borderRadius: 12, overflow:'hidden' }}>
          {T.pipeline.byType[tab].map((row, i) => (
            <div className="pipeline-detail-row" key={row.stage} style={{ display:'flex', gap: 0, padding:'14px 20px', borderBottom: i < 5 ? '1px solid var(--br)' : 'none' }}>
              <span style={{ fontSize: 13, fontWeight: 700, color:'var(--acc)', minWidth: 90, flexShrink: 0 }}>{row.stage}</span>
              <p style={{ fontSize: 15, color:'var(--fg2)', lineHeight: 1.5 }}>{row.detail}</p>
            </div>
          ))}
        </div>
      </div>

      <div style={{ display:'grid', gridTemplateColumns:'repeat(4,1fr)', gap: 12 }}>
        {[['2 rounds inclusos','Adicionais cobrados separadamente'],['Revisão interna obrigatória','Gate antes de entregar ao cliente'],['Fast-track sob aprovação','Custo adicional + aval do lead'],['Mudança = nova demanda','Não extensão — entra na fila']].map(([t,d]) => (
          <Card key={t} style={{ padding: 16 }}>
            <p style={{ fontSize: 14, fontWeight: 700, color:'var(--acc)', marginBottom: 6 }}>{t}</p>
            <p style={{ fontSize: 13, color:'var(--fg2)', lineHeight: 1.4 }}>{d}</p>
          </Card>
        ))}
      </div>
    </div>
  );
};

/* ─── SECTION 06: BRIEFING ───────────────────────────── */
const Briefing = () => {
  const [open, setOpen] = useState(null);
  return (
    <div>
      <SH num="06" title="Briefing como Contrato" desc="Nenhum trabalho começa sem briefing. É o contrato mínimo que protege designer, cliente e o processo." />

      <div style={{ background:'rgba(245,158,11,.08)', border:'1px solid rgba(245,158,11,.3)', borderRadius: 12, padding: 20, marginBottom: 24 }}>
        <p style={{ fontFamily:'var(--ffd)', fontSize: 22, fontWeight: 700, marginBottom: 8 }}>O briefing é o acordo.</p>
        <p style={{ fontSize: 15, color:'var(--fg2)', lineHeight: 1.6, maxWidth: 600 }}>Porque define escopo, expectativa, contexto e critérios de sucesso. Sem briefing, não há acordo claro — e sem acordo, há retrabalho.</p>
        <div style={{ display:'grid', gridTemplateColumns:'repeat(3,1fr)', gap: 10, marginTop: 16 }}>
          {[['Protege o designer','Clareza sobre o que será entregue e por quê'],['Protege o cliente','Garante que a entrega atende o que foi pedido'],['Protege o processo','Reduz ambiguidade e retrabalho desnecessário']].map(([t,d]) => (
            <div key={t} style={{ background:'var(--card)', borderRadius: 8, padding: 14 }}>
              <p style={{ fontSize: 14, fontWeight: 600, marginBottom: 4 }}>{t}</p>
              <p style={{ fontSize: 13, color:'var(--fg2)' }}>{d}</p>
            </div>
          ))}
        </div>
      </div>

      <p style={{ fontSize: 13, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color:'var(--fg3)', marginBottom: 14 }}>Modelo Mínimo Obrigatório — clique para ver exemplo</p>
      <div style={{ background:'var(--card)', border:'1px solid var(--br)', borderRadius: 12, overflow:'hidden', marginBottom: 24 }}>
        {T.briefing.items.map((item, i) => (
          <div key={item.field}>
            <div className="briefing-row" onClick={() => setOpen(open === i ? null : i)} style={{ display:'flex', alignItems:'center', gap: 16, padding:'16px 20px', cursor:'pointer', borderBottom: open===i ? '1px solid var(--br)' : i < 6 ? '1px solid var(--br)' : 'none', background: open===i?'var(--bg2)':'transparent', transition:'background .15s' }}>
              <span style={{ fontSize: 12, fontWeight: 700, color:'var(--acc)', minWidth: 24 }}>{item.num}</span>
              <span style={{ fontSize: 16, fontWeight: 600, flex: 1 }}>{item.field}</span>
              <span className="briefing-desc" style={{ fontSize: 14, color:'var(--fg2)' }}>{item.desc}</span>
              <span style={{ fontSize: 14, color:'var(--fg3)', marginLeft: 8 }}>{open===i?'↑':'↓'}</span>
            </div>
            {open===i && <div className="briefing-example" style={{ padding:'14px 20px 14px 60px', background:'var(--bg2)', borderBottom: i < 6 ? '1px solid var(--br)' : 'none' }}><p style={{ fontSize: 14, color:'var(--fg2)', fontStyle:'italic', lineHeight: 1.5 }}><strong style={{ color:'var(--fg3)', fontStyle:'normal', marginRight: 6 }}>Exemplo:</strong>{item.example}</p></div>}
          </div>
        ))}
      </div>

      <div style={{ display:'grid', gridTemplateColumns:'1fr 1fr', gap: 16 }}>
        <div style={{ background:'rgba(34,197,94,.08)', border:'1px solid rgba(34,197,94,.3)', borderRadius: 12, padding: 20 }}>
          <p style={{ fontSize: 14, fontWeight: 700, color:'oklch(68% .18 155)', marginBottom: 14 }}>✓ Briefing Bom</p>
          {T.briefing.good.map(g => <div key={g} style={{ display:'flex', gap: 8, marginBottom: 8 }}><span style={{ color:'oklch(68% .18 155)', flexShrink:0 }}>•</span><p style={{ fontSize: 14, color:'var(--fg2)', lineHeight: 1.4 }}>{g}</p></div>)}
        </div>
        <div style={{ background:'rgba(239,68,68,.08)', border:'1px solid rgba(239,68,68,.3)', borderRadius: 12, padding: 20 }}>
          <p style={{ fontSize: 14, fontWeight: 700, color:'oklch(65% .22 25)', marginBottom: 14 }}>× Briefing Ruim</p>
          {T.briefing.bad.map(g => <div key={g} style={{ display:'flex', gap: 8, marginBottom: 8 }}><span style={{ color:'oklch(65% .22 25)', flexShrink:0 }}>•</span><p style={{ fontSize: 14, color:'var(--fg2)', lineHeight: 1.4 }}>{g}</p></div>)}
        </div>
      </div>
    </div>
  );
};

/* ─── SECTION 07: PRINCÍPIOS ─────────────────────────── */
const Principles = () => {
  const [open, setOpen] = useState(null);
  return (
    <div>
      <SH num="07" title="Princípios Criativos" desc="4 princípios que orientam todas as decisões criativas. Memorizáveis, aplicáveis, não negociáveis." />
      <div style={{ display:'grid', gridTemplateColumns:'1fr 1fr', gap: 16 }}>
        {T.principles.map((p, i) => {
          const c = accentColors[p.color];
          return (
            <div key={p.num} style={{ background: open===i ? c.bg : 'var(--card)', border:`1.5px solid ${open===i ? c.border : 'var(--br)'}`, borderRadius: 12, overflow:'hidden', transition:'all .2s', cursor:'pointer' }} onClick={() => setOpen(open===i?null:i)}>
              <div style={{ padding: 24 }}>
                <div style={{ display:'flex', alignItems:'flex-start', justifyContent:'space-between', marginBottom: 12 }}>
                  <span style={{ fontSize: 12, fontWeight: 700, letterSpacing:'.09em', textTransform:'uppercase', color: c.text }}>{p.num}</span>
                  <span style={{ fontSize: 13, color:'var(--fg3)' }}>{open===i?'↑':'↓'}</span>
                </div>
                <p style={{ fontFamily:'var(--ffd)', fontSize: 22, fontWeight: 700, marginBottom: 6 }}>{p.title}</p>
                <p style={{ fontSize: 14, color:'var(--fg2)', lineHeight: 1.5 }}>{p.subtitle}</p>
              </div>
              {open===i && (
                <div style={{ borderTop:`1px solid ${c.border}`, padding: 24 }}>
                  <p style={{ fontSize: 15, color:'var(--fg2)', lineHeight: 1.6, marginBottom: 16 }}>{p.desc}</p>
                  <p style={{ fontSize: 12, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color: c.text, marginBottom: 10 }}>Na prática</p>
                  {p.actions.map(a => <div key={a} style={{ display:'flex', gap: 8, marginBottom: 7 }}><span style={{ color: c.text, flexShrink:0 }}>→</span><p style={{ fontSize: 14, color:'var(--fg2)' }}>{a}</p></div>)}
                  <div style={{ background:'var(--card)', borderRadius: 8, padding: 14, marginTop: 14 }}>
                    <p style={{ fontSize: 13, color:'var(--fg2)', lineHeight: 1.5, fontStyle:'italic' }}><strong style={{ color: c.text, fontStyle:'normal' }}>Exemplo: </strong>{p.example}</p>
                  </div>
                </div>
              )}
            </div>
          );
        })}
      </div>
      <Card style={{ marginTop: 16 }}>
        <p style={{ fontSize: 15, color:'var(--fg2)', lineHeight: 1.6 }}>Estes princípios não são regras isoladas — são um <strong style={{ color:'var(--fg)' }}>sistema de pensamento</strong> que guia decisão criativa em qualquer situação. Use-os para dar e receber feedback estruturado.</p>
      </Card>
    </div>
  );
};

/* ─── SECTION 08: GUARDRAILS ─────────────────────────── */
const Guardrails = () => {
  const [open, setOpen] = useState('green');
  const zones = [
    { key:'green', label:'Zona Verde', sub:'Você decide sozinho', color:'green', data: T.guardrails.green },
    { key:'yellow', label:'Zona Amarela', sub:'Alinhamento necessário', color:'amber', data: T.guardrails.yellow },
    { key:'red', label:'Zona Vermelha', sub:'Escalada obrigatória', color:'red', data: T.guardrails.red },
  ];
  return (
    <div>
      <SH num="08" title="Guardrails de Decisão" desc="O que você pode decidir sozinho, o que precisa alinhar, quando escalar. Autonomia com estrutura." />

      <div style={{ display:'flex', flexDirection:'column', gap: 12, marginBottom: 24 }}>
        {zones.map(z => {
          const c = accentColors[z.color];
          const isOpen = open === z.key;
          return (
            <div key={z.key} style={{ background: isOpen ? c.bg : 'var(--card)', border:`1.5px solid ${isOpen ? c.border : 'var(--br)'}`, borderRadius: 12, overflow:'hidden', transition:'all .2s' }}>
              <div onClick={() => setOpen(isOpen ? null : z.key)} style={{ display:'flex', alignItems:'center', gap: 16, padding:'18px 24px', cursor:'pointer' }}>
                <div style={{ width: 10, height: 10, borderRadius: '50%', background: c.text, flexShrink: 0 }} />
                <div style={{ flex: 1 }}>
                  <p style={{ fontFamily:'var(--ffd)', fontSize: 18, fontWeight: 700 }}>{z.label}</p>
                  <p style={{ fontSize: 14, color:'var(--fg2)' }}>{z.sub}</p>
                </div>
                <span style={{ fontSize: 14, color:'var(--fg3)' }}>{isOpen?'↑':'↓'}</span>
              </div>
              {isOpen && (
                <div style={{ borderTop:`1px solid ${c.border}`, padding: 24 }}>
                  <p style={{ fontSize: 15, color:'var(--fg2)', lineHeight: 1.6, marginBottom: 20 }}>{z.data.desc}</p>
                  <div style={{ marginBottom: z.data.with ? 20 : 0 }}>
                    <p style={{ fontSize: 12, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color: c.text, marginBottom: 12 }}>Exemplos</p>
                    <div style={{ display:'flex', flexWrap:'wrap', gap: 8 }}>
                      {z.data.items.map(item => <Chip key={item} color={z.color}>{item}</Chip>)}
                    </div>
                  </div>
                  {z.data.with && (
                    <div>
                      <p style={{ fontSize: 12, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color: c.text, marginBottom: 12 }}>Com quem alinhar / escalar</p>
                      {z.data.with.map(w => <div key={w} style={{ fontSize: 14, color:'var(--fg2)', padding:'8px 0', borderBottom:'1px solid var(--br)', lineHeight: 1.4 }}>{w}</div>)}
                    </div>
                  )}
                </div>
              )}
            </div>
          );
        })}
      </div>

      <Card>
        <p style={{ fontSize: 13, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color:'var(--fg3)', marginBottom: 14 }}>Fluxo de Decisão Rápida</p>
        <div style={{ display:'flex', flexDirection:'column', gap: 10 }}>
          {['Você está diante de uma decisão → Identifique a zona (Verde, Amarela, Vermelha)','Zona Verde? Execute com confiança.','Zona Amarela? Alinha rápido com a pessoa certa antes de executar.','Zona Vermelha? Escala imediatamente — não tenta resolver sozinho.'].map((s,i) => (
            <div key={i} style={{ display:'flex', gap: 12, alignItems:'flex-start' }}>
              <span style={{ width: 22, height: 22, borderRadius: '50%', background:'var(--bg3)', display:'flex', alignItems:'center', justifyContent:'center', fontSize: 11, fontWeight: 700, color:'var(--fg2)', flexShrink: 0 }}>{i+1}</span>
              <p style={{ fontSize: 15, color:'var(--fg2)', lineHeight: 1.5 }}>{s}</p>
            </div>
          ))}
        </div>
      </Card>
    </div>
  );
};

/* ─── SECTION 09: RITUAIS ────────────────────────────── */
const Rituals = () => {
  const [open, setOpen] = useState(0);
  const freqColor = { 'Semanal':'blue', 'Quinzenal':'purple', 'Mensal':'amber' };
  return (
    <div>
      <SH num="09" title="Rituais de Governança" desc="Rituais regulares que mantêm o time alinhado, sem reunionite. Cada um tem propósito claro." />
      <div style={{ display:'flex', flexDirection:'column', gap: 10 }}>
        {T.rituals.map((r, i) => {
          const fc = accentColors[freqColor[r.freq]] || accentColors.blue;
          const isOpen = open === i;
          return (
            <div key={r.title} style={{ background: isOpen?'var(--card)':'var(--card)', border:`1px solid ${isOpen?'var(--acc)':'var(--br)'}`, borderRadius: 12, overflow:'hidden', transition:'border .15s' }}>
              <div className="ritual-header" onClick={() => setOpen(isOpen?null:i)} style={{ display:'flex', alignItems:'center', gap: 16, padding:'16px 20px', cursor:'pointer' }}>
                <div className="ritual-frequency" style={{ textAlign:'center', minWidth: 72, padding:'6px 10px', background: fc.bg, border:`1px solid ${fc.border}`, borderRadius: 8 }}>
                  <p style={{ fontSize: 11, fontWeight: 700, color: fc.text, letterSpacing:'.06em', textTransform:'uppercase' }}>{r.freq}</p>
                </div>
                <div style={{ flex: 1 }}>
                  <p style={{ fontFamily:'var(--ffd)', fontSize: 17, fontWeight: 700, marginBottom: 2 }}>{r.title}</p>
                  <p style={{ fontSize: 13, color:'var(--fg2)' }}>{r.duration} · {r.who}</p>
                </div>
                <span style={{ fontSize: 14, color:'var(--fg3)' }}>{isOpen?'↑':'↓'}</span>
              </div>
              {isOpen && (
                <div className="ritual-details" style={{ borderTop:'1px solid var(--br)', padding:'20px 20px 20px 108px' }}>
                  <p style={{ fontSize: 15, color:'var(--fg2)', lineHeight: 1.6, marginBottom: 16 }}>{r.desc}</p>
                  <p style={{ fontSize: 12, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color:'var(--fg3)', marginBottom: 10 }}>Formato</p>
                  {r.format.map((f,fi) => (
                    <div key={fi} style={{ display:'flex', gap: 10, marginBottom: 8 }}>
                      <span style={{ color:'var(--acc)', fontWeight: 700, flexShrink: 0 }}>{fi+1}.</span>
                      <p style={{ fontSize: 14, color:'var(--fg2)', lineHeight: 1.5 }}>{f}</p>
                    </div>
                  ))}
                  <div style={{ background:'var(--bg2)', borderRadius: 8, padding: 12, marginTop: 12 }}>
                    <p style={{ fontSize: 13, color:'var(--fg2)', fontStyle:'italic' }}><strong style={{ color:'var(--fg)', fontStyle:'normal' }}>Output: </strong>{r.output}</p>
                  </div>
                </div>
              )}
            </div>
          );
        })}
      </div>
    </div>
  );
};

/* ─── SECTION 10: MÉTRICAS ───────────────────────────── */
const Metrics = () => {
  const [open, setOpen] = useState(null);
  return (
    <div>
      <SH num="10" title="Métricas Essenciais" desc="Indicadores simples para aprender e melhorar. Foco em sustentabilidade, não vigilância." />

      <div style={{ background:'var(--card)', border:'1px solid var(--br)', borderRadius: 12, padding: 20, marginBottom: 24 }}>
        <p style={{ fontFamily:'var(--ffd)', fontSize: 18, fontWeight: 700, marginBottom: 8 }}>Por que medir?</p>
        <p style={{ fontSize: 15, color:'var(--fg2)', lineHeight: 1.6, marginBottom: 16 }}>Métricas não servem para vigiar designers. Servem para identificar padrões, gargalos e oportunidades de melhoria no sistema. O objetivo é aprendizado coletivo, não performance individual.</p>
        <div style={{ display:'grid', gridTemplateColumns:'repeat(3,1fr)', gap: 10 }}>
          {[['Volume','Entender capacidade','blue'],['Retrabalho','Identificar causas raiz','amber'],['Gargalos','Resolver bloqueios','red']].map(([t,d,col]) => (
            <div key={t} style={{ textAlign:'center', padding: 14, background:'var(--bg2)', borderRadius: 8 }}>
              <p style={{ fontFamily:'var(--ffd)', fontSize: 20, fontWeight: 700, color: accentColors[col].text, marginBottom: 4 }}>{t}</p>
              <p style={{ fontSize: 13, color:'var(--fg2)' }}>{d}</p>
            </div>
          ))}
        </div>
      </div>

      <div style={{ display:'flex', flexDirection:'column', gap: 12 }}>
        {T.metrics.map((m, i) => {
          const c = accentColors[m.color];
          const isOpen = open === i;
          return (
            <div key={m.num} style={{ border:`1px solid ${isOpen?c.border:'var(--br)'}`, borderRadius: 12, overflow:'hidden', background:'var(--card)', transition:'border .15s' }}>
              <div onClick={() => setOpen(isOpen?null:i)} style={{ display:'flex', alignItems:'center', gap: 16, padding:'18px 20px', cursor:'pointer' }}>
                <div style={{ width: 36, height: 36, borderRadius: 8, background: c.bg, border:`1px solid ${c.border}`, display:'flex', alignItems:'center', justifyContent:'center', fontSize: 13, fontWeight: 800, color: c.text, flexShrink: 0 }}>{m.num}</div>
                <div style={{ flex: 1 }}>
                  <p style={{ fontFamily:'var(--ffd)', fontSize: 18, fontWeight: 700, marginBottom: 3 }}>{m.title}</p>
                  <p style={{ fontSize: 14, color:'var(--fg2)' }}>{m.question}</p>
                </div>
                <span style={{ fontSize: 14, color:'var(--fg3)' }}>{isOpen?'↑':'↓'}</span>
              </div>
              {isOpen && (
                <div className="metric-grid" style={{ borderTop:'1px solid var(--br)', display:'grid', gridTemplateColumns:'1fr 1fr', gap: 0 }}>
                  <div style={{ padding: 20, borderRight:'1px solid var(--br)' }}>
                    <p style={{ fontSize: 12, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color:'var(--fg3)', marginBottom: 10 }}>O que medir</p>
                    {m.measures.map(x => <div key={x} style={{ display:'flex', gap: 8, marginBottom: 8 }}><span style={{ color: c.text, flexShrink:0 }}>•</span><p style={{ fontSize: 14, color:'var(--fg2)', lineHeight: 1.4 }}>{x}</p></div>)}
                  </div>
                  <div style={{ padding: 20 }}>
                    <p style={{ fontSize: 12, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color:'var(--fg3)', marginBottom: 10 }}>Para que serve</p>
                    {m.purpose.map(x => <div key={x} style={{ display:'flex', gap: 8, marginBottom: 8 }}><span style={{ color: c.text, flexShrink:0 }}>→</span><p style={{ fontSize: 14, color:'var(--fg2)', lineHeight: 1.4 }}>{x}</p></div>)}
                  </div>
                  <div style={{ gridColumn:'1/-1', padding:'14px 20px', borderTop:'1px solid var(--br)', background:'var(--bg2)' }}>
                    <p style={{ fontSize: 13, color:'var(--fg2)', lineHeight: 1.5, fontStyle:'italic' }}><strong style={{ color: c.text, fontStyle:'normal' }}>Exemplo: </strong>{m.example}</p>
                  </div>
                </div>
              )}
            </div>
          );
        })}
      </div>

      <Card style={{ marginTop: 16 }}>
        <div style={{ display:'grid', gridTemplateColumns:'1fr 1fr', gap: 20 }}>
          <div>
            <p style={{ fontSize: 13, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color:'oklch(68% .18 155)', marginBottom: 10 }}>✓ Faça</p>
            {['Revise métricas mensalmente na retrospectiva','Foque em padrões, não casos isolados','Use para identificar causas raiz, não culpados','Transforme insights em ações concretas','Compartilhe métricas com transparência'].map(x => <p key={x} style={{ fontSize: 14, color:'var(--fg2)', marginBottom: 6 }}>• {x}</p>)}
          </div>
          <div>
            <p style={{ fontSize: 13, fontWeight: 700, letterSpacing:'.08em', textTransform:'uppercase', color:'oklch(65% .22 25)', marginBottom: 10 }}>× Não faça</p>
            {['Usar métricas para cobrar indivíduos','Criar ranking de produtividade','Medir por medir, sem usar dados para melhorar','Esconder métricas do time','Ignorar feedback qualitativo em favor de números'].map(x => <p key={x} style={{ fontSize: 14, color:'var(--fg2)', marginBottom: 6 }}>• {x}</p>)}
          </div>
        </div>
      </Card>
    </div>
  );
};

const SECTIONS = { Overview, Accounts, Allocation, AllocationMap, Pipeline, Briefing, Principles, Guardrails, Rituals, Metrics };
Object.assign(window, { SECTIONS });
