// Sybre — AI infrastructure page (the wedge). Interactive architecture diagram.

const AI_NODES = [
  { id:'user',     x: 80,  y: 200, label:'Your team',          sub:'Browser / Teams / app',     ring:'sage' },
  { id:'sso',      x: 290, y: 110, label:'Microsoft Entra ID', sub:'SSO · audited access',      ring:'sage' },
  { id:'gateway',  x: 290, y: 290, label:'Sybre AI gateway',   sub:'On-prem · request routing', ring:'orange' },
  { id:'rag',      x: 510, y: 110, label:'Document store',     sub:'Your files · indexed',      ring:'sage' },
  { id:'llm',      x: 510, y: 290, label:'Local LLM',          sub:'30B–70B params · NVIDIA RTX PRO 6000', ring:'orange' },
  { id:'audit',    x: 740, y: 200, label:'Audit & retention',  sub:'Every request, logged',     ring:'sage' },
];

const AI_EDGES = [
  { from:'user',    to:'sso',     label:'Authenticates' },
  { from:'user',    to:'gateway', label:'Asks a question' },
  { from:'sso',     to:'gateway', label:'Identity claim' },
  { from:'gateway', to:'rag',     label:'Retrieves context' },
  { from:'gateway', to:'llm',     label:'Generates answer' },
  { from:'rag',     to:'llm',     label:'Grounded passages' },
  { from:'gateway', to:'audit',   label:'Logs everything' },
];

const NODE_DESC = {
  user:    'Your team uses the same tools they already do — browser, Teams, your line-of-business app. They never see the plumbing.',
  sso:     'Single sign-on through your existing Microsoft Entra ID tenant. Conditional access, MFA, group-based permissions all carry through. No second identity to manage.',
  gateway: 'A small service we deploy on your premises. It handles request routing, prompt templates, rate limiting, and the audit trail. Open-source, transparent, yours to inspect.',
  rag:     'Your existing documents — Confluence, SharePoint, network drives — indexed into a local vector store. Retrieval-augmented generation grounds every answer in your real content.',
  llm:     'A current-generation open-weights model (Llama, Qwen, or similar) running on NVIDIA professional GPUs (RTX PRO 6000 Blackwell class). 30B parameters for general work, 70B where accuracy matters more than latency.',
  audit:   'Every request, every retrieval, every response — logged with the user identity, timestamp, and grounding sources. Retention configurable. Exports to your SIEM if you have one.',
};

function AIPage() {
  const [active, setActive] = React.useState('gateway');

  return (
    <Page>
      {/* HERO */}
      <section className="page-hero" style={{ position:'relative', overflow:'hidden' }}>
        <div aria-hidden="true" className="hero-splash" style={{ backgroundImage:'url(assets/Images/bw_geo01.jpg)' }} />
        <div className="container" style={{ position:'relative' }}>
          <Reveal>
            <Link to="/services" className="meta" style={{ display:'inline-block', marginBottom:24 }}>← All services</Link>
            <div className="eyebrow accent" style={{ marginBottom: 24 }}>AI infrastructure</div>
            <h1 className="h-hero" style={{ marginBottom: 28 }}>
              Your data stays<br/><em className="accent">on your premises</em>.
            </h1>
            <p className="lead lg" style={{ marginBottom: 36 }}>
              Your model is fine-tuned on your documents. Your team gets answers in seconds, not minutes. And no client information ever leaves the building.
            </p>
            <div style={{ display:'flex', gap:12, flexWrap:'wrap' }}>
              <Link to="/contact" className="btn btn-primary">Book a demo</Link>
              <Link to="/services/ai/roi" className="btn btn-text btn-arrow" style={{ color:'var(--soft-sage)' }}>Calculate your ROI</Link>
              <a href="#architecture" className="btn btn-text btn-arrow">See the architecture</a>
            </div>
          </Reveal>
        </div>
      </section>

      {/* OUTCOMES */}
      <section className="section">
        <div className="container">
          <SectionHead num="01" label="Outcomes" title="What you actually <em>get</em>." />
          <Reveal stagger className="grid-3">
            {[
              { n:'~6 hrs', l:'Saved per fee earner per week on contract review and document summarisation, on a typical legal deployment.', sage:true },
              { n:'0 bytes', l:'Of client data sent to an external AI provider. Inference happens on hardware you own.' },
              { n:'< 2 sec', l:'Median response time on grounded queries against a 100k-document corpus.' },
            ].map((s, i) => (
              <div key={i} className={'card' + (s.sage ? ' sage-fill' : '')} style={{ display:'flex', flexDirection:'column', justifyContent:'space-between', minHeight: 220 }}>
                <div className={'stat-num' + (s.sage ? '' : ' sage')} style={{ fontSize: 'clamp(40px, 5vw, 64px)' }}>{s.n}</div>
                <div className="stat-label">{s.l}</div>
              </div>
            ))}
          </Reveal>
        </div>
      </section>

      {/* ARCHITECTURE — interactive diagram */}
      <section id="architecture" className="band">
        <div className="container">
          <SectionHead
            num="02" label="Reference architecture"
            title="The whole stack, <em>on your floor</em>."
            lead="Hover any node to see what it does. Every box runs on hardware you own — or in your existing Microsoft tenant."
          />
          <Reveal>
            <div style={{
              background:'var(--sybre-black)',
              border:'1px solid var(--border-1)',
              borderRadius:'var(--r-card)',
              padding:'40px 24px 24px',
              position:'relative',
            }}>
              <ArchitectureDiagram active={active} setActive={setActive} />
              <div style={{
                marginTop:24, padding:'24px 28px',
                background:'var(--off-black)', borderRadius:'var(--r-inner)',
                border:'1px solid var(--border-1)',
                minHeight: 120,
              }}>
                <div className="eyebrow" style={{ marginBottom:10 }}>
                  {AI_NODES.find(n => n.id === active)?.label}
                </div>
                <p className="body" style={{ color:'var(--fg2)', maxWidth: 720 }}>
                  {NODE_DESC[active]}
                </p>
              </div>
              <div style={{ marginTop: 16, display:'flex', flexWrap:'wrap', gap: 18 }}>
                <span style={{ display:'inline-flex', alignItems:'center', gap:8, fontSize:13, color:'var(--fg3)' }}>
                  <span style={{ width:10, height:10, borderRadius:'50%', background:'var(--burnt-orange)' }} /> Sybre-deployed component
                </span>
                <span style={{ display:'inline-flex', alignItems:'center', gap:8, fontSize:13, color:'var(--fg3)' }}>
                  <span style={{ width:10, height:10, borderRadius:'50%', background:'var(--soft-sage)' }} /> Yours / existing
                </span>
                <span style={{ display:'inline-flex', alignItems:'center', gap:8, fontSize:13, color:'var(--fg3)' }}>
                  <span style={{ width:18, height:1, background:'var(--soft-sage)' }} /> Data flow
                </span>
              </div>
            </div>
          </Reveal>
        </div>
      </section>

      {/* HARDWARE */}
      <section className="section">
        <div className="container">
          <SectionHead num="03" label="Hardware" title="Specific, <em>not aspirational</em>." />
          <Reveal stagger className="grid-2">
            <div className="card">
              <h3 className="h-card" style={{ marginBottom: 14 }}>Compute</h3>
              <p className="body" style={{ marginBottom: 18 }}>We design around current-generation NVIDIA professional GPUs — RTX PRO 6000 Blackwell class — for 30B–70B parameter models. Sized to your concurrent-user load, with headroom.</p>
              <ul className="list-clean">
                <li>1× RTX PRO 6000 — up to ~25 concurrent users on a 30B model</li>
                <li>2× RTX PRO 6000 — 70B-class models with sub-2-second latency</li>
                <li>Rack-mount workstation form factor — fits a standard server cabinet</li>
              </ul>
            </div>
            <div className="card">
              <h3 className="h-card" style={{ marginBottom: 14 }}>Identity & governance</h3>
              <p className="body" style={{ marginBottom: 18 }}>Integrated with your existing Microsoft Entra ID tenant for SSO and audited access. No second directory to maintain, no shadow accounts.</p>
              <ul className="list-clean">
                <li>SSO via Entra ID — group-based access control</li>
                <li>Conditional access policies carry through</li>
                <li>Per-request audit log, retention configurable</li>
                <li>Optional SIEM export</li>
              </ul>
            </div>
          </Reveal>
        </div>
      </section>

      {/* DEPLOYMENT PATTERNS */}
      <section className="section">
        <div className="container">
          <SectionHead num="04" label="Deployment patterns" title="Three <em>shapes</em>." lead="Most engagements start with one and grow into the next. We tell you which shape fits before we sell you the work." />
          <Reveal stagger className="grid-3">
            {[
              { n:'01', t:'RAG-first', b:'A local LLM grounded in your existing documents. Fastest to value. Best for legal review, internal Q&A, policy lookup.' },
              { n:'02', t:'Fine-tuned', b:'A model trained on your data — letters, briefs, reports — to match your house style. Slower to deploy, sharper output.' },
              { n:'03', t:'Hybrid agentic', b:'The model takes actions in your stack: drafting in your DMS, raising tickets, triaging email. Bounded scope, audited every step.' },
            ].map(p => (
              <div key={p.n} className="card" style={{ minHeight: 220 }}>
                <h3 className="h-card" style={{ marginBottom: 12 }}>{p.t}</h3>
                <p className="body">{p.b}</p>
              </div>
            ))}
          </Reveal>
        </div>
      </section>

      <section className="band">
        <div className="container">
          <Reveal>
            <div style={{ maxWidth: 880 }}>
              <span className="placeholder">Testimonial — needs sourcing</span>
              <blockquote style={{
                fontFamily:'var(--font-display)', fontSize:'clamp(28px,3vw,38px)',
                fontWeight:300, letterSpacing:'-0.02em', lineHeight:1.3,
                marginTop:24, color:'var(--fg1)',
              }}>
                "Our partners stopped asking whether the AI tool was 'safe'. The answer was already in the architecture diagram."
              </blockquote>
              <div style={{ marginTop: 24, display:'flex', alignItems:'center', gap:16 }}>
                <div style={{ width: 48, height: 48, borderRadius: '50%', background:'var(--off-black)', border:'1px solid var(--border-2)' }} />
                <div>
                  <div style={{ fontFamily:'var(--font-display)', fontWeight:500, fontSize:15 }}>Managing partner</div>
                  <div className="meta">Mid-size law firm · Sydney</div>
                </div>
              </div>
            </div>
          </Reveal>
        </div>
      </section>

      <FinalCTA num="05" label="Next step" title="Bring your <em>worst document</em>." />
    </Page>
  );
}

function ArchitectureDiagram({ active, setActive }) {
  const W = 820, H = 400;
  const nodeById = id => AI_NODES.find(n => n.id === id);

  return (
    <div style={{ width:'100%', overflowX:'auto' }}>
      <svg viewBox={`0 0 ${W} ${H}`} style={{ width:'100%', minWidth: 720, display:'block' }}>
        <defs>
          <marker id="arrowhead" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
            <path d="M0,0 L10,5 L0,10 z" fill="#8DBFB0" opacity="0.7" />
          </marker>
        </defs>

        {/* edges */}
        {AI_EDGES.map((e, i) => {
          const a = nodeById(e.from), b = nodeById(e.to);
          const isActive = active === e.from || active === e.to;
          // gentle curve
          const mx = (a.x + b.x) / 2, my = (a.y + b.y) / 2;
          const dx = b.x - a.x, dy = b.y - a.y;
          // perpendicular offset for curve
          const len = Math.sqrt(dx*dx + dy*dy);
          const ox = -dy/len * 18, oy = dx/len * 18;
          const path = `M ${a.x},${a.y} Q ${mx + ox},${my + oy} ${b.x},${b.y}`;
          return (
            <g key={i}>
              <path d={path} fill="none"
                stroke={isActive ? '#8DBFB0' : 'rgba(141,191,176,0.35)'}
                strokeWidth={isActive ? 1.6 : 1}
                strokeDasharray={isActive ? '0' : '3 4'}
                markerEnd="url(#arrowhead)"
                style={{ transition:'all 0.25s ease' }}
              />
              {isActive && (
                <text x={(a.x + b.x) / 2 + ox * 1.4} y={(a.y + b.y) / 2 + oy * 1.4 - 4}
                      fill="#8DBFB0" fontSize="11" fontFamily="var(--font-body)"
                      textAnchor="middle" style={{ letterSpacing: '0.04em' }}>
                  {e.label}
                </text>
              )}
            </g>
          );
        })}

        {/* nodes */}
        {AI_NODES.map(n => {
          const isActive = active === n.id;
          const ringColor = n.ring === 'orange' ? '#C8652A' : '#8DBFB0';
          return (
            <g key={n.id}
               style={{ cursor:'pointer' }}
               onMouseEnter={() => setActive(n.id)}
               onFocus={() => setActive(n.id)}
               onClick={() => setActive(n.id)}
               tabIndex={0}>
              {isActive && (
                <circle cx={n.x} cy={n.y} r={42}
                        fill="none" stroke={ringColor} strokeWidth="1" opacity="0.4">
                  <animate attributeName="r" from="34" to="50" dur="1.6s" repeatCount="indefinite" />
                  <animate attributeName="opacity" from="0.5" to="0" dur="1.6s" repeatCount="indefinite" />
                </circle>
              )}
              <circle cx={n.x} cy={n.y} r={isActive ? 32 : 28}
                      fill="#1A1818"
                      stroke={ringColor}
                      strokeWidth={isActive ? 2 : 1.2}
                      style={{ transition:'all 0.25s ease' }} />
              <circle cx={n.x} cy={n.y} r="5" fill={ringColor} />
              <text x={n.x} y={n.y + 56}
                    fill={isActive ? '#fff' : 'rgba(255,255,255,0.75)'}
                    fontSize="13" fontFamily="var(--font-display)" fontWeight="500"
                    textAnchor="middle"
                    style={{ transition:'fill 0.2s ease' }}>
                {n.label}
              </text>
              <text x={n.x} y={n.y + 74}
                    fill="rgba(255,255,255,0.40)"
                    fontSize="11" fontFamily="var(--font-body)"
                    textAnchor="middle">
                {n.sub}
              </text>
            </g>
          );
        })}
      </svg>
    </div>
  );
}

Object.assign(window, { AIPage });
