root = Card([header, tfRow, kpisRow, alertsRow, positionsCard, riskCard, watchCard, ordersCard, marketCard, econCard, strategyCard, ddCard, limitsCard, rebalanceCard, orderCard, followups], "card", "column", "xl")

header = CardHeader("Trading Desk — Morning Workspace", "Overview as of 09:15 ET")

tfRow = Card([tfLabel, tfButtons], "clear", "row", "m")
tfLabel = TextContent("Timeframe:", "small-heavy")
tfButtons = Buttons([tf1d, tf1w, tf1m, tf3m, tf1y])
tf1d = Button("1D", null, "secondary", "normal", "small")
tf1w = Button("1W", null, "secondary", "normal", "small")
tf1m = Button("1M", null, "secondary", "normal", "small")
tf3m = Button("3M", null, "secondary", "normal", "small")
tf1y = Button("1Y", null, "primary", "normal", "small")

kpisRow = Card([kpiPortfolio, kpiPnL, kpiMargin, kpiVar], "clear", "row", "l")
kpiPortfolio = Card([kpiPortfolioTitle, kpiPortfolioVal], "sunk", "column", "xs")
kpiPortfolioTitle = TextContent("Portfolio Value", "small")
kpiPortfolioVal = TextContent("$12,480,250", "large-heavy")
kpiPnL = Card([kpiPnLTitle, kpiPnLVal, kpiPnLBadge], "sunk", "column", "xs")
kpiPnLTitle = TextContent("P&L Today", "small")
kpiPnLVal = TextContent("+$184,320", "large-heavy")
kpiPnLBadge = Tag("+1.5%", null, "sm", "success")
kpiMargin = Card([kpiMarginTitle, kpiMarginVal, kpiMarginProg], "sunk", "column", "xs")
kpiMarginTitle = TextContent("Margin in Use", "small")
kpiMarginVal = TextContent("$3,210,000", "large-heavy")
kpiMarginProg = Progress(68, "68% of limit")
kpiVar = Card([kpiVarTitle, kpiVarVal], "sunk", "column", "xs")
kpiVarTitle = TextContent("Value at Risk (95%, 1d)", "small")
kpiVarVal = TextContent("$412,000", "large-heavy")

alertsRow = Card([alert1, alert2], "clear", "column", "m")
alert1 = Alert("Risk limit near breach", "Equity concentration approaching 25% cap (24.8%).", "warning")
alert2 = Alert("Margin utilization", "Margin usage at 68% — above the 65% soft threshold.", "info")

positionsCard = Card([positionsHeader, positionsTable], "card", "column", "m")
positionsHeader = CardHeader("Positions", "Ticker, size, entry, current")
positionsTable = Table([posTicker, posSize, posEntry, posCurrent, posPnL])
posTicker = Col("Ticker", ["AAPL", "MSFT", "NVDA", "TSLA", "JPM", "XOM"])
posSize = Col("Size", [3200, 4100, 1500, 2200, 5100, 6800])
posEntry = Col("Entry", ["$172.40", "$398.20", "$118.60", "$248.30", "$196.10", "$112.40"])
posCurrent = Col("Current", ["$181.20", "$412.50", "$127.80", "$236.10", "$201.40", "$116.90"])
posPnL = Col("P&L", ["+$28,160", "+$58,630", "+$13,800", "-$26,840", "+$27,030", "+$30,600"])

riskCard = Card([riskHeader, exposureChart, varChart], "card", "column", "m")
riskHeader = CardHeader("Risk", "Exposure by sector and value at risk")
exposureChart = HorizontalBarChart(["Technology", "Energy", "Financials", "Healthcare", "Consumer"], [exposureSeries], "grouped", "Exposure ($M)", "Sector")
exposureSeries = Series("Exposure", [5.2, 2.4, 2.1, 1.6, 1.2])
varChart = AreaChart(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], [varSeries], "natural", "Month", "VaR ($K)")
varSeries = Series("VaR", [380, 410, 395, 430, 450, 420, 415, 440, 460, 425, 412, 412])

watchCard = Card([watchHeader, watchTable], "card", "column", "m")
watchHeader = CardHeader("Watchlist", "Instruments being watched")
watchTable = Table([watchTicker, watchPrice, watchMove])
watchTicker = Col("Ticker", ["AMD", "AMZN", "GOOGL", "META", "NFLX", "COIN"])
watchPrice = Col("Price", ["$164.30", "$186.70", "$178.20", "$512.40", "$622.10", "$245.80"])
watchMove = Col("Chg %", ["+2.1%", "-0.8%", "+1.2%", "+0.4%", "-1.6%", "+3.4%"])

ordersCard = Card([ordersHeader, ordersTable], "card", "column", "m")
ordersHeader = CardHeader("Working Orders", "Open orders awaiting fill")
ordersTable = Table([ordTicker, ordSide, ordQty, ordType, ordLimit])
ordTicker = Col("Ticker", ["AAPL", "MSFT", "NVDA"])
ordSide = Col("Side", ["Buy", "Sell", "Buy"])
ordQty = Col("Qty", [500, 300, 200])
ordType = Col("Type", ["Limit", "Limit", "Stop"])
ordLimit = Col("Limit", ["$178.50", "$415.00", "$125.00"])

marketCard = Card([marketHeader, marketList], "card", "column", "m")
marketHeader = CardHeader("Market Headlines", "With sentiment")
headline1 = ListItem("Fed signals pause in rate hikes", "Reuters · 08:40", null, "Neutral")
headline2 = ListItem("Chipmakers rally on AI demand outlook", "Bloomberg · 08:15", null, "Positive")
headline3 = ListItem("Oil slips as inventories build", "WSJ · 07:55", null, "Negative")
headline4 = ListItem("Treasury yields edge lower ahead of auction", "FT · 07:30", null, "Neutral")
marketList = ListBlock([headline1, headline2, headline3, headline4])

econCard = Card([econHeader, econList], "card", "column", "m")
econHeader = CardHeader("Economic Releases This Week", "Key data points")
econ1 = ListItem("CPI (MoM)", "Tue · 08:30 ET · Forecast +0.3%", null, "High impact")
econ2 = ListItem("Retail Sales", "Wed · 08:30 ET · Forecast +0.4%", null, "High impact")
econ3 = ListItem("Jobless Claims", "Thu · 08:30 ET · Forecast 215K", null, "Medium impact")
econ4 = ListItem("Prelim UoM Consumer Sentiment", "Fri · 10:00 ET · Forecast 71.2", null, "Medium impact")
econList = ListBlock([econ1, econ2, econ3, econ4])

strategyCard = Card([strategyHeader, strategyChart], "card", "column", "m")
strategyHeader = CardHeader("Strategy Returns (YTD)", "Each strategy's return this year")
strategyChart = BarChart(["Momentum", "Mean Reversion", "Carry", "Event Driven", "Arbitrage"], [strategySeries], "grouped", "Strategy", "Return %")
strategySeries = Series("Return %", [12.4, 8.1, 5.6, 9.3, 3.2])

ddCard = Card([ddHeader, ddChart], "card", "column", "m")
ddHeader = CardHeader("Drawdown — Past Year", "Portfolio drawdown over the last 12 months")
ddChart = LineChart(["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], [ddSeries], "natural", "Month", "Drawdown %")
ddSeries = Series("Drawdown", [0, -2, -4, -3, -6, -8, -5, -7, -9, -4, -2, -1])

limitsCard = Card([limitsHeader, limitsTable], "card", "column", "m")
limitsHeader = CardHeader("Risk Limits Near Breach", "Approaching limits that need attention")
limitsTable = Table([limitName, limitCurrent, limitCap, limitStatus])
limitName = Col("Limit", ["Equity Concentration", "Sector Exposure — Tech", "Leverage Ratio", "Single Name — NVDA"])
limitCurrent = Col("Current", ["24.8%", "41.7%", "2.9x", "4.1%"])
limitCap = Col("Cap", ["25%", "45%", "3.0x", "5%"])
limitStatus = Col("Status", ["Warning", "Warning", "Warning", "Watch"])
limitStatus0 = Col("Status", ["Warning", "Warning", "Warning", "Watch"])

rebalanceCard = Card([rebalanceHeader, rebalanceButtons], "card", "column", "m")
rebalanceHeader = CardHeader("Rebalance", "Re-align portfolio to target weights")
rebalanceButtons = Buttons([rebalanceBtn, rebalanceDetail])
rebalanceBtn = Button("Rebalance to Targets")
rebalanceDetail = Button("View Targets", null, "secondary")

orderCard = Card([orderHeader, orderForm], "card", "column", "m")
orderHeader = CardHeader("Place Order", "Ticker, side, and quantity")
orderForm = Form("place-order", orderButtons, [tickerField, sideField, qtyField])
tickerField = FormControl("Ticker", tickerInput)
tickerInput = Input("ticker", "e.g. AAPL")
sideField = FormControl("Side", sideSelect)
sideSelect = Select("side", [sideBuy, sideSell], "Buy or sell")
sideBuy = SelectItem("buy", "Buy")
sideSell = SelectItem("sell", "Sell")
qtyField = FormControl("Quantity", qtyInput)
qtyInput = Input("quantity", "e.g. 500", "number")
orderButtons = Buttons([submitOrder, cancelOrder])
submitOrder = Button("Submit Order", null, "primary")
cancelOrder = Button("Cancel", null, "tertiary")

followups = FollowUpBlock([fu1, fu2, fu3])
fu1 = FollowUpItem("Show detailed P&L breakdown by strategy")
fu2 = FollowUpItem("What risk limits are closest to breach?")
fu3 = FollowUpItem("Suggest rebalancing trades")