const hcCell = { padding: '6px 10px', borderTop: '1px solid #EEF1F7', font: '400 12px/1.3 var(--font-body)', color: 'var(--yk-charcoal)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' };
const hcHead = { padding: '6px 10px', font: '500 11px/1.3 var(--font-body)', color: 'var(--text-muted)', textAlign: 'left', whiteSpace: 'nowrap', background: '#FAFBFE', overflow: 'hidden', textOverflow: 'ellipsis', maxWidth: 0 };
const hcPanel = { border: '1px solid var(--border-default)', borderRadius: 8, background: '#fff', minWidth: 0 };

function Waveform({ bars = 28, height = 36 }) {
  return (
    <div style={{ display: 'flex', alignItems: 'center', gap: 2, height, flex: 'none' }} aria-hidden>
      {Array.from({ length: bars }).map((_, i) => (
        <span key={i} style={{ width: 2.5, height: height * (0.35 + 0.65 * Math.abs(Math.sin(i * 1.7))), borderRadius: 2, background: i % 3 === 0 ? 'var(--yk-violet)' : 'var(--yk-sky)', animation: `yk-wave ${0.8 + (i % 5) * 0.15}s ease-in-out ${(i % 7) * 0.09}s infinite` }} />
      ))}
    </div>
  );
}

function Spark({ data, color = '#06B6D4', w = 64, h = 20 }) {
  const mx = Math.max(...data), mn = Math.min(...data);
  const p = data.map((v, i) => `${(i / (data.length - 1)) * w},${h - 2 - ((v - mn) / (mx - mn || 1)) * (h - 4)}`).join(' ');
  return <svg width={w} height={h} style={{ display: 'block', flex: 'none' }} aria-hidden><polyline points={p} fill="none" stroke={color} strokeWidth="1.5" /></svg>;
}

function useTicker(ms, on = true) {
  const [t, setT] = React.useState(0);
  React.useEffect(() => { if (!on) return; const i = setInterval(() => setT((x) => x + 1), ms); return () => clearInterval(i); }, [ms, on]);
  return t;
}

/* ---------- Software: service overview ---------- */
function ConsoleSoftware() {
  const { Badge } = DS;
  const t = useTicker(1600);
  const narrow = useMedia('(max-width: 560px)');
  const base = [148, 152, 160, 171, 158, 149, 162, 188, 176, 165, 158, 151, 147, 155, 163, 170, 166, 159, 154, 150, 158, 166, 174, 169];
  const p95 = base.map((_, i) => base[(i + t) % base.length]);
  const p50 = p95.map((v, i) => Math.round(v * 0.42 + ((i * 7) % 9)));
  const W = 100, H = 100, max = 220;
  const line = (arr) => arr.map((v, i) => `${(i / (arr.length - 1)) * W},${H - (v / max) * H}`).join(' ');
  const rpm = 1284 + ((t * 37) % 60) - 30;
  const kpis = [['Requests / min', rpm.toLocaleString(), [9, 11, 10, 12, 13, 12, 14, 13], '#7C3AED'], ['p95 latency', `${p95[p95.length - 1]} ms`, p95.slice(-8), '#06B6D4'], ['Error rate', '0.12%', [3, 2, 4, 2, 1, 2, 1, 1], '#059669'], ['Uptime · 30d', '99.98%', [5, 5, 5, 4, 5, 5, 5, 5], '#059669']];
  const eps = [['POST', '/v1/orders', '412', '184 ms', '0.0%', 'success'], ['GET', '/v1/orders/:id', '588', '62 ms', '0.0%', 'success'], ['POST', '/hooks/crm.deal', '96', '231 ms', '0.4%', 'success'], ['POST', '/hooks/billing', '41', '1.9 s', '2.1%', 'warning']];
  return (
    <div style={{ display: 'grid', gap: 10 }}>
      <div style={{ display: 'grid', gridTemplateColumns: narrow ? 'repeat(2, minmax(0,1fr))' : 'repeat(4, minmax(0,1fr))', gap: 8 }}>
        {kpis.map(([k, v, d, c]) => (
          <div key={k} style={{ ...hcPanel, padding: '8px 10px' }}>
            <div style={{ font: '500 11px var(--font-body)', color: 'var(--text-muted)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{k}</div>
            <div style={{ display: 'flex', alignItems: 'flex-end', justifyContent: 'space-between', gap: 6, marginTop: 4 }}>
              <span style={{ font: '600 16px var(--font-display)', color: 'var(--yk-indigo)', letterSpacing: '-.01em', whiteSpace: 'nowrap' }}>{v}</span>
              <Spark data={d} color={c} w={40} h={18} />
            </div>
          </div>
        ))}
      </div>
      <div style={{ ...hcPanel, padding: '10px 12px' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 12, marginBottom: 8 }}>
          <span style={{ font: '600 12px var(--font-body)', color: 'var(--yk-indigo)' }}>Latency</span>
          <span style={{ display: 'inline-flex', alignItems: 'center', gap: 5, font: '400 11px var(--font-body)', color: 'var(--text-muted)' }}><span style={{ width: 10, height: 2, background: '#06B6D4' }} />p95</span>
          <span style={{ display: 'inline-flex', alignItems: 'center', gap: 5, font: '400 11px var(--font-body)', color: 'var(--text-muted)' }}><span style={{ width: 10, height: 2, background: '#7C3AED' }} />p50</span>
          <span style={{ flex: 1 }} /><MonoLabel>last 60 min · 15s buckets</MonoLabel>
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: '34px 1fr', gap: 4 }}>
          <div style={{ display: 'flex', flexDirection: 'column', justifyContent: 'space-between', height: 72 }}>{['200ms', '100ms', '0'].map((l) => <MonoLabel key={l} style={{ fontSize: 10, textAlign: 'right' }}>{l}</MonoLabel>)}</div>
          <div>
            <svg viewBox="0 0 100 100" preserveAspectRatio="none" width="100%" height="72" style={{ display: 'block' }}>
              {[9, 54.5, 100].map((y) => <line key={y} x1="0" x2="100" y1={y} y2={y} stroke="#EEF1F7" vectorEffect="non-scaling-stroke" />)}
              <polygon points={`0,100 ${line(p95)} 100,100`} fill="rgba(6,182,212,.07)" />
              <polyline points={line(p95)} fill="none" stroke="#06B6D4" strokeWidth="1.75" vectorEffect="non-scaling-stroke" />
              <polyline points={line(p50)} fill="none" stroke="#7C3AED" strokeWidth="1.5" vectorEffect="non-scaling-stroke" />
            </svg>
            <div style={{ display: 'flex', justifyContent: 'space-between', marginTop: 4 }}>{['13:05', '13:20', '13:35', '13:50', 'now'].map((l) => <MonoLabel key={l} style={{ fontSize: 10 }}>{l}</MonoLabel>)}</div>
          </div>
        </div>
      </div>
      <div style={{ ...hcPanel, overflow: 'hidden' }}>
        <table style={{ width: '100%', borderCollapse: 'collapse', tableLayout: 'fixed' }}>
          <colgroup><col style={{ width: narrow ? 56 : 68 }} /><col /><col style={{ width: narrow ? 40 : 52 }} /><col style={{ width: narrow ? 52 : 62 }} /><col style={{ width: narrow ? 44 : 58 }} /></colgroup>
          <thead><tr>{['Method', 'Endpoint', 'RPM', 'p95', 'Errors'].map((h) => <th key={h} style={hcHead}>{h}</th>)}</tr></thead>
          <tbody>{eps.map(([m, e, r, p, er, tone]) => (
            <tr key={e}><td style={hcCell}><Badge size="sm" mono tone={m === 'GET' ? 'sky' : 'violet'}>{m}</Badge></td><td style={{ ...hcCell, fontFamily: 'var(--font-mono)', fontSize: 11.5, color: 'var(--yk-indigo)' }}>{e}</td><td style={{ ...hcCell, fontFamily: 'var(--font-mono)', fontSize: 11.5 }}>{r}</td><td style={{ ...hcCell, fontFamily: 'var(--font-mono)', fontSize: 11.5 }}>{p}</td><td style={{ ...hcCell, fontFamily: 'var(--font-mono)', fontSize: 11.5, color: tone === 'warning' ? 'var(--yk-warning)' : 'var(--yk-charcoal)' }}>{er}</td></tr>
          ))}</tbody>
        </table>
      </div>
    </div>
  );
}

/* ---------- Voice: live call console ---------- */
const VOICE_LINES = [
  ['00:02', 'Agent', 'Thanks for calling Northwind Freight. Is this about a new shipment or an existing one?'],
  ['00:07', 'Caller', 'New one. Three pallets, Pune to Chennai, next Tuesday.'],
  ['00:14', 'Agent', 'Noted. Do the pallets need temperature control?'],
  ['00:18', 'Caller', 'No, dry goods. I just need a price today.'],
  ['00:23', 'Agent', 'I\u2019ll connect you to sales and send the details to WhatsApp on this number.'],
];
const VOICE_FIELDS = [['Intent', 'New shipment', 1], ['Load', '3 pallets · dry', 3], ['Route', 'Pune \u2192 Chennai', 1], ['Pickup', 'Tue, 14 Oct', 1], ['Priority', 'Quote today', 3]];

function ConsoleVoice() {
  const { Badge, Button, Icon } = DS;
  const narrow = useMedia('(max-width: 560px)');
  const [n, setN] = React.useState(1);
  const [handoff, setHandoff] = React.useState(false);
  React.useEffect(() => { if (n >= VOICE_LINES.length) return; const t = setTimeout(() => setN(n + 1), 1500); return () => clearTimeout(t); }, [n]);
  const calls = [['Ravi K.', 'Live · 00:' + String(18 + n * 3).padStart(2, '0'), 'sky', true], ['Meera S.', 'Booked · 2m', 'success'], ['+91 70•• 2291', 'Handed off · 6m', 'violet'], ['Arjun P.', 'Voicemail · 11m', 'neutral']];
  return (
    <div style={{ display: 'grid', gridTemplateColumns: narrow ? 'minmax(0,1fr)' : '132px minmax(0,1fr)', gap: 10, height: '100%' }}>
      <div style={{ ...hcPanel, overflow: 'hidden', alignSelf: 'stretch', display: narrow ? 'flex' : undefined, overflowX: narrow ? 'auto' : undefined, scrollbarWidth: narrow ? 'none' : undefined }}>
        <div style={{ ...hcHead, borderBottom: '1px solid #EEF1F7' }}>Calls today · 38</div>
        {calls.map(([who, st, tone, live], i) => (
          <div key={who} style={{ padding: '8px 10px', borderTop: i ? '1px solid #EEF1F7' : 0, background: live ? 'var(--yk-violet-50)' : '#fff', boxShadow: live ? 'inset 2px 0 0 var(--yk-violet)' : 'none' }}>
            <div style={{ font: '600 12px var(--font-body)', color: 'var(--yk-indigo)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{who}</div>
            <div style={{ display: 'flex', alignItems: 'center', gap: 5, marginTop: 3 }}><span style={{ width: 6, height: 6, borderRadius: '50%', background: { sky: 'var(--yk-sky)', success: 'var(--yk-success)', violet: 'var(--yk-violet)', neutral: 'var(--yk-slate-400)' }[tone], animation: live ? 'yk-pulse 1.6s infinite' : 'none' }} /><MonoLabel style={{ fontSize: 10.5, whiteSpace: 'nowrap' }}>{st}</MonoLabel></div>
          </div>
        ))}
      </div>
      <div style={{ display: 'grid', gridTemplateRows: 'auto 1fr auto', gap: 8, minWidth: 0 }}>
        <div style={{ ...hcPanel, display: 'flex', alignItems: 'center', gap: 10, padding: '8px 10px' }}>
          <span style={{ width: 28, height: 28, borderRadius: 7, background: 'var(--yk-light)', display: 'grid', placeItems: 'center', color: 'var(--yk-violet)', flex: 'none' }}><Icon name="phone-incoming" size={15} /></span>
          <div style={{ minWidth: 0, flex: 1 }}>
            <div style={{ font: '600 12.5px var(--font-body)', color: 'var(--yk-indigo)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>Ravi Kumar · +91 98•• ••4410</div>
            <MonoLabel style={{ fontSize: 10.5, display: 'block', overflow: 'hidden', textOverflow: 'ellipsis' }}>Inbound · Sales line · Voice agent v3</MonoLabel>
          </div>
          <span style={{ flex: 'none', display: 'inline-flex' }}><Waveform bars={narrow ? 10 : 16} height={22} /></span>
        </div>
        <div style={{ ...hcPanel, padding: '8px 10px', display: 'flex', flexDirection: 'column', gap: 6, overflow: 'hidden', minHeight: 0 }}>
          {VOICE_LINES.slice(0, n).map(([ts, who, t], i) => (
            <div key={i} style={{ display: 'grid', gridTemplateColumns: narrow ? '30px 40px minmax(0,1fr)' : '34px 44px 1fr', gap: 6, animation: 'yk-fade-up .35s cubic-bezier(.22,1,.36,1) both' }}>
              <MonoLabel style={{ fontSize: 10.5, color: 'var(--text-subtle)' }}>{ts}</MonoLabel>
              <MonoLabel style={{ fontSize: 10.5 }} color={who === 'Agent' ? 'var(--yk-violet)' : 'var(--yk-indigo)'}>{who}</MonoLabel>
              <span style={{ font: '400 12px/1.45 var(--font-body)', color: 'var(--yk-charcoal)' }}>{t}</span>
            </div>
          ))}
        </div>
        <div style={{ ...hcPanel, padding: '8px 10px' }}>
          <div style={{ display: 'grid', gridTemplateColumns: narrow ? 'repeat(3, minmax(0,1fr))' : 'repeat(5, minmax(0,1fr))', gap: 6, marginBottom: 8 }}>
            {VOICE_FIELDS.map(([k, v, at]) => (
              <div key={k} style={{ minWidth: 0 }}>
                <div style={{ font: '500 10.5px var(--font-body)', color: 'var(--text-muted)' }}>{k}</div>
                <div style={{ font: '500 11.5px var(--font-body)', color: n >= at + 1 ? 'var(--yk-indigo)' : 'var(--text-subtle)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', transition: 'color .3s' }}>{n >= at + 1 ? v : '\u2014'}</div>
              </div>
            ))}
          </div>
          <div style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
            <Badge size="sm" tone={n >= 5 ? 'success' : 'neutral'} icon="message-circle">{n >= 5 ? 'WhatsApp summary sent' : 'WhatsApp summary queued'}</Badge>
            <span style={{ flex: 1 }} />
            <Button size="sm" variant={handoff ? 'outline' : 'secondary'} iconLeft={handoff ? 'check' : 'user-round-check'} onClick={() => setHandoff(!handoff)}>{handoff ? 'Connected · Priya S.' : 'Warm handoff \u2192 Sales'}</Button>
          </div>
        </div>
      </div>
    </div>
  );
}

/* ---------- Ops: workflow run ---------- */
function ConsoleOps() {
  const { Badge, Button, Icon } = DS;
  const narrow = useMedia('(max-width: 560px)');
  const [stage, setStage] = React.useState(3);
  React.useEffect(() => { if (stage < 4 || stage >= 6) return; const t = setTimeout(() => setStage(stage + 1), 900); return () => clearTimeout(t); }, [stage]);
  const steps = [['Receive webhook', 'crm.deal.won · D-2291', '84 ms'], ['Validate fields', '12 / 12 passed', '210 ms'], ['Create ERP sales order', 'SO-55810 created', '1.24 s'], ['Manager approval', 'Discount 12% > 10% policy', null], ['Generate ops report', 'Daily dispatch sheet', '640 ms'], ['Notify #ops-daily', 'Slack message posted', '190 ms']];
  const logs = ['14:02:11.204  webhook received  deal_id=D-2291', '14:02:11.418  validate  ok  fields=12', '14:02:12.661  erp.create  SO-55810  201', '14:02:12.702  approval.request  to=r.mehta  channel=slack'];
  if (stage >= 4) logs.push('14:06:40.115  approval.granted  by=r.mehta');
  if (stage >= 5) logs.push('14:06:40.761  report.generate  ok');
  if (stage >= 6) logs.push('14:06:40.954  slack.post  #ops-daily  ok');
  const status = (i) => (i < stage ? 'done' : i === stage && stage === 3 ? 'wait' : i === stage ? 'run' : 'todo');
  return (
    <div style={{ display: 'grid', gap: 8 }}>
      <div style={{ display: 'flex', alignItems: 'center', gap: 8, flexWrap: 'wrap' }}>
        <span style={{ font: '600 13px var(--font-mono)', color: 'var(--yk-indigo)' }}>deal-won-to-erp</span><MonoLabel>Run #4821</MonoLabel>
        <Badge size="sm" dot tone={stage >= 6 ? 'success' : stage === 3 ? 'warning' : 'sky'} pulse={stage !== 6}>{stage >= 6 ? 'Succeeded' : stage === 3 ? 'Waiting for approval' : 'Running'}</Badge>
        <span style={{ flex: 1 }} /><MonoLabel>trigger · webhook</MonoLabel>
      </div>
      <div style={{ ...hcPanel, overflow: 'hidden' }}>
        {steps.map(([t, d, dur], i) => {
          const s = status(i);
          return (
            <div key={t} style={{ display: 'grid', gridTemplateColumns: narrow ? (s === 'wait' ? '20px minmax(0,1fr)' : '20px minmax(0,1fr) auto') : '20px minmax(0,1fr) auto', gap: 10, alignItems: 'center', padding: '7px 10px', borderTop: i ? '1px solid #EEF1F7' : 0, background: s === 'wait' ? 'var(--yk-warning-bg)' : '#fff', transition: 'background .3s' }}>
              <span style={{ width: 18, height: 18, borderRadius: '50%', display: 'grid', placeItems: 'center', background: s === 'done' ? 'var(--yk-success)' : s === 'wait' ? '#F59E0B' : s === 'run' ? 'var(--yk-sky)' : '#fff', border: s === 'todo' ? '1.5px solid var(--border-strong)' : 0, color: '#fff' }}>
                {s === 'done' && <Icon name="check" size={11} strokeWidth={3} />}{s === 'wait' && <Icon name="pause" size={10} strokeWidth={3} />}{s === 'run' && <span style={{ width: 6, height: 6, borderRadius: '50%', background: '#fff', animation: 'yk-pulse 1s infinite' }} />}
              </span>
              <div style={{ minWidth: 0 }}>
                <div style={{ font: '600 12px var(--font-body)', color: s === 'todo' ? 'var(--text-muted)' : 'var(--yk-indigo)' }}>{t}</div>
                <div style={{ font: '400 11px var(--font-body)', color: 'var(--text-muted)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{d}</div>
              </div>
              {s === 'wait' ? <div style={{ display: 'flex', gap: 6, gridColumn: narrow ? '1 / -1' : undefined, marginLeft: narrow ? 30 : undefined }}><Button size="sm" iconLeft="check" onClick={() => setStage(4)} style={{ height: 28, padding: '0 10px', fontSize: 12 }}>Approve</Button><Button size="sm" variant="outline" style={{ height: 28, padding: '0 10px', fontSize: 12 }}>Reject</Button></div>
                : <MonoLabel style={{ fontSize: 10.5 }}>{s === 'done' ? (dur || '4m 28s') : s === 'run' ? 'running\u2026' : 'queued'}</MonoLabel>}
            </div>
          );
        })}
      </div>
      <div style={{ background: 'var(--surface-code)', borderRadius: 8, padding: '8px 10px', height: 74, overflow: 'hidden', display: 'flex', flexDirection: 'column', justifyContent: 'flex-end' }}>
        {logs.slice(-4).map((l) => <div key={l} style={{ font: '400 10.5px/1.6 var(--font-mono)', color: l.includes('approval.granted') ? '#6EE7B7' : '#C7C4F2', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{l}</div>)}
      </div>
    </div>
  );
}

/* ---------- Marketing: review queue ---------- */
const MKT_ITEMS = [
  { id: 0, icon: 'clapperboard', type: 'Reel', title: '“Every order typed twice” · 30s', owner: 'AI draft', body: '[0–3s] Hook: “Your dispatch team re-types every order.”\n[3–12s] Screen: WhatsApp order → CRM → WMS, no re-keying.\n[12–30s] CTA: Book a 20-minute workflow audit.' },
  { id: 1, icon: 'file-text', type: 'Blog', title: 'Why dispatch teams still re-key orders', owner: 'AI draft · 6 sources', body: 'H2: Where the second entry happens\nH2: What a sync layer changes\nH2: Approval rules worth keeping\nSources linked inline for fact-check.' },
  { id: 2, icon: 'image', type: 'Carousel', title: '5 handoffs that lose customer context', owner: 'Anika R.', body: 'Slide 1: Missed call → no callback\nSlide 2: Chat → email, history lost\nSlide 3: Rep change mid-deal\n…' },
  { id: 3, icon: 'mail', type: 'Email', title: 'Nurture #2 · warehouse ops leads', owner: 'AI draft', body: 'Subject: The 11-minute order\nBody: How one ops team cut re-entry by connecting their CRM and WMS…' },
  { id: 4, icon: 'message-square-text', type: 'Caption', title: 'LinkedIn · approval-gate explainer', owner: 'Dev P.', body: 'Agents act alone only above the threshold you set.\nEverything else goes to a person, with context.\n#operations #automation' },
];

function ConsoleMarketing() {
  const { Badge, Checkbox, Button, Icon } = DS;
  const narrow = useMedia('(max-width: 560px)');
  const [sel, setSel] = React.useState(0);
  const [checks, setChecks] = React.useState({ 0: [true, false, false], 1: [true, true, false], 2: [true, true, true], 3: [false, false, false], 4: [true, true, true] });
  const [approved, setApproved] = React.useState({ 2: true });
  const it = MKT_ITEMS[sel]; const c = checks[sel]; const all = c.every(Boolean);
  const st = (i) => (approved[i] ? ['success', 'Approved'] : checks[i].every(Boolean) ? ['sky', 'Ready'] : ['warning', 'In review']);
  return (
    <div style={{ display: 'grid', gap: 8 }}>
      <div style={{ ...hcPanel, overflow: 'hidden' }}>
        {MKT_ITEMS.map((m, i) => { const [tone, lab] = st(i); return (
          <button key={m.id} type="button" onClick={() => setSel(i)} style={{ width: '100%', display: 'grid', gridTemplateColumns: '22px 62px minmax(0,1fr) auto', gap: 8, alignItems: 'center', padding: '7px 10px', border: 0, borderTop: i ? '1px solid #EEF1F7' : 0, background: sel === i ? 'var(--yk-violet-50)' : '#fff', boxShadow: sel === i ? 'inset 2px 0 0 var(--yk-violet)' : 'none', cursor: 'pointer', textAlign: 'left' }}>
            <Icon name={m.icon} size={15} color="var(--yk-violet)" />
            <span style={{ font: '500 11px var(--font-body)', color: 'var(--text-muted)' }}>{m.type}</span>
            <span style={{ minWidth: 0 }}><span style={{ display: 'block', font: '600 12px var(--font-body)', color: 'var(--yk-indigo)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{m.title}</span></span>
            <Badge size="sm" dot tone={tone}>{lab}</Badge>
          </button>); })}
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: narrow ? 'minmax(0,1fr)' : 'minmax(0,1.15fr) minmax(0,1fr)', gap: 8 }}>
        <div style={{ ...hcPanel, padding: '8px 10px' }}>
          <div style={{ display: 'flex', justifyContent: 'space-between', gap: 6, marginBottom: 6 }}><span style={{ font: '600 12px var(--font-body)', color: 'var(--yk-indigo)' }}>Draft</span><MonoLabel style={{ fontSize: 10.5 }}>{it.owner}</MonoLabel></div>
          <div key={sel} style={{ font: '400 11px/1.6 var(--font-mono)', color: 'var(--yk-charcoal)', background: 'var(--yk-light)', borderRadius: 6, padding: '6px 8px', whiteSpace: 'pre-line', height: 126, overflow: 'hidden', animation: 'yk-fade-up .3s cubic-bezier(.22,1,.36,1) both' }}>{it.body}</div>
        </div>
        <div style={{ ...hcPanel, padding: '8px 10px', display: 'grid', gap: 6, alignContent: 'start', borderColor: approved[sel] ? '#A7F3D0' : 'var(--border-default)' }}>
          <span style={{ font: '600 12px var(--font-body)', color: approved[sel] ? 'var(--yk-success)' : 'var(--yk-warning)' }}>{approved[sel] ? 'Approved for publishing' : 'Human review required'}</span>
          {['Claims checked', 'Brand voice', 'Legal / offers'].map((l, i) => <Checkbox key={l} checked={c[i]} disabled={!!approved[sel]} onChange={(v) => setChecks({ ...checks, [sel]: c.map((x, j) => (j === i ? v : x)) })} label={<span style={{ fontSize: 12, fontWeight: 500, whiteSpace: 'nowrap' }}>{l}</span>} />)}
          <Button size="sm" disabled={!all || approved[sel]} onClick={() => setApproved({ ...approved, [sel]: true })} style={{ height: 28, fontSize: 12, marginTop: 2 }}>{approved[sel] ? 'Scheduled' : 'Approve'}</Button>
        </div>
      </div>
    </div>
  );
}

const CONSOLE_TABS = [
  { value: 'sw', label: 'Software', icon: 'code-xml', crumb: ['Northwind', 'orders-api', 'Overview'], env: 'production', C: ConsoleSoftware },
  { value: 'voice', label: 'Voice & Chat AI', icon: 'phone-call', crumb: ['Northwind', 'Agents', 'Live calls'], env: 'sales line', C: ConsoleVoice },
  { value: 'ops', label: 'Ops Sync', icon: 'workflow', crumb: ['Northwind', 'Workflows', 'deal-won-to-erp'], env: 'production', C: ConsoleOps },
  { value: 'mkt', label: 'Digital Marketing', icon: 'megaphone', crumb: ['Northwind', 'Digital Marketing', 'Review queue'], env: '4 pending', C: ConsoleMarketing },
];

function HeroConsole() {
  const { WindowFrame, Tabs, Icon } = DS;
  const [tab, setTab] = React.useState('sw');
  const [manual, setManual] = React.useState(false);
  const reduced = useReducedMotion();
  const narrow = useMedia('(max-width: 560px)');
  React.useEffect(() => {
    if (manual || reduced) return;
    const t = setInterval(() => setTab((v) => CONSOLE_TABS[(CONSOLE_TABS.findIndex((x) => x.value === v) + 1) % CONSOLE_TABS.length].value), 6000);
    return () => clearInterval(t);
  }, [manual, reduced]);
  const pick = (v) => { setManual(true); setTab(v); };
  const cur = CONSOLE_TABS.find((t) => t.value === tab);
  return (
    <WindowFrame title={`app.northwind.in/${cur.crumb.slice(1).join('/').toLowerCase().replace(/ /g, '-')}`} status="Live" bodyStyle={{ padding: 0 }}>
      <div style={{ padding: '10px 12px', borderBottom: '1px solid var(--border-default)' }}>
        <Tabs size="sm" value={tab} onChange={pick} tabs={CONSOLE_TABS} style={{ width: '100%' }} />
      </div>
      <div style={{ display: 'grid', gridTemplateColumns: narrow ? 'minmax(0,1fr)' : '44px minmax(0,1fr)', height: narrow ? 'auto' : 440 }}>
        {!narrow && <div style={{ borderRight: '1px solid var(--border-default)', background: '#FAFBFE', display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4, padding: '10px 0' }}>
          {CONSOLE_TABS.map((t) => <button key={t.value} type="button" aria-label={t.label} onClick={() => pick(t.value)} style={{ width: 30, height: 30, borderRadius: 7, border: 0, display: 'grid', placeItems: 'center', cursor: 'pointer', background: t.value === tab ? 'var(--yk-lavender)' : 'transparent', color: t.value === tab ? 'var(--yk-violet)' : 'var(--yk-slate-500)' }}><Icon name={t.icon} size={16} /></button>)}
          <span style={{ flex: 1 }} />
          {['search', 'settings'].map((i) => <span key={i} style={{ width: 30, height: 30, display: 'grid', placeItems: 'center', color: 'var(--yk-slate-400)' }}><Icon name={i} size={16} /></span>)}
        </div>}
        <div style={{ display: 'grid', gridTemplateRows: 'auto 1fr', minWidth: 0, minHeight: 0 }}>
          <div style={{ display: 'flex', alignItems: 'center', gap: 6, padding: '8px 12px', borderBottom: '1px solid #EEF1F7' }}>
            <span style={{ display: 'flex', alignItems: 'center', gap: 6, minWidth: 0, overflow: 'hidden' }}>{cur.crumb.map((c, i) => <React.Fragment key={c}>{i > 0 && <Icon name="chevron-right" size={12} color="var(--yk-slate-400)" style={{ flex: 'none' }} />}<span style={{ font: `${i === cur.crumb.length - 1 ? 600 : 500} 12px var(--font-body)`, color: i === cur.crumb.length - 1 ? 'var(--yk-indigo)' : 'var(--text-muted)', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis' }}>{c}</span></React.Fragment>)}</span>
            <span style={{ flex: 1 }} />
            {!narrow && <span style={{ font: '500 11px var(--font-mono)', color: 'var(--text-muted)', border: '1px solid var(--border-default)', borderRadius: 5, padding: '2px 6px', whiteSpace: 'nowrap' }}>{cur.env}</span>}
            <span style={{ width: 22, height: 22, borderRadius: '50%', background: 'var(--yk-indigo)', color: '#fff', display: 'grid', placeItems: 'center', font: '600 10px var(--font-body)', flex: 'none' }}>RM</span>
          </div>
          <div key={tab} style={{ padding: 12, minHeight: 0, overflow: 'hidden', animation: 'yk-fade-up .4s cubic-bezier(.22,1,.36,1) both' }}><cur.C /></div>
        </div>
      </div>
    </WindowFrame>
  );
}

Object.assign(window, { HeroConsole, Waveform });
