// Simple Pro Mobile — Extra screens: Conversations (calls+messages unified), Estimates+detail, Customer forms
const { useState } = React;

// ── CONVERSATIONS DATA ────────────────────────────────────────
const THREADS = [
  { id:'sms-1', name:'Maria Ramos',      preview:'Got it, see you at 11:30!',              time:'10:42 AM', unread:1, avatar:'MR', color:'#e8f2fd', tc:'#0071e3', belle:true, kind:'sms' },
  { id:'sms-2', name:'Steinberg Corp',   preview:'The crew can access through the back.', time:'9:15 AM',  unread:0, avatar:'SC', color:'#e6f7ef', tc:'#1a9e5c', kind:'sms' },
  { id:'sms-3', name:'Chen Family',      preview:'Thank you! Payment sent.',               time:'Yesterday',unread:0, avatar:'CF', color:'#fef3e2', tc:'#d97706', kind:'sms' },
  { id:'sms-4', name:'Jake Torres',      preview:'On my way to Steinberg now.',            time:'Yesterday',unread:0, avatar:'JT', color:'#f3f4f6', tc:'#6b7280', kind:'sms' },
  { id:'sms-5', name:'Nguyen Group',     preview:'Can we reschedule to Friday?',           time:'Apr 19',   unread:2, avatar:'NG', color:'#fef2f2', tc:'#dc2626', belle:true, kind:'sms' },
  { id:'sms-6', name:'Park Residence',   preview:'Confirmed for Tuesday at 10 AM.',        time:'Apr 18',   unread:0, avatar:'PR', color:'#f5f0ff', tc:'#7c3aed', kind:'sms' },
];

const THREAD_MESSAGES = [
  { from:'customer', text:"Hi, just confirming the appointment for today at 11:30?", time:'10:28 AM' },
  { from:'me',       text:"Yes! I'll be there around 11:30. See you then.", time:'10:31 AM' },
  { from:'customer', text:"Got it, see you at 11:30!", time:'10:42 AM' },
];

const CALLS_DATA = [
  { id:'call-1', name:'Maria Ramos',    type:'inbound',  duration:'3:42', time:'10:28 AM', status:'answered',  job:'Drain Clog — Kitchen', phone:'(415) 555-0192', belle:true, summary:'Confirmed access and asked for ETA before the tech arrived.' },
  { id:'call-2', name:'Steinberg Corp', type:'outbound', duration:'1:15', time:'9:02 AM',  status:'answered',  job:'Full Bath Re-pipe',    phone:'(415) 555-0271' },
  { id:'call-3', name:'Unknown',        type:'inbound',  duration:'—',    time:'8:44 AM',  status:'missed',    job:null,                   phone:'(415) 555-0918', belle:true, summary:'Belle flagged the caller as a likely new customer asking about a clogged kitchen line.' },
  { id:'call-4', name:'Nguyen Group',   type:'outbound', duration:'0:32', time:'Yesterday',status:'voicemail', job:'Sewer Inspection',     phone:'(415) 555-0445' },
  { id:'call-5', name:'Chen Family',    type:'inbound',  duration:'5:11', time:'Yesterday',status:'answered',  job:'Water Heater Install', phone:'(415) 555-0388' },
];

// Build a unified inbox of SMS threads + calls, newest-first-ish (preserve input order).
const CONVERSATIONS = [
  ...THREADS.map(t => ({ ...t, kind:'sms' })),
  ...CALLS_DATA.map(c => ({
    id: c.id, name: c.name, time: c.time, kind:'call',
    call: c,
    preview: (c.status==='missed' ? '⚠ Missed call' : c.type==='inbound' ? '↙ Inbound call' : '↗ Outbound call')
      + ' · ' + c.duration + (c.job ? ` · ${c.job}` : ''),
    unread: c.status==='missed' ? 1 : 0,
    belle: c.belle,
    avatar: c.name.split(' ').map(w=>w[0]).slice(0,2).join(''),
    color: c.status==='missed' ? '#fef2f2' : '#e8f2fd',
    tc:    c.status==='missed' ? '#dc2626' : '#0071e3',
  })),
];

// ── CONVERSATIONS SCREEN (unified calls + messages inbox) ─────
function ConversationsScreen({ onNav }) {
  const [filter, setFilter] = useState('All');
  const [search, setSearch] = useState('');
  const filters = ['All','Messages','Calls','Unread'];
  const list = CONVERSATIONS.filter(c => {
    if (filter === 'Messages' && c.kind !== 'sms')  return false;
    if (filter === 'Calls'    && c.kind !== 'call') return false;
    if (filter === 'Unread'   && !c.unread)         return false;
    if (search && !c.name.toLowerCase().includes(search.toLowerCase())) return false;
    return true;
  });

  return (
    <div style={{background:'#f5f5f7',minHeight:'100%',paddingBottom:100}}>
      <NavHeader title="Conversations" onBack="__back"
        action={
          <div onClick={() => onNav('belle', {prompt:'Compose a new message'})}
            style={{width:32,height:32,borderRadius:'50%',background:'rgba(255,255,255,0.12)',
              display:'flex',alignItems:'center',justifyContent:'center',cursor:'pointer'}}>
            <svg width="14" height="14" viewBox="0 0 14 14" fill="white"><line x1="7" y1="1" x2="7" y2="13" strokeWidth="2" stroke="white" strokeLinecap="round"/><line x1="1" y1="7" x2="13" y2="7" strokeWidth="2" stroke="white" strokeLinecap="round"/></svg>
          </div>
        }
      />

      <div style={{padding:'10px 16px 4px'}}>
        <div style={{height:36,background:'rgba(0,0,0,0.06)',borderRadius:10,display:'flex',alignItems:'center',gap:8,padding:'0 12px'}}>
          <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="rgba(0,0,0,0.35)" strokeWidth="2.2" strokeLinecap="round"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
          <input value={search} onChange={e=>setSearch(e.target.value)} placeholder="Search calls or messages…"
            style={{flex:1,border:'none',background:'transparent',fontSize:14,color:'#111',outline:'none',fontFamily:'inherit'}}/>
        </div>
      </div>

      <div style={{display:'flex',gap:7,padding:'8px 16px 12px',overflowX:'auto',scrollbarWidth:'none'}}>
        {filters.map(f => (
          <div key={f} onClick={() => setFilter(f)}
            style={{flexShrink:0,height:30,padding:'0 13px',borderRadius:999,
              background: filter===f ? '#0071e3' : 'white',
              color: filter===f ? 'white' : 'rgba(0,0,0,0.6)',
              border: `1px solid ${filter===f ? '#0071e3' : 'rgba(0,0,0,0.1)'}`,
              fontSize:13,fontWeight: filter===f ? 600 : 400,
              display:'flex',alignItems:'center',cursor:'pointer'}}>
            {f}
          </div>
        ))}
      </div>

      {list.length === 0 ? (
        <EmptyState
          verb="send your first message"
          manualLabel="Write it manually"
          onAsk={() => onNav('belle', {prompt:'Send a message to a customer'})}
          onManual={() => onNav('belle', {prompt:'Compose a new message manually'})}
          icon={<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="1.9" strokeLinecap="round"><path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/></svg>}
        />
      ) : (
        <Card>
          {list.map((c,i) => (
            <div key={c.id} onClick={() => onNav('conversation-detail', {conversation: c})}
              style={{padding:'12px 16px',display:'flex',alignItems:'center',gap:12,
                borderBottom: i<list.length-1?'0.5px solid rgba(0,0,0,0.06)':'none',cursor:'pointer',
                borderLeft: c.belle ? '3px solid #0071e3' : '3px solid transparent'}}>
              <div style={{position:'relative',flexShrink:0}}>
                <div style={{width:42,height:42,borderRadius:'50%',background:c.color,
                  display:'flex',alignItems:'center',justifyContent:'center',
                  fontSize:13,fontWeight:700,color:c.tc}}>{c.avatar}</div>
                {c.unread > 0 && (
                  <div style={{position:'absolute',top:-2,right:-2,width:16,height:16,borderRadius:'50%',
                    background:'#0071e3',display:'flex',alignItems:'center',justifyContent:'center',
                    fontSize:10,fontWeight:700,color:'white',border:'1.5px solid #f5f5f7'}}>{c.unread}</div>
                )}
                {/* Kind indicator */}
                <div style={{position:'absolute',bottom:-2,right:-2,width:16,height:16,borderRadius:'50%',
                  background:'white',display:'flex',alignItems:'center',justifyContent:'center',
                  border:'1.5px solid #f5f5f7',color:'rgba(0,0,0,0.55)'}}>
                  {c.kind === 'call' ? (
                    <svg width="8" height="8" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round"><path d="M22 16.92v3a2 2 0 01-2.18 2 19.79 19.79 0 01-8.63-3.07A19.5 19.5 0 013.7 10.74 19.79 19.79 0 01.67 2.18 2 2 0 012.65 0h3a2 2 0 012 1.72c.127.96.361 1.903.7 2.81a2 2 0 01-.45 2.11L6.91 7.6a16 16 0 006.29 6.29l.97-1.97a2 2 0 012.11-.45c.907.339 1.85.573 2.81.7A2 2 0 0122 16.92z"/></svg>
                  ) : (
                    <svg width="8" height="8" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" strokeLinecap="round"><path d="M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"/></svg>
                  )}
                </div>
              </div>
              <div style={{flex:1,minWidth:0}}>
                <div style={{display:'flex',justifyContent:'space-between',marginBottom:2}}>
                  <span style={{fontSize:14,fontWeight: c.unread ? 700 : 500,color:'#111',letterSpacing:'-0.01em'}}>{c.name}</span>
                  <span style={{fontSize:11,color:'rgba(0,0,0,0.3)',flexShrink:0,marginLeft:8}}>{c.time}</span>
                </div>
                <div style={{fontSize:13,color:'rgba(0,0,0,0.4)',whiteSpace:'nowrap',overflow:'hidden',
                  textOverflow:'ellipsis',letterSpacing:'-0.005em'}}>{c.preview}</div>
              </div>
            </div>
          ))}
        </Card>
      )}
    </div>
  );
}

// ── CONVERSATION DETAIL — routes to SMS thread or call transcript
function ConversationDetailScreen({ onNav, params }) {
  const conv = params?.conversation;
  if (!conv) return <ConversationsScreen onNav={onNav}/>;
  if (conv.kind === 'call') {
    return <CallDetailScreen onNav={onNav} params={{call: conv.call}}/>;
  }
  return <SmsThreadScreen onNav={onNav} thread={conv}/>;
}

function SmsThreadScreen({ onNav, thread }) {
  const [draft, setDraft] = useState('');
  return (
    <div style={{background:'#f5f5f7',minHeight:'100%',display:'flex',flexDirection:'column'}}>
      <NavHeader title={thread.name} onBack="__back" backLabel="Conversations"
        action={
          <div onClick={() => onNav('belle', {prompt:`Call ${thread.name}`})}
            style={{width:32,height:32,borderRadius:'50%',background:'rgba(255,255,255,0.12)',
            display:'flex',alignItems:'center',justifyContent:'center',color:'rgba(255,255,255,0.7)',cursor:'pointer'}}>
            {Icons.phone}
          </div>
        }
      />
      <div style={{flex:1,overflowY:'auto',padding:'12px 16px',display:'flex',flexDirection:'column',gap:10}}>
        {THREAD_MESSAGES.map((m,i) => (
          <div key={i} style={{display:'flex',justifyContent: m.from==='me' ? 'flex-end':'flex-start'}}>
            <div style={{
              maxWidth:'78%', padding:'9px 13px',
              borderRadius: m.from==='me' ? '16px 16px 4px 16px' : '16px 16px 16px 4px',
              background: m.from==='me' ? '#0071e3' : 'white',
              color: m.from==='me' ? 'white' : '#111',
              fontSize:14, lineHeight:1.5, letterSpacing:'-0.005em',
              boxShadow: m.from==='me' ? 'none' : '0 1px 3px rgba(0,0,0,0.07)',
            }}>
              {m.text}
              <div style={{fontSize:10,color: m.from==='me' ? 'rgba(255,255,255,0.55)':'rgba(0,0,0,0.3)',
                marginTop:4,textAlign:'right'}}>{m.time}</div>
            </div>
          </div>
        ))}
      </div>
      {/* Belle suggest strip */}
      <div style={{margin:'0 12px 8px',background:'#f5f0ff',borderRadius:10,padding:'8px 12px',
        display:'flex',alignItems:'center',gap:8,border:'0.5px solid rgba(124,58,237,0.15)'}}>
        <div style={{width:18,height:18,borderRadius:'50%',background:'linear-gradient(135deg,#7c3aed,#4f46e5)',
          display:'flex',alignItems:'center',justifyContent:'center',flexShrink:0}}>
          <svg width="8" height="8" viewBox="0 0 24 24" fill="white"><path d="M12 2l2.09 6.26L20 9.27l-4.91 4.73 1.18 6.88L12 17.77l-6.27 3.11 1.18-6.88L2 9.27l5.91-1.01L12 2z"/></svg>
        </div>
        <div style={{fontSize:12,color:'#4c1d95',flex:1}}>Belle can reply: "I'm on my way, see you at 11:30"</div>
        <div onClick={() => setDraft("I'm on my way, see you at 11:30!")}
          style={{fontSize:12,fontWeight:600,color:'#7c3aed',cursor:'pointer'}}>Use</div>
      </div>
      {/* Input */}
      <div style={{padding:'8px 12px 28px',background:'white',borderTop:'0.5px solid rgba(0,0,0,0.08)',
        display:'flex',gap:8,alignItems:'flex-end'}}>
        <div style={{flex:1,minHeight:36,background:'#f2f2f4',borderRadius:18,
          display:'flex',alignItems:'center',padding:'0 13px'}}>
          <input value={draft} onChange={e=>setDraft(e.target.value)}
            placeholder="Message…"
            style={{flex:1,border:'none',background:'transparent',fontSize:14,color:'#111',
              outline:'none',fontFamily:'inherit'}}/>
        </div>
        <div onClick={() => setDraft('')}
          style={{width:36,height:36,borderRadius:'50%',
            background: draft.trim() ? '#0071e3' : '#e2e2e6',
            display:'flex',alignItems:'center',justifyContent:'center',cursor:'pointer',flexShrink:0}}>
          <svg width="14" height="14" viewBox="0 0 24 24" fill={draft.trim()?'white':'#999'} stroke="none">
            <line x1="22" y1="2" x2="11" y2="13" stroke={draft.trim()?'white':'#999'} strokeWidth="2" fill="none"/>
            <polygon points="22 2 15 22 11 13 2 9 22 2" fill={draft.trim()?'white':'#999'}/>
          </svg>
        </div>
      </div>
    </div>
  );
}

// ── ESTIMATES DATA (used by BillingScreen) ────────────────────
const ESTIMATES_DATA = [
  { id:'EST-0098', client:'Nguyen Group',    amount:'$550',   status:'approved', date:'Apr 20', job:'Sewer Line Inspection' },
  { id:'EST-0097', client:'Torres LLC',      amount:'$890',   status:'draft',    date:'Apr 19', job:'Gas Line Repair' },
  { id:'EST-0096', client:'Park Residence',  amount:'$180',   status:'sent',     date:'Apr 17', job:'Backflow Preventer Test' },
  { id:'EST-0095', client:'Adams Home',      amount:'$420',   status:'approved', date:'Apr 16', job:'Toilet Replacement' },
  { id:'EST-0094', client:'Steinberg Corp',  amount:'$2,800', status:'draft',    date:'Apr 14', job:'Full Bath Re-pipe' },
  { id:'EST-0093', client:'Chen Family',     amount:'$1,450', status:'sent',     date:'Apr 10', job:'Water Heater Install' },
];

// ── ESTIMATE DETAIL ───────────────────────────────────────────
function EstimateDetailScreen({ onNav, params }) {
  const est = (params && params.estimate) || ESTIMATES_DATA[0];
  const [converted, setConverted] = useState(false);

  // Tier-2 overflow: void, force-send, convert to job manually
  const overflow = (
    <OverflowMenu title="Estimate overrides" items={[
      { label:'Void estimate', sub:'(manual) — mark as voided, no notification', destructive:true },
      { label:'Force-send now', sub:'(manual) — bypass Belle review' },
      { label:'Convert to job manually', sub:'(manual) — skip Belle handoff',
        onTap:()=>onNav('new-job', {fromEstimate: est.id}) },
      { label:'Edit line items', sub:'(manual)' },
    ]}/>
  );

  return (
    <div style={{background:'#f5f5f7',minHeight:'100%',paddingBottom:120}}>
      <NavHeader title={est.id} onBack="__back" action={overflow}/>
      <div style={{background:'white',padding:'16px 20px 20px',borderBottom:'0.5px solid rgba(0,0,0,0.07)'}}>
        <div style={{display:'flex',justifyContent:'space-between',alignItems:'flex-start',marginBottom:4}}>
          <div>
            <div style={{fontSize:22,fontWeight:700,color:'#111',letterSpacing:'-0.02em',fontVariantNumeric:'tabular-nums'}}>{est.amount}</div>
            <div style={{fontSize:13,color:'rgba(0,0,0,0.4)',marginTop:2}}>{est.client} · {est.date}</div>
          </div>
          <Badge status={converted ? 'paid' : est.status}/>
        </div>
        {!converted && est.status==='approved' && (
          <BelleCTA style={{marginTop:16}}
            askLabel="Ask Belle to convert to invoice"
            manualLabel="Convert to invoice manually"
            onAsk={() => onNav('belle', {prompt:`Convert estimate ${est.id} to invoice`})}
            onManual={() => setConverted(true)}/>
        )}
        {!converted && est.status==='sent' && (
          <PrimaryButton label="Awaiting customer approval" color="#d1d5db" textColor="#6b7280" style={{marginTop:16}}
            onTap={() => onNav('belle', {prompt:`Check customer approval for ${est.id}`})}/>
        )}
        {converted && (
          <div style={{height:52,borderRadius:13,background:'#e6f7ef',display:'flex',alignItems:'center',
            justifyContent:'center',gap:8,color:'#1a9e5c',fontSize:15,fontWeight:600,marginTop:16}}>
            {Icons.check} Invoice Created
          </div>
        )}
        {est.status==='draft' && (
          <BelleCTA style={{marginTop:16}}
            askLabel="Ask Belle to send"
            manualLabel="Send estimate manually"
            onAsk={() => onNav('belle', {prompt:`Send estimate ${est.id} to ${est.client}`})}
            onManual={() => onNav('belle', {prompt:`Manually send estimate ${est.id} to ${est.client}`})}/>
        )}
      </div>
      <SectionHeader title="Line Items"/>
      <Card>
        {[
          { desc:'Labor — ' + est.job, qty:'3 hrs', rate:'$95/hr', total: '$285' },
          { desc:'Materials',           qty:'—',     rate:'—',      total: est.status==='approved' ? '$165' : '$35' },
        ].map((line,i,arr) => (
          <div key={i} style={{padding:'12px 16px',borderBottom: i<arr.length-1?'0.5px solid rgba(0,0,0,0.06)':'none'}}>
            <div style={{display:'flex',justifyContent:'space-between',alignItems:'flex-start'}}>
              <div style={{fontSize:14,fontWeight:500,color:'#111',flex:1,marginRight:8}}>{line.desc}</div>
              <div style={{fontSize:14,fontWeight:600,color:'#111',fontVariantNumeric:'tabular-nums'}}>{line.total}</div>
            </div>
            <div style={{fontSize:12,color:'rgba(0,0,0,0.4)',marginTop:2}}>{line.qty} · {line.rate}</div>
          </div>
        ))}
        <div style={{padding:'12px 16px',display:'flex',justifyContent:'space-between',background:'#f7f7f8'}}>
          <span style={{fontSize:15,fontWeight:600}}>Total</span>
          <span style={{fontSize:15,fontWeight:700,fontVariantNumeric:'tabular-nums'}}>{est.amount}</span>
        </div>
      </Card>
    </div>
  );
}

// ── CUSTOMER FORM SCREENS ─────────────────────────────────────
function CustomerFormScreen({ title, onNav, customer, submitLabel }) {
  const [form, setForm] = useState({
    firstName: customer?.firstName || customer?.name?.split(' ')[0] || 'Maria',
    lastName: customer?.lastName || customer?.name?.split(' ').slice(1).join(' ') || 'Ramos',
    company: customer?.company || 'Ramos Residence',
    phone: customer?.phone || '(415) 555-0192',
    email: customer?.email || 'maria@ramosresidence.com',
    address: customer?.address || '104 Oakmont Ave, San Francisco, CA',
    notes: customer?.notes || 'Gate code 2840. Prefers text updates before arrival.',
  });
  const fields = [
    { key:'firstName', label:'First name' },
    { key:'lastName', label:'Last name' },
    { key:'company', label:'Company / property' },
    { key:'phone', label:'Phone' },
    { key:'email', label:'Email' },
    { key:'address', label:'Service address' },
  ];

  return (
    <div style={{background:'#f5f5f7',minHeight:'100%',paddingBottom:120}}>
      <NavHeader title={title} onBack="__back"/>
      <SectionHeader title="Customer Details"/>
      <div style={{padding:'0 16px',display:'flex',flexDirection:'column',gap:10}}>
        {fields.map(field => (
          <div key={field.key} style={{background:'white',borderRadius:12,padding:'12px 14px',border:'0.5px solid rgba(0,0,0,0.07)'}}>
            <div style={{fontSize:11,fontWeight:700,color:'rgba(0,0,0,0.4)',letterSpacing:'0.05em',textTransform:'uppercase',marginBottom:6}}>{field.label}</div>
            <input
              value={form[field.key]}
              onChange={e => setForm(prev => ({ ...prev, [field.key]: e.target.value }))}
              style={{width:'100%',border:'none',outline:'none',fontSize:15,color:'#111',background:'transparent',fontFamily:'inherit',padding:0}}
            />
          </div>
        ))}
        <div style={{background:'white',borderRadius:12,padding:'12px 14px',border:'0.5px solid rgba(0,0,0,0.07)'}}>
          <div style={{fontSize:11,fontWeight:700,color:'rgba(0,0,0,0.4)',letterSpacing:'0.05em',textTransform:'uppercase',marginBottom:6}}>Notes</div>
          <textarea
            value={form.notes}
            onChange={e => setForm(prev => ({ ...prev, notes: e.target.value }))}
            rows={4}
            style={{width:'100%',border:'none',outline:'none',fontSize:15,color:'#111',background:'transparent',fontFamily:'inherit',padding:0,resize:'none',lineHeight:1.45}}
          />
        </div>
      </div>
      <div style={{padding:'16px'}}>
        <PrimaryButton label={submitLabel} onTap={() => onNav('__back')} />
      </div>
    </div>
  );
}

function NewCustomerScreen({ onNav }) {
  return <CustomerFormScreen title="New Customer" onNav={onNav} submitLabel="Create Customer"/>;
}

function EditCustomerScreen({ onNav, params }) {
  const customer = params?.customer || {
    name:'Maria Ramos',
    company:'Ramos Residence',
    phone:'(415) 555-0192',
    email:'maria@ramosresidence.com',
    address:'104 Oakmont Ave, San Francisco, CA',
    notes:'VIP customer. Ask before parking in the driveway.',
  };
  return <CustomerFormScreen title="Edit Customer" onNav={onNav} customer={customer} submitLabel="Save Changes"/>;
}

// ── CALL DETAIL ───────────────────────────────────────────────
function CallDetailScreen({ onNav, params }) {
  const call = params?.call || CALLS_DATA[0];
  const transcript = [
    { speaker:'Caller', text:'Hi, the kitchen sink is backing up again and water is pooling under the cabinet.' },
    { speaker:'Belle', text:'I can help with that. Are you looking for service today, and is the water shut off?' },
    { speaker:'Caller', text:'Yes, today if possible. The shutoff is on and we can give access anytime after 11.' },
    { speaker:'Belle', text:'I noted an urgent drain issue and shared the preferred access window with your team.' },
  ];

  return (
    <div style={{background:'#f5f5f7',minHeight:'100%',paddingBottom:100}}>
      <NavHeader title="Call Detail" onBack="__back"/>
      <div style={{background:'white',padding:'18px 20px',borderBottom:'0.5px solid rgba(0,0,0,0.07)'}}>
        <div style={{display:'flex',justifyContent:'space-between',alignItems:'flex-start'}}>
          <div>
            <div style={{fontSize:22,fontWeight:700,color:'#111',letterSpacing:'-0.02em'}}>{call.name}</div>
            <div style={{fontSize:13,color:'rgba(0,0,0,0.45)',marginTop:4}}>{call.phone} · {call.time} · {call.duration}</div>
          </div>
          <Badge status={call.status === 'missed' ? 'overdue' : 'completed'}/>
        </div>
        <div style={{marginTop:14,background:'#eff6ff',borderRadius:12,padding:'12px 14px',border:'1px solid rgba(37,99,235,0.08)'}}>
          <div style={{fontSize:11,fontWeight:700,color:'#2563eb',letterSpacing:'0.05em',textTransform:'uppercase',marginBottom:4}}>Caller Info</div>
          <div style={{fontSize:14,color:'#111',lineHeight:1.5}}>{call.summary || 'Caller discussed an open job and timing for technician arrival.'}</div>
        </div>
      </div>

      <SectionHeader title="Transcript"/>
      <Card>
        {transcript.map((line, i) => (
          <div key={i} style={{padding:'13px 16px',borderBottom:i<transcript.length-1?'0.5px solid rgba(0,0,0,0.06)':'none'}}>
            <div style={{fontSize:11,fontWeight:700,color:line.speaker==='Belle' ? '#7c3aed' : 'rgba(0,0,0,0.45)',letterSpacing:'0.05em',textTransform:'uppercase',marginBottom:5}}>{line.speaker}</div>
            <div style={{fontSize:14,color:'#111',lineHeight:1.5}}>{line.text}</div>
          </div>
        ))}
      </Card>
    </div>
  );
}

Object.assign(window, {
  ConversationsScreen, ConversationDetailScreen, SmsThreadScreen,
  EstimateDetailScreen, CallDetailScreen,
  NewCustomerScreen, EditCustomerScreen,
  ESTIMATES_DATA, CALLS_DATA, THREADS,
});
