root = Card([header, loadSection, capacitySection, genSection, plantSection, outageSection, forecastSection, priceSection, maintenanceSection, alertsSection, regionControl, curtailmentSection, emissionsSection])

header = CardHeader("Power Network Operator Console", "Live grid status and control")

loadSection = Card([loadHeading, loadValue, loadTrend], "sunk")
loadHeading = Heading("Current Load", "h3")
loadValue = TextContent("4,820 MW", "large-heavy")
loadTrend = TextContent("▲ +2.3% vs 1 hour ago", "small")

capacitySection = Card([capacityHeading, capacityBar, capacityText], "sunk")
capacityHeading = Heading("Network Capacity", "h3")
capacityBar = Progress(87, "87% of 5,540 MW capacity")
capacityText = TextContent("720 MW headroom available", "small")

genSection = Card([genHeading, genChart], "sunk")
genHeading = Heading("Generation by Source", "h3")
genChart = PieChart(["Coal", "Gas", "Nuclear", "Wind", "Solar", "Hydro"], [1850, 1200, 950, 420, 250, 150], "donut")

plantSection = Card([plantHeading, plantTable], "sunk")
plantHeading = Heading("Plant Output & Status", "h3")
plantTable = Table([plantName, plantOutput, plantStatus])
plantName = Col("Plant", ["Northport Coal", "Riverside Gas", "Valley Nuclear", "Hilltop Wind", "Desert Solar", "Canyon Hydro"])
plantOutput = Col("Output (MW)", [1850, 1200, 950, 420, 250, 150])
plantStatus = Col("Status", ["Online", "Online", "Online", "Reduced", "Online", "Maintenance"])

outageSection = Card([outageHeading, outageList], "sunk")
outageHeading = Heading("Active Outages", "h3")
outageList = ListBlock([outage1, outage2, outage3])
outage1 = ListItem("Outage #1042", "Transformer failure — North District", ["⚠️"])
outage2 = ListItem("Outage #1043", "Line maintenance — East Hills", ["🔧"])
outage3 = ListItem("Outage #1044", "Storm damage — Coastal Zone", ["🌩️"])

forecastSection = Card([forecastHeading, forecastChart], "sunk")
forecastHeading = Heading("Demand Forecast — Next 24 Hours", "h3")
forecastChart = LineChart(["0h", "3h", "6h", "9h", "12h", "15h", "18h", "21h", "24h"], [forecastSeries], "natural", "Time", "MW")
forecastSeries = Series("Forecast", [4820, 4550, 4380, 4600, 5100, 5400, 5300, 4900, 4700])

priceSection = Card([priceHeading, priceValue, priceChange], "sunk")
priceHeading = Heading("Current Price", "h3")
priceValue = TextContent("£54.20 / MWh", "large-heavy")
priceChange = TextContent("▼ £1.80 vs yesterday", "small")

maintenanceSection = Card([maintenanceHeading, maintenanceTable], "sunk")
maintenanceHeading = Heading("Maintenance — This Month", "h3")
maintenanceTable = Table([maintPlant, maintDate, maintType])
maintPlant = Col("Plant", ["Canyon Hydro", "Hilltop Wind", "Northport Coal", "Riverside Gas"])
maintDate = Col("Date", ["Mar 14–16", "Mar 18–20", "Mar 22–24", "Mar 28–30"])
maintType = Col("Type", ["Turbine overhaul", "Blade inspection", "Boiler service", "Turbine service"])

alertsSection = Card([alertsHeading, alertsList], "sunk")
alertsHeading = Heading("Live Alerts", "h3")
alertsList = ListBlock([alert1, alert2, alert3])
alert1 = ListItem("⚠️ High load warning", "Load at 87% capacity — monitor closely", ["🔴"])
alert2 = ListItem("⚠️ Wind farm reduced", "Hilltop Wind at 60% due to low wind", ["🟡"])
alert3 = ListItem("ℹ️ Price spike", "Price up 8% in last hour", ["🔵"])

regionControl = Card([regionHeading, regionForm], "sunk")
regionHeading = Heading("Focus on Region", "h3")
regionForm = Form("region-focus", regionButtons, [regionSelect])
regionSelect = FormControl("Select region", regionDropdown)
regionDropdown = Select("region", [regionNorth, regionEast, regionSouth, regionWest], "Choose a region")
regionNorth = SelectItem("north", "North District")
regionEast = SelectItem("east", "East Hills")
regionSouth = SelectItem("south", "South Valley")
regionWest = SelectItem("west", "Coastal Zone")
regionButtons = Buttons([regionApply])
regionApply = Button("Apply Focus")

curtailmentSection = Card([curtailHeading, curtailForm, curtailConfirm], "sunk")
curtailHeading = Heading("Order Curtailment", "h3")
curtailForm = Form("curtailment-order", curtailButtons, [curtailPlant, curtailAmount])
curtailPlant = FormControl("Plant to curtail", curtailPlantSelect)
curtailPlantSelect = Select("plant", [curtailCoal, curtailGas, curtailWind], "Select plant")
curtailCoal = SelectItem("coal", "Northport Coal")
curtailGas = SelectItem("gas", "Riverside Gas")
curtailWind = SelectItem("wind", "Hilltop Wind")
curtailAmount = FormControl("Amount (MW)", curtailSlider)
curtailSlider = Slider("amount", "discrete", 0, 500, 50, [100], "Curtail amount")
curtailButtons = Buttons([curtailOrder])
curtailOrder = Button("Order Curtailment", null, "primary")
curtailConfirm = AlertDialogBlock("Confirm Order", "Confirm curtailment", "Curtail 100 MW from Hilltop Wind?", "Confirm", "Cancel", "secondary")

emissionsSection = Card([emissionsHeading, emissionsValue, emissionsChart], "sunk")
emissionsHeading = Heading("Emissions Today", "h3")
emissionsValue = TextContent("2,340 t CO₂", "large-heavy")
emissionsChart = BarChart(["Coal", "Gas", "Nuclear", "Wind", "Solar", "Hydro"], [emissionsSeries], "grouped", "Source", "t CO₂")
emissionsSeries = Series("Emissions", [1850, 420, 0, 0, 0, 70])