// The "chat IS the product" section — paired chat demo + 3 principles
// + competitor comparison strip + role-tabbed use cases.

const { useState: useStateNs, useEffect: useEffectNs } = React;

/* ------------------------------------------------------------- *
   THE CHAT IS THE PRODUCT
 * ------------------------------------------------------------- */
function ChatSection() {
  return (
    <section className="chat-section" id="chat">
      <div className="container">
        <div className="chat-section-head">
          <div className="eyebrow">The chat is the product</div>
          <h2 className="chat-section-title">
            Drop anything in.<br/>
            <em>Finished work comes out.</em>
          </h2>
        </div>

        <div className="chat-section-grid">
          <div className="chat-section-chat">
            <AnimatedChat tall />
          </div>

          <div className="chat-section-rules">
            <article className="rule">
              <div className="rule-num">i.</div>
              <div className="rule-body">
                <h3>Speaks chat, not API.</h3>
                <p>
                  A voice note. A photo. A panicked &ldquo;is this working?&rdquo; — Octodus
                  replies like a coworker who already knows the project.
                </p>
              </div>
            </article>
            <article className="rule">
              <div className="rule-num">ii.</div>
              <div className="rule-body">
                <h3>Remembers your rules.</h3>
                <p>
                  &ldquo;Draft, wait for OK, then publish.&rdquo; Once learned, never repeated.
                  Every team keeps its own brain.
                </p>
              </div>
            </article>
            <article className="rule">
              <div className="rule-num">iii.</div>
              <div className="rule-body">
                <h3>Takes action, not notes.</h3>
                <p>
                  Ships scripts, files tasks, schedules briefings, verifies its own
                  bug fixes — and shows you the receipts.
                </p>
              </div>
            </article>

            <div className="rule-footer">
              <span className="eyebrow">Now watching</span>
              <span>3 real chat scenes from real users →</span>
            </div>
          </div>
        </div>
      </div>

      <style>{`
        .chat-section {
          padding: 140px 0 120px;
          position: relative;
        }
        .chat-section::before {
          content: ""; position: absolute; inset: 0;
          background: radial-gradient(ellipse 60% 50% at 70% 40%, var(--accent-tint-06), transparent 70%);
          pointer-events: none;
        }
        .chat-section-head { max-width: 720px; margin-bottom: 64px; }
        .chat-section-title {
          font-size: clamp(2.6rem, 5vw, 4.4rem);
          line-height: 0.95;
          letter-spacing: -0.045em;
          margin-top: 14px;
        }
        .chat-section-title em {
          font-style: normal;
          background: linear-gradient(120deg, var(--accent-light), var(--accent));
          -webkit-background-clip: text; background-clip: text; color: transparent;
        }

        .chat-section-grid {
          display: grid;
          grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
          gap: 64px;
          align-items: center;
          position: relative;
          z-index: 1;
        }
        @media (max-width: 1000px) {
          .chat-section-grid { grid-template-columns: 1fr; gap: 56px; }
        }

        .rule {
          padding: 22px 0;
          border-bottom: 1px dashed var(--border);
          display: grid;
          grid-template-columns: 56px 1fr;
          gap: 16px;
          align-items: baseline;
        }
        .rule:first-child { padding-top: 0; }
        .rule:last-of-type { border-bottom: none; padding-bottom: 12px; }
        .rule-num {
          font-family: var(--font-heading);
          font-size: 28px;
          font-style: italic;
          font-weight: 600;
          color: var(--accent-light);
          letter-spacing: -0.02em;
        }
        .rule-body { min-width: 0; }
        .rule h3 {
          font-size: clamp(1.4rem, 2vw, 1.8rem);
          line-height: 1.2;
          letter-spacing: -0.025em;
          margin-bottom: 10px;
          color: var(--text);
        }
        .rule p {
          font-size: 15px;
          line-height: 1.6;
          color: var(--text-secondary);
          max-width: 460px;
        }
        .rule-footer {
          margin-top: 28px;
          padding-top: 22px;
          border-top: 1px solid var(--border);
          display: flex; align-items: center; gap: 14px;
          font-family: var(--font-mono);
          font-size: 12px;
          color: var(--text-muted);
        }
      `}</style>
    </section>
  );
}

/* ------------------------------------------------------------- *
   COMPETITOR COMPARISON STRIP
 * ------------------------------------------------------------- */
const COMPETITORS = [
  {
    name: 'ChatGPT',
    label: 'A.I.',
    role: 'You ask. It answers.',
    miss: 'But it doesn\u2019t live in your chat. Doesn\u2019t remember your team\u2019s rules. Doesn\u2019t ship work without you copy-pasting it.',
    color: '#5fb494',
  },
  {
    name: 'Slack AI',
    label: 'A.I. in Slack',
    role: 'Summarises threads.',
    miss: 'But only inside Slack \u2014 if your team isn\u2019t there yet, neither is the AI. And summarising is not shipping.',
    color: '#4a154b',
  },
  {
    name: 'Notion AI',
    label: 'A.I. in docs',
    role: 'Writes in your docs.',
    miss: 'But only inside Notion. And only if someone opens Notion. Your team is in Telegram.',
    color: '#a78bfa',
  },
  {
    name: 'Zapier',
    label: 'No A.I.',
    role: 'If this, then that.',
    miss: 'But every &ldquo;if&rdquo; needs a human to wire. &ldquo;Context&rdquo; isn\u2019t a trigger.',
    color: '#fb7185',
  },
  {
    name: 'A junior hire',
    label: 'Human',
    role: 'Actually does work.',
    miss: 'But costs 50× more, sleeps, asks the same question twice, and quits.',
    color: '#fbbf24',
  },
];

function Compare() {
  return (
    <section className="compare" id="compare">
      <div className="container">
        <div className="compare-head">
          <div className="eyebrow">The receipts</div>
          <h2 className="compare-title">
            You&apos;ve tried the AI tools.<br/>
            <em>The work is still there.</em>
          </h2>
          <p className="compare-sub">
            Most AI is a parlor trick: clever answers, no shipped work. Octodus is the
            opposite. It is the thing that actually does the thing.
          </p>
        </div>

        <div className="compare-grid">
          {COMPETITORS.map((c) => (
            <article className="compare-card" key={c.name} style={{ '--c-tint': c.color }}>
              <header className="compare-card-head">
                <h3 className="compare-name">{c.name}</h3>
                <span className="compare-label">{c.label}</span>
              </header>
              <div className="compare-role">{c.role}</div>
              <div className="compare-miss" dangerouslySetInnerHTML={{ __html: c.miss }} />
              <div className="compare-bar">
                <div className="compare-bar-fill" />
                <div className="compare-bar-label">does <em>some</em> of it</div>
              </div>
            </article>
          ))}

          {/* Octodus card — the answer */}
          <article className="compare-card compare-card-us">
            <div className="compare-us-bg" />
            <header className="compare-card-head">
              <h3 className="compare-name compare-name-us">
                <OctodusLogo size={18} /> octodus
              </h3>
              <span className="compare-label compare-label-us">A.I. + action</span>
            </header>
            <div className="compare-role compare-role-us">
              Lives in your chat. Ships actual work.
            </div>
            <div className="compare-miss compare-miss-us">
              Reads context. Decides. Acts. Posts receipts — inside the chat your team
              already lives in. Not yet another tool to wire up.
            </div>
            <div className="compare-bar compare-bar-us">
              <div className="compare-bar-fill compare-bar-fill-us" />
              <div className="compare-bar-label compare-bar-label-us">does the whole job</div>
            </div>
          </article>
        </div>
      </div>

      <style>{`
        .compare {
          padding: 140px 0;
          position: relative;
          background: var(--bg-deep);
        }
        .compare-head { max-width: 760px; margin-bottom: 64px; }
        .compare-title {
          font-size: clamp(2.6rem, 5vw, 4.4rem);
          line-height: 0.95;
          letter-spacing: -0.045em;
          margin: 14px 0 22px;
        }
        .compare-title em {
          font-style: normal;
          background: linear-gradient(120deg, var(--accent-light), var(--accent));
          -webkit-background-clip: text; background-clip: text; color: transparent;
        }
        .compare-sub {
          font-size: 17px;
          color: var(--text-secondary);
          line-height: 1.6;
          max-width: 600px;
        }

        .compare-grid {
          display: grid;
          grid-template-columns: repeat(6, 1fr);
          gap: 12px;
        }
        @media (max-width: 1200px) { .compare-grid { grid-template-columns: repeat(3, 1fr); } }
        @media (max-width: 760px) { .compare-grid { grid-template-columns: repeat(2, 1fr); } }
        @media (max-width: 460px) { .compare-grid { grid-template-columns: 1fr; } }

        .compare-card {
          position: relative;
          padding: 24px 22px 22px;
          border-radius: 18px;
          background: var(--bg-card);
          border: 1px solid var(--border);
          display: flex; flex-direction: column;
          min-height: 280px;
          overflow: hidden;
        }
        .compare-card-head {
          display: flex; justify-content: space-between; align-items: baseline;
          margin-bottom: 16px;
        }
        .compare-name {
          font-size: 17px;
          font-weight: 700;
          letter-spacing: -0.01em;
          color: var(--text-secondary);
        }
        .compare-label {
          font-family: var(--font-mono);
          font-size: 9.5px;
          letter-spacing: 0.18em;
          text-transform: uppercase;
          color: var(--text-muted);
          padding: 3px 7px;
          border-radius: 999px;
          border: 1px solid var(--border);
        }
        .compare-role {
          font-size: 15px;
          color: var(--text);
          font-weight: 500;
          margin-bottom: 12px;
        }
        .compare-miss {
          font-size: 13.5px;
          color: var(--text-muted);
          line-height: 1.55;
          flex: 1;
        }
        .compare-bar {
          margin-top: 18px;
          padding-top: 14px;
          border-top: 1px dashed var(--border);
        }
        .compare-bar-fill {
          height: 5px;
          border-radius: 999px;
          background: linear-gradient(90deg, var(--c-tint) 0%, transparent 100%);
          width: 35%;
          margin-bottom: 8px;
          opacity: 0.6;
        }
        .compare-bar-label {
          font-family: var(--font-mono);
          font-size: 10.5px;
          letter-spacing: 0.12em;
          text-transform: uppercase;
          color: var(--text-muted);
        }
        .compare-bar-label em {
          font-style: italic;
          color: var(--c-tint);
        }

        /* Octodus card */
        .compare-card-us {
          background: linear-gradient(180deg, var(--accent-tint-10), var(--bg-card) 80%);
          border-color: var(--accent-tint-40);
          box-shadow: 0 0 0 1px var(--accent-tint-15), 0 30px 80px -30px var(--accent-tint-50);
          grid-column: span 1;
        }
        .compare-us-bg {
          position: absolute; inset: -1px;
          border-radius: 18px; padding: 1px;
          background: linear-gradient(135deg, var(--accent-tint-60), transparent 60%);
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask-composite: exclude;
          -webkit-mask-composite: xor;
          pointer-events: none;
        }
        .compare-name-us {
          display: flex; align-items: center; gap: 6px;
          color: var(--text);
        }
        .compare-label-us {
          background: var(--accent);
          color: var(--on-accent);
          border-color: var(--accent);
        }
        .compare-role-us { color: var(--accent-light); font-weight: 600; }
        .compare-miss-us { color: var(--text); }
        .compare-bar-fill-us {
          width: 100%;
          background: linear-gradient(90deg, var(--accent-light), var(--accent));
          opacity: 1;
          box-shadow: 0 0 12px var(--accent-tint-40);
        }
        .compare-bar-label-us em {
          color: var(--accent-light);
          font-style: normal;
          font-weight: 700;
        }
      `}</style>
    </section>
  );
}

/* ------------------------------------------------------------- *
   ROLE TABS — "Built for…"
 * ------------------------------------------------------------- */
const ROLES = [
  {
    id: 'creator',
    label: 'Solo creators',
    headline: 'Ship a product on the weekend.\nLaunch on Monday.',
    sub: 'You are the founder, designer, dev, marketer. Octodus is the team you can\u2019t afford yet.',
    icon: 'code',
    bullets: [
      ['Voice note → 112 dev-ready prompts', 'Like Michael, who shipped 6 Gumroad plugins'],
      ['Photo → published blog post + Telegram caption', 'Cover image auto-generated'],
      ['One subscription. No team to manage.', '$50 flat. $15 credits to start.'],
      ['Works while you sleep.', 'Wakes up: "ran the cleanup at 3:14 AM."'],
    ],
    tint: 'var(--t-code)',
  },
  {
    id: 'agency',
    label: 'Agencies',
    headline: 'Run 10+ clients.\nDouble delivery. Same headcount.',
    sub: 'Octodus is your junior team. Content pipelines, SEO blogs, design loops — across every client at once.',
    icon: 'pen',
    bullets: [
      ['Concurrent content pipelines', 'Each client gets its own memory & rules'],
      ['Design iteration in chat', '16 revisions in one evening, like Maya\u2019s pageant banner'],
      ['Blog SEO + social posts', 'Drafted, waits for OK, then publishes — automatically'],
      ['Senior-quality output.', 'You charge senior rates without a senior team.'],
    ],
    tint: 'var(--t-design)',
  },
  {
    id: 'eng',
    label: 'Engineers',
    headline: 'Stop watching dashboards.\nGet receipts in chat.',
    sub: 'Octodus reads logs, diagnoses, drafts the script, runs it, sets the TTLs, and posts the before/after.',
    icon: 'gear',
    bullets: [
      ['Self-healing infra', 'Like Dan: 27 GB → 124 MB at 3:14 AM'],
      ['DNS diagnostics that don\u2019t give up', 'Step-by-step until it\u2019s really working'],
      ['Plays well with your stack', 'OAuth-only integrations. No data lock-in.'],
      ['End-to-end task automation', 'Application form → CV tailored → PDF → OTP → submitted'],
    ],
    tint: 'var(--t-auto)',
  },
  {
    id: 'ops',
    label: 'Ops & programs',
    headline: 'Five orgs. One deadline.\nNo project manager.',
    sub: 'Pre-call briefings, paperwork chasing, schedule alignment — all from chat mentions and dropped docs.',
    icon: 'calendar',
    bullets: [
      ['Coordinate across organizations', 'Like Ana: $240K grant across 5 partners'],
      ['Pre-call briefs at 17:00 sharp', 'Reads the doc, makes the brief, reminds the team'],
      ['Lead hand-off without dropped balls', 'Recognises urgency, files the task, writes the follow-up'],
      ['No new tools to adopt.', 'It lives where the conversation already lives.'],
    ],
    tint: 'var(--t-plan)',
  },
];

function RoleTabs({ initialRoleId } = {}) {
  const defaultId = ROLES.find((r) => r.id === initialRoleId) ? initialRoleId : ROLES[0].id;
  const [active, setActive] = useStateNs(defaultId);
  const role = ROLES.find((r) => r.id === active);

  return (
    <section className="roles" id="roles">
      <div className="container">
        <div className="roles-head">
          <div className="eyebrow">Built for</div>
          <h2 className="roles-title">
            Whatever the role,<br/>
            <em>same teammate.</em>
          </h2>
        </div>

        {/* Tab bar */}
        <div className="roles-tabs" role="tablist">
          {ROLES.map((r) => (
            <button
              key={r.id}
              role="tab"
              aria-selected={active === r.id}
              className={`roles-tab ${active === r.id ? 'on' : ''}`}
              onClick={() => setActive(r.id)}
              style={{ '--tab-tint': r.tint }}
            >
              <span className="roles-tab-dot" />
              {r.label}
            </button>
          ))}
        </div>

        {/* Panel */}
        <div className="roles-panel" style={{ '--p-tint': role.tint }}>
          <div className="roles-panel-bg" />

          <div className="roles-panel-grid">
            <div className="roles-panel-copy">
              <h3 className="roles-panel-head">{role.headline}</h3>
              <p className="roles-panel-sub">{role.sub}</p>
              <a className="btn btn-primary" href="https://calend.ly/emdx" target="_blank" rel="noopener">
                {Icons.telegram({ width: 16, height: 16 })} Try in your chat {Icons.arrow({ width: 14, height: 14 })}
              </a>
            </div>

            <div className="roles-panel-grid-bullets">
              {role.bullets.map((b, i) => (
                <div className="role-bullet" key={i}>
                  <div className="role-bullet-num">{String(i + 1).padStart(2, '0')}</div>
                  <div>
                    <strong>{b[0]}</strong>
                    <span>{b[1]}</span>
                  </div>
                </div>
              ))}
            </div>

            <div className="roles-panel-mark" aria-hidden="true">
              {Icons[role.icon] ? Icons[role.icon]({ width: 56, height: 56 }) : null}
            </div>
          </div>
        </div>
      </div>

      <style>{`
        .roles {
          padding: 140px 0;
          position: relative;
                  }
        .roles-head { max-width: 720px; margin-bottom: 48px; }
        .roles-title {
          font-size: clamp(2.6rem, 5vw, 4.4rem);
          line-height: 0.95;
          letter-spacing: -0.045em;
          margin-top: 14px;
        }
        .roles-title em {
          font-style: normal;
          background: linear-gradient(120deg, var(--accent-light), var(--accent));
          -webkit-background-clip: text; background-clip: text; color: transparent;
        }

        .roles-tabs {
          display: flex; gap: 8px; flex-wrap: wrap;
          margin-bottom: 32px;
          padding-bottom: 4px;
        }
        .roles-tab {
          background: transparent;
          border: 1px solid var(--border);
          border-radius: 999px;
          padding: 10px 18px;
          color: var(--text-secondary);
          font-size: 14px;
          font-weight: 500;
          display: flex; align-items: center; gap: 8px;
          transition: all 220ms var(--ease-out);
        }
        .roles-tab:hover {
          color: var(--text);
          border-color: var(--border-light);
        }
        .roles-tab.on {
          color: var(--text);
          background: color-mix(in oklch, var(--tab-tint) 12%, transparent);
          border-color: color-mix(in oklch, var(--tab-tint) 50%, transparent);
        }
        .roles-tab-dot {
          width: 6px; height: 6px;
          border-radius: 50%;
          background: var(--tab-tint);
          opacity: 0.5;
        }
        .roles-tab.on .roles-tab-dot {
          opacity: 1;
          box-shadow: 0 0 8px var(--tab-tint);
        }

        .roles-panel {
          position: relative;
          padding: 56px 48px;
          border-radius: 28px;
          background:
            radial-gradient(ellipse 60% 60% at 90% 10%, color-mix(in oklch, var(--p-tint) 12%, transparent), transparent 60%),
            linear-gradient(180deg, var(--bg-card) 0%, var(--bg-elev) 100%);
          border: 1px solid var(--border);
          overflow: hidden;
        }
        .roles-panel-bg {
          position: absolute; inset: -1px;
          border-radius: 28px; padding: 1px;
          background: linear-gradient(135deg, color-mix(in oklch, var(--p-tint) 40%, transparent), transparent 60%);
          mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask-composite: exclude;
          -webkit-mask-composite: xor;
          pointer-events: none;
        }
        @media (max-width: 720px) {
          .roles-panel { padding: 36px 28px; }
        }

        .roles-panel-grid {
          display: grid;
          grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr);
          gap: 56px;
          position: relative;
          z-index: 1;
        }
        @media (max-width: 940px) { .roles-panel-grid { grid-template-columns: 1fr; gap: 36px; } }

        .roles-panel-head {
          font-size: clamp(2rem, 3.4vw, 3rem);
          line-height: 1.0;
          letter-spacing: -0.04em;
          white-space: pre-line;
          margin-bottom: 22px;
          color: var(--text);
        }
        .roles-panel-sub {
          font-size: 16px;
          color: var(--text-secondary);
          line-height: 1.6;
          max-width: 480px;
          margin-bottom: 28px;
        }

        .roles-panel-grid-bullets {
          display: grid;
          grid-template-columns: 1fr 1fr;
          gap: 20px 28px;
        }
        @media (max-width: 560px) { .roles-panel-grid-bullets { grid-template-columns: 1fr; } }
        .role-bullet {
          display: grid;
          grid-template-columns: 36px 1fr;
          gap: 4px;
        }
        .role-bullet-num {
          font-family: var(--font-mono);
          font-size: 11px;
          letter-spacing: 0.12em;
          color: var(--p-tint);
          padding-top: 4px;
        }
        .role-bullet strong {
          display: block;
          font-size: 15.5px;
          font-weight: 600;
          color: var(--text);
          margin-bottom: 4px;
          line-height: 1.35;
        }
        .role-bullet span {
          font-size: 13.5px;
          color: var(--text-muted);
          line-height: 1.5;
        }

        .roles-panel-mark {
          position: absolute;
          right: 36px;
          top: 32px;
          width: 80px; height: 80px;
          border-radius: 18px;
          background: color-mix(in oklch, var(--p-tint) 14%, transparent);
          border: 1px solid color-mix(in oklch, var(--p-tint) 35%, transparent);
          color: var(--p-tint);
          display: flex; align-items: center; justify-content: center;
        }
        .roles-panel-mark svg { display: block; }
        @media (max-width: 720px) {
          .roles-panel-mark { width: 56px; height: 56px; right: 24px; top: 24px; }
          .roles-panel-mark svg { width: 36px; height: 36px; }
        }
      `}</style>
    </section>
  );
}

Object.assign(window, { ChatSection, Compare, RoleTabs });
