// How To — an in-app playbook for the full workflow: industry news → intake →
// research → match → contacts → draft. Mirrors the shareable guide. Contacts
// carries a manual-entry warning because the AI is unreliable at finding people.

const HOWTO_FLOW = ['Industry news', 'Intake', 'Research', 'Match', 'Contacts', 'Draft'];

const HOWTO_STEPS = [
  {
    n: '0', key: 'intake', accent: true,
    title: 'Review industry news',
    where: 'News Intake → “Industry news” tab · also on the Dashboard',
    sub: 'Background intelligence, not an action list. Nothing to approve here — it sharpens your judgement for the decisions below.',
    dos: [
      'Skim the trade-press and rightsholder headlines for market moves: new sponsors, brands entering a category, budgets opening up.',
      'Note anything that might matter when you triage brands in the next step.',
      'Some items surface prospect leads, but no decision is required on this tab.',
    ],
  },
  {
    n: '1', key: 'intake',
    title: 'News intake — decide who enters the pipeline',
    where: 'News Intake (Step 01)',
    callout: { title: 'You must run the scan to add brands', text: 'New brands do NOT arrive on their own. In News Intake, click the “Re-run scan” button (top right) to fetch the latest brands for review — this is how brands enter the app for now.' },
    sub: 'A NEW badge means a brand arrived in the latest scan. Brands scoring 60+ with high confidence are already auto-researched; the rest wait for your call under “Maybe relevant”.',
    dos: [
      'Click Re-run scan (top right) to fetch the latest brands — this is how new brands come in for now.',
      'Open the Maybe relevant tab — these need your decision.',
      'Read each brand’s headline, signals and score. Click Source to check the article.',
      'Pick a Tier (1 / 2 / 3), then act: Research (into the pipeline), KIV (monitor only), Reject (stop), or Duplicate.',
      'Researching auto-assigns the owner: Tier 1 → Rene, everything else → Aaron.',
      'To act on many at once, tick the rows and use the bulk bar (Assign / Research / KIV / Reject).',
    ],
    tip: 'Add brand lets you paste an article URL — the app reads it, extracts the brand and starts research for you — or enter one by hand. “How scoring works” explains the 0–100 score. Re-run scan warns if you scanned within 24h because it uses quota.',
  },
  {
    n: '2', key: 'research',
    title: 'Research — build the profile',
    where: 'Brand Research (Step 02)',
    sub: 'The AI writes a sourced profile so you can judge fit fast.',
    dos: [
      'Open a brand from the active list (filter by tier, category, assignee or country).',
      'Read the profile: description, HQ, sponsorship history, detected signals, citations, and the recommended IPSEM properties.',
      'If a brand is marked Needs review, the AI found little — check it yourself and add what you know.',
      'Use Research now or Re-research to (re)generate the profile.',
      'Not interested? Click Reject or KIV right here — you no longer have to go back to News Intake. Reject and KIV are also in the top bar on every screen.',
      'The Notes panel sits under the brand header on Research, Match, Contacts and Draft. It is ONE list per brand — a note written at any stage is the same note read at every other stage.',
      'Type @ to tag Aaron, Rene or Stuart — they get a notification in the bell at the top right and on the Notifications page.',
      'The team sits in three time zones, so note times read as "2 hours ago" — that means the same thing to everyone. Hover any timestamp to see the exact moment in your zone and in the other two. Set your own zone under your avatar in the sidebar.',
      'Tick "Next action" on a note to make it an open action. Everything the team has written shows up on the Notes & Actions page, where you tick items off — actions get marked done, plain comments get marked reviewed — so what is left is what still needs you.',
      'Tier, status, relationship, outreach stage, assignee and the Reject / Duplicate / KIV actions sit in one strip under the brand header on every stage. You no longer have to go back to News Intake to change them.',
      'When the profile looks right, move on to Match.',
    ],
  },
  {
    n: '3', key: 'match',
    title: 'Property match — pick the fit',
    where: 'Property Match (Step 03)',
    sub: 'The system suggests; you decide. Nothing is ever pre-selected for you.',
    dos: [
      'Choose the mode: Specific (a named IPSEM property), Generic (pitch IPSEM as the rightsholder, no single property), or No match (stops the flow).',
      'Review the AI’s suggestions. They are ordered first and badged “AI suggestion”, but none of them is selected until you click Select.',
      'Where a property has disciplines (FEI → Dressage, Show Jumping, Eventing; ISU → Short Track, Ice Dancing, Synchronised Skating), tag the ones actually in play on the card.',
      'Open Geographic markets on any card for the full market list, the broadcast footprint and the market-by-market briefing.',
      'Nothing suitable in the portfolio? Click Add one-off property to create it here — set its engagement type to One-off or Short term — and it is selected immediately.',
      'Add a note explaining WHY you picked (or rejected) a property. @tag a colleague if you need their view.',
      'Click Confirm selection — this moves the brand forward to Contacts. A "Next brand" button then takes you straight to the next one awaiting a decision.',
      'Changed your mind? Click Remove property, then Remove approved property. The brand goes back to awaiting a decision — you no longer have to pick something else just to save.',
      'Your tier / category / assignee / country filters now stay set when you leave the page and come back.',
      'Then get the rightsholder’s approval: Properties → the property → Brands assigned lists every brand you confirmed for it. Export approval sheet gives you an Excel file to send them, they pick Approved / Approved with conditions / Needs discussion / Not approved, and Import their answers reads it straight back in.',
      'Before you export, check the “Why it fits” column. The research engine only writes a reason for properties it suggested itself, so anything you picked by hand starts blank — click the row and write one.',
    ],
  },
  {
    n: '4', key: 'contacts',
    title: 'Contacts — enter them yourself',
    where: 'Contacts (Step 04)',
    callout: { title: 'Manual entry required', text: 'The AI is NOT reliable at finding real decision-makers or correct email addresses. Treat anything “Discover contacts” returns as a hint only — verify everything before you use it.' },
    dos: [
      'Click Add contact and enter it by hand: name, job title, email, LinkedIn.',
      'Find the right person on LinkedIn or the company website — aim for the decision-maker (marketing, partnerships or brand lead).',
      'Verify the email. Guessed / pattern addresses are flagged — confirm them before sending.',
      'Keep only real, checked contacts. Delete anything the AI added that you can’t stand behind.',
      'Once you have a solid contact, go to Draft.',
    ],
  },
  {
    n: '5', key: 'draft',
    title: 'Draft — write, then send from your inbox',
    where: 'Draft Review (Step 05)',
    sub: 'The draft is a partnership proposal pitching the brand as the property’s Official Partner.',
    dos: [
      'Click Generate draft. Review and edit the subject and body; use Regenerate for a fresh version.',
      'Copy the Subject, Body, or the whole email — or click Send to open your email client addressed to the picked contacts and mark the brand as contacted.',
      'The app does NOT send for you; you send from your own inbox. Do-not-contact brands have sending disabled.',
      'A property that refused a brand cannot be pitched on: the draft leaves it out, and if every matched property refused, generating and marking as contacted are both blocked. Change the answer under Properties → Brands assigned to unblock it.',
      'After sending, track replies with the Outreach status on the row or the Pipeline board.',
    ],
  },
];

// Who does what, stage by stage. Splits each stage into the part the app
// handles, the part only a person can, and the gate that moves it on.
const HOWTO_STAGE_ROWS = [
  {
    n: '0', accent: true, key: 'intake', title: 'Industry news',
    app: 'Pulls trade-press and rightsholder headlines into a feed.',
    you: 'Skim for market moves. Nothing to approve.',
    gate: 'Never — it is context that sharpens the next decision.',
  },
  {
    n: '1', key: 'intake', title: 'News intake',
    app: 'On Re-run scan, finds brands, scores them 0–100, and auto-researches 60+ with high confidence.',
    you: 'Work the Maybe relevant tab: set a Tier, then Research / KIV / Reject / Duplicate.',
    gate: 'You click Research — the owner auto-assigns (Tier 1 → Rene, else Aaron).',
  },
  {
    n: '2', key: 'research', title: 'Brand research',
    app: 'Writes description, HQ, sponsorship history, signals, citations and suggested IPSEM properties.',
    you: 'Read it, fix what is wrong, add what you know. Note anything the team needs and @tag them.',
    gate: 'The profile is good enough to judge fit. Then open Match.',
  },
  {
    n: '3', key: 'match', title: 'Property match',
    app: 'Ranks suggestions, badges them AI suggestion, and holds the market and broadcast briefing per property.',
    you: 'Pick Specific / Generic / No match, tag the disciplines in play, write why.',
    gate: 'You click Confirm selection. Nothing is ever pre-selected for you.',
  },
  {
    n: '4', key: 'contacts', title: 'Contacts',
    app: 'Flags guessed or pattern email addresses. Its contact finding is not reliable.',
    you: 'Add the real decision-maker by hand from LinkedIn or the company site. Verify the email. Delete anything you cannot stand behind.',
    gate: 'One verified contact exists.',
    warn: true,
  },
  {
    n: '5', key: 'draft', title: 'Draft review',
    app: "Writes a proposal pitching the brand as the property's Official Partner. Regenerate for a fresh version.",
    you: 'Edit the subject and body, then copy or click Send to open your mail client.',
    gate: 'You send it from your own inbox — the app never sends for you.',
  },
];

// ─── Flow map ─────────────────────────────────────────────────────────────
// The whole pipeline as one diagram: who acts on the left, the stage down the
// middle, and every way a brand can leave the flow on the right. Inline SVG so
// it themes from the CSS tokens and scales without a chart library.
function HowToFlowMap() {
  return (
    <svg
      className="flowmap"
      viewBox="0 0 840 950"
      xmlns="http://www.w3.org/2000/svg"
      role="img"
      aria-label="Flow diagram of the six prospecting stages from industry news to outreach tracking, with the exit paths available at each stage."
    >
      <defs>
        <marker id="htm-arrow" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="6" markerHeight="6" orient="auto-start-reverse">
          <path d="M0,1 L9,5 L0,9 z" fill="var(--ink-4)" />
        </marker>
        <marker id="htm-arrow-sm" viewBox="0 0 10 10" refX="8" refY="5" markerWidth="5" markerHeight="5" orient="auto-start-reverse">
          <path d="M0,1 L9,5 L0,9 z" fill="var(--hairline-strong)" />
        </marker>
      </defs>

      {/* Column headers */}
      <text x="4"   y="20" className="mono" fontSize="10" letterSpacing="0.6" fill="var(--ink-3)">WHO ACTS</text>
      <text x="96"  y="20" className="mono" fontSize="10" letterSpacing="0.6" fill="var(--ink-3)">STAGE · WHAT HAPPENS</text>
      <text x="448" y="20" className="mono" fontSize="10" letterSpacing="0.6" fill="var(--ink-3)">HOW A BRAND CAN LEAVE</text>

      {/* Stage 0 — Industry news */}
      <rect x="4" y="123" width="72" height="22" rx="6" fill="var(--accent-soft-bg)" />
      <text x="40" y="138" textAnchor="middle" className="mono" fontSize="9.5" fill="var(--accent)">APP · AUTO</text>
      <rect x="96" y="96" width="296" height="76" rx="10" fill="var(--card)" stroke="var(--hairline-strong)" />
      <rect x="96" y="96" width="4" height="76" rx="2" fill="var(--accent)" />
      <text x="114" y="122" fontSize="13" fontWeight="600" fill="var(--ink)">0 · Industry news</text>
      <text x="114" y="140" fontSize="11" fill="var(--ink-3)">App pulls trade-press and rightsholder</text>
      <text x="114" y="155" fontSize="11" fill="var(--ink-3)">headlines. Nothing to approve here.</text>
      <path d="M392,134 H424" stroke="var(--hairline-strong)" fill="none" />
      <path d="M424,134 H448" stroke="var(--hairline-strong)" fill="none" markerEnd="url(#htm-arrow-sm)" />
      <rect x="452" y="123" width="330" height="22" rx="6" fill="var(--muted-soft)" />
      <text x="464" y="138" fontSize="10.5" fill="var(--ink-2)">Background only — no decision, nothing exits</text>
      <path d="M244,174 V198" stroke="var(--ink-4)" fill="none" markerEnd="url(#htm-arrow)" />

      {/* Stage 1 — News intake */}
      <rect x="4" y="233" width="72" height="22" rx="6" fill="var(--attention-soft)" />
      <text x="40" y="248" textAnchor="middle" className="mono" fontSize="9.5" fill="var(--attention)">YOU · DECIDE</text>
      <rect x="96" y="206" width="296" height="76" rx="10" fill="var(--card)" stroke="var(--attention)" />
      <rect x="96" y="206" width="4" height="76" rx="2" fill="var(--attention)" />
      <text x="114" y="232" fontSize="13" fontWeight="600" fill="var(--ink)">1 · News intake</text>
      <text x="114" y="250" fontSize="11" fill="var(--ink-3)">You click Re-run scan. New brands arrive</text>
      <text x="114" y="265" fontSize="11" fill="var(--ink-3)">scored 0–100. You set Tier, then act.</text>
      <path d="M392,244 H424" stroke="var(--hairline-strong)" fill="none" />
      <path d="M424,220 V272" stroke="var(--hairline-strong)" fill="none" />
      <path d="M424,220 H448" stroke="var(--hairline-strong)" fill="none" markerEnd="url(#htm-arrow-sm)" />
      <path d="M424,246 H448" stroke="var(--hairline-strong)" fill="none" markerEnd="url(#htm-arrow-sm)" />
      <path d="M424,272 H448" stroke="var(--hairline-strong)" fill="none" markerEnd="url(#htm-arrow-sm)" />
      <rect x="452" y="209" width="330" height="22" rx="6" fill="var(--negative-soft)" />
      <text x="464" y="224" fontSize="10.5" fill="var(--negative)">Reject — stops here, with a reason</text>
      <rect x="452" y="235" width="330" height="22" rx="6" fill="var(--pending-soft)" />
      <text x="464" y="250" fontSize="10.5" fill="var(--pending)">KIV — watched, no outreach</text>
      <rect x="452" y="261" width="330" height="22" rx="6" fill="var(--muted-soft)" />
      <text x="464" y="276" fontSize="10.5" fill="var(--ink-2)">Duplicate — merged into the original brand</text>
      <path d="M244,284 V308" stroke="var(--ink-4)" fill="none" markerEnd="url(#htm-arrow)" />

      {/* Stage 2 — Brand research */}
      <rect x="4" y="343" width="72" height="22" rx="6" fill="var(--accent-soft-bg)" />
      <text x="40" y="358" textAnchor="middle" className="mono" fontSize="9.5" fill="var(--accent)">APP + YOU</text>
      <rect x="96" y="316" width="296" height="76" rx="10" fill="var(--card)" stroke="var(--hairline-strong)" />
      <rect x="96" y="316" width="4" height="76" rx="2" fill="var(--accent)" />
      <text x="114" y="342" fontSize="13" fontWeight="600" fill="var(--ink)">2 · Brand research</text>
      <text x="114" y="360" fontSize="11" fill="var(--ink-3)">AI writes a sourced profile with citations.</text>
      <text x="114" y="375" fontSize="11" fill="var(--ink-3)">You read it, correct it, note what you know.</text>
      <path d="M392,354 H424" stroke="var(--hairline-strong)" fill="none" />
      <path d="M424,343 V369" stroke="var(--hairline-strong)" fill="none" />
      <path d="M424,343 H448" stroke="var(--hairline-strong)" fill="none" markerEnd="url(#htm-arrow-sm)" />
      <path d="M424,369 H448" stroke="var(--hairline-strong)" fill="none" markerEnd="url(#htm-arrow-sm)" />
      <rect x="452" y="332" width="330" height="22" rx="6" fill="var(--pending-soft)" />
      <text x="464" y="347" fontSize="10.5" fill="var(--pending)">Needs review — AI found too little, check it yourself</text>
      <rect x="452" y="358" width="330" height="22" rx="6" fill="var(--negative-soft)" />
      <text x="464" y="373" fontSize="10.5" fill="var(--negative)">Reject / KIV — now available from every stage</text>
      <path d="M244,394 V418" stroke="var(--ink-4)" fill="none" markerEnd="url(#htm-arrow)" />

      {/* Stage 3 — Property match */}
      <rect x="4" y="453" width="72" height="22" rx="6" fill="var(--attention-soft)" />
      <text x="40" y="468" textAnchor="middle" className="mono" fontSize="9.5" fill="var(--attention)">YOU · DECIDE</text>
      <rect x="96" y="426" width="296" height="76" rx="10" fill="var(--card)" stroke="var(--attention)" />
      <rect x="96" y="426" width="4" height="76" rx="2" fill="var(--attention)" />
      <text x="114" y="452" fontSize="13" fontWeight="600" fill="var(--ink)">3 · Property match</text>
      <text x="114" y="470" fontSize="11" fill="var(--ink-3)">AI suggests and badges options. Nothing is</text>
      <text x="114" y="485" fontSize="11" fill="var(--ink-3)">selected until you click Select, then Confirm.</text>
      <path d="M392,464 H424" stroke="var(--hairline-strong)" fill="none" />
      <path d="M424,453 V479" stroke="var(--hairline-strong)" fill="none" />
      <path d="M424,453 H448" stroke="var(--hairline-strong)" fill="none" markerEnd="url(#htm-arrow-sm)" />
      <path d="M424,479 H448" stroke="var(--hairline-strong)" fill="none" markerEnd="url(#htm-arrow-sm)" />
      <rect x="452" y="442" width="330" height="22" rx="6" fill="var(--negative-soft)" />
      <text x="464" y="457" fontSize="10.5" fill="var(--negative)">No match — stops here</text>
      <rect x="452" y="468" width="330" height="22" rx="6" fill="var(--accent-soft-bg)" />
      <text x="464" y="483" fontSize="10.5" fill="var(--accent)">Nothing fits? Add a one-off property and carry on</text>
      <path d="M244,504 V528" stroke="var(--ink-4)" fill="none" markerEnd="url(#htm-arrow)" />

      {/* Stage 4 — Contacts */}
      <rect x="4" y="563" width="72" height="22" rx="6" fill="var(--attention-soft)" />
      <text x="40" y="578" textAnchor="middle" className="mono" fontSize="9.5" fill="var(--attention)">YOU · MANUAL</text>
      <rect x="96" y="536" width="296" height="76" rx="10" fill="var(--card)" stroke="var(--attention)" />
      <rect x="96" y="536" width="4" height="76" rx="2" fill="var(--attention)" />
      <text x="114" y="562" fontSize="13" fontWeight="600" fill="var(--ink)">4 · Contacts</text>
      <text x="114" y="580" fontSize="11" fill="var(--ink-3)">You add the decision-maker by hand and verify</text>
      <text x="114" y="595" fontSize="11" fill="var(--ink-3)">the email. Treat AI finds as a hint only.</text>
      <path d="M392,574 H424" stroke="var(--hairline-strong)" fill="none" />
      <path d="M424,574 H448" stroke="var(--hairline-strong)" fill="none" markerEnd="url(#htm-arrow-sm)" />
      <rect x="452" y="563" width="330" height="22" rx="6" fill="var(--attention-soft)" />
      <text x="464" y="578" fontSize="10.5" fill="var(--attention)">No verified contact — the brand waits here</text>
      <path d="M244,614 V638" stroke="var(--ink-4)" fill="none" markerEnd="url(#htm-arrow)" />

      {/* Stage 5 — Draft review */}
      <rect x="4" y="673" width="72" height="22" rx="6" fill="var(--accent-soft-bg)" />
      <text x="40" y="688" textAnchor="middle" className="mono" fontSize="9.5" fill="var(--accent)">APP + YOU</text>
      <rect x="96" y="646" width="296" height="76" rx="10" fill="var(--card)" stroke="var(--hairline-strong)" />
      <rect x="96" y="646" width="4" height="76" rx="2" fill="var(--accent)" />
      <text x="114" y="672" fontSize="13" fontWeight="600" fill="var(--ink)">5 · Draft review</text>
      <text x="114" y="690" fontSize="11" fill="var(--ink-3)">AI writes the Official Partner proposal.</text>
      <text x="114" y="705" fontSize="11" fill="var(--ink-3)">You edit the subject and body, then copy or Send.</text>
      <path d="M392,684 H424" stroke="var(--hairline-strong)" fill="none" />
      <path d="M424,673 V699" stroke="var(--hairline-strong)" fill="none" />
      <path d="M424,673 H448" stroke="var(--hairline-strong)" fill="none" markerEnd="url(#htm-arrow-sm)" />
      <path d="M424,699 H448" stroke="var(--hairline-strong)" fill="none" markerEnd="url(#htm-arrow-sm)" />
      <rect x="452" y="662" width="330" height="22" rx="6" fill="var(--accent-soft-bg)" />
      <text x="464" y="677" fontSize="10.5" fill="var(--accent)">You send from your own inbox — the app never sends</text>
      <rect x="452" y="688" width="330" height="22" rx="6" fill="var(--muted-soft)" />
      <text x="464" y="703" fontSize="10.5" fill="var(--ink-2)">Do-not-contact brands have sending disabled</text>
      <path d="M244,724 V748" stroke="var(--ink-4)" fill="none" markerEnd="url(#htm-arrow)" />

      {/* After sending — outreach tracking */}
      <rect x="4" y="783" width="72" height="22" rx="6" fill="var(--positive-soft)" />
      <text x="40" y="798" textAnchor="middle" className="mono" fontSize="9.5" fill="var(--positive)">YOU · TRACK</text>
      <rect x="96" y="756" width="296" height="76" rx="10" fill="var(--card)" stroke="var(--positive)" />
      <rect x="96" y="756" width="4" height="76" rx="2" fill="var(--positive)" />
      <text x="114" y="782" fontSize="13" fontWeight="600" fill="var(--ink)">After sending · Outreach</text>
      <text x="114" y="800" fontSize="11" fill="var(--ink-3)">Contacted → Replied → Call scheduled → Closed.</text>
      <text x="114" y="815" fontSize="11" fill="var(--ink-3)">Set a follow-up date so it comes back to you.</text>
      <path d="M392,794 H424" stroke="var(--hairline-strong)" fill="none" />
      <path d="M424,794 H448" stroke="var(--hairline-strong)" fill="none" markerEnd="url(#htm-arrow-sm)" />
      <rect x="452" y="783" width="330" height="22" rx="6" fill="var(--positive-soft)" />
      <text x="464" y="798" fontSize="10.5" fill="var(--positive)">Due follow-ups reappear on your Dashboard</text>

      {/* What runs alongside every stage */}
      <rect x="4" y="864" width="828" height="72" rx="10" fill="var(--card-alt)" stroke="var(--hairline-strong)" strokeDasharray="4 4" />
      <text x="20" y="886" className="mono" fontSize="10" letterSpacing="0.6" fill="var(--ink-3)">RUNS ALONGSIDE EVERY STAGE</text>
      <text x="20" y="906" fontSize="11" fill="var(--ink-2)">Notes and @mentions (one list per brand, readable from any stage) · Notifications bell · Notes &amp; Actions worklist</text>
      <text x="20" y="923" fontSize="11" fill="var(--ink-2)">Tier / status / relationship / assignee strip and the Reject · KIV · Duplicate buttons sit under the brand header everywhere</text>
    </svg>
  );
}

function HowToStageTable({ onNavigate }) {
  const numStyle = (accent) => ({
    width: 24, height: 24, borderRadius: 7,
    background: accent ? 'var(--accent)' : 'var(--ink)', color: '#fff',
    fontFamily: 'var(--f-mono)', fontSize: 12, fontWeight: 700,
    display: 'inline-flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0,
  });
  return (
    <div className="col gap-2" style={{ marginTop: 6 }}>
      <div className="stagerow is-hdr">
        <div className="eyebrow" style={{ fontSize: 10 }}>Stage</div>
        <div className="eyebrow" style={{ fontSize: 10 }}>The app does</div>
        <div className="eyebrow" style={{ fontSize: 10 }}>You do</div>
        <div className="eyebrow" style={{ fontSize: 10 }}>It moves on when</div>
      </div>
      {HOWTO_STAGE_ROWS.map((s) => (
        <div className="stagerow" key={s.n}>
          <div>
            <button
              className="row gap-2"
              onClick={() => onNavigate && onNavigate(s.key)}
              title="Open this screen"
              style={{ background: 'transparent', border: 0, padding: 0, cursor: 'pointer', alignItems: 'center', textAlign: 'left' }}
            >
              <span style={numStyle(s.accent)}>{s.n}</span>
              <span className="h4">{s.title}</span>
            </button>
          </div>
          <div>
            <div className="cellhead">The app does</div>
            <span className="text-sm text-2" style={{ lineHeight: 1.55, color: s.warn ? 'var(--attention)' : undefined }}>{s.app}</span>
          </div>
          <div>
            <div className="cellhead">You do</div>
            <span className="text-sm text-2" style={{ lineHeight: 1.55 }}>{s.you}</span>
          </div>
          <div>
            <div className="cellhead">It moves on when</div>
            <span className="text-sm text-2" style={{ lineHeight: 1.55 }}>{s.gate}</span>
          </div>
        </div>
      ))}
    </div>
  );
}

function HowTo({ onNavigate }) {
  const numStyle = (accent) => ({
    flexShrink: 0, width: 40, height: 40, borderRadius: 10,
    background: accent ? 'var(--accent)' : 'var(--ink)',
    color: '#fff', fontFamily: 'var(--f-mono)', fontSize: 17, fontWeight: 700,
    display: 'flex', alignItems: 'center', justifyContent: 'center',
  });

  return (
    <div className="page page-cap">
      <SectionHeader
        eyebrow="Playbook"
        title="How to work a brand, start to finish"
        sub="Six stages take a brand from a news headline to a partnership email in your outbox. Follow them in order. The Pipeline board always shows where each brand sits."
      />

      {/* Daily-scan note */}
      <div className="row gap-2" style={{ marginBottom: 18, padding: '12px 16px', background: 'var(--card-alt)', border: '1px solid var(--hairline)', borderRadius: 10, alignItems: 'center' }}>
        <window.I.refresh size={15} stroke="var(--accent)" />
        <span className="text-sm text-2">
          <strong style={{ color: 'var(--ink)' }}>Scanning is manual for now.</strong> To pull in new brands, open <strong style={{ color: 'var(--ink)' }}>News Intake</strong> and click <strong style={{ color: 'var(--ink)' }}>Re-run scan</strong> (top right). The automatic 09:30 GMT+8 daily scan isn’t running yet. Start your day on the Dashboard.
        </span>
      </div>

      {/* Flow strip */}
      <div className="row gap-1" style={{ flexWrap: 'wrap', marginBottom: 24, padding: '14px 16px', background: 'var(--card)', border: '1px solid var(--hairline)', borderRadius: 12 }}>
        {HOWTO_FLOW.map((label, i) => (
          <React.Fragment key={label}>
            <span className="mono" style={{ fontSize: 12, fontWeight: 600, padding: '6px 11px', borderRadius: 999, background: 'var(--accent-soft-bg)', color: 'var(--accent)', whiteSpace: 'nowrap' }}>{label}</span>
            {i < HOWTO_FLOW.length - 1 ? <window.I.chevronRight size={13} stroke="var(--ink-4)" /> : null}
          </React.Fragment>
        ))}
      </div>

      {/* The whole flow as one diagram, then the same stages split into what the
          app handles versus what only a person can. */}
      <Card lg style={{ marginBottom: 16 }}>
        <div className="eyebrow" style={{ marginBottom: 4 }}>The whole flow on one screen</div>
        <p className="text-sm text-3" style={{ margin: '0 0 16px' }}>
          Read down the middle. The left tag says who acts. The right side is every way a brand can leave the flow.
        </p>
        <HowToFlowMap />
        <p className="text-xs text-3" style={{ margin: '14px 0 0', lineHeight: 1.6 }}>
          <strong style={{ color: 'var(--ink-2)' }}>Going backwards.</strong> On Match, <strong style={{ color: 'var(--ink-2)' }}>Remove property</strong> puts
          a brand back to awaiting a decision — you no longer have to pick something else just to save. Reject, KIV and Duplicate
          sit on the control strip at every stage, so a brand can leave the flow at any point, not only at Intake.
        </p>
      </Card>

      <Card lg style={{ marginBottom: 24 }}>
        <div className="eyebrow" style={{ marginBottom: 4 }}>Who does what, stage by stage</div>
        <p className="text-sm text-3" style={{ margin: '0 0 16px' }}>
          The same six stages, split into the part the app handles and the part only you can.
        </p>
        <HowToStageTable onNavigate={onNavigate} />
      </Card>

      {/* Steps */}
      <div className="col gap-3">
        {HOWTO_STEPS.map((s, i) => (
          <Card lg key={i} style={s.callout ? { borderColor: 'var(--attention)' } : undefined}>
            <div className="row gap-3" style={{ alignItems: 'flex-start' }}>
              <span style={numStyle(s.accent)}>{s.n}</span>
              <div className="grow" style={{ minWidth: 0 }}>
                <div className="h3" style={{ fontSize: 18 }}>{s.title}</div>
                <button
                  className="row gap-2"
                  onClick={() => onNavigate && onNavigate(s.key)}
                  title="Open this screen"
                  style={{ marginTop: 5, padding: 0, background: 'transparent', border: 0, cursor: 'pointer' }}
                >
                  <span style={{ width: 6, height: 6, borderRadius: 999, background: 'var(--accent)', flexShrink: 0 }} />
                  <span className="mono text-xs" style={{ color: 'var(--ink-3)', letterSpacing: '0.03em' }}>{s.where}</span>
                </button>
              </div>
            </div>

            {s.callout ? (
              <div style={{ margin: '14px 0 0 52px', padding: '13px 15px', background: 'var(--card-alt)', border: '1px solid var(--attention)', borderRadius: 10 }}>
                <div className="row gap-2" style={{ alignItems: 'center', marginBottom: 5 }}>
                  <window.I.warn size={14} stroke="var(--attention)" />
                  <span className="eyebrow" style={{ color: 'var(--attention)' }}>{s.callout.title}</span>
                </div>
                <p className="text-sm" style={{ margin: 0, lineHeight: 1.55 }}>{s.callout.text}</p>
              </div>
            ) : null}

            {s.sub ? <p className="text-2 text-sm" style={{ margin: '14px 0 0 52px', lineHeight: 1.6 }}>{s.sub}</p> : null}

            <ol className="col gap-2" style={{ margin: '14px 0 0 52px', padding: 0, listStyle: 'none', counterReset: 'howto' }}>
              {s.dos.map((d, j) => (
                <li key={j} className="row gap-2" style={{ alignItems: 'flex-start' }}>
                  <span className="mono" style={{ flexShrink: 0, width: 20, height: 20, borderRadius: 6, background: 'var(--accent-soft-bg)', color: 'var(--accent)', fontSize: 11, fontWeight: 700, display: 'flex', alignItems: 'center', justifyContent: 'center', marginTop: 1 }}>{j + 1}</span>
                  <span className="text-sm" style={{ lineHeight: 1.55 }}>{d}</span>
                </li>
              ))}
            </ol>

            {s.tip ? (
              <div className="row gap-2" style={{ margin: '14px 0 0 52px', alignItems: 'baseline' }}>
                <span className="eyebrow" style={{ color: 'var(--positive)', flexShrink: 0 }}>Handy</span>
                <span className="text-xs text-3" style={{ lineHeight: 1.55 }}>{s.tip}</span>
              </div>
            ) : null}
          </Card>
        ))}
      </div>

      {/* Views to keep open */}
      <Card lg style={{ marginTop: 18 }}>
        <div className="eyebrow" style={{ marginBottom: 10 }}>Views to keep open</div>
        <div className="col gap-2">
          <div className="row gap-2" style={{ alignItems: 'flex-start' }}>
            <window.I.home size={15} stroke="var(--accent)" style={{ marginTop: 2, flexShrink: 0 }} />
            <span className="text-sm text-2" style={{ lineHeight: 1.55 }}>
              <strong style={{ color: 'var(--ink)', cursor: 'pointer' }} onClick={() => onNavigate && onNavigate('dashboard')}>Dashboard</strong> — your daily home: follow-ups due, today’s picks, and the pipeline breakdown.
            </span>
          </div>
        </div>
      </Card>
    </div>
  );
}

window.HowTo = HowTo;
