root = Card([header, oeeSection, productionSection, linesSection, chartsRow, downtimeSection, maintenanceSection, inventorySection, deliveriesSection, shiftsSection, safetySection, qualitySection, energySection, workOrdersSection, scheduleSection, focusSection, andonSection, exportSection], "card", "column", "l")

header = CardHeader("Factory Floor Console", "Live overview — Shift A · 09:42")

oeeSection = Card([oeeHeading, oeeTable, oeeProgress], "sunk")
oeeHeading = Heading("Overall Equipment Effectiveness", "h3")
oeeTable = Table([oeeMetric, oeeValue])
oeeMetric = Col("Metric", ["Availability", "Performance", "Quality", "OEE"])
oeeValue = Col("Value", ["92%", "88%", "96%", "78%"])
oeeProgress = Progress(78, "OEE")

productionSection = Card([prodHeading, prodChart, prodProgress], "sunk")
prodHeading = Heading("Units Produced vs Today's Target", "h3")
prodChart = BarChart(["06:00", "07:00", "08:00", "09:00"], [producedSeries, targetSeries], "grouped", "Hour", "Units")
producedSeries = Series("Produced", [120, 180, 240, 310])
targetSeries = Series("Target", [150, 210, 270, 330])
prodProgress = Progress(94, "310 / 330 units")

linesSection = Card([linesHeading, linesTable], "sunk")
linesHeading = Heading("Production Lines", "h3")
linesTable = Table([lineName, lineRate, lineStatus])
lineName = Col("Line", ["Line A", "Line B", "Line C", "Line D"])
lineRate = Col("Rate (units/hr)", [145, 132, 158, 118])
lineStatus = Col("Status", ["Running", "Running", "Idle", "Running"])

chartsRow = Card([defectChart, energyChart], "sunk", "row", "l")
defectChart = Card([defectHeading, defectLine])
defectHeading = Heading("Defect Rate — Past Month", "h3")
defectLine = LineChart(["W1", "W2", "W3", "W4"], [defectSeries], "natural", "Week", "%")
defectSeries = Series("Defect %", [2.1, 1.8, 2.4, 1.6])
energyChart = Card([energyHeading, energyArea])
energyHeading = Heading("Energy Use Today", "h3")
energyArea = AreaChart(["06:00", "08:00", "10:00", "12:00"], [energySeries], "natural", "Hour", "kWh")
energySeries = Series("kWh", [180, 240, 310, 290])

downtimeSection = Card([downtimeHeading, downtimePie], "sunk")
downtimeHeading = Heading("Downtime by Cause", "h3")
downtimePie = PieChart(["Changeover", "Maintenance", "Material Shortage", "Breakdown"], [38, 27, 22, 13], "donut")

maintenanceSection = Card([maintHeading, maintList], "sunk")
maintHeading = Heading("Machines Due for Maintenance", "h3")
maintList = ListBlock([maintItem1, maintItem2, maintItem3], "number")
maintItem1 = ListItem("Press 3", "Due today — 2000 hrs run")
maintItem2 = ListItem("Conveyor 7", "Due tomorrow — belt wear")
maintItem3 = ListItem("Robot Arm 2", "Due Friday — lubrication")

inventorySection = Card([invHeading, invTable], "sunk")
invHeading = Heading("Stock Levels", "h3")
invTable = Table([invMaterial, invQty, invStatus])
invMaterial = Col("Material", ["Steel", "Resin", "Packaging"])
invQty = Col("Qty", ["420 t", "1.8 t", "12,400 units"])
invStatus = Col("Status", ["OK", "Low", "OK"])

deliveriesSection = Card([delHeading, delList], "sunk")
delHeading = Heading("Supplier Deliveries Due This Week", "h3")
delList = ListBlock([delItem1, delItem2, delItem3], "number")
delItem1 = ListItem("Steel coils — Arcelor", "Due Tue · 120 t")
delItem2 = ListItem("Resin pellets — BASF", "Due Wed · 2 t")
delItem3 = ListItem("Boxes — PackCo", "Due Fri · 5,000")

shiftsSection = Card([shiftsHeading, shiftsChart], "sunk")
shiftsHeading = Heading("Shift Output Comparison", "h3")
shiftsChart = HorizontalBarChart(["Shift A", "Shift B", "Shift C"], [shiftSeries], "grouped", "Units", "Shift")
shiftSeries = Series("Output", [310, 285, 260])

safetySection = Card([safetyHeading, safetyStats], "sunk")
safetyHeading = Heading("Safety", "h3")
safetyStats = Table([safetyMetric, safetyValue])
safetyMetric = Col("Metric", ["Incidents this year", "Days since last incident"])
safetyValue = Col("Value", ["2", "47"])
safetyCallout = Callout("success", "Good safety record", "47 days since the last incident — keep it up!")

qualitySection = Card([qualityHeading, qualityTable], "sunk")
qualityHeading = Heading("Batches on Quality Hold", "h3")
qualityTable = Table([batchId, batchQty, batchReason])
batchId = Col("Batch", ["B-1042", "B-1047", "B-1051"])
batchQty = Col("Qty", ["240", "180", "320"])
batchReason = Col("Reason", ["Color variance", "Dimensional check", "Resin contamination"])

workOrdersSection = Card([woHeading, woTable], "sunk")
woHeading = Heading("Open Work Orders", "h3")
woTable = Table([woId, woPriority, woLine])
woId = Col("Order", ["WO-221", "WO-224", "WO-227"])
woPriority = Col("Priority", ["High", "Medium", "Low"])
woLine = Col("Line", ["Line A", "Line B", "Line C"])

scheduleSection = Card([scheduleHeading, scheduleForm], "sunk")
scheduleHeading = Heading("Schedule Maintenance", "h3")
scheduleForm = Form("schedule-maint", scheduleButtons, [machField, dateField])
machField = FormControl("Machine", machSelect)
machSelect = Select("machine", [machOpt1, machOpt2, machOpt3], "Select machine")
machOpt1 = SelectItem("press3", "Press 3")
machOpt2 = SelectItem("conv7", "Conveyor 7")
machOpt3 = SelectItem("robot2", "Robot Arm 2")
dateField = FormControl("Date", dateInput)
dateInput = DatePicker("date", "single")
scheduleButtons = Buttons([scheduleBtn])
scheduleBtn = Button("Schedule")

focusSection = Card([focusHeading, focusButtons], "sunk")
focusHeading = Heading("Focus on a Line", "h3")
focusButtons = Buttons([focusA, focusB, focusC, focusD])
focusA = Button("Line A")
focusB = Button("Line B")
focusC = Button("Line C")
focusD = Button("Line D")

andonSection = Card([andonHeading, andonList], "sunk")
andonHeading = Heading("Live Andon Alerts", "h3")
andonList = ListBlock([andonItem1, andonItem2], "image")
andonItem1 = ListItem("Line C — Material shortage", "Resin low · 09:38")
andonItem2 = ListItem("Line B — Minor jam", "Conveyor 7 · 09:15")

exportSection = Card([exportButtons], "sunk")
exportButtons = Buttons([exportBtn])
exportBtn = Button("Export Shift Report")