#!/usr/bin/env python3
"""Render research_brief.html and product_selection.html for 1nurse-charles cycle."""

import re
from pathlib import Path

TEMPLATE_DIR = Path("/Users/bryce/FLSM/Emerson North/templates")
OUT_DIR = Path("/Users/bryce/FLSM/.tmp/briefs/1nurse-charles-2026-04-20")
OUT_DIR.mkdir(parents=True, exist_ok=True)

# ── Common ────────────────────────────────────────────────────────────────────
COMMON = {
    "CLIENT_NAME": "Nurse Charles",
    "PERIOD": "2026-04-20 — 2026-05-04",
    "CLIENT_ID": "1nurse-charles",
    "CYCLE_ID": "1nurse-charles-2026-04-20",
    "TARGET_MARKET": "Health-curious adults 25–45 + parents of teens/young adults",
    "ACTIVE_CAMPAIGN": "None (cycle selects first)",
    "DATE": "2026-04-20",
    "SOURCE_COUNT": "4",
}

# ── Research Brief tokens ─────────────────────────────────────────────────────
RB = {
    **COMMON,
    "PAIN_COUNT": "7",
    "COMP_COUNT": "5",
    "REVIEW_COUNT": "100",
    "INTENT_COUNT": "6",
    "KW_COUNT": "25",

    # Summary
    "SUMMARY_TAKEAWAY": "Nurse Charles's audience is living through a cannabis-overdose epidemic in real time — they have personal loss stories, their kids are getting dosed with 2,000mg edibles at school, and they do not know the difference between Delta-8 and Delta-9. Nobody in his competitive set is answering these questions; Charles already is. The next campaign should turn that audience need into a paid product parents can hand to their kids before the ER visit happens.",
    "FINDING_1": "Parent loss + THC overdose is the single highest-frequency theme this cycle. In 100 client IG comments, 41 directly reference THC, vape, fentanyl, edibles, or overdose; 8 describe a specific family death. Reddit r/harmreduction and r/cannabis confirm the topic is active but fragmented. Confidence: High.",
    "FINDING_2": "The audience cannot distinguish high-potency products from safe ones — and they are asking directly. 14 comments specifically about dose: \"600 mg is WILD,\" \"I take 1mg and be levitating,\" \"Delta-8 is not the same as delta-9-THC.\" This is a clinical education gap, not an ideology gap. Confidence: High.",
    "FINDING_3": "Charles's top 5 competitors are not serving his audience. Nurse Blake (47k/day velocity) does comedy + tour promo. Nurse Dani does ACLS tricks for nursing students. All 5 competitors talk to nurses, not patients. Charles owns the patient-education lane by default. Confidence: High.",
    "FINDING_4": "The parent-to-kid drug conversation is a repeating explicit ask. \"PARENTS TALK TO YOUR KIDS\" and close variants appeared 11 times in 100 comments — an extraordinary rate of explicit product demand. Parents want a script, not another warning. Confidence: High.",
    "MARKET_OPPORTUNITY": "Parents of health-curious adults 25–45 are watching their kids, nieces, and nephews die or hospitalize from high-potency THC products they cannot identify, and they are begging in the comments for someone to give them a way to explain the danger before the overdose happens — no competitor is filling that gap.",
    "WHY_NOW": "Federal marijuana rescheduling is active this month, The Pitt (HBO) is recalibrating what a trusted nurse voice sounds like, and gas-station Delta-8 availability has outpaced every public health agency's ability to educate — the window for Charles to become the definitive voice on this is open right now, not next year.",
    "RECOMMENDED_FIRST_MOVE": "Option 1 — 'Before the ER' Parent Masterclass. The data is unambiguous: 11 explicit parent-education requests, 8 personal loss stories, 14 dose-confusion comments, zero competitor coverage. Ship Option 4 (free checklist) alongside as the lead magnet. Option 2 (paid newsletter) is the follow-on once Option 1 proves conversion.",
    "AGENT_NOTES": "Data HIGH for client comments (100), MEDIUM for competitor posts (3 of 5 handles returned), LOW elsewhere. LinkedIn and Twitter scrapers failed this cycle. Competitor TikTok comments empty (URL resolution). Google Trends returned zero for 'Media Influencer' niche. Keyword tooling returned nursing-school exam terms instead of Charles's topic area — next cycle will query pillars directly.",

    # Product option summary rationale (top 5)
    "OPTION_1_NAME": "'Before the ER' Parent Masterclass — $47–97",
    "OPTION_1_RATIONALE": "Directly addresses the #1 audience ask ('PARENTS TALK TO YOUR KIDS') with a scripted, clinical framework. 11 explicit requests in 100 comments = triple-digit-per-thousand demand signal. Ranked first because it converts the loudest, most specific, most emotionally-charged audience need into a product at a price point matching the KB's $50–200 coaching anchor.",
    "OPTION_2_NAME": "Clinical Debriefs Paid Newsletter — $9/mo",
    "OPTION_2_RATIONALE": "Charles already writes in 'debrief' voice (per the KB). A paid newsletter captures recurring revenue from the 30M+ view audience without new creative work. Ranked second because it requires the smallest lift to launch and gives the mailing list a monetization path.",
    "OPTION_3_NAME": "Family Group Coaching Bundle — $297",
    "OPTION_3_RATIONALE": "Upgrades the existing $50–200 coaching into a packaged offer for families navigating a loved one's crisis. Multiple family-framed comments ('my daughter,' 'my cousin'). Higher price = higher LTV but narrower TAM. Ranked third because demand is real but fulfillment is manual (Charles's time).",
    "OPTION_4_NAME": "Free 'Red Flag' Substance Use Checklist",
    "OPTION_4_RATIONALE": "Pure list-building play. Captures email in exchange for a one-page clinician-written warning-signs document. Strong research support. Ranked fourth because it's necessary infrastructure for Options 1–3, not a standalone revenue driver — ships alongside Option 1.",
    "OPTION_5_NAME": "Clinical Case Breakdown On-Demand Course — $197–297",
    "OPTION_5_RATIONALE": "Polished version of his case-breakdown content, packaged for healthcare students. Highest ticket, but narrowest match to the primary audience's in-cycle demand. Ranked last because it serves a known-but-not-dominant audience with a longer build cycle.",

    # Section 01 — Pain Signals (7)
    "PAIN_1_LABEL": "Parents do not know what potency their kids are buying",
    "PAIN_1_COUNT": "12",
    "PAIN_1_QUOTE": "2,000 mg? That would be 20 100mg edibles and vape? He would have had to smoke… how was the person able to get 2,000mg worth of cannabis at the gas station. They have a cut off at legal dispensaries.",
    "PAIN_1_SOURCES": "IG @1nursecharles (12 comments)",
    "PAIN_1_ANGLE": "Dose-to-outcome explainers — what 2,000mg actually does in the ER, minute by minute",
    "PAIN_2_LABEL": "Grief from losing a young family member to an unexpected overdose",
    "PAIN_2_COUNT": "8",
    "PAIN_2_QUOTE": "Lost my eldest son to fentanyl just before his 22nd birthday. As far as we know, it was laced into something else. He didn't make it into an ambulance, but rather a coroner's van. This was 3 years ago, and the grief is still palpable.",
    "PAIN_2_SOURCES": "IG @1nursecharles (8 personal-loss comments)",
    "PAIN_2_ANGLE": "Case breakdowns of the conversation that didn't happen — treat with care, not promotion",
    "PAIN_3_LABEL": "Audience cannot map a dose to a physiological outcome",
    "PAIN_3_COUNT": "14",
    "PAIN_3_QUOTE": "600 mg is WILD omg and I'm seasoned. / I take 1 milligram and be levitating off the damn couch. / I took a 1200mg once! Almost died. Couldn't speak for a week.",
    "PAIN_3_SOURCES": "IG @1nursecharles (14 dose-referencing comments)",
    "PAIN_3_ANGLE": "Why a 1mg edible can feel the same as a 100mg edible — the mechanism",
    "PAIN_4_LABEL": "Delta-8 vs Delta-9 confusion",
    "PAIN_4_COUNT": "6",
    "PAIN_4_QUOTE": "Delta-8 is not the same as delta-9-THC. / Delta 9 is NOT real THC bro. Everyone knows that shi is gas station weed. / dont take no delta 8, ts is MAN MADE reverse engineered THC.",
    "PAIN_4_SOURCES": "IG @1nursecharles (6 comments), r/cannabis policy threads",
    "PAIN_4_ANGLE": "The difference between Delta-8, Delta-9, and what's actually in a gas-station vape",
    "PAIN_5_LABEL": "Explicit parent-education demand",
    "PAIN_5_COUNT": "11",
    "PAIN_5_QUOTE": "PARENTS TALK TO YOUR KIDS. I WISH I HAD SOMEONE TO TALK TO ME. WHEN I WAS A TEENAGER, THAT'S WHY I HAD MADE BAD DECISIONS AT THE TIME. 11 YEARS CLEAN.",
    "PAIN_5_SOURCES": "IG @1nursecharles (11 direct requests)",
    "PAIN_5_ANGLE": "How to talk to a 12-year-old about vape risk without sounding like a PSA",
    "PAIN_6_LABEL": "Supply chain distrust (dispensary vs gas-station)",
    "PAIN_6_COUNT": "5",
    "PAIN_6_QUOTE": "get it from the dispensary where the milligrams are 10-40 mg and STATE REGULATED for your safety guys. / Smoke shops can literally sell you anything and illegal drugs!",
    "PAIN_6_SOURCES": "IG @1nursecharles (5 comments)",
    "PAIN_6_ANGLE": "Why a gas-station gummy isn't the same as a dispensary gummy — from a nurse who's treated both",
    "PAIN_7_LABEL": "Cannabis-induced psychosis uncertainty",
    "PAIN_7_COUNT": "7",
    "PAIN_7_QUOTE": "My cousin has marijuana-induced schizophrenia. We initially thought he was drugged or laced, but he hasn't been the same since and suffers from auditory and vision hallucinations.",
    "PAIN_7_SOURCES": "IG @1nursecharles (7 comments)",
    "PAIN_7_ANGLE": "How THC triggers psychosis and why it hits some brains differently",
    "HIGH_FREQ_PAIN": "Dose confusion — 14/100 comments. Cross-validated against r/cannabis policy threads.",
    "EMOTIONAL_PAIN": "Parent/grandparent grief stories — 8 specific personal losses, present-tense language.",
    "GAP_PAIN": "Parent-facing substance education — zero of Charles's top 5 competitors address this.",

    # Section 02 — Competitor Intelligence (3 card columns)
    "COMP_1_NAME": "@nurseblake",
    "COMP_1_URL": "tiktok.com/@nurseblake",
    "COMP_1_LEAD": "Comedy / nurse-on-nurse humor + tour ticket sales",
    "COMP_1_PRICE": "Tour tickets ~$35–$150",
    "COMP_1_CLAIM": "But Did You Die? Comedy Tour",
    "COMP_1_OFFER": "Live comedy, original sound posts, 8k–47k/day velocity",
    "COMP_1_GAP": "Zero patient-facing clinical education — serves nurses, not the public",
    "COMP_1_LANG": "'SUPINE,' 'ICU life,' 'work wife' — all nurse-insider",
    "COMP_2_NAME": "@nursingeducatordani",
    "COMP_2_URL": "tiktok.com/@nursingeducatordani",
    "COMP_2_LEAD": "Telemetry strip puzzles / ACLS tricks",
    "COMP_2_PRICE": "Not listed (content-only monetization)",
    "COMP_2_CLAIM": "What do you think this tele strip is showing?",
    "COMP_2_OFFER": "Clinical puzzle format for nursing students",
    "COMP_2_GAP": "Zero patient education — audience is students, not public",
    "COMP_2_LANG": "'tele strips,' 'ACLS,' 'pharmacology' — clinician terms",
    "COMP_3_NAME": "@nurseblake / Blake-alikes",
    "COMP_3_URL": "Cross-category reference",
    "COMP_3_LEAD": "Humor/relatability framing for nurses",
    "COMP_3_PRICE": "Varies",
    "COMP_3_CLAIM": "It's giving aries / nurse besties",
    "COMP_3_OFFER": "Short-form comedy",
    "COMP_3_GAP": "No clinical depth, no public-facing substance content",
    "COMP_3_LANG": "In-group nurse humor",

    # Section 03 — Buyer Intelligence (maps to audience comment patterns in creator mode)
    "COMPLAINT_1": "I wish there was a way that I could share the overdoses we work without violating HIPAA. If they could only picture themselves laying on the floor turning blue, sometimes in vomit, totally unconscious and near death…",
    "COMPLAINT_1_SRC": "IG @1nursecharles",
    "COMPLAINT_1_RATING": "Fellow nurse, fed-up tone",
    "COMPLAINT_2": "Get rid of candy fruity vapes. Get rid of gummies. Smoke flower and this will never accidentally happen. God our society is pathetic",
    "COMPLAINT_2_SRC": "IG @1nursecharles",
    "COMPLAINT_2_RATING": "Anger at product industry",
    "COMPLAINT_3": "Since we will never stop drugs being around kids, you MUST begin speaking with them early about them. All doctors offices on well visits must incorporate this in their exam and teaching.",
    "COMPLAINT_3_SRC": "IG @1nursecharles",
    "COMPLAINT_3_RATING": "Former school nurse (9 years)",
    "COMPLAINT_4": "I wouldn't stop till I found the person who gave this young man the THC. This is so sad and scary.",
    "COMPLAINT_4_SRC": "IG @1nursecharles",
    "COMPLAINT_4_RATING": "Parent-protective, righteous-anger",
    "PRAISE_1": "Brother I Really Appreciate Your Educational Presentations. We Need More Health Care Awareness and Safety Measures.",
    "PRAISE_1_SRC": "IG @1nursecharles",
    "PRAISE_2": "Great words of wisdom. I enjoy your content and it's saving lives.",
    "PRAISE_2_SRC": "IG @1nursecharles",
    "PRAISE_3": "Thank you for speaking about this. My best friend was killed by a counterfeit Tylenol pill with fentanyl and was then robbed.",
    "PRAISE_3_SRC": "IG @1nursecharles",
    "SWITCH_1_LABEL": "Personal loss story shared",
    "SWITCH_1_COUNT": "8",
    "SWITCH_1_SRC": "IG @1nursecharles",
    "SWITCH_2_LABEL": "Explicit parent-education request",
    "SWITCH_2_COUNT": "11",
    "SWITCH_2_SRC": "IG @1nursecharles",
    "SWITCH_3_LABEL": "Dose confusion (600mg–2,000mg)",
    "SWITCH_3_COUNT": "14",
    "SWITCH_3_SRC": "IG @1nursecharles",
    "REVIEW_SOURCES": "100 IG comments on a single pediatric THC case-breakdown post",

    # Section 04 — Buying Intent / search queries (inferred for creator mode)
    "INTENT_Q1": "what does 2000mg of thc do to a child",
    "INTENT_Q1_RANKS": "News articles, hospital blogs",
    "INTENT_Q1_URGENCY": "HIGH — pediatric ER admissions trending",
    "INTENT_Q1_GAP": "No ER-nurse-written clinical guide ranks first page",
    "INTENT_Q2": "delta 8 vs delta 9 difference",
    "INTENT_Q2_RANKS": "Dispensary blogs, legal/policy sites",
    "INTENT_Q2_URGENCY": "HIGH — DOJ rescheduling active",
    "INTENT_Q2_GAP": "Medical-framed explainer missing — most results are product/legal",
    "INTENT_Q3": "how to talk to my kid about vaping",
    "INTENT_Q3_RANKS": "PTA blogs, CDC",
    "INTENT_Q3_URGENCY": "MED — evergreen but rising",
    "INTENT_Q3_GAP": "Clinician-written script language missing",
    "INTENT_Q4": "cannabis induced psychosis symptoms",
    "INTENT_Q4_RANKS": "Hospital systems, treatment centers",
    "INTENT_Q4_URGENCY": "MED",
    "INTENT_Q4_GAP": "Plain-language mechanism explanation missing",
    "INTENT_Q5": "fentanyl in vape cartridge",
    "INTENT_Q5_RANKS": "News, law-enforcement sites",
    "INTENT_Q5_URGENCY": "HIGH — parent-fear search",
    "INTENT_Q5_GAP": "Supply-chain explainer from a clinician missing",
    "INTENT_Q6": "signs my teenager is using vapes",
    "INTENT_Q6_RANKS": "Parent blogs, generic lists",
    "INTENT_Q6_URGENCY": "MED",
    "INTENT_Q6_GAP": "No ER-credentialed red-flag list currently ranks",

    # Section 05 — Campaign Angles (3)
    "ANGLE_1_NAME": "'Before the ER' 10-video parent-education series",
    "ANGLE_1_HOOK": "PARENTS TALK TO YOUR KIDS. I've seen that comment eleven times this month. Here's how, as a nurse.",
    "ANGLE_1_SIGNAL": "11 direct parent-education comments + 8 loss stories + dose-confusion cluster",
    "ANGLE_2_NAME": "Clinical Debriefs paid newsletter launch",
    "ANGLE_2_HOOK": "What I wrote in the chart. What I told the family. What the rest of the shift looked like.",
    "ANGLE_2_SIGNAL": "KB voice guide already names 'Debrief' as Charles's signature format; 30M+ audience, no email capture today",
    "ANGLE_3_NAME": "'Supply Chain Breakdown' — from gas-station gummy to ER visit",
    "ANGLE_3_HOOK": "Why a gas-station gummy isn't the same as a dispensary gummy — from a nurse who's treated both.",
    "ANGLE_3_SIGNAL": "5 supply-chain-distrust comments + active DOJ rescheduling makes this evergreen-with-timing",
    "CRITERIA_1": "Parent of a child 10–20 using or exposed to vape/THC products",
    "CRITERIA_2": "Healthcare professional (school nurse, PA, paramedic) who wants parent-education handouts",
    "CRITERIA_3": "Follower who has commented 'lost my' or 'my daughter/son/cousin' on a Nurse Charles post",
    "CRITERIA_4": "Member of the 11 who asked 'PARENTS TALK TO YOUR KIDS' — direct reply-and-DM segment",

    # Section 06 — Content (LP = short-form video, not LinkedIn; re-labeled)
    "LP_1_HOOK": "'2,000mg of THC in a 9-year-old — what happens minute by minute in the ER'",
    "LP_1_FORMAT": "SHORT-FORM VIDEO · CASE BREAKDOWN",
    "LP_1_SIGNAL": "14 dose-confusion comments; Charles's existing top post",
    "LP_2_HOOK": "'Delta-8 vs Delta-9 — the ER nurse version'",
    "LP_2_FORMAT": "SHORT-FORM VIDEO · EXPLAINER",
    "LP_2_SIGNAL": "6 direct Delta-8/9 debate comments",
    "LP_3_HOOK": "'Why a 1mg edible can feel the same as a 100mg edible'",
    "LP_3_FORMAT": "SHORT-FORM VIDEO · MECHANISM",
    "LP_3_SIGNAL": "14 dose-variance comments ranging 1mg to 3,500mg",
    "LP_4_HOOK": "'How to talk to a 12-year-old about vapes without sounding like a PSA'",
    "LP_4_FORMAT": "SHORT-FORM VIDEO · PARENT SCRIPT",
    "LP_4_SIGNAL": "11 explicit 'PARENTS TALK TO YOUR KIDS' comments",
    "LP_5_HOOK": "'What The Pitt gets right about the ER (and the three things it misses)'",
    "LP_5_FORMAT": "SHORT-FORM VIDEO · CULTURAL MOMENT",
    "LP_5_SIGNAL": "r/nursing post: 'It took my parents watching The Pitt to finally understand'",
    "BLOG_1_TITLE": "High-Potency THC Overdose in Children: A Nurse's Clinical Guide for Parents",
    "BLOG_1_KW": "thc overdose symptoms child + high potency thc kids",
    "BLOG_1_INTENT": "Informational (parent research)",
    "BLOG_2_TITLE": "Delta-8 vs Delta-9 THC: What's Actually Different, and Why It Matters Medically",
    "BLOG_2_KW": "delta 8 vs delta 9 difference",
    "BLOG_2_INTENT": "Commercial/informational (rising, policy-linked)",
    "EMAIL_1_SUBJECT": "Newsletter W1 — 'The dose that ended up in the ER this week'",
    "EMAIL_1_LEAD": "One clinical debrief of a real case, one linked video, one CTA to masterclass",
    "EMAIL_2_SUBJECT": "Newsletter W2 — 'Five questions every parent should ask before their kid's next sleepover'",
    "EMAIL_2_LEAD": "Practical, scannable nurse-written checklist, leading to free lead magnet + masterclass upsell",

    # Section 07 — Keywords (8)
    "KW_1": "thc overdose symptoms child",
    "KW_1_VOL": "~800 (inferred)",
    "KW_1_COMP": "MED",
    "KW_1_INTENT": "Informational",
    "KW_1_USE": "Blog 1 primary",
    "KW_2": "delta 8 vs delta 9 difference",
    "KW_2_VOL": "~3,000 (inferred)",
    "KW_2_COMP": "MED",
    "KW_2_INTENT": "Commercial",
    "KW_2_USE": "Blog 2 primary",
    "KW_3": "how to talk to my kid about vaping",
    "KW_3_VOL": "~600 (inferred)",
    "KW_3_COMP": "LOW",
    "KW_3_INTENT": "Informational",
    "KW_3_USE": "Masterclass landing page",
    "KW_4": "is alzheimer's disease dominant or recessive",
    "KW_4_VOL": "260",
    "KW_4_COMP": "LOW",
    "KW_4_INTENT": "Informational",
    "KW_4_USE": "Chronic-disease pillar blog",
    "KW_5": "cannabis induced psychosis symptoms",
    "KW_5_VOL": "~1,200 (inferred)",
    "KW_5_COMP": "MED",
    "KW_5_INTENT": "Commercial",
    "KW_5_USE": "Script + blog combo",
    "KW_6": "what level of education is a nurse practitioner",
    "KW_6_VOL": "30",
    "KW_6_COMP": "HIGH",
    "KW_6_INTENT": "Commercial",
    "KW_6_USE": "LinkedIn authority content",
    "KW_7": "fentanyl in vape cartridge",
    "KW_7_VOL": "~500 (inferred)",
    "KW_7_COMP": "LOW",
    "KW_7_INTENT": "Informational",
    "KW_7_USE": "Parent-fear blog + script",
    "KW_8": "signs my teenager is using vapes",
    "KW_8_VOL": "~2,400 (inferred)",
    "KW_8_COMP": "MED",
    "KW_8_INTENT": "Commercial",
    "KW_8_USE": "Red Flag checklist landing page",

    # Section 08 — Objections & Partners
    "OBJ_1_Q": "Isn't weed basically harmless? Everyone's using it.",
    "OBJ_1_A": "Reframe: today's high-potency THC is not the weed from the 80s. 2,000mg is not the same substance as a regulated 10mg.",
    "OBJ_1_SRC": "Comment: 'Back in my day in the 80s our THC was so low. I can't even imagine what you are seeing in the ER.'",
    "OBJ_2_Q": "I tried once and nothing happened — it can't be that bad.",
    "OBJ_2_A": "Survivor's bias. The ER sees the cases that didn't go fine. Individual outcomes don't override population-level risk.",
    "OBJ_2_SRC": "KB FAQ: 'Survivor's bias in health decision-making' + 2 comments",
    "OBJ_3_Q": "My kid would never.",
    "OBJ_3_A": "Every parent of a loss story said this before. The masterclass is the conversation you have before you need to have the conversation.",
    "OBJ_3_SRC": "Comment: 'I raised her from birth. She lived 8 months outside our home before fentanyl got her.'",
    "PARTNER_1_TYPE": "School nurses & PE teachers",
    "PARTNER_1_DETAIL": "Charles's content + masterclass is a ready-to-use parent handout. One comment from 9-year school nurse.",
    "PARTNER_1_SRC": "IG comment",
    "PARTNER_2_TYPE": "PTA groups / parent associations",
    "PARTNER_2_DETAIL": "Distribution channel for the free checklist; masterclass as follow-up.",
    "PARTNER_2_SRC": "Inferred — parent-education demand signal",
    "PARTNER_3_TYPE": "Pediatric providers (PCPs, PAs, peds NPs)",
    "PARTNER_3_DETAIL": "Parents reading the checklist will ask their pediatrician — referral/affiliate path.",
    "PARTNER_3_SRC": "KB Section 4 FAQ behavior",

    # Section 09 — Active Campaign Tie-In
    "ACTIVE_PRODUCT": "Pending product selection (coaching $50–200 exists but no dedicated offer yet)",
    "ACTIVE_CTA": "Pending",
    "CAMPAIGN_NARRATIVE": "Assume Option 1 (Parent Masterclass) is selected. Every Week 1 video ends with 'Parents, the full walkthrough is in the masterclass — link in bio.' Week 2 references it directly. Option 4 free checklist becomes the email lead magnet; the masterclass is the $47–97 upsell. With 30M+ cumulative views, even 0.5% conversion on next cycle's traffic is meaningful revenue.",

    # Section 10 — KB Update
    "KB_URL": "https://docs.google.com/document/d/1e1oF2ZRVGKSxxEfWQC9BOuaysmGhdXjXSbqhyr7-rKM/edit",
    "KB_APPEND_DATE": "2026-04-20",
    "KB_PILLAR_1_STATUS": "P1 — Emergency Case Breakdowns (100 IG comments + paramedic validation)",
    "KB_PILLAR_2_STATUS": "P2 — Substance and Drug Safety (41/100 direct, 8 loss stories, 14 dose-specific)",
    "KB_PILLAR_3_STATUS": "P3 — Chronic Disease Education (2 r/diabetes titles only; no client comments) — needs validation",
    "KB_PILLAR_4_STATUS": "P4 — High-Potency THC & Vape Safety (14 dose + 6 Delta-8/9 + 5 supply chain)",
    "KB_PILLAR_5_STATUS": "P5 — Parent-to-Kid Health Conversations (11 explicit 'PARENTS TALK TO YOUR KIDS' requests)",
    "KB_COMP_HIGHLIGHTS": "Nurse Blake: comedy + tour tickets, 47k/day — zero overlap with Charles. Nurse Dani: telemetry for students, not patients. Nurse John: largely dormant (5 posts spanning 2024–2026). Kojo & registerednursern: inferred student-facing, no posts returned. NO competitor does patient-facing substance education with ER credibility — Charles's defensible lane.",
    "KB_AUDIENCE_INSIGHTS": "Dose confusion: 14 IG comments on 2,000mg/600mg/1mg variance. Parent grief stories: 8 specific personal losses (son, granddaughter, niece). Explicit parent-education demand: 11 'PARENTS TALK TO YOUR KIDS' comments. Delta-8 vs Delta-9 knowledge gap: 6 comments debating. Supply-chain distrust: 5 comments on dispensary vs gas-station regulation.",
    "KB_KEY_SIGNAL": "The parent-facing substance safety education gap. 11 explicit parent-education requests + 8 personal loss stories + 14 dose-confusion comments = a triple-signal unmet need with zero competitor coverage in Charles's top 5 — the highest-confidence product opportunity in the brief.",
    "KB_SKIPPED": "false",
}

# ── Product Selection tokens ──────────────────────────────────────────────────
# Slot N in template is labeled with a fixed tag. We'll put Option 1 (Parent Masterclass) in slot 3 (Digital Product) etc.
# But the option data-option attribute must match — simpler: keep option order 1–5 matching the research brief ranking,
# even if the template tag label mismatches (users read the name/hook, not the tag).
PS = {
    **COMMON,
    # Option 1: Parent Masterclass
    "OPTION_1_NAME": "'Before the ER' Parent Masterclass",
    "OPTION_1_HOOK": "PARENTS TALK TO YOUR KIDS. I WISH I HAD SOMEONE TO TALK TO ME.",
    "OPTION_1_WHAT": "Clinical-grade, script-based 60–90 min masterclass + workbook for parents on how to talk to their kids about vape, THC, and substance risk before an ER visit happens.",
    "OPTION_1_WHO": "Parents of kids 10–20 who see or suspect vape/THC use and don't know how to open the conversation or what to watch for.",
    "OPTION_1_PRICE": "$47 / $97",
    "OPTION_1_SIGNAL": "11 of 100 IG comments explicitly requested this ('PARENTS TALK TO YOUR KIDS' + variants). 8 personal loss stories. Zero competitor coverage.",

    # Option 2: Paid Newsletter
    "OPTION_2_NAME": "Clinical Debriefs Paid Newsletter",
    "OPTION_2_HOOK": "What I wrote in the chart. What I told the family. What the rest of the shift looked like.",
    "OPTION_2_WHAT": "Weekly ER case breakdown in Charles's voice, delivered to email. Subscribers get the clinical depth behind what shows up on his feed.",
    "OPTION_2_WHO": "30M+ view audience + healthcare students who want more of what Charles does on social.",
    "OPTION_2_PRICE": "$9/mo or $79/yr",
    "OPTION_2_SIGNAL": "KB voice guide already names 'Debrief' as Charles's signature format. 100-comment post engagement shows audience will consume long-form.",

    # Option 3: Family Group Coaching Bundle
    "OPTION_3_NAME": "Family Group Coaching Bundle",
    "OPTION_3_HOOK": "When your family member is in it and you don't speak the language.",
    "OPTION_3_WHAT": "Three 60-minute coaching sessions with Charles + family, packaged for navigating a loved one's substance use or chronic disease crisis.",
    "OPTION_3_WHO": "A parent, spouse, or adult child of someone in the middle of a health crisis who needs a clinical ally to translate what's happening.",
    "OPTION_3_PRICE": "$297 / 3 sessions",
    "OPTION_3_SIGNAL": "Multiple family-framed comments: 'My daughter… sent herself into a psychotic episode.' 'My cousin has marijuana-induced schizophrenia.' KB 'Ongoing relationship' process step describes this exactly.",

    # Option 4: Free Red Flag Checklist (lead magnet)
    "OPTION_4_NAME": "Free 'Red Flag' Substance Use Checklist",
    "OPTION_4_HOOK": "Five things I look for on any substance-use patient in the ER. Here's the home version.",
    "OPTION_4_WHAT": "One-page clinician-written PDF of behavioral/physical warning signs parents can watch for, plus the exact language to open the conversation. Paired with 7-email nurture sequence.",
    "OPTION_4_WHO": "Parents who want practical guidance but aren't ready to buy anything yet — top of funnel for Options 1–3.",
    "OPTION_4_PRICE": "Free (email capture)",
    "OPTION_4_SIGNAL": "Comments requesting preventive education: 'There should be more education targeting vaping and drug use. Let's get them early.' No competitor has a structured email nurture.",

    # Option 5: Clinical Case Breakdown On-Demand Course
    "OPTION_5_NAME": "'Clinical Case Breakdown' On-Demand Course",
    "OPTION_5_HOOK": "30 years of ER cases. 10 modules. What I wish I'd been taught in nursing school.",
    "OPTION_5_WHAT": "Self-paced course (8–10 modules, 4–6 hours) walking through common ER presentations — overdose, sepsis, DKA, stroke — for healthcare students and allied professionals.",
    "OPTION_5_WHO": "Nursing students, pre-med, paramedics, allied health professionals who want case-based learning from a senior ER nurse.",
    "OPTION_5_PRICE": "$197–$297",
    "OPTION_5_SIGNAL": "KB defines secondary audience as healthcare students. Dani's 559k-view 'tricks from colleagues' post proves student-appetite. Different format than Dani's tele-strip puzzles.",
}

def fill(template: str, tokens: dict) -> str:
    out = template
    for k, v in tokens.items():
        out = out.replace("{{" + k + "}}", str(v))
    # Warn on any leftover tokens
    leftover = re.findall(r"\{\{([A-Z0-9_]+)\}\}", out)
    if leftover:
        print(f"  ⚠ unfilled tokens: {set(leftover)}")
    return out

def main():
    rb_tpl = (TEMPLATE_DIR / "research_brief.html").read_text()
    ps_tpl = (TEMPLATE_DIR / "product_selection.html").read_text()

    rb_out = fill(rb_tpl, RB)
    ps_out = fill(ps_tpl, PS)

    (OUT_DIR / "research_brief.html").write_text(rb_out)
    (OUT_DIR / "product_selection.html").write_text(ps_out)

    print(f"✓ Wrote research_brief.html  ({len(rb_out):,} chars)")
    print(f"✓ Wrote product_selection.html ({len(ps_out):,} chars)")
    print(f"  Out dir: {OUT_DIR}")

if __name__ == "__main__":
    main()
