// arcai-admin.jsx — A01 Org Dashboard, A02 Cohort View, A03 User Detail

const SIDEBAR_W = 240;

function SidebarNav({ active, onNavigate }) {
  const items = [
    { id: 'A01', label: 'Dashboard', icon: <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><rect x="3" y="3" width="7" height="7" rx="1"/><rect x="14" y="3" width="7" height="7" rx="1"/><rect x="3" y="14" width="7" height="7" rx="1"/><rect x="14" y="14" width="7" height="7" rx="1"/></svg> },
    { id: 'A02', label: 'Cohorts', icon: <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 00-3-3.87M16 3.13a4 4 0 010 7.75"/></svg> },
    { id: 'A03', label: 'Users', icon: <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="12" cy="8" r="4"/><path d="M4 20c0-4 3.6-7 8-7s8 3 8 7"/></svg> },
    { id: 'goals', label: 'Goals', icon: <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="12" cy="12" r="10"/><circle cx="12" cy="12" r="6"/><circle cx="12" cy="12" r="2"/></svg> },
    { id: 'reports', label: 'Reports', icon: <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><path d="M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="8" y1="13" x2="16" y2="13"/><line x1="8" y1="17" x2="12" y2="17"/></svg> },
    { id: 'settings', label: 'Settings', icon: <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="12" cy="12" r="3"/><path d="M12 2v2m0 16v2M4.22 4.22l1.42 1.42m12.72 12.72l1.42 1.42M2 12h2m16 0h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42"/></svg> },
  ];
  return (
    <div style={{ width: SIDEBAR_W, background: 'var(--bg-soft)', borderRight: '1px solid var(--border)', display: 'flex', flexDirection: 'column', height: '100%', flexShrink: 0 }}>
      {/* Logo */}
      <div style={{ padding: '24px 20px 20px', borderBottom: '1px solid var(--border)' }}>
        <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
          <svg width="28" height="28" viewBox="0 0 20 20" style={{ display: 'block', flexShrink: 0, filter: 'drop-shadow(0 0 6px var(--accent-glow))' }}>
            <path d="M 3 15 A 7 7 0 0 1 17 15" stroke="var(--accent)" strokeWidth="2.5" fill="none" strokeLinecap="round" />
            <circle cx="10" cy="8" r="2" fill="var(--accent)" />
          </svg>
          <span style={{ fontFamily: 'var(--font-display)', fontWeight: 700, fontSize: 18, color: 'var(--text)', letterSpacing: '-0.02em' }}>arcai</span>
        </div>
        <div style={{ fontSize: 11, color: 'var(--text-dim)', marginTop: 4, fontFamily: 'var(--font-mono)' }}>PT Acme · Admin</div>
      </div>
      {/* Nav items */}
      <nav style={{ flex: 1, padding: '12px 10px' }}>
        {items.map(item => (
          <button key={item.id} onClick={() => onNavigate(item.id)}
            style={{
              width: '100%', display: 'flex', alignItems: 'center', gap: 10,
              padding: '10px 12px', borderRadius: 10, marginBottom: 2,
              background: active === item.id ? 'var(--surface-1)' : 'transparent',
              border: 'none', cursor: 'pointer',
              color: active === item.id ? 'var(--accent)' : 'var(--text-muted)',
              fontSize: 14, fontWeight: active === item.id ? 600 : 400,
              fontFamily: 'var(--font-body)',
              textAlign: 'left',
              borderLeft: active === item.id ? '2px solid var(--accent)' : '2px solid transparent',
              transition: 'all 0.15s',
            }}>
            {item.icon}
            {item.label}
          </button>
        ))}
      </nav>
      {/* User */}
      <div style={{ padding: '16px', borderTop: '1px solid var(--border)', display: 'flex', alignItems: 'center', gap: 10 }}>
        <Avatar name="Sarah Kusuma" size={32} />
        <div>
          <div style={{ fontSize: 13, fontWeight: 600, color: 'var(--text)' }}>Sarah Kusuma</div>
          <div style={{ fontSize: 11, color: 'var(--text-muted)' }}>HR Manager</div>
        </div>
      </div>
    </div>
  );
}

function TopBar({ title, subtitle }) {
  return (
    <div style={{ height: 56, borderBottom: '1px solid var(--border)', display: 'flex', alignItems: 'center', justifyContent: 'space-between', padding: '0 28px', flexShrink: 0, background: 'var(--bg)' }}>
      <div>
        <div style={{ fontSize: 12, color: 'var(--text-dim)', fontFamily: 'var(--font-mono)' }}>{subtitle}</div>
        <div style={{ fontSize: 16, fontWeight: 700, color: 'var(--text)', fontFamily: 'var(--font-display)', letterSpacing: '-0.015em' }}>{title}</div>
      </div>
      <div style={{ display: 'flex', alignItems: 'center', gap: 12 }}>
        {['Minggu','Bulan','Kuartal'].map((l, i) => (
          <button key={l} style={{ padding: '5px 12px', borderRadius: 8, border: `1px solid ${i===1 ? 'var(--accent)' : 'var(--border)'}`, background: i===1 ? 'var(--accent-overlay-mid)' : 'transparent', color: i===1 ? 'var(--accent)' : 'var(--text-muted)', fontSize: 12, fontWeight: 600, cursor: 'pointer', fontFamily: 'var(--font-body)' }}>{l}</button>
        ))}
        <Avatar name="Sarah Kusuma" size={28} />
      </div>
    </div>
  );
}

// ── KPI Card ──────────────────────────────────────────────────────────────
function KPICard({ label, value, sub, sparkData, progress, icon, wide }) {
  return (
    <div style={{ background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 16, padding: '20px 22px', gridColumn: wide ? 'span 2' : 'span 1', minHeight: 120 }}>
      <div style={{ fontSize: 11, color: 'var(--text-muted)', fontWeight: 700, letterSpacing: '0.08em', textTransform: 'uppercase', marginBottom: 10, display: 'flex', alignItems: 'center', gap: 6 }}>
        {icon && <span>{icon}</span>}{label}
      </div>
      <div style={{ display: 'flex', alignItems: 'flex-end', gap: 12, justifyContent: 'space-between' }}>
        <div>
          <div style={{ fontFamily: 'var(--font-display)', fontSize: 36, fontWeight: 700, color: 'var(--text)', letterSpacing: '-0.03em', lineHeight: 1 }}>{value}</div>
          <div style={{ fontSize: 12, color: 'var(--text-muted)', marginTop: 5 }}>{sub}</div>
        </div>
        {sparkData && <Sparkline data={sparkData} width={64} height={32} />}
        {progress !== undefined && (
          <div style={{ width: 48, height: 48, position: 'relative', flexShrink: 0 }}>
            <svg width="48" height="48" viewBox="0 0 48 48">
              <circle cx="24" cy="24" r="20" fill="none" stroke="var(--surface-2)" strokeWidth="4"/>
              <circle cx="24" cy="24" r="20" fill="none" stroke="var(--accent)" strokeWidth="4"
                strokeDasharray={`${2 * Math.PI * 20 * progress} ${2 * Math.PI * 20 * (1 - progress)}`}
                strokeDashoffset={2 * Math.PI * 20 * 0.25}
                strokeLinecap="round"
              />
            </svg>
            <div style={{ position: 'absolute', inset: 0, display: 'flex', alignItems: 'center', justifyContent: 'center', fontSize: 11, fontWeight: 700, color: 'var(--accent)', fontFamily: 'var(--font-mono)' }}>
              {Math.round(progress * 100)}%
            </div>
          </div>
        )}
      </div>
    </div>
  );
}

// ── A01 Org Dashboard ─────────────────────────────────────────────────────
function ScreenA01({ onNavigate }) {
  const laggingUsers = [
    { name: 'Budi Santoso', team: 'Marketing', level: 1, lastActive: '8 hari lalu' },
    { name: 'Citra Lestari', team: 'Finance', level: 1, lastActive: '11 hari lalu' },
    { name: 'Doni Wijaya', team: 'Sales', level: 2, lastActive: '7 hari lalu' },
    { name: 'Eka Putri', team: 'HR', level: 1, lastActive: '14 hari lalu' },
    { name: 'Fajar Nugroho', team: 'Ops', level: 2, lastActive: '9 hari lalu' },
  ];
  const champions = [
    { name: 'Rayis Ananda', team: 'Product', level: 4, streak: 21, xp: 1240 },
    { name: 'Lina Sari', team: 'Engineering', level: 4, streak: 18, xp: 1180 },
    { name: 'Marco Tan', team: 'Design', level: 3, streak: 14, xp: 920 },
    { name: 'Nadia Putri', team: 'Marketing', level: 3, streak: 12, xp: 860 },
    { name: 'Omar Faisal', team: 'Product', level: 3, streak: 10, xp: 810 },
  ];
  const trendData = [
    { label: 'Jan', value: 1.2 }, { label: 'Feb', value: 1.5 }, { label: 'Mar', value: 1.7 },
    { label: 'Apr W1', value: 1.9 }, { label: 'Apr W2', value: 2.1 }, { label: 'Apr W3', value: 2.3 },
    { label: 'Apr W4', value: 2.4 },
  ];

  return (
    <div style={{ display: 'flex', height: '100%', overflow: 'hidden' }}>
      <SidebarNav active="A01" onNavigate={onNavigate} />
      <div style={{ flex: 1, display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
        <TopBar title="Dashboard" subtitle="PT Acme · Overview" />
        <div style={{ flex: 1, overflowY: 'auto', padding: '24px 28px' }}>
          {/* Alert banner */}
          <div style={{ background: 'rgba(255,196,0,0.08)', border: '1px solid rgba(255,196,0,0.2)', borderRadius: 12, padding: '12px 16px', marginBottom: 20, display: 'flex', alignItems: 'center', gap: 10 }}>
            <span style={{ fontSize: 16 }}>⚠️</span>
            <div style={{ fontSize: 13, color: 'var(--warn)', fontWeight: 600 }}>3 karyawan stuck lebih dari 7 hari — Tim Anda perlu perhatian</div>
            <button onClick={() => onNavigate('A02')} style={{ marginLeft: 'auto', fontSize: 12, color: 'var(--accent)', background: 'none', border: 'none', cursor: 'pointer', fontWeight: 600 }}>Lihat →</button>
          </div>

          {/* KPI row */}
          <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: 16, marginBottom: 24 }}>
            <KPICard label="Avg Level" value="2.4" sub="Target: 3.0" sparkData={[1.2,1.5,1.7,1.9,2.1,2.3,2.4]} />
            <KPICard label="Di Target" value="38%" sub="68 / 180 karyawan" progress={0.38} />
            <KPICard label="Active 30d" value="142" sub="142 / 180 terdaftar" sparkData={[110,118,125,130,135,138,142]} />
            <KPICard label="Avg Streak" value="5.2" sub="hari berturut-turut" icon="🔥" sparkData={[3.1,3.8,4.2,4.5,4.8,5.0,5.2]} />
          </div>

          {/* Trend chart */}
          <div style={{ background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 16, padding: '20px', marginBottom: 24 }}>
            <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--text)', marginBottom: 4 }}>Tren Avg Level</div>
            <div style={{ fontSize: 11, color: 'var(--text-muted)', marginBottom: 16 }}>Rata-rata level tim per minggu</div>
            <LineChart data={trendData} width={700} height={140} />
          </div>

          {/* Tables row */}
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr', gap: 20 }}>
            {/* Lagging */}
            <div style={{ background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 16, overflow: 'hidden' }}>
              <div style={{ padding: '16px 20px', borderBottom: '1px solid var(--border)', display: 'flex', alignItems: 'center', gap: 8 }}>
                <span style={{ fontSize: 14 }}>⚠️</span>
                <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--text)' }}>Perlu Perhatian</div>
                <div style={{ marginLeft: 'auto', fontSize: 11, color: 'var(--text-muted)' }}>5 karyawan</div>
              </div>
              {laggingUsers.map((u, i) => (
                <div key={i} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '12px 20px', borderBottom: i < laggingUsers.length - 1 ? '1px solid var(--border)' : 'none', cursor: 'pointer' }}
                  onMouseEnter={e => e.currentTarget.style.background = 'var(--bg-soft)'}
                  onMouseLeave={e => e.currentTarget.style.background = 'transparent'}
                  onClick={() => onNavigate('A03')}
                >
                  <Avatar name={u.name} size={28} />
                  <div style={{ flex: 1, minWidth: 0 }}>
                    <div style={{ fontSize: 13, fontWeight: 600, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{u.name}</div>
                    <div style={{ fontSize: 11, color: 'var(--text-muted)' }}>{u.team} · {u.lastActive}</div>
                  </div>
                  <LevelChip level={u.level} />
                  <button style={{ fontSize: 11, color: 'var(--text-muted)', background: 'var(--surface-2)', border: '1px solid var(--border)', padding: '4px 10px', borderRadius: 8, cursor: 'pointer', fontFamily: 'var(--font-body)', fontWeight: 600 }}>Nudge</button>
                </div>
              ))}
            </div>
            {/* Champions */}
            <div style={{ background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 16, overflow: 'hidden' }}>
              <div style={{ padding: '16px 20px', borderBottom: '1px solid var(--border)', display: 'flex', alignItems: 'center', gap: 8 }}>
                <span style={{ fontSize: 14 }}>🏆</span>
                <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--text)' }}>Top Performers</div>
                <div style={{ marginLeft: 'auto', fontSize: 11, color: 'var(--text-muted)' }}>bulan ini</div>
              </div>
              {champions.map((u, i) => (
                <div key={i} style={{ display: 'flex', alignItems: 'center', gap: 12, padding: '12px 20px', borderBottom: i < champions.length - 1 ? '1px solid var(--border)' : 'none', cursor: 'pointer' }}
                  onMouseEnter={e => e.currentTarget.style.background = 'var(--bg-soft)'}
                  onMouseLeave={e => e.currentTarget.style.background = 'transparent'}
                  onClick={() => onNavigate('A03')}
                >
                  <span style={{ fontSize: 12, fontWeight: 700, color: 'var(--text-dim)', fontFamily: 'var(--font-mono)', width: 16 }}>#{i+1}</span>
                  <Avatar name={u.name} size={28} />
                  <div style={{ flex: 1, minWidth: 0 }}>
                    <div style={{ fontSize: 13, fontWeight: 600, color: 'var(--text)', overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>{u.name}</div>
                    <div style={{ fontSize: 11, color: 'var(--text-muted)' }}>{u.team} · 🔥 {u.streak} hari</div>
                  </div>
                  <LevelChip level={u.level} />
                  <XPChip xp={`${u.xp}`} />
                </div>
              ))}
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

// ── A02 Cohort View ───────────────────────────────────────────────────────
function ScreenA02({ onNavigate }) {
  const [selected, setSelected] = React.useState(null);
  const [search, setSearch] = React.useState('');

  const teams = [
    { name: 'Marketing', manager: 'Andi Susanto', members: 24, avgLevel: 2.1, completion: 62, trend: [1.4,1.6,1.8,1.9,2.0,2.1], lastActivity: '1 jam lalu', trendDir: 'up' },
    { name: 'Engineering', manager: 'Lina Sari', members: 18, avgLevel: 3.4, completion: 89, trend: [2.1,2.5,2.8,3.0,3.2,3.4], lastActivity: '2 jam lalu', trendDir: 'up' },
    { name: 'Sales', manager: 'Hendra Gunawan', members: 32, avgLevel: 1.8, completion: 45, trend: [1.5,1.6,1.6,1.7,1.7,1.8], lastActivity: '3 hari lalu', trendDir: 'flat' },
    { name: 'Finance', manager: 'Maria Santoso', members: 14, avgLevel: 2.0, completion: 58, trend: [1.2,1.4,1.5,1.7,1.8,2.0], lastActivity: '5 jam lalu', trendDir: 'up' },
    { name: 'HR', manager: 'Dewi Rahayu', members: 10, avgLevel: 2.3, completion: 70, trend: [1.8,1.9,2.0,2.1,2.2,2.3], lastActivity: '1 hari lalu', trendDir: 'up' },
    { name: 'Operations', manager: 'Budi Hartono', members: 20, avgLevel: 1.5, completion: 38, trend: [1.2,1.2,1.3,1.4,1.4,1.5], lastActivity: '4 hari lalu', trendDir: 'flat' },
    { name: 'Product', manager: 'Sinta Dewi', members: 12, avgLevel: 3.2, completion: 83, trend: [2.0,2.4,2.7,2.9,3.1,3.2], lastActivity: '30 menit lalu', trendDir: 'up' },
    { name: 'Design', manager: 'Rian Kusuma', members: 8, avgLevel: 2.8, completion: 77, trend: [1.9,2.1,2.3,2.5,2.7,2.8], lastActivity: '2 jam lalu', trendDir: 'up' },
  ];

  const filtered = teams.filter(t => t.name.toLowerCase().includes(search.toLowerCase()) || t.manager.toLowerCase().includes(search.toLowerCase()));

  return (
    <div style={{ display: 'flex', height: '100%', overflow: 'hidden' }}>
      <SidebarNav active="A02" onNavigate={onNavigate} />
      <div style={{ flex: 1, display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
        <TopBar title="Cohorts" subtitle="PT Acme · Tim & Departemen" />
        <div style={{ flex: 1, overflowY: 'auto', padding: '24px 28px' }}>
          {/* Filter bar */}
          <div style={{ display: 'flex', alignItems: 'center', gap: 10, marginBottom: 20 }}>
            <div style={{ position: 'relative', flex: 1, maxWidth: 320 }}>
              <svg style={{ position: 'absolute', left: 12, top: '50%', transform: 'translateY(-50%)', color: 'var(--text-dim)' }} width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2"><circle cx="11" cy="11" r="8"/><path d="m21 21-4.35-4.35"/></svg>
              <input value={search} onChange={e => setSearch(e.target.value)} placeholder="Cari tim atau manager..."
                style={{ width: '100%', background: 'var(--surface-1)', border: '1px solid var(--border)', color: 'var(--text)', padding: '10px 14px 10px 36px', borderRadius: 12, fontSize: 13, fontFamily: 'var(--font-body)', outline: 'none' }}
                onFocus={e => e.target.style.borderColor = 'var(--accent)'}
                onBlur={e => e.target.style.borderColor = 'var(--border)'}
              />
            </div>
            {['Semua Dept','Manager','Level ≥ 2','Aktif'].map((f, i) => (
              <button key={f} style={{ padding: '8px 14px', borderRadius: 999, border: `1px solid ${i === 0 ? 'var(--accent)' : 'var(--border)'}`, background: i === 0 ? 'var(--accent-overlay-mid)' : 'transparent', color: i === 0 ? 'var(--accent)' : 'var(--text-muted)', fontSize: 12, fontWeight: 600, cursor: 'pointer', fontFamily: 'var(--font-body)' }}>{f}</button>
            ))}
          </div>

          {/* DataTable */}
          <div style={{ background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 16, overflow: 'hidden' }}>
            {/* Header */}
            <div style={{ display: 'grid', gridTemplateColumns: '1.4fr 1.2fr 80px 100px 140px 80px 100px', gap: 0, padding: '12px 20px', borderBottom: '1px solid var(--border)', background: 'var(--bg-soft)' }}>
              {['TIM', 'MANAGER', 'ANGGOTA', 'AVG LEVEL', 'COMPLETION', 'TREND', 'AKTIVITAS'].map((h, i) => (
                <div key={h} style={{ fontSize: 10, fontWeight: 700, color: 'var(--text-dim)', letterSpacing: '0.08em', textTransform: 'uppercase', display: 'flex', alignItems: 'center', gap: 4 }}>
                  {h} {i < 5 && <span style={{ color: 'var(--accent)', fontSize: 8 }}>▲</span>}
                </div>
              ))}
            </div>
            {filtered.map((t, i) => (
              <div key={t.name}
                onClick={() => setSelected(selected === t.name ? null : t.name)}
                style={{
                  display: 'grid', gridTemplateColumns: '1.4fr 1.2fr 80px 100px 140px 80px 100px',
                  gap: 0, padding: '0 20px', height: 56, alignItems: 'center',
                  borderBottom: i < filtered.length - 1 ? '1px solid var(--border)' : 'none',
                  cursor: 'pointer',
                  background: selected === t.name ? 'var(--accent-overlay-soft)' : 'transparent',
                  borderLeft: selected === t.name ? '2px solid var(--accent)' : '2px solid transparent',
                  transition: 'background 0.15s',
                }}
                onMouseEnter={e => { if (selected !== t.name) e.currentTarget.style.background = 'var(--bg-soft)'; }}
                onMouseLeave={e => { if (selected !== t.name) e.currentTarget.style.background = 'transparent'; }}
              >
                <div style={{ fontSize: 13, fontWeight: 600, color: 'var(--text)' }}>{t.name}</div>
                <div style={{ fontSize: 12, color: 'var(--text-muted)' }}>{t.manager}</div>
                <div style={{ fontSize: 13, fontWeight: 600, color: 'var(--text)', fontFamily: 'var(--font-mono)' }}>{t.members}</div>
                <LevelChip level={Math.floor(t.avgLevel)} label={t.avgLevel.toFixed(1)} />
                <div style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
                  <div style={{ flex: 1, height: 4, background: 'var(--surface-2)', borderRadius: 4, overflow: 'hidden' }}>
                    <div style={{ height: '100%', width: `${t.completion}%`, background: 'linear-gradient(90deg, var(--accent-deep), var(--accent))', borderRadius: 4 }} />
                  </div>
                  <span style={{ fontSize: 11, color: 'var(--text-muted)', fontFamily: 'var(--font-mono)', width: 28, flexShrink: 0 }}>{t.completion}%</span>
                </div>
                <div style={{ display: 'flex', alignItems: 'center', gap: 4 }}>
                  <Sparkline data={t.trend} width={44} height={20} />
                  <span style={{ fontSize: 11, color: t.trendDir === 'up' ? 'var(--success)' : 'var(--text-muted)' }}>{t.trendDir === 'up' ? '↑' : '→'}</span>
                </div>
                <div style={{ fontSize: 11, color: 'var(--text-dim)' }}>{t.lastActivity}</div>
              </div>
            ))}
          </div>

          {/* Side panel (inline summary) */}
          {selected && (
            <div style={{ marginTop: 16, background: 'var(--surface-1)', border: '1px solid var(--accent-deep)', borderRadius: 16, padding: '20px', animation: 'fadein 0.2s ease-out' }}>
              <div style={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', marginBottom: 16 }}>
                <div>
                  <div style={{ fontFamily: 'var(--font-display)', fontSize: 18, fontWeight: 700, color: 'var(--text)' }}>{selected}</div>
                  <div style={{ fontSize: 12, color: 'var(--text-muted)', marginTop: 2 }}>{teams.find(t => t.name === selected)?.manager}</div>
                </div>
                <BtnPrimary onClick={() => onNavigate('A03')} size="sm">Lihat Detail Anggota →</BtnPrimary>
              </div>
              <div style={{ display: 'grid', gridTemplateColumns: 'repeat(3,1fr)', gap: 12 }}>
                {[
                  { label: 'Avg Level', value: teams.find(t => t.name === selected)?.avgLevel.toFixed(1) },
                  { label: 'Completion', value: `${teams.find(t => t.name === selected)?.completion}%` },
                  { label: 'Anggota', value: teams.find(t => t.name === selected)?.members },
                ].map(s => (
                  <div key={s.label} style={{ textAlign: 'center', padding: '12px', background: 'var(--bg-soft)', borderRadius: 10, border: '1px solid var(--border)' }}>
                    <div style={{ fontFamily: 'var(--font-display)', fontSize: 24, fontWeight: 700, color: 'var(--accent)', letterSpacing: '-0.02em' }}>{s.value}</div>
                    <div style={{ fontSize: 11, color: 'var(--text-muted)', textTransform: 'uppercase', letterSpacing: '0.06em', fontWeight: 600, marginTop: 4 }}>{s.label}</div>
                  </div>
                ))}
              </div>
            </div>
          )}
        </div>
      </div>
    </div>
  );
}

// ── A03 User Detail ───────────────────────────────────────────────────────
function ScreenA03({ onNavigate }) {
  const [note, setNote] = React.useState('Sudah 3x tidak submit lesson minggu ini. Kirim pesan personal sebelum review bulanan.');

  const radarData = [
    { label: 'Foundations', value: 0.82 },
    { label: 'Prompting', value: 0.91 },
    { label: 'Tools', value: 0.64 },
    { label: 'Workflow', value: 0.45 },
    { label: 'Building', value: 0.3 },
  ];

  const activities = [
    { icon: '📝', title: 'Selesai: Prompt Engineering Basics', time: '2 hari lalu', score: '92/100', type: 'lesson' },
    { icon: '🎯', title: 'Quiz: ChatGPT API Fundamentals', time: '3 hari lalu', score: '78/100', type: 'quiz' },
    { icon: '⬆️', title: 'Naik ke Level 2', time: '5 hari lalu', score: null, type: 'levelup' },
    { icon: '📝', title: 'Selesai: Intro to AI Tools', time: '6 hari lalu', score: '85/100', type: 'lesson' },
    { icon: '📝', title: 'Selesai: AI dalam Kerjaan Harian', time: '8 hari lalu', score: '90/100', type: 'lesson' },
  ];

  const levelHistory = [
    { label: 'Jan', value: 1.0 }, { label: 'Feb', value: 1.2 }, { label: 'Mar', value: 1.4 },
    { label: 'Apr W1', value: 1.6 }, { label: 'Apr W2', value: 1.8 }, { label: 'Apr W3', value: 2.0 },
    { label: 'Skrg', value: 2.1 },
  ];

  return (
    <div style={{ display: 'flex', height: '100%', overflow: 'hidden' }}>
      <SidebarNav active="A03" onNavigate={onNavigate} />
      <div style={{ flex: 1, display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
        <TopBar title="User Detail" subtitle="PT Acme · Users · Budi Santoso" />
        <div style={{ flex: 1, overflowY: 'auto', padding: '24px 28px' }}>
          {/* Profile header */}
          <div style={{ background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 18, padding: '24px', marginBottom: 20 }}>
            <div style={{ display: 'flex', alignItems: 'flex-start', gap: 16, marginBottom: 16 }}>
              <Avatar name="Budi Santoso" size={64} />
              <div style={{ flex: 1 }}>
                <div style={{ fontFamily: 'var(--font-display)', fontSize: 22, fontWeight: 700, color: 'var(--text)', letterSpacing: '-0.02em' }}>Budi Santoso</div>
                <div style={{ fontSize: 13, color: 'var(--text-muted)', marginTop: 2 }}>Marketing · Senior Copywriter</div>
                <div style={{ fontSize: 12, color: 'var(--text-dim)', marginTop: 2 }}>Reports to: Andi Susanto</div>
                <div style={{ display: 'flex', gap: 8, marginTop: 10, flexWrap: 'wrap' }}>
                  <LevelChip level={2} label="AI-FLUENT" />
                  <XPChip xp="240 XP" />
                  <StreakChip days={0} />
                </div>
              </div>
              <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
                <BtnGhost small>Kirim Nudge</BtnGhost>
                <BtnGhost small danger>Reset Streak</BtnGhost>
                <BtnGhost small>Lihat sebagai user</BtnGhost>
              </div>
            </div>
            <div style={{ background: 'rgba(255,75,145,0.06)', border: '1px solid rgba(255,75,145,0.15)', borderRadius: 10, padding: '10px 14px', display: 'flex', alignItems: 'center', gap: 8 }}>
              <span style={{ color: 'var(--danger)', fontSize: 13 }}>⚠</span>
              <span style={{ fontSize: 12, color: 'var(--danger)', fontWeight: 600 }}>Tidak aktif 8 hari — streak terputus</span>
            </div>
          </div>

          {/* 2-col grid */}
          <div style={{ display: 'grid', gridTemplateColumns: '1fr 380px', gap: 20 }}>
            {/* Left: Activity timeline */}
            <div>
              <div style={{ background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 16, padding: '20px', marginBottom: 20 }}>
                <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--text)', marginBottom: 16 }}>Aktivitas Terbaru</div>
                <div style={{ position: 'relative' }}>
                  <div style={{ position: 'absolute', left: 14, top: 20, bottom: 0, width: 1, background: 'var(--border)' }} />
                  {activities.map((a, i) => (
                    <div key={i} style={{ display: 'flex', gap: 14, marginBottom: 16, alignItems: 'flex-start' }}>
                      <div style={{ width: 28, height: 28, borderRadius: '50%', background: a.type === 'levelup' ? 'var(--accent-overlay-mid)' : 'var(--surface-2)', border: `1px solid ${a.type === 'levelup' ? 'var(--accent)' : 'var(--border)'}`, display: 'flex', alignItems: 'center', justifyContent: 'center', flexShrink: 0, fontSize: 12, zIndex: 1 }}>
                        {a.icon}
                      </div>
                      <div style={{ flex: 1 }}>
                        <div style={{ fontSize: 13, fontWeight: 600, color: 'var(--text)', lineHeight: 1.3 }}>{a.title}</div>
                        <div style={{ display: 'flex', gap: 8, marginTop: 4, alignItems: 'center' }}>
                          <span style={{ fontSize: 11, color: 'var(--text-dim)' }}>{a.time}</span>
                          {a.score && <span style={{ fontSize: 11, color: 'var(--accent)', fontFamily: 'var(--font-mono)', fontWeight: 700 }}>{a.score}</span>}
                        </div>
                      </div>
                    </div>
                  ))}
                </div>
              </div>

              {/* Level progress per path */}
              <div style={{ background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 16, padding: '20px' }}>
                <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--text)', marginBottom: 14 }}>Progress per Lesson</div>
                {[
                  { name: 'AI dalam Kerjaan Harian', progress: 1.0, done: true },
                  { name: 'Intro to AI Tools', progress: 1.0, done: true },
                  { name: 'Prompt Engineering Basics', progress: 1.0, done: true },
                  { name: 'ChatGPT API Fundamentals', progress: 0.78, done: false },
                  { name: 'Chain-of-Thought Prompting', progress: 0, done: false },
                  { name: 'AI Workflow Automation', progress: 0, done: false, locked: true },
                ].map((l, i) => (
                  <div key={i} style={{ marginBottom: 12 }}>
                    <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 4 }}>
                      <span style={{ fontSize: 12, color: l.locked ? 'var(--text-dim)' : 'var(--text)', fontWeight: 500 }}>{l.name}</span>
                      <span style={{ fontSize: 11, color: l.done ? 'var(--success)' : 'var(--text-muted)', fontFamily: 'var(--font-mono)' }}>{l.done ? '✓ Selesai' : l.locked ? '🔒' : `${Math.round(l.progress * 100)}%`}</span>
                    </div>
                    <ProgressBar value={l.progress * 100} max={100} height={4} />
                  </div>
                ))}
              </div>
            </div>

            {/* Right: Radar + Note + Trend */}
            <div style={{ display: 'flex', flexDirection: 'column', gap: 20 }}>
              {/* Radar */}
              <div style={{ background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 16, padding: '20px', display: 'flex', flexDirection: 'column', alignItems: 'center' }}>
                <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--text)', marginBottom: 4, alignSelf: 'flex-start' }}>Competency Radar</div>
                <div style={{ fontSize: 11, color: 'var(--text-muted)', marginBottom: 12, alignSelf: 'flex-start' }}>5 dimensi kompetensi AI</div>
                <RadarChart data={radarData} size={220} animated={true} />
                <div style={{ marginTop: 12, display: 'flex', flexWrap: 'wrap', gap: 6 }}>
                  {radarData.map(d => (
                    <span key={d.label} style={{ fontSize: 10, color: d.value > 0.7 ? 'var(--success)' : d.value > 0.5 ? 'var(--accent)' : 'var(--text-muted)', fontWeight: 700 }}>
                      {d.label}: {d.value > 0.7 ? 'kuat' : d.value > 0.5 ? 'cukup' : 'perlu latihan'}
                    </span>
                  ))}
                </div>
              </div>

              {/* Manager note */}
              <div style={{ background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 16, padding: '20px' }}>
                <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--text)', marginBottom: 4 }}>Catatan Manager</div>
                <div style={{ fontSize: 11, color: 'var(--text-dim)', marginBottom: 10 }}>Privat · hanya terlihat Anda</div>
                <textarea value={note} onChange={e => setNote(e.target.value)}
                  style={{ width: '100%', background: 'var(--bg-soft)', border: '1px solid var(--border)', color: 'var(--text)', padding: '12px', borderRadius: 10, fontSize: 12, lineHeight: 1.55, fontFamily: 'var(--font-body)', resize: 'vertical', minHeight: 80, outline: 'none' }}
                  onFocus={e => e.target.style.borderColor = 'var(--accent)'}
                  onBlur={e => e.target.style.borderColor = 'var(--border)'}
                />
                <div style={{ fontSize: 10, color: 'var(--text-dim)', marginTop: 6 }}>Terakhir diubah 2 hari lalu</div>
              </div>

              {/* Level history */}
              <div style={{ background: 'var(--surface-1)', border: '1px solid var(--border)', borderRadius: 16, padding: '20px' }}>
                <div style={{ fontSize: 13, fontWeight: 700, color: 'var(--text)', marginBottom: 4 }}>Riwayat Level</div>
                <div style={{ fontSize: 11, color: 'var(--text-muted)', marginBottom: 8 }}>12 minggu terakhir</div>
                <LineChart data={levelHistory} width={320} height={100} />
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
}

Object.assign(window, { ScreenA01, ScreenA02, ScreenA03, SidebarNav, TopBar, KPICard });
