#!/usr/bin/env python3
"""PGS 15:2025 Management Presentatie - Phoenix Metals Pilot Plant v5.0"""

from pptx import Presentation
from pptx.util import Inches, Pt, Emu, Cm
from pptx.dml.color import RGBColor
from pptx.enum.text import PP_ALIGN, MSO_ANCHOR
from pptx.enum.shapes import MSO_SHAPE
import os

# ── Constants ──
W = Inches(13.333)  # 16:9 widescreen
H = Inches(7.5)
NAVY = RGBColor(0x00, 0x33, 0x66)
DARK_TEXT = RGBColor(0x1F, 0x29, 0x37)
WHITE = RGBColor(0xFF, 0xFF, 0xFF)
ORANGE = RGBColor(0xEA, 0x58, 0x0C)
RED = RGBColor(0xDC, 0x26, 0x26)
GREEN = RGBColor(0x16, 0xA3, 0x4A)
YELLOW = RGBColor(0xCA, 0x8A, 0x04)
LIGHT_BG = RGBColor(0xF8, 0xFA, 0xFC)
LIGHT_BLUE = RGBColor(0xE0, 0xF0, 0xFF)
LIGHT_RED = RGBColor(0xFE, 0xE2, 0xE2)
LIGHT_ORANGE = RGBColor(0xFF, 0xED, 0xD5)
LIGHT_GREEN = RGBColor(0xDC, 0xFC, 0xE7)
GRAY = RGBColor(0x6B, 0x72, 0x80)

LOGO = "/root/projects/jg/assets/branding/jvg-consultancy-logo.png"
OUT = "/root/projects/jg/2026-pgs15-phoenix-metals/deliverables/docx/PGS15_Management_Presentatie_Phoenix_Metals_D5_v5.0.pptx"

prs = Presentation()
prs.slide_width = W
prs.slide_height = H

# Use blank layout
blank = prs.slide_layouts[6]

def add_footer(slide):
    """Add footer bar"""
    bar = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(0), H - Inches(0.45), W, Inches(0.45))
    bar.fill.solid()
    bar.fill.fore_color.rgb = NAVY
    bar.line.fill.background()
    tf = bar.text_frame
    tf.word_wrap = True
    p = tf.paragraphs[0]
    p.text = "JvG Consultancy | Safety • Governance • Advisory | © 2026"
    p.font.size = Pt(9)
    p.font.color.rgb = WHITE
    p.alignment = PP_ALIGN.CENTER

def add_logo(slide):
    """Add logo top-right"""
    if os.path.exists(LOGO):
        slide.shapes.add_picture(LOGO, W - Inches(1.8), Inches(0.15), Inches(1.5), Inches(1.35))

def add_title_bar(slide, title_text, subtitle_text=None, bg_color=NAVY):
    """Add colored title bar at top"""
    bar = slide.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(0), Inches(0), W, Inches(1.2))
    bar.fill.solid()
    bar.fill.fore_color.rgb = bg_color
    bar.line.fill.background()
    tf = bar.text_frame
    tf.margin_left = Inches(0.5)
    tf.vertical_anchor = MSO_ANCHOR.MIDDLE
    p = tf.paragraphs[0]
    p.text = title_text
    p.font.size = Pt(28)
    p.font.bold = True
    p.font.color.rgb = WHITE
    p.font.name = "Calibri"
    if subtitle_text:
        p2 = tf.add_paragraph()
        p2.text = subtitle_text
        p2.font.size = Pt(14)
        p2.font.color.rgb = RGBColor(0xCC, 0xDD, 0xEE)
        p2.font.name = "Calibri"

def set_cell(cell, text, size=10, bold=False, color=DARK_TEXT, bg=None, align=PP_ALIGN.LEFT):
    cell.text = ""
    p = cell.text_frame.paragraphs[0]
    p.text = str(text)
    p.font.size = Pt(size)
    p.font.bold = bold
    p.font.color.rgb = color
    p.font.name = "Calibri"
    p.alignment = align
    cell.vertical_anchor = MSO_ANCHOR.MIDDLE
    if bg:
        cell.fill.solid()
        cell.fill.fore_color.rgb = bg

# ══════════════════════════════════════════════════════
# SLIDE 1: TITEL
# ══════════════════════════════════════════════════════
s = prs.slides.add_slide(blank)
bg = s.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(0), Inches(0), W, H)
bg.fill.solid()
bg.fill.fore_color.rgb = NAVY
bg.line.fill.background()

# Accent line
line = s.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(1), Inches(2.8), Inches(2), Inches(0.06))
line.fill.solid()
line.fill.fore_color.rgb = ORANGE
line.line.fill.background()

t = s.shapes.add_textbox(Inches(1), Inches(1.5), Inches(10), Inches(1.3))
tf = t.text_frame
p = tf.paragraphs[0]
p.text = "PGS 15:2025 Compliance"
p.font.size = Pt(44)
p.font.bold = True
p.font.color.rgb = WHITE
p.font.name = "Calibri"

t2 = s.shapes.add_textbox(Inches(1), Inches(3.1), Inches(10), Inches(1.5))
tf2 = t2.text_frame
p2 = tf2.paragraphs[0]
p2.text = "Phoenix Metals — Pilot Plant Slag Chemicals"
p2.font.size = Pt(24)
p2.font.color.rgb = RGBColor(0xCC, 0xDD, 0xEE)
p2.font.name = "Calibri"
p3 = tf2.add_paragraph()
p3.text = "Management Presentatie  |  v5.0  |  6 mei 2026"
p3.font.size = Pt(16)
p3.font.color.rgb = RGBColor(0x99, 0xBB, 0xDD)
p3.font.name = "Calibri"
p3.space_before = Pt(12)

# Logo
if os.path.exists(LOGO):
    s.shapes.add_picture(LOGO, Inches(1), Inches(5.2), Inches(1.5), Inches(1.35))

# Footer on title
ft = s.shapes.add_textbox(Inches(1), Inches(6.8), Inches(8), Inches(0.4))
p4 = ft.text_frame.paragraphs[0]
p4.text = "JvG Consultancy  |  Safety • Governance • Advisory  |  © 2026"
p4.font.size = Pt(10)
p4.font.color.rgb = RGBColor(0x77, 0x99, 0xBB)
p4.font.name = "Calibri"

# ══════════════════════════════════════════════════════
# SLIDE 2: AGENDA
# ══════════════════════════════════════════════════════
s = prs.slides.add_slide(blank)
add_title_bar(s, "📋  Agenda")
add_logo(s)
add_footer(s)

agenda = [
    ("1", "🏗️", "Projectoverzicht & Procesflow"),
    ("2", "🧪", "Stoffeninventarisatie (20 stoffen)"),
    ("3", "🚛", "ADR-Classificatie & Niveaubepaling"),
    ("4", "🔒", "Scheidingsgroepen & Compatibiliteit"),
    ("5", "⚠️", "CMR-Stoffen & Maatregelen"),
    ("6", "🏭", "Opslagconfiguratie (Niveau C)"),
    ("7", "✅", "Compliance Status & Openstaand"),
    ("8", "🎯", "Aanbevelingen & Vervolgstappen"),
]

for i, (num, icon, text) in enumerate(agenda):
    y = Inches(1.6) + Inches(i * 0.65)
    # Number circle
    circ = s.shapes.add_shape(MSO_SHAPE.OVAL, Inches(1.2), y, Inches(0.45), Inches(0.45))
    circ.fill.solid()
    circ.fill.fore_color.rgb = NAVY
    circ.line.fill.background()
    ctf = circ.text_frame
    ctf.paragraphs[0].text = num
    ctf.paragraphs[0].font.size = Pt(14)
    ctf.paragraphs[0].font.bold = True
    ctf.paragraphs[0].font.color.rgb = WHITE
    ctf.paragraphs[0].alignment = PP_ALIGN.CENTER
    ctf.vertical_anchor = MSO_ANCHOR.MIDDLE

    tb = s.shapes.add_textbox(Inches(1.9), y, Inches(8), Inches(0.45))
    ptb = tb.text_frame
    ptb.paragraphs[0].text = f"{icon}  {text}"
    ptb.paragraphs[0].font.size = Pt(16)
    ptb.paragraphs[0].font.color.rgb = DARK_TEXT
    ptb.paragraphs[0].font.name = "Calibri"
    ptb.vertical_anchor = MSO_ANCHOR.MIDDLE

# ══════════════════════════════════════════════════════
# SLIDE 3: PROJECTOVERZICHT
# ══════════════════════════════════════════════════════
s = prs.slides.add_slide(blank)
add_title_bar(s, "🏗️  Projectoverzicht", "Pilot Plant Slag Chemicals — Procesflow")
add_logo(s)
add_footer(s)

# Process flow boxes
flow_data = [
    ("📥 INPUT\n(5 stoffen)", LIGHT_BLUE, Inches(0.8)),
    ("⚙️ PROCESSING\n(reacties)", LIGHT_ORANGE, Inches(3.6)),
    ("🔄 INTERMEDIAIREN\n(5 stoffen)", LIGHT_GREEN, Inches(6.4)),
    ("📦 EINDPRODUCTEN\n(10 stoffen)", RGBColor(0xDD, 0xDA, 0xFC), Inches(9.2)),
]

for label, color, x in flow_data:
    box = s.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, x, Inches(1.6), Inches(2.2), Inches(1.3))
    box.fill.solid()
    box.fill.fore_color.rgb = color
    box.line.color.rgb = NAVY
    box.line.width = Pt(1.5)
    tf = box.text_frame
    tf.word_wrap = True
    tf.vertical_anchor = MSO_ANCHOR.MIDDLE
    tf.paragraphs[0].text = label
    tf.paragraphs[0].font.size = Pt(13)
    tf.paragraphs[0].font.bold = True
    tf.paragraphs[0].font.color.rgb = NAVY
    tf.paragraphs[0].alignment = PP_ALIGN.CENTER

# Arrows between boxes
for ax in [Inches(3.05), Inches(5.85), Inches(8.65)]:
    arr = s.shapes.add_shape(MSO_SHAPE.RIGHT_ARROW, ax, Inches(2.0), Inches(0.5), Inches(0.4))
    arr.fill.solid()
    arr.fill.fore_color.rgb = ORANGE
    arr.line.fill.background()

# Key stats
stats = [
    ("20", "Stoffen\ntotaal"),
    ("8", "ADR-\ngeclassificeerd"),
    ("3", "CMR-\nstoffen"),
    ("C", "Opslag-\nniveau"),
]
for i, (num, label) in enumerate(stats):
    x = Inches(1.5) + Inches(i * 2.8)
    # Big number
    tb = s.shapes.add_textbox(x, Inches(3.4), Inches(2), Inches(0.8))
    tf = tb.text_frame
    tf.paragraphs[0].text = num
    tf.paragraphs[0].font.size = Pt(48)
    tf.paragraphs[0].font.bold = True
    tf.paragraphs[0].font.color.rgb = NAVY if num != "C" else ORANGE
    tf.paragraphs[0].font.name = "Calibri"
    tf.paragraphs[0].alignment = PP_ALIGN.CENTER
    # Label
    tb2 = s.shapes.add_textbox(x, Inches(4.2), Inches(2), Inches(0.8))
    tf2 = tb2.text_frame
    tf2.word_wrap = True
    tf2.paragraphs[0].text = label
    tf2.paragraphs[0].font.size = Pt(12)
    tf2.paragraphs[0].font.color.rgb = GRAY
    tf2.paragraphs[0].alignment = PP_ALIGN.CENTER

# Wbdbo callout
wb = s.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(4.5), Inches(5.4), Inches(4.5), Inches(0.9))
wb.fill.solid()
wb.fill.fore_color.rgb = LIGHT_ORANGE
wb.line.color.rgb = ORANGE
wb.line.width = Pt(2)
tf = wb.text_frame
tf.vertical_anchor = MSO_ANCHOR.MIDDLE
tf.paragraphs[0].text = "⏱️  Wbdbo: 60 minuten (hoogste流血ingsduur)"
tf.paragraphs[0].font.size = Pt(14)
tf.paragraphs[0].font.bold = True
tf.paragraphs[0].font.color.rgb = ORANGE
tf.paragraphs[0].alignment = PP_ALIGN.CENTER

# ══════════════════════════════════════════════════════
# SLIDE 4: STOFFENINVENTARISATIE
# ══════════════════════════════════════════════════════
s = prs.slides.add_slide(blank)
add_title_bar(s, "🧪  Stoffeninventarisatie", "20 stoffen — 3 procesfasen")
add_logo(s)
add_footer(s)

# Two tables side by side: Input (5) + Intermediates (5) on left, End Products (10) on right
# Left table
rows_l = 10
cols_l = 3
tbl_l = s.shapes.add_table(rows_l, cols_l, Inches(0.4), Inches(1.5), Inches(5.8), Inches(5.0)).table
tbl_l.columns[0].width = Inches(0.6)
tbl_l.columns[1].width = Inches(2.8)
tbl_l.columns[2].width = Inches(2.4)

set_cell(tbl_l.cell(0, 0), "#", 9, True, WHITE, NAVY, PP_ALIGN.CENTER)
set_cell(tbl_l.cell(0, 1), "Stof", 9, True, WHITE, NAVY)
set_cell(tbl_l.cell(0, 2), "Type / H-codes", 9, True, WHITE, NAVY)

input_data = [
    ("IC-01", "Steelmaking Slag", "Vast | H315, H318"),
    ("IC-02", "Sulfuric acid 25%", "Vst | ADR 8 | H314"),
    ("IC-03", "Hydrogen peroxide 30%", "Vst | ADR 5.1 | H318"),
    ("IC-04", "Sodium persulfate", "Vast | ADR 5.1 | H272"),
    ("IC-05", "Hydrochloric acid 20%", "Vst | ADR 8 | H314"),
]
inter_data = [
    ("IM-01", "CaSO₄ + SiO₂ (mix)", "Vast | Geen H-codes"),
    ("IM-02", "Na₂SO₄·10H₂O", "Vast | Geen H-codes"),
    ("IM-03", "Trisodium orthovanadate", "Vast | H302, H319"),
    ("IM-04", "Na-metavanadate ⚠️", "ADR 6.1 | H341, H361"),
]

for i, (num, name, info) in enumerate(input_data + inter_data):
    bg = LIGHT_BLUE if i < 5 else LIGHT_GREEN
    set_cell(tbl_l.cell(i+1, 0), num, 8, False, DARK_TEXT, bg, PP_ALIGN.CENTER)
    set_cell(tbl_l.cell(i+1, 1), name, 8, False, DARK_TEXT, bg)
    set_cell(tbl_l.cell(i+1, 2), info, 8, False, DARK_TEXT, bg)

# Right table - End products
rows_r = 11
cols_r = 3
tbl_r = s.shapes.add_table(rows_r, cols_r, Inches(6.5), Inches(1.5), Inches(6.3), Inches(5.0)).table
tbl_r.columns[0].width = Inches(0.6)
tbl_r.columns[1].width = Inches(2.8)
tbl_r.columns[2].width = Inches(2.9)

set_cell(tbl_r.cell(0, 0), "#", 9, True, WHITE, NAVY, PP_ALIGN.CENTER)
set_cell(tbl_r.cell(0, 1), "Eindproduct", 9, True, WHITE, NAVY)
set_cell(tbl_r.cell(0, 2), "Type / H-codes", 9, True, WHITE, NAVY)

ep_data = [
    ("EP-01", "Calcium hydroxide", "Vast | H315, H318"),
    ("EP-02", "Silica (amorphous)", "Vast | Geen H-codes"),
    ("EP-03", "Iron oxide (Fe₂O₃)", "Vast | Geen H-codes"),
    ("EP-04", "Manganese(IV) oxide", "Vast | H302, H373"),
    ("EP-05", "Magnesium hydroxide", "Vast | Geen H-codes"),
    ("EP-06", "Sodium aluminate (vst)", "ADR 8 | H314"),
    ("EP-07", "Sodium phosphate", "Vast | H315, H319"),
    ("EP-08", "V₂O₅ ⚠️ CMR", "ADR 6.1 | H350"),
    ("EP-09", "V-electrolyt ⚠️ CMR", "ADR 8 | H361"),
    ("EP-10", "—", "—"),
]

for i, (num, name, info) in enumerate(ep_data):
    bg_c = LIGHT_RED if "CMR" in name else RGBColor(0xDD, 0xDA, 0xFC)
    set_cell(tbl_r.cell(i+1, 0), num, 8, False, DARK_TEXT, bg_c, PP_ALIGN.CENTER)
    set_cell(tbl_r.cell(i+1, 1), name, 8, "CMR" in name, RED if "CMR" in name else DARK_TEXT, bg_c)
    set_cell(tbl_r.cell(i+1, 2), info, 8, False, DARK_TEXT, bg_c)

# Legend
lg = s.shapes.add_textbox(Inches(0.4), Inches(5.3), Inches(6), Inches(0.8))
tf = lg.text_frame
tf.word_wrap = True
tf.paragraphs[0].text = "🔵 Input  🟢 Intermediairen  🟣 Eindproducten  🔴 CMR-stoffen"
tf.paragraphs[0].font.size = Pt(10)
tf.paragraphs[0].font.color.rgb = GRAY

# ══════════════════════════════════════════════════════
# SLIDE 5: ADR CLASSIFICATIE
# ══════════════════════════════════════════════════════
s = prs.slides.add_slide(blank)
add_title_bar(s, "🚛  ADR-Classificatie & Niveaubepaling", "8 ADR-geclassificeerde stoffen")
add_logo(s)
add_footer(s)

rows = 9
cols = 6
tbl = s.shapes.add_table(rows, cols, Inches(0.5), Inches(1.5), Inches(12), Inches(4.0)).table
tbl.columns[0].width = Inches(2.5)
tbl.columns[1].width = Inches(1.5)
tbl.columns[2].width = Inches(1.5)
tbl.columns[3].width = Inches(1.5)
tbl.columns[4].width = Inches(2.5)
tbl.columns[5].width = Inches(2.5)

headers = ["Stof", "ADR Klasse", "UN Nr.", "VG", "Scheidings-\ngroep", "Niveau"]
for i, h in enumerate(headers):
    set_cell(tbl.cell(0, i), h, 10, True, WHITE, NAVY, PP_ALIGN.CENTER)

adr_data = [
    ("Sulfuric acid 25%", "8", "2796", "II", "SG2", "C"),
    ("Hydrogen peroxide 30%", "5.1(8)", "2014", "II", "SG5", "C"),
    ("Sodium persulfate", "5.1", "1505", "III", "SG5", "C"),
    ("Na-metavanadate", "6.1", "3285", "III", "SG4", "C"),
    ("Sodium aluminate", "8", "1819", "II", "SG2", "C"),
    ("V₂O₅", "6.1", "2862", "III", "SG4", "C"),
    ("V-electrolyt", "8", "2796", "II", "SG2", "C"),
    ("HCl 20%", "8", "1789", "II", "SG2", "C"),
]

for i, (name, klasse, un, vg, sg, niv) in enumerate(adr_data):
    bg = LIGHT_BLUE if i % 2 == 0 else WHITE
    set_cell(tbl.cell(i+1, 0), name, 10, "V₂O₅" in name or "metavanadate" in name, DARK_TEXT, bg)
    set_cell(tbl.cell(i+1, 1), klasse, 10, False, DARK_TEXT, bg, PP_ALIGN.CENTER)
    set_cell(tbl.cell(i+1, 2), un, 10, False, DARK_TEXT, bg, PP_ALIGN.CENTER)
    set_cell(tbl.cell(i+1, 3), vg, 10, False, DARK_TEXT, bg, PP_ALIGN.CENTER)
    set_cell(tbl.cell(i+1, 4), sg, 10, False, DARK_TEXT, bg, PP_ALIGN.CENTER)
    # Niveau with emphasis
    set_cell(tbl.cell(i+1, 5), f"🔴 {niv}", 12, True, RED, bg, PP_ALIGN.CENTER)

# Callout wbdbo
wb = s.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(3), Inches(5.8), Inches(7), Inches(0.8))
wb.fill.solid()
wb.fill.fore_color.rgb = LIGHT_ORANGE
wb.line.color.rgb = ORANGE
wb.line.width = Pt(2)
tf = wb.text_frame
tf.vertical_anchor = MSO_ANCHOR.MIDDLE
tf.paragraphs[0].text = "⏱️  Wbdbo = 60 min (V₂O₅, poeder)  →  Bepalend voor Niveau C"
tf.paragraphs[0].font.size = Pt(14)
tf.paragraphs[0].font.bold = True
tf.paragraphs[0].font.color.rgb = ORANGE
tf.paragraphs[0].alignment = PP_ALIGN.CENTER

# ══════════════════════════════════════════════════════
# SLIDE 6: SCHEIDINGSGROEPEN
# ══════════════════════════════════════════════════════
s = prs.slides.add_slide(blank)
add_title_bar(s, "🔒  Scheidingsgroepen & Compatibiliteit", "PGS 15:2025 Tabel 9 — 3 groepen geïdentificeerd")
add_logo(s)
add_footer(s)

# 3 visual boxes for SG groups
sg_data = [
    ("SG2 — Zuren & Basen", "Sulfuric acid 25%\nNa-aluminate\nV-electrolyt\nHCl 20%", LIGHT_BLUE, "4 stoffen"),
    ("SG4 — Giftig", "Na-metavanadate ⚠️\nV₂O₅ ⚠️ CMR", LIGHT_RED, "2 stoffen"),
    ("SG5 — Oxiderend", "H₂O₂ 30%\nSodium persulfate", LIGHT_ORANGE, "2 stoffen"),
]

for i, (title, content, color, count) in enumerate(sg_data):
    x = Inches(0.5) + Inches(i * 4.2)
    box = s.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, x, Inches(1.5), Inches(3.8), Inches(2.8))
    box.fill.solid()
    box.fill.fore_color.rgb = color
    box.line.color.rgb = NAVY
    box.line.width = Pt(2)
    tf = box.text_frame
    tf.word_wrap = True
    tf.margin_left = Inches(0.2)
    tf.margin_top = Inches(0.15)
    tf.paragraphs[0].text = title
    tf.paragraphs[0].font.size = Pt(14)
    tf.paragraphs[0].font.bold = True
    tf.paragraphs[0].font.color.rgb = NAVY
    p2 = tf.add_paragraph()
    p2.text = content
    p2.font.size = Pt(11)
    p2.font.color.rgb = DARK_TEXT
    p2.space_before = Pt(8)
    p3 = tf.add_paragraph()
    p3.text = f"\n📦 {count}"
    p3.font.size = Pt(10)
    p3.font.color.rgb = GRAY

# Conflict callout
conf = s.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(1), Inches(4.7), Inches(11), Inches(1.0))
conf.fill.solid()
conf.fill.fore_color.rgb = LIGHT_RED
conf.line.color.rgb = RED
conf.line.width = Pt(2)
tf = conf.text_frame
tf.word_wrap = True
tf.vertical_anchor = MSO_ANCHOR.MIDDLE
tf.paragraphs[0].text = "⚠️  CONFLICTPAAR: SG2 (zuren) ✕ SG5 (oxiderend) — Sterke fysieke scheiding vereist!"
tf.paragraphs[0].font.size = Pt(14)
tf.paragraphs[0].font.bold = True
tf.paragraphs[0].font.color.rgb = RED
tf.paragraphs[0].alignment = PP_ALIGN.CENTER
p2 = tf.add_paragraph()
p2.text = "SG2 en SG4 compatibel met voorwaarden  |  SG4 en SG5 compatibel met voorwaarden  |  SG2 ✕ SG5 = NIET compatibel"
p2.font.size = Pt(10)
p2.font.color.rgb = DARK_TEXT
p2.alignment = PP_ALIGN.CENTER

# ══════════════════════════════════════════════════════
# SLIDE 7: CMR-STOFFEN (RODE ACHTERGROND!)
# ══════════════════════════════════════════════════════
s = prs.slides.add_slide(blank)
# Red background
bg = s.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(0), Inches(0), W, H)
bg.fill.solid()
bg.fill.fore_color.rgb = RGBColor(0x7F, 0x1D, 0x1D)
bg.line.fill.background()

# Title
t = s.shapes.add_textbox(Inches(0.5), Inches(0.3), Inches(10), Inches(1))
tf = t.text_frame
tf.paragraphs[0].text = "⚠️  CMR-STOFFEN — CARCINOGEEN / MUTAGEEN / REPRODUCTIETOXISCH"
tf.paragraphs[0].font.size = Pt(26)
tf.paragraphs[0].font.bold = True
tf.paragraphs[0].font.color.rgb = WHITE
tf.paragraphs[0].font.name = "Calibri"

if os.path.exists(LOGO):
    s.shapes.add_picture(LOGO, W - Inches(1.8), Inches(0.15), Inches(1.5), Inches(1.35))

# V2O5 - BIG callout
vbox = s.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(0.5), Inches(1.5), Inches(6), Inches(2.0))
vbox.fill.solid()
vbox.fill.fore_color.rgb = RGBColor(0xDC, 0x26, 0x26)
vbox.line.color.rgb = WHITE
vbox.line.width = Pt(3)
tf = vbox.text_frame
tf.word_wrap = True
tf.margin_left = Inches(0.3)
tf.paragraphs[0].text = "🔴 V₂O₅ (Vanadium pentoxide)"
tf.paragraphs[0].font.size = Pt(20)
tf.paragraphs[0].font.bold = True
tf.paragraphs[0].font.color.rgb = WHITE
p2 = tf.add_paragraph()
p2.text = "Carc. 1B (H350) — KANKERVERWEKKEND"
p2.font.size = Pt(18)
p2.font.bold = True
p2.font.color.rgb = RGBColor(0xFF, 0xEB, 0xEB)
p3 = tf.add_paragraph()
p3.text = "Muta. 2 | Repr. 2 | Lact. | ADR 6.1/III"
p3.font.size = Pt(12)
p3.font.color.rgb = RGBColor(0xFF, 0xCC, 0xCC)

# Right side: other CMR
na_box = s.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(7), Inches(1.5), Inches(5.5), Inches(1.0))
na_box.fill.solid()
na_box.fill.fore_color.rgb = RGBColor(0x99, 0x1B, 0x1B)
na_box.line.color.rgb = RGBColor(0xFF, 0xAA, 0xAA)
tf = na_box.text_frame
tf.word_wrap = True
tf.margin_left = Inches(0.2)
tf.paragraphs[0].text = "🟠 Na-metavanadate — Muta. 2 (H341), Repr. 2 (H361fd)"
tf.paragraphs[0].font.size = Pt(13)
tf.paragraphs[0].font.bold = True
tf.paragraphs[0].font.color.rgb = WHITE

ve_box = s.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(7), Inches(2.7), Inches(5.5), Inches(0.8))
ve_box.fill.solid()
ve_box.fill.fore_color.rgb = RGBColor(0x99, 0x1B, 0x1B)
ve_box.line.color.rgb = RGBColor(0xFF, 0xAA, 0xAA)
tf = ve_box.text_frame
tf.word_wrap = True
tf.margin_left = Inches(0.2)
tf.paragraphs[0].text = "🟠 V-electrolyt — Repr. 2 (H361)"
tf.paragraphs[0].font.size = Pt(13)
tf.paragraphs[0].font.bold = True
tf.paragraphs[0].font.color.rgb = WHITE

# Maatregelen table
rows = 5
cols = 2
tbl = s.shapes.add_table(rows, cols, Inches(0.5), Inches(4.0), Inches(12), Inches(2.3)).table
tbl.columns[0].width = Inches(3.5)
tbl.columns[1].width = Inches(8.5)

set_cell(tbl.cell(0, 0), "⚠️ Maatregel", 11, True, WHITE, RGBColor(0x99, 0x1B, 0x1B), PP_ALIGN.CENTER)
set_cell(tbl.cell(0, 1), "Toelichting", 11, True, WHITE, RGBColor(0x99, 0x1B, 0x1B))

maatregelen = [
    ("Gesloten opslag + LEV", "Volledige insluiting met lokale afzuiging (PGS 15 §5.3)"),
    ("PBM: type A filter", "Minimaal P3 masker + handschoenen + veiligheidsbril"),
    ("ADR 6.1 separaat", "SG4-stoffen fysiek gescheiden van SG2/SG5"),
    ("Wbdbo 60 min + CMR", "Niveau C + ARBO-blootstellingslimieten"),
]
for i, (m, u) in enumerate(maatregelen):
    bg = RGBColor(0x4A, 0x14, 0x14) if i % 2 == 0 else RGBColor(0x5A, 0x1E, 0x1E)
    set_cell(tbl.cell(i+1, 0), m, 10, True, WHITE, bg)
    set_cell(tbl.cell(i+1, 1), u, 10, False, RGBColor(0xFF, 0xDD, 0xDD), bg)

# ══════════════════════════════════════════════════════
# SLIDE 8: OPSLAGCONFIGURATIE
# ══════════════════════════════════════════════════════
s = prs.slides.add_slide(blank)
add_title_bar(s, "🏭  Opslagconfiguratie — Niveau C", "3 opslagvakken — floorplan indeling")
add_logo(s)
add_footer(s)

# 3 storage compartments as floorplan boxes
vakken = [
    ("VAK 1: SG2 — Zuren/Basen", "🧪", LIGHT_BLUE, NAVY,
     "• Sulfuric acid 25%\n• Na-aluminate oplossing\n• V-electrolyt\n• HCl 20%\n\nEisen: Wbdbo 60 min, LEV, vloeistofdichte vloer"),
    ("VAK 2: SG4 — Giftig", "☠️", LIGHT_RED, RED,
     "• Na-metavanadate\n• V₂O₅ (Carc. 1B)\n\nEisen: Gesloten systeem, P3-masker, CMR-regime, wbdbo 60 min"),
    ("VAK 3: SG5 — Oxiderend", "🔥", LIGHT_ORANGE, ORANGE,
     "• H₂O₂ 30%\n• Sodium persulfate\n\nEisen: Brandwerend 60 min, gescheiden van SG2, temperatuurcontrole"),
]

for i, (title, icon, color, border_c, content) in enumerate(vakken):
    x = Inches(0.3) + Inches(i * 4.3)
    box = s.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, x, Inches(1.5), Inches(4.0), Inches(4.2))
    box.fill.solid()
    box.fill.fore_color.rgb = color
    box.line.color.rgb = border_c
    box.line.width = Pt(3)
    tf = box.text_frame
    tf.word_wrap = True
    tf.margin_left = Inches(0.2)
    tf.margin_top = Inches(0.15)
    tf.paragraphs[0].text = f"{icon}  {title}"
    tf.paragraphs[0].font.size = Pt(13)
    tf.paragraphs[0].font.bold = True
    tf.paragraphs[0].font.color.rgb = border_c
    p2 = tf.add_paragraph()
    p2.text = content
    p2.font.size = Pt(10)
    p2.font.color.rgb = DARK_TEXT
    p2.space_before = Pt(10)

# General requirements
gen = s.shapes.add_shape(MSO_SHAPE.ROUNDED_RECTANGLE, Inches(0.3), Inches(5.9), Inches(12.7), Inches(0.8))
gen.fill.solid()
gen.fill.fore_color.rgb = LIGHT_BLUE
gen.line.color.rgb = NAVY
gen.line.width = Pt(1.5)
tf = gen.text_frame
tf.vertical_anchor = MSO_ANCHOR.MIDDLE
tf.paragraphs[0].text = "📋  Algemeen: Wbdbo 60 min | Stapelhoogte ≤ 3m | Ventilatie ≥ 6 luchtverv./uur | Nooddouche + oogdouches | Brandblussysteem"
tf.paragraphs[0].font.size = Pt(11)
tf.paragraphs[0].font.bold = True
tf.paragraphs[0].font.color.rgb = NAVY
tf.paragraphs[0].alignment = PP_ALIGN.CENTER

# ══════════════════════════════════════════════════════
# SLIDE 9: COMPLIANCE STATUS
# ══════════════════════════════════════════════════════
s = prs.slides.add_slide(blank)
add_title_bar(s, "✅  Compliance Status", "Verkeerslicht-overzicht — PGS 15:2025")
add_logo(s)
add_footer(s)

rows = 9
cols = 4
tbl = s.shapes.add_table(rows, cols, Inches(0.8), Inches(1.5), Inches(11.5), Inches(4.2)).table
tbl.columns[0].width = Inches(3.5)
tbl.columns[1].width = Inches(2)
tbl.columns[2].width = Inches(3.5)
tbl.columns[3].width = Inches(2.5)

set_cell(tbl.cell(0, 0), "Aspect", 11, True, WHITE, NAVY, PP_ALIGN.CENTER)
set_cell(tbl.cell(0, 1), "Status", 11, True, WHITE, NAVY, PP_ALIGN.CENTER)
set_cell(tbl.cell(0, 2), "Toelichting", 11, True, WHITE, NAVY)
set_cell(tbl.cell(0, 3), "Actie", 11, True, WHITE, NAVY, PP_ALIGN.CENTER)

compliance = [
    ("ADR-classificatie", "🟢", "Alle 8 stoffen geclassificeerd", "Afgerond"),
    ("Niveaubepaling (C)", "🟢", "Wbdbo 60 min → Niveau C bepaald", "Afgerond"),
    ("Scheidingsgroepen", "🟢", "SG2, SG4, SG5 geïdentificeerd", "Afgerond"),
    ("SDS-beschikbaarheid", "🟡", "19/20 SDS beschikbaar", "HCl 20% ontbreekt"),
    ("CMR-registratie", "🟢", "3 CMR-stoffen geïdentificeerd", "Afgerond"),
    ("Opslagplan (Niveau C)", "🟡", "3 vakken ontworpen", "Bouwkundig uitwerken"),
    ("List of chemicals check", "🟡", "3 correcties nodig", "Bijwerken document"),
    ("PBM-maatregelen", "🟢", "Type A filter + P3 voorgeschreven", "Afgerond"),
]

status_colors = {"🟢": LIGHT_GREEN, "🟡": RGBColor(0xFF, 0xF7, 0xED), "🔴": LIGHT_RED}

for i, (aspect, status, note, actie) in enumerate(compliance):
    bg = status_colors.get(status, WHITE)
    set_cell(tbl.cell(i+1, 0), aspect, 10, False, DARK_TEXT, bg)
    set_cell(tbl.cell(i+1, 1), status, 16, False, DARK_TEXT, bg, PP_ALIGN.CENTER)
    set_cell(tbl.cell(i+1, 2), note, 10, False, DARK_TEXT, bg)
    set_cell(tbl.cell(i+1, 3), actie, 10, "ontbreekt" in actie or "nodig" in actie, 
             RED if "ontbreekt" in actie else ORANGE if "nodig" in actie else DARK_TEXT, bg, PP_ALIGN.CENTER)

# Summary
sm = s.shapes.add_textbox(Inches(0.8), Inches(6.0), Inches(11), Inches(0.6))
sm.text_frame.paragraphs[0].text = "📊  Score: 5/8 volledig groen  |  3/8 openstaand (allemaal actiebaar)  |  Geen rode blokkades"
sm.text_frame.paragraphs[0].font.size = Pt(13)
sm.text_frame.paragraphs[0].font.bold = True
sm.text_frame.paragraphs[0].font.color.rgb = NAVY

# ══════════════════════════════════════════════════════
# SLIDE 10: AANBEVELINGEN
# ══════════════════════════════════════════════════════
s = prs.slides.add_slide(blank)
add_title_bar(s, "🎯  Top 5 Aanbevelingen", "Prioriteit: Hoog → Laag")
add_logo(s)
add_footer(s)

aanbevelingen = [
    ("1", "🔴", "SDS HCl 20% aanvragen", "Ontbrekende SDS ophalen bij leverancier — verplicht per REACH Art. 31"),
    ("2", "🟠", "List of chemicals bijwerken", "H341, H290, H411 correcties doorvoeren in masterdocument"),
    ("3", "🟠", "Bouwkundig ontwerp Niveau C", "Wbdbo 60 min specificatie laten uitwerken door bouwkundig adviseur"),
    ("4", "🔵", "CMR-exposuringsprotocol", "Formeel arbobeleid voor V₂O₅ (Carc. 1B) inclusief blootstellingsmeting"),
    ("5", "🔵", "Oefenplan gevaarlijke stoffen", "Jaarlijkse BHV-oefening inclusief lekkage H₂SO₄ en HCl scenario's"),
]

for i, (num, icon, title, desc) in enumerate(aanbevelingen):
    y = Inches(1.5) + Inches(i * 1.05)
    
    # Number
    circ = s.shapes.add_shape(MSO_SHAPE.OVAL, Inches(0.8), y + Inches(0.05), Inches(0.5), Inches(0.5))
    circ.fill.solid()
    circ.fill.fore_color.rgb = NAVY
    circ.line.fill.background()
    ctf = circ.text_frame
    ctf.paragraphs[0].text = num
    ctf.paragraphs[0].font.size = Pt(16)
    ctf.paragraphs[0].font.bold = True
    ctf.paragraphs[0].font.color.rgb = WHITE
    ctf.paragraphs[0].alignment = PP_ALIGN.CENTER
    ctf.vertical_anchor = MSO_ANCHOR.MIDDLE
    
    # Content
    tb = s.shapes.add_textbox(Inches(1.5), y, Inches(10.5), Inches(0.9))
    tf = tb.text_frame
    tf.word_wrap = True
    tf.paragraphs[0].text = f"{icon}  {title}"
    tf.paragraphs[0].font.size = Pt(16)
    tf.paragraphs[0].font.bold = True
    tf.paragraphs[0].font.color.rgb = DARK_TEXT
    tf.paragraphs[0].font.name = "Calibri"
    p2 = tf.add_paragraph()
    p2.text = desc
    p2.font.size = Pt(11)
    p2.font.color.rgb = GRAY
    p2.font.name = "Calibri"

# ══════════════════════════════════════════════════════
# SLIDE 11: VERVOLGSTAPPEN
# ══════════════════════════════════════════════════════
s = prs.slides.add_slide(blank)
add_title_bar(s, "🗺️  Vervolgstappen — Roadmap", "Timeline naar volledige PGS 15 compliance")
add_logo(s)
add_footer(s)

steps = [
    ("WK 20", "SDS HCl 20% opvragen", "🟢"),
    ("WK 20", "List of chemicals corrigeren", "🟢"),
    ("WK 21", "Bouwkundig adviseur briefen", "🔵"),
    ("WK 22", "Ontwerp Niveau C vakken", "🔵"),
    ("WK 23", "CMR-exposureringsplan opstellen", "🟠"),
    ("WK 24", "PBM-beleid formuleren", "🟠"),
    ("WK 25", "BHV-oefenplan goedkeuren", "🔵"),
    ("WK 26", "Eindreview + oplevering", "🔴"),
]

for i, (wk, taak, status) in enumerate(steps):
    y = Inches(1.5) + Inches(i * 0.68)
    # Timeline dot
    dot = s.shapes.add_shape(MSO_SHAPE.OVAL, Inches(1.5), y + Inches(0.08), Inches(0.25), Inches(0.25))
    dot.fill.solid()
    dot.fill.fore_color.rgb = NAVY
    dot.line.fill.background()
    
    # Connecting line (except last)
    if i < len(steps) - 1:
        ln = s.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(1.58), y + Inches(0.33), Inches(0.09), Inches(0.43))
        ln.fill.solid()
        ln.fill.fore_color.rgb = RGBColor(0xBB, 0xCC, 0xDD)
        ln.line.fill.background()
    
    # Week
    tb1 = s.shapes.add_textbox(Inches(2.0), y, Inches(1.2), Inches(0.4))
    tb1.text_frame.paragraphs[0].text = wk
    tb1.text_frame.paragraphs[0].font.size = Pt(12)
    tb1.text_frame.paragraphs[0].font.bold = True
    tb1.text_frame.paragraphs[0].font.color.rgb = NAVY
    
    # Task
    tb2 = s.shapes.add_textbox(Inches(3.5), y, Inches(6), Inches(0.4))
    tb2.text_frame.paragraphs[0].text = taak
    tb2.text_frame.paragraphs[0].font.size = Pt(13)
    tb2.text_frame.paragraphs[0].font.color.rgb = DARK_TEXT
    
    # Status
    tb3 = s.shapes.add_textbox(Inches(10), y, Inches(1.5), Inches(0.4))
    tb3.text_frame.paragraphs[0].text = status
    tb3.text_frame.paragraphs[0].font.size = Pt(14)
    tb3.text_frame.paragraphs[0].alignment = PP_ALIGN.CENTER

# ══════════════════════════════════════════════════════
# SLIDE 12: AFSLUITING
# ══════════════════════════════════════════════════════
s = prs.slides.add_slide(blank)
bg = s.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(0), Inches(0), W, H)
bg.fill.solid()
bg.fill.fore_color.rgb = NAVY
bg.line.fill.background()

# Accent line
line = s.shapes.add_shape(MSO_SHAPE.RECTANGLE, Inches(4.5), Inches(2.8), Inches(4), Inches(0.06))
line.fill.solid()
line.fill.fore_color.rgb = ORANGE
line.line.fill.background()

t = s.shapes.add_textbox(Inches(1), Inches(2.0), Inches(11), Inches(1))
tf = t.text_frame
tf.paragraphs[0].text = "Vragen?"
tf.paragraphs[0].font.size = Pt(52)
tf.paragraphs[0].font.bold = True
tf.paragraphs[0].font.color.rgb = WHITE
tf.paragraphs[0].font.name = "Calibri"
tf.paragraphs[0].alignment = PP_ALIGN.CENTER

t2 = s.shapes.add_textbox(Inches(1), Inches(3.5), Inches(11), Inches(1.5))
tf2 = t2.text_frame
tf2.paragraphs[0].text = "PGS 15:2025 Compliance — Phoenix Metals Pilot Plant"
tf2.paragraphs[0].font.size = Pt(18)
tf2.paragraphs[0].font.color.rgb = RGBColor(0xCC, 0xDD, 0xEE)
tf2.paragraphs[0].alignment = PP_ALIGN.CENTER
p2 = tf2.add_paragraph()
p2.text = "Versie 5.0  |  6 mei 2026"
p2.font.size = Pt(14)
p2.font.color.rgb = RGBColor(0x99, 0xBB, 0xDD)
p2.alignment = PP_ALIGN.CENTER

# Logo
if os.path.exists(LOGO):
    s.shapes.add_picture(LOGO, Inches(5.9), Inches(5.0), Inches(1.5), Inches(1.35))

ft = s.shapes.add_textbox(Inches(1), Inches(6.6), Inches(11), Inches(0.5))
ft.text_frame.paragraphs[0].text = "JvG Consultancy  |  Safety • Governance • Advisory  |  © 2026"
ft.text_frame.paragraphs[0].font.size = Pt(12)
ft.text_frame.paragraphs[0].font.color.rgb = RGBColor(0x77, 0x99, 0xBB)
ft.text_frame.paragraphs[0].alignment = PP_ALIGN.CENTER

# ── SAVE ──
os.makedirs(os.path.dirname(OUT), exist_ok=True)
prs.save(OUT)
print(f"✅ Saved: {OUT}")
