root = Card([header, oeeSection, productionLinesSection, chartsRow1, chartsRow2, inventoryRow, maintenanceRow, qualityRow, energyWorkOrdersRow, scheduleMaintenanceForm, andonAlerts, exportButton], "card", "column", "l")

header = CardHeader("Factory Floor Supervisor Console", "Live production overview — Shift A active")

oeeSection = Card([oeeTitle, oeeGrid], "sunk", "row", "l", "center", "between")
oeeTitle = Heading("Overall Equipment Effectiveness", "h3")
oeeGrid = Card([oeeAvailability, oeePerformance, oeeQuality, oeeOverall], "clear", "row", "m", "center", "around")
oeeAvailability = Card([availLabel, availValue], "card", "column", "xs", "center")
availLabel = TextContent("Availability", "small")
availValue = TextContent("92.4%", "large-heavy")
oeePerformance = Card([perfLabel, perfValue], "card", "column", "xs", "center")
perfLabel = TextContent("Performance", "small")
perfValue = TextContent("95.1%", "large-heavy")
oeeQuality = Card([qualLabel, qualValue], "card", "column", "xs", "center")
qualLabel = TextContent("Quality", "small")
qualValue = TextContent("98.7%", "large-heavy")
oeeOverall = Card([overallLabel, overallValue], "card", "column", "xs", "center")
overallLabel = TextContent("OEE", "small")
overallValue = TextContent("86.8%", "large-heavy")

productionLinesSection = Card([linesHeader, lineTabs], "sunk", "column", "m")
linesHeader = Card([linesTitle, lineFocusSelect], "clear", "row", "m", "center", "between")
linesTitle = Heading("Production Lines", "h3")
lineFocusSelect = Select("line-focus", lineFocusOptions, "Focus on line…", null, "small")
lineFocusOptions = [focusAll, focusLine1, focusLine2, focusLine3, focusLine4]
focusAll = SelectItem("all", "All Lines")
focusLine1 = SelectItem("line-1", "Line 1 — Assembly")
focusLine2 = SelectItem("line-2", "Line 2 — Molding")
focusLine3 = SelectItem("line-3", "Line 3 — Finishing")
focusLine4 = SelectItem("line-4", "Line 4 — Packaging")
lineTabs = Tabs([tabAll, tabLine1, tabLine2, tabLine3, tabLine4])
tabAll = TabItem("all", "All Lines", [linesTableAll])
tabLine1 = TabItem("line-1", "Line 1", [line1Detail])
tabLine2 = TabItem("line-2", "Line 2", [line2Detail])
tabLine3 = TabItem("line-3", "Line 3", [line3Detail])
tabLine4 = TabItem("line-4", "Line 4", [line4Detail])
linesTableAll = Table([lineCol, rateCol, statusCol, targetCol, actualCol, oeeCol])
lineCol = Col("Line", ["Line 1 — Assembly", "Line 2 — Molding", "Line 3 — Finishing", "Line 4 — Packaging"])
rateCol = Col("Rate (units/hr)", [420, 380, 310, 450])
statusCol = Col("Status", ["Running", "Running", "Setup", "Running"])
targetCol = Col("Target Today", [3200, 2800, 2400, 3600])
actualCol = Col("Actual", [2980, 2650, 1800, 3420])
oeeCol = Col("OEE", ["89%", "91%", "82%", "88%"])
line1Detail = Card([line1Cards], "clear", "row", "m")
line1Cards = [line1Rate, line1Status, line1Target, line1OEE]
line1Rate = Card([TextContent("Rate", "small"), TextContent("420 units/hr", "large-heavy")], "card", "column", "xs", "center")
line1Status = Card([TextContent("Status", "small"), Tag("Running", null, null, "success")], "card", "column", "xs", "center")
line1Target = Card([TextContent("Target", "small"), TextContent("3,200 units", "large-heavy")], "card", "column", "xs", "center")
line1OEE = Card([TextContent("OEE", "small"), TextContent("89%", "large-heavy")], "card", "column", "xs", "center")
line2Detail = Card([line2Cards], "clear", "row", "m")
line2Cards = [line2Rate, line2Status, line2Target, line2OEE]
line2Rate = Card([TextContent("Rate", "small"), TextContent("380 units/hr", "large-heavy")], "card", "column", "xs", "center")
line2Status = Card([TextContent("Status", "small"), Tag("Running", null, null, "success")], "card", "column", "xs", "center")
line2Target = Card([TextContent("Target", "small"), TextContent("2,800 units", "large-heavy")], "card", "column", "xs", "center")
line2OEE = Card([TextContent("OEE", "small"), TextContent("91%", "large-heavy")], "card", "column", "xs", "center")
line3Detail = Card([line3Cards], "clear", "row", "m")
line3Cards = [line3Rate, line3Status, line3Target, line3OEE]
line3Rate = Card([TextContent("Rate", "small"), TextContent("310 units/hr", "large-heavy")], "card", "column", "xs", "center")
line3Status = Card([TextContent("Status", "small"), Tag("Setup", null, null, "warning")], "card", "column", "xs", "center")
line3Target = Card([TextContent("Target", "small"), TextContent("2,400 units", "large-heavy")], "card", "column", "xs", "center")
line3OEE = Card([TextContent("OEE", "small"), TextContent("82%", "large-heavy")], "card", "column", "xs", "center")
line4Detail = Card([line4Cards], "clear", "row", "m")
line4Cards = [line4Rate, line4Status, line4Target, line4OEE]
line4Rate = Card([TextContent("Rate", "small"), TextContent("450 units/hr", "large-heavy")], "card", "column", "xs", "center")
line4Status = Card([TextContent("Status", "small"), Tag("Running", null, null, "success")], "card", "column", "xs", "center")
line4Target = Card([TextContent("Target", "small"), TextContent("3,600 units", "large-heavy")], "card", "column", "xs", "center")
line4OEE = Card([TextContent("OEE", "small"), TextContent("88%", "large-heavy")], "card", "column", "xs", "center")

chartsRow1 = Card([defectChartCard, downtimeChartCard], "sunk", "row", "l")
defectChartCard = Card([defectTitle, defectChart], "card", "column", "m")
defectTitle = Heading("Defect Rate — Past 30 Days", "h3")
defectChart = LineChart(defectLabels, [defectSeries], "natural", "Day", "Defect Rate %")
defectLabels = ["Day 1", "Day 2", "Day 3", "Day 4", "Day 5", "Day 6", "Day 7", "Day 8", "Day 9", "Day 10", "Day 11", "Day 12", "Day 13", "Day 14", "Day 15", "Day 16", "Day 17", "Day 18", "Day 19", "Day 20", "Day 21", "Day 22", "Day 23", "Day 24", "Day 25", "Day 26", "Day 27", "Day 28", "Day 29", "Day 30"]
defectSeries = Series("Defect Rate %", [2.1, 1.8, 2.3, 1.9, 2.0, 1.7, 1.6, 2.2, 1.9, 1.8, 2.1, 2.0, 1.9, 1.7, 1.6, 1.8, 2.0, 1.9, 1.7, 1.6, 1.5, 1.8, 1.9, 1.7, 1.6, 1.5, 1.4, 1.6, 1.5, 1.4])
downtimeChartCard = Card([downtimeTitle, downtimeChart], "card", "column", "m")
downtimeTitle = Heading("Downtime by Cause — This Month", "h3")
downtimeChart = PieChart(downtimeLabels, downtimeValues, "donut")
downtimeLabels = ["Mechanical", "Electrical", "Material", "Setup/Changeover", "Planned Maintenance", "Other"]
downtimeValues = [42, 28, 15, 8, 5, 2]

chartsRow2 = Card([shiftChartCard, unitsTargetCard], "sunk", "row", "l")
shiftChartCard = Card([shiftTitle, shiftChart], "card", "column", "m")
shiftTitle = Heading("Shift Output Comparison", "h3")
shiftChart = BarChart(shiftLabels, [shiftSeries], "grouped", "Shift", "Units Produced")
shiftLabels = ["Shift A", "Shift B", "Shift C"]
shiftSeries = Series("Units", [12450, 11800, 9200])
unitsTargetCard = Card([unitsTitle, unitsProgress, unitsDetail], "card", "column", "m")
unitsTitle = Heading("Units Produced vs Target Today", "h3")
unitsProgress = Progress(87, "10,430 / 12,000 units (87%)")
unitsDetail = TextContent("Target: 12,000  •  Current pace: 11,850 projected", "small")

inventoryRow = Card([stockCard, supplierCard], "sunk", "row", "l")
stockCard = Card([stockTitle, stockTable], "card", "column", "m")
stockTitle = Heading("Raw Material Stock", "h3")
stockTable = Table([materialCol, currentCol, minCol, maxCol, daysCol])
materialCol = Col("Material", ["Steel (coils)", "Resin (tons)", "Packaging (pallets)"])
currentCol = Col("Current", [42, 18, 85])
minCol = Col("Min", [20, 8, 40])
maxCol = Col("Max", [60, 25, 120])
daysCol = Col("Days Cover", [6, 5, 7])
supplierCard = Card([supplierTitle, supplierTable], "card", "column", "m")
supplierTitle = Heading("Supplier Deliveries Due This Week", "h3")
supplierTable = Table([supplierCol, materialDelCol, qtyCol, dueCol, statusDelCol])
supplierCol = Col("Supplier", ["Apex Metals", "PolySource", "PackWell", "Apex Metals", "PolySource"])
materialDelCol = Col("Material", ["Steel", "Resin", "Packaging", "Steel", "Resin"])
qtyCol = Col("Qty", [20, 10, 35, 15, 8])
dueCol = Col("Due Date", ["Mon 12/16", "Tue 12/17", "Wed 12/18", "Thu 12/19", "Fri 12/20"])
statusDelCol = Col("Status", ["Confirmed", "Confirmed", "Pending", "Confirmed", "At Risk"])

maintenanceRow = Card([maintTitle, maintTable], "sunk", "column", "m")
maintTitle = Heading("Machines Due for Maintenance", "h3")
maintTable = Table([machineCol, lineMaintCol, lastMaintCol, nextDueCol, priorityCol])
machineCol = Col("Machine", ["ASM-01", "MOLD-03", "FIN-02", "PKG-04", "ASM-02"])
lineMaintCol = Col("Line", ["Line 1", "Line 2", "Line 3", "Line 4", "Line 1"])
lastMaintCol = Col("Last Service", ["2024-10-15", "2024-10-20", "2024-10-10", "2024-10-25", "2024-10-18"])
nextDueCol = Col("Next Due", ["2024-12-15", "2024-12-18", "2024-12-14", "2024-12-22", "2024-12-16"])
priorityCol = Col("Priority", ["High", "Medium", "High", "Low", "Medium"])

qualityRow = Card([qualityTitle, qualityTable], "sunk", "column", "m")
qualityTitle = Heading("Batches on Quality Hold", "h3")
qualityTable = Table([batchCol, lineQualCol, reasonCol, qtyHoldCol, sinceCol])
batchCol = Col("Batch", ["B-20241214-003", "B-20241214-007", "B-20241213-012"])
lineQualCol = Col("Line", ["Line 2", "Line 3", "Line 1"])
reasonCol = Col("Reason", ["Dimensional variance", "Surface finish", "Weight out of spec"])
qtyHoldCol = Col("Qty Held", [150, 80, 200])
sinceCol = Col("Since", ["2024-12-14 06:30", "2024-12-14 10:15", "2024-12-13 22:00"])

energyWorkOrdersRow = Card([energyCard, workOrdersCard], "sunk", "row", "l")
energyCard = Card([energyTitle, energyValue, energyDetail], "card", "column", "m")
energyTitle = Heading("Energy Use Today", "h3")
energyValue = TextContent("1,847 kWh", "large-heavy")
energyDetail = TextContent("vs 1,920 kWh target  •  96% of budget", "small")
workOrdersCard = Card([woTitle, woTable], "card", "column", "m")
woTitle = Heading("Open Work Orders", "h3")
woTable = Table([woIdCol, woMachineCol, woDescCol, woPriorityCol, woAssignedCol])
woIdCol = Col("WO #", ["WO-1847", "WO-1842", "WO-1839", "WO-1835", "WO-1831"])
woMachineCol = Col("Machine", ["ASM-01", "MOLD-03", "FIN-02", "PKG-04", "ASM-02"])
woDescCol = Col("Description", ["Replace conveyor belt", "Calibrate injection pressure", "Adjust trimmer alignment", "Replace sealing jaw", "Lubricate linear rails"])
woPriorityCol = Col("Priority", ["Critical", "High", "Medium", "High", "Low"])
woAssignedCol = Col("Assigned", ["J. Martinez", "K. Chen", "R. Patel", "S. Okafor", "T. Nguyen"])

scheduleMaintenanceForm = Card([schedTitle, schedForm], "sunk", "column", "m")
schedTitle = Heading("Schedule Maintenance", "h3")
schedForm = Form("schedule-maintenance", schedButtons, [machineField, dateField, typeField, notesField])
machineField = FormControl("Machine", machineSelect, "Select equipment to service")
machineSelect = Select("machine", machineOptions, "Choose machine…", null, "medium")
machineOptions = [machAsm1, machAsm2, machMold1, machMold2, machMold3, machFin1, machFin2, machPkg1, machPkg2, machPkg3, machPkg4]
machAsm1 = SelectItem("ASM-01", "ASM-01 — Assembly Line 1")
machAsm2 = SelectItem("ASM-02", "ASM-02 — Assembly Line 1")
machMold1 = SelectItem("MOLD-01", "MOLD-01 — Molding Line 2")
machMold2 = SelectItem("MOLD-02", "MOLD-02 — Molding Line 2")
machMold3 = SelectItem("MOLD-03", "MOLD-03 — Molding Line 2")
machFin1 = SelectItem("FIN-01", "FIN-01 — Finishing Line 3")
machFin2 = SelectItem("FIN-02", "FIN-02 — Finishing Line 3")
machPkg1 = SelectItem("PKG-01", "PKG-01 — Packaging Line 4")
machPkg2 = SelectItem("PKG-02", "PKG-02 — Packaging Line 4")
machPkg3 = SelectItem("PKG-03", "PKG-03 — Packaging Line 4")
machPkg4 = SelectItem("PKG-04", "PKG-04 — Packaging Line 4")
dateField = FormControl("Date & Time", datePicker, "When to perform maintenance")
datePicker = DatePicker("maint-date", "single", null, null)
typeField = FormControl("Maintenance Type", typeSelect, "Category of work")
typeSelect = Select("maint-type", typeOptions, "Select type…", null, "medium")
typeOptions = [typePrev, typeCorr, typePred, typeInsp, typeCal]
typePrev = SelectItem("preventive", "Preventive")
typeCorr = SelectItem("corrective", "Corrective")
typePred = SelectItem("predictive", "Predictive")
typeInsp = SelectItem("inspection", "Inspection")
typeCal = SelectItem("calibration", "Calibration")
notesField = FormControl("Notes", notesArea, "Details, parts needed, safety permits…")
notesArea = TextArea("maint-notes", "Enter notes…", 3, null, null)
schedButtons = Buttons([schedSubmit, schedCancel], "row")
schedSubmit = Button("Schedule", null, "primary")
schedCancel = Button("Cancel", null, "tertiary")

andonAlerts = Card([andonTitle, andonList], "sunk", "column", "m")
andonTitle = Heading("Live Andon Alerts", "h3")
andonList = Card([alert1, alert2, alert3], "clear", "column", "s")
alert1 = Callout("warning", "Line 3 — FIN-02", "Cycle time exceeded threshold (45s > 38s target) — 2 min ago")
alert2 = Callout("error", "Line 1 — ASM-01", "Emergency stop activated — Operator investigating — 5 min ago")
alert3 = Callout("info", "Line 4 — PKG-04", "Low packaging material — Reorder triggered — 12 min ago")

exportButton = Buttons([exportBtn], "row")
exportBtn = Button("Export Shift Report", null, "primary", "normal", "large")

safetyCard = Card([safetyTitle, safetyGrid], "sunk", "column", "m")
safetyTitle = Heading("Safety", "h3")
safetyGrid = Card([incidentsCard, daysCard], "clear", "row", "m")
incidentsCard = Card([TextContent("Incidents This Year", "small"), TextContent("3", "large-heavy")], "card", "column", "xs", "center")
daysCard = Card([TextContent("Days Since Last Incident", "small"), TextContent("127", "large-heavy")], "card", "column", "xs", "center")