root = Card([header, periodSelector, kpiRow, chartsRow, topCustomersSection, riskAccountsSection, failedPaymentsSection, inviteAdminSection], "card", "column", "l")
header = CardHeader("Admin Overview", "SaaS metrics and account health")
periodSelector = Card([periodLabel, periodSelect], "clear", "row", "m", "center", "between")
periodLabel = TextContent("Reporting period:", "small-heavy")
periodSelect = Select("reporting_period", periodOptions, "Select period", null, null, "small")
periodOptions = [optLast30, optLast90, optLast12M, optYTD, optCustom]
optLast30 = SelectItem("last_30", "Last 30 days")
optLast90 = SelectItem("last_90", "Last 90 days")
optLast12M = SelectItem("last_12m", "Last 12 months")
optYTD = SelectItem("ytd", "Year to date")
optCustom = SelectItem("custom", "Custom range")
kpiRow = Card([mrrCard, arrCard, churnCard, npsCard], "clear", "row", "m", "stretch", "between", true)
mrrCard = Card([mrrLabel, mrrValue, mrrTrend], "card", "column", "s")
mrrLabel = TextContent("Monthly Recurring Revenue", "small")
mrrValue = TextContent("$127,450", "large-heavy")
mrrTrend = TextContent("+12.3% vs last month", "small")
arrCard = Card([arrLabel, arrValue, arrTrend], "card", "column", "s")
arrLabel = TextContent("Annual Recurring Revenue", "small")
arrValue = TextContent("$1,529,400", "large-heavy")
arrTrend = TextContent("+18.7% vs last year", "small")
churnCard = Card([churnLabel, churnValue, churnTrend], "card", "column", "s")
churnLabel = TextContent("Churn This Month", "small")
churnValue = TextContent("2.1%", "large-heavy")
churnTrend = TextContent("-0.4pp vs last month", "small")
npsCard = Card([npsLabel, npsValue, npsTrend], "card", "column", "s")
npsLabel = TextContent("Current NPS", "small")
npsValue = TextContent("67", "large-heavy")
npsTrend = TextContent("+5 vs last quarter", "small")
chartsRow = Card([signupsChartCard, planSplitCard, featureAdoptionCard, seatUtilCard], "clear", "row", "m", "stretch", "between", true)
signupsChartCard = Card([signupsTitle, signupsChart], "card", "column", "m")
signupsTitle = Heading("New Signups (90 days)", "h3")
signupsChart = LineChart(signupsLabels, [signupsSeries], "natural", "Day", "Signups")
signupsLabels = ["Day 1", "Day 10", "Day 20", "Day 30", "Day 40", "Day 50", "Day 60", "Day 70", "Day 80", "Day 90"]
signupsSeries = Series("Signups", [12, 18, 15, 22, 28, 25, 31, 29, 35, 33])
planSplitCard = Card([planSplitTitle, planSplitChart], "card", "column", "m")
planSplitTitle = Heading("Customers by Plan", "h3")
planSplitChart = PieChart(planLabels, planValues, "donut", "circular")
planLabels = ["Starter", "Professional", "Enterprise", "Custom"]
planValues = [342, 187, 64, 12]
featureAdoptionCard = Card([featureTitle, featureChart], "card", "column", "m")
featureTitle = Heading("New Feature Adoption", "h3")
featureChart = BarChart(featureLabels, [featureSeries], "grouped", "Feature", "Adoption %")
featureLabels = ["AI Insights", "Workflow Builder", "Advanced Analytics"]
featureSeries = Series("Adoption", [34, 28, 19])
seatUtilCard = Card([seatTitle, seatUtilList], "card", "column", "m")
seatTitle = Heading("Seat Utilization", "h3")
seatUtilList = Card([utilStarter, utilPro, utilEnt, utilCustom], "clear", "column", "s")
utilStarter = Card([utilStarterLabel, utilStarterBar], "clear", "row", "m", "center")
utilStarterLabel = TextContent("Starter (342 accounts)", "small")
utilStarterBar = Progress(68, "68%")
utilPro = Card([utilProLabel, utilProBar], "clear", "row", "m", "center")
utilProLabel = TextContent("Professional (187 accounts)", "small")
utilProBar = Progress(82, "82%")
utilEnt = Card([utilEntLabel, utilEntBar], "clear", "row", "m", "center")
utilEntLabel = TextContent("Enterprise (64 accounts)", "small")
utilEntBar = Progress(91, "91%")
utilCustom = Card([utilCustomLabel, utilCustomBar], "clear", "row", "m", "center")
utilCustomLabel = TextContent("Custom (12 accounts)", "small")
utilCustomBar = Progress(76, "76%")
topCustomersSection = Card([topCustomersTitle, topCustomersTable], "card", "column", "m")
topCustomersTitle = Heading("Top 10 Customers by Spend", "h3")
topCustomersTable = Table([custNameCol, custPlanCol, custSeatsCol, custSpendCol, custActionCol])
custNameCol = Col("Customer", ["Acme Corp", "Globex Inc", "Wayne Enterprises", "Stark Industries", "Umbrella Corp", "Cyberdyne Systems", "Tyrell Corp", "Weyland-Yutani", "Massive Dynamic", "Initech"])
custPlanCol = Col("Plan", ["Enterprise", "Enterprise", "Custom", "Enterprise", "Enterprise", "Professional", "Enterprise", "Custom", "Enterprise", "Professional"])
custSeatsCol = Col("Seats", [450, 380, 520, 310, 290, 220, 195, 180, 165, 150], "number")
custSpendCol = Col("Monthly Spend", ["$45,000", "$38,000", "$52,000", "$31,000", "$29,000", "$22,000", "$19,500", "$18,000", "$16,500", "$15,000"])
custActionCol = Col("Action", ["View", "View", "View", "View", "View", "View", "View", "View", "View", "View"], "action")
riskAccountsSection = Card([riskTitle, riskTable], "card", "column", "m")
riskTitle = Heading("Accounts at Risk", "h3")
riskTable = Table([riskNameCol, riskPlanCol, riskReasonCol, riskHealthCol, riskActionCol])
riskNameCol = Col("Account", ["DataFlow Labs", "Nexus Digital", "Apex Solutions", "Quantum Leap", "Horizon Tech"])
riskPlanCol = Col("Plan", ["Professional", "Starter", "Professional", "Enterprise", "Starter"])
riskReasonCol = Col("Risk Reason", ["Low usage (12% MAU)", "Payment failed 2x", "No login 30+ days", "Key champion left", "Competitor eval"])
riskHealthCol = Col("Health Score", ["23", "31", "18", "42", "29"], "number")
riskActionCol = Col("Action", ["Contact", "Retry Payment", "Re-engage", "Executive outreach", "Schedule call"], "action")
failedPaymentsSection = Card([failedTitle, failedTable], "card", "column", "m")
failedTitle = Heading("Failed Payments", "h3")
failedTable = Table([failNameCol, failAmountCol, failDateCol, failAttemptsCol, failRetryCol])
failNameCol = Col("Customer", ["BrightPath Co", "Meridian Systems", "Orbit Analytics", "Pinnacle Group", "Summit Software"])
failAmountCol = Col("Amount", ["$299", "$899", "$1,499", "$499", "$2,299"])
failDateCol = Col("Failed Date", ["2024-01-15", "2024-01-14", "2024-01-13", "2024-01-12", "2024-01-11"])
failAttemptsCol = Col("Attempts", [2, 1, 3, 1, 2], "number")
failRetryCol = Col("Retry", [retryBtn1, retryBtn2, retryBtn3, retryBtn4, retryBtn5], "action")
retryBtn1 = Button("Retry", ["retry_brightpath"])
retryBtn2 = Button("Retry", ["retry_meridian"])
retryBtn3 = Button("Retry", ["retry_orbit"])
retryBtn4 = Button("Retry", ["retry_pinnacle"])
retryBtn5 = Button("Retry", ["retry_summit"])
inviteAdminSection = Card([inviteTitle, inviteDesc, inviteButtons], "card", "column", "m")
inviteTitle = Heading("Invite Another Admin", "h3")
inviteDesc = TextContent("Add a team member with admin access to this dashboard.")
inviteButtons = Buttons([inviteBtn])
inviteBtn = Button("Invite Admin", null, "primary")