// Transport operator (owner) screens — single role
// Maps to role === 'operator'

const { useState: useStateT } = React;

const OP_VEHICLES = [
  { id:'TS09 EQ 4421', sch:'DPS Hyderabad', driver:'Ramesh K.', route:'Route 14', state:'On route', clr:'var(--success)', bg:'var(--success-50)', dot:'#10B981', model:'Tata Starbus · 32 seater', km:84210, age:'2.4 yrs', fuel:78, speed:42, occ:22, cap:32 },
  { id:'TS09 GH 8821', sch:'Vidyaranya', driver:'Suresh M.', route:'Route 7', state:'Boarding', clr:'var(--p600)', bg:'var(--p50)', dot:'var(--p600)', model:'Eicher Skyline · 36 seater', km:62100, age:'1.8 yrs', fuel:54, speed:0, occ:18, cap:36 },
  { id:'TS09 BC 1102', sch:'Oakridge', driver:'Anand P.', route:'Route 3', state:'Service due', clr:'var(--warning)', bg:'var(--warning-50)', dot:'var(--warning)', model:'Ashok Leyland · 40 seater', km:128400, age:'3.7 yrs', fuel:30, speed:0, occ:0, cap:40 },
  { id:'TS09 KL 6655', sch:'Chirec', driver:'Mohan R.', route:'Route 9', state:'Garage', clr:'var(--n600)', bg:'var(--n100)', dot:'var(--n400)', model:'Force Traveller · 26 seater', km:54000, age:'1.2 yrs', fuel:62, speed:0, occ:0, cap:26 },
  { id:'TS09 MN 2244', sch:'DPS Hyderabad', driver:'Krishna L.', route:'Route 22', state:'On route', clr:'var(--success)', bg:'var(--success-50)', dot:'#10B981', model:'Tata Starbus · 32 seater', km:46900, age:'1.0 yrs', fuel:88, speed:38, occ:24, cap:32 },
  { id:'TS09 PQ 9911', sch:'Vidyaranya', driver:'Naveen B.', route:'Route 11', state:'On route', clr:'var(--success)', bg:'var(--success-50)', dot:'#10B981', model:'Eicher Skyline · 36 seater', km:71200, age:'2.0 yrs', fuel:65, speed:48, occ:28, cap:36 },
];

const OP_DRIVERS = [
  { name:'Ramesh K.', initial:'RK', clr:'p', phone:'+91 98765 11111', license:'TS-013-20210045', exp:'8 yrs', rating:4.9, trips:1240, route:'Route 14', state:'On duty', stateClr:'var(--success)', stateBg:'var(--success-50)', incidents:0 },
  { name:'Suresh M.', initial:'SM', clr:'coral', phone:'+91 98765 22222', license:'TS-014-20180022', exp:'12 yrs', rating:4.8, trips:2104, route:'Route 7', state:'On duty', stateClr:'var(--success)', stateBg:'var(--success-50)', incidents:1 },
  { name:'Anand P.', initial:'AP', clr:'green', phone:'+91 98765 33333', license:'TS-015-20190088', exp:'6 yrs', rating:4.6, trips:912, route:'Route 3', state:'Off (medical)', stateClr:'var(--warning)', stateBg:'var(--warning-50)', incidents:2 },
  { name:'Mohan R.', initial:'MR', clr:'p', phone:'+91 98765 44444', license:'TS-016-20170012', exp:'14 yrs', rating:4.7, trips:2580, route:'Route 9', state:'Standby', stateClr:'var(--n600)', stateBg:'var(--n100)', incidents:0 },
  { name:'Krishna L.', initial:'KL', clr:'coral', phone:'+91 98765 55555', license:'TS-017-20220031', exp:'4 yrs', rating:4.9, trips:540, route:'Route 22', state:'On duty', stateClr:'var(--success)', stateBg:'var(--success-50)', incidents:0 },
  { name:'Arjun T.', initial:'AT', clr:'green', phone:'+91 98765 66666', license:'TS-018-20200077', exp:'5 yrs', rating:5.0, trips:680, route:'Route 14B', state:'On duty', stateClr:'var(--success)', stateBg:'var(--success-50)', incidents:0 },
];

const OP_ROUTES = [
  { id:'R-14', name:'Route 14 · Madhapur ↔ DPS', stops:5, students:22, schools:'DPS · Vidyaranya', bus:'TS09 EQ 4421', km:18, time:'48m', state:'active' },
  { id:'R-7', name:'Route 7 · Kondapur ↔ Vidyaranya', stops:6, students:18, schools:'Vidyaranya', bus:'TS09 GH 8821', km:14, time:'42m', state:'active' },
  { id:'R-3', name:'Route 3 · Banjara ↔ Oakridge', stops:7, students:24, schools:'Oakridge', bus:'TS09 BC 1102', km:22, time:'56m', state:'paused' },
  { id:'R-9', name:'Route 9 · Jubilee ↔ Chirec', stops:5, students:17, schools:'Chirec', bus:'TS09 KL 6655', km:16, time:'44m', state:'paused' },
  { id:'R-22', name:'Route 22 · Gachibowli ↔ DPS', stops:6, students:24, schools:'DPS', bus:'TS09 MN 2244', km:20, time:'52m', state:'active' },
  { id:'R-11', name:'Route 11 · Kukatpally ↔ Vidyaranya', stops:8, students:28, schools:'Vidyaranya', bus:'TS09 PQ 9911', km:26, time:'1h 4m', state:'active' },
];

const OP_SCHOOLS = [
  { name:'DPS Hyderabad', students:142, buses:5, revenue:'₹6.4L', mom:'+8%', clr:'#1E40AF', bg:'var(--info-50)', contract:'2024-26 · renews Apr 2026', invoice:'Paid · Mar', status:'healthy', type:'school' },
  { name:'Vidyaranya High', students:188, buses:6, revenue:'₹7.8L', mom:'+12%', clr:'var(--success)', bg:'var(--success-50)', contract:'2023-25 · renews Mar 2026', invoice:'Paid · Mar', status:'healthy', type:'school' },
  { name:'Oakridge Intl.', students:124, buses:4, revenue:'₹5.2L', mom:'-3%', clr:'var(--c600)', bg:'var(--c50)', contract:'2024-26 · renews Jun 2026', invoice:'Due · ₹62k', status:'attention', type:'school' },
  { name:'Chirec Public', students:108, buses:3, revenue:'₹4.1L', mom:'+4%', clr:'#8B5CF6', bg:'#FAF5FF', contract:'2024-25 · renews Apr 2025', invoice:'Paid · Mar', status:'renewal', type:'school' },
  { name:'Private riders', students:46, buses:2, revenue:'₹2.3L', mom:'+22%', clr:'#9A3412', bg:'#FFF7ED', contract:'Direct enrolment · multi-school', invoice:'38 paid · 8 due', status:'private', type:'private' },
];

const OP_PRIVATE_RIDERS = [
  { name:'Aarav Reddy', cls:'Class 8 · DPS Hyderabad', stop:'Madhapur Junction', fee:'₹2,800/mo', state:'Active', stateClr:'var(--success)', stateBg:'var(--success-50)', parent:'Maya Reddy · +91 98765 12345', paid:true, since:'Jun 2024' },
  { name:'Diya Reddy', cls:'Class 5 · GIIS Pune (boarder)', stop:'Kondapur', fee:'₹2,800/mo', state:'Active', stateClr:'var(--success)', stateBg:'var(--success-50)', parent:'Maya Reddy · +91 98765 12345', paid:true, since:'Jun 2024' },
  { name:'Kabir Shah', cls:'Class 10 · Glendale Acad.', stop:'Hi-Tech City', fee:'₹3,200/mo', state:'Active', stateClr:'var(--success)', stateBg:'var(--success-50)', parent:'Rohit Shah · +91 99012 33344', paid:true, since:'Sep 2024' },
  { name:'Ananya Kapoor', cls:'Class 7 · Sancta Maria', stop:'Gachibowli', fee:'₹2,800/mo', state:'Payment due', stateClr:'var(--warning)', stateBg:'var(--warning-50)', parent:'Neha Kapoor · +91 90087 22211', paid:false, since:'Jan 2025' },
  { name:'Vihaan Iyer', cls:'Class 9 · Manthan Intl.', stop:'Botanical Gardens', fee:'₹3,000/mo', state:'Active', stateClr:'var(--success)', stateBg:'var(--success-50)', parent:'Lakshmi Iyer · +91 90876 54321', paid:true, since:'Apr 2024' },
  { name:'Saanvi Naidu', cls:'Class 6 · Delhi Public North', stop:'Madhapur Junction', fee:'₹2,800/mo', state:'New · Mar 1', stateClr:'var(--p600)', stateBg:'var(--p50)', parent:'Karthik Naidu · +91 99234 11122', paid:false, since:'Mar 2025' },
];

const OP_INCIDENTS = [
  { sev:'critical', cat:'BREAKDOWN', when:'Today · 7:48 AM', title:'Bus TS09 BC 1102 — engine warning', sub:'Anand P. · Route 3 · 24 students re-routed to TS09 KL 6655', state:'open' },
  { sev:'high', cat:'DELAY', when:'Today · 7:32 AM', title:'Route 7 running 12 min late', sub:'Heavy traffic at Hi-Tech City flyover · DPS notified', state:'monitoring' },
  { sev:'med', cat:'COMPLAINT', when:'Yesterday', title:'Parent complaint — rough driving', sub:'Suresh M. (Route 7) · pending review', state:'open' },
  { sev:'low', cat:'MAINTENANCE', when:'2 days ago', title:'Service overdue — TS09 BC 1102', sub:'Booked at Maruti garage · Mar 16 · 8 AM', state:'scheduled' },
  { sev:'low', cat:'RESOLVED', when:'5 days ago', title:'AC repair completed', sub:'TS09 GH 8821 · ₹14,200 invoice', state:'closed' },
];

// ─────────────────────────────────────────────────────────────
// LIVE — map of all buses
// ─────────────────────────────────────────────────────────────
function OperatorLiveScreen({ nav }) {
  const [filter, setFilter] = useStateT('all');
  const buses = OP_VEHICLES.filter(v => filter === 'all' ? true : v.state === 'On route');
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title="Live fleet" onBack={() => nav.pop()} right={<button style={{ width:36,height:36,borderRadius:10,background:'var(--n50)',display:'grid',placeItems:'center'}}><Icon name="search" size={16}/></button>}/>
      <div className="app-body no-pad">
        {/* Map placeholder */}
        <div style={{ height: 320, position: 'relative', background: 'linear-gradient(135deg,#E0F2FE 0%,#F0F9FF 50%,#FEF3C7 100%)', borderBottom: '1px solid var(--n100)', overflow: 'hidden' }}>
          {/* Grid lines */}
          <svg style={{ position: 'absolute', inset: 0, width: '100%', height: '100%', opacity: .35 }}>
            <defs>
              <pattern id="grid" width="40" height="40" patternUnits="userSpaceOnUse"><path d="M 40 0 L 0 0 0 40" fill="none" stroke="#94A3B8" strokeWidth=".5"/></pattern>
            </defs>
            <rect width="100%" height="100%" fill="url(#grid)"/>
            {/* Simulated roads */}
            <path d="M 0 200 Q 100 180 180 220 T 360 200" stroke="#64748B" strokeWidth="6" fill="none" opacity=".25"/>
            <path d="M 60 0 L 100 320" stroke="#64748B" strokeWidth="4" fill="none" opacity=".25"/>
            <path d="M 240 0 Q 260 160 220 320" stroke="#64748B" strokeWidth="4" fill="none" opacity=".25"/>
          </svg>
          {/* Bus pins */}
          {[
            { x: 60, y: 80, color: '#10B981', label: '14' },
            { x: 180, y: 140, color: '#10B981', label: '22' },
            { x: 280, y: 100, color: 'var(--p600)', label: '7' },
            { x: 110, y: 220, color: '#10B981', label: '11' },
            { x: 250, y: 240, color: 'var(--warning)', label: '3' },
            { x: 320, y: 180, color: 'var(--n400)', label: '9' },
          ].map((p, i) => (
            <div key={i} style={{ position: 'absolute', left: p.x, top: p.y, transform: 'translate(-50%,-100%)' }}>
              <div style={{ width: 32, height: 32, borderRadius: '50% 50% 50% 0', transform: 'rotate(-45deg)', background: p.color, boxShadow: '0 4px 12px rgba(0,0,0,.2)', border: '2px solid #fff', display: 'grid', placeItems: 'center' }}>
                <span style={{ transform: 'rotate(45deg)', color: '#fff', fontSize: 10, fontWeight: 800, fontFamily: 'var(--mono)' }}>{p.label}</span>
              </div>
            </div>
          ))}
          {/* Legend */}
          <div style={{ position: 'absolute', bottom: 12, left: 12, right: 12, background: 'rgba(255,255,255,.95)', backdropFilter: 'blur(8px)', borderRadius: 12, padding: '8px 12px', display: 'flex', gap: 14, fontSize: 10, fontWeight: 600, color: 'var(--n700)' }}>
            <span className="row" style={{ gap: 4 }}><span className="dot" style={{ background: '#10B981' }}></span>On route</span>
            <span className="row" style={{ gap: 4 }}><span className="dot" style={{ background: 'var(--p600)' }}></span>Boarding</span>
            <span className="row" style={{ gap: 4 }}><span className="dot" style={{ background: 'var(--warning)' }}></span>Issue</span>
            <span className="row" style={{ gap: 4 }}><span className="dot" style={{ background: 'var(--n400)' }}></span>Garage</span>
          </div>
        </div>
        {/* Filter chips */}
        <div className="row" style={{ gap: 6, padding: '12px 20px 0', overflowX: 'auto' }}>
          {[{id:'all',l:'All · 18'},{id:'running',l:'On route · 14'},{id:'late',l:'Late · 1'},{id:'idle',l:'Idle · 3'}].map(f => (
            <button key={f.id} onClick={() => setFilter(f.id)} style={{ flexShrink:0, padding:'7px 12px', fontSize:11, fontWeight:700, borderRadius:99, background: filter === f.id ? 'var(--n900)' : 'var(--n50)', color: filter === f.id ? '#fff' : 'var(--n700)', border:'none' }}>{f.l}</button>
          ))}
        </div>
        {/* Bus list */}
        <div style={{ padding: '14px 20px 20px' }}>
          {buses.map((b, i) => (
            <button key={i} onClick={() => nav.push('opVehicle', b)} className="row card" style={{ padding: 12, gap: 12, marginBottom: 8, width:'100%', textAlign:'left' }}>
              <div style={{ width: 44, height: 44, borderRadius: 12, background: b.bg, color: b.clr, display: 'grid', placeItems: 'center', fontSize: 20 }}>🚌</div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div className="spread">
                  <div style={{ fontSize: 12, fontFamily: 'var(--mono)', fontWeight: 800, color: 'var(--n900)' }}>{b.id}</div>
                  <span style={{ fontSize: 9.5, padding: '3px 8px', background: b.bg, color: b.clr, borderRadius: 99, fontWeight: 700 }}><span className="dot" style={{ background: b.dot, marginRight: 4 }}></span>{b.state}</span>
                </div>
                <div style={{ fontSize: 11, color: 'var(--n500)', marginTop: 2 }}>{b.route} · {b.driver} · {b.occ}/{b.cap} students</div>
              </div>
              <Icon name="chev-r" size={14} style={{ color: 'var(--n400)' }}/>
            </button>
          ))}
        </div>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// FLEET — vehicle list
// ─────────────────────────────────────────────────────────────
function OperatorFleetScreen({ nav }) {
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title="Vehicles" onBack={() => nav.pop()} right={<button onClick={() => nav.push('opAddVehicle')} className="btn-sm" style={{ background:'var(--p600)', color:'#fff', height:32, padding:'0 12px', fontSize:11, fontWeight:700, borderRadius:8, border:'none' }}><Icon name="plus" size={12}/> Add bus</button>}/>
      <div className="app-body">
        <div className="card-flat" style={{ padding: 14, marginBottom: 14, display:'grid', gridTemplateColumns:'repeat(4,1fr)', gap:10 }}>
          {[{v:'18',l:'Total'},{v:'14',l:'Running'},{v:'1',l:'Service'},{v:'3',l:'Garage'}].map((s,i)=>(
            <div key={i} style={{ borderRight: i<3?'1px solid var(--n100)':'none' }}>
              <div style={{ fontSize:18, fontWeight:800, color:'var(--n900)', fontVariantNumeric:'tabular-nums' }}>{s.v}</div>
              <div style={{ fontSize:10, color:'var(--n500)', fontWeight:600, marginTop:2 }}>{s.l}</div>
            </div>
          ))}
        </div>
        {OP_VEHICLES.map((v, i) => (
          <button key={i} onClick={() => nav.push('opVehicle', v)} className="card" style={{ padding: 14, marginBottom: 8, width:'100%', textAlign:'left' }}>
            <div className="row" style={{ gap: 12 }}>
              <div style={{ width: 48, height: 48, borderRadius: 12, background: v.bg, color: v.clr, display: 'grid', placeItems: 'center', fontSize: 22 }}>🚌</div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div className="spread">
                  <div style={{ fontSize: 13, fontFamily: 'var(--mono)', fontWeight: 800, color: 'var(--n900)' }}>{v.id}</div>
                  <span style={{ fontSize: 9.5, padding: '3px 8px', background: v.bg, color: v.clr, borderRadius: 99, fontWeight: 700 }}><span className="dot" style={{ background: v.dot, marginRight: 4 }}></span>{v.state}</span>
                </div>
                <div style={{ fontSize: 11, color: 'var(--n500)', marginTop: 2 }}>{v.model}</div>
                <div className="row" style={{ gap: 12, marginTop: 8, fontSize: 10, color: 'var(--n600)' }}>
                  <span><b style={{ color: 'var(--n900)' }}>{v.driver}</b> · {v.route}</span>
                  <span style={{ marginLeft: 'auto', fontFamily: 'var(--mono)' }}>{v.km.toLocaleString()} km</span>
                </div>
              </div>
            </div>
          </button>
        ))}
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// VEHICLE DETAIL
// ─────────────────────────────────────────────────────────────
function OperatorVehicleDetail({ nav, params }) {
  const v = params || OP_VEHICLES[0];
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title={v.id} onBack={() => nav.pop()} right={<button style={{ width:36,height:36,borderRadius:10,background:'var(--n50)',display:'grid',placeItems:'center'}}><Icon name="more" size={16}/></button>}/>
      <div className="app-body">
        <div className="card-grad" style={{ padding: 18 }}>
          <div className="row" style={{ gap: 14 }}>
            <div style={{ width: 60, height: 60, borderRadius: 14, background: 'rgba(255,255,255,.22)', display: 'grid', placeItems: 'center', fontSize: 32 }}>🚌</div>
            <div style={{ flex: 1 }}>
              <div style={{ fontSize: 16, fontWeight: 800, fontFamily: 'var(--mono)' }}>{v.id}</div>
              <div style={{ fontSize: 12, opacity: .9, marginTop: 2 }}>{v.model}</div>
              <div style={{ fontSize: 10, opacity: .8, marginTop: 4, fontFamily: 'var(--mono)', fontWeight: 600 }}>AGE {v.age.toUpperCase()} · {v.km.toLocaleString()} KM</div>
            </div>
          </div>
          <div style={{ marginTop: 14, paddingTop: 14, borderTop: '1px solid rgba(255,255,255,.18)', display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 10 }}>
            <div><div style={{ fontSize: 18, fontWeight: 800, fontVariantNumeric: 'tabular-nums' }}>{v.fuel}%</div><div style={{ fontSize: 10, opacity: .85, fontWeight: 600 }}>Fuel</div></div>
            <div><div style={{ fontSize: 18, fontWeight: 800, fontVariantNumeric: 'tabular-nums' }}>{v.speed}<span style={{fontSize:10,opacity:.7}}> km/h</span></div><div style={{ fontSize: 10, opacity: .85, fontWeight: 600 }}>Speed</div></div>
            <div><div style={{ fontSize: 18, fontWeight: 800, fontVariantNumeric: 'tabular-nums' }}>{v.occ}/{v.cap}</div><div style={{ fontSize: 10, opacity: .85, fontWeight: 600 }}>Riders</div></div>
          </div>
        </div>

        <div style={{ marginTop:14, display:'grid', gridTemplateColumns:'repeat(2,1fr)', gap:8 }}>
          <button className="btn btn-soft" style={{ height:42 }}><Icon name="pin" size={14}/> Live track</button>
          <button className="btn btn-soft" style={{ height:42 }}><Icon name="clipboard" size={14}/> Service log</button>
        </div>

        <div className="card-flat" style={{ padding: 14, marginTop: 14 }}>
          <div style={{ fontSize: 12, fontWeight: 700, color: 'var(--n900)', marginBottom: 10 }}>Assigned</div>
          {[
            { lab: 'Driver', val: v.driver, sub: '+91 98765 11111', ic: 'user' },
            { lab: 'Route', val: v.route, sub: `${v.sch}`, ic: 'pin' },
            { lab: 'Insurance', val: 'Valid · expires Aug 2026', sub: 'Bharti AXA · Premium ₹42,000', ic: 'shield' },
            { lab: 'PUC', val: 'Valid · expires May 2025', sub: '63 days remaining', ic: 'check' },
            { lab: 'Fitness cert.', val: 'Valid · expires Dec 2026', sub: 'TS RTO Hyderabad', ic: 'clipboard' },
          ].map((it, i, arr) => (
            <div key={i} className="row" style={{ padding: '10px 0', borderBottom: i < arr.length-1?'1px solid var(--n100)':'none', gap: 10 }}>
              <div style={{ width: 32, height: 32, borderRadius: 9, background: 'var(--n50)', color: 'var(--n700)', display: 'grid', placeItems: 'center' }}><Icon name={it.ic} size={15}/></div>
              <div style={{ flex: 1 }}>
                <div style={{ fontSize: 10, color: 'var(--n500)', fontWeight: 700, letterSpacing: '.04em', textTransform: 'uppercase' }}>{it.lab}</div>
                <div style={{ fontSize: 12, fontWeight: 700, color: 'var(--n900)', marginTop: 1 }}>{it.val}</div>
                <div style={{ fontSize: 10, color: 'var(--n500)', marginTop: 1 }}>{it.sub}</div>
              </div>
            </div>
          ))}
        </div>

        <SH title="Recent maintenance" right={<button className="btn-ghost" style={{ fontSize: 11 }}>All</button>}/>
        <div className="card" style={{ padding: 0 }}>
          {[
            { d: 'Mar 10', t: 'Brake pad replacement', who: 'Maruti garage · ₹8,400', clr: 'var(--success)' },
            { d: 'Feb 22', t: 'AC condenser fix', who: 'Tata service · ₹14,200', clr: 'var(--success)' },
            { d: 'Jan 14', t: 'Engine oil + filter', who: 'In-house · ₹3,200', clr: 'var(--success)' },
          ].map((m, i, arr) => (
            <div key={i} className="row" style={{ padding: 12, gap: 10, borderBottom: i<arr.length-1?'1px solid var(--n100)':'none' }}>
              <div style={{ width: 8, height: 8, borderRadius: 99, background: m.clr }}></div>
              <div style={{ flex: 1 }}>
                <div style={{ fontSize: 12, fontWeight: 700, color: 'var(--n900)' }}>{m.t}</div>
                <div style={{ fontSize: 10.5, color: 'var(--n500)' }}>{m.who}</div>
              </div>
              <div style={{ fontSize: 10, color: 'var(--n500)', fontFamily:'var(--mono)', fontWeight:600 }}>{m.d}</div>
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// DRIVERS roster
// ─────────────────────────────────────────────────────────────
function OperatorDriversScreen({ nav }) {
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title="Drivers" onBack={() => nav.pop()} right={<button onClick={() => nav.push('opAddDriver')} className="btn-sm" style={{ background:'var(--p600)', color:'#fff', height:32, padding:'0 12px', fontSize:11, fontWeight:700, borderRadius:8, border:'none' }}><Icon name="plus" size={12}/> Onboard</button>}/>
      <div className="app-body">
        <div className="card-flat" style={{ padding: 14, marginBottom: 14, display:'grid', gridTemplateColumns:'repeat(4,1fr)', gap:10 }}>
          {[{v:'22',l:'Total'},{v:'18',l:'On duty'},{v:'2',l:'Off'},{v:'2',l:'Standby'}].map((s,i)=>(
            <div key={i} style={{ borderRight: i<3?'1px solid var(--n100)':'none' }}>
              <div style={{ fontSize:18, fontWeight:800, color:'var(--n900)', fontVariantNumeric:'tabular-nums' }}>{s.v}</div>
              <div style={{ fontSize:10, color:'var(--n500)', fontWeight:600, marginTop:2 }}>{s.l}</div>
            </div>
          ))}
        </div>
        {OP_DRIVERS.map((d, i) => (
          <button key={i} onClick={() => nav.push('opDriver', d)} className="card" style={{ padding: 14, marginBottom: 8, width:'100%', textAlign:'left' }}>
            <div className="row" style={{ gap: 12 }}>
              <div className={`av av-44 ${d.clr}`}>{d.initial}</div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div className="spread">
                  <div style={{ fontSize: 13, fontWeight: 800, color: 'var(--n900)' }}>{d.name}</div>
                  <span style={{ fontSize: 9.5, padding: '3px 8px', background: d.stateBg, color: d.stateClr, borderRadius: 99, fontWeight: 700 }}>{d.state}</span>
                </div>
                <div style={{ fontSize: 11, color: 'var(--n500)', marginTop: 2 }}>{d.route} · {d.exp} experience</div>
                <div className="row" style={{ gap: 10, marginTop: 8, fontSize: 10, color: 'var(--n600)' }}>
                  <span className="row" style={{ gap: 3 }}><span style={{color:'#F59E0B'}}>★</span><b style={{color:'var(--n900)'}}>{d.rating}</b></span>
                  <span><b style={{color:'var(--n900)'}}>{d.trips}</b> trips</span>
                  {d.incidents > 0 && <span style={{ color: 'var(--c600)' }}>{d.incidents} incident{d.incidents>1?'s':''}</span>}
                </div>
              </div>
            </div>
          </button>
        ))}
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// DRIVER DETAIL
// ─────────────────────────────────────────────────────────────
function OperatorDriverDetail({ nav, params }) {
  const d = params || OP_DRIVERS[0];
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title={d.name} onBack={() => nav.pop()} right={<button style={{ width:36,height:36,borderRadius:10,background:'var(--n50)',display:'grid',placeItems:'center'}}><Icon name="phone" size={16}/></button>}/>
      <div className="app-body">
        <div className="card-grad" style={{ padding: 18 }}>
          <div className="row" style={{ gap: 14 }}>
            <div className="av av-56" style={{ background: 'rgba(255,255,255,.25)', color: '#fff', border: '2px solid rgba(255,255,255,.4)', width: 64, height: 64, fontSize: 22 }}>{d.initial}</div>
            <div style={{ flex: 1 }}>
              <div style={{ fontSize: 18, fontWeight: 800 }}>{d.name}</div>
              <div style={{ fontSize: 12, opacity: .9, marginTop: 2 }}>{d.route} · {d.exp} experience</div>
              <div style={{ fontSize: 10, opacity: .8, marginTop: 4, fontFamily: 'var(--mono)' }}>LIC {d.license}</div>
            </div>
          </div>
          <div style={{ marginTop: 14, paddingTop: 14, borderTop: '1px solid rgba(255,255,255,.18)', display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 10 }}>
            <div><div style={{ fontSize: 22, fontWeight: 800 }}>★ {d.rating}</div><div style={{ fontSize: 10, opacity: .85, fontWeight: 600 }}>From {d.trips}</div></div>
            <div><div style={{ fontSize: 22, fontWeight: 800, fontVariantNumeric: 'tabular-nums' }}>{d.trips}</div><div style={{ fontSize: 10, opacity: .85, fontWeight: 600 }}>Total trips</div></div>
            <div><div style={{ fontSize: 22, fontWeight: 800, fontVariantNumeric: 'tabular-nums' }}>{d.incidents}</div><div style={{ fontSize: 10, opacity: .85, fontWeight: 600 }}>Incidents</div></div>
          </div>
        </div>

        <div className="card-flat" style={{ padding: 14, marginTop: 14 }}>
          <div style={{ fontSize: 12, fontWeight: 700, color: 'var(--n900)', marginBottom: 10 }}>Documents</div>
          {[
            { lab:'Driver license', val:'Valid · expires Sep 2027', ic:'check', clr:'var(--success)' },
            { lab:'Police verification', val:'Cleared · Mar 2024', ic:'shield', clr:'var(--success)' },
            { lab:'Medical fitness', val: d.state.includes('medical') ? 'On leave · doc submitted' : 'Valid · annual', ic:'clipboard', clr: d.state.includes('medical')?'var(--warning)':'var(--success)' },
            { lab:'Training', val:'Defensive driving · Dec 2024', ic:'trophy', clr:'var(--success)' },
          ].map((it, i, arr) => (
            <div key={i} className="row" style={{ padding: '10px 0', gap: 10, borderBottom: i<arr.length-1?'1px solid var(--n100)':'none' }}>
              <div style={{ width: 28, height: 28, borderRadius: 8, background: 'var(--n50)', color: it.clr, display: 'grid', placeItems: 'center' }}><Icon name={it.ic} size={14}/></div>
              <div style={{ flex: 1 }}>
                <div style={{ fontSize: 12, fontWeight: 700, color: 'var(--n900)' }}>{it.lab}</div>
                <div style={{ fontSize: 10.5, color: 'var(--n500)' }}>{it.val}</div>
              </div>
              <Icon name="chev-r" size={14} style={{ color:'var(--n400)' }}/>
            </div>
          ))}
        </div>

        <SH title="Recent trips"/>
        <div className="card" style={{ padding: 0 }}>
          {[
            { d:'Today AM', r:'Route 14 · Madhapur', dur:'48m', dist:'18 km', stars:5 },
            { d:'Yest PM', r:'Route 14 · DPS', dur:'52m', dist:'18 km', stars:5 },
            { d:'Yest AM', r:'Route 14 · Madhapur', dur:'46m', dist:'18 km', stars:4 },
          ].map((t, i, arr) => (
            <div key={i} className="row" style={{ padding: 12, gap: 10, borderBottom: i<arr.length-1?'1px solid var(--n100)':'none' }}>
              <div style={{ flex: 1 }}>
                <div style={{ fontSize: 12, fontWeight: 700, color: 'var(--n900)' }}>{t.r}</div>
                <div style={{ fontSize: 10.5, color: 'var(--n500)', fontFamily:'var(--mono)' }}>{t.d} · {t.dur} · {t.dist}</div>
              </div>
              <div style={{ fontSize: 11, color:'#F59E0B' }}>{'★'.repeat(t.stars)}</div>
            </div>
          ))}
        </div>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// ROUTES
// ─────────────────────────────────────────────────────────────
function OperatorRoutesScreen({ nav }) {
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title="Routes" onBack={() => nav.pop()} right={<button onClick={() => nav.push('opAddRoute')} className="btn-sm" style={{ background:'var(--p600)', color:'#fff', height:32, padding:'0 12px', fontSize:11, fontWeight:700, borderRadius:8, border:'none' }}><Icon name="plus" size={12}/> New</button>}/>
      <div className="app-body">
        <div className="card-flat" style={{ padding: 14, marginBottom: 14, display:'grid', gridTemplateColumns:'repeat(3,1fr)', gap:10 }}>
          {[{v:'24',l:'Routes'},{v:'18',l:'Active'},{v:'562',l:'Daily riders'}].map((s,i)=>(
            <div key={i} style={{ borderRight: i<2?'1px solid var(--n100)':'none' }}>
              <div style={{ fontSize:18, fontWeight:800, color:'var(--n900)', fontVariantNumeric:'tabular-nums' }}>{s.v}</div>
              <div style={{ fontSize:10, color:'var(--n500)', fontWeight:600, marginTop:2 }}>{s.l}</div>
            </div>
          ))}
        </div>
        {OP_ROUTES.map((r, i) => (
          <button key={i} onClick={() => nav.push('opRoute', r)} className="card" style={{ padding: 14, marginBottom: 8, width:'100%', textAlign:'left' }}>
            <div className="spread">
              <div style={{ flex: 1, minWidth: 0 }}>
                <div className="row" style={{ gap: 6 }}>
                  <span style={{ fontSize: 10, padding: '2px 7px', background: r.state==='active'?'var(--success-50)':'var(--warning-50)', color: r.state==='active'?'var(--success)':'var(--warning)', borderRadius: 99, fontWeight: 700 }}>{r.state.toUpperCase()}</span>
                  <span style={{ fontSize: 10, color:'var(--n500)', fontFamily:'var(--mono)', fontWeight: 700 }}>{r.id}</span>
                </div>
                <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--n900)', marginTop: 6 }}>{r.name}</div>
                <div style={{ fontSize: 11, color: 'var(--n500)', marginTop: 2 }}>{r.schools}</div>
              </div>
            </div>
            <div className="row" style={{ marginTop: 12, paddingTop: 12, borderTop: '1px dashed var(--n100)', gap: 14, fontSize: 11, color: 'var(--n600)' }}>
              <span><b style={{ color:'var(--n900)'}}>{r.stops}</b> stops</span>
              <span><b style={{ color:'var(--n900)'}}>{r.students}</b> riders</span>
              <span style={{ marginLeft:'auto', fontFamily:'var(--mono)' }}>{r.km} km · {r.time}</span>
            </div>
          </button>
        ))}
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// ROUTE DETAIL
// ─────────────────────────────────────────────────────────────
function OperatorRouteDetail({ nav, params }) {
  const r = params || OP_ROUTES[0];
  const stops = [
    { n:'Depot', t:'07:30', kids:0 },
    { n:'Madhapur Junction', t:'07:42', kids:4 },
    { n:'Hi-Tech City', t:'07:54', kids:6 },
    { n:'Kondapur', t:'08:02', kids:5 },
    { n:'Botanical Gardens', t:'08:12', kids:3 },
    { n:'Gachibowli (last)', t:'08:20', kids:4 },
  ];
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title={r.id} onBack={() => nav.pop()} right={<button style={{ width:36,height:36,borderRadius:10,background:'var(--n50)',display:'grid',placeItems:'center'}}><Icon name="edit" size={16}/></button>}/>
      <div className="app-body">
        <div className="card-grad" style={{ padding: 18 }}>
          <div style={{ fontSize: 11, opacity: .9, fontFamily: 'var(--mono)', fontWeight: 700, letterSpacing: '.06em' }}>{r.id} · {r.state.toUpperCase()}</div>
          <div style={{ fontSize: 18, fontWeight: 800, marginTop: 4, letterSpacing: '-.01em' }}>{r.name}</div>
          <div style={{ fontSize: 12, opacity: .9, marginTop: 2 }}>{r.schools} · bus {r.bus}</div>
          <div style={{ marginTop: 14, paddingTop: 14, borderTop: '1px solid rgba(255,255,255,.18)', display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: 10 }}>
            <div><div style={{ fontSize: 18, fontWeight: 800 }}>{r.stops}</div><div style={{ fontSize: 9, opacity: .85, fontWeight: 600 }}>STOPS</div></div>
            <div><div style={{ fontSize: 18, fontWeight: 800 }}>{r.students}</div><div style={{ fontSize: 9, opacity: .85, fontWeight: 600 }}>RIDERS</div></div>
            <div><div style={{ fontSize: 18, fontWeight: 800 }}>{r.km}</div><div style={{ fontSize: 9, opacity: .85, fontWeight: 600 }}>KM</div></div>
            <div><div style={{ fontSize: 14, fontWeight: 800 }}>{r.time}</div><div style={{ fontSize: 9, opacity: .85, fontWeight: 600 }}>DURATION</div></div>
          </div>
        </div>

        <SH title="Stops"/>
        <div className="card" style={{ padding: 16, position: 'relative' }}>
          <div style={{ position: 'absolute', left: 27, top: 24, bottom: 24, width: 2, background: 'var(--n100)' }}></div>
          {stops.map((s, i) => (
            <div key={i} className="row" style={{ gap: 14, padding: '10px 0', position: 'relative', zIndex: 1 }}>
              <div style={{ width: 16, height: 16, borderRadius: 99, flexShrink: 0, background: i===0?'var(--n400)':'#fff', border: i===0?'0':'2px solid var(--p400)' }}></div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div className="spread">
                  <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--n900)' }}>{s.n}</div>
                  <div style={{ fontSize: 11, fontFamily: 'var(--mono)', fontWeight: 700, color: 'var(--n500)' }}>{s.t}</div>
                </div>
                {s.kids > 0 && <div style={{ fontSize: 10.5, color: 'var(--n500)', marginTop: 2 }}>{s.kids} students board</div>}
              </div>
              <button style={{ width:28, height:28, borderRadius:8, background:'var(--n50)', color:'var(--n600)', display:'grid', placeItems:'center', flexShrink:0 }}><Icon name="more" size={12}/></button>
            </div>
          ))}
        </div>

        <div style={{ marginTop:14, display:'grid', gridTemplateColumns:'repeat(2,1fr)', gap:8 }}>
          <button className="btn btn-soft" style={{ height:42 }}><Icon name="users" size={14}/> Students ({r.students})</button>
          <button className="btn btn-soft" style={{ height:42 }}><Icon name="bus" size={14}/> Reassign bus</button>
        </div>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// SCHOOLS / CONTRACTS
// ─────────────────────────────────────────────────────────────
function OperatorSchoolsScreen({ nav }) {
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title="Contracts & riders" onBack={() => nav.pop()}/>
      <div className="app-body">
        <div className="card-grad-coral" style={{ padding: 16 }}>
          <div style={{ fontSize: 10, opacity: .85, fontFamily: 'var(--mono)', letterSpacing: '.08em', fontWeight: 700 }}>MAR REVENUE · ALL CONTRACTS</div>
          <div style={{ fontSize: 30, fontWeight: 800, marginTop: 4, fontVariantNumeric: 'tabular-nums', letterSpacing: '-.02em' }}>₹23.5L</div>
          <div className="row" style={{ gap: 10, marginTop: 6, fontSize: 11, opacity: .9 }}>
            <span>↑ 7% MoM</span><span>·</span><span>562 active riders</span>
          </div>
        </div>

        <div style={{ marginTop:14 }}>
          {OP_SCHOOLS.map((s, i) => (
            <button key={i} onClick={() => s.type==='private' ? nav.push('opPrivateRiders') : nav.push('opSchool', s)} className="card" style={{ padding: 14, marginBottom: 8, width:'100%', textAlign:'left' }}>
              <div className="row" style={{ gap: 12 }}>
                <div style={{ width: 44, height: 44, borderRadius: 11, background: s.bg, color: s.clr, display: 'grid', placeItems: 'center', fontSize: 16, fontWeight: 800 }}>{s.type==='private'?'👤':s.name.charAt(0)}</div>
                <div style={{ flex: 1, minWidth: 0 }}>
                  <div className="spread">
                    <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--n900)' }}>{s.name}</div>
                    {s.status === 'attention' && <span className="pill" style={{ background:'var(--warning-50)', color:'var(--warning)', fontSize:9, padding:'2px 7px', border:'none', fontWeight:700 }}>NEEDS ATTENTION</span>}
                    {s.status === 'renewal' && <span className="pill" style={{ background:'var(--p50)', color:'var(--p700)', fontSize:9, padding:'2px 7px', border:'none', fontWeight:700 }}>RENEWAL SOON</span>}
                    {s.status === 'private' && <span className="pill" style={{ background:'#FFF7ED', color:'#9A3412', fontSize:9, padding:'2px 7px', border:'none', fontWeight:700 }}>B2C · DIRECT</span>}
                  </div>
                  <div style={{ fontSize: 11, color: 'var(--n500)', marginTop: 2 }}>{s.contract}</div>
                </div>
              </div>
              <div className="row" style={{ marginTop: 12, paddingTop: 12, borderTop: '1px dashed var(--n100)', gap: 14, fontSize: 11, color: 'var(--n600)' }}>
                <span><b style={{ color:'var(--n900)'}}>{s.students}</b> riders</span>
                <span><b style={{ color:'var(--n900)'}}>{s.buses}</b> buses</span>
                <span style={{ marginLeft:'auto' }}><b style={{ color: s.mom.startsWith('-')?'var(--c600)':'var(--success)' }}>{s.revenue} {s.mom}</b></span>
              </div>
            </button>
          ))}
        </div>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// SCHOOL CONTRACT DETAIL
// ─────────────────────────────────────────────────────────────
function OperatorSchoolDetail({ nav, params }) {
  const s = params || OP_SCHOOLS[0];
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title={s.name} onBack={() => nav.pop()} right={<button style={{ width:36,height:36,borderRadius:10,background:'var(--n50)',display:'grid',placeItems:'center'}}><Icon name="message" size={16}/></button>}/>
      <div className="app-body">
        <div className="card-grad" style={{ padding: 18 }}>
          <div style={{ fontSize: 10, opacity: .9, fontFamily: 'var(--mono)', fontWeight: 700, letterSpacing: '.06em' }}>CONTRACT</div>
          <div style={{ fontSize: 18, fontWeight: 800, marginTop: 4 }}>{s.name}</div>
          <div style={{ fontSize: 11, opacity: .9, marginTop: 2 }}>{s.contract}</div>
          <div style={{ marginTop: 14, paddingTop: 14, borderTop: '1px solid rgba(255,255,255,.18)', display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 10 }}>
            <div><div style={{ fontSize: 18, fontWeight: 800 }}>{s.students}</div><div style={{ fontSize: 9, opacity: .85, fontWeight: 600 }}>RIDERS</div></div>
            <div><div style={{ fontSize: 18, fontWeight: 800 }}>{s.buses}</div><div style={{ fontSize: 9, opacity: .85, fontWeight: 600 }}>BUSES</div></div>
            <div><div style={{ fontSize: 14, fontWeight: 800 }}>{s.revenue}</div><div style={{ fontSize: 9, opacity: .85, fontWeight: 600 }}>MAR REV</div></div>
          </div>
        </div>

        <SH title="Invoices" right={<button className="btn-ghost" style={{ fontSize:11 }}>All</button>}/>
        <div className="card" style={{ padding: 0 }}>
          {[
            { m:'Mar 2025', amt:'₹6,40,000', state:s.invoice.includes('Due')?'Due':'Paid', date:'Mar 5' },
            { m:'Feb 2025', amt:'₹6,12,000', state:'Paid', date:'Feb 4' },
            { m:'Jan 2025', amt:'₹6,12,000', state:'Paid', date:'Jan 3' },
          ].map((iv, i, arr) => (
            <div key={i} className="row" style={{ padding: 12, gap: 10, borderBottom: i<arr.length-1?'1px solid var(--n100)':'none' }}>
              <div style={{ width: 36, height: 36, borderRadius: 10, background: iv.state==='Paid'?'var(--success-50)':'var(--warning-50)', color: iv.state==='Paid'?'var(--success)':'var(--warning)', display: 'grid', placeItems: 'center' }}><Icon name="rupee" size={16}/></div>
              <div style={{ flex: 1 }}>
                <div style={{ fontSize: 12, fontWeight: 700, color: 'var(--n900)' }}>{iv.m}</div>
                <div style={{ fontSize: 10.5, color: 'var(--n500)' }}>{iv.state} · {iv.date}</div>
              </div>
              <div style={{ fontSize: 13, fontWeight: 800, color:'var(--n900)', fontVariantNumeric:'tabular-nums' }}>{iv.amt}</div>
            </div>
          ))}
        </div>

        <SH title="Buses on contract"/>
        <div className="card" style={{ padding: 0 }}>
          {OP_VEHICLES.filter(v => v.sch === s.name).slice(0, 3).map((v, i, arr) => (
            <button key={i} onClick={() => nav.push('opVehicle', v)} className="row" style={{ padding: 12, gap: 10, width:'100%', textAlign:'left', borderBottom: i<arr.length-1?'1px solid var(--n100)':'none' }}>
              <div style={{ width: 36, height: 36, borderRadius: 10, background: v.bg, color: v.clr, display: 'grid', placeItems: 'center', fontSize: 18 }}>🚌</div>
              <div style={{ flex: 1 }}>
                <div style={{ fontSize: 12, fontWeight: 700, color: 'var(--n900)', fontFamily:'var(--mono)' }}>{v.id}</div>
                <div style={{ fontSize: 10.5, color: 'var(--n500)' }}>{v.route} · {v.driver}</div>
              </div>
              <Icon name="chev-r" size={14} style={{ color:'var(--n400)' }}/>
            </button>
          ))}
        </div>

        <div style={{ marginTop:14, display:'grid', gridTemplateColumns:'repeat(2,1fr)', gap:8 }}>
          <button className="btn btn-soft" style={{ height:42 }}><Icon name="rupee" size={14}/> Raise invoice</button>
          <button className="btn btn-outline" style={{ height:42 }}><Icon name="message" size={14}/> Message school</button>
        </div>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// INCIDENTS
// ─────────────────────────────────────────────────────────────
function OperatorIncidentsScreen({ nav }) {
  const [filter, setFilter] = useStateT('open');
  const sevClr = { critical:'var(--c600)', high:'var(--warning)', med:'var(--p600)', low:'var(--n500)' };
  const sevBg  = { critical:'var(--c50)', high:'var(--warning-50)', med:'var(--p50)', low:'var(--n100)' };
  const items = OP_INCIDENTS.filter(it => filter==='all' ? true : filter==='open' ? it.state!=='closed' : it.state==='closed');
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title="Incidents" onBack={() => nav.pop()}/>
      <div className="app-body">
        <div className="row" style={{ gap: 6, marginBottom: 14, overflowX: 'auto' }}>
          {[{id:'open',l:'Open · 4'},{id:'closed',l:'Closed · 8'},{id:'all',l:'All · 12'}].map(f => (
            <button key={f.id} onClick={() => setFilter(f.id)} style={{ flexShrink:0, padding:'7px 12px', fontSize:11, fontWeight:700, borderRadius:99, background: filter === f.id ? 'var(--n900)' : 'var(--n50)', color: filter === f.id ? '#fff' : 'var(--n700)', border:'none' }}>{f.l}</button>
          ))}
        </div>
        {items.map((it, i) => (
          <div key={i} className="card" style={{ padding: 14, marginBottom: 8 }}>
            <div className="row" style={{ gap: 6 }}>
              <span style={{ fontSize: 9, padding: '2px 7px', background: sevBg[it.sev], color: sevClr[it.sev], borderRadius: 99, fontWeight: 700 }}>{it.cat}</span>
              <span style={{ fontSize: 10, color: 'var(--n500)', fontFamily:'var(--mono)', fontWeight: 600, marginLeft: 'auto' }}>{it.when}</span>
            </div>
            <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--n900)', marginTop: 8 }}>{it.title}</div>
            <div style={{ fontSize: 11, color: 'var(--n500)', marginTop: 4 }}>{it.sub}</div>
            {it.state !== 'closed' && (
              <div className="row" style={{ marginTop: 12, gap: 8 }}>
                <button className="btn-sm btn-soft" style={{ flex: 1, height: 32, fontSize: 11 }}>Investigate</button>
                <button className="btn-sm btn-ghost" style={{ height: 32, padding: '0 12px', fontSize: 11 }}>Resolve</button>
              </div>
            )}
          </div>
        ))}
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// REVENUE
// ─────────────────────────────────────────────────────────────
function OperatorRevenueScreen({ nav }) {
  const months = [
    { m:'Oct', v:62 }, { m:'Nov', v:71 }, { m:'Dec', v:68 }, { m:'Jan', v:78 }, { m:'Feb', v:84 }, { m:'Mar', v:92 },
  ];
  const max = 100;
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title="Revenue" onBack={() => nav.pop()}/>
      <div className="app-body">
        <div className="card-grad" style={{ padding: 18 }}>
          <div style={{ fontSize: 10, opacity: .9, fontFamily: 'var(--mono)', fontWeight: 700, letterSpacing: '.06em' }}>FY 2024-25 · YEAR TO DATE</div>
          <div style={{ fontSize: 32, fontWeight: 800, marginTop: 4, fontVariantNumeric: 'tabular-nums', letterSpacing: '-.02em' }}>₹2.41 Cr</div>
          <div className="row" style={{ gap: 10, marginTop: 6, fontSize: 11, opacity: .9 }}>
            <span>↑ 18% YoY</span><span>·</span><span>4 contracts</span>
          </div>
          {/* Mini bar chart */}
          <div className="row" style={{ marginTop: 18, gap: 8, alignItems: 'flex-end', height: 80 }}>
            {months.map((m, i) => (
              <div key={i} style={{ flex: 1, display: 'flex', flexDirection: 'column', alignItems: 'center', gap: 4 }}>
                <div style={{ width: '100%', height: `${(m.v/max)*72}px`, background: i === months.length-1 ? '#fff' : 'rgba(255,255,255,.4)', borderRadius: 4 }}></div>
                <div style={{ fontSize: 9, opacity: .8, fontWeight: 700 }}>{m.m}</div>
              </div>
            ))}
          </div>
        </div>

        <SH title="By school" right={<button className="btn-ghost" style={{ fontSize:11 }}>Export</button>}/>
        <div className="card" style={{ padding: 0 }}>
          {OP_SCHOOLS.map((s, i, arr) => (
            <div key={i} className="row" style={{ padding: 12, gap: 10, borderBottom: i<arr.length-1?'1px solid var(--n100)':'none' }}>
              <div style={{ width: 36, height: 36, borderRadius: 10, background: s.bg, color: s.clr, display: 'grid', placeItems: 'center', fontSize: 12, fontWeight: 800 }}>{s.name.charAt(0)}</div>
              <div style={{ flex: 1 }}>
                <div style={{ fontSize: 12, fontWeight: 700, color: 'var(--n900)' }}>{s.name}</div>
                <div style={{ fontSize: 10.5, color: 'var(--n500)' }}>{s.students} riders · {s.mom} MoM</div>
              </div>
              <div style={{ fontSize: 13, fontWeight: 800, color:'var(--n900)', fontVariantNumeric:'tabular-nums' }}>{s.revenue}</div>
            </div>
          ))}
        </div>

        <SH title="Outstanding"/>
        <div className="card" style={{ padding: 14 }}>
          <div className="row">
            <div style={{ flex: 1 }}>
              <div style={{ fontSize: 11, color:'var(--n500)', fontFamily:'var(--mono)', fontWeight: 700, letterSpacing:'.04em' }}>UNPAID INVOICES</div>
              <div style={{ fontSize: 22, fontWeight: 800, color:'var(--n900)', marginTop: 4, fontVariantNumeric:'tabular-nums' }}>₹62,000</div>
              <div style={{ fontSize: 11, color:'var(--n500)', marginTop: 2 }}>1 invoice · Oakridge Intl. · 4 days overdue</div>
            </div>
            <button className="btn-sm btn-soft" style={{ height: 32, padding: '0 12px', fontSize: 11 }}>Send reminder</button>
          </div>
        </div>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// OPERATOR BOTTOM NAV
// ─────────────────────────────────────────────────────────────
function OperatorBottomNav({ active, onTab }) {
  const tabs = [
    { id:'home', ic:'home', l:'Home' },
    { id:'live', ic:'pin', l:'Live' },
    { id:'create', ic:'plus', l:'Add', primary:true },
    { id:'fleet', ic:'bus', l:'Fleet' },
    { id:'profile', ic:'user', l:'Profile' },
  ];
  return (
    <div style={{ position:'absolute', bottom:0, left:0, right:0, height:64, background:'#fff', borderTop:'1px solid var(--n100)', display:'flex' }}>
      {tabs.map(t => t.primary ? (
        <button key={t.id} onClick={() => onTab(t.id)} style={{ flex:1, display:'flex', alignItems:'center', justifyContent:'center', background:'none', border:'none' }}>
          <div style={{ width:46, height:46, borderRadius:14, background:'var(--p600)', color:'#fff', display:'grid', placeItems:'center', boxShadow:'0 6px 16px rgba(79,70,229,.35)' }}><Icon name="plus" size={22}/></div>
        </button>
      ) : (
        <button key={t.id} onClick={() => onTab(t.id)} style={{ flex:1, display:'flex', flexDirection:'column', alignItems:'center', justifyContent:'center', gap:3, color: active===t.id?'var(--p600)':'var(--n400)', background:'none', border:'none' }}>
          <Icon name={t.ic} size={20}/>
          <div style={{ fontSize:10, fontWeight:700 }}>{t.l}</div>
        </button>
      ))}
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// PRIVATE RIDERS — direct-enrolled (B2C) students
// ─────────────────────────────────────────────────────────────
function OperatorPrivateRidersScreen({ nav }) {
  const due = OP_PRIVATE_RIDERS.filter(r => !r.paid).length;
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title="Private riders" onBack={() => nav.pop()} right={<button onClick={() => nav.push('opEnrollStudent')} className="btn-sm" style={{ background:'var(--p600)', color:'#fff', height:32, padding:'0 12px', fontSize:11, fontWeight:700, borderRadius:8, border:'none' }}><Icon name="plus" size={12}/> Enrol</button>}/>
      <div className="app-body">
        <div className="card-grad-coral" style={{ padding: 16 }}>
          <div style={{ fontSize: 10, opacity: .85, fontFamily: 'var(--mono)', letterSpacing: '.08em', fontWeight: 700 }}>DIRECT ENROLMENT · MAR</div>
          <div style={{ fontSize: 28, fontWeight: 800, marginTop: 4, fontVariantNumeric: 'tabular-nums', letterSpacing: '-.02em' }}>₹2.30L</div>
          <div style={{ marginTop: 12, paddingTop: 12, borderTop: '1px solid rgba(255,255,255,.18)', display:'grid', gridTemplateColumns:'repeat(3,1fr)', gap:10 }}>
            <div><div style={{ fontSize:18, fontWeight:800 }}>46</div><div style={{ fontSize:9, opacity:.85, fontWeight:600 }}>RIDERS</div></div>
            <div><div style={{ fontSize:18, fontWeight:800 }}>{46-due}</div><div style={{ fontSize:9, opacity:.85, fontWeight:600 }}>PAID</div></div>
            <div><div style={{ fontSize:18, fontWeight:800 }}>{due}</div><div style={{ fontSize:9, opacity:.85, fontWeight:600 }}>DUE</div></div>
          </div>
        </div>

        <div className="card-flat" style={{ padding: 14, marginTop: 14 }}>
          <div className="row" style={{ gap: 10 }}>
            <Icon name="shield" size={16} style={{ color:'var(--p600)' }}/>
            <div style={{ fontSize: 11, color:'var(--n600)', flex:1, lineHeight: 1.5 }}>Private riders are parents who pay <b>you</b> directly. They can be from any school — you serve them across multiple campuses on shared routes.</div>
          </div>
        </div>

        <SH title="Riders" right={<button className="btn-ghost" style={{ fontSize:11 }}>By school</button>}/>
        {OP_PRIVATE_RIDERS.map((r, i) => (
          <button key={i} onClick={() => nav.push('opPrivateRider', r)} className="card" style={{ padding: 14, marginBottom: 8, width:'100%', textAlign:'left' }}>
            <div className="row" style={{ gap: 12 }}>
              <div className="av av-44 p">{r.name.split(' ').map(s=>s[0]).join('').slice(0,2)}</div>
              <div style={{ flex: 1, minWidth: 0 }}>
                <div className="spread">
                  <div style={{ fontSize: 13, fontWeight: 800, color: 'var(--n900)' }}>{r.name}</div>
                  <span style={{ fontSize: 9.5, padding: '3px 8px', background: r.stateBg, color: r.stateClr, borderRadius: 99, fontWeight: 700 }}>{r.state}</span>
                </div>
                <div style={{ fontSize: 11, color: 'var(--n500)', marginTop: 2 }}>{r.cls}</div>
                <div className="row" style={{ gap: 12, marginTop: 8, fontSize: 10.5, color: 'var(--n600)' }}>
                  <span><Icon name="pin" size={10}/> {r.stop}</span>
                  <span style={{ marginLeft:'auto', fontWeight: 700, color:'var(--n900)', fontVariantNumeric:'tabular-nums' }}>{r.fee}</span>
                </div>
              </div>
            </div>
          </button>
        ))}
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// PRIVATE RIDER DETAIL
// ─────────────────────────────────────────────────────────────
function OperatorPrivateRiderDetail({ nav, params }) {
  const r = params || OP_PRIVATE_RIDERS[0];
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title={r.name} onBack={() => nav.pop()} right={<button style={{ width:36,height:36,borderRadius:10,background:'var(--n50)',display:'grid',placeItems:'center'}}><Icon name="phone" size={16}/></button>}/>
      <div className="app-body">
        <div className="card-grad-coral" style={{ padding: 18 }}>
          <div className="row" style={{ gap: 14 }}>
            <div className="av" style={{ width:60, height:60, fontSize:20, background:'rgba(255,255,255,.25)', border:'2px solid rgba(255,255,255,.4)', color:'#fff' }}>{r.name.split(' ').map(s=>s[0]).join('').slice(0,2)}</div>
            <div style={{ flex:1 }}>
              <div style={{ fontSize:18, fontWeight:800 }}>{r.name}</div>
              <div style={{ fontSize:12, opacity:.9, marginTop:2 }}>{r.cls}</div>
              <div style={{ fontSize:10, opacity:.8, marginTop:4, fontFamily:'var(--mono)', fontWeight:600 }}>RIDER SINCE {r.since.toUpperCase()}</div>
            </div>
          </div>
        </div>

        <SH title="Parent contact"/>
        <div className="card" style={{ padding: 14 }}>
          <div className="row" style={{ gap: 10 }}>
            <div className="av av-44 coral">{r.parent.split(' ')[0][0]}</div>
            <div style={{ flex:1 }}>
              <div style={{ fontSize:13, fontWeight:700, color:'var(--n900)' }}>{r.parent.split('·')[0]}</div>
              <div style={{ fontSize:11, color:'var(--n500)', fontFamily:'var(--mono)' }}>{r.parent.split('·')[1]}</div>
            </div>
            <div className="row" style={{ gap: 6 }}>
              <button style={{ width:36,height:36,borderRadius:10,background:'var(--p50)',color:'var(--p600)',display:'grid',placeItems:'center',border:'none' }}><Icon name="message" size={16}/></button>
              <button style={{ width:36,height:36,borderRadius:10,background:'var(--p50)',color:'var(--p600)',display:'grid',placeItems:'center',border:'none' }}><Icon name="phone" size={16}/></button>
            </div>
          </div>
        </div>

        <SH title="Pickup details"/>
        <div className="card" style={{ padding: 0 }}>
          {[
            { lab:'Stop', val:r.stop, ic:'pin' },
            { lab:'Bus', val:'TS09 EQ 4421 · Tata Starbus', ic:'bus' },
            { lab:'Route', val:'R-14 · Madhapur ↔ DPS · 07:42 pickup', ic:'pin' },
            { lab:'Driver', val:'Ramesh K. · +91 98765 11111', ic:'user' },
          ].map((it, i, arr) => (
            <div key={i} className="row" style={{ padding: 12, gap: 10, borderBottom: i<arr.length-1?'1px solid var(--n100)':'none' }}>
              <div style={{ width:32,height:32,borderRadius:9,background:'var(--n50)',color:'var(--n700)',display:'grid',placeItems:'center' }}><Icon name={it.ic} size={14}/></div>
              <div style={{ flex:1 }}>
                <div style={{ fontSize:10, color:'var(--n500)', fontWeight:700, textTransform:'uppercase', letterSpacing:'.04em' }}>{it.lab}</div>
                <div style={{ fontSize:12, fontWeight:700, color:'var(--n900)', marginTop:1 }}>{it.val}</div>
              </div>
            </div>
          ))}
        </div>

        <SH title="Payments"/>
        <div className="card" style={{ padding: 14 }}>
          <div className="spread" style={{ marginBottom: 12 }}>
            <div>
              <div style={{ fontSize:10, color:'var(--n500)', fontWeight:700, textTransform:'uppercase', letterSpacing:'.04em' }}>Monthly fee</div>
              <div style={{ fontSize:22, fontWeight:800, color:'var(--n900)', marginTop:2, fontVariantNumeric:'tabular-nums' }}>{r.fee}</div>
            </div>
            <span style={{ fontSize:10, padding:'3px 8px', borderRadius:99, fontWeight:700, background: r.paid?'var(--success-50)':'var(--warning-50)', color: r.paid?'var(--success)':'var(--warning)' }}>{r.paid ? 'PAID · MAR' : 'DUE · MAR'}</span>
          </div>
          {!r.paid && <button className="btn btn-primary" style={{ height: 42, width:'100%' }}><Icon name="rupee" size={14}/> Send payment link</button>}
        </div>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// ENROL STUDENT (private)
// ─────────────────────────────────────────────────────────────
function OperatorEnrollStudent({ nav }) {
  const [step, setStep] = useStateT(1);
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title={`Enrol student · ${step}/3`} onBack={() => step>1?setStep(step-1):nav.pop()}/>
      <div className="row" style={{ gap: 6, padding: '0 20px 14px' }}>
        {[1,2,3].map(s => <div key={s} style={{ flex:1, height:4, borderRadius:2, background: s<=step?'var(--p600)':'var(--n100)' }}></div>)}
      </div>
      <div className="app-body" style={{ paddingTop: 0 }}>
        {step === 1 && (
          <>
            <div style={{ fontSize:18, fontWeight:800, color:'var(--n900)' }}>Student & parent</div>
            <div style={{ fontSize:12, color:'var(--n500)', marginTop:4, marginBottom:18 }}>Direct enrolment — the parent pays you, not a school.</div>
            <FieldT label="Student name" required><input placeholder="Aarav Reddy" style={inputStyleT}/></FieldT>
            <FieldT label="Class & school" required><input placeholder="Class 8 · DPS Hyderabad" style={inputStyleT}/></FieldT>
            <FieldT label="Parent name" required><input placeholder="Maya Reddy" style={inputStyleT}/></FieldT>
            <FieldT label="Parent mobile" required><input placeholder="+91 98765 12345" style={inputStyleT}/></FieldT>
            <FieldT label="Email"><input placeholder="parent@email.com" style={inputStyleT}/></FieldT>
          </>
        )}
        {step === 2 && (
          <>
            <div style={{ fontSize:18, fontWeight:800, color:'var(--n900)' }}>Pickup & route</div>
            <div style={{ fontSize:12, color:'var(--n500)', marginTop:4, marginBottom:18 }}>Pick the route nearest to home.</div>
            <FieldT label="Pickup address" required><textarea placeholder="House, street, area, PIN" style={{...inputStyleT, height:72, paddingTop:12, resize:'none'}}/></FieldT>
            <FieldT label="Stop" required><select style={inputStyleT}><option>Madhapur Junction · 07:42</option><option>Hi-Tech City · 07:54</option><option>Kondapur · 08:02</option><option>Botanical Gardens · 08:12</option><option>Gachibowli · 08:20</option><option>+ Add new stop</option></select></FieldT>
            <FieldT label="Direction">
              <div className="row" style={{ gap: 8 }}>
                {['Pick-up only','Drop-off only','Both ways'].map((d, i) => (
                  <button key={d} style={{ flex:1, height:42, borderRadius:10, background: i===2?'var(--p600)':'#fff', color: i===2?'#fff':'var(--n700)', border:'1px solid', borderColor: i===2?'var(--p600)':'var(--n200)', fontWeight:700, fontSize:11 }}>{d}</button>
                ))}
              </div>
            </FieldT>
            <FieldT label="Route assignment"><select style={inputStyleT}><option>R-14 · Madhapur ↔ DPS</option><option>R-7 · Kondapur ↔ Vidyaranya</option><option>R-22 · Gachibowli ↔ DPS</option></select></FieldT>
          </>
        )}
        {step === 3 && (
          <>
            <div style={{ fontSize:18, fontWeight:800, color:'var(--n900)' }}>Fee & start</div>
            <div style={{ fontSize:12, color:'var(--n500)', marginTop:4, marginBottom:18 }}>Auto-billed to parent each month.</div>
            <FieldT label="Monthly fee" required>
              <div className="row" style={{ gap: 8 }}>
                {[2400,2800,3000,3200].map(f => (
                  <button key={f} style={{ flex:1, height:42, borderRadius:10, background: f===2800?'var(--p600)':'#fff', color: f===2800?'#fff':'var(--n700)', border:'1px solid', borderColor: f===2800?'var(--p600)':'var(--n200)', fontWeight:700, fontSize:12 }}>₹{f.toLocaleString()}</button>
                ))}
              </div>
            </FieldT>
            <FieldT label="Start date" required><input type="date" style={inputStyleT}/></FieldT>
            <FieldT label="Billing cycle">
              <div className="row" style={{ gap: 8 }}>
                {['Monthly','Quarterly','Term-wise'].map((c, i) => (
                  <button key={c} style={{ flex:1, height:42, borderRadius:10, background: i===0?'var(--p600)':'#fff', color: i===0?'#fff':'var(--n700)', border:'1px solid', borderColor: i===0?'var(--p600)':'var(--n200)', fontWeight:700, fontSize:11 }}>{c}</button>
                ))}
              </div>
            </FieldT>
            <div className="card-flat" style={{ padding: 14, marginTop: 4 }}>
              <div className="row" style={{ gap: 10 }}>
                <Icon name="rupee" size={16} style={{ color:'var(--success)' }}/>
                <div style={{ fontSize: 11, color:'var(--n600)', flex:1, lineHeight: 1.5 }}>Parent gets a UPI mandate link via SMS. First month auto-prorated by start date.</div>
              </div>
            </div>
          </>
        )}
      </div>
      <div style={{ position:'absolute', bottom:0, left:0, right:0, padding:16, background:'#fff', borderTop:'1px solid var(--n100)' }}>
        <button onClick={() => step<3?setStep(step+1):nav.replace('opPrivateRiders')} className="btn btn-primary" style={{ height:46, width:'100%' }}>{step<3?'Continue':'Send enrolment to parent'}</button>
      </div>
    </div>
  );
}
// ─────────────────────────────────────────────────────────────
function OperatorCreateMenu({ nav }) {
  const items = [
    { dest:'opAddVehicle', ic:'bus', clr:'#9A3412', bg:'#FFF7ED', t:'Add a bus', sub:'Register a vehicle to your fleet' },
    { dest:'opAddDriver', ic:'user', clr:'var(--p600)', bg:'var(--p50)', t:'Onboard a driver', sub:'Verify license + police check' },
    { dest:'opAddRoute', ic:'pin', clr:'var(--success)', bg:'var(--success-50)', t:'Create a route', sub:'Plot stops, assign bus + driver' },
    { dest:'opAddContract', ic:'building', clr:'var(--c600)', bg:'var(--c50)', t:'New school contract', sub:'B2B · serve a campus' },
    { dest:'opEnrollStudent', ic:'users', clr:'#0E7490', bg:'#ECFEFF', t:'Enrol a private student', sub:'B2C · parent pays you directly' },
  ];
  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title="Create" onBack={() => nav.pop()}/>
      <div className="app-body">
        <div style={{ fontSize: 11, color: 'var(--n500)', textTransform: 'uppercase', letterSpacing: '.06em', fontWeight: 700, marginBottom: 10 }}>What would you like to add?</div>
        {items.map((it, i) => (
          <button key={i} onClick={() => nav.push(it.dest)} className="card" style={{ padding: 16, marginBottom: 10, width:'100%', textAlign:'left' }}>
            <div className="row" style={{ gap: 14 }}>
              <div style={{ width: 48, height: 48, borderRadius: 13, background: it.bg, color: it.clr, display: 'grid', placeItems: 'center' }}><Icon name={it.ic} size={22}/></div>
              <div style={{ flex: 1 }}>
                <div style={{ fontSize: 14, fontWeight: 700, color: 'var(--n900)' }}>{it.t}</div>
                <div style={{ fontSize: 11, color: 'var(--n500)', marginTop: 2, lineHeight: 1.4 }}>{it.sub}</div>
              </div>
              <Icon name="chev-r" size={16} style={{ color: 'var(--n400)' }}/>
            </div>
          </button>
        ))}
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// ADD VEHICLE — multi-step register form
// ─────────────────────────────────────────────────────────────
function OperatorAddVehicle({ nav }) {
  const [step, setStep] = useStateT(1);
  const [reg, setReg] = useStateT('TS09 ');
  const [model, setModel] = useStateT('');
  const [seats, setSeats] = useStateT(32);
  const [school, setSchool] = useStateT('');
  const [route, setRoute] = useStateT('');
  const [driver, setDriver] = useStateT('');

  const Stepper = () => (
    <div className="row" style={{ gap: 6, padding: '0 20px 14px' }}>
      {[1,2,3].map(s => (
        <div key={s} style={{ flex: 1, height: 4, borderRadius: 2, background: s <= step ? 'var(--p600)' : 'var(--n100)' }}></div>
      ))}
    </div>
  );

  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title={`Add bus · Step ${step}/3`} onBack={() => step > 1 ? setStep(step-1) : nav.pop()}/>
      <Stepper/>
      <div className="app-body" style={{ paddingTop: 0 }}>
        {step === 1 && (
          <>
            <div style={{ fontSize: 18, fontWeight: 800, color: 'var(--n900)', letterSpacing: '-.01em' }}>Vehicle details</div>
            <div style={{ fontSize: 12, color: 'var(--n500)', marginTop: 4, marginBottom: 18 }}>Register your bus with the RTO number and model.</div>
            <FieldT label="Registration number" required>
              <input value={reg} onChange={e => setReg(e.target.value.toUpperCase())} placeholder="TS09 EQ 4421" style={inputStyleT}/>
            </FieldT>
            <FieldT label="Make / Model" required>
              <select value={model} onChange={e => setModel(e.target.value)} style={inputStyleT}>
                <option value="">Choose model…</option>
                <option>Tata Starbus · 32 seater</option>
                <option>Tata Starbus · 40 seater</option>
                <option>Eicher Skyline · 36 seater</option>
                <option>Ashok Leyland · 40 seater</option>
                <option>Force Traveller · 26 seater</option>
              </select>
            </FieldT>
            <FieldT label="Seating capacity" required>
              <div className="row" style={{ gap: 8 }}>
                {[20, 26, 32, 36, 40].map(n => (
                  <button key={n} onClick={() => setSeats(n)} style={{ flex: 1, height: 42, borderRadius: 10, background: seats === n ? 'var(--p600)' : '#fff', color: seats === n ? '#fff' : 'var(--n700)', border: '1px solid', borderColor: seats === n ? 'var(--p600)' : 'var(--n200)', fontWeight: 700, fontSize: 13 }}>{n}</button>
                ))}
              </div>
            </FieldT>
            <FieldT label="Year of manufacture">
              <select style={inputStyleT}><option>2024</option><option>2023</option><option>2022</option><option>2021</option><option>2020 or earlier</option></select>
            </FieldT>
          </>
        )}
        {step === 2 && (
          <>
            <div style={{ fontSize: 18, fontWeight: 800, color: 'var(--n900)', letterSpacing: '-.01em' }}>Compliance documents</div>
            <div style={{ fontSize: 12, color: 'var(--n500)', marginTop: 4, marginBottom: 18 }}>Required by TS RTO. We'll alert you 30 days before each expires.</div>
            {[
              { lab:'RC (Registration Certificate)', sub:'PDF or photo · valid through 2034', done:true },
              { lab:'Insurance policy', sub:'Comprehensive · Bharti AXA preferred', done:true },
              { lab:'PUC certificate', sub:'Renew every 6 months', done:false },
              { lab:'Fitness certificate', sub:'Annual RTO inspection', done:false },
              { lab:'Permit', sub:'School bus permit · contract carriage', done:false },
            ].map((d, i) => (
              <div key={i} className="card" style={{ padding: 14, marginBottom: 8 }}>
                <div className="row" style={{ gap: 12 }}>
                  <div style={{ width: 38, height: 38, borderRadius: 10, background: d.done?'var(--success-50)':'var(--n50)', color: d.done?'var(--success)':'var(--n400)', display: 'grid', placeItems: 'center' }}><Icon name={d.done?'check':'plus'} size={16}/></div>
                  <div style={{ flex: 1 }}>
                    <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--n900)' }}>{d.lab}</div>
                    <div style={{ fontSize: 11, color: 'var(--n500)' }}>{d.sub}</div>
                  </div>
                  <button className="btn-sm btn-soft" style={{ height: 30, padding: '0 12px', fontSize: 11 }}>{d.done?'Replace':'Upload'}</button>
                </div>
              </div>
            ))}
          </>
        )}
        {step === 3 && (
          <>
            <div style={{ fontSize: 18, fontWeight: 800, color: 'var(--n900)', letterSpacing: '-.01em' }}>Assignment</div>
            <div style={{ fontSize: 12, color: 'var(--n500)', marginTop: 4, marginBottom: 18 }}>Optional — you can assign later.</div>
            <FieldT label="School (contract)">
              <select value={school} onChange={e=>setSchool(e.target.value)} style={inputStyleT}>
                <option value="">— Unassigned —</option>
                <option>DPS Hyderabad</option><option>Vidyaranya High</option><option>Oakridge Intl.</option><option>Chirec Public</option>
              </select>
            </FieldT>
            <FieldT label="Route">
              <select value={route} onChange={e=>setRoute(e.target.value)} style={inputStyleT}>
                <option value="">— Unassigned —</option>
                <option>R-14 · Madhapur ↔ DPS</option><option>R-7 · Kondapur ↔ Vidyaranya</option><option>R-22 · Gachibowli ↔ DPS</option>
              </select>
            </FieldT>
            <FieldT label="Driver">
              <select value={driver} onChange={e=>setDriver(e.target.value)} style={inputStyleT}>
                <option value="">— Unassigned —</option>
                <option>Ramesh K. · 8 yrs</option><option>Suresh M. · 12 yrs</option><option>Krishna L. · 4 yrs</option><option>Mohan R. (standby) · 14 yrs</option>
              </select>
            </FieldT>
            <div className="card-flat" style={{ padding: 14, marginTop: 4 }}>
              <div style={{ fontSize: 11, fontWeight: 700, color: 'var(--n500)', textTransform: 'uppercase', letterSpacing: '.05em' }}>Summary</div>
              <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--n900)', marginTop: 6, fontFamily: 'var(--mono)' }}>{reg || '—'} · {seats} seats</div>
              <div style={{ fontSize: 11, color: 'var(--n500)', marginTop: 2 }}>{model || 'Model not set'}</div>
            </div>
          </>
        )}
      </div>
      <div style={{ position:'absolute', bottom: 0, left: 0, right: 0, padding: 16, background: '#fff', borderTop: '1px solid var(--n100)' }}>
        <button onClick={() => step < 3 ? setStep(step+1) : nav.replace('opFleet')} className="btn btn-primary" style={{ height: 46, width:'100%' }}>{step < 3 ? 'Continue' : 'Add bus to fleet'}</button>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// ADD DRIVER — onboard
// ─────────────────────────────────────────────────────────────
function OperatorAddDriver({ nav }) {
  const [step, setStep] = useStateT(1);
  const [name, setName] = useStateT('');
  const [phone, setPhone] = useStateT('+91 ');
  const [license, setLicense] = useStateT('');

  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title={`Onboard driver · ${step}/3`} onBack={() => step > 1 ? setStep(step-1) : nav.pop()}/>
      <div className="row" style={{ gap: 6, padding: '0 20px 14px' }}>
        {[1,2,3].map(s => <div key={s} style={{ flex: 1, height: 4, borderRadius: 2, background: s <= step ? 'var(--p600)' : 'var(--n100)' }}></div>)}
      </div>
      <div className="app-body" style={{ paddingTop: 0 }}>
        {step === 1 && (
          <>
            <div style={{ fontSize: 18, fontWeight: 800, color: 'var(--n900)' }}>Personal details</div>
            <div style={{ fontSize: 12, color: 'var(--n500)', marginTop: 4, marginBottom: 18 }}>The driver will get a phone OTP to install the Driver app.</div>
            <FieldT label="Full name" required><input value={name} onChange={e=>setName(e.target.value)} placeholder="Ramesh Kumar" style={inputStyleT}/></FieldT>
            <FieldT label="Mobile number" required><input value={phone} onChange={e=>setPhone(e.target.value)} placeholder="+91 98765 11111" style={inputStyleT}/></FieldT>
            <FieldT label="Date of birth"><input type="date" style={inputStyleT}/></FieldT>
            <FieldT label="Aadhaar number"><input placeholder="XXXX XXXX XXXX" style={inputStyleT}/></FieldT>
            <FieldT label="Address">
              <textarea placeholder="House, street, area, PIN" style={{...inputStyleT, height: 72, paddingTop: 12, resize: 'none'}}/>
            </FieldT>
          </>
        )}
        {step === 2 && (
          <>
            <div style={{ fontSize: 18, fontWeight: 800, color: 'var(--n900)' }}>License & verification</div>
            <div style={{ fontSize: 12, color: 'var(--n500)', marginTop: 4, marginBottom: 18 }}>We'll auto-verify with TS RTO + run police check.</div>
            <FieldT label="Driver license number" required><input value={license} onChange={e=>setLicense(e.target.value)} placeholder="TS-013-20210045" style={inputStyleT}/></FieldT>
            <FieldT label="License class">
              <div className="row" style={{ gap: 8 }}>
                {['LMV','HMV','PSV'].map(c => (
                  <button key={c} style={{ flex:1, height: 42, borderRadius: 10, background: c === 'PSV' ? 'var(--p600)' : '#fff', color: c === 'PSV' ? '#fff' : 'var(--n700)', border: '1px solid', borderColor: c === 'PSV' ? 'var(--p600)' : 'var(--n200)', fontWeight: 700, fontSize: 12 }}>{c}</button>
                ))}
              </div>
            </FieldT>
            <FieldT label="License expiry"><input type="date" style={inputStyleT}/></FieldT>
            {[
              { lab:'License copy', clr:'var(--success)', state:'check' },
              { lab:'Police verification', clr:'var(--warning)', state:'plus' },
              { lab:'Medical fitness certificate', clr:'var(--warning)', state:'plus' },
              { lab:'Profile photo', clr:'var(--warning)', state:'plus' },
            ].map((d, i) => (
              <div key={i} className="row card" style={{ padding: 12, marginBottom: 8, gap: 12 }}>
                <div style={{ width: 32, height: 32, borderRadius: 9, background: d.state==='check'?'var(--success-50)':'var(--n50)', color: d.clr, display:'grid', placeItems:'center' }}><Icon name={d.state} size={14}/></div>
                <div style={{ flex: 1, fontSize: 12, fontWeight: 700, color: 'var(--n900)' }}>{d.lab}</div>
                <button className="btn-sm btn-soft" style={{ height:28, padding:'0 10px', fontSize:11 }}>{d.state==='check'?'Replace':'Upload'}</button>
              </div>
            ))}
          </>
        )}
        {step === 3 && (
          <>
            <div style={{ fontSize: 18, fontWeight: 800, color: 'var(--n900)' }}>Assign</div>
            <div style={{ fontSize: 12, color: 'var(--n500)', marginTop: 4, marginBottom: 18 }}>Optional — you can assign later.</div>
            <FieldT label="Bus"><select style={inputStyleT}><option value="">— Unassigned —</option><option>TS09 EQ 4421 · Tata Starbus</option><option>TS09 KL 6655 · Force Traveller</option></select></FieldT>
            <FieldT label="Route"><select style={inputStyleT}><option value="">— Unassigned —</option><option>R-14 · Madhapur ↔ DPS</option><option>R-9 · Jubilee ↔ Chirec</option></select></FieldT>
            <FieldT label="Shift">
              <div className="row" style={{ gap: 8 }}>
                {['Morning only','Afternoon only','Both shifts'].map((s, i) => (
                  <button key={s} style={{ flex:1, height: 42, borderRadius: 10, background: i === 2 ? 'var(--p600)' : '#fff', color: i === 2 ? '#fff' : 'var(--n700)', border: '1px solid', borderColor: i === 2 ? 'var(--p600)' : 'var(--n200)', fontWeight: 700, fontSize: 11 }}>{s}</button>
                ))}
              </div>
            </FieldT>
            <div className="card-flat" style={{ padding: 14, marginTop: 6 }}>
              <div className="row" style={{ gap: 10 }}>
                <Icon name="message" size={16} style={{ color: 'var(--p600)' }}/>
                <div style={{ fontSize: 11, color:'var(--n600)', flex: 1, lineHeight: 1.5 }}>An invite SMS will be sent to <b>{phone || '+91 …'}</b> with a one-time code to install the Driver app.</div>
              </div>
            </div>
          </>
        )}
      </div>
      <div style={{ position:'absolute', bottom: 0, left: 0, right: 0, padding: 16, background: '#fff', borderTop: '1px solid var(--n100)' }}>
        <button onClick={() => step < 3 ? setStep(step+1) : nav.replace('opDrivers')} className="btn btn-primary" style={{ height: 46, width:'100%' }}>{step < 3 ? 'Continue' : 'Send invite'}</button>
      </div>
    </div>
  );
}

// ─────────────────────────────────────────────────────────────
// ADD ROUTE — plot stops
// ─────────────────────────────────────────────────────────────
function OperatorAddRoute({ nav }) {
  const [name, setName] = useStateT('');
  const [school, setSchool] = useStateT('');
  const [stops, setStops] = useStateT([
    { n: 'Depot · Sai Travels yard', t: '07:30' },
    { n: '', t: '' },
  ]);
  const updateStop = (i, key, val) => setStops(s => s.map((st, j) => j === i ? { ...st, [key]: val } : st));
  const addStop = () => setStops(s => [...s, { n: '', t: '' }]);
  const rmStop = (i) => setStops(s => s.filter((_, j) => j !== i));

  return (
    <div className="app screen-in">
      <StatusBar/>
      <NavHeader title="Create route" onBack={() => nav.pop()}/>
      <div className="app-body" style={{ paddingBottom: 96 }}>
        <FieldT label="Route name" required>
          <input value={name} onChange={e=>setName(e.target.value)} placeholder="Madhapur ↔ DPS Hyderabad" style={inputStyleT}/>
        </FieldT>
        <FieldT label="School (contract)" required>
          <select value={school} onChange={e=>setSchool(e.target.value)} style={inputStyleT}>
            <option value="">Choose school…</option>
            <option>DPS Hyderabad</option><option>Vidyaranya High</option><option>Oakridge Intl.</option><option>Chirec Public</option>
          </select>
        </FieldT>
        <FieldT label="Direction">
          <div className="row" style={{ gap: 8 }}>
            {['Pick-up (AM)', 'Drop-off (PM)', 'Both'].map((d, i) => (
              <button key={d} style={{ flex:1, height: 40, borderRadius: 10, background: i === 2 ? 'var(--p600)' : '#fff', color: i === 2 ? '#fff' : 'var(--n700)', border: '1px solid', borderColor: i === 2 ? 'var(--p600)' : 'var(--n200)', fontWeight: 700, fontSize: 11 }}>{d}</button>
            ))}
          </div>
        </FieldT>

        <div className="spread" style={{ marginTop: 18, marginBottom: 10 }}>
          <div style={{ fontSize: 12, fontWeight: 700, color: 'var(--n900)', textTransform: 'uppercase', letterSpacing: '.05em' }}>Stops</div>
          <button onClick={addStop} className="btn-sm btn-soft" style={{ height: 28, padding: '0 10px', fontSize: 11 }}><Icon name="plus" size={12}/> Add stop</button>
        </div>

        <div className="card" style={{ padding: 14, position: 'relative' }}>
          <div style={{ position: 'absolute', left: 27, top: 24, bottom: 24, width: 2, background: 'var(--n100)' }}></div>
          {stops.map((s, i) => (
            <div key={i} className="row" style={{ gap: 12, padding: '8px 0', position: 'relative', zIndex: 1 }}>
              <div style={{ width: 16, height: 16, borderRadius: 99, flexShrink: 0, background: i===0?'var(--n400)':'#fff', border: i===0?'0':'2px solid var(--p400)' }}></div>
              <input value={s.n} onChange={e=>updateStop(i,'n',e.target.value)} placeholder={i===0?'Depot':'Stop name'} disabled={i===0} style={{ flex: 1, height: 36, padding: '0 10px', borderRadius: 8, border: '1px solid var(--n100)', fontSize: 12, background: i===0?'var(--n50)':'#fff' }}/>
              <input value={s.t} onChange={e=>updateStop(i,'t',e.target.value)} placeholder="07:42" style={{ width: 72, height: 36, padding: '0 10px', borderRadius: 8, border: '1px solid var(--n100)', fontSize: 12, fontFamily: 'var(--mono)', textAlign: 'center' }}/>
              {i > 1 && <button onClick={() => rmStop(i)} style={{ width: 28, height: 28, borderRadius: 8, background: 'var(--c50)', color: 'var(--c600)', border: 'none', display: 'grid', placeItems: 'center' }}><Icon name="x" size={12}/></button>}
            </div>
          ))}
        </div>

        <FieldT label="Assign bus" style={{ marginTop: 18 }}>
          <select style={inputStyleT}><option value="">— Assign later —</option><option>TS09 EQ 4421 · 32 seater</option><option>TS09 GH 8821 · 36 seater</option></select>
        </FieldT>
        <FieldT label="Assign driver">
          <select style={inputStyleT}><option value="">— Assign later —</option><option>Ramesh K. · 8 yrs</option><option>Krishna L. · 4 yrs</option></select>
        </FieldT>

        <div className="card-flat" style={{ padding: 14, marginTop: 6 }}>
          <div className="row" style={{ gap: 10 }}>
            <Icon name="pin" size={16} style={{ color: 'var(--success)' }}/>
            <div style={{ fontSize: 11, color: 'var(--n600)', flex: 1, lineHeight: 1.5 }}>Distance + ETA will be auto-calculated from stop coordinates after you save.</div>
          </div>
        </div>
      </div>
      <div style={{ position:'absolute', bottom: 0, left: 0, right: 0, padding: 16, background: '#fff', borderTop: '1px solid var(--n100)' }}>
        <button onClick={() => nav.replace('opRoutes')} className="btn btn-primary" style={{ height: 46, width:'100%' }}>Save route</button>
      </div>
    </div>
  );
}

// shared form helpers
const inputStyleT = { width: '100%', height: 44, padding: '0 14px', borderRadius: 11, border: '1px solid var(--n200)', fontSize: 14, fontFamily: 'inherit', background: '#fff', color: 'var(--n900)' };
function FieldT({ label, required, children, style }) {
  return (
    <div style={{ marginBottom: 14, ...style }}>
      <div style={{ fontSize: 11, fontWeight: 700, color: 'var(--n700)', marginBottom: 6, textTransform: 'uppercase', letterSpacing: '.04em' }}>{label}{required && <span style={{ color: 'var(--c600)' }}> *</span>}</div>
      {children}
    </div>
  );
}

Object.assign(window, {
  OperatorLiveScreen, OperatorFleetScreen, OperatorVehicleDetail,
  OperatorDriversScreen, OperatorDriverDetail,
  OperatorRoutesScreen, OperatorRouteDetail,
  OperatorSchoolsScreen, OperatorSchoolDetail,
  OperatorIncidentsScreen, OperatorRevenueScreen,
  OperatorPrivateRidersScreen, OperatorPrivateRiderDetail,
  OperatorBottomNav,
  OperatorAddVehicle, OperatorAddDriver, OperatorAddRoute, OperatorEnrollStudent, OperatorCreateMenu,
});
