function Industries() {
  const [i, setI] = React.useState(0); const [fade, setFade] = React.useState(false); const refs = React.useRef([]);
  const pick = (n, animate) => { setI(n); setFade(!!animate); };
  const onKey = e => { const d = { ArrowDown: 1, ArrowRight: 1, ArrowUp: -1, ArrowLeft: -1 }[e.key]; if (d == null && e.key !== 'Home' && e.key !== 'End') return; e.preventDefault(); const n = e.key === 'Home' ? 0 : e.key === 'End' ? INDUSTRIES.length - 1 : (i + d + INDUSTRIES.length) % INDUSTRIES.length; pick(n, false); refs.current[n] && refs.current[n].focus(); };
  const cur = INDUSTRIES[i];
  return <div className="tabs">
    <div className="tablist" role="tablist" aria-label="Industries" aria-orientation="vertical" onKeyDown={onKey}>{INDUSTRIES.map((it, n) => <button key={it.key} ref={el => refs.current[n] = el} role="tab" id={'tab-' + it.key} aria-selected={n === i} aria-controls={'panel-' + it.key} tabIndex={n === i ? 0 : -1} className="tab" onClick={() => pick(n, true)}><Tile icon={it.icon} size={40} />{it.name}<span style={{ marginLeft: 'auto', opacity: n === i ? 1 : .35, display: 'inline-flex' }} aria-hidden="true"><DS.Icon name="ArrowRight" size={18} /></span></button>)}</div>
    <div key={cur.key + (fade ? '-f' : '')} role="tabpanel" id={'panel-' + cur.key} aria-labelledby={'tab-' + cur.key} className={'tabpanel on-navy' + (fade ? ' fade' : '')}>
      <div><Tile icon={cur.icon} /><h3 style={{ fontSize: 30, fontWeight: 800, letterSpacing: '-.02em', marginTop: 20 }}>{cur.name}</h3><p className="small" style={{ margin: '12px 0 24px', fontSize: 16 }}>{cur.body}</p><DS.Button variant="cyan" href={'tel:' + cur.demo[1].replace(/\D/g, '')} aria-label={'Call the ' + cur.name.toLowerCase() + ' demo line, ' + cur.demo[1]}><DS.Icon name="Phone" size={18} /><span className="num">Call {cur.demo[1]}</span></DS.Button></div>
      <ul className="checks">{cur.bullets.map(b => <Check key={b}>{b}</Check>)}</ul>
    </div>
  </div>;
}
function DemoLines() {
  return <div className="demo on-navy" id="demo">
    <div className="reveal"><h2 id="demo-title">Hear it for yourself.</h2><p className="lead" style={{ marginTop: 12 }}>Call any line to hear a live AI receptionist trained for that industry. Free, instant, no signup.</p><div style={{ marginTop: 28, padding: 24, borderRadius: 20, background: 'rgba(255,255,255,.06)', border: '1px solid rgba(255,255,255,.14)' }}><div className="caption" style={{ fontWeight: 700, letterSpacing: '.08em', textTransform: 'uppercase', color: 'var(--oc-blue-on-navy)' }}>Main demo line</div><a href={TEL} className="num" aria-label={'Call ' + PHONE} style={{ display: 'block', marginTop: 6, fontFamily: 'var(--font-mono)', fontSize: 32, fontWeight: 500, color: '#fff', textDecoration: 'none', letterSpacing: '-.02em' }}>(877) 774-1777</a></div></div>
    <div style={{ display: 'grid', gap: 8 }}>{INDUSTRIES.map((it, n) => { const [biz, num, voice] = it.demo; return <a key={it.key} className="demo-row reveal" href={'tel:' + num.replace(/\D/g, '')} aria-label={'Call the ' + it.name.toLowerCase() + ' demo line, ' + num} style={{ transitionDelay: (Math.min(n, 5) * 50) + 'ms' }}><Tile icon={it.icon} size={44} /><span><span className="ind">{it.name}</span><span style={{ fontWeight: 700, fontSize: 16 }}>{biz}</span></span><span className="voice small" style={{ color: 'var(--oc-text-on-navy)' }}>Voice: {voice}</span><span className="demo-num">{num}<span aria-hidden="true"><DS.Icon name="Phone" size={15} /></span></span></a>; })}</div>
  </div>;
}
// Industry demo lines as a sliding card rail: the active card widens and fades in a blue gradient.
function IndustryCarousel() {
  const n = INDUSTRIES.length;
  const [i, setI] = React.useState(0);
  const [size, setSize] = React.useState({ w: 300, wa: 520, gap: 20, view: 1200 });
  const trackRef = React.useRef(null), listRef = React.useRef(null);
  const vel = React.useRef(0), anchor = React.useRef(null);
  const pos = React.useRef(0), mouse = React.useRef(null), raf = React.useRef(0), drag = React.useRef(null), iRef = React.useRef(0);
  const { w, wa, gap, view } = size;
  const maxPos = Math.max(0, (n - 1) * (w + gap) + wa - view);
  const peek = view >= 900 ? 72 : 24; // keep part of the previous card in view
  React.useEffect(() => {
    const measure = () => { const t = trackRef.current; const v = t ? Math.min(t.clientWidth, document.documentElement.clientWidth - t.getBoundingClientRect().left) : 1200; /* stop at the scrollbar */ setSize({ w: v < 640 ? 232 : 300, wa: Math.min(520, v - 32), gap: v < 640 ? 12 : 20, view: v }); };
    measure(); window.addEventListener('resize', measure); return () => window.removeEventListener('resize', measure);
  }, []);
  const maxRef = React.useRef(0); maxRef.current = maxPos;
  const setPos = (p, glide) => { pos.current = Math.max(0, Math.min(p, maxRef.current)); const t = trackRef.current; if (t) { t.classList.toggle('fade-l', pos.current > 1); t.classList.toggle('fade-r', pos.current < maxRef.current - 1); } const el = listRef.current; if (!el) return; el.classList.toggle('is-panning', !glide); el.style.transform = `translateX(${-pos.current}px)`; };
  const activate = k => { if (k !== iRef.current) { iRef.current = k; setI(k); } };
  const glideUntil = React.useRef(0);
  const focusTo = k => { k = (k + n) % n; activate(k); setPos(k * (w + gap) - (k ? peek : 0), true); glideUntil.current = performance.now() + 550; vel.current = 0; anchor.current = null; };
  React.useEffect(() => { setPos(pos.current, true); }, [maxPos]);
  // Mouse: the row drifts toward whichever side the pointer is on (only the middle 10% is still), faster nearer the edge.
  // Speed eases in and coasts out instead of snapping. Sensing reaches NEAR px above/below the cards and the full window width.
  const EDGE = 0.45, SPEED = 24, NEAR = 160, EASE = 0.09;
  const tick = () => {
    const m = mouse.current, track = trackRef.current, list = listRef.current;
    if (!track || !list) { raf.current = 0; return; }
    const r = track.getBoundingClientRect();
    const near = m && m.y >= r.top - NEAR && m.y <= r.bottom + NEAR;
    let target = 0;
    if (near) { const t = (m.x - r.left) / r.width; const v = t > 1 - EDGE ? Math.min(1, (t - (1 - EDGE)) / EDGE) : t < EDGE ? -Math.min(1, (EDGE - t) / EDGE) : 0; target = Math.sign(v) * Math.pow(Math.abs(v), 1.6) * SPEED; }
    if (performance.now() < glideUntil.current) { raf.current = requestAnimationFrame(tick); return; } // a dot click is gliding
    vel.current += (target - vel.current) * EASE;
    const before = pos.current;
    // Keep the expanded card fixed under the cursor while neighbours change width
    const a = anchor.current, card = list.children[iRef.current];
    if (card) { if (a && a.k === iRef.current) setPos(pos.current + (card.offsetLeft - a.left), false); anchor.current = { k: iRef.current, left: card.offsetLeft }; }
    setPos(pos.current + vel.current, false);
    const moved = Math.abs(pos.current - before);
    // Only switch cards once the row has nearly settled, so cards don't flicker open as they slide past
    if (near && moved < 3) { const hit = document.elementFromPoint(m.x, m.y)?.closest('.icar-card'); if (hit && list.contains(hit)) activate(+hit.dataset.k); }
    if (!near && Math.abs(vel.current) < 0.1) { vel.current = 0; anchor.current = null; raf.current = 0; return; }
    raf.current = requestAnimationFrame(tick);
  };
  React.useEffect(() => {
    const move = e => { if (e.pointerType !== 'mouse') return; mouse.current = { x: e.clientX, y: e.clientY }; if (!raf.current) raf.current = requestAnimationFrame(tick); };
    const out = e => { if (!e.relatedTarget) mouse.current = null; };
    window.addEventListener('pointermove', move, { passive: true }); document.addEventListener('pointerout', out);
    return () => { window.removeEventListener('pointermove', move); document.removeEventListener('pointerout', out); cancelAnimationFrame(raf.current); };
  }, []);
  const onKey = e => { if (e.key === 'ArrowRight') { e.preventDefault(); focusTo(i + 1); } if (e.key === 'ArrowLeft') { e.preventDefault(); focusTo(i - 1); } };
  // Touch: swipe to step through cards
  const down = e => { if (e.pointerType !== 'mouse') drag.current = e.clientX; };
  const up = e => { if (drag.current == null) return; const dx = e.clientX - drag.current; drag.current = null; if (Math.abs(dx) > 50) { focusTo(i + (dx < 0 ? 1 : -1)); drag.current = 'moved'; } };
  const pick = (k, e) => { if (drag.current === 'moved') { drag.current = null; return; } if (k !== i) { e.preventDefault(); focusTo(k); } };
  return <div className="icar" role="region" aria-roledescription="carousel" aria-label="Industry demo lines" onKeyDown={onKey} style={{ '--w': w + 'px', '--wa': wa + 'px', '--gap': gap + 'px' }}>
    <div className="icar-track" ref={trackRef} onPointerDown={down} onPointerUp={up} onPointerLeave={() => { drag.current = null; }}>
      <ul className="icar-list" ref={listRef}>
        {INDUSTRIES.map((it, k) => { const [biz, num] = it.demo; const on = k === i; const title = it.alt ? "Don't see your industry?" : it.name; const who = it.alt ? 'a general business' : biz; return <li key={it.key} data-k={k} className={'icar-card on-navy' + (on ? ' is-active' : '') + (it.alt ? ' is-alt' : '')} aria-roledescription="slide" aria-label={`${k + 1} of ${n}: ${it.name}`} aria-current={on ? 'true' : undefined} onClick={e => pick(k, e)}>
          <div className="icar-top"><Tile icon={it.icon} size={48} /><div><h3>{title}</h3><p className="icar-biz">{it.alt ? 'Trained on any business type' : biz}</p></div></div>
          <p className="icar-preview" aria-hidden="true">“{it.chat[0]}”</p>
          <div className="icar-detail" aria-hidden={!on}>
            <div className="icar-chat" aria-label={'Sample call with ' + who}>{it.chat.map((line, j) => <div key={j} className="icar-msg" style={{ '--d': j }}><DS.ChatBubble from={j % 2 ? 'caller' : 'ai'}>{line}</DS.ChatBubble></div>)}</div>
            <ul className="checks">{it.bullets.map(b => <Check key={b}>{b}</Check>)}</ul>
          </div>
          <div className="icar-foot">
            <span className="icar-label caption">Live demo line, answers as {who}</span>
            <a className="icar-call" href={'tel:' + num.replace(/\D/g, '')} tabIndex={on ? 0 : -1} aria-label={'Call the ' + it.name.toLowerCase() + ' demo line, ' + num}><span className="icar-ic" aria-hidden="true"><DS.Icon name="Phone" size={16} /></span><span className="num">{num}</span></a>
          </div>
        </li>; })}
      </ul>
    </div>
    <div className="icar-dots">{INDUSTRIES.map((it, k) => <button key={it.key} type="button" className={'icar-dot' + (k === i ? ' on' : '')} onClick={() => focusTo(k)} aria-label={'Show ' + it.name} aria-pressed={k === i}></button>)}</div>
  </div>;
}
Object.assign(window, { Industries, DemoLines, IndustryCarousel });