// apps-ipad.jsx — Primeways Business App on iPad (landscape, tablet-optimised)
// Tablet layouts for the key staff/admin screens: Dashboard, Leads (split view),
// Site Visit and Schedule. Reuses the shared kit tokens, icons and primitives.
(function () {
  const R = React, h = R.createElement;
  const { C, SURFACES } = window.PWKit;
  const { Media, Btn, Tag, Ico, Mark, Logo } = window;
  const Avatar = window.CRM._f.Avatar;

  const PADW = 1194, PADH = 834;

  /* ---------- iPad device frame (landscape) ---------- */
  function IPadDevice({ width = PADW, height = PADH, children }) {
    const bez = 15;
    return (
      <div style={{
        width: width + bez * 2, height: height + bez * 2, borderRadius: 38, padding: bez,
        background: 'linear-gradient(150deg,#2b2b2e,#0c0c0d)', position: 'relative',
        boxShadow: '0 50px 100px rgba(0,0,0,0.32), 0 0 0 1px rgba(0,0,0,0.4), inset 0 0 0 2px rgba(255,255,255,0.04)',
      }}>
        {/* front camera */}
        <div style={{ position: 'absolute', top: '50%', left: bez / 2 - 1, transform: 'translateY(-50%)', width: 6, height: 6, borderRadius: 6, background: '#1a1a1c', boxShadow: 'inset 0 0 2px rgba(120,150,255,0.4)' }} />
        <div style={{ width, height, borderRadius: 24, overflow: 'hidden', background: '#F2F2F7', position: 'relative', fontFamily: C.fontB }}>
          {children}
        </div>
      </div>
    );
  }

  /* ---------- iPad app shell: sidebar + content ---------- */
  const NAV = [
    ['grid', 'Home'], ['spark', 'Leads'], ['hammer', 'Jobs'], ['calendar', 'Schedule'],
    ['image', 'Photos'], ['msg', 'Messages'], ['spark', 'AI Assistant'],
  ];
  function Shell({ active, title, sub, actions, children, bg = '#F2F2F7' }) {
    return (
      <div style={{ display: 'flex', width: '100%', height: '100%' }}>
        {/* status bar overlay */}
        <div style={{ position: 'absolute', top: 0, left: 232, right: 0, height: 30, display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '0 22px', zIndex: 30, pointerEvents: 'none', fontFamily: '-apple-system, system-ui', fontSize: 13, fontWeight: 600, color: C.ink700 }}>
          <span>9:41</span>
          <span style={{ display: 'flex', gap: 6, alignItems: 'center' }}>
            <span style={{ fontWeight: 700 }}>Tue 10 Jun</span>
          </span>
        </div>
        {/* sidebar */}
        <div style={{ width: 232, flexShrink: 0, background: C.ink900, backgroundImage: 'var(--overlay-brand)', display: 'flex', flexDirection: 'column', padding: '26px 16px 18px', position: 'relative' }}>
          <div style={{ position: 'absolute', inset: 0, ...SURFACES.tarmac.css, opacity: 0.16 }} />
          <div style={{ position: 'relative', display: 'flex', alignItems: 'center', gap: 10, padding: '4px 8px 22px' }}>
            <Logo white height={26} />
          </div>
          <div style={{ position: 'relative', display: 'flex', flexDirection: 'column', gap: 4, flex: 1 }}>
            {NAV.map(([ic, label]) => {
              const on = label === active;
              return (
                <div key={label} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '11px 12px', borderRadius: 11, background: on ? C.accent : 'transparent', cursor: 'default' }}>
                  <Ico name={ic} size={19} color={on ? C.ink900 : 'rgba(255,255,255,0.72)'} />
                  <span style={{ fontFamily: C.fontH, fontWeight: 700, fontSize: 13.5, color: on ? C.ink900 : 'rgba(255,255,255,0.82)' }}>{label}</span>
                </div>
              );
            })}
          </div>
          <div style={{ position: 'relative', display: 'flex', alignItems: 'center', gap: 11, padding: '12px 8px 0', borderTop: '1px solid rgba(255,255,255,0.12)' }}>
            <Avatar name="Dave Owen" size={36} tone={C.blue} />
            <div>
              <div style={{ fontFamily: C.fontH, fontWeight: 700, fontSize: 13, color: '#fff' }}>Dave Owen</div>
              <div style={{ fontFamily: C.fontB, fontSize: 11, color: 'rgba(255,255,255,0.55)' }}>Director</div>
            </div>
          </div>
        </div>
        {/* content */}
        <div style={{ flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', background: bg }}>
          <div style={{ display: 'flex', alignItems: 'flex-end', justifyContent: 'space-between', padding: '40px 28px 16px', flexShrink: 0 }}>
            <div>
              {sub && <div style={{ fontFamily: C.fontH, fontWeight: 700, fontSize: 12, letterSpacing: '0.08em', textTransform: 'uppercase', color: C.blue, marginBottom: 5 }}>{sub}</div>}
              <div style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 27, letterSpacing: '-0.01em', textTransform: 'uppercase', color: C.ink900 }}>{title}</div>
            </div>
            {actions}
          </div>
          <div style={{ flex: 1, minHeight: 0, overflow: 'auto', padding: '0 28px 28px' }}>{children}</div>
        </div>
      </div>
    );
  }

  const Card = ({ title, action, children, pad = 16, style }) => (
    <div style={{ background: '#fff', borderRadius: 16, border: `1px solid ${C.border}`, boxShadow: C.shadowSm, overflow: 'hidden', ...style }}>
      {title && <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '14px 16px 0' }}>
        <span style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 14, textTransform: 'uppercase', color: C.ink900 }}>{title}</span>{action}
      </div>}
      <div style={{ padding: pad }}>{children}</div>
    </div>
  );
  const Lab = ({ children }) => <div style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 12, letterSpacing: '0.06em', textTransform: 'uppercase', color: C.ink500 }}>{children}</div>;
  const KPI = ({ label, value, delta, accent }) => (
    <div style={{ background: accent ? C.blue600 : '#fff', backgroundImage: accent ? 'var(--overlay-brand)' : undefined, border: accent ? 'none' : `1px solid ${C.border}`, borderRadius: 14, padding: '16px 18px', boxShadow: C.shadowSm }}>
      <Lab>{accent ? <span style={{ color: 'rgba(255,255,255,0.75)' }}>{label}</span> : label}</Lab>
      <div style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 32, color: accent ? '#fff' : C.ink900, marginTop: 6 }}>{value}</div>
      {delta && <div style={{ fontFamily: C.fontB, fontSize: 12, color: accent ? 'rgba(255,255,255,0.85)' : C.success, marginTop: 2 }}>{delta}</div>}
    </div>
  );

  /* ============================ 1 · DASHBOARD ============================ */
  function Dashboard() {
    const visits = [['09:00', 'Tarmac survey', 'Wilnecote', C.blue], ['14:00', 'Karen Doyle · Resin', 'Tamworth', C.danger]];
    const hot = [['Karen Doyle', 'Resin · 70m²', '£6,900', C.danger], ['Mark Evans', 'Tarmac · 2 cars', '£3,800', C.danger], ['T. Reilly', 'Block paving', '£5,200', C.warning]];
    const week = [['Tarmac drive', 'Wilnecote · Day 2 of 3', C.blue], ['Resin survey', 'Tamworth · 2pm', C.danger], ['Patio build', 'Fazeley · Tomorrow', C.success], ['Block paving', 'Lichfield · Thu', C.warning]];
    return (
      <Shell active="Home" sub="Tuesday 10 June" title="Good morning, Dave" actions={<Btn size="sm" variant="primary" icon="plus">Add Lead</Btn>}>
        <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4,1fr)', gap: 14, marginBottom: 16 }}>
          <KPI label="New leads" value="4" delta="2 hot · today" accent />
          <KPI label="Quotes to send" value="3" delta="£14.6k value" />
          <KPI label="Jobs live" value="6" delta="on schedule" />
          <KPI label="Reviews due" value="5" delta="ask today" />
        </div>
        <div style={{ display: 'grid', gridTemplateColumns: '1.5fr 1fr', gap: 16 }}>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
            <Card title="Today · 2 site visits" action={<Tag tone="brand">Route map</Tag>}>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
                {visits.map((v, i) => (
                  <div key={i} style={{ display: 'flex', alignItems: 'center', gap: 14, padding: '10px 12px', background: C.ink50, borderRadius: 12 }}>
                    <div style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 16, color: v[3], width: 52 }}>{v[0]}</div>
                    <div style={{ flex: 1 }}>
                      <div style={{ fontFamily: C.fontH, fontWeight: 700, fontSize: 15, color: C.ink900 }}>{v[1]}</div>
                      <div style={{ display: 'flex', alignItems: 'center', gap: 5, fontFamily: C.fontB, fontSize: 12.5, color: C.ink500 }}><Ico name="pin" size={12} color={C.ink400} />{v[2]}</div>
                    </div>
                    <Btn size="sm" variant="outline" icon="route">Directions</Btn>
                  </div>
                ))}
              </div>
            </Card>
            <Card title="This week" action={<span style={{ fontFamily: C.fontH, fontWeight: 700, fontSize: 11, color: C.blue, textTransform: 'uppercase' }}>Full schedule</span>}>
              <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10 }}>
                {week.map((j, i) => (
                  <div key={i} style={{ display: 'flex', gap: 11, alignItems: 'center', padding: '10px 12px', border: `1px solid ${C.border}`, borderRadius: 12 }}>
                    <div style={{ width: 4, alignSelf: 'stretch', borderRadius: 4, background: j[2] }} />
                    <div><div style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 13.5, color: C.ink900 }}>{j[0]}</div><div style={{ fontFamily: C.fontB, fontSize: 12, color: C.ink500 }}>{j[1]}</div></div>
                  </div>
                ))}
              </div>
            </Card>
          </div>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
            <Card title="Hot leads" action={<span style={{ fontFamily: C.fontH, fontWeight: 700, fontSize: 11, color: C.blue, textTransform: 'uppercase' }}>View all</span>}>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
                {hot.map((l, i) => (
                  <div key={i} style={{ display: 'flex', alignItems: 'center', gap: 11 }}>
                    <Avatar name={l[0]} size={38} tone={l[3]} />
                    <div style={{ flex: 1 }}><div style={{ fontFamily: C.fontH, fontWeight: 700, fontSize: 13.5, color: C.ink900 }}>{l[0]}</div><div style={{ fontFamily: C.fontB, fontSize: 12, color: C.ink500 }}>{l[1]}</div></div>
                    <div style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 14, color: C.ink900 }}>{l[2]}</div>
                  </div>
                ))}
              </div>
            </Card>
            <Card style={{ background: C.warning100, border: 'none' }}>
              <div style={{ display: 'flex', alignItems: 'center', gap: 13 }}>
                <Ico name="rain" size={26} color={C.warning} />
                <div><div style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 13.5, color: C.ink900 }}>Heavy rain Thursday</div><div style={{ fontFamily: C.fontB, fontSize: 12.5, color: C.ink600 }}>2 tarmac jobs may need moving</div></div>
              </div>
            </Card>
            <Card title="Jobs needing photos">
              <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 8 }}>
                {['after', 'after', 'after'].map((k, i) => <Media key={i} surface={['tarmac', 'resin', 'block'][i]} h={58} radius={9} />)}
              </div>
            </Card>
          </div>
        </div>
      </Shell>
    );
  }

  /* ============================ 2 · LEADS (split view) ============================ */
  function Leads() {
    const leads = [
      ['Karen Doyle', 'Resin · 70m²', 'Tamworth', 'Visualiser', 'hot', true],
      ['Mark Evans', 'Tarmac · 2 cars', 'Tamworth', 'Quote form', 'hot', false],
      ['New caller', 'Driveway enquiry', 'Lichfield', 'Missed call', 'warning', false],
      ['Sue Akhtar', 'Block paving', 'Polesworth', 'Facebook', 'cold', false],
      ['T. Reilly', 'Tarmac drive', 'Burntwood', 'Website', 'warning', false],
    ];
    const tone = (t) => t === 'hot' ? C.danger : t === 'warning' ? C.warning : C.blue;
    const timeline = [['spark', 'Lead created', 'Designed driveway in the visualiser', '2h'], ['eye', 'Viewed services', 'Resin + block paving pages', '2h'], ['file', 'Quote requested', '70m² resin-bound, front drive', '1h']];
    return (
      <Shell active="Leads" sub="4 new today" title="Lead Inbox" actions={<Btn size="sm" variant="outline" icon="filter">Filter</Btn>}>
        <div style={{ display: 'grid', gridTemplateColumns: '340px 1fr', gap: 16, height: '100%' }}>
          {/* list */}
          <div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
            {leads.map((l, i) => (
              <div key={i} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: 13, background: '#fff', border: `1px solid ${l[5] ? C.blue : C.border}`, outline: l[5] ? `1px solid ${C.blue}` : 'none', borderRadius: 14, boxShadow: C.shadowSm }}>
                <Avatar name={l[0]} size={42} tone={tone(l[4])} />
                <div style={{ flex: 1, minWidth: 0 }}>
                  <div style={{ display: 'flex', alignItems: 'center', gap: 6 }}>
                    <span style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 14.5, color: C.ink900 }}>{l[0]}</span>
                    {l[4] === 'hot' && <span style={{ width: 7, height: 7, borderRadius: 7, background: C.danger }} />}
                  </div>
                  <div style={{ fontFamily: C.fontB, fontSize: 12.5, color: C.ink600 }}>{l[1]}</div>
                  <div style={{ display: 'flex', alignItems: 'center', gap: 5, marginTop: 2, fontFamily: C.fontB, fontSize: 11.5, color: C.ink500 }}><Ico name="pin" size={11} color={C.ink400} />{l[2]} · {l[3]}</div>
                </div>
              </div>
            ))}
          </div>
          {/* detail */}
          <div style={{ display: 'flex', flexDirection: 'column', gap: 14, background: '#fff', border: `1px solid ${C.border}`, borderRadius: 16, boxShadow: C.shadowSm, padding: 20, overflow: 'hidden' }}>
            <div style={{ display: 'flex', alignItems: 'center', gap: 14 }}>
              <Avatar name="Karen Doyle" size={54} tone={C.danger} />
              <div style={{ flex: 1 }}>
                <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                  <span style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 20, color: C.ink900 }}>Karen Doyle</span>
                  <Tag tone="hot">Hot lead</Tag>
                </div>
                <div style={{ fontFamily: C.fontB, fontSize: 13, color: C.ink500 }}>14 Oak Rise, Tamworth B79 7DN · via Visualiser</div>
              </div>
              <div style={{ display: 'flex', gap: 8 }}>
                <Btn size="sm" variant="primary" icon="phone">Call</Btn>
                <Btn size="sm" variant="outline" icon="msg">Text</Btn>
              </div>
            </div>
            <div style={{ display: 'grid', gridTemplateColumns: '1.2fr 1fr', gap: 14, flex: 1, minHeight: 0 }}>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 12 }}>
                <div>
                  <Lab>Their visualiser design</Lab>
                  <div style={{ marginTop: 8 }}><Media surface="resin" h={150} radius={12} label="Resin · Autumn Gold" brand /></div>
                </div>
                <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10 }}>
                  <div style={{ padding: 12, background: C.blue50, borderRadius: 12 }}><Lab>Est. value</Lab><div style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 22, color: C.ink900 }}>£6,900</div></div>
                  <div style={{ padding: 12, background: C.ink50, borderRadius: 12 }}><Lab>Area</Lab><div style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 22, color: C.ink900 }}>70m²</div></div>
                </div>
                <Btn variant="accent" size="lg" iconR="arrow" style={{ justifyContent: 'center' }}>Build Quote</Btn>
              </div>
              <div>
                <Lab>Activity</Lab>
                <div style={{ marginTop: 8, display: 'flex', flexDirection: 'column', gap: 12 }}>
                  {timeline.map((t, i) => (
                    <div key={i} style={{ display: 'flex', gap: 11 }}>
                      <div style={{ width: 32, height: 32, borderRadius: 9, background: C.blue50, display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0 }}><Ico name={t[0]} size={15} color={C.blue} /></div>
                      <div style={{ flex: 1 }}><div style={{ fontFamily: C.fontH, fontWeight: 700, fontSize: 12.5, color: C.ink900 }}>{t[1]}</div><div style={{ fontFamily: C.fontB, fontSize: 11.5, color: C.ink500 }}>{t[2]}</div></div>
                      <span style={{ fontFamily: C.fontB, fontSize: 11, color: C.ink400 }}>{t[3]}</span>
                    </div>
                  ))}
                </div>
              </div>
            </div>
          </div>
        </div>
      </Shell>
    );
  }

  /* ============================ 3 · SITE VISIT ============================ */
  function SiteVisit() {
    const notes = [['Access', 'Good — driveway off road'], ['Drainage', 'Aco channel needed by garage'], ['Sub-base', 'Excavate ~150mm'], ['Edging', 'Charcoal block border']];
    return (
      <Shell active="Jobs" sub="Site Visit · 2:00pm" title="Karen Doyle" actions={<Btn size="sm" variant="outline" icon="route">Directions</Btn>} bg="#EEF0F3">
        <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 16, height: '100%' }}>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
            <Card>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 9 }}>
                {[['pin', '14 Oak Rise, Tamworth B79 7DN'], ['layers', 'Resin bound · approx 70m²'], ['clock', 'Replacing old tarmac · drainage issue']].map((d, i) => (
                  <div key={i} style={{ display: 'flex', alignItems: 'center', gap: 11, fontFamily: C.fontB, fontSize: 14, color: C.ink700 }}><Ico name={d[0]} size={17} color={C.blue} />{d[1]}</div>
                ))}
              </div>
            </Card>
            <Card title="Customer photos">
              <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 9 }}>
                {['old', 'old', 'old'].map((k, i) => <Media key={i} surface={k} h={92} radius={9} label={['Front', 'Close', 'Drain'][i]} />)}
              </div>
            </Card>
            <Card title="Site notes" style={{ flex: 1 }}>
              <div style={{ display: 'flex', flexDirection: 'column', gap: 11 }}>
                {notes.map((n, i) => (
                  <div key={i} style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontFamily: C.fontB, fontSize: 13.5, paddingBottom: 10, borderBottom: i < notes.length - 1 ? `1px solid ${C.border}` : 'none' }}>
                    <span style={{ color: C.ink500 }}>{n[0]}</span>
                    <span style={{ fontFamily: C.fontH, fontWeight: 700, color: C.ink900, textAlign: 'right', maxWidth: 280 }}>{n[1]}</span>
                  </div>
                ))}
              </div>
            </Card>
          </div>
          <div style={{ display: 'flex', flexDirection: 'column', gap: 14 }}>
            <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 12 }}>
              <div style={{ background: C.blue600, backgroundImage: 'var(--overlay-brand)', borderRadius: 16, padding: '22px 18px', display: 'flex', flexDirection: 'column', gap: 8, color: '#fff' }}>
                <Ico name="camera" size={26} color="#fff" />
                <span style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 15, textTransform: 'uppercase' }}>Take Photos</span>
                <span style={{ fontFamily: C.fontB, fontSize: 12, color: 'rgba(255,255,255,0.8)' }}>Filed to this job</span>
              </div>
              <div style={{ background: '#fff', border: `1px solid ${C.border}`, borderRadius: 16, padding: '22px 18px', display: 'flex', flexDirection: 'column', gap: 8 }}>
                <Ico name="mic" size={26} color={C.blue} />
                <span style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 15, textTransform: 'uppercase', color: C.ink900 }}>Voice Note</span>
                <span style={{ fontFamily: C.fontB, fontSize: 12, color: C.ink500 }}>Auto-transcribed</span>
              </div>
            </div>
            <Card title="Measure up" style={{ flex: 1 }}>
              <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 10, marginBottom: 12 }}>
                {[['Area', '70 m²'], ['Perimeter', '34 m'], ['Surface', 'Resin bound'], ['Sub-base', '150 mm']].map((m, i) => (
                  <div key={i} style={{ padding: 12, background: C.ink50, borderRadius: 12 }}><Lab>{m[0]}</Lab><div style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 20, color: C.ink900 }}>{m[1]}</div></div>
                ))}
              </div>
              <div style={{ padding: 14, borderRadius: 12, background: C.blue50, display: 'flex', alignItems: 'center', justifyContent: 'space-between' }}>
                <div><Lab>Indicative price</Lab><div style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 26, color: C.ink900 }}>£6,900</div></div>
                <Tag tone="brand">Auto-calculated</Tag>
              </div>
            </Card>
            <Btn variant="accent" size="lg" iconR="arrow" style={{ width: '100%', justifyContent: 'center' }}>Create Quote Draft</Btn>
          </div>
        </div>
      </Shell>
    );
  }

  /* ============================ 4 · SCHEDULE (week grid) ============================ */
  function Schedule() {
    const days = [['Mon', '9'], ['Tue', '10', true], ['Wed', '11'], ['Thu', '12'], ['Fri', '13'], ['Sat', '14']];
    const jobs = {
      0: [['Tarmac drive', 'Wilnecote', C.blue, 'Day 1']],
      1: [['Tarmac drive', 'Wilnecote', C.blue, 'Day 2'], ['Resin survey', 'Tamworth · 2pm', C.danger, 'Visit']],
      2: [['Tarmac drive', 'Wilnecote', C.blue, 'Day 3']],
      3: [['Block paving', 'Lichfield', C.warning, 'Rain risk']],
      4: [['Patio build', 'Fazeley', C.success, 'Day 1']],
      5: [['Gravel drive', 'Polesworth', C.blue, 'Half day']],
    };
    return (
      <Shell active="Schedule" sub="This week" title="Schedule" actions={<div style={{ display: 'flex', gap: 8 }}><Btn size="sm" variant="outline" icon="chevL">Prev</Btn><Btn size="sm" variant="primary" icon="plus">New Job</Btn></div>}>
        <div style={{ background: '#fff', border: `1px solid ${C.border}`, borderRadius: 16, boxShadow: C.shadowSm, overflow: 'hidden', height: '100%', display: 'flex', flexDirection: 'column' }}>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(6,1fr)' }}>
            {days.map((d, i) => (
              <div key={i} style={{ padding: '14px 12px', textAlign: 'center', borderBottom: `1px solid ${C.border}`, borderLeft: i ? `1px solid ${C.border}` : 'none', background: d[2] ? C.blue50 : '#fff' }}>
                <div style={{ fontFamily: C.fontH, fontWeight: 700, fontSize: 12, textTransform: 'uppercase', color: d[2] ? C.blue : C.ink500 }}>{d[0]}</div>
                <div style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 22, color: d[2] ? C.blue : C.ink900 }}>{d[1]}</div>
              </div>
            ))}
          </div>
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(6,1fr)', flex: 1 }}>
            {days.map((d, i) => (
              <div key={i} style={{ padding: 10, borderLeft: i ? `1px solid ${C.border}` : 'none', display: 'flex', flexDirection: 'column', gap: 8, background: d[2] ? 'rgba(31,79,163,0.03)' : '#fff' }}>
                {(jobs[i] || []).map((j, k) => (
                  <div key={k} style={{ borderRadius: 10, overflow: 'hidden', background: '#fff', border: `1px solid ${C.border}`, boxShadow: C.shadowSm }}>
                    <div style={{ height: 4, background: j[2] }} />
                    <div style={{ padding: '9px 10px' }}>
                      <div style={{ fontFamily: C.fontH, fontWeight: 800, fontSize: 12.5, color: C.ink900, lineHeight: 1.15 }}>{j[0]}</div>
                      <div style={{ fontFamily: C.fontB, fontSize: 11, color: C.ink500, marginTop: 2 }}>{j[1]}</div>
                      <div style={{ marginTop: 6 }}><Tag tone={j[2] === C.warning ? 'warning' : 'neutral'}>{j[3]}</Tag></div>
                    </div>
                  </div>
                ))}
              </div>
            ))}
          </div>
        </div>
      </Shell>
    );
  }

  window.APPS_IPAD = { IPadDevice, PADW, PADH, Dashboard, Leads, SiteVisit, Schedule };
})();
