Upload mellowtech_full (2).jsx
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012import { useState, useRef } from "react";import { BarChart, Bar, LineChart, Line, XAxis, YAxis, Tooltip, ResponsiveContainer, Cell} from "recharts";
// βββ DATA & HELPERS ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββconst LOCATIONS = { Home: { lat: -25.7461, lon: 28.1881 }, Work: { lat: -25.7580, lon: 28.1890 }, School: { lat: -25.7400, lon: 28.2100 }, Mall: { lat: -25.7650, lon: 28.3120 }, Hospital: { lat: -25.7320, lon: 28.2280 }, Airport: { lat: -25.9180, lon: 28.3820 }, Park: { lat: -25.7280, lon: 28.2450 }, Garage: { lat: -25.7500, lon: 28.1750 },};const LOC_NAMES = Object.keys(LOCATIONS);
function seededRand(seed) { let s = seed; return () => { s = (s * 1664525 + 1013904223) & 0xffffffff; return (s >>> 0) / 0xffffffff; };}
function congestionFor(seed, hr) { const r = seededRand(seed); let v = Math.floor(r() * 55) + 15; if ((hr >= 7 && hr <= 9) || (hr >= 16 && hr <= 18)) v = Math.min(100, v + 30); return v;}
function emissionLevel(c) { if (c > 65) return { label: "HIGH", color: "#ef4444" }; if (c > 40) return { label: "MEDIUM", color: "#f59e0b" }; return { label: "LOW", color: "#22c55e" };}
const now = new Date();const HOUR = now.getHours();const IS_RUSH = (HOUR >= 7 && HOUR <= 9) || (HOUR >= 16 && HOUR <= 18);const TIME_STR = now.toLocaleTimeString("en-ZA", { hour: "2-digit", minute: "2-digit" });const DATE_STR = now.toLocaleDateString("en-ZA", { day: "2-digit", month: "short", year: "numeric" });
// βββ DESIGN TOKENS ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββconst G = { bg0: "#030712", bg1: "#0a0f1e", bg2: "#0f1929", border: "#1e293b", text: "#e2e8f0", muted: "#475569", green: "#22c55e", green2: "#4ade80", red: "#ef4444", amber: "#f59e0b", blue: "#38bdf8",};
// βββ GLOBAL CSS ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββconst css = `@import url('https://fonts.googleapis.com/css2?family=Exo+2:wght@300;400;600;800;900&family=Share+Tech+Mono&display=swap');
* { box-sizing: border-box; margin: 0; padding: 0; }body { background: ${G.bg0}; color: ${G.text}; font-family: 'Exo 2', sans-serif; overflow-x: hidden; }::-webkit-scrollbar { width: 5px; }::-webkit-scrollbar-track { background: ${G.bg1}; }::-webkit-scrollbar-thumb { background: #1e3a4f; border-radius: 4px; }.mono { font-family: 'Share Tech Mono', monospace; }
/* ββ Drawer overlay ββ */.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.6); z-index: 40; transition: opacity .25s; }.drawer-overlay.hidden { opacity: 0; pointer-events: none; }
/* ββ Drawer panel ββ */.drawer { position: fixed; top: 0; left: 0; bottom: 0; width: 280px; background: #070d1a; border-right: 1px solid ${G.border}; z-index: 50; transform: translateX(-100%); transition: transform .28s cubic-bezier(.4,0,.2,1); display: flex; flex-direction: column;}.drawer.open { transform: translateX(0); }
/* ββ Top bar ββ */.topbar { position: sticky; top: 0; z-index: 30; background: ${G.bg0}; border-bottom: 1px solid ${G.border}; display: flex; align-items: center; gap: 12px; padding: 14px 16px;}.topbar-title { font-size: 18px; font-weight: 900; color: ${G.green2}; letter-spacing: 3px; }.hamburger { background: none; border: none; cursor: pointer; display: flex; flex-direction: column; gap: 5px; padding: 4px; }.hamburger span { display: block; width: 22px; height: 2px; background: ${G.green2}; border-radius: 2px; transition: .2s; }
/* ββ Nav items ββ */.nav-item { display: flex; align-items: center; gap: 14px; padding: 14px 20px; cursor: pointer; color: #64748b; font-size: 15px; font-weight: 600; transition: background .15s, color .15s; border-left: 3px solid transparent;}.nav-item:hover { background: #0d1f2e; color: #94a3b8; }.nav-item.active { background: linear-gradient(90deg,#0d2318,#0a1f14); color: ${G.green2}; border-left-color: ${G.green}; }.nav-icon { font-size: 20px; width: 28px; text-align: center; }
/* ββ Page content ββ */.content { padding: 16px; max-width: 1100px; margin: 0 auto; }
/* ββ Cards ββ */.card { background: linear-gradient(135deg,${G.bg1},${G.bg2}); border: 1px solid ${G.border}; border-radius: 16px; padding: 20px; position: relative; overflow: hidden;}.card::before { content:''; position:absolute; top:0;left:0;right:0;height:2px; background:linear-gradient(90deg,transparent,${G.green},transparent); }.card-red::before { background:linear-gradient(90deg,transparent,${G.red},transparent); }.card-amber::before { background:linear-gradient(90deg,transparent,${G.amber},transparent); }.card-blue::before { background:linear-gradient(90deg,transparent,${G.blue},transparent); }
.kv { font-size:28px; font-weight:900; font-family:'Share Tech Mono',monospace; }.kv-green { color:${G.green2}; }.kv-red { color:${G.red}; }.kv-amber { color:${G.amber}; }.kv-blue { color:${G.blue}; }.kl { font-size:10px; letter-spacing:3px; color:${G.muted}; text-transform:uppercase; margin-top:4px; }
/* ββ Alert banners ββ */.alert-red { background:#1c0a0a; border:1px solid #7f1d1d; border-left:4px solid ${G.red}; border-radius:12px; padding:14px 18px; margin:8px 0; }.alert-green { background:#071a0e; border:1px solid #14532d; border-left:4px solid ${G.green}; border-radius:12px; padding:14px 18px; margin:8px 0; }.alert-amber { background:#1a1203; border:1px solid #78350f; border-left:4px solid ${G.amber}; border-radius:12px; padding:14px 18px; margin:8px 0; }
/* ββ Progress bar ββ */.pbar-bg { background:${G.border}; border-radius:20px; height:8px; margin:6px 0; }.pbar-fill { height:8px; border-radius:20px; }
/* ββ Badge ββ */.badge { display:inline-block; background:#0d2318; color:${G.green2}; border:1px solid #166534; border-radius:20px; padding:3px 12px; font-size:11px; letter-spacing:2px; }
/* ββ Route boxes ββ */.route-blue { background:#071520; border:2px solid ${G.blue}; border-radius:14px; padding:16px; }.route-red { background:#1c0a0a; border:2px solid ${G.red}; border-radius:14px; padding:16px; }
/* ββ Login ββ */.login-wrap { max-width:380px; margin:60px auto; background:${G.bg1}; border:1px solid ${G.border}; border-radius:24px; padding:40px; text-align:center; }.inp { width:100%; background:${G.bg2}; border:1px solid ${G.border}; border-radius:10px; color:white; padding:10px 14px; font-size:14px; font-family:'Exo 2',sans-serif; outline:none; margin-bottom:12px; }.inp:focus { border-color:${G.green}; }.btn-green { width:100%; background:linear-gradient(135deg,#14532d,#166534); color:${G.green2}; border:1px solid #166534; border-radius:10px; padding:12px; font-weight:700; font-size:15px; font-family:'Exo 2',sans-serif; cursor:pointer; letter-spacing:1px; transition:.2s; }.btn-green:hover { box-shadow:0 0 20px #22c55e44; }.btn-sm { background:linear-gradient(135deg,#14532d,#166534); color:${G.green2}; border:1px solid #166534; border-radius:8px; padding:8px 16px; font-weight:700; font-size:13px; font-family:'Exo 2',sans-serif; cursor:pointer; letter-spacing:1px; }
/* ββ Layout grids ββ */.grid-2 { display:grid; grid-template-columns:1fr 1fr; gap:12px; }.grid-4 { display:grid; grid-template-columns:repeat(4,1fr); gap:12px; }@media(max-width:640px){ .grid-4{grid-template-columns:1fr 1fr;} .grid-2{grid-template-columns:1fr;} }
/* ββ Tabs ββ */.tabs { display:flex; border-bottom:1px solid ${G.border}; margin-bottom:16px; overflow-x:auto; }.tab { padding:10px 18px; cursor:pointer; font-size:13px; font-weight:600; color:#64748b; border-bottom:2px solid transparent; white-space:nowrap; }.tab.active { color:${G.green2}; border-bottom-color:${G.green}; }
/* ββ Form elements ββ */.sel { background:${G.bg2}; border:1px solid ${G.border}; border-radius:10px; color:white; padding:8px 12px; font-family:'Exo 2',sans-serif; font-size:13px; width:100%; }.lbl { font-size:11px; color:${G.muted}; letter-spacing:2px; margin-bottom:4px; }input[type=range] { accent-color:${G.green}; width:100%; }
/* ββ Misc ββ */.action-card { background:#0a0f1e; border:1px solid ${G.border}; border-radius:10px; padding:14px; margin-bottom:8px; }.reward-card { background:#0a0f1e; border:1px solid ${G.border}; border-radius:12px; padding:14px; margin-bottom:10px; }.sec-head { color:${G.text}; font-size:15px; font-weight:700; margin:16px 0 10px; }.page-head { display:flex; align-items:center; gap:12px; margin-bottom:12px; }.page-head h1 { color:${G.text}; font-weight:900; font-size:24px; }.page-head p { color:${G.muted}; font-size:12px; }`;
// βββ NAVIGATION CONFIG βββββββββββββββββββββββββββββββββββββββββββββββββββββββconst NAV = [ { id: "dashboard", icon: "π ", label: "Dashboard" }, { id: "routes", icon: "πΊοΈ", label: "Smart Routes" }, { id: "alerts", icon: "β οΈ", label: "Emission Alerts" }, { id: "analytics", icon: "π", label: "Analytics" }, { id: "ecoscore", icon: "β", label: "Eco Score" }, { id: "rewards", icon: "π", label: "Rewards" }, { id: "profile", icon: "π€", label: "Profile" },];
// βββ SHARED COMPONENTS βββββββββββββββββββββββββββββββββββββββββββββββββββββββfunction PageHead({ emoji, title, sub }) { return ( <div> <div className="page-head"> <span style={{ fontSize: 28 }}>{emoji}</span> <div><h1>{title}</h1><p>{sub}</p></div> </div> <hr style={{ border: "none", borderTop: `1px solid ${G.border}`, margin: "0 0 16px" }} /> </div> );}
function KpiCard({ value, label, cls = "", kvcls = "kv-green" }) { return ( <div className={`card ${cls}`}> <div className={`kv ${kvcls}`}>{value}</div> <div className="kl">{label}</div> </div> );}
// βββ PAGE: DASHBOARD βββββββββββββββββββββββββββββββββββββββββββββββββββββββββfunction Dashboard({ state }) { const pulseData = LOC_NAMES.map((n, i) => ({ name: n, value: congestionFor(i * 7 + 1, HOUR) })); const savings = +(state.greenPoints * 0.12).toFixed(2); const fuel = +(state.greenPoints * 0.05).toFixed(2);
return ( <div> <PageHead emoji="π " title="Dashboard" sub="Live emission intelligence overview" />
<div className="grid-4" style={{ marginBottom: 12 }}> <KpiCard value={TIME_STR} label={DATE_STR} cls="card-blue" kvcls="kv-blue" /> <KpiCard value={IS_RUSH ? "RUSH HOUR" : "CLEAR"} label="TRAFFIC STATUS" cls={IS_RUSH ? "card-red" : ""} kvcls={IS_RUSH ? "kv-red" : "kv-green"} /> <KpiCard value={`${state.ecoScore}/100`} label="ECO SCORE" /> <KpiCard value={state.greenPoints} label="GREEN POINTS" /> </div>
{IS_RUSH ? <div className="alert-red"> <b style={{ color: G.red }}>β οΈ HIGH EMISSION ALERT</b><br /> <span style={{ color: "#fca5a5", fontSize: 13 }}>Rush hour β consider delaying or choosing a clean route.</span> </div> : <div className="alert-green"> <b style={{ color: G.green }}>β
LOW EMISSION CONDITIONS</b><br /> <span style={{ color: "#86efac", fontSize: 13 }}>Traffic is clear β great time to travel and earn Green Points.</span> </div> }
<div className="sec-head">Real-Time City Emission Pulse</div> <div style={{ background: G.bg1, border: `1px solid ${G.border}`, borderRadius: 12, padding: 12 }}> <ResponsiveContainer width="100%" height={180}> <BarChart data={pulseData}> <XAxis dataKey="name" tick={{ fill: G.muted, fontSize: 10 }} /> <YAxis tick={{ fill: G.muted, fontSize: 10 }} domain={[0, 100]} /> <Tooltip contentStyle={{ background: G.bg2, border: `1px solid ${G.border}`, borderRadius: 8 }} /> <Bar dataKey="value" radius={4}> {pulseData.map((d, i) => <Cell key={i} fill={emissionLevel(d.value).color} />)} </Bar> </BarChart> </ResponsiveContainer> </div>
<div className="sec-head">Today's Impact</div> <div className="grid-2" style={{ gap: 10 }}> <KpiCard value={`${savings} kg`} label="CO2 SAVED TODAY" /> <KpiCard value={`R${fuel}`} label="FUEL COST SAVED" cls="card-amber" kvcls="kv-amber" /> <KpiCard value={state.trips} label="TRIPS COMPLETED" cls="card-blue" kvcls="kv-blue" /> <KpiCard value={state.greenPoints} label="TOTAL GREEN POINTS" /> </div>
<div className="alert-green" style={{ marginTop: 12 }}> <b style={{ color: G.green }}>Why It Matters</b><br /> <span style={{ color: "#86efac", fontSize: 13 }}>Every clean trip earns Green Points redeemable for real rewards while reducing urban air pollution.</span> </div> </div> );}
// βββ PAGE: SMART ROUTES ββββββββββββββββββββββββββββββββββββββββββββββββββββββfunction SmartRoutes({ state, setState }) { const [origin, setOrigin] = useState("Home"); const [dest, setDest] = useState("Work"); const [leaveHr, setLeaveHr] = useState(HOUR); const [tripMsg, setTripMsg] = useState("");
const r = seededRand(leaveHr + origin.charCodeAt(0) + dest.charCodeAt(0)); const congA = Math.min(100, Math.floor(r() * 35) + 10); const congB = Math.min(100, Math.floor(r() * 40) + 50 + (IS_RUSH ? 25 : 0)); const distA = +(r() * 14 + 4).toFixed(1); const distB = +(distA * (r() * 0.5 + 0.8)).toFixed(1); const timeA = Math.round(distA * 1.5 + congA * 0.3); const timeB = Math.round(distB * 1.5 + congB * 0.5); const fuelA = +(distA * 0.08).toFixed(2); const fuelB = +(distB * 0.08 + congB * 0.005).toFixed(2); const co2A = +(fuelA * 2.31).toFixed(2); const co2B = +(fuelB * 2.31).toFixed(2);
function takeTrip() { setState(s => ({ ...s, greenPoints: s.greenPoints + 15, trips: s.trips + 1, ecoScore: Math.min(100, s.ecoScore + 1) })); setTripMsg(`β
Trip started! +15 pts added.`); setTimeout(() => setTripMsg(""), 3000); }
return ( <div> <PageHead emoji="πΊοΈ" title="Smart Routes" sub="Choose cleaner routes β reduce emissions, earn Green Points" />
<div className="grid-2" style={{ gap: 10, marginBottom: 10 }}> <div> <div className="lbl">ORIGIN</div> <select className="sel" value={origin} onChange={e => setOrigin(e.target.value)}> {LOC_NAMES.map(l => <option key={l}>{l}</option>)} </select> </div> <div> <div className="lbl">DESTINATION</div> <select className="sel" value={dest} onChange={e => setDest(e.target.value)}> {LOC_NAMES.filter(l => l !== origin).map(l => <option key={l}>{l}</option>)} </select> </div> </div>
<div style={{ marginBottom: 12 }}> <div className="lbl">DEPARTURE HOUR: {leaveHr}:00</div> <input type="range" min={0} max={23} value={leaveHr} onChange={e => setLeaveHr(+e.target.value)} /> </div>
<div className="grid-2" style={{ gap: 10, marginBottom: 14 }}> {/* Clean route */} <div className="route-blue"> <div style={{ fontSize: 14, fontWeight: 800, color: G.blue }}>β
CLEAN ROUTE</div> <div style={{ color: "#7dd3fc", fontSize: 10, letterSpacing: 2, marginBottom: 10 }}>LOW EMISSIONS Β· RECOMMENDED</div> <div className="grid-2"> {[["Congestion", `${congA}%`, G.blue], ["Time", `${timeA} min`, G.blue], ["Distance", `${distA} km`, G.green2], ["CO2", `${co2A} kg`, G.green2] ].map(([l, v, c]) => ( <div key={l}> <div className="mono" style={{ fontSize: 22, fontWeight: 900, color: c }}>{v}</div> <div style={{ color: "#64748b", fontSize: 10 }}>{l.toUpperCase()}</div> </div> ))} </div> <div style={{ marginTop: 10, background: "#0a1a2e", borderRadius: 8, padding: 8, fontSize: 12, color: "#7dd3fc" }}> Smooth flow Β· Earn +15 Green Points </div> </div> {/* High emission route */} <div className="route-red"> <div style={{ fontSize: 14, fontWeight: 800, color: G.red }}>β HIGH EMISSION ROUTE</div> <div style={{ color: "#fca5a5", fontSize: 10, letterSpacing: 2, marginBottom: 10 }}>HEAVY TRAFFIC Β· AVOID</div> <div className="grid-2"> {[["Congestion", `${congB}%`, G.red], ["Time", `${timeB} min`, G.red], ["Distance", `${distB} km`, "#f87171"], ["CO2", `${co2B} kg`, "#f87171"] ].map(([l, v, c]) => ( <div key={l}> <div className="mono" style={{ fontSize: 22, fontWeight: 900, color: c }}>{v}</div> <div style={{ color: "#64748b", fontSize: 10 }}>{l.toUpperCase()}</div> </div> ))} </div> <div style={{ marginTop: 10, background: "#1c0808", borderRadius: 8, padding: 8, fontSize: 12, color: "#fca5a5" }}> Stop-and-go Β· High idling Β· More fuel </div> </div> </div>
<div className="alert-green"> <b style={{ color: G.green }}>Smart Advisor</b><br /> <span style={{ color: "#86efac", fontSize: 13 }}> Taking the Clean Route saves <b>{(co2B - co2A).toFixed(2)} kg CO2</b> and ~<b>R{((fuelB - fuelA) * 20).toFixed(2)}</b> in fuel. Earn <b>+15 Green Points</b>. </span> </div>
<button className="btn-green" style={{ marginTop: 14 }} onClick={takeTrip}> π Take Clean Route β Start Trip </button> {tripMsg && <div className="alert-green" style={{ marginTop: 8 }}><b style={{ color: G.green }}>{tripMsg}</b> Total: {state.greenPoints + 15} pts</div>} </div> );}
// βββ PAGE: EMISSION ALERTS βββββββββββββββββββββββββββββββββββββββββββββββββββfunction EmissionAlerts() { const r = seededRand(HOUR * 3 + 7); const emPct = IS_RUSH ? Math.floor(r() * 75) + 20 : Math.floor(r() * 45) + 10; const speed = IS_RUSH ? Math.floor(r() * 30) + 15 : Math.floor(r() * 50) + 50; const idle = Math.floor(r() * 8); const rpm = Math.floor(r() * 3200) + 800;
const speedData = [0,10,20,30,40,50,60,70,80,90,100,110,120].map((s, i) => ({ speed: s, emission: [85,80,70,55,38,25,20,18,22,30,42,58,75][i], }));
const actions = [ { icon: "π§", title: "Check Engine Diagnostics", desc: "Run OBD scan or visit mechanic if emissions stay high.", color: G.red }, { icon: "β½", title: "Reduce Fuel Waste", desc: "Avoid rapid acceleration, maintain 60-80 km/h, reduce RPM.", color: G.amber }, { icon: "π©", title: "Service Your Vehicle", desc: "Oil change, air filter, fuel injector cleaning, exhaust check.", color: G.blue }, { icon: "π«", title: "Stop Unnecessary Idling", desc: "Switch off engine after 1 minute of idling.", color: G.amber }, { icon: "πΊοΈ", title: "Switch to a Cleaner Route", desc: "Less traffic = less emissions. Open Smart Routes for options.", color: G.green }, ];
return ( <div> <PageHead emoji="β οΈ" title="Emission Alerts" sub="Live diagnostics and driving behaviour intelligence" />
{emPct > 65 ? <div className="alert-red"> <b style={{ color: G.red, fontSize: 16 }}>π΄ HIGH EMISSION DETECTED</b><br /> <span style={{ color: "#fca5a5", fontSize: 13 }}>Above-normal emissions. Reduce speed and check diagnostics.</span> </div> : emPct > 40 ? <div className="alert-amber"> <b style={{ color: G.amber, fontSize: 16 }}>π‘ MODERATE EMISSIONS</b><br /> <span style={{ color: "#fde68a", fontSize: 13 }}>Slightly elevated β maintain steady speed and avoid sudden braking.</span> </div> : <div className="alert-green"> <b style={{ color: G.green, fontSize: 16 }}>π’ LOW EMISSIONS β CLEAN DRIVING</b><br /> <span style={{ color: "#86efac", fontSize: 13 }}>Excellent! Keep it up and earn Green Points.</span> </div> }
<div className="grid-4" style={{ margin: "12px 0" }}> <KpiCard value={`${emPct}%`} label="EMISSION LEVEL" cls={emPct > 65 ? "card-red" : emPct > 40 ? "card-amber" : ""} kvcls={emPct > 65 ? "kv-red" : emPct > 40 ? "kv-amber" : "kv-green"} /> <KpiCard value={`${speed} km/h`} label="SPEED" cls="card-blue" kvcls="kv-blue" /> <KpiCard value={`${idle} min`} label="IDLE TIME" cls={idle > 2 ? "card-amber" : ""} kvcls={idle > 2 ? "kv-amber" : "kv-green"} /> <KpiCard value={rpm} label="ENGINE RPM" cls={rpm > 3000 ? "card-red" : ""} kvcls={rpm > 3000 ? "kv-red" : "kv-green"} /> </div>
<div className="sec-head">Speed & Emission Relationship</div> <div style={{ background: G.bg1, border: `1px solid ${G.border}`, borderRadius: 12, padding: 10 }}> <ResponsiveContainer width="100%" height={160}> <LineChart data={speedData}> <XAxis dataKey="speed" tick={{ fill: G.muted, fontSize: 10 }} /> <YAxis tick={{ fill: G.muted, fontSize: 10 }} /> <Tooltip contentStyle={{ background: G.bg2, border: `1px solid ${G.border}`, borderRadius: 8 }} /> <Line type="monotone" dataKey="emission" stroke={G.green} strokeWidth={2} dot={false} /> </LineChart> </ResponsiveContainer> </div> <div className="alert-green" style={{ marginTop: 8 }}> <b style={{ color: G.green }}>Key Insight</b>{" "} <span style={{ color: "#86efac", fontSize: 13 }}>Driving at a steady 60-80 km/h produces the least pollution. Stop-and-go and high speeds burn significantly more fuel.</span> </div>
<div className="sec-head">Action Plan</div> {actions.map(a => ( <div key={a.title} className="action-card" style={{ borderLeft: `3px solid ${a.color}` }}> <div style={{ color: a.color, fontWeight: 700, fontSize: 14 }}>{a.icon} {a.title}</div> <div style={{ color: "#94a3b8", fontSize: 13, marginTop: 4 }}>{a.desc}</div> </div> ))} </div> );}
// βββ PAGE: ANALYTICS βββββββββββββββββββββββββββββββββββββββββββββββββββββββββfunction Analytics() { const [tab, setTab] = useState(0); const TABS = ["π Hourly Trends", "πΊοΈ Zone Emissions", "π° Cost Impact", "π₯ Heatmap"];
// Hourly data const hourly = Array.from({ length: 24 }, (_, h) => { const r = seededRand(h * 5 + 3); let em = Math.floor(r() * 35) + 15; if ((h >= 7 && h <= 9) || (h >= 16 && h <= 18)) em = Math.min(100, em + 35); return { hour: `${h}:00`, emission: em, speed: Math.max(10, 85 - em / 2) }; });
// Zone data const zones = LOC_NAMES.map((n, i) => { const c = congestionFor(i * 11 + 2, HOUR); return { name: n, congestion: c, ...emissionLevel(c) }; });
// Heatmap data const DAYS = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]; const HRS = [6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]; const heat = DAYS.map((d, di) => { const row = { day: d }; HRS.forEach(h => { const r = seededRand(di * 100 + h); let v = Math.floor(r() * 70) + 10; if ([7,8,17,18].includes(h) && di < 5) v = Math.min(100, v + 35); row[`${h}:00`] = v; }); return row; }); const heatColor = v => v > 65 ? "#7f1d1d" : v > 40 ? "#78350f" : "#14532d";
// Cost estimator state const [weeklyKm, setWeeklyKm] = useState(200); const [fuelPrice, setFuelPrice] = useState(22); const [driveStyle, setDriveStyle] = useState("Moderate"); const cons = { Aggressive: 12, Moderate: 8, Eco: 6 }; const litres = weeklyKm / 100 * cons[driveStyle]; const costWk = (litres * fuelPrice).toFixed(2); const co2Wk = (litres * 2.31).toFixed(2); const ecoSave = Math.max(0, (litres - weeklyKm / 100 * 6) * fuelPrice).toFixed(2);
return ( <div> <PageHead emoji="π" title="Analytics" sub="Traffic and emission trends, zone status, cost impact" /> <div className="tabs"> {TABS.map((t, i) => <div key={i} className={`tab ${tab === i ? "active" : ""}`} onClick={() => setTab(i)}>{t}</div>)} </div>
{/* TAB 0 β Hourly trends */} {tab === 0 && ( <div> <div className="sec-head">24-Hour Emission & Speed Trends</div> <div style={{ background: G.bg1, border: `1px solid ${G.border}`, borderRadius: 12, padding: 10 }}> <ResponsiveContainer width="100%" height={200}> <LineChart data={hourly}> <XAxis dataKey="hour" tick={{ fill: G.muted, fontSize: 9 }} interval={3} /> <YAxis tick={{ fill: G.muted, fontSize: 9 }} /> <Tooltip contentStyle={{ background: G.bg2, border: `1px solid ${G.border}`, borderRadius: 8 }} /> <Line type="monotone" dataKey="emission" stroke={G.red} strokeWidth={2} dot={false} name="Emission %" /> <Line type="monotone" dataKey="speed" stroke={G.blue} strokeWidth={2} dot={false} name="Speed km/h" /> </LineChart> </ResponsiveContainer> </div> <div className="alert-amber" style={{ marginTop: 8 }}> <b style={{ color: G.amber }}>Peak:</b>{" "} <span style={{ color: "#fde68a", fontSize: 13 }}>Rush hours 07:00β09:00 and 16:00β18:00. Cleanest window: 10:00β15:00.</span> </div> </div> )}
{/* TAB 1 β Zone emissions */} {tab === 1 && ( <div> <div className="sec-head">Zone Emission Status</div> {zones.map(z => ( <div key={z.name} style={{ background: "#0a0f1e", border: `1px solid ${G.border}`, borderRadius: 10, padding: 12, marginBottom: 8 }}> <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}> <span style={{ fontWeight: 700, fontSize: 14 }}>{z.name}</span> <span style={{ background: z.color + "22", color: z.color, border: `1px solid ${z.color}55`, borderRadius: 20, padding: "2px 10px", fontSize: 11, fontWeight: 700 }}>{z.label}</span> </div> <div className="pbar-bg"><div className="pbar-fill" style={{ width: `${z.congestion}%`, background: z.color }} /></div> <div style={{ color: "#64748b", fontSize: 12 }}>{z.congestion}% congestion</div> </div> ))} </div> )}
{/* TAB 2 β Cost impact */} {tab === 2 && ( <div> <div className="sec-head">Fuel Cost Impact Estimator</div> <div style={{ marginBottom: 10 }}> <div className="lbl">WEEKLY DRIVING: {weeklyKm} km</div> <input type="range" min={50} max={500} value={weeklyKm} onChange={e => setWeeklyKm(+e.target.value)} /> </div> <div style={{ marginBottom: 10 }}> <div className="lbl">FUEL PRICE: R{fuelPrice}/L</div> <input type="range" min={18} max={30} value={fuelPrice} onChange={e => setFuelPrice(+e.target.value)} /> </div> <div style={{ marginBottom: 14 }}> <div className="lbl">DRIVING STYLE</div> <select className="sel" value={driveStyle} onChange={e => setDriveStyle(e.target.value)}> {["Aggressive","Moderate","Eco"].map(s => <option key={s}>{s}</option>)} </select> </div> <div className="grid-2" style={{ gap: 10 }}> <KpiCard value={`R${costWk}`} label="WEEKLY FUEL COST" cls="card-amber" kvcls="kv-amber" /> <KpiCard value={`${co2Wk} kg`} label="CO2 PER WEEK" cls="card-red" kvcls="kv-red" /> <KpiCard value={`R${(+costWk * 4.3).toFixed(0)}`} label="MONTHLY COST" cls="card-red" kvcls="kv-red" /> <KpiCard value={`R${ecoSave}`} label="POTENTIAL SAVING/WK" /> </div> {+ecoSave > 0 && ( <div className="alert-amber" style={{ marginTop: 10 }}> <b style={{ color: G.amber }}>Tip:</b>{" "} <span style={{ color: "#fde68a", fontSize: 13 }}>Switch to Eco driving to save R{ecoSave}/week (R{(+ecoSave * 52).toFixed(0)}/year).</span> </div> )} </div> )}
{/* TAB 3 β Heatmap */} {tab === 3 && ( <div> <div className="sec-head">Weekly Emission Heatmap</div> <div style={{ overflowX: "auto" }}> <table style={{ borderCollapse: "collapse", width: "100%", fontSize: 11 }}> <thead> <tr> <th style={{ padding: "4px 8px", color: G.muted, textAlign: "left" }}>Day</th> {HRS.map(h => <th key={h} style={{ padding: "4px 6px", color: G.muted }}>{h}:00</th>)} </tr> </thead> <tbody> {heat.map(row => ( <tr key={row.day}> <td style={{ padding: "4px 8px", color: G.text, fontWeight: 700 }}>{row.day}</td> {HRS.map(h => { const v = row[`${h}:00`]; return ( <td key={h} style={{ padding: "4px 6px", background: heatColor(v), borderRadius: 4, textAlign: "center", color: "#ccc", fontFamily: "monospace" }}>{v}</td> ); })} </tr> ))} </tbody> </table> </div> <div style={{ color: G.muted, fontSize: 11, marginTop: 8 }}>π΄ Red = heavy congestion Β· π’ Green = smooth flow</div> </div> )} </div> );}
// βββ PAGE: ECO SCORE βββββββββββββββββββββββββββββββββββββββββββββββββββββββββfunction EcoScore({ state }) { const s = state.ecoScore; const grade = s >= 80 ? "A" : s >= 65 ? "B" : s >= 50 ? "C" : "D"; const gCol = s >= 80 ? G.green : s >= 65 ? G.green2 : s >= 50 ? G.amber : G.red; const label = s >= 80 ? "Excellent Eco Driver" : s >= 65 ? "Good Eco Driver" : s >= 50 ? "Average Driver" : "High Emission Driver";
const weekLabels = ["6wk ago","5wk ago","4wk ago","3wk ago","2wk ago","Last wk","This wk"]; const weekData = weekLabels.map((w, i) => ({ week: w, score: state.weeklyScores[i] }));
const factors = [ ["Route Choices", 78, G.green], ["Speed Consistency", 65, G.green2], ["Idle Management", 82, G.green], ["Trip Efficiency", 70, G.amber], ["Emission Level", 55, G.amber], ["Carpooling Bonus", 40, G.red], ];
const leaderboard = [ { rank: "π₯ 1st", driver: "EcoDriver_01", score: 96, pts: 1240, co2: 148 }, { rank: "π₯ 2nd", driver: "GreenWheels", score: 91, pts: 985, co2: 118 }, { rank: "π₯ 3rd", driver: "CleanCommuter",score: 88, pts: 872, co2: 104 }, { rank: "4th", driver: state.username, score: s, pts: state.greenPoints, co2: +(state.greenPoints * 0.12).toFixed(1) }, { rank: "5th", driver: "QuickRacer", score: 43, pts: 120, co2: 14 }, ];
return ( <div> <PageHead emoji="β" title="Eco Score" sub="Your environmental driving rating" />
<div style={{ display: "flex", gap: 12, flexWrap: "wrap", marginBottom: 16 }}> <div className="card" style={{ textAlign: "center", padding: 24, minWidth: 140 }}> <div className="mono" style={{ fontSize: 64, fontWeight: 900, color: gCol }}>{grade}</div> <div className="mono" style={{ fontSize: 32, fontWeight: 900, color: gCol }}>{s}/100</div> <div style={{ color: "#64748b", fontSize: 10, letterSpacing: 2, marginTop: 8 }}>{label.toUpperCase()}</div> </div> <div style={{ flex: 1, minWidth: 200 }}> <div className="sec-head">Weekly Performance</div> <div style={{ background: G.bg1, border: `1px solid ${G.border}`, borderRadius: 12, padding: 10 }}> <ResponsiveContainer width="100%" height={130}> <LineChart data={weekData}> <XAxis dataKey="week" tick={{ fill: G.muted, fontSize: 9 }} /> <YAxis domain={[40, 100]} tick={{ fill: G.muted, fontSize: 9 }} /> <Tooltip contentStyle={{ background: G.bg2, border: `1px solid ${G.border}`, borderRadius: 8 }} /> <Line type="monotone" dataKey="score" stroke={G.green} strokeWidth={2} dot={{ fill: G.green, r: 3 }} /> </LineChart> </ResponsiveContainer> </div> </div> </div>
<div className="sec-head">Score Breakdown</div> {factors.map(([n, v, c]) => ( <div key={n} style={{ marginBottom: 10 }}> <div style={{ display: "flex", justifyContent: "space-between", marginBottom: 3 }}> <span style={{ fontSize: 13 }}>{n}</span> <span style={{ color: c, fontWeight: 700 }}>{v}/100</span> </div> <div className="pbar-bg"><div className="pbar-fill" style={{ width: `${v}%`, background: c }} /></div> </div> ))}
<div className="sec-head">Driver Leaderboard</div> <div style={{ overflowX: "auto" }}> <table style={{ width: "100%", borderCollapse: "collapse", fontSize: 13 }}> <thead> <tr style={{ borderBottom: `1px solid ${G.border}` }}> {["Rank","Driver","Eco Score","Green Pts","CO2 Saved"].map(h => ( <th key={h} style={{ padding: "8px 10px", color: G.muted, textAlign: "left", fontSize: 11 }}>{h}</th> ))} </tr> </thead> <tbody> {leaderboard.map(row => ( <tr key={row.rank} style={{ borderBottom: `1px solid ${G.border}`, background: row.driver === state.username ? "#0d2318" : "transparent" }}> <td style={{ padding: "8px 10px" }}>{row.rank}</td> <td style={{ padding: "8px 10px", color: row.driver === state.username ? G.green2 : G.text, fontWeight: row.driver === state.username ? 700 : 400 }}>{row.driver}</td> <td style={{ padding: "8px 10px", fontFamily: "monospace", color: G.green2 }}>{row.score}</td> <td style={{ padding: "8px 10px", fontFamily: "monospace", color: G.amber }}>{row.pts}</td> <td style={{ padding: "8px 10px", fontFamily: "monospace", color: G.blue }}>{row.co2} kg</td> </tr> ))} </tbody> </table> </div> </div> );}
// βββ PAGE: REWARDS βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββfunction Rewards({ state }) { const pts = state.greenPoints;
const rewardList = [ { name: "β½ Fuel Voucher", cost: 50, desc: "Save R10 at participating fuel stations", color: G.amber }, { name: "π³ Petrol Discount 10%", cost: 120, desc: "10% off your next full tank", color: G.amber }, { name: "ποΈ Shopping Voucher R50", cost: 100, desc: "Redeem at partner retailers", color: G.blue }, { name: "π Transport Credit", cost: 80, desc: "Bus or taxi credit for 5 trips", color: G.green }, { name: "π§ Free Vehicle Check", cost: 200, desc: "Emission diagnostic + engine check", color: "#a78bfa" }, { name: "π³ Tree Planting Credit", cost: 30, desc: "Sponsor a tree planted in your name", color: G.green }, { name: "πͺ Partner Discounts", cost: 60, desc: "Discounts at eco-friendly stores", color: G.blue }, { name: "π Premium Eco Status", cost: 500, desc: "Unlock premium leaderboard + extra pts", color: G.amber }, ];
const earnTips = [ ["πΊοΈ Clean Routes", "+15 pts/trip"], ["β‘ Steady Speed", "+5 pts/trip"], ["π Public Transport", "+20 pts/trip"], ["π« No Idling", "+3 pts" ], ["π€ Carpool", "+25 pts/trip"], ["π§ Vehicle Service", "+50 pts" ], ];
return ( <div> <PageHead emoji="π" title="Rewards" sub="Convert your Green Points into real-world rewards" />
{/* Rewards card */} <div style={{ background: "linear-gradient(135deg,#0f2a0a,#1a3a10)", border: "1px solid #166534", borderRadius: 16, padding: 24, marginBottom: 16 }}> <div style={{ fontFamily: "monospace", fontSize: 10, color: "#86efac", letterSpacing: 3 }}>MELLOWTECH REWARDS CARD</div> <div className="mono" style={{ fontSize: 36, fontWeight: 900, color: G.green2, margin: "6px 0" }}>{pts} pts</div> <div style={{ color: G.green, fontSize: 13 }}>{state.username}</div> <div style={{ color: "#64748b", fontSize: 11, marginTop: 4 }}>{DATE_STR} Β· ACTIVE</div> </div>
{/* Reward tiles */} <div className="grid-2"> {rewardList.map(rw => { const can = pts >= rw.cost; return ( <div key={rw.name} className="reward-card" style={{ borderColor: can ? rw.color + "55" : G.border }}> <div style={{ fontWeight: 700, fontSize: 14, color: can ? G.text : "#334155" }}>{rw.name}</div> <div style={{ color: "#64748b", fontSize: 12, margin: "4px 0" }}>{rw.desc}</div> <div style={{ display: "flex", justifyContent: "space-between", alignItems: "center", marginTop: 8 }}> <span className="mono" style={{ fontSize: 18, fontWeight: 900, color: rw.color }}>{rw.cost} pts</span> <span style={{ fontSize: 11, fontWeight: 600, color: can ? rw.color : "#334155" }}> {can ? "Tap to Redeem β
" : `Need ${rw.cost - pts} more`} </span> </div> </div> ); })} </div>
{/* Earn tips */} <div className="sec-head">How to Earn Green Points</div> <div className="grid-2"> {earnTips.map(([tip, val]) => ( <div key={tip} style={{ background: "#071a0e", border: "1px solid #14532d", borderRadius: 10, padding: 12, textAlign: "center", marginBottom: 8 }}> <div style={{ fontWeight: 700, fontSize: 13, color: G.green2 }}>{tip}</div> <div className="mono" style={{ color: G.green, fontSize: 15, fontWeight: 900, marginTop: 4 }}>{val}</div> </div> ))} </div> </div> );}
// βββ PAGE: PROFILE ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββfunction Profile({ state, setState }) { const [name, setName] = useState(state.username); const [home, setHome] = useState(state.home); const [mode, setMode] = useState(state.drivingMode); const [saved, setSaved] = useState(false);
const s = state.ecoScore; const grade = s >= 80 ? "A" : s >= 65 ? "B" : s >= 50 ? "C" : "D"; const gCol = s >= 80 ? G.green : s >= 65 ? G.green2 : s >= 50 ? G.amber : G.red; const co2 = +(state.greenPoints * 0.12).toFixed(2); const fuel = +(state.greenPoints * 0.05).toFixed(2);
function save() { setState(prev => ({ ...prev, username: name, home, drivingMode: mode })); setSaved(true); setTimeout(() => setSaved(false), 2500); }
return ( <div> <PageHead emoji="π€" title="Profile" sub="Your account and preferences" />
<div style={{ display: "flex", gap: 12, flexWrap: "wrap", marginBottom: 16 }}> {/* Avatar card */} <div className="card" style={{ textAlign: "center", padding: 24, minWidth: 160 }}> <div style={{ fontSize: 44 }}>πΏ</div> <div style={{ fontSize: 17, fontWeight: 900, color: G.green, marginTop: 8 }}>{state.username}</div> <span className="badge" style={{ marginTop: 6 }}>GRADE {grade}</span> <hr style={{ borderColor: G.border, margin: "12px 0" }} /> <div style={{ color: "#64748b", fontSize: 11 }}>Member since {now.toLocaleDateString("en-ZA", { month: "short", year: "numeric" })}</div> <div className="mono" style={{ fontSize: 28, fontWeight: 900, color: gCol, marginTop: 10 }}>{s}/100</div> <div style={{ color: "#64748b", fontSize: 10, letterSpacing: 2 }}>ECO SCORE</div> <div className="mono" style={{ fontSize: 24, fontWeight: 900, color: G.green2, marginTop: 8 }}>{state.greenPoints}</div> <div style={{ color: "#64748b", fontSize: 10, letterSpacing: 2 }}>GREEN POINTS</div> </div>
{/* Preferences */} <div style={{ flex: 1, minWidth: 200 }}> <div className="sec-head">Preferences</div> <div style={{ marginBottom: 10 }}> <div className="lbl">DISPLAY NAME</div> <input className="inp" value={name} onChange={e => setName(e.target.value)} /> </div> <div style={{ marginBottom: 10 }}> <div className="lbl">HOME LOCATION</div> <select className="sel" value={home} onChange={e => setHome(e.target.value)}> {LOC_NAMES.map(l => <option key={l}>{l}</option>)} </select> </div> <div style={{ marginBottom: 14 }}> <div className="lbl">DEFAULT DRIVING MODE</div> <select className="sel" value={mode} onChange={e => setMode(e.target.value)}> {["Eco Mode","Normal Mode","Fast Mode"].map(m => <option key={m}>{m}</option>)} </select> </div> <button className="btn-green" onClick={save}>πΎ Save Preferences</button> {saved && ( <div className="alert-green" style={{ marginTop: 8 }}> <b style={{ color: G.green }}>β
Preferences saved!</b> </div> )} </div> </div>
{/* Impact metrics */} <div className="sec-head">My Environmental Impact</div> <div className="grid-4" style={{ gap: 10 }}> <KpiCard value={`${co2} kg`} label="CO2 SAVED" /> <KpiCard value={`${fuel} L`} label="FUEL SAVED" cls="card-amber" kvcls="kv-amber" /> <KpiCard value={`R${(fuel*22).toFixed(2)}`} label="MONEY SAVED" cls="card-blue" kvcls="kv-blue" /> <KpiCard value={state.trips} label="TRIPS DONE" /> </div>
<div className="alert-green" style={{ marginTop: 12 }}> <b style={{ color: G.green }}>Your Climate Contribution</b><br /> <span style={{ color: "#86efac", fontSize: 13 }}> By using MellowTech you help reduce urban air pollution and contribute to South Africa's climate goals. Every clean trip counts. </span> </div> </div> );}
// βββ ROOT APP βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββexport default function App() { // Auth state const [loggedIn, setLoggedIn] = useState(false); const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [loginErr, setLoginErr] = useState("");
// UI state const [drawerOpen, setDrawerOpen] = useState(false); const [page, setPage] = useState("dashboard");
// App data (shared across pages) const [appState, setAppState] = useState({ username: "", greenPoints: 0, ecoScore: 72, trips: 0, home: "Home", drivingMode: "Normal", weeklyScores: [55, 61, 58, 67, 70, 68, 72], });
// ββ Touch-swipe to open/close drawer βββββββββββββββββββββββββββββββββββββ const touchStartX = useRef(null); function onTouchStart(e) { touchStartX.current = e.touches[0].clientX; } function onTouchEnd(e) { if (touchStartX.current === null) return; const dx = e.changedTouches[0].clientX - touchStartX.current; if (dx > 60) setDrawerOpen(true); if (dx < -60) setDrawerOpen(false); touchStartX.current = null; }
// ββ Login βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ function login() { if (!username.trim()) { setLoginErr("Please enter a username."); return; } if (!password) { setLoginErr("Please enter a password."); return; } setAppState(s => ({ ...s, username: username.trim() })); setLoggedIn(true); }
// ββ Navigate ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ function navigate(id) { setPage(id); setDrawerOpen(false); }
// ββ Page map ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ const PAGES = { dashboard: <Dashboard state={appState} />, routes: <SmartRoutes state={appState} setState={setAppState} />, alerts: <EmissionAlerts />, analytics: <Analytics />, ecoscore: <EcoScore state={appState} />, rewards: <Rewards state={appState} />, profile: <Profile state={appState} setState={setAppState} />, };
// βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ return ( <> <style>{css}</style>
{/* ββ LOGIN SCREEN ββββββββββββββββββββββββββββββββββββββββββββββββββ */} {!loggedIn ? ( <div style={{ minHeight: "100vh", display: "flex", flexDirection: "column", justifyContent: "center" }}> <div style={{ textAlign: "center", marginBottom: 8 }}> <div style={{ fontSize: 40, fontWeight: 900, color: G.green2, letterSpacing: 4, fontFamily: "Share Tech Mono" }}> MELLOWTECH </div> <div style={{ color: G.muted, fontSize: 11, letterSpacing: 6, textTransform: "uppercase" }}> Smart Emission Intelligence System </div> </div>
<div className="login-wrap"> <h3 style={{ color: G.green, fontWeight: 900, marginBottom: 4 }}>Sign In</h3> <p style={{ color: G.muted, fontSize: 11, letterSpacing: 2, marginBottom: 20 }}> PROTECTING THE PLANET, ONE TRIP AT A TIME </p> <input className="inp" placeholder="Username" value={username} onChange={e => setUsername(e.target.value)} onKeyDown={e => e.key === "Enter" && login()} /> <input className="inp" type="password" placeholder="Password" value={password} onChange={e => setPassword(e.target.value)} onKeyDown={e => e.key === "Enter" && login()} /> {loginErr && <div style={{ color: G.red, fontSize: 13, marginBottom: 8 }}>{loginErr}</div>} <button className="btn-green" onClick={login}>Launch MellowTech</button> <p style={{ color: "#334155", fontSize: 11, marginTop: 14 }}>Demo: any username + any password</p> </div> </div>
) : ( /* ββ MAIN APP ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ */ <div onTouchStart={onTouchStart} onTouchEnd={onTouchEnd} style={{ minHeight: "100vh" }}>
{/* Dim overlay β tap to close drawer */} <div className={`drawer-overlay ${drawerOpen ? "" : "hidden"}`} onClick={() => setDrawerOpen(false)} />
{/* ββ Slide-out Drawer βββββββββββββββββββββββββββββββββββββββ */} <div className={`drawer ${drawerOpen ? "open" : ""}`}>
{/* Brand header */} <div style={{ padding: "20px 20px 14px", borderBottom: `1px solid ${G.border}` }}> <div style={{ color: G.green2, fontSize: 18, fontWeight: 900, letterSpacing: 3 }}>πΏ MELLOWTECH</div> <div style={{ color: "#334155", fontSize: 9, letterSpacing: 2, marginTop: 2 }}>EMISSION INTELLIGENCE</div> </div>
{/* User info */} <div style={{ padding: "12px 20px", borderBottom: `1px solid ${G.border}` }}> <div style={{ color: G.text, fontSize: 13, fontWeight: 600 }}>π€ {appState.username}</div> <div style={{ color: G.green, fontSize: 11, marginTop: 2 }}>{appState.greenPoints} Green Points</div> </div>
{/* Scrollable nav list */} <div style={{ flex: 1, overflowY: "auto", padding: "8px 0" }}> {NAV.map(n => ( <div key={n.id} className={`nav-item ${page === n.id ? "active" : ""}`} onClick={() => navigate(n.id)} > <span className="nav-icon">{n.icon}</span> <span>{n.label}</span> </div> ))} </div>
{/* Eco score strip */} <div style={{ padding: "12px 20px", borderTop: `1px solid ${G.border}` }}> <div style={{ color: G.muted, fontSize: 10, letterSpacing: 2, marginBottom: 4 }}>ECO SCORE</div> <div className="pbar-bg"> <div className="pbar-fill" style={{ width: `${appState.ecoScore}%`, background: G.green }} /> </div> <div style={{ color: G.green2, fontSize: 13, fontWeight: 700, marginTop: 4 }}>{appState.ecoScore}/100</div> </div>
{/* Sign out */} <div style={{ padding: "12px 20px", borderTop: `1px solid ${G.border}` }}> <button className="btn-sm" style={{ width: "100%" }} onClick={() => { setLoggedIn(false); setUsername(""); setPassword(""); setPage("dashboard"); }} > π Sign Out </button> </div> </div>
{/* ββ Sticky Top Bar βββββββββββββββββββββββββββββββββββββββββ */} <div className="topbar"> <button className="hamburger" onClick={() => setDrawerOpen(o => !o)} aria-label="Open menu"> <span /><span /><span /> </button> <span className="topbar-title">MELLOWTECH</span> <span style={{ marginLeft: "auto", color: IS_RUSH ? G.red : G.green, fontSize: 11, fontWeight: 700 }}> {IS_RUSH ? "β οΈ RUSH HOUR" : "β
TRAFFIC CLEAR"} </span> </div>
{/* ββ Page Content βββββββββββββββββββββββββββββββββββββββββββ */} <main className="content" style={{ paddingTop: 16 }}> {PAGES[page]} </main>
</div> )} </> );}mellowtech_full (2).jsxAdded+1012